Limited joint/weight attributes to 4 sets 46/301046/1
authorDavid Steele <david.steele@samsung.com>
Mon, 6 Nov 2023 18:00:49 +0000 (18:00 +0000)
committerDavid Steele <david.steele@samsung.com>
Tue, 7 Nov 2023 13:51:23 +0000 (13:51 +0000)
Total number of supported joints per vertex = 16.

Change-Id: I4708382167d98f94b8d8f9fdf534972b85213c33

dali-scene3d/internal/loader/gltf2-util.cpp
dali-scene3d/public-api/loader/mesh-definition.cpp
dali-scene3d/public-api/loader/mesh-definition.h

index 8abb5bb4df25e5865d62746d2ed4c697c1bd51fa..c4e492f9c9ba3e3be58f3a43b78a415de88529a9 100644 (file)
@@ -816,14 +816,20 @@ MeshDefinition::Accessor* GetAccessorFromAttribute(gltf2::Attribute::HashType at
     }
     case gltf2::Attribute::JOINTS_N:
     {
-      meshDefinition.mJoints.emplace_back(MeshDefinition::Accessor{});
-      accessorDest = &meshDefinition.mJoints.back();
+      if(meshDefinition.mJoints.size() < MeshDefinition::MAX_NUMBER_OF_JOINT_SETS)
+      {
+        meshDefinition.mJoints.emplace_back(MeshDefinition::Accessor{});
+        accessorDest = &meshDefinition.mJoints.back();
+      }
       break;
     }
     case gltf2::Attribute::WEIGHTS_N:
     {
-      meshDefinition.mWeights.emplace_back(MeshDefinition::Accessor{});
-      accessorDest = &meshDefinition.mWeights.back();
+      if(meshDefinition.mWeights.size() < MeshDefinition::MAX_NUMBER_OF_JOINT_SETS)
+      {
+        meshDefinition.mWeights.emplace_back(MeshDefinition::Accessor{});
+        accessorDest = &meshDefinition.mWeights.back();
+      }
       break;
     }
     case gltf2::Attribute::INVALID:
index b7f8efcaa347578acdf6a35cb342aa394fe08b38..6b2feb6fa57b8ea844a9ba179e9ddc3407b5214b 100644 (file)
@@ -975,7 +975,12 @@ bool MeshDefinition::HasVertexColor() const
 
 uint32_t MeshDefinition::GetNumberOfJointSets() const
 {
-  return static_cast<uint32_t>(mJoints.size());
+  uint32_t number = static_cast<uint32_t>(mJoints.size());
+  if(number > MeshDefinition::MAX_NUMBER_OF_JOINT_SETS)
+  {
+    number = MeshDefinition::MAX_NUMBER_OF_JOINT_SETS;
+  }
+  return number;
 }
 
 bool MeshDefinition::HasBlendShapes() const
index 2c129c8aeec620b28b7f289c3b68f4394747c991..ec3e16028de89552b8fe425343e6a9afe0c2f699 100644 (file)
@@ -45,6 +45,11 @@ struct DALI_SCENE3D_API MeshDefinition
     INVALID = std::numeric_limits<uint32_t>::max()
   };
 
+  enum : uint32_t
+  {
+    MAX_NUMBER_OF_JOINT_SETS = 4
+  };
+
   enum Flags : uint32_t
   {
     FLIP_UVS_VERTICAL = NthBit(0),
@@ -270,6 +275,8 @@ struct DALI_SCENE3D_API MeshDefinition
 
   /**
    * @brief Returns the number of joint sets defined by the mesh
+   *
+   * @note Clamped to 4 to minimise GPU attrs.
    */
   uint32_t GetNumberOfJointSets() const;