MeshExtractor.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. #include "MeshExtractor.h"
  2. #define POSITION_BINDING 0
  3. #define COLOUR_BINDING 1
  4. #define TEXTURE_BINDING 2
  5. #include "../../common/Logger.h"
  6. #include "../../common/OgreGenUtilites.h"
  7. void
  8. MeshExtractor( const MeshData& mesh_data, const Ogre::String& material_name, File* file, int offset_to_data, VectorTexForGen& textures, const Ogre::MeshPtr& mesh, const Ogre::String& name, int bone_id )
  9. {
  10. int offset_to_vertex = offset_to_data;
  11. int offset_to_triangle_t = offset_to_vertex + 0x04 + file->GetU32LE( offset_to_vertex );
  12. int number_of_triangle_t = file->GetU16LE( offset_to_triangle_t );
  13. u16 tpage = file->GetU16LE( offset_to_triangle_t + 0x02 );
  14. int offset_to_quad_t = offset_to_triangle_t + 0x04 + number_of_triangle_t * 0x10;
  15. int number_of_quad_t = file->GetU16LE( offset_to_quad_t );
  16. int offset_to_triangle = offset_to_quad_t + 0x4 + number_of_quad_t * 0x14;
  17. int number_of_triangle = file->GetU16LE( offset_to_triangle );
  18. int offset_to_quad = offset_to_triangle + 0x4 + number_of_triangle * 0x14;
  19. int number_of_quad = file->GetU16LE( offset_to_quad );
  20. Ogre::SubMesh* sub_mesh = mesh->createSubMesh( name );
  21. sub_mesh->setMaterialName( material_name );
  22. sub_mesh->useSharedVertices = false;
  23. sub_mesh->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
  24. // Allocate and prepare vertex data
  25. sub_mesh->vertexData = new Ogre::VertexData();
  26. sub_mesh->vertexData->vertexStart = 0;
  27. sub_mesh->vertexData->vertexCount = static_cast< size_t >( number_of_triangle_t * 3 + number_of_quad_t * 6 + number_of_triangle * 3 + number_of_quad * 6 );
  28. sub_mesh->indexData = new Ogre::IndexData();
  29. sub_mesh->indexData->indexStart = 0;
  30. sub_mesh->indexData->indexCount = sub_mesh->vertexData->vertexCount;
  31. sub_mesh->indexData->indexBuffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
  32. Ogre::HardwareIndexBuffer::IT_16BIT,
  33. sub_mesh->indexData->indexCount,
  34. Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
  35. u16* idata = static_cast< u16* >( sub_mesh->indexData->indexBuffer->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
  36. u32 cur_index = 0;
  37. Ogre::VertexDeclaration* decl = sub_mesh->vertexData->vertexDeclaration;
  38. Ogre::VertexBufferBinding* bind = sub_mesh->vertexData->vertexBufferBinding;
  39. // 1st buffer
  40. decl->addElement( POSITION_BINDING, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION );
  41. Ogre::HardwareVertexBufferSharedPtr vbuf0 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
  42. decl->getVertexSize( POSITION_BINDING ),
  43. sub_mesh->vertexData->vertexCount,
  44. Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
  45. bind->setBinding( POSITION_BINDING, vbuf0 );
  46. // 2nd buffer
  47. decl->addElement( COLOUR_BINDING, 0, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE );
  48. Ogre::HardwareVertexBufferSharedPtr vbuf1 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
  49. decl->getVertexSize( COLOUR_BINDING ),
  50. sub_mesh->vertexData->vertexCount,
  51. Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
  52. // Set vertex buffer binding so buffer 1 is bound to our colour buffer
  53. bind->setBinding( COLOUR_BINDING, vbuf1 );
  54. // 3rd buffer
  55. decl->addElement( TEXTURE_BINDING, 0, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0 );
  56. Ogre::HardwareVertexBufferSharedPtr vbuf2 = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
  57. decl->getVertexSize( TEXTURE_BINDING ),
  58. sub_mesh->vertexData->vertexCount,
  59. Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY );
  60. bind->setBinding( TEXTURE_BINDING, vbuf2 );
  61. float* pPos = static_cast< float* >( vbuf0->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
  62. float* tPos = static_cast< float* >( vbuf2->lock( Ogre::HardwareBuffer::HBL_DISCARD ) );
  63. Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
  64. std::vector<Ogre::RGBA> coloursVec(sub_mesh->vertexData->vertexCount);
  65. Ogre::RGBA* colours = coloursVec.data();
  66. // add textured triangle
  67. for (int j = 0; j < number_of_triangle_t; ++j)
  68. {
  69. int offset_a = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0x0);
  70. int offset_b = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0x2);
  71. int offset_c = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0x4);
  72. Ogre::Vector3 a((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 00),
  73. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 02),
  74. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 04));
  75. Ogre::Vector3 b((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 00),
  76. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 02),
  77. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 04));
  78. Ogre::Vector3 c((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 00),
  79. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 02),
  80. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 04));
  81. a /= 512;
  82. b /= 512;
  83. c /= 512;
  84. u16 clut = file->GetU16LE(offset_to_triangle_t + 0x4 + j * 0x10 + 0xa);
  85. int clut_x = (clut & 0x003f) << 3;
  86. int clut_y = (clut & 0xffc0) >> 6;
  87. int bpp = (tpage >> 0x7) & 0x3;
  88. int vram_x = (tpage & 0xf) * 64;
  89. int vram_y = ((tpage & 0x10) >> 4) * 256;
  90. TexForGen texture;
  91. texture.palette_x = clut_x;
  92. texture.palette_y = clut_y;
  93. texture.texture_x = vram_x;
  94. texture.texture_y = vram_y;
  95. texture.bpp = ( BPP )bpp;
  96. AddTexture( texture, mesh_data, textures, LOGGER );
  97. Ogre::Vector2 at(0, 0);
  98. Ogre::Vector2 bt(0, 0);
  99. Ogre::Vector2 ct(0, 0);
  100. int x = file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0x8) + texture.start_x;
  101. at.x = x / (float)mesh_data.tex_width;
  102. int y = file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0x9) + texture.start_y;
  103. at.y = y / (float)mesh_data.tex_height;
  104. x = file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0xc) + texture.start_x;
  105. bt.x = x / (float)mesh_data.tex_width;
  106. y = file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0xd) + texture.start_y;
  107. bt.y = y / (float)mesh_data.tex_height;
  108. x = file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0xe) + texture.start_x;
  109. ct.x = x / (float)mesh_data.tex_width;
  110. y = file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0xf) + texture.start_y;
  111. ct.y = y / (float)mesh_data.tex_height;
  112. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  113. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  114. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  115. *tPos++ = at.x; *tPos++ = at.y;
  116. *tPos++ = ct.x; *tPos++ = ct.y;
  117. *tPos++ = bt.x; *tPos++ = bt.y;
  118. Ogre::ColourValue colour = Ogre::ColourValue(file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0x6) / 256.0f,
  119. file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0x6) / 256.0f,
  120. file->GetU8(offset_to_triangle_t + 0x4 + j * 0x10 + 0x6) / 256.0f,
  121. 1.0f);
  122. rs->convertColourValue(colour, colours + cur_index + 0);
  123. rs->convertColourValue(colour, colours + cur_index + 1);
  124. rs->convertColourValue(colour, colours + cur_index + 2);
  125. idata[cur_index + 0] = cur_index + 0;
  126. idata[cur_index + 1] = cur_index + 1;
  127. idata[cur_index + 2] = cur_index + 2;
  128. cur_index += 3;
  129. }
  130. // add textured quad
  131. for (int j = 0; j < number_of_quad_t; ++j)
  132. {
  133. int offset_a = file->GetU16LE(offset_to_quad_t + 0x4 + j * 0x14 + 0x0);
  134. int offset_b = file->GetU16LE(offset_to_quad_t + 0x4 + j * 0x14 + 0x2);
  135. int offset_c = file->GetU16LE(offset_to_quad_t + 0x4 + j * 0x14 + 0x4);
  136. int offset_d = file->GetU16LE(offset_to_quad_t + 0x4 + j * 0x14 + 0x6);
  137. Ogre::Vector3 a((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 00),
  138. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 02),
  139. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 04));
  140. Ogre::Vector3 b((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 00),
  141. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 02),
  142. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 04));
  143. Ogre::Vector3 c((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 00),
  144. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 02),
  145. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 04));
  146. Ogre::Vector3 d((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_d + 00),
  147. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_d + 02),
  148. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_d + 04));
  149. a /= 512;
  150. b /= 512;
  151. c /= 512;
  152. d /= 512;
  153. u16 clut = file->GetU16LE(offset_to_quad_t + 0x4 + j * 0x14 + 0xa);
  154. int clut_x = (clut & 0x003f) << 3;
  155. int clut_y = (clut & 0xffc0) >> 6;
  156. int bpp = (tpage >> 0x7) & 0x3;
  157. int vram_x = (tpage & 0xf) * 64;
  158. int vram_y = ((tpage & 0x10) >> 4) * 256;
  159. TexForGen texture;
  160. texture.palette_x = clut_x;
  161. texture.palette_y = clut_y;
  162. texture.texture_x = vram_x;
  163. texture.texture_y = vram_y;
  164. texture.bpp = ( BPP )bpp;
  165. AddTexture( texture, mesh_data, textures, LOGGER );
  166. Ogre::Vector2 at(0, 0);
  167. Ogre::Vector2 bt(0, 0);
  168. Ogre::Vector2 ct(0, 0);
  169. Ogre::Vector2 dt(0, 0);
  170. int x = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0x8) + texture.start_x;
  171. at.x = x / (float)mesh_data.tex_width;
  172. int y = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0x9) + texture.start_y;
  173. at.y = y / (float)mesh_data.tex_height;
  174. x = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0xc) + texture.start_x;
  175. bt.x = x / (float)mesh_data.tex_width;
  176. y = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0xd) + texture.start_y;
  177. bt.y = y / (float)mesh_data.tex_height;
  178. x = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0xe) + texture.start_x;
  179. ct.x = x / (float)mesh_data.tex_width;
  180. y = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0xf) + texture.start_y;
  181. ct.y = y / (float)mesh_data.tex_height;
  182. x = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0x10) + texture.start_x;
  183. dt.x = x / (float)mesh_data.tex_width;
  184. y = file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0x11) + texture.start_y;
  185. dt.y = y / (float)mesh_data.tex_height;
  186. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  187. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  188. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  189. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  190. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  191. *pPos++ = d.x; *pPos++ = d.y; *pPos++ = d.z;
  192. *tPos++ = at.x; *tPos++ = at.y;
  193. *tPos++ = ct.x; *tPos++ = ct.y;
  194. *tPos++ = bt.x; *tPos++ = bt.y;
  195. *tPos++ = bt.x; *tPos++ = bt.y;
  196. *tPos++ = ct.x; *tPos++ = ct.y;
  197. *tPos++ = dt.x; *tPos++ = dt.y;
  198. Ogre::ColourValue colour = Ogre::ColourValue(file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0x12) / 256.0f,
  199. file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0x12) / 256.0f,
  200. file->GetU8(offset_to_quad_t + 0x4 + j * 0x14 + 0x12) / 256.0f,
  201. 1.0f);
  202. rs->convertColourValue(colour, colours + cur_index + 0);
  203. rs->convertColourValue(colour, colours + cur_index + 1);
  204. rs->convertColourValue(colour, colours + cur_index + 2);
  205. rs->convertColourValue(colour, colours + cur_index + 3);
  206. rs->convertColourValue(colour, colours + cur_index + 4);
  207. rs->convertColourValue(colour, colours + cur_index + 5);
  208. idata[cur_index + 0] = cur_index + 0;
  209. idata[cur_index + 1] = cur_index + 1;
  210. idata[cur_index + 2] = cur_index + 2;
  211. idata[cur_index + 3] = cur_index + 3;
  212. idata[cur_index + 4] = cur_index + 4;
  213. idata[cur_index + 5] = cur_index + 5;
  214. cur_index += 6;
  215. }
  216. // add color triangle
  217. for (int j = 0; j < number_of_triangle; ++j)
  218. {
  219. int offset_a = file->GetU16LE(offset_to_triangle + 0x4 + j * 0x14 + 0x0);
  220. int offset_b = file->GetU16LE(offset_to_triangle + 0x4 + j * 0x14 + 0x2);
  221. int offset_c = file->GetU16LE(offset_to_triangle + 0x4 + j * 0x14 + 0x4);
  222. Ogre::Vector3 a((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 00),
  223. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 02),
  224. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 04));
  225. Ogre::Vector3 b((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 00),
  226. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 02),
  227. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 04));
  228. Ogre::Vector3 c((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 00),
  229. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 02),
  230. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 04));
  231. a /= 512;
  232. b /= 512;
  233. c /= 512;
  234. TexForGen texture;
  235. texture.palette_x = 0;
  236. texture.palette_y = 0;
  237. texture.texture_x = 0;
  238. texture.texture_y = 0;
  239. texture.bpp = BPP_BLACK;
  240. AddTexture( texture, mesh_data, textures, LOGGER );
  241. Ogre::Vector2 at(0, 0);
  242. Ogre::Vector2 bt(0, 0);
  243. Ogre::Vector2 ct(0, 0);
  244. at.x = bt.x = ct.x = texture.start_x / (float)mesh_data.tex_width;
  245. at.y = bt.y = ct.y = texture.start_y / (float)mesh_data.tex_height;
  246. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  247. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  248. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  249. *tPos++ = at.x; *tPos++ = at.y;
  250. *tPos++ = ct.x; *tPos++ = ct.y;
  251. *tPos++ = bt.x; *tPos++ = bt.y;
  252. Ogre::ColourValue a_colour = Ogre::ColourValue(file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x08) / 256.0f,
  253. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x09) / 256.0f,
  254. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x0a) / 256.0f,
  255. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x0b) / 256.0f);
  256. Ogre::ColourValue b_colour = Ogre::ColourValue(file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x0c) / 256.0f,
  257. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x0d) / 256.0f,
  258. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x0e) / 256.0f,
  259. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x0f) / 256.0f);
  260. Ogre::ColourValue c_colour = Ogre::ColourValue(file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x10) / 256.0f,
  261. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x11) / 256.0f,
  262. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x12) / 256.0f,
  263. file->GetU8(offset_to_triangle + 0x4 + j * 0x14 + 0x13) / 256.0f);
  264. rs->convertColourValue(a_colour, colours + cur_index + 0);
  265. rs->convertColourValue(c_colour, colours + cur_index + 1);
  266. rs->convertColourValue(b_colour, colours + cur_index + 2);
  267. idata[cur_index + 0] = cur_index + 0;
  268. idata[cur_index + 1] = cur_index + 1;
  269. idata[cur_index + 2] = cur_index + 2;
  270. cur_index += 3;
  271. }
  272. // add color quad
  273. for (int j = 0; j < number_of_quad; ++j)
  274. {
  275. int offset_a = file->GetU16LE(offset_to_quad + 0x4 + j * 0x18 + 0x0);
  276. int offset_b = file->GetU16LE(offset_to_quad + 0x4 + j * 0x18 + 0x2);
  277. int offset_c = file->GetU16LE(offset_to_quad + 0x4 + j * 0x18 + 0x4);
  278. int offset_d = file->GetU16LE(offset_to_quad + 0x4 + j * 0x18 + 0x6);
  279. Ogre::Vector3 a((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 00),
  280. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 02),
  281. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_a + 04));
  282. Ogre::Vector3 b((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 00),
  283. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 02),
  284. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_b + 04));
  285. Ogre::Vector3 c((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 00),
  286. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 02),
  287. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_c + 04));
  288. Ogre::Vector3 d((s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_d + 00),
  289. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_d + 02),
  290. (s16)file->GetU16LE(offset_to_vertex + 0x04 + offset_d + 04));
  291. a /= 512;
  292. b /= 512;
  293. c /= 512;
  294. d /= 512;
  295. TexForGen texture;
  296. texture.palette_x = 0;
  297. texture.palette_y = 0;
  298. texture.texture_x = 0;
  299. texture.texture_y = 0;
  300. texture.bpp = BPP_BLACK;
  301. AddTexture( texture, mesh_data, textures, LOGGER );
  302. Ogre::Vector2 at(0, 0);
  303. Ogre::Vector2 bt(0, 0);
  304. Ogre::Vector2 ct(0, 0);
  305. Ogre::Vector2 dt(0, 0);
  306. at.x = bt.x = ct.x = dt.x = texture.start_x / (float)mesh_data.tex_width;
  307. at.y = bt.y = ct.y = dt.y = texture.start_y / (float)mesh_data.tex_height;
  308. *pPos++ = a.x; *pPos++ = a.y; *pPos++ = a.z;
  309. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  310. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  311. *pPos++ = b.x; *pPos++ = b.y; *pPos++ = b.z;
  312. *pPos++ = c.x; *pPos++ = c.y; *pPos++ = c.z;
  313. *pPos++ = d.x; *pPos++ = d.y; *pPos++ = d.z;
  314. *tPos++ = at.x; *tPos++ = at.y;
  315. *tPos++ = ct.x; *tPos++ = ct.y;
  316. *tPos++ = bt.x; *tPos++ = bt.y;
  317. *tPos++ = bt.x; *tPos++ = bt.y;
  318. *tPos++ = ct.x; *tPos++ = ct.y;
  319. *tPos++ = dt.x; *tPos++ = dt.y;
  320. Ogre::ColourValue a_colour = Ogre::ColourValue(file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x08) / 256.0f,
  321. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x09) / 256.0f,
  322. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x0a) / 256.0f,
  323. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x0b) / 256.0f);
  324. Ogre::ColourValue b_colour = Ogre::ColourValue(file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x0c) / 256.0f,
  325. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x0d) / 256.0f,
  326. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x0e) / 256.0f,
  327. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x0f) / 256.0f);
  328. Ogre::ColourValue c_colour = Ogre::ColourValue(file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x10) / 256.0f,
  329. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x11) / 256.0f,
  330. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x12) / 256.0f,
  331. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x13) / 256.0f);
  332. Ogre::ColourValue d_colour = Ogre::ColourValue(file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x14) / 256.0f,
  333. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x15) / 256.0f,
  334. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x16) / 256.0f,
  335. file->GetU8(offset_to_quad + 0x4 + j * 0x18 + 0x17) / 256.0f);
  336. rs->convertColourValue(a_colour, colours + cur_index + 0);
  337. rs->convertColourValue(c_colour, colours + cur_index + 1);
  338. rs->convertColourValue(b_colour, colours + cur_index + 2);
  339. rs->convertColourValue(b_colour, colours + cur_index + 3);
  340. rs->convertColourValue(c_colour, colours + cur_index + 4);
  341. rs->convertColourValue(d_colour, colours + cur_index + 5);
  342. idata[cur_index + 0] = cur_index + 0;
  343. idata[cur_index + 1] = cur_index + 1;
  344. idata[cur_index + 2] = cur_index + 2;
  345. idata[cur_index + 3] = cur_index + 3;
  346. idata[cur_index + 4] = cur_index + 4;
  347. idata[cur_index + 5] = cur_index + 5;
  348. cur_index += 6;
  349. }
  350. vbuf0->unlock();
  351. vbuf1->writeData(0, vbuf1->getSizeInBytes(), colours, true);
  352. vbuf2->unlock();
  353. sub_mesh->indexData->indexBuffer->unlock();
  354. // Optimize index data
  355. sub_mesh->indexData->optimiseVertexCacheTriList();
  356. if (bone_id != -1)
  357. {
  358. LOGGER->Log("Assign bones to vertexes\n");
  359. int vertex_number = sub_mesh->vertexData->vertexCount;
  360. for( int i = 0; i < vertex_number; ++i )
  361. {
  362. Ogre::VertexBoneAssignment vba;
  363. vba.vertexIndex = i;
  364. vba.boneIndex = bone_id;
  365. vba.weight = 1.0f;
  366. sub_mesh->addBoneAssignment( vba );
  367. }
  368. }
  369. }