//threaded mesh creation // basically just creates the triangles and vertices on a thread then adds them to a mesh //in the main thread /// <summary> /// Creates the vertices. /// </summary> public void CreateVertices() { canCreatemesh = false; //create the verts verts = MarchingCubes.CreateVertices(Voxels, this, 2, 2, lodLevel); //store the size so as to avoid garbage creation size = verts.Length; //create normals normals = MeshFactory.CalculateNormals(Voxels, size, verts, lodLevel); //create colors int V = size; uv = new Color[size]; for (int i = 0; i < size; i++) { int x = Mathf.RoundToInt((verts[i].x - normals[i].x) / VoxelTerrainEngine.TriSize[lodLevel]); int y = Mathf.RoundToInt((verts[i].y - normals[i].y) / VoxelTerrainEngine.TriSize[lodLevel]); int z = Mathf.RoundToInt((verts[i].z - normals[i].z) / VoxelTerrainEngine.TriSize[lodLevel]); //conversion from voxel value to voxel type //seems to work well byte vox = Materials[x, y, z]; //basically each value gets assigned a color of 0.5 to 1.0 //in theory each decimal could be a voxel type if (vox == (int)VoxelType.Stone) { uv[i] = new Color(1, 0, 0, 0); } else if (vox == (int)VoxelType.Grass) { uv[i] = new Color(0, 1, 0, 0); } else if (vox == (int)VoxelType.SandStone) { uv[i] = new Color(0, 0, 1, 0); } else if (vox == (int)VoxelType.Dirt) { uv[i] = new Color(0, 0, 0, 1); } } canCreatemesh = true; VoxelTerrainEngine.MeshChunks.Enqueue(this); }
public static Vector3[] Createvertices(byte[,,] m_voxels, VoxelChunk chunk, int lod) { Vector3[] vertices = MarchingCubes.CreateVertices(m_voxels, chunk, 2, 2, lod); return(vertices); }