Several fixes to GLTF2 importer

This commit is contained in:
Juan Linietsky 2018-08-06 18:41:37 -03:00
parent edde52c8de
commit 00c573c255
2 changed files with 13 additions and 17 deletions

View File

@ -203,7 +203,6 @@ Error EditorSceneImporterGLTF::_parse_nodes(GLTFState &state) {
GLTFNode *node = memnew(GLTFNode); GLTFNode *node = memnew(GLTFNode);
Dictionary n = nodes[i]; Dictionary n = nodes[i];
print_line("node " + itos(i) + ": " + String(Variant(n)));
if (n.has("name")) { if (n.has("name")) {
node->name = n["name"]; node->name = n["name"];
} }
@ -1686,20 +1685,22 @@ void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node
node->set_name(n->name); node->set_name(n->name);
p_parent->add_child(node);
node->set_owner(p_owner);
node->set_transform(n->xform);
n->godot_nodes.push_back(node); n->godot_nodes.push_back(node);
if (n->skin >= 0 && Object::cast_to<MeshInstance>(node)) { if (n->skin >= 0 && Object::cast_to<MeshInstance>(node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(node); MeshInstance *mi = Object::cast_to<MeshInstance>(node);
//move skeleton around and place it on node, as the node _is_ a skeleton.
Skeleton *s = skeletons[n->skin]; Skeleton *s = skeletons[n->skin];
state.paths_to_skeleton[mi] = s; s->add_child(node); //According to spec, mesh should actually act as a child of the skeleton, as it inherits its transform
//move it later, as skeleton may be moved around first mi->set_skeleton_path(String(".."));
} else {
p_parent->add_child(node);
node->set_transform(n->xform);
} }
node->set_owner(p_owner);
#if 0 #if 0
for (int i = 0; i < n->skeleton_children.size(); i++) { for (int i = 0; i < n->skeleton_children.size(); i++) {
@ -1744,10 +1745,8 @@ void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vecto
const int parent = gltf_bone_node->parent; const int parent = gltf_bone_node->parent;
const int parent_index = s->find_bone(state.nodes[parent]->name); const int parent_index = s->find_bone(state.nodes[parent]->name);
s->add_bone(bone_name);
const int bone_index = s->find_bone(bone_name); const int bone_index = s->find_bone(bone_name);
s->set_bone_parent(bone_index, parent_index); 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->godot_nodes.push_back(s);
n->joints.write[i].godot_bone_index = bone_index; n->joints.write[i].godot_bone_index = bone_index;
@ -2061,6 +2060,10 @@ Spatial *EditorSceneImporterGLTF::_generate_scene(GLTFState &state, int p_bake_f
if (name == "") { if (name == "") {
name = _gen_unique_name(state, "Skeleton"); name = _gen_unique_name(state, "Skeleton");
} }
for (int j = 0; j < state.skins[i].bones.size(); j++) {
s->add_bone(state.nodes[state.skins[i].bones[j].node]->name);
s->set_bone_rest(j, state.skins[i].bones[j].inverse_bind.affine_inverse());
}
s->set_name(name); s->set_name(name);
root->add_child(s); root->add_child(s);
s->set_owner(root); s->set_owner(root);
@ -2074,12 +2077,6 @@ Spatial *EditorSceneImporterGLTF::_generate_scene(GLTFState &state, int p_bake_f
} }
} }
for (Map<Node *, Skeleton *>::Element *E = state.paths_to_skeleton.front(); E; E = E->next()) {
MeshInstance *mi = Object::cast_to<MeshInstance>(E->key());
ERR_CONTINUE(!mi);
mi->set_skeleton_path(mi->get_path_to(E->get()));
}
for (int i = 0; i < skeletons.size(); i++) { for (int i = 0; i < skeletons.size(); i++) {
skeletons[i]->localize_rests(); skeletons[i]->localize_rests();
} }

View File

@ -275,7 +275,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter {
Vector<GLTFAnimation> animations; Vector<GLTFAnimation> animations;
Map<int, Vector<int> > skeleton_nodes; Map<int, Vector<int> > skeleton_nodes;
Map<Node *, Skeleton *> paths_to_skeleton;
//Map<int, Vector<int> > skin_users; //cache skin users //Map<int, Vector<int> > skin_users; //cache skin users