@zephyr3d/scene 0.9.6 → 0.9.7

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 (203) hide show
  1. package/dist/animation/joint_dynamics/controller.js +92 -32
  2. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  3. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  4. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  5. package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
  6. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  7. package/dist/animation/joint_dynamics/solver.js +71 -27
  8. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  9. package/dist/animation/joint_dynamics_modifier.js +21 -20
  10. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  11. package/dist/animation/skeleton.js +7 -10
  12. package/dist/animation/skeleton.js.map +1 -1
  13. package/dist/app/engine.js +134 -140
  14. package/dist/app/engine.js.map +1 -1
  15. package/dist/app/scriptregistry.js +47 -16
  16. package/dist/app/scriptregistry.js.map +1 -1
  17. package/dist/asset/assetmanager.js +3 -1
  18. package/dist/asset/assetmanager.js.map +1 -1
  19. package/dist/asset/model.js +346 -7
  20. package/dist/asset/model.js.map +1 -1
  21. package/dist/avatar/wardrobe.js +20 -16
  22. package/dist/avatar/wardrobe.js.map +1 -1
  23. package/dist/camera/camera.js +416 -210
  24. package/dist/camera/camera.js.map +1 -1
  25. package/dist/index.d.ts +1349 -621
  26. package/dist/index.js +6 -11
  27. package/dist/index.js.map +1 -1
  28. package/dist/material/blinn.js +1 -1
  29. package/dist/material/blinn.js.map +1 -1
  30. package/dist/material/lambert.js +1 -1
  31. package/dist/material/lambert.js.map +1 -1
  32. package/dist/material/material.js +23 -1
  33. package/dist/material/material.js.map +1 -1
  34. package/dist/material/meshmaterial.js +178 -23
  35. package/dist/material/meshmaterial.js.map +1 -1
  36. package/dist/material/mixins/albedocolor.js +4 -4
  37. package/dist/material/mixins/albedocolor.js.map +1 -1
  38. package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
  39. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  40. package/dist/material/mixins/lightmodel/lambert.js +2 -1
  41. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  42. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
  43. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  44. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +105 -32
  45. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  46. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
  47. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  48. package/dist/material/mixins/lit.js +1 -1
  49. package/dist/material/mixins/lit.js.map +1 -1
  50. package/dist/material/mixins/pbr/common.js +276 -65
  51. package/dist/material/mixins/pbr/common.js.map +1 -1
  52. package/dist/material/mixins/texture.js +3 -3
  53. package/dist/material/mixins/texture.js.map +1 -1
  54. package/dist/material/mixins/vertexcolor.js +2 -2
  55. package/dist/material/mixins/vertexcolor.js.map +1 -1
  56. package/dist/material/mtoon.js +574 -0
  57. package/dist/material/mtoon.js.map +1 -0
  58. package/dist/material/pbrblueprint.js +499 -336
  59. package/dist/material/pbrblueprint.js.map +1 -1
  60. package/dist/material/pbrmr.js +118 -100
  61. package/dist/material/pbrmr.js.map +1 -1
  62. package/dist/material/pbrsg.js +1 -1
  63. package/dist/material/pbrsg.js.map +1 -1
  64. package/dist/material/shader/helper.js +324 -294
  65. package/dist/material/shader/helper.js.map +1 -1
  66. package/dist/material/subsurfaceprofile.js +812 -0
  67. package/dist/material/subsurfaceprofile.js.map +1 -0
  68. package/dist/material/unlit.js +1 -1
  69. package/dist/material/unlit.js.map +1 -1
  70. package/dist/posteffect/compositor.js +46 -11
  71. package/dist/posteffect/compositor.js.map +1 -1
  72. package/dist/posteffect/ssr.js +422 -96
  73. package/dist/posteffect/ssr.js.map +1 -1
  74. package/dist/posteffect/sss.js +1053 -0
  75. package/dist/posteffect/sss.js.map +1 -0
  76. package/dist/posteffect/taa.js +61 -60
  77. package/dist/posteffect/taa.js.map +1 -1
  78. package/dist/render/abuffer_oit.js +63 -12
  79. package/dist/render/abuffer_oit.js.map +1 -1
  80. package/dist/render/cluster_light.js +6 -5
  81. package/dist/render/cluster_light.js.map +1 -1
  82. package/dist/render/drawable.js +1 -5
  83. package/dist/render/drawable.js.map +1 -1
  84. package/dist/render/drawable_mixin.js +2 -1
  85. package/dist/render/drawable_mixin.js.map +1 -1
  86. package/dist/render/fbm_wavegenerator.js +2 -1
  87. package/dist/render/fbm_wavegenerator.js.map +1 -1
  88. package/dist/render/gerstner_wavegenerator.js +2 -1
  89. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  90. package/dist/render/globalbindgroup_allocator.js +2 -1
  91. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  92. package/dist/render/lightpass.js +110 -23
  93. package/dist/render/lightpass.js.map +1 -1
  94. package/dist/render/render_queue.js +51 -8
  95. package/dist/render/render_queue.js.map +1 -1
  96. package/dist/render/renderer.js +80 -66
  97. package/dist/render/renderer.js.map +1 -1
  98. package/dist/render/rendergraph/device_pool_allocator.js +8 -0
  99. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  100. package/dist/render/rendergraph/forward_plus_builder.js +481 -95
  101. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  102. package/dist/render/rendergraph/history_resource_manager.js +55 -0
  103. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  104. package/dist/render/rendergraph/history_resources.js +3 -1
  105. package/dist/render/rendergraph/history_resources.js.map +1 -1
  106. package/dist/render/rendergraph/types.js.map +1 -1
  107. package/dist/render/renderpass.js +10 -4
  108. package/dist/render/renderpass.js.map +1 -1
  109. package/dist/render/sky.js +31 -1
  110. package/dist/render/sky.js.map +1 -1
  111. package/dist/render/weightedblended_oit.js +23 -5
  112. package/dist/render/weightedblended_oit.js.map +1 -1
  113. package/dist/scene/basesprite.js +4 -2
  114. package/dist/scene/basesprite.js.map +1 -1
  115. package/dist/scene/batchgroup.js +3 -1
  116. package/dist/scene/batchgroup.js.map +1 -1
  117. package/dist/scene/environment.js +11 -1
  118. package/dist/scene/environment.js.map +1 -1
  119. package/dist/scene/light.js +21 -3
  120. package/dist/scene/light.js.map +1 -1
  121. package/dist/scene/mesh.js +29 -14
  122. package/dist/scene/mesh.js.map +1 -1
  123. package/dist/scene/meshdrawable.js +6 -0
  124. package/dist/scene/meshdrawable.js.map +1 -1
  125. package/dist/scene/msdftext.js +5 -2
  126. package/dist/scene/msdftext.js.map +1 -1
  127. package/dist/scene/msdftextsprite.js +5 -3
  128. package/dist/scene/msdftextsprite.js.map +1 -1
  129. package/dist/scene/particlesys.js +3 -1
  130. package/dist/scene/particlesys.js.map +1 -1
  131. package/dist/scene/scene.js +6 -5
  132. package/dist/scene/scene.js.map +1 -1
  133. package/dist/scene/terrain-cm/grass.js +4 -2
  134. package/dist/scene/terrain-cm/grass.js.map +1 -1
  135. package/dist/scene/terrain-cm/grassmaterial.js +2 -1
  136. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  137. package/dist/scene/terrain-cm/terrain-cm.js +4 -2
  138. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  139. package/dist/scene/water.js +4 -2
  140. package/dist/scene/water.js.map +1 -1
  141. package/dist/shaders/shadow.js +26 -393
  142. package/dist/shaders/shadow.js.map +1 -1
  143. package/dist/shadow/esm.js +112 -12
  144. package/dist/shadow/esm.js.map +1 -1
  145. package/dist/shadow/pcf_opt.js +2 -2
  146. package/dist/shadow/pcf_opt.js.map +1 -1
  147. package/dist/shadow/pcf_pd.js +19 -10
  148. package/dist/shadow/pcf_pd.js.map +1 -1
  149. package/dist/shadow/shader.js +58 -7
  150. package/dist/shadow/shader.js.map +1 -1
  151. package/dist/shadow/shadow_impl.js +6 -0
  152. package/dist/shadow/shadow_impl.js.map +1 -1
  153. package/dist/shadow/shadow_region.js +229 -0
  154. package/dist/shadow/shadow_region.js.map +1 -0
  155. package/dist/shadow/shadowmapper.js +67 -59
  156. package/dist/shadow/shadowmapper.js.map +1 -1
  157. package/dist/shadow/vsm.js +45 -19
  158. package/dist/shadow/vsm.js.map +1 -1
  159. package/dist/utility/blueprint/common/constants.js +8 -8
  160. package/dist/utility/blueprint/common/constants.js.map +1 -1
  161. package/dist/utility/blueprint/material/pbr.js +31 -4
  162. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  163. package/dist/utility/blueprint/material/texture.js +1 -17
  164. package/dist/utility/blueprint/material/texture.js.map +1 -1
  165. package/dist/utility/serialization/manager.js +327 -359
  166. package/dist/utility/serialization/manager.js.map +1 -1
  167. package/dist/utility/serialization/scene/animation.js +5 -2
  168. package/dist/utility/serialization/scene/animation.js.map +1 -1
  169. package/dist/utility/serialization/scene/batch.js +4 -1
  170. package/dist/utility/serialization/scene/batch.js.map +1 -1
  171. package/dist/utility/serialization/scene/camera.js +249 -54
  172. package/dist/utility/serialization/scene/camera.js.map +1 -1
  173. package/dist/utility/serialization/scene/common.js +37 -1
  174. package/dist/utility/serialization/scene/common.js.map +1 -1
  175. package/dist/utility/serialization/scene/light.js +42 -3
  176. package/dist/utility/serialization/scene/light.js.map +1 -1
  177. package/dist/utility/serialization/scene/material.js +1112 -646
  178. package/dist/utility/serialization/scene/material.js.map +1 -1
  179. package/dist/utility/serialization/scene/mesh.js +7 -4
  180. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  181. package/dist/utility/serialization/scene/node.js +31 -12
  182. package/dist/utility/serialization/scene/node.js.map +1 -1
  183. package/dist/utility/serialization/scene/particle.js +4 -1
  184. package/dist/utility/serialization/scene/particle.js.map +1 -1
  185. package/dist/utility/serialization/scene/primitive.js +3 -1
  186. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  187. package/dist/utility/serialization/scene/scene.js +18 -0
  188. package/dist/utility/serialization/scene/scene.js.map +1 -1
  189. package/dist/utility/serialization/scene/sprite.js +6 -3
  190. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  191. package/dist/utility/serialization/scene/terrain.js +5 -2
  192. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  193. package/dist/utility/serialization/scene/text.js +3 -1
  194. package/dist/utility/serialization/scene/text.js.map +1 -1
  195. package/dist/utility/serialization/scene/water.js +4 -1
  196. package/dist/utility/serialization/scene/water.js.map +1 -1
  197. package/dist/utility/textures/ltcdata.js +6 -0
  198. package/dist/utility/textures/ltcdata.js.map +1 -0
  199. package/dist/utility/textures/ltclut.js +61 -0
  200. package/dist/utility/textures/ltclut.js.map +1 -0
  201. package/dist/values.js +9 -1
  202. package/dist/values.js.map +1 -1
  203. package/package.json +3 -3
