Skip to content

Commit 9194658

Browse files
committed
fixes based on testing other reference models
1 parent 7b7e73a commit 9194658

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

DenizenModelsConverter/BBModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Face
6161

6262
public class UV
6363
{
64-
public int ULow, UHigh, VLow, VHigh;
64+
public float ULow, UHigh, VLow, VHigh;
6565
}
6666
}
6767
}

DenizenModelsConverter/BBModelReader.cs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ public static BBModel Interpret(string fileContent)
7171
Color = (int)jElement.GetRequired("color"),
7272
Rotation = jElement.ContainsKey("rotation") ? ParseDVecFromArr(jElement.GetRequired("rotation")) : new DoubleVector(),
7373
Origin = ParseDVecFromArr(jElement.GetRequired("origin")),
74-
North = ParseFaceFromJson(jFaces.GetRequired("north")),
75-
South = ParseFaceFromJson(jFaces.GetRequired("south")),
76-
East = ParseFaceFromJson(jFaces.GetRequired("east")),
77-
West = ParseFaceFromJson(jFaces.GetRequired("west")),
78-
Up = ParseFaceFromJson(jFaces.GetRequired("up")),
79-
Down = ParseFaceFromJson(jFaces.GetRequired("down")),
74+
North = ParseFaceFromJson(jFaces, "north"),
75+
South = ParseFaceFromJson(jFaces, "south"),
76+
East = ParseFaceFromJson(jFaces, "east"),
77+
West = ParseFaceFromJson(jFaces, "west"),
78+
Up = ParseFaceFromJson(jFaces, "up"),
79+
Down = ParseFaceFromJson(jFaces, "down"),
8080
Type = type,
8181
UUID = id
8282
};
@@ -102,6 +102,10 @@ public static BBModel Interpret(string fileContent)
102102
// Ignore 'saved'
103103
UUID = Guid.Parse((string)jTexture.GetRequired("uuid"))
104104
};
105+
if (texture.Name.EndsWith(".png"))
106+
{
107+
texture.Name = texture.Name.BeforeLast(".png");
108+
}
105109
string sourceTex = (string)jTexture.GetRequired("source");
106110
if (!sourceTex.StartsWith("data:image/png;base64,"))
107111
{
@@ -280,19 +284,28 @@ public static DoubleVector ParseDVecFromArr(JToken jVal)
280284
return new DoubleVector((double)jArr[0], (double)jArr[1], (double)jArr[2]);
281285
}
282286

283-
public static BBModel.Element.Face ParseFaceFromJson(JToken jVal)
287+
public static BBModel.Element.Face ParseFaceFromJson(JObject faces, string name)
284288
{
285-
JObject jObj = (JObject)jVal;
289+
JObject jObj = (JObject)faces.GetRequired(name);
286290
JArray uv = (JArray)jObj.GetRequired("uv");
291+
if (uv.Count < 4)
292+
{
293+
throw new Exception($"Cannot parse model for face {name}, UV count is {uv.Count}");
294+
}
295+
JToken tok = jObj.GetRequired("texture");
296+
if (tok.Type == JTokenType.Null) // 0 can be misread as null sometimes apparently
297+
{
298+
tok = 0;
299+
}
287300
return new()
288301
{
289-
TextureID = (int)jObj.GetRequired("texture"),
302+
TextureID = (int)tok,
290303
TexCoord = new BBModel.Element.Face.UV()
291304
{
292-
ULow = (int)uv[0],
293-
VLow = (int)uv[1],
294-
UHigh = (int)uv[2],
295-
VHigh = (int)uv[3]
305+
ULow = (float)uv[0],
306+
VLow = (float)uv[1],
307+
UHigh = (float)uv[2],
308+
VHigh = (float)uv[3]
296309
}
297310
};
298311
}

DenizenModelsConverter/MinecraftModelMaker.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ public static string CreateModelFor(BBModel model, BBModel.Outliner outline)
1919
JArray childrenList = new();
2020
foreach (BBModel.Texture texture in model.Textures)
2121
{
22-
textures.Add(texture.ID, texture.CorrectedFullPath);
22+
if (texture.ID == "1" && model.Textures.Count == 1)
23+
{ // Some models have only one texture, labeled '1', which should be #0
24+
textures.Add("0", texture.CorrectedFullPath);
25+
}
26+
else
27+
{
28+
textures.Add(texture.ID, texture.CorrectedFullPath);
29+
}
2330
if (texture.Particle)
2431
{
2532
textures.Add("particle", texture.CorrectedFullPath);

0 commit comments

Comments
 (0)