added new entity style irregular_cube
authorsapier <sapier at gmx dot net>
Sun, 15 Jan 2012 19:30:26 +0000 (20:30 +0100)
committersapier <sapier at gmx dot net>
Sun, 15 Jan 2012 19:30:26 +0000 (20:30 +0100)
src/content_cao.cpp
src/mesh.cpp
src/mesh.h

index 76f23082d222a2af254886cb3c25c781064b252e..83f1cedff8e5571644f01f0b6502eba90cf0cf2a 100644 (file)
@@ -1811,6 +1811,15 @@ public:
                        m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
                        mesh->drop();
 
+                       m_meshnode->setScale(v3f(1));
+                       // Will be shown when we know the brightness
+                       m_meshnode->setVisible(false);
+               } else if (m_prop->visual == "cube_disorted") {
+                       infostream<<"LuaEntityCAO::addToScene(): irregular_cube"<<std::endl;
+                       scene::IMesh *mesh = createCubeMesh(v3f(BS,BS,BS), m_prop->collisionbox);
+                       m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
+                       mesh->drop();
+
                        m_meshnode->setScale(v3f(1));
                        // Will be shown when we know the brightness
                        m_meshnode->setVisible(false);
index 8b9668593b10ca18ede14acb1f9776b6f5386534..c0b1419d4938cf6ceb0243123886ac67cf8a423d 100644 (file)
@@ -82,6 +82,59 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale)
        return anim_mesh;
 }
 
+scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box)
+{
+       video::SColor c(255,255,255,255);
+       video::S3DVertex vertices[24] =
+       {
+               // Up
+               video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,1,0, c, 0,1),
+               video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,1,0, c, 0,0),
+               video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,1,0, c, 1,0),
+               video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,1,0, c, 1,1),
+               // Down
+               video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,-1,0, c, 0,0),
+               video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,-1,0, c, 1,0),
+               video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,-1,0, c, 1,1),
+               video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,-1,0, c, 0,1),
+               // Right
+               video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 1,0,0, c, 0,1),
+               video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 1,0,0, c, 0,0),
+               video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 1,0,0, c, 1,0),
+               video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 1,0,0, c, 1,1),
+               // Left
+               video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, -1,0,0, c, 1,1),
+               video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, -1,0,0, c, 0,1),
+               video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, -1,0,0, c, 0,0),
+               video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, -1,0,0, c, 1,0),
+               // Back
+               video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,0,1, c, 1,1),
+               video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MaxEdge.Z, 0,0,1, c, 0,1),
+               video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,0,1, c, 0,0),
+               video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MaxEdge.Z, 0,0,1, c, 1,0),
+               // Front
+               video::S3DVertex(box.MinEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,0,-1, c, 0,1),
+               video::S3DVertex(box.MinEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,0,-1, c, 0,0),
+               video::S3DVertex(box.MaxEdge.X,box.MaxEdge.Y,box.MinEdge.Z, 0,0,-1, c, 1,0),
+               video::S3DVertex(box.MaxEdge.X,box.MinEdge.Y,box.MinEdge.Z, 0,0,-1, c, 1,1),
+       };
+
+       u16 indices[6] = {0,1,2,2,3,0};
+
+       scene::SMesh *mesh = new scene::SMesh();
+       for (u32 i=0; i<6; ++i)
+       {
+               scene::IMeshBuffer *buf = new scene::SMeshBuffer();
+               buf->append(vertices + 4 * i, 4, indices, 6);
+               mesh->addMeshBuffer(buf);
+               buf->drop();
+       }
+       scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
+       mesh->drop();
+       scaleMesh(anim_mesh, scale);  // also recalculates bounding box
+       return anim_mesh;
+}
+
 scene::IAnimatedMesh* createPlantMesh(v3f scale)
 {
        video::SColor c(255,255,255,255);
index 78c0dc1e70dcd476a7eaff7bcb6ca15184e69bea..b22ccc31895c306419401a1fe1780a4a71e61886 100644 (file)
@@ -31,6 +31,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 scene::IAnimatedMesh* createCubeMesh(v3f scale);
 
+/*
+       Create a new cube mesh not linked to mapnode size.
+       Vertices are defined by given box.
+
+       The resulting mesh has 6 materials (up, down, right, left, back, front)
+       which must be defined by the caller.
+*/
+scene::IAnimatedMesh* createCubeMesh(v3f scale,core::aabbox3d<f32> box);
+
 /*
        Create a new extruded mesh from a texture.
        Maximum bounding box is (+-scale.X/2, +-scale.Y/2, +-scale.Z).