Browse Source

add code generating code

Bert Temme 2 years ago
parent
commit
1afa1386a5

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

@@ -10,10 +10,16 @@ namespace SharpGLTF
 
 
         public static string RemoteSchemaRepo = "https://github.com/KhronosGroup/glTF.git";
         public static string RemoteSchemaRepo = "https://github.com/KhronosGroup/glTF.git";
 
 
+        /// <summary>
+        /// Program directory
+        /// </summary>
+        public static string ProgramDirectory => System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location);
+
         /// <summary>
         /// <summary>
         /// Directory where the schema is downloaded and used as source
         /// Directory where the schema is downloaded and used as source
         /// </summary>
         /// </summary>
-        public static string LocalRepoDirectory => System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location), "glTF");
+        public static string LocalRepoDirectory => System.IO.Path.Combine(ProgramDirectory, "glTF");
+
 
 
         #endregion
         #endregion
 
 
@@ -51,6 +57,12 @@ namespace SharpGLTF
             return System.IO.Path.Combine(VendorSchemaDir, ext, "schema", json);
             return System.IO.Path.Combine(VendorSchemaDir, ext, "schema", json);
         }
         }
 
 
+        internal static string CustomExtensionsPath(string ext, string json)
+        {
+            return System.IO.Path.Combine(ProgramDirectory, "Schemas", ext, "schema", json);
+        }
+
+
         #endregion
         #endregion
 
 
         #region code generation output paths
         #region code generation output paths

+ 68 - 0
build/SharpGLTF.CodeGen/Ext.EXT_MeshFeatures.cs

@@ -0,0 +1,68 @@
+using SharpGLTF.CodeGen;
+using SharpGLTF.SchemaReflection;
+using System;
+using System.Collections.Generic;
+
+namespace SharpGLTF
+{
+    class ExtMeshFeaturesExtension : SchemaProcessor
+    {
+        public override string GetTargetProject() { return Constants.CesiumProjectDirectory; }
+
+        private static string RootSchemaUri => Constants.CustomExtensionsPath("EXT_mesh_features", "mesh.primitive.EXT_mesh_features.schema.json");
+        public override void PrepareTypes(CSharpEmitter newEmitter, SchemaType.Context ctx)
+        {
+            newEmitter.SetRuntimeName("EXT_mesh_features glTF Mesh Primitive extension", "MeshExtMeshFeatures");
+            newEmitter.SetRuntimeName("Feature ID in EXT_mesh_features", "FeatureID");
+
+            // Todo Trying to fix the code generation for the FeatureIDTexture channel property
+
+            // Schema: from featureIdTexture.schema.json
+            //    "channels": {
+            //        "type": "array",
+            //    "items": {
+            //            "type": "integer",
+            //        "minimum": 0
+            //    },
+            //    "minItems": 1,
+            //    "description": "Texture channels containing feature IDs, identified by index. Feature IDs may be packed into multiple channels if a single channel does not have sufficient bit depth to represent all feature ID values. The values are packed in little-endian order.",
+            //    "default": [
+            //        0
+            //    ]
+            //},
+
+
+            // code generated
+            //                    private static readonly Int32[] _channelsDefault = [
+            //  0
+            //];
+            //        private const int _channelsMinItems = 1;
+            //        private List<Int32> _channels = _channelsDefault;
+
+            // should be?
+            //private static readonly Int32[] _channelsDefault = new Int32[1] { 0 };
+            //private const int _channelsMinItems = 1;
+            //private Int32[] _channels = _channelsDefault;
+
+            // attempts
+
+            //var FeatureIdTextureClass = ctx.FindClass("Feature ID Texture in EXT_mesh_features")
+            //    .GetField("channels")
+            //    .SetDefaultValue("new List<Int32>()");
+            // BT does not work :-( .SetDefaultValue("List<Int32>")
+        }
+
+        public override IEnumerable<(string TargetFileName, SchemaType.Context Schema)> Process()
+        {
+            yield return ("Ext.CESIUM_ext_mesh_features.g", ProcessRoot());
+        }
+
+        private static SchemaType.Context ProcessRoot()
+        {
+            var ctx = SchemaProcessing.LoadSchemaContext(RootSchemaUri);
+            ctx.IgnoredByCodeEmitter("glTF Property");
+            ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
+            return ctx;
+        }
+    }
+}

