Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- // Get rotation for things like chests
- u8 facedir = mn.getFaceDir(ndef);
- assert(facedir <= 23);
- static const u8 dir_to_tile[24 * 8] =
- {
- // 0 +X +Y +Z 0 -Z -Y -X
- 0, 2, 0, 4, 0, 5, 1, 3, // rotate over y+ 0 - 3
- 0, 4, 0, 3, 0, 2, 1, 5,
- 0, 3, 0, 5, 0, 4, 1, 2,
- 0, 5, 0, 2, 0, 3, 1, 4,
- 0, 3, 5, 0, 0, 1, 4, 2, // rotate over z+ 4 - 7
- 0, 5, 3, 0, 0, 1, 2, 4,
- 0, 3, 4, 0, 0, 1, 5, 2,
- 0, 4, 2, 0, 0, 1, 3, 5,
- 0, 2, 5, 1, 0, 0, 4, 3, // rotate over z- 8 - 11
- 0, 5, 2, 1, 0, 0, 3, 4,
- 0, 3, 4, 1, 0, 0, 5, 2,
- 0, 4, 3, 1, 0, 0, 2, 5,
- 0, 0, 5, 2, 0, 3, 4, 1, // rotate over x+ 12 - 15
- 0, 0, 3, 5, 0, 4, 2, 1,
- 0, 0, 4, 3, 0, 2, 5, 1,
- 0, 0, 2, 4, 0, 5, 3, 1,
- 0, 1, 5, 3, 0, 2, 4, 0, // rotate over x- 16 - 19
- 0, 1, 2, 5, 0, 4, 3, 0,
- 0, 1, 4, 2, 0, 3, 5, 0,
- 0, 1, 3, 4, 0, 5, 2, 0,
- 0, 3, 1, 4, 0, 5, 0, 2, // rotate over y- 20 - 23
- 0, 4, 1, 2, 0, 3, 0, 5,
- 0, 2, 1, 5, 0, 4, 0, 3,
- 0, 5, 1, 3, 0, 2, 0, 4,
- };
- u8 tileindex = dir_to_tile[facedir*8 + dir_i];
- TileSpec spec = getNodeTileN(mn, p, tileindex, data);
- spec.rotation=0;
- std::string name = data->m_gamedef->tsrc()->getTextureName(spec.texture.id);
- // Texture rotation
- // 0 - no rotation
- // 1 - R90
- // 2 - R180
- // 3 - R270
- // 4 - FXR90
- // 5 - FXR270
- // 6 - FYR90
- // 7 - FYR270
- // 8 - FX
- // 9 - FY
- switch (facedir)
- {
- case 0:
- break;
- case 1:
- if(tileindex == 0) spec.rotation=3;
- else if(tileindex == 1) spec.rotation=1;
- break;
- case 2:
- if(tileindex == 0) spec.rotation=2;
- else if(tileindex == 1) spec.rotation=2;
- break;
- case 3:
- if(tileindex == 0) spec.rotation=1;
- else if(tileindex == 1) spec.rotation=3;
- break;
- case 4:
- if(tileindex == 0) spec.rotation=2;
- else if(tileindex == 2) spec.rotation=7;
- else if(tileindex == 3) spec.rotation=6;
- else if(tileindex == 4) spec.rotation=2;
- break;
- case 5:
- if(tileindex == 0) spec.rotation=3;
- else if(tileindex == 1) spec.rotation=6;
- else if(tileindex == 2) spec.rotation=2;
- else if(tileindex == 4) spec.rotation=1;
- else if(tileindex == 5) spec.rotation=3;
- break;
- case 6:
- if(tileindex == 1) spec.rotation=2;
- else if(tileindex == 2) spec.rotation=1;
- else if(tileindex == 3) spec.rotation=3;
- else if(tileindex == 5) spec.rotation=2;
- break;
- case 7:
- if(tileindex == 0) spec.rotation=1;
- else if(tileindex == 1) spec.rotation=1;
- else if(tileindex == 3) spec.rotation=2;
- else if(tileindex == 4) spec.rotation=3;
- else if(tileindex == 5) spec.rotation=1;
- break;
- case 8:
- if(tileindex == 0) spec.rotation=2;
- else if(tileindex == 2) spec.rotation=7;
- else if(tileindex == 3) spec.rotation=6;
- else if(tileindex == 5) spec.rotation=2;
- break;
- case 9:
- if(tileindex == 0) spec.rotation=3;
- else if(tileindex == 1) spec.rotation=6;
- else if(tileindex == 2) spec.rotation=2;
- else if(tileindex == 4) spec.rotation=3;
- else if(tileindex == 5) spec.rotation=1;
- break;
- case 10:
- if(tileindex == 1) spec.rotation=2;
- else if(tileindex == 2) spec.rotation=6;
- else if(tileindex == 3) spec.rotation=7;
- else if(tileindex == 4) spec.rotation=2;
- break;
- case 11:
- if(tileindex == 0) spec.rotation=3;
- else if(tileindex == 1) spec.rotation=3;
- else if(tileindex == 3) spec.rotation=2;
- else if(tileindex == 4) spec.rotation=1;
- else if(tileindex == 5) spec.rotation=3;
- break;
- case 12:
- if(tileindex == 0) spec.rotation=2;
- else if(tileindex == 2) spec.rotation=4;
- else if(tileindex == 3) spec.rotation=5;
- else if(tileindex == 4) spec.rotation=3;
- else if(tileindex == 5) spec.rotation=3;
- break;
- case 13:
- if(tileindex == 0) spec.rotation=1;
- else if(tileindex == 1) spec.rotation=1;
- else if(tileindex == 2) spec.rotation=5;
- else if(tileindex == 3) spec.rotation=5;
- else if(tileindex == 4) spec.rotation=3;
- else if(tileindex == 5) spec.rotation=1;
- break;
- case 14:
- if(tileindex == 1) spec.rotation=2;
- else if(tileindex == 2) spec.rotation=5;
- else if(tileindex == 3) spec.rotation=4;
- else if(tileindex == 4) spec.rotation=3;
- else if(tileindex == 5) spec.rotation=3;
- break;
- case 15:
- if(tileindex == 0) spec.rotation=3;
- else if(tileindex == 1) spec.rotation=3;
- else if(tileindex == 2) spec.rotation=5;
- else if(tileindex == 3) spec.rotation=5;
- else if(tileindex == 4) spec.rotation=1;
- else if(tileindex == 5) spec.rotation=3;
- break;
- case 16:
- if(tileindex == 2) spec.rotation=4;
- else if(tileindex == 3) spec.rotation=5;
- else if(tileindex == 4) spec.rotation=1;
- else if(tileindex == 5) spec.rotation=1;
- break;
- case 17:
- if(tileindex == 0) spec.rotation=3;
- else if(tileindex == 1) spec.rotation=3;
- else if(tileindex == 2) spec.rotation=4;
- else if(tileindex == 3) spec.rotation=4;
- else if(tileindex == 4) spec.rotation=1;
- else if(tileindex == 5) spec.rotation=3;
- break;
- case 18:
- if(tileindex == 0) spec.rotation=8;
- else if(tileindex == 1) spec.rotation=2;
- else if(tileindex == 2) spec.rotation=5;
- else if(tileindex == 3) spec.rotation=4;
- else if(tileindex == 4) spec.rotation=1;
- else if(tileindex == 5) spec.rotation=1;
- break;
- case 19:
- if(tileindex == 0) spec.rotation=1;
- else if(tileindex == 1) spec.rotation=1;
- else if(tileindex == 2) spec.rotation=4;
- else if(tileindex == 3) spec.rotation=4;
- else if(tileindex == 4) spec.rotation=3;
- else if(tileindex == 5) spec.rotation=1;
- break;
- case 20:
- spec.rotation=2;
- break;
- case 21:
- if(tileindex == 0) spec.rotation=3;
- else if(tileindex == 1) spec.rotation=1;
- else if(tileindex == 2) spec.rotation=2;
- else if(tileindex == 3) spec.rotation=2;
- else if(tileindex == 4) spec.rotation=2;
- else if(tileindex == 5) spec.rotation=2;
- break;
- case 22:
- if(tileindex == 2) spec.rotation=2;
- else if(tileindex == 3) spec.rotation=2;
- else if(tileindex == 4) spec.rotation=2;
- else if(tileindex == 5) spec.rotation=2;
- break;
- case 23:
- if(tileindex == 0) spec.rotation=1;
- else if(tileindex == 1) spec.rotation=3;
- else if(tileindex == 2) spec.rotation=2;
- else if(tileindex == 3) spec.rotation=2;
- else if(tileindex == 4) spec.rotation=2;
- else if(tileindex == 5) spec.rotation=2;
- break;
- default:
- break;
- }
- spec.texture = data->m_gamedef->tsrc()->getTexture(name);
- return spec;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement