Skip to content

Commit cc9a2c3

Browse files
committed
Texture parsing is wrong apparently
1 parent 55351fd commit cc9a2c3

File tree

5 files changed

+9
-21
lines changed

5 files changed

+9
-21
lines changed

DenizenModelsConverter/BBModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class BBModel
1818

1919
public string FormatVersion;
2020

21+
public int ResolutionX, ResolutionY;
22+
2123
public DateTimeOffset CreationTime;
2224

2325
public List<Element> Elements = new();
@@ -77,8 +79,6 @@ public class Texture
7779
public byte[] RawImageBytes;
7880

7981
public string CorrectedFullPath;
80-
81-
public int Width, Height;
8282
}
8383

8484
public class Outliner

DenizenModelsConverter/BBModelReader.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ public static BBModel Interpret(string fileContent)
2525
Debug("Start read...");
2626
JObject data = JObject.Parse(fileContent);
2727
Debug("Parsed! Start proc...");
28-
JObject meta = data["meta"] as JObject;
28+
JObject meta = data.GetRequired("meta") as JObject;
29+
JObject resolution = data.GetRequired("resolution") as JObject;
2930
BBModel result = new()
3031
{
3132
JsonRoot = data,
3233
Name = (string)data.GetRequired("name"),
3334
FormatVersion = (string)meta.GetRequired("format_version"),
34-
CreationTime = DateTimeOffset.FromUnixTimeSeconds((long)meta.GetRequired("creation_time")).ToLocalTime()
35+
CreationTime = DateTimeOffset.FromUnixTimeSeconds((long)meta.GetRequired("creation_time")).ToLocalTime(),
36+
ResolutionX = (int)resolution.GetRequired("width"),
37+
ResolutionY = (int)resolution.GetRequired("height")
3538
};
3639
Debug("Core read, start body...");
3740
JArray elements = (JArray)data["elements"];
@@ -112,13 +115,6 @@ public static BBModel Interpret(string fileContent)
112115
throw new Exception($"Cannot read model - texture {texture.Name} contains source data that isn't the expected base64 png.");
113116
}
114117
texture.RawImageBytes = Convert.FromBase64String(sourceTex.After("data:image/png;base64,"));
115-
#pragma warning disable CA1416 // Validate platform compatibility
116-
using (Image image = Image.FromStream(new MemoryStream(texture.RawImageBytes)))
117-
{
118-
texture.Width = image.Width;
119-
texture.Height = image.Height;
120-
}
121-
#pragma warning restore CA1416 // Validate platform compatibility
122118
Debug($"Read texture {texture.Name}");
123119
result.Textures.Add(texture);
124120
}

DenizenModelsConverter/DenizenModelsConverter.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
<ItemGroup>
99
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
10-
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
1110
</ItemGroup>
1211

1312
<ItemGroup>

DenizenModelsConverter/MinecraftModelMaker.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ public static string CreateModelFor(BBModel model, BBModel.Outliner outline)
8888

8989
public static JObject FaceToJObj(BBModel.Element.Face face, BBModel model)
9090
{
91-
BBModel.Texture texture = model.Textures[face.TextureID];
92-
float relativeU = 16f / texture.Width;
93-
float relativeV = 16f / texture.Height;
91+
float relativeU = 16f / model.ResolutionX;
92+
float relativeV = 16f / model.ResolutionY;
9493
JObject output = new();
9594
output.Add("uv", new JArray(face.TexCoord.ULow * relativeU, face.TexCoord.VLow * relativeV, face.TexCoord.UHigh * relativeU, face.TexCoord.VHigh * relativeV));
9695
output.Add("texture", $"#{face.TextureID}");

DenizenModelsConverter/runtimeconfig.template.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)