pmndrs / use-cannon

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

Add deps param to useBody hooks (#119) #124

Closed patreeceeo closed 3 years ago

patreeceeo commented 4 years ago

This addresses #119.

I needed to be able to change the physics parameters of existing bodies in my scene, and couldn't figure out another way to do it. For instance, this change allows me to do:

export default (props) => {
  const [ref] = useSphere(() => ({
    position: [props.center.x, props.center.y, props.radius],
    velocity: props.velocity.direction, props.velocity.magnitude,
  }), null, [props.center, props.velocity]);
  return (
    <mesh ref={ref}>
      <sphereBufferGeometry args={[props.radius]} />
      <meshLambertMaterial />
    </mesh>
  )
}

and the position and velocity of the sphere rendered with this code will update whenever those props change.

nestarz commented 3 years ago

Would love to see this merged. Seems an easy fix to validate.

patreeceeo commented 3 years ago

Still hoping someone from Poimandres can comment, or merge if it's ready 🙏🏻

drcmda commented 3 years ago

sorry for the long wait