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

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 (94) hide show
  1. package/components.needle.json +1 -1
  2. package/dist/{gltf-progressive-Iy7aSAPk.umd.cjs → gltf-progressive-DWiyqrwB.umd.cjs} +1 -1
  3. package/dist/{gltf-progressive-CoZbSfPR.min.js → gltf-progressive-DhE1A6hX.min.js} +1 -1
  4. package/dist/{gltf-progressive-DUR9TuAH.js → gltf-progressive-egsMzRdv.js} +3 -3
  5. package/dist/{needle-engine.bundle-TvT7wv7z.js → needle-engine.bundle-BAsxNKpA.js} +7343 -7525
  6. package/dist/{needle-engine.bundle-DAo7BPxQ.umd.cjs → needle-engine.bundle-C7LSzO5L.umd.cjs} +122 -144
  7. package/dist/needle-engine.bundle-ugr1bBtk.min.js +1616 -0
  8. package/dist/needle-engine.js +444 -446
  9. package/dist/needle-engine.min.js +1 -1
  10. package/dist/needle-engine.umd.cjs +1 -1
  11. package/dist/{postprocessing-BHMVuZQ1.min.js → postprocessing-BZOSD1ln.min.js} +1 -1
  12. package/dist/{postprocessing-BsnRNRRS.umd.cjs → postprocessing-Bb5StX0o.umd.cjs} +1 -1
  13. package/dist/{postprocessing-DQ2pynXW.js → postprocessing-BzFF7i-7.js} +2 -2
  14. package/dist/{three-B-jwTHao.umd.cjs → three-BK56xWDs.umd.cjs} +11 -11
  15. package/dist/{three-CJSAehtG.js → three-CsHK73Zc.js} +0 -1
  16. package/dist/{three-qw28ZtTy.min.js → three-TNFQHSFa.min.js} +10 -10
  17. package/dist/{three-examples-BivkhnvN.min.js → three-examples-Bph291U2.min.js} +1 -1
  18. package/dist/{three-examples-Doq0rvFU.js → three-examples-BvMpKSun.js} +1 -1
  19. package/dist/{three-examples-Deqc1bNw.umd.cjs → three-examples-C9WfZu-X.umd.cjs} +1 -1
  20. package/dist/{three-mesh-ui-CktOi6oI.js → three-mesh-ui-CN6aRT7i.js} +1 -1
  21. package/dist/{three-mesh-ui-CsHwj9cJ.umd.cjs → three-mesh-ui-DnxkZWNA.umd.cjs} +1 -1
  22. package/dist/{three-mesh-ui-DhYXcXZe.min.js → three-mesh-ui-n_qS2BM-.min.js} +1 -1
  23. package/dist/{vendor-D0Yvltn9.umd.cjs → vendor-BtJpSuCj.umd.cjs} +1 -1
  24. package/dist/{vendor-JyrX4DVM.min.js → vendor-XJ9xiwrv.min.js} +1 -1
  25. package/dist/{vendor-DU8tJyl_.js → vendor-k9i6CeGi.js} +1 -1
  26. package/lib/engine/api.d.ts +0 -1
  27. package/lib/engine/api.js +0 -1
  28. package/lib/engine/api.js.map +1 -1
  29. package/lib/engine/codegen/register_types.js +0 -2
  30. package/lib/engine/codegen/register_types.js.map +1 -1
  31. package/lib/engine/engine_animation.d.ts +1 -21
  32. package/lib/engine/engine_animation.js +1 -32
  33. package/lib/engine/engine_animation.js.map +1 -1
  34. package/lib/engine/engine_gizmos.d.ts +2 -2
  35. package/lib/engine/engine_gizmos.js +2 -2
  36. package/lib/engine/engine_physics.js +3 -6
  37. package/lib/engine/engine_physics.js.map +1 -1
  38. package/lib/engine/webcomponents/needle-engine.d.ts +0 -1
  39. package/lib/engine/webcomponents/needle-engine.js +0 -6
  40. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  41. package/lib/engine/webcomponents/needle-engine.loading.js +23 -59
  42. package/lib/engine/webcomponents/needle-engine.loading.js.map +1 -1
  43. package/lib/engine-components/AnimatorController.js +0 -16
  44. package/lib/engine-components/AnimatorController.js.map +1 -1
  45. package/lib/engine-components/CameraUtils.js +9 -8
  46. package/lib/engine-components/CameraUtils.js.map +1 -1
  47. package/lib/engine-components/OrbitControls.d.ts +47 -4
  48. package/lib/engine-components/OrbitControls.js +178 -30
  49. package/lib/engine-components/OrbitControls.js.map +1 -1
  50. package/lib/engine-components/api.d.ts +1 -0
  51. package/lib/engine-components/api.js.map +1 -1
  52. package/lib/engine-components/codegen/components.d.ts +0 -1
  53. package/lib/engine-components/codegen/components.js +0 -1
  54. package/lib/engine-components/codegen/components.js.map +1 -1
  55. package/lib/engine-components/web/Clickthrough.d.ts +0 -3
  56. package/lib/engine-components/web/Clickthrough.js +0 -3
  57. package/lib/engine-components/web/Clickthrough.js.map +1 -1
  58. package/lib/engine-components/web/CursorFollow.d.ts +0 -3
  59. package/lib/engine-components/web/CursorFollow.js +0 -3
  60. package/lib/engine-components/web/CursorFollow.js.map +1 -1
  61. package/lib/engine-components/web/ScrollFollow.d.ts +0 -4
  62. package/lib/engine-components/web/ScrollFollow.js +0 -4
  63. package/lib/engine-components/web/ScrollFollow.js.map +1 -1
  64. package/lib/engine-components/web/index.d.ts +0 -1
  65. package/lib/engine-components/web/index.js +0 -1
  66. package/lib/engine-components/web/index.js.map +1 -1
  67. package/package.json +2 -2
  68. package/plugins/vite/alias.js +3 -5
  69. package/plugins/vite/poster-client.js +21 -22
  70. package/src/engine/api.ts +1 -2
  71. package/src/engine/codegen/register_types.ts +0 -2
  72. package/src/engine/engine_animation.ts +1 -69
  73. package/src/engine/engine_gizmos.ts +2 -2
  74. package/src/engine/engine_physics.ts +3 -6
  75. package/src/engine/webcomponents/needle-engine.loading.ts +24 -63
  76. package/src/engine/webcomponents/needle-engine.ts +1 -6
  77. package/src/engine-components/AnimatorController.ts +2 -21
  78. package/src/engine-components/CameraUtils.ts +9 -8
  79. package/src/engine-components/OrbitControls.ts +239 -30
  80. package/src/engine-components/api.ts +1 -0
  81. package/src/engine-components/codegen/components.ts +0 -1
  82. package/src/engine-components/web/Clickthrough.ts +0 -3
  83. package/src/engine-components/web/CursorFollow.ts +0 -3
  84. package/src/engine-components/web/ScrollFollow.ts +0 -4
  85. package/src/engine-components/web/index.ts +0 -1
  86. package/dist/needle-engine.bundle-DP2gYtOQ.min.js +0 -1638
  87. package/lib/engine/engine_camera.fit.d.ts +0 -68
  88. package/lib/engine/engine_camera.fit.js +0 -193
  89. package/lib/engine/engine_camera.fit.js.map +0 -1
  90. package/lib/engine-components/web/HoverAnimation.d.ts +0 -44
  91. package/lib/engine-components/web/HoverAnimation.js +0 -105
  92. package/lib/engine-components/web/HoverAnimation.js.map +0 -1
  93. package/src/engine/engine_camera.fit.ts +0 -288
  94. package/src/engine-components/web/HoverAnimation.ts +0 -99
