From Ulrich Hertlein, "as I hinted at on osg-users in the "obj loader: map_* only reads last component" thread, this submission broke material/texture loading for some files I have that specify texture matrix scaling.

The following link shows a very comprehensive list of .mtl file options:
http://local.wasp.uwa.edu.au/~pbourke/dataformats/mtl/

Attached is a patch that should fix spacey filenames and optional texture scale/offset.  I have tested it with files I have that I modified to contain spaces in the texture filenames."
This commit is contained in:
Robert Osfield
2008-07-25 15:45:40 +00:00
parent 55199b8e38
commit d8d2bc4193
3 changed files with 93 additions and 13 deletions

View File

@@ -163,7 +163,7 @@ inline osg::Vec3 ReaderWriterOBJ::transformNormal(const osg::Vec3& vec, const bo
// register with Registry to instantiate the above reader/writer.
REGISTER_OSGPLUGIN(obj, ReaderWriterOBJ)
void load_material_texture( obj::Model &model,
static void load_material_texture( obj::Model &model,
obj::Material &material,
osg::StateSet *stateset,
const std::string & filename,
@@ -174,7 +174,7 @@ void load_material_texture( obj::Model &model,
osg::ref_ptr< osg::Image > image;
if ( !model.getDatabasePath().empty() )
{
// first try with databasr path of parent.
// first try with database path of parent.
image = osgDB::readImageFile(model.getDatabasePath()+'/'+filename);
}
@@ -208,6 +208,26 @@ void load_material_texture( obj::Model &model,
}
}
}
if (material.uScale != 1.0f || material.vScale != 1.0f ||
material.uOffset != 0.0f || material.vOffset != 0.0f)
{
osg::Matrix mat;
if (material.uScale != 1.0f || material.vScale != 1.0f)
{
osg::notify(osg::DEBUG_INFO) << "Obj TexMat scale=" << material.uScale << "," << material.vScale << std::endl;
mat *= osg::Matrix::scale(material.uScale, material.vScale, 1.0);
}
if (material.uOffset != 0.0f || material.vOffset != 0.0f)
{
osg::notify(osg::DEBUG_INFO) << "Obj TexMat offset=" << material.uOffset << "," << material.uOffset << std::endl;
mat *= osg::Matrix::translate(material.uOffset, material.vOffset, 0.0);
}
osg::TexMat* texmat = new osg::TexMat;
texmat->setMatrix(mat);
stateset->setTextureAttributeAndModes( texture_unit,texmat,osg::StateAttribute::ON );
}
}