Browse Source

moved machinery to a separated class for ease of maintenance

Vicente Penades 4 years ago
parent
commit
e62e2f4162

+ 46 - 242
build/SharpGLTF.CodeGen/Program.cs

@@ -63,7 +63,7 @@ namespace SharpGLTF
         private static void _ProcessMainSchema()
         private static void _ProcessMainSchema()
         {
         {
             // load and process schema
             // load and process schema
-            var ctx1 = LoadSchemaContext(Constants.MainSchemaFile);
+            var ctx1 = SchemaProcessing.LoadSchemaContext(Constants.MainSchemaFile);
 
 
             // Ignore "glTF Property" because it is completely hand coded.
             // Ignore "glTF Property" because it is completely hand coded.
             ctx1.IgnoredByCodeEmitter("glTF Property");
             ctx1.IgnoredByCodeEmitter("glTF Property");
@@ -113,7 +113,7 @@ namespace SharpGLTF
             ctx1.FindEnum("MAT2-MAT3-MAT4-SCALAR-VEC2-VEC3-VEC4")
             ctx1.FindEnum("MAT2-MAT3-MAT4-SCALAR-VEC2-VEC3-VEC4")
                 .SetValue("CUSTOM", 0);
                 .SetValue("CUSTOM", 0);
 
 
-            ProcessSchema("gltf.g", ctx1);
+            SchemaProcessing.EmitCodeFromSchema("gltf.g", ctx1);
         }
         }
 
 
         #endregion
         #endregion
@@ -124,7 +124,7 @@ namespace SharpGLTF
         {
         {
             // Model extension
             // Model extension
 
 
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.XMP_Model);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.XMP_Model);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
@@ -146,20 +146,20 @@ namespace SharpGLTF
                 .SetDataType(typeof(Dictionary<string,Object>), true);
                 .SetDataType(typeof(Dictionary<string,Object>), true);
             */
             */
 
 
-            ProcessSchema("ext.XMP.Model.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.XMP.Model.g", ctx);
 
 
             // Node extension
             // Node extension
 
 
-            ctx = LoadSchemaContext(Constants.KhronosExtensions.XMP_Node);
+            ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.XMP_Node);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
-            ProcessSchema("ext.XMP.Node.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.XMP.Node.g", ctx);
         }        
         }        
 
 
         private static void _ProcessKhronosSpecularGlossinessExtension()
         private static void _ProcessKhronosSpecularGlossinessExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.PbrSpecularGlossiness);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.PbrSpecularGlossiness);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("Texture Info");
             ctx.IgnoredByCodeEmitter("Texture Info");
@@ -176,32 +176,32 @@ namespace SharpGLTF
                 .SetDefaultValue("Vector3.One")
                 .SetDefaultValue("Vector3.One")
                 .SetItemsRange(0);
                 .SetItemsRange(0);
 
 
-            ProcessSchema("ext.pbrSpecularGlossiness.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.pbrSpecularGlossiness.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosUnlitExtension()
         private static void _ProcessKhronosUnlitExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.Unlit);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.Unlit);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
-            ProcessSchema("ext.Unlit.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.Unlit.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosClearCoatExtension()
         private static void _ProcessKhronosClearCoatExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.PbrClearCoat);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.PbrClearCoat);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("Texture Info");
             ctx.IgnoredByCodeEmitter("Texture Info");
-            ctx.IgnoredByCodeEmitter("Material Normal Texture Info");            
+            ctx.IgnoredByCodeEmitter("Material Normal Texture Info");
 
 
-            ProcessSchema("ext.ClearCoat.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.ClearCoat.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosSpecularExtension()
         private static void _ProcessKhronosSpecularExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.PbrSpecular);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.PbrSpecular);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("Texture Info");
             ctx.IgnoredByCodeEmitter("Texture Info");
@@ -213,23 +213,23 @@ namespace SharpGLTF
                 .SetDefaultValue("Vector3.One")
                 .SetDefaultValue("Vector3.One")
                 .SetItemsRange(0);
                 .SetItemsRange(0);
 
 
-            ProcessSchema("ext.pbrSpecular.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.pbrSpecular.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosTransmissionExtension()
         private static void _ProcessKhronosTransmissionExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.PbrTransmission);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.PbrTransmission);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("Texture Info");
             ctx.IgnoredByCodeEmitter("Texture Info");
