|
@@ -21780,17 +21780,26 @@ var WebXRPlaneDetector = /** @class */ (function (_super) {
|
|
|
_this._detectedPlanes = [];
|
|
|
_this._lastFrameDetected = new Set();
|
|
|
if (_this._xrSessionManager.session) {
|
|
|
- _this._xrSessionManager.session.updateWorldTrackingState({ planeDetectionState: { enabled: true } });
|
|
|
- _this._enabled = true;
|
|
|
+ _this._init();
|
|
|
}
|
|
|
else {
|
|
|
_this._xrSessionManager.onXRSessionInit.addOnce(function () {
|
|
|
- _this._xrSessionManager.session.updateWorldTrackingState({ planeDetectionState: { enabled: true } });
|
|
|
- _this._enabled = true;
|
|
|
+ _this._init();
|
|
|
});
|
|
|
}
|
|
|
return _this;
|
|
|
}
|
|
|
+ WebXRPlaneDetector.prototype._init = function () {
|
|
|
+ if (!this._xrSessionManager.session.updateWorldTrackingState) {
|
|
|
+ // fail silently
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._xrSessionManager.session.updateWorldTrackingState({ planeDetectionState: { enabled: true } });
|
|
|
+ this._enabled = true;
|
|
|
+ if (this._detectedPlanes.length) {
|
|
|
+ this._detectedPlanes = [];
|
|
|
+ }
|
|
|
+ };
|
|
|
WebXRPlaneDetector.prototype._onXRFrame = function (frame) {
|
|
|
var _this = this;
|
|
|
if (!this.attached || !this._enabled || !frame) {
|
|
@@ -23487,6 +23496,11 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
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;
|
|
|
+ /**
|
|
|
+ * Should position compensation execute on first frame.
|
|
|
+ * This is used when copying the position from a native (non XR) camera
|
|
|
+ */
|
|
|
+ _this.compensateOnFirstFrame = true;
|
|
|
_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();
|
|
@@ -23502,7 +23516,7 @@ var WebXRCamera = /** @class */ (function (_super) {
|
|
|
_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;
|
|
|
+ _this._firstFrame = _this.compensateOnFirstFrame;
|
|
|
});
|
|
|
// Check transformation changes on each frame. Callback is added to be first so that the transformation will be
|
|
|
// applied to the rest of the elements using the referenceSpace object
|
|
@@ -23895,6 +23909,9 @@ var WebXRDefaultExperience = /** @class */ (function () {
|
|
|
// Create base experience
|
|
|
return _webXRExperienceHelper__WEBPACK_IMPORTED_MODULE_0__["WebXRExperienceHelper"].CreateAsync(scene).then(function (xrHelper) {
|
|
|
result.baseExperience = xrHelper;
|
|
|
+ if (options.ignoreNativeCameraTransformation) {
|
|
|
+ result.baseExperience.camera.compensateOnFirstFrame = false;
|
|
|
+ }
|
|
|
// Add controller support
|
|
|
result.input = new _webXRInput__WEBPACK_IMPORTED_MODULE_1__["WebXRInput"](xrHelper.sessionManager, xrHelper.camera, options.inputOptions);
|
|
|
result.pointerSelection = result.baseExperience.featuresManager.enableFeature(_features_WebXRControllerPointerSelection__WEBPACK_IMPORTED_MODULE_2__["WebXRControllerPointerSelection"].Name, "latest", {
|
|
@@ -24170,6 +24187,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
/* harmony import */ var _webXRCamera__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./webXRCamera */ "./Cameras/XR/webXRCamera.ts");
|
|
|
/* harmony import */ var _webXRTypes__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./webXRTypes */ "./Cameras/XR/webXRTypes.ts");
|
|
|
/* harmony import */ var _webXRFeaturesManager__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./webXRFeaturesManager */ "./Cameras/XR/webXRFeaturesManager.ts");
|
|
|
+/* harmony import */ var _Misc_logger__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../Misc/logger */ "./Misc/logger.ts");
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -24255,14 +24274,21 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
var _this = this;
|
|
|
if (renderTarget === void 0) { renderTarget = this.sessionManager.getWebXRRenderTarget(); }
|
|
|
if (!this._supported) {
|
|
|
- throw "XR not available";
|
|
|
+ throw "WebXR not supported";
|
|
|
}
|
|
|
this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_3__["WebXRState"].ENTERING_XR);
|
|
|
var sessionCreationOptions = {
|
|
|
optionalFeatures: (referenceSpaceType !== "viewer" && referenceSpaceType !== "local") ? [referenceSpaceType] : []
|
|
|
};
|
|
|
+ // we currently recommend "local" space in AR
|
|
|
+ if (sessionMode === "immersive-ar" && referenceSpaceType !== "local") {
|
|
|
+ _Misc_logger__WEBPACK_IMPORTED_MODULE_5__["Logger"].Warn("We recommend using 'local' reference space type when using 'immersive-ar' session mode");
|
|
|
+ }
|
|
|
// make sure that the session mode is supported
|
|
|
- return this.sessionManager.isSessionSupportedAsync(sessionMode).then(function () {
|
|
|
+ return this.sessionManager.isSessionSupportedAsync(sessionMode).then(function (supported) {
|
|
|
+ if (!supported) {
|
|
|
+ throw new Error("Session mode \"" + sessionMode + "\" not supported in browser");
|
|
|
+ }
|
|
|
return _this.sessionManager.initializeSessionAsync(sessionMode, sessionCreationOptions);
|
|
|
}).then(function () {
|
|
|
return _this.sessionManager.setReferenceSpaceTypeAsync(referenceSpaceType);
|
|
@@ -24278,7 +24304,14 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
_this._nonVRCamera = _this.scene.activeCamera;
|
|
|
// Overwrite current scene settings
|
|
|
_this.scene.autoClear = false;
|
|
|
- _this._nonXRToXRCamera();
|
|
|
+ _this.scene.activeCamera = _this.camera;
|
|
|
+ // do not compensate when AR session is used
|
|
|
+ if (sessionMode !== 'immersive-ar') {
|
|
|
+ _this._nonXRToXRCamera();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _this.camera.compensateOnFirstFrame = false;
|
|
|
+ }
|
|
|
_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) {
|
|
@@ -24287,11 +24320,13 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
// Restore scene settings
|
|
|
_this.scene.autoClear = _this._originalSceneAutoClear;
|
|
|
_this.scene.activeCamera = _this._nonVRCamera;
|
|
|
- if (_this._nonVRCamera.setPosition) {
|
|
|
- _this._nonVRCamera.setPosition(_this.camera.position);
|
|
|
- }
|
|
|
- else {
|
|
|
- _this._nonVRCamera.position.copyFrom(_this.camera.position);
|
|
|
+ if (sessionMode !== 'immersive-ar' && _this.camera.compensateOnFirstFrame) {
|
|
|
+ if (_this._nonVRCamera.setPosition) {
|
|
|
+ _this._nonVRCamera.setPosition(_this.camera.position);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _this._nonVRCamera.position.copyFrom(_this.camera.position);
|
|
|
+ }
|
|
|
}
|
|
|
_this._setState(_webXRTypes__WEBPACK_IMPORTED_MODULE_3__["WebXRState"].NOT_IN_XR);
|
|
|
});
|
|
@@ -24320,7 +24355,6 @@ var WebXRExperienceHelper = /** @class */ (function () {
|
|
|
}
|
|
|
};
|
|
|
WebXRExperienceHelper.prototype._nonXRToXRCamera = function () {
|
|
|
- this.scene.activeCamera = this.camera;
|
|
|
this.camera.setTransformationFromNonVRCamera(this._nonVRCamera);
|
|
|
this.onInitialXRPoseSetObservable.notifyObservers(this.camera);
|
|
|
};
|
|
@@ -25105,7 +25139,7 @@ var WebXRSessionManager = /** @class */ (function () {
|
|
|
/**
|
|
|
* Checks if a session would be supported for the creation options specified
|
|
|
* @param sessionMode session mode to check if supported eg. immersive-vr
|
|
|
- * @returns true if supported
|
|
|
+ * @returns A Promise that resolves to true if supported and false if not
|
|
|
*/
|
|
|
WebXRSessionManager.prototype.isSessionSupportedAsync = function (sessionMode) {
|
|
|
return WebXRSessionManager.IsSessionSupportedAsync(sessionMode);
|
|
@@ -25176,8 +25210,9 @@ var WebXRSessionManager = /** @class */ (function () {
|
|
|
return Promise.resolve(false);
|
|
|
}
|
|
|
else {
|
|
|
- return functionToUse.call(navigator.xr, sessionMode).then(function () {
|
|
|
- return Promise.resolve(true);
|
|
|
+ return functionToUse.call(navigator.xr, sessionMode).then(function (result) {
|
|
|
+ var returnValue = (typeof result === "undefined") ? true : result;
|
|
|
+ return Promise.resolve(returnValue);
|
|
|
}).catch(function (e) {
|
|
|
_Misc_logger__WEBPACK_IMPORTED_MODULE_0__["Logger"].Warn(e);
|
|
|
return Promise.resolve(false);
|
|
@@ -70044,6 +70079,7 @@ var InstancesBlock = /** @class */ (function (_super) {
|
|
|
_this.registerInput("world3", _Enums_nodeMaterialBlockConnectionPointTypes__WEBPACK_IMPORTED_MODULE_3__["NodeMaterialBlockConnectionPointTypes"].Vector4);
|
|
|
_this.registerInput("world", _Enums_nodeMaterialBlockConnectionPointTypes__WEBPACK_IMPORTED_MODULE_3__["NodeMaterialBlockConnectionPointTypes"].Matrix, true);
|
|
|
_this.registerOutput("output", _Enums_nodeMaterialBlockConnectionPointTypes__WEBPACK_IMPORTED_MODULE_3__["NodeMaterialBlockConnectionPointTypes"].Matrix);
|
|
|
+ _this.registerOutput("instanceID", _Enums_nodeMaterialBlockConnectionPointTypes__WEBPACK_IMPORTED_MODULE_3__["NodeMaterialBlockConnectionPointTypes"].Float);
|
|
|
return _this;
|
|
|
}
|
|
|
/**
|
|
@@ -70113,6 +70149,16 @@ var InstancesBlock = /** @class */ (function (_super) {
|
|
|
enumerable: true,
|
|
|
configurable: true
|
|
|
});
|
|
|
+ Object.defineProperty(InstancesBlock.prototype, "instanceID", {
|
|
|
+ /**
|
|
|
+ * Gets the isntanceID component
|
|
|
+ */
|
|
|
+ get: function () {
|
|
|
+ return this._outputs[1];
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
InstancesBlock.prototype.autoConfigure = function (material) {
|
|
|
if (!this.world0.connectedPoint) {
|
|
|
var world0Input = material.getInputBlockByPredicate(function (b) { return b.isAttribute && b.name === "world0"; });
|
|
@@ -70173,14 +70219,17 @@ var InstancesBlock = /** @class */ (function (_super) {
|
|
|
state.sharedData.blocksWithDefines.push(this);
|
|
|
// Emit code
|
|
|
var output = this._outputs[0];
|
|
|
+ var instanceID = this._outputs[1];
|
|
|
var world0 = this.world0;
|
|
|
var world1 = this.world1;
|
|
|
var world2 = this.world2;
|
|
|
var world3 = this.world3;
|
|
|
state.compilationString += "#ifdef INSTANCES\r\n";
|
|
|
state.compilationString += this._declareOutput(output, state) + (" = mat4(" + world0.associatedVariableName + ", " + world1.associatedVariableName + ", " + world2.associatedVariableName + ", " + world3.associatedVariableName + ");\r\n");
|
|
|
+ state.compilationString += this._declareOutput(instanceID, state) + " = float(gl_InstanceID);\r\n";
|
|
|
state.compilationString += "#else\r\n";
|
|
|
state.compilationString += this._declareOutput(output, state) + (" = " + this.world.associatedVariableName + ";\r\n");
|
|
|
+ state.compilationString += this._declareOutput(instanceID, state) + " = 0.0;\r\n";
|
|
|
state.compilationString += "#endif\r\n";
|
|
|
return this;
|
|
|
};
|