@needle-tools/engine 4.12.0-next.fb75c78 → 4.12.0

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 (71) hide show
  1. package/CHANGELOG.md +14 -4
  2. package/README.md +4 -2
  3. package/components.needle.json +1 -1
  4. package/dist/{gltf-progressive-Rs-ojtXy.umd.cjs → gltf-progressive-Bfpfaz84.umd.cjs} +1 -1
  5. package/dist/{gltf-progressive-DnLBuGK5.js → gltf-progressive-DPunMlEM.js} +1 -1
  6. package/dist/{gltf-progressive-BmSygnAC.min.js → gltf-progressive-hFPACYio.min.js} +1 -1
  7. package/dist/{needle-engine.bundle-CJSpoHVo.min.js → needle-engine.bundle-BhAUDZcQ.min.js} +146 -145
  8. package/dist/{needle-engine.bundle-C5pBHUhB.js → needle-engine.bundle-CpPhY8AW.js} +7984 -7801
  9. package/dist/{needle-engine.bundle-Cb3SBLtg.umd.cjs → needle-engine.bundle-DQdhrcLq.umd.cjs} +143 -142
  10. package/dist/needle-engine.d.ts +30 -23
  11. package/dist/needle-engine.js +3 -3
  12. package/dist/needle-engine.min.js +1 -1
  13. package/dist/needle-engine.umd.cjs +1 -1
  14. package/dist/{postprocessing-DZtb9Nnn.umd.cjs → postprocessing-BHQvwehB.umd.cjs} +1 -1
  15. package/dist/{postprocessing-B5ksn9-G.min.js → postprocessing-ClLv0reO.min.js} +1 -1
  16. package/dist/{postprocessing-__7s9wON.js → postprocessing-DLI2N3LL.js} +1 -1
  17. package/dist/{three-examples-y2GeYlze.js → three-examples-D4rE49Ui.js} +10 -2
  18. package/dist/{three-examples-MsJjauyk.min.js → three-examples-DB5Uoja4.min.js} +2 -2
  19. package/dist/{three-examples-Dho7cuu4.umd.cjs → three-examples-Djbk6WA4.umd.cjs} +2 -2
  20. package/lib/engine/engine_context.js +2 -0
  21. package/lib/engine/engine_context.js.map +1 -1
  22. package/lib/engine/engine_license.d.ts +18 -0
  23. package/lib/engine/engine_license.js +161 -9
  24. package/lib/engine/engine_license.js.map +1 -1
  25. package/lib/engine/engine_networking.js +15 -0
  26. package/lib/engine/engine_networking.js.map +1 -1
  27. package/lib/engine/engine_serialization_builtin_serializer.js +1 -1
  28. package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
  29. package/lib/engine/engine_three_utils.js +2 -2
  30. package/lib/engine/engine_three_utils.js.map +1 -1
  31. package/lib/engine/webcomponents/needle menu/needle-menu-spatial.js +2 -1
  32. package/lib/engine/webcomponents/needle menu/needle-menu-spatial.js.map +1 -1
  33. package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +2 -0
  34. package/lib/engine/webcomponents/needle menu/needle-menu.js +41 -2
  35. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  36. package/lib/engine/xr/NeedleXRSession.js +45 -7
  37. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  38. package/lib/engine-components/DragControls.js +1 -1
  39. package/lib/engine-components/DragControls.js.map +1 -1
  40. package/lib/engine-components/DropListener.d.ts +1 -0
  41. package/lib/engine-components/DropListener.js +26 -8
  42. package/lib/engine-components/DropListener.js.map +1 -1
  43. package/lib/engine-components/EventList.js +4 -1
  44. package/lib/engine-components/EventList.js.map +1 -1
  45. package/lib/engine-components/SceneSwitcher.d.ts +3 -2
  46. package/lib/engine-components/SceneSwitcher.js +24 -11
  47. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  48. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +8 -0
  49. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
  50. package/lib/engine-components/webxr/WebARSessionRoot.d.ts +5 -2
  51. package/lib/engine-components/webxr/WebARSessionRoot.js +5 -2
  52. package/lib/engine-components/webxr/WebARSessionRoot.js.map +1 -1
  53. package/lib/engine-components/webxr/WebXR.d.ts +3 -1
  54. package/lib/engine-components/webxr/WebXR.js +3 -1
  55. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  56. package/package.json +3 -3
  57. package/src/engine/engine_context.ts +2 -0
  58. package/src/engine/engine_license.ts +178 -9
  59. package/src/engine/engine_networking.ts +15 -0
  60. package/src/engine/engine_serialization_builtin_serializer.ts +1 -1
  61. package/src/engine/engine_three_utils.ts +4 -2
  62. package/src/engine/webcomponents/needle menu/needle-menu-spatial.ts +2 -1
  63. package/src/engine/webcomponents/needle menu/needle-menu.ts +44 -3
  64. package/src/engine/xr/NeedleXRSession.ts +53 -11
  65. package/src/engine-components/DragControls.ts +1 -1
  66. package/src/engine-components/DropListener.ts +29 -8
  67. package/src/engine-components/EventList.ts +5 -1
  68. package/src/engine-components/SceneSwitcher.ts +26 -13
  69. package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +11 -0
  70. package/src/engine-components/webxr/WebARSessionRoot.ts +7 -3
  71. package/src/engine-components/webxr/WebXR.ts +4 -2
