@needle-tools/engine 5.1.0-alpha.2 → 5.1.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.
Files changed (274) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/SKILL.md +4 -1
  3. package/components.needle.json +1 -1
  4. package/dist/needle-engine.bundle-AjVIot3d.min.js +1733 -0
  5. package/dist/{needle-engine.bundle-dit3f1l5.js → needle-engine.bundle-B7cqsI4c.js} +12199 -11704
  6. package/dist/needle-engine.bundle-DQCuBTVp.umd.cjs +1733 -0
  7. package/dist/needle-engine.d.ts +879 -226
  8. package/dist/needle-engine.js +584 -582
  9. package/dist/needle-engine.min.js +1 -1
  10. package/dist/needle-engine.umd.cjs +1 -1
  11. package/lib/engine/api.d.ts +5 -0
  12. package/lib/engine/api.js +4 -0
  13. package/lib/engine/api.js.map +1 -1
  14. package/lib/engine/codegen/register_types.js +2 -10
  15. package/lib/engine/codegen/register_types.js.map +1 -1
  16. package/lib/engine/debug/debug_spatial_console.d.ts +2 -0
  17. package/lib/engine/debug/debug_spatial_console.js +10 -7
  18. package/lib/engine/debug/debug_spatial_console.js.map +1 -1
  19. package/lib/engine/engine_addressables.d.ts +2 -0
  20. package/lib/engine/engine_addressables.js +6 -3
  21. package/lib/engine/engine_addressables.js.map +1 -1
  22. package/lib/engine/engine_audio.d.ts +68 -0
  23. package/lib/engine/engine_audio.js +172 -0
  24. package/lib/engine/engine_audio.js.map +1 -1
  25. package/lib/engine/engine_components.js +1 -1
  26. package/lib/engine/engine_components.js.map +1 -1
  27. package/lib/engine/engine_context.d.ts +1 -1
  28. package/lib/engine/engine_context.js +3 -2
  29. package/lib/engine/engine_context.js.map +1 -1
  30. package/lib/engine/engine_disposable.d.ts +172 -0
  31. package/lib/engine/engine_disposable.js +136 -0
  32. package/lib/engine/engine_disposable.js.map +1 -0
  33. package/lib/engine/engine_gameobject.d.ts +1 -10
  34. package/lib/engine/engine_gameobject.js +22 -120
  35. package/lib/engine/engine_gameobject.js.map +1 -1
  36. package/lib/engine/engine_gltf_builtin_components.js +7 -69
  37. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  38. package/lib/engine/engine_init.js +13 -3
  39. package/lib/engine/engine_init.js.map +1 -1
  40. package/lib/engine/engine_input.d.ts +1 -1
  41. package/lib/engine/engine_input.js +1 -1
  42. package/lib/engine/engine_input.js.map +1 -1
  43. package/lib/engine/engine_instantiate_resolve.d.ts +42 -0
  44. package/lib/engine/engine_instantiate_resolve.js +372 -0
  45. package/lib/engine/engine_instantiate_resolve.js.map +1 -0
  46. package/lib/engine/engine_license.js +1 -1
  47. package/lib/engine/engine_license.js.map +1 -1
  48. package/lib/engine/engine_mainloop_utils.js +7 -4
  49. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  50. package/lib/engine/engine_networking.d.ts +51 -37
  51. package/lib/engine/engine_networking.js +132 -82
  52. package/lib/engine/engine_networking.js.map +1 -1
  53. package/lib/engine/engine_networking.transport.websocket.d.ts +15 -0
  54. package/lib/engine/engine_networking.transport.websocket.js +38 -0
  55. package/lib/engine/engine_networking.transport.websocket.js.map +1 -0
  56. package/lib/engine/engine_networking_blob.js +1 -1
  57. package/lib/engine/engine_networking_blob.js.map +1 -1
  58. package/lib/engine/engine_networking_instantiate.js +2 -2
  59. package/lib/engine/engine_networking_instantiate.js.map +1 -1
  60. package/lib/engine/engine_networking_types.d.ts +39 -1
  61. package/lib/engine/engine_networking_types.js +7 -0
  62. package/lib/engine/engine_networking_types.js.map +1 -1
  63. package/lib/engine/engine_physics_rapier.d.ts +11 -3
  64. package/lib/engine/engine_physics_rapier.js +88 -25
  65. package/lib/engine/engine_physics_rapier.js.map +1 -1
  66. package/lib/engine/engine_scenedata.d.ts +2 -0
  67. package/lib/engine/engine_scenedata.js +4 -2
  68. package/lib/engine/engine_scenedata.js.map +1 -1
  69. package/lib/engine/engine_serialization_builtin_serializer.d.ts +10 -16
  70. package/lib/engine/engine_serialization_builtin_serializer.js +56 -46
  71. package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
  72. package/lib/engine/engine_serialization_core.d.ts +1 -0
  73. package/lib/engine/engine_serialization_core.js +7 -0
  74. package/lib/engine/engine_serialization_core.js.map +1 -1
  75. package/lib/engine/engine_types.d.ts +19 -11
  76. package/lib/engine/engine_types.js +1 -1
  77. package/lib/engine/engine_types.js.map +1 -1
  78. package/lib/engine/engine_util_decorator.js +7 -2
  79. package/lib/engine/engine_util_decorator.js.map +1 -1
  80. package/lib/engine/engine_utils.d.ts +1 -1
  81. package/lib/engine/engine_utils.js +19 -5
  82. package/lib/engine/engine_utils.js.map +1 -1
  83. package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
  84. package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js.map +1 -1
  85. package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +1 -1
  86. package/lib/engine/webcomponents/needle menu/needle-menu.js +1 -1
  87. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  88. package/lib/engine/webcomponents/needle-engine.d.ts +10 -4
  89. package/lib/engine/webcomponents/needle-engine.js +1 -1
  90. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  91. package/lib/engine/xr/NeedleXRSession.d.ts +3 -2
  92. package/lib/engine/xr/NeedleXRSession.js +50 -14
  93. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  94. package/lib/engine/xr/events.d.ts +1 -1
  95. package/lib/engine/xr/events.js.map +1 -1
  96. package/lib/engine-components/Animation.js +17 -16
  97. package/lib/engine-components/Animation.js.map +1 -1
  98. package/lib/engine-components/Animator.d.ts +6 -0
  99. package/lib/engine-components/Animator.js +17 -12
  100. package/lib/engine-components/Animator.js.map +1 -1
  101. package/lib/engine-components/AnimatorController.builder.d.ts +113 -0
  102. package/lib/engine-components/AnimatorController.builder.js +195 -0
  103. package/lib/engine-components/AnimatorController.builder.js.map +1 -0
  104. package/lib/engine-components/AnimatorController.d.ts +4 -119
  105. package/lib/engine-components/AnimatorController.js +35 -233
  106. package/lib/engine-components/AnimatorController.js.map +1 -1
  107. package/lib/engine-components/AudioSource.d.ts +19 -3
  108. package/lib/engine-components/AudioSource.js +121 -68
  109. package/lib/engine-components/AudioSource.js.map +1 -1
  110. package/lib/engine-components/Collider.d.ts +18 -9
  111. package/lib/engine-components/Collider.js +61 -14
  112. package/lib/engine-components/Collider.js.map +1 -1
  113. package/lib/engine-components/Component.d.ts +72 -9
  114. package/lib/engine-components/Component.js +114 -10
  115. package/lib/engine-components/Component.js.map +1 -1
  116. package/lib/engine-components/DragControls.d.ts +7 -0
  117. package/lib/engine-components/DragControls.js +19 -7
  118. package/lib/engine-components/DragControls.js.map +1 -1
  119. package/lib/engine-components/EventList.d.ts +31 -9
  120. package/lib/engine-components/EventList.js +37 -76
  121. package/lib/engine-components/EventList.js.map +1 -1
  122. package/lib/engine-components/Joints.d.ts +4 -2
  123. package/lib/engine-components/Joints.js +19 -3
  124. package/lib/engine-components/Joints.js.map +1 -1
  125. package/lib/engine-components/Light.js +9 -1
  126. package/lib/engine-components/Light.js.map +1 -1
  127. package/lib/engine-components/Networking.d.ts +1 -1
  128. package/lib/engine-components/Networking.js +1 -1
  129. package/lib/engine-components/OrbitControls.js +16 -11
  130. package/lib/engine-components/OrbitControls.js.map +1 -1
  131. package/lib/engine-components/ReflectionProbe.js +2 -0
  132. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  133. package/lib/engine-components/RigidBody.d.ts +12 -4
  134. package/lib/engine-components/RigidBody.js +18 -4
  135. package/lib/engine-components/RigidBody.js.map +1 -1
  136. package/lib/engine-components/SeeThrough.js +2 -2
  137. package/lib/engine-components/SeeThrough.js.map +1 -1
  138. package/lib/engine-components/api.d.ts +1 -1
  139. package/lib/engine-components/api.js +1 -1
  140. package/lib/engine-components/api.js.map +1 -1
  141. package/lib/engine-components/codegen/components.d.ts +3 -9
  142. package/lib/engine-components/codegen/components.js +3 -9
  143. package/lib/engine-components/codegen/components.js.map +1 -1
  144. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +1 -1
  145. package/lib/engine-components/postprocessing/VolumeParameter.d.ts +2 -0
  146. package/lib/engine-components/postprocessing/VolumeParameter.js +4 -1
  147. package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -1
  148. package/lib/engine-components/timeline/PlayableDirector.d.ts +16 -6
  149. package/lib/engine-components/timeline/PlayableDirector.js +70 -62
  150. package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
  151. package/lib/engine-components/timeline/SignalAsset.d.ts +3 -1
  152. package/lib/engine-components/timeline/SignalAsset.js +1 -0
  153. package/lib/engine-components/timeline/SignalAsset.js.map +1 -1
  154. package/lib/engine-components/timeline/TimelineBuilder.d.ts +247 -0
  155. package/lib/engine-components/timeline/TimelineBuilder.js +400 -0
  156. package/lib/engine-components/timeline/TimelineBuilder.js.map +1 -0
  157. package/lib/engine-components/timeline/TimelineModels.d.ts +2 -1
  158. package/lib/engine-components/timeline/TimelineModels.js +3 -0
  159. package/lib/engine-components/timeline/TimelineModels.js.map +1 -1
  160. package/lib/engine-components/timeline/TimelineTracks.d.ts +23 -0
  161. package/lib/engine-components/timeline/TimelineTracks.js +71 -13
  162. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  163. package/lib/engine-components/timeline/index.d.ts +2 -1
  164. package/lib/engine-components/timeline/index.js +2 -0
  165. package/lib/engine-components/timeline/index.js.map +1 -1
  166. package/lib/engine-components/ui/Canvas.d.ts +1 -1
  167. package/lib/engine-components/ui/Canvas.js +2 -8
  168. package/lib/engine-components/ui/Canvas.js.map +1 -1
  169. package/lib/engine-components/ui/Text.d.ts +1 -0
  170. package/lib/engine-components/ui/Text.js +10 -7
  171. package/lib/engine-components/ui/Text.js.map +1 -1
  172. package/lib/engine-components/web/CursorFollow.js +21 -12
  173. package/lib/engine-components/web/CursorFollow.js.map +1 -1
  174. package/lib/engine-components/webxr/WebXRImageTracking.js +4 -0
  175. package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
  176. package/package.json +2 -83
  177. package/plugins/common/license.js +5 -2
  178. package/plugins/common/worker.js +9 -4
  179. package/plugins/vite/asap.js +17 -8
  180. package/plugins/vite/dependencies.js +29 -10
  181. package/plugins/vite/dependency-watcher.js +2 -2
  182. package/plugins/vite/editor-connection.js +3 -3
  183. package/plugins/vite/local-files-core.js +3 -3
  184. package/plugins/vite/local-files-utils.d.ts +3 -1
  185. package/plugins/vite/local-files-utils.js +29 -5
  186. package/plugins/vite/reload.js +1 -1
  187. package/plugins/vite/server.js +2 -1
  188. package/src/engine/api.ts +7 -0
  189. package/src/engine/codegen/register_types.ts +2 -10
  190. package/src/engine/debug/debug_spatial_console.ts +10 -7
  191. package/src/engine/engine_addressables.ts +6 -3
  192. package/src/engine/engine_audio.ts +184 -0
  193. package/src/engine/engine_components.ts +1 -1
  194. package/src/engine/engine_context.ts +4 -3
  195. package/src/engine/engine_disposable.ts +214 -0
  196. package/src/engine/engine_gameobject.ts +54 -159
  197. package/src/engine/engine_gltf_builtin_components.ts +7 -76
  198. package/src/engine/engine_init.ts +13 -3
  199. package/src/engine/engine_input.ts +1 -1
  200. package/src/engine/engine_instantiate_resolve.ts +407 -0
  201. package/src/engine/engine_license.ts +1 -1
  202. package/src/engine/engine_mainloop_utils.ts +7 -4
  203. package/src/engine/engine_networking.transport.websocket.ts +45 -0
  204. package/src/engine/engine_networking.ts +161 -137
  205. package/src/engine/engine_networking_blob.ts +1 -1
  206. package/src/engine/engine_networking_instantiate.ts +2 -2
  207. package/src/engine/engine_networking_types.ts +41 -1
  208. package/src/engine/engine_physics_rapier.ts +82 -27
  209. package/src/engine/engine_scenedata.ts +5 -3
  210. package/src/engine/engine_serialization_builtin_serializer.ts +64 -52
  211. package/src/engine/engine_serialization_core.ts +9 -0
  212. package/src/engine/engine_types.ts +24 -15
  213. package/src/engine/engine_util_decorator.ts +7 -2
  214. package/src/engine/engine_utils.ts +16 -5
  215. package/src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +1 -1
  216. package/src/engine/webcomponents/needle menu/needle-menu.ts +1 -1
  217. package/src/engine/webcomponents/needle-engine.ts +10 -4
  218. package/src/engine/xr/NeedleXRSession.ts +48 -13
  219. package/src/engine/xr/events.ts +1 -1
  220. package/src/engine-components/Animation.ts +19 -16
  221. package/src/engine-components/Animator.ts +18 -11
  222. package/src/engine-components/AnimatorController.builder.ts +261 -0
  223. package/src/engine-components/AnimatorController.ts +23 -292
  224. package/src/engine-components/AudioSource.ts +130 -79
  225. package/src/engine-components/Collider.ts +66 -18
  226. package/src/engine-components/Component.ts +118 -20
  227. package/src/engine-components/DragControls.ts +18 -11
  228. package/src/engine-components/EventList.ts +45 -83
  229. package/src/engine-components/Joints.ts +20 -4
  230. package/src/engine-components/Light.ts +10 -2
  231. package/src/engine-components/Networking.ts +1 -1
  232. package/src/engine-components/OrbitControls.ts +18 -9
  233. package/src/engine-components/ReflectionProbe.ts +2 -0
  234. package/src/engine-components/RigidBody.ts +18 -4
  235. package/src/engine-components/SeeThrough.ts +2 -2
  236. package/src/engine-components/api.ts +1 -1
  237. package/src/engine-components/codegen/components.ts +3 -9
  238. package/src/engine-components/postprocessing/VolumeParameter.ts +4 -1
  239. package/src/engine-components/timeline/PlayableDirector.ts +67 -65
  240. package/src/engine-components/timeline/SignalAsset.ts +4 -1
  241. package/src/engine-components/timeline/TimelineBuilder.ts +564 -0
  242. package/src/engine-components/timeline/TimelineModels.ts +5 -1
  243. package/src/engine-components/timeline/TimelineTracks.ts +74 -13
  244. package/src/engine-components/timeline/index.ts +2 -1
  245. package/src/engine-components/ui/Canvas.ts +2 -8
  246. package/src/engine-components/ui/Text.ts +12 -8
  247. package/src/engine-components/web/CursorFollow.ts +21 -13
  248. package/src/engine-components/webxr/WebXRImageTracking.ts +2 -0
  249. package/dist/needle-engine.bundle-B-5Q2CpC.min.js +0 -1732
  250. package/dist/needle-engine.bundle-qZfVf_v-.umd.cjs +0 -1732
  251. package/lib/engine-components/AvatarLoader.d.ts +0 -80
  252. package/lib/engine-components/AvatarLoader.js +0 -232
  253. package/lib/engine-components/AvatarLoader.js.map +0 -1
  254. package/lib/engine-components/avatar/AvatarBlink_Simple.d.ts +0 -11
  255. package/lib/engine-components/avatar/AvatarBlink_Simple.js +0 -77
  256. package/lib/engine-components/avatar/AvatarBlink_Simple.js.map +0 -1
  257. package/lib/engine-components/avatar/AvatarEyeLook_Rotation.d.ts +0 -14
  258. package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js +0 -69
  259. package/lib/engine-components/avatar/AvatarEyeLook_Rotation.js.map +0 -1
  260. package/lib/engine-components/avatar/Avatar_Brain_LookAt.d.ts +0 -29
  261. package/lib/engine-components/avatar/Avatar_Brain_LookAt.js +0 -122
  262. package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +0 -1
  263. package/lib/engine-components/avatar/Avatar_MouthShapes.d.ts +0 -15
  264. package/lib/engine-components/avatar/Avatar_MouthShapes.js +0 -80
  265. package/lib/engine-components/avatar/Avatar_MouthShapes.js.map +0 -1
  266. package/lib/engine-components/avatar/Avatar_MustacheShake.d.ts +0 -9
  267. package/lib/engine-components/avatar/Avatar_MustacheShake.js +0 -30
  268. package/lib/engine-components/avatar/Avatar_MustacheShake.js.map +0 -1
  269. package/src/engine-components/AvatarLoader.ts +0 -264
  270. package/src/engine-components/avatar/AvatarBlink_Simple.ts +0 -70
  271. package/src/engine-components/avatar/AvatarEyeLook_Rotation.ts +0 -64
  272. package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +0 -140
  273. package/src/engine-components/avatar/Avatar_MouthShapes.ts +0 -84
  274. package/src/engine-components/avatar/Avatar_MustacheShake.ts +0 -32
