summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2018-08-06 18:41:37 -0300
committerJuan Linietsky <reduzio@gmail.com>2018-08-06 18:41:37 -0300
commit00c573c255d0fcae926dd2fe2a10991c7ad76cd9 (patch)
tree27906fb5bcc1d0c4205edfc7cb15a73da0c2f088
parentedde52c8dea0193111239b6b2f002adcc24ac0c9 (diff)
Several fixes to GLTF2 importer
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp29
-rw-r--r--editor/import/editor_scene_importer_gltf.h1
2 files changed, 13 insertions, 17 deletions
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index 7cfaa9070f..b1c0c7bf0a 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -203,7 +203,6 @@ Error EditorSceneImporterGLTF::_parse_nodes(GLTFState &state) {
GLTFNode *node = memnew(GLTFNode);
Dictionary n = nodes[i];
- print_line("node " + itos(i) + ": " + String(Variant(n)));
if (n.has("name")) {
node->name = n["name"];
}
@@ -1686,20 +1685,22 @@ void EditorSceneImporterGLTF::_generate_node(GLTFState &state, int p_node, Node
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);
if (n->skin >= 0 && 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];
- state.paths_to_skeleton[mi] = s;
- //move it later, as skeleton may be moved around first
+ s->add_child(node); //According to spec, mesh should actually act as a child of the skeleton, as it inherits its transform
+ mi->set_skeleton_path(String(".."));
+
+ } else {
+ p_parent->add_child(node);
+ node->set_transform(n->xform);
}
+ node->set_owner(p_owner);
+
#if 0
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_index = s->find_bone(state.nodes[parent]->name);
- 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.write[i].godot_bone_index = bone_index;
@@ -2061,6 +2060,10 @@ Spatial *EditorSceneImporterGLTF::_generate_scene(GLTFState &state, int p_bake_f
if (name == "") {
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);
root->add_child(s);
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++) {
skeletons[i]->localize_rests();
}
diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h
index e8f3bdff62..8258ec41fd 100644
--- a/editor/import/editor_scene_importer_gltf.h
+++ b/editor/import/editor_scene_importer_gltf.h
@@ -275,7 +275,6 @@ class EditorSceneImporterGLTF : public EditorSceneImporter {
Vector<GLTFAnimation> animations;
Map<int, Vector<int> > skeleton_nodes;
- Map<Node *, Skeleton *> paths_to_skeleton;
//Map<int, Vector<int> > skin_users; //cache skin users