Improvements to the handling of OBJ files

This commit is contained in:
Robert Osfield 2004-08-16 13:17:29 +00:00
parent 28e43fb2da
commit a8c05e9342
2 changed files with 18 additions and 2 deletions

View File

@ -242,18 +242,27 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil
if (omtl->textureName)
{
TextureMap::iterator titr = textureMap.find(omtl->textureName);
osg::notify(osg::DEBUG_INFO) << "textureName: " << omtl->textureName << std::endl;
if (titr==textureMap.end())
{
std::string fileName = osgDB::findFileInDirectory(omtl->textureName,directory,osgDB::CASE_INSENSITIVE);
if (!fileName.empty()) fileName = osgDB::findDataFile(omtl->textureName,osgDB::CASE_INSENSITIVE);
if (fileName.empty()) fileName = osgDB::findDataFile(omtl->textureName,osgDB::CASE_INSENSITIVE);
if (!fileName.empty())
{
osg::notify(osg::DEBUG_INFO) << "filename: " << fileName << std::endl;
osg::Image* osg_image = osgDB::readImageFile(fileName.c_str());
if (osg_image)
{
osg::notify(osg::DEBUG_INFO) << "imageRead: " << omtl->textureName << std::endl;
osg::Texture2D* osg_texture = new osg::Texture2D;
osg_texture->setImage(osg_image);
stateset->setTextureAttributeAndModes(0,osg_texture,osg::StateAttribute::ON);
@ -351,6 +360,9 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil
// state and material (if any)
if (!osg_mtl.empty()) {
osg::notify(osg::NOTICE)<<"ogrp->material="<<ogrp->material<<std::endl;
drawable->setStateSet(osg_mtl[ogrp->material].get());
}

View File

@ -654,6 +654,8 @@ _glmFirstPass(GLMmodel* model, FILE* file)
/* eat up rest of line */
fgets(buf, sizeof(buf), file);
break;
case 'o': /* group */
case 's': /* group */
case 'g': /* group */
{
/* eat up rest of line */
@ -844,6 +846,8 @@ _glmSecondPass(GLMmodel* model, FILE* file)
if (previousLineWas_g || firstGroup) group->material = material;
break;
case 'o': /* group */
case 's': /* group */
case 'g': /* group */
/* eat up rest of line */
fgets(buf, sizeof(buf), file);