diff options
author | Daniel Rakos <daniel.rakos@rastergrid.com> | 2019-03-11 15:53:53 +0100 |
---|---|---|
committer | Daniel Rakos <daniel.rakos@rastergrid.com> | 2019-03-11 16:26:45 +0100 |
commit | 1cf7ca87cebb0a07733ffe65a50e8f9b0e68b25a (patch) | |
tree | a73539e0166d6b0d987a5e5af4abac92191acb04 /editor | |
parent | 0deb3921e378178f04e9a185aa040a84fc9254e8 (diff) |
Fix skeleton reparenting to also work when the skeleton node is not a bone
Existing code only did the reparenting when the parent node was a bone. This
change fixes that, plus the reparenting code itself, which used the index of
the skin instead of the skin index itself to address the skeleton array.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/import/editor_scene_importer_gltf.cpp | 33 | ||||
-rw-r--r-- | editor/import/editor_scene_importer_gltf.h | 1 |
2 files changed, 22 insertions, 12 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 7032146229..090277d414 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1698,6 +1698,22 @@ void EditorSceneImporterGLTF::_assign_scene_names(GLTFState &state) { } } +void EditorSceneImporterGLTF::_reparent_skeleton(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, Node *p_parent_node) { + //reparent skeletons to proper place + Vector<int> nodes = state.skeleton_nodes[p_node]; + for (int i = 0; i < nodes.size(); i++) { + Skeleton *skeleton = skeletons[nodes[i]]; + Node *owner = skeleton->get_owner(); + skeleton->get_parent()->remove_child(skeleton); + p_parent_node->add_child(skeleton); + skeleton->set_owner(owner); + //may have meshes as children, set owner in them too + for (int j = 0; j < skeleton->get_child_count(); j++) { + skeleton->get_child(j)->set_owner(owner); + } + } +} + void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node *p_parent, Node *p_owner, Vector<Skeleton *> &skeletons) { ERR_FAIL_INDEX(p_node, state.nodes.size()); @@ -1769,24 +1785,17 @@ void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node _generate_node(state, n->children[i], node, p_owner, skeletons); } } + + if (state.skeleton_nodes.has(p_node)) { + _reparent_skeleton(state, p_node, skeletons, node); + } } void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, Node *p_parent_node) { ERR_FAIL_INDEX(p_node, state.nodes.size()); if (state.skeleton_nodes.has(p_node)) { - //reparent skeletons to proper place - Vector<int> nodes = state.skeleton_nodes[p_node]; - for (int i = 0; i < nodes.size(); i++) { - Node *owner = skeletons[i]->get_owner(); - skeletons[i]->get_parent()->remove_child(skeletons[i]); - p_parent_node->add_child(skeletons[i]); - skeletons[i]->set_owner(owner); - //may have meshes as children, set owner in them too - for (int j = 0; j < skeletons[i]->get_child_count(); j++) { - skeletons[i]->get_child(j)->set_owner(owner); - } - } + _reparent_skeleton(state, p_node, skeletons, p_parent_node); } GLTFNode *n = state.nodes[p_node]; diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h index 0dff45abaf..ebf20e122a 100644 --- a/editor/import/editor_scene_importer_gltf.h +++ b/editor/import/editor_scene_importer_gltf.h @@ -310,6 +310,7 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { Vector<Basis> _decode_accessor_as_basis(GLTFState &state, int p_accessor, bool p_for_vertex); Vector<Transform> _decode_accessor_as_xform(GLTFState &state, int p_accessor, bool p_for_vertex); + void _reparent_skeleton(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, Node *p_parent_node); void _generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, Node *p_parent_node); void _generate_node(GLTFState &state, int p_node, Node *p_parent, Node *p_owner, Vector<Skeleton *> &skeletons); void _import_animation(GLTFState &state, AnimationPlayer *ap, int index, int bake_fps, Vector<Skeleton *> skeletons); |