ModelFile.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. #include "ModelFile.h"
  2. #include "../../common/Logger.h"
  3. #include "../../common/OgreGenUtilites.h"
  4. #include <OgreStringConverter.h>
  5. ModelFile::ModelFile( const Ogre::String& file ):
  6. File( file )
  7. {
  8. }
  9. ModelFile::ModelFile( File *file, const u32 offset, const u32 length ):
  10. File( file, offset, length )
  11. {
  12. }
  13. ModelFile::ModelFile( u8* buffer, const u32 offset, const u32 length ):
  14. File( buffer, offset, length )
  15. {
  16. }
  17. ModelFile::ModelFile( File* file ):
  18. File( file )
  19. {
  20. }
  21. ModelFile::~ModelFile()
  22. {
  23. }
  24. void
  25. ModelFile::GetModel( Ogre::MeshPtr mesh, const MeshData& data, VectorTexForGen& textures, Logger* export_text )
  26. {
  27. m_ExportLog = export_text;
  28. int number_of_parts = GetU32LE( 0x0 );
  29. m_ExportLog->Log( "Model:\nnumber_of_parts: " + Ogre::StringConverter::toString( number_of_parts ) + "\n" );
  30. for( int part_id = 0; part_id < number_of_parts; ++part_id )
  31. {
  32. GetModelPart( part_id, mesh, data, textures, export_text, 0 );
  33. }
  34. }
  35. void
  36. ModelFile::GetModelPart( const int part_id, Ogre::MeshPtr mesh, const MeshData& data, VectorTexForGen& textures, Logger* export_text, const int bone_id )
  37. {
  38. int pointer_to_part_header = 0x10 + part_id * 0x38;
  39. int number_of_poly_blocks = GetU16LE( pointer_to_part_header + 0x6 );
  40. m_PointerToVertexData = GetU32LE( pointer_to_part_header + 0x08 );
  41. m_PointerToMeshData = GetU32LE( pointer_to_part_header + 0x10 );
  42. m_PointerToTextureData = GetU32LE( pointer_to_part_header + 0x14 );
  43. m_ExportLog->Log(
  44. "Part: " + Ogre::StringConverter::toString( part_id ) + "\n" +
  45. " number of poly blocks: " + Ogre::StringConverter::toString( number_of_poly_blocks ) + "\n"
  46. " pointer to polygon data: " + Ogre::StringConverter::toString( m_PointerToMeshData ) + "\n"
  47. " pointer to texture data: " + Ogre::StringConverter::toString( m_PointerToTextureData ) + "\n"
  48. );
  49. for( int poly_block_id = 0; poly_block_id < number_of_poly_blocks; ++poly_block_id )
  50. {
  51. u8 polygon_type = GetU8(m_PointerToMeshData + 0);
  52. int number_of_polygons = GetU16LE(m_PointerToMeshData + 2);
  53. int number_of_triangles = number_of_polygons;
  54. if (polygon_type == 0x09 || polygon_type == 0x0c || polygon_type == 0x0d) // if quads
  55. {
  56. number_of_triangles *= 2;
  57. }
  58. m_PointerToMeshData += 4;
  59. m_ExportLog->Log(
  60. " polygon type: " +
  61. Ogre::StringConverter::toString(polygon_type) +
  62. ", number of polygons: " +
  63. Ogre::StringConverter::toString(number_of_polygons) +
  64. "\n"
  65. );
  66. Ogre::SubMesh* sub_mesh = mesh->createSubMesh( Ogre::StringConverter::toString( part_id ) + "_" + Ogre::StringConverter::toString( poly_block_id ) );
  67. sub_mesh->setMaterialName( "xenogears/model/" + data.name );
  68. sub_mesh->useSharedVertices = false;
  69. sub_mesh->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
  70. // Allocate and prepare vertex data
  71. sub_mesh->vertexData = new Ogre::VertexData();
  72. sub_mesh->vertexData->vertexStart = 0;
  73. sub_mesh->vertexData->vertexCount = static_cast< size_t >( number_of_triangles * 3 );
  74. // Index buffer
  75. sub_mesh->indexData = new Ogre::IndexData();
  76. sub_mesh->indexData->indexStart = 0;
  77. sub_mesh->indexData->indexCount = sub_mesh->vertexData->vertexCount;
  78. sub_mesh->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, sub_mesh->indexData->indexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
  79. u16* idata = static_cast<u16*>(sub_mesh->indexData->indexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
  80. for( int i = 0; i < sub_mesh->vertexData->vertexCount; ++i )
  81. {
  82. idata[ i ] = i;
  83. }
  84. sub_mesh->indexData->indexBuffer->unlock();
  85. Ogre::VertexDeclaration* decl = sub_mesh->vertexData->vertexDeclaration;
  86. Ogre::VertexBufferBinding* bind = sub_mesh->vertexData->vertexBufferBinding;
  87. // 1st buffer (positions)
  88. decl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
  89. Ogre::HardwareVertexBufferSharedPtr vbuf0 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(0), sub_mesh->vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
  90. bind->setBinding(0, vbuf0);
  91. float* pPos = static_cast<float*>(vbuf0->lock(Ogre::HardwareBuffer::HBL_DISCARD));
  92. // 2nd buffer (colours)
  93. decl->addElement(1, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
  94. Ogre::HardwareVertexBufferSharedPtr vbuf1 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(1), sub_mesh->vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
  95. bind->setBinding(1, vbuf1);
  96. Ogre::RGBA* cPos = static_cast<Ogre::RGBA*>(vbuf1->lock(Ogre::HardwareBuffer::HBL_DISCARD));
  97. // 3rd buffer (texture coords)
  98. decl->addElement(2, 0, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
  99. Ogre::HardwareVertexBufferSharedPtr vbuf2 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(2), sub_mesh->vertexData->vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
  100. bind->setBinding(2, vbuf2);
  101. float* tPos = static_cast<float*>(vbuf2->lock(Ogre::HardwareBuffer::HBL_DISCARD));
  102. m_LightType = 0;
  103. for (int poly_id = 0; poly_id < number_of_polygons; ++poly_id)
  104. {
  105. // textured triangle
  106. if (polygon_type == 0x01 || polygon_type == 0x03 || polygon_type == 0x05)
  107. {
  108. if (LoadPoly010305_18(pPos, tPos, cPos, data, textures) != 0)
  109. {
  110. m_PointerToMeshData += 8;
  111. m_PointerToTextureData += 8;
  112. }
  113. else
  114. {
  115. --poly_id;
  116. m_PointerToTextureData += 4;
  117. }
  118. }
  119. // monochrome triangle
  120. else if (polygon_type == 0x04)
  121. {
  122. if (LoadPoly04_18(pPos, tPos, cPos, data, textures) != 0)
  123. {
  124. m_PointerToMeshData += 8;
  125. m_PointerToTextureData += 4;
  126. }
  127. else
  128. {
  129. --poly_id;
  130. m_PointerToTextureData += 4;
  131. }
  132. }
  133. // textured quad
  134. else if( polygon_type == 0x09 || polygon_type == 0x0d )
  135. {
  136. if( LoadPoly090d_18( pPos, tPos, cPos, data, textures ) != 0 )
  137. {
  138. m_PointerToMeshData += 8;
  139. m_PointerToTextureData += 12;
  140. }
  141. else
  142. {
  143. --poly_id;
  144. m_PointerToTextureData += 4;
  145. }
  146. }
  147. // monochrome quad
  148. else if( polygon_type == 0x0c )
  149. {
  150. if( LoadPoly0c_18( pPos, tPos, cPos, data, textures ) != 0 )
  151. {
  152. m_PointerToMeshData += 8;
  153. m_PointerToTextureData += 4;
  154. }
  155. else
  156. {
  157. --poly_id;
  158. m_PointerToTextureData += 4;
  159. }
  160. }
  161. else
  162. {
  163. m_ExportLog->Log( "ERROR: polygon type \"" + Ogre::StringConverter::toString(polygon_type) + "\" not implemented.\n" );
  164. break;
  165. }
  166. }
  167. vbuf0->unlock();
  168. vbuf1->unlock();
  169. vbuf2->unlock();
  170. // Optimize index data
  171. sub_mesh->indexData->optimiseVertexCacheTriList();
  172. LOGGER->Log( "Assign bones to vertexes\n" );
  173. int vertex_number = sub_mesh->vertexData->vertexCount;
  174. for( int i = 0; i < vertex_number; ++i )
  175. {
  176. Ogre::VertexBoneAssignment vba;
  177. vba.vertexIndex = i;
  178. vba.boneIndex = bone_id;
  179. vba.weight = 1.0f;
  180. sub_mesh->addBoneAssignment( vba );
  181. }
  182. }
  183. }
  184. int
  185. ModelFile::LoadPoly010305_18( float*& pPos, float*& tPos, Ogre::RGBA*& cPos, const MeshData& info, VectorTexForGen& textures )
  186. {
  187. if (TexSettings() == 0)
  188. {
  189. return 0;
  190. }
  191. int offset_a = GetU16LE(m_PointerToMeshData + 0x0);
  192. int offset_b = GetU16LE(m_PointerToMeshData + 0x2);
  193. int offset_c = GetU16LE(m_PointerToMeshData + 0x4);
  194. Ogre::Vector3 a((s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 00),
  195. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 02),
  196. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 04));
  197. Ogre::Vector3 b((s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 00),
  198. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 02),
  199. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 04));
  200. Ogre::Vector3 c((s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 00),
  201. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 02),
  202. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 04));
  203. a /= 512;
  204. b /= 512;
  205. c /= 512;
  206. //m_ExportLog->Log(" polygon: A (" + Ogre::StringConverter::toString(a) + "), B (" + Ogre::StringConverter::toString(b) + "), C (" + Ogre::StringConverter::toString(c) + ").\n");
  207. int clut_x = (m_CurrentClut & 0x3f) * 16;
  208. int clut_y = (m_CurrentClut >> 0x6) & 0x1ff;
  209. int bpp = (m_CurrentTexPage >> 0x7) & 0x3;
  210. int vram_x = (m_CurrentTexPage & 0xf) * 64;
  211. int vram_y = ((m_CurrentTexPage & 0x10) >> 4) * 256;
  212. TexForGen texture;
  213. texture.palette_x = clut_x;
  214. texture.palette_y = clut_y;
  215. texture.texture_x = vram_x;
  216. texture.texture_y = vram_y;
  217. texture.bpp = ( BPP )bpp;
  218. AddTexture(texture, info, textures, m_ExportLog);
  219. Ogre::Vector2 at(0, 0);
  220. Ogre::Vector2 bt(0, 0);
  221. Ogre::Vector2 ct(0, 0);
  222. int x = GetU8(m_PointerToTextureData + 0x4) + texture.start_x;
  223. at.x = x / (float)info.tex_width;
  224. int y = GetU8(m_PointerToTextureData + 0x5) + texture.start_y;
  225. at.y = y / (float)info.tex_height;
  226. x = GetU8(m_PointerToTextureData + 0x6) + texture.start_x;
  227. bt.x = x / (float)info.tex_width;
  228. y = GetU8(m_PointerToTextureData + 0x7) + texture.start_y;
  229. bt.y = y / (float)info.tex_height;
  230. x = GetU8(m_PointerToTextureData + 0x0) + texture.start_x;
  231. ct.x = x / (float)info.tex_width;
  232. y = GetU8(m_PointerToTextureData + 0x1) + texture.start_y;
  233. ct.y = y / (float)info.tex_height;
  234. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  235. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  236. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  237. *tPos++ = at.x; *tPos++ = at.y;
  238. *tPos++ = ct.x; *tPos++ = ct.y;
  239. *tPos++ = bt.x; *tPos++ = bt.y;
  240. Ogre::ColourValue colour = Ogre::ColourValue(1.0f, 1.0f, 1.0f, 1.0f);
  241. Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
  242. Ogre::RGBA conv_colour;
  243. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  244. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  245. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  246. return 1;
  247. }
  248. int
  249. ModelFile::LoadPoly04_18(float*& pPos, float*& tPos, Ogre::RGBA*& cPos, const MeshData& info, VectorTexForGen& textures)
  250. {
  251. int offset_a = GetU16LE(m_PointerToMeshData + 0x0);
  252. int offset_b = GetU16LE(m_PointerToMeshData + 0x2);
  253. int offset_c = GetU16LE(m_PointerToMeshData + 0x4);
  254. Ogre::Vector3 a((s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 00),
  255. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 02),
  256. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 04));
  257. Ogre::Vector3 b((s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 00),
  258. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 02),
  259. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 04));
  260. Ogre::Vector3 c((s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 00),
  261. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 02),
  262. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 04));
  263. a /= 512;
  264. b /= 512;
  265. c /= 512;
  266. //m_ExportLog->Log(" polygon: A (" + Ogre::StringConverter::toString(a) + "), B (" + Ogre::StringConverter::toString(b) + "), C (" + Ogre::StringConverter::toString(c) + ").\n");
  267. Ogre::Vector2 at(0, 0);
  268. Ogre::Vector2 bt(0, 0);
  269. Ogre::Vector2 ct(0, 0);
  270. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  271. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  272. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  273. *tPos++ = at.x; *tPos++ = at.y;
  274. *tPos++ = ct.x; *tPos++ = ct.y;
  275. *tPos++ = bt.x; *tPos++ = bt.y;
  276. Ogre::ColourValue colour = Ogre::ColourValue(GetU8(m_PointerToTextureData + 0x0) / 255.0f, GetU8(m_PointerToTextureData + 0x1) / 255.0f, GetU8(m_PointerToTextureData + 0x2) / 255.0f, 1.0f);
  277. Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
  278. Ogre::RGBA conv_colour;
  279. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  280. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  281. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  282. return 1;
  283. }
  284. int
  285. ModelFile::LoadPoly090d_18(float*& pPos, float*& tPos, Ogre::RGBA*& cPos, const MeshData& info, VectorTexForGen& textures)
  286. {
  287. if (TexSettings() == 0)
  288. {
  289. return 0;
  290. }
  291. int offset_a = GetU16LE(m_PointerToMeshData + 0x0);
  292. int offset_b = GetU16LE(m_PointerToMeshData + 0x2);
  293. int offset_c = GetU16LE(m_PointerToMeshData + 0x4);
  294. int offset_d = GetU16LE(m_PointerToMeshData + 0x6);
  295. Ogre::Vector3 a((s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 00),
  296. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 02),
  297. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 04));
  298. Ogre::Vector3 b((s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 00),
  299. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 02),
  300. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 04));
  301. Ogre::Vector3 c((s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 00),
  302. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 02),
  303. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 04));
  304. Ogre::Vector3 d((s16)GetU16LE(m_PointerToVertexData + offset_d * 0x8 + 00),
  305. (s16)GetU16LE(m_PointerToVertexData + offset_d * 0x8 + 02),
  306. (s16)GetU16LE(m_PointerToVertexData + offset_d * 0x8 + 04));
  307. a /= 512;
  308. b /= 512;
  309. c /= 512;
  310. d /= 512;
  311. //m_ExportLog->Log(" polygon: A (" + Ogre::StringConverter::toString(a) + "), B (" + Ogre::StringConverter::toString(b) + "), C (" + Ogre::StringConverter::toString(c) + "), D (" + Ogre::StringConverter::toString(d) + ").\n");
  312. int clut_x = (m_CurrentClut & 0x3f) * 16;
  313. int clut_y = (m_CurrentClut >> 0x6) & 0x1ff;
  314. int bpp = (m_CurrentTexPage >> 0x7) & 0x3;
  315. int vram_x = (m_CurrentTexPage & 0xf) * 64;
  316. int vram_y = ((m_CurrentTexPage & 0x10) >> 4) * 256;
  317. TexForGen texture;
  318. texture.palette_x = clut_x;
  319. texture.palette_y = clut_y;
  320. texture.texture_x = vram_x;
  321. texture.texture_y = vram_y;
  322. texture.bpp = ( BPP )bpp;
  323. AddTexture(texture, info, textures, m_ExportLog);
  324. Ogre::Vector2 at(0, 0);
  325. Ogre::Vector2 bt(0, 0);
  326. Ogre::Vector2 ct(0, 0);
  327. Ogre::Vector2 dt(0, 0);
  328. int x = GetU8(m_PointerToTextureData + 0x4) + texture.start_x;
  329. at.x = x / (float)info.tex_width;
  330. int y = GetU8(m_PointerToTextureData + 0x5) + texture.start_y;
  331. at.y = y / (float)info.tex_height;
  332. x = GetU8(m_PointerToTextureData + 0x6) + texture.start_x;
  333. bt.x = x / (float)info.tex_width;
  334. y = GetU8(m_PointerToTextureData + 0x7) + texture.start_y;
  335. bt.y = y / (float)info.tex_height;
  336. x = GetU8(m_PointerToTextureData + 0x8) + texture.start_x;
  337. ct.x = x / (float)info.tex_width;
  338. y = GetU8(m_PointerToTextureData + 0x9) + texture.start_y;
  339. ct.y = y / (float)info.tex_height;
  340. x = GetU8(m_PointerToTextureData + 0xa) + texture.start_x;
  341. dt.x = x / (float)info.tex_width;
  342. y = GetU8(m_PointerToTextureData + 0xb) + texture.start_y;
  343. dt.y = y / (float)info.tex_height;
  344. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  345. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  346. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  347. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  348. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  349. *pPos++ = d.x; *pPos++ = d.y; *pPos++ = d.z;
  350. *tPos++ = at.x; *tPos++ = at.y;
  351. *tPos++ = ct.x; *tPos++ = ct.y;
  352. *tPos++ = bt.x; *tPos++ = bt.y;
  353. *tPos++ = bt.x; *tPos++ = bt.y;
  354. *tPos++ = ct.x; *tPos++ = ct.y;
  355. *tPos++ = dt.x; *tPos++ = dt.y;
  356. Ogre::ColourValue colour = Ogre::ColourValue(1.0f, 1.0f, 1.0f, 1.0f);
  357. Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
  358. Ogre::RGBA conv_colour;
  359. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  360. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  361. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  362. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  363. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  364. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  365. return 1;
  366. }
  367. int
  368. ModelFile::LoadPoly0c_18(float*& pPos, float*& tPos, Ogre::RGBA*& cPos, const MeshData& info, VectorTexForGen& textures)
  369. {
  370. int offset_a = GetU16LE(m_PointerToMeshData + 0x0);
  371. int offset_b = GetU16LE(m_PointerToMeshData + 0x2);
  372. int offset_c = GetU16LE(m_PointerToMeshData + 0x4);
  373. int offset_d = GetU16LE(m_PointerToMeshData + 0x6);
  374. Ogre::Vector3 a((s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 00),
  375. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 02),
  376. (s16)GetU16LE(m_PointerToVertexData + offset_a * 0x8 + 04));
  377. Ogre::Vector3 b((s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 00),
  378. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 02),
  379. (s16)GetU16LE(m_PointerToVertexData + offset_b * 0x8 + 04));
  380. Ogre::Vector3 c((s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 00),
  381. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 02),
  382. (s16)GetU16LE(m_PointerToVertexData + offset_c * 0x8 + 04));
  383. Ogre::Vector3 d((s16)GetU16LE(m_PointerToVertexData + offset_d * 0x8 + 00),
  384. (s16)GetU16LE(m_PointerToVertexData + offset_d * 0x8 + 02),
  385. (s16)GetU16LE(m_PointerToVertexData + offset_d * 0x8 + 04));
  386. a /= 512;
  387. b /= 512;
  388. c /= 512;
  389. d /= 512;
  390. //m_ExportLog->Log(" polygon: A (" + Ogre::StringConverter::toString(a) + "), B (" + Ogre::StringConverter::toString(b) + "), C (" + Ogre::StringConverter::toString(c) + "), D (" + Ogre::StringConverter::toString(d) + ").\n");
  391. Ogre::Vector2 at(0, 0);
  392. Ogre::Vector2 bt(0, 0);
  393. Ogre::Vector2 ct(0, 0);
  394. Ogre::Vector2 dt(0, 0);
  395. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  396. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  397. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  398. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  399. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  400. *pPos++ = d.x; *pPos++ = d.y; *pPos++ = d.z;
  401. *tPos++ = at.x; *tPos++ = at.y;
  402. *tPos++ = ct.x; *tPos++ = ct.y;
  403. *tPos++ = bt.x; *tPos++ = bt.y;
  404. *tPos++ = bt.x; *tPos++ = bt.y;
  405. *tPos++ = ct.x; *tPos++ = ct.y;
  406. *tPos++ = dt.x; *tPos++ = dt.y;
  407. Ogre::ColourValue colour = Ogre::ColourValue(GetU8(m_PointerToTextureData + 0x0) / 255.0f, GetU8(m_PointerToTextureData + 0x1) / 255.0f, GetU8(m_PointerToTextureData + 0x2) / 255.0f, 1.0f);
  408. Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
  409. Ogre::RGBA conv_colour;
  410. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  411. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  412. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  413. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  414. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  415. rs->convertColourValue(colour, &conv_colour); *cPos++ = conv_colour;
  416. return 1;
  417. }
  418. int
  419. ModelFile::TexSettings()
  420. {
  421. int tex_settings = GetU8(m_PointerToTextureData + 0x3);
  422. if (tex_settings == 0xc4)
  423. {
  424. SetTexPageSettings();
  425. return 0;
  426. }
  427. if (tex_settings == 0xc8)
  428. {
  429. SetClutSettings();
  430. return 0;
  431. }
  432. return 1;
  433. }
  434. void
  435. ModelFile::SetTexPageSettings()
  436. {
  437. //m_ExportLog->Log(" Tex page settings values 0x" + ToHexString(GetU16LE(m_PointerToTextureData), 4, '0') + ".\n");
  438. m_CurrentTexPage = GetU16LE(m_PointerToTextureData);
  439. /*
  440. if (w[8004f7ac] == 1)
  441. {
  442. m_CurrentTexPage = h(w[800589b0] | (hu[[800589a8]] & ffe0));
  443. }
  444. else if (V1 == 2)
  445. {
  446. m_CurrentTexPage = h(w[800589b0]);
  447. }
  448. */
  449. }
  450. void
  451. ModelFile::SetClutSettings()
  452. {
  453. //m_ExportLog->Log(" Clut settings values 0x" + ToHexString(GetU16LE(m_PointerToTextureData), 4, '0') + ".\n");
  454. m_CurrentClut = GetU16LE(m_PointerToTextureData);
  455. /*
  456. [800589ac] = h(hu[A0 + 0]);
  457. if (w[8004f7b0] == 0)
  458. {
  459. m_CurrentClut = h(w[800589b4] | (hu[[800589ac]] & 000f));
  460. }
  461. */
  462. }