import { Quaternion, Euler } from 'three' // Reusuable objects to save on GC const quaternion = new Quaternion() const euler = new Euler() // TODO: Do we need to do this or will Rapier just accept a Three quaternion? const rotationToQuaternion = (rotation) => { const { w, x, y, z } = quaternion.setFromEuler(euler.set(...rotation)) return { w, x, y, z } } // Cast downward ray from origin & get list of pieces (sorted by Y position) // TODO: If we make direction a prop can this be used to castShape in any direction? export const castShapeDown = ( { world }, { shape, position, rotation, distance = 10000 }, predicate ) => world.raw().castShape( { x: position[0], y: distance, z: position[2] }, rotationToQuaternion(rotation), // quaternion.setFromEuler(euler.set(...rotation)) { x: 0, y: -1, z: 0 }, shape, distance + 1, // TODO: is it necessary to do +1? false, // firstHitOnly undefined, undefined, undefined, undefined, (...args) => predicate(...args) )