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(); }
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 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 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()); }
private Entity getEntity(ModelObjectGraphSimulator.Vertex v) { if (!entities.ContainsKey(v)) { var ent = new Entity(); ent.Mesh = UtilityMeshes.CreateMeshWithText(0.4f, v.ModelObject.GetType().Name, TW.Graphics); entities[v] = ent; TW.Data.Get <Data>().OwnedEntities.Add(ent); } return(entities[v]); }
public void initRendering() { text = new TextRectangle(); text.IsBillboard = true; plusBoxEnt = new Entity(); minBoxEnt = new Entity(); plusBoxEnt.Mesh = UtilityMeshes.CreateMeshWithText(0.5f, "+", TW.Graphics); minBoxEnt.Mesh = UtilityMeshes.CreateMeshWithText(0.5f, "-", TW.Graphics); Update(); Hide(); }
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))); }
public void TestExport() { var tex = new RAMTexture(); tex.GetCoreData().DiskFilePath = "trolo.png"; var mesh = UtilityMeshes.CreateBoxWithTexture(tex, new Vector3(10, 10, 10)); var exporter = new OBJExporter(); var objMesh = exporter.ConvertFromTWMesh(mesh); exporter.SaveToFile(objMesh, TWDir.GameData.CreateSubdirectory("Scattered\\Tests").FullName + "\\OBJExporterTrolo.obj"); }
private Physical getPhysical(IHotbarItem item) { if (physicals.ContainsKey(item)) { return(physicals[item]); } var physical = new Physical(); physical.Mesh = UtilityMeshes.CreateMeshWithText(0.5f, item.Name, TW.Graphics); physicals[item] = physical; return(physical); }
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 void FixMesh() { var text = "Wants: " + TraderPart.WantsAmount + " " + TraderPart.WantsType.Name + "\n" + "You get: " + TraderPart.GivesAmount + " " + TraderPart.GivesType.Name; if (TraderPart.StoredResourcesCount < TraderPart.GivesAmount) { text += "\nOut of resources"; } //text = "hello"; Physical.Mesh = UtilityMeshes.CreateMeshWithText(1, text, TW.Graphics); Physical.ObjectMatrix = Matrix.Translation(new Vector3(0, 1, 0)); }
public PrototypeObjectsFactory(IGameObjectsRepository repository) { this.repository = repository; TubeType = new ItemType() { Name = "Tube", Mesh = TW.Assets.LoadMesh("SkyMerchant/TubePart/TubePart") }; CogType = new ItemType() { Name = "Cog", Mesh = TW.Assets.LoadMesh("SkyMerchant/Cogs/Cog01") }; WoodType = new ItemType() { Name = "Wood", Mesh = UtilityMeshes.CreateMeshWithText(0.4f, "Wood", TW.Graphics) }; }
public void Show(Vector3 pos, Vector3 lookDir, Vector3 up) { Visible = true; Position = pos; lookDirection = lookDir; this.up = up; right = -Vector3.Cross(up, lookDirection); up = Vector3.Cross(lookDirection, up); foreach (var i in config.Items) { var color = new Color4(0.5f, 1, 0); if (provider.IsTargeted(i)) { color = new Color4(1, 0, 0); } var bb = getBoundingBox(i); if (!map.ContainsKey(i)) { var e = new Entity() { Mesh = UtilityMeshes.CreateMeshWithText(bb.GetSize().X * 0.5f, i.Name, TW.Graphics) //Visible = false }; entities.Add(e); map[i] = e; } var ent = map[i]; ent.WorldMatrix = Matrix.Translation(bb.GetCenter()); ent.Visible = true; } provider.Enabled = true; }
private void updateTexture() { Entity.Mesh = UtilityMeshes.CreateBoxWithTexture(UtilityMeshes.CreateTextureAssetFromText(_text, TW.Graphics), new Vector3(1, 1, 0.0002f)); Update(); }
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))); }
public ParticlesBoxRenderer() { boxMesh = UtilityMeshes.CreateBoxWithTexture(null, new Vector3(1, 1, 1)); }
private IMesh createMeshWithColor(Color4 color) { return(UtilityMeshes.CreateBoxColoredSize(color, new Vector3(0.5f, maxHeight, 0.5f))); }