Browse Source

get the pointcloud demo with custom attributes working

Bert Temme 2 years ago
parent
commit
1691d5d783

+ 10 - 0
src/SharpGLTF.Cesium/Schema2/EXTStructuralMetaDataRoot.cs

@@ -27,6 +27,10 @@ namespace SharpGLTF.Schema2
             if (propertyAttribute == null) { modelRoot.RemoveExtensions<EXTStructuralMetaDataRoot>(); return; }
 
             var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
+            // Todo: Check if this is correct, it's a kinda workaround
+            // for the OneOf issue. https://github.com/CesiumGS/glTF/blob/proposal-EXT_structural_metadata/extensions/2.0/Vendor/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json#L53
+            // Here we use schemaUri but not schema
+            ext.SchemaUri = "MetadataSchema.json"; 
             ext.PropertyAttributes.Clear();
             ext.PropertyAttributes.Add(propertyAttribute);
         }
@@ -96,6 +100,12 @@ namespace SharpGLTF.Schema2
             set { _propertyTables = value; }
         }
 
+        internal string SchemaUri
+        {
+            get { return _schemaUri; }
+            set { _schemaUri = value; }
+        }
+
         internal List<PropertyAttribute> PropertyAttributes
         {
             get { return _propertyAttributes; }

+ 10 - 22
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -5,6 +5,7 @@ using SharpGLTF.Materials;
 using SharpGLTF.Scenes;
 using SharpGLTF.Schema2;
 using SharpGLTF.Validation;
+using System;
 using System.Collections.Generic;
 using System.Numerics;
 
@@ -20,6 +21,7 @@ namespace SharpGLTF.Cesium
         }
 
         [Test(Description = "ext_structural_metadata with pointcloud and custom attributes")]
+        /// Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/PropertyAttributesPointCloud/PropertyAttributesPointCloudHouse.gltf
 
         public void CreatePointCloudWithCustomAttributesTest()
         {
@@ -27,15 +29,16 @@ namespace SharpGLTF.Cesium
             var mesh = new MeshBuilder<VertexPosition, VertexPointcloud, VertexEmpty>("mesh");
             var pointCloud = mesh.UsePrimitive(material, 1);
             var redColor = new Vector4(1f, 0f, 0f, 1f);
-
+            var rand = new Random();
             for (var x = -10; x < 10; x++)
             {
                 for (var y = -10; y < 10; y++)
                 {
                     for (var z = -10; z < 10; z++)
                     {
-                        // intensity values on x-axis, classification on z-axis
-                        var vt0 = VertexBuilder.GetVertexPointcloud(new Vector3(x, y, z), redColor, x, z);
+                        // intensity values is based on x-axis values
+                        // classification of points is 0 or 1 (random)
+                        var vt0 = VertexBuilder.GetVertexPointcloud(new Vector3(x, y, z), redColor, x, rand.Next(0,2));
 
                         pointCloud.AddPoint(vt0);
                     }
@@ -48,21 +51,6 @@ namespace SharpGLTF.Cesium
             model.UseScene("Default")
                 .CreateNode().WithMesh(model.LogicalMeshes[0]);
 
-            var ctx = new ValidationResult(model, ValidationMode.Strict, true);
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.glb");
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.gltf");
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.plotly");
-        }
-
-
-        /// <summary>
-        /// Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/PropertyAttributesPointCloud/PropertyAttributesPointCloudHouse.gltf
-        /// </summary>
-        [Test(Description = "ext_structural_metadata with PropertyAttributes")]
-        public void TriangleWithPropertyAttributes()
-        {
-            // todo: create a model with custom vertex attributes "_INTENSITY" and "_CLASSIFICATION"
-            var model = GetTriangleModel();
             var propertyAttribute = new Schema2.PropertyAttribute();
             propertyAttribute.Class = "exampleMetadataClass";
             var intensityProperty = new PropertyAttributeProperty();
@@ -73,13 +61,13 @@ namespace SharpGLTF.Cesium
             propertyAttribute.Properties["classification"] = classificationProperty;
 
             model.SetPropertyAttribute(propertyAttribute);
-            
             var ctx = new ValidationResult(model, ValidationMode.Strict, true);
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_property_attribute.glb");
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_property_attribute.gltf");
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_property_attribute.plotly");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.glb");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.gltf");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.plotly");
         }
 
+
         [Test(Description ="First test with ext_structural_metadata")]
         public void TriangleWithMetadataTest()
         {