@relu-interactives/spatial-ecs 0.2.2

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 (308) hide show
  1. package/README.md +125 -0
  2. package/dist/System-rXAmagXA.d.cts +659 -0
  3. package/dist/System-rXAmagXA.d.ts +659 -0
  4. package/dist/Video-CDemv74U.d.cts +1261 -0
  5. package/dist/Video-ChKV1UI7.d.ts +1261 -0
  6. package/dist/assets/draco/draco_decoder.js +34 -0
  7. package/dist/assets/draco/draco_decoder.wasm +0 -0
  8. package/dist/assets/draco/draco_wasm_wrapper.js +117 -0
  9. package/dist/chunk-AYEF3X2P.js +223 -0
  10. package/dist/chunk-AYEF3X2P.js.map +1 -0
  11. package/dist/chunk-MAWBTMCG.js +1722 -0
  12. package/dist/chunk-MAWBTMCG.js.map +1 -0
  13. package/dist/chunk-NFDTIYR4.js +248 -0
  14. package/dist/chunk-NFDTIYR4.js.map +1 -0
  15. package/dist/chunk-OY7ZODZP.js +16 -0
  16. package/dist/chunk-OY7ZODZP.js.map +1 -0
  17. package/dist/chunk-P2YDX5DB.js +3304 -0
  18. package/dist/chunk-P2YDX5DB.js.map +1 -0
  19. package/dist/chunk-QHILSPT4.js +3 -0
  20. package/dist/chunk-QHILSPT4.js.map +1 -0
  21. package/dist/chunk-XWIEEJ7Z.js +1315 -0
  22. package/dist/chunk-XWIEEJ7Z.js.map +1 -0
  23. package/dist/components/index.cjs +1745 -0
  24. package/dist/components/index.cjs.map +1 -0
  25. package/dist/components/index.d.cts +4 -0
  26. package/dist/components/index.d.ts +4 -0
  27. package/dist/components/index.js +4 -0
  28. package/dist/components/index.js.map +1 -0
  29. package/dist/docs/api/Behaviour/classes/Behaviour.md +554 -0
  30. package/dist/docs/api/Behaviour/index.md +15 -0
  31. package/dist/docs/api/Component/classes/Component.md +57 -0
  32. package/dist/docs/api/Component/index.md +15 -0
  33. package/dist/docs/api/components/classes/AnimationComponent.md +318 -0
  34. package/dist/docs/api/components/classes/AudioComponent.md +114 -0
  35. package/dist/docs/api/components/classes/CameraComponent.md +59 -0
  36. package/dist/docs/api/components/classes/EntityType.md +48 -0
  37. package/dist/docs/api/components/classes/Environment.md +47 -0
  38. package/dist/docs/api/components/classes/ImageComponent.md +57 -0
  39. package/dist/docs/api/components/classes/ImageTarget.md +60 -0
  40. package/dist/docs/api/components/classes/ImageTargetAnchor.md +48 -0
  41. package/dist/docs/api/components/classes/LightComponent.md +70 -0
  42. package/dist/docs/api/components/classes/MaterialComponent.md +181 -0
  43. package/dist/docs/api/components/classes/MeshComponent.md +48 -0
  44. package/dist/docs/api/components/classes/MeshGeometryComponent.md +64 -0
  45. package/dist/docs/api/components/classes/ModelComponent.md +49 -0
  46. package/dist/docs/api/components/classes/Name.md +46 -0
  47. package/dist/docs/api/components/classes/Object3DRef.md +54 -0
  48. package/dist/docs/api/components/classes/ParentId.md +47 -0
  49. package/dist/docs/api/components/classes/PhysicsComponent.md +82 -0
  50. package/dist/docs/api/components/classes/Postprocessing.md +49 -0
  51. package/dist/docs/api/components/classes/ScriptComponent.md +54 -0
  52. package/dist/docs/api/components/classes/Selectable.md +46 -0
  53. package/dist/docs/api/components/classes/SelectionTransformState.md +54 -0
  54. package/dist/docs/api/components/classes/SpriteComponent.md +55 -0
  55. package/dist/docs/api/components/classes/TransformComponent.md +197 -0
  56. package/dist/docs/api/components/classes/VideoComponent.md +123 -0
  57. package/dist/docs/api/components/functions/normalizePhysicsState.md +23 -0
  58. package/dist/docs/api/components/index.md +94 -0
  59. package/dist/docs/api/components/type-aliases/AnimationComponentOptions.md +42 -0
  60. package/dist/docs/api/components/type-aliases/CameraComponentOptions.md +45 -0
  61. package/dist/docs/api/components/type-aliases/CameraProjection.md +15 -0
  62. package/dist/docs/api/components/type-aliases/CameraRuntimeType.md +15 -0
  63. package/dist/docs/api/components/type-aliases/ColliderShape.md +15 -0
  64. package/dist/docs/api/components/type-aliases/ColliderState.md +62 -0
  65. package/dist/docs/api/components/type-aliases/CubeMeshParameters.md +27 -0
  66. package/dist/docs/api/components/type-aliases/EditableMeshObjectKind.md +15 -0
  67. package/dist/docs/api/components/type-aliases/EnvironmentFogState.md +37 -0
  68. package/dist/docs/api/components/type-aliases/EnvironmentFogType.md +15 -0
  69. package/dist/docs/api/components/type-aliases/EnvironmentGradientEffect.md +15 -0
  70. package/dist/docs/api/components/type-aliases/EnvironmentSkyboxState.md +34 -0
  71. package/dist/docs/api/components/type-aliases/EnvironmentSkyboxType.md +15 -0
  72. package/dist/docs/api/components/type-aliases/EnvironmentState.md +29 -0
  73. package/dist/docs/api/components/type-aliases/ImageTargetAnchorOptions.md +25 -0
  74. package/dist/docs/api/components/type-aliases/ImageTargetReference.md +33 -0
  75. package/dist/docs/api/components/type-aliases/LightValueState.md +41 -0
  76. package/dist/docs/api/components/type-aliases/MaterialTypeValue.md +15 -0
  77. package/dist/docs/api/components/type-aliases/MaterialValueState.md +75 -0
  78. package/dist/docs/api/components/type-aliases/MeshGeometryParameters.md +13 -0
  79. package/dist/docs/api/components/type-aliases/MeshGeometryParametersByKind.md +33 -0
  80. package/dist/docs/api/components/type-aliases/PhysicsState.md +25 -0
  81. package/dist/docs/api/components/type-aliases/PlaneMeshParameters.md +25 -0
  82. package/dist/docs/api/components/type-aliases/PostprocessingState.md +164 -0
  83. package/dist/docs/api/components/type-aliases/RadiusHeightMeshParameters.md +25 -0
  84. package/dist/docs/api/components/type-aliases/RadiusMeshParameters.md +23 -0
  85. package/dist/docs/api/components/type-aliases/RigidbodyState.md +53 -0
  86. package/dist/docs/api/components/type-aliases/RigidbodyType.md +19 -0
  87. package/dist/docs/api/components/type-aliases/ScriptEntry.md +38 -0
  88. package/dist/docs/api/components/type-aliases/TextureFilteringValue.md +15 -0
  89. package/dist/docs/api/components/type-aliases/TransformData.md +27 -0
  90. package/dist/docs/api/components/type-aliases/TransformModeValue.md +15 -0
  91. package/dist/docs/api/components/type-aliases/TransformSpaceValue.md +15 -0
  92. package/dist/docs/api/components/type-aliases/Vec3.md +27 -0
  93. package/dist/docs/api/components/variables/DEFAULT_COLLIDER_STATE.md +13 -0
  94. package/dist/docs/api/components/variables/DEFAULT_ENVIRONMENT_STATE.md +13 -0
  95. package/dist/docs/api/components/variables/DEFAULT_MESH_GEOMETRY_PARAMETERS.md +13 -0
  96. package/dist/docs/api/components/variables/DEFAULT_PHYSICS_STATE.md +13 -0
  97. package/dist/docs/api/components/variables/DEFAULT_POSTPROCESSING_STATE.md +13 -0
  98. package/dist/docs/api/components/variables/DEFAULT_RIGIDBODY_STATE.md +13 -0
  99. package/dist/docs/api/index/classes/AnimationStateMachine.md +201 -0
  100. package/dist/docs/api/index/classes/AnimationStateManager.md +253 -0
  101. package/dist/docs/api/index/classes/AnimationSystem.md +68 -0
  102. package/dist/docs/api/index/classes/AudioSystem.md +98 -0
  103. package/dist/docs/api/index/classes/CameraSyncSystem.md +49 -0
  104. package/dist/docs/api/index/classes/EnvironmentSyncSystem.md +75 -0
  105. package/dist/docs/api/index/classes/InputSystem.md +449 -0
  106. package/dist/docs/api/index/classes/LightSyncSystem.md +49 -0
  107. package/dist/docs/api/index/classes/MaterialSyncSystem.md +67 -0
  108. package/dist/docs/api/index/classes/MeshGeometrySystem.md +49 -0
  109. package/dist/docs/api/index/classes/ObjectManagementSystem.md +298 -0
  110. package/dist/docs/api/index/classes/ObjectVisibilitySystem.md +49 -0
  111. package/dist/docs/api/index/classes/PhysicsSyncSystem.md +83 -0
  112. package/dist/docs/api/index/classes/PostprocessingSyncSystem.md +80 -0
  113. package/dist/docs/api/index/classes/RenderSystem.md +64 -0
  114. package/dist/docs/api/index/classes/ScriptBehaviourSystem.md +83 -0
  115. package/dist/docs/api/index/classes/TransformSyncSystem.md +49 -0
  116. package/dist/docs/api/index/classes/VideoSystem.md +97 -0
  117. package/dist/docs/api/index/classes/World.md +1405 -0
  118. package/dist/docs/api/index/functions/createAnimationComponent.md +28 -0
  119. package/dist/docs/api/index/functions/createAudioComponent.md +32 -0
  120. package/dist/docs/api/index/functions/createCameraComponent.md +28 -0
  121. package/dist/docs/api/index/functions/createEntityTypeComponent.md +28 -0
  122. package/dist/docs/api/index/functions/createEnvironmentComponent.md +28 -0
  123. package/dist/docs/api/index/functions/createImageComponent.md +28 -0
  124. package/dist/docs/api/index/functions/createImageTargetAnchorComponent.md +28 -0
  125. package/dist/docs/api/index/functions/createImageTargetComponent.md +28 -0
  126. package/dist/docs/api/index/functions/createLightComponent.md +28 -0
  127. package/dist/docs/api/index/functions/createMaterialComponent.md +28 -0
  128. package/dist/docs/api/index/functions/createMeshComponent.md +28 -0
  129. package/dist/docs/api/index/functions/createMeshGeometryComponent.md +28 -0
  130. package/dist/docs/api/index/functions/createModelComponent.md +28 -0
  131. package/dist/docs/api/index/functions/createNameComponent.md +28 -0
  132. package/dist/docs/api/index/functions/createObject3DRefComponent.md +28 -0
  133. package/dist/docs/api/index/functions/createParentIdComponent.md +28 -0
  134. package/dist/docs/api/index/functions/createPhysicsComponent.md +30 -0
  135. package/dist/docs/api/index/functions/createPostprocessingComponent.md +28 -0
  136. package/dist/docs/api/index/functions/createScriptComponent.md +28 -0
  137. package/dist/docs/api/index/functions/createSelectableComponent.md +28 -0
  138. package/dist/docs/api/index/functions/createSelectionTransformStateComponent.md +28 -0
  139. package/dist/docs/api/index/functions/createSpriteComponent.md +28 -0
  140. package/dist/docs/api/index/functions/createTransformComponent.md +28 -0
  141. package/dist/docs/api/index/functions/createVideoComponent.md +28 -0
  142. package/dist/docs/api/index/functions/hydrateWorldFromSnapshot.md +28 -0
  143. package/dist/docs/api/index/functions/hydrateWorldFromSnapshotDetailed.md +28 -0
  144. package/dist/docs/api/index/functions/registerDefaultComponentFactories.md +23 -0
  145. package/dist/docs/api/index/functions/registerDefaultFactories.md +23 -0
  146. package/dist/docs/api/index/index.md +249 -0
  147. package/dist/docs/api/index/interfaces/EcsSystem.md +50 -0
  148. package/dist/docs/api/index/interfaces/StateMachine.md +26 -0
  149. package/dist/docs/api/index/type-aliases/AnimationStateCallbacks.md +25 -0
  150. package/dist/docs/api/index/type-aliases/ComponentFactory.md +25 -0
  151. package/dist/docs/api/index/type-aliases/EcsComponentFactoryKind.md +37 -0
  152. package/dist/docs/api/index/type-aliases/EcsWorldComponentSnapshot.md +26 -0
  153. package/dist/docs/api/index/type-aliases/EcsWorldStateSnapshotLike.md +25 -0
  154. package/dist/docs/api/index/type-aliases/HydrateWorldFromSnapshotResult.md +23 -0
  155. package/dist/docs/api/index/type-aliases/KeyboardKey.md +13 -0
  156. package/dist/docs/api/index/type-aliases/MouseButton.md +13 -0
  157. package/dist/docs/api/index/type-aliases/SelectionContext.md +31 -0
  158. package/dist/docs/api/index/variables/HYDRATABLE_ENTITY_KINDS.md +13 -0
  159. package/dist/docs/api/index/variables/KeyboardKeys.md +195 -0
  160. package/dist/docs/api/index.md +15 -0
  161. package/dist/docs/api/typedoc-sidebar.json +1 -0
  162. package/dist/docs/api/types/index.md +34 -0
  163. package/dist/docs/api/types/type-aliases/AssetInput.md +23 -0
  164. package/dist/docs/api/types/type-aliases/CheckboxInput.md +13 -0
  165. package/dist/docs/api/types/type-aliases/ColorInput.md +13 -0
  166. package/dist/docs/api/types/type-aliases/ComponentInput.md +52 -0
  167. package/dist/docs/api/types/type-aliases/ComponentKind.md +37 -0
  168. package/dist/docs/api/types/type-aliases/DropdownInput.md +23 -0
  169. package/dist/docs/api/types/type-aliases/DropdownOption.md +23 -0
  170. package/dist/docs/api/types/type-aliases/EcsEntityEditorKind.md +15 -0
  171. package/dist/docs/api/types/type-aliases/EcsEntityKind.md +35 -0
  172. package/dist/docs/api/types/type-aliases/EntityId.md +16 -0
  173. package/dist/docs/api/types/type-aliases/EntityInput.md +23 -0
  174. package/dist/docs/api/types/type-aliases/FloatInput.md +13 -0
  175. package/dist/docs/api/types/type-aliases/IntersectionResult.md +29 -0
  176. package/dist/docs/api/types/type-aliases/ParentLookup.md +26 -0
  177. package/dist/docs/api/types/type-aliases/SelectionListener.md +25 -0
  178. package/dist/docs/api/types/type-aliases/SliderInput.md +27 -0
  179. package/dist/docs/api/types/type-aliases/TextInput.md +13 -0
  180. package/dist/docs/api/types/type-aliases/ToggleInput.md +13 -0
  181. package/dist/docs/api/types/type-aliases/Vec3.md +23 -0
  182. package/dist/docs/api/types/type-aliases/Vector2Input.md +23 -0
  183. package/dist/docs/api/types/type-aliases/Vector3Input.md +25 -0
  184. package/dist/docs/api/types/type-aliases/WorldEntityView.md +17 -0
  185. package/dist/docs/guide/accessing-components.md +399 -0
  186. package/dist/docs/guide/authoring-a-behaviour.md +166 -0
  187. package/dist/docs/guide/behaviour-lifecycle.md +43 -0
  188. package/dist/docs/guide/component-catalog.md +59 -0
  189. package/dist/docs/guide/components/_sidebar.json +78 -0
  190. package/dist/docs/guide/components/animation.md +171 -0
  191. package/dist/docs/guide/components/audio.md +181 -0
  192. package/dist/docs/guide/components/camera.md +179 -0
  193. package/dist/docs/guide/components/entity-type.md +141 -0
  194. package/dist/docs/guide/components/image-target-anchor.md +103 -0
  195. package/dist/docs/guide/components/image-target.md +122 -0
  196. package/dist/docs/guide/components/image.md +146 -0
  197. package/dist/docs/guide/components/light.md +157 -0
  198. package/dist/docs/guide/components/material.md +161 -0
  199. package/dist/docs/guide/components/mesh-geometry.md +153 -0
  200. package/dist/docs/guide/components/mesh.md +151 -0
  201. package/dist/docs/guide/components/model.md +96 -0
  202. package/dist/docs/guide/components/name.md +121 -0
  203. package/dist/docs/guide/components/object3d-ref.md +115 -0
  204. package/dist/docs/guide/components/parent-id.md +108 -0
  205. package/dist/docs/guide/components/physics.md +163 -0
  206. package/dist/docs/guide/components/script.md +142 -0
  207. package/dist/docs/guide/components/sprite.md +155 -0
  208. package/dist/docs/guide/components/transform.md +155 -0
  209. package/dist/docs/guide/components/video.md +153 -0
  210. package/dist/docs/guide/concepts.md +34 -0
  211. package/dist/docs/guide/getting-started/creating-objects.md +50 -0
  212. package/dist/docs/guide/getting-started/editing-objects.md +62 -0
  213. package/dist/docs/guide/getting-started/editor/assets-browser.md +55 -0
  214. package/dist/docs/guide/getting-started/editor/hierarchy.md +47 -0
  215. package/dist/docs/guide/getting-started/editor/index.md +16 -0
  216. package/dist/docs/guide/getting-started/editor/inspector.md +36 -0
  217. package/dist/docs/guide/getting-started/editor/modules.md +35 -0
  218. package/dist/docs/guide/getting-started/editor/scene-inspector.md +64 -0
  219. package/dist/docs/guide/getting-started/editor/toolbar.md +39 -0
  220. package/dist/docs/guide/getting-started/editor/viewport.md +43 -0
  221. package/dist/docs/guide/getting-started/first-launch.md +17 -0
  222. package/dist/docs/guide/getting-started/index.md +37 -0
  223. package/dist/docs/guide/getting-started/installation.md +59 -0
  224. package/dist/docs/guide/getting-started/preview-and-test.md +55 -0
  225. package/dist/docs/guide/getting-started/project-types/3d.md +30 -0
  226. package/dist/docs/guide/getting-started/project-types/ar.md +6 -0
  227. package/dist/docs/guide/getting-started/project-types/face-tracking.md +6 -0
  228. package/dist/docs/guide/getting-started/project-types/image-tracking.md +42 -0
  229. package/dist/docs/guide/getting-started/project-types/index.md +25 -0
  230. package/dist/docs/guide/getting-started/project-types/vr.md +6 -0
  231. package/dist/docs/guide/getting-started/projects.md +53 -0
  232. package/dist/docs/guide/getting-started/shortcuts.md +43 -0
  233. package/dist/docs/guide/inspector-data-binding.md +367 -0
  234. package/dist/docs/guide/reading-input.md +202 -0
  235. package/dist/docs/guide/scene/environment.md +101 -0
  236. package/dist/docs/guide/scene/index.md +36 -0
  237. package/dist/docs/guide/scene/postprocessing.md +108 -0
  238. package/dist/docs/guide/spawning/ambient-light.md +28 -0
  239. package/dist/docs/guide/spawning/area-light.md +32 -0
  240. package/dist/docs/guide/spawning/audio.md +42 -0
  241. package/dist/docs/guide/spawning/camera.md +50 -0
  242. package/dist/docs/guide/spawning/capsule.md +29 -0
  243. package/dist/docs/guide/spawning/cube.md +31 -0
  244. package/dist/docs/guide/spawning/cylinder.md +29 -0
  245. package/dist/docs/guide/spawning/directional-light.md +32 -0
  246. package/dist/docs/guide/spawning/empty.md +31 -0
  247. package/dist/docs/guide/spawning/image-target.md +48 -0
  248. package/dist/docs/guide/spawning/image.md +33 -0
  249. package/dist/docs/guide/spawning/index.md +79 -0
  250. package/dist/docs/guide/spawning/model.md +31 -0
  251. package/dist/docs/guide/spawning/plane.md +31 -0
  252. package/dist/docs/guide/spawning/point-light.md +32 -0
  253. package/dist/docs/guide/spawning/sphere.md +29 -0
  254. package/dist/docs/guide/spawning/spot-light.md +32 -0
  255. package/dist/docs/guide/spawning/sprite.md +31 -0
  256. package/dist/docs/guide/spawning/video.md +53 -0
  257. package/dist/docs/guide/system-overview.md +73 -0
  258. package/dist/docs/guide/systems/_sidebar.json +66 -0
  259. package/dist/docs/guide/systems/animation-system.md +32 -0
  260. package/dist/docs/guide/systems/audio-system.md +28 -0
  261. package/dist/docs/guide/systems/camera-sync-system.md +31 -0
  262. package/dist/docs/guide/systems/environment-sync-system.md +31 -0
  263. package/dist/docs/guide/systems/input-system.md +217 -0
  264. package/dist/docs/guide/systems/light-sync-system.md +29 -0
  265. package/dist/docs/guide/systems/material-sync-system.md +32 -0
  266. package/dist/docs/guide/systems/mesh-geometry-system.md +40 -0
  267. package/dist/docs/guide/systems/object-management-system.md +38 -0
  268. package/dist/docs/guide/systems/object-visibility-system.md +26 -0
  269. package/dist/docs/guide/systems/physics-sync-system.md +56 -0
  270. package/dist/docs/guide/systems/postprocessing-sync-system.md +43 -0
  271. package/dist/docs/guide/systems/render-system.md +22 -0
  272. package/dist/docs/guide/systems/script-behaviour-system.md +59 -0
  273. package/dist/docs/guide/systems/transform-sync-system.md +29 -0
  274. package/dist/docs/guide/systems/video-system.md +30 -0
  275. package/dist/docs/guide/world-api.md +405 -0
  276. package/dist/factories/index.cjs +3077 -0
  277. package/dist/factories/index.cjs.map +1 -0
  278. package/dist/factories/index.d.cts +69 -0
  279. package/dist/factories/index.d.ts +69 -0
  280. package/dist/factories/index.js +6 -0
  281. package/dist/factories/index.js.map +1 -0
  282. package/dist/index-B4-YyUNR.d.cts +73 -0
  283. package/dist/index-BZUOKeTO.d.ts +73 -0
  284. package/dist/index.cjs +8584 -0
  285. package/dist/index.cjs.map +1 -0
  286. package/dist/index.d.cts +283 -0
  287. package/dist/index.d.ts +283 -0
  288. package/dist/index.js +1729 -0
  289. package/dist/index.js.map +1 -0
  290. package/dist/systems/index.cjs +5119 -0
  291. package/dist/systems/index.cjs.map +1 -0
  292. package/dist/systems/index.d.cts +200 -0
  293. package/dist/systems/index.d.ts +200 -0
  294. package/dist/systems/index.js +6 -0
  295. package/dist/systems/index.js.map +1 -0
  296. package/dist/types.cjs +4 -0
  297. package/dist/types.cjs.map +1 -0
  298. package/dist/types.d.cts +3 -0
  299. package/dist/types.d.ts +3 -0
  300. package/dist/types.js +3 -0
  301. package/dist/types.js.map +1 -0
  302. package/dist/worldSnapshotUtils.cjs +259 -0
  303. package/dist/worldSnapshotUtils.cjs.map +1 -0
  304. package/dist/worldSnapshotUtils.d.cts +3 -0
  305. package/dist/worldSnapshotUtils.d.ts +3 -0
  306. package/dist/worldSnapshotUtils.js +4 -0
  307. package/dist/worldSnapshotUtils.js.map +1 -0
  308. package/package.json +80 -0
