public override void Generate(MeshBuilder activeBuilder, Vector3Int pos, ChunkSection c) { Vector3Int top = pos - BlockMesh.Offset[BlockMesh.Up]; BlockType topBlock = (c != null) ? c.GetBlock(top.x, top.y, top.z) : BlockType.Air; Vector3[][] vertices; if (topBlock != Type) { vertices = FluidMesh.Vertices; } else { vertices = BlockMesh.Vertices; } TryAddFace(activeBuilder, pos, BlockMesh.East, c, vertices); TryAddFace(activeBuilder, pos, BlockMesh.West, c, vertices); TryAddFace(activeBuilder, pos, BlockMesh.South, c, vertices); TryAddFace(activeBuilder, pos, BlockMesh.North, c, vertices); TryAddFace(activeBuilder, pos, BlockMesh.Down, c, vertices); TryAddFace(activeBuilder, pos, BlockMesh.Up, c, vertices); }
void TryAddFace(MeshBuilder activeBuilder, Vector3 pos, int dir, ChunkSection c, Vector3[][] vertices) { if (c == null) { activeBuilder.AddQuad(vertices, pos, dir, UVs); return; } Vector3Int adj = (pos - BlockMesh.Offset[dir]).ToIntVec(); BlockType adjBlock = c.GetBlock(adj.x, adj.y, adj.z); if (Type != adjBlock && !BlockDictionary.Get(adjBlock).Opaque) { activeBuilder.AddQuad(vertices, pos, dir, UVs); } }
bool ShouldMakeFace(Vector3Int pos, int dir, ChunkSection c) { Vector3Int adj = pos - BlockMesh.Offset[dir]; BlockType adjBlock = BlockType.Air; if (c != null) { adjBlock = c.GetBlock(adj.x, adj.y, adj.z); } if (Order == MeshOrder.Fluid && Type == adjBlock) { return(false); } if (!BlockDictionary.Get(adjBlock).Opaque) { return(true); } return(false); }