Browse Source

add textures and propertytable test

Bert Temme 2 years ago
parent
commit
c16d6e64cf

+ 2 - 1
build/SharpGLTF.CodeGen/Ext.EXT_Structural_Metadata.cs

@@ -15,7 +15,8 @@ namespace SharpGLTF
 
         public override void PrepareTypes(CSharpEmitter newEmitter, SchemaType.Context ctx)
         {
-            newEmitter.SetRuntimeName("EXT_structural_metadata glTF extension", "EXTStructuralMetaDataRoot");
+            newEmitter.SetRuntimeName("EXT_structural_metadata glTF Mesh Primitive extension", "ExtStructuralMetadataMeshPrimitive");
+            newEmitter.SetRuntimeName("EXT_structural_metadata glTF extension", "EXTStructuralMetadataRoot");
             newEmitter.SetRuntimeName("Property Table in EXT_structural_metadata", "PropertyTable");
             newEmitter.SetRuntimeName("Schema in EXT_structural_metadata", "StructuralMetadataSchema");
             newEmitter.SetRuntimeName("Property Table Property in EXT_structural_metadata", "PropertyTableProperty");

+ 4 - 1
src/SharpGLTF.Cesium/Schema2/CesiumExtensions.cs

@@ -19,7 +19,10 @@
             ExtensionsFactory.RegisterExtension<MeshPrimitive, CesiumPrimitiveOutline>("CESIUM_primitive_outline");
             ExtensionsFactory.RegisterExtension<Node, MeshExtInstanceFeatures>("EXT_instance_features");
             ExtensionsFactory.RegisterExtension<MeshPrimitive, MeshExtMeshFeatures>("EXT_mesh_features");
-            ExtensionsFactory.RegisterExtension<ModelRoot, EXTStructuralMetaDataRoot>("EXT_structural_metadata");
+            ExtensionsFactory.RegisterExtension<ModelRoot, EXTStructuralMetadataRoot>("EXT_structural_metadata");
+
+            // todo: register the rest of the extensions
+            // ExtensionsFactory.RegisterExtension<MeshPrimitive, EXTStructuralMetadataMeshPrimitive>("EXT_structural_metadata");
         }
     }
 }

+ 65 - 28
src/SharpGLTF.Cesium/Schema2/EXTStructuralMetaDataRoot.cs

@@ -6,33 +6,67 @@ using System.Globalization;
 
 namespace SharpGLTF.Schema2
 {
-    public static class ExtStructuralMetadata
+    public static class ExtStructuralMetadataRoot
     {
-        // sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/SimplePropertyTexture/SimplePropertyTexture.gltf
-        public static void SetPropertyTexture(
+        public static void SetPropertyAttribute(
             this ModelRoot modelRoot,
-            PropertyTexture propertyTexture,
-            OneOf<StructuralMetadataSchema, Uri> schema
-            )
+            PropertyAttribute propertyAttribute,
+            OneOf<StructuralMetadataSchema, Uri> schema)
+        {
+            SetPropertyAttributes(modelRoot, new List<PropertyAttribute>() { propertyAttribute }, schema);
+        }
+
+        public static void SetPropertyAttributes(
+this ModelRoot modelRoot,
+List<PropertyAttribute> propertyAttributes,
+OneOf<StructuralMetadataSchema, Uri> schema)
         {
-            if (propertyTexture == null) { modelRoot.RemoveExtensions<EXTStructuralMetaDataRoot>(); return; }
+            if (propertyAttributes == null || propertyAttributes.Count == 0) { modelRoot.RemoveExtensions<EXTStructuralMetadataRoot>(); return; }
+
+            schema.Switch(
+                metadataschema =>
+                    CheckSchema(metadataschema),
+                Uri =>
+                {
+                    // do not check here, because schema is not loaded
+                }
+                );
 
-            var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
-            ext.PropertyTextures.Clear();
-            ext.PropertyTextures.Add(propertyTexture);
+            // todo add check propertyAttribute 
+            var ext = modelRoot.UseExtension<EXTStructuralMetadataRoot>();
+            ext.PropertyAttributes = propertyAttributes;
             ext.AddSchema(schema);
         }
 
-        public static void SetPropertyAttribute(
-            this ModelRoot modelRoot,
-            PropertyAttribute propertyAttribute,
-            OneOf<StructuralMetadataSchema, Uri> schema)
+
+        public static void SetPropertyTexture(
+    this ModelRoot modelRoot,
+    PropertyTexture propertyTexture,
+    OneOf<StructuralMetadataSchema, Uri> schema)
+        {
+            SetPropertyTextures(modelRoot, new List<PropertyTexture>() { propertyTexture }, schema);
+        }
+
+
+        public static void SetPropertyTextures(
+    this ModelRoot modelRoot,
+    List<PropertyTexture> propertyTextures,
+    OneOf<StructuralMetadataSchema, Uri> schema)
         {
-            if (propertyAttribute == null) { modelRoot.RemoveExtensions<EXTStructuralMetaDataRoot>(); return; }
+            if (propertyTextures == null || propertyTextures.Count == 0) { modelRoot.RemoveExtensions<EXTStructuralMetadataRoot>(); return; }
 
-            var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
-            ext.PropertyAttributes.Clear();
-            ext.PropertyAttributes.Add(propertyAttribute);
+            schema.Switch(
+                metadataschema =>
+                    CheckSchema(metadataschema),
+                Uri =>
+                {
+                    // do not check here, because schema is not loaded
+                }
+                );
+
+            // todo add check propertyTexture 
+            var ext = modelRoot.UseExtension<EXTStructuralMetadataRoot>();
+            ext.PropertyTextures = propertyTextures;
             ext.AddSchema(schema);
         }
 
@@ -49,7 +83,7 @@ namespace SharpGLTF.Schema2
             List<PropertyTable> propertyTables,
             OneOf<StructuralMetadataSchema, Uri> schema)
         {
-            if (propertyTables == null || propertyTables.Count == 0) { modelRoot.RemoveExtensions<EXTStructuralMetaDataRoot>(); return; }
+            if (propertyTables == null || propertyTables.Count == 0) { modelRoot.RemoveExtensions<EXTStructuralMetadataRoot>(); return; }
 
             schema.Switch(
                 metadataschema =>
@@ -77,7 +111,7 @@ namespace SharpGLTF.Schema2
                     );
             }
 
-            var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
+            var ext = modelRoot.UseExtension<EXTStructuralMetadataRoot>();
             ext.PropertyTables = propertyTables;
             ext.AddSchema(schema);
         }
