|
@@ -21019,18 +21019,30 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
* @param name the name of the camera
|
|
|
* @param scene the scene to add the camera to
|
|
|
*/
|
|
|
- function WebXRCamera(name, scene) {
|
|
|
+ function WebXRCamera(name, scene, _xrSessionManager) {
|
|
|
var _this = _super.call(this, name, _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), scene) || this;
|
|
|
+ _this._xrSessionManager = _xrSessionManager;
|
|
|
/**
|
|
|
* Is the camera in debug mode. Used when using an emulator
|
|
|
*/
|
|
|
_this.debugMode = false;
|
|
|
+ _this._firstFrame = false;
|
|
|
+ _this._referencedPosition = new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"]();
|
|
|
+ _this._referenceQuaternion = _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].Identity();
|
|
|
+ _this._xrInvPositionCache = new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"]();
|
|
|
+ _this._xrInvQuaternionCache = _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].Identity();
|
|
|
// Initial camera configuration
|
|
|
_this.minZ = 0.1;
|
|
|
_this.rotationQuaternion = new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
|
|
|
_this.cameraRigMode = _Cameras_camera__WEBPACK_IMPORTED_MODULE_2__["Camera"].RIG_MODE_CUSTOM;
|
|
|
_this.updateUpVectorFromRotation = true;
|
|
|
_this._updateNumberOfRigCameras(1);
|
|
|
+ _this._xrSessionManager.onXRSessionInit.add(function () {
|
|
|
+ _this._referencedPosition.copyFromFloats(0, 0, 0);
|
|
|
+ _this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);
|
|
|
+ // first frame - camera's y position should be 0 for the correct offset
|
|
|
+ _this._firstFrame = true;
|
|
|
+ });
|
|
|
return _this;
|
|
|
}
|
|
|
WebXRCamera.prototype._updateNumberOfRigCameras = function (viewCount) {
|
|
@@ -21038,7 +21050,6 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
while (this.rigCameras.length < viewCount) {
|
|
|
var newCamera = new _Cameras_targetCamera__WEBPACK_IMPORTED_MODULE_4__["TargetCamera"]("view: " + this.rigCameras.length, _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"].Zero(), this.getScene());
|
|
|
newCamera.minZ = 0.1;
|
|
|
- newCamera.parent = this;
|
|
|
newCamera.rotationQuaternion = new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"]();
|
|
|
newCamera.updateUpVectorFromRotation = true;
|
|
|
this.rigCameras.push(newCamera);
|
|
@@ -21064,30 +21075,107 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
/**
|
|
|
* Updates the cameras position from the current pose information of the XR session
|
|
|
* @param xrSessionManager the session containing pose information
|
|
|
- * @returns true if the camera has been updated, false if the session did not contain pose or frame data
|
|
|
*/
|
|
|
- WebXRCamera.prototype.updateFromXRSessionManager = function (xrSessionManager) {
|
|
|
- var _this = this;
|
|
|
- // Ensure all frame data is available
|
|
|
- if (!xrSessionManager.currentFrame || !xrSessionManager.currentFrame.getViewerPose) {
|
|
|
- return false;
|
|
|
+ WebXRCamera.prototype.update = function () {
|
|
|
+ if (!this._firstFrame) {
|
|
|
+ this._updateReferenceSpace();
|
|
|
}
|
|
|
- var pose = xrSessionManager.currentFrame.getViewerPose(xrSessionManager.referenceSpace);
|
|
|
- if (!pose) {
|
|
|
- return false;
|
|
|
+ this._updateFromXRSession();
|
|
|
+ _super.prototype.update.call(this);
|
|
|
+ };
|
|
|
+ WebXRCamera.prototype._updateReferenceSpace = function () {
|
|
|
+ // were position & rotation updated OUTSIDE of the xr update loop
|
|
|
+ if (!this.position.equals(this._referencedPosition) || !this.rotationQuaternion.equals(this._referenceQuaternion)) {
|
|
|
+ this.position.subtractToRef(this._referencedPosition, this._referencedPosition);
|
|
|
+ this._referenceQuaternion.conjugateInPlace();
|
|
|
+ this._referenceQuaternion.multiplyToRef(this.rotationQuaternion, this._referenceQuaternion);
|
|
|
+ this._updateReferenceSpaceOffset(this._referencedPosition, this._referenceQuaternion.normalize());
|
|
|
+ return true;
|
|
|
}
|
|
|
- if (pose.transform && pose.emulatedPosition) {
|
|
|
- this.position.copyFrom((pose.transform.position));
|
|
|
- this.rotationQuaternion.copyFrom((pose.transform.orientation));
|
|
|
+ return false;
|
|
|
+ };
|
|
|
+ WebXRCamera.prototype._updateReferenceSpaceOffset = function (positionOffset, rotationOffset, ignoreHeight) {
|
|
|
+ if (ignoreHeight === void 0) { ignoreHeight = false; }
|
|
|
+ if (!this._xrSessionManager.referenceSpace || !this._xrSessionManager.currentFrame) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // Compute the origin offset based on player position/orientation.
|
|
|
+ this._xrInvPositionCache.copyFrom(positionOffset);
|
|
|
+ if (rotationOffset) {
|
|
|
+ this._xrInvQuaternionCache.copyFrom(rotationOffset);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this._xrInvQuaternionCache.copyFromFloats(0, 0, 0, 1);
|
|
|
+ }
|
|
|
+ // right handed system
|
|
|
+ if (!this._scene.useRightHandedSystem) {
|
|
|
+ this._xrInvPositionCache.z *= -1;
|
|
|
+ this._xrInvQuaternionCache.z *= -1;
|
|
|
+ this._xrInvQuaternionCache.w *= -1;
|
|
|
+ }
|
|
|
+ this._xrInvPositionCache.negateInPlace();
|
|
|
+ this._xrInvQuaternionCache.conjugateInPlace();
|
|
|
+ // transform point according to rotation with pivot
|
|
|
+ this._xrInvPositionCache.rotateByQuaternionToRef(this._xrInvQuaternionCache, this._xrInvPositionCache);
|
|
|
+ if (ignoreHeight) {
|
|
|
+ this._xrInvPositionCache.y = 0;
|
|
|
+ }
|
|
|
+ var transform = new XRRigidTransform(Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({}, this._xrInvPositionCache), Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({}, this._xrInvQuaternionCache));
|
|
|
+ // Update offset reference to use a new originOffset with the teleported
|
|
|
+ // player position and orientation.
|
|
|
+ // This new offset needs to be applied to the base ref space.
|
|
|
+ var referenceSpace = this._xrSessionManager.referenceSpace.getOffsetReferenceSpace(transform);
|
|
|
+ var pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(referenceSpace);
|
|
|
+ if (pose) {
|
|
|
+ var pos = new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"]();
|
|
|
+ pos.copyFrom((pose.transform.position));
|
|
|
if (!this._scene.useRightHandedSystem) {
|
|
|
- this.position.z *= -1;
|
|
|
- this.rotationQuaternion.z *= -1;
|
|
|
- this.rotationQuaternion.w *= -1;
|
|
|
+ pos.z *= -1;
|
|
|
}
|
|
|
- this.computeWorldMatrix();
|
|
|
+ this.position.subtractToRef(pos, pos);
|
|
|
+ if (!this._scene.useRightHandedSystem) {
|
|
|
+ pos.z *= -1;
|
|
|
+ }
|
|
|
+ pos.negateInPlace();
|
|
|
+ var transform2 = new XRRigidTransform(Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__assign"])({}, pos));
|
|
|
+ // Update offset reference to use a new originOffset with the teleported
|
|
|
+ // player position and orientation.
|
|
|
+ // This new offset needs to be applied to the base ref space.
|
|
|
+ this._xrSessionManager.referenceSpace = referenceSpace.getOffsetReferenceSpace(transform2);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ WebXRCamera.prototype._updateFromXRSession = function () {
|
|
|
+ var _this = this;
|
|
|
+ var pose = this._xrSessionManager.currentFrame && this._xrSessionManager.currentFrame.getViewerPose(this._xrSessionManager.referenceSpace);
|
|
|
+ if (!pose) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (pose.transform) {
|
|
|
+ this._referencedPosition.copyFrom((pose.transform.position));
|
|
|
+ this._referenceQuaternion.copyFrom((pose.transform.orientation));
|
|
|
+ if (!this._scene.useRightHandedSystem) {
|
|
|
+ this._referencedPosition.z *= -1;
|
|
|
+ this._referenceQuaternion.z *= -1;
|
|
|
+ this._referenceQuaternion.w *= -1;
|
|
|
+ }
|
|
|
+ if (this._firstFrame) {
|
|
|
+ this._firstFrame = false;
|
|
|
+ // we have the XR reference, now use this to find the offset to get the camera to be
|
|
|
+ // in the right position
|
|
|
+ // set the height to correlate to the current height
|
|
|
+ this.position.y += this._referencedPosition.y;
|
|
|
+ // avoid using the head rotation on the first frame.
|
|
|
+ this._referenceQuaternion.copyFromFloats(0, 0, 0, 1);
|
|
|
+ // update the reference space so that the position will be correct
|
|
|
+ return this.update();
|
|
|
+ }
|
|
|
+ this.rotationQuaternion.copyFrom(this._referenceQuaternion);
|
|
|
+ this.position.copyFrom(this._referencedPosition);
|
|
|
}
|
|
|
// Update camera rigs
|
|
|
- this._updateNumberOfRigCameras(pose.views.length);
|
|
|
+ if (this.rigCameras.length !== pose.views.length) {
|
|
|
+ this._updateNumberOfRigCameras(pose.views.length);
|
|
|
+ }
|
|
|
pose.views.forEach(function (view, i) {
|
|
|
var currentRig = _this.rigCameras[i];
|
|
|
// update right and left, where applicable
|
|
@@ -21100,7 +21188,7 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
}
|
|
|
}
|
|
|
// Update view/projection matrix
|
|
|
- if (view.transform.position && view.transform.orientation) {
|
|
|
+ if (view.transform.position) {
|
|
|
currentRig.position.copyFrom(view.transform.position);
|
|
|
currentRig.rotationQuaternion.copyFrom(view.transform.orientation);
|
|
|
if (!_this._scene.useRightHandedSystem) {
|
|
@@ -21120,10 +21208,10 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
currentRig._projectionMatrix.toggleProjectionMatrixHandInPlace();
|
|
|
}
|
|
|
// Update viewport
|
|
|
- if (xrSessionManager.session.renderState.baseLayer) {
|
|
|
- var viewport = xrSessionManager.session.renderState.baseLayer.getViewport(view);
|
|
|
- var width = xrSessionManager.session.renderState.baseLayer.framebufferWidth;
|
|
|
- var height = xrSessionManager.session.renderState.baseLayer.framebufferHeight;
|
|
|
+ if (_this._xrSessionManager.session.renderState.baseLayer) {
|
|
|
+ var viewport = _this._xrSessionManager.session.renderState.baseLayer.getViewport(view);
|
|
|
+ var width = _this._xrSessionManager.session.renderState.baseLayer.framebufferWidth;
|
|
|
+ var height = _this._xrSessionManager.session.renderState.baseLayer.framebufferHeight;
|
|
|
currentRig.viewport.width = viewport.width / width;
|
|
|
currentRig.viewport.height = viewport.height / height;
|
|
|
currentRig.viewport.x = viewport.x / width;
|
|
@@ -21133,9 +21221,8 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
_this._updateForDualEyeDebugging();
|
|
|
}
|
|
|
// Set cameras to render to the session's render target
|
|
|
- currentRig.outputRenderTarget = xrSessionManager.getRenderTargetTextureForEye(view.eye);
|
|
|
+ currentRig.outputRenderTarget = _this._xrSessionManager.getRenderTargetTextureForEye(view.eye);
|
|
|
});
|
|
|
- return true;
|
|
|
};
|
|
|
return WebXRCamera;
|
|
|
}(_Cameras_freeCamera__WEBPACK_IMPORTED_MODULE_3__["FreeCamera"]));
|
|
@@ -21349,7 +21436,7 @@ var WebXRControllerModelLoader = /** @class */ (function () {
|
|
|
controllerModel.hand = c.inputSource.handedness;
|
|
|
controllerModel.isXR = true;
|
|
|
controllerModel.initControllerMesh(c.getScene(), function (m) {
|
|
|
- controllerModel.mesh.parent = c.grip || input.baseExperience.container;
|
|
|
+ controllerModel.mesh.parent = c.grip || null;
|
|
|
controllerModel.mesh.rotationQuaternion = rotation;
|
|
|
controllerModel.mesh.position = position;
|
|
|
m.isPickable = false;
|
|
@@ -21643,9 +21730,11 @@ var WebXRControllerTeleportation = /** @class */ (function () {
|
|
|
teleportationTarget.getChildren()[0].isVisible = false;
|
|
|
}
|
|
|
if (c.inputSource.gamepad) {
|
|
|
- if (c.inputSource.gamepad.axes[3] !== undefined) {
|
|
|
+ var yIndex = c.inputSource.gamepad.axes.length - 1;
|
|
|
+ var xIndex = c.inputSource.gamepad.axes.length - 2;
|
|
|
+ if (c.inputSource.gamepad.axes[yIndex] !== undefined) {
|
|
|
// Forward teleportation
|
|
|
- if (c.inputSource.gamepad.axes[3] < -0.7) {
|
|
|
+ if (c.inputSource.gamepad.axes[yIndex] < -0.7) {
|
|
|
forwardReadyToTeleport = true;
|
|
|
}
|
|
|
else {
|
|
@@ -21653,22 +21742,18 @@ var WebXRControllerTeleportation = /** @class */ (function () {
|
|
|
// Teleport the users feet to where they targeted
|
|
|
_this._tmpVector.copyFrom(teleportationTarget.position);
|
|
|
_this._tmpVector.y += input.baseExperience.camera.position.y;
|
|
|
- input.baseExperience.setPositionOfCameraUsingContainer(_this._tmpVector);
|
|
|
+ input.baseExperience.camera.position.copyFrom(_this._tmpVector);
|
|
|
}
|
|
|
forwardReadyToTeleport = false;
|
|
|
}
|
|
|
// Backward teleportation
|
|
|
- if (c.inputSource.gamepad.axes[3] > 0.7) {
|
|
|
+ if (c.inputSource.gamepad.axes[yIndex] > 0.7) {
|
|
|
backwardReadyToTeleport = true;
|
|
|
}
|
|
|
else {
|
|
|
if (backwardReadyToTeleport) {
|
|
|
- // Cast a ray down from behind the user
|
|
|
- var camMat = input.baseExperience.camera.computeWorldMatrix();
|
|
|
- var q = new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"]();
|
|
|
- camMat.decompose(undefined, q, _this._tmpRay.origin);
|
|
|
_this._tmpVector.set(0, 0, -1);
|
|
|
- _this._tmpVector.rotateByQuaternionToRef(q, _this._tmpVector);
|
|
|
+ _this._tmpVector.rotateByQuaternionToRef(input.baseExperience.camera.rotationQuaternion, _this._tmpVector);
|
|
|
_this._tmpVector.y = 0;
|
|
|
_this._tmpVector.normalize();
|
|
|
_this._tmpVector.y = -1.5;
|
|
@@ -21680,29 +21765,28 @@ var WebXRControllerTeleportation = /** @class */ (function () {
|
|
|
if (pick && pick.pickedPoint) {
|
|
|
// Teleport the users feet to where they targeted
|
|
|
_this._tmpVector.copyFrom(pick.pickedPoint);
|
|
|
- _this._tmpVector.y += input.baseExperience.camera.position.y;
|
|
|
- input.baseExperience.setPositionOfCameraUsingContainer(_this._tmpVector);
|
|
|
+ input.baseExperience.camera.position.addInPlace(_this._tmpVector);
|
|
|
}
|
|
|
}
|
|
|
backwardReadyToTeleport = false;
|
|
|
}
|
|
|
}
|
|
|
- if (c.inputSource.gamepad.axes[2] !== undefined) {
|
|
|
- if (c.inputSource.gamepad.axes[2] < -0.7) {
|
|
|
+ if (c.inputSource.gamepad.axes[xIndex] !== undefined) {
|
|
|
+ if (c.inputSource.gamepad.axes[xIndex] < -0.7) {
|
|
|
leftReadyToTeleport = true;
|
|
|
}
|
|
|
else {
|
|
|
if (leftReadyToTeleport) {
|
|
|
- input.baseExperience.rotateCameraByQuaternionUsingContainer(_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromEulerAngles(0, -Math.PI / 4, 0));
|
|
|
+ input.baseExperience.camera.rotationQuaternion.multiplyInPlace(_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromEulerAngles(0, -Math.PI / 4, 0));
|
|
|
}
|
|
|
leftReadyToTeleport = false;
|
|
|
}
|
|
|
- if (c.inputSource.gamepad.axes[2] > 0.7) {
|
|
|
+ if (c.inputSource.gamepad.axes[xIndex] > 0.7) {
|
|
|
rightReadyToTeleport = true;
|
|
|
}
|
|
|
else {
|
|
|
if (rightReadyToTeleport) {
|
|
|
- input.baseExperience.rotateCameraByQuaternionUsingContainer(_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromEulerAngles(0, Math.PI / 4, 0));
|
|
|
+ input.baseExperience.camera.rotationQuaternion.multiplyInPlace(_Maths_math_vector__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].FromEulerAngles(0, Math.PI / 4, 0));
|
|
|
}
|
|
|
rightReadyToTeleport = false;
|
|
|
}
|
|
@@ -22036,12 +22120,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "WebXRExperienceHelper", function() { return WebXRExperienceHelper; });
|
|
|
/* harmony import */ var _Misc_observable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../Misc/observable */ "./Misc/observable.ts");
|
|
|
/* harmony import */ var _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../Maths/math.vector */ "./Maths/math.vector.ts");
|
|
|
-/* harmony import */ var _Meshes_abstractMesh__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../Meshes/abstractMesh */ "./Meshes/abstractMesh.ts");
|
|
|
-/* harmony import */ var _webXRSessionManager__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./webXRSessionManager */ "./Cameras/XR/webXRSessionManager.ts");
|
|
|
-/* harmony import */ var _webXRCamera__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./webXRCamera */ "./Cameras/XR/webXRCamera.ts");
|
|
|
-/* harmony import */ var _webXRTypes__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./webXRTypes */ "./Cameras/XR/webXRTypes.ts");
|
|
|
-/* harmony import */ var _webXRFeaturesManager__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./webXRFeaturesManager */ "./Cameras/XR/webXRFeaturesManager.ts");
|
|
|
-
|
|
|
+/* harmony import */ var _webXRSessionManager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./webXRSessionManager */ "./Cameras/XR/webXRSessionManager.ts");
|
|
|
+/* harmony import */ var _webXRCamera__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./webXRCamera */ "./Cameras/XR/webXRCamera.ts");
|
|
|
+/* harmony import */ var _webXRTypes__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./webXRTypes */ "./Cameras/XR/webXRTypes.ts");
|
|
|
+/* harmony import */ var _webXRFeaturesManager__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./webXRFeaturesManager */ "./Cameras/XR/webXRFeaturesManager.ts");
|
|
|
|
|
|
|
|
|
|
|
@@ -22063,19 +22145,25 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
/**
|
|
|
* The current state of the XR experience (eg. transitioning, in XR or not in XR)
|
|
|
*/
|
|
|
- this.state = _webXRTypes__WEBPACK_IMPORTED_MODULE_5__["WebXRState"].NOT_IN_XR;
|
|
|
+ this.state = _webXRTypes__WEBPACK_IMPORTED_MODULE_4__["WebXRState"].NOT_IN_XR;
|
|
|
/**
|
|
|
* Fires when the state of the experience helper has changed
|
|
|
*/
|
|
|
this.onStateChangedObservable = new _Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
|
|
|
+ /**
|
|
|
+ * Observers registered here will be triggered after the camera's initial transformation is set
|
|
|
+ * This can be used to set a different ground level or an extra rotation.
|
|
|
+ *
|
|
|
+ * Note that ground level is considered to be at 0. The height defined by the XR camera will be added
|
|
|
+ * to the position set after this observable is done executing.
|
|
|
+ */
|
|
|
+ this.onInitialXRPoseSetObservable = new _Misc_observable__WEBPACK_IMPORTED_MODULE_0__["Observable"]();
|
|
|
this._nonVRCamera = null;
|
|
|
this._originalSceneAutoClear = true;
|
|
|
this._supported = false;
|
|
|
- this.camera = new _webXRCamera__WEBPACK_IMPORTED_MODULE_4__["WebXRCamera"]("", scene);
|
|
|
- this.sessionManager = new _webXRSessionManager__WEBPACK_IMPORTED_MODULE_3__["WebXRSessionManager"](scene);
|
|
|
- this.featuresManager = new _webXRFeaturesManager__WEBPACK_IMPORTED_MODULE_6__["WebXRFeaturesManager"](this.sessionManager);
|
|
|
- this.container = new _Meshes_abstractMesh__WEBPACK_IMPORTED_MODULE_2__["AbstractMesh"]("WebXR Container", scene);
|
|
|
- this.camera.parent = this.container;
|
|
|
+ this.sessionManager = new _webXRSessionManager__WEBPACK_IMPORTED_MODULE_2__["WebXRSessionManager"](scene);
|
|
|
+ this.camera = new _webXRCamera__WEBPACK_IMPORTED_MODULE_3__["WebXRCamera"]("", scene, this.sessionManager);
|
|
|
+ this.featuresManager = new _webXRFeaturesManager__WEBPACK_IMPORTED_MODULE_5__["WebXRFeaturesManager"](this.sessionManager);
|
|
|
scene.onDisposeObservable.add(function () {
|
|
|
_this.exitXRAsync();
|
|
|
});
|
|
@@ -22103,7 +22191,7 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
* @returns promise that resolves after xr mode has exited
|
|
|
*/
|
|
|
WebXRExperienceHelper.prototype.exitXRAsync = function () {
|
|
|
- this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_5__["WebXRState"].EXITING_XR);
|
|
|
+ this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_4__["WebXRState"].EXITING_XR);
|
|
|
return this.sessionManager.exitXRAsync();
|
|
|
};
|
|
|
/**
|
|
@@ -22118,7 +22206,7 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
if (!this._supported) {
|
|
|
throw "XR session not supported by this browser";
|
|
|
}
|
|
|
- this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_5__["WebXRState"].ENTERING_XR);
|
|
|
+ this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_4__["WebXRState"].ENTERING_XR);
|
|
|
var sessionCreationOptions = {
|
|
|
optionalFeatures: (referenceSpaceType !== "viewer" && referenceSpaceType !== "local") ? [referenceSpaceType] : []
|
|
|
};
|
|
@@ -22136,10 +22224,7 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
_this._nonVRCamera = _this.scene.activeCamera;
|
|
|
// Overwrite current scene settings
|
|
|
_this.scene.autoClear = false;
|
|
|
- _this.scene.activeCamera = _this.camera;
|
|
|
- _this.sessionManager.onXRFrameObservable.add(function () {
|
|
|
- _this.camera.updateFromXRSessionManager(_this.sessionManager);
|
|
|
- });
|
|
|
+ _this._nonXRToXRCamera();
|
|
|
_this.sessionManager.onXRSessionEnded.addOnce(function () {
|
|
|
// Reset camera rigs output render target to ensure sessions render target is not drawn after it ends
|
|
|
_this.camera.rigCameras.forEach(function (c) {
|
|
@@ -22148,12 +22233,17 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
// Restore scene settings
|
|
|
_this.scene.autoClear = _this._originalSceneAutoClear;
|
|
|
_this.scene.activeCamera = _this._nonVRCamera;
|
|
|
- _this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_5__["WebXRState"].NOT_IN_XR);
|
|
|
+ if (_this._nonVRCamera.setPosition) {
|
|
|
+ _this._nonVRCamera.setPosition(_this.camera.position);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _this._nonVRCamera.position.copyFrom(_this.camera.position);
|
|
|
+ }
|
|
|
+ _this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_4__["WebXRState"].NOT_IN_XR);
|
|
|
});
|
|
|
// Wait until the first frame arrives before setting state to in xr
|
|
|
_this.sessionManager.onXRFrameObservable.addOnce(function () {
|
|
|
- _this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_5__["WebXRState"].IN_XR);
|
|
|
- _this.setPositionOfCameraUsingContainer(new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"](_this._nonVRCamera.position.x, _this.camera.position.y, _this._nonVRCamera.position.z));
|
|
|
+ _this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_4__["WebXRState"].IN_XR);
|
|
|
});
|
|
|
return _this.sessionManager;
|
|
|
}).catch(function (e) {
|
|
@@ -22163,36 +22253,22 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
|
- * Updates the global position of the camera by moving the camera's container
|
|
|
- * This should be used instead of modifying the camera's position as it will be overwritten by an xrSessions's update frame
|
|
|
- * @param position The desired global position of the camera
|
|
|
- */
|
|
|
- WebXRExperienceHelper.prototype.setPositionOfCameraUsingContainer = function (position) {
|
|
|
- this.camera.globalPosition.subtractToRef(position, WebXRExperienceHelper._TmpVector);
|
|
|
- this.container.position.subtractInPlace(WebXRExperienceHelper._TmpVector);
|
|
|
- };
|
|
|
- /**
|
|
|
- * Rotates the xr camera by rotating the camera's container around the camera's position
|
|
|
- * This should be used instead of modifying the camera's rotation as it will be overwritten by an xrSessions's update frame
|
|
|
- * @param rotation the desired quaternion rotation to apply to the camera
|
|
|
- */
|
|
|
- WebXRExperienceHelper.prototype.rotateCameraByQuaternionUsingContainer = function (rotation) {
|
|
|
- if (!this.container.rotationQuaternion) {
|
|
|
- this.container.rotationQuaternion = _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromEulerVector(this.container.rotation);
|
|
|
- }
|
|
|
- this.container.rotationQuaternion.multiplyInPlace(rotation);
|
|
|
- this.container.position.rotateByQuaternionAroundPointToRef(rotation, this.camera.globalPosition, this.container.position);
|
|
|
- };
|
|
|
- /**
|
|
|
* Disposes of the experience helper
|
|
|
*/
|
|
|
WebXRExperienceHelper.prototype.dispose = function () {
|
|
|
this.camera.dispose();
|
|
|
- this.container.dispose();
|
|
|
this.onStateChangedObservable.clear();
|
|
|
this.sessionManager.dispose();
|
|
|
};
|
|
|
- WebXRExperienceHelper._TmpVector = new _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Vector3"]();
|
|
|
+ WebXRExperienceHelper.prototype._nonXRToXRCamera = function () {
|
|
|
+ this.scene.activeCamera = this.camera;
|
|
|
+ var mat = this._nonVRCamera.computeWorldMatrix();
|
|
|
+ mat.decompose(undefined, this.camera.rotationQuaternion, this.camera.position);
|
|
|
+ // set the ground level
|
|
|
+ this.camera.position.y = 0;
|
|
|
+ _Maths_math_vector__WEBPACK_IMPORTED_MODULE_1__["Quaternion"].FromEulerAnglesToRef(0, this.camera.rotationQuaternion.toEulerAngles().y, 0, this.camera.rotationQuaternion);
|
|
|
+ this.onInitialXRPoseSetObservable.notifyObservers(this.camera);
|
|
|
+ };
|
|
|
return WebXRExperienceHelper;
|
|
|
}());
|
|
|
|
|
@@ -22517,7 +22593,7 @@ var WebXRInput = /** @class */ (function () {
|
|
|
for (var _i = 0, addInputs_1 = addInputs; _i < addInputs_1.length; _i++) {
|
|
|
var input = addInputs_1[_i];
|
|
|
if (sources.indexOf(input) === -1) {
|
|
|
- var controller = new _webXRController__WEBPACK_IMPORTED_MODULE_1__["WebXRController"](this.baseExperience.camera._scene, input, this.baseExperience.container);
|
|
|
+ var controller = new _webXRController__WEBPACK_IMPORTED_MODULE_1__["WebXRController"](this.baseExperience.camera._scene, input);
|
|
|
this.controllers.push(controller);
|
|
|
this.onControllerAddedObservable.notifyObservers(controller);
|
|
|
}
|
|
@@ -22745,6 +22821,11 @@ var WebXRSessionManager = /** @class */ (function () {
|
|
|
* Fires when the xr session is ended either by the device or manually done
|
|
|
*/
|
|
|
this.onXRSessionInit = new _Misc_observable__WEBPACK_IMPORTED_MODULE_1__["Observable"]();
|
|
|
+ /**
|
|
|
+ * Used just in case of a failure to initialize an immersive session.
|
|
|
+ * The viewer reference space is compensated using this height, creating a kind of "viewer-floor" reference space
|
|
|
+ */
|
|
|
+ this.defaultHeightCompensation = 1.7;
|
|
|
/** WebXR timestamp updated every frame */
|
|
|
this.currentTimestamp = -1;
|
|
|
this.baseLayer = null;
|
|
@@ -22800,17 +22881,24 @@ var WebXRSessionManager = /** @class */ (function () {
|
|
|
WebXRSessionManager.prototype.setReferenceSpaceAsync = function (referenceSpace) {
|
|
|
var _this = this;
|
|
|
return this.session.requestReferenceSpace(referenceSpace).then(function (referenceSpace) {
|
|
|
- _this.referenceSpace = referenceSpace;
|
|
|
+ return referenceSpace;
|
|
|
}, function (rejectionReason) {
|
|
|
_Misc_logger__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error("XR.requestReferenceSpace failed for the following reason: ");
|
|
|
_Misc_logger__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error(rejectionReason);
|
|
|
_Misc_logger__WEBPACK_IMPORTED_MODULE_0__["Logger"].Log("Defaulting to universally-supported \"viewer\" reference space type.");
|
|
|
return _this.session.requestReferenceSpace("viewer").then(function (referenceSpace) {
|
|
|
- _this.referenceSpace = referenceSpace;
|
|
|
+ var heightCompensation = new XRRigidTransform({ x: 0, y: -_this.defaultHeightCompensation, z: 0 });
|
|
|
+ return referenceSpace.getOffsetReferenceSpace(heightCompensation);
|
|
|
}, function (rejectionReason) {
|
|
|
_Misc_logger__WEBPACK_IMPORTED_MODULE_0__["Logger"].Error(rejectionReason);
|
|
|
throw "XR initialization failed: required \"viewer\" reference space type not supported.";
|
|
|
});
|
|
|
+ }).then(function (referenceSpace) {
|
|
|
+ // initialize the base and offset (currently the same)
|
|
|
+ _this.referenceSpace = _this.baseReferenceSpace = referenceSpace;
|
|
|
+ _this.session.requestReferenceSpace("viewer").then(function (referenceSpace) {
|
|
|
+ _this.viewerReferenceSpace = referenceSpace;
|
|
|
+ });
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
@@ -22842,8 +22930,9 @@ var WebXRSessionManager = /** @class */ (function () {
|
|
|
_this.currentTimestamp = timestamp;
|
|
|
if (xrFrame) {
|
|
|
_this.onXRFrameObservable.notifyObservers(xrFrame);
|
|
|
+ // only run the render loop if a frame exists
|
|
|
+ _this.scene.getEngine()._renderLoop();
|
|
|
}
|
|
|
- _this.scene.getEngine()._renderLoop();
|
|
|
}
|
|
|
};
|
|
|
if (this._xrNavigator.xr.native) {
|
|
@@ -58413,6 +58502,11 @@ var DirectionalLight = /** @class */ (function (_super) {
|
|
|
* on each frame.
|
|
|
*/
|
|
|
_this.autoUpdateExtends = true;
|
|
|
+ /**
|
|
|
+ * Automatically compute the shadowMinZ and shadowMaxZ for the projection matrix to best fit (including all the casters)
|
|
|
+ * on each frame. autoUpdateExtends must be set to true for this to work
|
|
|
+ */
|
|
|
+ _this.autoCalcShadowZBounds = false;
|
|
|
// Cache
|
|
|
_this._orthoLeft = Number.MAX_VALUE;
|
|
|
_this._orthoRight = Number.MIN_VALUE;
|
|
@@ -58513,6 +58607,8 @@ var DirectionalLight = /** @class */ (function (_super) {
|
|
|
this._orthoRight = Number.MIN_VALUE;
|
|
|
this._orthoTop = Number.MIN_VALUE;
|
|
|
this._orthoBottom = Number.MAX_VALUE;
|
|
|
+ var shadowMinZ = Number.MAX_VALUE;
|
|
|
+ var shadowMaxZ = Number.MIN_VALUE;
|
|
|
for (var meshIndex = 0; meshIndex < renderList.length; meshIndex++) {
|
|
|
var mesh = renderList[meshIndex];
|
|
|
if (!mesh) {
|
|
@@ -58534,8 +58630,20 @@ var DirectionalLight = /** @class */ (function (_super) {
|
|
|
if (tempVector3.y > this._orthoTop) {
|
|
|
this._orthoTop = tempVector3.y;
|
|
|
}
|
|
|
+ if (this.autoCalcShadowZBounds) {
|
|
|
+ if (tempVector3.z < shadowMinZ) {
|
|
|
+ shadowMinZ = tempVector3.z;
|
|
|
+ }
|
|
|
+ if (tempVector3.z > shadowMaxZ) {
|
|
|
+ shadowMaxZ = tempVector3.z;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if (this.autoCalcShadowZBounds) {
|
|
|
+ this._shadowMinZ = shadowMinZ;
|
|
|
+ this._shadowMaxZ = shadowMaxZ;
|
|
|
+ }
|
|
|
}
|
|
|
var xOffset = this._orthoRight - this._orthoLeft;
|
|
|
var yOffset = this._orthoTop - this._orthoBottom;
|
|
@@ -58635,6 +58743,9 @@ var DirectionalLight = /** @class */ (function (_super) {
|
|
|
Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
|
|
|
Object(_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
|
|
|
], DirectionalLight.prototype, "autoUpdateExtends", void 0);
|
|
|
+ Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"])([
|
|
|
+ Object(_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__["serialize"])()
|
|
|
+ ], DirectionalLight.prototype, "autoCalcShadowZBounds", void 0);
|
|
|
return DirectionalLight;
|
|
|
}(_shadowLight__WEBPACK_IMPORTED_MODULE_5__["ShadowLight"]));
|
|
|
|
|
@@ -73993,24 +74104,29 @@ var NodeMaterial = /** @class */ (function (_super) {
|
|
|
* Serializes this material in a JSON representation
|
|
|
* @returns the serialized material object
|
|
|
*/
|
|
|
- NodeMaterial.prototype.serialize = function () {
|
|
|
- var serializationObject = _Misc_decorators__WEBPACK_IMPORTED_MODULE_17__["SerializationHelper"].Serialize(this);
|
|
|
- serializationObject.customType = "BABYLON.NodeMaterial";
|
|
|
- serializationObject.outputNodes = [];
|
|
|
+ NodeMaterial.prototype.serialize = function (selectedBlocks) {
|
|
|
+ var serializationObject = selectedBlocks ? {} : _Misc_decorators__WEBPACK_IMPORTED_MODULE_17__["SerializationHelper"].Serialize(this);
|
|
|
serializationObject.editorData = JSON.parse(JSON.stringify(this.editorData)); // Copy
|
|
|
var blocks = [];
|
|
|
- // Outputs
|
|
|
- for (var _i = 0, _a = this._vertexOutputNodes; _i < _a.length; _i++) {
|
|
|
- var outputNode = _a[_i];
|
|
|
- this._gatherBlocks(outputNode, blocks);
|
|
|
- serializationObject.outputNodes.push(outputNode.uniqueId);
|
|
|
+ if (selectedBlocks) {
|
|
|
+ blocks = selectedBlocks;
|
|
|
}
|
|
|
- for (var _b = 0, _c = this._fragmentOutputNodes; _b < _c.length; _b++) {
|
|
|
- var outputNode = _c[_b];
|
|
|
- this._gatherBlocks(outputNode, blocks);
|
|
|
- if (serializationObject.outputNodes.indexOf(outputNode.uniqueId) === -1) {
|
|
|
+ else {
|
|
|
+ serializationObject.customType = "BABYLON.NodeMaterial";
|
|
|
+ serializationObject.outputNodes = [];
|
|
|
+ // Outputs
|
|
|
+ for (var _i = 0, _a = this._vertexOutputNodes; _i < _a.length; _i++) {
|
|
|
+ var outputNode = _a[_i];
|
|
|
+ this._gatherBlocks(outputNode, blocks);
|
|
|
serializationObject.outputNodes.push(outputNode.uniqueId);
|
|
|
}
|
|
|
+ for (var _b = 0, _c = this._fragmentOutputNodes; _b < _c.length; _b++) {
|
|
|
+ var outputNode = _c[_b];
|
|
|
+ this._gatherBlocks(outputNode, blocks);
|
|
|
+ if (serializationObject.outputNodes.indexOf(outputNode.uniqueId) === -1) {
|
|
|
+ serializationObject.outputNodes.push(outputNode.uniqueId);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
// Blocks
|
|
|
serializationObject.blocks = [];
|
|
@@ -74018,12 +74134,14 @@ var NodeMaterial = /** @class */ (function (_super) {
|
|
|
var block = blocks_1[_d];
|
|
|
serializationObject.blocks.push(block.serialize());
|
|
|
}
|
|
|
- for (var _e = 0, _f = this.attachedBlocks; _e < _f.length; _e++) {
|
|
|
- var block = _f[_e];
|
|
|
- if (blocks.indexOf(block) !== -1) {
|
|
|
- continue;
|
|
|
+ if (!selectedBlocks) {
|
|
|
+ for (var _e = 0, _f = this.attachedBlocks; _e < _f.length; _e++) {
|
|
|
+ var block = _f[_e];
|
|
|
+ if (blocks.indexOf(block) !== -1) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ serializationObject.blocks.push(block.serialize());
|
|
|
}
|
|
|
- serializationObject.blocks.push(block.serialize());
|
|
|
}
|
|
|
return serializationObject;
|
|
|
};
|
|
@@ -100836,6 +100954,16 @@ var Vector3 = /** @class */ (function () {
|
|
|
return new Vector3(-this.x, -this.y, -this.z);
|
|
|
};
|
|
|
/**
|
|
|
+ * Negate this vector in place
|
|
|
+ * @returns this
|
|
|
+ */
|
|
|
+ Vector3.prototype.negateInPlace = function () {
|
|
|
+ this.x *= -1;
|
|
|
+ this.y *= -1;
|
|
|
+ this.z *= -1;
|
|
|
+ return this;
|
|
|
+ };
|
|
|
+ /**
|
|
|
* Multiplies the Vector3 coordinates by the float "scale"
|
|
|
* @param scale defines the multiplier factor
|
|
|
* @returns the current updated Vector3
|
|
@@ -102555,6 +102683,20 @@ var Quaternion = /** @class */ (function () {
|
|
|
return otherQuaternion && this.x === otherQuaternion.x && this.y === otherQuaternion.y && this.z === otherQuaternion.z && this.w === otherQuaternion.w;
|
|
|
};
|
|
|
/**
|
|
|
+ * Gets a boolean if two quaternions are equals (using an epsilon value)
|
|
|
+ * @param otherQuaternion defines the other quaternion
|
|
|
+ * @param epsilon defines the minimal distance to consider equality
|
|
|
+ * @returns true if the given quaternion coordinates are close to the current ones by a distance of epsilon.
|
|
|
+ */
|
|
|
+ Quaternion.prototype.equalsWithEpsilon = function (otherQuaternion, epsilon) {
|
|
|
+ if (epsilon === void 0) { epsilon = _math_constants__WEBPACK_IMPORTED_MODULE_1__["Epsilon"]; }
|
|
|
+ return otherQuaternion
|
|
|
+ && _math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(this.x, otherQuaternion.x, epsilon)
|
|
|
+ && _math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(this.y, otherQuaternion.y, epsilon)
|
|
|
+ && _math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(this.z, otherQuaternion.z, epsilon)
|
|
|
+ && _math_scalar__WEBPACK_IMPORTED_MODULE_0__["Scalar"].WithinEpsilon(this.w, otherQuaternion.w, epsilon);
|
|
|
+ };
|
|
|
+ /**
|
|
|
* Clone the current quaternion
|
|
|
* @returns a new quaternion copied from the current one
|
|
|
*/
|