+ 9 - 5
build/SharpGLTF.CodeGen/Program.cs

@@ -1,4 +1,6 @@
-using System;
+using SharpGLTF.CodeGen;
+using SharpGLTF.SchemaReflection;
+using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Reflection;
 using System.Reflection;
@@ -56,19 +58,21 @@ namespace SharpGLTF
             // other
             // other
             processors.Add(new XmpJsonLdExtension());
             processors.Add(new XmpJsonLdExtension());
 
 
+            processors.Add(new ExtMeshFeaturesExtension());
+
             // ----------------------------------------------  process all files
             // ----------------------------------------------  process all files
 
 
             foreach (var processor in processors)
             foreach (var processor in processors)
             {
             {
-                foreach(var (targetFileName, schema) in processor.Process())
+                foreach (var (targetFileName, schema) in processor.Process())
                 {
                 {
                     System.Console.WriteLine($"Emitting {targetFileName}...");
                     System.Console.WriteLine($"Emitting {targetFileName}...");
 
 
                     SchemaProcessing.EmitCodeFromSchema(processor.GetTargetProject(), targetFileName, schema, processors);
                     SchemaProcessing.EmitCodeFromSchema(processor.GetTargetProject(), targetFileName, schema, processors);
                 }
                 }
-            }            
+            }
         }
         }
 
 
         #endregion     
         #endregion     
-    }    
-}
+    }
+}

+ 0 - 0
src/SharpGLTF.Cesium/EXT_mesh_features/README.md → build/SharpGLTF.CodeGen/Schemas/EXT_mesh_features/README.md


+ 0 - 0
src/SharpGLTF.Cesium/EXT_mesh_features/schema/featureId.schema.json → build/SharpGLTF.CodeGen/Schemas/EXT_mesh_features/schema/featureId.schema.json


+ 0 - 0
src/SharpGLTF.Cesium/EXT_mesh_features/schema/featureIdAttribute.schema.json → build/SharpGLTF.CodeGen/Schemas/EXT_mesh_features/schema/featureIdAttribute.schema.json


+ 0 - 0
src/SharpGLTF.Cesium/EXT_mesh_features/schema/featureIdTexture.schema.json → build/SharpGLTF.CodeGen/Schemas/EXT_mesh_features/schema/featureIdTexture.schema.json


+ 0 - 0
src/SharpGLTF.Cesium/EXT_mesh_features/schema/mesh.primitive.EXT_mesh_features.schema.json → build/SharpGLTF.CodeGen/Schemas/EXT_mesh_features/schema/mesh.primitive.EXT_mesh_features.schema.json


+ 19 - 0
build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj

@@ -11,4 +11,23 @@
     <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.9.0" />
     <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.9.0" />
   </ItemGroup>
   </ItemGroup>
 
 
+  <ItemGroup>
+    <Folder Include="Schemas\" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <None Update="Schemas\EXT_mesh_features\schema\featureId.schema.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Update="Schemas\EXT_mesh_features\schema\featureIdAttribute.schema.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Update="Schemas\EXT_mesh_features\schema\featureIdTexture.schema.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Update="Schemas\EXT_mesh_features\schema\mesh.primitive.EXT_mesh_features.schema.json">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
 </Project>
 </Project>

+ 57 - 7
src/SharpGLTF.Cesium/Schema2/Generated/ext.MeshFeaturesMesh.g.cs → src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_mesh_features.g.cs

@@ -28,18 +28,59 @@ namespace SharpGLTF.Schema2
 	using Collections;
 	using Collections;
 
 
 	/// <summary>
 	/// <summary>
