@needle-tools/engine 4.17.0-next.36dcae2 → 4.17.0-next.4989636

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 (238) hide show
  1. package/components.needle.json +1 -1
  2. package/dist/gltf-progressive-BryRjllq.min.js +10 -0
  3. package/dist/gltf-progressive-Cl167Vjx.js +1537 -0
  4. package/dist/gltf-progressive-DJBMx-zB.umd.cjs +10 -0
  5. package/dist/gltf-progressive.worker-BqODMeeW.js +23 -0
  6. package/dist/needle-engine.bundle-BTIpdDE9.umd.cjs +1654 -0
  7. package/dist/{needle-engine.bundle-CQFEuAQB.js → needle-engine.bundle-CH2ZOagS.js} +35829 -35882
  8. package/dist/needle-engine.bundle-D5h7xxUH.min.js +1654 -0
  9. package/dist/needle-engine.d.ts +105 -39
  10. package/dist/needle-engine.js +608 -607
  11. package/dist/needle-engine.min.js +1 -1
  12. package/dist/needle-engine.umd.cjs +1 -1
  13. package/dist/three-examples.js +7815 -6828
  14. package/dist/three-examples.min.js +17 -15
  15. package/dist/three-examples.umd.cjs +17 -15
  16. package/dist/three.js +15994 -24892
  17. package/dist/three.min.js +214 -214
  18. package/dist/three.umd.cjs +208 -208
  19. package/dist/vendor-CntUvmJu.umd.cjs +1116 -0
  20. package/dist/{vendor-BPp9F5vR.min.js → vendor-DPbfJJ4d.min.js} +94 -94
  21. package/dist/{vendor-CQMI3jTS.js → vendor-vHLk8sXu.js} +8558 -8516
  22. package/lib/engine/analytics/index.js.map +1 -1
  23. package/lib/engine/codegen/register_types.d.ts +1 -1
  24. package/lib/engine/codegen/register_types.js +159 -157
  25. package/lib/engine/codegen/register_types.js.map +1 -1
  26. package/lib/engine/debug/debug.d.ts +1 -4
  27. package/lib/engine/debug/debug.js +1 -25
  28. package/lib/engine/debug/debug.js.map +1 -1
  29. package/lib/engine/debug/debug_environment.d.ts +4 -0
  30. package/lib/engine/debug/debug_environment.js +26 -0
  31. package/lib/engine/debug/debug_environment.js.map +1 -0
  32. package/lib/engine/debug/debug_overlay.js +2 -1
  33. package/lib/engine/debug/debug_overlay.js.map +1 -1
  34. package/lib/engine/debug/debug_spatial_console.js +1 -1
  35. package/lib/engine/debug/debug_spatial_console.js.map +1 -1
  36. package/lib/engine/engine_audio.js +0 -1
  37. package/lib/engine/engine_audio.js.map +1 -1
  38. package/lib/engine/engine_components.js +6 -3
  39. package/lib/engine/engine_components.js.map +1 -1
  40. package/lib/engine/engine_gltf_builtin_components.d.ts +0 -1
  41. package/lib/engine/engine_gltf_builtin_components.js +5 -4
  42. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  43. package/lib/engine/engine_init.d.ts +10 -0
  44. package/lib/engine/engine_init.js +44 -0
  45. package/lib/engine/engine_init.js.map +1 -0
  46. package/lib/engine/engine_loaders.d.ts +2 -0
  47. package/lib/engine/engine_loaders.js +2 -1
  48. package/lib/engine/engine_loaders.js.map +1 -1
  49. package/lib/engine/engine_modules.d.ts +8 -0
  50. package/lib/engine/engine_modules.js +1 -0
  51. package/lib/engine/engine_modules.js.map +1 -1
  52. package/lib/engine/engine_networking.d.ts +2 -1
  53. package/lib/engine/engine_networking.js +3 -1
  54. package/lib/engine/engine_networking.js.map +1 -1
  55. package/lib/engine/engine_networking_blob.js +3 -3
  56. package/lib/engine/engine_networking_blob.js.map +1 -1
  57. package/lib/engine/engine_networking_peer.d.ts +2 -2
  58. package/lib/engine/engine_networking_peer.js +7 -6
  59. package/lib/engine/engine_networking_peer.js.map +1 -1
  60. package/lib/engine/engine_networking_streams.d.ts +2 -1
  61. package/lib/engine/engine_networking_streams.js +2 -2
  62. package/lib/engine/engine_networking_streams.js.map +1 -1
  63. package/lib/engine/engine_physics_rapier.d.ts +2 -0
  64. package/lib/engine/engine_physics_rapier.js +35 -4
  65. package/lib/engine/engine_physics_rapier.js.map +1 -1
  66. package/lib/engine/engine_shims.d.ts +1 -0
  67. package/lib/engine/engine_shims.js +20 -19
  68. package/lib/engine/engine_shims.js.map +1 -1
  69. package/lib/engine/engine_tonemapping.js +0 -1
  70. package/lib/engine/engine_tonemapping.js.map +1 -1
  71. package/lib/engine/engine_types.d.ts +8 -0
  72. package/lib/engine/engine_typestore.d.ts +11 -0
  73. package/lib/engine/engine_typestore.js +29 -0
  74. package/lib/engine/engine_typestore.js.map +1 -1
  75. package/lib/engine/extensions/NEEDLE_animator_controller_model.d.ts +1 -1
  76. package/lib/engine/js-extensions/Camera.d.ts +1 -1
  77. package/lib/engine/js-extensions/Camera.js +43 -37
  78. package/lib/engine/js-extensions/Camera.js.map +1 -1
  79. package/lib/engine/js-extensions/Layers.js +0 -1
  80. package/lib/engine/js-extensions/Layers.js.map +1 -1
  81. package/lib/engine/js-extensions/Object3D.d.ts +1 -0
  82. package/lib/engine/js-extensions/Object3D.js +173 -167
  83. package/lib/engine/js-extensions/Object3D.js.map +1 -1
  84. package/lib/engine/js-extensions/Vector.d.ts +1 -0
  85. package/lib/engine/js-extensions/Vector.js +10 -4
  86. package/lib/engine/js-extensions/Vector.js.map +1 -1
  87. package/lib/engine/js-extensions/index.d.ts +0 -3
  88. package/lib/engine/js-extensions/index.js +0 -2
  89. package/lib/engine/js-extensions/index.js.map +1 -1
  90. package/lib/engine/webcomponents/WebXRButtons.js +11 -13
  91. package/lib/engine/webcomponents/WebXRButtons.js.map +1 -1
  92. package/lib/engine/webcomponents/buttons.js +4 -4
  93. package/lib/engine/webcomponents/buttons.js.map +1 -1
  94. package/lib/engine/webcomponents/font-urls.d.ts +2 -0
  95. package/lib/engine/webcomponents/font-urls.js +8 -0
  96. package/lib/engine/webcomponents/font-urls.js.map +1 -0
  97. package/lib/engine/webcomponents/fonts.d.ts +2 -2
  98. package/lib/engine/webcomponents/fonts.js +12 -7
  99. package/lib/engine/webcomponents/fonts.js.map +1 -1
  100. package/lib/engine/webcomponents/init.d.ts +4 -0
  101. package/lib/engine/webcomponents/init.js +20 -0
  102. package/lib/engine/webcomponents/init.js.map +1 -0
  103. package/lib/engine/webcomponents/logo-element.js +2 -2
  104. package/lib/engine/webcomponents/logo-element.js.map +1 -1
  105. package/lib/engine/webcomponents/needle menu/menu-priority.d.ts +10 -0
  106. package/lib/engine/webcomponents/needle menu/menu-priority.js +21 -0
  107. package/lib/engine/webcomponents/needle menu/menu-priority.js.map +1 -0
  108. package/lib/engine/webcomponents/needle menu/needle-menu-spatial.d.ts +1 -1
  109. package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +1 -1
  110. package/lib/engine/webcomponents/needle menu/needle-menu.js +7 -11
  111. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  112. package/lib/engine/webcomponents/needle-button.js +0 -3
  113. package/lib/engine/webcomponents/needle-button.js.map +1 -1
  114. package/lib/engine/webcomponents/needle-engine.js +4 -10
  115. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  116. package/lib/engine/webcomponents/quicklook-handler.d.ts +29 -0
  117. package/lib/engine/webcomponents/quicklook-handler.js +21 -0
  118. package/lib/engine/webcomponents/quicklook-handler.js.map +1 -0
  119. package/lib/engine/xr/NeedleXRSession.d.ts +1 -0
  120. package/lib/engine/xr/NeedleXRSession.js +1 -0
  121. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  122. package/lib/engine-components/AnimationUtilsAutoplay.d.ts +1 -1
  123. package/lib/engine-components/AnimationUtilsAutoplay.js +29 -23
  124. package/lib/engine-components/AnimationUtilsAutoplay.js.map +1 -1
  125. package/lib/engine-components/Animator.d.ts +1 -1
  126. package/lib/engine-components/AnimatorController.d.ts +1 -1
  127. package/lib/engine-components/CameraUtils.d.ts +1 -1
  128. package/lib/engine-components/CameraUtils.js +79 -73
  129. package/lib/engine-components/CameraUtils.js.map +1 -1
  130. package/lib/engine-components/Collider.d.ts +2 -0
  131. package/lib/engine-components/Collider.js +25 -3
  132. package/lib/engine-components/Collider.js.map +1 -1
  133. package/lib/engine-components/LookAtConstraint.d.ts +34 -1
  134. package/lib/engine-components/LookAtConstraint.js +54 -1
  135. package/lib/engine-components/LookAtConstraint.js.map +1 -1
  136. package/lib/engine-components/Networking.d.ts +2 -1
  137. package/lib/engine-components/Networking.js +2 -1
  138. package/lib/engine-components/Networking.js.map +1 -1
  139. package/lib/engine-components/SceneSwitcher.d.ts +1 -0
  140. package/lib/engine-components/SceneSwitcher.js +3 -1
  141. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  142. package/lib/engine-components/Skybox.d.ts +1 -0
  143. package/lib/engine-components/Skybox.js +4 -2
  144. package/lib/engine-components/Skybox.js.map +1 -1
  145. package/lib/engine-components/SyncedRoom.d.ts +1 -0
  146. package/lib/engine-components/SyncedRoom.js +1 -0
  147. package/lib/engine-components/SyncedRoom.js.map +1 -1
  148. package/lib/engine-components/api.d.ts +5 -8
  149. package/lib/engine-components/api.js +4 -7
  150. package/lib/engine-components/api.js.map +1 -1
  151. package/lib/engine-components/export/usdz/USDZExporter.js +8 -0
  152. package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
  153. package/lib/engine-components/postprocessing/PostProcessingHandler.js +18 -5
  154. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  155. package/lib/engine-components/postprocessing/utils.js +7 -2
  156. package/lib/engine-components/postprocessing/utils.js.map +1 -1
  157. package/lib/engine-components/timeline/TimelineTracks.d.ts +1 -1
  158. package/lib/engine-components/timeline/TimelineTracks.js +4 -2
  159. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  160. package/lib/engine-components/web/ScrollFollow.d.ts +0 -8
  161. package/lib/engine-components/webxr/WebXR.d.ts +15 -2
  162. package/lib/engine-components/webxr/WebXR.js +15 -2
  163. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  164. package/lib/needle-engine.d.ts +0 -1
  165. package/lib/needle-engine.js +2 -1
  166. package/lib/needle-engine.js.map +1 -1
  167. package/package.json +11 -3
  168. package/plugins/vite/ai.d.ts +11 -7
  169. package/plugins/vite/ai.js +21 -16
  170. package/plugins/vite/asap.js +42 -2
  171. package/plugins/vite/dependencies.js +110 -16
  172. package/plugins/vite/index.d.ts +1 -0
  173. package/plugins/vite/index.js +4 -0
  174. package/plugins/vite/treeshake.d.ts +11 -0
  175. package/plugins/vite/treeshake.js +216 -0
  176. package/src/engine/analytics/index.ts +1 -1
  177. package/src/engine/codegen/register_types.ts +159 -157
  178. package/src/engine/debug/debug.ts +1 -26
  179. package/src/engine/debug/debug_environment.ts +26 -0
  180. package/src/engine/debug/debug_overlay.ts +2 -1
  181. package/src/engine/debug/debug_spatial_console.ts +1 -1
  182. package/src/engine/engine_audio.ts +1 -2
  183. package/src/engine/engine_components.ts +6 -3
  184. package/src/engine/engine_gltf_builtin_components.ts +4 -5
  185. package/src/engine/engine_init.ts +45 -0
  186. package/src/engine/engine_loaders.ts +2 -1
  187. package/src/engine/engine_modules.ts +3 -0
  188. package/src/engine/engine_networking.ts +5 -1
  189. package/src/engine/engine_networking_blob.ts +3 -3
  190. package/src/engine/engine_networking_peer.ts +8 -6
  191. package/src/engine/engine_networking_streams.ts +4 -3
  192. package/src/engine/engine_physics_rapier.ts +37 -4
  193. package/src/engine/engine_shims.ts +22 -20
  194. package/src/engine/engine_tonemapping.ts +0 -1
  195. package/src/engine/engine_types.ts +9 -0
  196. package/src/engine/engine_typestore.ts +29 -0
  197. package/src/engine/extensions/NEEDLE_animator_controller_model.ts +1 -1
  198. package/src/engine/js-extensions/Camera.ts +40 -33
  199. package/src/engine/js-extensions/Layers.ts +1 -2
  200. package/src/engine/js-extensions/Object3D.ts +174 -170
  201. package/src/engine/js-extensions/Vector.ts +11 -4
  202. package/src/engine/js-extensions/index.ts +0 -3
  203. package/src/engine/webcomponents/WebXRButtons.ts +12 -13
  204. package/src/engine/webcomponents/buttons.ts +4 -4
  205. package/src/engine/webcomponents/font-urls.js +9 -0
  206. package/src/engine/webcomponents/fonts.ts +12 -7
  207. package/src/engine/webcomponents/init.ts +23 -0
  208. package/src/engine/webcomponents/logo-element.ts +2 -2
  209. package/src/engine/webcomponents/needle menu/menu-priority.ts +20 -0
  210. package/src/engine/webcomponents/needle menu/needle-menu.ts +8 -13
  211. package/src/engine/webcomponents/needle-button.ts +0 -3
  212. package/src/engine/webcomponents/needle-engine.ts +4 -13
  213. package/src/engine/webcomponents/quicklook-handler.ts +37 -0
  214. package/src/engine/xr/NeedleXRSession.ts +2 -1
  215. package/src/engine-components/AnimationUtilsAutoplay.ts +8 -3
  216. package/src/engine-components/AnimatorController.ts +1 -1
  217. package/src/engine-components/CameraUtils.ts +15 -8
  218. package/src/engine-components/Collider.ts +24 -3
  219. package/src/engine-components/LookAtConstraint.ts +46 -1
  220. package/src/engine-components/Networking.ts +3 -1
  221. package/src/engine-components/SceneSwitcher.ts +3 -1
  222. package/src/engine-components/Skybox.ts +4 -2
  223. package/src/engine-components/SyncedRoom.ts +2 -0
  224. package/src/engine-components/api.ts +5 -10
  225. package/src/engine-components/export/usdz/USDZExporter.ts +9 -0
  226. package/src/engine-components/postprocessing/PostProcessingHandler.ts +19 -7
  227. package/src/engine-components/postprocessing/utils.ts +7 -2
  228. package/src/engine-components/timeline/TimelineTracks.ts +6 -2
  229. package/src/engine-components/web/ScrollFollow.ts +0 -2
  230. package/src/engine-components/webxr/WebXR.ts +15 -2
  231. package/src/needle-engine.ts +2 -1
  232. package/dist/gltf-progressive-BBIL1q1j.umd.cjs +0 -4022
  233. package/dist/gltf-progressive-BbHl9z0v.js +0 -28272
  234. package/dist/gltf-progressive-Clq_N7Zx.min.js +0 -4022
  235. package/dist/gltf-progressive.worker-CCrD-Ycm.js +0 -3
  236. package/dist/needle-engine.bundle-CrqNZdEN.umd.cjs +0 -1657
  237. package/dist/needle-engine.bundle-DyVf6QdN.min.js +0 -1657
  238. package/dist/vendor-CipoooTV.umd.cjs +0 -1116
