Fix texture path handling.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1510 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2008-08-21 08:07:35 +00:00
parent d9c0ceb6ea
commit 9e354df022
3 changed files with 46 additions and 57 deletions

View File

@ -32,8 +32,8 @@ namespace scene
{
/** Constructor*/
CDMFLoader::CDMFLoader(ISceneManager* smgr)
: SceneMgr(smgr)
CDMFLoader::CDMFLoader(ISceneManager* smgr, io::IFileSystem* filesys)
: SceneMgr(smgr), FileSystem(filesys)
{
#ifdef _DEBUG
IReferenceCounted::setDebugName("CDMFLoader");
@ -88,7 +88,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
if (dmfRawFile.size()==0)
return 0;
SMesh * Mesh = new SMesh();
SMesh * mesh = new SMesh();
u32 i;
@ -122,7 +122,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
buffer->Material.MaterialType = video::EMT_LIGHTMAP_LIGHTING;
buffer->Material.Wireframe = false;
buffer->Material.Lighting = true;
Mesh->addMeshBuffer(buffer);
mesh->addMeshBuffer(buffer);
buffer->drop();
}
@ -137,7 +137,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
GetFaceNormal(verts[faces[i].firstVert].pos,
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);
u32 base = meshBuffer->Vertices.size();
@ -191,36 +191,24 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//a particular material in your scene it will be loaded and then destroyed.
for (i=0; i<header.numMaterials; i++)
{
String path = "";
if ( !SceneMgr->getParameters()->existsAttribute(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("/");
}
core::stringc path;
if ( SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) )
path = SceneMgr->getParameters()->getAttributeAsString(DMF_TEXTURE_PATH);
else
path = path +
String( SceneMgr->getParameters()->getAttributeAsString(DMF_TEXTURE_PATH)) + String("/");
path = FileSystem->getFileDir(file->getFileName());
path += ('/');
//texture and lightmap
ITexture *tex = 0;
ITexture *lig = 0;
//current buffer to apply material
SMeshBufferLightMap* buffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer(i);
SMeshBufferLightMap* buffer = (SMeshBufferLightMap*)mesh->getMeshBuffer(i);
//Primary texture is normal
if ((materiali[i].textureFlag==0) || (materiali[i].textureBlend==4))
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
if(materiali[i].textureFlag==1)
@ -263,7 +251,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//Lightmap is present
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
{
lig = 0;
@ -383,15 +371,15 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
// delete all buffers without geometry in it.
i = 0;
while(i < Mesh->MeshBuffers.size())
while(i < mesh->MeshBuffers.size())
{
if (Mesh->MeshBuffers[i]->getVertexCount() == 0 ||
Mesh->MeshBuffers[i]->getIndexCount() == 0 ||
Mesh->MeshBuffers[i]->getMaterial().getTexture(0) == 0)
if (mesh->MeshBuffers[i]->getVertexCount() == 0 ||
mesh->MeshBuffers[i]->getIndexCount() == 0 ||
mesh->MeshBuffers[i]->getMaterial().getTexture(0) == 0)
{
// Meshbuffer is empty -- drop it
Mesh->MeshBuffers[i]->drop();
Mesh->MeshBuffers.erase(i);
mesh->MeshBuffers[i]->drop();
mesh->MeshBuffers.erase(i);
}
else
{
@ -400,18 +388,18 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
}
// 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
SAnimatedMesh* AMesh = new SAnimatedMesh();
AMesh->Type = EAMT_UNKNOWN;
AMesh->addMesh(Mesh);
AMesh->addMesh(mesh);
AMesh->recalculateBoundingBox();
Mesh->drop();
mesh->drop();
return AMesh;
}

View File

@ -32,6 +32,7 @@
#include "IMeshLoader.h"
#include "IReadFile.h"
#include "IFileSystem.h"
#include "SMesh.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
@ -47,41 +48,41 @@ namespace scene
public:
/** constructor*/
CDMFLoader(ISceneManager* smgr);
CDMFLoader(ISceneManager* smgr, io::IFileSystem* filesys);
//! returns true if the file maybe is able to be loaded by this class
//! based on the file extension (e.g. ".cob")
virtual bool isALoadableFileExtension(const c8* fileName) const;
/** creates/loads an animated mesh from the file.
\return Pointer to the created mesh. Returns 0 if loading failed.
If you no longer need the mesh, you should call IAnimatedMesh::drop().
See IReferenceCounted::drop() for more information.*/
\return Pointer to the created mesh. Returns 0 if loading failed.
If you no longer need the mesh, you should call IAnimatedMesh::drop().
See IReferenceCounted::drop() for more information.*/
virtual IAnimatedMesh* createMesh(io::IReadFile* file);
/** loads dynamic lights present in this scene.
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.
\return number of lights loaded or 0 if loading failed.*/
int loadLights(const c8 * filename, ISceneManager* smgr,
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.
\return number of lights loaded or 0 if loading failed.*/
int loadLights(const c8 * filename, ISceneManager* smgr,
ISceneNode* parent = 0, s32 base_id = 1000);
/** 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).
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.*/
int loadWaterPlains ( const c8 *filename,
ISceneManager* smgr,
ISceneNode * parent = 0,
s32 base_id = 2000,
bool mode = true);
/** 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).
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.*/
int loadWaterPlains ( const c8 *filename,
ISceneManager* smgr,
ISceneNode * parent = 0,
s32 base_id = 2000,
bool mode = true);
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;
io::IFileSystem* FileSystem;
};
} // end namespace scene

View File

@ -223,7 +223,7 @@ CSceneManager::CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
MeshLoaderList.push_back(new CColladaFileLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_DMF_LOADER_
MeshLoaderList.push_back(new CDMFLoader(this));
MeshLoaderList.push_back(new CDMFLoader(this, FileSystem));
#endif
#ifdef _IRR_COMPILE_WITH_OGRE_LOADER_
MeshLoaderList.push_back(new COgreMeshFileLoader(FileSystem, Driver));