@needle-tools/engine 4.9.3-next.002c20b → 4.9.3-next.0facab6

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.
Files changed (89) hide show
  1. package/components.needle.json +1 -1
  2. package/dist/{gltf-progressive-DhE1A6hX.min.js → gltf-progressive-CoZbSfPR.min.js} +1 -1
  3. package/dist/{gltf-progressive-egsMzRdv.js → gltf-progressive-DUR9TuAH.js} +3 -3
  4. package/dist/{gltf-progressive-DWiyqrwB.umd.cjs → gltf-progressive-Iy7aSAPk.umd.cjs} +1 -1
  5. package/dist/{needle-engine.bundle-BcceMKjs.umd.cjs → needle-engine.bundle-DAo7BPxQ.umd.cjs} +116 -116
  6. package/dist/needle-engine.bundle-DP2gYtOQ.min.js +1638 -0
  7. package/dist/{needle-engine.bundle-BR5JPeY6.js → needle-engine.bundle-TvT7wv7z.js} +7011 -6869
  8. package/dist/needle-engine.js +446 -444
  9. package/dist/needle-engine.min.js +1 -1
  10. package/dist/needle-engine.umd.cjs +1 -1
  11. package/dist/{postprocessing-BZOSD1ln.min.js → postprocessing-BHMVuZQ1.min.js} +1 -1
  12. package/dist/{postprocessing-Bb5StX0o.umd.cjs → postprocessing-BsnRNRRS.umd.cjs} +1 -1
  13. package/dist/{postprocessing-BzFF7i-7.js → postprocessing-DQ2pynXW.js} +2 -2
  14. package/dist/{three-BK56xWDs.umd.cjs → three-B-jwTHao.umd.cjs} +11 -11
  15. package/dist/{three-CsHK73Zc.js → three-CJSAehtG.js} +1 -0
  16. package/dist/{three-examples-Bph291U2.min.js → three-examples-BivkhnvN.min.js} +1 -1
  17. package/dist/{three-examples-C9WfZu-X.umd.cjs → three-examples-Deqc1bNw.umd.cjs} +1 -1
  18. package/dist/{three-examples-BvMpKSun.js → three-examples-Doq0rvFU.js} +1 -1
  19. package/dist/{three-mesh-ui-CN6aRT7i.js → three-mesh-ui-CktOi6oI.js} +1 -1
  20. package/dist/{three-mesh-ui-DnxkZWNA.umd.cjs → three-mesh-ui-CsHwj9cJ.umd.cjs} +1 -1
  21. package/dist/{three-mesh-ui-n_qS2BM-.min.js → three-mesh-ui-DhYXcXZe.min.js} +1 -1
  22. package/dist/{three-TNFQHSFa.min.js → three-qw28ZtTy.min.js} +10 -10
  23. package/dist/{vendor-BtJpSuCj.umd.cjs → vendor-D0Yvltn9.umd.cjs} +1 -1
  24. package/dist/{vendor-k9i6CeGi.js → vendor-DU8tJyl_.js} +1 -1
  25. package/dist/{vendor-XJ9xiwrv.min.js → vendor-JyrX4DVM.min.js} +1 -1
  26. package/lib/engine/api.d.ts +1 -0
  27. package/lib/engine/api.js +1 -0
  28. package/lib/engine/api.js.map +1 -1
  29. package/lib/engine/codegen/register_types.js +2 -0
  30. package/lib/engine/codegen/register_types.js.map +1 -1
  31. package/lib/engine/engine_animation.d.ts +21 -1
  32. package/lib/engine/engine_animation.js +32 -1
  33. package/lib/engine/engine_animation.js.map +1 -1
  34. package/lib/engine/engine_camera.fit.d.ts +68 -0
  35. package/lib/engine/engine_camera.fit.js +193 -0
  36. package/lib/engine/engine_camera.fit.js.map +1 -0
  37. package/lib/engine/engine_gizmos.d.ts +2 -2
  38. package/lib/engine/engine_gizmos.js +2 -2
  39. package/lib/engine/engine_physics.js +6 -3
  40. package/lib/engine/engine_physics.js.map +1 -1
  41. package/lib/engine/webcomponents/needle-engine.d.ts +1 -0
  42. package/lib/engine/webcomponents/needle-engine.js +6 -0
  43. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  44. package/lib/engine-components/AnimatorController.js +16 -0
  45. package/lib/engine-components/AnimatorController.js.map +1 -1
  46. package/lib/engine-components/CameraUtils.js +8 -9
  47. package/lib/engine-components/CameraUtils.js.map +1 -1
  48. package/lib/engine-components/OrbitControls.d.ts +4 -47
  49. package/lib/engine-components/OrbitControls.js +30 -178
  50. package/lib/engine-components/OrbitControls.js.map +1 -1
  51. package/lib/engine-components/api.d.ts +0 -1
  52. package/lib/engine-components/api.js.map +1 -1
  53. package/lib/engine-components/codegen/components.d.ts +1 -0
  54. package/lib/engine-components/codegen/components.js +1 -0
  55. package/lib/engine-components/codegen/components.js.map +1 -1
  56. package/lib/engine-components/web/Clickthrough.d.ts +3 -0
  57. package/lib/engine-components/web/Clickthrough.js +3 -0
  58. package/lib/engine-components/web/Clickthrough.js.map +1 -1
  59. package/lib/engine-components/web/CursorFollow.d.ts +3 -0
  60. package/lib/engine-components/web/CursorFollow.js +3 -0
  61. package/lib/engine-components/web/CursorFollow.js.map +1 -1
  62. package/lib/engine-components/web/HoverAnimation.d.ts +44 -0
  63. package/lib/engine-components/web/HoverAnimation.js +105 -0
  64. package/lib/engine-components/web/HoverAnimation.js.map +1 -0
  65. package/lib/engine-components/web/ScrollFollow.d.ts +4 -0
  66. package/lib/engine-components/web/ScrollFollow.js +4 -0
  67. package/lib/engine-components/web/ScrollFollow.js.map +1 -1
  68. package/lib/engine-components/web/index.d.ts +1 -0
  69. package/lib/engine-components/web/index.js +1 -0
  70. package/lib/engine-components/web/index.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/engine/api.ts +2 -1
  73. package/src/engine/codegen/register_types.ts +2 -0
  74. package/src/engine/engine_animation.ts +69 -1
  75. package/src/engine/engine_camera.fit.ts +288 -0
  76. package/src/engine/engine_gizmos.ts +2 -2
  77. package/src/engine/engine_physics.ts +6 -3
  78. package/src/engine/webcomponents/needle-engine.ts +6 -1
  79. package/src/engine-components/AnimatorController.ts +21 -2
  80. package/src/engine-components/CameraUtils.ts +8 -9
  81. package/src/engine-components/OrbitControls.ts +30 -239
  82. package/src/engine-components/api.ts +0 -1
  83. package/src/engine-components/codegen/components.ts +1 -0
  84. package/src/engine-components/web/Clickthrough.ts +3 -0
  85. package/src/engine-components/web/CursorFollow.ts +3 -0
  86. package/src/engine-components/web/HoverAnimation.ts +99 -0
  87. package/src/engine-components/web/ScrollFollow.ts +4 -0
  88. package/src/engine-components/web/index.ts +1 -0
  89. package/dist/needle-engine.bundle-D3RtScQB.min.js +0 -1638
