BabylonJS / Exporters

Exporters for Babylon.js and gltf file formats
Other
596 stars 308 forks source link

Mesh deformation #915

Open WollieWoltaz opened 3 years ago

WollieWoltaz commented 3 years ago

Hello,

I'm encountering some strange mesh deformation when exporting with the latest version of the glTF exporter for 3dsMax 2021. Only a specific part of the mesh get's deformed everything else seems to look good in the online sandbox babylon viewer. There are a couple of errors/warnings but i'm not sure what those mean...

Here are 2 examples of 2 different characters who encounter a similar issue. I included the .FBX and glTF format: (Link Deleted)

1st character animation comparison: 3dsMax 2021: https://user-images.githubusercontent.com/19957561/103104326-c30c5900-4626-11eb-922d-b85d42f03d69.mp4 glTF viewer: https://user-images.githubusercontent.com/19957561/103104338-d7e8ec80-4626-11eb-86e4-9b9bad92f80f.mp4

(The scroll that he holds in his hand is getting deformed)

2nd character animation comparison: 3dsMax 2021: https://user-images.githubusercontent.com/19957561/103104371-08308b00-4627-11eb-91e6-8bca1d51d0fb.mp4 glTF viewer: https://user-images.githubusercontent.com/19957561/103104379-141c4d00-4627-11eb-95e4-1a071c066386.mp4

(The tongue is getting deformed)

Is this something that can be fixed in the export script from 3dsMax to glTF/glb?

Regards,

WollieWoltaz commented 3 years ago

Sorry for bumping this topic but i'd really like to know why this happens and if i can fix this manually before exporting? Or is this something that can be fixed in the glTF exporter?

Regards,

pandaGaume commented 3 years ago

Sorry for the delay, we were working on another topic and had limited bandwidth. I took a look at the scene and it's quite a difficult issue to follow due to the "complexity" of the scene. Are you able to reproduce it if you isolate the tongue that is involved?

WollieWoltaz commented 3 years ago

No problem. Glad you respond now. Yes i can reproduce the deforming issue when isolating the tongue mesh. I exported in GLB and glTF format: https://mega.nz/folder/nNEh1SSR#uAxYtuDXfK8pqObU5yoaiQ Hope this scene is easier to follow Do you also need the exported .FBX file or?

Regards,

pandaGaume commented 3 years ago

I only need the Max file, this is my starting point for debug :-), so if you can send it to me that will be nice.

WollieWoltaz commented 3 years ago

Sure no problem: https://mega.nz/file/bUMxUCza#lHu8VOHzdq_AXTgaAYfcE60o0UUg7ANxkNsgn_GRcXM

Not sure if you needed the Max file with or without the tongue isolation... this Max file is without Could it be that while exporting as glTF or GLB that it's not exporting some scale transforms? Not sure though...

pandaGaume commented 3 years ago

I need the file with the tongue isolation :-)

WollieWoltaz commented 3 years ago

I hope this is what you meant: https://mega.nz/file/eBU1XCRR#YAiMbeo78MV9S0uSRLFEi1IMbsnyc8g07MBh8-qmB6U

pandaGaume commented 3 years ago

This is perfect. I will work on it this week and i will let you know if I find where this issue is located .

WollieWoltaz commented 3 years ago

Awesome. Will wait for your reply this week. Thanks in advance,

WollieWoltaz commented 3 years ago

I think so yes. It's not a character i made actually so i'm not entirely sure. I can say though that when i export this model as an FBX and import it into another tool i can see that only tongue5_SKN has his scale transform changed, it's not the default (1,1,1) anymore. I've tried setting the scale transform of that specific bone in the other tool to (1,1,1) but that didn't fixed the issue, because i think that only changing the scale transform is not enough because it also transforms to the animation keys. Because all keys under it will be affected: poskeys, scalekeys, and rotkeys. At least that's what I think but then again, i have no idea how to fix it in 3ds max.

pandaGaume commented 3 years ago

Did you try to lower the number of Skinning Weight per vertex on the tongue (4 instead of 5)? WebGL is currently limit the number of Skinning weight per vertex to 4, and the primary intend for the exporter was for Babylon JS format and WebGL player. It evolved to export GLTF in the wait of official Max GLTF plugin. I will search in this direction. If you can make a test with 4 weight that maybe could solve your issue and save you time.

WollieWoltaz commented 3 years ago

