@threlte/xr
Version:
Tools to more easily create VR and AR experiences with Threlte
21 lines (20 loc) • 764 B
JavaScript
import { currentWritable, useTask, useThrelte } from '@threlte/core';
import { useHand } from './useHand';
/**
* Provides a reference to a requested hand joint, once available.
*/
export const useHandJoint = (handedness, joint) => {
const { invalidate } = useThrelte();
const jointSpaceStore = currentWritable(undefined);
const xrhand = useHand(handedness);
const { stop } = useTask(() => {
const jointSpace = xrhand.current?.hand.joints[joint];
// The joint radius is a good indicator that the joint is ready
if (jointSpace?.jointRadius !== undefined) {
jointSpaceStore.set(jointSpace);
invalidate();
stop();
}
}, { autoInvalidate: false });
return jointSpaceStore;
};