AwesomesauceLabs / piglet-viewer

Demo viewer app for Piglet glTF Importer
MIT License
6 stars 4 forks source link

Bug in correctly importing Fox and CesiumMan #1

Open dhawalbanker opened 3 years ago

dhawalbanker commented 3 years ago

Hello.. I was trying the WebGL demo and found that a few of the assets are not imported correctly. Distorted 3d object and (hence I guess) distored animations.

From the 2.0 Sample set, Fox and CesiumMan. Try .glb files. Attaching as well.

2.0.zip

AwesomesauceLabs commented 3 years ago

@dhawalbanker

Thanks for reporting this.

I saw a similar bug previously (explosion of triangles) with an animated model that a user shared privately. Not quite sure what is going on, but I suspect that there are certain cases where the translation from right-handed coords (glTF) to left-handed coords (Unity) is not handled correctly, i.e. linear algebra issues.

This is an important bug, but it may be a while before I can address this, since the math is quite tricky and I'm a bit overloaded with requests at the moment.

Attaching some screenshots, so I can more easily remind myself about the issue later:

Fox model in Microsoft 3D Viewer (correct):

fox-ms-3d-viewer

Fox model in Piglet WebGL Demo (wrong):

fox-piglet-webgl

benvvalk commented 2 years ago

Apologies for neglecting this issue.

I understand the problem better now, and since another user was asking about this issue today, I thought I would post some additional information here.

Most of the time, this kind of "exploding model" problem is caused because the bones-per-vertex setting (a.k.a. "Blend Weights") is set too low (e.g. 2 instead of 4). The option is found under Edit -> Project Settings... -> Quality -> Blend Weights, as shown in the screenshot below.

To determine if the "Blend Weights" is the cause of your problem, you should manually select each quality level and set "Blend Weights" to the maximum possible value of "4 Bones".

blend-weights

benvvalk commented 2 years ago

Adjusting the "Blend Weights" setting fixes the problem for the CesiumMan model, and PigletViewer is now hardcoded to use a Blend Weights setting of "4 Bones":

https://github.com/AwesomesauceLabs/piglet-viewer/blob/bff6235a368beb0270c479223885ee6c60b0331e/Assets/PigletViewer/Scripts/WebGL/WebGlGameManager.cs#L40-L48

However, in the particular case of the fox model, just increasing the "Blend Weights" setting does not solve the problem. It seems that the fox glTF file has some unique quirks/issues that Piglet does not handle correctly.

So far, I haven't invested much time into debugging the fox model, since I've never encountered this type of problem with any other models.

Btw, there was recently an updated version of the fox model released, which fixed an issue with how the animation data was encoded, as described in https://github.com/KhronosGroup/glTF-Sample-Models/pull/344. However, even after that fix, the model still explodes in the Piglet web demo.

Interestingly, if I download the fox model from Sketchfab instead, the problem is solved. So if I ever decide to spend further time debugging this model, comparing the GitHub and Sketchfab versions might be helpful.