55
66using FEZRepacker . Core . Definitions . Game . ArtObject ;
77using FEZRepacker . Core . Definitions . Game . Graphics ;
8+ using FEZRepacker . Core . Helpers . Json ;
89
910using SharpGLTF . Schema2 ;
1011using SharpGLTF . Transforms ;
@@ -29,13 +30,15 @@ internal static class GltfUtil
2930 private const float StepOffsetZ = - 2f ;
3031
3132 private const int TempFileBufferSize = 4096 ;
33+
34+ private const string PrimitiveTypeKey = "PrimitiveType" ;
3235
3336 private static readonly Dictionary < GltfPrimitiveType , XnaPrimitiveType > PrimitiveTypeLookup = new ( )
3437 {
3538 { GltfPrimitiveType . LINES , XnaPrimitiveType . LineList } ,
3639 { GltfPrimitiveType . LINE_STRIP , XnaPrimitiveType . LineStrip } ,
3740 { GltfPrimitiveType . TRIANGLES , XnaPrimitiveType . TriangleList } ,
38- { GltfPrimitiveType . TRIANGLE_STRIP , XnaPrimitiveType . TriangleList }
41+ { GltfPrimitiveType . TRIANGLE_STRIP , XnaPrimitiveType . TriangleStrip }
3942 } ;
4043
4144 private static readonly Dictionary < XnaPrimitiveType , GltfPrimitiveType > PrimitiveTypeReverseLookup = new ( )
@@ -65,6 +68,7 @@ public static ModelRoot ToGltfModel<T>(
6568 node . LocalTransform = new AffineTransform ( System . Numerics . Quaternion . Identity , translation . ToNumeric ( ) ) ;
6669 node . Mesh = CreateMesh ( model , entry . Geometry , material ) ;
6770 node . Extras = entry . Extras ;
71+ node . Extras [ PrimitiveTypeKey ] = ConfiguredJsonSerializer . SerializeToNode ( entry . Geometry . PrimitiveType ) ;
6872
6973 steps ++ ;
7074 translation . X += StepOffsetX ;
@@ -89,6 +93,7 @@ public static ModelRoot ToGltfModel<T>(
8993 node . LocalTransform = AffineTransform . Identity ;
9094 node . Mesh = CreateMesh ( model , entry . Geometry , material ) ;
9195 node . Extras = entry . Extras ;
96+ node . Extras [ PrimitiveTypeKey ] = ConfiguredJsonSerializer . SerializeToNode ( entry . Geometry . PrimitiveType ) ;
9297
9398 return model ;
9499 }
@@ -101,7 +106,10 @@ public static List<GltfEntry<T>> FromGltfModel<T>(ModelRoot model)
101106 {
102107 if ( node . Mesh == null )
103108 {
104- geometryList . Add ( new GltfEntry < T > ( node . Name , new IndexedPrimitives < VertexInstance , T > ( ) , node . Extras ) ) ;
109+ var jsonNode = node . Extras [ PrimitiveTypeKey ] ! ;
110+ var primitiveType = ConfiguredJsonSerializer . DeserializeFromNode < XnaPrimitiveType > ( jsonNode ) ;
111+ var instance = new IndexedPrimitives < VertexInstance , T > { PrimitiveType = primitiveType } ;
112+ geometryList . Add ( new GltfEntry < T > ( node . Name , instance , node . Extras ) ) ;
105113 continue ;
106114 }
107115
0 commit comments