UNPKG

@threlte/rapier

Version:

Components and hooks to use the Rapier physics engine in Threlte

17 lines (16 loc) 721 B
import { Vector3 } from 'three'; import { useJoint } from './useJoint'; import { isVector3 } from './utils'; export const useRevoluteJoint = (anchorA, anchorB, axis, limits) => { return useJoint((rbA, rbB, { world, rapier }) => { const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA); const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB); const jAxis = (isVector3(axis) ? axis : new Vector3(...axis)).normalize(); const params = rapier.JointData.revolute(jaA, jaB, jAxis); if (limits) { params.limitsEnabled = true; params.limits = limits; } return world.createImpulseJoint(params, rbA, rbB, true); }); };