protected override MeshData FaceDataDown(Chunk chunk, int x, int y, int z, MeshData meshData) { meshData.AddVertex(new Vector3(x + blockSize, y - blockSize, z - blockSize)); meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z - blockSize)); meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z + blockSize)); meshData.AddVertex(new Vector3(x + blockSize, y - blockSize, z + blockSize)); meshData.AddQuadTriangles(); return meshData; }
public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData) { this.chunk = chunk; meshData.useRenderDataForCol = true; //DOWN meshData = FaceDataUp(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.down)); meshData.uv.AddRange(FaceUVs(Direction.down)); meshData.uv.AddRange(FaceUVs(Direction.down)); meshData.uv.AddRange(FaceUVs(Direction.down)); //UP meshData = FaceDataDown(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.up)); meshData.uv.AddRange(FaceUVs(Direction.up)); meshData.uv.AddRange(FaceUVs(Direction.up)); meshData.uv.AddRange(FaceUVs(Direction.up)); //SOUTH meshData = FaceDataNorth(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.south)); meshData.uv.AddRange(FaceUVs(Direction.south)); meshData.uv.AddRange(FaceUVs(Direction.south)); meshData.uv.AddRange(FaceUVs(Direction.south)); //NORTH meshData = FaceDataSouth(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.north)); meshData.uv.AddRange(FaceUVs(Direction.north)); meshData.uv.AddRange(FaceUVs(Direction.north)); meshData.uv.AddRange(FaceUVs(Direction.north)); //WEST meshData = FaceDataEast(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.west)); meshData.uv.AddRange(FaceUVs(Direction.west)); meshData.uv.AddRange(FaceUVs(Direction.west)); meshData.uv.AddRange(FaceUVs(Direction.west)); //EAST meshData = FaceDataWest(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.east)); meshData.uv.AddRange(FaceUVs(Direction.east)); meshData.uv.AddRange(FaceUVs(Direction.east)); meshData.uv.AddRange(FaceUVs(Direction.east)); return meshData; }
public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData) { this.chunk = chunk; meshData.useRenderDataForCol = true; if (chunk.GetBlock(x, y - 1, z).IsSolid(Direction.up)) { meshData = FaceDataDown(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.down)); } return meshData; }
// Sends the calculated mesh information // to the mesh and collision components void RenderMesh(MeshData meshData) { filter.mesh.Clear(); filter.mesh.vertices = meshData.vertices.ToArray(); filter.mesh.triangles = meshData.triangles.ToArray(); filter.mesh.uv = meshData.uv.ToArray(); filter.mesh.RecalculateNormals(); coll.sharedMesh = null; Mesh mesh = new Mesh(); mesh.vertices = meshData.colVertices.ToArray(); mesh.triangles = meshData.colTriangles.ToArray(); mesh.RecalculateNormals(); coll.sharedMesh = mesh; }
public virtual MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData) { this.chunk = chunk; meshData.useRenderDataForCol = true; if (!chunk.GetBlock(x, y + 1, z).IsSolid(Direction.down)) { meshData = FaceDataUp(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.down)); } if (!chunk.GetBlock(x, y - 1, z).IsSolid(Direction.up)) { meshData = FaceDataDown(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.up)); } if (!chunk.GetBlock(x, y, z + 1).IsSolid(Direction.south)) { meshData = FaceDataNorth(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.south)); } if (!chunk.GetBlock(x, y, z - 1).IsSolid(Direction.north)) { meshData = FaceDataSouth(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.north)); } if (!chunk.GetBlock(x + 1, y, z).IsSolid(Direction.west)) { meshData = FaceDataEast(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.west)); } if (!chunk.GetBlock(x - 1, y, z).IsSolid(Direction.east)) { meshData = FaceDataWest(chunk, x, y, z, meshData); meshData.uv.AddRange(FaceUVs(Direction.east)); } return meshData; }
protected virtual MeshData FaceDataWest(Chunk chunk, int x, int y, int z, MeshData meshData) { meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z + blockSize)); meshData.AddVertex(new Vector3(x - blockSize, y + blockSize, z + blockSize)); meshData.AddVertex(new Vector3(x - blockSize, y + blockSize, z - blockSize)); meshData.AddVertex(new Vector3(x - blockSize, y - blockSize, z - blockSize)); meshData.AddQuadTriangles(); return meshData; }
public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData) { return meshData; }
void UpdateChunk() { rendered = true; MeshData meshData = new MeshData(); for (int x = 0; x < chunkSize; x++) { for (int y = 0; y < chunkSize; y++) { for (int z = 0; z < chunkSize; z++) { meshData = blocks[x, y, z].Blockdata(this, x, y, z, meshData); } } } RenderMesh(meshData); }
protected override MeshData FaceDataDown(Chunk chunk, int x, int y, int z, MeshData meshData) { meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), (z - treeOffset) - blockSize)); meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), (z - treeOffset) - blockSize)); meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), (z - treeOffset) + blockSize)); meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), (z - treeOffset) + blockSize)); meshData.AddQuadTriangles(); meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), z - blockSize)); meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), z - blockSize)); meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), z + blockSize)); meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), z + blockSize)); meshData.AddQuadTriangles(); meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), z - blockSize)); meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), z - blockSize)); meshData.AddVertex(new Vector3((x - treeOffset) + blockSize, y - (blockSize * treeHeight), z + blockSize)); meshData.AddVertex(new Vector3((x - treeOffset) - blockSize, y - (blockSize * treeHeight), z + blockSize)); meshData.AddQuadTriangles(); meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), (z + treeOffset) - blockSize)); meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), (z + treeOffset) - blockSize)); meshData.AddVertex(new Vector3((x + treeOffset) + blockSize, y - (blockSize * treeHeight), (z + treeOffset) + blockSize)); meshData.AddVertex(new Vector3((x + treeOffset) - blockSize, y - (blockSize * treeHeight), (z + treeOffset) + blockSize)); meshData.AddQuadTriangles(); return meshData; }