浏览代码

Fix pinch threshold

Fernando Serrano 5 年之前
父节点
当前提交
5987375b9a
共有 2 个文件被更改,包括 6 次插入3 次删除
  1. 4 3
      src/renderers/webxr/WebXRController.js
  2. 2 0
      src/renderers/webxr/WebXRManager.js

+ 4 - 3
src/renderers/webxr/WebXRController.js

@@ -39,7 +39,6 @@ Object.assign( WebXRController.prototype, {
 					// ??
 					// ??
 					this._hand.add( joint );
 					this._hand.add( joint );
 
 
-
 				}
 				}
 
 
 			}
 			}
@@ -167,8 +166,10 @@ Object.assign( WebXRController.prototype, {
 						const indexTip = hand.joints[ XRHand.INDEX_PHALANX_TIP ];
 						const indexTip = hand.joints[ XRHand.INDEX_PHALANX_TIP ];
 						const thumbTip = hand.joints[ XRHand.THUMB_PHALANX_TIP ];
 						const thumbTip = hand.joints[ XRHand.THUMB_PHALANX_TIP ];
 						const distance = indexTip.position.distanceTo( thumbTip.position );
 						const distance = indexTip.position.distanceTo( thumbTip.position );
+
 						const distanceToPinch = 0.02;
 						const distanceToPinch = 0.02;
-						if ( hand.inputState.pinching && distance > distanceToPinch ) {
+						const threshold = 0.005;
+						if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
 
 
 							hand.inputState.pinching = false;
 							hand.inputState.pinching = false;
 							this.dispatchEvent( {
 							this.dispatchEvent( {
@@ -176,7 +177,7 @@ Object.assign( WebXRController.prototype, {
 								target: this
 								target: this
 							} );
 							} );
 
 
-						} else if ( ! hand.inputState.pinching && distance <= distanceToPinch ) {
+						} else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
 
 
 							hand.inputState.pinching = true;
 							hand.inputState.pinching = true;
 							this.dispatchEvent( {
 							this.dispatchEvent( {

+ 2 - 0
src/renderers/webxr/WebXRManager.js

@@ -230,6 +230,8 @@ function WebXRManager( renderer, gl ) {
 
 
 		const inputSources = session.inputSources;
 		const inputSources = session.inputSources;
 
 
+		console.log("Update sources", inputSources);
+
 		// Assign inputSources to available controllers
 		// Assign inputSources to available controllers
 
 
 		for ( let i = 0; i < controllers.length; i ++ ) {
 		for ( let i = 0; i < controllers.length; i ++ ) {