Commit be924b27 authored by hybrid's avatar hybrid

Fixed core dumps and loading errors. Some speedup and simplifications.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1629 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f180825e
......@@ -16,6 +16,11 @@
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_DMF_LOADER_
#ifdef _DEBUG
#define _IRR_DMF_DEBUG_
#include "os.h"
#endif
#include "CDMFLoader.h"
#include "ISceneManager.h"
#include "IAttributes.h"
......@@ -41,37 +46,6 @@ CDMFLoader::CDMFLoader(ISceneManager* smgr, io::IFileSystem* filesys)
}
/** Given first three points of a face, returns a face normal*/
void CDMFLoader::GetFaceNormal( f32 a[3], //First point
f32 b[3], //Second point
f32 c[3], //Third point
f32 out[3]) //Normal computed
{
f32 v1[3], v2[3];
v1[0] = a[0] - b[0];
v1[1] = a[1] - b[1];
v1[2] = a[2] - b[2];
v2[0] = b[0] - c[0];
v2[1] = b[1] - c[1];
v2[2] = b[2] - c[2];
out[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]);
out[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]);
out[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]);
f32 dist = (f32)sqrtf((out[0] * out[0]) + (out[1] * out[1]) + (out[2] * out[2]));
if (dist == 0.0f)
dist = 0.001f;
out[0] /= dist;
out[1] /= dist;
out[2] /= dist;
}
/**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().
......@@ -101,20 +75,28 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
SceneMgr->setAmbientLight(header.dmfAmbient);
//let's create the correct number of materials, vertices and faces
dmfMaterial *materiali=new dmfMaterial[header.numMaterials];
core::array<dmfMaterial> materiali;
dmfVert *verts=new dmfVert[header.numVertices];
dmfFace *faces=new dmfFace[header.numFaces];
//let's get the materials
bool use_mat_dirs=false;
use_mat_dirs=SceneMgr->getParameters()->getAttributeAsBool(DMF_USE_MATERIALS_DIRS);
const bool use_mat_dirs=SceneMgr->getParameters()->getAttributeAsBool(DMF_USE_MATERIALS_DIRS);
GetDMFMaterials(dmfRawFile , materiali,header.numMaterials,use_mat_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);
//let's get vertices and faces
GetDMFVerticesFaces(dmfRawFile, verts,faces);
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Loading geometry");
#endif
GetDMFVerticesFaces(dmfRawFile, verts, faces);
//create a meshbuffer for each material, then we'll remove empty ones
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Creating meshbuffers.");
#endif
for (i=0; i<header.numMaterials; i++)
{
//create a new SMeshBufferLightMap for each material
......@@ -127,38 +109,38 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
}
// Build the mesh buffers
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Adding geometry to mesh.");
#endif
for (i = 0; i < header.numFaces; i++)
{
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Polygon with #vertices", core::stringc(faces[i].numVerts).c_str());
#endif
if (faces[i].numVerts < 3)
continue;
f32 normal[3];
GetFaceNormal(verts[faces[i].firstVert].pos,
verts[faces[i].firstVert+1].pos, verts[faces[i].firstVert+2].pos, normal);
const core::vector3df normal =
core::triangle3df(verts[faces[i].firstVert].pos,
verts[faces[i].firstVert+1].pos,
verts[faces[i].firstVert+2].pos).getNormal().normalize();
SMeshBufferLightMap * meshBuffer = (SMeshBufferLightMap*)mesh->getMeshBuffer(
faces[i].materialID);
u32 base = meshBuffer->Vertices.size();
const u32 base = meshBuffer->Vertices.size();
// Add this face's verts
u32 v;
for (v = 0; v < faces[i].numVerts; v++)
{
dmfVert * vv = &verts[faces[i].firstVert + v];
video::S3DVertex2TCoords vert(vv->pos[0], vv->pos[1], vv->pos[2],
normal[0], normal[1], normal[2], video::SColor(0,255,255,255), 0.0f, 0.0f);
if ( materiali[faces[i].materialID].textureBlend==4 &&
SceneMgr->getParameters()->getAttributeAsBool(DMF_FLIP_ALPHA_TEXTURES))
const dmfVert& vv = verts[faces[i].firstVert + v];
video::S3DVertex2TCoords vert(vv.pos,
normal, video::SColor(255,255,255,255), vv.tc, vv.lc);
if (materiali[faces[i].materialID].textureBlend==4 &&
SceneMgr->getParameters()->getAttributeAsBool(DMF_FLIP_ALPHA_TEXTURES))
{
vert.TCoords.set(vv->tc[0],-vv->tc[1]);
vert.TCoords2.set(vv->lc[0],vv->lc[1]);
}
else
{
vert.TCoords.set(vv->tc[0], vv->tc[1]);
vert.TCoords2.set(vv->lc[0], vv->lc[1]);
vert.TCoords.set(vv.tc.X,-vv.tc.Y);
}
meshBuffer->Vertices.push_back(vert);
}
......@@ -166,22 +148,22 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
// Now add the indices
// This weird loop turns convex polygons into triangle strips.
// I do it this way instead of a simple fan because it usually
// looks a lot better in wireframe, for example.
// looks a lot better in wireframe, for example.
u32 h = faces[i].numVerts - 1, l = 0, c; // High, Low, Center
for (v = 0; v < faces[i].numVerts - 2; v++)
{
if (v & 1)
if (v & 1) // odd
c = h - 1;
else
else // even
c = l + 1;
meshBuffer->Indices.push_back(base + h);
meshBuffer->Indices.push_back(base + l);
meshBuffer->Indices.push_back(base + c);
if (v & 1)
if (v & 1) // odd
h--;
else
else // even
l++;
}
}
......@@ -189,6 +171,9 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//load textures and lightmaps in materials.
//don't worry if you receive a could not load texture, cause if you don't need
//a particular material in your scene it will be loaded and then destroyed.
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Loading textures.");
#endif
for (i=0; i<header.numMaterials; i++)
{
core::stringc path;
......@@ -207,27 +192,14 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//Primary texture is normal
if ((materiali[i].textureFlag==0) || (materiali[i].textureBlend==4))
{
driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT,true);
tex = driver->getTexture((path+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)
else if(materiali[i].textureFlag==1)
{
String colour(materiali[i].textureName);
String alpha,red,green,blue;
alpha.append((char*)&colour[0]);
alpha.append((char*)&colour[1]);
blue.append((char*)&colour[2]);
blue.append((char*)&colour[3]);
green.append((char*)&colour[4]);
green.append((char*)&colour[5]);
red.append((char*)&colour[6]);
red.append((char*)&colour[7]);
SColor color(axtoi(alpha.c_str()),
axtoi(red.c_str()),axtoi(green.c_str()),
axtoi(blue.c_str()));
SColor color(axtoi(materiali[i].textureName.c_str()));
//just for compatibility with older Irrlicht versions
//to support transparent materials
......@@ -246,7 +218,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
buffer->Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
buffer->Material.MaterialTypeParam =(((f32) (color.getAlpha()-1))/255.0f);
}
immagine->drop();
}
//Lightmap is present
......@@ -260,28 +231,21 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
buffer->Material.AmbientColor=header.dmfAmbient.getInterpolated(SColor(255,0,0,0),mult/100.f);
}
if(materiali[i].textureBlend==4)
if (materiali[i].textureBlend==4)
{
buffer->Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
buffer->Material.MaterialTypeParam =SceneMgr->getParameters()->getAttributeAsFloat(DMF_ALPHA_CHANNEL_REF);
buffer->Material.MaterialTypeParam =
SceneMgr->getParameters()->getAttributeAsFloat(DMF_ALPHA_CHANNEL_REF);
}
core::dimension2d<s32> texsize;
core::dimension2d<s32> ligsize;
if (tex && header.dmfVersion<1.1)
texsize=tex->getSize();
if (lig && header.dmfVersion<1.1)
ligsize=lig->getSize();
//if texture is present mirror vertically owing to DeleD rapresentation
//if texture is present mirror vertically owing to DeleD representation
if (tex && header.dmfVersion<1.1)
{
const core::dimension2d<s32> texsize = tex->getSize();
void* pp = tex->lock();
if (pp)
{
video::ECOLOR_FORMAT format = tex->getColorFormat();
const video::ECOLOR_FORMAT format = tex->getColorFormat();
if (format == video::ECF_A1R5G5B5)
{
s16* p = (s16*)pp;
......@@ -308,10 +272,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
}
}
}
}
if(tex && header.dmfVersion<1.1)
{
tex->unlock();
tex->regenerateMipMapLevels();
}
......@@ -319,6 +279,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//if lightmap is present mirror vertically owing to DeleD rapresentation
if (lig && header.dmfVersion<1.1)
{
const core::dimension2d<s32> ligsize=lig->getSize();
void* pp = lig->lock();
if (pp)
{
......@@ -352,10 +313,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
}
}
}
}
if (lig && header.dmfVersion<1.1)
{
lig->unlock();
lig->regenerateMipMapLevels();
}
......@@ -366,16 +323,17 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
delete verts;
delete faces;
delete materiali;
}
// delete all buffers without geometry in it.
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Cleaning meshbuffers.");
#endif
i = 0;
while(i < mesh->MeshBuffers.size())
{
if (mesh->MeshBuffers[i]->getVertexCount() == 0 ||
mesh->MeshBuffers[i]->getIndexCount() == 0 ||
mesh->MeshBuffers[i]->getMaterial().getTexture(0) == 0)
mesh->MeshBuffers[i]->getIndexCount() == 0)
{
// Meshbuffer is empty -- drop it
mesh->MeshBuffers[i]->drop();
......
......@@ -71,16 +71,13 @@ namespace 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,
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]);
ISceneManager* SceneMgr;
io::IFileSystem* FileSystem;
};
......
......@@ -31,7 +31,7 @@ struct dmfHeader
{
//main file header
f32 dmfVersion; //!<File version
char dmfName[128]; //!<Scene name
core::stringc dmfName; //!<Scene name
SColor dmfAmbient; //!<Ambient color
f32 dmfShadow; //!<Shadow intensity
u32 numObjects; //!<Number of objects in this scene
......@@ -44,16 +44,17 @@ struct dmfHeader
};
/** A structure rapresenting a DeleD material.
/** A structure representing a DeleD material.
This structure contains texture names, an ID and some flags.*/
struct dmfMaterial
{
u32 materialID;//!<This material unique ID.
u32 textureLayers;//!<First texture Flag (0=Normal, 1=Color).
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).
char textureName[64];//!<Name of first texture (only file name, no path).
char lightmapName[64];//!<Name of lightmap (only file name, no path).
core::stringc textureName;//!<Name of first texture (only file name, no path).
core::stringc lightmapName;//!<Name of lightmap (only file name, no path).
};
......@@ -71,13 +72,13 @@ struct dmfFace
This structure contains vertice position coordinates and texture an lightmap UV.*/
struct dmfVert
{
f32 tc[2];//!<Texture UV coords.
f32 lc[2];//!<Lightmap UV coords.
f32 pos[3];//!<Position of vertice x,y,z
core::vector3df pos;//!<Position of vertice x,y,z
core::vector2df tc;//!<Texture UV coords.
core::vector2df lc;//!<Lightmap UV coords.
};
/** A structure rapresenting a single dynamic light.
/** A structure representing a single dynamic light.
This structure contains light position coordinates, diffuse colour, specular colour and maximum radius of light.*/
struct dmfLight
{
......@@ -191,7 +192,7 @@ public:
//This function subdivides a string in a list of strings
/** This function subdivides strings divided by divider in a list of strings.
\return A StringList made of all strings divided by divider.*/
StringList SubdivideString(String str, String divider)
StringList SubdivideString(const String& str, const String& divider)
{
StringList strings; //returned StringList
strings.clear(); //clear returned stringlist
......@@ -227,7 +228,7 @@ StringList SubdivideString(String str, String divider)
/**This function extract a dmfHeader from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile.
\return true if function succeed or false on fail.*/
bool GetDMFHeader (StringList RawFile, dmfHeader & header)
bool GetDMFHeader(const StringList& RawFile, dmfHeader& header)
{
StringList temp=SubdivideString(RawFile[0],String(";")); //file info
......@@ -238,27 +239,16 @@ bool GetDMFHeader (StringList RawFile, dmfHeader & header)
temp = SubdivideString(RawFile[1],String(" "));//get version
StringList temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
header.dmfVersion = (float)atof(temp1[0].c_str());//save version
if (header.dmfVersion < 0.91)
return false;//not correct version
header.dmfVersion = (float)atof(temp1[0].c_str());//save version
temp.clear();
temp = SubdivideString(RawFile[2],String(";"));//get name,ambient color and shadow opacity
sprintf(header.dmfName,"%s",temp[0].c_str());//save name
String red=String(""), green=String(""), blue=String("");
//get color value in hex
blue.append((char*)&temp[1][2]);
blue.append((char*)&temp[1][3]);
green.append((char*)&temp[1][4]);
green.append((char*)&temp[1][5]);
red.append((char*)&temp[1][6]);
red.append((char*)&temp[1][7]);
header.dmfName=temp[0];//save name
//set ambient color
header.dmfAmbient.set(0, axtoi(red.c_str()),
axtoi(green.c_str()), axtoi(blue.c_str()));
header.dmfAmbient.set(axtoi(temp[1].c_str()));
//set Shadow intensity
header.dmfShadow = (float)atof(temp[2].c_str());
......@@ -339,52 +329,41 @@ bool GetDMFHeader (StringList RawFile, dmfHeader & header)
}
/**This function extract an array of dmfMaterial from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile.
\param RawFile StringList representing a DMF file.
\param materials Materials returned.
\param num_material Number of materials contained in DMF file.
\param use_material_dirs Here you can choose to use default DeleD structure for material dirs.
\return true if function succeed or false on fail.*/
bool GetDMFMaterials(StringList RawFile /**<StringList representing a DMF file.*/,
dmfMaterial materials[]/**<Materials returned.*/,
int num_material/**<Number of materials contained in DMF file.*/,
bool use_material_dirs=false/**<Here you can choose to use default DeleD structure for material dirs.*/)
bool GetDMFMaterials(const StringList& RawFile,
core::array<dmfMaterial>& materials,
int num_material,
bool use_material_dirs=false)
{
int offs=4;
StringList temp;
StringList temp1;
StringList temp2;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
//end checking
temp.clear();
temp1.clear();
for(int i=0;i<num_material; ++i)
materials.reallocate(num_material);
for(int i=0; i<num_material; ++i)
{
materials.push_back(dmfMaterial());
temp=SubdivideString(RawFile[offs+i],";");
materials[i].materialID = i;
materials[i].textureLayers = atoi(temp[3].c_str());
temp1=SubdivideString(temp[5],",");
materials[i].textureFlag = atoi(temp1[0].c_str());
if(!use_material_dirs)
if(!use_material_dirs && !materials[i].textureFlag)
{
temp2=SubdivideString(temp1[1],"\\");
sprintf(materials[i].textureName, "%s", temp2[temp2.size()-1].c_str());
materials[i].textureName=temp2.getLast();
}
else
sprintf(materials[i].textureName, "%s", temp1[1].c_str());
materials[i].textureName=temp1[1];
materials[i].textureBlend = atoi(temp1[2].c_str());
temp1.clear();
temp2.clear();
......@@ -396,15 +375,15 @@ bool GetDMFMaterials(StringList RawFile /**<StringList representing a DMF file.*
if(!use_material_dirs)
{
temp2=SubdivideString(temp1[1],"\\");
sprintf(materials[i].lightmapName,"%s",temp2[temp2.size() - 1].c_str());
materials[i].lightmapName=temp2.getLast();
}
else
sprintf(materials[i].lightmapName,"%s",temp1[1].c_str());
materials[i].lightmapName=temp1[1];
}
else
{
materials[i].lightmapFlag=1;
materials[i].lightmapName[0]=0;
materials[i].lightmapName="";
}
temp1.clear();
temp2.clear();
......@@ -416,8 +395,8 @@ bool GetDMFMaterials(StringList RawFile /**<StringList representing a DMF file.*
/**This function extract an array of dmfMaterial from a DMF file considering 1st an 2nd layer for water plains.
You must give in input a StringList representing a DMF file loaded with LoadFromFile.
\return true if function succeed or false on fail.*/
bool GetDMFWaterMaterials(StringList RawFile /**<StringList representing a DMF file.*/,
dmfMaterial materials[]/**<Materials returned.*/,
bool GetDMFWaterMaterials(const StringList& RawFile /**<StringList representing a DMF file.*/,
core::array<dmfMaterial>& materials/**<Materials returned.*/,
int num_material/**<Number of materials contained in DMF file.*/
)
{
......@@ -451,7 +430,7 @@ bool GetDMFWaterMaterials(StringList RawFile /**<StringList representing a DMF f
materials[i].textureFlag=atoi(temp1[0].c_str());
temp2 = SubdivideString(temp1[1],"\\");
sprintf(materials[i].textureName,"%s",temp2[temp2.size()-1].c_str());
materials[i].textureName=temp2.getLast();
temp1.clear();
temp2.clear();
int a=temp.size();
......@@ -460,12 +439,12 @@ bool GetDMFWaterMaterials(StringList RawFile /**<StringList representing a DMF f
temp1=SubdivideString(temp[6],",");
materials[i].lightmapFlag=atoi(temp1[0].c_str());
temp2=SubdivideString(temp1[1],"\\");
sprintf(materials[i].lightmapName,"%s",temp2[temp2.size() - 1].c_str());
materials[i].lightmapName=temp2.getLast();
}
else
{
materials[i].lightmapFlag=1;
sprintf(materials[i].lightmapName,"FFFFFFFF");
materials[i].lightmapName="FFFFFFFF";
}
temp1.clear();
temp2.clear();
......@@ -473,83 +452,73 @@ bool GetDMFWaterMaterials(StringList RawFile /**<StringList representing a DMF f
return true;
}
/**This function extract an array of dmfVert and dmfFace from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile and two arrays long enough.
Please use GetDMFHeader() before this function to know number of vertices and faces.
\return true if function succeed or false on fail.*/
bool GetDMFVerticesFaces(StringList RawFile/**<StringList representing a DMF file.*/,
bool GetDMFVerticesFaces(const StringList& RawFile/**<StringList representing a DMF file.*/,
dmfVert vertices[]/**<Vertices returned*/,
dmfFace faces[]/**Faces returned*/
)
{
int offs=3;
int offs1=0;
StringList temp,temp1;
//Checking if this is a DeleD map File of version >= 0.91
temp=SubdivideString(RawFile[0],String(";"));//file info
if ( temp[0] != String("DeleD Map File") )
return false;//not a deled file
temp.clear();
temp=SubdivideString(RawFile[1],String(" "));//get version
temp1=SubdivideString(temp[1],String(";"));
// skip materials
s32 offs = 4 + atoi(RawFile[3].c_str());
if (atof(temp1[0].c_str()) < 0.91)
return false;//not correct version
const s32 objs = atoi(RawFile[offs].c_str());
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Reading objects", core::stringc(objs).c_str());
#endif
//end checking
temp.clear();
temp1.clear();
offs=offs + atoi(RawFile[offs].c_str());
s32 vert=0, tmp_sz=0, vert_cnt=0, face_cnt=0;
offs++;
s32 objs = atoi(RawFile[offs].c_str());
s32 fac=0, vert=0, tmp_sz=0, vert_cnt=0, face_cnt=0;
offs++;
for (int i=0; i<objs; i++)
for (int i=0; i<objs; ++i)
{
StringList wat=SubdivideString(RawFile[offs],";");
StringList wat1=SubdivideString(wat[0],"_");
#ifdef _IRR_DMF_DEBUG_
os::Printer::log("Reading object", wat[0].c_str());
#endif
offs++;
offs1=offs;
offs=offs + atoi(RawFile[offs].c_str());
const s32 vrtxPos=offs+1;
// skip vertices
offs += atoi(RawFile[offs].c_str());
offs++;
offs1++;
fac=atoi(RawFile[offs].c_str());
const s32 numFaces=atoi(RawFile[offs].c_str());
offs++;
if(!(wat1[0]==String("water") && wat[2]==String("0")))
{
for(int j=0;j<fac;j++)
for(s32 j=0; j<numFaces; ++j)
{
temp=SubdivideString(RawFile[offs+j],";");
//first value is vertices number for this face
faces[face_cnt].numVerts=atoi(temp[0].c_str());
vert=faces[face_cnt].numVerts;
vert=atoi(temp[0].c_str());
faces[face_cnt].numVerts=vert;
//second is material ID
faces[face_cnt].materialID=atoi(temp[1].c_str());
//vertices are ordined
faces[face_cnt].firstVert=vert_cnt;
//now we'll create vertices structure
for(int k=0;k<vert;k++)
for(s32 k=0; k<vert; ++k)
{
//get vertex position
temp1=SubdivideString(RawFile[offs1+atoi(temp[2+k].c_str())],";");
temp1=SubdivideString(RawFile[vrtxPos+atoi(temp[2+k].c_str())],";");
//copy x,y,z values
vertices[vert_cnt].pos[0] = (float)atof(temp1[0].c_str());
vertices[vert_cnt].pos[1] = (float)atof(temp1[1].c_str());
vertices[vert_cnt].pos[2] = (float)-atof(temp1[2].c_str());
vertices[vert_cnt].pos.set((float)atof(temp1[0].c_str()),
(float)atof(temp1[1].c_str()),
(float)-atof(temp1[2].c_str()));
//get uv coords for tex and light if any
vertices[vert_cnt].tc[0] = (float)atof(temp[2+vert+(2*k)].c_str());
vertices[vert_cnt].tc[1] = (float)atof(temp[2+vert+(2*k)+1].c_str());
vertices[vert_cnt].tc.set((float)atof(temp[2+vert+(2*k)].c_str()),
(float)atof(temp[2+vert+(2*k)+1].c_str()));
tmp_sz=temp.size();
vertices[vert_cnt].lc[0] = (float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str());
vertices[vert_cnt].lc[1] = (float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str());
vertices[vert_cnt].lc.set((float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str()),
(float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str()));
vert_cnt++;
temp1.clear();
}
......@@ -559,7 +528,7 @@ bool GetDMFVerticesFaces(StringList RawFile/**<StringList representing a DMF fil
}
}
offs=offs+fac;
offs=offs+numFaces;
}
return true;
......@@ -570,7 +539,7 @@ You must give in input a StringList representing a DMF file loaded with
LoadFromFile and one array long enough. Please use GetDMFHeader() before this
function to know number of dynamic lights.
\return true if function succeed or false on fail.*/
bool GetDMFLights(StringList RawFile/**<StringList representing a DMF file.*/,
bool GetDMFLights(const StringList& RawFile/**<StringList representing a DMF file.*/,
dmfLight lights[]/**<Lights returned.*/
)
{
......@@ -649,11 +618,11 @@ bool GetDMFLights(StringList RawFile/**<StringList representing a DMF file.*/,
return true;
}
/**This function extract an array of dmfWaterPlain,dmfVert and dmfFace from a DMF file.
/**This function extracts an array of dmfWaterPlain,dmfVert and dmfFace from a DMF file.
You must give in input a StringList representing a DMF file loaded with LoadFromFile and three arrays long enough.
Please use GetDMFHeader() before this function to know number of water plains and water faces as well as water vertices.
\return true if function succeed or false on fail.*/
bool GetDMFWaterPlains(StringList RawFile/**<StringList representing a DMF file.*/,
bool GetDMFWaterPlains(const StringList& RawFile/**<StringList representing a DMF file.*/,
dmfWaterPlain wat_planes[]/**<Water planes returned.*/,
dmfVert vertices[]/**<Vertices returned*/,
dmfFace faces[]/**Faces returned*/
......@@ -762,21 +731,21 @@ bool GetDMFWaterPlains(StringList RawFile/**<StringList representing a DMF file.
temp1=SubdivideString(RawFile[offs1+atoi(temp[2+k].c_str())], ";");
//copy x,y,z values
vertices[vert_cnt].pos[0]=(float)atof(temp1[0].c_str());
vertices[vert_cnt].pos[1]=(float)atof(temp1[1].c_str());
vertices[vert_cnt].pos[2]=(float)-atof(temp1[2].c_str());
vertices[vert_cnt].pos.set((float)atof(temp1[0].c_str()),
(float)atof(temp1[1].c_str()),
(float)-atof(temp1[2].c_str()));
//get uv coords for tex and light if any
vertices[vert_cnt].tc[0]=(float)atof(temp[2+vert+(2*k)].c_str());
vertices[vert_cnt].tc[1]=(float)atof(temp[2+vert+(2*k)+1].c_str());
vertices[vert_cnt].tc.set((float)atof(temp[2+vert+(2*k)].c_str()),
(float)atof(temp[2+vert+(2*k)+1].c_str()));
tmp_sz=temp.size();
vertices[vert_cnt].lc[0]=(float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str());
vertices[vert_cnt].lc[1]=(float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str());
vert_cnt++;
vertices[vert_cnt].lc.set((float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str()),
(float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str()));
++vert_cnt;
temp1.clear();
}
face_cnt++;
++face_cnt;
temp.clear();
}
}
......
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