Rotate facedir-rotated top and bottom textures too, and re-implement nodebox side...
authorPerttu Ahola <celeron55@gmail.com>
Sat, 21 Jul 2012 17:23:32 +0000 (20:23 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 21 Jul 2012 17:23:32 +0000 (20:23 +0300)
src/content_mapblock.cpp
src/mapblock_mesh.cpp

index 3d049f8cd6c7f148d0776d4643eb1c79bdbf668d..ad819e7939e9669853f44db449a339a06e40e4c3 100644 (file)
@@ -1029,52 +1029,20 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                break;}
                case NDT_NODEBOX:
                {
+                       static const v3s16 tile_dirs[6] = {
+                               v3s16(0, 1, 0),
+                               v3s16(0, -1, 0),
+                               v3s16(1, 0, 0),
+                               v3s16(-1, 0, 0),
+                               v3s16(0, 0, 1),
+                               v3s16(0, 0, -1)
+                       };
+
                        TileSpec tiles[6];
                        for(int i = 0; i < 6; i++)
                        {
-                               tiles[i] = getNodeTileN(n, p, i, data);
-                       }
-
-                       // Facedir rotation for textures
-                       if(f.node_box.type == NODEBOX_FIXED){
-                               int facedir = n.getFaceDir(nodedef);
-                               if(facedir == 1){ // -90
-                                       TileSpec old[6];
-                                       for(int i=0; i<6; i++)
-                                               old[i] = tiles[i];
-                                       // right <- back
-                                       tiles[2] = old[4];
-                                       // back <- left
-                                       tiles[4] = old[3];
-                                       // left <- front
-                                       tiles[3] = old[5];
-                                       // front <- right
-                                       tiles[5] = old[2];
-                               }
-                               if(facedir == 2){ // 180
-                                       TileSpec old[6];
-                                       for(int i=0; i<6; i++)
-                                               old[i] = tiles[i];
-                                       // right <-> left
-                                       tiles[2] = old[3];
-                                       tiles[3] = old[2];
-                                       // back <-> front
-                                       tiles[4] = old[5];
-                                       tiles[5] = old[4];
-                               }
-                               if(facedir == 3){ // 90
-                                       TileSpec old[6];
-                                       for(int i=0; i<6; i++)
-                                               old[i] = tiles[i];
-                                       // right <- front
-                                       tiles[2] = old[5];
-                                       // back <- right
-                                       tiles[4] = old[2];
-                                       // left <- back
-                                       tiles[3] = old[4];
-                                       // front <- left
-                                       tiles[5] = old[3];
-                               }
+                               // Handles facedir rotation for textures
+                               tiles[i] = getNodeTile(n, p, tile_dirs[i], data);
                        }
 
                        u16 l = getInteriorLight(n, 0, data);
index 3f40f9c0046fb8acd851d5cfb326ff4a8765b789..9ae9b21c07058d7be6cce5ba33cc27edeeab807e 100644 (file)
@@ -605,7 +605,46 @@ TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
                   0,  5,  0,  2,  0,  3,  1,  4,  // facedir = 3
        };
        u8 tileindex = dir_to_tile[facedir*8 + dir_i];
-       return getNodeTileN(mn, p, tileindex, data);
+
+       // If not rotated or is side tile, we're done
+       if(facedir == 0 || (tileindex != 0 && tileindex != 1))
+               return getNodeTileN(mn, p, tileindex, data);
+
+       // This is the top or bottom tile, and it shall be rotated; thus rotate it
+       TileSpec spec = getNodeTileN(mn, p, tileindex, data);
+       if(tileindex == 0){
+               if(facedir == 1){ // -90
+                       std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
+                       name += "^[transformR270";
+                       spec.texture = data->m_gamedef->tsrc()->getTexture(name);
+               }
+               else if(facedir == 2){ // 180
+                       spec.texture.pos += spec.texture.size;
+                       spec.texture.size *= -1;
+               }
+               else if(facedir == 3){ // 90
+                       std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
+                       name += "^[transformR90";
+                       spec.texture = data->m_gamedef->tsrc()->getTexture(name);
+               }
+       }
+       else if(tileindex == 1){
+               if(facedir == 1){ // -90
+                       std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
+                       name += "^[transformR90";
+                       spec.texture = data->m_gamedef->tsrc()->getTexture(name);
+               }
+               else if(facedir == 2){ // 180
+                       spec.texture.pos += spec.texture.size;
+                       spec.texture.size *= -1;
+               }
+               else if(facedir == 3){ // 90
+                       std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
+                       name += "^[transformR270";
+                       spec.texture = data->m_gamedef->tsrc()->getTexture(name);
+               }
+       }
+       return spec;
 }
 
 static void getTileInfo(