I have thought of that, the problem is I don't know how to do this correctly.. Could you share a little step-by-step tutorial?

pandaGaume commented 3 years ago

@bghgary do you have any idea on who can help @WollieWoltaz to test fixing the number of skinning weight ?

bghgary commented 3 years ago

WebGL is currently limit the number of Skinning weight per vertex to 4, and the primary intend for the exporter was for Babylon JS format and WebGL player.

Hmm, this isn't true. WebGL has no such limit. There are limits on the number of vertex attributes on various browsers/devices which may drive the limit for how many weights per vertex. Babylon.js supports up to 8 per vertex (2 sets). The glTF loader supports the same. The glTF spec itself requires that engines support at least one set (4 per vertex).

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#meshes

Client implementations must support ... one joints/weights set.

https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins

The number of joints that influence one vertex is limited to 4 per set

@pandaGaume Does the exporter support more than one set of joint indices/weights?

pandaGaume commented 3 years ago

8 is way better than 4... @bghgary thanks for the infos and correction. I'm currently investigate this idea, but this is the very first time i touch on this part of the code, so i may figure how it's act first, at max level, then babylon level, then gltf. Keep you posted.

pandaGaume commented 3 years ago

OK, first test show that with 5 weight influences with a weight matrix as

Capture

the second set is not define at babylon level (into the exported babylon file) "matricesWeightsExtra": null for the related mesh. I will investigate further but it's not obvious to figure where is going wrong.. :-) Update : it seem it's not the issue while the skin define no more than 4 influences per vertex..

pandaGaume commented 3 years ago

@bghgary tell the team to update https://doc.babylonjs.com/divingDeeper/mesh/bonesSkeletons where it's stated that "You should note that babylon.js supports up to 4 bones influences per vertex."

WollieWoltaz commented 3 years ago

"it seem it's not the issue while the skin define no more than 4 influences per vertex.." Did you find anything else then what may cause this effect? Someone told me that glTF does not support skew or shearing, and the transform matrices must be decomposable to translation, rotation and scale. Not sure if that's true though... just thought i should mention it here.

pandaGaume commented 3 years ago

@WollieWoltaz You send us two sample where this animation failed. However the second one has strange animation rendering under max. See the attachment. mechant.zip could you explain what happening here at the model level ?

pandaGaume commented 3 years ago

Regarding GLTF or Babylon, there is several matrices invloved. the base formula for each join is jointMatrix[j] = inverse(globalTransform) * globalJointTransform[j] * inverseBindMatrix[j] Then these matrices are conbine to create the skinning matrix (which transform the vertices based on the skeleton pose before 3D rendering pipeline), so this is not obvious to figure what going wrong with the numbers :-).

WollieWoltaz commented 3 years ago

Hmm that's strange, didn't had that issue before. How did this occur? Did you made some adjustments? If not.. then there's was probably something going wrong with the .fbx export Here is a new .max file of the same character, with the problematic mesh isolated... https://mega.nz/file/LFFjWKpD#GSLtjcwfaPFVxQG7u8Og92KZ4jI0ey8zJqgEtr8G2eM

pandaGaume commented 3 years ago

TahmKench_attack1.zip

bghgary commented 3 years ago

Using fbx2gltf, it seems to convert correctly. We can use this as reference.

TahmKench_attack1_out.zip

WollieWoltaz commented 3 years ago

Oh that's great news..hopefully you guys figure it out. In the meanwhile... could you give an exact example on how to use the cmd of FBX2glTF? I haven't worked with cmd in a while, so i'm now sure what i have to type in?

Thanks,

pandaGaume commented 3 years ago

non animated version bestioleBabylon.zip Animated version animatedBestioleBabylon.zip

bghgary commented 3 years ago

could you give an exact example on how to use the cmd of FBX2glTF?

fbx2gltf.exe <path to fbx>

:)

WollieWoltaz commented 3 years ago

Got it! Thanks this is a good work-around for now :)

WollieWoltaz commented 3 years ago

Any new information on why this issue occurs?

pandaGaume commented 3 years ago

@bghgary do we have an answer from Babylon JS team about this ?

bghgary commented 3 years ago

@pandaGaume I wasn't aware you were waiting on something. Are you talking about the docs?

pandaGaume commented 3 years ago

@bghgary during one of our review about this, we sent an exported scene with the bug embeded to analyse by babylon js team. It was about root transformation & skin totally wrong. My question was about this :-)