-	/// A texture containing feature IDs
+	/// Reference to a texture.
 	/// </summary>
 	/// </summary>
-	partial class FeatureIDTextureinEXT_mesh_features : TextureInfo
+	#if NET6_0_OR_GREATER
+	[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
+	#endif
+	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
+	partial class TextureInfo : ExtraProperties
 	{
 	{
 	
 	
-		private static readonly Int32[] _channelsDefault = new Int32[1] {0 };
-		private Int32[] _channels = _channelsDefault;
+		private Int32 _index;
 		
 		
+		private const Int32 _texCoordDefault = 0;
+		private const Int32 _texCoordMinimum = 0;
+		private Int32? _texCoord = _texCoordDefault;
+		
+	
 		protected override void SerializeProperties(Utf8JsonWriter writer)
 		protected override void SerializeProperties(Utf8JsonWriter writer)
 		{
 		{
 			base.SerializeProperties(writer);
 			base.SerializeProperties(writer);
-			SerializeProperty(writer,"channels",_channels);
+			SerializeProperty(writer, "index", _index);
+			SerializeProperty(writer, "texCoord", _texCoord, _texCoordDefault);
+		}
+	
+		protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader)
+		{
+			switch (jsonPropertyName)
+			{
+				case "index": _index = DeserializePropertyValue<Int32>(ref reader); break;
+				case "texCoord": _texCoord = DeserializePropertyValue<Int32?>(ref reader); break;
+				default: base.DeserializeProperty(jsonPropertyName,ref reader); break;
+			}
+		}
+	
+	}
+
+	/// <summary>
+	/// A texture containing feature IDs
+	/// </summary>
+	#if NET6_0_OR_GREATER
+	[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
+	#endif
+	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
+	partial class FeatureIDTextureinEXT_mesh_features : TextureInfo
+	{
+        private static readonly Int32[] _channelsDefault = new Int32[1] { 0 };
+        private const int _channelsMinItems = 1;
+        private Int32[] _channels = _channelsDefault;
+
+
+        protected override void SerializeProperties(Utf8JsonWriter writer)
+		{
+			base.SerializeProperties(writer);
+			SerializeProperty(writer, "channels", _channels, _channelsMinItems);
 		}
 		}
 	
 	
 		protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader)
 		protected override void DeserializeProperty(string jsonPropertyName, ref Utf8JsonReader reader)
@@ -56,6 +97,10 @@ namespace SharpGLTF.Schema2
 	/// <summary>
 	/// <summary>
 	/// Feature IDs stored in an attribute or texture.
 	/// Feature IDs stored in an attribute or texture.
 	/// </summary>
 	/// </summary>
+	#if NET6_0_OR_GREATER
+	[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
+	#endif
+	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
 	partial class FeatureID : ExtraProperties
 	partial class FeatureID : ExtraProperties
 	{
 	{
 	
 	
@@ -105,13 +150,18 @@ namespace SharpGLTF.Schema2
 	/// <summary>
 	/// <summary>
 	/// An object describing feature IDs for a mesh primitive.
 	/// An object describing feature IDs for a mesh primitive.
 	/// </summary>
 	/// </summary>
+	#if NET6_0_OR_GREATER
+	[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
+	#endif
+	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
 	partial class MeshExtMeshFeatures : ExtraProperties
 	partial class MeshExtMeshFeatures : ExtraProperties
 	{
 	{
 	
 	
 		private const int _featureIdsMinItems = 1;
 		private const int _featureIdsMinItems = 1;
 		private List<FeatureID> _featureIds;
 		private List<FeatureID> _featureIds;
-
-        protected override void SerializeProperties(Utf8JsonWriter writer)
+		
+	
+		protected override void SerializeProperties(Utf8JsonWriter writer)
 		{
 		{
 			base.SerializeProperties(writer);
 			base.SerializeProperties(writer);
 			SerializeProperty(writer, "featureIds", _featureIds, _featureIdsMinItems);
 			SerializeProperty(writer, "featureIds", _featureIds, _featureIdsMinItems);