@@ -21,5 +21,4 @@ export function ensureAudioContextIsResumed() {
21
21
  }, 500);
22
22
  });
23
23
  });
24
- }
25
- setTimeout(ensureAudioContextIsResumed, 1000);
24
+ }
@@ -44,7 +44,10 @@ export function getOrAddComponent<T extends IComponent>(go: Object3D, typeName:
44
44
  return addComponent(go, typeName, init);
45
45
  }
46
46
 
47
- const idProvider = new InstantiateIdProvider("addComponentIdProvider");
47
+ let idProvider: InstantiateIdProvider;
48
+ function getIdProvider() {
49
+ return idProvider ??= new InstantiateIdProvider("addComponentIdProvider");
50
+ }
48
51
 
49
52
  export function addNewComponent<T extends IComponent>(obj: Object3D, componentInstance: T, callAwake = true): T {
50
53
  if (!obj) {
@@ -56,7 +59,7 @@ export function addNewComponent<T extends IComponent>(obj: Object3D, componentIn
56
59
  componentInstance.gameObject = obj as IGameObject;
57
60
  // TODO: currently add component does not ensure a new component instance has a guid
58
61
  if (componentInstance.guid === undefined || componentInstance.guid === "invalid") {
59
- componentInstance.guid = idProvider.generateUUID();
62
+ componentInstance.guid = getIdProvider().generateUUID();
60
63
  }
61
64
  apply(obj);
62
65
  // register the component - make sure to provide the component instance context (if assigned)
@@ -106,7 +109,7 @@ export function addComponent<T extends IComponent>(obj: Object3D, componentInsta
106
109
  // componentInstance.__internalEnable();
107
110
  // componentInstance.transform = obj;
108
111
  if (componentInstance.guid === undefined || componentInstance.guid === "invalid") {
109
- componentInstance.guid = idProvider.generateUUID();
112
+ componentInstance.guid = getIdProvider().generateUUID();
110
113
  }
111
114
  if(init) componentInstance._internalInit(init);
112
115
  // Register the component - make sure to provide the component instance context (if assigned)
@@ -1,5 +1,3 @@
1
- import "./codegen/register_types.js";
2
-
3
1
  import { Object3D } from "three";
4
2
  import { type GLTF } from "three/examples/jsm/loaders/GLTFLoader.js";
5
3
 
@@ -214,9 +212,10 @@ async function onCreateBuiltinComponents(context: SerializationContext, obj: Obj
214
212
  for (const compData of components) {
215
213
  try {
216
214
  if (compData === null) continue;
217
- const type = TypeStore.get(compData.name);
218
- // console.log(compData, compData.name, type, TypeStore);
219
- if (type !== undefined && type !== null) {
215
+ let type = TypeStore.get(compData.name);
216
+ // If not eagerly registered, try lazy/async loading
217
+ if (!type) type = await TypeStore.getAsync(compData.name);
218
+ if (type) {
220
219
  const instance: IComponent = new type() as IComponent;
221
220
  instance.sourceId = context.gltfId;
222
221
 
@@ -0,0 +1,45 @@
1
+ import { initAnimationAutoplay } from "../engine-components/AnimationUtilsAutoplay.js";
2
+ import { initCameraUtils } from "../engine-components/CameraUtils.js";
3
+ import { initSceneSwitcherAttributes } from "../engine-components/SceneSwitcher.js";
4
+ import { initSkyboxAttributes } from "../engine-components/Skybox.js";
5
+ import { initBuiltinTypes } from "./codegen/register_types.js";
6
+ import { ensureAudioContextIsResumed } from "./engine_audio.js";
7
+ import { initNeedleLoader } from "./engine_loaders.js";
8
+ import { initShims } from "./engine_shims.js";
9
+ import { patchTonemapping } from "./engine_tonemapping.js";
10
+ import { initCameraExtensions } from "./js-extensions/Camera.js";
11
+ import { patchLayers } from "./js-extensions/Layers.js";
12
+ import { initObject3DExtensions } from "./js-extensions/Object3D.js";
13
+ import { initVectorExtensions } from "./js-extensions/Vector.js";
14
+ import { initWebComponents } from "./webcomponents/init.js";
15
+
16
+ let initialized = false;
17
+
18
+ /**
19
+ * Initialize all engine subsystems. Called once from the entry point.
20
+ *
21
+ * Every subsystem (prototype patches, type registrations, loader setup, etc.)
22
+ * is wrapped in an explicit init function instead of running at module scope.
23
+ * This creates an unbroken call chain from the entry point that bundlers can
24
+ * trace, so the package can declare `sideEffects: false` and tree-shake
25
+ * correctly — without maintaining a fragile list of side-effect files.
26
+ */
27
+ export function initEngine() {
28
+ if (initialized) return;
29
+ initialized = true;
30
+
31
+ initWebComponents();
32
+ initShims();
33
+ patchTonemapping();
34
+ patchLayers();
35
+ initCameraExtensions();
36
+ initObject3DExtensions();
37
+ initVectorExtensions();
38
+ initBuiltinTypes();
39
+ initNeedleLoader();
40
+ setTimeout(ensureAudioContextIsResumed, 1000);
41
+ initCameraUtils();
42
+ initAnimationAutoplay();
43
+ initSkyboxAttributes();
44
+ initSceneSwitcherAttributes();
45
+ }
@@ -35,7 +35,8 @@ export class NeedleLoader implements INeedleGltfLoader {
35
35
  return loadSync(context, url, sourceId, seed, prog);
36
36
  }
37
37
  }
38
- registerLoader(NeedleLoader); // Register the loader
38
+ /** Initialize the default NeedleLoader. Called from engine_init.ts */
39
+ export function initNeedleLoader() { registerLoader(NeedleLoader); }
39
40
 
40
41
 
41
42
  const printGltf = utils.getParam("printGltf") || utils.getParam("printgltf");
@@ -43,4 +43,7 @@ export const MODULES = {
43
43
  POSTPROCESSING_AO: createModule<typeof import("n8ao")>(
44
44
  () => import("n8ao")
45
45
  ),
46
+ PEERJS: createModule<typeof import("peerjs")>(
47
+ () => import("peerjs")
48
+ ),
46
49
  };
@@ -118,6 +118,7 @@ declare type OwnershipResponse = {
118
118
 
119
119
  declare type WebsocketSendType = IModel | object | boolean | null | string | number;
120
120
 
121
+ // #region OwnershipModel
121
122
  /**
122
123
  * Manages ownership of networked objects or components.
123
124
  *
@@ -368,6 +369,8 @@ export class OwnershipModel {
368
369
  }
369
370
 
370
371
 
372
+ // #region Networking
373
+
371
374
  export declare type BinaryCallback = {
372
375
  (data: any | flatbuffers.ByteBuffer): void;
373
376
  }
@@ -411,6 +414,7 @@ export declare type BinaryCallback = {
411
414
  * @see {@link RoomEvents} for room lifecycle events
412
415
  * @see {@link OwnershipModel} for object ownership
413
416
  * @link https://engine.needle.tools/docs/how-to-guides/networking/
417
+ * @category Networking
414
418
  */
415
419
  export class NetworkConnection implements INetworkConnection {
416
420
 
@@ -560,7 +564,7 @@ export class NetworkConnection implements INetworkConnection {
560
564
  return true;
561
565
  }
562
566
 
563
- /** Send a message to the networking backend - it will broadcasted to all connected users in the same room by default */
567
+ /** Send a message to the networking backend - it will be broadcasted to all connected users (except yourself) in the same room by default */
564
568
  public send<T extends WebsocketSendType>(key: string | OwnershipEvent, data: T | null = null, queue: SendQueue = SendQueue.Queued) {
565
569
 
566
570
  //@ts-ignore
@@ -1,6 +1,6 @@
1
- // workaround for this is not a function when deployed
2
- // see https://github.com/pvorb/node-md5/issues/52
3
- import md5 from "md5";
1
+ import * as _md5 from "md5";
2
+ // CJS interop: md5 may appear as { default: fn } or fn depending on bundler
3
+ const md5 = typeof _md5 === "function" ? _md5 : (_md5 as any).default;
4
4
  import { FileLoader } from "three";
5
5
 
6
6
  import { showBalloonWarning } from "./debug/index.js";
@@ -1,6 +1,7 @@
1
1
  import type { DataConnection, PeerJSOption } from "peerjs";
2
- import Peer, { type PeerConnectOption } from "peerjs";
2
+ import type Peer from "peerjs";
3
3
 
4
+ import { MODULES } from "./engine_modules.js";
4
5
  import { type ConstructorConcrete } from "./engine_types.js";
5
6
 
6
7
  let peerOptions: PeerJSOption | undefined = undefined;
@@ -11,22 +12,23 @@ export function getPeerOptions() {
11
12
  export function setPeerOptions(opts: PeerJSOption) {
12
13
  peerOptions = opts;
13
14
  }
14
- export function getPeerjsInstance(id?: string, opts?: PeerJSOption): Peer {
15
+ export async function getPeerjsInstance(id?: string, opts?: PeerJSOption): Promise<Peer> {
16
+ const peerjs = await MODULES.PEERJS.load();
17
+ const PeerConstructor = peerjs.default;
15
18
  if (!opts) opts = {}
16
19
  opts = {
17
20
  ...peerOptions,
18
21
  ...opts,
19
22
  }
20
23
  if (id)
21
- return new Peer(id, opts);
22
- return new Peer(opts);
24
+ return new PeerConstructor(id, opts);
25
+ return new PeerConstructor(opts);
23
26
  }
24
27
 
25
28
 
26
29
 
27
30
  async function importPeer(): Promise<ConstructorConcrete<Peer>> {
28
- const pkg = await import("peerjs");
29
- console.log(pkg);
31
+ const pkg = await MODULES.PEERJS.load();
30
32
  if (pkg.default === undefined) return pkg as any;
31
33
  return pkg.default;
32
34
  }
@@ -1,4 +1,5 @@
1
- import Peer, { CallOption, MediaConnection } from "peerjs"
1
+ import type Peer from "peerjs";
2
+ import type { CallOption, MediaConnection } from "peerjs";
2
3
  import { EventDispatcher } from "three";
3
4
 
4
5
  import { RoomEvents } from "../engine/engine_networking.js";
@@ -285,14 +286,14 @@ export class PeerHandle extends EventDispatcher<any> {
285
286
  // private onUserJoinedOrLeftRoom(_: UserJoinedOrLeftRoomModel): void {
286
287
  // };
287
288
 
288
- private setupPeer() {
289
+ private async setupPeer() {
289
290
  if (!this.context.connection.connectionId) return;
290
291
  if (this._enabledPeer) return;
291
292
  this._enabledPeer = true;
292
293
  if (!this._peer) {
293
294
  const peerId = this.getMyPeerId();
294
295
  if (peerId)
295
- this._peer = getPeerjsInstance(peerId);
296
+ this._peer = await getPeerjsInstance(peerId);
296
297
  else console.error("Failed to setup peerjs because we dont have a connection id", this.context.connection.connectionId);
297
298
  }
298
299
  if (this._enabled)
@@ -203,6 +203,14 @@ export class RapierPhysics implements IPhysicsEngine {
203
203
  }
204
204
  }
205
205
 
206
+ setColliderEnabled(collider: ICollider, enabled: boolean): boolean {
207
+ const rapierCollider = collider[$bodyKey] as Collider;
208
+ if (!rapierCollider) return false;
209
+ rapierCollider.setEnabled(enabled);
210
+ if (debugPhysics) console.log("SET COLLIDER ENABLED", collider.name, enabled);
211
+ return true;
212
+ }
213
+
206
214
  updateBody(comp: ICollider | IRigidbody, translation: boolean, rotation: boolean) {
207
215
  this.validate();
208
216
  if (!this.enabled) return;
@@ -1188,6 +1196,7 @@ export class RapierPhysics implements IPhysicsEngine {
1188
1196
 
1189
1197
  // private _lastStepTime: number | undefined = 0;
1190
1198
  private lines?: LineSegments;
1199
+ private disabledLines?: LineSegments;
1191
1200
 
1192
1201
  public step(dt?: number) {
1193
1202
  if (!this.world) return;
@@ -1238,29 +1247,53 @@ export class RapierPhysics implements IPhysicsEngine {
1238
1247
  const material = new LineBasicMaterial({
1239
1248
  color: 0x77dd77,
1240
1249
  fog: false,
1241
- // vertexColors: VertexColors
1242
1250
  });
1243
1251
  const geometry = new BufferGeometry();
1244
1252
  this.lines = new LineSegments(geometry, material);
1245
1253
  this.lines.layers.disableAll();
1246
1254
  this.lines.layers.enable(2);
1247
1255
  }
1256
+ if (!this.disabledLines) {
1257
+ const material = new LineBasicMaterial({
1258
+ color: 0xdd7777,
1259
+ fog: false,
1260
+ });
1261
+ const geometry = new BufferGeometry();
1262
+ this.disabledLines = new LineSegments(geometry, material);
1263
+ this.disabledLines.layers.disableAll();
1264
+ this.disabledLines.layers.enable(2);
1265
+ }
1248
1266
  if (this.lines.parent !== this.context?.scene)
1249
1267
  this.context?.scene.add(this.lines);
1250
- const buffers = world.debugRender();
1251
- this.lines.geometry.setAttribute('position', new BufferAttribute(buffers.vertices, 3));
1252
- this.lines.geometry.setAttribute('color', new BufferAttribute(buffers.colors, 4));
1268
+ if (this.disabledLines.parent !== this.context?.scene)
1269
+ this.context?.scene.add(this.disabledLines);
1270
+
1271
+ // Render enabled colliders in green
1272
+ const enabledBuffers = world.debugRender(undefined, col => col.isEnabled());
1273
+ this.lines.geometry.setAttribute('position', new BufferAttribute(enabledBuffers.vertices, 3));
1274
+ this.lines.geometry.setAttribute('color', new BufferAttribute(enabledBuffers.colors, 4));
1275
+
1276
+ // Render disabled colliders in red
1277
+ const disabledBuffers = world.debugRender(undefined, col => !col.isEnabled());
1278
+ this.disabledLines.geometry.setAttribute('position', new BufferAttribute(disabledBuffers.vertices, 3));
1279
+ this.disabledLines.geometry.setAttribute('color', new BufferAttribute(disabledBuffers.colors, 4));
1280
+ this.disabledLines.visible = disabledBuffers.vertices.length > 0;
1281
+
1253
1282
  // If a scene has no colliders at all at the start of the scene
1254
1283
  // the bounding sphere radius will be 0 and the lines will not be rendered
1255
1284
  // so we need to update the bounding sphere (perhaps it's enough to do this once...)
1256
1285
  if (this.context!.time.frame % 30 === 0 || this.lines.geometry.boundingSphere?.radius === 0) {
1257
1286
  this.lines.geometry.computeBoundingSphere();
1287
+ this.disabledLines.geometry.computeBoundingSphere();
1258
1288
  }
1259
1289
  }
1260
1290
  else {
1261
1291
  if (this.lines) {
1262
1292
  this.context?.scene.remove(this.lines);
1263
1293
  }
1294
+ if (this.disabledLines) {
1295
+ this.context?.scene.remove(this.disabledLines);
1296
+ }
1264
1297
  }
1265
1298
  }
1266
1299
 
@@ -10,24 +10,26 @@ export declare type OffscreenCanvasExt = OffscreenCanvas & {
10
10
 
11
11
  // REMOVE once usage of browsers that don't support OffscreenCanvas is low
12
12
  // Shim for missing OffscreenCanvas in iOS 16.x
13
- if (typeof globalThis !== undefined && !('OffscreenCanvas' in globalThis)) {
14
- // @ts-ignore
15
- globalThis['OffscreenCanvas'] = class OffscreenCanvas {
16
- canvas: HTMLCanvasElement;
17
- constructor(width, height) {
18
- this.canvas = document.createElement("canvas");
19
- this.canvas.width = width;
20
- this.canvas.height = height;
21
-
22
- // @ts-ignore
23
- this.canvas.convertToBlob = (type?: string, quality?: any) => {
24
- return new Promise(resolve => {
25
- this.canvas.toBlob(resolve, type, quality);
26
- });
27
- };
28
-
29
- // @ts-ignore
30
- return this.canvas;
31
- }
32
- };
13
+ export function initShims() {
14
+ if (typeof globalThis !== undefined && !('OffscreenCanvas' in globalThis)) {
15
+ // @ts-ignore
16
+ globalThis['OffscreenCanvas'] = class OffscreenCanvas {
17
+ canvas: HTMLCanvasElement;
18
+ constructor(width, height) {
19
+ this.canvas = document.createElement("canvas");
20
+ this.canvas.width = width;
21
+ this.canvas.height = height;
22
+
23
+ // @ts-ignore
24
+ this.canvas.convertToBlob = (type?: string, quality?: any) => {
25
+ return new Promise(resolve => {
26
+ this.canvas.toBlob(resolve, type, quality);
27
+ });
28
+ };
29
+
30
+ // @ts-ignore
31
+ return this.canvas;
32
+ }
33
+ };
34
+ }
33
35
  }
@@ -10,7 +10,6 @@ export function patchTonemapping(_ctx?: Context) {
10
10
  patchNeutral();
11
11
  patchAGX();
12
12
  }
13
- patchTonemapping();
14
13
 
15
14
  function patchNeutral() {
16
15
  // From https://github.com/google/model-viewer/pull/4495
@@ -719,6 +719,15 @@ export interface IPhysicsEngine {
719
719
  */
720
720
  removeBody(body: IComponent);
721
721
 
722
+ /**
723
+ * Enables or disables a collider in the physics world without destroying it.
724
+ * Uses Rapier's `setEnabled()` for efficient toggling instead of removing and recreating the collider.
725
+ * @param collider The collider component to enable or disable
726
+ * @param enabled Whether the collider should be enabled
727
+ * @returns True if the collider was found and its state was changed, false otherwise
728
+ */
729
+ setColliderEnabled(collider: ICollider, enabled: boolean): boolean;
730
+
722
731
  /**
723
732
  * Gets the physics body for a component
724
733
  * @param obj The collider or rigidbody component
@@ -8,6 +8,7 @@ class _TypeStore {
8
8
 
9
9
  private _types: Map<string, Type> = new Map();
10
10
  private _reverseTypes: Map<Type, string> = new Map();
11
+ private _lazyLoaders: Map<string, () => Promise<Type>> = new Map();
11
12
 
12
13
  constructor() {
13
14
  if (debug) console.warn("TypeStore: Created", this);
@@ -32,6 +33,16 @@ class _TypeStore {
32
33
  }
33
34
  }
34
35
 
36
+ /**
37
+ * Register a lazy-loadable type. The loader is called on first use via {@link getAsync}.
38
+ * Once resolved, the type is cached for synchronous access via {@link get}.
39
+ */
40
+ public addLazy(key: string, loader: () => Promise<Type>) {
41
+ if (!this._types.has(key)) {
42
+ this._lazyLoaders.set(key, loader);
43
+ }
44
+ }
45
+
35
46
  /**
36
47
  * @returns the type for the given key if registered
37
48
  */
@@ -39,6 +50,24 @@ class _TypeStore {
39
50
  return this._types.get(key) || null;
40
51
  }
41
52
 
53
+ /**
54
+ * Async version of {@link get} that also resolves lazy-registered types.
55
+ * After resolving, the type is cached for future synchronous access.
56
+ */
57
+ public async getAsync(key: string): Promise<Type | null> {
58
+ const existing = this._types.get(key);
59
+ if (existing) return existing;
60
+ const loader = this._lazyLoaders.get(key);
61
+ if (loader) {
62
+ if (debug) console.warn("LAZY LOAD TYPE", key);
63
+ const type = await loader();
64
+ this.add(key, type);
65
+ this._lazyLoaders.delete(key);
66
+ return type;
67
+ }
68
+ return null;
69
+ }
70
+
42
71
  /**
43
72
  * @returns the key/name for the given type if registered
44
73
  */
@@ -1,7 +1,7 @@
1
1
  import { AnimationAction, AnimationClip, MathUtils, Object3D } from "three"
2
2
 
3
3
  import { InstantiateIdProvider } from "../../engine/engine_networking_instantiate.js";
4
- import { Animator } from "../../engine-components/Animator.js";
4
+ import type { Animator } from "../../engine-components/Animator.js";
5
5
  import { Context } from "../engine_setup.js";
6
6
 
7
7
 
@@ -1,38 +1,45 @@
1
1
  import { PerspectiveCamera } from "three";
2
2
 
3
+ let initialized = false;
4
+
3
5
  // Wrap camera FOV to allow animation of fov
4
- Object.defineProperty(PerspectiveCamera.prototype, "fov", {
5
- get: function () {
6
- return this._fov;;
7
- },
8
- set: function (val) {
9
- const changed = val !== this._fov;
10
- this._fov = val;
11
- if (changed && this.view !== undefined) this.updateProjectionMatrix();
12
- },
13
- configurable: true
14
- });
6
+ export function initCameraExtensions() {
7
+ if (initialized) return;
8
+ initialized = true;
9
+
10
+ Object.defineProperty(PerspectiveCamera.prototype, "fov", {
11
+ get: function () {
12
+ return this._fov;;
13
+ },
14
+ set: function (val) {
15
+ const changed = val !== this._fov;
16
+ this._fov = val;
17
+ if (changed && this.view !== undefined) this.updateProjectionMatrix();
18
+ },
19
+ configurable: true
20
+ });
15
21
 
16
- Object.defineProperty(PerspectiveCamera.prototype, "near", {
17
- get: function () {
18
- return this._near;
19
- },
20
- set: function (val) {
21
- const changed = val !== this._near;
22
- this._near = val;
23
- if (changed && this.view !== undefined) this.updateProjectionMatrix();
24
- },
25
- configurable: true
26
- });
22
+ Object.defineProperty(PerspectiveCamera.prototype, "near", {
23
+ get: function () {
24
+ return this._near;
25
+ },
26
+ set: function (val) {
27
+ const changed = val !== this._near;
28
+ this._near = val;
29
+ if (changed && this.view !== undefined) this.updateProjectionMatrix();
30
+ },
31
+ configurable: true
32
+ });
27
33
 
28
- Object.defineProperty(PerspectiveCamera.prototype, "far", {
29
- get: function () {
30
- return this._far;
31
- },
32
- set: function (val) {
33
- const changed = val !== this._far;
34
- this._far = val;
35
- if (changed && this.view !== undefined) this.updateProjectionMatrix();
36
- },
37
- configurable: true
38
- });
34
+ Object.defineProperty(PerspectiveCamera.prototype, "far", {
35
+ get: function () {
36
+ return this._far;
37
+ },
38
+ set: function (val) {
39
+ const changed = val !== this._far;
40
+ this._far = val;
41
+ if (changed && this.view !== undefined) this.updateProjectionMatrix();
42
+ },
43
+ configurable: true
44
+ });
45
+ }
@@ -20,5 +20,4 @@ export function patchLayers() {
20
20
  if(this[$customVisibilityFlag] === false) return false;
21
21
  return origTest.call(this, layer);
22
22
  };
23
- }
24
- patchLayers();
23
+ }