@@ -591,6 +591,20 @@ const muteAudioTracks = getParam("mutetimeline");
591
591
 
592
592
  declare type AudioClipModel = Models.ClipModel & { _didTriggerPlay: boolean };
593
593
 
594
+ /**
595
+ * Handles audio playback for a timeline audio track.
596
+ *
597
+ * **Runtime mutation:** The track model is read fresh every frame during `evaluate()`.
598
+ * You can mutate `track.volume`, `clip.start`, `clip.end`, `clip.asset.volume` etc.
599
+ * at any time — changes take effect on the next frame without rebuilding the timeline.
600
+ *
601
+ * **Audio stopping:** Audio clips are automatically stopped when:
602
+ * - Timeline time moves outside a clip's `[start, end]` range (e.g. jumping or normal playback advancing past a clip)
603
+ * - The track is muted (via `muted = true`)
604
+ * - The director is stopped (`director.stop()`)
605
+ * - The director is paused (`director.pause()`)
606
+ * - The director is disabled or destroyed
607
+ */
594
608
  export class AudioTrackHandler extends TrackHandler {
595
609
 
596
610
  models: Array<AudioClipModel> = [];
@@ -600,6 +614,10 @@ export class AudioTrackHandler extends TrackHandler {
600
614
  lastTime: number = 0;
601
615
  audioSource?: AudioSource;
602
616
 
617
+ /** Track-level volume multiplier (0–1). Applied on top of per-clip volume each frame. */
618
+ get volume(): number { return this.track.volume ?? 1; }
619
+ set volume(val: number) { this.track.volume = val; }
620
+
603
621
  private _audioLoader: AudioLoader | null = null;
604
622
 
605
623
  private getAudioFilePath(path: string) {
@@ -863,21 +881,29 @@ export class SignalTrackHandler extends TrackHandler {
863
881
  didTrigger: boolean[] = [];
864
882
  receivers: Array<SignalReceiver | null> = [];
865
883
 
866
- // TODO: test when timeline signals are being reset in Unity
867
- // onEnable() {
868
- // for (let i = 0; i < this.didTrigger?.length; i++) {
869
- // this.didTrigger[i] = false;
870
- // }
871
- // }
884
+ private _lastTime: number = -1;
885
+
886
+ onEnable() {
887
+ // Reset state so signals fire fresh on replay
888
+ this._lastTime = -1;
889
+ for (let i = 0; i < this.didTrigger.length; i++) {
890
+ this.didTrigger[i] = false;
891
+ }
892
+ }
872
893
 
873
- // private _lastTime: number = -1;
894
+ onMuteChanged() {
895
+ // When unmuted, sync _lastTime to avoid stale comparisons
896
+ if (!this.track.muted) {
897
+ this._lastTime = -1;
898
+ }
899
+ }
874
900
 
875
901
  evaluate(time: number) {
876
902
  if (this.track.muted) return;
877
903
 
878
- // let lastTime = this._lastTime;
879
- // if (lastTime === -1) lastTime = time;
880
- // this._lastTime = time;
904
+ let lastTime = this._lastTime;
905
+ if (lastTime === -1) lastTime = time;
906
+ this._lastTime = time;
881
907
 
882
908
  const estimatedFrameLengthWithPadding = this.director.context.time.deltaTime * 1.5;
883
909
 
@@ -899,7 +925,6 @@ export class SignalTrackHandler extends TrackHandler {
899
925
  isActive = true;
900
926
  }
901
927
  }
902
- // console.log(time, td, isActive);
903
928
  if (isActive) {
904
929
  if (!wasTriggered) {
905
930
  if (debug)
@@ -917,9 +942,45 @@ export class SignalTrackHandler extends TrackHandler {
917
942
  }
918
943
  }
919
944
  }
920
- else {
921
- if (!model.emitOnce)
945
+ else if (!model.emitOnce) {
946
+ // Only reset didTrigger when time has moved backward past the signal
947
+ // (e.g. timeline looped or was scrubbed back). Don't reset just because
948
+ // the deltaTime-based activation window shrank on a fast frame.
949
+ if (time < model.time && lastTime >= model.time) {
922
950
  this.didTrigger[i] = false;
951
+ }
952
+ }
953
+ }
954
+ }
955
+ }
956
+
957
+
958
+ export class ActivationTrackHandler extends TrackHandler {
959
+
960
+ evaluate(time: number) {
961
+ if (this.track.muted) return;
962
+ // NE-3241 / NE-3737: Don't evaluate when stopped (preserves "Leave as is" post-playback).
963
+ // But DO evaluate if the user explicitly called director.evaluate().
964
+ if (!this.director.isPlaying && !this.director._isUserEvaluation) return;
965
+
966
+ for (let i = 0; i < this.track.outputs.length; i++) {
967
+ const binding = this.track.outputs[i];
968
+ if (typeof binding !== "object" || binding === null) continue;
969
+
970
+ let isActive = false;
971
+ if (this.track.clips) {
972
+ for (const clip of this.track.clips) {
973
+ if (clip.start <= time && time <= clip.end) {
974
+ isActive = true;
975
+ break;
976
+ }
977
+ }
978
+ }
979
+
980
+ const obj = binding as Object3D;
981
+ if (obj.visible !== undefined && obj.visible !== isActive) {
982
+ obj.visible = isActive;
983
+ if (debug) console.warn(this.director.name, "ActivationTrack-" + i, obj.name, isActive, time);
923
984
  }
924
985
  }
925
986
  }
@@ -1,4 +1,5 @@
1
- export { type ITimelineAnimationCallbacks as ITimelineAnimationOverride } from "./PlayableDirector.js"
1
+ export { DirectorWrapMode, type ITimelineAnimationCallbacks as ITimelineAnimationOverride } from "./PlayableDirector.js"
2
2
  export * from "./SignalAsset.js"
3
+ export * from "./TimelineBuilder.js"
3
4
  export * from "./TimelineModels.js"
4
5
  export * from "./TimelineTracks.js"
@@ -4,7 +4,7 @@ import * as ThreeMeshUI from 'three-mesh-ui'
4
4
  import { Mathf } from "../../engine/engine_math.js";
5
5
  import { serializable } from "../../engine/engine_serialization_decorator.js";
6
6
  import { FrameEvent } from "../../engine/engine_setup.js";
7
- import { delayForFrames, getParam } from "../../engine/engine_utils.js";
7
+ import { getParam } from "../../engine/engine_utils.js";
8
8
  import { type NeedleXREventArgs } from "../../engine/xr/api.js";
9
9
  import { Camera } from "../Camera.js";
10
10
  import { GameObject } from "../Component.js";
@@ -236,19 +236,13 @@ export class Canvas extends UIRootComponent implements ICanvas {
236
236
  }
237
237
  }
238
238
 
239
- async onEnterXR(args: NeedleXREventArgs) {
239
+ onEnterXR(args: NeedleXREventArgs) {
240
240
  // workaround for https://linear.app/needle/issue/NE-4114
241
241
  if (this.screenspace) {
242
242
  if (args.xr.isVR || args.xr.isPassThrough) {
243
243
  this.gameObject.visible = false;
244
244
  }
245
245
  }
246
- else {
247
- this.gameObject.visible = false;
248
- await delayForFrames(1).then(()=>{
249
- this.gameObject.visible = true;
250
- });
251
- }
252
246
  }
253
247
  onLeaveXR(args: NeedleXREventArgs): void {
254
248
  if (this.screenspace) {
@@ -170,12 +170,15 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
170
170
  this._font = val;
171
171
  this.uiObject?.set(this.getTextOpts());
172
172
  this.markDirty();
173
+ // If the font is assigned during deserialization it means the font URL MUST be resolved with the style suffix. If it's assigned at runtime by a user invocation and is absolute then we assume the user is prividing a full path to the font asset json or png
174
+ this._assignedAtRuntime = this.__didAwake;
173
175
  }
174
176
  }
175
177
  get font(): string | null {
176
178
  return this._font;
177
179
  }
178
180
  private _font: string | null = "https://cdn.needle.tools/static/fonts/msdf/arial/arial";
181
+ private _assignedAtRuntime: boolean = true;
179
182
 
180
183
 
181
184
  /**
@@ -274,7 +277,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
274
277
  }
275
278
 
276
279
  protected onCreate(_opts: any): void {
277
- if (debug) console.log(this);
280
+ if (debug) console.log("[Text] onCreate", this);
278
281
 
279
282
  // @marwie : Should be fixed. Currently _opts are always fed with :
280
283
  // backgroundOpacity : color.opacity
@@ -442,7 +445,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
442
445
  private feedText(text: string, richText: boolean): void {
443
446
  // if (!text || text.length <= 0) return;
444
447
  // if (!text ) return;
445
- if (debug) console.log("feedText", this.uiObject, text, richText);
448
+ if (debug) console.log("[Text] feedText", this.uiObject, text, richText);
446
449
 
447
450
  if (!this.uiObject) return;
448
451
  if (!this._textMeshUi)
@@ -603,16 +606,17 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
603
606
  * @private
604
607
  */
605
608
  private setFont(opts: ThreeMeshUIEveryOptions, fontStyle: FontStyle) {
606
-
609
+
607
610
  if (!this.font) {
608
- if(debug) console.warn("No font set for Text component, skipping font setup");
611
+ if (debug) console.warn("[Text] No font set for Text component, skipping font setup");
609
612
  return;
610
613
  }
611
614
 
612
615
  const fontName = this.font;
616
+
613
617
  const familyName = this.getFamilyNameWithCorrectSuffix(fontName, fontStyle);
614
618
 
615
- if (debug) console.log("Selected font family:" + familyName, this.font);
619
+ if (debug) console.log(`[Text] Selected font family '${familyName}' from ${fontName} with style ${FontStyle[fontStyle]}`);
616
620
 
617
621
  // ensure a font family is register under this name
618
622
  let fontFamily = ThreeMeshUI.FontLibrary.getFontFamily(familyName as string);
@@ -676,7 +680,7 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
676
680
  // e.g. -Medium, -Black, -Thin...
677
681
  const styleName = familyName.substring(styleSeparator + 1)?.toLowerCase();
678
682
  if (unsupportedStyleNames.includes(styleName)) {
679
- if (debug) console.warn("Unsupported font style: " + styleName);
683
+ if (debug) console.warn("[Text] Unsupported font style: " + styleName);
680
684
  return familyName;
681
685
  }
682
686
 
@@ -691,12 +695,12 @@ export class Text extends Graphic implements IHasAlphaFactor, ICanvasEventReceiv
691
695
  const isUpperCase = fontBaseName[0] === fontBaseName[0].toUpperCase();
692
696
  const fontNameWithoutSuffix = familyName.substring(0, styleSeparator > pathSeparatorIndex ? styleSeparator : familyName.length);
693
697
 
694
- if (debug) console.log("Select font: ", familyName, FontStyle[style], fontBaseName, isUpperCase, fontNameWithoutSuffix);
698
+ if (debug) console.log("[Text] Select font: ", familyName, FontStyle[style], fontBaseName, isUpperCase, fontNameWithoutSuffix);
695
699
 
696
700
  /**
697
701
  * If a user provides a font with an absolute URL AND the font name does not end with "-msdf.json" or ".png" (e.g. "https://example.com/fonts/Arial-Bold"), we will assume that the user is providing the full path to the font files and we will not try to modify the font name based on the style. This allows users to have more control over the font files they are using, especially if they are hosting their own fonts or using a custom font provider that does not follow the same naming conventions as our default fonts.
698
702
  */
699
- if (isAbsolute && !(familyName.endsWith("-msdf.json") || familyName.endsWith(".png"))) {
703
+ if (isAbsolute && this._assignedAtRuntime && !(familyName.endsWith("-msdf.json") || familyName.endsWith(".png"))) {
700
704
  return fontNameWithoutSuffix;
701
705
  }
702
706
 
@@ -289,20 +289,28 @@ export class CursorFollow extends Behaviour {
289
289
 
290
290
 
291
291
  if (this.snapToSurface) {
292
- ray.origin = _position;
293
- ray.direction = rayDirection.multiplyScalar(-1);
294
- const hits = this.context.physics.raycastFromRay(ray);
295
- if (hits?.length) {
296
- const hit = hits[0];
297
- if (this.damping > 0) {
298
- this.gameObject.worldPosition = _position.lerp(hit.point, this.context.time.deltaTime / this.damping);
299
- }
300
- else {
301
- this.gameObject.worldPosition = hit.point;
292
+ ray.origin = cameraPosition;
293
+ ray.direction = rayDirection;
294
+ const hits = this.context.physics.raycastFromRay(ray, {
295
+ testObject: obj => {
296
+ return obj !== this.gameObject && !this.gameObject.contains(obj) ? true : false
302
297
  }
303
-
304
- if(debug) {
305
- Gizmos.DrawLine(hit.point, hit.normal!.add(hit.point), 0x00FF00);
298
+ });
299
+ if (hits?.length) {
300
+ // Get the first hit that is not a child of *this* object. Because we do not want to lerp to a surface that is part of the object itself, since that would result in *this* object moving closer and closer to the camera as it tries to snap to itself
301
+ const hit = hits[0];//.find(h => !this.gameObject.contains(h.object));
302
+ if (hit) {
303
+ if (this.damping > 0) {
304
+ this.gameObject.worldPosition = _position.lerp(hit.point, this.context.time.deltaTime / this.damping);
305
+ // this._distance = this.gameObject.worldPosition.distanceTo(cameraPosition);
306
+ }
307
+ else {
308
+ this.gameObject.worldPosition = hit.point;
309
+ // this._distance = hit.point.distanceTo(cameraPosition);
310
+ }
311
+ if (debug) {
312
+ Gizmos.DrawLine(hit.point, hit.normal!.add(hit.point), 0x00FF00);
313
+ }
306
314
  }
307
315
  }
308
316
  }
@@ -886,9 +886,11 @@ async function loadImage(url: string) {
886
886
  }
887
887
  const promise = new Promise<boolean>(res => {
888
888
  _imageElements.set(url, null);
889
+ if(isDevEnvironment() || debug) console.debug(`[WebXRImageTracking] Start loading image for tracking: ${url}`);
889
890
  const imageElement = document.createElement("img") as HTMLImageElement;
890
891
  imageElement.src = url;
891
892
  imageElement.addEventListener("load", async () => {
893
+ if(isDevEnvironment() || debug) console.debug(`[WebXRImageTracking] Loaded image for tracking: ${url}`);
892
894
  const img = await createImageBitmap(imageElement);
893
895
  _imageElements.set(url, img);
894
896
  res(true);