@needle-tools/engine 4.9.2 → 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 (105) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/components.needle.json +1 -1
  3. package/dist/{gltf-progressive-DhE1A6hX.min.js → gltf-progressive-CoZbSfPR.min.js} +1 -1
  4. package/dist/{gltf-progressive-egsMzRdv.js → gltf-progressive-DUR9TuAH.js} +3 -3
  5. package/dist/{gltf-progressive-DWiyqrwB.umd.cjs → gltf-progressive-Iy7aSAPk.umd.cjs} +1 -1
  6. package/dist/{needle-engine.bundle-WLYWw5OF.umd.cjs → needle-engine.bundle-DAo7BPxQ.umd.cjs} +149 -127
  7. package/dist/needle-engine.bundle-DP2gYtOQ.min.js +1638 -0
  8. package/dist/{needle-engine.bundle-XBRfMDwo.js → needle-engine.bundle-TvT7wv7z.js} +7567 -7380
  9. package/dist/needle-engine.js +446 -444
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/dist/{postprocessing-B_FzkwDz.min.js → postprocessing-BHMVuZQ1.min.js} +53 -53
  13. package/dist/{postprocessing-DTX5VXrj.umd.cjs → postprocessing-BsnRNRRS.umd.cjs} +76 -76
  14. package/dist/{postprocessing-DP1U_BpT.js → postprocessing-DQ2pynXW.js} +213 -191
  15. package/dist/{three-BK56xWDs.umd.cjs → three-B-jwTHao.umd.cjs} +11 -11
  16. package/dist/{three-CsHK73Zc.js → three-CJSAehtG.js} +1 -0
  17. package/dist/{three-examples-Bph291U2.min.js → three-examples-BivkhnvN.min.js} +1 -1
  18. package/dist/{three-examples-C9WfZu-X.umd.cjs → three-examples-Deqc1bNw.umd.cjs} +1 -1
  19. package/dist/{three-examples-BvMpKSun.js → three-examples-Doq0rvFU.js} +1 -1
  20. package/dist/{three-mesh-ui-CN6aRT7i.js → three-mesh-ui-CktOi6oI.js} +1 -1
  21. package/dist/{three-mesh-ui-DnxkZWNA.umd.cjs → three-mesh-ui-CsHwj9cJ.umd.cjs} +1 -1
  22. package/dist/{three-mesh-ui-n_qS2BM-.min.js → three-mesh-ui-DhYXcXZe.min.js} +1 -1
  23. package/dist/{three-TNFQHSFa.min.js → three-qw28ZtTy.min.js} +10 -10
  24. package/dist/{vendor-BtJpSuCj.umd.cjs → vendor-D0Yvltn9.umd.cjs} +1 -1
  25. package/dist/{vendor-k9i6CeGi.js → vendor-DU8tJyl_.js} +1 -1
  26. package/dist/{vendor-XJ9xiwrv.min.js → vendor-JyrX4DVM.min.js} +1 -1
  27. package/lib/engine/api.d.ts +1 -0
  28. package/lib/engine/api.js +1 -0
  29. package/lib/engine/api.js.map +1 -1
  30. package/lib/engine/codegen/register_types.js +2 -0
  31. package/lib/engine/codegen/register_types.js.map +1 -1
  32. package/lib/engine/engine_animation.d.ts +21 -1
  33. package/lib/engine/engine_animation.js +32 -1
  34. package/lib/engine/engine_animation.js.map +1 -1
  35. package/lib/engine/engine_camera.fit.d.ts +68 -0
  36. package/lib/engine/engine_camera.fit.js +193 -0
  37. package/lib/engine/engine_camera.fit.js.map +1 -0
  38. package/lib/engine/engine_gizmos.d.ts +2 -2
  39. package/lib/engine/engine_gizmos.js +2 -2
  40. package/lib/engine/engine_physics.js +6 -3
  41. package/lib/engine/engine_physics.js.map +1 -1
  42. package/lib/engine/webcomponents/needle-engine.d.ts +1 -0
  43. package/lib/engine/webcomponents/needle-engine.js +6 -0
  44. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  45. package/lib/engine/webcomponents/needle-engine.loading.js +59 -23
  46. package/lib/engine/webcomponents/needle-engine.loading.js.map +1 -1
  47. package/lib/engine/xr/NeedleXRSession.d.ts +1 -0
  48. package/lib/engine/xr/NeedleXRSession.js +25 -11
  49. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  50. package/lib/engine-components/AnimatorController.js +16 -0
  51. package/lib/engine-components/AnimatorController.js.map +1 -1
  52. package/lib/engine-components/CameraUtils.js +8 -9
  53. package/lib/engine-components/CameraUtils.js.map +1 -1
  54. package/lib/engine-components/OrbitControls.d.ts +4 -47
  55. package/lib/engine-components/OrbitControls.js +30 -178
  56. package/lib/engine-components/OrbitControls.js.map +1 -1
  57. package/lib/engine-components/Renderer.js +9 -5
  58. package/lib/engine-components/Renderer.js.map +1 -1
  59. package/lib/engine-components/SpriteRenderer.js +4 -1
  60. package/lib/engine-components/SpriteRenderer.js.map +1 -1
  61. package/lib/engine-components/api.d.ts +0 -1
  62. package/lib/engine-components/api.js.map +1 -1
  63. package/lib/engine-components/codegen/components.d.ts +1 -0
  64. package/lib/engine-components/codegen/components.js +1 -0
  65. package/lib/engine-components/codegen/components.js.map +1 -1
  66. package/lib/engine-components/web/Clickthrough.d.ts +3 -0
  67. package/lib/engine-components/web/Clickthrough.js +3 -0
  68. package/lib/engine-components/web/Clickthrough.js.map +1 -1
  69. package/lib/engine-components/web/CursorFollow.d.ts +3 -0
  70. package/lib/engine-components/web/CursorFollow.js +3 -0
  71. package/lib/engine-components/web/CursorFollow.js.map +1 -1
  72. package/lib/engine-components/web/HoverAnimation.d.ts +44 -0
  73. package/lib/engine-components/web/HoverAnimation.js +105 -0
  74. package/lib/engine-components/web/HoverAnimation.js.map +1 -0
  75. package/lib/engine-components/web/ScrollFollow.d.ts +4 -0
  76. package/lib/engine-components/web/ScrollFollow.js +4 -0
  77. package/lib/engine-components/web/ScrollFollow.js.map +1 -1
  78. package/lib/engine-components/web/index.d.ts +1 -0
  79. package/lib/engine-components/web/index.js +1 -0
  80. package/lib/engine-components/web/index.js.map +1 -1
  81. package/package.json +2 -2
  82. package/plugins/vite/alias.js +5 -3
  83. package/plugins/vite/poster-client.js +22 -21
  84. package/src/engine/api.ts +2 -1
  85. package/src/engine/codegen/register_types.ts +2 -0
  86. package/src/engine/engine_animation.ts +69 -1
  87. package/src/engine/engine_camera.fit.ts +288 -0
  88. package/src/engine/engine_gizmos.ts +2 -2
  89. package/src/engine/engine_physics.ts +6 -3
  90. package/src/engine/webcomponents/needle-engine.loading.ts +63 -24
  91. package/src/engine/webcomponents/needle-engine.ts +6 -1
  92. package/src/engine/xr/NeedleXRSession.ts +25 -10
  93. package/src/engine-components/AnimatorController.ts +21 -2
  94. package/src/engine-components/CameraUtils.ts +8 -9
  95. package/src/engine-components/OrbitControls.ts +30 -239
  96. package/src/engine-components/Renderer.ts +9 -6
  97. package/src/engine-components/SpriteRenderer.ts +3 -1
  98. package/src/engine-components/api.ts +0 -1
  99. package/src/engine-components/codegen/components.ts +1 -0
  100. package/src/engine-components/web/Clickthrough.ts +3 -0
  101. package/src/engine-components/web/CursorFollow.ts +3 -0
  102. package/src/engine-components/web/HoverAnimation.ts +99 -0
  103. package/src/engine-components/web/ScrollFollow.ts +4 -0
  104. package/src/engine-components/web/index.ts +1 -0
  105. package/dist/needle-engine.bundle-DwspSk2O.min.js +0 -1616
