mesh.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "mesh.h"
  17. #include "debug.h"
  18. #include "log.h"
  19. #include <cmath>
  20. #include <iostream>
  21. #include <IAnimatedMesh.h>
  22. #include <SAnimatedMesh.h>
  23. #include <IAnimatedMeshSceneNode.h>
  24. inline static void applyShadeFactor(video::SColor& color, float factor)
  25. {
  26. color.setRed(core::clamp(core::round32(color.getRed()*factor), 0, 255));
  27. color.setGreen(core::clamp(core::round32(color.getGreen()*factor), 0, 255));
  28. color.setBlue(core::clamp(core::round32(color.getBlue()*factor), 0, 255));
  29. }
  30. void applyFacesShading(video::SColor &color, const v3f &normal)
  31. {
  32. /*
  33. Some drawtypes have normals set to (0, 0, 0), this must result in
  34. maximum brightness: shade factor 1.0.
  35. Shade factors for aligned cube faces are:
  36. +Y 1.000000 sqrt(1.0)
  37. -Y 0.447213 sqrt(0.2)
  38. +-X 0.670820 sqrt(0.45)
  39. +-Z 0.836660 sqrt(0.7)
  40. */
  41. float x2 = normal.X * normal.X;
  42. float y2 = normal.Y * normal.Y;
  43. float z2 = normal.Z * normal.Z;
  44. if (normal.Y < 0)
  45. applyShadeFactor(color, 0.670820f * x2 + 0.447213f * y2 + 0.836660f * z2);
  46. else if ((x2 > 1e-3) || (z2 > 1e-3))
  47. applyShadeFactor(color, 0.670820f * x2 + 1.000000f * y2 + 0.836660f * z2);
  48. }
  49. scene::IAnimatedMesh* createCubeMesh(v3f scale)
  50. {
  51. video::SColor c(255,255,255,255);
  52. video::S3DVertex vertices[24] =
  53. {
  54. // Up
  55. video::S3DVertex(-0.5,+0.5,-0.5, 0,1,0, c, 0,1),
  56. video::S3DVertex(-0.5,+0.5,+0.5, 0,1,0, c, 0,0),
  57. video::S3DVertex(+0.5,+0.5,+0.5, 0,1,0, c, 1,0),
  58. video::S3DVertex(+0.5,+0.5,-0.5, 0,1,0, c, 1,1),
  59. // Down
  60. video::S3DVertex(-0.5,-0.5,-0.5, 0,-1,0, c, 0,0),
  61. video::S3DVertex(+0.5,-0.5,-0.5, 0,-1,0, c, 1,0),
  62. video::S3DVertex(+0.5,-0.5,+0.5, 0,-1,0, c, 1,1),
  63. video::S3DVertex(-0.5,-0.5,+0.5, 0,-1,0, c, 0,1),
  64. // Right
  65. video::S3DVertex(+0.5,-0.5,-0.5, 1,0,0, c, 0,1),
  66. video::S3DVertex(+0.5,+0.5,-0.5, 1,0,0, c, 0,0),
  67. video::S3DVertex(+0.5,+0.5,+0.5, 1,0,0, c, 1,0),
  68. video::S3DVertex(+0.5,-0.5,+0.5, 1,0,0, c, 1,1),
  69. // Left
  70. video::S3DVertex(-0.5,-0.5,-0.5, -1,0,0, c, 1,1),
  71. video::S3DVertex(-0.5,-0.5,+0.5, -1,0,0, c, 0,1),
  72. video::S3DVertex(-0.5,+0.5,+0.5, -1,0,0, c, 0,0),
  73. video::S3DVertex(-0.5,+0.5,-0.5, -1,0,0, c, 1,0),
  74. // Back
  75. video::S3DVertex(-0.5,-0.5,+0.5, 0,0,1, c, 1,1),
  76. video::S3DVertex(+0.5,-0.5,+0.5, 0,0,1, c, 0,1),
  77. video::S3DVertex(+0.5,+0.5,+0.5, 0,0,1, c, 0,0),
  78. video::S3DVertex(-0.5,+0.5,+0.5, 0,0,1, c, 1,0),
  79. // Front
  80. video::S3DVertex(-0.5,-0.5,-0.5, 0,0,-1, c, 0,1),
  81. video::S3DVertex(-0.5,+0.5,-0.5, 0,0,-1, c, 0,0),
  82. video::S3DVertex(+0.5,+0.5,-0.5, 0,0,-1, c, 1,0),
  83. video::S3DVertex(+0.5,-0.5,-0.5, 0,0,-1, c, 1,1),
  84. };
  85. u16 indices[6] = {0,1,2,2,3,0};
  86. scene::SMesh *mesh = new scene::SMesh();
  87. for (u32 i=0; i<6; ++i)
  88. {
  89. scene::IMeshBuffer *buf = new scene::SMeshBuffer();
  90. buf->append(vertices + 4 * i, 4, indices, 6);
  91. // Set default material
  92. buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
  93. buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
  94. buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
  95. // Add mesh buffer to mesh
  96. mesh->addMeshBuffer(buf);
  97. buf->drop();
  98. }
  99. scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
  100. mesh->drop();
  101. scaleMesh(anim_mesh, scale); // also recalculates bounding box
  102. return anim_mesh;
  103. }
  104. void scaleMesh(scene::IMesh *mesh, v3f scale)
  105. {
  106. if (mesh == NULL)
  107. return;
  108. aabb3f bbox;
  109. bbox.reset(0, 0, 0);
  110. u32 mc = mesh->getMeshBufferCount();
  111. for (u32 j = 0; j < mc; j++) {
  112. scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
  113. const u32 stride = getVertexPitchFromType(buf->getVertexType());
  114. u32 vertex_count = buf->getVertexCount();
  115. u8 *vertices = (u8 *)buf->getVertices();
  116. for (u32 i = 0; i < vertex_count; i++)
  117. ((video::S3DVertex *)(vertices + i * stride))->Pos *= scale;
  118. buf->recalculateBoundingBox();
  119. // calculate total bounding box
  120. if (j == 0)
  121. bbox = buf->getBoundingBox();
  122. else
  123. bbox.addInternalBox(buf->getBoundingBox());
  124. }
  125. mesh->setBoundingBox(bbox);
  126. }
  127. void translateMesh(scene::IMesh *mesh, v3f vec)
  128. {
  129. if (mesh == NULL)
  130. return;
  131. aabb3f bbox;
  132. bbox.reset(0, 0, 0);
  133. u32 mc = mesh->getMeshBufferCount();
  134. for (u32 j = 0; j < mc; j++) {
  135. scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
  136. const u32 stride = getVertexPitchFromType(buf->getVertexType());
  137. u32 vertex_count = buf->getVertexCount();
  138. u8 *vertices = (u8 *)buf->getVertices();
  139. for (u32 i = 0; i < vertex_count; i++)
  140. ((video::S3DVertex *)(vertices + i * stride))->Pos += vec;
  141. buf->recalculateBoundingBox();
  142. // calculate total bounding box
  143. if (j == 0)
  144. bbox = buf->getBoundingBox();
  145. else
  146. bbox.addInternalBox(buf->getBoundingBox());
  147. }
  148. mesh->setBoundingBox(bbox);
  149. }
  150. void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color)
  151. {
  152. const u32 stride = getVertexPitchFromType(buf->getVertexType());
  153. u32 vertex_count = buf->getVertexCount();
  154. u8 *vertices = (u8 *) buf->getVertices();
  155. for (u32 i = 0; i < vertex_count; i++)
  156. ((video::S3DVertex *) (vertices + i * stride))->Color = color;
  157. }
  158. void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color)
  159. {
  160. for (u32 i = 0; i < node->getMaterialCount(); ++i) {
  161. node->getMaterial(i).EmissiveColor = color;
  162. }
  163. }
  164. void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
  165. {
  166. if (mesh == NULL)
  167. return;
  168. u32 mc = mesh->getMeshBufferCount();
  169. for (u32 j = 0; j < mc; j++)
  170. setMeshBufferColor(mesh->getMeshBuffer(j), color);
  171. }
  172. void setMeshBufferTextureCoords(scene::IMeshBuffer *buf, const v2f *uv, u32 count)
  173. {
  174. const u32 stride = getVertexPitchFromType(buf->getVertexType());
  175. assert(buf->getVertexCount() >= count);
  176. u8 *vertices = (u8 *) buf->getVertices();
  177. for (u32 i = 0; i < count; i++)
  178. ((video::S3DVertex*) (vertices + i * stride))->TCoords = uv[i];
  179. }
  180. template <typename F>
  181. static void applyToMesh(scene::IMesh *mesh, const F &fn)
  182. {
  183. u16 mc = mesh->getMeshBufferCount();
  184. for (u16 j = 0; j < mc; j++) {
  185. scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
  186. const u32 stride = getVertexPitchFromType(buf->getVertexType());
  187. u32 vertex_count = buf->getVertexCount();
  188. char *vertices = reinterpret_cast<char *>(buf->getVertices());
  189. for (u32 i = 0; i < vertex_count; i++)
  190. fn(reinterpret_cast<video::S3DVertex *>(vertices + i * stride));
  191. }
  192. }
  193. void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor)
  194. {
  195. const u32 stride = getVertexPitchFromType(buf->getVertexType());
  196. u32 vertex_count = buf->getVertexCount();
  197. u8 *vertices = (u8 *) buf->getVertices();
  198. for (u32 i = 0; i < vertex_count; i++) {
  199. video::S3DVertex *vertex = (video::S3DVertex *) (vertices + i * stride);
  200. video::SColor *vc = &(vertex->Color);
  201. // Reset color
  202. *vc = *buffercolor;
  203. // Apply shading
  204. applyFacesShading(*vc, vertex->Normal);
  205. }
  206. }
  207. void setMeshColorByNormalXYZ(scene::IMesh *mesh,
  208. const video::SColor &colorX,
  209. const video::SColor &colorY,
  210. const video::SColor &colorZ)
  211. {
  212. if (!mesh)
  213. return;
  214. auto colorizator = [=] (video::S3DVertex *vertex) {
  215. f32 x = fabs(vertex->Normal.X);
  216. f32 y = fabs(vertex->Normal.Y);
  217. f32 z = fabs(vertex->Normal.Z);
  218. if (x >= y && x >= z)
  219. vertex->Color = colorX;
  220. else if (y >= z)
  221. vertex->Color = colorY;
  222. else
  223. vertex->Color = colorZ;
  224. };
  225. applyToMesh(mesh, colorizator);
  226. }
  227. void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal,
  228. const video::SColor &color)
  229. {
  230. if (!mesh)
  231. return;
  232. auto colorizator = [normal, color] (video::S3DVertex *vertex) {
  233. if (vertex->Normal == normal)
  234. vertex->Color = color;
  235. };
  236. applyToMesh(mesh, colorizator);
  237. }
  238. template <float v3f::*U, float v3f::*V>
  239. static void rotateMesh(scene::IMesh *mesh, float degrees)
  240. {
  241. degrees *= M_PI / 180.0f;
  242. float c = std::cos(degrees);
  243. float s = std::sin(degrees);
  244. auto rotator = [c, s] (video::S3DVertex *vertex) {
  245. float u = vertex->Pos.*U;
  246. float v = vertex->Pos.*V;
  247. vertex->Pos.*U = c * u - s * v;
  248. vertex->Pos.*V = s * u + c * v;
  249. };
  250. applyToMesh(mesh, rotator);
  251. }
  252. void rotateMeshXYby(scene::IMesh *mesh, f64 degrees)
  253. {
  254. rotateMesh<&v3f::X, &v3f::Y>(mesh, degrees);
  255. }
  256. void rotateMeshXZby(scene::IMesh *mesh, f64 degrees)
  257. {
  258. rotateMesh<&v3f::X, &v3f::Z>(mesh, degrees);
  259. }
  260. void rotateMeshYZby(scene::IMesh *mesh, f64 degrees)
  261. {
  262. rotateMesh<&v3f::Y, &v3f::Z>(mesh, degrees);
  263. }
  264. void rotateMeshBy6dFacedir(scene::IMesh *mesh, int facedir)
  265. {
  266. int axisdir = facedir >> 2;
  267. facedir &= 0x03;
  268. switch (facedir) {
  269. case 1: rotateMeshXZby(mesh, -90); break;
  270. case 2: rotateMeshXZby(mesh, 180); break;
  271. case 3: rotateMeshXZby(mesh, 90); break;
  272. }
  273. switch (axisdir) {
  274. case 1: rotateMeshYZby(mesh, 90); break; // z+
  275. case 2: rotateMeshYZby(mesh, -90); break; // z-
  276. case 3: rotateMeshXYby(mesh, -90); break; // x+
  277. case 4: rotateMeshXYby(mesh, 90); break; // x-
  278. case 5: rotateMeshXYby(mesh, -180); break;
  279. }
  280. }
  281. void recalculateBoundingBox(scene::IMesh *src_mesh)
  282. {
  283. aabb3f bbox;
  284. bbox.reset(0,0,0);
  285. for (u16 j = 0; j < src_mesh->getMeshBufferCount(); j++) {
  286. scene::IMeshBuffer *buf = src_mesh->getMeshBuffer(j);
  287. buf->recalculateBoundingBox();
  288. if (j == 0)
  289. bbox = buf->getBoundingBox();
  290. else
  291. bbox.addInternalBox(buf->getBoundingBox());
  292. }
  293. src_mesh->setBoundingBox(bbox);
  294. }
  295. bool checkMeshNormals(scene::IMesh *mesh)
  296. {
  297. // Assume correct normals if this many first faces get it right.
  298. static const u16 MAX_FACES_TO_CHECK = 9;
  299. u32 buffer_count = mesh->getMeshBufferCount();
  300. for (u32 i = 0; i < buffer_count; i++) {
  301. scene::IMeshBuffer *buffer = mesh->getMeshBuffer(i);
  302. // Here we intentionally check only first normal, assuming that if buffer
  303. // has it valid, then most likely all other ones are fine too. We can
  304. // check all of the normals to have length, but it seems like an overkill
  305. // hurting the performance and covering only really weird broken models.
  306. f32 length = buffer->getNormal(0).getLength();
  307. if (!std::isfinite(length) || length < 1e-10f)
  308. return false;
  309. const u16 count = MYMIN(MAX_FACES_TO_CHECK * 3, buffer->getIndexCount() - 3);
  310. for (u16 i = 0; i < count; i += 3) {
  311. core::plane3df plane(buffer->getPosition(buffer->getIndices()[i]),
  312. buffer->getPosition(buffer->getIndices()[i+1]),
  313. buffer->getPosition(buffer->getIndices()[i+2]));
  314. for (u16 j = 0; j < 3; j++)
  315. if (plane.Normal.dotProduct(buffer->getNormal(buffer->getIndices()[i+j])) <= 0)
  316. return false;
  317. }
  318. }
  319. return true;
  320. }
  321. scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
  322. {
  323. switch (mesh_buffer->getVertexType()) {
  324. case video::EVT_STANDARD: {
  325. video::S3DVertex *v = (video::S3DVertex *) mesh_buffer->getVertices();
  326. u16 *indices = mesh_buffer->getIndices();
  327. scene::SMeshBuffer *cloned_buffer = new scene::SMeshBuffer();
  328. cloned_buffer->append(v, mesh_buffer->getVertexCount(), indices,
  329. mesh_buffer->getIndexCount());
  330. return cloned_buffer;
  331. }
  332. case video::EVT_2TCOORDS: {
  333. video::S3DVertex2TCoords *v =
  334. (video::S3DVertex2TCoords *) mesh_buffer->getVertices();
  335. u16 *indices = mesh_buffer->getIndices();
  336. scene::SMeshBufferLightMap *cloned_buffer =
  337. new scene::SMeshBufferLightMap();
  338. cloned_buffer->append(v, mesh_buffer->getVertexCount(), indices,
  339. mesh_buffer->getIndexCount());
  340. return cloned_buffer;
  341. }
  342. case video::EVT_TANGENTS: {
  343. video::S3DVertexTangents *v =
  344. (video::S3DVertexTangents *) mesh_buffer->getVertices();
  345. u16 *indices = mesh_buffer->getIndices();
  346. scene::SMeshBufferTangents *cloned_buffer =
  347. new scene::SMeshBufferTangents();
  348. cloned_buffer->append(v, mesh_buffer->getVertexCount(), indices,
  349. mesh_buffer->getIndexCount());
  350. return cloned_buffer;
  351. }
  352. }
  353. // This should not happen.
  354. sanity_check(false);
  355. return NULL;
  356. }
  357. scene::SMesh* cloneMesh(scene::IMesh *src_mesh)
  358. {
  359. scene::SMesh* dst_mesh = new scene::SMesh();
  360. for (u16 j = 0; j < src_mesh->getMeshBufferCount(); j++) {
  361. scene::IMeshBuffer *temp_buf = cloneMeshBuffer(
  362. src_mesh->getMeshBuffer(j));
  363. dst_mesh->addMeshBuffer(temp_buf);
  364. temp_buf->drop();
  365. }
  366. return dst_mesh;
  367. }
  368. scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
  369. const f32 *uv_coords, float expand)
  370. {
  371. scene::SMesh* dst_mesh = new scene::SMesh();
  372. for (u16 j = 0; j < 6; j++)
  373. {
  374. scene::IMeshBuffer *buf = new scene::SMeshBuffer();
  375. buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
  376. buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
  377. dst_mesh->addMeshBuffer(buf);
  378. buf->drop();
  379. }
  380. video::SColor c(255,255,255,255);
  381. for (aabb3f box : boxes) {
  382. box.repair();
  383. box.MinEdge.X -= expand;
  384. box.MinEdge.Y -= expand;
  385. box.MinEdge.Z -= expand;
  386. box.MaxEdge.X += expand;
  387. box.MaxEdge.Y += expand;
  388. box.MaxEdge.Z += expand;
  389. // Compute texture UV coords
  390. f32 tx1 = (box.MinEdge.X / BS) + 0.5;
  391. f32 ty1 = (box.MinEdge.Y / BS) + 0.5;
  392. f32 tz1 = (box.MinEdge.Z / BS) + 0.5;
  393. f32 tx2 = (box.MaxEdge.X / BS) + 0.5;
  394. f32 ty2 = (box.MaxEdge.Y / BS) + 0.5;
  395. f32 tz2 = (box.MaxEdge.Z / BS) + 0.5;
  396. f32 txc_default[24] = {
  397. // up
  398. tx1, 1 - tz2, tx2, 1 - tz1,
  399. // down
  400. tx1, tz1, tx2, tz2,
  401. // right
  402. tz1, 1 - ty2, tz2, 1 - ty1,
  403. // left
  404. 1 - tz2, 1 - ty2, 1 - tz1, 1 - ty1,
  405. // back
  406. 1 - tx2, 1 - ty2, 1 - tx1, 1 - ty1,
  407. // front
  408. tx1, 1 - ty2, tx2, 1 - ty1,
  409. };
  410. // use default texture UV mapping if not provided
  411. const f32 *txc = uv_coords ? uv_coords : txc_default;
  412. v3f min = box.MinEdge;
  413. v3f max = box.MaxEdge;
  414. video::S3DVertex vertices[24] =
  415. {
  416. // up
  417. video::S3DVertex(min.X,max.Y,max.Z, 0,1,0, c, txc[0],txc[1]),
  418. video::S3DVertex(max.X,max.Y,max.Z, 0,1,0, c, txc[2],txc[1]),
  419. video::S3DVertex(max.X,max.Y,min.Z, 0,1,0, c, txc[2],txc[3]),
  420. video::S3DVertex(min.X,max.Y,min.Z, 0,1,0, c, txc[0],txc[3]),
  421. // down
  422. video::S3DVertex(min.X,min.Y,min.Z, 0,-1,0, c, txc[4],txc[5]),
  423. video::S3DVertex(max.X,min.Y,min.Z, 0,-1,0, c, txc[6],txc[5]),
  424. video::S3DVertex(max.X,min.Y,max.Z, 0,-1,0, c, txc[6],txc[7]),
  425. video::S3DVertex(min.X,min.Y,max.Z, 0,-1,0, c, txc[4],txc[7]),
  426. // right
  427. video::S3DVertex(max.X,max.Y,min.Z, 1,0,0, c, txc[ 8],txc[9]),
  428. video::S3DVertex(max.X,max.Y,max.Z, 1,0,0, c, txc[10],txc[9]),
  429. video::S3DVertex(max.X,min.Y,max.Z, 1,0,0, c, txc[10],txc[11]),
  430. video::S3DVertex(max.X,min.Y,min.Z, 1,0,0, c, txc[ 8],txc[11]),
  431. // left
  432. video::S3DVertex(min.X,max.Y,max.Z, -1,0,0, c, txc[12],txc[13]),
  433. video::S3DVertex(min.X,max.Y,min.Z, -1,0,0, c, txc[14],txc[13]),
  434. video::S3DVertex(min.X,min.Y,min.Z, -1,0,0, c, txc[14],txc[15]),
  435. video::S3DVertex(min.X,min.Y,max.Z, -1,0,0, c, txc[12],txc[15]),
  436. // back
  437. video::S3DVertex(max.X,max.Y,max.Z, 0,0,1, c, txc[16],txc[17]),
  438. video::S3DVertex(min.X,max.Y,max.Z, 0,0,1, c, txc[18],txc[17]),
  439. video::S3DVertex(min.X,min.Y,max.Z, 0,0,1, c, txc[18],txc[19]),
  440. video::S3DVertex(max.X,min.Y,max.Z, 0,0,1, c, txc[16],txc[19]),
  441. // front
  442. video::S3DVertex(min.X,max.Y,min.Z, 0,0,-1, c, txc[20],txc[21]),
  443. video::S3DVertex(max.X,max.Y,min.Z, 0,0,-1, c, txc[22],txc[21]),
  444. video::S3DVertex(max.X,min.Y,min.Z, 0,0,-1, c, txc[22],txc[23]),
  445. video::S3DVertex(min.X,min.Y,min.Z, 0,0,-1, c, txc[20],txc[23]),
  446. };
  447. u16 indices[] = {0,1,2,2,3,0};
  448. for(u16 j = 0; j < 24; j += 4)
  449. {
  450. scene::IMeshBuffer *buf = dst_mesh->getMeshBuffer(j / 4);
  451. buf->append(vertices + j, 4, indices, 6);
  452. }
  453. }
  454. return dst_mesh;
  455. }