Advertisement
Guest User

Plant draw type

a guest
Jan 5th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. --- celeron55-minetest-6957930.orig/src/content_cao.cpp 2011-12-24 05:38:29.000000000 +0100
  2. +++ celeron55-minetest-6957930/src/content_cao.cpp 2011-12-24 14:07:21.000000000 +0100
  3. @@ -1816,6 +1816,17 @@
  4. // Will be shown when we know the brightness
  5. m_meshnode->setVisible(false);
  6. }
  7. + else if (m_prop->visual == "plant") {
  8. + infostream<<"LuaEntityCAO::addToScene(): plant"<<std::endl;
  9. +
  10. + scene::IMesh *mesh = createPlantMesh(v3f(BS,BS,BS));
  11. + m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
  12. + mesh->drop();
  13. +
  14. + m_meshnode->setScale(v3f(1));
  15. + // Will be shown when we know the brightness
  16. + m_meshnode->setVisible(false);
  17. + }
  18. else {
  19. infostream<<"LuaEntityCAO::addToScene(): \""<<m_prop->visual
  20. <<"\" not supported"<<std::endl;
  21. @@ -1968,28 +1979,55 @@
  22. tsrc->getTextureRaw(texturestring));
  23. }
  24. if(m_meshnode){
  25. - for (u32 i = 0; i < 6; ++i)
  26. - {
  27. - std::string texturestring = "unknown_block.png";
  28. - if(m_prop->textures.size() > i)
  29. - texturestring = m_prop->textures[i];
  30. - texturestring += mod;
  31. - AtlasPointer ap = tsrc->getTexture(texturestring);
  32. -
  33. - // Get the tile texture and atlas transformation
  34. - video::ITexture* atlas = ap.atlas;
  35. - v2f pos = ap.pos;
  36. - v2f size = ap.size;
  37. -
  38. - // Set material flags and texture
  39. - video::SMaterial& material = m_meshnode->getMaterial(i);
  40. - material.setFlag(video::EMF_LIGHTING, false);
  41. - material.setFlag(video::EMF_BILINEAR_FILTER, false);
  42. - material.setTexture(0, atlas);
  43. - material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
  44. - material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
  45. - material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
  46. + if (m_prop->visual == "plant") {
  47. + for (u32 i = 0; i < 4; ++i)
  48. + {
  49. + std::string texturestring = "unknown_block.png";
  50. + if(m_prop->textures.size() > 0)
  51. + texturestring = m_prop->textures[0];
  52. + texturestring += mod;
  53. + AtlasPointer ap = tsrc->getTexture(texturestring);
  54. +
  55. + // Get the tile texture and atlas transformation
  56. + video::ITexture* atlas = ap.atlas;
  57. + v2f pos = ap.pos;
  58. + v2f size = ap.size;
  59. +
  60. + // Set material flags and texture
  61. + video::SMaterial& material = m_meshnode->getMaterial(i);
  62. + material.setFlag(video::EMF_LIGHTING, false);
  63. + material.setFlag(video::EMF_BILINEAR_FILTER, false);
  64. + material.setTexture(0, atlas);
  65. + material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
  66. + material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
  67. + material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
  68. + }
  69. }
  70. + else {
  71. + for (u32 i = 0; i < 6; ++i)
  72. + {
  73. + std::string texturestring = "unknown_block.png";
  74. + if(m_prop->textures.size() > i)
  75. + texturestring = m_prop->textures[i];
  76. + texturestring += mod;
  77. + AtlasPointer ap = tsrc->getTexture(texturestring);
  78. +
  79. + // Get the tile texture and atlas transformation
  80. + video::ITexture* atlas = ap.atlas;
  81. + v2f pos = ap.pos;
  82. + v2f size = ap.size;
  83. +
  84. + // Set material flags and texture
  85. + video::SMaterial& material = m_meshnode->getMaterial(i);
  86. + material.setFlag(video::EMF_LIGHTING, false);
  87. + material.setFlag(video::EMF_BILINEAR_FILTER, false);
  88. + material.setTexture(0, atlas);
  89. + material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
  90. + material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
  91. + material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
  92. + }
  93. + }
  94. +
  95. }
  96. }
  97.  
  98. --- celeron55-minetest-6957930.orig/src/mesh.h 2011-12-24 05:34:20.000000000 +0100
  99. +++ celeron55-minetest-6957930/src/mesh.h 2011-12-24 12:49:47.000000000 +0100
  100. @@ -40,6 +40,16 @@
  101. */
  102. scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box);
  103.  
  104. +
  105. +/*
  106. + Create a new cube mesh.
  107. + Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
  108. +
  109. + The resulting mesh has 6 materials (up, down, right, left, back, front)
  110. + which must be defined by the caller.
  111. +*/
  112. +scene::IAnimatedMesh* createPlantMesh(v3f scale);
  113. +
  114. /*
  115. Create a new extruded mesh from a texture.
  116. Maximum bounding box is (+-scale.X/2, +-scale.Y/2, +-scale.Z).
  117. --- celeron55-minetest-6957930.orig/src/mesh.cpp 2011-12-24 05:34:20.000000000 +0100
  118. +++ celeron55-minetest-6957930/src/mesh.cpp 2011-12-24 14:06:51.000000000 +0100
  119. @@ -82,6 +82,52 @@
  120. return anim_mesh;
  121. }
  122.  
  123. +scene::IAnimatedMesh* createPlantMesh(v3f scale)
  124. +{
  125. + video::SColor c(255,255,255,255);
  126. + video::S3DVertex vertices[16] =
  127. + {
  128. + // Plane 1 Front
  129. + video::S3DVertex(-0.5,-0.5,-0.5, 0.5,0,-0.5, c, 0,1),
  130. + video::S3DVertex(-0.5,+0.5,-0.5, 0.5,0,-0.5, c, 0,0),
  131. + video::S3DVertex(+0.5,+0.5,+0.5, 0.5,0,-0.5, c, 1,0),
  132. + video::S3DVertex(+0.5,-0.5,+0.5, 0.5,0,-0.5, c, 1,1),
  133. + // Plane 1 Back
  134. + video::S3DVertex(+0.5,-0.5,+0.5, -0.5,0,0.5, c, 1,1),
  135. + video::S3DVertex(+0.5,+0.5,+0.5, -0.5,0,0.5, c, 1,0),
  136. + video::S3DVertex(-0.5,+0.5,-0.5, -0.5,0,0.5, c, 0,0),
  137. + video::S3DVertex(-0.5,-0.5,-0.5, -0.5,0,0.5, c, 0,1),
  138. +
  139. + // Plane 2 Front
  140. + video::S3DVertex(-0.5,-0.5,+0.5, -0.5,0,-0.5, c, 1,1),
  141. + video::S3DVertex(-0.5,+0.5,+0.5, -0.5,0,-0.5, c, 1,0),
  142. + video::S3DVertex(+0.5,+0.5,-0.5, -0.5,0,-0.5, c, 0,0),
  143. + video::S3DVertex(+0.5,-0.5,-0.5, -0.5,0,-0.5, c, 0,1),
  144. +
  145. + // Plane 2 Back
  146. + video::S3DVertex(+0.5,-0.5,-0.5, 0.5,0,0.5, c, 0,1),
  147. + video::S3DVertex(+0.5,+0.5,-0.5, 0.5,0,0.5, c, 0,0),
  148. + video::S3DVertex(-0.5,+0.5,+0.5, 0.5,0,0.5, c, 1,0),
  149. + video::S3DVertex(-0.5,-0.5,+0.5, 0.5,0,0.5, c, 1,1)
  150. +
  151. + };
  152. +
  153. + u16 indices[6] = {0,1,2,2,3,0};
  154. +
  155. + scene::SMesh *mesh = new scene::SMesh();
  156. + for (u32 i=0; i<4; ++i)
  157. + {
  158. + scene::IMeshBuffer *buf = new scene::SMeshBuffer();
  159. + buf->append(vertices + 4 * i, 4, indices, 6);
  160. + mesh->addMeshBuffer(buf);
  161. + buf->drop();
  162. + }
  163. + scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
  164. + mesh->drop();
  165. + scaleMesh(anim_mesh, scale); // also recalculates bounding box
  166. + return anim_mesh;
  167. +}
  168. +
  169. scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box)
  170. {
  171. video::SColor c(255,255,255,255);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement