UNPKG

@threlte/rapier

Version:

Components and hooks to use the Rapier physics engine in Threlte

15 lines (14 loc) 818 B
import { Euler, Quaternion, Vector3 } from 'three'; import { useJoint } from './useJoint'; import { isEuler, isVector3 } from './utils'; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const useFixedJoint = (anchorA, frameA, anchorB, frameB) => { const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA); const jfA = new Quaternion().setFromEuler(isEuler(frameA) ? frameA : new Euler(...frameA)); const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB); const jfB = new Quaternion().setFromEuler(isEuler(frameB) ? frameB : new Euler(...frameB)); return useJoint((rbA, rbB, { world, rapier }) => { const params = rapier.JointData.fixed(jaA, jfA, jaB, jfB); return world.createImpulseJoint(params, rbA, rbB, true); }); };