Bones are now named and their parents are correct.

(cherry picked from commit ac541f5d16)
This commit is contained in:
K. S. Ernest (iFire) Lee 2018-07-24 14:49:34 -07:00 committed by Rémi Verschelde
parent 005d1c8901
commit ff35310650
2 changed files with 16 additions and 18 deletions

View File

@ -1708,14 +1708,14 @@ void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node
#endif
for (int i = 0; i < n->children.size(); i++) {
if (state.nodes[n->children[i]]->joints.size()) {
_generate_bone(state, n->children[i], skeletons, Vector<int>(), node);
_generate_bone(state, n->children[i], skeletons, node);
} else {
_generate_node(state, n->children[i], node, p_owner, skeletons);
}
}
}
void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, const Vector<int> &p_parent_bones, Node *p_parent_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)) {
@ -1730,30 +1730,28 @@ void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vecto
}
GLTFNode *n = state.nodes[p_node];
Vector<int> parent_bones;
for (int i = 0; i < n->joints.size(); i++) {
ERR_FAIL_COND(n->joints[i].skin < 0);
const int skin = n->joints[i].skin;
ERR_FAIL_COND(skin < 0);
int bone_index = n->joints[i].bone;
Skeleton *s = skeletons[skin];
const GLTFNode *gltf_bone_node = state.nodes[state.skins[skin].bones[n->joints[i].bone].node];
const String bone_name = gltf_bone_node->name;
const int parent = gltf_bone_node->parent;
const int parent_index = s->find_bone(state.nodes[parent]->name);
Skeleton *s = skeletons[n->joints[i].skin];
while (s->get_bone_count() <= bone_index) {
s->add_bone("Bone " + itos(s->get_bone_count()));
}
if (p_parent_bones.size()) {
s->set_bone_parent(bone_index, p_parent_bones[i]);
}
s->set_bone_rest(bone_index, state.skins[n->joints[i].skin].bones[n->joints[i].bone].inverse_bind.affine_inverse());
s->add_bone(bone_name);
const int bone_index = s->find_bone(bone_name);
s->set_bone_parent(bone_index, parent_index);
s->set_bone_rest(bone_index, state.skins[skin].bones[n->joints[i].bone].inverse_bind.affine_inverse());
n->godot_nodes.push_back(s);
n->joints[i].godot_bone_index = bone_index;
parent_bones.push_back(bone_index);
}
for (int i = 0; i < n->children.size(); i++) {
_generate_bone(state, n->children[i], skeletons, parent_bones, p_parent_node);
_generate_bone(state, n->children[i], skeletons, p_parent_node);
}
}
@ -2068,7 +2066,7 @@ Spatial *EditorSceneImporterGLTF::_generate_scene(GLTFState &state, int p_bake_f
}
for (int i = 0; i < state.root_nodes.size(); i++) {
if (state.nodes[state.root_nodes[i]]->joints.size()) {
_generate_bone(state, state.root_nodes[i], skeletons, Vector<int>(), root);
_generate_bone(state, state.root_nodes[i], skeletons, root);
} else {
_generate_node(state, state.root_nodes[i], root, root, skeletons);
}

View File

@ -311,7 +311,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 _generate_bone(GLTFState &state, int p_node, Vector<Skeleton *> &skeletons, const Vector<int> &p_parent_bones, 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);