-            ctx.IgnoredByCodeEmitter("Material Normal Texture Info");            
+            ctx.IgnoredByCodeEmitter("Material Normal Texture Info");
 
 
-            ProcessSchema("ext.Transmission.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.Transmission.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosSheenExtension()
         private static void _ProcessKhronosSheenExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.PbrSheen);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.PbrSheen);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("Texture Info");
             ctx.IgnoredByCodeEmitter("Texture Info");
@@ -247,25 +247,25 @@ namespace SharpGLTF
                 .SetDataType(typeof(float), true)                
                 .SetDataType(typeof(float), true)                
                 .SetItemsRange(0);
                 .SetItemsRange(0);
 
 
-            ProcessSchema("ext.Sheen.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.Sheen.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosIorExtension()
         private static void _ProcessKhronosIorExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.MaterialIor);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.MaterialIor);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             // ctx.IgnoredByCodeEmitter("Texture Info");
             // ctx.IgnoredByCodeEmitter("Texture Info");
             // ctx.IgnoredByCodeEmitter("Material Normal Texture Info");
             // ctx.IgnoredByCodeEmitter("Material Normal Texture Info");
 
 
-            ProcessSchema("ext.Ior.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.Ior.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosLightsPunctualExtension()
         private static void _ProcessKhronosLightsPunctualExtension()
         {
         {
             // Model
             // Model
 
 
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.LightsPunctual_Model);            
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.LightsPunctual_Model);            
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
@@ -275,20 +275,20 @@ namespace SharpGLTF
                 .SetDefaultValue("Vector3.One")
                 .SetDefaultValue("Vector3.One")
                 .SetItemsRange(0);
                 .SetItemsRange(0);
 
 
-            ProcessSchema("ext.ModelLightsPunctual.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.ModelLightsPunctual.g", ctx);
 
 
             // Node
             // Node
 
 
-            ctx = LoadSchemaContext(Constants.KhronosExtensions.LightsPunctual_Node);
+            ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.LightsPunctual_Node);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
-            ProcessSchema("ext.NodeLightsPunctual.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.NodeLightsPunctual.g", ctx);
         }
         }
 
 
         private static void _ProcessKhronosTextureTransformExtension()
         private static void _ProcessKhronosTextureTransformExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.TextureTransform);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.TextureTransform);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
@@ -304,45 +304,45 @@ namespace SharpGLTF
                 .SetDefaultValue("Vector2.One")
                 .SetDefaultValue("Vector2.One")
                 .SetItemsRange(0);
                 .SetItemsRange(0);
 
 
-            ProcessSchema("ext.TextureTransform.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.TextureTransform.g", ctx);
         }
         }
 
 
         private static void _ProcessMicrosoftTextureDDSExtension()
         private static void _ProcessMicrosoftTextureDDSExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.VendorExtensions.TextureDDS);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.VendorExtensions.TextureDDS);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
 
 
-            ProcessSchema("ext.MSFT.TextureDDS.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.MSFT.TextureDDS.g", ctx);
         }
         }
 
 
         private static void _ProcessTextureWebpExtension()
         private static void _ProcessTextureWebpExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.VendorExtensions.TextureWebp);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.VendorExtensions.TextureWebp);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
 
 
-            ProcessSchema("ext.TextureWEBP.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.TextureWEBP.g", ctx);
         }
         }
 
 
         private static void _ProcessTextureKtx2Extension()
         private static void _ProcessTextureKtx2Extension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.KhronosExtensions.Ktx2);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.KhronosExtensions.Ktx2);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
 
 
