|
@@ -25,7 +25,7 @@ Object.assign( WebXRController.prototype, {
|
|
|
|
|
|
if ( window.XRHand ) {
|
|
|
|
|
|
- for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
|
|
|
+ for ( let i = 0; i <= 24; i ++ ) {
|
|
|
|
|
|
// The transform of this joint will be updated with the joint pose on each frame
|
|
|
const joint = new Group();
|
|
@@ -138,54 +138,51 @@ Object.assign( WebXRController.prototype, {
|
|
|
if ( hand && inputSource.hand ) {
|
|
|
|
|
|
handPose = true;
|
|
|
+ let i = 0;
|
|
|
|
|
|
- for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
|
|
|
+ for ( let inputjoint of inputSource.hand.values() ) {
|
|
|
|
|
|
- if ( inputSource.hand[ i ] ) {
|
|
|
+ // Update the joints groups with the XRJoint poses
|
|
|
+ const jointPose = frame.getJointPose( inputjoint, referenceSpace );
|
|
|
+ const joint = hand.joints[ i++ ];
|
|
|
|
|
|
- // Update the joints groups with the XRJoint poses
|
|
|
- const jointPose = frame.getJointPose( inputSource.hand[ i ], referenceSpace );
|
|
|
- const joint = hand.joints[ i ];
|
|
|
+ if ( jointPose !== null ) {
|
|
|
|
|
|
- if ( jointPose !== null ) {
|
|
|
+ joint.matrix.fromArray( jointPose.transform.matrix );
|
|
|
+ joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
|
|
|
+ joint.jointRadius = jointPose.radius;
|
|
|
|
|
|
- joint.matrix.fromArray( jointPose.transform.matrix );
|
|
|
- joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
|
|
|
- joint.jointRadius = jointPose.radius;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- joint.visible = jointPose !== null;
|
|
|
+ }
|
|
|
|
|
|
- // Custom events
|
|
|
+ joint.visible = jointPose !== null;
|
|
|
|
|
|
- // Check pinch
|
|
|
- const indexTip = hand.joints[ window.XRHand.INDEX_PHALANX_TIP ];
|
|
|
- const thumbTip = hand.joints[ window.XRHand.THUMB_PHALANX_TIP ];
|
|
|
- const distance = indexTip.position.distanceTo( thumbTip.position );
|
|
|
+ // Custom events
|
|
|
|
|
|
- const distanceToPinch = 0.02;
|
|
|
- const threshold = 0.005;
|
|
|
+ // Check pinchz
|
|
|
+ const indexTip = hand.joints[ 9 ];
|
|
|
+ const thumbTip = hand.joints[ 4 ];
|
|
|
+ const distance = indexTip.position.distanceTo( thumbTip.position );
|
|
|
|
|
|
- if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
|
|
|
+ const distanceToPinch = 0.02;
|
|
|
+ const threshold = 0.005;
|
|
|
|
|
|
- hand.inputState.pinching = false;
|
|
|
- this.dispatchEvent( {
|
|
|
- type: "pinchend",
|
|
|
- handedness: inputSource.handedness,
|
|
|
- target: this
|
|
|
- } );
|
|
|
+ if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
|
|
|
|
|
|
- } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
|
|
|
+ hand.inputState.pinching = false;
|
|
|
+ this.dispatchEvent( {
|
|
|
+ type: "pinchend",
|
|
|
+ handedness: inputSource.handedness,
|
|
|
+ target: this
|
|
|
+ } );
|
|
|
|
|
|
- hand.inputState.pinching = true;
|
|
|
- this.dispatchEvent( {
|
|
|
- type: "pinchstart",
|
|
|
- handedness: inputSource.handedness,
|
|
|
- target: this
|
|
|
- } );
|
|
|
+ } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
|
|
|
|
|
|
- }
|
|
|
+ hand.inputState.pinching = true;
|
|
|
+ this.dispatchEvent( {
|
|
|
+ type: "pinchstart",
|
|
|
+ handedness: inputSource.handedness,
|
|
|
+ target: this
|
|
|
+ } );
|
|
|
|
|
|
}
|
|
|
|