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 WeirdProgressBarRenderer(ICoreClientAPI api) { this.capi = api; // This will get a line loop with vertices inside [-1,-1] till [1,1] MeshData rectangle = LineMeshUtil.GetRectangle(ColorUtil.WhiteArgb); whiteRectangleRef = api.Render.UploadMesh(rectangle); // This will get a quad with vertices inside [-1,-1] till [1,1] progressQuadRef = api.Render.UploadMesh(QuadMeshUtil.GetQuad()); }
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); }
private void RegenOutlineMesh(bool[,,] recipeToOutlineVoxels, byte[,,] voxels) { recipeOutlineMeshRef?.Dispose(); MeshData recipeOutlineMesh = new MeshData(24, 36, false, false, true, false); recipeOutlineMesh.SetMode(EnumDrawMode.Lines); int greenCol = (170 << 24) | (100 << 16) | (200 << 8) | (100); int orangeCol = (220 << 24) | (75 << 16) | (0 << 8) | (47); 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(); int yMax = recipeToOutlineVoxels.GetLength(1); for (int x = 0; x < 16; x++) { for (int y = 0; y < 6; y++) { for (int z = 0; z < 16; z++) { bool requireMetalHere = y >= yMax ? false : recipeToOutlineVoxels[x, y, z]; EnumVoxelMaterial mat = (EnumVoxelMaterial)voxels[x, y, z]; if (requireMetalHere && mat == EnumVoxelMaterial.Metal) { continue; } if (!requireMetalHere && mat == EnumVoxelMaterial.Empty) { continue; } float px = x / 16f; float py = 10 / 16f + y / 16f; 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 = (requireMetalHere && mat == EnumVoxelMaterial.Empty) ? greenVoxelMesh.Rgba : orangeVoxelMesh.Rgba; recipeOutlineMesh.AddMeshData(voxelMeshOffset); } } } recipeOutlineMeshRef = api.Render.UploadMesh(recipeOutlineMesh); }