]> git.lizzy.rs Git - minetest.git/blobdiff - src/mesh.cpp
Remove ClientMap::m_camera_mutex
[minetest.git] / src / mesh.cpp
index a800ddf1e773b59b654bd99bc6397d1626a3ca0f..d79f545f3cca8c9040f5767e849594dd9a7211af 100644 (file)
@@ -405,9 +405,11 @@ scene::IMesh* cloneMesh(scene::IMesh *src_mesh)
        return dst_mesh;
 }
 
-scene::IMesh* convertNodeboxNodeToMesh(ContentFeatures *f)
+scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
+               const f32 *uv_coords)
 {
        scene::SMesh* dst_mesh = new scene::SMesh();
+
        for (u16 j = 0; j < 6; j++)
        {
                scene::IMeshBuffer *buf = new scene::SMeshBuffer();
@@ -416,12 +418,10 @@ scene::IMesh* convertNodeboxNodeToMesh(ContentFeatures *f)
                dst_mesh->addMeshBuffer(buf);
                buf->drop();
        }
-       
+
        video::SColor c(255,255,255,255);       
 
-       std::vector<aabb3f> boxes = f->node_box.fixed;
-               
-       for(std::vector<aabb3f>::iterator
+       for(std::vector<aabb3f>::const_iterator
                        i = boxes.begin();
                        i != boxes.end(); ++i)
        {
@@ -446,27 +446,33 @@ scene::IMesh* convertNodeboxNodeToMesh(ContentFeatures *f)
                                box.MinEdge.Z=box.MaxEdge.Z;
                                box.MaxEdge.Z=temp;
                        }
-               // Compute texture coords
-               f32 tx1 = (box.MinEdge.X/BS)+0.5;
-               f32 ty1 = (box.MinEdge.Y/BS)+0.5;
-               f32 tz1 = (box.MinEdge.Z/BS)+0.5;
-               f32 tx2 = (box.MaxEdge.X/BS)+0.5;
-               f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
-               f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
-               f32 txc[24] = {
+
+               // Compute texture UV coords
+               f32 tx1 = (box.MinEdge.X / BS) + 0.5;
+               f32 ty1 = (box.MinEdge.Y / BS) + 0.5;
+               f32 tz1 = (box.MinEdge.Z / BS) + 0.5;
+               f32 tx2 = (box.MaxEdge.X / BS) + 0.5;
+               f32 ty2 = (box.MaxEdge.Y / BS) + 0.5;
+               f32 tz2 = (box.MaxEdge.Z / BS) + 0.5;
+
+               f32 txc_default[24] = {
                        // up
-                       tx1, 1-tz2, tx2, 1-tz1,
+                       tx1, 1 - tz2, tx2, 1 - tz1,
                        // down
                        tx1, tz1, tx2, tz2,
                        // right
-                       tz1, 1-ty2, tz2, 1-ty1,
+                       tz1, 1 - ty2, tz2, 1 - ty1,
                        // left
-                       1-tz2, 1-ty2, 1-tz1, 1-ty1,
+                       1 - tz2, 1 - ty2, 1 - tz1, 1 - ty1,
                        // back
-                       1-tx2, 1-ty2, 1-tx1, 1-ty1,
+                       1 - tx2, 1 - ty2, 1 - tx1, 1 - ty1,
                        // front
-                       tx1, 1-ty2, tx2, 1-ty1,
+                       tx1, 1 - ty2, tx2, 1 - ty1,
                };
+
+               // use default texture UV mapping if not provided
+               const f32 *txc = uv_coords ? uv_coords : txc_default;
+
                v3f min = box.MinEdge;
                v3f max = box.MaxEdge;