@zephyr3d/scene 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. package/dist/animation/animation.js +4 -33
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +24 -11
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +1 -0
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +0 -1
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/ik/ccd_solver.js +372 -0
  10. package/dist/animation/ik/ccd_solver.js.map +1 -0
  11. package/dist/animation/ik/fabrik_solver.js +399 -0
  12. package/dist/animation/ik/fabrik_solver.js.map +1 -0
  13. package/dist/animation/ik/ik_angle_constraint.js +181 -0
  14. package/dist/animation/ik/ik_angle_constraint.js.map +1 -0
  15. package/dist/animation/ik/ik_chain.js +163 -0
  16. package/dist/animation/ik/ik_chain.js.map +1 -0
  17. package/dist/animation/ik/ik_chain_builder.js +68 -0
  18. package/dist/animation/ik/ik_chain_builder.js.map +1 -0
  19. package/dist/animation/ik/ik_constraint.js +25 -0
  20. package/dist/animation/ik/ik_constraint.js.map +1 -0
  21. package/dist/animation/ik/ik_pole_constraint.js +123 -0
  22. package/dist/animation/ik/ik_pole_constraint.js.map +1 -0
  23. package/dist/animation/ik/ik_solver.js +48 -0
  24. package/dist/animation/ik/ik_solver.js.map +1 -0
  25. package/dist/animation/ik/ik_track.js +96 -0
  26. package/dist/animation/ik/ik_track.js.map +1 -0
  27. package/dist/animation/ik/ik_utils.js +270 -0
  28. package/dist/animation/ik/ik_utils.js.map +1 -0
  29. package/dist/animation/ik/two_bone_ik_solver.js +332 -0
  30. package/dist/animation/ik/two_bone_ik_solver.js.map +1 -0
  31. package/dist/animation/ik_modifier.js +61 -0
  32. package/dist/animation/ik_modifier.js.map +1 -0
  33. package/dist/animation/ik_postprocessor.js +71 -0
  34. package/dist/animation/ik_postprocessor.js.map +1 -0
  35. package/dist/animation/manual_transform_processor.js +156 -0
  36. package/dist/animation/manual_transform_processor.js.map +1 -0
  37. package/dist/animation/morphtarget.js +7 -1
  38. package/dist/animation/morphtarget.js.map +1 -1
  39. package/dist/animation/morphtrack.js +3 -3
  40. package/dist/animation/morphtrack.js.map +1 -1
  41. package/dist/animation/proptrack.js +37 -41
  42. package/dist/animation/proptrack.js.map +1 -1
  43. package/dist/animation/rotationtrack.js +0 -1
  44. package/dist/animation/rotationtrack.js.map +1 -1
  45. package/dist/animation/scaletrack.js +0 -1
  46. package/dist/animation/scaletrack.js.map +1 -1
  47. package/dist/animation/skeleton.js +57 -60
  48. package/dist/animation/skeleton.js.map +1 -1
  49. package/dist/animation/skeleton_modifier.js +38 -0
  50. package/dist/animation/skeleton_modifier.js.map +1 -0
  51. package/dist/animation/skeleton_postprocessor.js +50 -0
  52. package/dist/animation/skeleton_postprocessor.js.map +1 -0
  53. package/dist/animation/spring/multi_chain_spring_system.js +503 -0
  54. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -0
  55. package/dist/animation/spring/spring_chain.js +103 -0
  56. package/dist/animation/spring/spring_chain.js.map +1 -0
  57. package/dist/animation/spring/spring_collider.js +247 -0
  58. package/dist/animation/spring/spring_collider.js.map +1 -0
  59. package/dist/animation/spring/spring_constraint.js +21 -0
  60. package/dist/animation/spring/spring_constraint.js.map +1 -0
  61. package/dist/animation/spring/spring_particle.js +20 -0
  62. package/dist/animation/spring/spring_particle.js.map +1 -0
  63. package/dist/animation/spring/spring_system.js +526 -0
  64. package/dist/animation/spring/spring_system.js.map +1 -0
  65. package/dist/animation/spring_modifier.js +45 -0
  66. package/dist/animation/spring_modifier.js.map +1 -0
  67. package/dist/animation/spring_postprocessor.js +54 -0
  68. package/dist/animation/spring_postprocessor.js.map +1 -0
  69. package/dist/animation/translationtrack.js +0 -1
  70. package/dist/animation/translationtrack.js.map +1 -1
  71. package/dist/app/api.js +13 -4
  72. package/dist/app/api.js.map +1 -1
  73. package/dist/app/app.js +13 -1
  74. package/dist/app/app.js.map +1 -1
  75. package/dist/app/engine.js +33 -45
  76. package/dist/app/engine.js.map +1 -1
  77. package/dist/app/inputmgr.js.map +1 -1
  78. package/dist/app/runtimescript.js.map +1 -1
  79. package/dist/app/screen.js +318 -0
  80. package/dist/app/screen.js.map +1 -0
  81. package/dist/app/scriptingsystem.js +10 -6
  82. package/dist/app/scriptingsystem.js.map +1 -1
  83. package/dist/app/scriptregistry.js +11 -22
  84. package/dist/app/scriptregistry.js.map +1 -1
  85. package/dist/asset/assetmanager.js +79 -58
  86. package/dist/asset/assetmanager.js.map +1 -1
  87. package/dist/asset/builtin.js +5 -5
  88. package/dist/asset/builtin.js.map +1 -1
  89. package/dist/asset/loaders/dds/dds.js +6 -2
  90. package/dist/asset/loaders/dds/dds.js.map +1 -1
  91. package/dist/asset/loaders/dds/dds_loader.js +1 -1
  92. package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
  93. package/dist/asset/loaders/gltf/gltf_loader.js +14 -6
  94. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  95. package/dist/asset/loaders/gltf/helpers.js +6 -2
  96. package/dist/asset/loaders/gltf/helpers.js.map +1 -1
  97. package/dist/asset/loaders/hdr/hdr.js +22 -15
  98. package/dist/asset/loaders/hdr/hdr.js.map +1 -1
  99. package/dist/asset/loaders/image/tga_Loader.js +2 -1
  100. package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
  101. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  102. package/dist/asset/loaders/loader.js +2 -2
  103. package/dist/asset/loaders/loader.js.map +1 -1
  104. package/dist/asset/model.js +9 -5
  105. package/dist/asset/model.js.map +1 -1
  106. package/dist/blitter/bilateralblur.js.map +1 -1
  107. package/dist/blitter/blitter.js +9 -11
  108. package/dist/blitter/blitter.js.map +1 -1
  109. package/dist/blitter/box.js +0 -1
  110. package/dist/blitter/box.js.map +1 -1
  111. package/dist/blitter/copy.js.map +1 -1
  112. package/dist/blitter/gaussianblur.js.map +1 -1
  113. package/dist/camera/base.js +1 -3
  114. package/dist/camera/base.js.map +1 -1
  115. package/dist/camera/camera.js +121 -37
  116. package/dist/camera/camera.js.map +1 -1
  117. package/dist/camera/fps.js +19 -17
  118. package/dist/camera/fps.js.map +1 -1
  119. package/dist/camera/orbit.js +45 -43
  120. package/dist/camera/orbit.js.map +1 -1
  121. package/dist/camera/orthocamera.js +27 -21
  122. package/dist/camera/orthocamera.js.map +1 -1
  123. package/dist/camera/perspectivecamera.js +28 -19
  124. package/dist/camera/perspectivecamera.js.map +1 -1
  125. package/dist/index.d.ts +15802 -15577
  126. package/dist/index.js +33 -11
  127. package/dist/index.js.map +1 -1
  128. package/dist/material/blinn.js.map +1 -1
  129. package/dist/material/grassmaterial.js.map +1 -1
  130. package/dist/material/lambert.js.map +1 -1
  131. package/dist/material/material.js +11 -5
  132. package/dist/material/material.js.map +1 -1
  133. package/dist/material/meshmaterial.js +10 -9
  134. package/dist/material/meshmaterial.js.map +1 -1
  135. package/dist/material/mixins/albedocolor.js.map +1 -1
  136. package/dist/material/mixins/foliage.js.map +1 -1
  137. package/dist/material/mixins/lightmodel/blinnphong.js +66 -4
  138. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  139. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  140. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +7 -0
  141. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  142. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  143. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  144. package/dist/material/mixins/lit.js +3 -3
  145. package/dist/material/mixins/lit.js.map +1 -1
  146. package/dist/material/mixins/pbr/brdf.js.map +1 -1
  147. package/dist/material/mixins/pbr/common.js.map +1 -1
  148. package/dist/material/mixins/texture.js +3 -0
  149. package/dist/material/mixins/texture.js.map +1 -1
  150. package/dist/material/mixins/vertexcolor.js.map +1 -1
  151. package/dist/material/particle.js.map +1 -1
  152. package/dist/material/pbrblueprint.js +180 -22
  153. package/dist/material/pbrblueprint.js.map +1 -1
  154. package/dist/material/pbrmr.js.map +1 -1
  155. package/dist/material/pbrsg.js.map +1 -1
  156. package/dist/material/shader/helper.js +41 -56
  157. package/dist/material/shader/helper.js.map +1 -1
  158. package/dist/material/sprite.js +301 -0
  159. package/dist/material/sprite.js.map +1 -0
  160. package/dist/material/sprite3d.js +301 -0
  161. package/dist/material/sprite3d.js.map +1 -0
  162. package/dist/material/sprite3d_std.js +116 -0
  163. package/dist/material/sprite3d_std.js.map +1 -0
  164. package/dist/material/sprite3dblueprint.js +235 -0
  165. package/dist/material/sprite3dblueprint.js.map +1 -0
  166. package/dist/material/sprite_std.js +116 -0
  167. package/dist/material/sprite_std.js.map +1 -0
  168. package/dist/material/spriteblueprint.js +235 -0
  169. package/dist/material/spriteblueprint.js.map +1 -0
  170. package/dist/material/terrain-cm.js +0 -1
  171. package/dist/material/terrain-cm.js.map +1 -1
  172. package/dist/material/unlit.js.map +1 -1
  173. package/dist/material/water.js.map +1 -1
  174. package/dist/posteffect/bloom.js.map +1 -1
  175. package/dist/posteffect/compositor.js.map +1 -1
  176. package/dist/posteffect/fxaa.js.map +1 -1
  177. package/dist/posteffect/grayscale.js.map +1 -1
  178. package/dist/posteffect/motionblur.js.map +1 -1
  179. package/dist/posteffect/posteffect.js.map +1 -1
  180. package/dist/posteffect/sao.js.map +1 -1
  181. package/dist/posteffect/ssr.js +7 -5
  182. package/dist/posteffect/ssr.js.map +1 -1
  183. package/dist/posteffect/taa.js.map +1 -1
  184. package/dist/posteffect/tonemap.js.map +1 -1
  185. package/dist/render/abuffer_oit.js +8 -6
  186. package/dist/render/abuffer_oit.js.map +1 -1
  187. package/dist/render/clipmap.js +0 -10
  188. package/dist/render/clipmap.js.map +1 -1
  189. package/dist/render/cluster_light.js +4 -4
  190. package/dist/render/cluster_light.js.map +1 -1
  191. package/dist/render/cull_visitor.js +15 -17
  192. package/dist/render/cull_visitor.js.map +1 -1
  193. package/dist/render/depthpass.js +3 -4
  194. package/dist/render/depthpass.js.map +1 -1
  195. package/dist/render/drawable.js +15 -0
  196. package/dist/render/drawable.js.map +1 -0
  197. package/dist/render/drawable_mixin.js +8 -4
  198. package/dist/render/drawable_mixin.js.map +1 -1
  199. package/dist/render/envlight.js.map +1 -1
  200. package/dist/render/fbm_wavegenerator.js +3 -1
  201. package/dist/render/fbm_wavegenerator.js.map +1 -1
  202. package/dist/render/fft_wavegenerator.js +67 -64
  203. package/dist/render/fft_wavegenerator.js.map +1 -1
  204. package/dist/render/fullscreenquad.js.map +1 -1
  205. package/dist/render/gerstner_wavegenerator.js +3 -1
  206. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  207. package/dist/render/globalbindgroup_allocator.js +3 -1
  208. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  209. package/dist/render/hzb.js +1 -2
  210. package/dist/render/hzb.js.map +1 -1
  211. package/dist/render/lightpass.js +13 -13
  212. package/dist/render/lightpass.js.map +1 -1
  213. package/dist/render/objectcolorpass.js +4 -7
  214. package/dist/render/objectcolorpass.js.map +1 -1
  215. package/dist/render/primitive.js +4 -5
  216. package/dist/render/primitive.js.map +1 -1
  217. package/dist/render/render_queue.js +10 -5
  218. package/dist/render/render_queue.js.map +1 -1
  219. package/dist/render/renderer.js +16 -22
  220. package/dist/render/renderer.js.map +1 -1
  221. package/dist/render/renderpass.js +27 -52
  222. package/dist/render/renderpass.js.map +1 -1
  223. package/dist/render/rendertarget.js +5 -0
  224. package/dist/render/rendertarget.js.map +1 -0
  225. package/dist/render/screenrendertarget.js +56 -0
  226. package/dist/render/screenrendertarget.js.map +1 -0
  227. package/dist/render/shadowmap_pass.js +4 -5
  228. package/dist/render/shadowmap_pass.js.map +1 -1
  229. package/dist/render/sky.js +16 -14
  230. package/dist/render/sky.js.map +1 -1
  231. package/dist/render/weightedblended_oit.js.map +1 -1
  232. package/dist/scene/basesprite.js +296 -0
  233. package/dist/scene/basesprite.js.map +1 -0
  234. package/dist/scene/batchgroup.js +4 -2
  235. package/dist/scene/batchgroup.js.map +1 -1
  236. package/dist/scene/environment.js +9 -10
  237. package/dist/scene/environment.js.map +1 -1
  238. package/dist/scene/graph_node.js.map +1 -1
  239. package/dist/scene/light.js +22 -4
  240. package/dist/scene/light.js.map +1 -1
  241. package/dist/scene/mesh.js +96 -26
  242. package/dist/scene/mesh.js.map +1 -1
  243. package/dist/scene/octree.js.map +1 -1
  244. package/dist/scene/particlesys.js +25 -22
  245. package/dist/scene/particlesys.js.map +1 -1
  246. package/dist/scene/raycast_visitor.js +0 -16
  247. package/dist/scene/raycast_visitor.js.map +1 -1
  248. package/dist/scene/scene.js +7 -4
  249. package/dist/scene/scene.js.map +1 -1
  250. package/dist/scene/scene_node.js +20 -35
  251. package/dist/scene/scene_node.js.map +1 -1
  252. package/dist/scene/sprite.js +18 -0
  253. package/dist/scene/sprite.js.map +1 -0
  254. package/dist/scene/sprite3d.js +18 -0
  255. package/dist/scene/sprite3d.js.map +1 -0
  256. package/dist/scene/terrain-cm/grass.js +5 -4
  257. package/dist/scene/terrain-cm/grass.js.map +1 -1
  258. package/dist/scene/terrain-cm/grassmaterial.js +3 -1
  259. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  260. package/dist/scene/terrain-cm/terrain-cm.js +65 -48
  261. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  262. package/dist/scene/water.js +35 -30
  263. package/dist/scene/water.js.map +1 -1
  264. package/dist/shaders/atmosphere.js +17 -29
  265. package/dist/shaders/atmosphere.js.map +1 -1
  266. package/dist/shaders/fog.js.map +1 -1
  267. package/dist/shaders/misc.js.map +1 -1
  268. package/dist/shaders/noise.js.map +1 -1
  269. package/dist/shaders/pbr.js.map +1 -1
  270. package/dist/shaders/shadow.js.map +1 -1
  271. package/dist/shaders/ssr.js.map +1 -1
  272. package/dist/shaders/temporal.js.map +1 -1
  273. package/dist/shaders/water.js.map +1 -1
  274. package/dist/shadow/esm.js +1 -1
  275. package/dist/shadow/esm.js.map +1 -1
  276. package/dist/shadow/pcf_opt.js.map +1 -1
  277. package/dist/shadow/pcf_pd.js.map +1 -1
  278. package/dist/shadow/shader.js +3 -1
  279. package/dist/shadow/shader.js.map +1 -1
  280. package/dist/shadow/shadow_impl.js.map +1 -1
  281. package/dist/shadow/shadowmapper.js +6 -18
  282. package/dist/shadow/shadowmapper.js.map +1 -1
  283. package/dist/shadow/ssm.js.map +1 -1
  284. package/dist/shadow/vsm.js.map +1 -1
  285. package/dist/shapes/box.js +9 -3
  286. package/dist/shapes/box.js.map +1 -1
  287. package/dist/shapes/cylinder.js +2 -2
  288. package/dist/shapes/cylinder.js.map +1 -1
  289. package/dist/shapes/plane.js +2 -2
  290. package/dist/shapes/plane.js.map +1 -1
  291. package/dist/shapes/shape.js +2 -1
  292. package/dist/shapes/shape.js.map +1 -1
  293. package/dist/shapes/sphere.js +2 -2
  294. package/dist/shapes/sphere.js.map +1 -1
  295. package/dist/shapes/tetrahedron.js +5 -6
  296. package/dist/shapes/tetrahedron.js.map +1 -1
  297. package/dist/shapes/torus.js +2 -2
  298. package/dist/shapes/torus.js.map +1 -1
  299. package/dist/utility/aabbtree.js +1 -1
  300. package/dist/utility/aabbtree.js.map +1 -1
  301. package/dist/utility/blueprint/common/constants.js +578 -104
  302. package/dist/utility/blueprint/common/constants.js.map +1 -1
  303. package/dist/utility/blueprint/common/math.js +471 -9
  304. package/dist/utility/blueprint/common/math.js.map +1 -1
  305. package/dist/utility/blueprint/common.js +1 -1
  306. package/dist/utility/blueprint/common.js.map +1 -1
  307. package/dist/utility/blueprint/material/func.js +9 -5
  308. package/dist/utility/blueprint/material/func.js.map +1 -1
  309. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  310. package/dist/utility/blueprint/material/ir.js +288 -80
  311. package/dist/utility/blueprint/material/ir.js.map +1 -1
  312. package/dist/utility/blueprint/material/pbr.js +92 -4
  313. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  314. package/dist/utility/blueprint/material/texture.js +62 -45
  315. package/dist/utility/blueprint/material/texture.js.map +1 -1
  316. package/dist/utility/blueprint/node.js +28 -1
  317. package/dist/utility/blueprint/node.js.map +1 -1
  318. package/dist/utility/bounding_volume.js.map +1 -1
  319. package/dist/utility/debug.js.map +1 -1
  320. package/dist/utility/draco/decoder.js.map +1 -1
  321. package/dist/utility/misc.js +1 -1
  322. package/dist/utility/misc.js.map +1 -1
  323. package/dist/utility/panorama.js.map +1 -1
  324. package/dist/utility/pmrem.js.map +1 -1
  325. package/dist/utility/rendermipmap.js.map +1 -1
  326. package/dist/utility/serialization/json.js +19 -15
  327. package/dist/utility/serialization/json.js.map +1 -1
  328. package/dist/utility/serialization/manager.js +89 -22
  329. package/dist/utility/serialization/manager.js.map +1 -1
  330. package/dist/utility/serialization/scene/animation.js +44 -41
  331. package/dist/utility/serialization/scene/animation.js.map +1 -1
  332. package/dist/utility/serialization/scene/batch.js +4 -3
  333. package/dist/utility/serialization/scene/batch.js.map +1 -1
  334. package/dist/utility/serialization/scene/camera.js +97 -9
  335. package/dist/utility/serialization/scene/camera.js.map +1 -1
  336. package/dist/utility/serialization/scene/common.js +102 -28
  337. package/dist/utility/serialization/scene/common.js.map +1 -1
  338. package/dist/utility/serialization/scene/light.js +14 -12
  339. package/dist/utility/serialization/scene/light.js.map +1 -1
  340. package/dist/utility/serialization/scene/material.js +216 -26
  341. package/dist/utility/serialization/scene/material.js.map +1 -1
  342. package/dist/utility/serialization/scene/mesh.js +71 -100
  343. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  344. package/dist/utility/serialization/scene/misc.js +3 -2
  345. package/dist/utility/serialization/scene/misc.js.map +1 -1
  346. package/dist/utility/serialization/scene/node.js +42 -9
  347. package/dist/utility/serialization/scene/node.js.map +1 -1
  348. package/dist/utility/serialization/scene/particle.js +7 -5
  349. package/dist/utility/serialization/scene/particle.js.map +1 -1
  350. package/dist/utility/serialization/scene/primitive.js +18 -15
  351. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  352. package/dist/utility/serialization/scene/scene.js +3 -2
  353. package/dist/utility/serialization/scene/scene.js.map +1 -1
  354. package/dist/utility/serialization/scene/sprite.js +164 -0
  355. package/dist/utility/serialization/scene/sprite.js.map +1 -0
  356. package/dist/utility/serialization/scene/terrain.js +8 -6
  357. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  358. package/dist/utility/serialization/scene/water.js +11 -9
  359. package/dist/utility/serialization/scene/water.js.map +1 -1
  360. package/dist/utility/serialization/types.js +6 -0
  361. package/dist/utility/serialization/types.js.map +1 -0
  362. package/dist/utility/shprojector.js.map +1 -1
  363. package/dist/utility/textures/ggxlut.js.map +1 -1
  364. package/dist/utility/textures/gradientnoise.js.map +1 -1
  365. package/dist/utility/textures/randomnoise.js.map +1 -1
  366. package/dist/values.js +14 -14
  367. package/dist/values.js.map +1 -1
  368. package/package.json +80 -80
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spring_modifier.js","sources":["../../src/animation/spring_modifier.ts"],"sourcesContent":["import { SkeletonModifier } from './skeleton_modifier';\r\nimport type { Skeleton } from './skeleton';\r\nimport type { SpringSystem } from './spring/spring_system';\r\n\r\n/**\r\n * Post-processor wrapper for spring physics systems.\r\n *\r\n * Integrates spring-based physics simulation into the skeleton post-processing pipeline.\r\n * The spring system is updated each frame and results are blended with the base animation.\r\n *\r\n * @public\r\n */\r\nexport class SpringModifier extends SkeletonModifier {\r\n private _springSystem: SpringSystem;\r\n\r\n /**\r\n * Create a spring post-processor.\r\n *\r\n * @param springSystem - The spring system to integrate\r\n * @param weight - Blend weight [0-1] (default: 1.0)\r\n */\r\n constructor(springSystem: SpringSystem, weight: number = 1.0) {\r\n super(weight);\r\n this._springSystem = springSystem;\r\n }\r\n\r\n /**\r\n * Get the spring system.\r\n */\r\n get springSystem(): SpringSystem {\r\n return this._springSystem;\r\n }\r\n\r\n /**\r\n * Apply spring physics to skeleton joints.\r\n */\r\n apply(_skeleton: Skeleton, deltaTime: number): void {\r\n if (!this._enabled || this._weight <= 0) {\r\n return;\r\n }\r\n\r\n // Update spring physics simulation\r\n this._springSystem.update(deltaTime);\r\n\r\n // Apply results to scene nodes with blending\r\n this._springSystem.applyToNodes(this._weight);\r\n }\r\n\r\n /**\r\n * Reset the spring system to initial state.\r\n */\r\n reset(): void {\r\n this._springSystem.reset();\r\n }\r\n}\r\n"],"names":["SpringModifier","SkeletonModifier","_springSystem","springSystem","weight","apply","_skeleton","deltaTime","_enabled","_weight","update","applyToNodes","reset"],"mappings":";;AAIA;;;;;;;IAQO,MAAMA,cAAuBC,SAAAA,gBAAAA,CAAAA;IAC1BC,aAA4B;AAEpC;;;;;AAKC,MACD,WAAYC,CAAAA,YAA0B,EAAEC,MAAAA,GAAiB,GAAG,CAAE;AAC5D,QAAA,KAAK,CAACA,MAAAA,CAAAA;QACN,IAAI,CAACF,aAAa,GAAGC,YAAAA;AACvB;AAEA;;AAEC,MACD,IAAIA,YAA6B,GAAA;QAC/B,OAAO,IAAI,CAACD,aAAa;AAC3B;AAEA;;AAEC,MACDG,KAAMC,CAAAA,SAAmB,EAAEC,SAAiB,EAAQ;QAClD,IAAI,CAAC,IAAI,CAACC,QAAQ,IAAI,IAAI,CAACC,OAAO,IAAI,CAAG,EAAA;AACvC,YAAA;AACF;;AAGA,QAAA,IAAI,CAACP,aAAa,CAACQ,MAAM,CAACH,SAAAA,CAAAA;;AAG1B,QAAA,IAAI,CAACL,aAAa,CAACS,YAAY,CAAC,IAAI,CAACF,OAAO,CAAA;AAC9C;AAEA;;AAEC,MACDG,KAAc,GAAA;QACZ,IAAI,CAACV,aAAa,CAACU,KAAK,EAAA;AAC1B;AACF;;;;"}
@@ -0,0 +1,54 @@
1
+ import { SkeletonPostProcessor } from './skeleton_postprocessor.js';
2
+
3
+ /**
4
+ * Post-processor wrapper for spring physics systems.
5
+ *
6
+ * Integrates spring-based physics simulation into the skeleton post-processing pipeline.
7
+ * The spring system is updated each frame and results are blended with the base animation.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const springChain = new SpringChain([joint1, joint2, joint3]);
12
+ * const springSystem = new SpringSystem(springChain);
13
+ * const processor = new SpringPostProcessor(springSystem, 1.0);
14
+ * skeleton.addPostProcessor(processor);
15
+ * ```
16
+ *
17
+ * @public
18
+ */ class SpringPostProcessor extends SkeletonPostProcessor {
19
+ _springSystem;
20
+ /**
21
+ * Create a spring post-processor.
22
+ *
23
+ * @param springSystem - The spring system to integrate
24
+ * @param weight - Blend weight [0-1] (default: 1.0)
25
+ * @param priority - Priority for ordering (default: 50)
26
+ */ constructor(springSystem, weight = 1.0, priority = 50){
27
+ super(weight, priority);
28
+ this._springSystem = springSystem;
29
+ }
30
+ /**
31
+ * Get the spring system.
32
+ */ get springSystem() {
33
+ return this._springSystem;
34
+ }
35
+ /**
36
+ * Apply spring physics to skeleton joints.
37
+ */ apply(_skeleton, deltaTime) {
38
+ if (!this._enabled || this._weight <= 0) {
39
+ return;
40
+ }
41
+ // Update spring physics simulation
42
+ this._springSystem.update(deltaTime);
43
+ // Apply results to scene nodes with blending
44
+ this._springSystem.applyToNodes(this._weight);
45
+ }
46
+ /**
47
+ * Reset the spring system to initial state.
48
+ */ reset() {
49
+ this._springSystem.reset();
50
+ }
51
+ }
52
+
53
+ export { SpringPostProcessor };
54
+ //# sourceMappingURL=spring_postprocessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spring_postprocessor.js","sources":["../../src/animation/spring_postprocessor.ts"],"sourcesContent":["import { SkeletonPostProcessor } from './skeleton_postprocessor';\r\nimport type { Skeleton } from './skeleton';\r\nimport type { SpringSystem } from './spring/spring_system';\r\n\r\n/**\r\n * Post-processor wrapper for spring physics systems.\r\n *\r\n * Integrates spring-based physics simulation into the skeleton post-processing pipeline.\r\n * The spring system is updated each frame and results are blended with the base animation.\r\n *\r\n * @example\r\n * ```typescript\r\n * const springChain = new SpringChain([joint1, joint2, joint3]);\r\n * const springSystem = new SpringSystem(springChain);\r\n * const processor = new SpringPostProcessor(springSystem, 1.0);\r\n * skeleton.addPostProcessor(processor);\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport class SpringPostProcessor extends SkeletonPostProcessor {\r\n private _springSystem: SpringSystem;\r\n\r\n /**\r\n * Create a spring post-processor.\r\n *\r\n * @param springSystem - The spring system to integrate\r\n * @param weight - Blend weight [0-1] (default: 1.0)\r\n * @param priority - Priority for ordering (default: 50)\r\n */\r\n constructor(springSystem: SpringSystem, weight: number = 1.0, priority: number = 50) {\r\n super(weight, priority);\r\n this._springSystem = springSystem;\r\n }\r\n\r\n /**\r\n * Get the spring system.\r\n */\r\n get springSystem(): SpringSystem {\r\n return this._springSystem;\r\n }\r\n\r\n /**\r\n * Apply spring physics to skeleton joints.\r\n */\r\n apply(_skeleton: Skeleton, deltaTime: number): void {\r\n if (!this._enabled || this._weight <= 0) {\r\n return;\r\n }\r\n\r\n // Update spring physics simulation\r\n this._springSystem.update(deltaTime);\r\n\r\n // Apply results to scene nodes with blending\r\n this._springSystem.applyToNodes(this._weight);\r\n }\r\n\r\n /**\r\n * Reset the spring system to initial state.\r\n */\r\n reset(): void {\r\n this._springSystem.reset();\r\n }\r\n}\r\n"],"names":["SpringPostProcessor","SkeletonPostProcessor","_springSystem","springSystem","weight","priority","apply","_skeleton","deltaTime","_enabled","_weight","update","applyToNodes","reset"],"mappings":";;AAIA;;;;;;;;;;;;;;;IAgBO,MAAMA,mBAA4BC,SAAAA,qBAAAA,CAAAA;IAC/BC,aAA4B;AAEpC;;;;;;MAOA,WAAA,CAAYC,YAA0B,EAAEC,MAAAA,GAAiB,GAAG,EAAEC,QAAAA,GAAmB,EAAE,CAAE;AACnF,QAAA,KAAK,CAACD,MAAQC,EAAAA,QAAAA,CAAAA;QACd,IAAI,CAACH,aAAa,GAAGC,YAAAA;AACvB;AAEA;;AAEC,MACD,IAAIA,YAA6B,GAAA;QAC/B,OAAO,IAAI,CAACD,aAAa;AAC3B;AAEA;;AAEC,MACDI,KAAMC,CAAAA,SAAmB,EAAEC,SAAiB,EAAQ;QAClD,IAAI,CAAC,IAAI,CAACC,QAAQ,IAAI,IAAI,CAACC,OAAO,IAAI,CAAG,EAAA;AACvC,YAAA;AACF;;AAGA,QAAA,IAAI,CAACR,aAAa,CAACS,MAAM,CAACH,SAAAA,CAAAA;;AAG1B,QAAA,IAAI,CAACN,aAAa,CAACU,YAAY,CAAC,IAAI,CAACF,OAAO,CAAA;AAC9C;AAEA;;AAEC,MACDG,KAAc,GAAA;QACZ,IAAI,CAACX,aAAa,CAACW,KAAK,EAAA;AAC1B;AACF;;;;"}
@@ -10,7 +10,6 @@ import { AnimationTrack } from './animationtrack.js';
10
10
  constructor(modeOrInterpolator, keyFramesOrEmbedded, embedded){
11
11
  if (modeOrInterpolator === undefined) {
12
12
  super(false);
13
- this._interpolator = null;
14
13
  } else if (modeOrInterpolator instanceof Interpolator) {
15
14
  if (modeOrInterpolator.target !== 'vec3') {
16
15
  throw new Error(`TranslationTrack(): interpolator target must be 'vec3'`);
@@ -1 +1 @@
1
- {"version":3,"file":"translationtrack.js","sources":["../../src/animation/translationtrack.ts"],"sourcesContent":["import type { InterpolationMode } from '@zephyr3d/base';\r\nimport { Interpolator, Vector3 } from '@zephyr3d/base';\r\nimport { AnimationTrack } from './animationtrack';\r\nimport type { SceneNode } from '../scene';\r\n\r\n/**\r\n * Translate animation track\r\n * @public\r\n */\r\nexport class NodeTranslationTrack extends AnimationTrack<Vector3> {\r\n private readonly _state: Vector3;\r\n private _interpolator: Interpolator;\r\n /**\r\n * Create an instance of TranslationTrack\r\n */\r\n constructor();\r\n /**\r\n * Create an instance of TranslationTrack from keyframe values\r\n * @param interpolator - Interpolator object that contains the keyframe values\r\n * @param embedded - Whether this track be an embedded track\r\n */\r\n constructor(interpolator: Interpolator, embedded?: boolean);\r\n /**\r\n * Create an instance of TranslationTrack from keyframe values\r\n * @param mode - The interpolation mode of keyframes\r\n * @param keyFrames - Keyframe values\r\n * @param embedded - Whether this track be an embedded track\r\n */\r\n constructor(mode: InterpolationMode, keyFrames: { time: number; value: Vector3 }[], embedded?: boolean);\r\n constructor(\r\n modeOrInterpolator?: Interpolator | InterpolationMode,\r\n keyFramesOrEmbedded?: { time: number; value: Vector3 }[] | boolean,\r\n embedded?: boolean\r\n ) {\r\n if (modeOrInterpolator === undefined) {\r\n super(false);\r\n this._interpolator = null;\r\n } else if (modeOrInterpolator instanceof Interpolator) {\r\n if (modeOrInterpolator.target !== 'vec3') {\r\n throw new Error(`TranslationTrack(): interpolator target must be 'vec3'`);\r\n }\r\n super((keyFramesOrEmbedded as boolean) ?? false);\r\n this._interpolator = modeOrInterpolator;\r\n } else {\r\n const keyFrames = keyFramesOrEmbedded as { time: number; value: Vector3 }[];\r\n const inputs = new Float32Array(keyFrames.map((val) => val.time));\r\n const outputs = new Float32Array(keyFrames.length * 3);\r\n for (let i = 0; i < keyFrames.length; i++) {\r\n outputs[i * 3 + 0] = keyFrames[i].value.x;\r\n outputs[i * 3 + 1] = keyFrames[i].value.y;\r\n outputs[i * 3 + 2] = keyFrames[i].value.z;\r\n }\r\n super(embedded ?? false);\r\n this._interpolator = new Interpolator(modeOrInterpolator, 'vec3', inputs, outputs);\r\n }\r\n this._state = new Vector3();\r\n this._jointIndex = -1;\r\n }\r\n get interpolator() {\r\n return this._interpolator;\r\n }\r\n set interpolator(interp: Interpolator) {\r\n if (interp && interp.target !== 'vec3') {\r\n throw new Error(`TranslationTrack(): interpolator target must be 'vec3'`);\r\n }\r\n this._interpolator = interp ?? null;\r\n }\r\n /** {@inheritDoc AnimationTrack.calculateState} */\r\n calculateState(target: object, currentTime: number): Vector3 {\r\n this._interpolator.interpolate(currentTime, this._state);\r\n return this._state;\r\n }\r\n /** {@inheritDoc AnimationTrack.applyState} */\r\n applyState(node: SceneNode, state: Vector3) {\r\n node.position.set(state);\r\n }\r\n /** {@inheritDoc AnimationTrack.mixState} */\r\n mixState(a: Vector3, b: Vector3, t: number): Vector3 {\r\n return new Vector3(a.x + t * (b.x - a.x), a.y + t * (b.y - a.y), a.z + t * (b.z - a.z));\r\n }\r\n /** {@inheritDoc AnimationTrack.getBlendId} */\r\n getBlendId(): unknown {\r\n return 'node-translation';\r\n }\r\n /** {@inheritDoc AnimationTrack.getDuration} */\r\n getDuration(): number {\r\n return this._interpolator.maxTime;\r\n }\r\n}\r\n"],"names":["NodeTranslationTrack","AnimationTrack","_state","_interpolator","modeOrInterpolator","keyFramesOrEmbedded","embedded","undefined","Interpolator","target","Error","keyFrames","inputs","Float32Array","map","val","time","outputs","length","i","value","x","y","z","Vector3","_jointIndex","interpolator","interp","calculateState","currentTime","interpolate","applyState","node","state","position","set","mixState","a","b","t","getBlendId","getDuration","maxTime"],"mappings":";;;AAKA;;;IAIO,MAAMA,oBAA6BC,SAAAA,cAAAA,CAAAA;IACvBC,MAAgB;IACzBC,aAA4B;AAkBpC,IAAA,WAAA,CACEC,kBAAqD,EACrDC,mBAAkE,EAClEC,QAAkB,CAClB;AACA,QAAA,IAAIF,uBAAuBG,SAAW,EAAA;AACpC,YAAA,KAAK,CAAC,KAAA,CAAA;YACN,IAAI,CAACJ,aAAa,GAAG,IAAA;SAChB,MAAA,IAAIC,8BAA8BI,YAAc,EAAA;YACrD,IAAIJ,kBAAAA,CAAmBK,MAAM,KAAK,MAAQ,EAAA;AACxC,gBAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,sDAAsD,CAAC,CAAA;AAC1E;YACA,KAAK,CAAC,mBAAoC,IAAA,KAAA,CAAA;YAC1C,IAAI,CAACP,aAAa,GAAGC,kBAAAA;SAChB,MAAA;AACL,YAAA,MAAMO,SAAYN,GAAAA,mBAAAA;YAClB,MAAMO,MAAAA,GAAS,IAAIC,YAAaF,CAAAA,SAAAA,CAAUG,GAAG,CAAC,CAACC,GAAQA,GAAAA,GAAAA,CAAIC,IAAI,CAAA,CAAA;AAC/D,YAAA,MAAMC,OAAU,GAAA,IAAIJ,YAAa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AACA,MAAM;AACpB;AACA,mDACA6B,UAAAA,CAAWC,IAAe,EAAEC,KAAc,EAAE;QAC1CD,IAAKE,CAAAA,QAAQ,CAACC,GAAG,CAACF,KAAAA,CAAAA;AACpB;AACA,iDACAG,QAASC,CAAAA,CAAU,EAAEC,CAAU,EAAEC,CAAS,EAAW;AACnD,QAAA,OAAO,IAAIf,OAAQa,CAAAA,CAAAA,CAAEhB,CAAC,GAAGkB,KAAKD,CAAAA,CAAEjB,CAAC,GAAGgB,EAAEhB,CAAAA,CAAIgB,EAAAA,CAAAA,CAAEf,CAAC,GAAGiB,CAAAA,IAAKD,CAAAA,CAAEhB,CAAC,GAAGe,CAAAA,CAAEf,CAAAA,GAAIe,CAAEd,CAAAA,CAAC,GAAGgB,CAAAA,IAAKD,CAAEf,CAAAA,CAAC,GAAGc,CAAAA,CAAEd,CAAC,CAADA,CAAAA;AACtF;AACA,mDACAiB,UAAsB,GAAA;QACpB,OAAO,kBAAA;AACT;AACA,oDACAC,WAAsB,GAAA;AACpB,QAAA,OAAO,IAAI,CAACtC,aAAa,CAACuC,OAAO;AACnC;AACF;;;;"}
1
+ {"version":3,"file":"translationtrack.js","sources":["../../src/animation/translationtrack.ts"],"sourcesContent":["import type { InterpolationMode } from '@zephyr3d/base';\r\nimport { Interpolator, Vector3 } from '@zephyr3d/base';\r\nimport { AnimationTrack } from './animationtrack';\r\nimport type { SceneNode } from '../scene';\r\n\r\n/**\r\n * Translate animation track\r\n * @public\r\n */\r\nexport class NodeTranslationTrack extends AnimationTrack<Vector3> {\r\n private readonly _state: Vector3;\r\n private _interpolator!: Interpolator;\r\n /**\r\n * Create an instance of TranslationTrack\r\n */\r\n constructor();\r\n /**\r\n * Create an instance of TranslationTrack from keyframe values\r\n * @param interpolator - Interpolator object that contains the keyframe values\r\n * @param embedded - Whether this track be an embedded track\r\n */\r\n constructor(interpolator: Interpolator, embedded?: boolean);\r\n /**\r\n * Create an instance of TranslationTrack from keyframe values\r\n * @param mode - The interpolation mode of keyframes\r\n * @param keyFrames - Keyframe values\r\n * @param embedded - Whether this track be an embedded track\r\n */\r\n constructor(mode: InterpolationMode, keyFrames: { time: number; value: Vector3 }[], embedded?: boolean);\r\n constructor(\r\n modeOrInterpolator?: Interpolator | InterpolationMode,\r\n keyFramesOrEmbedded?: { time: number; value: Vector3 }[] | boolean,\r\n embedded?: boolean\r\n ) {\r\n if (modeOrInterpolator === undefined) {\r\n super(false);\r\n } else if (modeOrInterpolator instanceof Interpolator) {\r\n if (modeOrInterpolator.target !== 'vec3') {\r\n throw new Error(`TranslationTrack(): interpolator target must be 'vec3'`);\r\n }\r\n super((keyFramesOrEmbedded as boolean) ?? false);\r\n this._interpolator = modeOrInterpolator;\r\n } else {\r\n const keyFrames = keyFramesOrEmbedded as { time: number; value: Vector3 }[];\r\n const inputs = new Float32Array(keyFrames.map((val) => val.time));\r\n const outputs = new Float32Array(keyFrames.length * 3);\r\n for (let i = 0; i < keyFrames.length; i++) {\r\n outputs[i * 3 + 0] = keyFrames[i].value.x;\r\n outputs[i * 3 + 1] = keyFrames[i].value.y;\r\n outputs[i * 3 + 2] = keyFrames[i].value.z;\r\n }\r\n super(embedded ?? false);\r\n this._interpolator = new Interpolator(modeOrInterpolator, 'vec3', inputs, outputs);\r\n }\r\n this._state = new Vector3();\r\n this._jointIndex = -1;\r\n }\r\n get interpolator() {\r\n return this._interpolator;\r\n }\r\n set interpolator(interp: Interpolator) {\r\n if (interp && interp.target !== 'vec3') {\r\n throw new Error(`TranslationTrack(): interpolator target must be 'vec3'`);\r\n }\r\n this._interpolator = interp ?? null;\r\n }\r\n /** {@inheritDoc AnimationTrack.calculateState} */\r\n calculateState(target: object, currentTime: number) {\r\n this._interpolator.interpolate(currentTime, this._state);\r\n return this._state;\r\n }\r\n /** {@inheritDoc AnimationTrack.applyState} */\r\n applyState(node: SceneNode, state: Vector3) {\r\n node.position.set(state);\r\n }\r\n /** {@inheritDoc AnimationTrack.mixState} */\r\n mixState(a: Vector3, b: Vector3, t: number) {\r\n return new Vector3(a.x + t * (b.x - a.x), a.y + t * (b.y - a.y), a.z + t * (b.z - a.z));\r\n }\r\n /** {@inheritDoc AnimationTrack.getBlendId} */\r\n getBlendId() {\r\n return 'node-translation';\r\n }\r\n /** {@inheritDoc AnimationTrack.getDuration} */\r\n getDuration() {\r\n return this._interpolator.maxTime;\r\n }\r\n}\r\n"],"names":["NodeTranslationTrack","AnimationTrack","_state","_interpolator","modeOrInterpolator","keyFramesOrEmbedded","embedded","undefined","Interpolator","target","Error","keyFrames","inputs","Float32Array","map","val","time","outputs","length","i","value","x","y","z","Vector3","_jointIndex","interpolator","interp","calculateState","currentTime","interpolate","applyState","node","state","position","set","mixState","a","b","t","getBlendId","getDuration","maxTime"],"mappings":";;;AAKA;;;IAIO,MAAMA,oBAA6BC,SAAAA,cAAAA,CAAAA;IACvBC,MAAgB;IACzBC,aAA6B;AAkBrC,IAAA,WAAA,CACEC,kBAAqD,EACrDC,mBAAkE,EAClEC,QAAkB,CAClB;AACA,QAAA,IAAIF,uBAAuBG,SAAW,EAAA;AACpC,YAAA,KAAK,CAAC,KAAA,CAAA;SACD,MAAA,IAAIH,8BAA8BI,YAAc,EAAA;YACrD,IAAIJ,kBAAAA,CAAmBK,MAAM,KAAK,MAAQ,EAAA;AACxC,gBAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,sDAAsD,CAAC,CAAA;AAC1E;YACA,KAAK,CAAC,mBAAoC,IAAA,KAAA,CAAA;YAC1C,IAAI,CAACP,aAAa,GAAGC,kBAAAA;SAChB,MAAA;AACL,YAAA,MAAMO,SAAYN,GAAAA,mBAAAA;YAClB,MAAMO,MAAAA,GAAS,IAAIC,YAAaF,CAAAA,SAAAA,CAAUG,GAAG,CAAC,CAACC,GAAQA,GAAAA,GAAAA,CAAIC,IAAI,CAAA,CAAA;AAC/D,YAAA,MAAMC,OAAU,GAAA,IAAIJ,YAAaF,CAAAA,SAAAA,CAAUO,MAAM,GAAG,CAAA,CAAA;AACpD,YA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KAAc,EAAE;QAC1CD,IAAKE,CAAAA,QAAQ,CAACC,GAAG,CAACF,KAAAA,CAAAA;AACpB;AACA,iDACAG,QAASC,CAAAA,CAAU,EAAEC,CAAU,EAAEC,CAAS,EAAE;AAC1C,QAAA,OAAO,IAAIf,OAAQa,CAAAA,CAAAA,CAAEhB,CAAC,GAAGkB,KAAKD,CAAAA,CAAEjB,CAAC,GAAGgB,EAAEhB,CAAAA,CAAIgB,EAAAA,CAAAA,CAAEf,CAAC,GAAGiB,CAAAA,IAAKD,CAAAA,CAAEhB,CAAC,GAAGe,CAAAA,CAAEf,CAAAA,GAAIe,CAAEd,CAAAA,CAAC,GAAGgB,CAAAA,IAAKD,CAAEf,CAAAA,CAAC,GAAGc,CAAAA,CAAEd,CAAC,CAADA,CAAAA;AACtF;AACA,mDACAiB,UAAa,GAAA;QACX,OAAO,kBAAA;AACT;AACA,oDACAC,WAAc,GAAA;AACZ,QAAA,OAAO,IAAI,CAACtC,aAAa,CAACuC,OAAO;AACnC;AACF;;;;"}
package/dist/app/api.js CHANGED
@@ -11,6 +11,15 @@
11
11
  */ function getApp() {
12
12
  return appInstance;
13
13
  }
14
+ /**
15
+ * Singleton accessor for the current Application instance.
16
+ *
17
+ * @returns The Application singleton.
18
+ *
19
+ * @public
20
+ */ function tryGetApp() {
21
+ return appInstance ?? null;
22
+ }
14
23
  /**
15
24
  * Singleton accessor for the current engine instance.
16
25
  *
@@ -18,7 +27,7 @@
18
27
  *
19
28
  * @public
20
29
  */ function getEngine() {
21
- return appInstance?.engine ?? null;
30
+ return appInstance.engine;
22
31
  }
23
32
  /**
24
33
  * Singleton accessor for the device instance.
@@ -27,7 +36,7 @@
27
36
  *
28
37
  * @public
29
38
  */ function getDevice() {
30
- return appInstance?.device ?? null;
39
+ return appInstance.device;
31
40
  }
32
41
  /**
33
42
  * Singleton accessor for the input manager instance.
@@ -36,8 +45,8 @@
36
45
  *
37
46
  * @public
38
47
  */ function getInput() {
39
- return appInstance?.inputManager ?? null;
48
+ return appInstance.inputManager;
40
49
  }
41
50
 
42
- export { appInstance, getApp, getDevice, getEngine, getInput, setApp };
51
+ export { appInstance, getApp, getDevice, getEngine, getInput, setApp, tryGetApp };
43
52
  //# sourceMappingURL=api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sources":["../../src/app/api.ts"],"sourcesContent":["import type { AbstractDevice } from '@zephyr3d/device';\r\nimport type { Application } from './app';\r\nimport type { Engine } from './engine';\r\nimport type { InputManager } from '.';\r\n\r\n/** @internal */\r\nexport let appInstance: Application;\r\n\r\n/** @internal */\r\nexport function setApp(app: Application) {\r\n appInstance = app;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the current Application instance.\r\n *\r\n * @returns The Application singleton.\r\n *\r\n * @public\r\n */\r\n\r\nexport function getApp(): Application {\r\n return appInstance;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the current engine instance.\r\n *\r\n * @returns The engine singleton.\r\n *\r\n * @public\r\n */\r\nexport function getEngine(): Engine {\r\n return appInstance?.engine ?? null;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the device instance.\r\n *\r\n * @returns The device singleton.\r\n *\r\n * @public\r\n */\r\nexport function getDevice(): AbstractDevice {\r\n return appInstance?.device ?? null;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the input manager instance.\r\n *\r\n * @returns The input manager singleton.\r\n *\r\n * @public\r\n */\r\n\r\nexport function getInput(): InputManager {\r\n return appInstance?.inputManager ?? null;\r\n}\r\n"],"names":["appInstance","setApp","app","getApp","getEngine","engine","getDevice","device","getInput","inputManager"],"mappings":"AAKA,iBACO,IAAIA;AAEX,iBACO,SAASC,MAAAA,CAAOC,GAAgB,EAAA;IACrCF,WAAcE,GAAAA,GAAAA;AAChB;AAEA;;;;;;AAMC,IAEM,SAASC,MAAAA,GAAAA;IACd,OAAOH,WAAAA;AACT;AAEA;;;;;;AAMC,IACM,SAASI,SAAAA,GAAAA;AACd,IAAA,OAAOJ,aAAaK,MAAU,IAAA,IAAA;AAChC;AAEA;;;;;;AAMC,IACM,SAASC,SAAAA,GAAAA;AACd,IAAA,OAAON,aAAaO,MAAU,IAAA,IAAA;AAChC;AAEA;;;;;;AAMC,IAEM,SAASC,QAAAA,GAAAA;AACd,IAAA,OAAOR,aAAaS,YAAgB,IAAA,IAAA;AACtC;;;;"}
1
+ {"version":3,"file":"api.js","sources":["../../src/app/api.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport type { Application } from './app';\r\n\r\n/** @internal */\r\nexport let appInstance: Application;\r\n\r\n/** @internal */\r\nexport function setApp(app: Application) {\r\n appInstance = app;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the current Application instance.\r\n *\r\n * @returns The Application singleton.\r\n *\r\n * @public\r\n */\r\nexport function getApp() {\r\n return appInstance;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the current Application instance.\r\n *\r\n * @returns The Application singleton.\r\n *\r\n * @public\r\n */\r\nexport function tryGetApp(): Nullable<Application> {\r\n return appInstance ?? null;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the current engine instance.\r\n *\r\n * @returns The engine singleton.\r\n *\r\n * @public\r\n */\r\nexport function getEngine() {\r\n return appInstance!.engine!;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the device instance.\r\n *\r\n * @returns The device singleton.\r\n *\r\n * @public\r\n */\r\nexport function getDevice() {\r\n return appInstance!.device!;\r\n}\r\n\r\n/**\r\n * Singleton accessor for the input manager instance.\r\n *\r\n * @returns The input manager singleton.\r\n *\r\n * @public\r\n */\r\n\r\nexport function getInput() {\r\n return appInstance!.inputManager!;\r\n}\r\n"],"names":["appInstance","setApp","app","getApp","tryGetApp","getEngine","engine","getDevice","device","getInput","inputManager"],"mappings":"AAGA,iBACO,IAAIA;AAEX,iBACO,SAASC,MAAAA,CAAOC,GAAgB,EAAA;IACrCF,WAAcE,GAAAA,GAAAA;AAChB;AAEA;;;;;;AAMC,IACM,SAASC,MAAAA,GAAAA;IACd,OAAOH,WAAAA;AACT;AAEA;;;;;;AAMC,IACM,SAASI,SAAAA,GAAAA;AACd,IAAA,OAAOJ,WAAe,IAAA,IAAA;AACxB;AAEA;;;;;;AAMC,IACM,SAASK,SAAAA,GAAAA;AACd,IAAA,OAAOL,YAAaM,MAAM;AAC5B;AAEA;;;;;;AAMC,IACM,SAASC,SAAAA,GAAAA;AACd,IAAA,OAAOP,YAAaQ,MAAM;AAC5B;AAEA;;;;;;AAMC,IAEM,SAASC,QAAAA,GAAAA;AACd,IAAA,OAAOT,YAAaU,YAAY;AAClC;;;;"}
package/dist/app/app.js CHANGED
@@ -27,6 +27,7 @@ import { getApp, setApp } from './api.js';
27
27
  _device;
28
28
  _inputManager;
29
29
  _engine;
30
+ _editorMode;
30
31
  _ready;
31
32
  /**
32
33
  * Construct the Application singleton with the provided options.
@@ -47,10 +48,20 @@ import { getApp, setApp } from './api.js';
47
48
  canvas: opt.canvas
48
49
  };
49
50
  this._inputManager = new InputManager(this);
50
- this._engine = new Engine(opt.runtimeOptions?.VFS, opt.runtimeOptions?.scriptsRoot, opt.runtimeOptions?.editorMode, opt.runtimeOptions?.enabled);
51
+ this._engine = new Engine(opt.runtimeOptions?.VFS, opt.runtimeOptions?.scriptsRoot, opt.runtimeOptions?.enabled);
52
+ if (opt.runtimeOptions?.screen) {
53
+ this._engine.screen.config = opt.runtimeOptions.screen;
54
+ }
55
+ this._editorMode = opt.runtimeOptions?.editorMode ?? 'none';
56
+ this._device = null;
51
57
  this._ready = false;
52
58
  }
53
59
  /**
60
+ * Editor mode
61
+ */ get editorMode() {
62
+ return this._editorMode;
63
+ }
64
+ /**
54
65
  * The input manager instance handling pointer/keyboard event routing.
55
66
  */ get inputManager() {
56
67
  return this._inputManager;
@@ -101,6 +112,7 @@ import { getApp, setApp } from './api.js';
101
112
  await this._engine.init();
102
113
  this._inputManager.start();
103
114
  this._device.on('resize', (width, height)=>{
115
+ this._engine.screen.resolveViewport();
104
116
  this.dispatchEvent('resize', width, height);
105
117
  });
106
118
  this._ready = true;
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sources":["../../src/app/app.ts"],"sourcesContent":["import type { VFS } from '@zephyr3d/base';\r\nimport { Observable, flushPendingDisposals } from '@zephyr3d/base';\r\nimport type { AbstractDevice, DeviceBackend } from '@zephyr3d/device';\r\nimport { InputManager } from './inputmgr';\r\nimport { Engine } from './engine';\r\nimport { getApp, setApp } from './api';\r\n\r\ntype appEventMap = {\r\n /**\r\n * Emitted when the drawing surface (canvas/device) is resized.\r\n *\r\n * @param width - New drawable width in device pixels.\r\n * @param height - New drawable height in device pixels.\r\n */\r\n resize: [width: number, height: number];\r\n /**\r\n * Emitted every frame with timing information.\r\n *\r\n * @param deltaTimeMs - Elapsed time since last frame in milliseconds.\r\n * @param elapsedTimeMs - Elapsed time since app start in milliseconds.\r\n */\r\n tick: [deltaTimeMs: number, elapsedTimeMs: number];\r\n /** Pointer/mouse and keyboard input events forwarded by the Application. */\r\n click: [evt: PointerEvent];\r\n dblclick: [evt: PointerEvent];\r\n pointerdown: [evt: PointerEvent];\r\n pointerup: [evt: PointerEvent];\r\n pointermove: [evt: PointerEvent];\r\n pointercancel: [evt: PointerEvent];\r\n pointerenter: [evt: PointerEvent];\r\n pointerleave: [evt: PointerEvent];\r\n pointerover: [evt: PointerEvent];\r\n pointerout: [evt: PointerEvent];\r\n wheel: [evt: WheelEvent];\r\n keydown: [evt: KeyboardEvent];\r\n keyup: [evt: KeyboardEvent];\r\n keypress: [evt: KeyboardEvent];\r\n drag: [evt: DragEvent];\r\n dragenter: [evt: DragEvent];\r\n dragleave: [evt: DragEvent];\r\n dragover: [evt: DragEvent];\r\n dragstart: [evt: DragEvent];\r\n dragend: [evt: DragEvent];\r\n drop: [evt: DragEvent];\r\n};\r\n\r\n/**\r\n * Creation options for Application.\r\n *\r\n * Provides the canvas, device backend, and optional runtime and device configuration.\r\n * @public\r\n */\r\nexport type AppOptions = {\r\n /**\r\n * Target canvas element to attach the rendering device to.\r\n */\r\n canvas: HTMLCanvasElement;\r\n /**\r\n * Device backend implementation to use for GPU creation (e.g., WebGL/WebGPU backend).\r\n */\r\n backend: DeviceBackend;\r\n /**\r\n * Whether to enable multi-sample anti-aliasing (MSAA) if supported by the backend.\r\n * Defaults to false.\r\n */\r\n enableMSAA?: boolean;\r\n /**\r\n * Device pixel ratio used when creating the device. Defaults to `window.devicePixelRatio` or 1.\r\n */\r\n pixelRatio?: number;\r\n /**\r\n * Options for the runtime scripting system.\r\n */\r\n runtimeOptions?: {\r\n /**\r\n * Virtual file system used to load scripts. Defaults to HttpFS at '.' if not provided.\r\n */\r\n VFS?: VFS;\r\n /**\r\n * Root directory for script files. Defaults to '/'.\r\n */\r\n scriptsRoot?: string;\r\n /**\r\n * Whether the application is running in editor mode. Should be true for user applications.\r\n */\r\n editorMode?: boolean;\r\n /**\r\n * Whether the runtime scripting system is enabled. Should be true for user applications.\r\n */\r\n enabled?: boolean;\r\n };\r\n};\r\n\r\n/**\r\n * Log severity levels.\r\n * @public\r\n */\r\nexport type LogMode = 'info' | 'warn' | 'error' | 'debug';\r\n\r\n/**\r\n * Application\r\n *\r\n * Entry-point and lifecycle coordinator for the engine. Responsible for:\r\n * - Creating and owning the rendering device from a chosen backend.\r\n * - Managing the per-frame loop, including timing and viewport setup.\r\n * - Forwarding device/DOM input events via an observable event map.\r\n * - Hosting the runtime scripting system and input manager.\r\n *\r\n * Singleton:\r\n * - Only one instance may exist at a time. Access via `{@link getApp}`.\r\n *\r\n * Events:\r\n * - See `appEventMap` for all emitted events (resize, tick, pointer/keyboard/drag).\r\n *\r\n * Usage:\r\n * - Construct with `AppOptions`, await `ready()`, then call `run()` to start the loop.\r\n *\r\n * @public\r\n */\r\nexport class Application extends Observable<appEventMap> {\r\n private readonly _options: AppOptions;\r\n private _device: AbstractDevice;\r\n private readonly _inputManager: InputManager;\r\n private readonly _engine: Engine;\r\n private _ready: boolean;\r\n /**\r\n * Construct the Application singleton with the provided options.\r\n *\r\n * Throws if an instance already exists.\r\n *\r\n * @param opt - Application creation options (canvas, backend, and optional runtime/device settings).\r\n */\r\n constructor(opt: AppOptions) {\r\n super();\r\n if (getApp()) {\r\n throw new Error('It is not allowed to have multiple Application instances');\r\n }\r\n setApp(this);\r\n\r\n this._options = {\r\n backend: opt.backend,\r\n enableMSAA: opt.enableMSAA ?? false,\r\n pixelRatio: opt.pixelRatio ?? window.devicePixelRatio ?? 1,\r\n canvas: opt.canvas\r\n };\r\n this._inputManager = new InputManager(this);\r\n this._engine = new Engine(\r\n opt.runtimeOptions?.VFS,\r\n opt.runtimeOptions?.scriptsRoot,\r\n opt.runtimeOptions?.editorMode,\r\n opt.runtimeOptions?.enabled\r\n );\r\n this._ready = false;\r\n }\r\n /**\r\n * The input manager instance handling pointer/keyboard event routing.\r\n */\r\n get inputManager(): InputManager {\r\n return this._inputManager;\r\n }\r\n /**\r\n * Get the instanceof {@link Engine}.\r\n */\r\n get engine(): Engine {\r\n return this._engine;\r\n }\r\n /**\r\n * The (sanitized) options used to create this application.\r\n *\r\n * Note: Defaults are applied for `enableMSAA` and `pixelRatio` if omitted.\r\n */\r\n get options(): AppOptions {\r\n return this._options;\r\n }\r\n /**\r\n * The initialized rendering device.\r\n *\r\n * Available after `await ready()`.\r\n */\r\n get device(): AbstractDevice {\r\n return this._device;\r\n }\r\n /**\r\n * Convenience accessor for the device type name provided by the backend.\r\n */\r\n get deviceType(): string {\r\n return this._options.backend.typeName();\r\n }\r\n /**\r\n * Set keyboard focus to the device's canvas element.\r\n */\r\n focus() {\r\n this._device.canvas.focus();\r\n }\r\n /**\r\n * Initialize the rendering device and start input processing.\r\n *\r\n * @throws If device creation fails.\r\n */\r\n async ready() {\r\n if (!this._ready) {\r\n this._device = await this._options.backend.createDevice(this._options.canvas, {\r\n dpr: this._options.pixelRatio,\r\n msaa: !!this._options.enableMSAA\r\n });\r\n if (!this._device) {\r\n throw new Error('App.init(): create device failed');\r\n }\r\n this._device.canvas.focus();\r\n await this._engine.init();\r\n this._inputManager.start();\r\n this._device.on('resize', (width, height) => {\r\n this.dispatchEvent('resize', width, height);\r\n });\r\n this._ready = true;\r\n }\r\n }\r\n /**\r\n * Render a single frame.\r\n *\r\n * Steps:\r\n * - Flushes pending disposals from the previous frame.\r\n * - Clears device state (framebuffer, viewport, scissor).\r\n * - Queries frame timing from the device (`elapsedFrame`, `elapsedOverall`).\r\n * - Updates the runtime manager (scripting/behaviors).\r\n * - Emits `tick` with delta/elapsed times.\r\n *\r\n * Safe to call manually; also used by the run loop.\r\n */\r\n frame() {\r\n // Processes all pending disposals from the previous frame.\r\n flushPendingDisposals();\r\n if (this._ready) {\r\n this.device.setFramebuffer(null);\r\n this.device.setViewport(null);\r\n this.device.setScissor(null);\r\n const dt = this.device.frameInfo.elapsedFrame;\r\n const elapsed = this.device.frameInfo.elapsedOverall;\r\n this.dispatchEvent('tick', dt, elapsed);\r\n this._engine.update(dt * 0.001, elapsed * 0.001);\r\n this._engine.render();\r\n }\r\n }\r\n /**\r\n * Start the application's render loop.\r\n *\r\n * Uses the device's internal scheduling (`device.runLoop`) to repeatedly call `frame()`.\r\n */\r\n run() {\r\n this.device.runLoop(() => {\r\n this.frame();\r\n });\r\n }\r\n /**\r\n * Stop the application's render loop.\r\n *\r\n * Uses `device.exitLoop()` to end the scheduling started by `run()`.\r\n */\r\n stop() {\r\n this.device.exitLoop();\r\n }\r\n}\r\n"],"names":["Application","Observable","_options","_device","_inputManager","_engine","_ready","opt","getApp","Error","setApp","backend","enableMSAA","pixelRatio","window","devicePixelRatio","canvas","InputManager","Engine","runtimeOptions","VFS","scriptsRoot","editorMode","enabled","inputManager","engine","options","device","deviceType","typeName","focus","ready","createDevice","dpr","msaa","init","start","on","width","height","dispatchEvent","frame","flushPendingDisposals","setFramebuffer","setViewport","setScissor","dt","frameInfo","elapsedFrame","elapsed","elapsedOverall","update","render","run","runLoop","stop","exitLoop"],"mappings":";;;;;AAmGA;;;;;;;;;;;;;;;;;;;IAoBO,MAAMA,WAAoBC,SAAAA,UAAAA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AChB,MAAM,CAACiB,WAAW,CAAC,IAAA,CAAA;AACxB,YAAA,IAAI,CAACjB,MAAM,CAACkB,UAAU,CAAC,IAAA,CAAA;AACvB,YAAA,MAAMC,KAAK,IAAI,CAACnB,MAAM,CAACoB,SAAS,CAACC,YAAY;AAC7C,YAAA,MAAMC,UAAU,IAAI,CAACtB,MAAM,CAACoB,SAAS,CAACG,cAAc;AACpD,YAAA,IAAI,CAACV,aAAa,CAAC,MAAA,EAAQM,EAAIG,EAAAA,OAAAA,CAAAA;AAC/B,YAAA,IAAI,CAAC5C,OAAO,CAAC8C,MAAM,CAACL,EAAAA,GAAK,OAAOG,OAAU,GAAA,KAAA,CAAA;YAC1C,IAAI,CAAC5C,OAAO,CAAC+C,MAAM,EAAA;AACrB;AACF;AACA;;;;AAIC,MACDC,GAAM,GAAA;AACJ,QAAA,IAAI,CAAC1B,MAAM,CAAC2B,OAAO,CAAC,IAAA;AAClB,YAAA,IAAI,CAACb,KAAK,EAAA;AACZ,SAAA,CAAA;AACF;AACA;;;;AAIC,MACDc,IAAO,GAAA;QACL,IAAI,CAAC5B,MAAM,CAAC6B,QAAQ,EAAA;AACtB;AACF;;;;"}
1
+ {"version":3,"file":"app.js","sources":["../../src/app/app.ts"],"sourcesContent":["import type { Nullable, RequireOptionals, VFS } from '@zephyr3d/base';\r\nimport { Observable, flushPendingDisposals } from '@zephyr3d/base';\r\nimport type { AbstractDevice, DeviceBackend } from '@zephyr3d/device';\r\nimport { InputManager } from './inputmgr';\r\nimport { Engine } from './engine';\r\nimport { getApp, setApp } from './api';\r\nimport type { ScreenConfig } from './screen';\r\n\r\ntype appEventMap = {\r\n /**\r\n * Emitted when the drawing surface (canvas/device) is resized.\r\n *\r\n * @param width - New drawable width in device pixels.\r\n * @param height - New drawable height in device pixels.\r\n */\r\n resize: [width: number, height: number];\r\n /**\r\n * Emitted every frame with timing information.\r\n *\r\n * @param deltaTimeMs - Elapsed time since last frame in milliseconds.\r\n * @param elapsedTimeMs - Elapsed time since app start in milliseconds.\r\n */\r\n tick: [deltaTimeMs: number, elapsedTimeMs: number];\r\n /** Pointer/mouse and keyboard input events forwarded by the Application. */\r\n click: [evt: PointerEvent];\r\n dblclick: [evt: PointerEvent];\r\n pointerdown: [evt: PointerEvent];\r\n pointerup: [evt: PointerEvent];\r\n pointermove: [evt: PointerEvent];\r\n pointercancel: [evt: PointerEvent];\r\n pointerenter: [evt: PointerEvent];\r\n pointerleave: [evt: PointerEvent];\r\n pointerover: [evt: PointerEvent];\r\n pointerout: [evt: PointerEvent];\r\n wheel: [evt: WheelEvent];\r\n keydown: [evt: KeyboardEvent];\r\n keyup: [evt: KeyboardEvent];\r\n keypress: [evt: KeyboardEvent];\r\n drag: [evt: DragEvent];\r\n dragenter: [evt: DragEvent];\r\n dragleave: [evt: DragEvent];\r\n dragover: [evt: DragEvent];\r\n dragstart: [evt: DragEvent];\r\n dragend: [evt: DragEvent];\r\n drop: [evt: DragEvent];\r\n};\r\n\r\n/** Editor Mode */\r\nexport type EditorMode = 'editor' | 'editor-preview' | 'none';\r\n\r\n/**\r\n * Options for Application.\r\n *\r\n * @public\r\n */\r\nexport interface AppOptions {\r\n /**\r\n * Target canvas element to attach the rendering device to.\r\n */\r\n canvas: HTMLCanvasElement;\r\n /**\r\n * Device backend implementation to use for GPU creation (e.g., WebGL/WebGPU backend).\r\n */\r\n backend: DeviceBackend;\r\n /**\r\n * Whether to enable multi-sample anti-aliasing (MSAA) if supported by the backend.\r\n * Defaults to false.\r\n */\r\n enableMSAA?: boolean;\r\n /**\r\n * Device pixel ratio used when creating the device. Defaults to `window.devicePixelRatio` or 1.\r\n */\r\n pixelRatio?: number;\r\n}\r\n\r\n/**\r\n * Creation options for Application.\r\n *\r\n * Provides the canvas, device backend, and optional runtime and device configuration.\r\n * @public\r\n */\r\nexport interface AppCreationOptions extends AppOptions {\r\n /**\r\n * Options for the runtime scripting system.\r\n */\r\n runtimeOptions?: {\r\n /**\r\n * Virtual file system used to load scripts. Defaults to HttpFS at '.' if not provided.\r\n */\r\n VFS?: VFS;\r\n /**\r\n * Root directory for script files. Defaults to '/'.\r\n */\r\n scriptsRoot?: string;\r\n /**\r\n * Whether the application is running in editor mode. Should be true for user applications.\r\n */\r\n editorMode?: EditorMode;\r\n /**\r\n * Whether the runtime scripting system is enabled. Should be true for user applications.\r\n */\r\n enabled?: boolean;\r\n /**\r\n * Screen configuration\r\n */\r\n screen?: ScreenConfig;\r\n };\r\n}\r\n\r\n/**\r\n * Log severity levels.\r\n * @public\r\n */\r\nexport type LogMode = 'info' | 'warn' | 'error' | 'debug';\r\n\r\n/**\r\n * Application\r\n *\r\n * Entry-point and lifecycle coordinator for the engine. Responsible for:\r\n * - Creating and owning the rendering device from a chosen backend.\r\n * - Managing the per-frame loop, including timing and viewport setup.\r\n * - Forwarding device/DOM input events via an observable event map.\r\n * - Hosting the runtime scripting system and input manager.\r\n *\r\n * Singleton:\r\n * - Only one instance may exist at a time. Access via `{@link getApp}`.\r\n *\r\n * Events:\r\n * - See `appEventMap` for all emitted events (resize, tick, pointer/keyboard/drag).\r\n *\r\n * Usage:\r\n * - Construct with `AppOptions`, await `ready()`, then call `run()` to start the loop.\r\n *\r\n * @public\r\n */\r\nexport class Application extends Observable<appEventMap> {\r\n private readonly _options: RequireOptionals<AppOptions>;\r\n private _device: Nullable<AbstractDevice>;\r\n private readonly _inputManager: InputManager;\r\n private readonly _engine: Engine;\r\n private readonly _editorMode: EditorMode;\r\n private _ready: boolean;\r\n /**\r\n * Construct the Application singleton with the provided options.\r\n *\r\n * Throws if an instance already exists.\r\n *\r\n * @param opt - Application creation options (canvas, backend, and optional runtime/device settings).\r\n */\r\n constructor(opt: AppCreationOptions) {\r\n super();\r\n if (getApp()) {\r\n throw new Error('It is not allowed to have multiple Application instances');\r\n }\r\n setApp(this);\r\n\r\n this._options = {\r\n backend: opt.backend,\r\n enableMSAA: opt.enableMSAA ?? false,\r\n pixelRatio: opt.pixelRatio ?? window.devicePixelRatio ?? 1,\r\n canvas: opt.canvas\r\n };\r\n this._inputManager = new InputManager(this);\r\n this._engine = new Engine(\r\n opt.runtimeOptions?.VFS,\r\n opt.runtimeOptions?.scriptsRoot,\r\n opt.runtimeOptions?.enabled\r\n );\r\n if (opt.runtimeOptions?.screen) {\r\n this._engine.screen.config = opt.runtimeOptions.screen;\r\n }\r\n this._editorMode = opt.runtimeOptions?.editorMode ?? 'none';\r\n this._device = null;\r\n this._ready = false;\r\n }\r\n /**\r\n * Editor mode\r\n */\r\n get editorMode() {\r\n return this._editorMode;\r\n }\r\n /**\r\n * The input manager instance handling pointer/keyboard event routing.\r\n */\r\n get inputManager() {\r\n return this._inputManager;\r\n }\r\n /**\r\n * Get the instanceof {@link Engine}.\r\n */\r\n get engine() {\r\n return this._engine;\r\n }\r\n /**\r\n * The (sanitized) options used to create this application.\r\n *\r\n * Note: Defaults are applied for `enableMSAA` and `pixelRatio` if omitted.\r\n */\r\n get options() {\r\n return this._options;\r\n }\r\n /**\r\n * The initialized rendering device.\r\n *\r\n * Available after `await ready()`.\r\n */\r\n get device() {\r\n return this._device!;\r\n }\r\n /**\r\n * Convenience accessor for the device type name provided by the backend.\r\n */\r\n get deviceType() {\r\n return this._options.backend.typeName();\r\n }\r\n /**\r\n * Set keyboard focus to the device's canvas element.\r\n */\r\n focus() {\r\n this._device!.canvas.focus();\r\n }\r\n /**\r\n * Initialize the rendering device and start input processing.\r\n *\r\n * @throws If device creation fails.\r\n */\r\n async ready() {\r\n if (!this._ready) {\r\n this._device = await this._options.backend.createDevice(this._options.canvas, {\r\n dpr: this._options.pixelRatio,\r\n msaa: !!this._options.enableMSAA\r\n });\r\n if (!this._device) {\r\n throw new Error('App.init(): create device failed');\r\n }\r\n this._device.canvas.focus();\r\n await this._engine.init();\r\n this._inputManager.start();\r\n this._device.on('resize', (width, height) => {\r\n this._engine.screen.resolveViewport();\r\n this.dispatchEvent('resize', width, height);\r\n });\r\n this._ready = true;\r\n }\r\n }\r\n /**\r\n * Render a single frame.\r\n *\r\n * Steps:\r\n * - Flushes pending disposals from the previous frame.\r\n * - Clears device state (framebuffer, viewport, scissor).\r\n * - Queries frame timing from the device (`elapsedFrame`, `elapsedOverall`).\r\n * - Updates the runtime manager (scripting/behaviors).\r\n * - Emits `tick` with delta/elapsed times.\r\n *\r\n * Safe to call manually; also used by the run loop.\r\n */\r\n frame() {\r\n // Processes all pending disposals from the previous frame.\r\n flushPendingDisposals();\r\n if (this._ready) {\r\n this.device.setFramebuffer(null);\r\n this.device.setViewport(null);\r\n this.device.setScissor(null);\r\n const dt = this.device.frameInfo.elapsedFrame;\r\n const elapsed = this.device.frameInfo.elapsedOverall;\r\n this.dispatchEvent('tick', dt, elapsed);\r\n this._engine.update(dt * 0.001, elapsed * 0.001);\r\n this._engine.render();\r\n }\r\n }\r\n /**\r\n * Start the application's render loop.\r\n *\r\n * Uses the device's internal scheduling (`device.runLoop`) to repeatedly call `frame()`.\r\n */\r\n run() {\r\n this.device.runLoop(() => {\r\n this.frame();\r\n });\r\n }\r\n /**\r\n * Stop the application's render loop.\r\n *\r\n * Uses `device.exitLoop()` to end the scheduling started by `run()`.\r\n */\r\n stop() {\r\n this.device.exitLoop();\r\n }\r\n}\r\n"],"names":["Application","Observable","_options","_device","_inputManager","_engine","_editorMode","_ready","opt","getApp","Error","setApp","backend","enableMSAA","pixelRatio","window","devicePixelRatio","canvas","InputManager","Engine","runtimeOptions","VFS","scriptsRoot","enabled","screen","config","editorMode","inputManager","engine","options","device","deviceType","typeName","focus","ready","createDevice","dpr","msaa","init","start","on","width","height","resolveViewport","dispatchEvent","frame","flushPendingDisposals","setFramebuffer","setViewport","setScissor","dt","frameInfo","elapsedFrame","elapsed","elapsedOverall","update","render","run","runLoop","stop","exitLoop"],"mappings":";;;;;AAmHA;;;;;;;;;;;;;;;;;;;IAoBO,MAAMA,WAAoBC,SAAAA,UAAAA,CAAAA;IACdC,QAAuC;IAChDC,OAAkC;IACzBC,aAA4B;IAC5BC,OAAgB;IAChBC,WAAwB;IACjC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AAOC,EAAAA,MAAAA,CAAAA;AACtC,aAAA,CAAA;YACA,IAAI,CAACnC,MAAM,GAAG,IAAA;AAChB;AACF;AACA;;;;;;;;;;;AAWC,MACDsC,KAAQ,GAAA;;AAENC,QAAAA,qBAAAA,EAAAA;QACA,IAAI,IAAI,CAACvC,MAAM,EAAE;AACf,YAAA,IAAI,CAACuB,MAAM,CAACiB,cAAc,CAAC,IAAA,CAAA;AAC3B,YAAA,IAAI,CAACjB,MAAM,CAACkB,WAAW,CAAC,IAAA,CAAA;AACxB,YAAA,IAAI,CAAClB,MAAM,CAACmB,UAAU,CAAC,IAAA,CAAA;AACvB,YAAA,MAAMC,KAAK,IAAI,CAACpB,MAAM,CAACqB,SAAS,CAACC,YAAY;AAC7C,YAAA,MAAMC,UAAU,IAAI,CAACvB,MAAM,CAACqB,SAAS,CAACG,cAAc;AACpD,YAAA,IAAI,CAACV,aAAa,CAAC,MAAA,EAAQM,EAAIG,EAAAA,OAAAA,CAAAA;AAC/B,YAAA,IAAI,CAAChD,OAAO,CAACkD,MAAM,CAACL,EAAAA,GAAK,OAAOG,OAAU,GAAA,KAAA,CAAA;YAC1C,IAAI,CAAChD,OAAO,CAACmD,MAAM,EAAA;AACrB;AACF;AACA;;;;AAIC,MACDC,GAAM,GAAA;AACJ,QAAA,IAAI,CAAC3B,MAAM,CAAC4B,OAAO,CAAC,IAAA;AAClB,YAAA,IAAI,CAACb,KAAK,EAAA;AACZ,SAAA,CAAA;AACF;AACA;;;;AAIC,MACDc,IAAO,GAAA;QACL,IAAI,CAAC7B,MAAM,CAAC8B,QAAQ,EAAA;AACtB;AACF;;;;"}
@@ -1,48 +1,30 @@
1
- import { HttpFS, DRef, MemoryFS } from '@zephyr3d/base';
1
+ import { HttpFS, DRef, MemoryFS, objectEntries } from '@zephyr3d/base';
2
2
  import { ScriptingSystem } from './scriptingsystem.js';
3
- import '../utility/pmrem.js';
4
- import '../utility/panorama.js';
3
+ import { ResourceManager } from '../utility/serialization/manager.js';
5
4
  import '../render/primitive.js';
6
- import '@zephyr3d/device';
7
- import '../scene/scene.js';
8
- import '../values.js';
5
+ import { BoxShape } from '../shapes/box.js';
6
+ import { CylinderShape } from '../shapes/cylinder.js';
7
+ import { TorusShape } from '../shapes/torus.js';
8
+ import { PlaneShape } from '../shapes/plane.js';
9
+ import { SphereShape } from '../shapes/sphere.js';
10
+ import { TetrahedronShape } from '../shapes/tetrahedron.js';
9
11
  import '../material/shader/helper.js';
10
12
  import { LambertMaterial } from '../material/lambert.js';
11
13
  import { BlinnMaterial } from '../material/blinn.js';
12
14
  import { UnlitMaterial } from '../material/unlit.js';
13
15
  import '../material/particle.js';
16
+ import '@zephyr3d/device';
17
+ import '../values.js';
14
18
  import '../material/meshmaterial.js';
15
19
  import '../material/grassmaterial.js';
16
- import '../material/terrainmaterial.js';
17
20
  import '../material/terrain-cm.js';
18
21
  import { PBRMetallicRoughnessMaterial } from '../material/pbrmr.js';
19
22
  import { PBRSpecularGlossinessMaterial } from '../material/pbrsg.js';
20
23
  import '../material/pbrblueprint.js';
21
- import '../render/renderer.js';
22
- import '../render/sky.js';
23
- import '../render/clipmap.js';
24
- import '../shaders/atmosphere.js';
25
- import '../scene/scene_node.js';
26
- import '../shadow/shadowmapper.js';
27
- import '../scene/mesh.js';
28
- import '../scene/water.js';
29
- import '../scene/particlesys.js';
30
- import '../scene/batchgroup.js';
31
- import '../scene/terrain/patch.js';
32
- import '../scene/terrain/grass.js';
33
- import '../scene/terrain-cm/terrain-cm.js';
34
- import '../scene/terrain-cm/grass.js';
35
- import '../camera/camera.js';
36
- import '../animation/eulerrotationtrack.js';
37
- import '../animation/skeleton.js';
38
- import { ResourceManager } from '../utility/serialization/manager.js';
24
+ import '../material/sprite.js';
25
+ import { StandardSpriteMaterial } from '../material/sprite_std.js';
39
26
  import '../utility/blueprint/material/texture.js';
40
- import { BoxShape } from '../shapes/box.js';
41
- import { CylinderShape } from '../shapes/cylinder.js';
42
- import { TorusShape } from '../shapes/torus.js';
43
- import { PlaneShape } from '../shapes/plane.js';
44
- import { SphereShape } from '../shapes/sphere.js';
45
- import { TetrahedronShape } from '../shapes/tetrahedron.js';
27
+ import { ScreenAdapter } from './screen.js';
46
28
 
47
29
  /**
48
30
  * Core engine class managing scripting, serialization, and rendering.
@@ -65,6 +47,7 @@ import { TetrahedronShape } from '../shapes/tetrahedron.js';
65
47
  _scriptingSystem;
66
48
  _resourceManager;
67
49
  _enabled;
50
+ _screen;
68
51
  _activeRenderables;
69
52
  _loadingScenes;
70
53
  /**
@@ -72,20 +55,19 @@ import { TetrahedronShape } from '../shapes/tetrahedron.js';
72
55
  *
73
56
  * @param VFS - Optional virtual file system passed to the internal {@link ScriptingSystem}.
74
57
  * @param scriptsRoot - Optional scripts root path within the VFS. Defaults as in `ScriptingSystem`.
75
- * @param editorMode - Optional editor mode flag for the underlying `ScriptingSystem`.
76
58
  * @param enabled - Whether runtime operations are active. Defaults to `true`.
77
- */ constructor(VFS, scriptsRoot, editorMode, enabled){
59
+ */ constructor(VFS, scriptsRoot, enabled){
78
60
  VFS = VFS ?? new HttpFS('./');
79
61
  this._builtinsVFS = null;
80
62
  this._scriptingSystem = new ScriptingSystem({
81
63
  VFS,
82
- scriptsRoot,
83
- editorMode
64
+ scriptsRoot
84
65
  });
85
66
  this._resourceManager = new ResourceManager(VFS);
86
67
  this._enabled = enabled ?? true;
87
68
  this._activeRenderables = [];
88
- this._loadingScenes = [];
69
+ this._loadingScenes = {};
70
+ this._screen = new ScreenAdapter();
89
71
  }
90
72
  /**
91
73
  * Exposes the instance of {@link ScriptingSystem}.
@@ -110,6 +92,11 @@ import { TetrahedronShape } from '../shapes/tetrahedron.js';
110
92
  */ get resourceManager() {
111
93
  return this._resourceManager;
112
94
  }
95
+ /**
96
+ * Exposes the instanceof {@link Screen}
97
+ */ get screen() {
98
+ return this._screen;
99
+ }
113
100
  /** @internal */ async init() {
114
101
  await this.ensureBuiltinVFS();
115
102
  }
@@ -180,10 +167,11 @@ import { TetrahedronShape } from '../shapes/tetrahedron.js';
180
167
  setRenderable(renderable, layer = 0, hook) {
181
168
  if (!this._activeRenderables[layer]) {
182
169
  this._activeRenderables[layer] = {
183
- renderable: new DRef(null)
170
+ renderable: new DRef(null),
171
+ hook: null
184
172
  };
185
173
  }
186
- this._activeRenderables[layer].hook = hook;
174
+ this._activeRenderables[layer].hook = hook ?? null;
187
175
  this._activeRenderables[layer].renderable.set(renderable);
188
176
  }
189
177
  async readFile(path, encoding) {
@@ -216,16 +204,15 @@ import { TetrahedronShape } from '../shapes/tetrahedron.js';
216
204
  this.setRenderable(null, splashScreenLayer);
217
205
  }
218
206
  render() {
219
- for (const k of Object.keys(this._activeRenderables)){
220
- const info = this._activeRenderables[k];
207
+ this._activeRenderables.forEach((info)=>{
221
208
  const render = info.hook?.beforeRender ? info.hook.beforeRender(info.renderable.get() ?? null) ?? true : true;
222
- if (render && info.renderable.get()) {
223
- info.renderable.get().render();
209
+ if (render) {
210
+ info.renderable.get()?.render();
224
211
  }
225
212
  if (info.hook?.afterRender) {
226
213
  info.hook.afterRender(info.renderable.get() ?? null);
227
214
  }
228
- }
215
+ });
229
216
  }
230
217
  async ensureBuiltinVFS() {
231
218
  if (!this._builtinsVFS) {
@@ -247,9 +234,10 @@ import { TetrahedronShape } from '../shapes/tetrahedron.js';
247
234
  '/materials/lambert.zmtl': LambertMaterial,
248
235
  '/materials/blinnphong.zmtl': BlinnMaterial,
249
236
  '/materials/pbr_metallic_roughness.zmtl': PBRMetallicRoughnessMaterial,
250
- '/materials/pbr_specular_glossiness.zmtl': PBRSpecularGlossinessMaterial
237
+ '/materials/pbr_specular_glossiness.zmtl': PBRSpecularGlossinessMaterial,
238
+ '/materials/sprite_std.zmtl': StandardSpriteMaterial
251
239
  };
252
- for (const key of Object.keys(shapeClsMap)){
240
+ for (const [key] of objectEntries(shapeClsMap)){
253
241
  const obj = new shapeClsMap[key]();
254
242
  await this.writeSerializableObject(fs, 'Default', obj, key);
255
243
  obj.dispose();
@@ -1 +1 @@
1
- {"version":3,"file":"engine.js","sources":["../../src/app/engine.ts"],"sourcesContent":["import type { IDisposable, ReadOptions } from '@zephyr3d/base';\r\nimport { MemoryFS } 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 } from './runtimescript';\r\nimport { ResourceManager } from '../utility';\r\nimport type { Scene } from '../scene';\r\nimport { BoxShape, CylinderShape, PlaneShape, SphereShape, TetrahedronShape, TorusShape } from '../shapes';\r\nimport {\r\n BlinnMaterial,\r\n LambertMaterial,\r\n PBRMetallicRoughnessMaterial,\r\n PBRSpecularGlossinessMaterial,\r\n UnlitMaterial\r\n} from '../material';\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\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: MemoryFS;\r\n private _scriptingSystem: ScriptingSystem;\r\n private _resourceManager: ResourceManager;\r\n private _enabled: boolean;\r\n protected _activeRenderables: {\r\n renderable: DRef<IRenderable>;\r\n hook?: IRenderHook;\r\n }[];\r\n private _loadingScenes: Record<string, Promise<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 editorMode - Optional editor mode flag for the underlying `ScriptingSystem`.\r\n * @param enabled - Whether runtime operations are active. Defaults to `true`.\r\n */\r\n constructor(VFS?: VFS, scriptsRoot?: string, editorMode?: boolean, enabled?: boolean) {\r\n VFS = VFS ?? new HttpFS('./');\r\n this._builtinsVFS = null;\r\n this._scriptingSystem = new ScriptingSystem({ VFS, scriptsRoot, editorMode });\r\n this._resourceManager = new ResourceManager(VFS);\r\n this._enabled = enabled ?? true;\r\n this._activeRenderables = [];\r\n this._loadingScenes = [];\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 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 /** @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 * 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 * @returns The `RuntimeScript<T>` instance, or `null` if disabled or on failure.\r\n */\r\n async attachScript<T extends Host>(host: T, module: string): Promise<RuntimeScript<T>> {\r\n return this._enabled ? await this._scriptingSystem.attachScript(host, module) : 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): T[] {\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 * Delegates to {@link ScriptingSystem.update}. No-op when disabled.\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 async loadSceneFromFile(path: string): Promise<Scene> {\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 setRenderable(renderable: IRenderable, layer = 0, hook?: IRenderHook) {\r\n if (!this._activeRenderables[layer]) {\r\n this._activeRenderables[layer] = {\r\n renderable: new DRef<IRenderable>(null)\r\n };\r\n }\r\n this._activeRenderables[layer].hook = hook;\r\n this._activeRenderables[layer].renderable.set(renderable);\r\n }\r\n async readFile<T extends ReadOptions['encoding'] = 'binary'>(\r\n path: string,\r\n encoding?: T\r\n ): Promise<T extends 'binary' ? ArrayBuffer : string> {\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 async startup(startupScene: string, splashScreen: string, startupScript: string) {\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 render() {\r\n for (const k of Object.keys(this._activeRenderables)) {\r\n const info = this._activeRenderables[k];\r\n const render = info.hook?.beforeRender\r\n ? (info.hook.beforeRender(info.renderable.get() ?? null) ?? true)\r\n : true;\r\n if (render && info.renderable.get()) {\r\n info.renderable.get().render();\r\n }\r\n if (info.hook?.afterRender) {\r\n info.hook.afterRender(info.renderable.get() ?? null);\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(): Promise<MemoryFS> {\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 '/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 } as const;\r\n for (const key of Object.keys(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): Promise<Scene> {\r\n try {\r\n const scene = await this._resourceManager.loadScene(path);\r\n if (scene) {\r\n if (scene.script) {\r\n try {\r\n await this.attachScript(scene, scene.script);\r\n } catch (err) {\r\n console.error(`Attach script failed: ${err}`);\r\n }\r\n }\r\n const P: Promise<any>[] = [];\r\n const scripts: string[] = [];\r\n scene.rootNode.iterate((node) => {\r\n if (node.script) {\r\n scripts.push(node.script);\r\n P.push(this.attachScript(node, node.script));\r\n }\r\n });\r\n if (P.length > 0) {\r\n const result = await Promise.allSettled(P);\r\n for (let i = 0; i < result.length; i++) {\r\n if (result[i].status === 'rejected') {\r\n console.error(`Attach script failed: ${scripts[i]}`);\r\n }\r\n }\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"],"names":["Engine","_builtinsVFS","_scriptingSystem","_resourceManager","_enabled","_activeRenderables","_loadingScenes","VFS","scriptsRoot","editorMode","enabled","HttpFS","ScriptingSystem","ResourceManager","scriptingSystem","registry","vfs","close","ensureBuiltinVFS","resourceManager","init","detachAllScripts","attachScript","host","module","detachScript","idOrInstance","getScriptObjects","update","deltaTime","elapsedTime","loadSceneFromFile","path","normalizePath","_loadScene","setRenderable","renderable","layer","hook","DRef","set","readFile","encoding","content","err","console","error","startup","startupScene","splashScreen","startupScript","splashScreenLayer","splashScreenScene","toLowerCase","endsWith","slice","scene","render","k","Object","keys","info","beforeRender","get","afterRender","createBuiltinVFS","unmount","mount","fs","MemoryFS","shapeClsMap","BoxShape","SphereShape","CylinderShape","PlaneShape","TorusShape","TetrahedronShape","UnlitMaterial","LambertMaterial","BlinnMaterial","PBRMetallicRoughnessMaterial","PBRSpecularGlossinessMaterial","key","obj","writeSerializableObject","dispose","readOnly","type","data","serializeObject","JSON","stringify","writeFile","create","loadScene","script","P","scripts","rootNode","iterate","node","push","length","result","Promise","allSettled","i","status"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMA,MAAAA,CAAAA;IACHC,YAAuB;IACvBC,gBAAkC;IAClCC,gBAAkC;IAClCC,QAAkB;IAChBC,kBAGN;IACIC,cAAiD;AACzD;;;;;;;MAQA,WAAA,CAAYC,GAAS,EAAEC,WAAoB,EAAEC,UAAoB,EAAEC,OAAiB,CAAE;QACpFH,GAAMA,GAAAA,GAAAA,IAAO,IAAII,MAAO,CAAA,IAAA,CAAA;QACxB,IAAI,CAACV,YAAY,GAAG,IAAA;AACpB,QAAA,IAAI,CAACC,gBAAgB,GAAG,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AA;AACxC,oBAAA,IAAK,IAAIU,CAAI,GAAA,CAAA,EAAGA,IAAIH,MAAOD,CAAAA,MAAM,EAAEI,CAAK,EAAA,CAAA;AACtC,wBAAA,IAAIH,MAAM,CAACG,CAAAA,CAAE,CAACC,MAAM,KAAK,UAAY,EAAA;4BACnC9D,OAAQC,CAAAA,KAAK,CAAC,CAAC,sBAAsB,EAAEmD,OAAO,CAACS,EAAE,CAAE,CAAA,CAAA;AACrD;AACF;AACF;AACF;YACA,OAAOlD,KAAAA;AACT,SAAA,CAAE,OAAOZ,GAAK,EAAA;YACZC,OAAQC,CAAAA,KAAK,CAAC,CAAC,iBAAiB,EAAEd,IAAK,CAAA,UAAU,EAAEY,GAAK,CAAA,CAAA,CAAA;YACxD,OAAO,IAAA;AACT;AACF;AACF;;;;"}
1
+ {"version":3,"file":"engine.js","sources":["../../src/app/engine.ts"],"sourcesContent":["import type { 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 } from './runtimescript';\r\nimport { ResourceManager } from '../utility/serialization/manager';\r\nimport type { Scene } from '../scene';\r\nimport { BoxShape, CylinderShape, PlaneShape, SphereShape, TetrahedronShape, TorusShape } 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\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\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 _enabled: boolean;\r\n private _screen: ScreenAdapter;\r\n protected _activeRenderables: {\r\n renderable: 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._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 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 instanceof {@link Screen}\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 * 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 * @returns The `RuntimeScript<T>` instance, or `null` if disabled or on failure.\r\n */\r\n async attachScript<T extends Host>(host: Nullable<T>, module: string) {\r\n return this._enabled ? await this._scriptingSystem.attachScript(host, module) : 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 * Delegates to {@link ScriptingSystem.update}. No-op when disabled.\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 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 setRenderable(renderable: Nullable<IRenderable>, layer = 0, hook?: IRenderHook) {\r\n if (!this._activeRenderables[layer]) {\r\n this._activeRenderables[layer] = {\r\n renderable: new DRef<IRenderable>(null),\r\n hook: null\r\n };\r\n }\r\n this._activeRenderables[layer].hook = hook ?? null;\r\n this._activeRenderables[layer].renderable.set(renderable);\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 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 render() {\r\n this._activeRenderables.forEach((info) => {\r\n const render = info.hook?.beforeRender\r\n ? (info.hook.beforeRender(info.renderable.get() ?? null) ?? true)\r\n : true;\r\n if (render) {\r\n info.renderable.get()?.render();\r\n }\r\n if (info.hook?.afterRender) {\r\n info.hook.afterRender(info.renderable.get() ?? null);\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 '/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 if (scene.script) {\r\n try {\r\n await this.attachScript(scene, scene.script);\r\n } catch (err) {\r\n console.error(`Attach script failed: ${err}`);\r\n }\r\n }\r\n const P: Promise<any>[] = [];\r\n const scripts: string[] = [];\r\n scene.rootNode.iterate((node) => {\r\n if (node.script) {\r\n scripts.push(node.script);\r\n P.push(this.attachScript(node, node.script));\r\n }\r\n });\r\n if (P.length > 0) {\r\n const result = await Promise.allSettled(P);\r\n for (let i = 0; i < result.length; i++) {\r\n if (result[i].status === 'rejected') {\r\n console.error(`Attach script failed: ${scripts[i]}`);\r\n }\r\n }\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"],"names":["Engine","_builtinsVFS","_scriptingSystem","_resourceManager","_enabled","_screen","_activeRenderables","_loadingScenes","VFS","scriptsRoot","enabled","HttpFS","ScriptingSystem","ResourceManager","ScreenAdapter","scriptingSystem","registry","vfs","close","ensureBuiltinVFS","resourceManager","screen","init","detachAllScripts","attachScript","host","module","detachScript","idOrInstance","getScriptObjects","update","deltaTime","elapsedTime","loadSceneFromFile","path","normalizePath","_loadScene","setRenderable","renderable","layer","hook","DRef","set","readFile","encoding","content","err","console","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","UnlitMaterial","LambertMaterial","BlinnMaterial","PBRMetallicRoughnessMaterial","PBRSpecularGlossinessMaterial","StandardSpriteMaterial","key","objectEntries","obj","writeSerializableObject","dispose","readOnly","type","data","serializeObject","JSON","stringify","writeFile","create","loadScene","script","P","scripts","rootNode","iterate","node","push","length","result","Promise","allSettled","i","status"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMA,MAAAA,CAAAA;IACHC,YAAiC;IACjCC,gBAAkC;IAClCC,gBAAkC;IAClCC,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,CAACV,YAAY,GAAG,IAAA;AACpB,QAAA,IAAI,CAACC,gBAAgB,GAAG,IAAIU,eAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKC,YAAAA;AAAY,SAAA,CAAA;AAC/D,QAAA,IAAI,CAACN,gBAAgB,GAAG,IAAIU,eAAgBL,CAAAA,GAAAA,CAAAA;QAC5C,IAAI,CAACJ,QAAQ,GAAGM,OAAW,IAAA,IAAA;QAC3B,IAAI,CAACJ,kBAAkB,GAAG,EAAE;QAC5B,IAAI,CAACC,cAAc,GAAG,EAAC;QACvB,IAAI,CAACF,OAAO,GAAG,IAAIS,aAAAA,EAAAA;AACrB;AACA;;AAEC,MACD,IAAIC,eAAkB,GAAA;QACpB,OAAO,IAAI,CAACb,gBAAgB;AAC9B;AACA;;AAEC,MACD,IAAIM,GAAM,GAAA;AACR,QAAA,OAAO,IAAI,CAACN,gBAAgB,CAACc,QAAQ,CAACR,GAAG;AAC3C;IACA,IAAIA,GAAAA,CAAIS,GAAQ,EAAE;AAChB,QAAA,IAAIA,QAAQ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