diff options
Diffstat (limited to 'source/Irrlicht/COBJMeshFileLoader.cpp')
-rw-r--r-- | source/Irrlicht/COBJMeshFileLoader.cpp | 353 |
1 files changed, 0 insertions, 353 deletions
diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index 17dcec9..f16cf9e 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -6,7 +6,6 @@ #ifdef _IRR_COMPILE_WITH_OBJ_LOADER_
#include "COBJMeshFileLoader.h"
-#include "CMeshTextureLoader.h"
#include "IMeshManipulator.h"
#include "IVideoDriver.h"
#include "SMesh.h"
@@ -39,8 +38,6 @@ COBJMeshFileLoader::COBJMeshFileLoader(scene::ISceneManager* smgr, io::IFileSyst if (FileSystem)
FileSystem->grab();
-
- TextureLoader = new CMeshTextureLoader( FileSystem, SceneManager->getVideoDriver() );
}
@@ -69,9 +66,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) if (!file)
return 0;
- if ( getMeshTextureLoader() )
- getMeshTextureLoader()->setMeshFile(file);
-
const long filesize = file->getSize();
if (!filesize)
return 0;
@@ -119,7 +113,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) #ifdef _IRR_DEBUG_OBJ_LOADER_
os::Printer::log("Reading material file",name);
#endif
- readMTL(name, relPath);
}
}
break;
@@ -358,352 +351,6 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) return animMesh;
}
-
-const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const bufEnd, SObjMtl* currMaterial, const io::path& relPath)
-{
- u8 type=0; // map_Kd - diffuse color texture map
- // map_Ks - specular color texture map
- // map_Ka - ambient color texture map
- // map_Ns - shininess texture map
- if ((!strncmp(bufPtr,"map_bump",8)) || (!strncmp(bufPtr,"bump",4)))
- type=1; // normal map
- else if ((!strncmp(bufPtr,"map_d",5)) || (!strncmp(bufPtr,"map_opacity",11)))
- type=2; // opacity map
- else if (!strncmp(bufPtr,"map_refl",8))
- type=3; // reflection map
- // extract new material's name
- c8 textureNameBuf[WORD_BUFFER_LENGTH];
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
-
- f32 bumpiness = 6.0f;
- bool clamp = false;
- core::vector3df tscale(1.f); //For map_Kd texture scaling
- core::vector3df tpos(0.f); //For map_Kd texture translation
- // handle options
- while (textureNameBuf[0]=='-')
- {
- if (!strncmp(bufPtr,"-bm",3))
- {
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- currMaterial->Meshbuffer->Material.MaterialTypeParam=core::fast_atof(textureNameBuf);
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- continue;
- }
- else
- if (!strncmp(bufPtr,"-blendu",7))
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- else
- if (!strncmp(bufPtr,"-blendv",7))
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- else
- if (!strncmp(bufPtr,"-cc",3))
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- else
- if (!strncmp(bufPtr,"-clamp",6))
- bufPtr = readBool(bufPtr, clamp, bufEnd);
- else
- if (!strncmp(bufPtr,"-texres",7))
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- else
- if (!strncmp(bufPtr,"-type",5))
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- else
- if (!strncmp(bufPtr,"-mm",3))
- {
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- }
- else
- if (!strncmp(bufPtr,"-o",2)) // texture coord translation
- {
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1])))
- tpos.X = core::fast_atof(textureNameBuf);
-
- // next parameters are optional, so skip rest of loop if no number is found
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
- continue;
- tpos.Y = core::fast_atof(textureNameBuf);
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
- continue;
- tpos.Z = core::fast_atof(textureNameBuf);
- }
- else
- if (!strncmp(bufPtr,"-s",2)) // texture coord scale
- {
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1])))
- tscale.X = core::fast_atof(textureNameBuf);
-
- // next parameters are optional, so skip rest of loop if no number is found
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
- continue;
- tscale.Y = core::fast_atof(textureNameBuf);
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
- continue;
- tscale.Z = core::fast_atof(textureNameBuf);
- }
- else
- if (!strncmp(bufPtr,"-t",2))
- {
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- // next parameters are optional, so skip rest of loop if no number is found
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
- continue;
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- if (!(core::isdigit(textureNameBuf[0]) || (textureNameBuf[0] == '-' && core::isdigit(textureNameBuf[1]))))
- continue;
- }
- // get next word
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- }
-
- if ((type==1) && (core::isdigit(textureNameBuf[0])))
- {
- currMaterial->Meshbuffer->Material.MaterialTypeParam=core::fast_atof(textureNameBuf);
- bufPtr = goAndCopyNextWord(textureNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- }
- if (clamp)
- currMaterial->Meshbuffer->Material.setFlag(video::EMF_TEXTURE_WRAP, video::ETC_CLAMP);
-
- io::path texname(textureNameBuf);
- if (texname.size() && getMeshTextureLoader())
- {
- video::ITexture * texture = getMeshTextureLoader()->getTexture(texname);
- if ( texture )
- {
- if (type==0)
- {
- currMaterial->Meshbuffer->Material.setTexture(0, texture);
- bool needsTextureMatrix = tscale != core::vector3df(1.f) || tpos != core::vector3df(0.f);
- if (needsTextureMatrix)
- {
- currMaterial->Meshbuffer->Material.getTextureMatrix(0).setTextureScale(tscale.X, tscale.Y);
- currMaterial->Meshbuffer->Material.getTextureMatrix(0).setTextureTranslate(tpos.X, tpos.Y);
- }
- }
- else if (type==1)
- {
- if ( texture->getSource() == video::ETS_FROM_FILE)
- SceneManager->getVideoDriver()->makeNormalMapTexture(texture, bumpiness);
- currMaterial->Meshbuffer->Material.setTexture(1, texture);
- currMaterial->Meshbuffer->Material.MaterialType=video::EMT_PARALLAX_MAP_SOLID;
- currMaterial->Meshbuffer->Material.MaterialTypeParam=0.035f;
- }
- else if (type==2)
- {
- currMaterial->Meshbuffer->Material.setTexture(0, texture);
- currMaterial->Meshbuffer->Material.MaterialType=video::EMT_TRANSPARENT_ADD_COLOR;
- }
- else if (type==3)
- {
- // currMaterial->Meshbuffer->Material.Textures[1] = texture;
- // currMaterial->Meshbuffer->Material.MaterialType=video::EMT_REFLECTION_2_LAYER;
- }
- // Set diffuse material color to white so as not to affect texture color
- // Because Maya set diffuse color Kd to black when you use a diffuse color map
- // But is this the right thing to do?
- currMaterial->Meshbuffer->Material.DiffuseColor.set(
- currMaterial->Meshbuffer->Material.DiffuseColor.getAlpha(), 255, 255, 255 );
- }
- }
- return bufPtr;
-}
-
-
-void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath)
-{
- const io::path realFile(fileName);
- io::IReadFile * mtlReader;
-
- if (FileSystem->existFile(realFile))
- mtlReader = FileSystem->createAndOpenFile(realFile);
- else if (FileSystem->existFile(relPath + realFile))
- mtlReader = FileSystem->createAndOpenFile(relPath + realFile);
- else if (FileSystem->existFile(FileSystem->getFileBasename(realFile)))
- mtlReader = FileSystem->createAndOpenFile(FileSystem->getFileBasename(realFile));
- else
- mtlReader = FileSystem->createAndOpenFile(relPath + FileSystem->getFileBasename(realFile));
- if (!mtlReader) // fail to open and read file
- {
- os::Printer::log("Could not open material file", realFile, ELL_WARNING);
- return;
- }
-
- if ( getMeshTextureLoader() )
- {
- getMeshTextureLoader()->setMaterialFile(mtlReader);
- if ( SceneManager->getParameters()->existsAttribute(OBJ_TEXTURE_PATH) )
- getMeshTextureLoader()->setTexturePath(SceneManager->getParameters()->getAttributeAsString(OBJ_TEXTURE_PATH));
- }
-
- const long filesize = mtlReader->getSize();
- if (!filesize)
- {
- os::Printer::log("Skipping empty material file", realFile, ELL_WARNING);
- mtlReader->drop();
- return;
- }
-
- c8* buf = new c8[filesize];
- mtlReader->read((void*)buf, filesize);
- const c8* bufEnd = buf+filesize;
-
- SObjMtl* currMaterial = 0;
-
- const c8* bufPtr = buf;
- while(bufPtr != bufEnd)
- {
- switch(*bufPtr)
- {
- case 'n': // newmtl
- {
- // if there's an existing material, store it first
- if ( currMaterial )
- Materials.push_back( currMaterial );
-
- // extract new material's name
- c8 mtlNameBuf[WORD_BUFFER_LENGTH];
- bufPtr = goAndCopyNextWord(mtlNameBuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
-
- currMaterial = new SObjMtl;
- currMaterial->Name = mtlNameBuf;
- }
- break;
- case 'i': // illum - illumination
- if ( currMaterial )
- {
- const u32 COLOR_BUFFER_LENGTH = 16;
- c8 illumStr[COLOR_BUFFER_LENGTH];
-
- bufPtr = goAndCopyNextWord(illumStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
- currMaterial->Illumination = (c8)atol(illumStr);
- }
- break;
- case 'N':
- if ( currMaterial )
- {
- switch(bufPtr[1])
- {
- case 's': // Ns - shininess
- {
- const u32 COLOR_BUFFER_LENGTH = 16;
- c8 nsStr[COLOR_BUFFER_LENGTH];
-
- bufPtr = goAndCopyNextWord(nsStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
- f32 shininessValue = core::fast_atof(nsStr);
-
- // wavefront shininess is from [0, 1000], so scale for OpenGL
- shininessValue *= 0.128f;
- currMaterial->Meshbuffer->Material.Shininess = shininessValue;
- }
- break;
- case 'i': // Ni - refraction index
- {
- c8 tmpbuf[WORD_BUFFER_LENGTH];
- bufPtr = goAndCopyNextWord(tmpbuf, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
- }
- break;
- }
- }
- break;
- case 'K':
- if ( currMaterial )
- {
- switch(bufPtr[1])
- {
- case 'd': // Kd = diffuse
- {
- bufPtr = readColor(bufPtr, currMaterial->Meshbuffer->Material.DiffuseColor, bufEnd);
-
- }
- break;
-
- case 's': // Ks = specular
- {
- bufPtr = readColor(bufPtr, currMaterial->Meshbuffer->Material.SpecularColor, bufEnd);
- }
- break;
-
- case 'a': // Ka = ambience
- {
- bufPtr=readColor(bufPtr, currMaterial->Meshbuffer->Material.AmbientColor, bufEnd);
- }
- break;
- case 'e': // Ke = emissive
- {
- currMaterial->Meshbuffer->Material.EmissiveColor.setAlpha(255);
- bufPtr=readColor(bufPtr, currMaterial->Meshbuffer->Material.EmissiveColor, bufEnd);
- }
- break;
- } // end switch(bufPtr[1])
- } // end case 'K': if ( 0 != currMaterial )...
- break;
- case 'b': // bump
- case 'm': // texture maps
- if (currMaterial)
- {
- bufPtr=readTextures(bufPtr, bufEnd, currMaterial, relPath);
- }
- break;
- case 'd': // d - transparency
- if ( currMaterial )
- {
- const u32 COLOR_BUFFER_LENGTH = 16;
- c8 dStr[COLOR_BUFFER_LENGTH];
-
- bufPtr = goAndCopyNextWord(dStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
- f32 dValue = core::fast_atof(dStr);
-
- currMaterial->Meshbuffer->Material.DiffuseColor.setAlpha( (s32)(dValue * 255) );
- if (dValue<1.0f)
- currMaterial->Meshbuffer->Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
- }
- break;
- case 'T':
- if ( currMaterial )
- {
- switch ( bufPtr[1] )
- {
- case 'f': // Tf - Transmitivity
- const u32 COLOR_BUFFER_LENGTH = 16;
- c8 redStr[COLOR_BUFFER_LENGTH];
- c8 greenStr[COLOR_BUFFER_LENGTH];
- c8 blueStr[COLOR_BUFFER_LENGTH];
-
- bufPtr = goAndCopyNextWord(redStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
- bufPtr = goAndCopyNextWord(greenStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
- bufPtr = goAndCopyNextWord(blueStr, bufPtr, COLOR_BUFFER_LENGTH, bufEnd);
-
- f32 transparency = ( core::fast_atof(redStr) + core::fast_atof(greenStr) + core::fast_atof(blueStr) ) / 3;
-
- currMaterial->Meshbuffer->Material.DiffuseColor.setAlpha( (s32)(transparency * 255) );
- if (transparency < 1.0f)
- currMaterial->Meshbuffer->Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
- }
- }
- break;
- default: // comments or not recognised
- break;
- } // end switch(bufPtr[0])
- // go to next line
- bufPtr = goNextLine(bufPtr, bufEnd);
- } // end while (bufPtr)
-
- // end of file. if there's an existing material, store it
- if ( currMaterial )
- Materials.push_back( currMaterial );
-
- delete [] buf;
- mtlReader->drop();
-}
-
-
//! Read RGB color
const c8* COBJMeshFileLoader::readColor(const c8* bufPtr, video::SColor& color, const c8* const bufEnd)
{
|