|
|
@@ -25,6 +25,7 @@ import { Color3 } from '../../Maths/math.color';
|
|
|
import { Scene } from '../../scene';
|
|
|
import { UtilityLayerRenderer } from '../../Rendering/utilityLayerRenderer';
|
|
|
import { PointerEventTypes } from '../../Events/pointerEvents';
|
|
|
+import { SetAndStartTimer } from '../../Misc/timer';
|
|
|
|
|
|
/**
|
|
|
* The options container for the teleportation module
|
|
|
@@ -429,20 +430,14 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
|
|
|
controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;
|
|
|
controllerData.teleportationState.currentRotation = 0;
|
|
|
const timeToSelect = this._options.timeToTeleport || 3000;
|
|
|
- let timer = 0;
|
|
|
- const observer = this._xrSessionManager.onXRFrameObservable.add(() => {
|
|
|
- if (!mainComponent.pressed) {
|
|
|
- this._xrSessionManager.onXRFrameObservable.remove(observer);
|
|
|
- return;
|
|
|
- }
|
|
|
- timer += this._xrSessionManager.scene.getEngine().getDeltaTime();
|
|
|
- if (timer >= timeToSelect && this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {
|
|
|
- this._teleportForward(xrController.uniqueId);
|
|
|
- }
|
|
|
-
|
|
|
- // failsafe
|
|
|
- if (timer >= timeToSelect) {
|
|
|
- this._xrSessionManager.onXRFrameObservable.remove(observer);
|
|
|
+ SetAndStartTimer({
|
|
|
+ time: timeToSelect,
|
|
|
+ countingObservable: this._xrSessionManager.onXRFrameObservable,
|
|
|
+ breakCondition: () => !mainComponent.pressed,
|
|
|
+ onEnded: () => {
|
|
|
+ if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {
|
|
|
+ this._teleportForward(xrController.uniqueId);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
@@ -526,15 +521,13 @@ export class WebXRMotionControllerTeleportation extends WebXRAbstractFeature {
|
|
|
controllerData.teleportationState.baseRotation = this._options.xrInput.xrCamera.rotationQuaternion.toEulerAngles().y;
|
|
|
controllerData.teleportationState.currentRotation = 0;
|
|
|
const timeToSelect = this._options.timeToTeleport || 3000;
|
|
|
- let timer = 0;
|
|
|
- const observer = this._xrSessionManager.onXRFrameObservable.add(() => {
|
|
|
- timer += this._xrSessionManager.scene.getEngine().getDeltaTime();
|
|
|
- if (timer >= timeToSelect && this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {
|
|
|
- this._teleportForward(xrController.uniqueId);
|
|
|
- }
|
|
|
-
|
|
|
- if (timer >= timeToSelect) {
|
|
|
- this._xrSessionManager.onXRFrameObservable.remove(observer);
|
|
|
+ SetAndStartTimer({
|
|
|
+ time: timeToSelect,
|
|
|
+ countingObservable: this._xrSessionManager.onXRFrameObservable,
|
|
|
+ onEnded: () => {
|
|
|
+ if (this._currentTeleportationControllerId === controllerData.xrController.uniqueId && controllerData.teleportationState.forward) {
|
|
|
+ this._teleportForward(xrController.uniqueId);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
} else if (pointerInfo.type === PointerEventTypes.POINTERUP) {
|