|
@@ -1,12 +1,16 @@
|
|
|
import { Nullable } from "../../types";
|
|
|
-import { WebXRExperienceHelper, WebXRState } from "./webXRExperienceHelper";
|
|
|
-import { WebXROutputTarget } from "./webXROutputTarget";
|
|
|
+import { Observable } from "../../Misc/observable";
|
|
|
+import { ThinEngine } from '../../Engines/thinEngine';
|
|
|
+import { WebXRState, WebXRRenderTarget } from "./webXRTypes";
|
|
|
|
|
|
/**
|
|
|
* Creates a canvas that is added/removed from the webpage when entering/exiting XR
|
|
|
*/
|
|
|
-export class WebXRManagedOutputCanvas implements WebXROutputTarget {
|
|
|
+export class WebXRManagedOutputCanvas implements WebXRRenderTarget {
|
|
|
+
|
|
|
+ private _engine: ThinEngine;
|
|
|
private _canvas: Nullable<HTMLCanvasElement> = null;
|
|
|
+
|
|
|
/**
|
|
|
* xrpresent context of the canvas which can be used to display/mirror xr content
|
|
|
*/
|
|
@@ -29,20 +33,21 @@ export class WebXRManagedOutputCanvas implements WebXROutputTarget {
|
|
|
|
|
|
/**
|
|
|
* Initializes the canvas to be added/removed upon entering/exiting xr
|
|
|
- * @param helper the xr experience helper used to trigger adding/removing of the canvas
|
|
|
+ * @param engine the Babylon engine
|
|
|
+ * @param onStateChangedObservable the mechanism by which the canvas will be added/removed based on XR state
|
|
|
* @param canvas The canvas to be added/removed (If not specified a full screen canvas will be created)
|
|
|
*/
|
|
|
- constructor(private helper: WebXRExperienceHelper, canvas?: HTMLCanvasElement) {
|
|
|
+ constructor(engine: ThinEngine, onStateChangedObservable: Observable<WebXRState>, canvas?: HTMLCanvasElement) {
|
|
|
if (!canvas) {
|
|
|
canvas = document.createElement('canvas');
|
|
|
canvas.style.cssText = "position:absolute; bottom:0px;right:0px;z-index:10;width:90%;height:100%;background-color: #000000;";
|
|
|
}
|
|
|
this._setManagedOutputCanvas(canvas);
|
|
|
- helper.onStateChangedObservable.add((stateInfo) => {
|
|
|
+ onStateChangedObservable.add((stateInfo) => {
|
|
|
if (stateInfo == WebXRState.ENTERING_XR) {
|
|
|
// The canvas is added to the screen before entering XR because currently the xr session must be initialized while the canvas is added render properly
|
|
|
this._addCanvas();
|
|
|
- } else if (helper.state == WebXRState.NOT_IN_XR) {
|
|
|
+ } else if (stateInfo == WebXRState.NOT_IN_XR) {
|
|
|
this._removeCanvas();
|
|
|
}
|
|
|
});
|
|
@@ -70,13 +75,13 @@ export class WebXRManagedOutputCanvas implements WebXROutputTarget {
|
|
|
}
|
|
|
|
|
|
private _addCanvas() {
|
|
|
- if (this._canvas && this._canvas !== this.helper.container.getScene().getEngine().getRenderingCanvas()) {
|
|
|
+ if (this._canvas && this._canvas !== this._engine.getRenderingCanvas()) {
|
|
|
document.body.appendChild(this._canvas);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private _removeCanvas() {
|
|
|
- if (this._canvas && document.body.contains(this._canvas) && this._canvas !== this.helper.container.getScene().getEngine().getRenderingCanvas()) {
|
|
|
+ if (this._canvas && document.body.contains(this._canvas) && this._canvas !== this._engine.getRenderingCanvas()) {
|
|
|
document.body.removeChild(this._canvas);
|
|
|
}
|
|
|
}
|