|
@@ -20,25 +20,9 @@ Object.assign( WebXRController.prototype, {
|
|
this._hand.matrixAutoUpdate = false;
|
|
this._hand.matrixAutoUpdate = false;
|
|
this._hand.visible = false;
|
|
this._hand.visible = false;
|
|
|
|
|
|
- this._hand.joints = [];
|
|
|
|
|
|
+ this._hand.joints = {};
|
|
this._hand.inputState = { pinching: false };
|
|
this._hand.inputState = { pinching: false };
|
|
|
|
|
|
- if ( window.XRHand ) {
|
|
|
|
-
|
|
|
|
- for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
|
|
|
|
-
|
|
|
|
- // The transform of this joint will be updated with the joint pose on each frame
|
|
|
|
- const joint = new Group();
|
|
|
|
- joint.matrixAutoUpdate = false;
|
|
|
|
- joint.visible = false;
|
|
|
|
- this._hand.joints.push( joint );
|
|
|
|
- // ??
|
|
|
|
- this._hand.add( joint );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return this._hand;
|
|
return this._hand;
|
|
@@ -139,55 +123,64 @@ Object.assign( WebXRController.prototype, {
|
|
|
|
|
|
handPose = true;
|
|
handPose = true;
|
|
|
|
|
|
- for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
|
|
|
|
|
|
+ for ( const inputjoint of inputSource.hand.values() ) {
|
|
|
|
|
|
- if ( inputSource.hand[ i ] ) {
|
|
|
|
|
|
+ // Update the joints groups with the XRJoint poses
|
|
|
|
+ const jointPose = frame.getJointPose( inputjoint, referenceSpace );
|
|
|
|
|
|
- // Update the joints groups with the XRJoint poses
|
|
|
|
- const jointPose = frame.getJointPose( inputSource.hand[ i ], referenceSpace );
|
|
|
|
- const joint = hand.joints[ i ];
|
|
|
|
|
|
+ if ( hand.joints[ inputjoint.jointName ] === undefined ) {
|
|
|
|
|
|
- if ( jointPose !== null ) {
|
|
|
|
|
|
+ // The transform of this joint will be updated with the joint pose on each frame
|
|
|
|
+ const joint = new Group();
|
|
|
|
+ joint.matrixAutoUpdate = false;
|
|
|
|
+ joint.visible = false;
|
|
|
|
+ hand.joints[ inputjoint.jointName ] = joint;
|
|
|
|
+ // ??
|
|
|
|
+ hand.add( joint );
|
|
|
|
|
|
- joint.matrix.fromArray( jointPose.transform.matrix );
|
|
|
|
- joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
|
|
|
|
- joint.jointRadius = jointPose.radius;
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const joint = hand.joints[ inputjoint.jointName ];
|
|
|
|
+
|
|
|
|
+ if ( jointPose !== null ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ 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 );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- const distanceToPinch = 0.02;
|
|
|
|
- const threshold = 0.005;
|
|
|
|
|
|
+ // Custom events
|
|
|
|
|
|
- if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
|
|
|
|
|
|
+ // Check pinchz
|
|
|
|
+ const indexTip = hand.joints[ 'index-finger-tip' ];
|
|
|
|
+ const thumbTip = hand.joints[ 'thumb-tip' ];
|
|
|
|
+ const distance = indexTip.position.distanceTo( thumbTip.position );
|
|
|
|
|
|
- hand.inputState.pinching = false;
|
|
|
|
- this.dispatchEvent( {
|
|
|
|
- type: 'pinchend',
|
|
|
|
- handedness: inputSource.handedness,
|
|
|
|
- target: this
|
|
|
|
- } );
|
|
|
|
|
|
+ const distanceToPinch = 0.02;
|
|
|
|
+ const threshold = 0.005;
|
|
|
|
|
|
- } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
|
|
|
|
|
|
+ if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
|
|
|
|
|
|
- hand.inputState.pinching = true;
|
|
|
|
- this.dispatchEvent( {
|
|
|
|
- type: 'pinchstart',
|
|
|
|
- handedness: inputSource.handedness,
|
|
|
|
- target: this
|
|
|
|
- } );
|
|
|
|
|
|
+ hand.inputState.pinching = false;
|
|
|
|
+ this.dispatchEvent( {
|
|
|
|
+ type: 'pinchend',
|
|
|
|
+ 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
|
|
|
|
+ } );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|