-            ProcessSchema("ext.TextureKTX2.g", ctx);
+            SchemaProcessing.EmitCodeFromSchema("ext.TextureKTX2.g", ctx);
         }
         }
 
 
         private static void _ProcessMeshGpuInstancingExtension()
         private static void _ProcessMeshGpuInstancingExtension()
         {
         {
-            var ctx = LoadSchemaContext(Constants.VendorExtensions.MeshGpuInstancing);
+            var ctx = SchemaProcessing.LoadSchemaContext(Constants.VendorExtensions.MeshGpuInstancing);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
-            
-            ProcessSchema("ext.MeshGpuInstancing.g", ctx);
+
+            SchemaProcessing.EmitCodeFromSchema("ext.MeshGpuInstancing.g", ctx);
         }
         }
 
 
         private static void _ProcessAgiArticulationsExtension()
         private static void _ProcessAgiArticulationsExtension()
         {
         {
-            var ctx1 = LoadSchemaContext(Constants.VendorExtensions.AgiRootArticulations);
+            var ctx1 = SchemaProcessing.LoadSchemaContext(Constants.VendorExtensions.AgiRootArticulations);
             ctx1.IgnoredByCodeEmitter("glTF Property");
             ctx1.IgnoredByCodeEmitter("glTF Property");
             ctx1.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx1.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
@@ -351,226 +351,30 @@ namespace SharpGLTF
                 .SetDataType(typeof(System.Numerics.Vector3), true)
                 .SetDataType(typeof(System.Numerics.Vector3), true)
                 .SetItemsRange(0);
                 .SetItemsRange(0);
 
 
-            ProcessSchema("ext.AgiRootArticulations.g", ctx1);
+            SchemaProcessing.EmitCodeFromSchema("ext.AgiRootArticulations.g", ctx1);
 
 
-            var ctx2 = LoadSchemaContext(Constants.VendorExtensions.AgiNodeArticulations);
+            var ctx2 = SchemaProcessing.LoadSchemaContext(Constants.VendorExtensions.AgiNodeArticulations);
             ctx2.IgnoredByCodeEmitter("glTF Property");
             ctx2.IgnoredByCodeEmitter("glTF Property");
             ctx2.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx2.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
-            ProcessSchema("ext.AgiNodeArticulations.g", ctx2);
+            SchemaProcessing.EmitCodeFromSchema("ext.AgiNodeArticulations.g", ctx2);
         }
         }
 
 
         private static void _ProcessAgiStkMetadataExtension()
         private static void _ProcessAgiStkMetadataExtension()
         {
         {
-            var ctx1 = LoadSchemaContext(Constants.VendorExtensions.AgiRootStkMetadata);
+            var ctx1 = SchemaProcessing.LoadSchemaContext(Constants.VendorExtensions.AgiRootStkMetadata);
             ctx1.IgnoredByCodeEmitter("glTF Property");
             ctx1.IgnoredByCodeEmitter("glTF Property");
             ctx1.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx1.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
-            ProcessSchema("ext.AgiRootStkMetadata.g", ctx1);
+            SchemaProcessing.EmitCodeFromSchema("ext.AgiRootStkMetadata.g", ctx1);
 
 
-            var ctx2 = LoadSchemaContext(Constants.VendorExtensions.AgiNodeStkMetadata);
+            var ctx2 = SchemaProcessing.LoadSchemaContext(Constants.VendorExtensions.AgiNodeStkMetadata);
             ctx2.IgnoredByCodeEmitter("glTF Property");
             ctx2.IgnoredByCodeEmitter("glTF Property");
             ctx2.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx2.IgnoredByCodeEmitter("glTF Child of Root Property");
 
 
-            ProcessSchema("ext.AgiNodeStkMetadata.g", ctx2);
-        }
-
-        #endregion
-
-        #region code generation
-
-        private static string _FindTargetDirectory(string dstDir)
-        {
-            var dir = Constants.LocalRepoDirectory;
-
-            while(dir.Length > 3)
-            {
-                var xdir = System.IO.Path.Combine(dir, dstDir);
-                if (System.IO.Directory.Exists(xdir)) return xdir;
-
-                dir = System.IO.Path.GetDirectoryName(dir); // move up
-            }
-
-            return null;
-        }
-
-        private static void ProcessSchema(string dstFile, SchemaType.Context ctx)
-        {
-            var newEmitter = new CSharpEmitter();
-            newEmitter.DeclareContext(ctx);
-            newEmitter.SetCollectionContainer("List<TItem>");
-
-            const string rootName = "ModelRoot";
-
-            newEmitter.SetRuntimeName("glTF", rootName);
-            newEmitter.SetRuntimeName("glTF Property", "ExtraProperties");
-            newEmitter.SetRuntimeName("glTF Child of Root Property", "LogicalChildOfRoot");
-
-            newEmitter.SetRuntimeName("Sampler", "TextureSampler");
-
-            newEmitter.SetRuntimeName("UNSIGNED_BYTE-UNSIGNED_INT-UNSIGNED_SHORT", "IndexEncodingType");            
-            newEmitter.SetRuntimeName("BYTE-FLOAT-SHORT-UNSIGNED_BYTE-UNSIGNED_INT-UNSIGNED_SHORT", "EncodingType");            
-            newEmitter.SetRuntimeName("MAT2-MAT3-MAT4-SCALAR-VEC2-VEC3-VEC4", "DimensionType");
-            newEmitter.SetRuntimeName("rotation-scale-translation-weights", "PropertyPath");
-            newEmitter.SetRuntimeName("ARRAY_BUFFER-ELEMENT_ARRAY_BUFFER", "BufferMode");
-            newEmitter.SetRuntimeName("orthographic-perspective", "CameraType");
-            newEmitter.SetRuntimeName("BLEND-MASK-OPAQUE", "AlphaMode");
-            newEmitter.SetRuntimeName("LINE_LOOP-LINE_STRIP-LINES-POINTS-TRIANGLE_FAN-TRIANGLE_STRIP-TRIANGLES", "PrimitiveType");
-            newEmitter.SetRuntimeName("CUBICSPLINE-LINEAR-STEP", "AnimationInterpolationMode");
-            newEmitter.SetRuntimeName("LINEAR-NEAREST", "TextureInterpolationFilter");
-            newEmitter.SetRuntimeName("CLAMP_TO_EDGE-MIRRORED_REPEAT-REPEAT", "TextureWrapMode");
-            newEmitter.SetRuntimeName("LINEAR-LINEAR_MIPMAP_LINEAR-LINEAR_MIPMAP_NEAREST-NEAREST-NEAREST_MIPMAP_LINEAR-NEAREST_MIPMAP_NEAREST", "TextureMipMapFilter");
-
-            newEmitter.SetRuntimeName("KHR_materials_pbrSpecularGlossiness glTF extension", "MaterialPBRSpecularGlossiness");
-            newEmitter.SetRuntimeName("KHR_materials_unlit glTF extension", "MaterialUnlit");
-            newEmitter.SetRuntimeName("KHR_materials_specular glTF extension", "MaterialSpecular");
-            newEmitter.SetRuntimeName("KHR_materials_clearcoat glTF extension", "MaterialClearCoat");
-            newEmitter.SetRuntimeName("KHR_materials_transmission glTF extension", "MaterialTransmission");
-            newEmitter.SetRuntimeName("KHR_materials_sheen glTF extension", "MaterialSheen");
-            newEmitter.SetRuntimeName("KHR_materials_ior glTF extension", "MaterialIOR");
-
-            newEmitter.SetRuntimeName("KHR_xmp glTF extension", "XMPPacketsCollection");
-            newEmitter.SetRuntimeName("KHR_xmp node extension", "XMPPacketReference");
-
-
-
-            newEmitter.SetRuntimeName("light", "PunctualLight");
-            newEmitter.SetRuntimeName("light/spot", "PunctualLightSpot");
-            newEmitter.SetRuntimeName("KHR_lights_punctual glTF extension", "_ModelPunctualLights");
-            newEmitter.SetRuntimeName("KHR_lights_punctual node extension", "_NodePunctualLight");
-
-            newEmitter.SetRuntimeName("KHR_texture_transform textureInfo extension", "TextureTransform");
-
-            newEmitter.SetRuntimeName("MSFT_texture_dds extension", "TextureDDS");
-            newEmitter.SetRuntimeName("EXT_texture_webp glTF extension", "TextureWEBP");
-            newEmitter.SetRuntimeName("KHR_texture_basisu glTF extension", "TextureKTX2");
-
-            newEmitter.SetRuntimeName("EXT_mesh_gpu_instancing glTF extension", "MeshGpuInstancing");
-
-            newEmitter.SetRuntimeName("AGI_articulations glTF extension", "AgiRootArticulations");
-            newEmitter.SetRuntimeName("AGI_articulations glTF Node extension", "AgiNodeArticulations");
-            newEmitter.SetRuntimeName("Articulation", "AgiArticulation");
-            newEmitter.SetRuntimeName("Articulation Stage", "AgiArticulationStage");
-            newEmitter.SetRuntimeName("uniformScale-xRotate-xScale-xTranslate-yRotate-yScale-yTranslate-zRotate-zScale-zTranslate", "AgiArticulationTransformType");
-            newEmitter.SetRuntimeName("AGI_stk_metadata glTF extension", "AgiRootStkMetadata");
-            newEmitter.SetRuntimeName("AGI_stk_metadata glTF Node extension", "AgiNodeStkMetadata");
-            newEmitter.SetRuntimeName("Solar Panel Group", "AgiStkSolarPanelGroup");
-
-            var classes = ctx.Classes.ToArray();
-            var fields = classes.SelectMany(item => item.Fields).ToArray();
-
-            var meshClass = ctx.FindClass("Mesh");
-            if (meshClass != null)
-            {
-                newEmitter.SetCollectionContainer(meshClass.UseField("primitives"), "ChildrenCollection<TItem,Mesh>");
-            }
-
-            var animationClass = ctx.FindClass("Animation");
-            if (animationClass != null)
-            {
-                newEmitter.SetCollectionContainer(animationClass.UseField("channels"), "ChildrenCollection<TItem,Animation>");
-                newEmitter.SetCollectionContainer(animationClass.UseField("samplers"), "ChildrenCollection<TItem,Animation>");
-            }
-
-            var agiArticulationRootClass = ctx.FindClass("AGI_articulations glTF extension");
-            if (agiArticulationRootClass != null)
-            {
-                newEmitter.SetCollectionContainer(agiArticulationRootClass.UseField("articulations"), "ChildrenCollection<TItem,AgiRootArticulations>");
-            }
-
-            var agiArticulationClass = ctx.FindClass("Articulation");
-            if (agiArticulationClass != null)
-            {
-                newEmitter.SetCollectionContainer(agiArticulationClass.UseField("stages"), "ChildrenCollection<TItem,AgiArticulation>");
-            }
-
-            var agiStkMetadataRootClass = ctx.FindClass("AGI_stk_metadata glTF extension");
-            if (agiStkMetadataRootClass != null)
-            {
-                newEmitter.SetCollectionContainer(agiStkMetadataRootClass.UseField("solarPanelGroups"), "ChildrenCollection<TItem,AgiRootStkMetadata>");
-            }
-
-            foreach (var f in fields)
-            {
-                if (f.FieldType is ArrayType atype)
-                {
-                    if (atype.ItemType is ClassType ctype)
-                    {
-                        if (ctype.BaseClass != null && ctype.BaseClass.PersistentName == "glTF Child of Root Property")
-                        {
-                            newEmitter.SetCollectionContainer(f, $"ChildrenCollection<TItem,{rootName}>");
-                        }
-                    }
-                }
-            }
-
-            var textOut = newEmitter.EmitContext(ctx);
-
-            var dstDir = _FindTargetDirectory(Constants.TargetProjectDirectory);
-            var dstPath = System.IO.Path.Combine(dstDir, $"{dstFile}.cs");
-
-            System.IO.File.WriteAllText(dstPath, textOut);            
+            SchemaProcessing.EmitCodeFromSchema("ext.AgiNodeStkMetadata.g", ctx2);
         }
         }
 
 
