void RegenMesh() { workItemMeshRef?.Dispose(); workItemMeshRef = null; if (stack == null) { return; } Shape shape; tmpMetal = stack.Collectible.LastCodePart(); if (stack.Collectible.FirstCodePart() == "metalplate") { tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("platepile"))); shape = capi.Assets.TryGet("shapes/block/stone/forge/platepile.json").ToObject <Shape>(); } else { tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("ingotpile"))); shape = capi.Assets.TryGet("shapes/block/stone/forge/ingotpile.json").ToObject <Shape>(); } workItemTexPos = tmpTextureSource[tmpMetal]; MeshData mesh; capi.Tesselator.TesselateShape("block-fcr", shape, out mesh, this, null, 0, 0, stack.StackSize); mesh.Rgba2 = null; workItemMeshRef = capi.Render.UploadMesh(mesh); }
internal void SetChildRenderer(ItemStack contentStack, IInFirepitRenderer renderer) { this.ContentStack = contentStack; meshref?.Dispose(); meshref = null; contentStackRenderer = renderer; }
private void RegenOutlineMesh(ClayFormingRecipe recipeToOutline, bool[,,] Voxels, int recipeLayer) { MeshData recipeOutlineMesh = new MeshData(24, 36, false, false, true, false); recipeOutlineMesh.SetMode(EnumDrawMode.Lines); int greenCol = (156 << 24) | (100 << 16) | (200 << 8) | (100); int orangeCol = (156 << 24) | (226 << 16) | (171 << 8) | (92); MeshData greenVoxelMesh = LineMeshUtil.GetCube(greenCol); MeshData orangeVoxelMesh = LineMeshUtil.GetCube(orangeCol); for (int i = 0; i < greenVoxelMesh.xyz.Length; i++) { greenVoxelMesh.xyz[i] = greenVoxelMesh.xyz[i] / 32f + 1 / 32f; orangeVoxelMesh.xyz[i] = orangeVoxelMesh.xyz[i] / 32f + 1 / 32f; } MeshData voxelMeshOffset = greenVoxelMesh.Clone(); for (int x = 0; x < 16; x++) { int y = recipeLayer; for (int z = 0; z < 16; z++) { bool shouldFill = recipeToOutline.Voxels[x, y, z]; bool didFill = Voxels[x, y, z]; if (shouldFill == didFill) { continue; } float px = x / 16f; float py = y / 16f + 0.001f; float pz = z / 16f; for (int i = 0; i < greenVoxelMesh.xyz.Length; i += 3) { voxelMeshOffset.xyz[i] = px + greenVoxelMesh.xyz[i]; voxelMeshOffset.xyz[i + 1] = py + greenVoxelMesh.xyz[i + 1]; voxelMeshOffset.xyz[i + 2] = pz + greenVoxelMesh.xyz[i + 2]; } voxelMeshOffset.Rgba = (shouldFill && !didFill) ? greenVoxelMesh.Rgba : orangeVoxelMesh.Rgba; recipeOutlineMesh.AddMeshData(voxelMeshOffset); } } recipeOutlineMeshRef?.Dispose(); recipeOutlineMeshRef = null; if (recipeOutlineMesh.VerticesCount > 0) { recipeOutlineMeshRef = api.Render.UploadMesh(recipeOutlineMesh); } }
public override void OnBlockUnloaded() { base.OnBlockUnloaded(); renderer?.Dispose(); // BaseMeshRef is the engine default mesh, we don't need to dispose it FluxMeshRef?.Dispose(); TopMeshRef?.Dispose(); }
public override void Dispose() { base.Dispose(); blockMeshRef1?.Dispose(); blockMeshRef2?.Dispose(); }
public void LoadCloudModel() { MeshData modeldata = new MeshData(4 * 6, 6 * 6, false, false, true); modeldata.Rgba2 = null; modeldata.Flags = new int[4 * 6]; float[] CloudSideShadings = new float[] { 1f, 0.9f, 0.9f, 0.7f }; MeshData tile = CloudMeshUtil.GetCubeModelDataForClouds( CloudTileSize / 2, CloudTileSize / 4, new Vec3f(0, 0, 0) ); byte[] rgba = CubeMeshUtil.GetShadedCubeRGBA(ColorUtil.WhiteArgb, CloudSideShadings, false); tile.SetRgba(rgba); tile.Flags = new int[] { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 }; modeldata.AddMeshData(tile); // modeldata will hold xyz (+offset), indices and cloud density InitCustomDataBuffers(modeldata); UpdateBufferContents(modeldata); cloudTilesMeshRef?.Dispose(); cloudTilesMeshRef = capi.Render.UploadMesh(modeldata); }
public void Dispose() { gearboxCage?.Dispose(); gearboxPeg?.Dispose(); axle?.Dispose(); windmillRotor?.Dispose(); }
public void Dispose() { capi.Event.UnregisterRenderer(this, EnumRenderStage.Opaque); capi.Event.UnregisterRenderer(this, EnumRenderStage.ShadowFar); capi.Event.UnregisterRenderer(this, EnumRenderStage.ShadowNear); meshref?.Dispose(); }
public void Dispose() { capi.Event.UnregisterRenderer(this, EnumRenderStage.Opaque); emberQuadRef?.Dispose(); coalQuadRef?.Dispose(); workItemMeshRef?.Dispose(); }
public void Dispose() { api.Event.UnregisterRenderer(this, EnumRenderStage.Opaque); loadedTexture?.Dispose(); quadModelRef?.Dispose(); }
public override void Dispose() { base.Dispose(); gearboxCage?.Dispose(); gearboxPeg?.Dispose(); }
public override void Dispose() { if (meshRefOpaque != null) { meshRefOpaque.Dispose(); meshRefOpaque = null; } if (meshRefOit != null) { meshRefOit.Dispose(); meshRefOit = null; } if (nameTagTexture != null) { nameTagTexture.Dispose(); nameTagTexture = null; } if (debugTagTexture != null) { debugTagTexture.Dispose(); debugTagTexture = null; } capi.Event.ReloadShapes -= TesselateShape; }
public override void Dispose() { base.Dispose(); quadModel.Dispose(); // Texture is disposed by WaypointMapLayer }
public void Dispose() { potRef?.Dispose(); lidRef?.Dispose(); cookingSound?.Stop(); cookingSound?.Dispose(); }
private void RegenOutlineMesh(SmithingRecipe recipeToOutline) { recipeOutlineMeshRef?.Dispose(); MeshData recipeOutlineMesh = new MeshData(24, 36, false, false, true, false, false); recipeOutlineMesh.SetMode(EnumDrawMode.Lines); MeshData voxelMesh = LineMeshUtil.GetCube((180 << 24) | (100 << 16) | (200 << 8) | (200)); for (int i = 0; i < voxelMesh.xyz.Length; i++) { voxelMesh.xyz[i] = voxelMesh.xyz[i] / 32f + 1 / 32f; } MeshData voxelMeshOffset = voxelMesh.Clone(); for (int x = 0; x < 16; x++) { int y = 10; for (int z = 0; z < 16; z++) { if (!recipeToOutline.Voxels[x, z]) { continue; } float px = x / 16f; float py = y / 16f; float pz = z / 16f; for (int i = 0; i < voxelMesh.xyz.Length; i += 3) { voxelMeshOffset.xyz[i] = px + voxelMesh.xyz[i]; voxelMeshOffset.xyz[i + 1] = py + voxelMesh.xyz[i + 1]; voxelMeshOffset.xyz[i + 2] = pz + voxelMesh.xyz[i + 2]; } recipeOutlineMesh.AddMeshData(voxelMeshOffset); } } recipeOutlineMeshRef = api.Render.UploadMesh(recipeOutlineMesh); }
public void Dispose() { capi.Event.UnregisterRenderer(this, EnumRenderStage.Opaque); if (heQuadRef != null) { heQuadRef.Dispose(); } if (workItemMeshRef != null) { workItemMeshRef.Dispose(); } }
public override void Dispose() { base.Dispose(); toggleMeshref?.Dispose(); for (int i = 0; i < metals.Length; i++) { lPoundMeshrefs[i]?.Dispose(); rPounderMeshrefs[i]?.Dispose(); } }
public void InitQuads() { quadTilesRef?.Dispose(); float height = 200; MeshData mesh = new MeshData(4, 6, false, true, true, false); float x = 0, y = 0, z = 0; Random rnd = new Random(); for (int i = 0; i < 15; i++) { Vec3f dir = new Vec3f((float)rnd.NextDouble() * 20 - 10, (float)rnd.NextDouble() * 5 - 3, (float)rnd.NextDouble() * 20 - 10); dir.Normalize(); x = (float)rnd.NextDouble() * 800 - 400; y = (float)rnd.NextDouble() * 80 - 40; z = (float)rnd.NextDouble() * 800 - 400; for (int j = 0; j < 100; j++) { float lngx = (float)rnd.NextDouble() * 5 + 20; float lngy = (float)rnd.NextDouble() * 4 + 4; float lngz = (float)rnd.NextDouble() * 5 + 20; x += dir.X * lngx; y += dir.Y * lngy; z += dir.Z * lngz; //float width = 20 + (float)rnd.NextDouble() * 5; //MeshData quad = QuadMeshUtil.GetCustomQuad(z, 20, x, x - prevx, height, 255, 255, 255, 255); //mesh.AddMeshData(quad); int lastelement = mesh.VerticesCount; mesh.AddVertex(x, y + height, z, j % 2, 1); mesh.AddVertex(x, y, z, j % 2, 0); if (j > 0 && j < 19) { mesh.AddIndex(lastelement + 0); mesh.AddIndex(lastelement + 1); mesh.AddIndex(lastelement + 2); mesh.AddIndex(lastelement + 1); mesh.AddIndex(lastelement + 3); mesh.AddIndex(lastelement + 2); } } } quadTilesRef = capi.Render.UploadMesh(mesh); }
internal void UpdateMeshes(MeshData needleMesh, MeshData discMesh) { needleMeshRef?.Dispose(); discMeshRef?.Dispose(); needleMeshRef = null; discMeshRef = null; if (needleMesh != null) { //needleMesh.Rgba2 = null; needleMeshRef = api.Render.UploadMesh(needleMesh); } if (discMesh != null) { //discMesh.Rgba2 = null; discMeshRef = api.Render.UploadMesh(discMesh); } updatedTotalMs = api.World.ElapsedMilliseconds; }
public void SetFillLevel(float voxelHeight) { if (this.voxelHeight == voxelHeight && cubeModelRef != null) { return; } this.voxelHeight = voxelHeight; cubeModelRef?.Dispose(); if (voxelHeight == 0) { return; } MeshData modeldata = CubeMeshUtil.GetCube(8 / 32f, voxelHeight / 32f, new Vec3f(0, 0, 0)); modeldata.Flags = new int[6 * 4]; cubeModelRef = api.Render.UploadMesh(modeldata); }
public override void Dispose() { if (texturesByIcon != null) { foreach (var val in texturesByIcon) { val.Value.Dispose(); } } texturesByIcon = null; quadModel?.Dispose(); base.Dispose(); }
public void RegenMesh(ItemStack workitemStack, byte[,,] voxels, bool[,,] recipeToOutlineVoxels) { workItemMeshRef?.Dispose(); workItemMeshRef = null; this.ingot = workitemStack; if (workitemStack == null) { return; } ObjectCacheUtil.Delete(api, "" + workitemStack.Attributes.GetInt("meshRefId")); workitemStack.Attributes.RemoveAttribute("meshRefId"); if (recipeToOutlineVoxels != null) { RegenOutlineMesh(recipeToOutlineVoxels, voxels); } MeshData workItemMesh = ItemWorkItem.GenMesh(api, workitemStack, voxels, out texId); workItemMeshRef = api.Render.UploadMesh(workItemMesh); }
protected void genMesh(List <Vec3d> points) { float[] data = new float[points.Count * 3]; for (int i = 0; i < points.Count; i++) { var point = points[i]; data[i * 3 + 0] = (float)point.X; data[i * 3 + 1] = (float)point.Y; data[i * 3 + 2] = (float)point.Z; } quadRef?.Dispose(); var quadMesh = CubeMeshUtil.GetCube(0.5f, 0.5f, 0.5f, new Vec3f(0f, 0f, 0f)); quadMesh.Flags = null; quadMesh.Rgba = null; quadMesh.CustomFloats = new CustomMeshDataPartFloat() { Instanced = true, InterleaveOffsets = new int[] { 0, 12 }, InterleaveSizes = new int[] { 3, 3 }, InterleaveStride = 12, StaticDraw = false, Values = data, Count = data.Length }; var updateMesh = new MeshData(false); updateMesh.CustomFloats = quadMesh.CustomFloats; quadRef = capi.Render.UploadMesh(quadMesh); capi.Render.UpdateMesh(quadRef, updateMesh); }
public override void Dispose() { if (meshRefOpaque != null) { meshRefOpaque.Dispose(); meshRefOpaque = null; } if (meshRefOit != null) { meshRefOit.Dispose(); meshRefOit = null; } if (nameTagTexture != null) { nameTagTexture.Dispose(); nameTagTexture = null; } if (debugTagTexture != null) { debugTagTexture.Dispose(); debugTagTexture = null; } capi.Event.ReloadShapes -= TesselateShape; if (DisplayChatMessages) { capi.Event.ChatMessage -= OnChatMessage; } if (eagent?.GearInventory != null) { eagent.GearInventory.SlotModified -= gearSlotModified; } if (entity is EntityPlayer eplr) { IInventory inv = eplr.Player?.InventoryManager.GetOwnInventory(GlobalConstants.backpackInvClassName); if (inv != null) { inv.SlotModified -= backPackSlotModified; } } }
private void Event_LeaveWorld() { ropeMeshRef?.Dispose(); }
public void Dispose() { api.Event.UnregisterRenderer(this, EnumRenderStage.Opaque); meshref.Dispose(); }
public void Dispose() { meshref?.Dispose(); }
void RegenMesh() { if (workItemMeshRef != null) { workItemMeshRef.Dispose(); } workItemMeshRef = null; if (stack == null) { return; } Shape shape; tmpMetal = stack.Collectible.LastCodePart(); MeshData mesh = null; string firstCodePart = stack.Collectible.FirstCodePart(); if (firstCodePart == "metalplate") { tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("platepile"))); shape = capi.Assets.TryGet("shapes/block/stone/forge/platepile.json").ToObject <Shape>(); textureId = tmpTextureSource[tmpMetal].atlasTextureId; capi.Tesselator.TesselateShape("block-fcr", shape, out mesh, this, null, 0, 0, 0, stack.StackSize); } else if (firstCodePart == "workitem") { MeshData workItemMesh = ItemWorkItem.GenMesh(capi, stack, ItemWorkItem.GetVoxels(stack), out textureId); workItemMesh.Scale(new Vec3f(0.5f, 0.5f, 0.5f), 0.75f, 0.75f, 0.75f); workItemMesh.Translate(0, -9f / 16f, 0); workItemMeshRef = capi.Render.UploadMesh(workItemMesh); } else if (firstCodePart == "ingot") { tmpTextureSource = capi.Tesselator.GetTexSource(capi.World.GetBlock(new AssetLocation("ingotpile"))); shape = capi.Assets.TryGet("shapes/block/stone/forge/ingotpile.json").ToObject <Shape>(); textureId = tmpTextureSource[tmpMetal].atlasTextureId; capi.Tesselator.TesselateShape("block-fcr", shape, out mesh, this, null, 0, 0, 0, stack.StackSize); } else if (stack.Collectible.Attributes != null && stack.Collectible.Attributes.IsTrue("forgable") == true) { if (stack.Class == EnumItemClass.Block) { mesh = capi.TesselatorManager.GetDefaultBlockMesh(stack.Block).Clone(); textureId = capi.BlockTextureAtlas.AtlasTextureIds[0]; } else { capi.Tesselator.TesselateItem(stack.Item, out mesh); textureId = capi.ItemTextureAtlas.AtlasTextureIds[0]; } ModelTransform tf = stack.Collectible.Attributes["inForgeTransform"].AsObject <ModelTransform>(); if (tf != null) { tf.EnsureDefaultValues(); mesh.ModelTransform(tf); } } if (mesh != null) { workItemMeshRef = capi.Render.UploadMesh(mesh); } }
public override void Dispose() { backPackMeshRef?.Dispose(); }
public virtual void TesselateShape() { if (!loaded) { return; } shapeFresh = true; CompositeShape compositeShape = OverrideCompositeShape != null ? OverrideCompositeShape : entity.Properties.Client.Shape; Shape entityShape = OverrideEntityShape != null ? OverrideEntityShape : entity.Properties.Client.LoadedShapeForEntity; if (entityShape == null) { return; } OnTesselation?.Invoke(ref entityShape, compositeShape.Base.ToString()); entity.OnTesselation(ref entityShape, compositeShape.Base.ToString()); defaultTexSource = GetTextureSource(); TyronThreadPool.QueueTask(() => { MeshData meshdata; if (entity.Properties.Client.Shape.VoxelizeTexture) { int altTexNumber = entity.WatchedAttributes.GetInt("textureIndex", 0); TextureAtlasPosition pos = defaultTexSource["all"]; CompositeTexture[] Alternates = entity.Properties.Client.FirstTexture.Alternates; CompositeTexture tex = altTexNumber == 0 ? entity.Properties.Client.FirstTexture : Alternates[altTexNumber % Alternates.Length]; meshdata = capi.Tesselator.VoxelizeTexture(tex, capi.EntityTextureAtlas.Size, pos); for (int i = 0; i < meshdata.xyz.Length; i += 3) { meshdata.xyz[i] -= 0.125f; meshdata.xyz[i + 1] -= 0.5f; meshdata.xyz[i + 2] += 0.125f / 2; } } else { try { TesselationMetaData meta = new TesselationMetaData() { quantityElements = compositeShape.QuantityElements, selectiveElements = compositeShape.SelectiveElements, texSource = this, withJointIds = true, withDamageEffect = true, typeForLogging = "entity" }; capi.Tesselator.TesselateShape(meta, entityShape, out meshdata, new Vec3f(compositeShape.rotateX, compositeShape.rotateY, compositeShape.rotateZ)); meshdata.Translate(compositeShape.offsetX, compositeShape.offsetY, compositeShape.offsetZ); } catch (Exception e) { capi.World.Logger.Fatal("Failed tesselating entity {0} with id {1}. Entity will probably be invisible!. The teselator threw {2}", entity.Code, entity.EntityId, e); return; } } MeshData opaqueMesh = meshdata.Clone().Clear(); MeshData oitMesh = meshdata.Clone().Clear(); opaqueMesh.AddMeshData(meshdata, EnumChunkRenderPass.Opaque); oitMesh.AddMeshData(meshdata, EnumChunkRenderPass.Transparent); capi.Event.EnqueueMainThreadTask(() => { if (meshRefOpaque != null) { meshRefOpaque.Dispose(); meshRefOpaque = null; } if (meshRefOit != null) { meshRefOit.Dispose(); meshRefOit = null; } if (capi.IsShuttingDown) { return; } if (opaqueMesh.VerticesCount > 0) { meshRefOpaque = capi.Render.UploadMesh(opaqueMesh); } if (oitMesh.VerticesCount > 0) { meshRefOit = capi.Render.UploadMesh(oitMesh); } }, "uploadentitymesh"); capi.TesselatorManager.ThreadDispose(); }); }