@needle-tools/engine 4.9.0-alpha.2 → 4.9.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -221,6 +221,8 @@ function handleAutoStart(value: string | null) {
221
221
  // });
222
222
  // }
223
223
 
224
+ const $initialFov = Symbol("initial-fov");
225
+
224
226
  /**
225
227
  * This class manages an XRSession to provide helper methods and events. It provides easy access to the XRInputSources (controllers and hands)
226
228
  * - Start a XRSession with `NeedleXRSession.start(...)`
@@ -914,6 +916,7 @@ export class NeedleXRSession implements INeedleXRSession {
914
916
  */
915
917
  private _mainCamera: ICamera | null = null;
916
918
 
919
+
917
920
  private constructor(mode: XRSessionMode, session: XRSession, context: Context, extra: {
918
921
  scripts: INeedleXRSessionEventReceiver[],
919
922
  controller_added: ControllerChangedEvt[],
@@ -954,6 +957,9 @@ export class NeedleXRSession implements INeedleXRSession {
954
957
  this._originalCameraWorldRotation = getWorldQuaternion(this.context.mainCamera, new Quaternion());
955
958
  this._originalCameraWorldScale = getWorldScale(this.context.mainCamera, new Vector3());
956
959
  this._originalCameraParent = this.context.mainCamera.parent;
960
+ if (this.context.mainCamera instanceof PerspectiveCamera) {
961
+ this.context.mainCamera[$initialFov] = this.context.mainCamera.fov;
962
+ }
957
963
  }
958
964
 
959
965
  this._defaultRig = new ImplictXRRig();
@@ -1058,7 +1064,7 @@ export class NeedleXRSession implements INeedleXRSession {
1058
1064
  if (debug) console.log("Disconnecting controller", oldController.index);
1059
1065
 
1060
1066
  const index = array.indexOf(oldController);
1061
- if(index >= 0) array.splice(index, 1);
1067
+ if (index >= 0) array.splice(index, 1);
1062
1068
 
1063
1069
  this.invokeControllerEvent(oldController, this._controllerRemoved, "removed");
1064
1070
  const args: NeedleXRControllerEventArgs = {
@@ -1161,6 +1167,11 @@ export class NeedleXRSession implements INeedleXRSession {
1161
1167
  if (this._originalCameraWorldScale) {
1162
1168
  setWorldScale(this.context.mainCamera, this._originalCameraWorldScale);
1163
1169
  }
1170
+
1171
+ if (this.context.mainCamera instanceof PerspectiveCamera && this.context.mainCamera[$initialFov]) {
1172
+ this.context.mainCamera.fov = this.context.mainCamera[$initialFov]!;
1173
+ this.context.mainCamera[$initialFov] = 0;
1174
+ }
1164
1175
  }
1165
1176
 
1166
1177
  // mark for size change since DPI might have changed
@@ -1564,7 +1575,7 @@ export class NeedleXRSession implements INeedleXRSession {
1564
1575
  if (this._camera instanceof PerspectiveCamera && Math.abs(this._camera.near - minNearPlane) > .0001) {
1565
1576
  this.originalCameraNearPlane = this._camera.near;
1566
1577
  this._camera.near = minNearPlane;
1567
- if(debug) console.debug(`Setting camera near plane to ${minNearPlane} (was ${this.originalCameraNearPlane}) to account for XR rendering scale`);
1578
+ if (debug) console.debug(`Setting camera near plane to ${minNearPlane} (was ${this.originalCameraNearPlane}) to account for XR rendering scale`);
1568
1579
  }
1569
1580
  }
1570
1581
  }
@@ -147,6 +147,7 @@ export abstract class GameObject extends Object3D implements Object3D, IGameObje
147
147
  * The forward direction vector of this GameObject in world space
148
148
  */
149
149
  abstract get worldForward(): Vector3;
150
+ abstract set worldForward(val: Vector3);
150
151
 
151
152
  /**
152
153
  * The right direction vector of this GameObject in world space
@@ -522,11 +522,15 @@ export class OrbitControls extends Behaviour implements ICameraController {
522
522
  if (debug) Gizmos.DrawWireSphere(hit.point, 0.1, 0xff0000, 2);
523
523
  this._controls?.target.copy(hits[0].point);
524
524
  }
525
+ else {
526
+ if (debug) console.log("OrbitControls: No hit found when updating target", { hits: [...hits] });
527
+ }
525
528
  }
526
529
 
527
530
  private _orbitStartAngle: number = 0;
528
531
  private _zoomStartDistance: number = 0;
529
532
  private onControlsChangeStarted = () => {
533
+ if(debug) console.debug("OrbitControls: Change started");
530
534
  if (this._controls) {
531
535
  this._orbitStartAngle = this._controls.getAzimuthalAngle() + this._controls.getPolarAngle();
532
536
  this._zoomStartDistance = this._controls.getDistance();
@@ -536,6 +540,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
536
540
  }
537
541
  }
538
542
  private onControlsChangeEnded = () => {
543
+ if(debug) console.debug("OrbitControls: Change ended", { autoTarget: this.autoTarget });
539
544
  if (this._controls) {
540
545
  if (this.autoTarget) {
541
546
  const newAngle = this._controls.getAzimuthalAngle() + this._controls.getPolarAngle();