pmndrs/use-cannon

Can't pass instanced bodies to useConstraint

Open

#50 geöffnet am 28. März 2020

Auf GitHub ansehen
 (0 Kommentare) (1 Reaktion) (0 zugewiesene Personen)TypeScript (164 Forks)github user discovery
enhancementhelp wanted

Repository-Metriken

Stars
 (2.950 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Creating constraints between instanced meshes isn't possible at the moment.

From #48 @drcmda

we could maybe learn from react-springs playbook here, esp useSprings: https://www.react-spring.io/docs/hooks/use-springs

const [refs, api] = useDistanceConstraints(10000, () => ({ ... }))
return data.map((id, index) => <mesh key={id} ref={refs[index]} ... />

I think this would be a good pattern for constraints on instanced bodies. An iterator function that returns an array of two indexes could attach a standard mesh to instanced meshes or instanced mesh to instanced mesh.

const [bodyA] = useBox({...})
const [bodyB] = useSphere({...}) // ref for instancedMesh

useDistanceConstraints(count, bodyA, bodyB, fn: (i) => [0, i], options, deps]) // where fn returns [bodyAIndex, bodyBIndex]

Contributor Guide