HMPLoader.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (ASSIMP)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2008, ASSIMP Development Team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the ASSIMP team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the ASSIMP Development Team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Implementation of the MDL importer class */
  35. // internal headers
  36. #include "MaterialSystem.h"
  37. #include "HMPLoader.h"
  38. #include "MD2FileData.h"
  39. // public ASSIMP headers
  40. #include "../include/DefaultLogger.h"
  41. #include "../include/IOStream.h"
  42. #include "../include/IOSystem.h"
  43. #include "../include/aiMesh.h"
  44. #include "../include/aiScene.h"
  45. #include "../include/aiAssert.h"
  46. // boost headers
  47. #include <boost/scoped_ptr.hpp>
  48. using namespace Assimp;
  49. // ------------------------------------------------------------------------------------------------
  50. // Constructor to be privately used by Importer
  51. HMPImporter::HMPImporter()
  52. {
  53. // nothing to do here
  54. }
  55. // ------------------------------------------------------------------------------------------------
  56. // Destructor, private as well
  57. HMPImporter::~HMPImporter()
  58. {
  59. // nothing to do here
  60. }
  61. // ------------------------------------------------------------------------------------------------
  62. // Returns whether the class can handle the format of the given file.
  63. bool HMPImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
  64. {
  65. // simple check of file extension is enough for the moment
  66. std::string::size_type pos = pFile.find_last_of('.');
  67. // no file extension - can't read
  68. if( pos == std::string::npos)
  69. return false;
  70. std::string extension = pFile.substr( pos);
  71. if (extension.length() < 4)return false;
  72. if (extension[0] != '.')return false;
  73. if (extension[1] != 'h' && extension[1] != 'H')return false;
  74. if (extension[2] != 'm' && extension[2] != 'M')return false;
  75. if (extension[3] != 'p' && extension[3] != 'P')return false;
  76. return true;
  77. }
  78. // ------------------------------------------------------------------------------------------------
  79. // Imports the given file into the given scene structure.
  80. void HMPImporter::InternReadFile(
  81. const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler)
  82. {
  83. boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
  84. // Check whether we can read from the file
  85. if( file.get() == NULL)
  86. {
  87. throw new ImportErrorException( "Failed to open HMP file " + pFile + ".");
  88. }
  89. // check whether the HMP file is large enough to contain
  90. // at least the file header
  91. size_t fileSize = file->FileSize();
  92. if( fileSize < 50)
  93. {
  94. throw new ImportErrorException( "HMP File is too small.");
  95. }
  96. // allocate storage and copy the contents of the file to a memory buffer
  97. this->pScene = pScene;
  98. this->pIOHandler = pIOHandler;
  99. this->mBuffer = new unsigned char[fileSize+1];
  100. file->Read( (void*)mBuffer, 1, fileSize);
  101. this->iFileSize = (unsigned int)fileSize;
  102. // determine the file subtype and call the appropriate member function
  103. uint32_t iMagic = *((uint32_t*)this->mBuffer);
  104. try {
  105. // HMP4 format
  106. if (AI_HMP_MAGIC_NUMBER_LE_4 == iMagic ||
  107. AI_HMP_MAGIC_NUMBER_BE_4 == iMagic)
  108. {
  109. DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A4, magic word is HMP4");
  110. this->InternReadFile_HMP4();
  111. }
  112. // HMP5 format
  113. else if (AI_HMP_MAGIC_NUMBER_LE_5 == iMagic ||
  114. AI_HMP_MAGIC_NUMBER_BE_5 == iMagic)
  115. {
  116. DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A5, magic word is HMP5");
  117. this->InternReadFile_HMP5();
  118. }
  119. // HMP7 format
  120. else if (AI_HMP_MAGIC_NUMBER_LE_7 == iMagic ||
  121. AI_HMP_MAGIC_NUMBER_BE_7 == iMagic)
  122. {
  123. DefaultLogger::get()->debug("HMP subtype: 3D GameStudio A7, magic word is HMP7");
  124. this->InternReadFile_HMP7();
  125. }
  126. else
  127. {
  128. // print the magic word to the logger
  129. char szBuffer[5];
  130. szBuffer[0] = ((char*)&iMagic)[0];
  131. szBuffer[1] = ((char*)&iMagic)[1];
  132. szBuffer[2] = ((char*)&iMagic)[2];
  133. szBuffer[3] = ((char*)&iMagic)[3];
  134. szBuffer[4] = '\0';
  135. // we're definitely unable to load this file
  136. throw new ImportErrorException( "Unknown HMP subformat " + pFile +
  137. ". Magic word (" + szBuffer + ") is not known");
  138. }
  139. } catch (ImportErrorException* ex) {
  140. delete[] this->mBuffer;
  141. throw ex;
  142. }
  143. // delete the file buffer
  144. delete[] this->mBuffer;
  145. return;
  146. }
  147. // ------------------------------------------------------------------------------------------------
  148. void HMPImporter::ValidateHeader_HMP457( )
  149. {
  150. const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)this->mBuffer;
  151. if (120 > this->iFileSize)
  152. {
  153. throw new ImportErrorException("HMP file is too small (header size is "
  154. "120 bytes, this file is smaller)");
  155. }
  156. if (!pcHeader->ftrisize_x || !pcHeader->ftrisize_y)
  157. {
  158. throw new ImportErrorException("Size of triangles in either x or y direction is zero");
  159. }
  160. if(pcHeader->fnumverts_x < 1.0f || (pcHeader->numverts/pcHeader->fnumverts_x) < 1.0f)
  161. {
  162. throw new ImportErrorException("Number of triangles in either x or y direction is zero");
  163. }
  164. if(!pcHeader->numframes)
  165. {
  166. throw new ImportErrorException("There are no frames. At least one should be there");
  167. }
  168. }
  169. // ------------------------------------------------------------------------------------------------
  170. void HMPImporter::InternReadFile_HMP4( )
  171. {
  172. throw new ImportErrorException("HMP4 is currently not supported");
  173. }
  174. // ------------------------------------------------------------------------------------------------
  175. void HMPImporter::InternReadFile_HMP5( )
  176. {
  177. // read the file header and skip everything to byte 84
  178. const HMP::Header_HMP5* pcHeader = (const HMP::Header_HMP5*)this->mBuffer;
  179. const unsigned char* szCurrent = (const unsigned char*)(this->mBuffer+84);
  180. this->ValidateHeader_HMP457();
  181. // generate an output mesh
  182. this->pScene->mNumMeshes = 1;
  183. this->pScene->mMeshes = new aiMesh*[1];
  184. aiMesh* pcMesh = this->pScene->mMeshes[0] = new aiMesh();
  185. pcMesh->mMaterialIndex = 0;
  186. pcMesh->mVertices = new aiVector3D[pcHeader->numverts];
  187. pcMesh->mNormals = new aiVector3D[pcHeader->numverts];
  188. const unsigned int height = (unsigned int)(pcHeader->numverts / pcHeader->fnumverts_x);
  189. const unsigned int width = (unsigned int)pcHeader->fnumverts_x;
  190. // generate/load a material for the terrain
  191. this->CreateMaterial(szCurrent,&szCurrent);
  192. // goto offset 120, I don't know why ...
  193. // (fixme) is this the frame header? I assume yes since it starts with 2.
  194. szCurrent += 36;
  195. this->SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
  196. // now load all vertices from the file
  197. aiVector3D* pcVertOut = pcMesh->mVertices;
  198. aiVector3D* pcNorOut = pcMesh->mNormals;
  199. const HMP::Vertex_HMP5* src = (const HMP::Vertex_HMP5*) szCurrent;
  200. for (unsigned int y = 0; y < height;++y)
  201. {
  202. for (unsigned int x = 0; x < width;++x)
  203. {
  204. pcVertOut->x = x * pcHeader->ftrisize_x;
  205. pcVertOut->y = y * pcHeader->ftrisize_y;
  206. pcVertOut->z = (((float)src->z / 0xffff)-0.5f) * pcHeader->ftrisize_x * 8.0f;
  207. MD2::LookupNormalIndex(src->normals162index, *pcNorOut );
  208. ++pcVertOut;++pcNorOut;++src;
  209. }
  210. }
  211. // generate texture coordinates if necessary
  212. if (pcHeader->numskins)this->GenerateTextureCoords(width,height);
  213. // now build a list of faces
  214. this->CreateOutputFaceList(width,height);
  215. // there is no nodegraph in HMP files. Simply assign the one mesh
  216. // (no, not the one ring) to the root node
  217. this->pScene->mRootNode = new aiNode();
  218. this->pScene->mRootNode->mName.Set("terrain_root");
  219. this->pScene->mRootNode->mNumMeshes = 1;
  220. this->pScene->mRootNode->mMeshes = new unsigned int[1];
  221. this->pScene->mRootNode->mMeshes[0] = 0;
  222. }
  223. // ------------------------------------------------------------------------------------------------
  224. void HMPImporter::InternReadFile_HMP7( )
  225. {
  226. // read the file header and skip everything to byte 84
  227. const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)this->mBuffer;
  228. const unsigned char* szCurrent = (const unsigned char*)(this->mBuffer+84);
  229. this->ValidateHeader_HMP457();
  230. // generate an output mesh
  231. this->pScene->mNumMeshes = 1;
  232. this->pScene->mMeshes = new aiMesh*[1];
  233. aiMesh* pcMesh = this->pScene->mMeshes[0] = new aiMesh();
  234. pcMesh->mMaterialIndex = 0;
  235. pcMesh->mVertices = new aiVector3D[pcHeader->numverts];
  236. pcMesh->mNormals = new aiVector3D[pcHeader->numverts];
  237. const unsigned int height = (unsigned int)(pcHeader->numverts / pcHeader->fnumverts_x);
  238. const unsigned int width = (unsigned int)pcHeader->fnumverts_x;
  239. // generate/load a material for the terrain
  240. this->CreateMaterial(szCurrent,&szCurrent);
  241. // goto offset 120, I don't know why ...
  242. // (fixme) is this the frame header? I assume yes since it starts with 2.
  243. szCurrent += 36;
  244. this->SizeCheck(szCurrent + sizeof(const HMP::Vertex_HMP7)*height*width);
  245. // now load all vertices from the file
  246. aiVector3D* pcVertOut = pcMesh->mVertices;
  247. aiVector3D* pcNorOut = pcMesh->mNormals;
  248. const HMP::Vertex_HMP7* src = (const HMP::Vertex_HMP7*) szCurrent;
  249. for (unsigned int y = 0; y < height;++y)
  250. {
  251. for (unsigned int x = 0; x < width;++x)
  252. {
  253. pcVertOut->x = x * pcHeader->ftrisize_x;
  254. pcVertOut->y = y * pcHeader->ftrisize_y;
  255. // FIXME: What exctly is the correct scaling factor to use?
  256. // possibly pcHeader->scale_origin[2] in combination with a
  257. // signed interpretation of src->z?
  258. pcVertOut->z = (((float)src->z / 0xffff)-0.5f) * pcHeader->ftrisize_x * 8.0f;
  259. pcNorOut->x = ((float)src->normal_x / 0x80 ); // * pcHeader->scale_origin[0];
  260. pcNorOut->y = ((float)src->normal_y / 0x80 ); // * pcHeader->scale_origin[1];
  261. pcNorOut->z = 1.0f;
  262. pcNorOut->Normalize();
  263. ++pcVertOut;++pcNorOut;++src;
  264. }
  265. }
  266. // generate texture coordinates if necessary
  267. if (pcHeader->numskins)this->GenerateTextureCoords(width,height);
  268. // now build a list of faces
  269. this->CreateOutputFaceList(width,height);
  270. // there is no nodegraph in HMP files. Simply assign the one mesh
  271. // (no, not the One Ring) to the root node
  272. this->pScene->mRootNode = new aiNode();
  273. this->pScene->mRootNode->mName.Set("terrain_root");
  274. this->pScene->mRootNode->mNumMeshes = 1;
  275. this->pScene->mRootNode->mMeshes = new unsigned int[1];
  276. this->pScene->mRootNode->mMeshes[0] = 0;
  277. }
  278. // ------------------------------------------------------------------------------------------------
  279. void HMPImporter::CreateMaterial(const unsigned char* szCurrent,
  280. const unsigned char** szCurrentOut)
  281. {
  282. aiMesh* const pcMesh = this->pScene->mMeshes[0];
  283. const HMP::Header_HMP5* const pcHeader = (const HMP::Header_HMP5*)this->mBuffer;
  284. // we don't need to generate texture coordinates if
  285. // we have no textures in the file ...
  286. if (pcHeader->numskins)
  287. {
  288. pcMesh->mTextureCoords[0] = new aiVector3D[pcHeader->numverts];
  289. pcMesh->mNumUVComponents[0] = 2;
  290. // now read the first skin and skip all others
  291. this->ReadFirstSkin(pcHeader->numskins,szCurrent,&szCurrent);
  292. }
  293. else
  294. {
  295. // generate a default material
  296. const int iMode = (int)aiShadingMode_Gouraud;
  297. MaterialHelper* pcHelper = new MaterialHelper();
  298. pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
  299. aiColor3D clr;
  300. clr.b = clr.g = clr.r = 0.6f;
  301. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
  302. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
  303. clr.b = clr.g = clr.r = 0.05f;
  304. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
  305. aiString szName;
  306. szName.Set(AI_DEFAULT_MATERIAL_NAME);
  307. pcHelper->AddProperty(&szName,AI_MATKEY_NAME);
  308. // add the material to the scene
  309. this->pScene->mNumMaterials = 1;
  310. this->pScene->mMaterials = new aiMaterial*[1];
  311. this->pScene->mMaterials[0] = pcHelper;
  312. }
  313. *szCurrentOut = szCurrent;
  314. }
  315. // ------------------------------------------------------------------------------------------------
  316. void HMPImporter::CreateOutputFaceList(unsigned int width,unsigned int height)
  317. {
  318. aiMesh* const pcMesh = this->pScene->mMeshes[0];
  319. // allocate enough storage
  320. const unsigned int iNumSquares = (width-1) * (height-1);
  321. pcMesh->mNumFaces = iNumSquares << 1;
  322. pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
  323. pcMesh->mNumVertices = pcMesh->mNumFaces*3;
  324. aiVector3D* pcVertices = new aiVector3D[pcMesh->mNumVertices];
  325. aiVector3D* pcNormals = new aiVector3D[pcMesh->mNumVertices];
  326. aiFace* pcFaceOut(pcMesh->mFaces);
  327. aiVector3D* pcVertOut = pcVertices;
  328. aiVector3D* pcNorOut = pcNormals;
  329. aiVector3D* pcUVs = pcMesh->mTextureCoords[0] ? new aiVector3D[pcMesh->mNumVertices] : NULL;
  330. aiVector3D* pcUVOut(pcUVs);
  331. // build the terrain square
  332. unsigned int iCurrent = 0;
  333. for (unsigned int y = 0; y < height-1;++y)
  334. {
  335. for (unsigned int x = 0; x < width-1;++x)
  336. {
  337. // first triangle of the square
  338. pcFaceOut->mNumIndices = 3;
  339. pcFaceOut->mIndices = new unsigned int[3];
  340. *pcVertOut++ = pcMesh->mVertices[y*width+x];
  341. *pcVertOut++ = pcMesh->mVertices[y*width+x+1];
  342. *pcVertOut++ = pcMesh->mVertices[(y+1)*width+x];
  343. *pcNorOut++ = pcMesh->mNormals[y*width+x];
  344. *pcNorOut++ = pcMesh->mNormals[y*width+x+1];
  345. *pcNorOut++ = pcMesh->mNormals[(y+1)*width+x];
  346. if (pcMesh->mTextureCoords[0])
  347. {
  348. *pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x];
  349. *pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x+1];
  350. *pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x];
  351. }
  352. pcFaceOut->mIndices[2] = iCurrent++;
  353. pcFaceOut->mIndices[1] = iCurrent++;
  354. pcFaceOut->mIndices[0] = iCurrent++;
  355. ++pcFaceOut;
  356. // second triangle of the square
  357. pcFaceOut->mNumIndices = 3;
  358. pcFaceOut->mIndices = new unsigned int[3];
  359. *pcVertOut++ = pcMesh->mVertices[(y+1)*width+x];
  360. *pcVertOut++ = pcMesh->mVertices[y*width+x+1];
  361. *pcVertOut++ = pcMesh->mVertices[(y+1)*width+x+1];
  362. *pcNorOut++ = pcMesh->mNormals[(y+1)*width+x];
  363. *pcNorOut++ = pcMesh->mNormals[y*width+x+1];
  364. *pcNorOut++ = pcMesh->mNormals[(y+1)*width+x+1];
  365. if (pcMesh->mTextureCoords[0])
  366. {
  367. *pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x];
  368. *pcUVOut++ = pcMesh->mTextureCoords[0][y*width+x+1];
  369. *pcUVOut++ = pcMesh->mTextureCoords[0][(y+1)*width+x+1];
  370. }
  371. pcFaceOut->mIndices[2] = iCurrent++;
  372. pcFaceOut->mIndices[1] = iCurrent++;
  373. pcFaceOut->mIndices[0] = iCurrent++;
  374. ++pcFaceOut;
  375. }
  376. }
  377. delete[] pcMesh->mVertices;
  378. pcMesh->mVertices = pcVertices;
  379. delete[] pcMesh->mNormals;
  380. pcMesh->mNormals = pcNormals;
  381. if (pcMesh->mTextureCoords[0])
  382. {
  383. delete[] pcMesh->mTextureCoords[0];
  384. pcMesh->mTextureCoords[0] = pcUVs;
  385. }
  386. }
  387. // ------------------------------------------------------------------------------------------------
  388. void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char* szCursor,
  389. const unsigned char** szCursorOut)
  390. {
  391. ai_assert(0 != iNumSkins && NULL != szCursor);
  392. // read the type of the skin ...
  393. // sometimes we need to skip 12 bytes here, I don't know why ...
  394. uint32_t iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
  395. if (0 == iType)
  396. {
  397. DefaultLogger::get()->warn("Skin type is 0. Skipping 12 bytes to "
  398. "the next valid value, which seems to be the real skin type. "
  399. "However, it is not known whether or not this is correct.");
  400. szCursor += sizeof(uint32_t) * 2;
  401. iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
  402. if (0 == iType)
  403. {
  404. throw new ImportErrorException("Unable to read HMP7 skin chunk");
  405. }
  406. }
  407. // read width and height
  408. uint32_t iWidth = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
  409. uint32_t iHeight = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
  410. // allocate an output material
  411. MaterialHelper* pcMat = new MaterialHelper();
  412. // read the skin, this works exactly as for MDL7
  413. this->ParseSkinLump_3DGS_MDL7(szCursor,&szCursor,
  414. pcMat,iType,iWidth,iHeight);
  415. // now we need to skip any other skins ...
  416. for (unsigned int i = 1; i< iNumSkins;++i)
  417. {
  418. iType = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
  419. iWidth = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
  420. iHeight = *((uint32_t*)szCursor);szCursor += sizeof(uint32_t);
  421. this->SkipSkinLump_3DGS_MDL7(szCursor,&szCursor,
  422. iType,iWidth,iHeight);
  423. this->SizeCheck(szCursor);
  424. }
  425. // setup the material ...
  426. this->pScene->mNumMaterials = 1;
  427. this->pScene->mMaterials = new aiMaterial*[1];
  428. this->pScene->mMaterials[0] = pcMat;
  429. *szCursorOut = szCursor;
  430. return;
  431. }
  432. // ------------------------------------------------------------------------------------------------
  433. void HMPImporter::GenerateTextureCoords(
  434. const unsigned int width, const unsigned int height)
  435. {
  436. ai_assert(NULL != this->pScene->mMeshes && NULL != this->pScene->mMeshes[0] &&
  437. NULL != this->pScene->mMeshes[0]->mTextureCoords[0]);
  438. aiVector3D* uv = this->pScene->mMeshes[0]->mTextureCoords[0];
  439. const float fY = (1.0f / height) + (1.0f / height) / (height-1);
  440. const float fX = (1.0f / width) + (1.0f / width) / (width-1);
  441. for (unsigned int y = 0; y < height;++y)
  442. {
  443. for (unsigned int x = 0; x < width;++x)
  444. {
  445. uv->y = 1.0f-fY*y;
  446. uv->x = fX*x;
  447. uv->z = 0.0f;
  448. ++uv;
  449. }
  450. }
  451. return;
  452. }