@zephyr3d/scene 0.9.27 → 0.10.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 (502) hide show
  1. package/README.md +60 -27
  2. package/dist/animation/animation_bank.js +634 -0
  3. package/dist/animation/animation_bank.js.map +1 -0
  4. package/dist/animation/animation_bank_gpu.js +256 -0
  5. package/dist/animation/animation_bank_gpu.js.map +1 -0
  6. package/dist/animation/animationset.js +54 -0
  7. package/dist/animation/animationset.js.map +1 -1
  8. package/dist/animation/cloth/gpu_cloth_component.js +406 -0
  9. package/dist/animation/cloth/gpu_cloth_component.js.map +1 -0
  10. package/dist/animation/cloth/gpu_cloth_system.js +332 -202
  11. package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
  12. package/dist/animation/gpu_animation_driver.js +289 -0
  13. package/dist/animation/gpu_animation_driver.js.map +1 -0
  14. package/dist/animation/joint_dynamics/collision.js +112 -1
  15. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  16. package/dist/animation/joint_dynamics/controller.js +6 -0
  17. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  18. package/dist/animation/joint_dynamics/joint_dynamics_system.js +11 -0
  19. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  20. package/dist/animation/joint_dynamics/solver.js +50 -12
  21. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  22. package/dist/animation/joint_dynamics/types.js.map +1 -1
  23. package/dist/animation/skeleton.js +279 -55
  24. package/dist/animation/skeleton.js.map +1 -1
  25. package/dist/animation/skin_palette_atlas.js +252 -0
  26. package/dist/animation/skin_palette_atlas.js.map +1 -0
  27. package/dist/animation/spring/multi_chain_spring_system.js +298 -38
  28. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -1
  29. package/dist/animation/spring/spring_chain.js +2 -0
  30. package/dist/animation/spring/spring_chain.js.map +1 -1
  31. package/dist/animation/spring/spring_collider.js +159 -21
  32. package/dist/animation/spring/spring_collider.js.map +1 -1
  33. package/dist/animation/spring/spring_particle.js +1 -0
  34. package/dist/animation/spring/spring_particle.js.map +1 -1
  35. package/dist/animation/spring/spring_solver.js +173 -0
  36. package/dist/animation/spring/spring_solver.js.map +1 -0
  37. package/dist/animation/spring/spring_system.js +249 -24
  38. package/dist/animation/spring/spring_system.js.map +1 -1
  39. package/dist/animation/spring_modifier.js +32 -1
  40. package/dist/animation/spring_modifier.js.map +1 -1
  41. package/dist/app/app.js +26 -0
  42. package/dist/app/app.js.map +1 -1
  43. package/dist/app/engine.js +86 -15
  44. package/dist/app/engine.js.map +1 -1
  45. package/dist/app/gamepad.js +191 -0
  46. package/dist/app/gamepad.js.map +1 -0
  47. package/dist/app/inputactions.js +271 -0
  48. package/dist/app/inputactions.js.map +1 -0
  49. package/dist/app/inputmgr.js +331 -22
  50. package/dist/app/inputmgr.js.map +1 -1
  51. package/dist/app/loading.js +138 -0
  52. package/dist/app/loading.js.map +1 -0
  53. package/dist/app/pipelinecache.js +209 -0
  54. package/dist/app/pipelinecache.js.map +1 -0
  55. package/dist/app/runtimescript.js +25 -0
  56. package/dist/app/runtimescript.js.map +1 -1
  57. package/dist/app/scriptingsystem.js +54 -0
  58. package/dist/app/scriptingsystem.js.map +1 -1
  59. package/dist/app/scriptregistry.js +7 -2
  60. package/dist/app/scriptregistry.js.map +1 -1
  61. package/dist/asset/asset_manifest.js +59 -0
  62. package/dist/asset/asset_manifest.js.map +1 -0
  63. package/dist/asset/asset_preload.js +258 -0
  64. package/dist/asset/asset_preload.js.map +1 -0
  65. package/dist/asset/assetmanager.js +117 -65
  66. package/dist/asset/assetmanager.js.map +1 -1
  67. package/dist/asset/loaders/ktx2/basis/LICENSE +201 -0
  68. package/dist/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
  69. package/dist/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
  70. package/dist/asset/loaders/ktx2/basis_location.js +17 -0
  71. package/dist/asset/loaders/ktx2/basis_location.js.map +1 -0
  72. package/dist/asset/loaders/ktx2/ktx2_loader.js +88 -0
  73. package/dist/asset/loaders/ktx2/ktx2_loader.js.map +1 -0
  74. package/dist/asset/loaders/ktx2/ktx2_targets.js +118 -0
  75. package/dist/asset/loaders/ktx2/ktx2_targets.js.map +1 -0
  76. package/dist/asset/loaders/ktx2/transcoder_pool.js +259 -0
  77. package/dist/asset/loaders/ktx2/transcoder_pool.js.map +1 -0
  78. package/dist/asset/mesh_lod_builder.js +104 -0
  79. package/dist/asset/mesh_lod_builder.js.map +1 -0
  80. package/dist/asset/mesh_settings.js +111 -0
  81. package/dist/asset/mesh_settings.js.map +1 -0
  82. package/dist/asset/meshopt_decoder.js +18 -0
  83. package/dist/asset/meshopt_decoder.js.map +1 -0
  84. package/dist/asset/meshopt_simplifier.js +26 -0
  85. package/dist/asset/meshopt_simplifier.js.map +1 -0
  86. package/dist/asset/model.js +171 -1
  87. package/dist/asset/model.js.map +1 -1
  88. package/dist/asset/texture_settings.js +231 -0
  89. package/dist/asset/texture_settings.js.map +1 -0
  90. package/dist/asset/zmsh_binary.js +131 -0
  91. package/dist/asset/zmsh_binary.js.map +1 -0
  92. package/dist/asset/zsdf_binary.js +111 -0
  93. package/dist/asset/zsdf_binary.js.map +1 -0
  94. package/dist/blitter/bilateralblur.js +1 -2
  95. package/dist/blitter/bilateralblur.js.map +1 -1
  96. package/dist/blitter/gaussianblur.js +1 -6
  97. package/dist/blitter/gaussianblur.js.map +1 -1
  98. package/dist/camera/base.js +31 -10
  99. package/dist/camera/base.js.map +1 -1
  100. package/dist/camera/camera.js +104 -178
  101. package/dist/camera/camera.js.map +1 -1
  102. package/dist/camera/follow.js +342 -0
  103. package/dist/camera/follow.js.map +1 -0
  104. package/dist/camera/fps.js +9 -7
  105. package/dist/camera/fps.js.map +1 -1
  106. package/dist/camera/orbit.js +46 -19
  107. package/dist/camera/orbit.js.map +1 -1
  108. package/dist/index.d.ts +25436 -15990
  109. package/dist/index.js +65 -11
  110. package/dist/index.js.map +1 -1
  111. package/dist/material/blinn.js +3 -0
  112. package/dist/material/blinn.js.map +1 -1
  113. package/dist/material/eye.js +1 -1
  114. package/dist/material/eye.js.map +1 -1
  115. package/dist/material/hair.js +2 -3
  116. package/dist/material/hair.js.map +1 -1
  117. package/dist/material/lambert.js +4 -1
  118. package/dist/material/lambert.js.map +1 -1
  119. package/dist/material/material.js +66 -4
  120. package/dist/material/material.js.map +1 -1
  121. package/dist/material/meshmaterial.js +118 -45
  122. package/dist/material/meshmaterial.js.map +1 -1
  123. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  124. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  125. package/dist/material/mixins/lightmodel/lambert.js +1 -1
  126. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  127. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +34 -61
  128. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  129. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +16 -2
  130. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  131. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +2 -1
  132. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  133. package/dist/material/mixins/lit.js +191 -83
  134. package/dist/material/mixins/lit.js.map +1 -1
  135. package/dist/material/mixins/pbr/common.js +31 -206
  136. package/dist/material/mixins/pbr/common.js.map +1 -1
  137. package/dist/material/mtoon.js +1 -1
  138. package/dist/material/mtoon.js.map +1 -1
  139. package/dist/material/pbrmr.js +3 -0
  140. package/dist/material/pbrmr.js.map +1 -1
  141. package/dist/material/pbrsg.js +3 -0
  142. package/dist/material/pbrsg.js.map +1 -1
  143. package/dist/material/sdf_debug.js +78 -0
  144. package/dist/material/sdf_debug.js.map +1 -0
  145. package/dist/material/shader/helper.js +333 -191
  146. package/dist/material/shader/helper.js.map +1 -1
  147. package/dist/material/shader/terrain_blend.js +204 -43
  148. package/dist/material/shader/terrain_blend.js.map +1 -1
  149. package/dist/material/skin.js +331 -297
  150. package/dist/material/skin.js.map +1 -1
  151. package/dist/material/skinprofile.js +1058 -0
  152. package/dist/material/skinprofile.js.map +1 -0
  153. package/dist/material/sss.js +353 -0
  154. package/dist/material/sss.js.map +1 -0
  155. package/dist/material/sss_kernel.js +265 -0
  156. package/dist/material/sss_kernel.js.map +1 -0
  157. package/dist/material/sssprofile.js +879 -0
  158. package/dist/material/sssprofile.js.map +1 -0
  159. package/dist/material/subsurfaceprofile.js +4 -8
  160. package/dist/material/subsurfaceprofile.js.map +1 -1
  161. package/dist/material/terrain-cm.js +464 -188
  162. package/dist/material/terrain-cm.js.map +1 -1
  163. package/dist/material/unlit.js +3 -0
  164. package/dist/material/unlit.js.map +1 -1
  165. package/dist/material/water.js +1261 -1438
  166. package/dist/material/water.js.map +1 -1
  167. package/dist/node_modules/meshoptimizer/LICENSE +21 -0
  168. package/dist/node_modules/meshoptimizer/meshopt_decoder.js +197 -0
  169. package/dist/node_modules/meshoptimizer/meshopt_decoder.js.map +1 -0
  170. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js +677 -0
  171. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js.map +1 -0
  172. package/dist/physics/character.js +226 -0
  173. package/dist/physics/character.js.map +1 -0
  174. package/dist/physics/collider.js +209 -0
  175. package/dist/physics/collider.js.map +1 -0
  176. package/dist/physics/events.js +79 -0
  177. package/dist/physics/events.js.map +1 -0
  178. package/dist/physics/joint.js +272 -0
  179. package/dist/physics/joint.js.map +1 -0
  180. package/dist/physics/node_physics.js +234 -0
  181. package/dist/physics/node_physics.js.map +1 -0
  182. package/dist/physics/part.js +91 -0
  183. package/dist/physics/part.js.map +1 -0
  184. package/dist/physics/rigid_body.js +379 -0
  185. package/dist/physics/rigid_body.js.map +1 -0
  186. package/dist/physics/vehicle.js +335 -0
  187. package/dist/physics/vehicle.js.map +1 -0
  188. package/dist/physics/world.js +25 -0
  189. package/dist/physics/world.js.map +1 -0
  190. package/dist/posteffect/bloom.js +49 -14
  191. package/dist/posteffect/bloom.js.map +1 -1
  192. package/dist/posteffect/motionblur.js +106 -106
  193. package/dist/posteffect/motionblur.js.map +1 -1
  194. package/dist/posteffect/postsss.js +572 -0
  195. package/dist/posteffect/postsss.js.map +1 -0
  196. package/dist/posteffect/sao.js +2 -6
  197. package/dist/posteffect/sao.js.map +1 -1
  198. package/dist/posteffect/skinsss.js +605 -355
  199. package/dist/posteffect/skinsss.js.map +1 -1
  200. package/dist/posteffect/ssgi.js +91 -162
  201. package/dist/posteffect/ssgi.js.map +1 -1
  202. package/dist/posteffect/ssr.js +3 -11
  203. package/dist/posteffect/ssr.js.map +1 -1
  204. package/dist/posteffect/sss.js +4 -13
  205. package/dist/posteffect/sss.js.map +1 -1
  206. package/dist/posteffect/taa.js +1 -0
  207. package/dist/posteffect/taa.js.map +1 -1
  208. package/dist/render/abuffer_oit.js +3 -2
  209. package/dist/render/abuffer_oit.js.map +1 -1
  210. package/dist/render/clipmap.js +179 -64
  211. package/dist/render/clipmap.js.map +1 -1
  212. package/dist/render/cluster_light.js +958 -224
  213. package/dist/render/cluster_light.js.map +1 -1
  214. package/dist/render/cull_visitor.js +25 -5
  215. package/dist/render/cull_visitor.js.map +1 -1
  216. package/dist/render/debug_views.js +37 -0
  217. package/dist/render/debug_views.js.map +1 -0
  218. package/dist/render/depthpass.js +5 -1
  219. package/dist/render/depthpass.js.map +1 -1
  220. package/dist/render/drawable_mixin.js +53 -6
  221. package/dist/render/drawable_mixin.js.map +1 -1
  222. package/dist/render/dualdepthpeeling_oit.js +5 -5
  223. package/dist/render/dualdepthpeeling_oit.js.map +1 -1
  224. package/dist/render/envlight.js +196 -113
  225. package/dist/render/envlight.js.map +1 -1
  226. package/dist/render/fbm_wavegenerator.js +5 -10
  227. package/dist/render/fbm_wavegenerator.js.map +1 -1
  228. package/dist/render/fft_wavegenerator.js +247 -157
  229. package/dist/render/fft_wavegenerator.js.map +1 -1
  230. package/dist/render/gerstner_wavegenerator.js +16 -38
  231. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  232. package/dist/render/gi/probe_volume.js +1334 -0
  233. package/dist/render/gi/probe_volume.js.map +1 -0
  234. package/dist/render/gi/scene_gi.js +282 -0
  235. package/dist/render/gi/scene_gi.js.map +1 -0
  236. package/dist/render/gi/voxel_atlas.js +198 -0
  237. package/dist/render/gi/voxel_atlas.js.map +1 -0
  238. package/dist/render/gi/voxel_lighting.js +652 -0
  239. package/dist/render/gi/voxel_lighting.js.map +1 -0
  240. package/dist/render/gi/voxel_scene.js +642 -0
  241. package/dist/render/gi/voxel_scene.js.map +1 -0
  242. package/dist/render/gi/voxelize_pass.js +223 -0
  243. package/dist/render/gi/voxelize_pass.js.map +1 -0
  244. package/dist/render/globalbindgroup_allocator.js +3 -2
  245. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  246. package/dist/render/gpu_picking.js +9 -36
  247. package/dist/render/gpu_picking.js.map +1 -1
  248. package/dist/render/instance_culling.js +499 -0
  249. package/dist/render/instance_culling.js.map +1 -0
  250. package/dist/render/lightpass.js +19 -8
  251. package/dist/render/lightpass.js.map +1 -1
  252. package/dist/render/lod.js +46 -0
  253. package/dist/render/lod.js.map +1 -0
  254. package/dist/render/primitive.js +301 -9
  255. package/dist/render/primitive.js.map +1 -1
  256. package/dist/render/primitive_readback.js +209 -0
  257. package/dist/render/primitive_readback.js.map +1 -0
  258. package/dist/render/render_queue.js +162 -11
  259. package/dist/render/render_queue.js.map +1 -1
  260. package/dist/render/renderer.js +10 -7
  261. package/dist/render/renderer.js.map +1 -1
  262. package/dist/render/rendergraph/blackboard.js +14 -1
  263. package/dist/render/rendergraph/blackboard.js.map +1 -1
  264. package/dist/render/rendergraph/executor.js +136 -0
  265. package/dist/render/rendergraph/executor.js.map +1 -1
  266. package/dist/render/rendergraph/forward_plus_builder.js +272 -55
  267. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  268. package/dist/render/rendergraph/frame_graph_context.js +41 -0
  269. package/dist/render/rendergraph/frame_graph_context.js.map +1 -0
  270. package/dist/render/rendergraph/scene_render_context.js +31 -2
  271. package/dist/render/rendergraph/scene_render_context.js.map +1 -1
  272. package/dist/render/rendergraph/types.js.map +1 -1
  273. package/dist/render/renderpass.js +28 -5
  274. package/dist/render/renderpass.js.map +1 -1
  275. package/dist/render/sdf/box_allocator.js +98 -0
  276. package/dist/render/sdf/box_allocator.js.map +1 -0
  277. package/dist/render/sdf/global_sdf.js +865 -0
  278. package/dist/render/sdf/global_sdf.js.map +1 -0
  279. package/dist/render/sdf/scene_sdf.js +562 -0
  280. package/dist/render/sdf/scene_sdf.js.map +1 -0
  281. package/dist/render/sdf/sdf_atlas.js +227 -0
  282. package/dist/render/sdf/sdf_atlas.js.map +1 -0
  283. package/dist/render/sdf/sdf_programs.js +42 -0
  284. package/dist/render/sdf/sdf_programs.js.map +1 -0
  285. package/dist/render/sdf/sdf_view.js +199 -0
  286. package/dist/render/sdf/sdf_view.js.map +1 -0
  287. package/dist/render/sdf/waterline.js +610 -0
  288. package/dist/render/sdf/waterline.js.map +1 -0
  289. package/dist/render/shadow_mask_pass.js +142 -25
  290. package/dist/render/shadow_mask_pass.js.map +1 -1
  291. package/dist/render/shore_wave_generator.js +1193 -0
  292. package/dist/render/shore_wave_generator.js.map +1 -0
  293. package/dist/render/sky.js +516 -86
  294. package/dist/render/sky.js.map +1 -1
  295. package/dist/render/transmission_thickness_pass.js +477 -0
  296. package/dist/render/transmission_thickness_pass.js.map +1 -0
  297. package/dist/render/underwater.js +58 -158
  298. package/dist/render/underwater.js.map +1 -1
  299. package/dist/render/virtualtexture/virtual_texture.js +1214 -0
  300. package/dist/render/virtualtexture/virtual_texture.js.map +1 -0
  301. package/dist/render/volumetric_cloud/cloud_common.js +472 -0
  302. package/dist/render/volumetric_cloud/cloud_common.js.map +1 -0
  303. package/dist/render/volumetric_cloud/cloud_noise.js +189 -0
  304. package/dist/render/volumetric_cloud/cloud_noise.js.map +1 -0
  305. package/dist/render/volumetric_cloud/debug_view.js +131 -0
  306. package/dist/render/volumetric_cloud/debug_view.js.map +1 -0
  307. package/dist/render/volumetric_cloud/resources.js +380 -0
  308. package/dist/render/volumetric_cloud/resources.js.map +1 -0
  309. package/dist/render/volumetric_cloud/sky_cache.js +380 -0
  310. package/dist/render/volumetric_cloud/sky_cache.js.map +1 -0
  311. package/dist/render/volumetric_cloud/volumetric_cloud.js +318 -0
  312. package/dist/render/volumetric_cloud/volumetric_cloud.js.map +1 -0
  313. package/dist/render/water_caustics.js +134 -319
  314. package/dist/render/water_caustics.js.map +1 -1
  315. package/dist/render/water_foam.js +627 -0
  316. package/dist/render/water_foam.js.map +1 -0
  317. package/dist/render/water_interaction.js +1795 -0
  318. package/dist/render/water_interaction.js.map +1 -0
  319. package/dist/render/weightedblended_oit.js +3 -3
  320. package/dist/render/weightedblended_oit.js.map +1 -1
  321. package/dist/scene/basesprite.js +9 -4
  322. package/dist/scene/basesprite.js.map +1 -1
  323. package/dist/scene/batchgroup.js +108 -12
  324. package/dist/scene/batchgroup.js.map +1 -1
  325. package/dist/scene/environment.js +28 -7
  326. package/dist/scene/environment.js.map +1 -1
  327. package/dist/scene/foliage.js +1020 -0
  328. package/dist/scene/foliage.js.map +1 -0
  329. package/dist/scene/foliage_buckets.js +147 -0
  330. package/dist/scene/foliage_buckets.js.map +1 -0
  331. package/dist/scene/foliage_mask.js +358 -0
  332. package/dist/scene/foliage_mask.js.map +1 -0
  333. package/dist/scene/hair.js +15 -4
  334. package/dist/scene/hair.js.map +1 -1
  335. package/dist/scene/light.js +179 -13
  336. package/dist/scene/light.js.map +1 -1
  337. package/dist/scene/mesh.js +327 -45
  338. package/dist/scene/mesh.js.map +1 -1
  339. package/dist/scene/meshdrawable.js +6 -0
  340. package/dist/scene/meshdrawable.js.map +1 -1
  341. package/dist/scene/msdftext.js +9 -3
  342. package/dist/scene/msdftext.js.map +1 -1
  343. package/dist/scene/msdftextsprite.js +9 -3
  344. package/dist/scene/msdftextsprite.js.map +1 -1
  345. package/dist/scene/particlesys.js +8 -2
  346. package/dist/scene/particlesys.js.map +1 -1
  347. package/dist/scene/physics_settings.js +157 -0
  348. package/dist/scene/physics_settings.js.map +1 -0
  349. package/dist/scene/scene.js +190 -44
  350. package/dist/scene/scene.js.map +1 -1
  351. package/dist/scene/scene_node.js +147 -6
  352. package/dist/scene/scene_node.js.map +1 -1
  353. package/dist/scene/terrain-cm/bladegrassmaterial.js +735 -0
  354. package/dist/scene/terrain-cm/bladegrassmaterial.js.map +1 -0
  355. package/dist/scene/terrain-cm/grass.js +881 -42
  356. package/dist/scene/terrain-cm/grass.js.map +1 -1
  357. package/dist/scene/terrain-cm/grass_gpu.js +929 -0
  358. package/dist/scene/terrain-cm/grass_gpu.js.map +1 -0
  359. package/dist/scene/terrain-cm/grassmaterial.js +180 -9
  360. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  361. package/dist/scene/terrain-cm/terrain-cm.js +465 -36
  362. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  363. package/dist/scene/terrain-cm/terrain_gi_albedo.js +257 -0
  364. package/dist/scene/terrain-cm/terrain_gi_albedo.js.map +1 -0
  365. package/dist/scene/terrain-cm/terrain_rvt.js +395 -0
  366. package/dist/scene/terrain-cm/terrain_rvt.js.map +1 -0
  367. package/dist/scene/update_queue.js +54 -0
  368. package/dist/scene/update_queue.js.map +1 -0
  369. package/dist/scene/water.js +633 -268
  370. package/dist/scene/water.js.map +1 -1
  371. package/dist/scene/water_surface_sampler.js +324 -0
  372. package/dist/scene/water_surface_sampler.js.map +1 -0
  373. package/dist/scene/wind.js +317 -0
  374. package/dist/scene/wind.js.map +1 -0
  375. package/dist/shaders/atmosphere.js +388 -166
  376. package/dist/shaders/atmosphere.js.map +1 -1
  377. package/dist/shaders/fog.js +100 -32
  378. package/dist/shaders/fog.js.map +1 -1
  379. package/dist/shaders/gi.js +365 -0
  380. package/dist/shaders/gi.js.map +1 -0
  381. package/dist/shaders/ltc_rect.js +202 -0
  382. package/dist/shaders/ltc_rect.js.map +1 -0
  383. package/dist/shaders/misc.js +1 -10
  384. package/dist/shaders/misc.js.map +1 -1
  385. package/dist/shaders/noise.js +5 -1
  386. package/dist/shaders/noise.js.map +1 -1
  387. package/dist/shaders/probes.js +309 -0
  388. package/dist/shaders/probes.js.map +1 -0
  389. package/dist/shaders/sdf.js +537 -0
  390. package/dist/shaders/sdf.js.map +1 -0
  391. package/dist/shaders/shadow.js +104 -70
  392. package/dist/shaders/shadow.js.map +1 -1
  393. package/dist/shaders/skin_brdf.js +243 -0
  394. package/dist/shaders/skin_brdf.js.map +1 -0
  395. package/dist/shaders/ssgi.js +63 -0
  396. package/dist/shaders/ssgi.js.map +1 -0
  397. package/dist/shaders/ssgi_reprojection.js +118 -0
  398. package/dist/shaders/ssgi_reprojection.js.map +1 -0
  399. package/dist/shaders/ssr.js +6 -159
  400. package/dist/shaders/ssr.js.map +1 -1
  401. package/dist/shaders/temporal.js +38 -27
  402. package/dist/shaders/temporal.js.map +1 -1
  403. package/dist/shaders/water.js +32 -82
  404. package/dist/shaders/water.js.map +1 -1
  405. package/dist/shaders/water_medium.js +7 -21
  406. package/dist/shaders/water_medium.js.map +1 -1
  407. package/dist/shadow/dom.js +110 -19
  408. package/dist/shadow/dom.js.map +1 -1
  409. package/dist/shadow/esm.js +3 -3
  410. package/dist/shadow/esm.js.map +1 -1
  411. package/dist/shadow/pcf_opt.js +15 -48
  412. package/dist/shadow/pcf_opt.js.map +1 -1
  413. package/dist/shadow/pcf_pd.js +15 -53
  414. package/dist/shadow/pcf_pd.js.map +1 -1
  415. package/dist/shadow/pcss.js +34 -9
  416. package/dist/shadow/pcss.js.map +1 -1
  417. package/dist/shadow/shadow_impl.js +3 -8
  418. package/dist/shadow/shadow_impl.js.map +1 -1
  419. package/dist/shadow/shadow_region.js +40 -2
  420. package/dist/shadow/shadow_region.js.map +1 -1
  421. package/dist/shadow/shadowmapper.js +93 -53
  422. package/dist/shadow/shadowmapper.js.map +1 -1
  423. package/dist/shadow/ssm.js +18 -72
  424. package/dist/shadow/ssm.js.map +1 -1
  425. package/dist/shadow/vsm.js +3 -3
  426. package/dist/shadow/vsm.js.map +1 -1
  427. package/dist/shapes/shape.js +44 -1
  428. package/dist/shapes/shape.js.map +1 -1
  429. package/dist/utility/buoyancy.js +287 -0
  430. package/dist/utility/buoyancy.js.map +1 -0
  431. package/dist/utility/physical.js +10 -1
  432. package/dist/utility/physical.js.map +1 -1
  433. package/dist/utility/pmrem.js +17 -43
  434. package/dist/utility/pmrem.js.map +1 -1
  435. package/dist/utility/sdf/bake.js +435 -0
  436. package/dist/utility/sdf/bake.js.map +1 -0
  437. package/dist/utility/sdf/bvh.js +576 -0
  438. package/dist/utility/sdf/bvh.js.map +1 -0
  439. package/dist/utility/serialization/manager.js +34 -6
  440. package/dist/utility/serialization/manager.js.map +1 -1
  441. package/dist/utility/serialization/scene/animation.js +46 -5
  442. package/dist/utility/serialization/scene/animation.js.map +1 -1
  443. package/dist/utility/serialization/scene/batch.js +11 -4
  444. package/dist/utility/serialization/scene/batch.js.map +1 -1
  445. package/dist/utility/serialization/scene/camera.js +87 -254
  446. package/dist/utility/serialization/scene/camera.js.map +1 -1
  447. package/dist/utility/serialization/scene/cloth.js +25 -0
  448. package/dist/utility/serialization/scene/cloth.js.map +1 -0
  449. package/dist/utility/serialization/scene/common.js +14 -6
  450. package/dist/utility/serialization/scene/common.js.map +1 -1
  451. package/dist/utility/serialization/scene/foliage.js +821 -0
  452. package/dist/utility/serialization/scene/foliage.js.map +1 -0
  453. package/dist/utility/serialization/scene/hair.js +11 -4
  454. package/dist/utility/serialization/scene/hair.js.map +1 -1
  455. package/dist/utility/serialization/scene/light.js +115 -7
  456. package/dist/utility/serialization/scene/light.js.map +1 -1
  457. package/dist/utility/serialization/scene/material.js +388 -220
  458. package/dist/utility/serialization/scene/material.js.map +1 -1
  459. package/dist/utility/serialization/scene/mesh.js +69 -4
  460. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  461. package/dist/utility/serialization/scene/node.js +140 -5
  462. package/dist/utility/serialization/scene/node.js.map +1 -1
  463. package/dist/utility/serialization/scene/node_physics.js +1318 -0
  464. package/dist/utility/serialization/scene/node_physics.js.map +1 -0
  465. package/dist/utility/serialization/scene/particle.js +11 -4
  466. package/dist/utility/serialization/scene/particle.js.map +1 -1
  467. package/dist/utility/serialization/scene/physics.js +120 -0
  468. package/dist/utility/serialization/scene/physics.js.map +1 -0
  469. package/dist/utility/serialization/scene/primitive.js +124 -10
  470. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  471. package/dist/utility/serialization/scene/scene.js +1687 -51
  472. package/dist/utility/serialization/scene/scene.js.map +1 -1
  473. package/dist/utility/serialization/scene/sprite.js +11 -4
  474. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  475. package/dist/utility/serialization/scene/terrain.js +163 -33
  476. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  477. package/dist/utility/serialization/scene/text.js +11 -4
  478. package/dist/utility/serialization/scene/text.js.map +1 -1
  479. package/dist/utility/serialization/scene/water.js +1543 -264
  480. package/dist/utility/serialization/scene/water.js.map +1 -1
  481. package/dist/utility/serialization/types.js.map +1 -1
  482. package/dist/utility/shprojector.js +10 -22
  483. package/dist/utility/shprojector.js.map +1 -1
  484. package/dist/utility/textures/foam.js +170 -0
  485. package/dist/utility/textures/foam.js.map +1 -0
  486. package/dist/utility/textures/ggxlut.js +17 -43
  487. package/dist/utility/textures/ggxlut.js.map +1 -1
  488. package/dist/utility/textures/ltcdata.js +4 -4
  489. package/dist/utility/textures/ltcdata.js.map +1 -1
  490. package/dist/utility/textures/ltclut.js +16 -6
  491. package/dist/utility/textures/ltclut.js.map +1 -1
  492. package/dist/utility/unsupported.js +24 -0
  493. package/dist/utility/unsupported.js.map +1 -0
  494. package/dist/values.js +13 -1
  495. package/dist/values.js.map +1 -1
  496. package/package.json +25 -12
  497. package/src/asset/loaders/ktx2/basis/LICENSE +201 -0
  498. package/src/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
  499. package/src/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
  500. package/src/asset/meshoptimizer/LICENSE +21 -0
  501. package/dist/animation/joint_dynamics/convex_collider.js +0 -320
  502. package/dist/animation/joint_dynamics/convex_collider.js.map +0 -1
