Browse Source

add a guard for FeatureID attribute custom vertex

Bert Temme 2 years ago
parent
commit
a4e5c3cca0
1 changed files with 9 additions and 0 deletions
  1. 9 0
      src/SharpGLTF.Cesium/Schema2/MeshExtMeshFeatures.cs

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

@@ -1,4 +1,5 @@
 using SharpGLTF.Validation;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 
@@ -77,6 +78,14 @@ namespace SharpGLTF.Schema2
         {
             if (list == null) { primitive.RemoveExtensions<MeshExtMeshFeatures>(); return; }
 
+            // Guard that the custom vertex attribute (_FEATURE_ID_{attribute}) exists when FeatureID has attribute set
+            foreach (var item in list) {
+                if (item.Attribute.HasValue) {
+                    var expectedVertexAttribute = $"_FEATURE_ID_{item.Attribute}";
+                    Guard.NotNull(primitive.GetVertexAccessor(expectedVertexAttribute), expectedVertexAttribute);
+                }
+            };
+
             var ext = primitive.UseExtension<MeshExtMeshFeatures>();
             ext.FeatureIds = list;
         }