Needle Engine

Changes between version 3.32.4-alpha and 3.32.5-alpha
Files changed (6) hide show
  1. src/engine/xr/NeedleXRController.ts +1 -1
  2. src/engine/xr/NeedleXRSession.ts +9 -3
  3. src/engine-components/webxr/WebARSessionRoot.ts +4 -0
  4. src/engine-components/webxr/WebXR.ts +1 -0
  5. src/engine-components/webxr/WebXRRig.ts +1 -0
  6. src/engine-components/webxr/controllers/XRControllerMovement.ts +4 -2
src/engine/xr/NeedleXRController.ts CHANGED
@@ -456,7 +456,7 @@
456
456
  }
457
457
  }
458
458
  }
459
- if (debug) console.log(this._layout, this.inputSource);
459
+ // if (debug) console.log(this._layout, this.inputSource);
460
460
  // debugger;
461
461
  // this.getButton("a-button")
462
462
  return this._motioncontroller;
src/engine/xr/NeedleXRSession.ts CHANGED
@@ -375,8 +375,11 @@
375
375
  controller_removed: this._controllerRemovedListeners,
376
376
  init: init
377
377
  });
378
- session.addEventListener("end", this.onEnd)
379
- console.log("%c" + `Started ${mode} session`, "font-weight:bold;");
378
+ session.addEventListener("end", this.onEnd);
379
+ if (debug)
380
+ console.log("%c" + `Started ${mode} session`, "font-weight:bold;", scripts);
381
+ else
382
+ console.log("%c" + `Started ${mode} session`, "font-weight:bold;");
380
383
  return this._activeSession;
381
384
  }
382
385
  /** stops the active XR session */
@@ -901,7 +904,10 @@
901
904
  }
902
905
 
903
906
  // invoke session listeners start
904
- for (const script of this._xr_scripts) {
907
+ // we need to make a copy because the array might be modified during the loop (could also use a for loop and iterate backwards perhaps but then order of invocation would be changed OR check if the size has changed...)
908
+ const copy = [...this._xr_scripts];
909
+ if (debug) console.log("NeedleXRSession start, handle scripts:", copy);
910
+ for (const script of copy) {
905
911
  if (script.destroyed) {
906
912
  this._script_to_remove.push(script);
907
913
  continue;
src/engine-components/webxr/WebARSessionRoot.ts CHANGED
@@ -99,6 +99,7 @@
99
99
  const rootObject = new Object3D();
100
100
  this._createdPlacementObject = rootObject;
101
101
  rootObject.name = "AR Session Root";
102
+ this._placementScene.name = "AR Placement Scene";
102
103
  this._placementScene.children.length = 0;
103
104
  for (let i = this.context.scene.children.length - 1; i >= 0; i--) {
104
105
  const ch = this.context.scene.children[i];
@@ -136,6 +137,7 @@
136
137
  }
137
138
  onUpdateXR(args: NeedleXREventArgs): void {
138
139
 
140
+ // disable session placement while images are being tracked
139
141
  if (args.xr.isTrackingImages) {
140
142
  for (const ret of this._reticle)
141
143
  ret.visible = false;
@@ -292,8 +294,10 @@
292
294
 
293
295
  private onRevertSceneChanges() {
294
296
  for (const ret of this._reticle) {
297
+ ret.visible = false;
295
298
  ret?.removeFromParent();
296
299
  }
300
+ this._reticle.length = 0;
297
301
 
298
302
  for (let i = this._placementScene.children.length - 1; i >= 0; i--) {
299
303
  const ch = this._placementScene.children[i];
src/engine-components/webxr/WebXR.ts CHANGED
@@ -175,6 +175,7 @@
175
175
  sessionroot.arTouchTransform = this.usePlacementAdjustment;
176
176
  sessionroot.useXRAnchor = this.useXRAnchor;
177
177
  }
178
+ else if(debug) console.log("WebXR: WebARSessionRoot already exists, not creating a new one")
178
179
  }
179
180
 
180
181
  // handle VR controls
src/engine-components/webxr/WebXRRig.ts CHANGED
@@ -47,6 +47,7 @@
47
47
  onEnterXR(args: NeedleXREventArgs): void {
48
48
  this._startScale = this.gameObject.scale.clone();
49
49
  args.xr.addRig(this);
50
+ if(debug) console.log("WebXR: add Rig", this.name, this.priority)
50
51
  }
51
52
  onLeaveXR(args: NeedleXREventArgs): void {
52
53
  args.xr.removeRig(this);
src/engine-components/webxr/controllers/XRControllerMovement.ts CHANGED
@@ -187,6 +187,8 @@
187
187
  const rot = ctrl.rayWorldQuaternion;
188
188
  line.position.copy(pos);
189
189
  line.quaternion.copy(rot);
190
+ const scale = session.rigScale;
191
+ line.scale.set(scale, scale, scale);
190
192
  line.visible = true;
191
193
  line.layers.disableAll();
192
194
  line.layers.enable(2);
@@ -204,7 +206,7 @@
204
206
 
205
207
  const hit = this.context.physics.raycastFromRay(ctrl.ray, {})[0];
206
208
  if (hit) {
207
- const rigScale = (session.rig?.gameObject.worldScale.x ?? 1);
209
+ const rigScale = (session.rigScale ?? 1);
208
210
  if (debug) Gizmos.DrawWireSphere(hit.point, .025 * rigScale, 0xff0000, .2);
209
211
 
210
212
  let disc = this._hitDiscs[i];
@@ -213,7 +215,7 @@
213
215
  this._hitDiscs[i] = disc;
214
216
  }
215
217
  disc.visible = true;
216
- const size = .01 * (1 + hit.distance) * rigScale;
218
+ const size = (.01 * (1 + hit.distance));
217
219
  disc.scale.set(size, size, size);
218
220
  disc.layers.disableAll();
219
221
  disc.layers.enable(2);