Needle Engine

Changes between version 4.4.3-beta.1 and 4.4.3
Files changed (1) hide show
  1. src/engine-components/OrbitControls.ts +13 -5
src/engine-components/OrbitControls.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Box3Helper, Euler, Object3D, PerspectiveCamera, Quaternion, Ray, Vector2, Vector3, Vector3Like } from "three";
1
+ import { Box3Helper, Camera as Camera3, Euler, Object3D, PerspectiveCamera, Ray, Vector2, Vector3, Vector3Like } from "three";
2
2
  import { OrbitControls as ThreeOrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
3
3
 
4
4
  import { isDevEnvironment } from "../engine/debug/index.js";
@@ -449,7 +449,7 @@
449
449
  if (debug) console.debug("OrbitControls: No movement detected, updating target now");
450
450
  this.updateTargetNow();
451
451
  }
452
- else if(debug) console.debug("OrbitControls: Movement detected", delta);
452
+ else if (debug) console.debug("OrbitControls: Movement detected", delta);
453
453
  }
454
454
  }
455
455
 
@@ -506,7 +506,7 @@
506
506
  // if the look at target is set to the camera position we can't move at all anymore
507
507
  const distanceToCenter = Math.max(.01, worldPosition.length());
508
508
  const forward = new Vector3(0, 0, -distanceToCenter).applyMatrix4(camGo.threeCamera.matrixWorld);
509
- if(debug) Gizmos.DrawLine(worldPosition, forward, 0x5555ff, 10)
509
+ if (debug) Gizmos.DrawLine(worldPosition, forward, 0x5555ff, 10)
510
510
  this.setLookTargetPosition(forward, true);
511
511
  }
512
512
  if (!this.setLookTargetFromConstraint()) {
@@ -671,18 +671,26 @@
671
671
  */
672
672
  public setCameraAndLookTarget(source: Object3D | Camera, immediateOrDuration: number | boolean = false): boolean {
673
673
  if (!source) {
674
- if (isDevEnvironment()) console.warn("[OrbitControls] setCameraAndLookTarget target is null");
674
+ if (isDevEnvironment() || debug) console.warn("[OrbitControls] setCameraAndLookTarget target is null");
675
675
  return false;
676
676
  }
677
677
  if (!(source instanceof Object3D) && !(source instanceof Camera)) {
678
- if (isDevEnvironment()) console.warn("[OrbitControls] setCameraAndLookTarget target is not an Object3D or Camera");
678
+ if (isDevEnvironment() || debug) console.warn("[OrbitControls] setCameraAndLookTarget target is not an Object3D or Camera");
679
679
  return false;
680
680
  }
681
+
681
682
  if (source instanceof Camera) {
682
683
  source = source.gameObject;
683
684
  }
684
685
  const worldPosition = source.worldPosition;
685
686
  const forward = source.worldForward;
687
+
688
+ // The camera render direction is -Z. When a camera is passed in then we'll take the view direction OR the object Z forward direction.
689
+ if (source instanceof Camera3) {
690
+ if (debug) console.debug("[OrbitControls] setCameraAndLookTarget flip forward direction for camera");
691
+ forward.multiplyScalar(-1);
692
+ }
693
+
686
694
  const ray = new Ray(worldPosition, forward);
687
695
 
688
696
  if (debug) Gizmos.DrawRay(ray.origin, ray.direction, 0xff0000, 10);