pmndrs / drei

🥉 useful helpers for react-three-fiber
https://docs.pmnd.rs/drei
MIT License
8.18k stars 668 forks source link

Bounds Ignores Group Scale #2027

Open AndrewJSchoen opened 1 month ago

AndrewJSchoen commented 1 month ago

Problem description:

When using the Bounds component, it incorrectly ignores scaling applied to group objects (and possibly others). This applies to especially to cases where the group is scaled by reference. This results in a mismatch from the expected bounds, based on what you see in the visual.

Screenshot 2024-07-11 at 11 41 15 AM

Relevant code:

https://codesandbox.io/p/devbox/bounds-gltf-y7g9xc



### Suggested solution:

Not sure, but it does seem like this is consistent regardless of whether the scale is applied via props (if dynamic), or whether they are applied to the Three object directly by ref in `useFrame`. I have also tried manually triggering the `fit` and `clip` functions some time after loading, but this doesn't seem to make a difference.
drcmda commented 1 month ago

it does seem to center the model correctly in the demo you made? it seems to me you expect the component with the red wireframe to re-render because you called bounds.refresh().clip().fit() but that call won't trigger any state updates, it merely refreshes internals and starts cam transforms essentially bounds works, the component shows the old bounds because it doesn't re-render