Needle Engine

Changes between version 4.1.0-beta.9 and 4.1.0
Files changed (1) hide show
  1. src/engine-components/webxr/WebXR.ts +23 -14
src/engine-components/webxr/WebXR.ts CHANGED
@@ -227,23 +227,32 @@
227
227
  XRState.Global.Set(isVR ? XRStateFlag.VR : XRStateFlag.AR);
228
228
 
229
229
  // Handle AR session root
230
- if (this.usePlacementReticle && args.xr.isAR) {
230
+ if (args.xr.isAR) {
231
231
  let sessionroot = GameObject.findObjectOfType(WebARSessionRoot);
232
+ // Only create a WebARSessionRoot if none is in the scene already
232
233
  if (!sessionroot) {
233
- const implicitSessionRoot = new Object3D();
234
- for (const ch of this.context.scene.children)
235
- implicitSessionRoot.add(ch);
236
- this.context.scene.add(implicitSessionRoot);
237
- sessionroot = GameObject.addComponent(implicitSessionRoot, WebARSessionRoot)!;
238
- this._createdComponentsInSession.push(sessionroot);
234
+ if (this.usePlacementReticle) {
235
+ const implicitSessionRoot = new Object3D();
236
+ for (const ch of this.context.scene.children)
237
+ implicitSessionRoot.add(ch);
238
+ this.context.scene.add(implicitSessionRoot);
239
+ sessionroot = GameObject.addComponent(implicitSessionRoot, WebARSessionRoot)!;
240
+ this._createdComponentsInSession.push(sessionroot);
241
+ }
242
+ else if (debug || isDevEnvironment()) {
243
+ console.warn("WebXR: No WebARSessionRoot found in scene and usePlacementReticle is disabled in WebXR component.")
244
+ }
239
245
  }
240
-
241
- sessionroot.customReticle = this.customARPlacementReticle;
242
- sessionroot.arScale = this.arScale;
243
- sessionroot.arTouchTransform = this.usePlacementAdjustment;
244
- sessionroot.autoPlace = this.autoPlace;
245
- sessionroot.autoCenter = this.autoCenter;
246
- sessionroot.useXRAnchor = this.useXRAnchor;
246
+
247
+ if (sessionroot) {
248
+ // sessionroot.enabled = this.usePlacementReticle; // < not sure if we want to disable the session root when placement reticle if OFF...
249
+ sessionroot.customReticle = this.customARPlacementReticle;
250
+ sessionroot.arScale = this.arScale;
251
+ sessionroot.arTouchTransform = this.usePlacementAdjustment;
252
+ sessionroot.autoPlace = this.autoPlace;
253
+ sessionroot.autoCenter = this.autoCenter;
254
+ sessionroot.useXRAnchor = this.useXRAnchor;
255
+ }
247
256
  }
248
257
 
249
258
  // handle VR controls