@zephyr3d/scene 0.9.26 → 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 (506) 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 +146 -30
  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 +300 -56
  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 +177 -3
  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 +178 -200
  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 +30475 -19865
  109. package/dist/index.js +67 -12
  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/hairstrand.js +235 -235
  118. package/dist/material/hairstrand.js.map +1 -1
  119. package/dist/material/lambert.js +4 -1
  120. package/dist/material/lambert.js.map +1 -1
  121. package/dist/material/material.js +362 -300
  122. package/dist/material/material.js.map +1 -1
  123. package/dist/material/meshmaterial.js +118 -45
  124. package/dist/material/meshmaterial.js.map +1 -1
  125. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  126. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  127. package/dist/material/mixins/lightmodel/lambert.js +1 -1
  128. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  129. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +34 -61
  130. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  131. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +16 -2
  132. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  133. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +2 -1
  134. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  135. package/dist/material/mixins/lit.js +223 -83
  136. package/dist/material/mixins/lit.js.map +1 -1
  137. package/dist/material/mixins/pbr/common.js +31 -206
  138. package/dist/material/mixins/pbr/common.js.map +1 -1
  139. package/dist/material/mtoon.js +1 -1
  140. package/dist/material/mtoon.js.map +1 -1
  141. package/dist/material/pbrmr.js +3 -0
  142. package/dist/material/pbrmr.js.map +1 -1
  143. package/dist/material/pbrsg.js +3 -0
  144. package/dist/material/pbrsg.js.map +1 -1
  145. package/dist/material/sdf_debug.js +78 -0
  146. package/dist/material/sdf_debug.js.map +1 -0
  147. package/dist/material/shader/helper.js +733 -190
  148. package/dist/material/shader/helper.js.map +1 -1
  149. package/dist/material/shader/terrain_blend.js +204 -43
  150. package/dist/material/shader/terrain_blend.js.map +1 -1
  151. package/dist/material/skin.js +331 -297
  152. package/dist/material/skin.js.map +1 -1
  153. package/dist/material/skinprofile.js +1058 -0
  154. package/dist/material/skinprofile.js.map +1 -0
  155. package/dist/material/sss.js +353 -0
  156. package/dist/material/sss.js.map +1 -0
  157. package/dist/material/sss_kernel.js +265 -0
  158. package/dist/material/sss_kernel.js.map +1 -0
  159. package/dist/material/sssprofile.js +879 -0
  160. package/dist/material/sssprofile.js.map +1 -0
  161. package/dist/material/subsurfaceprofile.js +4 -8
  162. package/dist/material/subsurfaceprofile.js.map +1 -1
  163. package/dist/material/terrain-cm.js +464 -188
  164. package/dist/material/terrain-cm.js.map +1 -1
  165. package/dist/material/unlit.js +3 -0
  166. package/dist/material/unlit.js.map +1 -1
  167. package/dist/material/water.js +2009 -201
  168. package/dist/material/water.js.map +1 -1
  169. package/dist/node_modules/meshoptimizer/LICENSE +21 -0
  170. package/dist/node_modules/meshoptimizer/meshopt_decoder.js +197 -0
  171. package/dist/node_modules/meshoptimizer/meshopt_decoder.js.map +1 -0
  172. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js +677 -0
  173. package/dist/node_modules/meshoptimizer/meshopt_simplifier.js.map +1 -0
  174. package/dist/physics/character.js +226 -0
  175. package/dist/physics/character.js.map +1 -0
  176. package/dist/physics/collider.js +209 -0
  177. package/dist/physics/collider.js.map +1 -0
  178. package/dist/physics/events.js +79 -0
  179. package/dist/physics/events.js.map +1 -0
  180. package/dist/physics/joint.js +272 -0
  181. package/dist/physics/joint.js.map +1 -0
  182. package/dist/physics/node_physics.js +234 -0
  183. package/dist/physics/node_physics.js.map +1 -0
  184. package/dist/physics/part.js +91 -0
  185. package/dist/physics/part.js.map +1 -0
  186. package/dist/physics/rigid_body.js +379 -0
  187. package/dist/physics/rigid_body.js.map +1 -0
  188. package/dist/physics/vehicle.js +335 -0
  189. package/dist/physics/vehicle.js.map +1 -0
  190. package/dist/physics/world.js +25 -0
  191. package/dist/physics/world.js.map +1 -0
  192. package/dist/posteffect/bloom.js +49 -14
  193. package/dist/posteffect/bloom.js.map +1 -1
  194. package/dist/posteffect/motionblur.js +668 -63
  195. package/dist/posteffect/motionblur.js.map +1 -1
  196. package/dist/posteffect/posteffect.js +12 -1
  197. package/dist/posteffect/posteffect.js.map +1 -1
  198. package/dist/posteffect/postsss.js +572 -0
  199. package/dist/posteffect/postsss.js.map +1 -0
  200. package/dist/posteffect/sao.js +48 -50
  201. package/dist/posteffect/sao.js.map +1 -1
  202. package/dist/posteffect/skinsss.js +605 -355
  203. package/dist/posteffect/skinsss.js.map +1 -1
  204. package/dist/posteffect/ssgi.js +91 -162
  205. package/dist/posteffect/ssgi.js.map +1 -1
  206. package/dist/posteffect/ssr.js +3 -11
  207. package/dist/posteffect/ssr.js.map +1 -1
  208. package/dist/posteffect/sss.js +34 -15
  209. package/dist/posteffect/sss.js.map +1 -1
  210. package/dist/posteffect/taa.js +1 -0
  211. package/dist/posteffect/taa.js.map +1 -1
  212. package/dist/render/abuffer_oit.js +40 -39
  213. package/dist/render/abuffer_oit.js.map +1 -1
  214. package/dist/render/clipmap.js +328 -62
  215. package/dist/render/clipmap.js.map +1 -1
  216. package/dist/render/cluster_light.js +958 -224
  217. package/dist/render/cluster_light.js.map +1 -1
  218. package/dist/render/cull_visitor.js +26 -5
  219. package/dist/render/cull_visitor.js.map +1 -1
  220. package/dist/render/debug_views.js +37 -0
  221. package/dist/render/debug_views.js.map +1 -0
  222. package/dist/render/depthpass.js +5 -1
  223. package/dist/render/depthpass.js.map +1 -1
  224. package/dist/render/drawable_mixin.js +53 -6
  225. package/dist/render/drawable_mixin.js.map +1 -1
  226. package/dist/render/dualdepthpeeling_oit.js +53 -53
  227. package/dist/render/dualdepthpeeling_oit.js.map +1 -1
  228. package/dist/render/envlight.js +196 -113
  229. package/dist/render/envlight.js.map +1 -1
  230. package/dist/render/fbm_wavegenerator.js +8 -13
  231. package/dist/render/fbm_wavegenerator.js.map +1 -1
  232. package/dist/render/fft_wavegenerator.js +268 -136
  233. package/dist/render/fft_wavegenerator.js.map +1 -1
  234. package/dist/render/gerstner_wavegenerator.js +113 -28
  235. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  236. package/dist/render/gi/probe_volume.js +1334 -0
  237. package/dist/render/gi/probe_volume.js.map +1 -0
  238. package/dist/render/gi/scene_gi.js +282 -0
  239. package/dist/render/gi/scene_gi.js.map +1 -0
  240. package/dist/render/gi/voxel_atlas.js +198 -0
  241. package/dist/render/gi/voxel_atlas.js.map +1 -0
  242. package/dist/render/gi/voxel_lighting.js +652 -0
  243. package/dist/render/gi/voxel_lighting.js.map +1 -0
  244. package/dist/render/gi/voxel_scene.js +642 -0
  245. package/dist/render/gi/voxel_scene.js.map +1 -0
  246. package/dist/render/gi/voxelize_pass.js +223 -0
  247. package/dist/render/gi/voxelize_pass.js.map +1 -0
  248. package/dist/render/globalbindgroup_allocator.js +3 -2
  249. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  250. package/dist/render/gpu_picking.js +9 -36
  251. package/dist/render/gpu_picking.js.map +1 -1
  252. package/dist/render/hzb.js +80 -22
  253. package/dist/render/hzb.js.map +1 -1
  254. package/dist/render/instance_culling.js +499 -0
  255. package/dist/render/instance_culling.js.map +1 -0
  256. package/dist/render/lightpass.js +23 -9
  257. package/dist/render/lightpass.js.map +1 -1
  258. package/dist/render/lod.js +46 -0
  259. package/dist/render/lod.js.map +1 -0
  260. package/dist/render/oit.js +11 -11
  261. package/dist/render/oit.js.map +1 -1
  262. package/dist/render/primitive.js +301 -9
  263. package/dist/render/primitive.js.map +1 -1
  264. package/dist/render/primitive_readback.js +209 -0
  265. package/dist/render/primitive_readback.js.map +1 -0
  266. package/dist/render/render_queue.js +198 -11
  267. package/dist/render/render_queue.js.map +1 -1
  268. package/dist/render/renderer.js +14 -7
  269. package/dist/render/renderer.js.map +1 -1
  270. package/dist/render/rendergraph/blackboard.js +15 -1
  271. package/dist/render/rendergraph/blackboard.js.map +1 -1
  272. package/dist/render/rendergraph/executor.js +136 -0
  273. package/dist/render/rendergraph/executor.js.map +1 -1
  274. package/dist/render/rendergraph/forward_plus_builder.js +585 -59
  275. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  276. package/dist/render/rendergraph/frame_resource_requirements.js +1 -0
  277. package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -1
  278. package/dist/render/rendergraph/history_resources.js +8 -1
  279. package/dist/render/rendergraph/history_resources.js.map +1 -1
  280. package/dist/render/rendergraph/scene_render_context.js +31 -2
  281. package/dist/render/rendergraph/scene_render_context.js.map +1 -1
  282. package/dist/render/rendergraph/types.js.map +1 -1
  283. package/dist/render/renderpass.js +28 -5
  284. package/dist/render/renderpass.js.map +1 -1
  285. package/dist/render/sdf/box_allocator.js +98 -0
  286. package/dist/render/sdf/box_allocator.js.map +1 -0
  287. package/dist/render/sdf/global_sdf.js +865 -0
  288. package/dist/render/sdf/global_sdf.js.map +1 -0
  289. package/dist/render/sdf/scene_sdf.js +562 -0
  290. package/dist/render/sdf/scene_sdf.js.map +1 -0
  291. package/dist/render/sdf/sdf_atlas.js +227 -0
  292. package/dist/render/sdf/sdf_atlas.js.map +1 -0
  293. package/dist/render/sdf/sdf_programs.js +42 -0
  294. package/dist/render/sdf/sdf_programs.js.map +1 -0
  295. package/dist/render/sdf/sdf_view.js +199 -0
  296. package/dist/render/sdf/sdf_view.js.map +1 -0
  297. package/dist/render/sdf/waterline.js +610 -0
  298. package/dist/render/sdf/waterline.js.map +1 -0
  299. package/dist/render/shadow_mask_pass.js +142 -25
  300. package/dist/render/shadow_mask_pass.js.map +1 -1
  301. package/dist/render/shore_wave_generator.js +1193 -0
  302. package/dist/render/shore_wave_generator.js.map +1 -0
  303. package/dist/render/sky.js +516 -86
  304. package/dist/render/sky.js.map +1 -1
  305. package/dist/render/transmission_thickness_pass.js +477 -0
  306. package/dist/render/transmission_thickness_pass.js.map +1 -0
  307. package/dist/render/underwater.js +524 -0
  308. package/dist/render/underwater.js.map +1 -0
  309. package/dist/render/virtualtexture/virtual_texture.js +1214 -0
  310. package/dist/render/virtualtexture/virtual_texture.js.map +1 -0
  311. package/dist/render/volumetric_cloud/cloud_common.js +472 -0
  312. package/dist/render/volumetric_cloud/cloud_common.js.map +1 -0
  313. package/dist/render/volumetric_cloud/cloud_noise.js +189 -0
  314. package/dist/render/volumetric_cloud/cloud_noise.js.map +1 -0
  315. package/dist/render/volumetric_cloud/debug_view.js +131 -0
  316. package/dist/render/volumetric_cloud/debug_view.js.map +1 -0
  317. package/dist/render/volumetric_cloud/resources.js +380 -0
  318. package/dist/render/volumetric_cloud/resources.js.map +1 -0
  319. package/dist/render/volumetric_cloud/sky_cache.js +380 -0
  320. package/dist/render/volumetric_cloud/sky_cache.js.map +1 -0
  321. package/dist/render/volumetric_cloud/volumetric_cloud.js +318 -0
  322. package/dist/render/volumetric_cloud/volumetric_cloud.js.map +1 -0
  323. package/dist/render/water_caustics.js +1195 -0
  324. package/dist/render/water_caustics.js.map +1 -0
  325. package/dist/render/water_foam.js +627 -0
  326. package/dist/render/water_foam.js.map +1 -0
  327. package/dist/render/water_interaction.js +1795 -0
  328. package/dist/render/water_interaction.js.map +1 -0
  329. package/dist/render/weightedblended_oit.js +36 -36
  330. package/dist/render/weightedblended_oit.js.map +1 -1
  331. package/dist/scene/basesprite.js +9 -4
  332. package/dist/scene/basesprite.js.map +1 -1
  333. package/dist/scene/batchgroup.js +108 -12
  334. package/dist/scene/batchgroup.js.map +1 -1
  335. package/dist/scene/environment.js +28 -7
  336. package/dist/scene/environment.js.map +1 -1
  337. package/dist/scene/foliage.js +1020 -0
  338. package/dist/scene/foliage.js.map +1 -0
  339. package/dist/scene/foliage_buckets.js +147 -0
  340. package/dist/scene/foliage_buckets.js.map +1 -0
  341. package/dist/scene/foliage_mask.js +358 -0
  342. package/dist/scene/foliage_mask.js.map +1 -0
  343. package/dist/scene/hair.js +15 -4
  344. package/dist/scene/hair.js.map +1 -1
  345. package/dist/scene/light.js +179 -13
  346. package/dist/scene/light.js.map +1 -1
  347. package/dist/scene/mesh.js +327 -45
  348. package/dist/scene/mesh.js.map +1 -1
  349. package/dist/scene/meshdrawable.js +6 -0
  350. package/dist/scene/meshdrawable.js.map +1 -1
  351. package/dist/scene/msdftext.js +9 -3
  352. package/dist/scene/msdftext.js.map +1 -1
  353. package/dist/scene/msdftextsprite.js +9 -3
  354. package/dist/scene/msdftextsprite.js.map +1 -1
  355. package/dist/scene/particlesys.js +8 -2
  356. package/dist/scene/particlesys.js.map +1 -1
  357. package/dist/scene/physics_settings.js +157 -0
  358. package/dist/scene/physics_settings.js.map +1 -0
  359. package/dist/scene/scene.js +190 -44
  360. package/dist/scene/scene.js.map +1 -1
  361. package/dist/scene/scene_node.js +147 -6
  362. package/dist/scene/scene_node.js.map +1 -1
  363. package/dist/scene/terrain-cm/bladegrassmaterial.js +735 -0
  364. package/dist/scene/terrain-cm/bladegrassmaterial.js.map +1 -0
  365. package/dist/scene/terrain-cm/grass.js +881 -42
  366. package/dist/scene/terrain-cm/grass.js.map +1 -1
  367. package/dist/scene/terrain-cm/grass_gpu.js +929 -0
  368. package/dist/scene/terrain-cm/grass_gpu.js.map +1 -0
  369. package/dist/scene/terrain-cm/grassmaterial.js +180 -9
  370. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  371. package/dist/scene/terrain-cm/terrain-cm.js +465 -36
  372. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  373. package/dist/scene/terrain-cm/terrain_gi_albedo.js +257 -0
  374. package/dist/scene/terrain-cm/terrain_gi_albedo.js.map +1 -0
  375. package/dist/scene/terrain-cm/terrain_rvt.js +395 -0
  376. package/dist/scene/terrain-cm/terrain_rvt.js.map +1 -0
  377. package/dist/scene/update_queue.js +54 -0
  378. package/dist/scene/update_queue.js.map +1 -0
  379. package/dist/scene/water.js +997 -96
  380. package/dist/scene/water.js.map +1 -1
  381. package/dist/scene/water_surface_sampler.js +324 -0
  382. package/dist/scene/water_surface_sampler.js.map +1 -0
  383. package/dist/scene/wind.js +317 -0
  384. package/dist/scene/wind.js.map +1 -0
  385. package/dist/shaders/atmosphere.js +388 -166
  386. package/dist/shaders/atmosphere.js.map +1 -1
  387. package/dist/shaders/fog.js +100 -32
  388. package/dist/shaders/fog.js.map +1 -1
  389. package/dist/shaders/gi.js +365 -0
  390. package/dist/shaders/gi.js.map +1 -0
  391. package/dist/shaders/ltc_rect.js +202 -0
  392. package/dist/shaders/ltc_rect.js.map +1 -0
  393. package/dist/shaders/misc.js +1 -10
  394. package/dist/shaders/misc.js.map +1 -1
  395. package/dist/shaders/noise.js +5 -1
  396. package/dist/shaders/noise.js.map +1 -1
  397. package/dist/shaders/probes.js +309 -0
  398. package/dist/shaders/probes.js.map +1 -0
  399. package/dist/shaders/sdf.js +537 -0
  400. package/dist/shaders/sdf.js.map +1 -0
  401. package/dist/shaders/shadow.js +104 -70
  402. package/dist/shaders/shadow.js.map +1 -1
  403. package/dist/shaders/skin_brdf.js +243 -0
  404. package/dist/shaders/skin_brdf.js.map +1 -0
  405. package/dist/shaders/ssr.js +6 -159
  406. package/dist/shaders/ssr.js.map +1 -1
  407. package/dist/shaders/temporal.js +38 -27
  408. package/dist/shaders/temporal.js.map +1 -1
  409. package/dist/shaders/water.js +40 -87
  410. package/dist/shaders/water.js.map +1 -1
  411. package/dist/shaders/water_medium.js +42 -0
  412. package/dist/shaders/water_medium.js.map +1 -0
  413. package/dist/shadow/dom.js +110 -19
  414. package/dist/shadow/dom.js.map +1 -1
  415. package/dist/shadow/esm.js +3 -3
  416. package/dist/shadow/esm.js.map +1 -1
  417. package/dist/shadow/pcf_opt.js +15 -48
  418. package/dist/shadow/pcf_opt.js.map +1 -1
  419. package/dist/shadow/pcf_pd.js +15 -53
  420. package/dist/shadow/pcf_pd.js.map +1 -1
  421. package/dist/shadow/pcss.js +34 -9
  422. package/dist/shadow/pcss.js.map +1 -1
  423. package/dist/shadow/shadow_impl.js +3 -8
  424. package/dist/shadow/shadow_impl.js.map +1 -1
  425. package/dist/shadow/shadow_region.js +87 -49
  426. package/dist/shadow/shadow_region.js.map +1 -1
  427. package/dist/shadow/shadowmapper.js +93 -53
  428. package/dist/shadow/shadowmapper.js.map +1 -1
  429. package/dist/shadow/ssm.js +18 -72
  430. package/dist/shadow/ssm.js.map +1 -1
  431. package/dist/shadow/vsm.js +3 -3
  432. package/dist/shadow/vsm.js.map +1 -1
  433. package/dist/shapes/shape.js +44 -1
  434. package/dist/shapes/shape.js.map +1 -1
  435. package/dist/utility/buoyancy.js +287 -0
  436. package/dist/utility/buoyancy.js.map +1 -0
  437. package/dist/utility/physical.js +10 -1
  438. package/dist/utility/physical.js.map +1 -1
  439. package/dist/utility/pmrem.js +17 -43
  440. package/dist/utility/pmrem.js.map +1 -1
  441. package/dist/utility/sdf/bake.js +435 -0
  442. package/dist/utility/sdf/bake.js.map +1 -0
  443. package/dist/utility/sdf/bvh.js +576 -0
  444. package/dist/utility/sdf/bvh.js.map +1 -0
  445. package/dist/utility/serialization/manager.js +36 -6
  446. package/dist/utility/serialization/manager.js.map +1 -1
  447. package/dist/utility/serialization/scene/animation.js +77 -7
  448. package/dist/utility/serialization/scene/animation.js.map +1 -1
  449. package/dist/utility/serialization/scene/batch.js +11 -4
  450. package/dist/utility/serialization/scene/batch.js.map +1 -1
  451. package/dist/utility/serialization/scene/camera.js +140 -279
  452. package/dist/utility/serialization/scene/camera.js.map +1 -1
  453. package/dist/utility/serialization/scene/cloth.js +25 -0
  454. package/dist/utility/serialization/scene/cloth.js.map +1 -0
  455. package/dist/utility/serialization/scene/common.js +14 -6
  456. package/dist/utility/serialization/scene/common.js.map +1 -1
  457. package/dist/utility/serialization/scene/foliage.js +821 -0
  458. package/dist/utility/serialization/scene/foliage.js.map +1 -0
  459. package/dist/utility/serialization/scene/hair.js +11 -4
  460. package/dist/utility/serialization/scene/hair.js.map +1 -1
  461. package/dist/utility/serialization/scene/light.js +115 -7
  462. package/dist/utility/serialization/scene/light.js.map +1 -1
  463. package/dist/utility/serialization/scene/material.js +388 -220
  464. package/dist/utility/serialization/scene/material.js.map +1 -1
  465. package/dist/utility/serialization/scene/mesh.js +69 -4
  466. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  467. package/dist/utility/serialization/scene/node.js +140 -5
  468. package/dist/utility/serialization/scene/node.js.map +1 -1
  469. package/dist/utility/serialization/scene/node_physics.js +1318 -0
  470. package/dist/utility/serialization/scene/node_physics.js.map +1 -0
  471. package/dist/utility/serialization/scene/particle.js +11 -4
  472. package/dist/utility/serialization/scene/particle.js.map +1 -1
  473. package/dist/utility/serialization/scene/physics.js +120 -0
  474. package/dist/utility/serialization/scene/physics.js.map +1 -0
  475. package/dist/utility/serialization/scene/primitive.js +124 -10
  476. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  477. package/dist/utility/serialization/scene/scene.js +1687 -51
  478. package/dist/utility/serialization/scene/scene.js.map +1 -1
  479. package/dist/utility/serialization/scene/sprite.js +11 -4
  480. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  481. package/dist/utility/serialization/scene/terrain.js +163 -33
  482. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  483. package/dist/utility/serialization/scene/text.js +11 -4
  484. package/dist/utility/serialization/scene/text.js.map +1 -1
  485. package/dist/utility/serialization/scene/water.js +2473 -114
  486. package/dist/utility/serialization/scene/water.js.map +1 -1
  487. package/dist/utility/serialization/types.js.map +1 -1
  488. package/dist/utility/shprojector.js +97 -109
  489. package/dist/utility/shprojector.js.map +1 -1
  490. package/dist/utility/textures/foam.js +170 -0
  491. package/dist/utility/textures/foam.js.map +1 -0
  492. package/dist/utility/textures/ggxlut.js +17 -43
  493. package/dist/utility/textures/ggxlut.js.map +1 -1
  494. package/dist/utility/textures/ltcdata.js +4 -4
  495. package/dist/utility/textures/ltcdata.js.map +1 -1
  496. package/dist/utility/textures/ltclut.js +16 -6
  497. package/dist/utility/textures/ltclut.js.map +1 -1
  498. package/dist/utility/unsupported.js +24 -0
  499. package/dist/utility/unsupported.js.map +1 -0
  500. package/dist/values.js +13 -1
  501. package/dist/values.js.map +1 -1
  502. package/package.json +25 -12
  503. package/src/asset/loaders/ktx2/basis/LICENSE +201 -0
  504. package/src/asset/loaders/ktx2/basis/basis_transcoder.js +2 -0
  505. package/src/asset/loaders/ktx2/basis/basis_transcoder.wasm +0 -0
  506. package/src/asset/meshoptimizer/LICENSE +21 -0