package/dist/index.js ADDED
@@ -0,0 +1,1729 @@
1
+ import { MeshGeometrySystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem } from './chunk-P2YDX5DB.js';
2
+ export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, InputSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem } from './chunk-P2YDX5DB.js';
3
+ import { registerDefaultFactories } from './chunk-XWIEEJ7Z.js';
4
+ export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVideoComponent, registerDefaultComponentFactories, registerDefaultFactories } from './chunk-XWIEEJ7Z.js';
5
+ import { ObjectManagementSystem, applyTransform } from './chunk-AYEF3X2P.js';
6
+ export { ObjectManagementSystem } from './chunk-AYEF3X2P.js';
7
+ import { SelectionTransformState, Object3DRef, Name, EntityType, ScriptComponent, AnimationComponent, TransformComponent, ModelComponent, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, CameraComponent, Environment, Postprocessing, ImageTarget, LightComponent, MaterialComponent, MeshGeometryComponent, Selectable, PhysicsComponent } from './chunk-MAWBTMCG.js';
8
+ export { AnimationStateMachine, AnimationStateManager, components_exports as CoreComponents } from './chunk-MAWBTMCG.js';
9
+ import './chunk-QHILSPT4.js';
10
+ import { normalizeDebugValue, DEBUG_CHANGE_IGNORED_SYSTEMS, cloneHistoryValue } from './chunk-NFDTIYR4.js';
11
+ import { __name } from './chunk-OY7ZODZP.js';
12
+ export { Component } from './chunk-OY7ZODZP.js';
13
+ import * as THREE from 'three';
14
+
15
+ var _World = class _World {
16
+ constructor(options) {
17
+ this.nextEntityId = 1;
18
+ this.entities = /* @__PURE__ */ new Set();
19
+ this.systems = [];
20
+ this.selectionListeners = /* @__PURE__ */ new Set();
21
+ this.storeListeners = /* @__PURE__ */ new Set();
22
+ this.components = /* @__PURE__ */ new Map();
23
+ this.inputSystem = null;
24
+ this.rapierModule = null;
25
+ this.rapierModulePromise = null;
26
+ this.physicsWorld = null;
27
+ this.isEditor = false;
28
+ this.paused = false;
29
+ this.scene = options.scene;
30
+ this.camera = options.camera;
31
+ this.renderer = options.renderer;
32
+ this.featureFlags = {
33
+ supportSkybox: options.featureFlags?.supportSkybox ?? true,
34
+ supportPostprocessing: options.featureFlags?.supportPostprocessing ?? true
35
+ };
36
+ this.renderer.shadowMap.enabled = true;
37
+ }
38
+ createEntity() {
39
+ const entityId = this.nextEntityId;
40
+ this.nextEntityId += 1;
41
+ this.entities.add(entityId);
42
+ this.emitStoreChanged();
43
+ return entityId;
44
+ }
45
+ destroyEntity(entityId) {
46
+ if (!this.entities.has(entityId)) {
47
+ return;
48
+ }
49
+ this.entities.delete(entityId);
50
+ for (const store of this.components.values()) {
51
+ store.delete(entityId);
52
+ }
53
+ if (this.getSelectedEntity() === entityId) {
54
+ this.setSelectedEntity(null);
55
+ }
56
+ this.emitStoreChanged();
57
+ }
58
+ getSelectionState() {
59
+ const entityId = this.query(SelectionTransformState)[0];
60
+ if (entityId === void 0) {
61
+ return void 0;
62
+ }
63
+ return this.getComponent(entityId, SelectionTransformState);
64
+ }
65
+ hasEntity(entityId) {
66
+ return this.entities.has(entityId);
67
+ }
68
+ getEntities() {
69
+ return [...this.entities];
70
+ }
71
+ getEntityCount() {
72
+ return this.entities.size;
73
+ }
74
+ addComponent(entityId, component) {
75
+ if (!this.entities.has(entityId)) {
76
+ throw new Error(`Cannot add component to missing entity ${entityId}`);
77
+ }
78
+ const componentType = component.constructor;
79
+ if (!this.components.has(componentType)) {
80
+ this.components.set(componentType, /* @__PURE__ */ new Map());
81
+ }
82
+ this.components.get(componentType)?.set(entityId, component);
83
+ this.emitStoreChanged();
84
+ }
85
+ addComponents(entityId, components) {
86
+ if (!this.entities.has(entityId)) {
87
+ throw new Error(`Cannot add component to missing entity ${entityId}`);
88
+ }
89
+ for (const component of components) {
90
+ const componentType = component.constructor;
91
+ if (!this.components.has(componentType)) {
92
+ this.components.set(componentType, /* @__PURE__ */ new Map());
93
+ }
94
+ this.components.get(componentType)?.set(entityId, component);
95
+ }
96
+ this.emitStoreChanged();
97
+ }
98
+ removeComponent(entityId, componentType) {
99
+ this.components.get(componentType)?.delete(entityId);
100
+ this.emitStoreChanged();
101
+ }
102
+ getComponent(entityId, componentType) {
103
+ return this.components.get(componentType)?.get(entityId);
104
+ }
105
+ hasComponent(entityId, componentType) {
106
+ return this.components.get(componentType)?.has(entityId) ?? false;
107
+ }
108
+ query(...componentTypes) {
109
+ return [...this.entities].filter(
110
+ (entityId) => componentTypes.every(
111
+ (componentType) => this.components.get(componentType)?.has(entityId)
112
+ )
113
+ );
114
+ }
115
+ /**
116
+ * Returns `true` if the entity is currently visible (its `Object3DRef.visibility`
117
+ * is `true`), or if the entity has no `Object3DRef` component (entities without a
118
+ * scene object are always considered active). Systems use this to skip per-entity
119
+ * updates for hidden objects.
120
+ */
121
+ isEntityVisible(entityId) {
122
+ const objectRef = this.getComponent(entityId, Object3DRef);
123
+ return objectRef ? objectRef.visibility : true;
124
+ }
125
+ getInputSystem() {
126
+ if (this.inputSystem !== null) return this.inputSystem;
127
+ const inputSystem = this.systems.find(
128
+ (system) => system.constructor.name === "InputSystem"
129
+ );
130
+ this.inputSystem = inputSystem;
131
+ return inputSystem ?? null;
132
+ }
133
+ getKeyDown(key) {
134
+ const inputSystem = this.getInputSystem();
135
+ if (!inputSystem) {
136
+ return false;
137
+ }
138
+ return inputSystem.getKeyDown(key);
139
+ }
140
+ getKeyUp(key) {
141
+ const inputSystem = this.getInputSystem();
142
+ if (!inputSystem) {
143
+ return false;
144
+ }
145
+ return inputSystem.getKeyUp(key);
146
+ }
147
+ getKey(key) {
148
+ const inputSystem = this.getInputSystem();
149
+ if (!inputSystem) {
150
+ return false;
151
+ }
152
+ return inputSystem.getKey(key);
153
+ }
154
+ getMouse(button) {
155
+ const inputSystem = this.getInputSystem();
156
+ if (!inputSystem) {
157
+ return false;
158
+ }
159
+ return inputSystem.getMouse(button);
160
+ }
161
+ getMouseDown(button) {
162
+ const inputSystem = this.getInputSystem();
163
+ if (!inputSystem) {
164
+ return false;
165
+ }
166
+ return inputSystem.getMouseDown(button);
167
+ }
168
+ getMouseUp(button) {
169
+ const inputSystem = this.getInputSystem();
170
+ if (!inputSystem) {
171
+ return false;
172
+ }
173
+ return inputSystem.getMouseUp(button);
174
+ }
175
+ getScrollClick() {
176
+ const inputSystem = this.getInputSystem();
177
+ if (!inputSystem) {
178
+ return false;
179
+ }
180
+ return inputSystem.getScrollClick();
181
+ }
182
+ getScrollClickDown() {
183
+ const inputSystem = this.getInputSystem();
184
+ if (!inputSystem) {
185
+ return false;
186
+ }
187
+ return inputSystem.getScrollClickDown();
188
+ }
189
+ getScrollClickUp() {
190
+ const inputSystem = this.getInputSystem();
191
+ if (!inputSystem) {
192
+ return false;
193
+ }
194
+ return inputSystem.getScrollClickUp();
195
+ }
196
+ getScrollDelta() {
197
+ const inputSystem = this.getInputSystem();
198
+ if (!inputSystem) {
199
+ return { x: 0, y: 0 };
200
+ }
201
+ return inputSystem.getScrollDelta();
202
+ }
203
+ consumeScrollDelta() {
204
+ const inputSystem = this.getInputSystem();
205
+ if (!inputSystem) {
206
+ return { x: 0, y: 0 };
207
+ }
208
+ return inputSystem.consumeScrollDelta();
209
+ }
210
+ getMousePosition() {
211
+ const inputSystem = this.getInputSystem();
212
+ if (!inputSystem) {
213
+ return { x: 0, y: 0 };
214
+ }
215
+ return inputSystem.getMousePosition();
216
+ }
217
+ getMouseDelta() {
218
+ const inputSystem = this.getInputSystem();
219
+ if (!inputSystem) {
220
+ return { x: 0, y: 0 };
221
+ }
222
+ return inputSystem.getMouseDelta();
223
+ }
224
+ consumeMouseDelta() {
225
+ const inputSystem = this.getInputSystem();
226
+ if (!inputSystem) {
227
+ return { x: 0, y: 0 };
228
+ }
229
+ return inputSystem.consumeMouseDelta();
230
+ }
231
+ async getRapierModule() {
232
+ if (this.rapierModule) {
233
+ return this.rapierModule;
234
+ }
235
+ if (!this.rapierModulePromise) {
236
+ this.rapierModulePromise = import('@dimforge/rapier3d-compat').then(
237
+ async (moduleValue) => {
238
+ await moduleValue.init();
239
+ this.rapierModule = moduleValue;
240
+ return moduleValue;
241
+ }
242
+ );
243
+ }
244
+ return this.rapierModulePromise;
245
+ }
246
+ getPhysicsWorld() {
247
+ return this.physicsWorld;
248
+ }
249
+ setPhysicsWorld(physicsWorld) {
250
+ this.physicsWorld = physicsWorld;
251
+ }
252
+ async createPhysicsWorld(options) {
253
+ if (this.physicsWorld) {
254
+ return this.physicsWorld;
255
+ }
256
+ const RAPIER = await this.getRapierModule();
257
+ const gravity = options?.gravity;
258
+ const gravityVector = new RAPIER.Vector3(
259
+ typeof gravity?.x === "number" ? gravity.x : 0,
260
+ typeof gravity?.y === "number" ? gravity.y : -9.81,
261
+ typeof gravity?.z === "number" ? gravity.z : 0
262
+ );
263
+ this.physicsWorld = new RAPIER.World(gravityVector);
264
+ return this.physicsWorld;
265
+ }
266
+ lockMousePointer() {
267
+ const inputSystem = this.getInputSystem();
268
+ if (inputSystem) {
269
+ inputSystem.setPointerLockElement(
270
+ this.renderer.domElement
271
+ );
272
+ return inputSystem.lockMousePointer();
273
+ }
274
+ if (typeof document === "undefined") {
275
+ return false;
276
+ }
277
+ if (typeof this.renderer.domElement.requestPointerLock !== "function") {
278
+ return false;
279
+ }
280
+ try {
281
+ const result = this.renderer.domElement.requestPointerLock();
282
+ if (result instanceof Promise) {
283
+ result.catch(() => {
284
+ });
285
+ }
286
+ return true;
287
+ } catch {
288
+ return false;
289
+ }
290
+ }
291
+ unlockMousePointer() {
292
+ const inputSystem = this.getInputSystem();
293
+ if (inputSystem) {
294
+ return inputSystem.unlockMousePointer();
295
+ }
296
+ if (typeof document === "undefined") {
297
+ return false;
298
+ }
299
+ if (!document.pointerLockElement || typeof document.exitPointerLock !== "function") {
300
+ return false;
301
+ }
302
+ document.exitPointerLock();
303
+ return true;
304
+ }
305
+ isMousePointerLocked() {
306
+ const inputSystem = this.getInputSystem();
307
+ if (inputSystem) {
308
+ inputSystem.setPointerLockElement(
309
+ this.renderer.domElement
310
+ );
311
+ return inputSystem.isMousePointerLocked();
312
+ }
313
+ if (typeof document === "undefined") {
314
+ return false;
315
+ }
316
+ return document.pointerLockElement === this.renderer.domElement;
317
+ }
318
+ getSystem(system) {
319
+ const resolvedSystem = this.systems.find((candidate) => {
320
+ return candidate === system || candidate.constructor === system.constructor;
321
+ });
322
+ if (!resolvedSystem) {
323
+ const systemName = system.constructor?.name || "AnonymousSystem";
324
+ throw new Error(
325
+ `System '${systemName}' is not registered in this world.`
326
+ );
327
+ }
328
+ return resolvedSystem;
329
+ }
330
+ hasSystem(system) {
331
+ return this.systems.includes(system) || this.systems.some(
332
+ (candidate) => candidate.constructor === system.constructor
333
+ );
334
+ }
335
+ addSystem(system) {
336
+ this.systems.push(system);
337
+ }
338
+ addSystems(systems) {
339
+ for (const system of systems) {
340
+ this.addSystem(system);
341
+ }
342
+ }
343
+ setup({ systems, isEditor }) {
344
+ const objectManagementSystem = new ObjectManagementSystem(
345
+ this.scene,
346
+ this.camera,
347
+ isEditor ?? false
348
+ );
349
+ const meshGeometrySystem = new MeshGeometrySystem();
350
+ const environmentSyncSystem = this.featureFlags.supportSkybox ? new EnvironmentSyncSystem(this.scene) : null;
351
+ const postprocessingSyncSystem = this.featureFlags.supportPostprocessing ? new PostprocessingSyncSystem(this.renderer, this.scene, this.camera) : null;
352
+ const lightSyncSystem = new LightSyncSystem();
353
+ const materialSyncSystem = new MaterialSyncSystem();
354
+ const physicsSyncSystem = new PhysicsSyncSystem({
355
+ isEditor: isEditor ?? false
356
+ });
357
+ const animationSystem = new AnimationSystem();
358
+ const audioSystem = new AudioSystem({ isEditor: isEditor ?? false });
359
+ const videoSystem = new VideoSystem({ isEditor: isEditor ?? false });
360
+ const cameraSyncSystem = new CameraSyncSystem();
361
+ const transformSyncSystem = new TransformSyncSystem();
362
+ const objectVisibilitySystem = new ObjectVisibilitySystem();
363
+ const renderSystem = new RenderSystem(
364
+ this.renderer,
365
+ this.scene,
366
+ this.camera
367
+ );
368
+ registerDefaultFactories(objectManagementSystem);
369
+ this.inputSystem = null;
370
+ const coreSystems = [
371
+ objectManagementSystem,
372
+ meshGeometrySystem
373
+ ];
374
+ if (environmentSyncSystem) {
375
+ coreSystems.push(environmentSyncSystem);
376
+ }
377
+ if (postprocessingSyncSystem) {
378
+ coreSystems.push(postprocessingSyncSystem);
379
+ }
380
+ this.addSystems([
381
+ ...coreSystems,
382
+ physicsSyncSystem,
383
+ ...systems,
384
+ objectVisibilitySystem,
385
+ lightSyncSystem,
386
+ materialSyncSystem,
387
+ animationSystem,
388
+ audioSystem,
389
+ videoSystem,
390
+ cameraSyncSystem,
391
+ transformSyncSystem,
392
+ renderSystem
393
+ ]);
394
+ const inputSystem = this.getInputSystem();
395
+ if (inputSystem) {
396
+ inputSystem.setPointerLockElement(
397
+ this.renderer.domElement
398
+ );
399
+ }
400
+ this.isEditor = isEditor ?? false;
401
+ return {
402
+ objectManagementSystem,
403
+ transformSyncSystem,
404
+ renderSystem
405
+ };
406
+ }
407
+ isEditorMode() {
408
+ return this.isEditor;
409
+ }
410
+ /**
411
+ * Pauses world simulation. While paused, `update()` skips all system ticks so
412
+ * physics, animation, scripts, and rendering stop advancing. The last rendered
413
+ * frame remains frozen on-screen.
414
+ *
415
+ * Call {@link resume} to continue.
416
+ */
417
+ pause() {
418
+ this.paused = true;
419
+ }
420
+ /**
421
+ * Resumes world simulation after a previous {@link pause} call.
422
+ * Has no effect if the world is not paused.
423
+ */
424
+ resume() {
425
+ this.paused = false;
426
+ }
427
+ /**
428
+ * Returns `true` if the world is currently paused.
429
+ *
430
+ * @example
431
+ * ```ts
432
+ * if (this.world.isPaused()) {
433
+ * this.world.resume();
434
+ * }
435
+ * ```
436
+ */
437
+ isPaused() {
438
+ return this.paused;
439
+ }
440
+ getScene() {
441
+ return this.scene;
442
+ }
443
+ getCamera() {
444
+ return this.camera;
445
+ }
446
+ getRenderer() {
447
+ return this.renderer;
448
+ }
449
+ update(deltaTime) {
450
+ if (this.paused) return;
451
+ for (const system of this.systems) {
452
+ system.update(this, deltaTime);
453
+ }
454
+ }
455
+ dispose() {
456
+ for (const system of this.systems) {
457
+ system.dispose?.(this);
458
+ }
459
+ this.selectionListeners.clear();
460
+ this.storeListeners.clear();
461
+ this.physicsWorld = null;
462
+ this.systems = [];
463
+ this.paused = false;
464
+ }
465
+ setSelectedEntity(entityId) {
466
+ const state = this.getSelectionState();
467
+ if (!state) {
468
+ return;
469
+ }
470
+ const nextEntityId = entityId !== null && this.entities.has(entityId) ? entityId : null;
471
+ if (state.selectedEntityId === nextEntityId) {
472
+ return;
473
+ }
474
+ state.selectedEntityId = nextEntityId;
475
+ for (const listener of this.selectionListeners) {
476
+ listener(nextEntityId);
477
+ }
478
+ this.emitStoreChanged();
479
+ }
480
+ getSelectedEntity() {
481
+ return this.getSelectionState()?.selectedEntityId ?? null;
482
+ }
483
+ getEntityComponents(entityId) {
484
+ const components = [];
485
+ for (const store of this.components.values()) {
486
+ const component = store.get(entityId);
487
+ if (component) {
488
+ components.push(component);
489
+ }
490
+ }
491
+ return components;
492
+ }
493
+ getEntityName(entityId) {
494
+ const nameComponent = this.getComponent(entityId, Name);
495
+ const name = nameComponent?.value?.trim();
496
+ if (name) {
497
+ return name;
498
+ }
499
+ return `Entity ${entityId}`;
500
+ }
501
+ getEntityType(entityId) {
502
+ const typeComponent = this.getComponent(entityId, EntityType);
503
+ const type = typeComponent?.value?.trim();
504
+ if (type) {
505
+ return type;
506
+ }
507
+ return `EntityType ${entityId}`;
508
+ }
509
+ getObject3d(entityId) {
510
+ const object3DRefComponent = this.getComponent(entityId, Object3DRef);
511
+ const object = object3DRefComponent?.object;
512
+ if (object) {
513
+ return object;
514
+ }
515
+ return null;
516
+ }
517
+ toEntityView(entityId) {
518
+ return {
519
+ entityId,
520
+ name: this.getEntityName(entityId),
521
+ object: this.getObject3d(entityId),
522
+ type: this.getEntityType(entityId),
523
+ components: this.getEntityComponents(entityId)
524
+ };
525
+ }
526
+ getEntitiesByComponent(component) {
527
+ const componentType = component.constructor;
528
+ const entityStore = this.components.get(componentType);
529
+ if (!entityStore) {
530
+ return [];
531
+ }
532
+ return [...entityStore.keys()].filter((entityId) => this.entities.has(entityId)).sort((a, b) => a - b).map((entityId) => this.toEntityView(entityId));
533
+ }
534
+ getEntitiesByName(name) {
535
+ const searchName = name.trim();
536
+ if (!searchName) {
537
+ return [];
538
+ }
539
+ return this.getAllEntities().filter((entity) => entity.name === searchName);
540
+ }
541
+ getEntityByName(name) {
542
+ const [entity] = this.getEntitiesByName(name);
543
+ return entity ?? null;
544
+ }
545
+ getEntityById(entityId) {
546
+ if (!this.entities.has(entityId)) {
547
+ return null;
548
+ }
549
+ return this.toEntityView(entityId);
550
+ }
551
+ /**
552
+ * Cast a ray from `origin` along `direction` and return every intersected
553
+ * entity-bound mesh, sorted by distance. Each result is a standard
554
+ * `THREE.Intersection` augmented with the owning `entityId` (or `null` if
555
+ * the hit object is not part of any tracked entity).
556
+ *
557
+ * @param origin - World-space origin of the ray (`THREE.Vector3` or
558
+ * `{ x, y, z }`).
559
+ * @param direction - World-space direction of the ray. Will be normalized
560
+ * internally; magnitude is ignored.
561
+ * @param near - Minimum hit distance from the origin. Defaults to `0`.
562
+ * @param far - Maximum hit distance from the origin. Defaults to `Infinity`.
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * const hits = world.raycast(
567
+ * { x: 0, y: 1, z: 0 },
568
+ * { x: 0, y: 0, z: -1 },
569
+ * );
570
+ * if (hits[0]?.entityId !== null) {
571
+ * console.log("hit entity", hits[0].entityId, "at", hits[0].point);
572
+ * }
573
+ * ```
574
+ */
575
+ raycast(origin, direction, near = 0, far = Infinity) {
576
+ const rayOrigin = new THREE.Vector3(origin.x, origin.y, origin.z);
577
+ const rayDirection = new THREE.Vector3(
578
+ direction.x,
579
+ direction.y,
580
+ direction.z
581
+ );
582
+ if (rayDirection.lengthSq() === 0) {
583
+ return [];
584
+ }
585
+ rayDirection.normalize();
586
+ const raycaster = new THREE.Raycaster(rayOrigin, rayDirection, near, far);
587
+ const intersections = raycaster.intersectObjects(
588
+ this.scene.children,
589
+ true
590
+ );
591
+ const objectToEntity = this.buildObjectToEntityMap();
592
+ return intersections.map(
593
+ (intersection) => this.toIntersectionResult(intersection, objectToEntity)
594
+ );
595
+ }
596
+ /**
597
+ * Cast a ray from an entity's world-space position along its forward
598
+ * direction (the +Z axis of its world matrix). Returns intersected
599
+ * entity-bound meshes sorted by distance, with the source entity itself
600
+ * filtered out so the ray does not hit the caster.
601
+ *
602
+ * @param entityId - Entity to cast the ray from. Must have an `Object3DRef`.
603
+ * @param near - Minimum hit distance from the origin. Defaults to `0`.
604
+ * @param far - Maximum hit distance from the origin. Defaults to `Infinity`.
605
+ *
606
+ * @example
607
+ * ```ts
608
+ * const hits = world.raycastFrom(this.entityId, 0, 50);
609
+ * const closest = hits[0];
610
+ * if (closest && closest.entityId !== null) {
611
+ * console.log("looking at", closest.entityId);
612
+ * }
613
+ * ```
614
+ */
615
+ raycastFrom(entityId, near = 0, far = Infinity) {
616
+ const sourceObject = this.getObject3d(entityId);
617
+ if (!sourceObject) {
618
+ return [];
619
+ }
620
+ const rayOrigin = new THREE.Vector3();
621
+ const rayDirection = new THREE.Vector3();
622
+ sourceObject.getWorldPosition(rayOrigin);
623
+ sourceObject.getWorldDirection(rayDirection);
624
+ if (rayDirection.lengthSq() === 0) {
625
+ return [];
626
+ }
627
+ const raycaster = new THREE.Raycaster(rayOrigin, rayDirection, near, far);
628
+ const intersections = raycaster.intersectObjects(
629
+ this.scene.children,
630
+ true
631
+ );
632
+ const objectToEntity = this.buildObjectToEntityMap();
633
+ return intersections.map(
634
+ (intersection) => this.toIntersectionResult(intersection, objectToEntity)
635
+ ).filter((result) => result.entityId !== entityId);
636
+ }
637
+ buildObjectToEntityMap() {
638
+ const map = /* @__PURE__ */ new Map();
639
+ const store = this.components.get(
640
+ Object3DRef
641
+ );
642
+ if (!store) {
643
+ return map;
644
+ }
645
+ for (const [entityId, component] of store) {
646
+ const object = component.object;
647
+ if (object) {
648
+ map.set(object, entityId);
649
+ }
650
+ }
651
+ return map;
652
+ }
653
+ resolveEntityForObject(object, objectToEntity) {
654
+ let current = object;
655
+ while (current) {
656
+ const entityId = objectToEntity.get(current);
657
+ if (entityId !== void 0) {
658
+ return entityId;
659
+ }
660
+ current = current.parent;
661
+ }
662
+ return null;
663
+ }
664
+ toIntersectionResult(intersection, objectToEntity) {
665
+ return {
666
+ entityId: this.resolveEntityForObject(
667
+ intersection.object,
668
+ objectToEntity
669
+ ),
670
+ threeResult: intersection
671
+ };
672
+ }
673
+ getEntityScript(entityId) {
674
+ if (!this.entities.has(entityId)) {
675
+ return null;
676
+ }
677
+ const scriptComponent = this.getComponent(entityId, ScriptComponent);
678
+ if (!scriptComponent || scriptComponent.scriptInstance === null) {
679
+ return null;
680
+ }
681
+ return scriptComponent.scriptInstance;
682
+ }
683
+ getScripts(className) {
684
+ const normalizedClassName = className.trim();
685
+ if (!normalizedClassName) {
686
+ return [];
687
+ }
688
+ const scriptEntityIds = this.query(ScriptComponent);
689
+ const instances = [];
690
+ for (const entityId of scriptEntityIds) {
691
+ const scriptComponent = this.getComponent(entityId, ScriptComponent);
692
+ if (!scriptComponent) {
693
+ continue;
694
+ }
695
+ const hasClassMatch = Array.isArray(scriptComponent.entries) ? scriptComponent.entries.some((entry) => {
696
+ if (!entry || typeof entry !== "object") {
697
+ return false;
698
+ }
699
+ const classNameValue = entry.className;
700
+ return typeof classNameValue === "string" && classNameValue === normalizedClassName;
701
+ }) : false;
702
+ if (!hasClassMatch) {
703
+ continue;
704
+ }
705
+ if (scriptComponent.scriptInstance !== null) {
706
+ instances.push(scriptComponent.scriptInstance);
707
+ }
708
+ }
709
+ return instances;
710
+ }
711
+ getScript(className) {
712
+ const [instance] = this.getScripts(className);
713
+ return instance ?? null;
714
+ }
715
+ getAllEntities() {
716
+ return [...this.entities].sort((a, b) => a - b).map((entityId) => this.toEntityView(entityId));
717
+ }
718
+ onSelectionChanged(listener) {
719
+ this.selectionListeners.add(listener);
720
+ return () => {
721
+ this.selectionListeners.delete(listener);
722
+ };
723
+ }
724
+ subscribe(listener) {
725
+ this.storeListeners.add(listener);
726
+ return () => {
727
+ this.storeListeners.delete(listener);
728
+ };
729
+ }
730
+ getDebugSnapshot(maxDepth = 3) {
731
+ const components = [...this.components.entries()].map(([componentClass, store]) => {
732
+ return {
733
+ component: componentClass.name,
734
+ entries: [...store.entries()].map(([entityId, component]) => {
735
+ return {
736
+ entityId,
737
+ value: normalizeDebugValue(component, {
738
+ seen: /* @__PURE__ */ new WeakSet(),
739
+ depth: 0,
740
+ maxDepth
741
+ })
742
+ };
743
+ }).sort((a, b) => a.entityId - b.entityId)
744
+ };
745
+ }).sort((a, b) => a.component.localeCompare(b.component));
746
+ const systems = this.systems.map((system) => {
747
+ const systemName = system.constructor?.name || "AnonymousSystem";
748
+ return {
749
+ system,
750
+ systemName
751
+ };
752
+ }).filter(({ systemName }) => !DEBUG_CHANGE_IGNORED_SYSTEMS.has(systemName)).map(({ system, systemName }) => {
753
+ return {
754
+ system: systemName,
755
+ state: normalizeDebugValue(system, {
756
+ seen: /* @__PURE__ */ new WeakSet(),
757
+ depth: 0,
758
+ maxDepth
759
+ })
760
+ };
761
+ });
762
+ return {
763
+ selectedEntityId: this.getSelectedEntity(),
764
+ entities: [...this.entities].sort((a, b) => a - b),
765
+ nextEntityId: this.nextEntityId,
766
+ components,
767
+ systems
768
+ };
769
+ }
770
+ getDebugSignature(maxDepth = 3) {
771
+ return JSON.stringify(this.getDebugSnapshot(maxDepth));
772
+ }
773
+ createHistorySnapshot() {
774
+ return {
775
+ selectedEntityId: this.getSelectedEntity(),
776
+ entities: [...this.entities],
777
+ nextEntityId: this.nextEntityId,
778
+ components: [...this.components.entries()].map(
779
+ ([componentType, store]) => {
780
+ return {
781
+ componentType,
782
+ entries: [...store.entries()].map(([entityId, component]) => {
783
+ return {
784
+ entityId,
785
+ component: cloneHistoryValue(component)
786
+ };
787
+ })
788
+ };
789
+ }
790
+ )
791
+ };
792
+ }
793
+ applyHistorySnapshot(snapshot) {
794
+ const previousSelectedEntityId = this.getSelectedEntity();
795
+ this.nextEntityId = snapshot.nextEntityId;
796
+ this.entities = new Set(snapshot.entities);
797
+ const nextComponents = /* @__PURE__ */ new Map();
798
+ for (const componentBlock of snapshot.components) {
799
+ const store = /* @__PURE__ */ new Map();
800
+ for (const entry of componentBlock.entries) {
801
+ if (!this.entities.has(entry.entityId)) {
802
+ continue;
803
+ }
804
+ store.set(entry.entityId, cloneHistoryValue(entry.component));
805
+ }
806
+ nextComponents.set(componentBlock.componentType, store);
807
+ }
808
+ this.components = nextComponents;
809
+ const selectionState = this.getSelectionState();
810
+ const nextSelectedEntityId = snapshot.selectedEntityId !== null && this.entities.has(snapshot.selectedEntityId) ? snapshot.selectedEntityId : null;
811
+ if (selectionState) {
812
+ selectionState.selectedEntityId = nextSelectedEntityId;
813
+ }
814
+ const selectionChanged = previousSelectedEntityId !== nextSelectedEntityId;
815
+ if (selectionChanged) {
816
+ for (const listener of this.selectionListeners) {
817
+ listener(nextSelectedEntityId);
818
+ }
819
+ }
820
+ this.emitStoreChanged();
821
+ }
822
+ emitStoreChanged() {
823
+ for (const listener of this.storeListeners) {
824
+ listener();
825
+ }
826
+ }
827
+ };
828
+ __name(_World, "World");
829
+ var World = _World;
830
+
831
+ // core/hydration/readers.ts
832
+ function asRecord(value) {
833
+ if (!value || typeof value !== "object") {
834
+ return null;
835
+ }
836
+ return value;
837
+ }
838
+ __name(asRecord, "asRecord");
839
+ function readString(value) {
840
+ if (typeof value === "string") {
841
+ return value;
842
+ }
843
+ const record = asRecord(value);
844
+ if (!record) {
845
+ return null;
846
+ }
847
+ return typeof record.value === "string" ? record.value : null;
848
+ }
849
+ __name(readString, "readString");
850
+ function readTransform(value) {
851
+ const record = asRecord(value);
852
+ if (!record) {
853
+ return void 0;
854
+ }
855
+ const position = asRecord(record.position);
856
+ const rotation = asRecord(record.rotation);
857
+ const scale = asRecord(record.scale);
858
+ return {
859
+ position: position ? {
860
+ x: typeof position.x === "number" ? position.x : void 0,
861
+ y: typeof position.y === "number" ? position.y : void 0,
862
+ z: typeof position.z === "number" ? position.z : void 0
863
+ } : void 0,
864
+ rotation: rotation ? {
865
+ x: typeof rotation.x === "number" ? rotation.x : void 0,
866
+ y: typeof rotation.y === "number" ? rotation.y : void 0,
867
+ z: typeof rotation.z === "number" ? rotation.z : void 0
868
+ } : void 0,
869
+ scale: scale ? {
870
+ x: typeof scale.x === "number" ? scale.x : void 0,
871
+ y: typeof scale.y === "number" ? scale.y : void 0,
872
+ z: typeof scale.z === "number" ? scale.z : void 0
873
+ } : void 0
874
+ };
875
+ }
876
+ __name(readTransform, "readTransform");
877
+ function readByComponent(components, componentName) {
878
+ const component = components.find((entry) => entry.component === componentName);
879
+ const map = /* @__PURE__ */ new Map();
880
+ if (!component) {
881
+ return map;
882
+ }
883
+ for (const entry of component.entries) {
884
+ map.set(entry.entityId, entry.value);
885
+ }
886
+ return map;
887
+ }
888
+ __name(readByComponent, "readByComponent");
889
+ function readBoolean(value) {
890
+ return typeof value === "boolean" ? value : void 0;
891
+ }
892
+ __name(readBoolean, "readBoolean");
893
+ function readNumber(value) {
894
+ return typeof value === "number" ? value : void 0;
895
+ }
896
+ __name(readNumber, "readNumber");
897
+
898
+ // core/hydration/componentValues.ts
899
+ function buildComponentValueMaps(snapshot) {
900
+ return {
901
+ object3DRefValues: readByComponent(snapshot.components, "Object3DRef"),
902
+ nameValues: readByComponent(snapshot.components, "Name"),
903
+ transformValues: readByComponent(snapshot.components, "TransformComponent"),
904
+ modelValues: readByComponent(snapshot.components, "ModelComponent"),
905
+ imageValues: readByComponent(snapshot.components, "ImageComponent"),
906
+ spriteValues: readByComponent(snapshot.components, "SpriteComponent"),
907
+ videoValues: readByComponent(snapshot.components, "VideoComponent"),
908
+ cameraValues: readByComponent(snapshot.components, "CameraComponent"),
909
+ environmentValues: readByComponent(snapshot.components, "Environment"),
910
+ postprocessingValues: readByComponent(snapshot.components, "Postprocessing"),
911
+ audioValues: readByComponent(snapshot.components, "AudioComponent"),
912
+ imageTargetValues: readByComponent(snapshot.components, "ImageTarget"),
913
+ lightValues: readByComponent(snapshot.components, "LightComponent"),
914
+ materialValues: readByComponent(snapshot.components, "MaterialComponent"),
915
+ meshGeometryValues: readByComponent(snapshot.components, "MeshGeometryComponent"),
916
+ selectableValues: readByComponent(snapshot.components, "Selectable"),
917
+ physicsValues: readByComponent(snapshot.components, "PhysicsComponent"),
918
+ animationValues: readByComponent(snapshot.components, "AnimationComponent"),
919
+ imageTargetAnchorValues: readByComponent(snapshot.components, "ImageTargetAnchor"),
920
+ scriptValues: readByComponent(snapshot.components, "ScriptComponent")
921
+ };
922
+ }
923
+ __name(buildComponentValueMaps, "buildComponentValueMaps");
924
+
925
+ // core/hydration/parentLinks.ts
926
+ function applyParentLinks(snapshot, idMap, objectManagementSystem, world) {
927
+ const parentValues = readByComponent(snapshot.components, "ParentId");
928
+ for (const [sourceEntityId, parentValue] of parentValues.entries()) {
929
+ const targetEntityId = idMap.get(sourceEntityId);
930
+ if (targetEntityId === void 0) {
931
+ continue;
932
+ }
933
+ const parentRecord = asRecord(parentValue);
934
+ const sourceParentId = parentRecord && typeof parentRecord.value === "number" ? parentRecord.value : null;
935
+ if (sourceParentId === null) {
936
+ objectManagementSystem.setParent(world, targetEntityId, null, {
937
+ preserveWorldTransform: false
938
+ });
939
+ continue;
940
+ }
941
+ const mappedParentId = idMap.get(sourceParentId);
942
+ objectManagementSystem.setParent(world, targetEntityId, mappedParentId ?? null, {
943
+ preserveWorldTransform: false
944
+ });
945
+ }
946
+ }
947
+ __name(applyParentLinks, "applyParentLinks");
948
+
949
+ // core/hydration/postCreateComponents.ts
950
+ function remapEntityRefsInScriptData(data, idMap) {
951
+ const result = {};
952
+ for (const [key, value] of Object.entries(data)) {
953
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
954
+ const v = value;
955
+ if (v.type === "entity" && typeof v.value === "number") {
956
+ result[key] = { ...v, value: idMap.get(v.value) ?? v.value };
957
+ } else if (v.type === "component" && v.value !== null && typeof v.value === "object" && !Array.isArray(v.value) && typeof v.value.entityId === "number") {
958
+ const ref = v.value;
959
+ result[key] = {
960
+ ...v,
961
+ value: { ...ref, entityId: idMap.get(ref.entityId) ?? ref.entityId }
962
+ };
963
+ } else {
964
+ result[key] = value;
965
+ }
966
+ } else {
967
+ result[key] = value;
968
+ }
969
+ }
970
+ return result;
971
+ }
972
+ __name(remapEntityRefsInScriptData, "remapEntityRefsInScriptData");
973
+ function restorePostCreateComponents(world, objectManagementSystem, targetEntityId, sourceEntityId, entityType, values, idMap) {
974
+ const objectRef = world.getComponent(targetEntityId, Object3DRef)?.object ?? null;
975
+ const sourceAudio = asRecord(values.audioValues.get(sourceEntityId));
976
+ if (sourceAudio && entityType !== "audio") {
977
+ const sourceOptions = asRecord(sourceAudio.options) ?? {};
978
+ objectManagementSystem.createComponentNow(
979
+ "audio",
980
+ world,
981
+ targetEntityId,
982
+ typeof sourceAudio.path === "string" ? sourceAudio.path : "",
983
+ sourceOptions,
984
+ {
985
+ object: objectRef,
986
+ listener: objectManagementSystem.getOrCreateAudioListener(),
987
+ isEditor: objectManagementSystem.isEditorMode()
988
+ }
989
+ );
990
+ }
991
+ const sourceImageTarget = asRecord(values.imageTargetValues.get(sourceEntityId));
992
+ if (sourceImageTarget && entityType !== "imageTarget") {
993
+ objectManagementSystem.createComponentNow(
994
+ "imageTarget",
995
+ world,
996
+ targetEntityId,
997
+ {
998
+ targets: Array.isArray(sourceImageTarget.targets) ? sourceImageTarget.targets : [],
999
+ compiledTargetUrl: typeof sourceImageTarget.compiledTargetUrl === "string" ? sourceImageTarget.compiledTargetUrl : void 0,
1000
+ compiledTargetDir: typeof sourceImageTarget.compiledTargetDir === "string" ? sourceImageTarget.compiledTargetDir : void 0
1001
+ }
1002
+ );
1003
+ }
1004
+ const sourceImageTargetAnchor = asRecord(values.imageTargetAnchorValues.get(sourceEntityId));
1005
+ if (sourceImageTargetAnchor) {
1006
+ const mappedTargetId = typeof sourceImageTargetAnchor.targetId === "number" && Number.isFinite(sourceImageTargetAnchor.targetId) ? sourceImageTargetAnchor.targetId : null;
1007
+ objectManagementSystem.createComponentNow("imageTargetAnchor", world, targetEntityId, {
1008
+ targetId: mappedTargetId,
1009
+ targetUrl: typeof sourceImageTargetAnchor.targetUrl === "string" ? sourceImageTargetAnchor.targetUrl : void 0
1010
+ });
1011
+ }
1012
+ const sourceScript = asRecord(values.scriptValues.get(sourceEntityId));
1013
+ if (sourceScript) {
1014
+ const entries = Array.isArray(sourceScript.entries) ? sourceScript.entries.map((entry) => asRecord(entry)).filter((entry) => Boolean(entry)).map((entry) => {
1015
+ const runtimeState = entry.runtimeState === "idle" || entry.runtimeState === "loading" || entry.runtimeState === "ready" || entry.runtimeState === "error" ? entry.runtimeState : void 0;
1016
+ return {
1017
+ entityId: targetEntityId,
1018
+ className: typeof entry.className === "string" ? entry.className : "",
1019
+ scriptUrl: typeof entry.scriptUrl === "string" ? entry.scriptUrl : "",
1020
+ enabled: typeof entry.enabled === "boolean" ? entry.enabled : true,
1021
+ data: entry.data && typeof entry.data === "object" && !Array.isArray(entry.data) ? remapEntityRefsInScriptData(entry.data, idMap) : {},
1022
+ runtimeState,
1023
+ runtimeMessage: typeof entry.runtimeMessage === "string" ? entry.runtimeMessage : void 0
1024
+ };
1025
+ }).filter((entry) => entry.className || entry.scriptUrl) : [];
1026
+ if (!entries.length) {
1027
+ return;
1028
+ }
1029
+ world.addComponent(
1030
+ targetEntityId,
1031
+ new ScriptComponent(entries)
1032
+ );
1033
+ }
1034
+ }
1035
+ __name(restorePostCreateComponents, "restorePostCreateComponents");
1036
+
1037
+ // core/hydration/animation.ts
1038
+ function readAnimationClipName(value) {
1039
+ if (typeof value === "string") {
1040
+ return value;
1041
+ }
1042
+ const record = asRecord(value);
1043
+ if (!record) {
1044
+ return null;
1045
+ }
1046
+ if (typeof record.name === "string") {
1047
+ return record.name;
1048
+ }
1049
+ return null;
1050
+ }
1051
+ __name(readAnimationClipName, "readAnimationClipName");
1052
+ function readAnimationStates(value) {
1053
+ if (!Array.isArray(value)) {
1054
+ return [];
1055
+ }
1056
+ const states = [];
1057
+ for (const entry of value) {
1058
+ const state = asRecord(entry);
1059
+ if (!state) {
1060
+ continue;
1061
+ }
1062
+ const name = typeof state.name === "string" ? state.name : null;
1063
+ const clip = readAnimationClipName(state.clip);
1064
+ if (!name || !clip) {
1065
+ continue;
1066
+ }
1067
+ states.push({
1068
+ name,
1069
+ clip,
1070
+ clipId: typeof state.clipId === "string" ? state.clipId : void 0,
1071
+ loop: typeof state.loop === "boolean" ? state.loop : false
1072
+ });
1073
+ }
1074
+ return states;
1075
+ }
1076
+ __name(readAnimationStates, "readAnimationStates");
1077
+ function readAnimationClipSources(value) {
1078
+ if (!Array.isArray(value)) {
1079
+ return [];
1080
+ }
1081
+ const seen = /* @__PURE__ */ new Set();
1082
+ const sources = [];
1083
+ for (const entry of value) {
1084
+ if (typeof entry !== "string") {
1085
+ continue;
1086
+ }
1087
+ const trimmed = entry.trim();
1088
+ if (!trimmed || seen.has(trimmed)) {
1089
+ continue;
1090
+ }
1091
+ seen.add(trimmed);
1092
+ sources.push(trimmed);
1093
+ }
1094
+ return sources;
1095
+ }
1096
+ __name(readAnimationClipSources, "readAnimationClipSources");
1097
+ function toAnimationOptions(sourceAnimation) {
1098
+ const paused = readBoolean(sourceAnimation.paused);
1099
+ const reverse = readBoolean(sourceAnimation.reverse);
1100
+ const timeScale = readNumber(sourceAnimation.timeScale);
1101
+ const crossFadeDuration = readNumber(sourceAnimation.crossFadeDuration);
1102
+ const states = readAnimationStates(sourceAnimation.states);
1103
+ const externalClipSources = readAnimationClipSources(
1104
+ sourceAnimation.externalClipSources
1105
+ );
1106
+ const activeStateName = typeof sourceAnimation.activeStateName === "string" ? sourceAnimation.activeStateName : typeof sourceAnimation.activeState === "string" ? sourceAnimation.activeState : typeof sourceAnimation.active?.name === "string" ? sourceAnimation.active.name ?? null : null;
1107
+ return {
1108
+ paused,
1109
+ reverse,
1110
+ timeScale,
1111
+ crossFadeDuration,
1112
+ states,
1113
+ externalClipSources,
1114
+ activeState: activeStateName
1115
+ };
1116
+ }
1117
+ __name(toAnimationOptions, "toAnimationOptions");
1118
+ function restoreAnimationComponent(world, objectManagementSystem, targetEntityId, sourceAnimation) {
1119
+ const options = toAnimationOptions(sourceAnimation);
1120
+ let animation = world.getComponent(targetEntityId, AnimationComponent);
1121
+ if (!animation) {
1122
+ objectManagementSystem.createComponentNow(
1123
+ "animation",
1124
+ world,
1125
+ targetEntityId,
1126
+ options
1127
+ );
1128
+ animation = world.getComponent(targetEntityId, AnimationComponent);
1129
+ }
1130
+ if (!animation) {
1131
+ return;
1132
+ }
1133
+ const availableClips = Array.isArray(sourceAnimation.availableClips) ? sourceAnimation.availableClips.filter(
1134
+ (clip) => typeof clip === "string" && clip.length > 0
1135
+ ) : [];
1136
+ if (availableClips.length > 0) {
1137
+ animation.availableClips = [...availableClips];
1138
+ }
1139
+ if (Array.isArray(options.externalClipSources)) {
1140
+ animation.setExternalClipSources(options.externalClipSources);
1141
+ }
1142
+ const states = options.states ?? [];
1143
+ const hasClips = Array.isArray(animation.clips) && animation.clips.length > 0;
1144
+ if (!hasClips) {
1145
+ animation.__pendingHydratedOptions = options;
1146
+ if (typeof options.reverse === "boolean") {
1147
+ animation.reverse = options.reverse;
1148
+ }
1149
+ if (typeof options.timeScale === "number") {
1150
+ animation.timeScale = options.timeScale;
1151
+ }
1152
+ if (typeof options.crossFadeDuration === "number") {
1153
+ animation.crossFadeDuration = options.crossFadeDuration;
1154
+ }
1155
+ if (typeof options.paused === "boolean") {
1156
+ animation.paused = options.paused;
1157
+ }
1158
+ return;
1159
+ }
1160
+ if (states.length > 0) {
1161
+ animation.setStates(states);
1162
+ }
1163
+ if (typeof options.reverse === "boolean") {
1164
+ animation.reverse = options.reverse;
1165
+ }
1166
+ if (typeof options.timeScale === "number") {
1167
+ animation.timeScale = options.timeScale;
1168
+ }
1169
+ if (typeof options.crossFadeDuration === "number") {
1170
+ animation.crossFadeDuration = options.crossFadeDuration;
1171
+ }
1172
+ if (typeof options.activeState === "string" && options.activeState.length > 0) {
1173
+ animation.setActiveState(options.activeState, !options.paused);
1174
+ }
1175
+ if (typeof options.paused === "boolean") {
1176
+ if (options.paused) {
1177
+ animation.pauseState();
1178
+ } else if (typeof options.activeState === "string" && options.activeState.length > 0) {
1179
+ animation.playState(options.activeState);
1180
+ }
1181
+ }
1182
+ }
1183
+ __name(restoreAnimationComponent, "restoreAnimationComponent");
1184
+
1185
+ // core/hydration/restoreComponentState.ts
1186
+ function readEnvironmentState(value) {
1187
+ const record = asRecord(value);
1188
+ if (!record) {
1189
+ return null;
1190
+ }
1191
+ const nestedValues = asRecord(record.values);
1192
+ if (nestedValues) {
1193
+ return nestedValues;
1194
+ }
1195
+ return record;
1196
+ }
1197
+ __name(readEnvironmentState, "readEnvironmentState");
1198
+ function readPostprocessingState(value) {
1199
+ const record = asRecord(value);
1200
+ if (!record) {
1201
+ return null;
1202
+ }
1203
+ const nestedValues = asRecord(record.values);
1204
+ if (nestedValues) {
1205
+ return nestedValues;
1206
+ }
1207
+ return record;
1208
+ }
1209
+ __name(readPostprocessingState, "readPostprocessingState");
1210
+ function restoreComponentState(world, objectManagementSystem, targetEntityId, sourceEntityId, entityType, values) {
1211
+ const sourceName = readString(values.nameValues.get(sourceEntityId));
1212
+ if (sourceName !== null) {
1213
+ const nameComponent = world.getComponent(targetEntityId, Name);
1214
+ if (nameComponent) {
1215
+ nameComponent.value = sourceName;
1216
+ }
1217
+ }
1218
+ const sourceObject3DRef = asRecord(values.object3DRefValues.get(sourceEntityId));
1219
+ if (sourceObject3DRef) {
1220
+ const object3DRefComponent = world.getComponent(targetEntityId, Object3DRef);
1221
+ const visibility = readBoolean(sourceObject3DRef.visibility);
1222
+ if (object3DRefComponent && typeof visibility === "boolean") {
1223
+ object3DRefComponent.visibility = visibility;
1224
+ }
1225
+ }
1226
+ const sourceTransform = readTransform(values.transformValues.get(sourceEntityId));
1227
+ if (sourceTransform) {
1228
+ const transformComponent = world.getComponent(targetEntityId, TransformComponent);
1229
+ if (transformComponent) {
1230
+ if (typeof sourceTransform.position?.x === "number") {
1231
+ transformComponent.position.x = sourceTransform.position.x;
1232
+ }
1233
+ if (typeof sourceTransform.position?.y === "number") {
1234
+ transformComponent.position.y = sourceTransform.position.y;
1235
+ }
1236
+ if (typeof sourceTransform.position?.z === "number") {
1237
+ transformComponent.position.z = sourceTransform.position.z;
1238
+ }
1239
+ if (typeof sourceTransform.rotation?.x === "number") {
1240
+ transformComponent.rotation.x = sourceTransform.rotation.x;
1241
+ }
1242
+ if (typeof sourceTransform.rotation?.y === "number") {
1243
+ transformComponent.rotation.y = sourceTransform.rotation.y;
1244
+ }
1245
+ if (typeof sourceTransform.rotation?.z === "number") {
1246
+ transformComponent.rotation.z = sourceTransform.rotation.z;
1247
+ }
1248
+ if (typeof sourceTransform.scale?.x === "number") {
1249
+ transformComponent.scale.x = sourceTransform.scale.x;
1250
+ }
1251
+ if (typeof sourceTransform.scale?.y === "number") {
1252
+ transformComponent.scale.y = sourceTransform.scale.y;
1253
+ }
1254
+ if (typeof sourceTransform.scale?.z === "number") {
1255
+ transformComponent.scale.z = sourceTransform.scale.z;
1256
+ }
1257
+ }
1258
+ }
1259
+ const sourceModel = asRecord(values.modelValues.get(sourceEntityId));
1260
+ if (sourceModel) {
1261
+ const modelComponent = world.getComponent(targetEntityId, ModelComponent);
1262
+ if (modelComponent && typeof sourceModel.path === "string") {
1263
+ modelComponent.path = sourceModel.path;
1264
+ }
1265
+ }
1266
+ const sourceImage = asRecord(values.imageValues.get(sourceEntityId));
1267
+ if (sourceImage) {
1268
+ const imageComponent = world.getComponent(targetEntityId, ImageComponent);
1269
+ if (imageComponent) {
1270
+ if (typeof sourceImage.path === "string") {
1271
+ imageComponent.path = sourceImage.path;
1272
+ }
1273
+ const width = readNumber(sourceImage.width);
1274
+ if (typeof width === "number") {
1275
+ imageComponent.width = width;
1276
+ }
1277
+ const height = readNumber(sourceImage.height);
1278
+ if (typeof height === "number") {
1279
+ imageComponent.height = height;
1280
+ }
1281
+ }
1282
+ }
1283
+ const sourceSprite = asRecord(values.spriteValues.get(sourceEntityId));
1284
+ if (sourceSprite) {
1285
+ const spriteComponent = world.getComponent(targetEntityId, SpriteComponent);
1286
+ if (spriteComponent) {
1287
+ if (typeof sourceSprite.path === "string") {
1288
+ spriteComponent.path = sourceSprite.path;
1289
+ }
1290
+ const width = readNumber(sourceSprite.width);
1291
+ if (typeof width === "number") {
1292
+ spriteComponent.width = width;
1293
+ }
1294
+ const height = readNumber(sourceSprite.height);
1295
+ if (typeof height === "number") {
1296
+ spriteComponent.height = height;
1297
+ }
1298
+ }
1299
+ }
1300
+ const sourceVideo = asRecord(values.videoValues.get(sourceEntityId));
1301
+ if (sourceVideo) {
1302
+ const videoComponent = world.getComponent(targetEntityId, VideoComponent);
1303
+ if (videoComponent) {
1304
+ if (typeof sourceVideo.path === "string") {
1305
+ videoComponent.path = sourceVideo.path;
1306
+ }
1307
+ const videoOptions = asRecord(sourceVideo.options);
1308
+ if (videoOptions) {
1309
+ videoComponent.options = {
1310
+ ...videoComponent.options,
1311
+ ...videoOptions
1312
+ };
1313
+ }
1314
+ }
1315
+ }
1316
+ const sourceAudio = asRecord(values.audioValues.get(sourceEntityId));
1317
+ if (sourceAudio && entityType === "audio") {
1318
+ const audioComponent = world.getComponent(targetEntityId, AudioComponent);
1319
+ if (audioComponent) {
1320
+ if (typeof sourceAudio.path === "string") {
1321
+ audioComponent.path = sourceAudio.path;
1322
+ }
1323
+ const audioOptions = asRecord(sourceAudio.options);
1324
+ if (audioOptions) {
1325
+ audioComponent.options = {
1326
+ ...audioComponent.options,
1327
+ ...audioOptions
1328
+ };
1329
+ }
1330
+ }
1331
+ }
1332
+ const sourceCamera = asRecord(values.cameraValues.get(sourceEntityId));
1333
+ if (sourceCamera) {
1334
+ const cameraComponent = world.getComponent(targetEntityId, CameraComponent);
1335
+ if (cameraComponent) {
1336
+ if (sourceCamera.projection === "orthographic" || sourceCamera.projection === "perspective") {
1337
+ cameraComponent.projection = sourceCamera.projection;
1338
+ }
1339
+ if (sourceCamera.type === "3d" || sourceCamera.type === "ar") {
1340
+ cameraComponent.type = sourceCamera.type;
1341
+ }
1342
+ if (typeof sourceCamera.isDefault === "boolean") {
1343
+ cameraComponent.isDefault = sourceCamera.isDefault;
1344
+ }
1345
+ const fov = readNumber(sourceCamera.fov);
1346
+ if (typeof fov === "number") {
1347
+ cameraComponent.fov = fov;
1348
+ }
1349
+ const near = readNumber(sourceCamera.near);
1350
+ if (typeof near === "number") {
1351
+ cameraComponent.near = near;
1352
+ }
1353
+ const far = readNumber(sourceCamera.far);
1354
+ if (typeof far === "number") {
1355
+ cameraComponent.far = far;
1356
+ }
1357
+ const left = readNumber(sourceCamera.left);
1358
+ if (typeof left === "number") {
1359
+ cameraComponent.left = left;
1360
+ }
1361
+ const right = readNumber(sourceCamera.right);
1362
+ if (typeof right === "number") {
1363
+ cameraComponent.right = right;
1364
+ }
1365
+ const top = readNumber(sourceCamera.top);
1366
+ if (typeof top === "number") {
1367
+ cameraComponent.top = top;
1368
+ }
1369
+ const bottom = readNumber(sourceCamera.bottom);
1370
+ if (typeof bottom === "number") {
1371
+ cameraComponent.bottom = bottom;
1372
+ }
1373
+ const zoom = readNumber(sourceCamera.zoom);
1374
+ if (typeof zoom === "number") {
1375
+ cameraComponent.zoom = zoom;
1376
+ }
1377
+ }
1378
+ }
1379
+ const sourceEnvironment = readEnvironmentState(
1380
+ values.environmentValues.get(sourceEntityId)
1381
+ );
1382
+ if (sourceEnvironment) {
1383
+ let environmentComponent = world.getComponent(targetEntityId, Environment);
1384
+ if (!environmentComponent) {
1385
+ objectManagementSystem.createComponentNow(
1386
+ "environment",
1387
+ world,
1388
+ targetEntityId,
1389
+ sourceEnvironment
1390
+ );
1391
+ environmentComponent = world.getComponent(targetEntityId, Environment);
1392
+ }
1393
+ if (environmentComponent) {
1394
+ environmentComponent.values = new Environment({
1395
+ ...environmentComponent.values,
1396
+ ...sourceEnvironment
1397
+ }).values;
1398
+ }
1399
+ }
1400
+ const sourcePostprocessing = readPostprocessingState(
1401
+ values.postprocessingValues.get(sourceEntityId)
1402
+ );
1403
+ if (sourcePostprocessing) {
1404
+ let postprocessingComponent = world.getComponent(targetEntityId, Postprocessing);
1405
+ if (!postprocessingComponent) {
1406
+ objectManagementSystem.createComponentNow(
1407
+ "postprocessing",
1408
+ world,
1409
+ targetEntityId,
1410
+ sourcePostprocessing
1411
+ );
1412
+ postprocessingComponent = world.getComponent(targetEntityId, Postprocessing);
1413
+ }
1414
+ if (postprocessingComponent) {
1415
+ postprocessingComponent.values = new Postprocessing({
1416
+ ...postprocessingComponent.values,
1417
+ ...sourcePostprocessing
1418
+ }).values;
1419
+ }
1420
+ }
1421
+ const sourceImageTarget = asRecord(values.imageTargetValues.get(sourceEntityId));
1422
+ if (sourceImageTarget && entityType === "imageTarget") {
1423
+ const imageTargetComponent = world.getComponent(targetEntityId, ImageTarget);
1424
+ if (imageTargetComponent) {
1425
+ imageTargetComponent.targets = Array.isArray(sourceImageTarget.targets) ? sourceImageTarget.targets : [];
1426
+ imageTargetComponent.compiledTargetUrl = typeof sourceImageTarget.compiledTargetUrl === "string" ? sourceImageTarget.compiledTargetUrl : void 0;
1427
+ imageTargetComponent.compiledTargetDir = typeof sourceImageTarget.compiledTargetDir === "string" ? sourceImageTarget.compiledTargetDir : void 0;
1428
+ }
1429
+ }
1430
+ const sourceLight = asRecord(values.lightValues.get(sourceEntityId));
1431
+ if (sourceLight) {
1432
+ const lightComponent = world.getComponent(targetEntityId, LightComponent);
1433
+ const sourceValues = asRecord(sourceLight.values);
1434
+ if (lightComponent && sourceValues) {
1435
+ lightComponent.values = {
1436
+ ...lightComponent.values,
1437
+ ...sourceValues
1438
+ };
1439
+ }
1440
+ }
1441
+ const sourceMaterial = asRecord(values.materialValues.get(sourceEntityId));
1442
+ if (sourceMaterial) {
1443
+ const materialComponent = world.getComponent(targetEntityId, MaterialComponent);
1444
+ const sourceValues = sourceMaterial.values;
1445
+ if (materialComponent && Array.isArray(sourceValues)) {
1446
+ materialComponent.values = sourceValues;
1447
+ }
1448
+ }
1449
+ const sourceMeshGeometry = asRecord(values.meshGeometryValues.get(sourceEntityId));
1450
+ if (sourceMeshGeometry) {
1451
+ const meshGeometryComponent = world.getComponent(
1452
+ targetEntityId,
1453
+ MeshGeometryComponent
1454
+ );
1455
+ if (meshGeometryComponent) {
1456
+ const parameters = asRecord(sourceMeshGeometry.parameters);
1457
+ if (parameters) {
1458
+ meshGeometryComponent.parameters = parameters;
1459
+ }
1460
+ if (typeof sourceMeshGeometry.modelName === "string") {
1461
+ meshGeometryComponent.modelName = sourceMeshGeometry.modelName;
1462
+ }
1463
+ if (typeof sourceMeshGeometry.castShadow === "boolean") {
1464
+ meshGeometryComponent.castShadow = sourceMeshGeometry.castShadow;
1465
+ }
1466
+ if (typeof sourceMeshGeometry.receiveShadow === "boolean") {
1467
+ meshGeometryComponent.receiveShadow = sourceMeshGeometry.receiveShadow;
1468
+ }
1469
+ }
1470
+ }
1471
+ const sourceSelectable = asRecord(values.selectableValues.get(sourceEntityId));
1472
+ if (sourceSelectable) {
1473
+ const enabled = readBoolean(sourceSelectable.enabled);
1474
+ let selectable = world.getComponent(targetEntityId, Selectable);
1475
+ if (!selectable) {
1476
+ objectManagementSystem.createComponentNow(
1477
+ "selectable",
1478
+ world,
1479
+ targetEntityId,
1480
+ enabled ?? true
1481
+ );
1482
+ selectable = world.getComponent(targetEntityId, Selectable);
1483
+ }
1484
+ if (selectable && typeof enabled === "boolean") {
1485
+ selectable.enabled = enabled;
1486
+ }
1487
+ }
1488
+ const sourcePhysics = asRecord(values.physicsValues.get(sourceEntityId));
1489
+ if (sourcePhysics) {
1490
+ const physicsValues = asRecord(sourcePhysics.values) ?? sourcePhysics;
1491
+ let physics = world.getComponent(targetEntityId, PhysicsComponent);
1492
+ if (!physics) {
1493
+ objectManagementSystem.createComponentNow(
1494
+ "physics",
1495
+ world,
1496
+ targetEntityId,
1497
+ physicsValues
1498
+ );
1499
+ physics = world.getComponent(targetEntityId, PhysicsComponent);
1500
+ }
1501
+ if (physics) {
1502
+ physics.setValues({
1503
+ rigidbody: asRecord(physicsValues.rigidbody) ?? {},
1504
+ collider: asRecord(physicsValues.collider) ?? {}
1505
+ });
1506
+ }
1507
+ }
1508
+ const sourceAnimation = asRecord(values.animationValues.get(sourceEntityId));
1509
+ if (sourceAnimation) {
1510
+ restoreAnimationComponent(
1511
+ world,
1512
+ objectManagementSystem,
1513
+ targetEntityId,
1514
+ sourceAnimation
1515
+ );
1516
+ }
1517
+ }
1518
+ __name(restoreComponentState, "restoreComponentState");
1519
+
1520
+ // core/hydration/types.ts
1521
+ var HYDRATABLE_ENTITY_KINDS = /* @__PURE__ */ new Set([
1522
+ "cube",
1523
+ "sphere",
1524
+ "plane",
1525
+ "capsule",
1526
+ "cylinder",
1527
+ "empty",
1528
+ "model",
1529
+ "image",
1530
+ "imageTarget",
1531
+ "sprite",
1532
+ "audio",
1533
+ "camera",
1534
+ "video",
1535
+ "ambientLight",
1536
+ "directionalLight",
1537
+ "pointLight",
1538
+ "spotLight",
1539
+ "areaLight"
1540
+ ]);
1541
+
1542
+ // core/hydration/hydrateWorld.ts
1543
+ function buildEntityCreationPayload(sourceEntityId, kind, componentValues) {
1544
+ const payload = {
1545
+ name: readString(componentValues.nameValues.get(sourceEntityId)) ?? void 0,
1546
+ transform: readTransform(componentValues.transformValues.get(sourceEntityId))
1547
+ };
1548
+ if (kind === "model") {
1549
+ const model = asRecord(componentValues.modelValues.get(sourceEntityId));
1550
+ if (typeof model?.path === "string") {
1551
+ payload.path = model.path;
1552
+ }
1553
+ }
1554
+ if (kind === "image") {
1555
+ const image = asRecord(componentValues.imageValues.get(sourceEntityId));
1556
+ if (typeof image?.path === "string") {
1557
+ payload.path = image.path;
1558
+ }
1559
+ }
1560
+ if (kind === "sprite") {
1561
+ const sprite = asRecord(componentValues.spriteValues.get(sourceEntityId));
1562
+ if (typeof sprite?.path === "string") {
1563
+ payload.path = sprite.path;
1564
+ }
1565
+ }
1566
+ if (kind === "video") {
1567
+ const video = asRecord(componentValues.videoValues.get(sourceEntityId));
1568
+ if (typeof video?.path === "string") {
1569
+ payload.path = video.path;
1570
+ }
1571
+ const videoOptions = asRecord(video?.options);
1572
+ if (videoOptions) {
1573
+ payload.options = videoOptions;
1574
+ }
1575
+ }
1576
+ if (kind === "audio") {
1577
+ const audio = asRecord(componentValues.audioValues.get(sourceEntityId));
1578
+ if (typeof audio?.path === "string") {
1579
+ payload.path = audio.path;
1580
+ }
1581
+ const audioOptions = asRecord(audio?.options);
1582
+ if (audioOptions) {
1583
+ payload.options = audioOptions;
1584
+ }
1585
+ }
1586
+ if (kind === "camera") {
1587
+ const camera = asRecord(componentValues.cameraValues.get(sourceEntityId));
1588
+ if (camera) {
1589
+ const projection = camera.projection === "orthographic" || camera.projection === "perspective" ? camera.projection : void 0;
1590
+ const type = camera.type === "3d" || camera.type === "ar" ? camera.type : void 0;
1591
+ payload.options = {
1592
+ isDefault: typeof camera.isDefault === "boolean" ? camera.isDefault : void 0,
1593
+ projection,
1594
+ type,
1595
+ fov: typeof camera.fov === "number" ? camera.fov : void 0,
1596
+ near: typeof camera.near === "number" ? camera.near : void 0,
1597
+ far: typeof camera.far === "number" ? camera.far : void 0,
1598
+ left: typeof camera.left === "number" ? camera.left : void 0,
1599
+ right: typeof camera.right === "number" ? camera.right : void 0,
1600
+ top: typeof camera.top === "number" ? camera.top : void 0,
1601
+ bottom: typeof camera.bottom === "number" ? camera.bottom : void 0,
1602
+ zoom: typeof camera.zoom === "number" ? camera.zoom : void 0
1603
+ };
1604
+ }
1605
+ }
1606
+ if (kind === "imageTarget") {
1607
+ const imageTarget = asRecord(componentValues.imageTargetValues.get(sourceEntityId));
1608
+ if (imageTarget) {
1609
+ payload.options = {
1610
+ targets: Array.isArray(imageTarget.targets) ? imageTarget.targets : [],
1611
+ compiledTargetUrl: typeof imageTarget.compiledTargetUrl === "string" ? imageTarget.compiledTargetUrl : void 0,
1612
+ compiledTargetDir: typeof imageTarget.compiledTargetDir === "string" ? imageTarget.compiledTargetDir : void 0
1613
+ };
1614
+ }
1615
+ }
1616
+ return payload;
1617
+ }
1618
+ __name(buildEntityCreationPayload, "buildEntityCreationPayload");
1619
+ function resolvePrimaryCameraSourceEntityId(snapshot, componentValues, entityTypeValues) {
1620
+ let firstCameraSourceEntityId = null;
1621
+ for (const sourceEntityId of snapshot.entities) {
1622
+ const entityType = readString(entityTypeValues.get(sourceEntityId));
1623
+ if (entityType !== "camera") {
1624
+ continue;
1625
+ }
1626
+ if (firstCameraSourceEntityId === null) {
1627
+ firstCameraSourceEntityId = sourceEntityId;
1628
+ }
1629
+ const cameraValue = asRecord(componentValues.cameraValues.get(sourceEntityId));
1630
+ if (cameraValue?.isDefault === true) {
1631
+ return sourceEntityId;
1632
+ }
1633
+ }
1634
+ return firstCameraSourceEntityId;
1635
+ }
1636
+ __name(resolvePrimaryCameraSourceEntityId, "resolvePrimaryCameraSourceEntityId");
1637
+ function applyLocalTransformsAfterHierarchyRestore(world) {
1638
+ const transformEntities = world.query(TransformComponent, Object3DRef);
1639
+ for (const entityId of transformEntities) {
1640
+ const transform = world.getComponent(entityId, TransformComponent);
1641
+ const object = world.getComponent(entityId, Object3DRef)?.object;
1642
+ if (!transform || !object) {
1643
+ continue;
1644
+ }
1645
+ applyTransform(object, transform);
1646
+ object.updateMatrixWorld(true);
1647
+ }
1648
+ }
1649
+ __name(applyLocalTransformsAfterHierarchyRestore, "applyLocalTransformsAfterHierarchyRestore");
1650
+ function hydrateWorldFromSnapshotDetailed(snapshot, world, objectManagementSystem) {
1651
+ if (!snapshot || !snapshot.entities.length) {
1652
+ return {
1653
+ restoredCount: 0,
1654
+ selectedEntityId: null
1655
+ };
1656
+ }
1657
+ const entityTypeValues = readByComponent(snapshot.components, "EntityType");
1658
+ const componentValues = buildComponentValueMaps(snapshot);
1659
+ const primaryCameraSourceEntityId = resolvePrimaryCameraSourceEntityId(
1660
+ snapshot,
1661
+ componentValues,
1662
+ entityTypeValues
1663
+ );
1664
+ const idMap = /* @__PURE__ */ new Map();
1665
+ for (const sourceEntityId of snapshot.entities) {
1666
+ const entityTypeValue = entityTypeValues.get(sourceEntityId);
1667
+ const entityType = readString(entityTypeValue);
1668
+ if (!entityType || !HYDRATABLE_ENTITY_KINDS.has(entityType)) {
1669
+ continue;
1670
+ }
1671
+ const kind = entityType;
1672
+ const payload = buildEntityCreationPayload(sourceEntityId, kind, componentValues);
1673
+ if (kind === "camera" && sourceEntityId === primaryCameraSourceEntityId) {
1674
+ payload.useWorldCamera = true;
1675
+ const options = asRecord(payload.options);
1676
+ payload.options = {
1677
+ ...options ?? {},
1678
+ isDefault: true
1679
+ };
1680
+ }
1681
+ const createdEntityId = objectManagementSystem.createNow(kind, world, payload);
1682
+ idMap.set(sourceEntityId, createdEntityId);
1683
+ }
1684
+ for (const sourceEntityId of snapshot.entities) {
1685
+ const targetEntityId = idMap.get(sourceEntityId);
1686
+ if (targetEntityId === void 0) {
1687
+ continue;
1688
+ }
1689
+ const entityType = readString(entityTypeValues.get(sourceEntityId));
1690
+ restoreComponentState(
1691
+ world,
1692
+ objectManagementSystem,
1693
+ targetEntityId,
1694
+ sourceEntityId,
1695
+ entityType,
1696
+ componentValues
1697
+ );
1698
+ restorePostCreateComponents(
1699
+ world,
1700
+ objectManagementSystem,
1701
+ targetEntityId,
1702
+ sourceEntityId,
1703
+ entityType,
1704
+ componentValues,
1705
+ idMap
1706
+ );
1707
+ }
1708
+ applyParentLinks(snapshot, idMap, objectManagementSystem, world);
1709
+ objectManagementSystem.reconcileSceneFromWorld(world);
1710
+ applyLocalTransformsAfterHierarchyRestore(world);
1711
+ const selectedEntityId = typeof snapshot.selectedEntityId === "number" ? idMap.get(snapshot.selectedEntityId) ?? null : null;
1712
+ return {
1713
+ restoredCount: idMap.size,
1714
+ selectedEntityId
1715
+ };
1716
+ }
1717
+ __name(hydrateWorldFromSnapshotDetailed, "hydrateWorldFromSnapshotDetailed");
1718
+ function hydrateWorldFromSnapshot(snapshot, world, objectManagementSystem) {
1719
+ return hydrateWorldFromSnapshotDetailed(
1720
+ snapshot,
1721
+ world,
1722
+ objectManagementSystem
1723
+ ).restoredCount;
1724
+ }
1725
+ __name(hydrateWorldFromSnapshot, "hydrateWorldFromSnapshot");
1726
+
1727
+ export { HYDRATABLE_ENTITY_KINDS, World, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed };
1728
+ //# sourceMappingURL=index.js.map
1729
+ //# sourceMappingURL=index.js.map