Advertisement
Guest User

Untitled

a guest
Oct 13th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. scene::IMesh* transformNodeboxNodeToMesh(ContentFeatures *f)
  2. {
  3. scene::SMesh* dst_mesh = new scene::SMesh();
  4. for (u16 j = 0; j < 6; j++)
  5. {
  6. scene::IMeshBuffer *buf = new scene::SMeshBuffer();
  7. buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
  8. buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
  9. buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
  10. dst_mesh->addMeshBuffer(buf);
  11. buf->drop();
  12. }
  13.  
  14. video::SColor c(255,255,255,255);
  15.  
  16. std::vector<aabb3f> boxes = f->node_box.fixed;
  17.  
  18. for(std::vector<aabb3f>::iterator
  19. i = boxes.begin();
  20. i != boxes.end(); i++)
  21. {
  22. aabb3f box = *i;
  23.  
  24. f32 temp;
  25. if (box.MinEdge.X > box.MaxEdge.X)
  26. {
  27. temp=box.MinEdge.X;
  28. box.MinEdge.X=box.MaxEdge.X;
  29. box.MaxEdge.X=temp;
  30. }
  31. if (box.MinEdge.Y > box.MaxEdge.Y)
  32. {
  33. temp=box.MinEdge.Y;
  34. box.MinEdge.Y=box.MaxEdge.Y;
  35. box.MaxEdge.Y=temp;
  36. }
  37. if (box.MinEdge.Z > box.MaxEdge.Z)
  38. {
  39. temp=box.MinEdge.Z;
  40. box.MinEdge.Z=box.MaxEdge.Z;
  41. box.MaxEdge.Z=temp;
  42. }
  43.  
  44. // Compute texture coords
  45. f32 tx1 = (box.MinEdge.X/BS)+0.5;
  46. f32 ty1 = (box.MinEdge.Y/BS)+0.5;
  47. f32 tz1 = (box.MinEdge.Z/BS)+0.5;
  48. f32 tx2 = (box.MaxEdge.X/BS)+0.5;
  49. f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
  50. f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
  51. f32 txc[24] = {
  52. // up
  53. tx1, 1-tz2, tx2, 1-tz1,
  54. // down
  55. tx1, tz1, tx2, tz2,
  56. // right
  57. tz1, 1-ty2, tz2, 1-ty1,
  58. // left
  59. 1-tz2, 1-ty2, 1-tz1, 1-ty1,
  60. // back
  61. 1-tx2, 1-ty2, 1-tx1, 1-ty1,
  62. // front
  63. tx1, 1-ty2, tx2, 1-ty1,
  64. };
  65. v3f min = box.MinEdge;
  66. v3f max = box.MaxEdge;
  67.  
  68. video::S3DVertex vertices[24] =
  69. {
  70. // up
  71. video::S3DVertex(min.X,max.Y,max.Z, 0,1,0, c, txc[0],txc[1]),
  72. video::S3DVertex(max.X,max.Y,max.Z, 0,1,0, c, txc[2],txc[1]),
  73. video::S3DVertex(max.X,max.Y,min.Z, 0,1,0, c, txc[2],txc[3]),
  74. video::S3DVertex(min.X,max.Y,min.Z, 0,1,0, c, txc[0],txc[3]),
  75. // down
  76. video::S3DVertex(min.X,min.Y,min.Z, 0,-1,0, c, txc[4],txc[5]),
  77. video::S3DVertex(max.X,min.Y,min.Z, 0,-1,0, c, txc[6],txc[5]),
  78. video::S3DVertex(max.X,min.Y,max.Z, 0,-1,0, c, txc[6],txc[7]),
  79. video::S3DVertex(min.X,min.Y,max.Z, 0,-1,0, c, txc[4],txc[7]),
  80. // right
  81. video::S3DVertex(max.X,max.Y,min.Z, 1,0,0, c, txc[ 8],txc[9]),
  82. video::S3DVertex(max.X,max.Y,max.Z, 1,0,0, c, txc[10],txc[9]),
  83. video::S3DVertex(max.X,min.Y,max.Z, 1,0,0, c, txc[10],txc[11]),
  84. video::S3DVertex(max.X,min.Y,min.Z, 1,0,0, c, txc[ 8],txc[11]),
  85. // left
  86. video::S3DVertex(min.X,max.Y,max.Z, -1,0,0, c, txc[12],txc[13]),
  87. video::S3DVertex(min.X,max.Y,min.Z, -1,0,0, c, txc[14],txc[13]),
  88. video::S3DVertex(min.X,min.Y,min.Z, -1,0,0, c, txc[14],txc[15]),
  89. video::S3DVertex(min.X,min.Y,max.Z, -1,0,0, c, txc[12],txc[15]),
  90. // back
  91. video::S3DVertex(max.X,max.Y,max.Z, 0,0,1, c, txc[16],txc[17]),
  92. video::S3DVertex(min.X,max.Y,max.Z, 0,0,1, c, txc[18],txc[17]),
  93. video::S3DVertex(min.X,min.Y,max.Z, 0,0,1, c, txc[18],txc[19]),
  94. video::S3DVertex(max.X,min.Y,max.Z, 0,0,1, c, txc[16],txc[19]),
  95. // front
  96. video::S3DVertex(min.X,max.Y,min.Z, 0,0,-1, c, txc[20],txc[21]),
  97. video::S3DVertex(max.X,max.Y,min.Z, 0,0,-1, c, txc[22],txc[21]),
  98. video::S3DVertex(max.X,min.Y,min.Z, 0,0,-1, c, txc[22],txc[23]),
  99. video::S3DVertex(min.X,min.Y,min.Z, 0,0,-1, c, txc[20],txc[23]),
  100. };
  101.  
  102. u16 indices[] = {0,1,2,2,3,0};
  103.  
  104. for(u16 j = 0; j < 24; j += 4)
  105. {
  106. scene::IMeshBuffer *buf = dst_mesh->getMeshBuffer(j / 4);
  107. buf->append(vertices + j, 4, indices, 6);
  108. }
  109. }
  110. return dst_mesh;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement