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

Bounding box for quantized models computed incorrectly? #2450

Closed
donmccurdy opened this issue Jun 2, 2021 · 6 comments · Fixed by #2463
Closed

Bounding box for quantized models computed incorrectly? #2450

donmccurdy opened this issue Jun 2, 2021 · 6 comments · Fixed by #2463
Labels
type: bug Something isn't working

Comments

@donmccurdy
Copy link
Contributor

Description

In three.js r128 a fix was added to compute the correct bounding boxes for quantized models (mrdoob/three.js#21554). That fix is working in my viewer now (https://gltf-viewer.donmccurdy.com/) but for some reason the latest version of model-viewer still does not center models using quantized position attributes.

The effect of the incorrect bounding box is that the model is not visible at all.

Live Demo

export-v1.glb.zip

Compare:

Version

  • model-viewer: v1.7.2
@ghost
Copy link

ghost commented Jun 2, 2021 via email

ghost pushed a commit that referenced this issue Jun 8, 2021
@ghost ghost closed this as completed in #2463 Jun 10, 2021
ghost pushed a commit that referenced this issue Jun 10, 2021
* Fixes issue with framing a quantized GLTF

fixes #2450

* removed normalized check
@donmccurdy
Copy link
Contributor Author

I'm seeing a very similar issue with models using skinning:

Archive.zip

The archive has a .base.glb and .quantize-hi.glb version, the latter is quantized. The quantization transform is applied to the skinned mesh's inverse bind matrices, so the root cause here is probably mrdoob/three.js#14499 if you're using three.js' new Box3().setFromObject(...) ... if model-viewer uses some other method to compute the bounding box, it may be worth looking into including inverse bind matrices in that.

original quantized
Screen Shot 2021-08-19 at 9 47 44 PM Screen Shot 2021-08-19 at 9 47 45 PM

@elalish
Copy link
Collaborator

elalish commented Aug 20, 2021

In fact we do use our own function: https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/ModelUtils.ts#L60, so that we can also compute a bounding frustum. I've been meaning to contribute this back to three.js, but haven't gotten around to it. Do you have any thoughts on the right way to fix this?

@elalish elalish reopened this Aug 20, 2021
@elalish elalish added the type: bug Something isn't working label Aug 20, 2021
@ghost ghost self-assigned this Sep 2, 2021
@elalish
Copy link
Collaborator

elalish commented Apr 5, 2022

@donmccurdy So, we recently fixed the issue with skinned meshes and their bind poses and your original model works just fine, but both of your CesiumMan models in your zip still fail. I don't really understand why: even without quantization, I'm getting bone transforms with huge weights (like 22) that send the vertices way off and I end up with a bounding box hundreds of meters on a side. I'm trying to upstream my bounding function (since three.js doesn't have a good way to calculate skinned mesh bounds at all right now), but I'd like to make sure I'm doing it right.

I'm also curious if the quantization scaling should be applied before or after the bone transforms? I can't check with these models, because they don't work even when the scale is 1.

@elalish
Copy link
Collaborator

elalish commented Apr 5, 2022

@donmccurdy Upon further inspection, it appears your version of CesiumMan is an invalid glTF (since fixed in the repo), as it has bone weights of x: 44, y: 164, z: 34, w: 13, which certainly don't sum to 1: KhronosGroup/glTF#1352

Interestingly, it also doesn't fail the validator. On the other hand, it seems three.js normalizes the weights in its shaders, but not in its CPU code, hence the bug. Perhaps that should be fixed regardless?

@elalish
Copy link
Collaborator

elalish commented Jul 29, 2022

This is mostly fixed and we have some similar open issues anyway.

@elalish elalish closed this as completed Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants