Commit 9e354df0 authored by hybrid's avatar hybrid

Fix texture path handling.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1510 dfc29bdd-3216-0410-991c-e03cc46cb475
parent d9c0ceb6
...@@ -32,8 +32,8 @@ namespace scene ...@@ -32,8 +32,8 @@ namespace scene
{ {
/** Constructor*/ /** Constructor*/
CDMFLoader::CDMFLoader(ISceneManager* smgr) CDMFLoader::CDMFLoader(ISceneManager* smgr, io::IFileSystem* filesys)
: SceneMgr(smgr) : SceneMgr(smgr), FileSystem(filesys)
{ {
#ifdef _DEBUG #ifdef _DEBUG
IReferenceCounted::setDebugName("CDMFLoader"); IReferenceCounted::setDebugName("CDMFLoader");
...@@ -88,7 +88,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -88,7 +88,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
if (dmfRawFile.size()==0) if (dmfRawFile.size()==0)
return 0; return 0;
SMesh * Mesh = new SMesh(); SMesh * mesh = new SMesh();
u32 i; u32 i;
...@@ -122,7 +122,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -122,7 +122,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
buffer->Material.MaterialType = video::EMT_LIGHTMAP_LIGHTING; buffer->Material.MaterialType = video::EMT_LIGHTMAP_LIGHTING;
buffer->Material.Wireframe = false; buffer->Material.Wireframe = false;
buffer->Material.Lighting = true; buffer->Material.Lighting = true;
Mesh->addMeshBuffer(buffer); mesh->addMeshBuffer(buffer);
buffer->drop(); buffer->drop();
} }
...@@ -137,7 +137,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -137,7 +137,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
GetFaceNormal(verts[faces[i].firstVert].pos, GetFaceNormal(verts[faces[i].firstVert].pos,
verts[faces[i].firstVert+1].pos, verts[faces[i].firstVert+2].pos, normal); verts[faces[i].firstVert+1].pos, verts[faces[i].firstVert+2].pos, normal);
SMeshBufferLightMap * meshBuffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer( SMeshBufferLightMap * meshBuffer = (SMeshBufferLightMap*)mesh->getMeshBuffer(
faces[i].materialID); faces[i].materialID);
u32 base = meshBuffer->Vertices.size(); u32 base = meshBuffer->Vertices.size();
...@@ -191,36 +191,24 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -191,36 +191,24 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//a particular material in your scene it will be loaded and then destroyed. //a particular material in your scene it will be loaded and then destroyed.
for (i=0; i<header.numMaterials; i++) for (i=0; i<header.numMaterials; i++)
{ {
String path = ""; core::stringc path;
if ( !SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) ) if ( SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) )
{ path = SceneMgr->getParameters()->getAttributeAsString(DMF_TEXTURE_PATH);
//get the right path for textures
StringList filepath = SubdivideString(String(file->getFileName()),"\\");
StringList filepath1 = SubdivideString(String(file->getFileName()),"/");
if(filepath1.size()>filepath.size())
{
filepath.clear();
filepath=filepath1;
}
for (u32 j=0; j<filepath.size()-1; ++j)
path = path + filepath[j] + String("/");
}
else else
path = path + path = FileSystem->getFileDir(file->getFileName());
String( SceneMgr->getParameters()->getAttributeAsString(DMF_TEXTURE_PATH)) + String("/"); path += ('/');
//texture and lightmap //texture and lightmap
ITexture *tex = 0; ITexture *tex = 0;
ITexture *lig = 0; ITexture *lig = 0;
//current buffer to apply material //current buffer to apply material
SMeshBufferLightMap* buffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer(i); SMeshBufferLightMap* buffer = (SMeshBufferLightMap*)mesh->getMeshBuffer(i);
//Primary texture is normal //Primary texture is normal
if ((materiali[i].textureFlag==0) || (materiali[i].textureBlend==4)) if ((materiali[i].textureFlag==0) || (materiali[i].textureBlend==4))
driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT,true); driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT,true);
tex = driver->getTexture((path+String(materiali[i].textureName)).c_str()); tex = driver->getTexture((path+materiali[i].textureName).c_str());
//Primary texture is just a colour //Primary texture is just a colour
if(materiali[i].textureFlag==1) if(materiali[i].textureFlag==1)
...@@ -263,7 +251,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -263,7 +251,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//Lightmap is present //Lightmap is present
if (materiali[i].lightmapFlag == 0) if (materiali[i].lightmapFlag == 0)
lig = driver->getTexture((path+String(materiali[i].lightmapName)).c_str()); lig = driver->getTexture((path+materiali[i].lightmapName).c_str());
else //no lightmap else //no lightmap
{ {
lig = 0; lig = 0;
...@@ -383,15 +371,15 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -383,15 +371,15 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
// delete all buffers without geometry in it. // delete all buffers without geometry in it.
i = 0; i = 0;
while(i < Mesh->MeshBuffers.size()) while(i < mesh->MeshBuffers.size())
{ {
if (Mesh->MeshBuffers[i]->getVertexCount() == 0 || if (mesh->MeshBuffers[i]->getVertexCount() == 0 ||
Mesh->MeshBuffers[i]->getIndexCount() == 0 || mesh->MeshBuffers[i]->getIndexCount() == 0 ||
Mesh->MeshBuffers[i]->getMaterial().getTexture(0) == 0) mesh->MeshBuffers[i]->getMaterial().getTexture(0) == 0)
{ {
// Meshbuffer is empty -- drop it // Meshbuffer is empty -- drop it
Mesh->MeshBuffers[i]->drop(); mesh->MeshBuffers[i]->drop();
Mesh->MeshBuffers.erase(i); mesh->MeshBuffers.erase(i);
} }
else else
{ {
...@@ -400,18 +388,18 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file) ...@@ -400,18 +388,18 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
} }
// create bounding box // create bounding box
for (i = 0; i < Mesh->MeshBuffers.size(); i++) for (i = 0; i < mesh->MeshBuffers.size(); ++i)
{ {
((SMeshBufferLightMap*)Mesh->MeshBuffers[i])->recalculateBoundingBox(); mesh->MeshBuffers[i]->recalculateBoundingBox();
} }
Mesh->recalculateBoundingBox(); mesh->recalculateBoundingBox();
// Set up an animated mesh to hold the mesh // Set up an animated mesh to hold the mesh
SAnimatedMesh* AMesh = new SAnimatedMesh(); SAnimatedMesh* AMesh = new SAnimatedMesh();
AMesh->Type = EAMT_UNKNOWN; AMesh->Type = EAMT_UNKNOWN;
AMesh->addMesh(Mesh); AMesh->addMesh(mesh);
AMesh->recalculateBoundingBox(); AMesh->recalculateBoundingBox();
Mesh->drop(); mesh->drop();
return AMesh; return AMesh;
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "IMeshLoader.h" #include "IMeshLoader.h"
#include "IReadFile.h" #include "IReadFile.h"
#include "IFileSystem.h"
#include "SMesh.h" #include "SMesh.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "ISceneManager.h" #include "ISceneManager.h"
...@@ -47,41 +48,41 @@ namespace scene ...@@ -47,41 +48,41 @@ namespace scene
public: public:
/** constructor*/ /** constructor*/
CDMFLoader(ISceneManager* smgr); CDMFLoader(ISceneManager* smgr, io::IFileSystem* filesys);
//! returns true if the file maybe is able to be loaded by this class //! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".cob") //! based on the file extension (e.g. ".cob")
virtual bool isALoadableFileExtension(const c8* fileName) const; virtual bool isALoadableFileExtension(const c8* fileName) const;
/** creates/loads an animated mesh from the file. /** creates/loads an animated mesh from the file.
\return Pointer to the created mesh. Returns 0 if loading failed. \return Pointer to the created mesh. Returns 0 if loading failed.
If you no longer need the mesh, you should call IAnimatedMesh::drop(). If you no longer need the mesh, you should call IAnimatedMesh::drop().
See IReferenceCounted::drop() for more information.*/ See IReferenceCounted::drop() for more information.*/
virtual IAnimatedMesh* createMesh(io::IReadFile* file); virtual IAnimatedMesh* createMesh(io::IReadFile* file);
/** loads dynamic lights present in this scene. /** loads dynamic lights present in this scene.
Note that loaded lights from DeleD must have the suffix \b dynamic_ and must be \b pointlight. Note that loaded lights from DeleD must have the suffix \b dynamic_ and must be \b pointlight.
Irrlicht correctly loads specular color, diffuse color , position and distance of object affected by light. Irrlicht correctly loads specular color, diffuse color , position and distance of object affected by light.
\return number of lights loaded or 0 if loading failed.*/ \return number of lights loaded or 0 if loading failed.*/
int loadLights(const c8 * filename, ISceneManager* smgr, int loadLights(const c8 * filename, ISceneManager* smgr,
ISceneNode* parent = 0, s32 base_id = 1000); ISceneNode* parent = 0, s32 base_id = 1000);
/** loads water plains present in this scene. /** loads water plains present in this scene.
Note that loaded water plains from DeleD must have the suffix \b water_ and must be \b rectangle (with just 1 rectangular face). Note that loaded water plains from DeleD must have the suffix \b water_ and must be \b rectangle (with just 1 rectangular face).
Irrlicht correctly loads position and rotation of water plain as well as texture layers. Irrlicht correctly loads position and rotation of water plain as well as texture layers.
\return number of water plains loaded or 0 if loading failed.*/ \return number of water plains loaded or 0 if loading failed.*/
int loadWaterPlains ( const c8 *filename, int loadWaterPlains ( const c8 *filename,
ISceneManager* smgr, ISceneManager* smgr,
ISceneNode * parent = 0, ISceneNode * parent = 0,
s32 base_id = 2000, s32 base_id = 2000,
bool mode = true); bool mode = true);
private: private:
void GetFaceNormal(f32 a[3], f32 b[3], f32 c[3], f32 out[3]); void GetFaceNormal(f32 a[3], f32 b[3], f32 c[3], f32 out[3]);
video::IVideoDriver* Driver;
ISceneManager* SceneMgr; ISceneManager* SceneMgr;
io::IFileSystem* FileSystem;
}; };
} // end namespace scene } // end namespace scene
......
...@@ -223,7 +223,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs, ...@@ -223,7 +223,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
MeshLoaderList.push_back(new CColladaFileLoader(this, FileSystem)); MeshLoaderList.push_back(new CColladaFileLoader(this, FileSystem));
#endif #endif
#ifdef _IRR_COMPILE_WITH_DMF_LOADER_ #ifdef _IRR_COMPILE_WITH_DMF_LOADER_
MeshLoaderList.push_back(new CDMFLoader(this)); MeshLoaderList.push_back(new CDMFLoader(this, FileSystem));
#endif #endif
#ifdef _IRR_COMPILE_WITH_OGRE_LOADER_ #ifdef _IRR_COMPILE_WITH_OGRE_LOADER_
MeshLoaderList.push_back(new COgreMeshFileLoader(FileSystem, Driver)); MeshLoaderList.push_back(new COgreMeshFileLoader(FileSystem, Driver));
......
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