Commit 701bf011 authored by hybrid's avatar hybrid

Fixed Deled texture search. The scene parameter DMF_USE_MATERIALS_DIR was...

Fixed Deled texture search. The scene parameter DMF_USE_MATERIALS_DIR was renamed to DMF_IGNORE_MATERIALS_DIR with opposite meaning, because the default should be to use the directory defined in the file.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2487 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ff8cb9f6
......@@ -67,7 +67,9 @@ namespace scene
const c8* const COLLADA_CREATE_SCENE_INSTANCES = "COLLADA_CreateSceneInstances";
//! Name of the parameter for changing the texture path of the built-in DMF loader.
/** Use it like this:
/** This path is prefixed to the file names defined in the Deled file when loading
textures. This allows to alter the paths for a specific project setting.
Use it like this:
\code
SceneManager->getStringParameters()->setAttribute(scene::DMF_TEXTURE_PATH, "path/to/your/textures");
\endcode
......@@ -75,17 +77,20 @@ namespace scene
const c8* const DMF_TEXTURE_PATH = "DMF_TexturePath";
//! Name of the parameter for preserving DMF textures dir structure with built-in DMF loader.
/** Use it like this:
/** If this parameter is set to true, the texture directory defined in the Deled file
is ignored, and only the texture name is used to find the proper file. Otherwise, the
texture path is also used, which allows to use a nicer media layout.
Use it like this:
\code
//this way you won't use this setting
SceneManager->getParameters()->setAttribute(scene::DMF_USE_MATERIALS_DIRS, false);
//this way you won't use this setting (default)
SceneManager->getParameters()->setAttribute(scene::DMF_IGNORE_MATERIALS_DIRS, false);
\endcode
\code
//this way you'll use this setting
SceneManager->getParameters()->setAttribute(scene::DMF_USE_MATERIALS_DIRS, true);
SceneManager->getParameters()->setAttribute(scene::DMF_IGNORE_MATERIALS_DIRS, true);
\endcode
**/
const c8* const DMF_USE_MATERIALS_DIRS = "DMF_MaterialsDir";
const c8* const DMF_IGNORE_MATERIALS_DIRS = "DMF_IgnoreMaterialsDir";
//! Name of the parameter for setting reference value of alpha in transparent materials.
/** Use it like this:
......
......@@ -80,12 +80,10 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
dmfFace *faces=new dmfFace[header.numFaces];
//let's get the materials
const bool use_mat_dirs=SceneMgr->getParameters()->getAttributeAsBool(DMF_USE_MATERIALS_DIRS);
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Loading materials", core::stringc(header.numMaterials).c_str());
#endif
GetDMFMaterials(dmfRawFile, materiali, header.numMaterials, use_mat_dirs);
GetDMFMaterials(dmfRawFile, materiali, header.numMaterials);
//let's get vertices and faces
#ifdef _IRR_DMF_DEBUG_
......@@ -115,7 +113,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
for (i = 0; i < header.numFaces; i++)
{
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Polygon with #vertices", core::stringc(faces[i].numVerts).c_str());
// os::Printer::log("Polygon with #vertices", core::stringc(faces[i].numVerts).c_str());
#endif
if (faces[i].numVerts < 3)
continue;
......@@ -174,15 +172,17 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Loading textures.");
#endif
const bool use_mat_dirs=!SceneMgr->getParameters()->getAttributeAsBool(DMF_IGNORE_MATERIALS_DIRS);
core::stringc path;
if ( SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) )
path = SceneMgr->getParameters()->getAttributeAsString(DMF_TEXTURE_PATH);
else
path = FileSystem->getFileDir(file->getFileName());
path += ('/');
for (i=0; i<header.numMaterials; i++)
{
core::stringc path;
if ( SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) )
path = SceneMgr->getParameters()->getAttributeAsString(DMF_TEXTURE_PATH);
else
path = FileSystem->getFileDir(file->getFileName());
path += ('/');
//texture and lightmap
video::ITexture *tex = 0;
video::ITexture *lig = 0;
......@@ -195,12 +195,28 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
{
if (materiali[i].textureBlend==4)
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT,true);
if (FileSystem->existFile(path+materiali[i].textureName))
// path + texpath + full name
if (use_mat_dirs && FileSystem->existFile(path+materiali[i].pathName+materiali[i].textureName))
tex = driver->getTexture((path+materiali[i].pathName+materiali[i].textureName));
// path + full name
else if (FileSystem->existFile(path+materiali[i].textureName))
tex = driver->getTexture((path+materiali[i].textureName));
// path + texpath + base name
else if (use_mat_dirs && FileSystem->existFile(path+materiali[i].pathName+FileSystem->getFileBasename(materiali[i].textureName)))
tex = driver->getTexture((path+materiali[i].pathName+FileSystem->getFileBasename(materiali[i].textureName)));
// path + base name
else if (FileSystem->existFile(path+FileSystem->getFileBasename(materiali[i].textureName)))
tex = driver->getTexture((path+FileSystem->getFileBasename(materiali[i].textureName)));
// texpath + full name
else if (use_mat_dirs && FileSystem->existFile(materiali[i].pathName+materiali[i].textureName))
tex = driver->getTexture(materiali[i].pathName+materiali[i].textureName.c_str());
// full name
else if (FileSystem->existFile(materiali[i].textureName))
tex = driver->getTexture(materiali[i].textureName.c_str());
// texpath + base name
else if (use_mat_dirs && FileSystem->existFile(materiali[i].pathName+FileSystem->getFileBasename(materiali[i].textureName)))
tex = driver->getTexture(materiali[i].pathName+FileSystem->getFileBasename(materiali[i].textureName));
// base name
else if (FileSystem->existFile(FileSystem->getFileBasename(materiali[i].textureName)))
tex = driver->getTexture(FileSystem->getFileBasename(materiali[i].textureName));
#ifdef _IRR_DMF_DEBUG_
......
......@@ -21,6 +21,7 @@
#define __DMF_SUPPORT_H_INCLUDED__
#include "irrString.h"
#include "fast_atof.h"
namespace irr
{
......@@ -55,12 +56,13 @@ struct dmfMaterial
u32 textureFlag;//!<First texture Flag (0=Normal, 1=Color).
u32 lightmapFlag;//!<Lightmap Flag (0=Normal, others not considered).
u32 textureBlend;//!<Texture Blend mode used to support alpha maps (4=Alpha map, others not implemented yet).
core::stringc pathName;//!<Name of path defined in path element.
core::stringc textureName;//!<Name of first texture (only file name, no path).
core::stringc lightmapName;//!<Name of lightmap (only file name, no path).
};
/** A structure rapresenting a single face.
/** A structure representing a single face.
This structure contains first vertice index, number of vertices and the material used.*/
struct dmfFace
{
......@@ -340,49 +342,49 @@ You must give in input a StringList representing a DMF file loaded with LoadFrom
\return true if function succeed or false on fail.*/
bool GetDMFMaterials(const StringList& RawFile,
core::array<dmfMaterial>& materials,
int num_material,
bool use_material_dirs=false)
int num_material)
{
int offs=4;
// offset for already handled lines
const int offs=4;
StringList temp;
StringList temp1;
StringList temp2;
// The number of materials is predetermined
materials.reallocate(num_material);
for(int i=0; i<num_material; ++i)
{
materials.push_back(dmfMaterial());
// get all tokens
temp=SubdivideString(RawFile[offs+i],";");
// should be equal to first token
materials[i].materialID = i;
materials[i].textureLayers = atoi(temp[3].c_str());
// The path used for the texture
materials[i].pathName = temp[2];
materials[i].pathName.replace('\\','/');
materials[i].pathName += "/";
// can be negative! Maybe the wrong field?
materials[i].textureLayers = core::strtol10(temp[3].c_str());
// Three values are separated by commas
temp1=SubdivideString(temp[5],",");
materials[i].textureFlag = atoi(temp1[0].c_str());
materials[i].textureName=temp1[1];
materials[i].textureName.replace('\\','/');
materials[i].textureBlend = atoi(temp1[2].c_str());
temp1.clear();
temp2.clear();
int a=temp.size();
if(a>=9)
{
temp1=SubdivideString(temp[temp.size() - 1],",");
materials[i].lightmapFlag=atoi(temp1[0].c_str());
if(!use_material_dirs)
{
temp2=SubdivideString(temp1[1],"\\");
materials[i].lightmapName=temp2.getLast();
}
else
materials[i].lightmapName=temp1[1];
materials[i].lightmapName=temp1[1];
materials[i].lightmapName.replace('\\','/');
}
else
{
materials[i].lightmapFlag=1;
materials[i].lightmapName="";
}
temp1.clear();
temp2.clear();
}
return true;
}
......
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