HMPLoader.cpp 18 KB

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