@@ -357,7 +357,7 @@ export class Renderer extends Behaviour implements IRenderer {
357
357
  get sharedMaterials(): SharedMaterialArray {
358
358
 
359
359
  // @ts-ignore during deserialization code might access this property *before* the setter and then create an empty array
360
- if(!this.__didAwake) return null;
360
+ if (!this.__didAwake) return null;
361
361
 
362
362
  if (!this._sharedMaterials || !this._sharedMaterials.is(this)) {
363
363
  if (!this._originalMaterials) this._originalMaterials = [];
@@ -674,7 +674,7 @@ export class Renderer extends Behaviour implements IRenderer {
674
674
  this.applySettings(this.gameObject);
675
675
  }
676
676
 
677
- if (this.sharedMaterials.changed) {
677
+ if (this.sharedMaterials?.changed) {
678
678
  this.sharedMaterials.changed = false;
679
679
  this.applyLightmapping();
680
680
  }
@@ -718,12 +718,15 @@ export class Renderer extends Behaviour implements IRenderer {
718
718
  // since three 163 we need to set the envMap to the scene envMap if it is not set
719
719
  // otherwise the envmapIntensity has no effect: https://github.com/mrdoob/three.js/pull/27903
720
720
  // internal issue: https://linear.app/needle/issue/NE-6363
721
- for (const mat of this._sharedMaterials) {
722
- // If the material has a envMap and is NOT using a reflection probe we set the envMap to the scene environment
723
- if (mat && "envMap" in mat && "envMapIntensity" in mat && !ReflectionProbe.isUsingReflectionProbe(mat)) {
724
- mat.envMap = this.context.scene.environment;
721
+ if (this._sharedMaterials) {
722
+ for (const mat of this._sharedMaterials) {
723
+ // If the material has a envMap and is NOT using a reflection probe we set the envMap to the scene environment
724
+ if (mat && "envMap" in mat && "envMapIntensity" in mat && !ReflectionProbe.isUsingReflectionProbe(mat)) {
725
+ mat.envMap = this.context.scene.environment;
726
+ }
725
727
  }
726
728
  }
729
+ else if (debugRenderer) console.warn("[Renderer] sharedMaterials not initialized yet: " + this.name);
727
730
  }
728
731
 
729
732
  private onBeforeRenderThree = (_renderer, _scene, _camera, _geometry, material, _group) => {
@@ -329,7 +329,9 @@ export class SpriteRenderer extends Behaviour {
329
329
  set sprite(value: Sprite | SpriteData | undefined | number) {
330
330
  if (value === this._spriteSheet) return;
331
331
  if (typeof value === "number") {
332
- const index = Math.floor(value);
332
+ // the value if interpolated is sometimes *slightly* off (e.g. 0.999999 or 1.000001) so we round it
333
+ const index = Math.round(value);
334
+ if (debug) console.log("[SpriteSheet] Set index to " + index + " (was " + this.spriteIndex + ")", value);
333
335
  this.spriteIndex = index;
334
336
  }
335
337
  else if (value instanceof Sprite) {
@@ -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";