未验证 提交 fd3d28e0 编写于 作者: D davehill00 提交者: GitHub

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: NMichael Herzog <michael.herzog@human-interactive.org>
Co-authored-by: NMr.doob <info@mrdoob.com>
上级 979d8f28
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;
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册