-        #endregion
-
-        #region schema loader
-
-        private static SchemaType.Context LoadSchemaContext(string srcSchema)
-        {
-            var schema = LoadSchema(srcSchema);
-
-            var settings = new NJsonSchema.CodeGeneration.CSharp.CSharpGeneratorSettings
-            {
-                Namespace = "glTf.POCO",
-                ClassStyle = NJsonSchema.CodeGeneration.CSharp.CSharpClassStyle.Poco
-            };
-
-            var ctypes = new NJsonSchema.CodeGeneration.CSharp.CSharpTypeResolver(settings);
-            ctypes.Resolve(schema, false, null);
-
-            return SchemaTypesReader.Generate(ctypes);
-        }
-
-        static JSONSCHEMA LoadSchema(string filePath)
-        {
-            // https://blogs.msdn.microsoft.com/benjaminperkins/2017/03/08/how-to-call-an-async-method-from-a-console-app-main-method/
-
-            if (!System.IO.File.Exists(filePath)) throw new System.IO.FileNotFoundException(nameof(filePath), filePath);
-
-            return JSONSCHEMA
-                .FromFileAsync(filePath, s => _Resolver(s,filePath) )
-                .ConfigureAwait(false)
-                .GetAwaiter()
-                .GetResult();
-        }
-
-        static NJsonSchema.JsonReferenceResolver _Resolver(JSONSCHEMA schema, string basePath)
-        {
-            var generator = new NJsonSchema.Generation.JsonSchemaGeneratorSettings();
-
-            var solver = new NJsonSchema.JsonSchemaAppender(schema, generator.TypeNameGenerator);
-
-            return new MyReferenceResolver(solver);            
-        }
-
-        class MyReferenceResolver : NJsonSchema.JsonReferenceResolver
-        {
-            public MyReferenceResolver(NJsonSchema.JsonSchemaAppender resolver) : base(resolver) { }
-
-            public override Task<IJsonReference> ResolveFileReferenceAsync(string filePath, System.Threading.CancellationToken cancellationToken)
-            {
-                if (System.IO.File.Exists(filePath)) return base.ResolveFileReferenceAsync(filePath);
-
-                filePath = System.IO.Path.GetFileName(filePath);
-                filePath = System.IO.Path.Combine(Constants.MainSchemaDir, filePath);
-
-                if (System.IO.File.Exists(filePath)) return base.ResolveFileReferenceAsync(filePath);
-
-                throw new System.IO.FileNotFoundException(filePath);
-            }
-        }
-
-        #endregion
+        #endregion                
     }    
     }    
 }
 }

