Browse Source

working on more extensions

Vicente Penades 6 years ago
parent
commit
10111c7879

+ 2 - 0
build/SharpGLTF.CodeGen/CodeGen/EmitCSharp.cs

@@ -350,6 +350,8 @@ namespace SharpGLTF.CodeGen
 
             foreach (var ctype in context.Classes)
             {
+                if (ctype.IgnoredByEmitter) continue;
+
                 var cout = EmitClass(ctype);
 
                 sb.AppendLine(cout);

+ 2 - 1
build/SharpGLTF.CodeGen/Constants.cs

@@ -27,7 +27,8 @@ namespace SharpGLTF
         public static string KhronosSchemaDir => System.IO.Path.Combine(Constants.LocalRepoDirectory, "extensions", "2.0", "Khronos");
         public static string KhronosDracoSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_draco_mesh_compression", "schema");
         public static string KhronosPbrSpecGlossSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_materials_pbrSpecularGlossiness", "schema", "glTF.KHR_materials_pbrSpecularGlossiness.schema.json");
-        public static string KhronesUnlitSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_materials_unlit", "schema", "glTF.KHR_materials_unlit.schema.json");
+        public static string KhronosUnlitSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_materials_unlit", "schema", "glTF.KHR_materials_unlit.schema.json");
+        public static string KhronosLightsPunctualSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_lights_punctual", "schema", "glTF.KHR_lights_punctual.schema.json");
 
 
         /// <summary>

+ 32 - 10
build/SharpGLTF.CodeGen/Program.cs

@@ -23,6 +23,7 @@ namespace SharpGLTF
 
             _ProcessKhronosPBRExtension();
             _ProcessKhronosUnlitExtension();
+            _ProcessKhronosLightsPunctualExtension();
 
             // these extansions are not fully supported and temporarily removed:
             // _ProcessDracoExtension();
@@ -95,13 +96,13 @@ namespace SharpGLTF
 
         private static void _ProcessKhronosPBRExtension()
         {
-            var ctx4 = LoadSchemaContext(Constants.KhronosPbrSpecGlossSchemaFile);
+            var ctx = LoadSchemaContext(Constants.KhronosPbrSpecGlossSchemaFile);
 
             // remove already defined classes
-            ctx4.Remove("glTF Property");
-            ctx4.Remove("Texture Info");
+            ctx.Remove("glTF Property");
+            ctx.Remove("Texture Info");
 
-            ctx4.Classes
+            ctx.Classes
                 .ToArray()
                 .FirstOrDefault(item => item.PersistentName == "KHR_materials_pbrSpecularGlossiness glTF extension")
                 .UseField("diffuseFactor")
@@ -109,7 +110,7 @@ namespace SharpGLTF
                 .SetDefaultValue("Vector4.One")
                 .SetItemsRange(0);
 
-            ctx4.Classes
+            ctx.Classes
                 .ToArray()
                 .FirstOrDefault(item => item.PersistentName == "KHR_materials_pbrSpecularGlossiness glTF extension")
                 .UseField("specularFactor")
@@ -117,15 +118,33 @@ namespace SharpGLTF
                 .SetDefaultValue("Vector3.One")
                 .SetItemsRange(0);
 
-            ProcessSchema("ext.pbrSpecularGlossiness.g", ctx4);
+            ProcessSchema("ext.pbrSpecularGlossiness.g", ctx);
         }
 
         private static void _ProcessKhronosUnlitExtension()
         {
-            var ctx4 = LoadSchemaContext(Constants.KhronesUnlitSchemaFile);
-            ctx4.Remove("glTF Property");            
+            var ctx = LoadSchemaContext(Constants.KhronosUnlitSchemaFile);
+            ctx.Remove("glTF Property");
 
-            ProcessSchema("ext.Unlit.g", ctx4);
+            ProcessSchema("ext.Unlit.g", ctx);
+        }
+
+        private static void _ProcessKhronosLightsPunctualExtension()
+        {
+            var ctx = LoadSchemaContext(Constants.KhronosLightsPunctualSchemaFile);            
+            ctx.Remove("glTF Property");
+            ctx.Classes.FirstOrDefault(item => item.PersistentName == "glTF Child of Root Property").IgnoredByEmitter = true;
+
+            var light = ctx.Classes
+                .ToArray()
+                .FirstOrDefault(item => item.PersistentName == "light");            
+
+            light.UseField("color")
+                .SetDataType(typeof(System.Numerics.Vector3), true)
+                .SetDefaultValue("Vector3.One")
+                .SetItemsRange(0);
+
+            ProcessSchema("ext.LightsPunctual.g", ctx);
         }
 
         /*
@@ -185,7 +204,10 @@ namespace SharpGLTF
             newEmitter.SetRuntimeName("KHR_materials_pbrSpecularGlossiness glTF extension", "MaterialPBRSpecularGlossiness_KHR");
             newEmitter.SetRuntimeName("KHR_materials_unlit glTF extension", "MaterialUnlit_KHR");
 
-            
+            newEmitter.SetRuntimeName("light", "Light_KHR");
+            newEmitter.SetRuntimeName("light/spot", "LightSpot_KHR");
+
+
 
             var classes = ctx.Classes.ToArray();
             var fields = classes.SelectMany(item => item.Fields).ToArray();

+ 6 - 1
build/SharpGLTF.CodeGen/SchemaReflection/SchemaTypes.cs

@@ -27,7 +27,7 @@ namespace SharpGLTF.SchemaReflection
         /// <summary>
         /// identifier used for serialization and deserialization
         /// </summary>
-        public abstract string PersistentName { get; }
+        public abstract string PersistentName { get; }        
 
         #endregion
 
@@ -336,6 +336,11 @@ namespace SharpGLTF.SchemaReflection
 
         public IEnumerable<FieldInfo> Fields => _Fields;
 
+        /// <summary>
+        /// True to prevent to codegen emitter to emit this class
+        /// </summary>
+        public bool IgnoredByEmitter { get; set; }
+
         #endregion
 
         #region API