Skip to content

Commit

Permalink
clean up face textures
Browse files Browse the repository at this point in the history
  • Loading branch information
tomba committed Mar 12, 2016
1 parent ef9de49 commit 8ea3149
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Client/MapControl3D/VoxelTerrain/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ void CreateUndefinedChunk(ref IntGrid3 viewGrid, ref IntGrid3 chunkGrid, VertexL
}
}

void GetTextures(IntVector3 p, ref Voxel vox, out FaceTexture baseTexture, out FaceTexture topTexture)
void GetTextures(IntVector3 p, ref Voxel vox, out FaceTexture baseTexture, out FaceTexture topTexture,
bool showFloor)
{
var td = m_map.GetTileData(p);

Expand Down Expand Up @@ -553,7 +554,7 @@ void GetTextures(IntVector3 p, ref Voxel vox, out FaceTexture baseTexture, out F
}

// If the top face of the tile is visible, we have a "floor"
if ((vox.VisibleFaces & Direction.PositiveZ) != 0)
if (showFloor && (vox.VisibleFaces & Direction.PositiveZ) != 0)
{
if (m_map.Contains(p.Up) && m_map.GetTileData(p.Up).IsGreen)
{
Expand Down Expand Up @@ -623,16 +624,12 @@ void GetTextures(IntVector3 p, ref Voxel vox, out FaceTexture baseTexture, out F
void HandleVoxel(IntVector3 p, ref Voxel vox, ref IntGrid3 viewGrid, Direction visibleChunkFaces,
VertexList<TerrainVertex> vertexList)
{
FaceTexture baseTexture, topTexture;

GetTextures(p, ref vox, out baseTexture, out topTexture);

int x = p.X;
int y = p.Y;
int z = p.Z;

Direction visibleFaces = visibleChunkFaces & vox.VisibleFaces;
/* sides that are shown due to the viewgrid, but are really hidden by other voxels */
// Faces that are hidden by other voxels, but shown due to viewgrid
Direction visibleHiddenFaces = 0;

// up
Expand All @@ -641,8 +638,6 @@ void HandleVoxel(IntVector3 p, ref Voxel vox, ref IntGrid3 viewGrid, Direction v
const Direction b = Direction.PositiveZ;
visibleHiddenFaces |= b & ~visibleFaces;
visibleFaces |= b;
// override the top tex to remove the grass
topTexture = baseTexture;
}

// down
Expand Down Expand Up @@ -685,6 +680,10 @@ void HandleVoxel(IntVector3 p, ref Voxel vox, ref IntGrid3 viewGrid, Direction v
if (visibleFaces == 0)
return;

FaceTexture baseTexture, topTexture;
bool showFloor = z != viewGrid.Z2;
GetTextures(p, ref vox, out baseTexture, out topTexture, showFloor);

CreateCube(p, visibleFaces, visibleHiddenFaces, ref baseTexture, ref topTexture, vertexList);
}

Expand Down

0 comments on commit 8ea3149

Please sign in to comment.