godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.08k stars 21.18k forks source link

Import GLTF curves physical skeleton not exact place #39757

Closed Darkinggq closed 2 years ago

Darkinggq commented 4 years ago

Godot version: v3.2.1stable/v3.2.2rc2

OS/device including version: Debian 10.4

Issue description: Blender 2.83 export import format GLTF/DAE problem miscellaneous left or right 2020-06-22_17-29

already tried godot 3.2.1stable and 3.2.2rc2 anyway it's useless who hasn't fixed physical bones

blender 2.83 the original modeling + skeletons image

Minimal reproduction project: _cloth_phys.blend.zip only blender 2.83

Darkinggq commented 4 years ago

test model took from youtube tutorial https://www.youtube.com/watch?v=mdyRO8_q7lI

xtremezero commented 4 years ago

This is an issue with the mesh it self

The mesh transformations were not applied before exporting 👌

However, it's true that GLTF importer in godot has an issue with identifying bones orientation when creating physical bones

fire commented 4 years ago

_cloth_phys.blend.zip

I can create a fixed version of this.

Using the gltf2 on 3.2 and the blender option set to "fortune".

Screen Shot 2020-06-24 at 1 38 40 AM

Darkinggq commented 4 years ago

this i made the result useless nothing has changed physical bones

2020-06-24_17-15

fire commented 4 years ago

I'm not able to dig deeply into [to] find the cause today. However, I can post the scene for my variation if it can help.

editor_screenshot_2020-06-24T080517-0700

I can confirm it fails for rc2.

fire commented 4 years ago

Are you able to retest on latest stable?

Blackiris commented 3 years ago

Still reproducible in Godot 3.2.4 beta 4

Blackiris commented 3 years ago

From what I understand, this issue could be from 2 different causes: error from the Create physical skeleton code, or error from the GLTF (parsing, or export from Blender). Given that GLTF seems to work well for animation, I have looked at the first cause.

In skeleton_editor_plugin.cpp, the code is assuming the bone direction is pointing to -Z, hence the physical bone body offset to put it in the middle:

body_transform.origin = Vector3(0, 0, -half_height);

But, when using GLTF model, it could point to completely another direction By setting the body offset using the bone rest vector instead, it partially fixes the issue:

Vector3 bone_rest_origin = skeleton->get_bone_rest(bone_child_id).origin;
body_transform.origin = bone_rest_origin * 0.5;

bone_origin_ok_dir_ko

However, the physical bone rotation is not set along the bone, and for this, I had to use:

body_transform = body_transform.looking_at(Vector3(0, 0, 0), Vector3(0, 0, 1));

bone_origin_ok_dir_ok

It is my first look at Godot's code so I don't know if it is the proper way to do the rotation...

Blackiris commented 3 years ago

It was not a good idea to rotate the physical bones since it creates issues with the physic engine. Instead, rotation the collision shape is much safer.

Blackiris commented 3 years ago

I have just created a PR for the Godot 4.0 version #48310. Please find here a reproduction project for Godot 4.0 containing 3 models, using DAE and GLTF (total 6 cases):

testSkeleton-godot4-0.zip

Just open one of the 6 scene, select the skeleton and click on Create physical skeleton.

akien-mga commented 2 years ago

Fixed by #48310.