@@ -0,0 +1,634 @@
1
+ import { Matrix4x4, Vector3, Quaternion, Disposable } from '@zephyr3d/base';
2
+ import { getDevice } from '../app/api.js';
3
+ import { BoundingBox } from '../utility/bounding_volume.js';
4
+ import { SkinPaletteAtlas } from './skin_palette_atlas.js';
5
+ import { AnimationBankGpuEvaluator } from './animation_bank_gpu.js';
6
+
7
+ /** Rate clips are sampled at when baked into a bank */ const ANIMATION_BANK_SAMPLE_RATE = 30;
8
+ /** Floats in one baked joint key: position xyz, rotation quaternion xyzw, scale xyz */ const KEY_FLOATS = 10;
9
+ const tmpMatrix = new Matrix4x4();
10
+ const tmpMatrix2 = new Matrix4x4();
11
+ const tmpPosition = new Vector3();
12
+ const tmpRotation = new Quaternion();
13
+ const tmpScale = new Vector3();
14
+ const tmpPoint = new Vector3();
15
+ const tmpPoint2 = new Vector3();
16
+ const tmpHeader = new Float32Array(16);
17
+ /**
18
+ * Skeletal animation clips of one skin baked into joint poses, played back without the joint
19
+ * scene nodes the clips were made for.
20
+ *
21
+ * @remarks
22
+ * Every clip is sampled at {@link ANIMATION_BANK_SAMPLE_RATE} frames per second into joint poses
23
+ * relative to the root of the skin, so that a pose is evaluated per joint without walking the
24
+ * joint hierarchy.
25
+ *
26
+ * A bank is played by {@link AnimationBankTrack}s. Each track owns one palette in the skin palette
27
+ * atlas, and any number of instances of the model skin their meshes by it, so a crowd costs the
28
+ * evaluation of its tracks rather than of its characters.
29
+ *
30
+ * Meshes skinned by a track do not run IK, joint dynamics or any other skeleton modifier, and do
31
+ * not blend clips.
32
+ *
33
+ * @public
34
+ */ class AnimationBank extends Disposable {
35
+ _jointCount;
36
+ _jointNames;
37
+ _inverseBindMatrices;
38
+ _entries;
39
+ _tracks;
40
+ _version;
41
+ /**
42
+ * Bake clips of an animation set into a bank for one skin.
43
+ *
44
+ * @remarks
45
+ * Sampling poses the joints of the skin; their transforms are restored afterwards. Only tracks
46
+ * targeting the joints of the skin, or the root joint of its rig, are sampled, and skeleton
47
+ * modifiers do not run.
48
+ *
49
+ * @param animationSet - Animation set holding the clips
50
+ * @param binding - Skin binding whose joints the clips animate
51
+ * @param clipNames - Names of the clips to bake, default all clips of the set. More can be added
52
+ * later with {@link addClip}
53
+ */ constructor(animationSet, binding, clipNames){
54
+ super();
55
+ this._jointCount = binding.joints.length;
56
+ this._jointNames = binding.joints.map((joint)=>joint.name);
57
+ this._inverseBindMatrices = binding.inverseBindMatrices.map((m)=>new Matrix4x4(new Float32Array(m)));
58
+ this._entries = [];
59
+ this._tracks = new Set();
60
+ this._version = 0;
61
+ const names = clipNames ?? animationSet.getAnimationNames();
62
+ for (const name of names){
63
+ this.addClip(animationSet, binding, name);
64
+ }
65
+ }
66
+ /**
67
+ * Bake one more clip into the bank.
68
+ *
69
+ * @param animationSet - Animation set holding the clip
70
+ * @param binding - Skin binding the bank was baked for, or a compatible one
71
+ * @param name - Name of the clip
72
+ * @returns Index of the entry, the existing one if the clip has been baked already, or -1 if
73
+ * the clip does not animate the joints of the skin
74
+ */ addClip(animationSet, binding, name) {
75
+ const index = this.getEntryIndex(name);
76
+ if (index >= 0) {
77
+ return index;
78
+ }
79
+ const entry = this.bakeClip(animationSet, binding, name);
80
+ if (!entry) {
81
+ return -1;
82
+ }
83
+ this._entries.push(entry);
84
+ this._version++;
85
+ return this._entries.length - 1;
86
+ }
87
+ /** Increased each time a clip is added */ get version() {
88
+ return this._version;
89
+ }
90
+ /** Number of joints of the skin */ get jointCount() {
91
+ return this._jointCount;
92
+ }
93
+ /** Baked clips */ get entries() {
94
+ return this._entries;
95
+ }
96
+ /** Inverse bind matrices of the joints of the skin */ get inverseBindMatrices() {
97
+ return this._inverseBindMatrices;
98
+ }
99
+ /**
100
+ * Gets the index of a baked clip by name.
101
+ *
102
+ * @param name - Name of the clip
103
+ * @returns Index of the entry, or -1 if the clip has not been baked
104
+ */ getEntryIndex(name) {
105
+ return this._entries.findIndex((entry)=>entry.name === name);
106
+ }
107
+ /**
108
+ * Whether a skin binding has the joints this bank was baked for, in the same order.
109
+ *
110
+ * @param binding - Skin binding to check
111
+ */ isCompatible(binding) {
112
+ const joints = binding.joints;
113
+ return joints.length === this._jointCount && joints.every((joint, i)=>joint.name === this._jointNames[i]) && // Skins sharing a rig differ by their inverse bind matrices
114
+ binding.inverseBindMatrices.every((m, i)=>m.equalsTo(this._inverseBindMatrices[i], 1e-4));
115
+ }
116
+ /**
117
+ * Create a track playing a baked clip.
118
+ *
119
+ * @param clip - Name or entry index of the clip
120
+ * @param options - Playback options
121
+ * @returns The track
122
+ */ createTrack(clip, options) {
123
+ const index = typeof clip === 'number' ? clip : this.getEntryIndex(clip);
124
+ if (index < 0 || index >= this._entries.length) {
125
+ throw new Error(`AnimationBank.createTrack(): clip not baked: ${clip}`);
126
+ }
127
+ const track = new AnimationBankTrack(this, index, options);
128
+ this._tracks.add(track);
129
+ return track;
130
+ }
131
+ /**
132
+ * Write the skinning palette of a pose to the skin palette atlas.
133
+ *
134
+ * @remarks
135
+ * The two keys around the position are blended, positions and scales linearly and rotations by
136
+ * normalized linear interpolation along the shorter arc, and the pose is followed by the inverse
137
+ * bind matrix.
138
+ *
139
+ * @internal
140
+ */ writePalette(entryIndex, position, slot, out) {
141
+ const entry = this._entries[entryIndex];
142
+ const { key0, key1, alpha } = getKeyIndicesFromTime(position, entry.frameCount, entry.playLength);
143
+ const keys = entry.keys;
144
+ const n = this._jointCount;
145
+ for(let i = 0; i < n; i++){
146
+ blendKeys(keys, (key0 * n + i) * KEY_FLOATS, (key1 * n + i) * KEY_FLOATS, alpha, tmpMatrix);
147
+ Matrix4x4.multiplyAffine(tmpMatrix, this._inverseBindMatrices[i], tmpMatrix2);
148
+ out.set(tmpMatrix2, i * 16);
149
+ }
150
+ SkinPaletteAtlas.instance.writeSlots(slot, out);
151
+ }
152
+ /**
153
+ * Compute the bounds of a mesh over all frames of a baked clip.
154
+ *
155
+ * @param entryIndex - Index of the baked clip
156
+ * @param mesh - Mesh skinned by the bank
157
+ * @param binding - Skin binding of the mesh, whose reference node the keys are relative to
158
+ * @returns Bounds in the local space of the mesh, or null if the mesh has no skinned bounding data
159
+ * @internal
160
+ */ computeBoundingBox(entryIndex, mesh, binding) {
161
+ const info = mesh.skinnedBoundingInfo;
162
+ if (!info) {
163
+ return null;
164
+ }
165
+ const entry = this._entries[entryIndex];
166
+ const skinSpace = mesh.getSkinSpaceMatrix(binding);
167
+ const influenceCount = Math.max(1, info.influenceCount ?? 4);
168
+ const n = this._jointCount;
169
+ const box = new BoundingBox();
170
+ box.beginExtend();
171
+ for(let frame = 0; frame < entry.frameCount; frame++){
172
+ for(let v = 0; v < info.boundingVertices.length; v++){
173
+ tmpPoint.setXYZ(0, 0, 0);
174
+ for(let j = 0; j < influenceCount; j++){
175
+ const weight = Number(info.boundingVertexJointWeights[v * influenceCount + j]) || 0;
176
+ const joint = Number(info.boundingVertexBlendIndices[v * influenceCount + j]) || 0;
177
+ if (weight <= 0 || joint >= n) {
178
+ continue;
179
+ }
180
+ const offset = (frame * n + joint) * KEY_FLOATS;
181
+ blendKeys(entry.keys, offset, offset, 0, tmpMatrix);
182
+ Matrix4x4.multiplyAffine(tmpMatrix, this._inverseBindMatrices[joint], tmpMatrix2);
183
+ tmpMatrix2.transformPointAffine(info.boundingVertices[v], tmpPoint2).scaleBy(weight);
184
+ tmpPoint.addBy(tmpPoint2);
185
+ }
186
+ box.extend(skinSpace.transformPointAffine(tmpPoint, tmpPoint));
187
+ }
188
+ }
189
+ return box.isValid() ? box : null;
190
+ }
191
+ /** @internal */ removeTrack(track) {
192
+ this._tracks.delete(track);
193
+ }
194
+ /** Dispose all tracks of the bank */ onDispose() {
195
+ super.onDispose();
196
+ for (const track of [
197
+ ...this._tracks
198
+ ]){
199
+ track.dispose();
200
+ }
201
+ }
202
+ bakeClip(animationSet, binding, name) {
203
+ const clip = animationSet.get(name);
204
+ if (!clip) {
205
+ console.error(`AnimationBank: animation not found: ${name}`);
206
+ return null;
207
+ }
208
+ const rig = binding.rig;
209
+ const joints = new Set(binding.joints);
210
+ if (rig.rootJoint) {
211
+ joints.add(rig.rootJoint);
212
+ }
213
+ const tracks = [
214
+ ...clip.tracks
215
+ ].filter(([target])=>joints.has(target));
216
+ if (tracks.length === 0) {
217
+ return null;
218
+ }
219
+ // Keep the joint transforms so baking leaves the model as it was
220
+ const saved = [
221
+ ...joints
222
+ ].map((joint)=>{
223
+ const node = joint;
224
+ return {
225
+ node,
226
+ position: node.position.clone(),
227
+ rotation: node.rotation.clone(),
228
+ scale: node.scale.clone()
229
+ };
230
+ });
231
+ const playLength = clip.timeDuration;
232
+ const frameCount = Math.max(1, Math.round(playLength * ANIMATION_BANK_SAMPLE_RATE) + 1);
233
+ const n = binding.joints.length;
234
+ const keys = new Float32Array(frameCount * n * KEY_FLOATS);
235
+ const reference = binding.referenceNode;
236
+ try {
237
+ rig.computeBindPose();
238
+ for(let frame = 0; frame < frameCount; frame++){
239
+ const time = frameCount > 1 ? playLength * frame / (frameCount - 1) : 0;
240
+ for (const [target, targetTracks] of tracks){
241
+ for (const track of targetTracks){
242
+ const t = playLength > 0 ? time / playLength * track.getDuration() : 0;
243
+ track.applyState(target, track.calculateState(target, t));
244
+ }
245
+ }
246
+ const invReference = reference ? Matrix4x4.invertAffine(reference.worldMatrix, tmpMatrix2) : null;
247
+ for(let i = 0; i < n; i++){
248
+ const world = binding.joints[i].worldMatrix;
249
+ if (invReference) {
250
+ Matrix4x4.multiplyAffine(invReference, world, tmpMatrix);
251
+ } else {
252
+ tmpMatrix.set(world);
253
+ }
254
+ tmpMatrix.decompose(tmpScale, tmpRotation, tmpPosition);
255
+ const offset = (frame * n + i) * KEY_FLOATS;
256
+ keys[offset] = tmpPosition.x;
257
+ keys[offset + 1] = tmpPosition.y;
258
+ keys[offset + 2] = tmpPosition.z;
259
+ keys[offset + 3] = tmpRotation.x;
260
+ keys[offset + 4] = tmpRotation.y;
261
+ keys[offset + 5] = tmpRotation.z;
262
+ keys[offset + 6] = tmpRotation.w;
263
+ keys[offset + 7] = tmpScale.x;
264
+ keys[offset + 8] = tmpScale.y;
265
+ keys[offset + 9] = tmpScale.z;
266
+ }
267
+ }
268
+ } finally{
269
+ for (const { node, position, rotation, scale } of saved){
270
+ node.position.set(position);
271
+ node.rotation.set(rotation);
272
+ node.scale.set(scale);
273
+ }
274
+ }
275
+ return {
276
+ name,
277
+ frameCount,
278
+ playLength: frameCount > 1 ? playLength : 0,
279
+ keys
280
+ };
281
+ }
282
+ }
283
+ /**
284
+ * A playing clip of an animation bank, owning one skinning palette that any number of meshes
285
+ * of compatible skins are skinned by.
286
+ *
287
+ * @remarks
288
+ * Tracks advance once per frame before the skin palette atlas is uploaded. The palette keeps
289
+ * the previous pose as well, for motion vectors.
290
+ *
291
+ * Where supported (WebGPU), palettes are evaluated in a compute pass, see
292
+ * {@link AnimationBankTrackOptions.evaluation}; elsewhere on the CPU. Both produce the same pose.
293
+ *
294
+ * @public
295
+ */ class AnimationBankTrack extends Disposable {
296
+ static _activeTracks = new Set();
297
+ static _updateFrame = -1;
298
+ _bank;
299
+ _entryIndex;
300
+ _position;
301
+ /** Position at the previous evaluation, for the previous pose of GPU evaluation */ _previousPosition;
302
+ /** Position the palette was last evaluated at */ _evaluatedPosition;
303
+ /** Whether the palette is evaluated on the GPU, into fixed current and previous sets */ _gpu;
304
+ _playRate;
305
+ _loop;
306
+ _autoPlay;
307
+ _block;
308
+ /** Offsets of the current and previous sets in the block, as `SkinBinding` keeps them */ _offsets;
309
+ _dirty;
310
+ _palette;
311
+ _meshes;
312
+ /** @internal */ constructor(bank, entryIndex, options){
313
+ super();
314
+ this._bank = bank;
315
+ this._entryIndex = entryIndex;
316
+ this._playRate = options?.playRate ?? 1;
317
+ this._loop = options?.loop ?? true;
318
+ this._autoPlay = options?.autoPlay ?? true;
319
+ this._position = this.wrap(options?.position ?? 0);
320
+ this._previousPosition = this._position;
321
+ this._evaluatedPosition = this._position;
322
+ this._gpu = (options?.evaluation ?? 'auto') === 'auto' && AnimationBankGpuEvaluator.isSupported();
323
+ this._block = SkinPaletteAtlas.instance.allocate(bank.jointCount * 2 + 1);
324
+ this._offsets = [
325
+ 0,
326
+ 0
327
+ ];
328
+ this._dirty = true;
329
+ this._palette = new Float32Array(this._gpu ? 0 : bank.jointCount * 16);
330
+ this._meshes = new Map();
331
+ AnimationBankTrack._activeTracks.add(this);
332
+ if (this._gpu) {
333
+ // Fixed sets, both rewritten by every dispatch
334
+ this._offsets[0] = 1;
335
+ this._offsets[1] = 1 + bank.jointCount;
336
+ this.writeHeader();
337
+ AnimationBankGpuEvaluator.addTrack(this);
338
+ } else {
339
+ this.evaluate();
340
+ }
341
+ }
342
+ /**
343
+ * Advance all tracks by the frame time, once per device frame.
344
+ *
345
+ * @internal
346
+ */ static updateAll(deltaInSeconds) {
347
+ const frame = getDevice().frameInfo.frameCounter;
348
+ if (frame !== this._updateFrame) {
349
+ this._updateFrame = frame;
350
+ for (const track of this._activeTracks){
351
+ track.update(deltaInSeconds);
352
+ }
353
+ }
354
+ }
355
+ /** The bank this track plays */ get bank() {
356
+ return this._bank;
357
+ }
358
+ /** Name of the clip playing */ get clipName() {
359
+ return this._bank.entries[this._entryIndex].name;
360
+ }
361
+ /** Length of the clip in seconds */ get playLength() {
362
+ return this._bank.entries[this._entryIndex].playLength;
363
+ }
364
+ /** Playback position in seconds */ get position() {
365
+ return this._position;
366
+ }
367
+ set position(val) {
368
+ this._position = this.wrap(val);
369
+ this._dirty = true;
370
+ }
371
+ /** Playback rate, negative values play backwards */ get playRate() {
372
+ return this._playRate;
373
+ }
374
+ set playRate(val) {
375
+ this._playRate = val;
376
+ }
377
+ /** Whether playback wraps around at either end */ get loop() {
378
+ return this._loop;
379
+ }
380
+ set loop(val) {
381
+ this._loop = val;
382
+ }
383
+ /** Whether the position advances with time */ get autoPlay() {
384
+ return this._autoPlay;
385
+ }
386
+ set autoPlay(val) {
387
+ this._autoPlay = val;
388
+ }
389
+ /** Slot index of the palette header in the skin palette atlas */ get paletteBase() {
390
+ return this._block?.base ?? 0;
391
+ }
392
+ /** Whether the palette is evaluated on the GPU */ get gpuEvaluated() {
393
+ return this._gpu;
394
+ }
395
+ /** @internal */ get entryIndex() {
396
+ return this._entryIndex;
397
+ }
398
+ /** @internal Position of the previous pose */ get previousPosition() {
399
+ return this._previousPosition;
400
+ }
401
+ /**
402
+ * Play another clip of the bank, keeping the playback options.
403
+ *
404
+ * @remarks
405
+ * The pose changes at once; tracks do not blend clips. The bounds of attached meshes are
406
+ * recomputed for the new clip.
407
+ *
408
+ * @param clip - Name or entry index of the clip
409
+ * @param position - Position to start at in seconds, default 0
410
+ */ setClip(clip, position = 0) {
411
+ const index = typeof clip === 'number' ? clip : this._bank.getEntryIndex(clip);
412
+ if (index < 0 || index >= this._bank.entries.length) {
413
+ throw new Error(`AnimationBankTrack.setClip(): clip not baked: ${clip}`);
414
+ }
415
+ this._entryIndex = index;
416
+ this._position = this.wrap(position);
417
+ // The previous pose belonged to another clip, so the new one starts still
418
+ this._previousPosition = this._position;
419
+ this._evaluatedPosition = this._position;
420
+ this._dirty = true;
421
+ for (const mesh of this._meshes.keys()){
422
+ this.attachMesh(mesh);
423
+ }
424
+ }
425
+ /**
426
+ * Skin all meshes under a node by this track.
427
+ *
428
+ * @remarks
429
+ * Meshes whose skin binding has other joints than the bank are skipped. The skin bindings of the
430
+ * attached meshes stop updating their own palettes until detached.
431
+ *
432
+ * @param node - Root of the model, typically an instance of the model the bank was baked from
433
+ * @param binding - If given, only meshes skinned by this binding are attached
434
+ * @returns Number of meshes attached
435
+ */ attach(node, binding) {
436
+ let count = 0;
437
+ node.iterate((child)=>{
438
+ if (child.isMesh() && this.attachMesh(child, binding)) {
439
+ count++;
440
+ }
441
+ return false;
442
+ });
443
+ return count;
444
+ }
445
+ /**
446
+ * Skin the meshes under a node by their skin bindings again.
447
+ *
448
+ * @param node - Node passed to {@link attach}
449
+ */ detach(node) {
450
+ node.iterate((child)=>{
451
+ if (child.isMesh() && this._meshes.has(child)) {
452
+ this.detachMesh(child);
453
+ }
454
+ return false;
455
+ });
456
+ }
457
+ /**
458
+ * Advance the position by the frame time and write the new pose.
459
+ *
460
+ * @internal
461
+ */ update(deltaInSeconds) {
462
+ if (this._autoPlay && this._playRate !== 0) {
463
+ this._position = this.wrap(this._position + this._playRate * deltaInSeconds);
464
+ this._dirty = true;
465
+ }
466
+ if (this._gpu) {
467
+ // Evaluated by the next dispatch; a still pose evaluates to the same matrices twice
468
+ this._previousPosition = this._evaluatedPosition;
469
+ this._evaluatedPosition = this._position;
470
+ this._dirty = false;
471
+ } else if (this._dirty) {
472
+ this.evaluate();
473
+ } else if (this._offsets[1] !== this._offsets[0]) {
474
+ // A still pose: point the previous set at the current one so motion vectors become zero
475
+ this._offsets[1] = this._offsets[0];
476
+ this.writeHeader();
477
+ }
478
+ }
479
+ /** Release the palette and skin the attached meshes by their skin bindings again */ onDispose() {
480
+ super.onDispose();
481
+ for (const mesh of [
482
+ ...this._meshes.keys()
483
+ ]){
484
+ this.detachMesh(mesh);
485
+ }
486
+ AnimationBankTrack._activeTracks.delete(this);
487
+ if (this._gpu) {
488
+ AnimationBankGpuEvaluator.removeTrack(this);
489
+ }
490
+ this._bank.removeTrack(this);
491
+ if (this._block) {
492
+ SkinPaletteAtlas.instance.free(this._block);
493
+ this._block = null;
494
+ }
495
+ }
496
+ attachMesh(mesh, only) {
497
+ const binding = mesh.findSkinBindingById(mesh.skinBindingName);
498
+ if (!binding || only && binding !== only || !this._bank.isCompatible(binding)) {
499
+ return false;
500
+ }
501
+ const previous = mesh.getSkinPaletteOverride();
502
+ if (previous?.owner && previous.owner !== this) {
503
+ previous.owner.detachMesh(mesh);
504
+ }
505
+ if (!this._meshes.has(mesh)) {
506
+ binding.suspendPalette(true);
507
+ }
508
+ const boundingBox = this._bank.computeBoundingBox(this._entryIndex, mesh, binding);
509
+ this._meshes.set(mesh, boundingBox);
510
+ mesh.setSkinPaletteOverride({
511
+ paletteBase: this.paletteBase,
512
+ boundingBox,
513
+ owner: this
514
+ });
515
+ return true;
516
+ }
517
+ /** @internal */ detachMesh(mesh) {
518
+ if (this._meshes.delete(mesh)) {
519
+ mesh.findSkinBindingById(mesh.skinBindingName)?.suspendPalette(false);
520
+ if (mesh.getSkinPaletteOverride()?.owner === this) {
521
+ mesh.setSkinPaletteOverride(null);
522
+ }
523
+ }
524
+ }
525
+ /** Write the pose at the position into the set not holding the previous pose */ evaluate() {
526
+ if (!this._block) {
527
+ return;
528
+ }
529
+ const n = this._bank.jointCount;
530
+ if (this._offsets[0] === 0) {
531
+ this._offsets[0] = 1;
532
+ this._offsets[1] = 1;
533
+ } else {
534
+ this._offsets[1] = this._offsets[0];
535
+ this._offsets[0] = n - this._offsets[0] + 2;
536
+ }
537
+ this._bank.writePalette(this._entryIndex, this._position, this._block.base + this._offsets[0], this._palette);
538
+ this.writeHeader();
539
+ this._dirty = false;
540
+ }
541
+ writeHeader() {
542
+ const base = this._block.base;
543
+ tmpHeader[0] = base + this._offsets[0];
544
+ tmpHeader[1] = base + this._offsets[1];
545
+ SkinPaletteAtlas.instance.writeSlots(base, tmpHeader);
546
+ }
547
+ wrap(position) {
548
+ const length = this.playLength;
549
+ if (this._loop) {
550
+ position = length === 0 ? 0 : position % length;
551
+ if (position < 0) {
552
+ position += length;
553
+ }
554
+ return position;
555
+ }
556
+ return Math.min(Math.max(position, 0), length);
557
+ }
558
+ }
559
+ function getKeyIndicesFromTime(time, numKeys, sequenceLength) {
560
+ if (time <= 0 || numKeys === 1) {
561
+ return {
562
+ key0: 0,
563
+ key1: 0,
564
+ alpha: 0
565
+ };
566
+ }
567
+ const lastIndex = numKeys - 1;
568
+ if (time >= sequenceLength) {
569
+ return {
570
+ key0: lastIndex,
571
+ key1: 0,
572
+ alpha: 0
573
+ };
574
+ }
575
+ const keyPos = time * (lastIndex / sequenceLength);
576
+ const key0 = Math.min(Math.max(Math.floor(keyPos), 0), lastIndex);
577
+ const alpha = keyPos - key0;
578
+ const key1 = key0 + 1 === numKeys ? key0 : key0 + 1;
579
+ return {
580
+ key0,
581
+ key1,
582
+ alpha
583
+ };
584
+ }
585
+ /** Blend two keys into a joint pose matrix */ function blendKeys(keys, a, b, alpha, out) {
586
+ const beta = 1 - alpha;
587
+ // Rotations are normalized before and after blending, along the shorter arc
588
+ let ax = keys[a + 3], ay = keys[a + 4], az = keys[a + 5], aw = keys[a + 6];
589
+ let bx = keys[b + 3], by = keys[b + 4], bz = keys[b + 5], bw = keys[b + 6];
590
+ let len = Math.hypot(ax, ay, az, aw) || 1;
591
+ ax /= len;
592
+ ay /= len;
593
+ az /= len;
594
+ aw /= len;
595
+ len = Math.hypot(bx, by, bz, bw) || 1;
596
+ const sign = ax * bx + ay * by + az * bz + aw * bw < 0 ? -1 / len : 1 / len;
597
+ bx *= sign;
598
+ by *= sign;
599
+ bz *= sign;
600
+ bw *= sign;
601
+ let x = ax * beta + bx * alpha;
602
+ let y = ay * beta + by * alpha;
603
+ let z = az * beta + bz * alpha;
604
+ let w = aw * beta + bw * alpha;
605
+ len = Math.hypot(x, y, z, w) || 1;
606
+ x /= len;
607
+ y /= len;
608
+ z /= len;
609
+ w /= len;
610
+ const sx = keys[a + 7] * beta + keys[b + 7] * alpha;
611
+ const sy = keys[a + 8] * beta + keys[b + 8] * alpha;
612
+ const sz = keys[a + 9] * beta + keys[b + 9] * alpha;
613
+ // Column-major translation * rotation * scale
614
+ out[0] = (1 - 2 * (y * y + z * z)) * sx;
615
+ out[1] = 2 * (x * y + z * w) * sx;
616
+ out[2] = 2 * (x * z - y * w) * sx;
617
+ out[3] = 0;
618
+ out[4] = 2 * (x * y - z * w) * sy;
619
+ out[5] = (1 - 2 * (x * x + z * z)) * sy;
620
+ out[6] = 2 * (y * z + x * w) * sy;
621
+ out[7] = 0;
622
+ out[8] = 2 * (x * z + y * w) * sz;
623
+ out[9] = 2 * (y * z - x * w) * sz;
624
+ out[10] = (1 - 2 * (x * x + y * y)) * sz;
625
+ out[11] = 0;
626
+ out[12] = keys[a] * beta + keys[b] * alpha;
627
+ out[13] = keys[a + 1] * beta + keys[b + 1] * alpha;
628
+ out[14] = keys[a + 2] * beta + keys[b + 2] * alpha;
629
+ out[15] = 1;
630
+ return out;
631
+ }
632
+
633
+ export { ANIMATION_BANK_SAMPLE_RATE, AnimationBank, AnimationBankTrack };
634
+ //# sourceMappingURL=animation_bank.js.map