示例#1
0
/*
	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;

	// Get rotation for things like chests
	u8 facedir = mn.getFaceDir(ndef);
	assert(facedir <= 3);
	
	static const u8 dir_to_tile[4 * 8] =
	{
		// 0  +X  +Y  +Z   0  -Z  -Y  -X
		   0,  2,  0,  4,  0,  5,  1,  3,  // facedir = 0
		   0,  4,  0,  3,  0,  2,  1,  5,  // facedir = 1
		   0,  3,  0,  5,  0,  4,  1,  2,  // facedir = 2
		   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);
}
示例#2
0
/*
	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);
	if (facedir > 23)
		facedir = 0;
	static const u16 dir_to_tile[24 * 16] =
	{
		// 0     +X    +Y    +Z           -Z    -Y    -X   ->   value=tile,rotation  
		   0,0,  2,0 , 0,0 , 4,0 ,  0,0,  5,0 , 1,0 , 3,0 ,  // rotate around 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,  2,3 , 5,0 , 0,2 ,  0,0,  1,0 , 4,2 , 3,1 ,  // rotate around z+ 4 - 7
		   0,0,  4,3 , 2,0 , 0,3 ,  0,0,  1,1 , 3,2 , 5,1 ,
		   0,0,  3,3 , 4,0 , 0,0 ,  0,0,  1,2 , 5,2 , 2,1 ,
		   0,0,  5,3 , 3,0 , 0,1 ,  0,0,  1,3 , 2,2 , 4,1 ,

		   0,0,  2,1 , 4,2 , 1,2 ,  0,0,  0,0 , 5,0 , 3,3 ,  // rotate around z- 8 - 11
		   0,0,  4,1 , 3,2 , 1,3 ,  0,0,  0,3 , 2,0 , 5,3 ,
		   0,0,  3,1 , 5,2 , 1,0 ,  0,0,  0,2 , 4,0 , 2,3 ,
		   0,0,  5,1 , 2,2 , 1,1 ,  0,0,  0,1 , 3,0 , 4,3 ,

		   0,0,  0,3 , 3,3 , 4,1 ,  0,0,  5,3 , 2,3 , 1,3 ,  // rotate around x+ 12 - 15
		   0,0,  0,2 , 5,3 , 3,1 ,  0,0,  2,3 , 4,3 , 1,0 ,
		   0,0,  0,1 , 2,3 , 5,1 ,  0,0,  4,3 , 3,3 , 1,1 ,
		   0,0,  0,0 , 4,3 , 2,1 ,  0,0,  3,3 , 5,3 , 1,2 ,

		   0,0,  1,1 , 2,1 , 4,3 ,  0,0,  5,1 , 3,1 , 0,1 ,  // rotate around x- 16 - 19  
		   0,0,  1,2 , 4,1 , 3,3 ,  0,0,  2,1 , 5,1 , 0,0 ,
		   0,0,  1,3 , 3,1 , 5,3 ,  0,0,  4,1 , 2,1 , 0,3 ,  
		   0,0,  1,0 , 5,1 , 2,3 ,  0,0,  3,1 , 4,1 , 0,2 ,  

		   0,0,  3,2 , 1,2 , 4,2 ,  0,0,  5,2 , 0,2 , 2,2 ,  // rotate around y- 20 - 23
		   0,0,  5,2 , 1,3 , 3,2 ,  0,0,  2,2 , 0,1 , 4,2 ,  
		   0,0,  2,2 , 1,0 , 5,2 ,  0,0,  4,2 , 0,0 , 3,2 ,  
		   0,0,  4,2 , 1,1 , 2,2 ,  0,0,  3,2 , 0,3 , 5,2   

	};
	u16 tile_index=facedir*16 + dir_i;
	TileSpec spec = getNodeTileN(mn, p, dir_to_tile[tile_index], data);
	spec.rotation=dir_to_tile[tile_index + 1];
	spec.texture = data->m_gamedef->tsrc()->getTexture(spec.texture_id);
	return spec;
}
示例#3
0
/*
	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;

    // Get rotation for things like chests
    u8 facedir = mn.getFaceDir(ndef);
    assert(facedir <= 3);

    static const u8 dir_to_tile[4 * 8] =
    {
        // 0  +X  +Y  +Z   0  -Z  -Y  -X
        0,  2,  0,  4,  0,  5,  1,  3,  // facedir = 0
        0,  4,  0,  3,  0,  2,  1,  5,  // facedir = 1
        0,  3,  0,  5,  0,  4,  1,  2,  // facedir = 2
        0,  5,  0,  2,  0,  3,  1,  4,  // facedir = 3
    };
    u8 tileindex = dir_to_tile[facedir*8 + dir_i];

    // 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;
}