浏览代码

WebXRManager: Get linear/angular velocity for targetRay and grip poses if available. (#21524)

* Get linear and angular velocity for targetRay and grip poses if available

WebXR spec has been updated allowing the User Agent to pass along linear and angular velocity values for the controller poses. Read this if it's available and pass attach to the _targetRay and _grip structures.

See https://immersive-web.github.io/webxr/#xrpose-interface for more info.

* fixed linting errors

* more linting issues :\

* third time's a charm

* fix check for existence of angular and linear velocity to fail gracefully when not present

* simplified to use copy instead of set

* Update WebXRController.js

Clean up code style.

Co-authored-by: Michael Herzog <[email protected]>
Co-authored-by: Mr.doob <[email protected]>
davehill00 4 年之前
父节点
当前提交
fd3d28e01a
共有 1 个文件被更改,包括 54 次插入1 次删除
  1. 54 1
      src/renderers/webxr/WebXRController.js

+ 54 - 1
src/renderers/webxr/WebXRController.js

@@ -1,3 +1,4 @@
+import { Vector3 } from '../../math/Vector3.js';
 import { Group } from '../../objects/Group.js';
 
 const _moveEvent = { type: 'move' };
@@ -36,6 +37,10 @@ class WebXRController {
 			this._targetRay = new Group();
 			this._targetRay.matrixAutoUpdate = false;
 			this._targetRay.visible = false;
+			this._targetRay.hasLinearVelocity = false;
+			this._targetRay.linearVelocity = new Vector3();
+			this._targetRay.hasAngularVelocity = false;
+			this._targetRay.angularVelocity = new Vector3();
 
 		}
 
@@ -50,6 +55,10 @@ class WebXRController {
 			this._grip = new Group();
 			this._grip.matrixAutoUpdate = false;
 			this._grip.visible = false;
+			this._grip.hasLinearVelocity = false;
+			this._grip.linearVelocity = new Vector3();
+			this._grip.hasAngularVelocity = false;
+			this._grip.angularVelocity = new Vector3();
 
 		}
 
@@ -128,7 +137,29 @@ class WebXRController {
 					targetRay.matrix.fromArray( inputPose.transform.matrix );
 					targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
 
-					this.dispatchEvent( _moveEvent );
+					if ( inputPose.linearVelocity !== null ) {
+
+						targetRay.hasLinearVelocity = true;
+						targetRay.linearVelocity.copy( inputPose.linearVelocity );
+
+					} else {
+
+						targetRay.hasLinearVelocity = false;
+
+					}
+
+					if ( inputPose.angularVelocity !== null ) {
+
+						targetRay.hasAngularVelocity = true;
+						targetRay.angularVelocity.copy( inputPose.angularVelocity );
+
+					} else {
+
+						targetRay.hasAngularVelocity = false;
+
+					}
+
+          this.dispatchEvent( _moveEvent );
 
 				}
 
@@ -210,6 +241,28 @@ class WebXRController {
 						grip.matrix.fromArray( gripPose.transform.matrix );
 						grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
 
+						if ( gripPose.linearVelocity !== null ) {
+
+							grip.hasLinearVelocity = true;
+							grip.linearVelocity.copy( gripPose.linearVelocity );
+
+						} else {
+
+							grip.hasLinearVelocity = false;
+
+						}
+
+						if ( gripPose.angularVelocity !== null ) {
+
+							grip.hasAngularVelocity = true;
+							grip.angularVelocity.copy( gripPose.angularVelocity );
+
+						} else {
+
+							grip.hasAngularVelocity = false;
+
+						}
+
 					}
 
 				}