Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gltf importer doesn't import skeleton(s) correctly #15181

Closed
1 task
fire opened this issue Dec 29, 2017 · 24 comments
Closed
1 task

Gltf importer doesn't import skeleton(s) correctly #15181

fire opened this issue Dec 29, 2017 · 24 comments

Comments

@fire
Copy link
Member

fire commented Dec 29, 2017

Godot version:
Patched version of 99960d9

OS/device including version:
gtx 1080. I don't think driver versions are related.

Issue description:
Gltf2 skeletons don't import correctly. It also breaks my gltf2fbx workflow.

License: Creative Commons Attribution
stepladder.zip

TheDrone (https://sketchfab.com/thedrone)

https://sketchfab.com/models/7ece1ee1b602436dbcfb77e4f58ba8e5# (See the animation playback online)

Steps to reproduce:

  1. Import gltf2 by placing in a folder inside of the project
  2. Play the animation. See that is is scaled incorrectly.
  3. godot windows opt tools 64_2017-12-29_15-53-24
  • I searched the existing GitHub issues for potential duplicates.
@fire
Copy link
Member Author

fire commented Dec 29, 2017

  1. Even if you scale the entire root to .01 xyz. The skeleton is incorrect.

@fire
Copy link
Member Author

fire commented Dec 30, 2017

@fire
Copy link
Member Author

fire commented Jan 5, 2018

Trialing a8a3d5c

@fire
Copy link
Member Author

fire commented Jan 5, 2018

https://www.youtube.com/watch?v=_OWce6kJRJ0 I had to rescale xyz to 0.1 and have a 90 deg rotation, but the bones animation seems correct.

@fire
Copy link
Member Author

fire commented Mar 22, 2018

@RandomShaper https://github.com/KhronosGroup/glTF-Blender-Exporter/tree/master/polly This model fails to be imported in gltf2. Reduz said to ping you.

To see the failure, play the animation.

@fire
Copy link
Member Author

fire commented Mar 22, 2018

@reduz Seems to be related to KhronosGroup/glTF-Sample-Models#83 (comment)

@fire
Copy link
Member Author

fire commented Apr 4, 2018

Here's a sample project.
Test Gltf2.zip

It is based on mrdoob/three.js#11644

https://i.imgur.com/o6cg6oq.png

@RandomShaper
Copy link
Member

I'm investigating skeleton issues. At this point I have a solid clue to follow.

@fire
Copy link
Member Author

fire commented Apr 4, 2018

--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -1723,6 +1723,9 @@ void EditorSceneImporterGLTF::_generate_bone(GLTFState &state, int p_node, Vecto
 			skeletons[i]->get_parent()->remove_child(skeletons[i]);
 			p_parent_node->add_child(skeletons[i]);
 			skeletons[i]->set_owner(owner);
+			Transform parent_inverse = Object::cast_to<Spatial>(skeletons[i]->get_parent())->get_transform().affine_inverse();
+			Skeleton *skeleton = Object::cast_to<Skeleton>(skeletons[i]);
+			skeleton->set_transform(skeleton->get_transform() * parent_inverse);
 		}		
 	}

I noticed that doing this for the above Test Gltf2 project it gives the correct animation. Although the entire scene is shrunk by 100.

+			Transform parent_inverse = Object::cast_to<Spatial>(skeletons[i]->get_parent())->get_transform().affine_inverse(); 

This line should be getting the parent's global transform but I ran into a problem getting it.

Hope this helps.

@fire
Copy link
Member Author

fire commented Apr 4, 2018

https://drive.google.com/a/chibifire.com/uc?id=1iS5JUv5SkuMltYxtluWteBH7tgD6bWl_

This is the dae scene of the above project if it helps for comparison.

@fire
Copy link
Member Author

fire commented Apr 5, 2018

--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -2069,6 +2069,16 @@ 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);
+		for (int i = 0; i < skeletons.size(); i++) {
+			//get global transform
+			Spatial *node = Object::cast_to<Spatial>(skeletons[i]);
+			Transform global = Transform();
+			while (node != nullptr) {
+				global = global * Object::cast_to<Spatial>(node)->get_transform();
+				node = Object::cast_to<Spatial>(node->get_parent());
+			}
+			mi->set_transform(global);
+		}
 		mi->set_skeleton_path(mi->get_path_to(E->get()));
 	}

This code works for the above project and the ladder project on sketchfab. https://sketchfab.com/models/7ece1ee1b602436dbcfb77e4f58ba8e5#

The scale is a 100 on the sample project initially, but playing the anim shrinks the model.

@fire
Copy link
Member Author

fire commented Apr 5, 2018

--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -2069,6 +2069,13 @@ 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);
+		Spatial *node = Object::cast_to<Spatial>(E->value());
+		Transform global = Transform();
+		while (node != nullptr) {
+			global = global * Object::cast_to<Spatial>(node)->get_transform();
+			node = Object::cast_to<Spatial>(node->get_parent());
+		}
+		mi->set_transform(global);
 		mi->set_skeleton_path(mi->get_path_to(E->get()));
 	}
 

Better version of the code.

@RandomShaper
Copy link
Member

Could you try your solution with this one, please?
https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/RiggedFigure/glTF

@fire
Copy link
Member Author

fire commented Apr 5, 2018

It doesn't work. Note the gltf doesn't open in https://github.com/pissang/clay-viewer though.

@fire
Copy link
Member Author

fire commented Apr 5, 2018

Trying to take raw dae and reexporting it as gltf2. https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/sourceModels/RiggedFigure/RiggedFigure.dae

I tried opening the dae in modo and exporting it as gltf2. Noticed that the animations don't play in modo and the exported scene lacks anims.

I tried opening the dae in blender and hit animate. The animation played, but exporting as fbx and opening it in modo or clay viewer failed with animations.

@fire
Copy link
Member Author

fire commented Apr 5, 2018

@fire
Copy link
Member Author

fire commented Apr 5, 2018

No idea what is happening. Have to do something else now.

@RandomShaper
Copy link
Member

Thanks. So RiggedFigure doesn't work in Godot even with your patch. Am I right?

@fire
Copy link
Member Author

fire commented Apr 7, 2018

@RandomShaper Tried with EmaSimpleSkin.dae converted to gltf2 using modo.

https://i.imgur.com/JUvd5bz.png

Sample model was from mrdoob/three.js#11644

@RandomShaper
Copy link
Member

This issue hasn't changed after #18032, right?

@fire
Copy link
Member Author

fire commented Apr 10, 2018

Let me try it on master.

@fire
Copy link
Member Author

fire commented Apr 10, 2018

The skeleton is still scaled 100 times bigger and the animation is scaled 100 times smaller on ca1312d

@RandomShaper
Copy link
Member

Thanks. It was just to be sure there's still an issue to investigate.

@fire
Copy link
Member Author

fire commented Aug 7, 2018

Works as of 5b70ad9

@fire fire closed this as completed Aug 7, 2018
@akien-mga akien-mga added this to the 3.1 milestone Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants