public override void Cache(McResourcePack pack) { if (!Model.Textures.TryGetValue("layer0", out var t)) { t = Model.Textures.FirstOrDefault(x => x.Value != null).Value; } if (t == null) { return; } List <VertexPositionColor> vertices = new List <VertexPositionColor>(); if (pack.TryGetBitmap(t, out var rawTexture)) { var texture = rawTexture.CloneAs <Rgba32>(); float toolPosX = 0.0f; float toolPosY = 1.0f; float toolPosZ = (1f / 16f) * 7.5f; for (int y = 0; y < texture.Height; y++) { for (int x = 0; x < texture.Width; x++) { var pixel = texture[x, y]; if (pixel.A == 0) { continue; } Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A); ItemModelCube built = new ItemModelCube(new Vector3(1f / texture.Width, 1f / texture.Height, 1f / 16f)); built.BuildCube(color); var origin = new Vector3( (toolPosX + (1f / texture.Width) * x), toolPosY - (1f / texture.Height) * y, toolPosZ ); vertices.AddRange(Modify(built.Front, origin)); vertices.AddRange(Modify(built.Bottom, origin)); vertices.AddRange(Modify(built.Back, origin)); vertices.AddRange(Modify(built.Top, origin)); vertices.AddRange(Modify(built.Left, origin)); vertices.AddRange(Modify(built.Right, origin)); } } } Vertices = vertices.ToArray(); }
public override void Cache(McResourcePack pack) { string t = string.Empty; if (!Model.Textures.TryGetValue("layer0", out t)) { t = Model.Textures.FirstOrDefault(x => x.Value != null).Value; } if (t == default) { return; } List <VertexPositionColor> vertices = new List <VertexPositionColor>(); List <short> indexes = new List <short>(); if (pack.TryGetBitmap(t, out var rawTexture)) { var texture = rawTexture.CloneAs <Rgba32>(); int i = 0; float toolPosX = 0.0f; float toolPosY = 1.0f; float toolPosZ = (1f / 16f) * 7.5f; int verticesPerTool = texture.Width * texture.Height * 36; for (int y = 0; y < texture.Height; y++) { for (int x = 0; x < texture.Width; x++) { var pixel = texture[x, y]; if (pixel.A == 0) { continue; } Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A); ItemModelCube built = new ItemModelCube(new Vector3(1f / texture.Width, 1f / texture.Height, 1f / 16f)); built.BuildCube(color); var origin = new Vector3( (toolPosX + (1f / texture.Width) * x), toolPosY - (1f / texture.Height) * y, toolPosZ ); vertices = ModifyCubeIndexes(vertices, ref built.Front, origin); vertices = ModifyCubeIndexes(vertices, ref built.Back, origin); vertices = ModifyCubeIndexes(vertices, ref built.Top, origin); vertices = ModifyCubeIndexes(vertices, ref built.Bottom, origin); vertices = ModifyCubeIndexes(vertices, ref built.Left, origin); vertices = ModifyCubeIndexes(vertices, ref built.Right, origin); var indices = built.Front.indexes .Concat(built.Back.indexes) .Concat(built.Top.indexes) .Concat(built.Bottom.indexes) .Concat(built.Left.indexes) .Concat(built.Right.indexes) .ToArray(); indexes.AddRange(indices); } } } Vertices = vertices.ToArray(); for (var index = 0; index < Vertices.Length; index++) { var vertice = Vertices[index]; Vertices[index] = vertice; } Indexes = indexes.ToArray(); }
private void Cache(McResourcePack pack) { var t = Model.Textures.FirstOrDefault(x => x.Value != null); if (t.Value == default) { return; } List <VertexPositionColor> vertices = new List <VertexPositionColor>(); List <short> indexes = new List <short>(); if (pack.TryGetBitmap(t.Value, out Bitmap texture)) { int i = 0; float toolPosX = 0.0f; float toolPosY = 0.0f; float toolPosZ = 0.0f; int verticesPerTool = texture.Width * texture.Height * 36; for (int y = 0; y < texture.Height; y++) { for (int x = 0; x < texture.Width; x++) { var pixel = texture.GetPixel(x, y); if (pixel.A == 0) { continue; } Color color = new Color(pixel.R, pixel.G, pixel.B, pixel.A); ItemModelCube built = new ItemModelCube(new Vector3(1f / texture.Width)); built.BuildCube(color); var origin = new Vector3(toolPosX + (1f / texture.Width) * x, toolPosY - (1f / texture.Height) * y, toolPosZ); vertices = ModifyCubeIndexes(vertices, ref built.Front, origin); vertices = ModifyCubeIndexes(vertices, ref built.Back, origin); vertices = ModifyCubeIndexes(vertices, ref built.Top, origin); vertices = ModifyCubeIndexes(vertices, ref built.Bottom, origin); vertices = ModifyCubeIndexes(vertices, ref built.Left, origin); vertices = ModifyCubeIndexes(vertices, ref built.Right, origin); var indices = built.Front.indexes .Concat(built.Back.indexes) .Concat(built.Top.indexes) .Concat(built.Bottom.indexes) .Concat(built.Left.indexes) .Concat(built.Right.indexes) .ToArray(); indexes.AddRange(indices); } } } Vertices = vertices.ToArray(); for (var index = 0; index < Vertices.Length; index++) { var vertice = Vertices[index]; Vertices[index] = vertice; } Indexes = indexes.ToArray(); }