Added support for spherical texture mapping and better file search support

for meterial files.
This commit is contained in:
Robert Osfield 2004-08-31 14:48:05 +00:00
parent 1da72da167
commit de686f409b
2 changed files with 25 additions and 3 deletions

View File

@ -108,6 +108,13 @@ void ReaderWriterOBJ::buildMaterialToStateSetMap(obj::Model& model, MaterialToSt
{
osg::Texture2D* texture = new osg::Texture2D(image);
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
if (material.textureReflection)
{
osg::TexGen* texgen = new osg::TexGen;
texgen->setMode(osg::TexGen::SPHERE_MAP);
stateset->setTextureAttributeAndModes(0,texgen,osg::StateAttribute::ON);
}
}
}
@ -439,6 +446,9 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil
std::ifstream fin(fileName.c_str());
if (fin)
{
osgDB::PushAndPopDataPath papdp( osgDB::getFilePath(fileName.c_str()) );
obj::Model model;
model.readOBJ(fin);

View File

@ -17,6 +17,9 @@
#include <osg/Notify>
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
using namespace obj;
bool Model::readline(std::istream& fin, char* line, const int LINE_SIZE)
@ -241,6 +244,10 @@ bool Model::readMTL(std::istream& fin)
std::string filename(line+7);
material->map_Ks = filename;
}
else if (strcmp(line,"refl")==0 || strncmp(line,"refl ",5)==0)
{
material->textureReflection = true;
}
else
{
osg::notify(osg::NOTICE) <<"*** line not handled *** :"<<line<<std::endl;
@ -382,10 +389,15 @@ bool Model::readOBJ(std::istream& fin)
}
else if (strncmp(line,"mtllib ",7)==0)
{
std::ifstream mfin(line+7);
if (mfin)
std::string fileName = osgDB::findDataFile( line+7 );
if (!fileName.empty())
{
readMTL(mfin);
std::ifstream mfin(fileName.c_str());
if (mfin)
{
readMTL(mfin);
}
}
}
else if (strncmp(line,"o ",2)==0)