private void updateVisibleChunks(Point2 offset, Point2 windowSize) { windowSize = ((offset + windowSize).ToVector2() / ChunkSize).Ceiling(); offset = (offset.ToVector2() / ChunkSize).Floor(); windowSize -= offset; chunkEntities.ForEach((e, _) => e.Visible = false); var visible = new List <Entity>(); windowSize.ForEach(p => { p += offset; var chunk = chunkEntities[p]; if (chunk == null) { return; } visible.Add(chunkEntities[p]); if (chunk.Mesh == null || dirtyChunks.Contains(p)) { updateChunk(p); } }); visible.ForEach(e => e.Visible = true); chunkEntities.Values.Except(visible).ForEach(e => e.Visible = false); }
private IMesh BuildChunkMesh(Point2 offset, Point2 size) { IMesh batch = new RAMMesh(); size.ForEach(p => { var v = world.GetVoxel(p + new Point2(offset)); if (v == null) { return; } var mesh = meshProvider.GetMesh(v); if (mesh == null) { return; } var vWorld = Matrix.Scaling(new Vector3(world.VoxelSize.X)) * Matrix.Translation(((p.ToVector2() + new Vector2(0.5f)) * world.VoxelSize.X).ToXZ(v.Data.Height)); MeshBuilder.AppendMeshTo(meshProvider.GetMesh(v), batch, vWorld); }); var optimizer = new MeshOptimizer(); batch = optimizer.CreateOptimized(batch); return(batch); }