void RenderMesh(MeshData meshData) { Filter.mesh.Clear(); Filter.mesh.vertices = meshData.Verticies.ToArray(); Filter.mesh.triangles = meshData.Tris.ToArray(); Filter.mesh.uv = meshData.UV.ToArray(); Filter.mesh.RecalculateNormals(); Coll.sharedMesh = null; Mesh mesh = new Mesh(); mesh.vertices = meshData.ColVerticies.ToArray(); mesh.triangles = meshData.ColTris.ToArray(); mesh.RecalculateNormals(); Coll.sharedMesh = mesh; }
public virtual MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData) { meshData.UseRenderDataForCol = true; if (!chunk.GetBlock(x, y + 1, z).IsSolid(Direction.Down)) { meshData = FaceDataUp(chunk, x, y, z, meshData); } if (!chunk.GetBlock(x, y - 1, z).IsSolid(Direction.Up)) { meshData = FaceDataDown(chunk, x, y, z, meshData); } if (!chunk.GetBlock(x, y, z + 1).IsSolid(Direction.South)) { meshData = FaceDataNorth(chunk, x, y, z, meshData); } if (!chunk.GetBlock(x, y, z - 1).IsSolid(Direction.North)) { meshData = FaceDataSouth(chunk, x, y, z, meshData); } if (!chunk.GetBlock(x + 1, y, z).IsSolid(Direction.West)) { meshData = FaceDataEast(chunk, x, y, z, meshData); } if (!chunk.GetBlock(x - 1, y, z).IsSolid(Direction.East)) { meshData = FaceDataWest(chunk, x, y, z, meshData); } return meshData; }
protected virtual MeshData FaceDataWest(Chunk chunk, int x, int y, int z, MeshData meshData) { meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z + 0.5f)); meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f)); meshData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f)); meshData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, z - 0.5f)); meshData.AddQuadTriangles(); meshData.UV.AddRange (FaceUVs (Direction.West)); return meshData; }
public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData) { return meshData; }
public override MeshData Blockdata(Chunk chunk, int x, int y, int z, MeshData meshData) { return(meshData); }
void UpdateChunk() { MeshData meshData = new MeshData(); for (int x = 0; x < CHUNK_SIZE; x++) { for (int y = 0; y < CHUNK_SIZE; y++) { for (int z = 0; z < CHUNK_SIZE; z++) { meshData = Blocks[x, y, z].Blockdata(this, x, y, z, meshData); } } } RenderMesh(meshData); }