@@ -1,7 +1,7 @@
1
1
  import { EquirectangularReflectionMapping, Object3D, Scene, Texture } from "three";
2
2
 
3
3
  import { AssetReference } from "../engine/engine_addressables.js";
4
- import { destroy } from "../engine/engine_gameobject.js";
4
+ import { destroy, instantiate } from "../engine/engine_gameobject.js";
5
5
  import { InputEvents } from "../engine/engine_input.js";
6
6
  import { isLocalNetwork } from "../engine/engine_networking_utils.js";
7
7
  import { serializable } from "../engine/engine_serialization.js";
@@ -247,14 +247,23 @@ export class SceneSwitcher extends Behaviour {
247
247
 
248
248
  private _currentIndex: number = -1;
249
249
  private _currentScene: AssetReference | undefined = undefined;
250
+ private _currentSceneAsset: Object3D | undefined = undefined;
250
251
  private _engineElementOverserver: MutationObserver | undefined = undefined;
251
252
 
252
253
  private _preloadScheduler?: PreLoadScheduler;
253
254
 
254
255
  private _menuButtons?: HTMLElement[];
255
256
 
257
+ // this is the scene that was requested last
258
+ private __lastSwitchScene?: AssetReference;
259
+ private __lastSwitchScenePromise?: Promise<boolean>;
260
+
256
261
  /** @internal */
257
262
  awake(): void {
263
+ this._currentScene = undefined;
264
+ this._lastLoadingScene = undefined;
265
+ this.__lastSwitchScenePromise = undefined;
266
+
258
267
  if (this.scenes === undefined) this.scenes = [];
259
268
  // remove all scenes from the url that are in the scenes array at startup
260
269
  for (const scene of this.scenes) {
@@ -538,10 +547,6 @@ export class SceneSwitcher extends Behaviour {
538
547
  return false;
539
548
  }
540
549
 
541
- // this is the scene that was requested last
542
- private __lastSwitchScene?: AssetReference;
543
- private __lastSwitchScenePromise?: Promise<boolean>;
544
-
545
550
  /**
546
551
  * Switch to a scene by its AssetReference.
547
552
  * If the scene is already loaded it will be unloaded and the new scene will be loaded.
@@ -601,13 +606,15 @@ export class SceneSwitcher extends Behaviour {
601
606
  const res = sceneListener.sceneClosing();
602
607
  if (res instanceof Promise) await res;
603
608
  }
604
- // if the current scene has a URL (so it can be reloaded)
605
- // then we unload it
606
- if (current.hasUrl)
609
+
610
+ // // if the current scene has a URL (so it can be reloaded)
611
+ // // then we unload it
612
+ if (current.hasUrl) {
607
613
  current.unload();
608
- // otherwise if it's a regular Object3D we just remove it from the scene
609
- else if (current.asset instanceof Object3D) {
610
- GameObject.remove(current.asset as any as Object3D);
614
+ if (this._currentSceneAsset) destroy(this._currentSceneAsset, true, false);
615
+ }
616
+ else {
617
+ GameObject.remove(this._currentSceneAsset);
611
618
  }
612
619
  }
613
620
  }
@@ -658,7 +665,6 @@ export class SceneSwitcher extends Behaviour {
658
665
  if (debug) console.log("[SceneSwitcher] ADD", scene.url);
659
666
  this._currentScene = scene;
660
667
 
661
-
662
668
  // Experimental: replace the whole content of the scene
663
669
  if (experimental_clearSceneOnLoad) {
664
670
  const camera = this.context.mainCameraComponent?.gameObject || this.context.mainCamera;
@@ -672,7 +678,14 @@ export class SceneSwitcher extends Behaviour {
672
678
  }
673
679
  }
674
680
 
675
- GameObject.add(scene.asset, this.gameObject);
681
+ // @TODO: if multiple scene switcher or scenes use this asset already it will be moved
682
+ if (!scene.asset.parent) {
683
+ this._currentSceneAsset = scene.asset;
684
+ GameObject.add(scene.asset, this.gameObject);
685
+ }
686
+ else {
687
+ this._currentSceneAsset = instantiate(scene.asset, { parent: this.gameObject });
688
+ }
676
689
 
677
690
  if (this.useSceneLighting)
678
691
  this.context.sceneLighting.enable(scene);
@@ -11,6 +11,7 @@ import { Animation } from "../../../../Animation.js";
11
11
  import { Animator } from "../../../../Animator.js";
12
12
  import { AudioSource } from "../../../../AudioSource.js";
13
13
  import { Behaviour, GameObject } from "../../../../Component.js";
14
+ import { Rigidbody } from "../../../../RigidBody.js";
14
15
  import type { IPointerClickHandler, PointerEventData } from "../../../../ui/PointerEvents.js";
15
16
  import { ObjectRaycaster,Raycaster } from "../../../../ui/Raycaster.js";
16
17
  import { makeNameSafeForUSD,USDDocument, USDObject, USDZExporterContext } from "../../ThreeUSDZExporter.js";
@@ -68,6 +69,16 @@ export class ChangeTransformOnClick extends Behaviour implements IPointerClickHa
68
69
  }
69
70
 
70
71
  onPointerClick(args: PointerEventData) {
72
+
73
+ const rbs = this.object?.getComponentsInChildren(Rigidbody);
74
+
75
+ if (rbs){
76
+ for (const rb of rbs) {
77
+ rb.resetVelocities();
78
+ rb.resetForcesAndTorques();
79
+ }
80
+ }
81
+
71
82
  args.use();
72
83
  if (this.coroutine) this.stopCoroutine(this.coroutine);
73
84
  if (!this.relativeMotion)
@@ -10,6 +10,7 @@ import type { IComponent, IGameObject } from "../../engine/engine_types.js";
10
10
  import { DeviceUtilities, getParam } from "../../engine/engine_utils.js";
11
11
  import { NeedleXRController, type NeedleXREventArgs, type NeedleXRHitTestResult, NeedleXRSession } from "../../engine/engine_xr.js";
12
12
  import { Behaviour, GameObject } from "../Component.js";
13
+ import type { WebXR } from "./WebXR.js";
13
14
 
14
15
  // https://github.com/takahirox/takahirox.github.io/blob/master/js.mmdeditor/examples/js/controls/DeviceOrientationControls.js
15
16
 
@@ -20,14 +21,17 @@ const invertForwardMatrix = new Matrix4().makeRotationY(Math.PI);
20
21
 
21
22
  /**
22
23
  * The WebARSessionRoot is the root object for a WebAR session and used to place the scene in AR.
23
- * It is also responsible for scaling the user in AR and to define the center of the AR scene. If not present in the scene it will be created automatically by the WebXR component when entering an AR session.
24
+ * It is also responsible for scaling the user in AR and to define the center of the AR scene.
25
+ * If not present in the scene it will be created automatically by the WebXR component when entering an AR session.
24
26
  *
25
- * @example
27
+ * **Note**: If the WebXR component {@link WebXR.autoCenter} option is enabled the scene will be automatically centered based on the content in the scene.
28
+ *
29
+ * @example Callback when the scene has been placed in AR:
26
30
  * ```ts
27
31
  * WebARSessionRoot.onPlaced((args) => {
28
32
  * console.log("Scene has been placed in AR");
29
33
  * });
30
- * ```
34
+ * ```
31
35
  *
32
36
  * @summary Root object for WebAR sessions, managing scene placement and user scaling in AR.
33
37
  * @category XR
@@ -23,7 +23,7 @@ const debug = getParam("debugwebxr");
23
23
  const debugQuicklook = getParam("debugusdz");
24
24
 
25
25
  /**
26
- * Use the WebXR component to enable VR, AR and Quicklook on iOS in your scene.
26
+ * Use the WebXR component to enable VR and AR on iOS and Android in your scene. VisionOS support is also provided via QuickLook USDZ export.
27
27
  *
28
28
  * The WebXR component is a simple to use wrapper around the {@link NeedleXRSession} API and adds some additional features like creating buttons for AR, VR, enabling default movement behaviour ({@link XRControllerMovement}) and controller rendering ({@link XRControllerModel}), as well as handling AR placement and Quicklook USDZ export.
29
29
  *
@@ -146,7 +146,9 @@ export class WebXR extends Behaviour {
146
146
 
147
147
  /**
148
148
  * When enabled, the AR session root center will be automatically adjusted to place the center of the scene.
149
- * This helps ensure the scene is properly aligned with detected surfaces.
149
+ * This helps ensure the scene is properly aligned with detected surfaces.
150
+ *
151
+ * **Note**: This option overrides the placement of the {@link WebARSessionRoot} component if both are used.
150
152
  */
151
153
  @serializable()
152
154
  autoCenter: boolean = false;