Browse Source

add pointcloud test

Bert Temme 2 years ago
parent
commit
64c378290d

+ 34 - 0
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -19,6 +19,40 @@ namespace SharpGLTF.Cesium
             CesiumExtensions.RegisterExtensions();
         }
 
+        [Test(Description = "ext_structural_metadata with pointcloud and custom attributes")]
+
+        public void CreatePointCloudWithCustomAttributesTest()
+        {
+            var material = new MaterialBuilder("material1").WithUnlitShader();
+            var mesh = new MeshBuilder<VertexPosition, VertexPointcloud, VertexEmpty>("mesh");
+            var pointCloud = mesh.UsePrimitive(material, 1);
+
+            for (var x = -10; x < 10; x++)
+            {
+                for (var y = -10; y < 10; y++)
+                {
+                    for (var z = -10; z < 10; z++)
+                    {
+                        var vt0 = VertexBuilder.GetVertexPointcloud(new Vector3(x, y, z), 199, 4);
+
+                        pointCloud.AddPoint(vt0);
+                    }
+                }
+            }
+            var model = ModelRoot.CreateModel();
+            model.CreateMeshes(mesh);
+
+            // create a scene, a node, and assign the first mesh (the terrain)
+            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_prointcloud_attributes.gltf");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_prointcloud_attributes.plotly");
+        }
+
+
         /// <summary>
         /// Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/PropertyAttributesPointCloud/PropertyAttributesPointCloudHouse.gltf
         /// </summary>

+ 8 - 0
tests/SharpGLTF.Cesium.Tests/VertexBuilder.cs

@@ -13,5 +13,13 @@ namespace SharpGLTF
             return vb0;
         }
 
+        internal static VertexBuilder<VertexPosition, VertexPointcloud, VertexEmpty> GetVertexPointcloud(Vector3 position, float intensity, float classification)
+        {
+            var vertexPointcloud = new VertexPointcloud(intensity, classification);
+            vertexPointcloud.SetColor(0, new Vector4(1, 0, 0, 0));
+            var vp0 = new VertexPosition(position);
+            var vb0 = new VertexBuilder<VertexPosition, VertexPointcloud, VertexEmpty>(vp0, vertexPointcloud);
+            return vb0;
+        }
     }
 }

+ 80 - 0
tests/SharpGLTF.Cesium.Tests/VertexPointcloud.cs

@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+
+using SharpGLTF.Geometry.VertexTypes;
+using SharpGLTF.Schema2;
+
+namespace SharpGLTF
+{
+    [System.Diagnostics.DebuggerDisplay("𝐂:{Color} 𝐔𝐕:{TexCoord}")]
+    public struct VertexPointcloud : IVertexCustom
+    {
+        public VertexPointcloud(float intensity, float classification)
+        {
+            Intensity = intensity;
+            Classification = classification;
+        }
+
+        public const string INTENSITYATTRIBUTENAME = "_INTENSITY";
+        public const string CLASSIFICATIONATTRIBUTENAME = "_CLASSIFICATION";
+
+        [VertexAttribute(INTENSITYATTRIBUTENAME, EncodingType.FLOAT, false)]
+        public float Intensity;
+        
+        [VertexAttribute(CLASSIFICATIONATTRIBUTENAME, EncodingType.FLOAT, false)]
+        public float Classification;
+
+        public int MaxColors => 0;
+
+        public int MaxTextCoords => 0;
+
+        public IEnumerable<string> CustomAttributes => throw new NotImplementedException();
+
+        public void SetColor(int setIndex, Vector4 color) {
+        }
+
+        public void SetTexCoord(int setIndex, Vector2 coord) { }
+
+        public Vector4 GetColor(int index) { throw new ArgumentOutOfRangeException(nameof(index)); }
+
+        public Vector2 GetTexCoord(int index) { throw new ArgumentOutOfRangeException(nameof(index)); }
+
+        public void Validate() { }
+
+        public object GetCustomAttribute(string attributeName)
+        {
+            throw new NotImplementedException();
+        }
+
+        public bool TryGetCustomAttribute(string attribute, out object value)
+        {
+            if (attribute == INTENSITYATTRIBUTENAME) {
+                value = Intensity; return true;
+            }
+            else if(attribute == CLASSIFICATIONATTRIBUTENAME)
+            {
+                value = Classification; return true;
+            }
+            else
+            {
+                value = null; return false;
+            }
+        }
+
+        public void SetCustomAttribute(string attributeName, object value)
+        {
+            throw new NotImplementedException();
+        }
+
+        public VertexMaterialDelta Subtract(IVertexMaterial baseValue)
+        {
+            throw new NotImplementedException();
+        }
+
+        public void Add(in VertexMaterialDelta delta)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}