@@ -1,288 +0,0 @@
1
- import { Camera, Object3D, PerspectiveCamera, Vector3, Vector3Like } from "three";
2
-
3
- import { GroundProjectedEnv } from "../engine-components/GroundProjection.js";
4
- import { findObjectOfType } from "./engine_components.js";
5
- import { Context } from "./engine_context.js";
6
- import { Gizmos } from "./engine_gizmos.js";
7
- import { getBoundingBox } from "./engine_three_utils.js";
8
- import { NeedleXRSession } from "./xr/NeedleXRSession.js";
9
-
10
-
11
- /**
12
- * Options for fitting the camera to the scene. Used in {@link OrbitControls.fitCamera}
13
- */
14
- export type FitCameraOptions = {
15
- /** When enabled debug rendering will be shown */
16
- debug?: boolean,
17
-
18
- /**
19
- * If true the camera position and target will be applied immediately
20
- * @default true
21
- */
22
- autoApply?: boolean,
23
-
24
- /**
25
- * The context to use. If not provided the current context will be used
26
- */
27
- context?: Context,
28
-
29
- /**
30
- * The camera to fit. If not provided the current camera will be used
31
- */
32
- camera?: Camera,
33
-
34
- currentZoom?: number,
35
- minZoom?: number,
36
- maxZoom?: number,
37
-
38
- /**
39
- * The objects to fit the camera to. If not provided the scene children will be used
40
- */
41
- objects?: Object3D[] | Object3D;
42
-
43
- /** Fit offset: A factor to multiply the distance to the objects by
44
- * @default 1.1
45
- */
46
- fitOffset?: number,
47
-
48
- /** The direction from which the camera should be fitted in worldspace. If not defined the current camera's position will be used */
49
- fitDirection?: Vector3Like,
50
-
51
- /** If set to "y" the camera will be centered in the y axis */
52
- centerCamera?: "none" | "y",
53
- /** Set to 'auto' to update the camera near or far plane based on the fitted-objects bounds */
54
- cameraNearFar?: "keep" | "auto",
55
-
56
- /**
57
- * Offset the camera position in world space
58
- */
59
- cameraOffset?: Partial<Vector3Like>,
60
- /**
61
- * Offset the camera position relative to the size of the objects being focused on (e.g. x: 0.5).
62
- * Value range: -1 to 1
63
- */
64
- relativeCameraOffset?: Partial<Vector3Like>,
65
-
66
- /**
67
- * Offset the camera target position in world space
68
- */
69
- targetOffset?: Partial<Vector3Like>,
70
- /**
71
- * Offset the camera target position relative to the size of the objects being focused on.
72
- * Value range: -1 to 1
73
- */
74
- relativeTargetOffset?: Partial<Vector3Like>,
75
-
76
- /**
77
- * Field of view (FOV) for the camera
78
- */
79
- fov?: number,
80
- }
81
-
82
- export type FitCameraReturnType = {
83
- camera: Camera,
84
- position: Vector3,
85
- lookAt: Vector3,
86
- fov: number | undefined
87
- }
88
-
89
-
90
- export function fitCamera(objectsOrOptions?: Object3D | Array<Object3D> | FitCameraOptions, options?: FitCameraOptions): null | FitCameraReturnType {
91
-
92
- if (NeedleXRSession.active) {
93
- // camera fitting in XR is not supported
94
- console.warn('[OrbitControls] Can not fit camera while XR session is active');
95
- return null;
96
- }
97
-
98
- const context = Context.Current;
99
- if (!context) {
100
- console.warn('[OrbitControls] No context found');
101
- return null;
102
- }
103
- const camera = options?.camera || context.mainCamera;
104
-
105
- let objects: Object3D | Array<Object3D> | undefined = undefined;
106
- // If the user passed in an array as first argument
107
- if (Array.isArray(objectsOrOptions)) {
108
- objects = objectsOrOptions;
109
- }
110
- // If the user passed in an object as first argument
111
- else if (objectsOrOptions && "type" in objectsOrOptions) {
112
- objects = objectsOrOptions;
113
- }
114
- // If the user passed in an object as first argument and options as second argument
115
- else if (objectsOrOptions && typeof objectsOrOptions === "object") {
116
- if (!(objectsOrOptions instanceof Object3D) && !Array.isArray(objectsOrOptions)) {
117
- options = objectsOrOptions;
118
- objects = options.objects;
119
- }
120
- }
121
- // Ensure objects are setup correctly
122
- if (objects && !Array.isArray(objects)) {
123
- objects = [objects];
124
- }
125
- if (!Array.isArray(objects) || objects && objects.length <= 0) {
126
- objects = context.scene.children;
127
- }
128
-
129
- // Make sure there's anything to fit to
130
- if (!Array.isArray(objects) || objects.length <= 0) {
131
- console.warn("No objects to fit camera to...");
132
- return null;
133
- }
134
-
135
-
136
- // const controls = this._controls as ThreeOrbitControls | null;
137
-
138
- if (!camera) {
139
- console.warn("No camera or controls found to fit camera to objects...");
140
- return null;
141
- }
142
-
143
- if (!options) options = {}
144
- options.autoApply = options.autoApply !== false; // default to true
145
- options.minZoom ||= 0;
146
- options.maxZoom ||= Infinity;
147
-
148
- const {
149
- centerCamera,
150
- cameraNearFar = "auto",
151
- fitOffset = 1.1,
152
- fov = camera instanceof PerspectiveCamera ? camera?.fov : -1
153
- } = options;
154
-
155
- const size = new Vector3();
156
- const center = new Vector3();
157
- const aspect = camera instanceof PerspectiveCamera ? camera.aspect : 1;
158
- // TODO would be much better to calculate the bounds in camera space instead of world space -
159
- // we would get proper view-dependant fit.
160
- // Right now it's independent from where the camera is actually looking from,
161
- // and thus we're just getting some maximum that will work for sure.
162
- const box = getBoundingBox(objects, undefined, camera?.layers);
163
- const boxCopy = box.clone();
164
- box.getCenter(center);
165
-
166
- const box_size = new Vector3();
167
- box.getSize(box_size);
168
-
169
- // project this box into camera space
170
- if (camera instanceof PerspectiveCamera) camera.updateProjectionMatrix();
171
- camera.updateMatrixWorld();
172
- box.applyMatrix4(camera.matrixWorldInverse);
173
-
174
- box.getSize(size);
175
- box.setFromCenterAndSize(center, size);
176
- if (Number.isNaN(size.x) || Number.isNaN(size.y) || Number.isNaN(size.z)) {
177
- console.warn("Camera fit size resultet in NaN", camera, box);
178
- return null;
179
- }
180
- if (size.length() <= 0.0000000001) {
181
- console.warn("Camera fit size is zero", box);
182
- return null;
183
- }
184
-
185
- const verticalFov = fov;
186
- const horizontalFov = 2 * Math.atan(Math.tan(verticalFov * Math.PI / 360 / 2) * aspect) / Math.PI * 360;
187
- const fitHeightDistance = size.y / (2 * Math.atan(Math.PI * verticalFov / 360));
188
- const fitWidthDistance = size.x / (2 * Math.atan(Math.PI * horizontalFov / 360));
189
-
190
- const distance = fitOffset * Math.max(fitHeightDistance, fitWidthDistance) + size.z / 2;
191
- options.maxZoom = distance * 10;
192
- options.minZoom = distance * 0.01;
193
-
194
- if (options.debug === true) {
195
- console.log("Fit camera to objects", { fitHeightDistance, fitWidthDistance, distance, verticalFov, horizontalFov });
196
- }
197
-
198
- const verticalOffset = 0.05;
199
- const lookAt = center.clone();
200
- lookAt.y -= size.y * verticalOffset;
201
- if (options.targetOffset) {
202
- if (options.targetOffset.x !== undefined) lookAt.x += options.targetOffset.x;
203
- if (options.targetOffset.y !== undefined) lookAt.y += options.targetOffset.y;
204
- if (options.targetOffset.z !== undefined) lookAt.z += options.targetOffset.z;
205
- }
206
- if (options.relativeTargetOffset) {
207
- if (options.relativeTargetOffset.x !== undefined) lookAt.x += options.relativeTargetOffset.x * size.x;
208
- if (options.relativeTargetOffset.y !== undefined) lookAt.y += options.relativeTargetOffset.y * size.y;
209
- if (options.relativeTargetOffset.z !== undefined) lookAt.z += options.relativeTargetOffset.z * size.z;
210
- }
211
- // this.setLookTargetPosition(lookAt, immediate);
212
- // this.setFieldOfView(options.fov, immediate);
213
-
214
- if (cameraNearFar == undefined || cameraNearFar == "auto") {
215
- // Check if the scene has a GroundProjectedEnv and include the scale to the far plane so that it doesnt cut off
216
- const groundprojection = findObjectOfType(GroundProjectedEnv);
217
- const groundProjectionRadius = groundprojection ? groundprojection.radius : 0;
218
- const boundsMax = Math.max(box_size.x, box_size.y, box_size.z, groundProjectionRadius);
219
- // TODO: this doesnt take the Camera component nearClipPlane into account
220
- if (camera instanceof PerspectiveCamera) {
221
- camera.near = (distance / 100);
222
- camera.far = boundsMax + distance * 10;
223
- camera.updateProjectionMatrix();
224
- }
225
-
226
- // adjust maxZoom so that the ground projection radius is always inside
227
- if (groundprojection) {
228
- options.maxZoom = Math.max(Math.min(options.maxZoom, groundProjectionRadius * 0.5), distance);
229
- }
230
- }
231
-
232
- // ensure we're not clipping out of the current zoom level just because we're fitting
233
- if (options.currentZoom !== undefined) {
234
- if (options.currentZoom < options.minZoom) options.minZoom = options.currentZoom * 0.9;
235
- if (options.currentZoom > options.maxZoom) options.maxZoom = options.currentZoom * 1.1;
236
- }
237
-
238
- const direction = center.clone();
239
- if (options.fitDirection) {
240
- direction.sub(new Vector3().copy(options.fitDirection).multiplyScalar(1_000_000));
241
- }
242
- else {
243
- direction.sub(camera.worldPosition);
244
- }
245
- if (centerCamera === "y")
246
- direction.y = 0;
247
- direction.normalize();
248
- direction.multiplyScalar(distance);
249
- if (centerCamera === "y")
250
- direction.y += -verticalOffset * 4 * distance;
251
-
252
- let cameraLocalPosition = center.clone().sub(direction);
253
- if (options.cameraOffset) {
254
- if (options.cameraOffset.x !== undefined) cameraLocalPosition.x += options.cameraOffset.x;
255
- if (options.cameraOffset.y !== undefined) cameraLocalPosition.y += options.cameraOffset.y;
256
- if (options.cameraOffset.z !== undefined) cameraLocalPosition.z += options.cameraOffset.z;
257
- }
258
- if (options.relativeCameraOffset) {
259
- if (options.relativeCameraOffset.x !== undefined) cameraLocalPosition.x += options.relativeCameraOffset.x * size.x;
260
- if (options.relativeCameraOffset.y !== undefined) cameraLocalPosition.y += options.relativeCameraOffset.y * size.y;
261
- if (options.relativeCameraOffset.z !== undefined) cameraLocalPosition.z += options.relativeCameraOffset.z * size.z;
262
- }
263
- if (camera.parent) {
264
- cameraLocalPosition = camera.parent.worldToLocal(cameraLocalPosition);
265
- }
266
- // this.setCameraTargetPosition(cameraLocalPosition, immediate);
267
-
268
- if (options.debug) {
269
- Gizmos.DrawWireBox3(box, 0xffff33, 10);
270
- Gizmos.DrawWireBox3(boxCopy, 0x00ff00, 10);
271
- }
272
-
273
- if (options.autoApply) {
274
- camera.position.copy(cameraLocalPosition);
275
- camera.lookAt(lookAt);
276
- if (fov > 0 && camera instanceof PerspectiveCamera) {
277
- camera.fov = fov;
278
- camera.updateProjectionMatrix();
279
- }
280
- }
281
-
282
- return {
283
- camera: camera,
284
- position: cameraLocalPosition,
285
- lookAt: lookAt,
286
- fov: options.fov,
287
- }
288
- }
@@ -1,99 +0,0 @@
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
- }