From 25ab612c5030b5a5696b22771b880e019cf9a0d8 Mon Sep 17 00:00:00 2001 From: Lyonich Date: Mon, 18 Nov 2024 14:54:34 +0800 Subject: [PATCH] fixed joints conversion from gltf to ozz: removed Armature nodes that not indexed in joints and vertex bone indices --- src/animation/offline/gltf/gltf2ozz.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/animation/offline/gltf/gltf2ozz.cc b/src/animation/offline/gltf/gltf2ozz.cc index 2fa4bc284..758df5a1e 100644 --- a/src/animation/offline/gltf/gltf2ozz.cc +++ b/src/animation/offline/gltf/gltf2ozz.cc @@ -521,6 +521,17 @@ class GltfImporter : public ozz::animation::offline::OzzImporter { return success; } + static bool IsSkinJoint(const tinygltf::Skin& skin, int node) { + static constexpr int invalid_node = -1; + static constexpr int visited = -2; + if (node == invalid_node || node == visited) return false; + + return std::any_of( + skin.joints.begin(), skin.joints.end(), + [&node](const int& joint) { return joint == node; } + ); + } + // Find all unique root joints of skeletons used by given skins and add them // to `roots` void FindSkinRootJointIndices(const ozz::vector& skins, @@ -546,7 +557,7 @@ class GltfImporter : public ozz::animation::offline::OzzImporter { } int root = skin.joints[0]; - while (root != visited && parents[root] != no_parent) { + while (IsSkinJoint(skin, parents[root])) { root = parents[root]; } if (root != visited) {