+ 211 - 0
build/SharpGLTF.CodeGen/SchemaProcessing.cs

@@ -0,0 +1,211 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using SharpGLTF.CodeGen;
+using SharpGLTF.SchemaReflection;
+
+using System.Threading.Tasks;
+
+using NJsonSchema.References;
+
+using JSONSCHEMA = NJsonSchema.JsonSchema;
+
+namespace SharpGLTF
+{
+    static class SchemaProcessing
+    {
+        #region schema loader
+
+        public static SchemaType.Context LoadSchemaContext(string srcSchema)
+        {
+            var schema = LoadSchema(srcSchema);
+
+            var settings = new NJsonSchema.CodeGeneration.CSharp.CSharpGeneratorSettings
+            {
+                Namespace = "glTf.POCO",
+                ClassStyle = NJsonSchema.CodeGeneration.CSharp.CSharpClassStyle.Poco
+            };
+
+            var ctypes = new NJsonSchema.CodeGeneration.CSharp.CSharpTypeResolver(settings);
+            ctypes.Resolve(schema, false, null);
+
+            return SchemaTypesReader.Generate(ctypes);
+        }
+
+        private static JSONSCHEMA LoadSchema(string filePath)
+        {
+            // https://blogs.msdn.microsoft.com/benjaminperkins/2017/03/08/how-to-call-an-async-method-from-a-console-app-main-method/
+
+            if (!System.IO.File.Exists(filePath)) throw new System.IO.FileNotFoundException(nameof(filePath), filePath);
+
+            return JSONSCHEMA
+                .FromFileAsync(filePath, s => _Resolver(s, filePath))
+                .ConfigureAwait(false)
+                .GetAwaiter()
+                .GetResult();
+        }
+
+        static NJsonSchema.JsonReferenceResolver _Resolver(JSONSCHEMA schema, string basePath)
+        {
+            var generator = new NJsonSchema.Generation.JsonSchemaGeneratorSettings();
+
+            var solver = new NJsonSchema.JsonSchemaAppender(schema, generator.TypeNameGenerator);
+
+            return new MyReferenceResolver(solver);
+        }
+
+        class MyReferenceResolver : NJsonSchema.JsonReferenceResolver
+        {
+            public MyReferenceResolver(NJsonSchema.JsonSchemaAppender resolver) : base(resolver) { }
+
+            public override Task<IJsonReference> ResolveFileReferenceAsync(string filePath, System.Threading.CancellationToken cancellationToken)
+            {
+                if (System.IO.File.Exists(filePath)) return base.ResolveFileReferenceAsync(filePath);
+
+                filePath = System.IO.Path.GetFileName(filePath);
+                filePath = System.IO.Path.Combine(Constants.MainSchemaDir, filePath);
+
+                if (System.IO.File.Exists(filePath)) return base.ResolveFileReferenceAsync(filePath);
+
+                throw new System.IO.FileNotFoundException(filePath);
+            }
+        }
+
+        #endregion
+
+        public static void EmitCodeFromSchema(string dstFile, SchemaType.Context ctx)
+        {
+            var newEmitter = new CSharpEmitter();
+            newEmitter.DeclareContext(ctx);
+            newEmitter.SetCollectionContainer("List<TItem>");
+
+            const string rootName = "ModelRoot";
+
+            newEmitter.SetRuntimeName("glTF", rootName);
+            newEmitter.SetRuntimeName("glTF Property", "ExtraProperties");
+            newEmitter.SetRuntimeName("glTF Child of Root Property", "LogicalChildOfRoot");
+
+            newEmitter.SetRuntimeName("Sampler", "TextureSampler");
+
+            newEmitter.SetRuntimeName("UNSIGNED_BYTE-UNSIGNED_INT-UNSIGNED_SHORT", "IndexEncodingType");
+            newEmitter.SetRuntimeName("BYTE-FLOAT-SHORT-UNSIGNED_BYTE-UNSIGNED_INT-UNSIGNED_SHORT", "EncodingType");
+            newEmitter.SetRuntimeName("MAT2-MAT3-MAT4-SCALAR-VEC2-VEC3-VEC4", "DimensionType");
+            newEmitter.SetRuntimeName("rotation-scale-translation-weights", "PropertyPath");
+            newEmitter.SetRuntimeName("ARRAY_BUFFER-ELEMENT_ARRAY_BUFFER", "BufferMode");
+            newEmitter.SetRuntimeName("orthographic-perspective", "CameraType");
+            newEmitter.SetRuntimeName("BLEND-MASK-OPAQUE", "AlphaMode");
+            newEmitter.SetRuntimeName("LINE_LOOP-LINE_STRIP-LINES-POINTS-TRIANGLE_FAN-TRIANGLE_STRIP-TRIANGLES", "PrimitiveType");
+            newEmitter.SetRuntimeName("CUBICSPLINE-LINEAR-STEP", "AnimationInterpolationMode");
+            newEmitter.SetRuntimeName("LINEAR-NEAREST", "TextureInterpolationFilter");
+            newEmitter.SetRuntimeName("CLAMP_TO_EDGE-MIRRORED_REPEAT-REPEAT", "TextureWrapMode");
+            newEmitter.SetRuntimeName("LINEAR-LINEAR_MIPMAP_LINEAR-LINEAR_MIPMAP_NEAREST-NEAREST-NEAREST_MIPMAP_LINEAR-NEAREST_MIPMAP_NEAREST", "TextureMipMapFilter");
+
+            newEmitter.SetRuntimeName("KHR_materials_pbrSpecularGlossiness glTF extension", "MaterialPBRSpecularGlossiness");
+            newEmitter.SetRuntimeName("KHR_materials_unlit glTF extension", "MaterialUnlit");
+            newEmitter.SetRuntimeName("KHR_materials_specular glTF extension", "MaterialSpecular");
+            newEmitter.SetRuntimeName("KHR_materials_clearcoat glTF extension", "MaterialClearCoat");
+            newEmitter.SetRuntimeName("KHR_materials_transmission glTF extension", "MaterialTransmission");
+            newEmitter.SetRuntimeName("KHR_materials_sheen glTF extension", "MaterialSheen");
+            newEmitter.SetRuntimeName("KHR_materials_ior glTF extension", "MaterialIOR");
+
+            newEmitter.SetRuntimeName("KHR_xmp glTF extension", "XMPPacketsCollection");
+            newEmitter.SetRuntimeName("KHR_xmp node extension", "XMPPacketReference");
+
+
+
+            newEmitter.SetRuntimeName("light", "PunctualLight");
+            newEmitter.SetRuntimeName("light/spot", "PunctualLightSpot");
+            newEmitter.SetRuntimeName("KHR_lights_punctual glTF extension", "_ModelPunctualLights");
+            newEmitter.SetRuntimeName("KHR_lights_punctual node extension", "_NodePunctualLight");
+
+            newEmitter.SetRuntimeName("KHR_texture_transform textureInfo extension", "TextureTransform");
+
+            newEmitter.SetRuntimeName("MSFT_texture_dds extension", "TextureDDS");
+            newEmitter.SetRuntimeName("EXT_texture_webp glTF extension", "TextureWEBP");
+            newEmitter.SetRuntimeName("KHR_texture_basisu glTF extension", "TextureKTX2");
+
+            newEmitter.SetRuntimeName("EXT_mesh_gpu_instancing glTF extension", "MeshGpuInstancing");
+
+            newEmitter.SetRuntimeName("AGI_articulations glTF extension", "AgiRootArticulations");
+            newEmitter.SetRuntimeName("AGI_articulations glTF Node extension", "AgiNodeArticulations");
+            newEmitter.SetRuntimeName("Articulation", "AgiArticulation");
+            newEmitter.SetRuntimeName("Articulation Stage", "AgiArticulationStage");
+            newEmitter.SetRuntimeName("uniformScale-xRotate-xScale-xTranslate-yRotate-yScale-yTranslate-zRotate-zScale-zTranslate", "AgiArticulationTransformType");
+            newEmitter.SetRuntimeName("AGI_stk_metadata glTF extension", "AgiRootStkMetadata");
+            newEmitter.SetRuntimeName("AGI_stk_metadata glTF Node extension", "AgiNodeStkMetadata");
+            newEmitter.SetRuntimeName("Solar Panel Group", "AgiStkSolarPanelGroup");
+
+            var classes = ctx.Classes.ToArray();
+            var fields = classes.SelectMany(item => item.Fields).ToArray();
+
+            var meshClass = ctx.FindClass("Mesh");
+            if (meshClass != null)
+            {
+                newEmitter.SetCollectionContainer(meshClass.UseField("primitives"), "ChildrenCollection<TItem,Mesh>");
+            }
+
+            var animationClass = ctx.FindClass("Animation");
+            if (animationClass != null)
+            {
+                newEmitter.SetCollectionContainer(animationClass.UseField("channels"), "ChildrenCollection<TItem,Animation>");
+                newEmitter.SetCollectionContainer(animationClass.UseField("samplers"), "ChildrenCollection<TItem,Animation>");
+            }
+
+            var agiArticulationRootClass = ctx.FindClass("AGI_articulations glTF extension");
+            if (agiArticulationRootClass != null)
+            {
+                newEmitter.SetCollectionContainer(agiArticulationRootClass.UseField("articulations"), "ChildrenCollection<TItem,AgiRootArticulations>");
+            }
+
+            var agiArticulationClass = ctx.FindClass("Articulation");
+            if (agiArticulationClass != null)
+            {
+                newEmitter.SetCollectionContainer(agiArticulationClass.UseField("stages"), "ChildrenCollection<TItem,AgiArticulation>");
+            }
+
+            var agiStkMetadataRootClass = ctx.FindClass("AGI_stk_metadata glTF extension");
+            if (agiStkMetadataRootClass != null)
+            {
+                newEmitter.SetCollectionContainer(agiStkMetadataRootClass.UseField("solarPanelGroups"), "ChildrenCollection<TItem,AgiRootStkMetadata>");
+            }
+
+            foreach (var f in fields)
+            {
+                if (f.FieldType is ArrayType atype)
+                {
+                    if (atype.ItemType is ClassType ctype)
+                    {
+                        if (ctype.BaseClass != null && ctype.BaseClass.PersistentName == "glTF Child of Root Property")
+                        {
+                            newEmitter.SetCollectionContainer(f, $"ChildrenCollection<TItem,{rootName}>");
+                        }
+                    }
+                }
+            }
+
+            var textOut = newEmitter.EmitContext(ctx);
+
+            var dstDir = _FindTargetDirectory(Constants.TargetProjectDirectory);
+            var dstPath = System.IO.Path.Combine(dstDir, $"{dstFile}.cs");
+
+            System.IO.File.WriteAllText(dstPath, textOut);
+        }
+
+        private static string _FindTargetDirectory(string dstDir)
+        {
+            var dir = Constants.LocalRepoDirectory;
+
+            while (dir.Length > 3)
+            {
+                var xdir = System.IO.Path.Combine(dir, dstDir);
+                if (System.IO.Directory.Exists(xdir)) return xdir;
+
+                dir = System.IO.Path.GetDirectoryName(dir); // move up
+            }
+
+            return null;
+        }
+    }
+}

+ 1 - 1
build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj

@@ -3,7 +3,7 @@
   <PropertyGroup>
   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp3.1</TargetFramework>
     <TargetFramework>netcoreapp3.1</TargetFramework>
-    <RootNamespace>glTF2Sharp</RootNamespace>
+    <RootNamespace>SharpGLTF</RootNamespace>
   </PropertyGroup>
   </PropertyGroup>
 
 
   <ItemGroup>
   <ItemGroup>