@@ -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 }
0 commit comments