public Task BuildMesh(MaterialCollection materials, Dictionary <ChunkSide, Chunk> neighbours, Chunk chunk, int slice, bool rebuild) { return(Task.Run(() => { if (rebuild) { _meshData = GreedyMeshing.CreateMesh(chunk, neighbours, materials, null); } if (slice >= 0 && slice < ChunkDataSettings.YSize) { _meshDataSlice = GreedyMeshing.CreateMesh(chunk, neighbours, materials, slice); } })); }
public void BuildMesh(MaterialCollection materials, Dictionary <ChunkSide, Chunk> neighbours, Chunk chunk, int slice, bool rebuild) { NeedsUpdate = false; _meshRenderer.shadowCastingMode = slice <= 0 ? ShadowCastingMode.ShadowsOnly : ShadowCastingMode.On; if (slice <= 0 || slice > ChunkDataSettings.YSize && !rebuild) { return; } List <Vector3> upVoxels; var meshdata = GreedyMeshing.CreateMesh(chunk, neighbours, materials, slice, false, out upVoxels); ApplyMeshData(materials, meshdata, ref _mesh, _meshRenderer, _meshCollider, _meshFilter); gameObject.SetActive(meshdata.Vertices.Length != 0); meshdata = GreedyMeshing.CreateMesh(chunk, neighbours, materials, slice, true, out upVoxels); ApplyMeshData(materials, meshdata, ref _slicedMesh, _slicedRenderer, _slicedCollider, _slicedFilter); _sliced.SetActive(meshdata.Vertices.Length != 0); }