@@ -234,27 +234,23 @@ void SkinnedMesh::calculateGlobalMatrices(std::vector<core::matrix4> &matrices)
234234 }
235235}
236236
237- bool SkinnedMesh::checkForAnimation () const
237+ bool SkinnedMesh::checkForWeights () const
238238{
239- for (auto *joint : AllJoints) {
240- if (!joint->keys .empty ()) {
241- return true ;
242- }
243- }
244-
245- // meshes with weights are animatable
246- for (auto *buf : LocalBuffers) {
247- if (buf->getWeights ()) {
248- return true ;
249- }
250- }
239+ return std::any_of (LocalBuffers.begin (), LocalBuffers.end (),
240+ [](const auto *buf) { return buf->getWeights () != nullptr ; });
241+ }
251242
252- return false ;
243+ bool SkinnedMesh::checkForKeys () const
244+ {
245+ return std::any_of (AllJoints.begin (), AllJoints.end (),
246+ [](const auto *joint) { return !joint->keys .empty (); });
253247}
254248
255249void SkinnedMesh::prepareForSkinning ()
256250{
257- HasAnimation = checkForAnimation ();
251+ HasWeights = checkForWeights ();
252+ // Meshes with weights are animatable (e.g. with bone overrides)
253+ HasAnimation = HasWeights || checkForKeys ();
258254 if (!HasAnimation || PreparedForSkinning)
259255 return ;
260256
@@ -400,6 +396,17 @@ SkinnedMesh *SkinnedMeshBuilder::finalize() &&
400396 // (see e.g. SkinnedMesh::calculateGlobalMatrices)
401397 topoSortJoints ();
402398
399+ // Add all weights such that checkForWeights() works as expected
400+ for (const auto &weight : weights) {
401+ auto *buf = mesh->LocalBuffers .at (weight.buffer_id );
402+ auto *weights = buf->getWeights ();
403+ if (!weights) {
404+ buf->addWeightBuffer ();
405+ weights = buf->getWeights ();
406+ }
407+ weights->addWeight (weight.vertex_id , weight.joint_id , weight.strength );
408+ }
409+
403410 mesh->prepareForSkinning ();
404411
405412 std::vector<core::matrix4> matrices;
@@ -425,16 +432,6 @@ SkinnedMesh *SkinnedMeshBuilder::finalize() &&
425432 }
426433 }
427434
428- for (const auto &weight : weights) {
429- auto *buf = mesh->LocalBuffers .at (weight.buffer_id );
430- auto *weights = buf->getWeights ();
431- if (!weights) {
432- buf->addWeightBuffer ();
433- weights = buf->getWeights ();
434- }
435- weights->addWeight (weight.vertex_id , weight.joint_id , weight.strength );
436- }
437-
438435 for (auto *buffer : mesh->LocalBuffers ) {
439436 // With HW skinning, the VBOs should be static by default
440437 buffer->setHardwareMappingHint (EHM_STATIC);
0 commit comments