@needle-tools/engine 2.65.2-pre → 2.67.0-pre

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 (289) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/needle-engine.js +34490 -26304
  3. package/dist/needle-engine.umd.cjs +748 -303
  4. package/lib/engine/api.d.ts +4 -0
  5. package/lib/engine/api.js +10 -0
  6. package/lib/engine/api.js.map +1 -1
  7. package/lib/engine/codegen/register_types.js +23 -7
  8. package/lib/engine/codegen/register_types.js.map +1 -1
  9. package/lib/engine/debug/debug_overlay.js +11 -2
  10. package/lib/engine/debug/debug_overlay.js.map +1 -1
  11. package/lib/engine/engine_addressables.js +4 -4
  12. package/lib/engine/engine_addressables.js.map +1 -1
  13. package/lib/engine/engine_assetdatabase.d.ts +17 -51
  14. package/lib/engine/engine_assetdatabase.js +252 -126
  15. package/lib/engine/engine_assetdatabase.js.map +1 -1
  16. package/lib/engine/engine_components.js +13 -1
  17. package/lib/engine/engine_components.js.map +1 -1
  18. package/lib/engine/engine_components_internal.d.ts +8 -0
  19. package/lib/engine/engine_components_internal.js +29 -0
  20. package/lib/engine/engine_components_internal.js.map +1 -0
  21. package/lib/engine/engine_constants.d.ts +1 -0
  22. package/lib/engine/engine_constants.js +1 -0
  23. package/lib/engine/engine_constants.js.map +1 -1
  24. package/lib/engine/engine_context_registry.d.ts +2 -0
  25. package/lib/engine/engine_context_registry.js +6 -0
  26. package/lib/engine/engine_context_registry.js.map +1 -1
  27. package/lib/engine/engine_editor-sync.d.ts +9 -0
  28. package/lib/engine/engine_editor-sync.js +8 -0
  29. package/lib/engine/engine_editor-sync.js.map +1 -0
  30. package/lib/engine/engine_element.d.ts +1 -0
  31. package/lib/engine/engine_element.js +4 -1
  32. package/lib/engine/engine_element.js.map +1 -1
  33. package/lib/engine/engine_element_loading.d.ts +3 -2
  34. package/lib/engine/engine_element_loading.js +19 -15
  35. package/lib/engine/engine_element_loading.js.map +1 -1
  36. package/lib/engine/engine_gameobject.js +21 -23
  37. package/lib/engine/engine_gameobject.js.map +1 -1
  38. package/lib/engine/engine_gizmos.js +3 -1
  39. package/lib/engine/engine_gizmos.js.map +1 -1
  40. package/lib/engine/engine_gltf_builtin_components.d.ts +2 -3
  41. package/lib/engine/engine_gltf_builtin_components.js +23 -6
  42. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  43. package/lib/engine/engine_networking.d.ts +3 -1
  44. package/lib/engine/engine_networking.js +10 -8
  45. package/lib/engine/engine_networking.js.map +1 -1
  46. package/lib/engine/engine_networking_auto.d.ts +1 -0
  47. package/lib/engine/engine_networking_auto.js +42 -9
  48. package/lib/engine/engine_networking_auto.js.map +1 -1
  49. package/lib/engine/engine_patcher.d.ts +8 -0
  50. package/lib/engine/engine_patcher.js +98 -0
  51. package/lib/engine/engine_patcher.js.map +1 -0
  52. package/lib/engine/engine_physics.d.ts +34 -2
  53. package/lib/engine/engine_physics.js +110 -11
  54. package/lib/engine/engine_physics.js.map +1 -1
  55. package/lib/engine/engine_scenetools.js +0 -1
  56. package/lib/engine/engine_scenetools.js.map +1 -1
  57. package/lib/engine/engine_serialization_core.js +4 -0
  58. package/lib/engine/engine_serialization_core.js.map +1 -1
  59. package/lib/engine/engine_setup.d.ts +1 -1
  60. package/lib/engine/engine_setup.js +12 -5
  61. package/lib/engine/engine_setup.js.map +1 -1
  62. package/lib/engine/engine_texture.d.ts +6 -1
  63. package/lib/engine/engine_texture.js +39 -1
  64. package/lib/engine/engine_texture.js.map +1 -1
  65. package/lib/engine/engine_types.d.ts +4 -0
  66. package/lib/engine/engine_types.js.map +1 -1
  67. package/lib/engine/engine_utils.js +3 -2
  68. package/lib/engine/engine_utils.js.map +1 -1
  69. package/lib/engine/extensions/NEEDLE_progressive.d.ts +0 -1
  70. package/lib/engine/extensions/NEEDLE_progressive.js +24 -26
  71. package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
  72. package/lib/engine/extensions/NEEDLE_render_objects.js +9 -0
  73. package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
  74. package/lib/engine/extensions/extensions.d.ts +4 -1
  75. package/lib/engine/extensions/extensions.js +16 -0
  76. package/lib/engine/extensions/extensions.js.map +1 -1
  77. package/lib/engine/extensions/usage_tracker.d.ts +12 -0
  78. package/lib/engine/extensions/usage_tracker.js +59 -0
  79. package/lib/engine/extensions/usage_tracker.js.map +1 -0
  80. package/lib/engine-components/Animator.js +0 -1
  81. package/lib/engine-components/Animator.js.map +1 -1
  82. package/lib/engine-components/AnimatorController.js +4 -0
  83. package/lib/engine-components/AnimatorController.js.map +1 -1
  84. package/lib/engine-components/AudioSource.js +2 -1
  85. package/lib/engine-components/AudioSource.js.map +1 -1
  86. package/lib/engine-components/Camera.d.ts +6 -0
  87. package/lib/engine-components/Camera.js +70 -31
  88. package/lib/engine-components/Camera.js.map +1 -1
  89. package/lib/engine-components/CharacterController.d.ts +1 -0
  90. package/lib/engine-components/CharacterController.js +14 -9
  91. package/lib/engine-components/CharacterController.js.map +1 -1
  92. package/lib/engine-components/Collider.js +14 -1
  93. package/lib/engine-components/Collider.js.map +1 -1
  94. package/lib/engine-components/Component.d.ts +52 -0
  95. package/lib/engine-components/Component.js +55 -14
  96. package/lib/engine-components/Component.js.map +1 -1
  97. package/lib/engine-components/Networking.js +19 -0
  98. package/lib/engine-components/Networking.js.map +1 -1
  99. package/lib/engine-components/OrbitControls.d.ts +2 -0
  100. package/lib/engine-components/OrbitControls.js +9 -0
  101. package/lib/engine-components/OrbitControls.js.map +1 -1
  102. package/lib/engine-components/ParticleSystem.d.ts +5 -1
  103. package/lib/engine-components/ParticleSystem.js +52 -7
  104. package/lib/engine-components/ParticleSystem.js.map +1 -1
  105. package/lib/engine-components/ParticleSystemModules.d.ts +2 -0
  106. package/lib/engine-components/ParticleSystemModules.js +26 -0
  107. package/lib/engine-components/ParticleSystemModules.js.map +1 -1
  108. package/lib/engine-components/ParticleSystemSubEmitter.js +5 -2
  109. package/lib/engine-components/ParticleSystemSubEmitter.js.map +1 -1
  110. package/lib/engine-components/ReflectionProbe.js +18 -6
  111. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  112. package/lib/engine-components/Renderer.d.ts +1 -1
  113. package/lib/engine-components/Renderer.js +33 -11
  114. package/lib/engine-components/Renderer.js.map +1 -1
  115. package/lib/engine-components/ScreenCapture.js +3 -3
  116. package/lib/engine-components/ScreenCapture.js.map +1 -1
  117. package/lib/engine-components/Skybox.js +2 -0
  118. package/lib/engine-components/Skybox.js.map +1 -1
  119. package/lib/engine-components/SmoothFollow.js +1 -2
  120. package/lib/engine-components/SmoothFollow.js.map +1 -1
  121. package/lib/engine-components/SpectatorCamera.js +3 -3
  122. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  123. package/lib/engine-components/SyncedCamera.js +1 -1
  124. package/lib/engine-components/SyncedCamera.js.map +1 -1
  125. package/lib/engine-components/SyncedTransform.js +2 -2
  126. package/lib/engine-components/SyncedTransform.js.map +1 -1
  127. package/lib/engine-components/TestRunner.js +1 -1
  128. package/lib/engine-components/TestRunner.js.map +1 -1
  129. package/lib/engine-components/WebARCameraBackground.d.ts +19 -0
  130. package/lib/engine-components/WebARCameraBackground.js +185 -0
  131. package/lib/engine-components/WebARCameraBackground.js.map +1 -0
  132. package/lib/engine-components/WebARSessionRoot.js +3 -2
  133. package/lib/engine-components/WebARSessionRoot.js.map +1 -1
  134. package/lib/engine-components/WebXR.d.ts +4 -0
  135. package/lib/engine-components/WebXR.js +11 -8
  136. package/lib/engine-components/WebXR.js.map +1 -1
  137. package/lib/engine-components/WebXRAvatar.js +1 -0
  138. package/lib/engine-components/WebXRAvatar.js.map +1 -1
  139. package/lib/engine-components/WebXRGrabRendering.js +2 -2
  140. package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
  141. package/lib/engine-components/WebXRSync.js +2 -2
  142. package/lib/engine-components/WebXRSync.js.map +1 -1
  143. package/lib/engine-components/codegen/components.d.ts +14 -6
  144. package/lib/engine-components/codegen/components.js +14 -6
  145. package/lib/engine-components/codegen/components.js.map +1 -1
  146. package/lib/engine-components/js-extensions/Object3D.js +4 -1
  147. package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
  148. package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +13 -0
  149. package/lib/engine-components/postprocessing/Effects/Antialiasing.js +46 -0
  150. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -0
  151. package/lib/engine-components/postprocessing/Effects/Bloom.d.ts +12 -0
  152. package/lib/engine-components/postprocessing/Effects/Bloom.js +76 -0
  153. package/lib/engine-components/postprocessing/Effects/Bloom.js.map +1 -0
  154. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +8 -0
  155. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +39 -0
  156. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -0
  157. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +12 -0
  158. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +96 -0
  159. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -0
  160. package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +21 -0
  161. package/lib/engine-components/postprocessing/Effects/DepthOfField.js +87 -0
  162. package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -0
  163. package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +7 -0
  164. package/lib/engine-components/postprocessing/Effects/Pixelation.js +30 -0
  165. package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -0
  166. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +11 -0
  167. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +70 -0
  168. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -0
  169. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +16 -0
  170. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +52 -0
  171. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -0
  172. package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +11 -0
  173. package/lib/engine-components/postprocessing/Effects/Vignette.js +57 -0
  174. package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -0
  175. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +29 -0
  176. package/lib/engine-components/postprocessing/PostProcessingEffect.js +89 -0
  177. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -0
  178. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +13 -0
  179. package/lib/engine-components/postprocessing/PostProcessingHandler.js +119 -0
  180. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -0
  181. package/lib/engine-components/postprocessing/Volume.d.ts +23 -0
  182. package/lib/engine-components/postprocessing/Volume.js +176 -0
  183. package/lib/engine-components/postprocessing/Volume.js.map +1 -0
  184. package/lib/engine-components/postprocessing/VolumeParameter.d.ts +21 -0
  185. package/lib/engine-components/postprocessing/VolumeParameter.js +75 -0
  186. package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -0
  187. package/lib/engine-components/postprocessing/VolumeProfile.d.ts +7 -0
  188. package/lib/engine-components/postprocessing/VolumeProfile.js +42 -0
  189. package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -0
  190. package/lib/engine-components/timeline/TimelineTracks.js +14 -15
  191. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  192. package/lib/engine-components/ui/Text.js +28 -170
  193. package/lib/engine-components/ui/Text.js.map +1 -1
  194. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +18 -0
  195. package/lib/engine-components-experimental/networking/PlayerSync.js +62 -8
  196. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  197. package/lib/include/three/ARButton.d.ts +1 -1
  198. package/lib/include/three/ARButton.js +11 -19
  199. package/lib/include/three/ARButton.js.map +1 -1
  200. package/lib/include/three/VRButton.js +1 -4
  201. package/lib/include/three/VRButton.js.map +1 -1
  202. package/package.json +3 -2
  203. package/plugins/vite/drop-client.js +77 -0
  204. package/plugins/vite/drop.js +81 -0
  205. package/plugins/vite/editor-connection.js +121 -0
  206. package/plugins/vite/index.js +9 -4
  207. package/plugins/vite/meta.js +3 -0
  208. package/plugins/vite/poster-client.js +6 -4
  209. package/src/engine/api.ts +30 -1
  210. package/src/engine/codegen/register_types.js +25 -9
  211. package/src/engine/debug/debug_overlay.ts +11 -2
  212. package/src/engine/engine_addressables.ts +4 -4
  213. package/src/engine/engine_assetdatabase.ts +291 -184
  214. package/src/engine/engine_components.ts +20 -1
  215. package/src/engine/engine_components_internal.ts +30 -0
  216. package/src/engine/engine_constants.ts +4 -1
  217. package/src/engine/engine_context_registry.ts +7 -0
  218. package/src/engine/engine_editor-sync.ts +21 -0
  219. package/src/engine/engine_element.ts +8 -1
  220. package/src/engine/engine_element_loading.ts +19 -15
  221. package/src/engine/engine_gameobject.ts +579 -583
  222. package/src/engine/engine_gizmos.ts +3 -2
  223. package/src/engine/engine_gltf_builtin_components.ts +30 -15
  224. package/src/engine/engine_networking.ts +10 -8
  225. package/src/engine/engine_networking_auto.ts +48 -11
  226. package/src/engine/engine_patcher.ts +113 -0
  227. package/src/engine/engine_physics.ts +128 -12
  228. package/src/engine/engine_scenetools.ts +0 -1
  229. package/src/engine/engine_serialization_core.ts +6 -0
  230. package/src/engine/engine_setup.ts +15 -5
  231. package/src/engine/engine_texture.ts +54 -5
  232. package/src/engine/engine_types.ts +6 -1
  233. package/src/engine/engine_utils.ts +6 -5
  234. package/src/engine/extensions/NEEDLE_progressive.ts +32 -32
  235. package/src/engine/extensions/NEEDLE_render_objects.ts +10 -1
  236. package/src/engine/extensions/extensions.ts +22 -1
  237. package/src/engine/extensions/usage_tracker.ts +91 -0
  238. package/src/engine-components/Animator.ts +0 -1
  239. package/src/engine-components/AnimatorController.ts +2 -0
  240. package/src/engine-components/AudioSource.ts +1 -1
  241. package/src/engine-components/Camera.ts +77 -37
  242. package/src/engine-components/CharacterController.ts +12 -9
  243. package/src/engine-components/Collider.ts +16 -2
  244. package/src/engine-components/Component.ts +74 -30
  245. package/src/engine-components/Networking.ts +9 -1
  246. package/src/engine-components/OrbitControls.ts +11 -2
  247. package/src/engine-components/ParticleSystem.ts +54 -10
  248. package/src/engine-components/ParticleSystemModules.ts +28 -1
  249. package/src/engine-components/ParticleSystemSubEmitter.ts +5 -3
  250. package/src/engine-components/ReflectionProbe.ts +17 -7
  251. package/src/engine-components/Renderer.ts +36 -16
  252. package/src/engine-components/ScreenCapture.ts +3 -3
  253. package/src/engine-components/Skybox.ts +2 -0
  254. package/src/engine-components/SmoothFollow.ts +4 -4
  255. package/src/engine-components/SpectatorCamera.ts +3 -3
  256. package/src/engine-components/SyncedCamera.ts +1 -1
  257. package/src/engine-components/SyncedTransform.ts +2 -2
  258. package/src/engine-components/TestRunner.ts +1 -1
  259. package/src/engine-components/WebARCameraBackground.ts +215 -0
  260. package/src/engine-components/WebARSessionRoot.ts +3 -2
  261. package/src/engine-components/WebXR.ts +12 -8
  262. package/src/engine-components/WebXRAvatar.ts +1 -1
  263. package/src/engine-components/WebXRGrabRendering.ts +2 -2
  264. package/src/engine-components/WebXRSync.ts +2 -2
  265. package/src/engine-components/codegen/components.ts +14 -6
  266. package/src/engine-components/js-extensions/Object3D.ts +6 -1
  267. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +52 -0
  268. package/src/engine-components/postprocessing/Effects/Bloom.ts +75 -0
  269. package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +36 -0
  270. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +114 -0
  271. package/src/engine-components/postprocessing/Effects/DepthOfField.ts +90 -0
  272. package/src/engine-components/postprocessing/Effects/Pixelation.ts +28 -0
  273. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +71 -0
  274. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +55 -0
  275. package/src/engine-components/postprocessing/Effects/Vignette.ts +55 -0
  276. package/src/engine-components/postprocessing/PostProcessingEffect.ts +112 -0
  277. package/src/engine-components/postprocessing/PostProcessingHandler.ts +148 -0
  278. package/src/engine-components/postprocessing/Volume.ts +194 -0
  279. package/src/engine-components/postprocessing/VolumeParameter.ts +85 -0
  280. package/src/engine-components/postprocessing/VolumeProfile.ts +40 -0
  281. package/src/engine-components/timeline/TimelineTracks.ts +16 -17
  282. package/src/engine-components/ui/Text.ts +37 -174
  283. package/src/engine-components-experimental/networking/PlayerSync.ts +69 -8
  284. package/src/include/three/ARButton.js +13 -24
  285. package/src/include/three/VRButton.js +1 -7
  286. package/lib/engine-components/Volume.d.ts +0 -34
  287. package/lib/engine-components/Volume.js +0 -140
  288. package/lib/engine-components/Volume.js.map +0 -1
  289. package/src/engine-components/Volume.ts +0 -141
