KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 318 forks source link

Models deforming when converting from Blender to GLTF #2104

Open cgordon5025 opened 8 months ago

cgordon5025 commented 8 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to File>Export>GLTF
  2. Click on ExportToGLTF
  3. See error

Expected behavior When exporting my scene with animated models, I expect that the models retain their structure and integrity as I see it in the blender GUI.

Screenshots Expected Behavior (screenshot taken in Blender): Screenshot 2024-01-08 182344

Actual Behavior (screenshot taken in React Project): Screenshot 2024-01-08 182316

myProject.zip

Version

Additional context Add any other context about the problem here. I am using the polmandres GLTF to JSX converter to render this, when using their provided GLTF viewer (https://gltf.pmnd.rs/) the models looks correct, yet in the project they are warped. Further when I export within Blender, I see immediately that the Fox and Dog models have the same deformation that appear in the gltf file. If I click undo, they are 'fixed', but the gltf remains warped.

donmccurdy commented 8 months ago

To help us narrow this down, do you see the same issue when running gltfjsx with a higher precision? The default is 3 decimals precision in node position/rotation/scale, which could be an issue. There's an option for this in the gltfjsx GUI, or the --precision flag in the CLI. I think the CLI is generally more up-to-date than the web GUI.

Further when I export within Blender, I see immediately that the Fox and Dog models have the same deformation that appear in the gltf file...

I'm not sure I understood this part, do you mean you see the deformation in Blender after export, unrelated to gltfjsx? I'm testing in Blender 4.0 and not seeing the deformation there so far.

julienduroure commented 8 months ago

Seems your rigs are using BBone, that can not be exported in glTF. This can explain deformation issue in any glTF viewer.

Note that Blender now have the requested API to convert BBone to multiple bones. But the work still to be done to manage it correctly at export is huge, and not planned for now.

cgordon5025 commented 8 months ago

I'm not sure I understood this part, do you mean you see the deformation in Blender after export, unrelated to gltfjsx? I'm testing in Blender 4.0 and not seeing the deformation there so far. @donmccurdy

Thought I had resolved it by updating my blender to 4.0, things were working yesterday and now this morning it broke once again. Yes, both the gltf file and Blender have deformed bones after the export occurs. This morning I had to make a quick adjustment to the scene, and when I exported it once more the bones deformed again

cgordon5025 commented 8 months ago

Seems your rigs are using BBone, that can not be exported in glTF. This can explain deformation issue in any glTF viewer.

Note that Blender now have the requested API to convert BBone to multiple bones. But the work still to be done to manage it correctly at export is huge, and not planned for now. @julienduroure I used rigify to create the rig. I am fairly new to Blender. Is there any way I can remove/change this without restarting the rig? Or a way to convert it myself before exporting?

cgordon5025 commented 8 months ago

@julienduroure Another question, if it is the bendy bones why are the two other rigged models in this file work/retain their structure, while the two quadrupeds lose it?

julienduroure commented 8 months ago

If you want me to investigate more deeply, can you please create a new .blend file with only the dog and a single action for it, where we can see the deformation the best, and indicate what part is deformed.

As far as I can see, there is not so much BBone deformation on owl and crab (even if there is some BBones).

But there are for the dog (on the neck for example):

image

cgordon5025 commented 8 months ago

@julienduroure Sure I can provide that. What is odd, is that I made a demo version of this file with only one animal, and it exported without problem. I have since updated to Blender 4.0, but the issue is still persisting. I am noticing it is only the front paws of both the fox and dog (quadrupeds) that are affected, would changing the bone type for that segment resolve this, though in an unorthodox manner? DogCustomRig.zip

In the main file, where I see the deformation occur is on the front two paws on the joint just above the foot, identified as the foot_front_heel, in the model you can see its near perpendicular to the xy axis, but when I export to gltf it becomes more parallel to the xy axis.

This deformation occurs on the neutral pose of the models, so it affects every animation they use

julienduroure commented 8 months ago

Sorry, but I am not able to understand clearly what your problem is.

Is your blend file changed after export, or is the issue can be viewed in an external viewer? Please make some screenshots that show the issue.

Is it some bone/joint rotation issue, or the problem come from geometry/mesh issue? There is no "foot_front_heel" in your file. Do you mean "front_foot_heel_ik.R/L" ?

Does your DogCustomRig shows the issue, or only the main file myProject ?

cgordon5025 commented 8 months ago

@julienduroure my Blender file is changed after export AND the deformation is viewed in the final destination. When using a GLTF viewer (https://gltf.pmnd.rs/) the issue does not show itself.

It seems to be a bone rotation issue, that after executing the export front_foot_heel)ik.R/L changes its orientation. Because the rig is parent to the model, the model deforms due to the front_foot_heel_ik.R/L changing orientation/rotation.

CustomDogRig was showing no issues when I tried to export it. The issue is only in the main file (myProject)

Below are photos of the model in three different environments In blender (before exporting) inBlender

In GLTF Viewer

inGLTFViewer

In ReactProject and Blender after exporting inReactProject

julienduroure commented 8 months ago

Seems I am not able to reproduce

Before Export :

Pose image

Rest image

After Export:

image

Pose image

Rest image

In https://gltf.pmnd.rs/

image

In https://gltf-viewer.donmccurdy.com/

image

cgordon5025 commented 8 months ago

@julienduroure This is correct, however noce you convert this to jsx and using gltfjsx, you will see that the animations are all deformed. the strangest part is that the neutral poses are correct, but once you apply the animation it does not work any more.

Attached is the sandbox I have been using to test my animations in a React project

animation-sandbox.zip

donmccurdy commented 8 months ago

@cgordon5025 is it possible to observe the deformation in any of these viewers?

If not, I think it may be necessary to report an issue at https://github.com/pmndrs/gltfjsx/. This exporter aims to produce a valid and visually-correct glTF file. Generating a JSX template from that is an additional process with its own complexities.

cgordon5025 commented 8 months ago

@donmccurdy Yes, in the first link provided, https://gltf-viewer.donmccurdy.com/

You can see that the dog, when in idle/rest position that the legs are proper and not deformed, but when activating the animation, the rig becomes deformed

See attached video.

https://github.com/KhronosGroup/glTF-Blender-IO/assets/112432755/1b05ce65-858a-4856-9fd7-da8e14586d45

julienduroure commented 8 months ago

The legs are also with this shape in Blender before export , when using this action DogHeadNod

image

cgordon5025 commented 8 months ago

@julienduroure In my blender file they are not like that, let me send another playground.zip

I have noticed that if it is not deformed before exporting, it will become deformed, but then you are able to undo w/ control-z

julienduroure commented 8 months ago

I can reproduce with this new .blend file Investigation in progress

julienduroure commented 7 months ago

I opened a discussion here about the Blender API to reset bones to rest pose (that is root of the issue):

https://projects.blender.org/blender/blender/issues/118077

julienduroure commented 7 months ago

Some bones are locked and have non default values (MCH-front_foot_parent.L for example). During switch between actions, to avoid unexpected issue when some channels are keyed on an action, but not in another, we reset bone matrices. This reset make all matrices Identity. But because of non default locked bone, this is not the behavior we get when using Clear Transforms (alt+G/R/S).

You can workaround that (if all your channels are keyed) by disable this option: Reset Bones between actions

image