pmndrs / use-cannon

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

setting pivots in useConstrained on setup isn't enough #51

Open drcmda opened 4 years ago

drcmda commented 4 years ago

im trying to do this: http://schteppe.github.io/cannon.js/examples/threejs_mousepick.html

in the example repo, the monday morning demo, try picking the chair - it just makes no sense because it goes to object center (i guess). the pivot needs to be calculated once the object is clicked. but currently the constraint is first set up with a fixed pivot, then disabled and enabled on demand.

any ideas how this could be solved?

codynova commented 4 years ago

It looks like in Schteppe's demo, he's just creating a new constraint on each click. I can't think of any reason why we couldn't allow updating a constraint's pivots (which doesn't mean there isn't a reason, haha), just need to make that possible in cannon-es.

drcmda commented 4 years ago

i believe its really just a loose vector on the object, so it could be overwritten, correct? in that case we could maybe extend makeApi with new updaters.

codynova commented 4 years ago

I just checked and it looks like you're right, should be fine to just overwrite those vectors, and they should get updated automatically (rotated into World space) on the World step

codynova commented 4 years ago

I took a quick stab at it, but I'm not sure if the pivot vectors are in the correct coordinate space. Can you test this branch against the MondayMorning demo when you have a moment?

It's worth noting that some constraints don't have pivots, and some constraints do have axes - so I think we should make the types more honest at some point...

Is there a reason to add the axes to the Constraint API (I'm guessing yes)?

mattrossman commented 4 years ago

Is there any progress on this issue? I'm trying to make a demo much like the mousepick one that Paul shared, and I'm stuck because reactive pivots in usePointToPointConstraint don't work as expected.