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); }
public void UpdateWindow(Point2 offset, Vector3 worldTranslation, Point2 windowSize) { entities.ForEach((e, p) => { var v = world.GetVoxel(p + new Point2(offset)); if (v == null) { e.Visible = false; return; } e.Mesh = getMesh(v); e.WorldMatrix = Matrix.Scaling(new Vector3(world.VoxelSize.X)) * Matrix.Translation(world.GetBoundingBox(p).GetCenter() + worldTranslation); e.Visible = e.Mesh != null; }); }