Browse Source

adding tests with Feature ID by Texture Coordinates

Bert Temme 2 years ago
parent
commit
08da7c7e4a

+ 13 - 14
src/SharpGLTF.Cesium/Schema2/Generated/Ext.CESIUM_ext_mesh_features.g.cs

@@ -25,14 +25,14 @@ using System.Text.Json;
 
 namespace SharpGLTF.Schema2
 {
-	using Collections;
+    using Collections;
 
-	/// <summary>
-	/// A texture containing feature IDs
-	/// </summary>
-	#if NET6_0_OR_GREATER
+    /// <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
+#endif
 	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
 	partial class MeshExtMeshFeatureIDTexture : TextureInfo
 	{
@@ -55,16 +55,15 @@ namespace SharpGLTF.Schema2
 				default: base.DeserializeProperty(jsonPropertyName,ref reader); break;
 			}
 		}
-	
-	}
+    }
 
-	/// <summary>
-	/// Feature IDs stored in an attribute or texture.
-	/// </summary>
-	#if NET6_0_OR_GREATER
+    /// <summary>
+    /// Feature IDs stored in an attribute or texture.
+    /// </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")]
+#endif
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
 	partial class MeshExtMeshFeatureID : ExtraProperties
 	{
 	

+ 13 - 1
src/SharpGLTF.Cesium/Schema2/MeshExtMeshFeatures.cs

@@ -40,14 +40,26 @@ namespace SharpGLTF.Schema2
         }
     }
 
+    public partial class MeshExtMeshFeatureIDTexture
+    {
+        public MeshExtMeshFeatureIDTexture(List<int> channels, int? index = null, int? texCoord = null)
+        {
+            _channels = channels;
+            if (index.HasValue) _LogicalTextureIndex = (int)index;
+            if (texCoord.HasValue) TextureCoordinate = (int)texCoord;
+        }
+    }
+
     public partial class MeshExtMeshFeatureID
     {
-        public MeshExtMeshFeatureID(int featureCount, int? attribute = null, int? propertyTable = null, string label = null)
+        public MeshExtMeshFeatureID(int featureCount, int? attribute = null, int? propertyTable = null, string label = null, int? nullFeatureId = null, MeshExtMeshFeatureIDTexture texture = null)
         {
             _featureCount = featureCount;
             _attribute = attribute;
             _label = label;
             _propertyTable = propertyTable;
+            _nullFeatureId = nullFeatureId;
+            _texture = texture;
         }
     }
 

+ 1 - 1
src/SharpGLTF.Core/Schema2/gltf.TextureInfo.cs

@@ -8,7 +8,7 @@ namespace SharpGLTF.Schema2
     {
         #region properties
 
-        internal int _LogicalTextureIndex
+        public int _LogicalTextureIndex
         {
             get => _index;
             set => _index = value;

+ 13 - 4
tests/SharpGLTF.Cesium.Tests/ExtMeshFeaturesTests.cs

@@ -26,7 +26,6 @@ namespace SharpGLTF.Cesium
             TestContext.CurrentContext.AttachGltfValidatorLinks();
 
             var material = MaterialBuilder.CreateDefault();
-
             var mesh = new MeshBuilder<VertexPosition>("mesh");
 
             var prim = mesh.UsePrimitive(material);
@@ -39,8 +38,18 @@ namespace SharpGLTF.Cesium
             var model = scene.ToGltf2();
 
             // See sample https://github.com/CesiumGS/glTF/tree/proposal-EXT_mesh_features/extensions/2.0/Vendor/EXT_mesh_features#feature-id-by-vertex
-            var featureId = new MeshExtMeshFeatureID(2, 0);
-            var featureIds = new List<MeshExtMeshFeatureID>() { featureId };
+
+            // Feature ID by attribute
+            var featureIdAttribute = new MeshExtMeshFeatureID(2, 0);
+
+            // Feature ID by Texture coordinates
+            var texture = new MeshExtMeshFeatureIDTexture(new List<int>() { 0 }, 0, 0);
+            var featureIdTexture = new MeshExtMeshFeatureID(3, nullFeatureId: 0, texture: texture);
+
+            // Feature ID with property table
+            var featureIdPropertyTable = new MeshExtMeshFeatureID(3, nullFeatureId: 0, texture: texture,propertyTable:1, label:"classification");
+
+            var featureIds = new List<MeshExtMeshFeatureID>() { featureIdAttribute, featureIdTexture, featureIdPropertyTable };
             model.LogicalMeshes[0].Primitives[0].SetFeatureIds(featureIds);
 
             var cesiumExtMeshFeaturesExtension = (MeshExtMeshFeatures)model.LogicalMeshes[0].Primitives[0].Extensions.FirstOrDefault();
@@ -49,8 +58,8 @@ namespace SharpGLTF.Cesium
             Assert.IsTrue(cesiumExtMeshFeaturesExtension.FeatureIds.Equals(featureIds));
 
             var ctx = new ValidationResult(model, ValidationMode.Strict, true);
-            model.ValidateContent(ctx.GetContext());
 
+            model.ValidateContent(ctx.GetContext());
             scene.AttachToCurrentTest("cesium_ext_mesh_features.glb");
             scene.AttachToCurrentTest("cesium_ext_mesh_features.gltf");
             scene.AttachToCurrentTest("cesium_ext_mesh_features.plotly");