@@ -276,7 +276,7 @@ export class AnimatorController {
276
276
  * @returns The found state or null if not found
277
277
  */
278
278
  FindState(name: string | number | undefined | null): State | null { return this.findState(name); }
279
-
279
+
280
280
  /**
281
281
  * Finds an animation state by name or hash.
282
282
  *
@@ -321,6 +321,25 @@ export class AnimatorController {
321
321
  return action;
322
322
  }
323
323
 
324
+ // addState(state: State, layerIndex: number = 0) {
325
+ // if (!this.model) throw new Error("AnimatorController model is missing");
326
+ // if (layerIndex < 0 || layerIndex >= this.model.layers.length) {
327
+ // throw new Error(`Invalid layer index: ${layerIndex}`);
328
+ // }
329
+ // const layer = this.model.layers[layerIndex];
330
+ // if (!layer.stateMachine) {
331
+ // layer.stateMachine = { states: [], defaultState: 0 };
332
+ // }
333
+ // if (!layer.stateMachine.states) {
334
+ // layer.stateMachine.states = [];
335
+ // }
336
+ // if (state.hash === undefined) {
337
+ // state.hash = stringToHash(state.name || "state" + layer.stateMachine.states.length);
338
+ // }
339
+
340
+ // }
341
+
342
+
324
343
  /**
325
344
  * The normalized time (0-1) to start playing the first state at.
326
345
  * This affects the initial state when the animator is first enabled.
@@ -331,7 +350,7 @@ export class AnimatorController {
331
350
  * The Animator component this controller is bound to.
332
351
  */
333
352
  animator?: Animator;
334
-
353
+
335
354
  /**
336
355
  * The data model describing the animation states and transitions.
337
356
  */
@@ -117,16 +117,15 @@ function createDefaultCameraControls(context: IContext, cam?: ICamera) {
117
117
  if (cameraObject) {
118
118
  const orbit = getOrAddComponent(cameraObject, OrbitControls) as OrbitControls;
119
119
  orbit.sourceId = cam?.sourceId ?? "unknown";
120
+ // /enable auto-rotate if the auto-rotate attribute is provided
120
121
  const autoRotate = context.domElement.getAttribute("auto-rotate");
121
- orbit.autoRotate = autoRotate !== undefined && autoRotate !== null && (autoRotate != "0" && autoRotate?.toLowerCase() != "false");
122
- orbit.autoRotateSpeed = 0.5;
123
- orbit.autoFit = true;
124
- if (orbit.autoRotate && autoRotate) {
125
- const autoRotateValue = parseFloat(autoRotate);
126
- if (!isNaN(autoRotateValue)) {
127
- orbit.autoRotateSpeed = autoRotateValue;
128
- }
129
- }
122
+ orbit.autoRotate = autoRotate != "0" && autoRotate?.toLowerCase() != "false";
123
+ const autoRotateSpeed = Number.parseFloat(autoRotate || ".5");
124
+ orbit.autoRotateSpeed = !isNaN(autoRotateSpeed) ? autoRotateSpeed : .5;
125
+ console.log("Auto-rotate", orbit.autoRotate, "speed:", orbit.autoRotateSpeed);
126
+ const autoFit = context.domElement.getAttribute("auto-fit");
127
+ orbit.autoFit = autoFit !== "0" && autoFit?.toLowerCase() != "false";
128
+ orbit.autoTarget = true;
130
129
  }
131
130
  else {
132
131
  console.warn("Missing camera object, can not add orbit controls")
@@ -2,18 +2,19 @@ import { Camera as Camera3, Object3D, PerspectiveCamera, Ray, Vector2, Vector3,
2
2
  import { OrbitControls as ThreeOrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
3
3
 
4
4
  import { isDevEnvironment } from "../engine/debug/index.js";
5
+ import { fitCamera, FitCameraOptions } from "../engine/engine_camera.fit.js";
5
6
  import { setCameraController } from "../engine/engine_camera.js";
6
7
  import { Gizmos } from "../engine/engine_gizmos.js";
7
8
  import { InputEventQueue, NEPointerEvent } from "../engine/engine_input.js";
8
9
  import { Mathf } from "../engine/engine_math.js";
9
10
  import { IRaycastOptions, RaycastOptions } from "../engine/engine_physics.js";
10
11
  import { serializable } from "../engine/engine_serialization_decorator.js";
11
- import { getBoundingBox, getTempVector, getWorldPosition } from "../engine/engine_three_utils.js";
12
+ import { getTempVector, getWorldPosition } from "../engine/engine_three_utils.js";
12
13
  import type { ICameraController } from "../engine/engine_types.js";
13
14
  import { DeviceUtilities, getParam } from "../engine/engine_utils.js";
15
+ import { NeedleEngineWebComponent } from "../engine/webcomponents/needle-engine.js";
14
16
  import { Camera } from "./Camera.js";
15
17
  import { Behaviour, GameObject } from "./Component.js";
16
- import { GroundProjectedEnv } from "./GroundProjection.js";
17
18
  import { LookAtConstraint } from "./LookAtConstraint.js";
18
19
  import { SyncedTransform } from "./SyncedTransform.js";
19
20
  import { type AfterHandleInputEvent, EventSystem, EventSystemEvents } from "./ui/EventSystem.js";
@@ -354,6 +355,9 @@ export class OrbitControls extends Behaviour implements ICameraController {
354
355
  if (debug) console.debug("OrbitControls", this);
355
356
  this._didSetTarget = 0;
356
357
  this._startedListeningToKeyEvents = false;
358
+ if ((this.context.domElement as NeedleEngineWebComponent).cameraControls === false) {
359
+ this.enabled = false;
360
+ }
357
361
  }
358
362
 
359
363
  /** @internal */
@@ -490,10 +494,13 @@ export class OrbitControls extends Behaviour implements ICameraController {
490
494
  this._lastTimeClickOnBackground = this.context.time.time;
491
495
  if (this.clickBackgroundToFitScene <= 1 || dt < this.clickBackgroundToFitScene * .15) {
492
496
  this._clickOnBackgroundCount += 1;
493
- if (this._clickOnBackgroundCount >= this.clickBackgroundToFitScene - 1)
494
- this.fitCamera(this.context.scene.children, {
495
- immediate: false
497
+ if (this._clickOnBackgroundCount >= this.clickBackgroundToFitScene - 1) {
498
+ this.autoRotate = false;
499
+ this.fitCamera({
500
+ objects: this.context.scene,
501
+ immediate: false,
496
502
  });
503
+ }
497
504
  }
498
505
  else {
499
506
  this._clickOnBackgroundCount = 0;
@@ -530,7 +537,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
530
537
  private _orbitStartAngle: number = 0;
531
538
  private _zoomStartDistance: number = 0;
532
539
  private onControlsChangeStarted = () => {
533
- if(debug) console.debug("OrbitControls: Change started");
540
+ if (debug) console.debug("OrbitControls: Change started");
534
541
  if (this._controls) {
535
542
  this._orbitStartAngle = this._controls.getAzimuthalAngle() + this._controls.getPolarAngle();
536
543
  this._zoomStartDistance = this._controls.getDistance();
@@ -540,7 +547,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
540
547
  }
541
548
  }
542
549
  private onControlsChangeEnded = () => {
543
- if(debug) console.debug("OrbitControls: Change ended", { autoTarget: this.autoTarget });
550
+ if (debug) console.debug("OrbitControls: Change ended", { autoTarget: this.autoTarget });
544
551
  if (this._controls) {
545
552
  if (this.autoTarget) {
546
553
  const newAngle = this._controls.getAzimuthalAngle() + this._controls.getPolarAngle();
@@ -989,242 +996,26 @@ export class OrbitControls extends Behaviour implements ICameraController {
989
996
  /**
990
997
  * Fits the camera to show the objects provided (defaults to the scene if no objects are passed in)
991
998
  */
992
- fitCamera(options?: FitCameraOptions);
993
- fitCamera(objects?: Object3D | Array<Object3D>, options?: Omit<FitCameraOptions, "objects">);
994
- fitCamera(objectsOrOptions?: Object3D | Array<Object3D> | FitCameraOptions, options?: FitCameraOptions): void {
995
-
996
- if (this.context.isInXR) {
997
- // camera fitting in XR is not supported
998
- console.warn('[OrbitControls] Can not fit camera while XR session is active');
999
- return;
1000
- }
1001
-
1002
- let objects: Object3D | Array<Object3D> | undefined = undefined;
1003
- // If the user passed in an array as first argument
1004
- if (Array.isArray(objectsOrOptions)) {
1005
- objects = objectsOrOptions;
1006
- }
1007
- // If the user passed in an object as first argument
1008
- else if (objectsOrOptions && "type" in objectsOrOptions) {
1009
- objects = objectsOrOptions;
1010
- }
1011
- // If the user passed in an object as first argument and options as second argument
1012
- else if (objectsOrOptions && typeof objectsOrOptions === "object") {
1013
- if (!(objectsOrOptions instanceof Object3D) && !Array.isArray(objectsOrOptions)) {
1014
- options = objectsOrOptions;
1015
- objects = options.objects;
1016
- }
1017
- }
1018
- // Ensure objects are setup correctly
1019
- if (objects && !Array.isArray(objects)) {
1020
- objects = [objects];
1021
- }
1022
- if (!Array.isArray(objects) || objects && objects.length <= 0) {
1023
- objects = this.context.scene.children;
1024
- }
1025
-
1026
- // Make sure there's anything to fit to
1027
- if (!Array.isArray(objects) || objects.length <= 0) {
1028
- console.warn("No objects to fit camera to...");
1029
- return;
1030
- }
1031
-
1032
- const camera = this._cameraObject as PerspectiveCamera;
1033
- const controls = this._controls as ThreeOrbitControls | null;
1034
-
1035
- if (!camera || !controls) {
1036
- console.warn("No camera or controls found to fit camera to objects...");
1037
- return;
1038
- }
1039
- if (!options) options = {}
1040
- const { immediate = false, centerCamera, cameraNearFar = "auto", fitOffset = 1.1, fov = camera?.fov } = options;
1041
- const size = new Vector3();
1042
- const center = new Vector3();
1043
- // TODO would be much better to calculate the bounds in camera space instead of world space -
1044
- // we would get proper view-dependant fit.
1045
- // Right now it's independent from where the camera is actually looking from,
1046
- // and thus we're just getting some maximum that will work for sure.
1047
- const box = getBoundingBox(objects, undefined, this._camera?.threeCamera?.layers);
1048
- const boxCopy = box.clone();
1049
- box.getCenter(center);
1050
-
1051
- const box_size = new Vector3();
1052
- box.getSize(box_size);
1053
-
1054
- // project this box into camera space
1055
- camera.updateMatrixWorld();
1056
- box.applyMatrix4(camera.matrixWorldInverse);
1057
-
1058
- box.getSize(size);
1059
- box.setFromCenterAndSize(center, size);
1060
- if (Number.isNaN(size.x) || Number.isNaN(size.y) || Number.isNaN(size.z)) {
1061
- console.warn("Camera fit size resultet in NaN", camera, box, [...objects]);
1062
- return;
1063
- }
1064
- if (size.length() <= 0.0000000001) {
1065
- if (debugCameraFit) console.warn("Camera fit size is zero", box, [...objects]);
1066
- return;
1067
- }
1068
-
1069
- const verticalFov = fov;
1070
- const horizontalFov = 2 * Math.atan(Math.tan(verticalFov * Math.PI / 360 / 2) * camera.aspect) / Math.PI * 360;
1071
- const fitHeightDistance = size.y / (2 * Math.atan(Math.PI * verticalFov / 360));
1072
- const fitWidthDistance = size.x / (2 * Math.atan(Math.PI * horizontalFov / 360));
1073
-
1074
- const distance = fitOffset * Math.max(fitHeightDistance, fitWidthDistance) + size.z / 2;
1075
-
1076
- if (debugCameraFit) {
1077
- console.log("Fit camera to objects", { fitHeightDistance, fitWidthDistance, distance, verticalFov, horizontalFov });
1078
- }
1079
-
1080
- this.maxZoom = distance * 10;
1081
- this.minZoom = distance * 0.01;
1082
-
1083
- const verticalOffset = 0.05;
1084
- const lookAt = center.clone();
1085
- lookAt.y -= size.y * verticalOffset;
1086
- if (options.targetOffset) {
1087
- if (options.targetOffset.x !== undefined) lookAt.x += options.targetOffset.x;
1088
- if (options.targetOffset.y !== undefined) lookAt.y += options.targetOffset.y;
1089
- if (options.targetOffset.z !== undefined) lookAt.z += options.targetOffset.z;
1090
- }
1091
- if (options.relativeTargetOffset) {
1092
- if (options.relativeTargetOffset.x !== undefined) lookAt.x += options.relativeTargetOffset.x * size.x;
1093
- if (options.relativeTargetOffset.y !== undefined) lookAt.y += options.relativeTargetOffset.y * size.y;
1094
- if (options.relativeTargetOffset.z !== undefined) lookAt.z += options.relativeTargetOffset.z * size.z;
1095
- }
1096
- this.setLookTargetPosition(lookAt, immediate);
1097
- this.setFieldOfView(options.fov, immediate);
1098
-
1099
- if (cameraNearFar == undefined || cameraNearFar == "auto") {
1100
- // Check if the scene has a GroundProjectedEnv and include the scale to the far plane so that it doesnt cut off
1101
- const groundprojection = GameObject.findObjectOfType(GroundProjectedEnv);
1102
- const groundProjectionRadius = groundprojection ? groundprojection.radius : 0;
1103
- const boundsMax = Math.max(box_size.x, box_size.y, box_size.z, groundProjectionRadius);
1104
- // TODO: this doesnt take the Camera component nearClipPlane into account
1105
- camera.near = (distance / 100);
1106
- camera.far = boundsMax + distance * 10;
1107
- camera.updateProjectionMatrix();
1108
-
1109
- // adjust maxZoom so that the ground projection radius is always inside
1110
- if (groundprojection) {
1111
- this.maxZoom = Math.max(Math.min(this.maxZoom, groundProjectionRadius * 0.5), distance);
1112
- }
1113
- }
1114
-
1115
- // ensure we're not clipping out of the current zoom level just because we're fitting
1116
- const currentZoom = controls.getDistance();
1117
- if (currentZoom < this.minZoom) this.minZoom = currentZoom * 0.9;
1118
- if (currentZoom > this.maxZoom) this.maxZoom = currentZoom * 1.1;
1119
-
1120
- const direction = center.clone();
1121
- if (options.fitDirection) {
1122
- direction.sub(new Vector3().copy(options.fitDirection).multiplyScalar(1_000_000));
1123
- }
1124
- else {
1125
- direction.sub(camera.worldPosition);
1126
- }
1127
- if (centerCamera === "y")
1128
- direction.y = 0;
1129
- direction.normalize();
1130
- direction.multiplyScalar(distance);
1131
- if (centerCamera === "y")
1132
- direction.y += -verticalOffset * 4 * distance;
1133
-
1134
- let cameraLocalPosition = center.clone().sub(direction);
1135
- if (options.cameraOffset) {
1136
- if (options.cameraOffset.x !== undefined) cameraLocalPosition.x += options.cameraOffset.x;
1137
- if (options.cameraOffset.y !== undefined) cameraLocalPosition.y += options.cameraOffset.y;
1138
- if (options.cameraOffset.z !== undefined) cameraLocalPosition.z += options.cameraOffset.z;
1139
- }
1140
- if (options.relativeCameraOffset) {
1141
- if (options.relativeCameraOffset.x !== undefined) cameraLocalPosition.x += options.relativeCameraOffset.x * size.x;
1142
- if (options.relativeCameraOffset.y !== undefined) cameraLocalPosition.y += options.relativeCameraOffset.y * size.y;
1143
- if (options.relativeCameraOffset.z !== undefined) cameraLocalPosition.z += options.relativeCameraOffset.z * size.z;
1144
- }
1145
- if (camera.parent) {
1146
- cameraLocalPosition = camera.parent.worldToLocal(cameraLocalPosition);
1147
- }
1148
- this.setCameraTargetPosition(cameraLocalPosition, immediate);
1149
-
1150
- if (debugCameraFit || options.debug) {
1151
- Gizmos.DrawWireBox3(box, 0xffff33, 10);
1152
- Gizmos.DrawWireBox3(boxCopy, 0x00ff00, 10);
1153
-
1154
- if (!this._haveAttachedKeyboardEvents && debugCameraFit) {
1155
- this._haveAttachedKeyboardEvents = true;
1156
- document.body.addEventListener("keydown", (e) => {
1157
- if (e.code === "KeyF") {
1158
- // random fov for easier debugging of fov-based fitting
1159
- let fov: number | undefined = undefined;
1160
- if (this._cameraObject instanceof PerspectiveCamera) fov = (Math.random() * Math.random()) * 170 + 10;
1161
- this.fitCamera({ objects, fitOffset, immediate: false, fov });
1162
- }
1163
- if (e.code === "KeyV") {
1164
- if (this._cameraObject instanceof PerspectiveCamera) this._cameraObject.fov = 60;
1165
- }
1166
- });
1167
- }
1168
- }
1169
-
999
+ fitCamera(options?: OrbitFitCameraOptions): void {
1000
+ const res = fitCamera({
1001
+ ...options,
1002
+ autoApply: false,
1003
+ context: this.context,
1004
+ camera: this._cameraObject as Camera3,
1005
+ currentZoom: this._controls?.getDistance() || undefined,
1006
+ minZoom: this.minZoom,
1007
+ maxZoom: this.maxZoom,
1008
+ });
1009
+ if (!res) return;
1010
+ this.setLookTargetPosition(res.lookAt, options?.immediate || false);
1011
+ this.setCameraTargetPosition(res.position, options?.immediate || false);
1012
+ this.setFieldOfView(options?.fov, options?.immediate || false);
1170
1013
  this.onBeforeRender();
1171
- // controls.update(); // this is not enough when calling fitCamera({immediate:true}) in an interval
1172
1014
  }
1173
1015
 
1174
1016
  private _haveAttachedKeyboardEvents: boolean = false;
1175
1017
  }
1176
1018
 
1177
-
1178
- /**
1179
- * Options for fitting the camera to the scene. Used in {@link OrbitControls.fitCamera}
1180
- */
1181
- export type FitCameraOptions = {
1182
- /** When enabled debug rendering will be shown */
1183
- debug?: boolean,
1184
- /**
1185
- * The objects to fit the camera to. If not provided the scene children will be used
1186
- */
1187
- objects?: Object3D[] | Object3D;
1188
- /** If true the camera will move immediately to the new position, otherwise it will lerp
1189
- * @default false
1190
- */
1019
+ type OrbitFitCameraOptions = FitCameraOptions & {
1191
1020
  immediate?: boolean,
1192
-
1193
- /** Fit offset: A factor to multiply the distance to the objects by
1194
- * @default 1.1
1195
- */
1196
- fitOffset?: number,
1197
-
1198
- /** The direction from which the camera should be fitted in worldspace. If not defined the current camera's position will be used */
1199
- fitDirection?: Vector3Like,
1200
-
1201
- /** If set to "y" the camera will be centered in the y axis */
1202
- centerCamera?: "none" | "y",
1203
- /** Set to 'auto' to update the camera near or far plane based on the fitted-objects bounds */
1204
- cameraNearFar?: "keep" | "auto",
1205
-
1206
- /**
1207
- * Offset the camera position in world space
1208
- */
1209
- cameraOffset?: Partial<Vector3Like>,
1210
- /**
1211
- * Offset the camera position relative to the size of the objects being focused on (e.g. x: 0.5).
1212
- * Value range: -1 to 1
1213
- */
1214
- relativeCameraOffset?: Partial<Vector3Like>,
1215
-
1216
- /**
1217
- * Offset the camera target position in world space
1218
- */
1219
- targetOffset?: Partial<Vector3Like>,
1220
- /**
1221
- * Offset the camera target position relative to the size of the objects being focused on.
1222
- * Value range: -1 to 1
1223
- */
1224
- relativeTargetOffset?: Partial<Vector3Like>,
1225
-
1226
- /**
1227
- * Field of view (FOV) for the camera
1228
- */
1229
- fov?: number,
1230
- }
1021
+ }
@@ -53,7 +53,6 @@ import "./AnimationUtilsAutoplay.js"
53
53
 
54
54
  export { DragMode } from "./DragControls.js";
55
55
  export type { DropListenerNetworkEventArguments, DropListenerOnDropArguments } from "./DropListener.js";
56
- export { type FitCameraOptions } from "./OrbitControls.js";
57
56
  export * from "./particlesystem/api.js"
58
57
  export * from "./splines/index.js";
59
58
  export * from "./web/index.js";
@@ -205,6 +205,7 @@ export { VideoPlayer } from "../VideoPlayer.js";
205
205
  export { Voip } from "../Voip.js";
206
206
  export { ClickThrough } from "../web/Clickthrough.js";
207
207
  export { CursorFollow } from "../web/CursorFollow.js";
208
+ export { HoverAnimation } from "../web/HoverAnimation.js";
208
209
  export { ScrollFollow } from "../web/ScrollFollow.js";
209
210
  export { Avatar } from "../webxr/Avatar.js";
210
211
  export { XRControllerFollow } from "../webxr/controllers/XRControllerFollow.js";
@@ -21,6 +21,9 @@ onStart(ctx => {
21
21
  * - Alternatively, add the `clickthrough` attribute to the `<needle-engine>` HTML element (e.g. `<needle-engine clickthrough></needle-engine>`).
22
22
  *
23
23
  * @link Example https://stackblitz.com/~/github.com/needle-engine/sample-3d-over-html
24
+ * @category Web
25
+ * @group Components
26
+ * @component
24
27
  */
25
28
  export class ClickThrough extends Behaviour {
26
29
 
@@ -4,6 +4,9 @@ import { Behaviour } from "../Component.js";
4
4
 
5
5
  /**
6
6
  * The CursorFollow component makes the object follow the cursor (or touch) position on screen.
7
+ * @category Web
8
+ * @group Components
9
+ * @component
7
10
  */
8
11
  export class CursorFollow extends Behaviour {
9
12
 
@@ -0,0 +1,99 @@
1
+ import { AnimationClip } from "three";
2
+
3
+ import { ScaleClipType } from "../../engine/engine_animation.js";
4
+ import { AnimationUtils } from "../../engine/engine_animation.js";
5
+ import { serializable } from "../../engine/engine_serialization_decorator.js";
6
+ import { registerType } from "../../engine/engine_typestore.js";
7
+ import { Animation } from "../Animation.js";
8
+ import { Behaviour } from "../Component.js";
9
+
10
+
11
+ /**
12
+ * @category Web
13
+ * @group Components
14
+ * @component
15
+ */
16
+ @registerType
17
+ export class HoverAnimation extends Behaviour {
18
+
19
+ /**
20
+ * Default hover animation type if no custom clip is provided.
21
+ * **Node**: This is only used if no custom hover animation clip is provided.
22
+ * @default "linear"
23
+ */
24
+ @serializable()
25
+ type: ScaleClipType = "linear";
26
+
27
+ /**
28
+ * Duration of the hover animation in seconds.
29
+ * **Node**: This is only used if no custom hover animation clip is provided.
30
+ * @default 0.1
31
+ */
32
+ @serializable()
33
+ duration: number = 0.1;
34
+
35
+ /**
36
+ * Scale factor to apply when hovering.
37
+ * **Node**: This is only used if no custom hover animation clip is provided.
38
+ * @default 1.1
39
+ */
40
+ @serializable()
41
+ scaleFactor: number = 1.1;
42
+
43
+
44
+ /**
45
+ * Animation clip to play when hovering. If null, a default scale-up animation is used.
46
+ */
47
+ @serializable(AnimationClip)
48
+ hovered: AnimationClip | null = null;
49
+
50
+ /**
51
+ * Animation clip to play when not hovering. If null, an empty clip is used.
52
+ */
53
+ @serializable(AnimationClip)
54
+ idle: AnimationClip | null = null;
55
+
56
+ private animation: Animation | null = null;
57
+
58
+ start() {
59
+ if (!this.idle) this.idle = AnimationUtils.emptyClip();
60
+
61
+ if (!this.hovered) {
62
+ this.hovered = AnimationUtils.createScaleClip({
63
+ type: "linear",
64
+ duration: this.duration || 0.1,
65
+ scale: this.gameObject.scale,
66
+ scaleFactor: this.scaleFactor || 1.1,
67
+ });
68
+ }
69
+
70
+ this.animation ??= this.gameObject.addComponent(Animation);
71
+ this.animation.playAutomatically = false;
72
+ this.playIdle();
73
+ }
74
+
75
+ onEnable() {
76
+ if (this.animation) this.animation.enabled = true;
77
+ this.playIdle();
78
+ }
79
+ onDisable() {
80
+ if (this.animation) this.animation.enabled = false;
81
+ this.playIdle();
82
+ }
83
+
84
+ onPointerEnter() {
85
+ this.playHover();
86
+ }
87
+
88
+ onPointerExit() {
89
+ this.playIdle();
90
+ }
91
+
92
+ private playIdle() {
93
+ if (this.idle) this.animation?.play(this.idle, { exclusive: true, fadeDuration: .1, loop: true });
94
+ }
95
+ private playHover() {
96
+ if (this.hovered) this.animation?.play(this.hovered, { exclusive: true, fadeDuration: .1, loop: false, clampWhenFinished: true });
97
+ }
98
+
99
+ }
@@ -44,6 +44,10 @@ type ScrollFollowEvent = {
44
44
  * 2. Add a ScrollFollow component to the same GameObject or another GameObject in the scene.
45
45
  * 3. Assign the PlayableDirector component to the ScrollFollow's target property.
46
46
  * 4. The timeline will now scrub based on the scroll position of the page.
47
+ *
48
+ * @category Web
49
+ * @group Components
50
+ * @component
47
51
  */
48
52
  export class ScrollFollow extends Behaviour {
49
53
 
@@ -1,3 +1,4 @@
1
1
  export * from "./Clickthrough.js";
2
2
  export * from "./CursorFollow.js";
3
+ export * from "./HoverAnimation.js";
3
4
  export * from "./ScrollFollow.js";