public static Vector3[] createWorldMesh(BlockClasses blocks) { List <Vector3> worldVertexes = new List <Vector3>(); foreach (Block block in blocks.world) { foreach (BlockVec.Direction dir in blocks.GetEmptyAround(block.pos)) { worldVertexes.AddRange(createFace(block.pos.ToUnity(), dir)); } } return(worldVertexes.ToArray()); }
public void CreateWorld(BlockClasses blocks) { GameObject chunkInstance = Instantiate(chunkObject, transform.position, new Quaternion(0, 0, 0, 0), transform); MeshFilter chunkInstanceMesh = chunkInstance.GetComponent <MeshFilter>(); Mesh mesh = new Mesh(); /* * Vector3[] vertices = new Vector3[3];//chunkInstanceMesh.sharedMesh.vertices; * vertices[0] = new Vector3(-1, 0, 0); * vertices[1] = new Vector3(1, 0, 0); * vertices[2] = new Vector3(0, 1.7f, 0); * mesh.vertices = vertices; */ mesh.vertices = MeshUtils.createWorldMesh(blocks); //mesh.uv = MeshUtils.GetUvs(3); mesh.triangles = MeshUtils.GetTris(mesh.vertices.Length); chunkInstanceMesh.sharedMesh = mesh; MeshCollider meshCollider = chunkInstance.GetComponent <MeshCollider>(); if (meshCollider != null) { meshCollider.sharedMesh = mesh; } /* * foreach (Block block in blocks.world) * { * GameObject blockInstance = Instantiate(BlockObject, block.pos.ToUnity() + transform.position, new Quaternion(0,0,0,0), transform); * } */ }
// Start is called before the first frame update void Start() { _blockManager = new BlockClasses(); Generate(0, 2, maxHeight, oneChunkSize, chunksPerDirection, vars); }