Commit 7c19d2db authored by hybrid's avatar hybrid

Use the filesystem methods to deal with paths.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1294 dfc29bdd-3216-0410-991c-e03cc46cb475
parent e300dc2c
...@@ -163,8 +163,6 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -163,8 +163,6 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file)
if (readChunk(file, &data)) if (readChunk(file, &data))
{ {
// success // success
SAnimatedMesh* am = new SAnimatedMesh();
am->Type = EAMT_3DS;
for (u32 i=0; i<Mesh->getMeshBufferCount(); ++i) for (u32 i=0; i<Mesh->getMeshBufferCount(); ++i)
{ {
...@@ -177,7 +175,6 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -177,7 +175,6 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file)
} }
else else
{ {
mb->recalculateBoundingBox();
if (mb->Material.MaterialType == video::EMT_PARALLAX_MAP_SOLID) if (mb->Material.MaterialType == video::EMT_PARALLAX_MAP_SOLID)
{ {
SMesh tmp; SMesh tmp;
...@@ -186,11 +183,14 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -186,11 +183,14 @@ IAnimatedMesh* C3DSMeshFileLoader::createMesh(io::IReadFile* file)
mb->drop(); mb->drop();
Mesh->MeshBuffers[i]=tangentMesh->getMeshBuffer(0); Mesh->MeshBuffers[i]=tangentMesh->getMeshBuffer(0);
} }
Mesh->MeshBuffers[i]->recalculateBoundingBox();
} }
} }
Mesh->recalculateBoundingBox(); Mesh->recalculateBoundingBox();
SAnimatedMesh* am = new SAnimatedMesh();
am->Type = EAMT_3DS;
am->addMesh(Mesh); am->addMesh(Mesh);
am->recalculateBoundingBox(); am->recalculateBoundingBox();
Mesh->drop(); Mesh->drop();
...@@ -392,7 +392,17 @@ bool C3DSMeshFileLoader::readMaterialChunk(io::IReadFile* file, ChunkData* paren ...@@ -392,7 +392,17 @@ bool C3DSMeshFileLoader::readMaterialChunk(io::IReadFile* file, ChunkData* paren
case C3DS_MATBUMPMAP: case C3DS_MATBUMPMAP:
{ {
matSection=data.header.id; matSection=data.header.id;
#if 1 // Should contain a percentage chunk, but does not work with the meshes // Should contain a percentage chunk, but does
// not always have it
s16 testval;
const long pos = file->getPos();
file->read(&testval, 2);
#ifdef __BIG_ENDIAN__
testval = os::Byteswap::byteswap(testval);
#endif
file->seek(pos, false);
if ((testval == C3DS_PERCENTAGE_I) ||
(testval == C3DS_PERCENTAGE_F))
switch (matSection) switch (matSection)
{ {
case C3DS_MATTEXMAP: case C3DS_MATTEXMAP:
...@@ -408,7 +418,6 @@ bool C3DSMeshFileLoader::readMaterialChunk(io::IReadFile* file, ChunkData* paren ...@@ -408,7 +418,6 @@ bool C3DSMeshFileLoader::readMaterialChunk(io::IReadFile* file, ChunkData* paren
readPercentageChunk(file, &data, CurrentMaterial.Strength[4]); readPercentageChunk(file, &data, CurrentMaterial.Strength[4]);
break; break;
} }
#endif
} }
break; break;
case C3DS_MATMAPFILE: case C3DS_MATMAPFILE:
...@@ -1031,24 +1040,6 @@ void C3DSMeshFileLoader::composeObject(io::IReadFile* file, const core::stringc& ...@@ -1031,24 +1040,6 @@ void C3DSMeshFileLoader::composeObject(io::IReadFile* file, const core::stringc&
} }
core::stringc C3DSMeshFileLoader::getTextureFileName(const core::stringc& texture,
core::stringc& model)
{
s32 idx = -1;
idx = model.findLast('/');
if (idx == -1)
idx = model.findLast('\\');
if (idx == -1)
return core::stringc();
core::stringc p = model.subString(0, idx+1);
p.append(texture);
return p;
}
void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
{ {
// create a mesh buffer for every material // create a mesh buffer for every material
...@@ -1067,15 +1058,15 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1067,15 +1058,15 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
m->getMaterial() = Materials[i].Material; m->getMaterial() = Materials[i].Material;
if (Materials[i].Filename[0].size()) if (Materials[i].Filename[0].size())
{ {
video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[0].c_str()); video::ITexture* texture = 0;
if (FileSystem->existFile(Materials[i].Filename[0].c_str()))
texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[0].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( const core::stringc fname = FileSystem->getFileDir(modelFilename) + "/" + FileSystem->getFileBasename(Materials[i].Filename[0]);
Materials[i].Filename[0], modelFilename); if (FileSystem->existFile(fname.c_str()))
if (fname.size())
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
if (!texture) if (!texture)
os::Printer::log("Could not load a texture for entry in 3ds file", os::Printer::log("Could not load a texture for entry in 3ds file",
Materials[i].Filename[0].c_str(), ELL_WARNING); Materials[i].Filename[0].c_str(), ELL_WARNING);
...@@ -1085,16 +1076,15 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1085,16 +1076,15 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
if (Materials[i].Filename[2].size()) if (Materials[i].Filename[2].size())
{ {
video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[2].c_str()); video::ITexture* texture = 0;
if (FileSystem->existFile(Materials[i].Filename[2].c_str()))
texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[2].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( const core::stringc fname = FileSystem->getFileDir(modelFilename) + "/" + FileSystem->getFileBasename(Materials[i].Filename[2]);
Materials[i].Filename[2], modelFilename); if (FileSystem->existFile(fname.c_str()))
if (fname.size())
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
if (!texture) if (!texture)
{ {
os::Printer::log("Could not load a texture for entry in 3ds file", os::Printer::log("Could not load a texture for entry in 3ds file",
...@@ -1109,13 +1099,13 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1109,13 +1099,13 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
if (Materials[i].Filename[3].size()) if (Materials[i].Filename[3].size())
{ {
video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[3].c_str()); video::ITexture* texture = 0;
if (FileSystem->existFile(Materials[i].Filename[3].c_str()))
texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[3].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( const core::stringc fname = FileSystem->getFileDir(modelFilename) + "/" + FileSystem->getFileBasename(Materials[i].Filename[3]);
Materials[i].Filename[3], modelFilename); if (FileSystem->existFile(fname.c_str()))
if (fname.size())
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
...@@ -1134,23 +1124,22 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file) ...@@ -1134,23 +1124,22 @@ void C3DSMeshFileLoader::loadMaterials(io::IReadFile* file)
if (Materials[i].Filename[4].size()) if (Materials[i].Filename[4].size())
{ {
video::ITexture* texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[4].c_str()); video::ITexture* texture = 0;
if (FileSystem->existFile(Materials[i].Filename[4].c_str()))
texture = SceneManager->getVideoDriver()->getTexture(Materials[i].Filename[4].c_str());
if (!texture) if (!texture)
{ {
core::stringc fname = getTextureFileName( const core::stringc fname = FileSystem->getFileDir(modelFilename) + "/" + FileSystem->getFileBasename(Materials[i].Filename[4]);
Materials[i].Filename[4], modelFilename); if (FileSystem->existFile(fname.c_str()))
if (fname.size())
texture = SceneManager->getVideoDriver()->getTexture(fname.c_str()); texture = SceneManager->getVideoDriver()->getTexture(fname.c_str());
} }
if (!texture) if (!texture)
os::Printer::log("Could not load a texture for entry in 3ds file", os::Printer::log("Could not load a texture for entry in 3ds file",
Materials[i].Filename[4].c_str(), ELL_WARNING); Materials[i].Filename[4].c_str(), ELL_WARNING);
else else
{ {
m->getMaterial().setTexture(1, texture); m->getMaterial().setTexture(1, texture);
SceneManager->getVideoDriver()->makeNormalMapTexture(texture, Materials[i].Strength[4]); SceneManager->getVideoDriver()->makeNormalMapTexture(texture, Materials[i].Strength[4]*10.f);
m->getMaterial().MaterialType=video::EMT_PARALLAX_MAP_SOLID; m->getMaterial().MaterialType=video::EMT_PARALLAX_MAP_SOLID;
m->getMaterial().MaterialTypeParam=.035f; m->getMaterial().MaterialTypeParam=.035f;
} }
......
...@@ -150,7 +150,6 @@ private: ...@@ -150,7 +150,6 @@ private:
void composeObject(io::IReadFile* file, const core::stringc& name); void composeObject(io::IReadFile* file, const core::stringc& name);
void loadMaterials(io::IReadFile* file); void loadMaterials(io::IReadFile* file);
void cleanUp(); void cleanUp();
core::stringc getTextureFileName(const core::stringc& texture, core::stringc& model);
scene::ISceneManager* SceneManager; scene::ISceneManager* SceneManager;
io::IFileSystem* FileSystem; io::IFileSystem* FileSystem;
......
...@@ -58,17 +58,16 @@ struct SMD3Skin ...@@ -58,17 +58,16 @@ struct SMD3Skin
//! Constructor //! Constructor
CAnimatedMeshMD3::CAnimatedMeshMD3 () CAnimatedMeshMD3::CAnimatedMeshMD3()
// TODO: Correct initial values needed // TODO: Correct initial values needed
: Mesh(0), IPolShift(0), LoopMode(0), Scaling(1.f) : Mesh(0), IPolShift(0), LoopMode(0), Scaling(1.f)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CAnimatedMeshMD3"); setDebugName("CAnimatedMeshMD3");
#endif #endif
Mesh = new SMD3Mesh (); Mesh = new SMD3Mesh();
memset ( &Mesh->MD3Header, 0, sizeof ( Mesh->MD3Header ) ); memset( &Mesh->MD3Header, 0, sizeof ( Mesh->MD3Header ) );
setInterpolationShift ( 0, 0 ); setInterpolationShift ( 0, 0 );
} }
...@@ -77,8 +76,8 @@ CAnimatedMeshMD3::CAnimatedMeshMD3 () ...@@ -77,8 +76,8 @@ CAnimatedMeshMD3::CAnimatedMeshMD3 ()
//! Destructor //! Destructor
CAnimatedMeshMD3::~CAnimatedMeshMD3() CAnimatedMeshMD3::~CAnimatedMeshMD3()
{ {
if ( Mesh ) if (Mesh)
Mesh->drop (); Mesh->drop();
} }
......
...@@ -346,16 +346,14 @@ bool CMS3DMeshFileLoader::load(io::IReadFile* file) ...@@ -346,16 +346,14 @@ bool CMS3DMeshFileLoader::load(io::IReadFile* file)
tmpBuffer->Material.Shininess = material->Shininess; tmpBuffer->Material.Shininess = material->Shininess;
core::stringc TexturePath(material->Texture); core::stringc TexturePath(material->Texture);
TexturePath.trim(); if (TexturePath.trim()!="")
if (TexturePath!="")
{ {
TexturePath=stripPathFromString(file->getFileName(),true) + stripPathFromString(TexturePath,false); TexturePath=stripPathFromString(file->getFileName(),true) + stripPathFromString(TexturePath,false);
tmpBuffer->Material.setTexture(0, Driver->getTexture(TexturePath.c_str()) ); tmpBuffer->Material.setTexture(0, Driver->getTexture(TexturePath.c_str()) );
} }
core::stringc AlphamapPath=(const c8*)material->Alphamap; core::stringc AlphamapPath=(const c8*)material->Alphamap;
AlphamapPath.trim(); if (AlphamapPath.trim()!="")
if (AlphamapPath!="")
{ {
AlphamapPath=stripPathFromString(file->getFileName(),true) + stripPathFromString(AlphamapPath,false); AlphamapPath=stripPathFromString(file->getFileName(),true) + stripPathFromString(AlphamapPath,false);
tmpBuffer->Material.setTexture(2, Driver->getTexture(AlphamapPath.c_str()) ); tmpBuffer->Material.setTexture(2, Driver->getTexture(AlphamapPath.c_str()) );
......
...@@ -68,24 +68,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -68,24 +68,8 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
u32 smoothingGroup=0; u32 smoothingGroup=0;
core::map<video::S3DVertex, int> vertMap; core::map<video::S3DVertex, int> vertMap;
// ******************************************************************** const core::stringc fullName = file->getFileName();
// Patch to locate the file in the same folder as the .obj. const core::stringc relPath = FileSystem->getFileDir(fullName)+"/";
// If you load the file as "data/some.obj" and mtllib contains
// "mtlname test.mtl" (as usual), the loading will fail. Instead it
// must look for data/test.mtl. This patch does exactly that.
//
// patch by mandrav@codeblocks.org
// ********************************************************************
core::stringc obj_fullname = file->getFileName();
core::stringc obj_relpath = "";
s32 pathend = obj_fullname.findLast('/');
if (pathend == -1)
pathend = obj_fullname.findLast('\\');
if (pathend != -1)
obj_relpath = obj_fullname.subString(0, pathend + 1);
// ********************************************************************
// end of mtl folder patch
// ********************************************************************
c8* buf = new c8[filesize]; c8* buf = new c8[filesize];
memset(buf, 0, filesize); memset(buf, 0, filesize);
...@@ -104,7 +88,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file) ...@@ -104,7 +88,7 @@ IAnimatedMesh* COBJMeshFileLoader::createMesh(io::IReadFile* file)
{ {
c8 name[WORD_BUFFER_LENGTH]; c8 name[WORD_BUFFER_LENGTH];
bufPtr = goAndCopyNextWord(name, bufPtr, WORD_BUFFER_LENGTH, bufEnd); bufPtr = goAndCopyNextWord(name, bufPtr, WORD_BUFFER_LENGTH, bufEnd);
readMTL(name, obj_relpath); readMTL(name, relPath);
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment