pmndrs / use-cannon

👋💣 physics based hooks for @react-three/fiber
https://cannon.pmnd.rs
2.76k stars 155 forks source link

Scale of InstancedMesh is overwritten #367

Closed krispya closed 2 years ago

krispya commented 2 years ago

If a scale is applied to an instanced mesh before use-cannon touches it, use-cannon will overwrite it back to [1, 1, 1].

Here is a simple sandbox example: https://codesandbox.io/s/use-cannon-debug-instance-example-forked-yi6m2y?file=/src/App.js

bjornstar commented 2 years ago

I don't really understand what's going on here. You change the scale of the three object, but don't change the scale of the physics object. How is this supposed to work? It's still going to be the original scale in the physics engine and it won't match the scale of the three object.

krispya commented 2 years ago

The base use case I have is a gltf that I need to scale down to have it fit in my scene and match the physics body I have defined. This scale gets wiped out by use-cannon currently leaving me with no tools to fit my gltf InstancedMeshes in my scene other than to resize them in Blender and reexport them. Another use case I have is sometimes scaling an InstancedMesh is part of a visual effect I have that I don't want to affect the physics body. For instance, I scale a mesh down to have it "disappear" and then once it is gone I clean up the physics body. This is also impossible currently.

Although you are right, I should enhance the example to actually adjust the physics bodies to match the intended mesh scales. I got lazy. :)