public override IMesh GetMesh(IVoxelHandle handle) { if (handle.Data.DataValue < datavalOffset) { handle.Data.DataValue = datavalOffset; } var index = (int)Math.Floor((handle.Data.DataValue - datavalOffset) / (float)batchSize); if (index > 4) { index = 4; } IMesh tmp; datavalueMeshes.TryGetValue(index, out tmp); if (tmp == null) { tmp = UtilityMeshes.CreateBoxColored(Color.FromArgb(255, 86, 86, 86), new Vector3(0.5f, 0.05f, 0.5f)); } var meshBuilder = new MeshBuilder(); meshBuilder.AddMesh(tmp, Matrix.Identity); var groundMesh = GetDefaultGroundMesh(handle.Data.Height, Color.FromArgb(255, 86, 86, 86)); if (groundMesh == null) { return(tmp); } meshBuilder.AddMesh(groundMesh, Matrix.Translation(0, -0.9f, 0)); return(meshBuilder.CreateMesh()); }
public void TestDeleteMeshNoMemoryLeak() { var game = new DX11Game(); game.InitDirectX(); var renderer = new DeferredRenderer(game); var mesh = UtilityMeshes.CreateBoxColored(new Color4(1, 0, 0), new Vector3(0.1f)); DeferredMeshElement[] elements = new DeferredMeshElement[100]; int i = 0; game.GameLoopEvent += delegate { elements[i] = renderer.CreateMeshElement(mesh); elements[i].WorldMatrix = Matrix.Translation((float)Math.Cos((float)i / elements.Length * MathHelper.TwoPi) * 5, 0, (float)Math.Sin((float)i / elements.Length * MathHelper.TwoPi) * 5); i = (i + 1) % elements.Length; //if (elements[i] != null) elements[i].Delete(); renderer.Draw(); }; game.Run(); }
public override IEnumerable <IRenderable> GetCustomVisualizers(IVoxelHandle handle) { foreach (var e in base.GetCustomVisualizers(handle)) { yield return(e); } yield return(new EntityVisualizer(e => { e.Mesh = UtilityMeshes.CreateBoxColored(new Color4(0, 0, 1), new Vector3(1)); var miner = ((IVoxel)handle).GetPart <Miner>(); var targetVoxel = miner.TargetOreVoxel; e.Visible = targetVoxel != null; if (targetVoxel == null) { return; } var progress = miner.OreMiningProgress; var factor = progress < 0.5f ? progress * 2 : 1 - (progress - 0.5f) * 2; var toOre = handle.GetOffset(targetVoxel); var offset = (toOre.ToVector2() * factor).ToXZ(); e.WorldMatrix = Matrix.Translation(((GameVoxel)handle).GetBoundingBox().GetCenter() + offset * 10); })); }
public void TestRenderManyMeshes() { var game = new DX11Game(); game.InitDirectX(); var renderer = new DeferredRenderer(game); var mesh = UtilityMeshes.CreateBoxColored(new Color4(1, 0, 0), new Vector3(0.1f)); DeferredMeshElement[] elements = new DeferredMeshElement[100]; for (int i = 0; i < elements.Length; i++) { elements[i] = renderer.CreateMeshElement(mesh); elements[i].WorldMatrix = Matrix.Translation((float)Math.Cos((float)i / elements.Length * MathHelper.TwoPi) * 5, 0, (float)Math.Sin((float)i / elements.Length * MathHelper.TwoPi) * 5); } game.GameLoopEvent += delegate { renderer.Draw(); }; game.Run(); }
private ItemType CreateItemType(string name, Color color) { if (rawTypes.Any(t => t.Name == name)) { throw new InvalidOperationException("Duplicate item name!!"); } var ret = new ItemType { Name = name, Mesh = UtilityMeshes.CreateBoxColored(color, new Vector3(1)) }; rawTypes.Add(ret); return(ret); }
public IMesh GetDefaultGroundMesh(float height, Color c) { const float groundHeight = 15f * 0.1f; var meshheight = height * 0.1f; if (meshheight < 0) { return(null); } var ret = UtilityMeshes.CreateBoxColored(c, new Vector3(0.5f, meshheight + groundHeight, 0.5f)); return(MeshBuilder.Transform(ret, Matrix.Translation(0, -meshheight - 0.1f - groundHeight, 0))); }
private ItemTypeKanbans createKanbanTypes(ItemType type) { var ret = new ItemTypeKanbans { ItemType = type, IncomingKanban = new ItemType { Name = type.Name + "IncomingKanban", Mesh = UtilityMeshes.CreateBoxColored(Color.Green, new Vector3(0.5f)) }, OutgoingKanban = new ItemType { Name = type.Name + "OutgoingKanban", Mesh = UtilityMeshes.CreateBoxColored(Color.Red, new Vector3(0.5f)) } }; kanbanTypes.Add(ret); return(ret); }
public static IMesh createColoredMesh(Color color1) { return(MeshBuilder.Transform(UtilityMeshes.CreateBoxColored(color1, new Vector3(0.5f, 0.05f, 0.5f)), Matrix.Translation(0, -0.05f, 0))); }