use-cannon icon indicating copy to clipboard operation
use-cannon copied to clipboard

can shapes work on the inside?

Open drcmda opened this issue 5 years ago • 3 comments
trafficstars

this demo: https://codesandbox.io/s/r3f-ibl-envmap-simple-6ebrr?file=/src/App.js:1025-1561 realizes the pill-box using 6 infinite planes:

  const [ref, api] = useCompoundBody(() => ({
    shapes: [
      { type: 'Plane', position: [0, -1.8, 0], rotation: [-Math.PI / 2, 0, 0] },
      { type: 'Plane', position: [0, 1.8, 0], rotation: [Math.PI / 2, 0, 0] },
      { type: 'Plane', position: [-0.8, 0, 0], rotation: [0, Math.PI / 2, 0] },
      { type: 'Plane', position: [0.8, 0, 0], rotation: [0, -Math.PI / 2, 0] },
      { type: 'Plane', position: [0, 0, -0.8], rotation: [0, 0, 0] },
      { type: 'Plane', position: [0, 0, 0.8], rotation: [0, -Math.PI, 0] }
    ]
  }))

which is ineffective, messy to write, and it wouldn't work if there's supposed to be physics outside of it. couldn't i just write

  const [ref, api] = useBox(...)

and dump the spheres inside? i haven't tried, i just assumed i couldn't possibly work, but would this be feasible for any situation where you want some kind of container?

drcmda avatar Aug 09 '20 06:08 drcmda

This shouldn't work, as shapes that aren't planes should be treated as solid objects by the simulation - this is why boxes tend to be better than planes for faster collisions. However I guess you could write a usePhysicsContainer helper hook or something and give it a geometry, and let it construct the planes?

codynova avatar Aug 09 '20 06:08 codynova

or a flag that inverts the geometry? would that be hard to realize in cannon?

drcmda avatar Aug 09 '20 06:08 drcmda

Unfortunately I imagine that would be very difficult, especially since we'd need to allow passing the flag on a per-Body basis

codynova avatar Aug 09 '20 15:08 codynova