Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Gets node tile given a face direction.
- */
- TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 dir, MeshMakeData *data)
- {
- INodeDefManager *ndef = data->m_gamedef->ndef();
- // Direction must be (1,0,0), (-1,0,0), (0,1,0), (0,-1,0),
- // (0,0,1), (0,0,-1) or (0,0,0)
- assert(dir.X * dir.X + dir.Y * dir.Y + dir.Z * dir.Z <= 1);
- // Convert direction to single integer for table lookup
- // 0 = (0,0,0)
- // 1 = (1,0,0)
- // 2 = (0,1,0)
- // 3 = (0,0,1)
- // 4 = invalid, treat as (0,0,0)
- // 5 = (0,0,-1)
- // 6 = (0,-1,0)
- // 7 = (-1,0,0)
- u8 dir_i = ((dir.X + 2 * dir.Y + 3 * dir.Z) & 7)*2;
- // Get rotation for things like chests
- u8 facedir = mn.getFaceDir(ndef);
- assert(facedir <= 23);
- static const u16 dir_to_tile[24 * 16] =
- {
- // 0 +X +Y +Z 0 -Z -Y -X value=tile,rotation
- 0,0, 2,0 , 0,0 , 4,0 , 0,0, 5,0 , 1,0 , 3,0 , // rotate over y+ 0 - 3
- 0,0, 4,0 , 0,3 , 3,0 , 0,0, 2,0 , 1,1 , 5,0 ,
- 0,0, 3,0 , 0,2 , 5,0 , 0,0, 4,0 , 1,2 , 2,0 ,
- 0,0, 5,0 , 0,1 , 2,0 , 0,0, 3,0 , 1,3 , 4,0 ,
- 0,0, 3,6 , 5,0 , 0,2 , 0,0, 1,0 , 4,2 , 2,7 , // rotate over z+ 4 - 7
- 0,0, 5,3 , 3,0 , 0,3 , 0,0, 1,6 , 2,2 , 4,1 ,
- 0,0, 3,3 , 4,0 , 0,0 , 0,0, 1,2 , 5,2 , 2,1 ,
- 0,0, 4,3 , 2,0 , 0,1 , 0,0, 1,1 , 3,2 , 5,1 ,
- 0,0, 2,7 , 5,2 , 1,0 , 0,0, 0,2 , 4,0 , 3,6 , // rotate over z- 8 - 11
- 0,0, 5,1 , 2,2 , 1,6 , 0,0, 0,3 , 3,0 , 4,3 ,
- 0,0, 3,7 , 4,2 , 1,2 , 0,0, 0,0 , 5,0 , 2,6 ,
- 0,0, 4,1 , 3,2 , 1,3 , 0,0, 0,3 , 2,0 , 5,3 ,
- 0,0, 0,2 , 5,3 , 2,4 , 0,0, 3,5 , 4,3 , 1,0 , // rotate over x+ 12 - 15
- 0,0, 0,1 , 3,5 , 5,1 , 0,0, 4,3 , 2,5 , 1,1 ,
- 0,0, 0,0 , 4,3 , 3,4 , 0,0, 2,5 , 5,3 , 1,2 ,
- 0,0, 0,3 , 2,5 , 4,1 , 0,0, 5,3 , 3,5 , 1,3 ,
- 0,0, 1,0 , 5,1 , 3,5 , 0,0, 2,4 , 4,1 , 0,0 , // rotate over x- 16 - 19
- 0,0, 1,3 , 2,4 , 5,3 , 0,0, 4,1 , 3,4 , 0,3 ,
- 0,0, 1,2 , 4,1 , 2,5 , 0,0, 3,4 , 5,1 , 0,8 ,
- 0,0, 1,1 , 3,4 , 4,3 , 0,0, 5,1 , 2,4 , 0,1 ,
- 0,0, 3,2 , 1,2 , 4,2 , 0,0, 5,2 , 0,2 , 2,2 , // rotate over y- 20 - 23
- 0,0, 4,2 , 1,1 , 2,2 , 0,0, 3,2 , 0,3 , 5,2 ,
- 0,0, 2,2 , 1,0 , 5,2 , 0,0, 4,2 , 0,0 , 3,2 ,
- 0,0, 5,2 , 1,3 , 3,2 , 0,0, 2,2 , 0,1 , 4,2
- };
- TileSpec spec = getNodeTileN(mn, p, dir_to_tile[facedir*16 + dir_i], data);
- spec.rotation=dir_to_tile[facedir*16 + dir_i+1];
- std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
- spec.texture = data->m_gamedef->tsrc()->getTexture(name);
- return spec;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement