Browse Source

WIP: first steps of adding XMP extension support.

Vicente Penades 5 years ago
parent
commit
fb2ed971d6

+ 1 - 1
build/SharpGLTF.CodeGen/CodeGen/EmitCSharp.cs

@@ -151,7 +151,7 @@ namespace SharpGLTF.CodeGen
 
             foreach(var f in type.Fields)
             {
-                var runtimeName = _SanitizeName(f.PersistentName);
+                var runtimeName = _SanitizeName(f.PersistentName).Replace("@","at");
 
                 SetFieldName(f, $"_{runtimeName}");
                 SetPropertyName(f, runtimeName);

+ 3 - 0
build/SharpGLTF.CodeGen/Constants.cs

@@ -27,6 +27,9 @@ namespace SharpGLTF
         public static string KhronosSchemaDir => System.IO.Path.Combine(Constants.LocalRepoDirectory, "extensions", "2.0", "Khronos");
         public static string VendorSchemaDir => System.IO.Path.Combine(Constants.LocalRepoDirectory, "extensions", "2.0", "Vendor");
 
+        public static string KhronosModelXMPSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_xmp", "schema", "glTF.KHR_xmp.schema.json");
+        public static string KhronosNodeXMPSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_xmp", "schema", "node.KHR_xmp.schema.json");
+
         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");
 

+ 52 - 22
build/SharpGLTF.CodeGen/Program.cs

@@ -24,6 +24,9 @@ namespace SharpGLTF
 
             _ProcessMainSchema();
 
+            // XMP
+            _ProcessKhronosXMPExtension();            
+
             // material extensions
             _ProcessKhronosUnlitExtension();
             _ProcessKhronosClearCoatExtension();
@@ -31,8 +34,7 @@ namespace SharpGLTF
             _ProcessKhronosSpecularGlossinessExtension();
 
             // lights
-            _ProcessKhronosModelLightsPunctualExtension();
-            _ProcessKhronosNodeLightsPunctualExtension();
+            _ProcessKhronosLightsPunctualExtension();
 
             // textures
             _ProcessKhronosTextureTransformExtension();
@@ -98,6 +100,43 @@ namespace SharpGLTF
 
         #region Extensions code generation
 
+        private static void _ProcessKhronosXMPExtension()
+        {
+            // Model extension
+
+            var ctx = LoadSchemaContext(Constants.KhronosModelXMPSchemaFile);
+            ctx.IgnoredByCodeEmitter("glTF Property");
+            ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
+
+            /*
+            var jdict = ctx.UseClass("JsonDictionary");
+            var jlist = ctx.UseClass("JsonList");
+
+            ctx.FindClass("KHR_xmp glTF extension")
+                .GetField("@context")
+                .SetDataType(jdict);
+
+            ctx.FindClass("KHR_xmp glTF extension")
+                .GetField("packets")
+                .SetDataType(jlist);*/
+
+            /*
+            ctx.FindClass("KHR_xmp glTF extension")
+                .GetField("@context")
+                .SetDataType(typeof(Dictionary<string,Object>), true);
+            */
+
+            ProcessSchema("ext.XMP.Model.g", ctx);
+
+            // Node extension
+
+            ctx = LoadSchemaContext(Constants.KhronosNodeXMPSchemaFile);
+            ctx.IgnoredByCodeEmitter("glTF Property");
+            ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
+
+            ProcessSchema("ext.XMP.Node.g", ctx);
+        }        
+
         private static void _ProcessKhronosSpecularGlossinessExtension()
         {
             var ctx = LoadSchemaContext(Constants.KhronosPbrSpecGlossSchemaFile);
@@ -135,20 +174,7 @@ namespace SharpGLTF
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
             ctx.IgnoredByCodeEmitter("Texture Info");
-            ctx.IgnoredByCodeEmitter("Material Normal Texture Info");
-
-            /*
-            ctx.FindClass("KHR_materials_pbrSpecularGlossiness glTF extension")
-                .GetField("diffuseFactor")
-                .SetDataType(typeof(System.Numerics.Vector4), true)
-                .SetDefaultValue("Vector4.One")
-                .SetItemsRange(0);
-
-            ctx.FindClass("KHR_materials_pbrSpecularGlossiness glTF extension")
-                .GetField("specularFactor")
-                .SetDataType(typeof(System.Numerics.Vector3), true)
-                .SetDefaultValue("Vector3.One")
-                .SetItemsRange(0);*/
+            ctx.IgnoredByCodeEmitter("Material Normal Texture Info");            
 
             ProcessSchema("ext.ClearCoat.g", ctx);
         }
@@ -164,8 +190,10 @@ namespace SharpGLTF
             ProcessSchema("ext.Transmission.g", ctx);
         }
 
-        private static void _ProcessKhronosModelLightsPunctualExtension()
+        private static void _ProcessKhronosLightsPunctualExtension()
         {
+            // Model
+
             var ctx = LoadSchemaContext(Constants.KhronosModelLightsPunctualSchemaFile);            
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
@@ -177,11 +205,10 @@ namespace SharpGLTF
                 .SetItemsRange(0);
 
             ProcessSchema("ext.ModelLightsPunctual.g", ctx);
-        }
 
