Browse Source

trying to add color

Bert Temme 2 years ago
parent
commit
d58067b1c1

+ 4 - 4
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -26,6 +26,7 @@ namespace SharpGLTF.Cesium
             var material = new MaterialBuilder("material1").WithUnlitShader();
             var material = new MaterialBuilder("material1").WithUnlitShader();
             var mesh = new MeshBuilder<VertexPosition, VertexPointcloud, VertexEmpty>("mesh");
             var mesh = new MeshBuilder<VertexPosition, VertexPointcloud, VertexEmpty>("mesh");
             var pointCloud = mesh.UsePrimitive(material, 1);
             var pointCloud = mesh.UsePrimitive(material, 1);
+            var greenColor = new Vector4(0f, 1f, 0f, 1f);
 
 
             for (var x = -10; x < 10; x++)
             for (var x = -10; x < 10; x++)
             {
             {
@@ -33,7 +34,7 @@ namespace SharpGLTF.Cesium
                 {
                 {
                     for (var z = -10; z < 10; z++)
                     for (var z = -10; z < 10; z++)
                     {
                     {
-                        var vt0 = VertexBuilder.GetVertexPointcloud(new Vector3(x, y, z), 199, 4);
+                        var vt0 = VertexBuilder.GetVertexPointcloud(new Vector3(x, y, z), greenColor, 199, 4);
 
 
                         pointCloud.AddPoint(vt0);
                         pointCloud.AddPoint(vt0);
                     }
                     }
@@ -45,11 +46,10 @@ namespace SharpGLTF.Cesium
             // create a scene, a node, and assign the first mesh (the terrain)
             // create a scene, a node, and assign the first mesh (the terrain)
             model.UseScene("Default")
             model.UseScene("Default")
                 .CreateNode().WithMesh(model.LogicalMeshes[0]);
                 .CreateNode().WithMesh(model.LogicalMeshes[0]);
-
             var ctx = new ValidationResult(model, ValidationMode.Strict, true);
             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.glb");
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_prointcloud_attributes.gltf");
-            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_prointcloud_attributes.plotly");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.gltf");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.plotly");
         }
         }
 
 
 
 

+ 2 - 3
tests/SharpGLTF.Cesium.Tests/VertexBuilder.cs

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

+ 8 - 2
tests/SharpGLTF.Cesium.Tests/VertexPointcloud.cs

@@ -10,8 +10,10 @@ namespace SharpGLTF
     [System.Diagnostics.DebuggerDisplay("𝐂:{Color} 𝐔𝐕:{TexCoord}")]
     [System.Diagnostics.DebuggerDisplay("𝐂:{Color} 𝐔𝐕:{TexCoord}")]
     public struct VertexPointcloud : IVertexCustom
     public struct VertexPointcloud : IVertexCustom
     {
     {
-        public VertexPointcloud(float intensity, float classification)
+        public VertexPointcloud(Vector4 color, float intensity, float classification)
         {
         {
+            // Q: How to set the color??
+            Color = color;
             Intensity = intensity;
             Intensity = intensity;
             Classification = classification;
             Classification = classification;
         }
         }
@@ -19,6 +21,9 @@ namespace SharpGLTF
         public const string INTENSITYATTRIBUTENAME = "_INTENSITY";
         public const string INTENSITYATTRIBUTENAME = "_INTENSITY";
         public const string CLASSIFICATIONATTRIBUTENAME = "_CLASSIFICATION";
         public const string CLASSIFICATIONATTRIBUTENAME = "_CLASSIFICATION";
 
 
+        [VertexAttribute("COLOR_0", EncodingType.UNSIGNED_BYTE, true)]
+        public Vector4 Color;
+
         [VertexAttribute(INTENSITYATTRIBUTENAME, EncodingType.FLOAT, false)]
         [VertexAttribute(INTENSITYATTRIBUTENAME, EncodingType.FLOAT, false)]
         public float Intensity;
         public float Intensity;
         
         
@@ -31,7 +36,8 @@ namespace SharpGLTF
 
 
         public IEnumerable<string> CustomAttributes => throw new NotImplementedException();
         public IEnumerable<string> CustomAttributes => throw new NotImplementedException();
 
 
-        public void SetColor(int setIndex, Vector4 color) {
+        void IVertexMaterial.SetColor(int setIndex, Vector4 color) {
+            if (setIndex == 0) this.Color = color;
         }
         }
 
 
         public void SetTexCoord(int setIndex, Vector2 coord) { }
         public void SetTexCoord(int setIndex, Vector2 coord) { }