@@ -145,10 +145,9 @@ class Internal {
145
145
  }
146
146
 
147
147
  static getSphere(radius: number, duration: number, wireframe: boolean): Mesh {
148
-
149
148
  let sphere = this.spheresCache.pop();
150
149
  if (!sphere) {
151
- sphere = new Mesh(new SphereGeometry(.5, 8, 8));
150
+ sphere = new Mesh(new SphereGeometry(1, 8, 8));
152
151
  }
153
152
  sphere.scale.set(radius, radius, radius);
154
153
  sphere.material["wireframe"] = wireframe;
@@ -176,6 +175,8 @@ class Internal {
176
175
  this.contextPostRenderCallbacks.set(context, cb);
177
176
  context.post_render_callbacks.push(cb);
178
177
  }
178
+ object.layers.disableAll();
179
+ object.layers.enable(2);
179
180
  object[$cacheSymbol] = cache;
180
181
  this.timedObjectsBuffer.push(object);
181
182
  this.timesBuffer.push(Context.Current.time.time + duration);
@@ -1,15 +1,15 @@
1
1
  import "./codegen/register_types";
2
2
  import { TypeStore } from "./engine_typestore";
3
3
  import * as THREE from "three";
4
- import { Component, GameObject } from "../engine-components/Component";
4
+ // import { GameObject } from "../engine-components/Component";
5
5
  import { InstantiateIdProvider } from "./engine_networking_instantiate"
6
6
  import { Context } from "./engine_setup";
7
7
  import { deserializeObject, serializeObject } from "./engine_serialization";
8
8
  import { assign, ImplementationInformation, ISerializable, SerializationContext } from "./engine_serialization_core";
9
9
  import { NEEDLE_components } from "./extensions/NEEDLE_components";
10
10
  import { debugExtension } from "./engine_default_parameters";
11
- import { builtinComponentKeyName } from "./engine_constants";
12
- import { GuidsMap, SourceIdentifier } from "./engine_types";
11
+ import { $originalGuid, builtinComponentKeyName } from "./engine_constants";
12
+ import { GuidsMap, IComponent, IGameObject, SourceIdentifier } from "./engine_types";
13
13
  import { UIDProvider } from "./engine_types";
14
14
  import { addNewComponent } from "./engine_components";
15
15
  import { getParam } from "./engine_utils";
@@ -21,7 +21,7 @@ const debug = debugExtension;
21
21
  const debugTypeStore = getParam("debugtypestore");
22
22
  if (debugTypeStore) console.log(TypeStore);
23
23
 
24
- export function writeBuiltinComponentData(comp: Component, context: SerializationContext): object | null {
24
+ export function writeBuiltinComponentData(comp: IComponent, context: SerializationContext): object | null {
25
25
 
26
26
  // const fn = (comp as unknown as ISerializable)?.onBeforeSerialize;
27
27
  // if (fn) {
@@ -39,6 +39,7 @@ export function writeBuiltinComponentData(comp: Component, context: Serializatio
39
39
  }
40
40
 
41
41
  const typeImplementationInformation = new ImplementationInformation();
42
+ const $context_deserialize_queue = Symbol("deserialize-queue");
42
43
 
43
44
  export async function createBuiltinComponents(context: Context, gltfId: SourceIdentifier, gltf, seed: number | null | UIDProvider = null, extension?: NEEDLE_components) {
44
45
  if (!gltf) return;
@@ -56,26 +57,34 @@ export async function createBuiltinComponents(context: Context, gltfId: SourceId
56
57
  serializationContext.nodeToObject = extension?.nodeToObjectMap;
57
58
  serializationContext.implementationInformation = typeImplementationInformation;
58
59
 
59
- const deserialize: DeserializeData[] = [];
60
+ // If we're loading multiple gltf files in one scene we need to make sure we deserialize all of them in one go
61
+ // for that we collect them in one list per context
62
+ let deserializeQueue = context[$context_deserialize_queue];
63
+ if (!deserializeQueue) deserializeQueue = context[$context_deserialize_queue] = [];
60
64
 
61
65
  if (gltf.scenes) {
62
66
  for (const scene of gltf.scenes) {
63
- await onCreateBuiltinComponents(serializationContext, scene, deserialize, lateResolve);
67
+ await onCreateBuiltinComponents(serializationContext, scene, deserializeQueue, lateResolve);
64
68
  }
65
69
  }
66
70
  if (gltf.children) {
67
71
  for (const ch of gltf.children) {
68
- await onCreateBuiltinComponents(serializationContext, ch, deserialize, lateResolve);
72
+ await onCreateBuiltinComponents(serializationContext, ch, deserializeQueue, lateResolve);
69
73
  }
70
74
  }
71
75
 
72
-
73
76
  context.new_scripts_pre_setup_callbacks.push(() => {
74
-
75
- for (const des of deserialize) {
76
- handleDeserialization(des, serializationContext);
77
+ // First deserialize ALL components that were loaded before pre setup
78
+ // Down below they get new guids assigned so we have to do all of them first
79
+ // E.g. in cases where we load multiple glb files on startup from one scene
80
+ // and they might have cross-glb references
81
+ const queue = context[$context_deserialize_queue];
82
+ if (queue) {
83
+ for (const des of queue) {
84
+ handleDeserialization(des, serializationContext);
85
+ }
86
+ queue.length = 0;
77
87
  }
78
-
79
88
  // when dropping the same file multiple times we need to generate new guids
80
89
  // e.g. SyncTransform sends its own guid to the server to know about ownership
81
90
  // so it requires a unique guid for a new instance
@@ -95,7 +104,7 @@ export async function createBuiltinComponents(context: Context, gltfId: SourceId
95
104
  // console.log("finished creating builtin components", gltf.scene?.name, gltf);
96
105
  }
97
106
 
98
- function recursiveCreateGuids(obj: GameObject, idProvider: UIDProvider | null, guidsMap: GuidsMap) {
107
+ function recursiveCreateGuids(obj: IGameObject, idProvider: UIDProvider | null, guidsMap: GuidsMap) {
99
108
  if (idProvider === null) return;
100
109
  if (!obj) return;
101
110
  const prev = obj.guid;
@@ -117,7 +126,7 @@ function recursiveCreateGuids(obj: GameObject, idProvider: UIDProvider | null, g
117
126
  }
118
127
  if (obj.children) {
119
128
  for (const child of obj.children) {
120
- recursiveCreateGuids(child as GameObject, idProvider, guidsMap);
129
+ recursiveCreateGuids(child as IGameObject, idProvider, guidsMap);
121
130
  }
122
131
  }
123
132
  }
@@ -140,6 +149,7 @@ declare type LateResolveCallback = (gltf: THREE.Object3D) => void;
140
149
 
141
150
  const unknownComponentsBuffer: Array<string> = [];
142
151
 
152
+
143
153
  async function onCreateBuiltinComponents(context: SerializationContext, obj: THREE.Object3D,
144
154
  deserialize: DeserializeData[], lateResolve: LateResolveCallback[]) {
145
155
  if (!obj) return;
@@ -156,11 +166,16 @@ async function onCreateBuiltinComponents(context: SerializationContext, obj: THR
156
166
  const type = TypeStore.get(compData.name);
157
167
  // console.log(compData, compData.name, type, TypeStore);
158
168
  if (type !== undefined && type !== null) {
159
- const instance: Component = new type() as Component;
169
+ const instance: IComponent = new type() as IComponent;
160
170
  instance.sourceId = context.gltfId;
161
171
 
162
172
  // assign basic fields
163
173
  assign(instance, compData, context.implementationInformation);
174
+
175
+ // assign the guid of the original instance
176
+ if("guid" in compData)
177
+ instance[$originalGuid] = compData.guid;
178
+
164
179
  // Object.assign(instance, compData);
165
180
  // dont call awake here because some references might not be resolved yet and components that access those fields in awake will throw
166
181
  // for example Duplicatable reference to object might still be { node: id }
@@ -147,7 +147,7 @@ export class OwnershipModel {
147
147
  // console.log(res);
148
148
  if (res.guid === this.guid) {
149
149
  if (this._isWaitingForOwnershipResponseCallback) {
150
- this.connection.stopListening(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
150
+ this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
151
151
  this._isWaitingForOwnershipResponseCallback = null;
152
152
  }
153
153
  this._isOwned = res.value;
@@ -185,18 +185,18 @@ export class OwnershipModel {
185
185
  // TODO: abort "requestOwnershipIfNotOwned"
186
186
  this.connection.send(OwnershipEvent.RemoveOwnership, { guid: this.guid });
187
187
  if (this._isWaitingForOwnershipResponseCallback) {
188
- this.connection.stopListening(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
188
+ this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
189
189
  this._isWaitingForOwnershipResponseCallback = null;
190
190
  }
191
191
  return this;
192
192
  }
193
193
 
194
194
  public destroy() {
195
- this.connection.stopListening(OwnershipEvent.GainedOwnership, this._gainSubscription);
196
- this.connection.stopListening(OwnershipEvent.LostOwnership, this._lostSubscription);
197
- this.connection.stopListening(OwnershipEvent.ResponseHasOwner, this._hasOwnerResponse);
195
+ this.connection.stopListen(OwnershipEvent.GainedOwnership, this._gainSubscription);
196
+ this.connection.stopListen(OwnershipEvent.LostOwnership, this._lostSubscription);
197
+ this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._hasOwnerResponse);
198
198
  if (this._isWaitingForOwnershipResponseCallback) {
199
- this.connection.stopListening(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
199
+ this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
200
200
  this._isWaitingForOwnershipResponseCallback = null;
201
201
  }
202
202
  }
@@ -368,7 +368,9 @@ export class NetworkConnection implements INetworkConnection {
368
368
  return callback;
369
369
  }
370
370
 
371
- public stopListening(key: string | OwnershipEvent, callback: Function | null) {
371
+ /**@deprecated please use stopListen instead (2.65.2-pre) */
372
+ public stopListening(key: string | OwnershipEvent, callback: Function | null) { return this.stopListen(key, callback); }
373
+ public stopListen(key: string | OwnershipEvent, callback: Function | null) {
372
374
  if (!callback) return;
373
375
  if (!this._listeners[key]) return;
374
376
  const index = this._listeners[key].indexOf(callback);
@@ -377,7 +379,7 @@ export class NetworkConnection implements INetworkConnection {
377
379
  }
378
380
  }
379
381
 
380
- public beginListenBinrary(identifier: string, callback: BinaryCallback): BinaryCallback {
382
+ public beginListenBinary(identifier: string, callback: BinaryCallback): BinaryCallback {
381
383
  if (!this._listenersBinary[identifier])
382
384
  this._listenersBinary[identifier] = [];
383
385
  this._listenersBinary[identifier].push(callback);
@@ -4,6 +4,7 @@ import { RoomEvents } from "./engine_networking";
4
4
 
5
5
  const debug = getParam("debugautosync");
6
6
 
7
+ const $syncerId = Symbol("syncerId");
7
8
  class ComponentsSyncerManager {
8
9
  private _syncers: { [key: string]: ComponentPropertiesSyncer } = {};
9
10
 
@@ -11,9 +12,14 @@ class ComponentsSyncerManager {
11
12
  if (!comp.guid) return null;
12
13
  if (this._syncers[comp.guid]) return this._syncers[comp.guid];
13
14
  const syncer = new ComponentPropertiesSyncer(comp);
14
- this._syncers[comp.guid] = syncer;
15
+ syncer[$syncerId] = comp.guid;
16
+ this._syncers[syncer[$syncerId]] = syncer;
15
17
  return syncer;
16
18
  }
19
+
20
+ removeSyncer(syncer: ComponentPropertiesSyncer) {
21
+ delete this._syncers[syncer[$syncerId]];
22
+ }
17
23
  }
18
24
  const syncerHandler = new ComponentsSyncerManager();
19
25
 
@@ -35,6 +41,7 @@ class ComponentPropertiesSyncer {
35
41
  private data = {};
36
42
 
37
43
  private _boundEvent?: Function;
44
+ private _handleReceivingMethod?: Function;
38
45
 
39
46
  get networkingKey(): string {
40
47
  const obj = this.comp as object;
@@ -46,6 +53,7 @@ class ComponentPropertiesSyncer {
46
53
  private _isReceiving: boolean = false;
47
54
  private _isInit = false;
48
55
 
56
+
49
57
  init(comp) {
50
58
  if (this._isInit) return;
51
59
  this._isInit = true;
@@ -53,10 +61,22 @@ class ComponentPropertiesSyncer {
53
61
  // console.log("INIT", this.comp.name, this.networkingKey);
54
62
  this._boundEvent = this.onHandleSending.bind(this);
55
63
  this.comp.context.post_render_callbacks.push(this._boundEvent);
56
- this.comp.context.connection.beginListen(this.networkingKey, this.onHandleReceiving.bind(this));
64
+ this._handleReceivingMethod = this.onHandleReceiving.bind(this);
65
+ this.comp.context.connection.beginListen(this.networkingKey, this._handleReceivingMethod);
57
66
 
58
67
  const state = this.comp.context.connection.tryGetState(this.comp.guid);
59
- if(state) this.onHandleReceiving(state);
68
+ if (state) this.onHandleReceiving(state);
69
+ }
70
+
71
+ destroy() {
72
+ if (!this._isInit) return;
73
+ if (this._boundEvent)
74
+ this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent), 1);
75
+ if (this._handleReceivingMethod)
76
+ this.comp.context.connection.stopListen(this.networkingKey, this._handleReceivingMethod);
77
+ //@ts-ignore
78
+ this.comp = null;
79
+ this._isInit = false;
60
80
  }
61
81
 
62
82
  notifyChanged(propertyName: string, value: any) {
@@ -156,16 +176,26 @@ function testValueChanged(newValue, previousValue): boolean {
156
176
  return valueChanged;
157
177
  }
158
178
 
179
+ const $syncer = Symbol("AutoSyncHandler");
159
180
  function getSyncer(instance): ComponentPropertiesSyncer | null {
160
- if (instance["__autoPropertySyncHandler"]) {
161
- return instance["__autoPropertySyncHandler"];
181
+ if (instance[$syncer]) {
182
+ return instance[$syncer];
162
183
  }
163
184
  const syncer = syncerHandler.getOrCreateSyncer(instance);
164
185
  syncer?.init(instance);
165
- instance["__autoPropertySyncHandler"] = syncer;
186
+ instance[$syncer] = syncer;
166
187
  return syncer;
167
188
  }
168
189
 
190
+ function destroySyncer(instance) {
191
+ const syncer = instance[$syncer];
192
+ if (syncer) {
193
+ syncerHandler.removeSyncer(syncer);
194
+ syncer.destroy();
195
+ delete instance[$syncer];
196
+ }
197
+ }
198
+
169
199
  export declare type SyncFieldOptions = {
170
200
  onPropertyChanged: Function,
171
201
  };
@@ -190,7 +220,7 @@ export const syncField = function (onFieldChanged?: string) {
190
220
  const internalAwake = t.__internalAwake;
191
221
  if (debug)
192
222
  console.log(propertyKey);
193
- const backingFieldName = propertyKey + "k__BackingField";
223
+ const backingFieldName = Symbol(propertyKey);
194
224
 
195
225
  t.__internalAwake = function () {
196
226
  if (this[backingFieldName] !== undefined) {
@@ -221,7 +251,13 @@ export const syncField = function (onFieldChanged?: string) {
221
251
  }
222
252
 
223
253
  syncer?.init(this);
224
-
254
+
255
+ }
256
+
257
+ const internalDestroy = t.__internalDestroy;
258
+ t.__internalDestroy = function () {
259
+ destroySyncer(this);
260
+ internalDestroy.call(this);
225
261
  }
226
262
 
227
263
  }
@@ -233,6 +269,7 @@ export declare type SyncOptions = {
233
269
  fieldName?: string,
234
270
  };
235
271
 
272
+ /** experimental - use syncField instead */
236
273
  export const sync = function (_options?: SyncOptions) {
237
274
 
238
275
  return function <T>(target: any, _propertyKey: string, descriptor: PropertyDescriptor) {
@@ -253,14 +290,14 @@ export const sync = function (_options?: SyncOptions) {
253
290
  // inject getter and setter
254
291
  if (!descriptor.get) {
255
292
  const previousSetter = descriptor.set;
256
- const backingFieldName = _propertyKey + "k__BackingField";
293
+ const $backingField = Symbol(_propertyKey);
257
294
  Object.defineProperty(target, _propertyKey, {
258
295
  set: function (value) {
259
- this[backingFieldName] = value;
296
+ this[$backingField] = value;
260
297
  previousSetter?.call(this, value);
261
298
  },
262
299
  get: function () {
263
- return this[backingFieldName];
300
+ return this[$backingField];
264
301
  }
265
302
  });
266
303
  const newDescriptor = Object.getOwnPropertyDescriptor(target, _propertyKey);
@@ -0,0 +1,113 @@
1
+
2
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn
3
+
4
+ const _wrappedMethods = new WeakSet();
5
+
6
+ export declare type FieldPatch = (instance: object, oldValue: any, newValue: any) => any;
7
+ export type MethodPatch<T> = (instance: T, result: any, ...args) => any;
8
+
9
+ /**
10
+ * Use patcher for patching properties insteadof calling Object.defineProperty individually
11
+ * since this will cause conflicts if multiple patches need to be applied to the same property
12
+ */
13
+ export function addPatch<TType extends object, TCallback extends (FieldPatch | MethodPatch<any>)>(prototype: TType, fieldName: string, cb: TCallback) {
14
+
15
+ // TODO: we probably want to turn this into a symbol to prevent anyone from overriding it
16
+ // But when we need to store the symbol per prototype to allow e.g. material disposing to iterate those and dispose all
17
+ const backingField = fieldName + "__needle";// Symbol(fieldName);// + " (patched)";
18
+
19
+ internalAddPatch(prototype, fieldName, cb);
20
+
21
+ const desc = Object.getOwnPropertyDescriptor(prototype, fieldName);
22
+
23
+ if (desc) {
24
+ // TODO: check if the property is writable
25
+ // the property might be a method in which case we want to wrap it
26
+ if (typeof desc.value === "function") {
27
+ const method = desc.value;
28
+ if (method) {
29
+ if (_wrappedMethods.has(method)) {
30
+ return;
31
+ }
32
+ _wrappedMethods.add(method);
33
+ prototype[fieldName] = function (this: object, ...args: any[]) {
34
+ // call the original method
35
+ const result = method.apply(this, args);
36
+ // call the patches
37
+ const patches = getPatches(prototype, fieldName);
38
+ if (patches) {
39
+ for (const patch of patches) {
40
+ patch(this, result, ...args);
41
+ }
42
+ }
43
+ return result;
44
+ }
45
+ }
46
+ else {
47
+ // TODO: declare method?
48
+ }
49
+ }
50
+ }
51
+ else if (prototype.hasOwnProperty(backingField)) {
52
+ }
53
+ else {
54
+ Object.defineProperty(prototype, fieldName, {
55
+ set: function (this: object, value: any) {
56
+ const prev = this[backingField];
57
+ this[backingField] = value;
58
+ executePatches(prototype, fieldName, this, prev, value);
59
+ },
60
+ get: function (this: any) {
61
+ return this[backingField];
62
+ }
63
+ });
64
+ }
65
+ }
66
+
67
+ export function removePatch(prototype: object, fieldName: string, cb: Function) {
68
+ const patches = getPatches(prototype, fieldName);
69
+ if (patches) {
70
+ for (let i = patches.length - 1; i >= 0; i--) {
71
+ if (patches[i] === cb) {
72
+ patches.splice(i, 1);
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+
79
+
80
+
81
+ const patches = new WeakMap<object, Map<string, Function[]>>();
82
+
83
+ function getPatches(prototype, fieldName: string) {
84
+ let patchesMap = patches.get(prototype);
85
+ if (!patchesMap) {
86
+ return;
87
+ }
88
+ return patchesMap.get(fieldName);;
89
+ }
90
+
91
+ function internalAddPatch(prototype, fieldName: string, cb: Function) {
92
+ let patchesMap = patches.get(prototype);
93
+ if (!patchesMap) {
94
+ patchesMap = new Map();
95
+ patches.set(prototype, patchesMap);
96
+ }
97
+ let patchList = patchesMap.get(fieldName);
98
+ if (!patchList) {
99
+ patchList = [];
100
+ patchesMap.set(fieldName, patchList);
101
+ }
102
+ patchList.push(cb);
103
+ }
104
+
105
+ function executePatches(prototype, fieldName: string, instance: object, oldValue: any, newValue: any) {
106
+ if (!instance) return;
107
+ const patches = getPatches(prototype, fieldName);
108
+ if (patches) {
109
+ for (const patch of patches) {
110
+ patch(instance, oldValue, newValue);
111
+ }
112
+ }
113
+ }