-        private static void _ProcessKhronosNodeLightsPunctualExtension()
-        {
-            var ctx = LoadSchemaContext(Constants.KhronosNodeLightsPunctualSchemaFile);
+            // Node
+
+            ctx = LoadSchemaContext(Constants.KhronosNodeLightsPunctualSchemaFile);
             ctx.IgnoredByCodeEmitter("glTF Property");
             ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
 
@@ -272,10 +299,13 @@ namespace SharpGLTF
             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_unlit glTF extension", "MaterialUnlit");            
             newEmitter.SetRuntimeName("KHR_materials_clearcoat glTF extension", "MaterialClearCoat");
             newEmitter.SetRuntimeName("KHR_materials_transmission glTF extension", "MaterialTransmission");
 
+            newEmitter.SetRuntimeName("KHR_xmp glTF extension", "XMPPacketsCollection");
+            newEmitter.SetRuntimeName("KHR_xmp node extension", "XMPPacketReference");
+
 
 
             newEmitter.SetRuntimeName("light", "PunctualLight");

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

@@ -244,7 +244,7 @@ namespace SharpGLTF.SchemaReflection
 
         public String Description { get; set; }
 
-        public string PersistentName => _PersistentName;                
+        public String PersistentName => _PersistentName;
 
         public SchemaType FieldType { get => _FieldType; set => _FieldType = value; }
 

+ 61 - 0
src/SharpGLTF.Core/Schema2/Generated/ext.XMP.Model.g.cs

@@ -0,0 +1,61 @@
+// <auto-generated/>
+
+//------------------------------------------------------------------------------------------------
+//      This file has been programatically generated; DON´T EDIT!
+//------------------------------------------------------------------------------------------------
+
+#pragma warning disable SA1001
+#pragma warning disable SA1027
+#pragma warning disable SA1028
+#pragma warning disable SA1121
+#pragma warning disable SA1205
+#pragma warning disable SA1309
+#pragma warning disable SA1402
+#pragma warning disable SA1505
+#pragma warning disable SA1507
+#pragma warning disable SA1508
+#pragma warning disable SA1652
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Numerics;
+using System.Text.Json;
+
+namespace SharpGLTF.Schema2
+{
+	using Collections;
+
+	/// <summary>
+	/// Metadata about the glTF asset.
+	/// </summary>
+	partial class XMPPacketsCollection : ExtraProperties
+	{
+	
+		private Object _atcontext;
+		
+		private const int _packetsMinItems = 1;
+		private List<Object> _packets;
+		
+	
+		protected override void SerializeProperties(Utf8JsonWriter writer)
+		{
+			base.SerializeProperties(writer);
+			SerializeProperty(writer, "@context", _atcontext);
+			SerializeProperty(writer, "packets", _packets, _packetsMinItems);
+		}
+	
+		protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader)
+		{
+			switch (jsonPropertyName)
+			{
+				case "@context": _atcontext = DeserializePropertyValue<Object>(ref reader); break;
+				case "packets": DeserializePropertyList<Object>(ref reader, _packets); break;
+				default: base.DeserializeProperty(jsonPropertyName,ref reader); break;
+			}
+		}
+	
+	}
+
+}

+ 56 - 0
src/SharpGLTF.Core/Schema2/Generated/ext.XMP.Node.g.cs

@@ -0,0 +1,56 @@
+// <auto-generated/>
+
+//------------------------------------------------------------------------------------------------
+//      This file has been programatically generated; DON´T EDIT!
+//------------------------------------------------------------------------------------------------
+
+#pragma warning disable SA1001
+#pragma warning disable SA1027
+#pragma warning disable SA1028
+#pragma warning disable SA1121
+#pragma warning disable SA1205
+#pragma warning disable SA1309
+#pragma warning disable SA1402
+#pragma warning disable SA1505
+#pragma warning disable SA1507
+#pragma warning disable SA1508
+#pragma warning disable SA1652
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Numerics;
+using System.Text.Json;
+
+namespace SharpGLTF.Schema2
+{
+	using Collections;
+
+	/// <summary>
+	/// References an XMP packet listed in `KHR_xmp glTF extension`
+	/// </summary>
+	partial class XMPPacketReference : ExtraProperties
+	{
+	
+		private Int32 _packet;
+		
+	
+		protected override void SerializeProperties(Utf8JsonWriter writer)
+		{
+			base.SerializeProperties(writer);
+			SerializeProperty(writer, "packet", _packet);
+		}
+	
+		protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader)
+		{
+			switch (jsonPropertyName)
+			{
+				case "packet": _packet = DeserializePropertyValue<Int32>(ref reader); break;
+				default: base.DeserializeProperty(jsonPropertyName,ref reader); break;
+			}
+		}
+	
+	}
+
+}