dmfsupport.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. //
  5. // This file was originally written by Salvatore Russo.
  6. // I (Nikolaus Gebhardt) did some minor modifications changes to it and integrated
  7. // it into Irrlicht:
  8. // - removed STL dependency
  9. // - removed log file and replaced it with irrlicht logging
  10. // - adapted code formatting a bit to Irrlicht style
  11. // - removed memory leaks
  12. // Thanks a lot to Salvatore for his work on this and that he gave me
  13. // his permission to add it into Irrlicht.
  14. // This support library has been made by Salvatore Russo and is released under GNU public license for general uses.
  15. // For uses in Irrlicht core and only for Irrlicht related uses I release this library under zlib license.
  16. #ifndef __DMF_SUPPORT_H_INCLUDED__
  17. #define __DMF_SUPPORT_H_INCLUDED__
  18. #include "irrString.h"
  19. #include "fast_atof.h"
  20. namespace irr
  21. {
  22. namespace scene
  23. {
  24. namespace
  25. {
  26. /** A structure representing some DeleD infos.
  27. This structure contains data about DeleD level file like: version, ambient color, number of objects etc...*/
  28. struct dmfHeader
  29. {
  30. //main file header
  31. core::stringc dmfName; //!<Scene name
  32. f32 dmfVersion; //!<File version
  33. video::SColor dmfAmbient; //!<Ambient color
  34. f32 dmfShadow; //!<Shadow intensity
  35. u32 numObjects; //!<Number of objects in this scene
  36. u32 numMaterials; //!<Number of materials in this scene
  37. u32 numVertices; //!<Total number of vertices faces*(vertices for each face)
  38. u32 numFaces; //!<Total number of faces
  39. u32 numLights; //!<Number of dynamic lights in this scene
  40. u32 numWatVertices; //!<Total number of vertices of water plains watfaces*(vertices for each face)
  41. u32 numWatFaces; //!<Total number of faces for water plains.Note that each water plane is a rectangle with one face only.
  42. };
  43. /** A structure representing a DeleD material.
  44. This structure contains texture names, an ID and some flags.*/
  45. struct dmfMaterial
  46. {
  47. u32 materialID;//!<This material unique ID.
  48. u32 textureLayers;//!<First texture Flag (0=Normal, 1=Color).
  49. u32 textureFlag;//!<First texture Flag (0=Normal, 1=Color).
  50. u32 lightmapFlag;//!<Lightmap Flag (0=Normal, others not considered).
  51. u32 textureBlend;//!<Texture Blend mode used to support alpha maps (4=Alpha map, others not implemented yet).
  52. core::stringc pathName;//!<Name of path defined in path element.
  53. core::stringc textureName;//!<Name of first texture (only file name, no path).
  54. core::stringc lightmapName;//!<Name of lightmap (only file name, no path).
  55. u32 lightmapBlend;//!<Blend mode used to support alpha maps (not implemented yet).
  56. };
  57. /** A structure representing a single face.
  58. This structure contains first vertice index, number of vertices and the material used.*/
  59. struct dmfFace
  60. {
  61. u32 firstVert;//!<First vertex index.
  62. u32 numVerts;//!<Number of vertices for this face.
  63. u32 materialID;//!<Material used for this face.
  64. };
  65. /** A structure representing a single vertice.
  66. This structure contains vertice position coordinates and texture an lightmap UV.*/
  67. struct dmfVert
  68. {
  69. core::vector3df pos;//!<Position of vertex
  70. core::vector2df tc;//!<Texture UV coords
  71. core::vector2df lc;//!<Lightmap UV coords
  72. };
  73. /** A structure representing a single dynamic light.
  74. This structure contains light position coordinates, diffuse color, specular color and maximum radius of light.*/
  75. struct dmfLight
  76. {
  77. core::vector3df pos;//!<Position of this light.
  78. video::SColorf diffuseColor;//!<Diffuse color.
  79. video::SColorf specularColor;//!<Specular color.
  80. f32 radius;//!<Maximum radius of light.
  81. };
  82. /** A structure representing a single water plane.
  83. This structure contains light position coordinates, diffuse color, specular color and maximum radius of light.*/
  84. struct dmfWaterPlane
  85. {
  86. u32 waterID;//!<ID of specified water plane.
  87. u32 numFaces;//!<number of faces that make this plain.Owing to the fact that this is a rectangle you'll have 1 every time.
  88. u32 firstFace;//!<first face of this plain.
  89. core::dimension2d<u32> tileNum;//!<number of tiles of this water plain.
  90. f32 waveHeight;//!<height of waves.
  91. f32 waveSpeed;//!<waves speed.
  92. f32 waveLength;//!<waves length.
  93. };
  94. /** A function to convert a hexstring to a int.
  95. This function converts an hex string (i.e. FF) to its int value (i.e. 255).
  96. \return An int representing the hex input value.*/
  97. int axtoi(const char *hexStg)
  98. {
  99. unsigned int intValue = 0; // integer value of hex string
  100. sscanf(hexStg, "%x", &intValue);
  101. return (intValue);
  102. }
  103. typedef core::array<core::stringc> StringList;
  104. //Loads a stringlist from a file
  105. //note that each String added to StringList
  106. //is separated by a \\n character and it's present
  107. //at the end of line.
  108. /** Loads a StringList from a file.
  109. This function loads a StringList from a file where each string is divided by a \\n char.*/
  110. void LoadFromFile(io::IReadFile* file, StringList& strlist)
  111. {
  112. const long sz = file->getSize();
  113. char* buf = new char[sz+1];
  114. file->read(buf, sz);
  115. buf[sz] = 0;
  116. char* p = buf;
  117. char* start = p;
  118. while(*p)
  119. {
  120. if (*p == '\n')
  121. {
  122. core::stringc str(start, (u32)(p - start - 1));
  123. str.trim();
  124. strlist.push_back(str);
  125. start = p+1;
  126. }
  127. ++p;
  128. }
  129. if (p - start > 1)
  130. {
  131. core::stringc str(start, (u32)(p - start - 1));
  132. str.trim();
  133. strlist.push_back(str);
  134. }
  135. delete [] buf;
  136. };
  137. //This function subdivides a string in a list of strings
  138. /** This function subdivides strings divided by divider in a list of strings.
  139. \return A StringList made of all strings divided by divider.*/
  140. StringList SubdivideString(const core::stringc& str, const core::stringc& divider)
  141. {
  142. StringList strings; //returned StringList
  143. strings.clear(); //clear returned stringlist
  144. int c=0;
  145. int l=str.size();
  146. //process entire string
  147. while(c<l)
  148. {
  149. core::stringc resultstr;
  150. resultstr = "";
  151. //read characters until divider is encountered
  152. while((str[c]!=divider[0]) && c<l)
  153. {
  154. resultstr += str[c];
  155. ++c;
  156. }
  157. //Remove spaces \t and \n from string in my implementation...
  158. //pay attention or change it in dll.h if you don't want to remove
  159. //a particular char.
  160. resultstr.trim();//trims string resultstr
  161. strings.push_back(resultstr);//add trimmed string
  162. ++c;
  163. }
  164. return strings;
  165. }
  166. //Get DeleD informations and convert in dmfHeader
  167. /**This function extract a dmfHeader from a DMF file.
  168. You must give in input a StringList representing a DMF file loaded with LoadFromFile.
  169. \return true if function succeed or false on fail.*/
  170. bool GetDMFHeader(const StringList& RawFile, dmfHeader& header)
  171. {
  172. StringList temp;
  173. RawFile[0].split(temp, ";"); //file info
  174. // StringList temp=SubdivideString(RawFile[0],";"); //file info
  175. if ( temp[0] != "DeleD Map File" )
  176. return false; //not a deled file
  177. temp.clear();
  178. temp = SubdivideString(RawFile[1]," ");//get version
  179. StringList temp1=SubdivideString(temp[1],";");
  180. header.dmfVersion = (float)atof(temp1[0].c_str());//save version
  181. if (header.dmfVersion < 0.91)
  182. return false;//not correct version
  183. temp.clear();
  184. temp = SubdivideString(RawFile[2],";");//get name,ambient color and shadow opacity
  185. header.dmfName=temp[0];//save name
  186. //set ambient color
  187. header.dmfAmbient.set(axtoi(temp[1].c_str()));
  188. //set Shadow intensity
  189. header.dmfShadow = (float)atof(temp[2].c_str());
  190. //set current position
  191. int offs=3;
  192. //set Materials Number
  193. header.numMaterials=atoi(RawFile[offs].c_str());
  194. offs+=header.numMaterials;
  195. ++offs;
  196. //set Object Number
  197. header.numObjects=atoi(RawFile[offs].c_str());
  198. //retrieve face and vertices number
  199. header.numVertices=0;
  200. header.numFaces=0;
  201. header.numWatFaces=0;
  202. header.numWatVertices=0;
  203. offs++;
  204. s32 fac;
  205. int i;
  206. for(i=0; i < (int)header.numObjects; i++)
  207. {
  208. StringList wat=SubdivideString(RawFile[offs],";");
  209. StringList wat1=SubdivideString(wat[0],"_");
  210. ++offs;
  211. offs += atoi(RawFile[offs].c_str());
  212. ++offs;
  213. fac=atoi(RawFile[offs].c_str());
  214. if(!(wat1[0]=="water" && wat[2]=="0"))
  215. header.numFaces = header.numFaces + fac;
  216. else
  217. header.numWatFaces = header.numWatFaces + fac;
  218. offs++;
  219. for(int j=0; j<fac; j++)
  220. {
  221. if(!(wat1[0] == "water" && wat[2] == "0"))
  222. header.numVertices=header.numVertices + atoi(RawFile[offs+j].c_str());
  223. else
  224. header.numWatVertices=header.numWatVertices + atoi(RawFile[offs + j].c_str());
  225. }
  226. offs = offs + fac;
  227. }
  228. //retrieve number of dynamic lights
  229. header.numLights=0;
  230. temp.clear();
  231. temp1.clear();
  232. s32 lit = atoi(RawFile[offs].c_str());
  233. for (i=0; i<lit; i++)
  234. {
  235. offs++;
  236. temp=SubdivideString(RawFile[offs],";");
  237. if(atoi(temp[0].c_str())==1)
  238. {
  239. temp1=SubdivideString(temp[18],"_");
  240. if(temp1[0]=="dynamic")
  241. header.numLights++;
  242. }
  243. temp.clear();
  244. temp1.clear();
  245. }
  246. return true; //everything is OK so loading is correct
  247. }
  248. /**This function extract an array of dmfMaterial from a DMF file.
  249. You must give in input a StringList representing a DMF file loaded with LoadFromFile.
  250. \param RawFile StringList representing a DMF file.
  251. \param materials Materials returned.
  252. \param num_material Number of materials contained in DMF file.
  253. \param use_material_dirs Here you can choose to use default DeleD structure for material dirs.
  254. \return true if function succeed or false on fail.*/
  255. bool GetDMFMaterials(const StringList& RawFile,
  256. core::array<dmfMaterial>& materials,
  257. int num_material)
  258. {
  259. // offset for already handled lines
  260. const int offs=4;
  261. StringList temp;
  262. StringList temp1;
  263. // The number of materials is predetermined
  264. materials.reallocate(num_material);
  265. for(int i=0; i<num_material; ++i)
  266. {
  267. materials.push_back(dmfMaterial());
  268. // get all tokens
  269. temp=SubdivideString(RawFile[offs+i],";");
  270. // should be equal to first token
  271. materials[i].materialID = i;
  272. // The path used for the texture
  273. materials[i].pathName = temp[2];
  274. materials[i].pathName.replace('\\','/');
  275. materials[i].pathName += "/";
  276. // temp[3] is reserved, temp[4] is the number of texture layers
  277. materials[i].textureLayers = core::strtoul10(temp[4].c_str());
  278. // Three values are separated by commas
  279. temp1=SubdivideString(temp[5],",");
  280. materials[i].textureFlag = atoi(temp1[0].c_str());
  281. materials[i].textureName=temp1[1];
  282. materials[i].textureName.replace('\\','/');
  283. materials[i].textureBlend = atoi(temp1[2].c_str());
  284. if(temp.size()>=9)
  285. {
  286. temp1=SubdivideString(temp[temp.size() - 1],",");
  287. materials[i].lightmapFlag=atoi(temp1[0].c_str());
  288. materials[i].lightmapName=temp1[1];
  289. materials[i].lightmapName.replace('\\','/');
  290. materials[i].lightmapBlend = atoi(temp1[2].c_str());
  291. }
  292. else
  293. {
  294. materials[i].lightmapFlag=1;
  295. materials[i].lightmapName="";
  296. }
  297. }
  298. return true;
  299. }
  300. /**This function extract an array of dmfMaterial from a DMF file considering 1st an 2nd layer for water plains.
  301. You must give in input a StringList representing a DMF file loaded with LoadFromFile.
  302. \return true if function succeed or false on fail.*/
  303. bool GetDMFWaterMaterials(const StringList& RawFile /**<StringList representing a DMF file.*/,
  304. core::array<dmfMaterial>& materials/**<Materials returned.*/,
  305. int num_material/**<Number of materials contained in DMF file.*/
  306. )
  307. {
  308. int offs=4;
  309. StringList temp;
  310. StringList temp1;
  311. StringList temp2;
  312. //Checking if this is a DeleD map File of version >= 0.91
  313. temp=SubdivideString(RawFile[0],";");//file info
  314. if ( temp[0] != "DeleD Map File" )
  315. return false;//not a deled file
  316. temp.clear();
  317. temp=SubdivideString(RawFile[1]," ");//get version
  318. temp1=SubdivideString(temp[1],";");
  319. if (atof(temp1[0].c_str()) < 0.91)
  320. return false;//not correct version
  321. //end checking
  322. temp.clear();
  323. temp1.clear();
  324. for(int i=0;i<num_material;i++)
  325. {
  326. temp = SubdivideString(RawFile[offs+i],";");
  327. materials[i].materialID=i;
  328. temp1 = SubdivideString(temp[5],",");
  329. materials[i].textureFlag=atoi(temp1[0].c_str());
  330. temp2 = SubdivideString(temp1[1],"\\");
  331. materials[i].textureName=temp2.getLast();
  332. temp1.clear();
  333. temp2.clear();
  334. int a=temp.size();
  335. if(a==7)
  336. {
  337. temp1=SubdivideString(temp[6],",");
  338. materials[i].lightmapFlag=atoi(temp1[0].c_str());
  339. temp2=SubdivideString(temp1[1],"\\");
  340. materials[i].lightmapName=temp2.getLast();
  341. }
  342. else
  343. {
  344. materials[i].lightmapFlag=1;
  345. materials[i].lightmapName="FFFFFFFF";
  346. }
  347. temp1.clear();
  348. temp2.clear();
  349. }
  350. return true;
  351. }
  352. /**This function extract an array of dmfVert and dmfFace from a DMF file.
  353. You must give in input a StringList representing a DMF file loaded with LoadFromFile and two arrays long enough.
  354. Please use GetDMFHeader() before this function to know number of vertices and faces.
  355. \return true if function succeed or false on fail.*/
  356. bool GetDMFVerticesFaces(const StringList& RawFile/**<StringList representing a DMF file.*/,
  357. dmfVert vertices[]/**<Vertices returned*/,
  358. dmfFace faces[]/**Faces returned*/
  359. )
  360. {
  361. StringList temp,temp1;
  362. // skip materials
  363. s32 offs = 4 + atoi(RawFile[3].c_str());
  364. const s32 objs = atoi(RawFile[offs].c_str());
  365. offs++;
  366. #ifdef _IRR_DMF_DEBUG_
  367. os::Printer::log("Reading objects", core::stringc(objs).c_str());
  368. #endif
  369. s32 vert_cnt=0, face_cnt=0;
  370. for (int i=0; i<objs; ++i)
  371. {
  372. StringList wat=SubdivideString(RawFile[offs],";");
  373. StringList wat1=SubdivideString(wat[0],"_");
  374. #ifdef _IRR_DMF_DEBUG_
  375. os::Printer::log("Reading object", wat[0].c_str());
  376. #endif
  377. offs++;
  378. // load vertices
  379. core::array<core::vector3df> pos;
  380. const u32 posCount = core::strtoul10(RawFile[offs].c_str());
  381. ++offs;
  382. pos.reallocate(posCount);
  383. for (u32 i=0; i<posCount; ++i)
  384. {
  385. temp1=SubdivideString(RawFile[offs].c_str(),";");
  386. pos.push_back(core::vector3df(core::fast_atof(temp1[0].c_str()),
  387. core::fast_atof(temp1[1].c_str()),
  388. -core::fast_atof(temp1[2].c_str())));
  389. ++offs;
  390. }
  391. const u32 numFaces=core::strtoul10(RawFile[offs].c_str());
  392. offs++;
  393. if(!(wat1[0]=="water" && wat[2]=="0"))
  394. {
  395. for(u32 j=0; j<numFaces; ++j)
  396. {
  397. temp=SubdivideString(RawFile[offs+j],";");
  398. //first value is vertices number for this face
  399. const u32 vert=core::strtoul10(temp[0].c_str());
  400. faces[face_cnt].numVerts=vert;
  401. //second is material ID
  402. faces[face_cnt].materialID=core::strtoul10(temp[1].c_str());
  403. //vertices are ordined
  404. faces[face_cnt].firstVert=vert_cnt;
  405. //now we'll create vertices structure
  406. for(u32 k=0; k<vert; ++k)
  407. {
  408. //copy position
  409. vertices[vert_cnt].pos.set(pos[core::strtoul10(temp[2+k].c_str())]);
  410. //get uv coords for tex and light if any
  411. vertices[vert_cnt].tc.set(core::fast_atof(temp[2+vert+(2*k)].c_str()),
  412. core::fast_atof(temp[2+vert+(2*k)+1].c_str()));
  413. const u32 tmp_sz=temp.size();
  414. vertices[vert_cnt].lc.set(core::fast_atof(temp[tmp_sz-(2*vert)+(2*k)].c_str()),
  415. core::fast_atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str()));
  416. vert_cnt++;
  417. }
  418. face_cnt++;
  419. }
  420. }
  421. offs+=numFaces;
  422. }
  423. return true;
  424. }
  425. /**This function extract an array of dmfLights from a DMF file.
  426. You must give in input a StringList representing a DMF file loaded with
  427. LoadFromFile and one array long enough. Please use GetDMFHeader() before this
  428. function to know number of dynamic lights.
  429. \return true if function succeed or false on fail.*/
  430. bool GetDMFLights(const StringList& RawFile/**<StringList representing a DMF file.*/,
  431. dmfLight lights[]/**<Lights returned.*/
  432. )
  433. {
  434. int offs=3;
  435. StringList temp,temp1;
  436. //Checking if this is a DeleD map File of version >= 0.91
  437. temp=SubdivideString(RawFile[0],";");//file info
  438. if ( temp[0] != "DeleD Map File" )
  439. return false;//not a deled file
  440. temp.clear();
  441. temp=SubdivideString(RawFile[1]," ");//get version
  442. temp1=SubdivideString(temp[1],";");
  443. if (atof(temp1[0].c_str()) < 0.91)
  444. return false;//not correct version
  445. //end checking
  446. temp.clear();
  447. temp1.clear();
  448. offs=offs + atoi(RawFile[offs].c_str());
  449. offs++;
  450. s32 objs = atoi(RawFile[offs].c_str());
  451. s32 lit=0;
  452. s32 d_lit=0;
  453. offs++;
  454. //let's get position of lights in file
  455. int i;
  456. for(i=0;i<objs;i++)
  457. {
  458. offs++;
  459. offs = offs + atoi(RawFile[offs].c_str());
  460. offs++;
  461. offs = offs + atoi(RawFile[offs].c_str());
  462. offs++;
  463. }
  464. //let's find dynamic lights
  465. lit = atoi(RawFile[offs].c_str());
  466. for(i=0;i<lit;i++)
  467. {
  468. offs++;
  469. temp=SubdivideString(RawFile[offs],";");
  470. if(atoi(temp[0].c_str())==1)
  471. {
  472. temp1=SubdivideString(temp[18],"_");
  473. if(temp1[0]=="dynamic")
  474. {
  475. lights[d_lit].radius = (float)atof(temp[4].c_str());
  476. lights[d_lit].pos.set((float)atof(temp[5].c_str()),
  477. (float)atof(temp[6].c_str()),
  478. (float)-atof(temp[7].c_str()));
  479. lights[d_lit].diffuseColor = video::SColorf(
  480. video::SColor(255, atoi(temp[10].c_str()), atoi(temp[11].c_str()),
  481. atoi(temp[12].c_str())));
  482. lights[d_lit].specularColor = video::SColorf(
  483. video::SColor(255, atoi(temp[13].c_str()), atoi(temp[14].c_str()),
  484. atoi(temp[15].c_str())));
  485. d_lit++;
  486. }
  487. }
  488. temp.clear();
  489. temp1.clear();
  490. }
  491. return true;
  492. }
  493. /**This function extracts an array of dmfWaterPlane,dmfVert and dmfFace from a DMF file.
  494. You must give in input a StringList representing a DMF file loaded with LoadFromFile and three arrays long enough.
  495. Please use GetDMFHeader() before this function to know number of water plains and water faces as well as water vertices.
  496. \return true if function succeed or false on fail.*/
  497. bool GetDMFWaterPlanes(const StringList& RawFile/**<StringList representing a DMF file.*/,
  498. dmfWaterPlane wat_planes[]/**<Water planes returned.*/,
  499. dmfVert vertices[]/**<Vertices returned*/,
  500. dmfFace faces[]/**Faces returned*/
  501. )
  502. {
  503. int offs=3;
  504. int offs1=0;
  505. StringList temp,temp1;
  506. //Checking if this is a DeleD map File of version >= 0.91
  507. temp=SubdivideString(RawFile[0],";");//file info
  508. if ( temp[0] != "DeleD Map File" )
  509. return false;//not a deled file
  510. temp.clear();
  511. temp=SubdivideString(RawFile[1]," ");//get version
  512. temp1=SubdivideString(temp[1],";");
  513. if (atof(temp1[0].c_str()) < 0.91)
  514. return false;//not correct version
  515. //end checking
  516. temp.clear();
  517. temp1.clear();
  518. offs=offs+atoi(RawFile[offs].c_str());
  519. offs++;
  520. s32 objs=atoi(RawFile[offs].c_str());
  521. s32 fac=0,vert=0,tmp_sz=0,vert_cnt=0,face_cnt=0,wat_id=0;
  522. core::dimension2d<u32> tilenum(40,40);
  523. f32 waveheight=3.0f;
  524. f32 wavespeed=300.0f;
  525. f32 wavelength=80.0f;
  526. offs++;
  527. for(int i=0;i<objs;i++)
  528. {
  529. StringList wat=SubdivideString(RawFile[offs],";");
  530. StringList wat1=SubdivideString(wat[0],"_");
  531. offs++;
  532. offs1=offs;
  533. offs=offs+atoi(RawFile[offs].c_str());
  534. offs++;
  535. offs1++;
  536. fac=atoi(RawFile[offs].c_str());
  537. offs++;
  538. if(wat1[0]=="water" && wat[2]=="0")
  539. {
  540. StringList userinfo=SubdivideString(wat[7],",");
  541. int j;
  542. for (j=0; j<(int)userinfo.size(); j++)
  543. {
  544. switch(j)
  545. {
  546. case 0:
  547. if(atoi(userinfo[0].c_str()))
  548. tilenum.Width = atoi(userinfo[0].c_str());
  549. break;
  550. case 1:
  551. if(atoi(userinfo[1].c_str()))
  552. tilenum.Height = atoi(userinfo[1].c_str());
  553. break;
  554. case 2:
  555. if(atof(userinfo[2].c_str()))
  556. waveheight = (float)atof(userinfo[2].c_str());
  557. break;
  558. case 3:
  559. if(atof(userinfo[3].c_str()))
  560. wavespeed = (float)atof(userinfo[3].c_str());
  561. break;
  562. case 4:
  563. if(atof(userinfo[4].c_str()))
  564. wavelength = (float)atof(userinfo[4].c_str());
  565. break;
  566. }
  567. }
  568. wat_planes[wat_id].waterID=wat_id;
  569. wat_planes[wat_id].numFaces=fac;
  570. wat_planes[wat_id].firstFace=face_cnt;
  571. wat_planes[wat_id].tileNum=tilenum;
  572. wat_planes[wat_id].waveHeight=waveheight;
  573. wat_planes[wat_id].waveSpeed=wavespeed;
  574. wat_planes[wat_id].waveLength=wavelength;
  575. for(j=0;j<fac;j++)
  576. {
  577. temp=SubdivideString(RawFile[offs+j],";");
  578. //first value is vertices number for this face
  579. faces[face_cnt].numVerts=atoi(temp[0].c_str());
  580. vert=faces[face_cnt].numVerts;
  581. //second is material ID
  582. faces[face_cnt].materialID=atoi(temp[1].c_str());
  583. //vertices are ordined
  584. faces[face_cnt].firstVert=vert_cnt;
  585. //now we'll create vertices structure
  586. for(int k=0;k<vert;k++)
  587. {
  588. //get vertex position
  589. temp1=SubdivideString(RawFile[offs1+atoi(temp[2+k].c_str())], ";");
  590. //copy x,y,z values
  591. vertices[vert_cnt].pos.set((float)atof(temp1[0].c_str()),
  592. (float)atof(temp1[1].c_str()),
  593. (float)-atof(temp1[2].c_str()));
  594. //get uv coords for tex and light if any
  595. vertices[vert_cnt].tc.set((float)atof(temp[2+vert+(2*k)].c_str()),
  596. (float)atof(temp[2+vert+(2*k)+1].c_str()));
  597. tmp_sz=temp.size();
  598. vertices[vert_cnt].lc.set((float)atof(temp[tmp_sz-(2*vert)+(2*k)].c_str()),
  599. (float)atof(temp[tmp_sz-(2*vert)+(2*k)+1].c_str()));
  600. ++vert_cnt;
  601. temp1.clear();
  602. }
  603. ++face_cnt;
  604. temp.clear();
  605. }
  606. }
  607. offs=offs+fac;
  608. }
  609. return true;
  610. }
  611. } // end namespace
  612. } // end namespace scene
  613. } // end namespace irr
  614. #endif /* __DMF_SUPPORT_H__ */