pmndrs / use-cannon

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

can shapes work on the inside? #107

Open drcmda opened 4 years ago

drcmda commented 4 years ago

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?

codynova commented 4 years ago

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?

drcmda commented 4 years ago

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

codynova commented 4 years ago

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