@@ -14,6 +14,7 @@ import { LambertMaterial } from '../material/lambert.js';
14
14
  import { BlinnMaterial } from '../material/blinn.js';
15
15
  import { UnlitMaterial } from '../material/unlit.js';
16
16
  import '../material/particle.js';
17
+ import '../material/subsurfaceprofile.js';
17
18
  import '@zephyr3d/device';
18
19
  import '../values.js';
19
20
  import '../material/meshmaterial.js';
@@ -21,30 +22,30 @@ import '../material/grassmaterial.js';
21
22
  import '../material/terrain-cm.js';
22
23
  import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
23
24
  import { PBRSpecularGlossinessMaterial } from '../material/pbrsg.js';
25
+ import '../material/mtoon.js';
24
26
  import '../material/pbrblueprint.js';
25
27
  import '../material/sprite.js';
26
28
  import { StandardSpriteMaterial } from '../material/sprite_std.js';
27
- import '../material/msdf_text.js';
28
29
  import '../utility/blueprint/material/texture.js';
29
30
  import { ScreenAdapter } from './screen.js';
30
31
  import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js';
31
32
 
32
- /**
33
- * Core engine class managing scripting, serialization, and rendering.
34
- *
35
- * Responsibilities:
36
- * - Manages a {@link ScriptingSystem} for dynamic script attachment and lifecycle.
37
- * - Manages a {@link ResourceManager} for loading scenes and assets.
38
- * - Maintains a list of active renderable objects to be rendered each frame.
39
- * - Provides methods to attach/detach scripts, update scripts, load scenes, and read files.
40
- * - Supports enabling/disabling of runtime operations.
41
- *
42
- * @remarks
43
- * The engine can be configured with a virtual file system (VFS) and script root path.
44
- * It exposes methods to manage scripts on host objects, update scripts each frame,
45
- * load scenes from files, and render active objects.
46
- *
47
- * @public
33
+ /**
34
+ * Core engine class managing scripting, serialization, and rendering.
35
+ *
36
+ * Responsibilities:
37
+ * - Manages a {@link ScriptingSystem} for dynamic script attachment and lifecycle.
38
+ * - Manages a {@link ResourceManager} for loading scenes and assets.
39
+ * - Maintains a list of active renderable objects to be rendered each frame.
40
+ * - Provides methods to attach/detach scripts, update scripts, load scenes, and read files.
41
+ * - Supports enabling/disabling of runtime operations.
42
+ *
43
+ * @remarks
44
+ * The engine can be configured with a virtual file system (VFS) and script root path.
45
+ * It exposes methods to manage scripts on host objects, update scripts each frame,
46
+ * load scenes from files, and render active objects.
47
+ *
48
+ * @public
48
49
  */ class Engine {
49
50
  _builtinsVFS;
50
51
  _scriptingSystem;
@@ -54,12 +55,12 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
54
55
  _screen;
55
56
  _activeRenderables;
56
57
  _loadingScenes;
57
- /**
58
- * Creates a new runtime manager.
59
- *
60
- * @param VFS - Optional virtual file system passed to the internal {@link ScriptingSystem}.
61
- * @param scriptsRoot - Optional scripts root path within the VFS. Defaults as in `ScriptingSystem`.
62
- * @param enabled - Whether runtime operations are active. Defaults to `true`.
58
+ /**
59
+ * Creates a new runtime manager.
60
+ *
61
+ * @param VFS - Optional virtual file system passed to the internal {@link ScriptingSystem}.
62
+ * @param scriptsRoot - Optional scripts root path within the VFS. Defaults as in `ScriptingSystem`.
63
+ * @param enabled - Whether runtime operations are active. Defaults to `true`.
63
64
  */ constructor(VFS, scriptsRoot, enabled){
64
65
  VFS = VFS ?? new HttpFS('./');
65
66
  this._builtinsVFS = null;
@@ -74,24 +75,17 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
74
75
  this._loadingScenes = {};
75
76
  this._screen = new ScreenAdapter();
76
77
  }
77
- /**
78
- * Exposes the instance of {@link ScriptingSystem}.
78
+ /**
79
+ * Exposes the instance of {@link ScriptingSystem}.
79
80
  */ get scriptingSystem() {
80
81
  return this._scriptingSystem;
81
82
  }
82
- /**
83
- * Exposes the virtual file system used by the underlying {@link ScriptingSystem}'s registry.
83
+ /**
84
+ * Exposes the virtual file system used by the underlying {@link ScriptingSystem}'s registry.
84
85
  */ get VFS() {
85
86
  return this._scriptingSystem.registry.VFS;
86
87
  }
87
- /**
88
- * Replaces the virtual file system used by the engine.
89
- *
90
- * The previous resource manager VFS is closed, the scripting registry is updated,
91
- * and built-in assets are remounted on the new VFS.
92
- *
93
- * @param vfs - New virtual file system.
94
- */ set VFS(vfs) {
88
+ set VFS(vfs) {
95
89
  if (vfs !== this._resourceManager.VFS) {
96
90
  this._resourceManager.VFS?.close();
97
91
  this._resourceManager.VFS = vfs;
@@ -99,24 +93,24 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
99
93
  this.ensureBuiltinVFS();
100
94
  }
101
95
  }
102
- /**
103
- * Exposes the instance of {@link ResourceManager}.
96
+ /**
97
+ * Exposes the instance of {@link ResourceManager}.
104
98
  */ get resourceManager() {
105
99
  return this._resourceManager;
106
100
  }
107
- /**
108
- * Exposes the shared runtime MSDF text atlas manager.
101
+ /**
102
+ * Exposes the shared runtime MSDF text atlas manager.
109
103
  */ get msdfTextAtlasManager() {
110
104
  return this._msdfTextAtlasManager;
111
105
  }
112
- /**
113
- * Releases a loaded font asset from the resource cache and disposes its shared MSDF atlas textures.
114
- *
115
- * Existing scene nodes that still reference this font asset are not updated automatically.
116
- * Call this only after you have stopped using the font, or when you intentionally want it to rebuild later.
117
- *
118
- * @param font - The loaded font asset path to release.
119
- * @returns `true` if either the atlas cache or the font cache had an entry to remove.
106
+ /**
107
+ * Releases a loaded font asset from the resource cache and disposes its shared MSDF atlas textures.
108
+ *
109
+ * Existing scene nodes that still reference this font asset are not updated automatically.
110
+ * Call this only after you have stopped using the font, or when you intentionally want it to rebuild later.
111
+ *
112
+ * @param font - The loaded font asset path to release.
113
+ * @returns `true` if either the atlas cache or the font cache had an entry to remove.
120
114
  */ releaseFontAsset(font) {
121
115
  const fontAsset = this._resourceManager.getFontAsset(font);
122
116
  if (!fontAsset) {
@@ -126,21 +120,21 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
126
120
  const fontReleased = this._resourceManager.releaseFontAsset(fontAsset);
127
121
  return atlasReleased || fontReleased;
128
122
  }
129
- /**
130
- * Configures the MSDF atlas for a given font asset, creating or replacing the atlas as needed.
131
- *
132
- * This is useful to customize the glyph size, atlas page size, distance range, and padding for MSDF text rendering.
133
- * Existing scene nodes that reference this font asset will use the updated atlas automatically.
134
- *
135
- * @param font - The font asset path to configure the MSDF atlas for.
136
- * @param pageSize - The size of each atlas page in pixels (e.g., 512, 1024).
137
- * @param glyphSize - The size of each glyph in pixels (e.g., 32, 64).
138
- * @param distanceRange - The distance range for MSDF generation. Defaults to 4.
139
- * @param padding - The padding between glyphs in the atlas in pixels. Defaults to 2.
140
- * @returns `true` if the atlas was successfully configured, or `false` if the font asset was not found.
141
- *
142
- * @remarks
143
- * The font asset must be loaded and available in the resource manager for the atlas to be configured.
123
+ /**
124
+ * Configures the MSDF atlas for a given font asset, creating or replacing the atlas as needed.
125
+ *
126
+ * This is useful to customize the glyph size, atlas page size, distance range, and padding for MSDF text rendering.
127
+ * Existing scene nodes that reference this font asset will use the updated atlas automatically.
128
+ *
129
+ * @param font - The font asset path to configure the MSDF atlas for.
130
+ * @param pageSize - The size of each atlas page in pixels (e.g., 512, 1024).
131
+ * @param glyphSize - The size of each glyph in pixels (e.g., 32, 64).
132
+ * @param distanceRange - The distance range for MSDF generation. Defaults to 4.
133
+ * @param padding - The padding between glyphs in the atlas in pixels. Defaults to 2.
134
+ * @returns `true` if the atlas was successfully configured, or `false` if the font asset was not found.
135
+ *
136
+ * @remarks
137
+ * The font asset must be loaded and available in the resource manager for the atlas to be configured.
144
138
  */ configureMSDFAtlas(font, pageSize, glyphSize, distanceRange, padding) {
145
139
  const fontAsset = this._resourceManager.getFontAsset(font);
146
140
  if (!fontAsset) {
@@ -150,85 +144,85 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
150
144
  this._msdfTextAtlasManager.configureAtlas(fontAsset, pageSize, glyphSize, distanceRange, padding);
151
145
  return true;
152
146
  }
153
- /**
154
- * Exposes the active {@link ScreenAdapter}.
147
+ /**
148
+ * Exposes the active {@link ScreenAdapter}.
155
149
  */ get screen() {
156
150
  return this._screen;
157
151
  }
158
152
  /** @internal */ async init() {
159
153
  await this.ensureBuiltinVFS();
160
154
  }
161
- /**
162
- * Detaches all scripts from all hosts, if enabled.
163
- *
164
- * No-op when `enabled === false`.
155
+ /**
156
+ * Detaches all scripts from all hosts, if enabled.
157
+ *
158
+ * No-op when `enabled === false`.
165
159
  */ detachAllScripts() {
166
160
  if (this._enabled) {
167
161
  this._scriptingSystem.detachAllScripts();
168
162
  }
169
163
  }
170
- /**
171
- * Loads a runtime script class from file
172
- * @param module - file path
173
- * @returns The runtime script class or null
164
+ /**
165
+ * Loads a runtime script class from file
166
+ * @param module - file path
167
+ * @returns The runtime script class or null
174
168
  */ async loadRuntimeScriptClass(module) {
175
169
  return await this._scriptingSystem.loadRuntimeScriptClass(module);
176
170
  }
177
- /**
178
- * Attaches a script module to the given host, if enabled.
179
- *
180
- * When disabled, this method resolves to `null` without side effects.
181
- *
182
- * @typeParam T - Host type.
183
- * @param host - Host object to attach the script to.
184
- * @param module - Module identifier to resolve and load.
185
- * @param config - Optional configuration passed to the script instance.
186
- * @returns The `RuntimeScript<T>` instance, or `null` if disabled or on failure.
171
+ /**
172
+ * Attaches a script module to the given host, if enabled.
173
+ *
174
+ * When disabled, this method resolves to `null` without side effects.
175
+ *
176
+ * @typeParam T - Host type.
177
+ * @param host - Host object to attach the script to.
178
+ * @param module - Module identifier to resolve and load.
179
+ * @param config - Optional configuration passed to the script instance.
180
+ * @returns The `RuntimeScript<T>` instance, or `null` if disabled or on failure.
187
181
  */ async attachScript(host, module, config) {
188
182
  return this._enabled ? await this._scriptingSystem.attachScript(host, module, config) : null;
189
183
  }
190
- /**
191
- * Detaches a script from a host, by module ID or instance, if enabled.
192
- *
193
- * No-op when disabled.
194
- *
195
- * @typeParam T - Host type.
196
- * @param host - Host to detach from.
197
- * @param idOrInstance - Target script by module ID or instance reference.
184
+ /**
185
+ * Detaches a script from a host, by module ID or instance, if enabled.
186
+ *
187
+ * No-op when disabled.
188
+ *
189
+ * @typeParam T - Host type.
190
+ * @param host - Host to detach from.
191
+ * @param idOrInstance - Target script by module ID or instance reference.
198
192
  */ detachScript(host, idOrInstance) {
199
193
  if (this._enabled) {
200
194
  this._scriptingSystem.detachScript(host, idOrInstance);
201
195
  }
202
196
  }
203
- /**
204
- * Gets all scripts attached to a host.
205
- *
206
- * Delegates to {@link ScriptingSystem.getScriptObjects}.
207
- *
208
- * @typeParam T - Expected script type.
209
- * @param host - Host object to query.
210
- * @returns Script instances attached to the host, or an empty array.
197
+ /**
198
+ * Gets all scripts attached to a host.
199
+ *
200
+ * Delegates to {@link ScriptingSystem.getScriptObjects}.
201
+ *
202
+ * @typeParam T - Expected script type.
203
+ * @param host - Host object to query.
204
+ * @returns Script instances attached to the host, or an empty array.
211
205
  */ getScriptObjects(host) {
212
206
  return this._scriptingSystem.getScriptObjects(host);
213
207
  }
214
- /**
215
- * Ticks all attached scripts by calling their `onUpdate` hooks, if enabled.
216
- *
217
- * @param deltaTime - Time since last update in Seconds.
218
- * @param elapsedTime - Total elapsed time in Seconds.
208
+ /**
209
+ * Ticks all attached scripts by calling their `onUpdate` hooks, if enabled.
210
+ *
211
+ * @param deltaTime - Time since last update in Seconds.
212
+ * @param elapsedTime - Total elapsed time in Seconds.
219
213
  */ update(deltaTime, elapsedTime) {
220
214
  if (this._enabled) {
221
215
  this._scriptingSystem.update(deltaTime, elapsedTime);
222
216
  }
223
217
  }
224
- /**
225
- * Loads a scene from a file path.
226
- *
227
- * Concurrent requests for the same normalized path share the same loading promise.
228
- * Scripts declared on the scene and its nodes are attached after the scene is loaded.
229
- *
230
- * @param path - Scene file path in the current VFS.
231
- * @returns The loaded scene, or `null` when loading fails.
218
+ /**
219
+ * Loads a scene from a file path.
220
+ *
221
+ * Concurrent requests for the same normalized path share the same loading promise.
222
+ * Scripts declared on the scene and its nodes are attached after the scene is loaded.
223
+ *
224
+ * @param path - Scene file path in the current VFS.
225
+ * @returns The loaded scene, or `null` when loading fails.
232
226
  */ async loadSceneFromFile(path) {
233
227
  path = this.VFS.normalizePath(path);
234
228
  if (!this._loadingScenes[path]) {
@@ -236,15 +230,15 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
236
230
  }
237
231
  return this._loadingScenes[path];
238
232
  }
239
- /**
240
- * Sets or clears the renderable for a render layer.
241
- *
242
- * Passing `null` clears the layer. Object renderables are held through a strong reference wrapper,
243
- * while render functions are stored directly.
244
- *
245
- * @param renderable - Renderable object or render function to assign, or `null` to clear.
246
- * @param layer - Render layer index. Defaults to `0`.
247
- * @param hook - Optional render hook invoked before and after this layer renders.
233
+ /**
234
+ * Sets or clears the renderable for a render layer.
235
+ *
236
+ * Passing `null` clears the layer. Object renderables are held through a strong reference wrapper,
237
+ * while render functions are stored directly.
238
+ *
239
+ * @param renderable - Renderable object or render function to assign, or `null` to clear.
240
+ * @param layer - Render layer index. Defaults to `0`.
241
+ * @param hook - Optional render hook invoked before and after this layer renders.
248
242
  */ setRenderable(renderable, layer = 0, hook) {
249
243
  const entry = this._activeRenderables[layer];
250
244
  if (!entry) {
@@ -267,13 +261,13 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
267
261
  entry.hook = hook ?? null;
268
262
  }
269
263
  }
270
- /**
271
- * Reads a file from the current VFS.
272
- *
273
- * @typeParam T - Requested read encoding.
274
- * @param path - File path to read.
275
- * @param encoding - Optional read encoding. Defaults to `binary`.
276
- * @returns The file content, or `null` when the read fails.
264
+ /**
265
+ * Reads a file from the current VFS.
266
+ *
267
+ * @typeParam T - Requested read encoding.
268
+ * @param path - File path to read.
269
+ * @param encoding - Optional read encoding. Defaults to `binary`.
270
+ * @returns The file content, or `null` when the read fails.
277
271
  */ async readFile(path, encoding) {
278
272
  try {
279
273
  const content = await this.VFS.readFile(path, {
@@ -285,14 +279,14 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
285
279
  return null;
286
280
  }
287
281
  }
288
- /**
289
- * Starts the runtime by optionally showing a splash screen, running a startup script,
290
- * and loading the startup scene.
291
- *
292
- * @param startupScene - Optional scene path rendered on layer `0` after startup completes.
293
- * @param splashScreen - Optional scene path rendered on a temporary splash layer during startup.
294
- * @param startupScript - Optional startup script module path. A trailing `.ts` or `.js`
295
- * extension is removed before loading.
282
+ /**
283
+ * Starts the runtime by optionally showing a splash screen, running a startup script,
284
+ * and loading the startup scene.
285
+ *
286
+ * @param startupScene - Optional scene path rendered on layer `0` after startup completes.
287
+ * @param splashScreen - Optional scene path rendered on a temporary splash layer during startup.
288
+ * @param startupScript - Optional startup script module path. A trailing `.ts` or `.js`
289
+ * extension is removed before loading.
296
290
  */ async startup(startupScene, splashScreen, startupScript) {
297
291
  const splashScreenLayer = 9999;
298
292
  if (splashScreen) {
@@ -311,11 +305,11 @@ import { MSDFTextAtlasManager } from '../text/runtime/msdf_text_atlas_manager.js
311
305
  }
312
306
  this.setRenderable(null, splashScreenLayer);
313
307
  }
314
- /**
315
- * Renders all active render layers.
316
- *
317
- * Each layer's `beforeRender` hook can return `false` to skip rendering that layer.
318
- * The `afterRender` hook is invoked after the render attempt.
308
+ /**
309
+ * Renders all active render layers.
310
+ *
311
+ * Each layer's `beforeRender` hook can return `false` to skip rendering that layer.
312
+ * The `afterRender` hook is invoked after the render attempt.
319
313
  */ render() {
320
314
  this._activeRenderables.forEach((info)=>{
321
315
  if (!info.renderable) {
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sources":["../../src/app/engine.ts"],"sourcesContent":["import type { GenericConstructor, IDisposable, Nullable, ReadOptions } from '@zephyr3d/base';\r\nimport { MemoryFS, objectEntries } from '@zephyr3d/base';\r\nimport { DRef } from '@zephyr3d/base';\r\nimport { HttpFS, type VFS } from '@zephyr3d/base';\r\nimport { ScriptingSystem } from './scriptingsystem';\r\nimport type { Host } from './scriptingsystem';\r\nimport type { RuntimeScript, RuntimeScriptConfig } from './runtimescript';\r\nimport { ResourceManager } from '../utility/serialization/manager';\r\nimport type { Scene } from '../scene';\r\nimport {\r\n BoxShape,\r\n CapsuleShape,\r\n CylinderShape,\r\n PlaneShape,\r\n SphereShape,\r\n TetrahedronShape,\r\n TorusShape\r\n} from '../shapes';\r\nimport {\r\n BlinnMaterial,\r\n LambertMaterial,\r\n PBRMetallicRoughnessMaterial,\r\n PBRSpecularGlossinessMaterial,\r\n UnlitMaterial\r\n} from '../material';\r\nimport { StandardSpriteMaterial } from '../material/sprite_std';\r\nimport { ScreenAdapter } from './screen';\r\nimport { MSDFTextAtlasManager } from '../text/runtime';\r\n\r\n/**\r\n * Interface for objects that can be rendered.\r\n *\r\n * @public\r\n */\r\nexport interface IRenderable extends IDisposable {\r\n render(): void;\r\n}\r\n\r\nexport type RenderFunc = () => void;\r\n\r\n/**\r\n * Interface for render hooks to customize rendering behavior.\r\n *\r\n * @public\r\n */\r\nexport interface IRenderHook {\r\n // If presents, called before rendering the renderable. Return `false` to skip rendering.\r\n beforeRender?: (renderable: any) => boolean | void;\r\n // If presents, called after rendering the renderable.\r\n afterRender?: (renderable: any) => void;\r\n}\r\n\r\n/**\r\n * Core engine class managing scripting, serialization, and rendering.\r\n *\r\n * Responsibilities:\r\n * - Manages a {@link ScriptingSystem} for dynamic script attachment and lifecycle.\r\n * - Manages a {@link ResourceManager} for loading scenes and assets.\r\n * - Maintains a list of active renderable objects to be rendered each frame.\r\n * - Provides methods to attach/detach scripts, update scripts, load scenes, and read files.\r\n * - Supports enabling/disabling of runtime operations.\r\n *\r\n * @remarks\r\n * The engine can be configured with a virtual file system (VFS) and script root path.\r\n * It exposes methods to manage scripts on host objects, update scripts each frame,\r\n * load scenes from files, and render active objects.\r\n *\r\n * @public\r\n */\r\nexport class Engine {\r\n private _builtinsVFS: Nullable<MemoryFS>;\r\n private _scriptingSystem: ScriptingSystem;\r\n private _resourceManager: ResourceManager;\r\n private _msdfTextAtlasManager: MSDFTextAtlasManager;\r\n private _enabled: boolean;\r\n private _screen: ScreenAdapter;\r\n protected _activeRenderables: {\r\n renderable: Nullable<RenderFunc> | DRef<IRenderable>;\r\n hook: Nullable<IRenderHook>;\r\n }[];\r\n private _loadingScenes: Partial<Record<string, Promise<Nullable<Scene>>>>;\r\n /**\r\n * Creates a new runtime manager.\r\n *\r\n * @param VFS - Optional virtual file system passed to the internal {@link ScriptingSystem}.\r\n * @param scriptsRoot - Optional scripts root path within the VFS. Defaults as in `ScriptingSystem`.\r\n * @param enabled - Whether runtime operations are active. Defaults to `true`.\r\n */\r\n constructor(VFS?: VFS, scriptsRoot?: string, enabled?: boolean) {\r\n VFS = VFS ?? new HttpFS('./');\r\n this._builtinsVFS = null;\r\n this._scriptingSystem = new ScriptingSystem({ VFS, scriptsRoot });\r\n this._resourceManager = new ResourceManager(VFS);\r\n this._msdfTextAtlasManager = new MSDFTextAtlasManager();\r\n this._enabled = enabled ?? true;\r\n this._activeRenderables = [];\r\n this._loadingScenes = {};\r\n this._screen = new ScreenAdapter();\r\n }\r\n /**\r\n * Exposes the instance of {@link ScriptingSystem}.\r\n */\r\n get scriptingSystem() {\r\n return this._scriptingSystem;\r\n }\r\n /**\r\n * Exposes the virtual file system used by the underlying {@link ScriptingSystem}'s registry.\r\n */\r\n get VFS() {\r\n return this._scriptingSystem.registry.VFS;\r\n }\r\n /**\r\n * Replaces the virtual file system used by the engine.\r\n *\r\n * The previous resource manager VFS is closed, the scripting registry is updated,\r\n * and built-in assets are remounted on the new VFS.\r\n *\r\n * @param vfs - New virtual file system.\r\n */\r\n set VFS(vfs: VFS) {\r\n if (vfs !== this._resourceManager.VFS) {\r\n this._resourceManager.VFS?.close();\r\n this._resourceManager.VFS = vfs;\r\n this._scriptingSystem.registry.VFS = vfs;\r\n this.ensureBuiltinVFS();\r\n }\r\n }\r\n /**\r\n * Exposes the instance of {@link ResourceManager}.\r\n */\r\n get resourceManager() {\r\n return this._resourceManager;\r\n }\r\n /**\r\n * Exposes the shared runtime MSDF text atlas manager.\r\n */\r\n get msdfTextAtlasManager() {\r\n return this._msdfTextAtlasManager;\r\n }\r\n /**\r\n * Releases a loaded font asset from the resource cache and disposes its shared MSDF atlas textures.\r\n *\r\n * Existing scene nodes that still reference this font asset are not updated automatically.\r\n * Call this only after you have stopped using the font, or when you intentionally want it to rebuild later.\r\n *\r\n * @param font - The loaded font asset path to release.\r\n * @returns `true` if either the atlas cache or the font cache had an entry to remove.\r\n */\r\n releaseFontAsset(font: string) {\r\n const fontAsset = this._resourceManager.getFontAsset(font);\r\n if (!fontAsset) {\r\n return false;\r\n }\r\n const atlasReleased = this._msdfTextAtlasManager.releaseAtlas(fontAsset);\r\n const fontReleased = this._resourceManager.releaseFontAsset(fontAsset);\r\n return atlasReleased || fontReleased;\r\n }\r\n /**\r\n * Configures the MSDF atlas for a given font asset, creating or replacing the atlas as needed.\r\n *\r\n * This is useful to customize the glyph size, atlas page size, distance range, and padding for MSDF text rendering.\r\n * Existing scene nodes that reference this font asset will use the updated atlas automatically.\r\n *\r\n * @param font - The font asset path to configure the MSDF atlas for.\r\n * @param pageSize - The size of each atlas page in pixels (e.g., 512, 1024).\r\n * @param glyphSize - The size of each glyph in pixels (e.g., 32, 64).\r\n * @param distanceRange - The distance range for MSDF generation. Defaults to 4.\r\n * @param padding - The padding between glyphs in the atlas in pixels. Defaults to 2.\r\n * @returns `true` if the atlas was successfully configured, or `false` if the font asset was not found.\r\n *\r\n * @remarks\r\n * The font asset must be loaded and available in the resource manager for the atlas to be configured.\r\n */\r\n configureMSDFAtlas(\r\n font: string,\r\n pageSize: number,\r\n glyphSize: number,\r\n distanceRange?: number,\r\n padding?: number\r\n ) {\r\n const fontAsset = this._resourceManager.getFontAsset(font);\r\n if (!fontAsset) {\r\n console.warn(`Font asset '${font}' not found for MSDF atlas configuration.`);\r\n return false;\r\n }\r\n this._msdfTextAtlasManager.configureAtlas(fontAsset, pageSize, glyphSize, distanceRange, padding);\r\n return true;\r\n }\r\n /**\r\n * Exposes the active {@link ScreenAdapter}.\r\n */\r\n get screen() {\r\n return this._screen;\r\n }\r\n /** @internal */\r\n async init() {\r\n await this.ensureBuiltinVFS();\r\n }\r\n /**\r\n * Detaches all scripts from all hosts, if enabled.\r\n *\r\n * No-op when `enabled === false`.\r\n */\r\n detachAllScripts() {\r\n if (this._enabled) {\r\n this._scriptingSystem.detachAllScripts();\r\n }\r\n }\r\n /**\r\n * Loads a runtime script class from file\r\n * @param module - file path\r\n * @returns The runtime script class or null\r\n */\r\n async loadRuntimeScriptClass<T extends Host = Host>(\r\n module: string\r\n ): Promise<Nullable<{ url: string; cls: GenericConstructor<RuntimeScript<T>> }>> {\r\n return await this._scriptingSystem.loadRuntimeScriptClass(module);\r\n }\r\n /**\r\n * Attaches a script module to the given host, if enabled.\r\n *\r\n * When disabled, this method resolves to `null` without side effects.\r\n *\r\n * @typeParam T - Host type.\r\n * @param host - Host object to attach the script to.\r\n * @param module - Module identifier to resolve and load.\r\n * @param config - Optional configuration passed to the script instance.\r\n * @returns The `RuntimeScript<T>` instance, or `null` if disabled or on failure.\r\n */\r\n async attachScript<T extends Host>(\r\n host: Nullable<T>,\r\n module: string,\r\n config?: Nullable<RuntimeScriptConfig>\r\n ) {\r\n return this._enabled ? await this._scriptingSystem.attachScript(host, module, config) : null;\r\n }\r\n /**\r\n * Detaches a script from a host, by module ID or instance, if enabled.\r\n *\r\n * No-op when disabled.\r\n *\r\n * @typeParam T - Host type.\r\n * @param host - Host to detach from.\r\n * @param idOrInstance - Target script by module ID or instance reference.\r\n */\r\n detachScript<T extends Host>(host: T, idOrInstance: string | RuntimeScript<T>) {\r\n if (this._enabled) {\r\n this._scriptingSystem.detachScript(host, idOrInstance);\r\n }\r\n }\r\n /**\r\n * Gets all scripts attached to a host.\r\n *\r\n * Delegates to {@link ScriptingSystem.getScriptObjects}.\r\n *\r\n * @typeParam T - Expected script type.\r\n * @param host - Host object to query.\r\n * @returns Script instances attached to the host, or an empty array.\r\n */\r\n getScriptObjects<T extends RuntimeScript<any>>(host: unknown) {\r\n return this._scriptingSystem.getScriptObjects(host) as T[];\r\n }\r\n /**\r\n * Ticks all attached scripts by calling their `onUpdate` hooks, if enabled.\r\n *\r\n * @param deltaTime - Time since last update in Seconds.\r\n * @param elapsedTime - Total elapsed time in Seconds.\r\n */\r\n update(deltaTime: number, elapsedTime: number) {\r\n if (this._enabled) {\r\n this._scriptingSystem.update(deltaTime, elapsedTime);\r\n }\r\n }\r\n /**\r\n * Loads a scene from a file path.\r\n *\r\n * Concurrent requests for the same normalized path share the same loading promise.\r\n * Scripts declared on the scene and its nodes are attached after the scene is loaded.\r\n *\r\n * @param path - Scene file path in the current VFS.\r\n * @returns The loaded scene, or `null` when loading fails.\r\n */\r\n async loadSceneFromFile(path: string) {\r\n path = this.VFS.normalizePath(path);\r\n if (!this._loadingScenes[path]) {\r\n this._loadingScenes[path] = this._loadScene(path);\r\n }\r\n return this._loadingScenes[path]!;\r\n }\r\n /**\r\n * Sets or clears the renderable for a render layer.\r\n *\r\n * Passing `null` clears the layer. Object renderables are held through a strong reference wrapper,\r\n * while render functions are stored directly.\r\n *\r\n * @param renderable - Renderable object or render function to assign, or `null` to clear.\r\n * @param layer - Render layer index. Defaults to `0`.\r\n * @param hook - Optional render hook invoked before and after this layer renders.\r\n */\r\n setRenderable(renderable: Nullable<IRenderable | RenderFunc>, layer = 0, hook?: IRenderHook) {\r\n const entry = this._activeRenderables[layer];\r\n if (!entry) {\r\n this._activeRenderables[layer] = {\r\n renderable: renderable\r\n ? typeof renderable === 'function'\r\n ? renderable\r\n : new DRef<IRenderable>(renderable)\r\n : null,\r\n hook: hook ?? null\r\n };\r\n } else {\r\n if (entry.renderable) {\r\n if (entry.renderable instanceof DRef) {\r\n entry.renderable.dispose();\r\n }\r\n entry.renderable = null;\r\n }\r\n if (typeof renderable === 'function') {\r\n entry.renderable = renderable;\r\n } else if (renderable) {\r\n entry.renderable = new DRef<IRenderable>(renderable);\r\n }\r\n entry.hook = hook ?? null;\r\n }\r\n }\r\n /**\r\n * Reads a file from the current VFS.\r\n *\r\n * @typeParam T - Requested read encoding.\r\n * @param path - File path to read.\r\n * @param encoding - Optional read encoding. Defaults to `binary`.\r\n * @returns The file content, or `null` when the read fails.\r\n */\r\n async readFile<T extends ReadOptions['encoding'] = 'binary'>(path: string, encoding?: T) {\r\n try {\r\n const content = await this.VFS.readFile(path, { encoding: encoding ?? 'binary' });\r\n return content as T extends 'binary' ? ArrayBuffer : string;\r\n } catch (err) {\r\n console.error(`Read file '${path}' failed: ${err}`);\r\n return null;\r\n }\r\n }\r\n /**\r\n * Starts the runtime by optionally showing a splash screen, running a startup script,\r\n * and loading the startup scene.\r\n *\r\n * @param startupScene - Optional scene path rendered on layer `0` after startup completes.\r\n * @param splashScreen - Optional scene path rendered on a temporary splash layer during startup.\r\n * @param startupScript - Optional startup script module path. A trailing `.ts` or `.js`\r\n * extension is removed before loading.\r\n */\r\n async startup(\r\n startupScene?: Nullable<string>,\r\n splashScreen?: Nullable<string>,\r\n startupScript?: Nullable<string>\r\n ) {\r\n const splashScreenLayer = 9999;\r\n if (splashScreen) {\r\n const splashScreenScene = await this.loadSceneFromFile(splashScreen);\r\n if (splashScreenScene) {\r\n this.setRenderable(splashScreenScene, splashScreenLayer);\r\n }\r\n }\r\n if (startupScript) {\r\n const path =\r\n startupScript.toLowerCase().endsWith('.ts') || startupScript.toLowerCase().endsWith('.js')\r\n ? startupScript.slice(0, -3)\r\n : startupScript;\r\n await this.attachScript(null, path);\r\n }\r\n if (startupScene) {\r\n const scene = await this.loadSceneFromFile(startupScene);\r\n this.setRenderable(scene, 0);\r\n }\r\n this.setRenderable(null, splashScreenLayer);\r\n }\r\n /**\r\n * Renders all active render layers.\r\n *\r\n * Each layer's `beforeRender` hook can return `false` to skip rendering that layer.\r\n * The `afterRender` hook is invoked after the render attempt.\r\n */\r\n render() {\r\n this._activeRenderables.forEach((info) => {\r\n if (!info.renderable) {\r\n return;\r\n }\r\n const render = info.hook?.beforeRender\r\n ? (info.hook.beforeRender(\r\n typeof info.renderable === 'function' ? info.renderable : info.renderable.get()\r\n ) ?? true)\r\n : true;\r\n if (render) {\r\n if (typeof info.renderable === 'function') {\r\n info.renderable();\r\n } else {\r\n info.renderable.get()?.render();\r\n }\r\n }\r\n if (info.hook?.afterRender) {\r\n info.hook.afterRender(\r\n typeof info.renderable === 'function' ? info.renderable : info.renderable.get()\r\n );\r\n }\r\n });\r\n }\r\n private async ensureBuiltinVFS() {\r\n if (!this._builtinsVFS) {\r\n this._builtinsVFS = await this.createBuiltinVFS();\r\n }\r\n this.VFS.unmount('/assets/@builtins');\r\n this.VFS.mount('/assets/@builtins', this._builtinsVFS);\r\n }\r\n private async createBuiltinVFS() {\r\n const fs = new MemoryFS();\r\n const shapeClsMap = {\r\n '/primitives/box.zmsh': BoxShape,\r\n '/primitives/sphere.zmsh': SphereShape,\r\n '/primitives/cylinder.zmsh': CylinderShape,\r\n '/primitives/plane.zmsh': PlaneShape,\r\n '/primitives/torus.zmsh': TorusShape,\r\n '/primitives/tetrahedron.zmsh': TetrahedronShape,\r\n '/primitives/capsule.zmsh': CapsuleShape,\r\n '/materials/unlit.zmtl': UnlitMaterial,\r\n '/materials/lambert.zmtl': LambertMaterial,\r\n '/materials/blinnphong.zmtl': BlinnMaterial,\r\n '/materials/pbr_metallic_roughness.zmtl': PBRMetallicRoughnessMaterial,\r\n '/materials/pbr_specular_glossiness.zmtl': PBRSpecularGlossinessMaterial,\r\n '/materials/sprite_std.zmtl': StandardSpriteMaterial\r\n } as const;\r\n for (const [key] of objectEntries(shapeClsMap)) {\r\n const obj = new shapeClsMap[key]();\r\n await this.writeSerializableObject(fs, 'Default', obj, key);\r\n obj.dispose();\r\n }\r\n fs.readOnly = true;\r\n return fs;\r\n }\r\n private async writeSerializableObject(VFS: VFS, type: string, obj: any, path: string) {\r\n try {\r\n const data = await this.resourceManager.serializeObject(obj);\r\n const content = JSON.stringify({ type, data }, null, 2);\r\n await VFS.writeFile(path, content, { encoding: 'utf8', create: true });\r\n } catch (err) {\r\n console.error(`Write file '${path}' failed: ${err}`);\r\n }\r\n }\r\n private async _loadScene(path: string) {\r\n try {\r\n const scene = await this._resourceManager.loadScene(path);\r\n if (scene) {\r\n const sceneScripts =\r\n scene.scripts.length > 0\r\n ? scene.scripts\r\n : scene.script\r\n ? [{ script: scene.script, config: scene.scriptConfig }]\r\n : [];\r\n for (const attachment of sceneScripts) {\r\n if (!attachment.script) {\r\n continue;\r\n }\r\n try {\r\n await this.attachScript(\r\n scene,\r\n attachment.script,\r\n (attachment.config ?? null) as RuntimeScriptConfig | null\r\n );\r\n } catch (err) {\r\n console.error(`Attach script failed: ${err}`);\r\n }\r\n }\r\n const nodes: (typeof scene.rootNode)[] = [];\r\n scene.rootNode.iterate((node) => {\r\n nodes.push(node);\r\n });\r\n const attachTasks = nodes.map(async (node) => {\r\n const attachments =\r\n node.scripts.length > 0\r\n ? node.scripts\r\n : node.script\r\n ? [{ script: node.script, config: node.scriptConfig }]\r\n : [];\r\n for (const attachment of attachments) {\r\n if (!attachment.script) {\r\n continue;\r\n }\r\n try {\r\n await this.attachScript(\r\n node,\r\n attachment.script,\r\n (attachment.config ?? null) as RuntimeScriptConfig | null\r\n );\r\n } catch (err) {\r\n console.error(`Attach script failed: ${err}`);\r\n }\r\n }\r\n });\r\n if (attachTasks.length > 0) {\r\n await Promise.allSettled(attachTasks);\r\n }\r\n }\r\n return scene;\r\n } catch (err) {\r\n console.error(`Load scene from '${path}' failed: ${err}`);\r\n return null;\r\n }\r\n }\r\n}\r\n\r\nexport { MSDFTextAtlasManager };\r\n"],"names":["Engine","_builtinsVFS","_scriptingSystem","_resourceManager","_msdfTextAtlasManager","_enabled","_screen","_activeRenderables","_loadingScenes","VFS","scriptsRoot","enabled","HttpFS","ScriptingSystem","ResourceManager","MSDFTextAtlasManager","ScreenAdapter","scriptingSystem","registry","vfs","close","ensureBuiltinVFS","resourceManager","msdfTextAtlasManager","releaseFontAsset","font","fontAsset","getFontAsset","atlasReleased","releaseAtlas","fontReleased","configureMSDFAtlas","pageSize","glyphSize","distanceRange","padding","console","warn","configureAtlas","screen","init","detachAllScripts","loadRuntimeScriptClass","module","attachScript","host","config","detachScript","idOrInstance","getScriptObjects","update","deltaTime","elapsedTime","loadSceneFromFile","path","normalizePath","_loadScene","setRenderable","renderable","layer","hook","entry","DRef","dispose","readFile","encoding","content","err","error","startup","startupScene","splashScreen","startupScript","splashScreenLayer","splashScreenScene","toLowerCase","endsWith","slice","scene","render","forEach","info","beforeRender","get","afterRender","createBuiltinVFS","unmount","mount","fs","MemoryFS","shapeClsMap","BoxShape","SphereShape","CylinderShape","PlaneShape","TorusShape","TetrahedronShape","CapsuleShape","UnlitMaterial","LambertMaterial","BlinnMaterial","PBRMetallicRoughnessMaterial","PBRSpecularGlossinessMaterial","StandardSpriteMaterial","key","objectEntries","obj","writeSerializableObject","readOnly","type","data","serializeObject","JSON","stringify","writeFile","create","loadScene","sceneScripts","scripts","length","script","scriptConfig","attachment","nodes","rootNode","iterate","node","push","attachTasks","map","attachments","Promise","allSettled"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMA,MAAAA,CAAAA;IACHC,YAAiC;IACjCC,gBAAkC;IAClCC,gBAAkC;IAClCC,qBAA4C;IAC5CC,QAAkB;IAClBC,OAAuB;IACrB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WACJJ,GAAAA,IAAAA,CAAKR,OAAO,CAACC,MAAM,GAAG,CAClBO,GAAAA,IAAAA,CAAKR,OAAO,GACZQ,IAAKN,CAAAA,MAAM,GACT;AAAC,wBAAA;AAAEA,4BAAAA,MAAAA,EAAQM,KAAKN,MAAM;AAAE1E,4BAAAA,MAAAA,EAAQgF,KAAKL;AAAa;AAAE,qBAAA,GACpD,EAAE;oBACV,KAAK,MAAMC,cAAcQ,WAAa,CAAA;wBACpC,IAAI,CAACR,UAAWF,CAAAA,MAAM,EAAE;AACtB,4BAAA;AACF;wBACA,IAAI;4BACF,MAAM,IAAI,CAAC5E,YAAY,CACrBkF,IAAAA,EACAJ,WAAWF,MAAM,EAChBE,UAAW5E,CAAAA,MAAM,IAAI,IAAA,CAAA;AAE1B,yBAAA,CAAE,OAAOqB,GAAK,EAAA;AACZ/B,4BAAAA,OAAAA,CAAQgC,KAAK,CAAC,CAAC,sBAAsB,EAAED,GAAK,CAAA,CAAA,CAAA;AAC9C;AACF;AACF,iBAAA,CAAA;gBACA,IAAI6D,WAAAA,CAAYT,MAAM,GAAG,CAAG,EAAA;oBAC1B,MAAMY,OAAAA,CAAQC,UAAU,CAACJ,WAAAA,CAAAA;AAC3B;AACF;YACA,OAAOlD,KAAAA;AACT,SAAA,CAAE,OAAOX,GAAK,EAAA;YACZ/B,OAAQgC,CAAAA,KAAK,CAAC,CAAC,iBAAiB,EAAEd,IAAK,CAAA,UAAU,EAAEa,GAAK,CAAA,CAAA,CAAA;YACxD,OAAO,IAAA;AACT;AACF;AACF;;;;"}
1
+ {"version":3,"file":"engine.js","sources":["../../src/app/engine.ts"],"sourcesContent":["import type { GenericConstructor, IDisposable, Nullable, ReadOptions } from '@zephyr3d/base';\nimport { MemoryFS, objectEntries } from '@zephyr3d/base';\nimport { DRef } from '@zephyr3d/base';\nimport { HttpFS, type VFS } from '@zephyr3d/base';\nimport { ScriptingSystem } from './scriptingsystem';\nimport type { Host } from './scriptingsystem';\nimport type { RuntimeScript, RuntimeScriptConfig } from './runtimescript';\nimport { ResourceManager } from '../utility/serialization/manager';\nimport type { Scene } from '../scene';\nimport {\n BoxShape,\n CapsuleShape,\n CylinderShape,\n PlaneShape,\n SphereShape,\n TetrahedronShape,\n TorusShape\n} from '../shapes';\nimport {\n BlinnMaterial,\n LambertMaterial,\n PBRMetallicRoughnessMaterial,\n PBRSpecularGlossinessMaterial,\n UnlitMaterial\n} from '../material';\nimport { StandardSpriteMaterial } from '../material/sprite_std';\nimport { ScreenAdapter } from './screen';\nimport { MSDFTextAtlasManager } from '../text/runtime';\n\n/**\n * Interface for objects that can be rendered.\n *\n * @public\n */\nexport interface IRenderable extends IDisposable {\n render(): void;\n}\n\n/**\n * Type for render functions that can be registered as renderables.\n *\n * @public\n */\nexport type RenderFunc = () => void;\n\n/**\n * Interface for render hooks to customize rendering behavior.\n *\n * @public\n */\nexport interface IRenderHook {\n // If presents, called before rendering the renderable. Return `false` to skip rendering.\n beforeRender?: (renderable: any) => boolean | void;\n // If presents, called after rendering the renderable.\n afterRender?: (renderable: any) => void;\n}\n\n/**\n * Core engine class managing scripting, serialization, and rendering.\n *\n * Responsibilities:\n * - Manages a {@link ScriptingSystem} for dynamic script attachment and lifecycle.\n * - Manages a {@link ResourceManager} for loading scenes and assets.\n * - Maintains a list of active renderable objects to be rendered each frame.\n * - Provides methods to attach/detach scripts, update scripts, load scenes, and read files.\n * - Supports enabling/disabling of runtime operations.\n *\n * @remarks\n * The engine can be configured with a virtual file system (VFS) and script root path.\n * It exposes methods to manage scripts on host objects, update scripts each frame,\n * load scenes from files, and render active objects.\n *\n * @public\n */\nexport class Engine {\n private _builtinsVFS: Nullable<MemoryFS>;\n private _scriptingSystem: ScriptingSystem;\n private _resourceManager: ResourceManager;\n private _msdfTextAtlasManager: MSDFTextAtlasManager;\n private _enabled: boolean;\n private _screen: ScreenAdapter;\n protected _activeRenderables: {\n renderable: Nullable<RenderFunc> | DRef<IRenderable>;\n hook: Nullable<IRenderHook>;\n }[];\n private _loadingScenes: Partial<Record<string, Promise<Nullable<Scene>>>>;\n /**\n * Creates a new runtime manager.\n *\n * @param VFS - Optional virtual file system passed to the internal {@link ScriptingSystem}.\n * @param scriptsRoot - Optional scripts root path within the VFS. Defaults as in `ScriptingSystem`.\n * @param enabled - Whether runtime operations are active. Defaults to `true`.\n */\n constructor(VFS?: VFS, scriptsRoot?: string, enabled?: boolean) {\n VFS = VFS ?? new HttpFS('./');\n this._builtinsVFS = null;\n this._scriptingSystem = new ScriptingSystem({ VFS, scriptsRoot });\n this._resourceManager = new ResourceManager(VFS);\n this._msdfTextAtlasManager = new MSDFTextAtlasManager();\n this._enabled = enabled ?? true;\n this._activeRenderables = [];\n this._loadingScenes = {};\n this._screen = new ScreenAdapter();\n }\n /**\n * Exposes the instance of {@link ScriptingSystem}.\n */\n get scriptingSystem() {\n return this._scriptingSystem;\n }\n /**\n * Exposes the virtual file system used by the underlying {@link ScriptingSystem}'s registry.\n */\n get VFS() {\n return this._scriptingSystem.registry.VFS;\n }\n set VFS(vfs: VFS) {\n if (vfs !== this._resourceManager.VFS) {\n this._resourceManager.VFS?.close();\n this._resourceManager.VFS = vfs;\n this._scriptingSystem.registry.VFS = vfs;\n this.ensureBuiltinVFS();\n }\n }\n /**\n * Exposes the instance of {@link ResourceManager}.\n */\n get resourceManager() {\n return this._resourceManager;\n }\n /**\n * Exposes the shared runtime MSDF text atlas manager.\n */\n get msdfTextAtlasManager() {\n return this._msdfTextAtlasManager;\n }\n /**\n * Releases a loaded font asset from the resource cache and disposes its shared MSDF atlas textures.\n *\n * Existing scene nodes that still reference this font asset are not updated automatically.\n * Call this only after you have stopped using the font, or when you intentionally want it to rebuild later.\n *\n * @param font - The loaded font asset path to release.\n * @returns `true` if either the atlas cache or the font cache had an entry to remove.\n */\n releaseFontAsset(font: string) {\n const fontAsset = this._resourceManager.getFontAsset(font);\n if (!fontAsset) {\n return false;\n }\n const atlasReleased = this._msdfTextAtlasManager.releaseAtlas(fontAsset);\n const fontReleased = this._resourceManager.releaseFontAsset(fontAsset);\n return atlasReleased || fontReleased;\n }\n /**\n * Configures the MSDF atlas for a given font asset, creating or replacing the atlas as needed.\n *\n * This is useful to customize the glyph size, atlas page size, distance range, and padding for MSDF text rendering.\n * Existing scene nodes that reference this font asset will use the updated atlas automatically.\n *\n * @param font - The font asset path to configure the MSDF atlas for.\n * @param pageSize - The size of each atlas page in pixels (e.g., 512, 1024).\n * @param glyphSize - The size of each glyph in pixels (e.g., 32, 64).\n * @param distanceRange - The distance range for MSDF generation. Defaults to 4.\n * @param padding - The padding between glyphs in the atlas in pixels. Defaults to 2.\n * @returns `true` if the atlas was successfully configured, or `false` if the font asset was not found.\n *\n * @remarks\n * The font asset must be loaded and available in the resource manager for the atlas to be configured.\n */\n configureMSDFAtlas(\n font: string,\n pageSize: number,\n glyphSize: number,\n distanceRange?: number,\n padding?: number\n ) {\n const fontAsset = this._resourceManager.getFontAsset(font);\n if (!fontAsset) {\n console.warn(`Font asset '${font}' not found for MSDF atlas configuration.`);\n return false;\n }\n this._msdfTextAtlasManager.configureAtlas(fontAsset, pageSize, glyphSize, distanceRange, padding);\n return true;\n }\n /**\n * Exposes the active {@link ScreenAdapter}.\n */\n get screen() {\n return this._screen;\n }\n /** @internal */\n async init() {\n await this.ensureBuiltinVFS();\n }\n /**\n * Detaches all scripts from all hosts, if enabled.\n *\n * No-op when `enabled === false`.\n */\n detachAllScripts() {\n if (this._enabled) {\n this._scriptingSystem.detachAllScripts();\n }\n }\n /**\n * Loads a runtime script class from file\n * @param module - file path\n * @returns The runtime script class or null\n */\n async loadRuntimeScriptClass<T extends Host = Host>(\n module: string\n ): Promise<Nullable<{ url: string; cls: GenericConstructor<RuntimeScript<T>> }>> {\n return await this._scriptingSystem.loadRuntimeScriptClass(module);\n }\n /**\n * Attaches a script module to the given host, if enabled.\n *\n * When disabled, this method resolves to `null` without side effects.\n *\n * @typeParam T - Host type.\n * @param host - Host object to attach the script to.\n * @param module - Module identifier to resolve and load.\n * @param config - Optional configuration passed to the script instance.\n * @returns The `RuntimeScript<T>` instance, or `null` if disabled or on failure.\n */\n async attachScript<T extends Host>(\n host: Nullable<T>,\n module: string,\n config?: Nullable<RuntimeScriptConfig>\n ) {\n return this._enabled ? await this._scriptingSystem.attachScript(host, module, config) : null;\n }\n /**\n * Detaches a script from a host, by module ID or instance, if enabled.\n *\n * No-op when disabled.\n *\n * @typeParam T - Host type.\n * @param host - Host to detach from.\n * @param idOrInstance - Target script by module ID or instance reference.\n */\n detachScript<T extends Host>(host: T, idOrInstance: string | RuntimeScript<T>) {\n if (this._enabled) {\n this._scriptingSystem.detachScript(host, idOrInstance);\n }\n }\n /**\n * Gets all scripts attached to a host.\n *\n * Delegates to {@link ScriptingSystem.getScriptObjects}.\n *\n * @typeParam T - Expected script type.\n * @param host - Host object to query.\n * @returns Script instances attached to the host, or an empty array.\n */\n getScriptObjects<T extends RuntimeScript<any>>(host: unknown) {\n return this._scriptingSystem.getScriptObjects(host) as T[];\n }\n /**\n * Ticks all attached scripts by calling their `onUpdate` hooks, if enabled.\n *\n * @param deltaTime - Time since last update in Seconds.\n * @param elapsedTime - Total elapsed time in Seconds.\n */\n update(deltaTime: number, elapsedTime: number) {\n if (this._enabled) {\n this._scriptingSystem.update(deltaTime, elapsedTime);\n }\n }\n /**\n * Loads a scene from a file path.\n *\n * Concurrent requests for the same normalized path share the same loading promise.\n * Scripts declared on the scene and its nodes are attached after the scene is loaded.\n *\n * @param path - Scene file path in the current VFS.\n * @returns The loaded scene, or `null` when loading fails.\n */\n async loadSceneFromFile(path: string) {\n path = this.VFS.normalizePath(path);\n if (!this._loadingScenes[path]) {\n this._loadingScenes[path] = this._loadScene(path);\n }\n return this._loadingScenes[path]!;\n }\n /**\n * Sets or clears the renderable for a render layer.\n *\n * Passing `null` clears the layer. Object renderables are held through a strong reference wrapper,\n * while render functions are stored directly.\n *\n * @param renderable - Renderable object or render function to assign, or `null` to clear.\n * @param layer - Render layer index. Defaults to `0`.\n * @param hook - Optional render hook invoked before and after this layer renders.\n */\n setRenderable(renderable: Nullable<IRenderable | RenderFunc>, layer = 0, hook?: IRenderHook) {\n const entry = this._activeRenderables[layer];\n if (!entry) {\n this._activeRenderables[layer] = {\n renderable: renderable\n ? typeof renderable === 'function'\n ? renderable\n : new DRef<IRenderable>(renderable)\n : null,\n hook: hook ?? null\n };\n } else {\n if (entry.renderable) {\n if (entry.renderable instanceof DRef) {\n entry.renderable.dispose();\n }\n entry.renderable = null;\n }\n if (typeof renderable === 'function') {\n entry.renderable = renderable;\n } else if (renderable) {\n entry.renderable = new DRef<IRenderable>(renderable);\n }\n entry.hook = hook ?? null;\n }\n }\n /**\n * Reads a file from the current VFS.\n *\n * @typeParam T - Requested read encoding.\n * @param path - File path to read.\n * @param encoding - Optional read encoding. Defaults to `binary`.\n * @returns The file content, or `null` when the read fails.\n */\n async readFile<T extends ReadOptions['encoding'] = 'binary'>(path: string, encoding?: T) {\n try {\n const content = await this.VFS.readFile(path, { encoding: encoding ?? 'binary' });\n return content as T extends 'binary' ? ArrayBuffer : string;\n } catch (err) {\n console.error(`Read file '${path}' failed: ${err}`);\n return null;\n }\n }\n /**\n * Starts the runtime by optionally showing a splash screen, running a startup script,\n * and loading the startup scene.\n *\n * @param startupScene - Optional scene path rendered on layer `0` after startup completes.\n * @param splashScreen - Optional scene path rendered on a temporary splash layer during startup.\n * @param startupScript - Optional startup script module path. A trailing `.ts` or `.js`\n * extension is removed before loading.\n */\n async startup(\n startupScene?: Nullable<string>,\n splashScreen?: Nullable<string>,\n startupScript?: Nullable<string>\n ) {\n const splashScreenLayer = 9999;\n if (splashScreen) {\n const splashScreenScene = await this.loadSceneFromFile(splashScreen);\n if (splashScreenScene) {\n this.setRenderable(splashScreenScene, splashScreenLayer);\n }\n }\n if (startupScript) {\n const path =\n startupScript.toLowerCase().endsWith('.ts') || startupScript.toLowerCase().endsWith('.js')\n ? startupScript.slice(0, -3)\n : startupScript;\n await this.attachScript(null, path);\n }\n if (startupScene) {\n const scene = await this.loadSceneFromFile(startupScene);\n this.setRenderable(scene, 0);\n }\n this.setRenderable(null, splashScreenLayer);\n }\n /**\n * Renders all active render layers.\n *\n * Each layer's `beforeRender` hook can return `false` to skip rendering that layer.\n * The `afterRender` hook is invoked after the render attempt.\n */\n render() {\n this._activeRenderables.forEach((info) => {\n if (!info.renderable) {\n return;\n }\n const render = info.hook?.beforeRender\n ? (info.hook.beforeRender(\n typeof info.renderable === 'function' ? info.renderable : info.renderable.get()\n ) ?? true)\n : true;\n if (render) {\n if (typeof info.renderable === 'function') {\n info.renderable();\n } else {\n info.renderable.get()?.render();\n }\n }\n if (info.hook?.afterRender) {\n info.hook.afterRender(\n typeof info.renderable === 'function' ? info.renderable : info.renderable.get()\n );\n }\n });\n }\n private async ensureBuiltinVFS() {\n if (!this._builtinsVFS) {\n this._builtinsVFS = await this.createBuiltinVFS();\n }\n this.VFS.unmount('/assets/@builtins');\n this.VFS.mount('/assets/@builtins', this._builtinsVFS);\n }\n private async createBuiltinVFS() {\n const fs = new MemoryFS();\n const shapeClsMap = {\n '/primitives/box.zmsh': BoxShape,\n '/primitives/sphere.zmsh': SphereShape,\n '/primitives/cylinder.zmsh': CylinderShape,\n '/primitives/plane.zmsh': PlaneShape,\n '/primitives/torus.zmsh': TorusShape,\n '/primitives/tetrahedron.zmsh': TetrahedronShape,\n '/primitives/capsule.zmsh': CapsuleShape,\n '/materials/unlit.zmtl': UnlitMaterial,\n '/materials/lambert.zmtl': LambertMaterial,\n '/materials/blinnphong.zmtl': BlinnMaterial,\n '/materials/pbr_metallic_roughness.zmtl': PBRMetallicRoughnessMaterial,\n '/materials/pbr_specular_glossiness.zmtl': PBRSpecularGlossinessMaterial,\n '/materials/sprite_std.zmtl': StandardSpriteMaterial\n } as const;\n for (const [key] of objectEntries(shapeClsMap)) {\n const obj = new shapeClsMap[key]();\n await this.writeSerializableObject(fs, 'Default', obj, key);\n obj.dispose();\n }\n fs.readOnly = true;\n return fs;\n }\n private async writeSerializableObject(VFS: VFS, type: string, obj: any, path: string) {\n try {\n const data = await this.resourceManager.serializeObject(obj);\n const content = JSON.stringify({ type, data }, null, 2);\n await VFS.writeFile(path, content, { encoding: 'utf8', create: true });\n } catch (err) {\n console.error(`Write file '${path}' failed: ${err}`);\n }\n }\n private async _loadScene(path: string) {\n try {\n const scene = await this._resourceManager.loadScene(path);\n if (scene) {\n const sceneScripts =\n scene.scripts.length > 0\n ? scene.scripts\n : scene.script\n ? [{ script: scene.script, config: scene.scriptConfig }]\n : [];\n for (const attachment of sceneScripts) {\n if (!attachment.script) {\n continue;\n }\n try {\n await this.attachScript(\n scene,\n attachment.script,\n (attachment.config ?? null) as RuntimeScriptConfig | null\n );\n } catch (err) {\n console.error(`Attach script failed: ${err}`);\n }\n }\n const nodes: (typeof scene.rootNode)[] = [];\n scene.rootNode.iterate((node) => {\n nodes.push(node);\n });\n const attachTasks = nodes.map(async (node) => {\n const attachments =\n node.scripts.length > 0\n ? node.scripts\n : node.script\n ? [{ script: node.script, config: node.scriptConfig }]\n : [];\n for (const attachment of attachments) {\n if (!attachment.script) {\n continue;\n }\n try {\n await this.attachScript(\n node,\n attachment.script,\n (attachment.config ?? null) as RuntimeScriptConfig | null\n );\n } catch (err) {\n console.error(`Attach script failed: ${err}`);\n }\n }\n });\n if (attachTasks.length > 0) {\n await Promise.allSettled(attachTasks);\n }\n }\n return scene;\n } catch (err) {\n console.error(`Load scene from '${path}' failed: ${err}`);\n return null;\n }\n }\n}\n\nexport { MSDFTextAtlasManager };\n"],"names":["Engine","_builtinsVFS","_scriptingSystem","_resourceManager","_msdfTextAtlasManager","_enabled","_screen","_activeRenderables","_loadingScenes","VFS","scriptsRoot","enabled","HttpFS","ScriptingSystem","ResourceManager","MSDFTextAtlasManager","ScreenAdapter","scriptingSystem","registry","vfs","close","ensureBuiltinVFS","resourceManager","msdfTextAtlasManager","releaseFontAsset","font","fontAsset","getFontAsset","atlasReleased","releaseAtlas","fontReleased","configureMSDFAtlas","pageSize","glyphSize","distanceRange","padding","console","warn","configureAtlas","screen","init","detachAllScripts","loadRuntimeScriptClass","module","attachScript","host","config","detachScript","idOrInstance","getScriptObjects","update","deltaTime","elapsedTime","loadSceneFromFile","path","normalizePath","_loadScene","setRenderable","renderable","layer","hook","entry","DRef","dispose","readFile","encoding","content","err","error","startup","startupScene","splashScreen","startupScript","splashScreenLayer","splashScreenScene","toLowerCase","endsWith","slice","scene","render","forEach","info","beforeRender","get","afterRender","createBuiltinVFS","unmount","mount","fs","MemoryFS","shapeClsMap","BoxShape","SphereShape","CylinderShape","PlaneShape","TorusShape","TetrahedronShape","CapsuleShape","UnlitMaterial","LambertMaterial","BlinnMaterial","PBRMetallicRoughnessMaterial","PBRSpecularGlossinessMaterial","StandardSpriteMaterial","key","objectEntries","obj","writeSerializableObject","readOnly","type","data","serializeObject","JSON","stringify","writeFile","create","loadScene","sceneScripts","scripts","length","script","scriptConfig","attachment","nodes","rootNode","iterate","node","push","attachTasks","map","attachments","Promise","allSettled"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMA,MAAAA,CAAAA;IACHC,YAAiC;IACjCC,gBAAkC;IAClCC,gBAAkC;IAClCC,qBAA4C;IAC5CC,QAAkB;IAClBC,OAAuB;IACrBC,kBAGN;IACIC,cAAkE;AAC1E;;;;;;AAMC,MACD,YAAYC,GAAS,EAAEC,WAAoB,EAAEC,OAAiB,CAAE;QAC9DF,GAAMA,GAAAA,GAAAA,IAAO,IAAIG,MAAO,CAAA,IAAA,CAAA;QACxB,IAAI,CAACX,YAAY,GAAG,IAAA;AACpB,QAAA,IAAI,CAACC,gBAAgB,GAAG,IAAIW,eAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKC,YAAAA;AAAY,SAAA,CAAA;AAC/D,QAAA,IAAI,CAACP,gBAAgB,GAAG,IAAIW,eAAgBL,CAAAA,GAAAA,CAAAA;QAC5C,IAAI,CAACL,qBAAqB,GAAG,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