@@ -0,0 +1,289 @@
1
+ import { tryGetApp } from '../app/api.js';
2
+ import { AnimationBank } from './animation_bank.js';
3
+ import { NodeEulerRotationTrack } from './eulerrotationtrack.js';
4
+ import { NodeRotationTrack } from './rotationtrack.js';
5
+ import { NodeScaleTrack } from './scaletrack.js';
6
+ import { NodeTranslationTrack } from './translationtrack.js';
7
+
8
+ /** Joint tracks a bank can bake */ function isJointTrack(track) {
9
+ return track instanceof NodeTranslationTrack || track instanceof NodeRotationTrack || track instanceof NodeEulerRotationTrack || track instanceof NodeScaleTrack;
10
+ }
11
+ /** Banks shared by the instances of a model, by model and skin binding */ const sharedBanks = new Map();
12
+ let nextDriverId = 0;
13
+ /**
14
+ * Plays the skeletal animation of an {@link AnimationSet} with animation bank tracks while it
15
+ * allows, see {@link AnimationSet.gpuAnimation}.
16
+ *
17
+ * @remarks
18
+ * The animation set keeps advancing playback time, loops, ranges and events; only the posing
19
+ * of the joints is replaced: each skin binding the clip animates is skinned by a bank track that
20
+ * is set to the playback time every frame. Banks are baked a clip at a time on first use and
21
+ * shared by every instance of the same model.
22
+ *
23
+ * Playback falls back to the joint nodes, at once and without a visible jump, whenever a frame
24
+ * does not meet the conditions of a bank: exactly one active clip, animating joints only, no
25
+ * skeleton modifier, no GPU cloth, and nothing attached to the joints that would follow them.
26
+ *
27
+ * @internal
28
+ */ class GpuAnimationDriver {
29
+ _set;
30
+ _id;
31
+ _tracks;
32
+ /** Shared bank keys acquired by this driver, by skin binding */ _bankKeys;
33
+ _clipInfo;
34
+ _clip;
35
+ _time;
36
+ _structureTag;
37
+ _structureCheckedTag;
38
+ _structureOk;
39
+ /** Frames the model has held a still pose with no clip active, see update() */ _idleFrames;
40
+ _onStructureChanged;
41
+ constructor(animationSet){
42
+ this._set = animationSet;
43
+ this._id = ++nextDriverId;
44
+ this._tracks = new Map();
45
+ this._bankKeys = new Map();
46
+ this._clipInfo = new WeakMap();
47
+ this._clip = null;
48
+ this._time = 0;
49
+ this._structureTag = 0;
50
+ this._structureCheckedTag = -1;
51
+ this._structureOk = false;
52
+ this._idleFrames = 0;
53
+ this._onStructureChanged = ()=>{
54
+ this._structureTag++;
55
+ };
56
+ animationSet.model.on('nodeattached', this._onStructureChanged);
57
+ animationSet.model.on('noderemoved', this._onStructureChanged);
58
+ }
59
+ /** Whether the pose currently comes from bank tracks */ get active() {
60
+ return this._tracks.size > 0;
61
+ }
62
+ /**
63
+ * Pose the model for this frame by bank tracks if the conditions allow.
64
+ *
65
+ * @param clip - The only active clip, or null if none or more than one is active
66
+ * @param time - Playback time of the clip
67
+ * @returns true if bank tracks pose the model, so the joints are not to be posed this frame
68
+ */ update(clip, time) {
69
+ if (!clip) {
70
+ return this.updateIdle();
71
+ }
72
+ this._idleFrames = 0;
73
+ const bindings = this.getClipBindings(clip);
74
+ if (!bindings || !this.canDrive(bindings)) {
75
+ this.leave(true);
76
+ return false;
77
+ }
78
+ if (clip !== this._clip) {
79
+ // Joints the new clip leaves alone keep the pose they had on the regular path
80
+ this.syncJoints();
81
+ if (!this.untouchedJointsAtBindPose(clip, bindings)) {
82
+ this.leave(false);
83
+ return false;
84
+ }
85
+ }
86
+ for (const binding of bindings){
87
+ const bank = this.acquireBank(binding);
88
+ const index = bank.addClip(this._set, binding, clip.name);
89
+ if (index < 0) {
90
+ this.leave(false);
91
+ return false;
92
+ }
93
+ let track = this._tracks.get(binding);
94
+ if (!track) {
95
+ track = bank.createTrack(index, {
96
+ position: time,
97
+ autoPlay: false,
98
+ loop: false
99
+ });
100
+ track.attach(this._set.model, binding);
101
+ this._tracks.set(binding, track);
102
+ } else if (track.entryIndex !== index) {
103
+ track.setClip(index, time);
104
+ }
105
+ track.position = time;
106
+ }
107
+ this._clip = clip;
108
+ this._time = time;
109
+ return true;
110
+ }
111
+ /**
112
+ * With no clip active the pose does not change, so once the palettes hold it the skin bindings
113
+ * stop rewriting them, and with that the skinned meshes stop recomputing their bounds.
114
+ *
115
+ * @remarks
116
+ * Two frames are left to the regular path first: the first writes the pose, and the second
117
+ * writes it again so the previous pose equals the current one and the meshes show no motion.
118
+ */ updateIdle() {
119
+ this.leave(true);
120
+ const bindings = this._set.skinBindings.map((ref)=>ref.get()).filter((binding)=>!!binding);
121
+ if (bindings.length === 0 || !this.canDrive(bindings)) {
122
+ this._idleFrames = 0;
123
+ return false;
124
+ }
125
+ return ++this._idleFrames > 2;
126
+ }
127
+ /**
128
+ * Hand the pose back to the joint nodes.
129
+ *
130
+ * @param sync - Pose the joints as the clip was at the last frame posed by bank tracks
131
+ */ leave(sync = true) {
132
+ if (this._tracks.size > 0) {
133
+ if (sync) {
134
+ this.syncJoints();
135
+ }
136
+ for (const track of this._tracks.values()){
137
+ track.dispose();
138
+ }
139
+ this._tracks.clear();
140
+ }
141
+ this._clip = null;
142
+ }
143
+ /** Release the tracks and shared banks of this driver */ dispose() {
144
+ this.leave(false);
145
+ for (const key of this._bankKeys.values()){
146
+ const shared = sharedBanks.get(key);
147
+ if (shared && --shared.refs === 0) {
148
+ shared.bank.dispose();
149
+ sharedBanks.delete(key);
150
+ }
151
+ }
152
+ this._bankKeys.clear();
153
+ this._set.model.off('nodeattached', this._onStructureChanged);
154
+ this._set.model.off('noderemoved', this._onStructureChanged);
155
+ }
156
+ /** Conditions checked every frame, as they change without the scene graph changing */ canDrive(bindings) {
157
+ // Clips may be edited in the editor while a bank holds an older bake of them
158
+ if (tryGetApp()?.editorMode === 'editor') {
159
+ return false;
160
+ }
161
+ for (const binding of bindings){
162
+ if (binding.rig.modifiers.length > 0) {
163
+ return false;
164
+ }
165
+ }
166
+ if (this._structureCheckedTag !== this._structureTag) {
167
+ this._structureCheckedTag = this._structureTag;
168
+ this._structureOk = this.checkStructure(bindings);
169
+ }
170
+ return this._structureOk;
171
+ }
172
+ /**
173
+ * No GPU cloth, no mesh with skinning suspended, and nothing but joints below the joints,
174
+ * which would otherwise follow joint nodes that bank tracks no longer move
175
+ */ checkStructure(bindings) {
176
+ const joints = new Set();
177
+ for (const binding of bindings){
178
+ for (const joint of binding.joints){
179
+ joints.add(joint);
180
+ }
181
+ }
182
+ for (const joint of joints){
183
+ if (joint.children.some((child)=>!joints.has(child))) {
184
+ return false;
185
+ }
186
+ }
187
+ let ok = true;
188
+ this._set.model.iterate((node)=>{
189
+ if (node.gpuClothComponents.length > 0 || node.isMesh() && node.suspendSkinning) {
190
+ ok = false;
191
+ }
192
+ return !ok;
193
+ });
194
+ return ok;
195
+ }
196
+ /** Skin bindings a clip animates, or null if it animates anything other than their joints */ getClipBindings(clip) {
197
+ if (this._clipInfo.has(clip)) {
198
+ return this._clipInfo.get(clip);
199
+ }
200
+ const rigByJoint = new Map();
201
+ for (const ref of this._set.skinBindings){
202
+ const rig = ref.get()?.rig;
203
+ if (rig) {
204
+ for (const joint of rig.joints){
205
+ rigByJoint.set(joint, rig);
206
+ }
207
+ if (rig.rootJoint) {
208
+ rigByJoint.set(rig.rootJoint, rig);
209
+ }
210
+ }
211
+ }
212
+ const rigs = new Set();
213
+ let result = null;
214
+ let ok = clip.tracks.size > 0;
215
+ for (const [target, tracks] of clip.tracks){
216
+ const rig = rigByJoint.get(target);
217
+ if (!rig || !tracks.every(isJointTrack)) {
218
+ ok = false;
219
+ break;
220
+ }
221
+ rigs.add(rig);
222
+ }
223
+ if (ok) {
224
+ result = this._set.skinBindings.map((ref)=>ref.get()).filter((binding)=>!!binding && rigs.has(binding.rig));
225
+ if (result.length === 0) {
226
+ result = null;
227
+ }
228
+ }
229
+ this._clipInfo.set(clip, result);
230
+ return result;
231
+ }
232
+ /** A bank bakes the joints a clip leaves alone at their bind pose, so they must be there */ untouchedJointsAtBindPose(clip, bindings) {
233
+ for (const binding of bindings){
234
+ for (const joint of binding.joints){
235
+ if (clip.tracks.has(joint)) {
236
+ continue;
237
+ }
238
+ const pose = binding.rig.getBindPoseForJoint(joint);
239
+ if (pose && !(joint.position.equalsTo(pose.position, 1e-5) && joint.rotation.equalsTo(pose.rotation, 1e-5) && joint.scale.equalsTo(pose.scale, 1e-5))) {
240
+ return false;
241
+ }
242
+ }
243
+ }
244
+ return true;
245
+ }
246
+ /** Pose the joint nodes as the last clip posed by bank tracks was at its last time */ syncJoints() {
247
+ const clip = this._clip;
248
+ if (!clip || this._tracks.size === 0) {
249
+ return;
250
+ }
251
+ for (const [target, tracks] of clip.tracks){
252
+ for (const track of tracks){
253
+ // The same mapping from clip time to track time as AnimationSet.update()
254
+ const t = clip.timeDuration > 0 ? this._time / clip.timeDuration * track.getDuration() : 0;
255
+ track.applyState(target, track.calculateState(target, t));
256
+ }
257
+ }
258
+ }
259
+ /**
260
+ * The bank of a skin binding, shared by the instances of the model: keyed by the prefab or model
261
+ * asset the model was created from and the index of the binding in it
262
+ */ acquireBank(binding) {
263
+ let key = this._bankKeys.get(binding);
264
+ if (!key) {
265
+ const prefabId = this._set.model.getPrefabNode()?.prefabId;
266
+ const index = this._set.skinBindings.findIndex((ref)=>ref.get() === binding);
267
+ key = `${prefabId || `driver:${this._id}`}|${index}|${binding.joints.length}`;
268
+ let shared = sharedBanks.get(key);
269
+ if (!shared || !shared.bank.isCompatible(binding)) {
270
+ // An incompatible bank under the same key comes from an edited copy of the model
271
+ key = shared ? `driver:${this._id}|${index}` : key;
272
+ shared = sharedBanks.get(key);
273
+ if (!shared) {
274
+ shared = {
275
+ bank: new AnimationBank(this._set, binding, []),
276
+ refs: 0
277
+ };
278
+ sharedBanks.set(key, shared);
279
+ }
280
+ }
281
+ shared.refs++;
282
+ this._bankKeys.set(binding, key);
283
+ }
284
+ return sharedBanks.get(key).bank;
285
+ }
286
+ }
287
+
288
+ export { GpuAnimationDriver };
289
+ //# sourceMappingURL=gpu_animation_driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gpu_animation_driver.js","sources":["../../src/animation/gpu_animation_driver.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { tryGetApp } from '../app/api';\r\nimport type { SceneNode } from '../scene/scene_node';\r\nimport type { AnimationClip } from './animation';\r\nimport { AnimationBank } from './animation_bank';\r\nimport type { AnimationBankTrack } from './animation_bank';\r\nimport type { AnimationSet } from './animationset';\r\nimport { NodeEulerRotationTrack } from './eulerrotationtrack';\r\nimport { NodeRotationTrack } from './rotationtrack';\r\nimport { NodeScaleTrack } from './scaletrack';\r\nimport type { SkeletonRig, SkinBinding } from './skeleton';\r\nimport { NodeTranslationTrack } from './translationtrack';\r\n\r\n/** Joint tracks a bank can bake */\r\nfunction isJointTrack(track: object) {\r\n return (\r\n track instanceof NodeTranslationTrack ||\r\n track instanceof NodeRotationTrack ||\r\n track instanceof NodeEulerRotationTrack ||\r\n track instanceof NodeScaleTrack\r\n );\r\n}\r\n\r\n/** Banks shared by the instances of a model, by model and skin binding */\r\nconst sharedBanks: Map<string, { bank: AnimationBank; refs: number }> = new Map();\r\nlet nextDriverId = 0;\r\n\r\n/**\r\n * Plays the skeletal animation of an {@link AnimationSet} with animation bank tracks while it\r\n * allows, see {@link AnimationSet.gpuAnimation}.\r\n *\r\n * @remarks\r\n * The animation set keeps advancing playback time, loops, ranges and events; only the posing\r\n * of the joints is replaced: each skin binding the clip animates is skinned by a bank track that\r\n * is set to the playback time every frame. Banks are baked a clip at a time on first use and\r\n * shared by every instance of the same model.\r\n *\r\n * Playback falls back to the joint nodes, at once and without a visible jump, whenever a frame\r\n * does not meet the conditions of a bank: exactly one active clip, animating joints only, no\r\n * skeleton modifier, no GPU cloth, and nothing attached to the joints that would follow them.\r\n *\r\n * @internal\r\n */\r\nexport class GpuAnimationDriver {\r\n private readonly _set: AnimationSet;\r\n private readonly _id: number;\r\n private readonly _tracks: Map<SkinBinding, AnimationBankTrack>;\r\n /** Shared bank keys acquired by this driver, by skin binding */\r\n private readonly _bankKeys: Map<SkinBinding, string>;\r\n private readonly _clipInfo: WeakMap<AnimationClip, Nullable<SkinBinding[]>>;\r\n private _clip: Nullable<AnimationClip>;\r\n private _time: number;\r\n private _structureTag: number;\r\n private _structureCheckedTag: number;\r\n private _structureOk: boolean;\r\n /** Frames the model has held a still pose with no clip active, see update() */\r\n private _idleFrames: number;\r\n private readonly _onStructureChanged: () => void;\r\n constructor(animationSet: AnimationSet) {\r\n this._set = animationSet;\r\n this._id = ++nextDriverId;\r\n this._tracks = new Map();\r\n this._bankKeys = new Map();\r\n this._clipInfo = new WeakMap();\r\n this._clip = null;\r\n this._time = 0;\r\n this._structureTag = 0;\r\n this._structureCheckedTag = -1;\r\n this._structureOk = false;\r\n this._idleFrames = 0;\r\n this._onStructureChanged = () => {\r\n this._structureTag++;\r\n };\r\n animationSet.model.on('nodeattached', this._onStructureChanged);\r\n animationSet.model.on('noderemoved', this._onStructureChanged);\r\n }\r\n /** Whether the pose currently comes from bank tracks */\r\n get active() {\r\n return this._tracks.size > 0;\r\n }\r\n /**\r\n * Pose the model for this frame by bank tracks if the conditions allow.\r\n *\r\n * @param clip - The only active clip, or null if none or more than one is active\r\n * @param time - Playback time of the clip\r\n * @returns true if bank tracks pose the model, so the joints are not to be posed this frame\r\n */\r\n update(clip: Nullable<AnimationClip>, time: number) {\r\n if (!clip) {\r\n return this.updateIdle();\r\n }\r\n this._idleFrames = 0;\r\n const bindings = this.getClipBindings(clip);\r\n if (!bindings || !this.canDrive(bindings)) {\r\n this.leave(true);\r\n return false;\r\n }\r\n if (clip !== this._clip) {\r\n // Joints the new clip leaves alone keep the pose they had on the regular path\r\n this.syncJoints();\r\n if (!this.untouchedJointsAtBindPose(clip, bindings)) {\r\n this.leave(false);\r\n return false;\r\n }\r\n }\r\n for (const binding of bindings) {\r\n const bank = this.acquireBank(binding);\r\n const index = bank.addClip(this._set, binding, clip.name);\r\n if (index < 0) {\r\n this.leave(false);\r\n return false;\r\n }\r\n let track = this._tracks.get(binding);\r\n if (!track) {\r\n track = bank.createTrack(index, { position: time, autoPlay: false, loop: false });\r\n track.attach(this._set.model, binding);\r\n this._tracks.set(binding, track);\r\n } else if (track.entryIndex !== index) {\r\n track.setClip(index, time);\r\n }\r\n track.position = time;\r\n }\r\n this._clip = clip;\r\n this._time = time;\r\n return true;\r\n }\r\n /**\r\n * With no clip active the pose does not change, so once the palettes hold it the skin bindings\r\n * stop rewriting them, and with that the skinned meshes stop recomputing their bounds.\r\n *\r\n * @remarks\r\n * Two frames are left to the regular path first: the first writes the pose, and the second\r\n * writes it again so the previous pose equals the current one and the meshes show no motion.\r\n */\r\n private updateIdle() {\r\n this.leave(true);\r\n const bindings = this._set.skinBindings\r\n .map((ref) => ref.get())\r\n .filter((binding): binding is SkinBinding => !!binding);\r\n if (bindings.length === 0 || !this.canDrive(bindings)) {\r\n this._idleFrames = 0;\r\n return false;\r\n }\r\n return ++this._idleFrames > 2;\r\n }\r\n /**\r\n * Hand the pose back to the joint nodes.\r\n *\r\n * @param sync - Pose the joints as the clip was at the last frame posed by bank tracks\r\n */\r\n leave(sync = true) {\r\n if (this._tracks.size > 0) {\r\n if (sync) {\r\n this.syncJoints();\r\n }\r\n for (const track of this._tracks.values()) {\r\n track.dispose();\r\n }\r\n this._tracks.clear();\r\n }\r\n this._clip = null;\r\n }\r\n /** Release the tracks and shared banks of this driver */\r\n dispose() {\r\n this.leave(false);\r\n for (const key of this._bankKeys.values()) {\r\n const shared = sharedBanks.get(key);\r\n if (shared && --shared.refs === 0) {\r\n shared.bank.dispose();\r\n sharedBanks.delete(key);\r\n }\r\n }\r\n this._bankKeys.clear();\r\n this._set.model.off('nodeattached', this._onStructureChanged);\r\n this._set.model.off('noderemoved', this._onStructureChanged);\r\n }\r\n /** Conditions checked every frame, as they change without the scene graph changing */\r\n private canDrive(bindings: SkinBinding[]) {\r\n // Clips may be edited in the editor while a bank holds an older bake of them\r\n if (tryGetApp()?.editorMode === 'editor') {\r\n return false;\r\n }\r\n for (const binding of bindings) {\r\n if (binding.rig.modifiers.length > 0) {\r\n return false;\r\n }\r\n }\r\n if (this._structureCheckedTag !== this._structureTag) {\r\n this._structureCheckedTag = this._structureTag;\r\n this._structureOk = this.checkStructure(bindings);\r\n }\r\n return this._structureOk;\r\n }\r\n /**\r\n * No GPU cloth, no mesh with skinning suspended, and nothing but joints below the joints,\r\n * which would otherwise follow joint nodes that bank tracks no longer move\r\n */\r\n private checkStructure(bindings: SkinBinding[]) {\r\n const joints = new Set<SceneNode>();\r\n for (const binding of bindings) {\r\n for (const joint of binding.joints) {\r\n joints.add(joint);\r\n }\r\n }\r\n for (const joint of joints) {\r\n if (joint.children.some((child) => !joints.has(child))) {\r\n return false;\r\n }\r\n }\r\n let ok = true;\r\n this._set.model.iterate((node) => {\r\n if (node.gpuClothComponents.length > 0 || (node.isMesh() && node.suspendSkinning)) {\r\n ok = false;\r\n }\r\n return !ok;\r\n });\r\n return ok;\r\n }\r\n /** Skin bindings a clip animates, or null if it animates anything other than their joints */\r\n private getClipBindings(clip: AnimationClip) {\r\n if (this._clipInfo.has(clip)) {\r\n return this._clipInfo.get(clip)!;\r\n }\r\n const rigByJoint = new Map<object, SkeletonRig>();\r\n for (const ref of this._set.skinBindings) {\r\n const rig = ref.get()?.rig;\r\n if (rig) {\r\n for (const joint of rig.joints) {\r\n rigByJoint.set(joint, rig);\r\n }\r\n if (rig.rootJoint) {\r\n rigByJoint.set(rig.rootJoint, rig);\r\n }\r\n }\r\n }\r\n const rigs = new Set<SkeletonRig>();\r\n let result: Nullable<SkinBinding[]> = null;\r\n let ok = clip.tracks.size > 0;\r\n for (const [target, tracks] of clip.tracks) {\r\n const rig = rigByJoint.get(target);\r\n if (!rig || !tracks.every(isJointTrack)) {\r\n ok = false;\r\n break;\r\n }\r\n rigs.add(rig);\r\n }\r\n if (ok) {\r\n result = this._set.skinBindings\r\n .map((ref) => ref.get())\r\n .filter((binding): binding is SkinBinding => !!binding && rigs.has(binding.rig));\r\n if (result.length === 0) {\r\n result = null;\r\n }\r\n }\r\n this._clipInfo.set(clip, result);\r\n return result;\r\n }\r\n /** A bank bakes the joints a clip leaves alone at their bind pose, so they must be there */\r\n private untouchedJointsAtBindPose(clip: AnimationClip, bindings: SkinBinding[]) {\r\n for (const binding of bindings) {\r\n for (const joint of binding.joints) {\r\n if (clip.tracks.has(joint)) {\r\n continue;\r\n }\r\n const pose = binding.rig.getBindPoseForJoint(joint);\r\n if (\r\n pose &&\r\n !(\r\n joint.position.equalsTo(pose.position, 1e-5) &&\r\n joint.rotation.equalsTo(pose.rotation, 1e-5) &&\r\n joint.scale.equalsTo(pose.scale, 1e-5)\r\n )\r\n ) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n /** Pose the joint nodes as the last clip posed by bank tracks was at its last time */\r\n private syncJoints() {\r\n const clip = this._clip;\r\n if (!clip || this._tracks.size === 0) {\r\n return;\r\n }\r\n for (const [target, tracks] of clip.tracks) {\r\n for (const track of tracks) {\r\n // The same mapping from clip time to track time as AnimationSet.update()\r\n const t = clip.timeDuration > 0 ? (this._time / clip.timeDuration) * track.getDuration() : 0;\r\n track.applyState(target, track.calculateState(target, t));\r\n }\r\n }\r\n }\r\n /**\r\n * The bank of a skin binding, shared by the instances of the model: keyed by the prefab or model\r\n * asset the model was created from and the index of the binding in it\r\n */\r\n private acquireBank(binding: SkinBinding) {\r\n let key = this._bankKeys.get(binding);\r\n if (!key) {\r\n const prefabId = this._set.model.getPrefabNode()?.prefabId;\r\n const index = this._set.skinBindings.findIndex((ref) => ref.get() === binding);\r\n key = `${prefabId || `driver:${this._id}`}|${index}|${binding.joints.length}`;\r\n let shared = sharedBanks.get(key);\r\n if (!shared || !shared.bank.isCompatible(binding)) {\r\n // An incompatible bank under the same key comes from an edited copy of the model\r\n key = shared ? `driver:${this._id}|${index}` : key;\r\n shared = sharedBanks.get(key);\r\n if (!shared) {\r\n shared = { bank: new AnimationBank(this._set, binding, []), refs: 0 };\r\n sharedBanks.set(key, shared);\r\n }\r\n }\r\n shared.refs++;\r\n this._bankKeys.set(binding, key);\r\n }\r\n return sharedBanks.get(key)!.bank;\r\n }\r\n}\r\n"],"names":["isJointTrack","track","NodeTranslationTrack","NodeRotationTrack","NodeEulerRotationTrack","NodeScaleTrack","sharedBanks","Map","nextDriverId","GpuAnimationDriver","_set","_id","_tracks","_clipInfo","_clip","_time","_structureTag","_structureCheckedTag","_structureOk","_onStructureChanged","animationSet","_bankKeys","WeakMap","_idleFrames","model","on","active","size","update","clip","time","updateIdle","bindings","getClipBindings","canDrive","leave","syncJoints","untouchedJointsAtBindPose","binding","bank","acquireBank","index","addClip","name","get","createTrack","position","autoPlay","loop","attach","set","entryIndex","setClip","skinBindings","map","ref","filter","length","sync","values","dispose","clear","key","shared","refs","delete","off","tryGetApp","editorMode","rig","modifiers","checkStructure","joints","Set","joint","add","children","some","child","has","ok","iterate","node","gpuClothComponents","isMesh","suspendSkinning","rigByJoint","rootJoint","rigs","result","tracks","target","every","pose","getBindPoseForJoint","equalsTo","rotation","scale","t","timeDuration","getDuration","applyState","calculateState","prefabId","getPrefabNode","findIndex","isCompatible","AnimationBank"],"mappings":";;;;;;;AAaA,oCACA,SAASA,YAAAA,CAAaC,KAAa,EAAA;AACjC,IAAA,OACEA,iBAAiBC,oBACjBD,IAAAA,KAAAA,YAAiBE,iBACjBF,IAAAA,KAAAA,YAAiBG,0BACjBH,KAAiBI,YAAAA,cAAAA;AAErB;AAEA,2EACA,MAAMC,WAAAA,GAAkE,IAAIC,GAAAA,EAAAA;AAC5E,IAAIC,YAAe,GAAA,CAAA;AAEnB;;;;;;;;;;;;;;;AAeC,IACM,MAAMC,kBAAAA,CAAAA;IACMC,IAAmB;IACnBC,GAAY;IACZC,OAA8C;qEAE/D,SAAqD;IACpCC,SAA2D;IACpEC,KAA+B;IAC/BC,KAAc;IACdC,aAAsB;IACtBC,oBAA6B;IAC7BC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,SAAS,CAAC6B,GAAG,CAACZ,OAASwB,EAAAA,GAAAA,CAAAA;AAC9B;AACA,QAAA,OAAOxD,WAAYsC,CAAAA,GAAG,CAACkB,GAAAA,CAAAA,CAAMvB,IAAI;AACnC;AACF;;;;"}
@@ -184,11 +184,39 @@ function writeNearestPointsResult(out, tP, tQ, pointOnP, pointOnQ, sqrDistance,
184
184
  *
185
185
  * @public
186
186
  */ function pushoutFromCollider(colR, colRW, point, ptR, out) {
187
+ if (colR.boxHalfExtents) {
188
+ return pushoutFromBox(colRW, colR.boxHalfExtents, ptR.pointRadius, point, out);
189
+ }
187
190
  if (colR.height <= EPSILON) {
188
191
  return pushoutFromSphere(colRW.positionCurrent, colRW.radius, ptR.pointRadius, point, out);
189
192
  }
190
193
  return pushoutFromCapsule(colR, colRW, point, ptR, out);
191
194
  }
195
+ /** Pushes a point out of an oriented box collider. */ function pushoutFromBox(colRW, halfExtents, pointRadius, point, out) {
196
+ const delta = Vector3.sub(point, colRW.positionCurrent, _pushoutSphereDirection);
197
+ const local = new Vector3(Vector3.dot(delta, colRW.boxAxes[0]), Vector3.dot(delta, colRW.boxAxes[1]), Vector3.dot(delta, colRW.boxAxes[2]));
198
+ const target = new Vector3(halfExtents.x + pointRadius, halfExtents.y + pointRadius, halfExtents.z + pointRadius);
199
+ const penetration = new Vector3(target.x - Math.abs(local.x), target.y - Math.abs(local.y), target.z - Math.abs(local.z));
200
+ if (penetration.x < 0 || penetration.y < 0 || penetration.z < 0) {
201
+ return writeCollisionResult(out, false, point, !out);
202
+ }
203
+ let axis = 0;
204
+ let minPenetration = penetration.x;
205
+ if (penetration.y < minPenetration) {
206
+ axis = 1;
207
+ minPenetration = penetration.y;
208
+ }
209
+ if (penetration.z < minPenetration) {
210
+ axis = 2;
211
+ minPenetration = penetration.z;
212
+ }
213
+ const value = axis === 0 ? local.x : axis === 1 ? local.y : local.z;
214
+ const sign = value < 0 ? -1 : 1;
215
+ const result = point.clone();
216
+ const correction = Vector3.scale(colRW.boxAxes[axis], minPenetration * sign, new Vector3());
217
+ Vector3.add(result, correction, result);
218
+ return writeCollisionResult(out, true, result, !out);
219
+ }
192
220
  /**
193
221
  * Pushes a point out of a capsule collider.
194
222
  *
@@ -244,11 +272,37 @@ function writeNearestPointsResult(out, tP, tQ, pointOnP, pointOnQ, sqrDistance,
244
272
  *
245
273
  * @public
246
274
  */ function pushInFromCollider(colR, colRW, point, out) {
275
+ if (colR.boxHalfExtents) {
276
+ return pushInFromBox(colRW, colR.boxHalfExtents, point, out);
277
+ }
247
278
  if (colR.height <= EPSILON) {
248
279
  return pushInFromSphere(colRW.positionCurrent, colRW.radius, point, out);
249
280
  }
250
281
  return pushInFromCapsule(colR, colRW, point, out);
251
282
  }
283
+ /** Pulls a point back inside an oriented box collider. */ function pushInFromBox(colRW, halfExtents, point, out) {
284
+ const delta = Vector3.sub(point, colRW.positionCurrent, _pushInSphereDirection);
285
+ const local = new Vector3(Vector3.dot(delta, colRW.boxAxes[0]), Vector3.dot(delta, colRW.boxAxes[1]), Vector3.dot(delta, colRW.boxAxes[2]));
286
+ const excess = new Vector3(Math.abs(local.x) - halfExtents.x, Math.abs(local.y) - halfExtents.y, Math.abs(local.z) - halfExtents.z);
287
+ if (excess.x <= 0 && excess.y <= 0 && excess.z <= 0) {
288
+ return writeCollisionResult(out, false, point, !out);
289
+ }
290
+ let axis = 0;
291
+ let correctionDistance = excess.x;
292
+ if (excess.y > correctionDistance) {
293
+ axis = 1;
294
+ correctionDistance = excess.y;
295
+ }
296
+ if (excess.z > correctionDistance) {
297
+ axis = 2;
298
+ correctionDistance = excess.z;
299
+ }
300
+ const value = axis === 0 ? local.x : axis === 1 ? local.y : local.z;
301
+ const sign = value < 0 ? -1 : 1;
302
+ const correction = Vector3.scale(colRW.boxAxes[axis], -correctionDistance * sign, new Vector3());
303
+ const result = Vector3.add(point, correction, new Vector3());
304
+ return writeCollisionResult(out, true, result, !out);
305
+ }
252
306
  /**
253
307
  * Pulls a point inside a capsule collider.
254
308
  *
@@ -340,11 +394,68 @@ function writeNearestPointsResult(out, tP, tQ, pointOnP, pointOnQ, sqrDistance,
340
394
  *
341
395
  * @public
342
396
  */ function collisionDetection(colR, colRW, point1, point2, out) {
397
+ if (colR.boxHalfExtents) {
398
+ return collisionDetectionBox(colRW, colR.boxHalfExtents, point1, point2, out);
399
+ }
343
400
  if (colR.height <= EPSILON) {
344
401
  return collisionDetectionSphere(colRW.positionCurrent, colRW.radius, point1, point2, out);
345
402
  }
346
403
  return collisionDetectionCapsule(colR, colRW, point1, point2, out);
347
404
  }
405
+ function collisionDetectionBox(colRW, halfExtents, point1, point2, out) {
406
+ const p1 = Vector3.sub(point1, colRW.positionCurrent, new Vector3());
407
+ const p2 = Vector3.sub(point2, colRW.positionCurrent, new Vector3());
408
+ const a = new Vector3(Vector3.dot(p1, colRW.boxAxes[0]), Vector3.dot(p1, colRW.boxAxes[1]), Vector3.dot(p1, colRW.boxAxes[2]));
409
+ const b = new Vector3(Vector3.dot(p2, colRW.boxAxes[0]), Vector3.dot(p2, colRW.boxAxes[1]), Vector3.dot(p2, colRW.boxAxes[2]));
410
+ const d = Vector3.sub(b, a, new Vector3());
411
+ let enter = 0;
412
+ let exit = 1;
413
+ const mins = [
414
+ -halfExtents.x,
415
+ -halfExtents.y,
416
+ -halfExtents.z
417
+ ];
418
+ const maxs = [
419
+ halfExtents.x,
420
+ halfExtents.y,
421
+ halfExtents.z
422
+ ];
423
+ const av = [
424
+ a.x,
425
+ a.y,
426
+ a.z
427
+ ];
428
+ const dv = [
429
+ d.x,
430
+ d.y,
431
+ d.z
432
+ ];
433
+ for(let axis = 0; axis < 3; axis++){
434
+ if (Math.abs(dv[axis]) <= EPSILON) {
435
+ if (av[axis] < mins[axis] || av[axis] > maxs[axis]) {
436
+ return writeLineCollisionResult(out, false, point1, colRW.positionCurrent, 0, !out);
437
+ }
438
+ continue;
439
+ }
440
+ const inv = 1 / dv[axis];
441
+ let t0 = (mins[axis] - av[axis]) * inv;
442
+ let t1 = (maxs[axis] - av[axis]) * inv;
443
+ if (t0 > t1) {
444
+ [t0, t1] = [
445
+ t1,
446
+ t0
447
+ ];
448
+ }
449
+ enter = Math.max(enter, t0);
450
+ exit = Math.min(exit, t1);
451
+ if (enter > exit) {
452
+ return writeLineCollisionResult(out, false, point1, colRW.positionCurrent, 0, !out);
453
+ }
454
+ }
455
+ const t = Math.max(0, Math.min(1, enter));
456
+ const hitPoint = Vector3.add(point1, Vector3.scale(Vector3.sub(point2, point1, new Vector3()), t, new Vector3()), new Vector3());
457
+ return writeLineCollisionResult(out, true, hitPoint, hitPoint, 0, !out);
458
+ }
348
459
  /**
349
460
  * Performs inward collision detection.
350
461
  *
@@ -511,5 +622,5 @@ function lerp(a, b, t) {
511
622
  return a + (b - a) * t;
512
623
  }
513
624
 
514
- export { checkSurfaceCollision, collisionDetection, collisionDetectionCapsule, collisionDetectionSphere, computeNearestPoints, pushInCollisionDetection, pushInFromCapsule, pushInFromCollider, pushInFromSphere, pushoutFromCapsule, pushoutFromCollider, pushoutFromSphere };
625
+ export { checkSurfaceCollision, collisionDetection, collisionDetectionCapsule, collisionDetectionSphere, computeNearestPoints, pushInCollisionDetection, pushInFromBox, pushInFromCapsule, pushInFromCollider, pushInFromSphere, pushoutFromBox, pushoutFromCapsule, pushoutFromCollider, pushoutFromSphere };
515
626
  //# sourceMappingURL=collision.js.map