@@ -170,11 +204,11 @@ namespace SharpGLTF.Schema2
         }
     }
 
-    public partial class EXTStructuralMetaDataRoot
+    public partial class EXTStructuralMetadataRoot
     {
         private ModelRoot modelRoot;
 
-        internal EXTStructuralMetaDataRoot(ModelRoot modelRoot)
+        internal EXTStructuralMetadataRoot(ModelRoot modelRoot)
         {
             this.modelRoot = modelRoot;
             _propertyTables = new List<PropertyTable>();
@@ -252,13 +286,16 @@ namespace SharpGLTF.Schema2
 
     public partial class PropertyTextureProperty
     {
-        // todo: how to set index?
+        public PropertyTextureProperty()
+        {
+            _channels = new List<int>();
+        }
 
-        //public int Index
-        //{
-        //    get { return _index; }
-        //    set { _index = value; }
-        //}
+        public List<int> Channels
+        {
+            get { return _channels; }
+            set { _channels = value; }
+        }
     }
 
     public partial class PropertyAttribute

+ 1 - 1
src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_primitive.g.cs

@@ -34,7 +34,7 @@ namespace SharpGLTF.Schema2
 	[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 EXT_structural_metadataglTFMeshPrimitiveextension : ExtraProperties
+	partial class ExtStructuralMetadataMeshPrimitive : ExtraProperties
 	{
 	
 		private const int _propertyAttributesMinItems = 1;

+ 1 - 1
src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_structural_metadata_root.g.cs

@@ -638,7 +638,7 @@ namespace SharpGLTF.Schema2
 	[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 EXTStructuralMetaDataRoot : ExtraProperties
+	partial class EXTStructuralMetadataRoot : ExtraProperties
 	{
 	
 		private const int _propertyAttributesMinItems = 1;

+ 5 - 0
src/SharpGLTF.Cesium/Schema2/MeshExtMeshFeatures.cs

@@ -38,6 +38,11 @@ namespace SharpGLTF.Schema2
 
     public partial class MeshExtMeshFeatureIDTexture
     {
+        public MeshExtMeshFeatureIDTexture()
+        {
+            _channels = new List<int>();
+        }
+
         public MeshExtMeshFeatureIDTexture(List<int> channels, int? index = null, int? texCoord = null)
         {
             Guard.NotNullOrEmpty(channels, nameof(channels));

File diff suppressed because it is too large
+ 6 - 0
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs


Some files were not shown because too many files changed in this diff