@zephyr3d/scene 0.9.1 → 0.9.3

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 (522) hide show
  1. package/dist/animation/animationset.js +2 -0
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/cloth/gpu_cloth_system.js +9 -1
  4. package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
  5. package/dist/animation/fixed_geometry_cache_track.js +5 -1
  6. package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
  7. package/dist/animation/geometry_cache_utils.js +20 -4
  8. package/dist/animation/geometry_cache_utils.js.map +1 -1
  9. package/dist/animation/ik/ik_angle_constraint.js +2 -6
  10. package/dist/animation/ik/ik_angle_constraint.js.map +1 -1
  11. package/dist/animation/ik/ik_chain_builder.js +68 -0
  12. package/dist/animation/ik/ik_chain_builder.js.map +1 -0
  13. package/dist/animation/ik/ik_pole_constraint.js +2 -7
  14. package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
  15. package/dist/animation/ik/two_bone_ik_solver.js +2 -6
  16. package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
  17. package/dist/animation/joint_dynamics/collision.js +60 -12
  18. package/dist/animation/joint_dynamics/collision.js.map +1 -1
  19. package/dist/animation/joint_dynamics/constraints.js +20 -4
  20. package/dist/animation/joint_dynamics/constraints.js.map +1 -1
  21. package/dist/animation/joint_dynamics/controller.js +94 -46
  22. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  23. package/dist/animation/joint_dynamics/math.js +16 -0
  24. package/dist/animation/joint_dynamics/math.js.map +1 -0
  25. package/dist/animation/joint_dynamics/solver.js +21 -11
  26. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  27. package/dist/animation/joint_dynamics/types.js +15 -3
  28. package/dist/animation/joint_dynamics/types.js.map +1 -1
  29. package/dist/animation/pca_geometry_cache_track.js +5 -1
  30. package/dist/animation/pca_geometry_cache_track.js.map +1 -1
  31. package/dist/animation/skeleton.js +2 -2
  32. package/dist/animation/skeleton.js.map +1 -1
  33. package/dist/animation/skeleton_modifier.js +2 -6
  34. package/dist/animation/skeleton_modifier.js.map +1 -1
  35. package/dist/animation/spring/spring_particle.js +4 -4
  36. package/dist/animation/spring/spring_particle.js.map +1 -1
  37. package/dist/animation/spring/spring_system.js +13 -40
  38. package/dist/animation/spring/spring_system.js.map +1 -1
  39. package/dist/animation/spring2/constraints.js.map +1 -1
  40. package/dist/animation/spring2/controller.js +64 -64
  41. package/dist/animation/spring2/controller.js.map +1 -1
  42. package/dist/animation/spring2/math.js.map +1 -1
  43. package/dist/animation/spring2/spring_system.js +8 -8
  44. package/dist/animation/spring2/spring_system.js.map +1 -1
  45. package/dist/app/app.js.map +1 -1
  46. package/dist/app/engine.js +1 -1
  47. package/dist/app/engine.js.map +1 -1
  48. package/dist/app/screen.js +4 -4
  49. package/dist/app/screen.js.map +1 -1
  50. package/dist/app/scriptingsystem.js +24 -1
  51. package/dist/app/scriptingsystem.js.map +1 -1
  52. package/dist/app/scriptregistry.js +22 -1
  53. package/dist/app/scriptregistry.js.map +1 -1
  54. package/dist/asset/assetmanager.js +2 -2
  55. package/dist/asset/assetmanager.js.map +1 -1
  56. package/dist/asset/model.js +60 -60
  57. package/dist/asset/model.js.map +1 -1
  58. package/dist/camera/camera.js +1 -1
  59. package/dist/camera/camera.js.map +1 -1
  60. package/dist/camera/orbit.js.map +1 -1
  61. package/dist/index.d.ts +795 -266
  62. package/dist/index.js +3 -2
  63. package/dist/index.js.map +1 -1
  64. package/dist/material/material.js +3 -1
  65. package/dist/material/material.js.map +1 -1
  66. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  67. package/dist/material/shader/helper.js +281 -278
  68. package/dist/material/shader/helper.js.map +1 -1
  69. package/dist/material/sprite.js +6 -6
  70. package/dist/material/sprite.js.map +1 -1
  71. package/dist/material/terrain-cm.js +2 -2
  72. package/dist/material/terrain-cm.js.map +1 -1
  73. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  74. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  75. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  76. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  77. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  78. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  79. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  80. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  81. package/dist/posteffect/taa.js +31 -39
  82. package/dist/posteffect/taa.js.map +1 -1
  83. package/dist/render/cluster_light.js +3 -4
  84. package/dist/render/cluster_light.js.map +1 -1
  85. package/dist/render/drawable.js +5 -1
  86. package/dist/render/drawable.js.map +1 -1
  87. package/dist/render/rendergraph/device_pool_allocator.js +29 -3
  88. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  89. package/dist/render/rendergraph/executor.js +283 -33
  90. package/dist/render/rendergraph/executor.js.map +1 -1
  91. package/dist/render/rendergraph/forward_plus_builder.js +338 -108
  92. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  93. package/dist/render/rendergraph/history_resource_manager.js +195 -115
  94. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  95. package/dist/render/rendergraph/history_resources.js +10 -0
  96. package/dist/render/rendergraph/history_resources.js.map +1 -0
  97. package/dist/render/rendergraph/rendergraph.js +162 -35
  98. package/dist/render/rendergraph/rendergraph.js.map +1 -1
  99. package/dist/render/rendergraph/types.js +25 -5
  100. package/dist/render/rendergraph/types.js.map +1 -1
  101. package/dist/render/rendertarget.js +5 -1
  102. package/dist/render/rendertarget.js.map +1 -1
  103. package/dist/render/screenrendertarget.js +5 -1
  104. package/dist/render/screenrendertarget.js.map +1 -1
  105. package/dist/render/sky.js +4 -4
  106. package/dist/render/sky.js.map +1 -1
  107. package/dist/scene/basesprite.js +2 -2
  108. package/dist/scene/basesprite.js.map +1 -1
  109. package/dist/scene/graph_node.js +1 -1
  110. package/dist/scene/graph_node.js.map +1 -1
  111. package/dist/scene/mesh.js +81 -97
  112. package/dist/scene/mesh.js.map +1 -1
  113. package/dist/scene/particlesys.js +1 -1
  114. package/dist/scene/particlesys.js.map +1 -1
  115. package/dist/scene/scene_node.js +228 -228
  116. package/dist/scene/scene_node.js.map +1 -1
  117. package/dist/scene/script_attachment.js +15 -3
  118. package/dist/scene/script_attachment.js.map +1 -1
  119. package/dist/scene/terrain-cm/terrain-cm.js +3 -3
  120. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  121. package/dist/shadow/shadowmapper.js.map +1 -1
  122. package/dist/shapes/box.js +1 -1
  123. package/dist/shapes/box.js.map +1 -1
  124. package/dist/shapes/capsule.js +0 -3
  125. package/dist/shapes/capsule.js.map +1 -1
  126. package/dist/shapes/cylinder.js +0 -3
  127. package/dist/shapes/cylinder.js.map +1 -1
  128. package/dist/shapes/plane.js +0 -3
  129. package/dist/shapes/plane.js.map +1 -1
  130. package/dist/shapes/tetrahedron.js +3 -9
  131. package/dist/shapes/tetrahedron.js.map +1 -1
  132. package/dist/shapes/torus.js +94 -66
  133. package/dist/shapes/torus.js.map +1 -1
  134. package/dist/src/animation/animation.js +127 -0
  135. package/dist/src/animation/animation.js.map +1 -0
  136. package/dist/src/animation/animationset.js +255 -0
  137. package/dist/src/animation/animationset.js.map +1 -0
  138. package/dist/src/animation/animationtrack.js +34 -0
  139. package/dist/src/animation/animationtrack.js.map +1 -0
  140. package/dist/src/animation/eulerrotationtrack.js +52 -0
  141. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  142. package/dist/src/animation/morphtarget.js +93 -0
  143. package/dist/src/animation/morphtarget.js.map +1 -0
  144. package/dist/src/animation/morphtrack.js +70 -0
  145. package/dist/src/animation/morphtrack.js.map +1 -0
  146. package/dist/src/animation/proptrack.js +161 -0
  147. package/dist/src/animation/proptrack.js.map +1 -0
  148. package/dist/src/animation/rotationtrack.js +51 -0
  149. package/dist/src/animation/rotationtrack.js.map +1 -0
  150. package/dist/src/animation/scaletrack.js +50 -0
  151. package/dist/src/animation/scaletrack.js.map +1 -0
  152. package/dist/src/animation/skeleton.js +204 -0
  153. package/dist/src/animation/skeleton.js.map +1 -0
  154. package/dist/src/animation/translationtrack.js +50 -0
  155. package/dist/src/animation/translationtrack.js.map +1 -0
  156. package/dist/src/app/app.js +129 -0
  157. package/dist/src/app/app.js.map +1 -0
  158. package/dist/src/app/inputmgr.js +267 -0
  159. package/dist/src/app/inputmgr.js.map +1 -0
  160. package/dist/src/asset/assetmanager.js +404 -0
  161. package/dist/src/asset/assetmanager.js.map +1 -0
  162. package/dist/src/asset/builtin.js +337 -0
  163. package/dist/src/asset/builtin.js.map +1 -0
  164. package/dist/src/asset/loaders/dds/dds.js +470 -0
  165. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  166. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  167. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  168. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  169. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  170. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  171. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  172. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  173. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  174. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  175. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  176. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  177. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  178. package/dist/src/asset/loaders/loader.js +45 -0
  179. package/dist/src/asset/loaders/loader.js.map +1 -0
  180. package/dist/src/asset/model.js +414 -0
  181. package/dist/src/asset/model.js.map +1 -0
  182. package/dist/src/blitter/bilateralblur.js +221 -0
  183. package/dist/src/blitter/bilateralblur.js.map +1 -0
  184. package/dist/src/blitter/blitter.js +390 -0
  185. package/dist/src/blitter/blitter.js.map +1 -0
  186. package/dist/src/blitter/box.js +118 -0
  187. package/dist/src/blitter/box.js.map +1 -0
  188. package/dist/src/blitter/copy.js +22 -0
  189. package/dist/src/blitter/copy.js.map +1 -0
  190. package/dist/src/blitter/gaussianblur.js +228 -0
  191. package/dist/src/blitter/gaussianblur.js.map +1 -0
  192. package/dist/src/camera/base.js +92 -0
  193. package/dist/src/camera/base.js.map +1 -0
  194. package/dist/src/camera/camera.js +1005 -0
  195. package/dist/src/camera/camera.js.map +1 -0
  196. package/dist/src/camera/fps.js +238 -0
  197. package/dist/src/camera/fps.js.map +1 -0
  198. package/dist/src/camera/orbit.js +245 -0
  199. package/dist/src/camera/orbit.js.map +1 -0
  200. package/dist/src/camera/orthocamera.js +167 -0
  201. package/dist/src/camera/orthocamera.js.map +1 -0
  202. package/dist/src/camera/perspectivecamera.js +141 -0
  203. package/dist/src/camera/perspectivecamera.js.map +1 -0
  204. package/dist/src/index.js +120 -0
  205. package/dist/src/index.js.map +1 -0
  206. package/dist/src/material/blinn.js +81 -0
  207. package/dist/src/material/blinn.js.map +1 -0
  208. package/dist/src/material/grassmaterial.js +113 -0
  209. package/dist/src/material/grassmaterial.js.map +1 -0
  210. package/dist/src/material/lambert.js +92 -0
  211. package/dist/src/material/lambert.js.map +1 -0
  212. package/dist/src/material/material.js +301 -0
  213. package/dist/src/material/material.js.map +1 -0
  214. package/dist/src/material/meshmaterial.js +704 -0
  215. package/dist/src/material/meshmaterial.js.map +1 -0
  216. package/dist/src/material/mixins/albedocolor.js +76 -0
  217. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  218. package/dist/src/material/mixins/foliage.js +47 -0
  219. package/dist/src/material/mixins/foliage.js.map +1 -0
  220. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  221. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  222. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  223. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  224. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  225. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  226. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  227. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  228. package/dist/src/material/mixins/lit.js +476 -0
  229. package/dist/src/material/mixins/lit.js.map +1 -0
  230. package/dist/src/material/mixins/pbr/common.js +918 -0
  231. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  232. package/dist/src/material/mixins/texture.js +172 -0
  233. package/dist/src/material/mixins/texture.js.map +1 -0
  234. package/dist/src/material/mixins/vertexcolor.js +56 -0
  235. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  236. package/dist/src/material/particle.js +178 -0
  237. package/dist/src/material/particle.js.map +1 -0
  238. package/dist/src/material/pbrmr.js +97 -0
  239. package/dist/src/material/pbrmr.js.map +1 -0
  240. package/dist/src/material/pbrsg.js +97 -0
  241. package/dist/src/material/pbrsg.js.map +1 -0
  242. package/dist/src/material/shader/helper.js +1209 -0
  243. package/dist/src/material/shader/helper.js.map +1 -0
  244. package/dist/src/material/terrain-cm.js +606 -0
  245. package/dist/src/material/terrain-cm.js.map +1 -0
  246. package/dist/src/material/terrainmaterial.js +375 -0
  247. package/dist/src/material/terrainmaterial.js.map +1 -0
  248. package/dist/src/material/unlit.js +41 -0
  249. package/dist/src/material/unlit.js.map +1 -0
  250. package/dist/src/material/water.js +417 -0
  251. package/dist/src/material/water.js.map +1 -0
  252. package/dist/src/posteffect/bloom.js +361 -0
  253. package/dist/src/posteffect/bloom.js.map +1 -0
  254. package/dist/src/posteffect/compositor.js +226 -0
  255. package/dist/src/posteffect/compositor.js.map +1 -0
  256. package/dist/src/posteffect/fxaa.js +273 -0
  257. package/dist/src/posteffect/fxaa.js.map +1 -0
  258. package/dist/src/posteffect/grayscale.js +69 -0
  259. package/dist/src/posteffect/grayscale.js.map +1 -0
  260. package/dist/src/posteffect/motionblur.js +96 -0
  261. package/dist/src/posteffect/motionblur.js.map +1 -0
  262. package/dist/src/posteffect/posteffect.js +126 -0
  263. package/dist/src/posteffect/posteffect.js.map +1 -0
  264. package/dist/src/posteffect/sao.js +324 -0
  265. package/dist/src/posteffect/sao.js.map +1 -0
  266. package/dist/src/posteffect/ssr.js +489 -0
  267. package/dist/src/posteffect/ssr.js.map +1 -0
  268. package/dist/src/posteffect/taa.js +172 -0
  269. package/dist/src/posteffect/taa.js.map +1 -0
  270. package/dist/src/posteffect/tonemap.js +94 -0
  271. package/dist/src/posteffect/tonemap.js.map +1 -0
  272. package/dist/src/render/abuffer_oit.js +361 -0
  273. package/dist/src/render/abuffer_oit.js.map +1 -0
  274. package/dist/src/render/clipmap.js +851 -0
  275. package/dist/src/render/clipmap.js.map +1 -0
  276. package/dist/src/render/cluster_light.js +333 -0
  277. package/dist/src/render/cluster_light.js.map +1 -0
  278. package/dist/src/render/cull_visitor.js +187 -0
  279. package/dist/src/render/cull_visitor.js.map +1 -0
  280. package/dist/src/render/depthpass.js +68 -0
  281. package/dist/src/render/depthpass.js.map +1 -0
  282. package/dist/src/render/drawable_mixin.js +227 -0
  283. package/dist/src/render/drawable_mixin.js.map +1 -0
  284. package/dist/src/render/envlight.js +463 -0
  285. package/dist/src/render/envlight.js.map +1 -0
  286. package/dist/src/render/fbm_wavegenerator.js +251 -0
  287. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  288. package/dist/src/render/fft_wavegenerator.js +1006 -0
  289. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  290. package/dist/src/render/fullscreenquad.js +38 -0
  291. package/dist/src/render/fullscreenquad.js.map +1 -0
  292. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  293. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  294. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  295. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  296. package/dist/src/render/hzb.js +273 -0
  297. package/dist/src/render/hzb.js.map +1 -0
  298. package/dist/src/render/lightpass.js +172 -0
  299. package/dist/src/render/lightpass.js.map +1 -0
  300. package/dist/src/render/objectcolorpass.js +51 -0
  301. package/dist/src/render/objectcolorpass.js.map +1 -0
  302. package/dist/src/render/primitive.js +364 -0
  303. package/dist/src/render/primitive.js.map +1 -0
  304. package/dist/src/render/render_queue.js +467 -0
  305. package/dist/src/render/render_queue.js.map +1 -0
  306. package/dist/src/render/renderbundle_wrapper.js +152 -0
  307. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  308. package/dist/src/render/renderer.js +455 -0
  309. package/dist/src/render/renderer.js.map +1 -0
  310. package/dist/src/render/renderpass.js +200 -0
  311. package/dist/src/render/renderpass.js.map +1 -0
  312. package/dist/src/render/shadowmap_pass.js +56 -0
  313. package/dist/src/render/shadowmap_pass.js.map +1 -0
  314. package/dist/src/render/sky.js +1103 -0
  315. package/dist/src/render/sky.js.map +1 -0
  316. package/dist/src/render/weightedblended_oit.js +168 -0
  317. package/dist/src/render/weightedblended_oit.js.map +1 -0
  318. package/dist/src/scene/batchgroup.js +162 -0
  319. package/dist/src/scene/batchgroup.js.map +1 -0
  320. package/dist/src/scene/environment.js +209 -0
  321. package/dist/src/scene/environment.js.map +1 -0
  322. package/dist/src/scene/graph_node.js +72 -0
  323. package/dist/src/scene/graph_node.js.map +1 -0
  324. package/dist/src/scene/light.js +416 -0
  325. package/dist/src/scene/light.js.map +1 -0
  326. package/dist/src/scene/mesh.js +341 -0
  327. package/dist/src/scene/mesh.js.map +1 -0
  328. package/dist/src/scene/octree.js +649 -0
  329. package/dist/src/scene/octree.js.map +1 -0
  330. package/dist/src/scene/particlesys.js +738 -0
  331. package/dist/src/scene/particlesys.js.map +1 -0
  332. package/dist/src/scene/raycast_visitor.js +103 -0
  333. package/dist/src/scene/raycast_visitor.js.map +1 -0
  334. package/dist/src/scene/scene.js +284 -0
  335. package/dist/src/scene/scene.js.map +1 -0
  336. package/dist/src/scene/scene_node.js +732 -0
  337. package/dist/src/scene/scene_node.js.map +1 -0
  338. package/dist/src/scene/terrain/grass.js +278 -0
  339. package/dist/src/scene/terrain/grass.js.map +1 -0
  340. package/dist/src/scene/terrain/heightfield.js +475 -0
  341. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  342. package/dist/src/scene/terrain/patch.js +530 -0
  343. package/dist/src/scene/terrain/patch.js.map +1 -0
  344. package/dist/src/scene/terrain/quadtree.js +461 -0
  345. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  346. package/dist/src/scene/terrain/terrain.js +246 -0
  347. package/dist/src/scene/terrain/terrain.js.map +1 -0
  348. package/dist/src/scene/terrain-cm/grass.js +594 -0
  349. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  350. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  351. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  352. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  353. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  354. package/dist/src/scene/water.js +374 -0
  355. package/dist/src/scene/water.js.map +1 -0
  356. package/dist/src/shaders/atmosphere.js +957 -0
  357. package/dist/src/shaders/atmosphere.js.map +1 -0
  358. package/dist/src/shaders/fog.js +112 -0
  359. package/dist/src/shaders/fog.js.map +1 -0
  360. package/dist/src/shaders/misc.js +266 -0
  361. package/dist/src/shaders/misc.js.map +1 -0
  362. package/dist/src/shaders/noise.js +222 -0
  363. package/dist/src/shaders/noise.js.map +1 -0
  364. package/dist/src/shaders/pbr.js +51 -0
  365. package/dist/src/shaders/pbr.js.map +1 -0
  366. package/dist/src/shaders/shadow.js +636 -0
  367. package/dist/src/shaders/shadow.js.map +1 -0
  368. package/dist/src/shaders/ssr.js +490 -0
  369. package/dist/src/shaders/ssr.js.map +1 -0
  370. package/dist/src/shaders/temporal.js +215 -0
  371. package/dist/src/shaders/temporal.js.map +1 -0
  372. package/dist/src/shaders/water.js +756 -0
  373. package/dist/src/shaders/water.js.map +1 -0
  374. package/dist/src/shadow/esm.js +237 -0
  375. package/dist/src/shadow/esm.js.map +1 -0
  376. package/dist/src/shadow/pcf_opt.js +181 -0
  377. package/dist/src/shadow/pcf_opt.js.map +1 -0
  378. package/dist/src/shadow/pcf_pd.js +189 -0
  379. package/dist/src/shadow/pcf_pd.js.map +1 -0
  380. package/dist/src/shadow/shader.js +37 -0
  381. package/dist/src/shadow/shader.js.map +1 -0
  382. package/dist/src/shadow/shadow_impl.js +15 -0
  383. package/dist/src/shadow/shadow_impl.js.map +1 -0
  384. package/dist/src/shadow/shadowmapper.js +790 -0
  385. package/dist/src/shadow/shadowmapper.js.map +1 -0
  386. package/dist/src/shadow/ssm.js +159 -0
  387. package/dist/src/shadow/ssm.js.map +1 -0
  388. package/dist/src/shadow/vsm.js +297 -0
  389. package/dist/src/shadow/vsm.js.map +1 -0
  390. package/dist/src/shapes/box.js +386 -0
  391. package/dist/src/shapes/box.js.map +1 -0
  392. package/dist/src/shapes/cylinder.js +125 -0
  393. package/dist/src/shapes/cylinder.js.map +1 -0
  394. package/dist/src/shapes/plane.js +88 -0
  395. package/dist/src/shapes/plane.js.map +1 -0
  396. package/dist/src/shapes/shape.js +87 -0
  397. package/dist/src/shapes/shape.js.map +1 -0
  398. package/dist/src/shapes/sphere.js +114 -0
  399. package/dist/src/shapes/sphere.js.map +1 -0
  400. package/dist/src/shapes/tetrahedron.js +188 -0
  401. package/dist/src/shapes/tetrahedron.js.map +1 -0
  402. package/dist/src/shapes/torus.js +111 -0
  403. package/dist/src/shapes/torus.js.map +1 -0
  404. package/dist/src/utility/aabbtree.js +400 -0
  405. package/dist/src/utility/aabbtree.js.map +1 -0
  406. package/dist/src/utility/bounding_volume.js +29 -0
  407. package/dist/src/utility/bounding_volume.js.map +1 -0
  408. package/dist/src/utility/debug.js +28 -0
  409. package/dist/src/utility/debug.js.map +1 -0
  410. package/dist/src/utility/draco/decoder.js +116 -0
  411. package/dist/src/utility/draco/decoder.js.map +1 -0
  412. package/dist/src/utility/misc.js +105 -0
  413. package/dist/src/utility/misc.js.map +1 -0
  414. package/dist/src/utility/panorama.js +163 -0
  415. package/dist/src/utility/panorama.js.map +1 -0
  416. package/dist/src/utility/pmrem.js +354 -0
  417. package/dist/src/utility/pmrem.js.map +1 -0
  418. package/dist/src/utility/rendermipmap.js +115 -0
  419. package/dist/src/utility/rendermipmap.js.map +1 -0
  420. package/dist/src/utility/serialization/json.js +402 -0
  421. package/dist/src/utility/serialization/json.js.map +1 -0
  422. package/dist/src/utility/serialization/manager.js +623 -0
  423. package/dist/src/utility/serialization/manager.js.map +1 -0
  424. package/dist/src/utility/serialization/scene/animation.js +248 -0
  425. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  426. package/dist/src/utility/serialization/scene/batch.js +59 -0
  427. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  428. package/dist/src/utility/serialization/scene/camera.js +790 -0
  429. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  430. package/dist/src/utility/serialization/scene/common.js +222 -0
  431. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  432. package/dist/src/utility/serialization/scene/light.js +575 -0
  433. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  434. package/dist/src/utility/serialization/scene/material.js +1111 -0
  435. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  436. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  437. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  438. package/dist/src/utility/serialization/scene/misc.js +39 -0
  439. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  440. package/dist/src/utility/serialization/scene/node.js +451 -0
  441. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  442. package/dist/src/utility/serialization/scene/particle.js +425 -0
  443. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  444. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  445. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  446. package/dist/src/utility/serialization/scene/scene.js +704 -0
  447. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  448. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  449. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  450. package/dist/src/utility/serialization/scene/water.js +465 -0
  451. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  452. package/dist/src/utility/shprojector.js +297 -0
  453. package/dist/src/utility/shprojector.js.map +1 -0
  454. package/dist/src/utility/textures/ggxlut.js +213 -0
  455. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  456. package/dist/src/utility/textures/gradientnoise.js +62 -0
  457. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  458. package/dist/src/utility/textures/randomnoise.js +41 -0
  459. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  460. package/dist/src/values.js +162 -0
  461. package/dist/src/values.js.map +1 -0
  462. package/dist/utility/blueprint/material/common.js +7 -0
  463. package/dist/utility/blueprint/material/common.js.map +1 -0
  464. package/dist/utility/blueprint/material/inputs.js +3 -3
  465. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  466. package/dist/utility/blueprint/material/ir.js +4 -4
  467. package/dist/utility/blueprint/material/ir.js.map +1 -1
  468. package/dist/utility/serialization/blueprint/constants.js +255 -0
  469. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  470. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  471. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  472. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  473. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  474. package/dist/utility/serialization/manager.js +299 -268
  475. package/dist/utility/serialization/manager.js.map +1 -1
  476. package/dist/utility/serialization/scene/animation.js +45 -0
  477. package/dist/utility/serialization/scene/animation.js.map +1 -1
  478. package/dist/utility/serialization/scene/camera.js +53 -0
  479. package/dist/utility/serialization/scene/camera.js.map +1 -1
  480. package/dist/utility/serialization/scene/common.js +10 -0
  481. package/dist/utility/serialization/scene/common.js.map +1 -1
  482. package/dist/utility/serialization/scene/light.js +30 -0
  483. package/dist/utility/serialization/scene/light.js.map +1 -1
  484. package/dist/utility/serialization/scene/material.js +63 -0
  485. package/dist/utility/serialization/scene/material.js.map +1 -1
  486. package/dist/utility/serialization/scene/mesh.js +11 -0
  487. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  488. package/dist/utility/serialization/scene/misc.js +2 -0
  489. package/dist/utility/serialization/scene/misc.js.map +1 -1
  490. package/dist/utility/serialization/scene/node.js +19 -0
  491. package/dist/utility/serialization/scene/node.js.map +1 -1
  492. package/dist/utility/serialization/scene/particle.js +22 -0
  493. package/dist/utility/serialization/scene/particle.js.map +1 -1
  494. package/dist/utility/serialization/scene/primitive.js +33 -0
  495. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  496. package/dist/utility/serialization/scene/scene.js +39 -0
  497. package/dist/utility/serialization/scene/scene.js.map +1 -1
  498. package/dist/utility/serialization/scene/script.js +2 -0
  499. package/dist/utility/serialization/scene/script.js.map +1 -1
  500. package/dist/utility/serialization/scene/sprite.js +6 -0
  501. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  502. package/dist/utility/serialization/scene/terrain.js +9 -0
  503. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  504. package/dist/utility/serialization/scene/water.js +21 -0
  505. package/dist/utility/serialization/scene/water.js.map +1 -1
  506. package/dist/utility/serialization/types.js +5 -1
  507. package/dist/utility/serialization/types.js.map +1 -1
  508. package/dist/values.js +49 -53
  509. package/dist/values.js.map +1 -1
  510. package/package.json +2 -2
  511. package/dist/animation/joint_dynamics/vrm_spring_bone.js +0 -46
  512. package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +0 -1
  513. package/dist/animation/spring/spring_bone.js +0 -240
  514. package/dist/animation/spring/spring_bone.js.map +0 -1
  515. package/dist/animation/spring/spring_bone_collider.js +0 -198
  516. package/dist/animation/spring/spring_bone_collider.js.map +0 -1
  517. package/dist/animation/spring/spring_bone_constraint.js +0 -170
  518. package/dist/animation/spring/spring_bone_constraint.js.map +0 -1
  519. package/dist/animation/spring/spring_bone_system.js +0 -328
  520. package/dist/animation/spring/spring_bone_system.js.map +0 -1
  521. package/dist/render/sky_motion_vector.js +0 -85
  522. package/dist/render/sky_motion_vector.js.map +0 -1
@@ -1,7 +1,11 @@
1
1
  import { AnimationTrack } from './animationtrack.js';
2
2
  import { createGeometryCacheState, mixGeometryCacheBoundingBox, ensureGeometryCacheMeshBinding } from './geometry_cache_utils.js';
3
3
 
4
- class FixedGeometryCacheTrack extends AnimationTrack {
4
+ /**
5
+ * Geometry cache track backed by explicit per-frame vertex data.
6
+ *
7
+ * @public
8
+ */ class FixedGeometryCacheTrack extends AnimationTrack {
5
9
  _times;
6
10
  _frames;
7
11
  _state;
@@ -1 +1 @@
1
- {"version":3,"file":"fixed_geometry_cache_track.js","sources":["../../src/animation/fixed_geometry_cache_track.ts"],"sourcesContent":["import { AnimationTrack } from './animationtrack';\r\nimport type { Mesh } from '../scene';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport {\r\n createGeometryCacheState,\r\n ensureGeometryCacheMeshBinding,\r\n mixGeometryCacheBoundingBox,\r\n type GeometryCacheFrame,\r\n type GeometryCacheMeshBinding,\r\n type GeometryCacheState\r\n} from './geometry_cache_utils';\r\n\r\nexport type FixedGeometryCacheFrame = GeometryCacheFrame;\r\nexport type FixedGeometryCacheState = GeometryCacheState;\r\n\r\nexport class FixedGeometryCacheTrack extends AnimationTrack<FixedGeometryCacheState> {\r\n private _times: Float32Array;\r\n private _frames: FixedGeometryCacheFrame[];\r\n private _state: Nullable<FixedGeometryCacheState>;\r\n private readonly _meshBindings: WeakMap<Mesh, GeometryCacheMeshBinding>;\r\n\r\n constructor(times?: Float32Array, frames?: FixedGeometryCacheFrame[], embedded?: boolean) {\r\n super(embedded);\r\n this._times = times ?? new Float32Array();\r\n this._frames = frames ?? [];\r\n this._state = this._frames.length > 0 ? createGeometryCacheState(this._frames[0]) : null;\r\n this._meshBindings = new WeakMap();\r\n }\r\n\r\n get times() {\r\n return this._times;\r\n }\r\n\r\n set times(value: Float32Array) {\r\n this._times = value ?? new Float32Array();\r\n }\r\n\r\n get frames() {\r\n return this._frames;\r\n }\r\n\r\n set frames(value: FixedGeometryCacheFrame[]) {\r\n this._frames = value ?? [];\r\n this._state = this._frames.length > 0 ? createGeometryCacheState(this._frames[0]) : null;\r\n }\r\n\r\n calculateState(_target: object, currentTime: number) {\r\n if (this._frames.length === 0) {\r\n throw new Error('FixedGeometryCacheTrack.calculateState(): no frames available');\r\n }\r\n if (this._frames.length === 1 || this._times.length <= 1) {\r\n return this.copyFrameToState(this._frames[0]);\r\n }\r\n if (currentTime <= this._times[0]) {\r\n return this.copyFrameToState(this._frames[0]);\r\n }\r\n const lastIndex = this._times.length - 1;\r\n if (currentTime >= this._times[lastIndex]) {\r\n return this.copyFrameToState(this._frames[lastIndex]);\r\n }\r\n let right = 1;\r\n while (right < this._times.length && this._times[right] < currentTime) {\r\n right++;\r\n }\r\n const left = Math.max(0, right - 1);\r\n const start = this._times[left];\r\n const end = this._times[right];\r\n const t = end > start ? (currentTime - start) / (end - start) : 0;\r\n return this.interpolateFrames(this._frames[left], this._frames[right], t);\r\n }\r\n\r\n applyState(target: object, state: FixedGeometryCacheState) {\r\n const mesh = target as Mesh;\r\n const binding = this.ensureMeshBinding(mesh, state);\r\n binding.positionBuffer.bufferSubData(0, state.positions as unknown as Float32Array<ArrayBuffer>);\r\n if (binding.normalBuffer && state.normals) {\r\n binding.normalBuffer.bufferSubData(0, state.normals as unknown as Float32Array<ArrayBuffer>);\r\n }\r\n mesh.setAnimatedBoundingBox(state.boundingBox);\r\n }\r\n\r\n mixState(a: FixedGeometryCacheState, b: FixedGeometryCacheState, t: number) {\r\n if (!this._state) {\r\n throw new Error('FixedGeometryCacheTrack.mixState(): invalid state');\r\n }\r\n const positions = new Float32Array(a.positions.length);\r\n for (let i = 0; i < positions.length; i++) {\r\n positions[i] = a.positions[i] + (b.positions[i] - a.positions[i]) * t;\r\n }\r\n let normals: Nullable<Float32Array> = null;\r\n if (a.normals && b.normals && a.normals.length === b.normals.length) {\r\n normals = new Float32Array(a.normals.length);\r\n for (let i = 0; i < normals.length; i++) {\r\n normals[i] = a.normals[i] + (b.normals[i] - a.normals[i]) * t;\r\n }\r\n }\r\n return {\r\n positions,\r\n normals,\r\n boundingBox: mixGeometryCacheBoundingBox(a.boundingBox, b.boundingBox, t)\r\n };\r\n }\r\n\r\n getBlendId() {\r\n return 'fixed-geometry-cache';\r\n }\r\n\r\n getDuration() {\r\n return this._times.length > 0 ? this._times[this._times.length - 1] : 0;\r\n }\r\n\r\n reset(target: object) {\r\n if (this._frames.length > 0) {\r\n this.applyState(target, this.copyFrameToState(this._frames[0]));\r\n }\r\n }\r\n\r\n private copyFrameToState(frame: FixedGeometryCacheFrame) {\r\n if (!this._state) {\r\n this._state = createGeometryCacheState(frame);\r\n }\r\n this._state.positions.set(frame.positions);\r\n if (frame.normals) {\r\n if (!this._state.normals || this._state.normals.length !== frame.normals.length) {\r\n this._state.normals = new Float32Array(frame.normals.length);\r\n }\r\n this._state.normals.set(frame.normals);\r\n } else {\r\n this._state.normals = null;\r\n }\r\n this._state.boundingBox.minPoint.set(frame.boundingBox.minPoint);\r\n this._state.boundingBox.maxPoint.set(frame.boundingBox.maxPoint);\r\n return this._state;\r\n }\r\n\r\n private interpolateFrames(a: FixedGeometryCacheFrame, b: FixedGeometryCacheFrame, t: number) {\r\n if (!this._state) {\r\n this._state = createGeometryCacheState(a);\r\n }\r\n for (let i = 0; i < this._state.positions.length; i++) {\r\n this._state.positions[i] = a.positions[i] + (b.positions[i] - a.positions[i]) * t;\r\n }\r\n if (a.normals && b.normals && a.normals.length === b.normals.length) {\r\n if (!this._state.normals || this._state.normals.length !== a.normals.length) {\r\n this._state.normals = new Float32Array(a.normals.length);\r\n }\r\n for (let i = 0; i < this._state.normals.length; i++) {\r\n this._state.normals[i] = a.normals[i] + (b.normals[i] - a.normals[i]) * t;\r\n }\r\n } else {\r\n this._state.normals = null;\r\n }\r\n this._state.boundingBox.minPoint.setXYZ(\r\n a.boundingBox.minPoint.x + (b.boundingBox.minPoint.x - a.boundingBox.minPoint.x) * t,\r\n a.boundingBox.minPoint.y + (b.boundingBox.minPoint.y - a.boundingBox.minPoint.y) * t,\r\n a.boundingBox.minPoint.z + (b.boundingBox.minPoint.z - a.boundingBox.minPoint.z) * t\r\n );\r\n this._state.boundingBox.maxPoint.setXYZ(\r\n a.boundingBox.maxPoint.x + (b.boundingBox.maxPoint.x - a.boundingBox.maxPoint.x) * t,\r\n a.boundingBox.maxPoint.y + (b.boundingBox.maxPoint.y - a.boundingBox.maxPoint.y) * t,\r\n a.boundingBox.maxPoint.z + (b.boundingBox.maxPoint.z - a.boundingBox.maxPoint.z) * t\r\n );\r\n return this._state;\r\n }\r\n\r\n private ensureMeshBinding(mesh: Mesh, state: FixedGeometryCacheState) {\r\n return ensureGeometryCacheMeshBinding(\r\n this._meshBindings,\r\n mesh,\r\n state,\r\n 'FixedGeometryCacheTrack.applyState()'\r\n );\r\n }\r\n}\r\n"],"names":["FixedGeometryCacheTrack","AnimationTrack","_times","_frames","_state","_meshBindings","times","frames","embedded","Float32Array","length","createGeometryCacheState","WeakMap","value","calculateState","_target","currentTime","Error","copyFrameToState","lastIndex","right","left","Math","max","start","end","t","interpolateFrames","applyState","target","state","mesh","binding","ensureMeshBinding","positionBuffer","bufferSubData","positions","normalBuffer","normals","setAnimatedBoundingBox","boundingBox","mixState","a","b","i","mixGeometryCacheBoundingBox","getBlendId","getDuration","reset","frame","set","minPoint","maxPoint","setXYZ","x","y","z","ensureGeometryCacheMeshBinding"],"mappings":";;;AAeO,MAAMA,uBAAgCC,SAAAA,cAAAA,CAAAA;IACnCC,MAAqB;IACrBC,OAAm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AAEH,WAAW,CAACW,QAAQ,CAACI,CAAC,GAAGb,CAAAA,CAAEF,WAAW,CAACW,QAAQ,CAACI,CAAC,IAAI7B,CAAAA,EACnFgB,EAAEF,WAAW,CAACW,QAAQ,CAACK,CAAC,GAAIb,CAAAA,CAAEH,CAAAA,WAAW,CAACW,QAAQ,CAACK,CAAC,GAAGd,EAAEF,WAAW,CAACW,QAAQ,CAACK,CAAC,IAAI9B,CAAAA,CAAAA;AAErF,QAAA,IAAI,CAACtB,MAAM,CAACoC,WAAW,CAACY,QAAQ,CAACC,MAAM,CACrCX,CAAAA,CAAEF,WAAW,CAACY,QAAQ,CAACE,CAAC,GAAG,CAACX,CAAAA,CAAEH,WAAW,CAACY,QAAQ,CAACE,CAAC,GAAGZ,CAAEF,CAAAA,WAAW,CAACY,QAAQ,CAACE,CAAAA,IAAK5B,CACnFgB,EAAAA,CAAAA,CAAEF,WAAW,CAACY,QAAQ,CAACG,CAAC,GAAG,CAACZ,EAAEH,WAAW,CAACY,QAAQ,CAACG,CAAC,GAAGb,CAAAA,CAAEF,WAAW,CAACY,QAAQ,CAACG,CAAC,IAAI7B,CAAAA,EACnFgB,EAAEF,WAAW,CAACY,QAAQ,CAACI,CAAC,GAAIb,CAAAA,CAAEH,CAAAA,WAAW,CAACY,QAAQ,CAACI,CAAC,GAAGd,EAAEF,WAAW,CAACY,QAAQ,CAACI,CAAC,IAAI9B,CAAAA,CAAAA;QAErF,OAAO,IAAI,CAACtB,MAAM;AACpB;IAEQ6B,iBAAkBF,CAAAA,IAAU,EAAED,KAA8B,EAAE;AACpE,QAAA,OAAO2B,+BACL,IAAI,CAACpD,aAAa,EAClB0B,MACAD,KACA,EAAA,sCAAA,CAAA;AAEJ;AACF;;;;"}
1
+ {"version":3,"file":"fixed_geometry_cache_track.js","sources":["../../src/animation/fixed_geometry_cache_track.ts"],"sourcesContent":["import { AnimationTrack } from './animationtrack';\r\nimport type { Mesh } from '../scene';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport {\r\n createGeometryCacheState,\r\n ensureGeometryCacheMeshBinding,\r\n mixGeometryCacheBoundingBox,\r\n type GeometryCacheFrame,\r\n type GeometryCacheMeshBinding,\r\n type GeometryCacheState\r\n} from './geometry_cache_utils';\r\n\r\n/** @public */\r\nexport type FixedGeometryCacheFrame = GeometryCacheFrame;\r\n/** @public */\r\nexport type FixedGeometryCacheState = GeometryCacheState;\r\n\r\n/**\r\n * Geometry cache track backed by explicit per-frame vertex data.\r\n *\r\n * @public\r\n */\r\nexport class FixedGeometryCacheTrack extends AnimationTrack<FixedGeometryCacheState> {\r\n private _times: Float32Array;\r\n private _frames: FixedGeometryCacheFrame[];\r\n private _state: Nullable<FixedGeometryCacheState>;\r\n private readonly _meshBindings: WeakMap<Mesh, GeometryCacheMeshBinding>;\r\n\r\n constructor(times?: Float32Array, frames?: FixedGeometryCacheFrame[], embedded?: boolean) {\r\n super(embedded);\r\n this._times = times ?? new Float32Array();\r\n this._frames = frames ?? [];\r\n this._state = this._frames.length > 0 ? createGeometryCacheState(this._frames[0]) : null;\r\n this._meshBindings = new WeakMap();\r\n }\r\n\r\n get times() {\r\n return this._times;\r\n }\r\n\r\n set times(value: Float32Array) {\r\n this._times = value ?? new Float32Array();\r\n }\r\n\r\n get frames() {\r\n return this._frames;\r\n }\r\n\r\n set frames(value: FixedGeometryCacheFrame[]) {\r\n this._frames = value ?? [];\r\n this._state = this._frames.length > 0 ? createGeometryCacheState(this._frames[0]) : null;\r\n }\r\n\r\n calculateState(_target: object, currentTime: number) {\r\n if (this._frames.length === 0) {\r\n throw new Error('FixedGeometryCacheTrack.calculateState(): no frames available');\r\n }\r\n if (this._frames.length === 1 || this._times.length <= 1) {\r\n return this.copyFrameToState(this._frames[0]);\r\n }\r\n if (currentTime <= this._times[0]) {\r\n return this.copyFrameToState(this._frames[0]);\r\n }\r\n const lastIndex = this._times.length - 1;\r\n if (currentTime >= this._times[lastIndex]) {\r\n return this.copyFrameToState(this._frames[lastIndex]);\r\n }\r\n let right = 1;\r\n while (right < this._times.length && this._times[right] < currentTime) {\r\n right++;\r\n }\r\n const left = Math.max(0, right - 1);\r\n const start = this._times[left];\r\n const end = this._times[right];\r\n const t = end > start ? (currentTime - start) / (end - start) : 0;\r\n return this.interpolateFrames(this._frames[left], this._frames[right], t);\r\n }\r\n\r\n applyState(target: object, state: FixedGeometryCacheState) {\r\n const mesh = target as Mesh;\r\n const binding = this.ensureMeshBinding(mesh, state);\r\n binding.positionBuffer.bufferSubData(0, state.positions as unknown as Float32Array<ArrayBuffer>);\r\n if (binding.normalBuffer && state.normals) {\r\n binding.normalBuffer.bufferSubData(0, state.normals as unknown as Float32Array<ArrayBuffer>);\r\n }\r\n mesh.setAnimatedBoundingBox(state.boundingBox);\r\n }\r\n\r\n mixState(a: FixedGeometryCacheState, b: FixedGeometryCacheState, t: number) {\r\n if (!this._state) {\r\n throw new Error('FixedGeometryCacheTrack.mixState(): invalid state');\r\n }\r\n const positions = new Float32Array(a.positions.length);\r\n for (let i = 0; i < positions.length; i++) {\r\n positions[i] = a.positions[i] + (b.positions[i] - a.positions[i]) * t;\r\n }\r\n let normals: Nullable<Float32Array> = null;\r\n if (a.normals && b.normals && a.normals.length === b.normals.length) {\r\n normals = new Float32Array(a.normals.length);\r\n for (let i = 0; i < normals.length; i++) {\r\n normals[i] = a.normals[i] + (b.normals[i] - a.normals[i]) * t;\r\n }\r\n }\r\n return {\r\n positions,\r\n normals,\r\n boundingBox: mixGeometryCacheBoundingBox(a.boundingBox, b.boundingBox, t)\r\n };\r\n }\r\n\r\n getBlendId() {\r\n return 'fixed-geometry-cache';\r\n }\r\n\r\n getDuration() {\r\n return this._times.length > 0 ? this._times[this._times.length - 1] : 0;\r\n }\r\n\r\n reset(target: object) {\r\n if (this._frames.length > 0) {\r\n this.applyState(target, this.copyFrameToState(this._frames[0]));\r\n }\r\n }\r\n\r\n private copyFrameToState(frame: FixedGeometryCacheFrame) {\r\n if (!this._state) {\r\n this._state = createGeometryCacheState(frame);\r\n }\r\n this._state.positions.set(frame.positions);\r\n if (frame.normals) {\r\n if (!this._state.normals || this._state.normals.length !== frame.normals.length) {\r\n this._state.normals = new Float32Array(frame.normals.length);\r\n }\r\n this._state.normals.set(frame.normals);\r\n } else {\r\n this._state.normals = null;\r\n }\r\n this._state.boundingBox.minPoint.set(frame.boundingBox.minPoint);\r\n this._state.boundingBox.maxPoint.set(frame.boundingBox.maxPoint);\r\n return this._state;\r\n }\r\n\r\n private interpolateFrames(a: FixedGeometryCacheFrame, b: FixedGeometryCacheFrame, t: number) {\r\n if (!this._state) {\r\n this._state = createGeometryCacheState(a);\r\n }\r\n for (let i = 0; i < this._state.positions.length; i++) {\r\n this._state.positions[i] = a.positions[i] + (b.positions[i] - a.positions[i]) * t;\r\n }\r\n if (a.normals && b.normals && a.normals.length === b.normals.length) {\r\n if (!this._state.normals || this._state.normals.length !== a.normals.length) {\r\n this._state.normals = new Float32Array(a.normals.length);\r\n }\r\n for (let i = 0; i < this._state.normals.length; i++) {\r\n this._state.normals[i] = a.normals[i] + (b.normals[i] - a.normals[i]) * t;\r\n }\r\n } else {\r\n this._state.normals = null;\r\n }\r\n this._state.boundingBox.minPoint.setXYZ(\r\n a.boundingBox.minPoint.x + (b.boundingBox.minPoint.x - a.boundingBox.minPoint.x) * t,\r\n a.boundingBox.minPoint.y + (b.boundingBox.minPoint.y - a.boundingBox.minPoint.y) * t,\r\n a.boundingBox.minPoint.z + (b.boundingBox.minPoint.z - a.boundingBox.minPoint.z) * t\r\n );\r\n this._state.boundingBox.maxPoint.setXYZ(\r\n a.boundingBox.maxPoint.x + (b.boundingBox.maxPoint.x - a.boundingBox.maxPoint.x) * t,\r\n a.boundingBox.maxPoint.y + (b.boundingBox.maxPoint.y - a.boundingBox.maxPoint.y) * t,\r\n a.boundingBox.maxPoint.z + (b.boundingBox.maxPoint.z - a.boundingBox.maxPoint.z) * t\r\n );\r\n return this._state;\r\n }\r\n\r\n private ensureMeshBinding(mesh: Mesh, state: FixedGeometryCacheState) {\r\n return ensureGeometryCacheMeshBinding(\r\n this._meshBindings,\r\n mesh,\r\n state,\r\n 'FixedGeometryCacheTrack.applyState()'\r\n );\r\n }\r\n}\r\n"],"names":["FixedGeometryCacheTrack","AnimationTrack","_times","_frames","_state","_meshBindings","times","frames","embedded","Float32Array","length","createGeometryCacheState","WeakMap","value","calculateState","_target","currentTime","Error","copyFrameToState","lastIndex","right","left","Math","max","start","end","t","interpolateFrames","applyState","target","state","mesh","binding","ensureMeshBinding","positionBuffer","bufferSubData","positions","normalBuffer","normals","setAnimatedBoundingBox","boundingBox","mixState","a","b","i","mixGeometryCacheBoundingBox","getBlendId","getDuration","reset","frame","set","minPoint","maxPoint","setXYZ","x","y","z","ensureGeometryCacheMeshBinding"],"mappings":";;;AAiBA;;;;IAKO,MAAMA,uBAAgCC,SAAAA,cAAAA,CAAAA;IACnCC,MAAqB;IACrBC,OAAmC;IACnCC,MAA0C;IACjCC,aAAuD;AAExE,IAAA,WAAA,CAAYC,KAAoB,EAAEC,MAAkC,EAAEC,QAAkB,CAAE;AACxF,QAAA,KAAK,CAACA,QAAAA,CAAAA;AACN,QAAA,IAAI,CAACN,MAAM,GAAGI,KAAAA,IAAS,IAAIG,YAAAA,EAAAA;AAC3B,QAAA,IAAI,CAACN,OAAO,GAAGI,MAAAA,IAAU,EAAE;AAC3B,QAAA,IAAI,CAACH,MAAM,GAAG,IAAI,CAACD,OAAO,CAACO,MAAM,GAAG,CAAA,GAAIC,yBAAyB,IAAI,CAACR,OAAO,CAAC,EAAE,CAAI,GAAA,IAAA;QACpF,IAAI,CAACE,aAAa,GAAG,IAAIO,OAAAA,EAAAA;AAC3B;AAEA,IAAA,IAAIN,KAAQ,GAAA;QACV,OAAO,IAAI,CAACJ,MAAM;AACpB;IAEA,IAAII,KAAAA,CAAMO,KAAmB,EAAE;AAC7B,QAAA,IAAI,CAACX,MAAM,GAAGW,KAAAA,IAAS,IAAIJ,YAAAA,EAAAA;AAC7B;AAEA,IAAA,IAAI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AQ,CAACG,CAAC,IAAI7B,CAAAA,EACnFgB,EAAEF,WAAW,CAACY,QAAQ,CAACI,CAAC,GAAIb,CAAAA,CAAEH,CAAAA,WAAW,CAACY,QAAQ,CAACI,CAAC,GAAGd,EAAEF,WAAW,CAACY,QAAQ,CAACI,CAAC,IAAI9B,CAAAA,CAAAA;QAErF,OAAO,IAAI,CAACtB,MAAM;AACpB;IAEQ6B,iBAAkBF,CAAAA,IAAU,EAAED,KAA8B,EAAE;AACpE,QAAA,OAAO2B,+BACL,IAAI,CAACpD,aAAa,EAClB0B,MACAD,KACA,EAAA,sCAAA,CAAA;AAEJ;AACF;;;;"}
@@ -3,17 +3,29 @@ import { BoundingBox } from '../utility/bounding_volume.js';
3
3
  import { Vector3 } from '@zephyr3d/base';
4
4
 
5
5
  const geometryCacheMeshStates = new WeakMap();
6
- function createGeometryCacheState(frame) {
6
+ /**
7
+ * Creates a reusable geometry cache state buffer for a frame layout.
8
+ *
9
+ * @public
10
+ */ function createGeometryCacheState(frame) {
7
11
  return {
8
12
  positions: new Float32Array(frame.positions.length),
9
13
  normals: frame.normals ? new Float32Array(frame.normals.length) : null,
10
14
  boundingBox: new BoundingBox()
11
15
  };
12
16
  }
13
- function mixGeometryCacheBoundingBox(a, b, t) {
17
+ /**
18
+ * Linearly interpolates two geometry-cache bounding boxes.
19
+ *
20
+ * @public
21
+ */ function mixGeometryCacheBoundingBox(a, b, t) {
14
22
  return new BoundingBox(new Vector3(a.minPoint.x + (b.minPoint.x - a.minPoint.x) * t, a.minPoint.y + (b.minPoint.y - a.minPoint.y) * t, a.minPoint.z + (b.minPoint.z - a.minPoint.z) * t), new Vector3(a.maxPoint.x + (b.maxPoint.x - a.maxPoint.x) * t, a.maxPoint.y + (b.maxPoint.y - a.maxPoint.y) * t, a.maxPoint.z + (b.maxPoint.z - a.maxPoint.z) * t));
15
23
  }
16
- function ensureGeometryCacheMeshBinding(meshBindings, mesh, state, errorPrefix) {
24
+ /**
25
+ * Ensures the target mesh has GPU buffers compatible with the geometry cache state.
26
+ *
27
+ * @public
28
+ */ function ensureGeometryCacheMeshBinding(meshBindings, mesh, state, errorPrefix) {
17
29
  let binding = meshBindings.get(mesh);
18
30
  if (!binding) {
19
31
  const primitive = mesh.primitive;
@@ -38,7 +50,11 @@ function ensureGeometryCacheMeshBinding(meshBindings, mesh, state, errorPrefix)
38
50
  }
39
51
  return binding;
40
52
  }
41
- async function restoreGeometryCacheMeshBinding(mesh) {
53
+ /**
54
+ * Restores a mesh primitive after geometry cache playback.
55
+ *
56
+ * @public
57
+ */ async function restoreGeometryCacheMeshBinding(mesh) {
42
58
  const meshState = geometryCacheMeshStates.get(mesh);
43
59
  if (!meshState) {
44
60
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"geometry_cache_utils.js","sources":["../../src/animation/geometry_cache_utils.ts"],"sourcesContent":["import { getDevice, getEngine } from '../app/api';\r\nimport type { Mesh } from '../scene';\r\nimport type { Primitive } from '../render/primitive';\r\nimport { BoundingBox } from '../utility/bounding_volume';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport { Vector3 } from '@zephyr3d/base';\r\nimport type { StructuredBuffer } from '@zephyr3d/device';\r\n\r\nexport type GeometryCacheFrame = {\r\n positions: Float32Array;\r\n normals?: Nullable<Float32Array>;\r\n boundingBox: BoundingBox;\r\n};\r\n\r\nexport type GeometryCacheState = {\r\n positions: Float32Array;\r\n normals?: Nullable<Float32Array>;\r\n boundingBox: BoundingBox;\r\n};\r\n\r\nexport type GeometryCacheMeshBinding = {\r\n originalPrimitive: Primitive;\r\n primitive: Primitive;\r\n positionBuffer: StructuredBuffer;\r\n normalBuffer: Nullable<StructuredBuffer>;\r\n};\r\n\r\ntype GeometryCacheMeshState = {\r\n originalPrimitive: Primitive;\r\n originalPrimitiveAssetId: string;\r\n cachePrimitive: Primitive;\r\n positionBuffer: StructuredBuffer;\r\n normalBuffer: Nullable<StructuredBuffer>;\r\n};\r\n\r\nconst geometryCacheMeshStates = new WeakMap<Mesh, GeometryCacheMeshState>();\r\n\r\nexport function createGeometryCacheState(\r\n frame: Pick<GeometryCacheFrame, 'positions' | 'normals'>\r\n): GeometryCacheState {\r\n return {\r\n positions: new Float32Array(frame.positions.length),\r\n normals: frame.normals ? new Float32Array(frame.normals.length) : null,\r\n boundingBox: new BoundingBox()\r\n };\r\n}\r\n\r\nexport function mixGeometryCacheBoundingBox(a: BoundingBox, b: BoundingBox, t: number) {\r\n return new BoundingBox(\r\n new Vector3(\r\n a.minPoint.x + (b.minPoint.x - a.minPoint.x) * t,\r\n a.minPoint.y + (b.minPoint.y - a.minPoint.y) * t,\r\n a.minPoint.z + (b.minPoint.z - a.minPoint.z) * t\r\n ),\r\n new Vector3(\r\n a.maxPoint.x + (b.maxPoint.x - a.maxPoint.x) * t,\r\n a.maxPoint.y + (b.maxPoint.y - a.maxPoint.y) * t,\r\n a.maxPoint.z + (b.maxPoint.z - a.maxPoint.z) * t\r\n )\r\n );\r\n}\r\n\r\nexport function ensureGeometryCacheMeshBinding(\r\n meshBindings: WeakMap<Mesh, GeometryCacheMeshBinding>,\r\n mesh: Mesh,\r\n state: GeometryCacheState,\r\n errorPrefix: string\r\n) {\r\n let binding = meshBindings.get(mesh);\r\n if (!binding) {\r\n const primitive = mesh.primitive;\r\n const meshState = geometryCacheMeshStates.get(mesh);\r\n const originalPrimitive = meshState?.originalPrimitive ?? primitive;\r\n if (!originalPrimitive) {\r\n throw new Error(`${errorPrefix}: target mesh has no primitive`);\r\n }\r\n validateGeometryCacheState(originalPrimitive, state, errorPrefix);\r\n const ensuredState = meshState\r\n ? ensureGeometryCacheNormalBuffer(meshState, originalPrimitive, state, errorPrefix)\r\n : createGeometryCacheMeshState(originalPrimitive, state);\r\n geometryCacheMeshStates.set(mesh, ensuredState);\r\n if (mesh.primitive !== ensuredState.cachePrimitive) {\r\n mesh.primitive = ensuredState.cachePrimitive;\r\n }\r\n binding = {\r\n originalPrimitive,\r\n primitive: ensuredState.cachePrimitive,\r\n positionBuffer: ensuredState.positionBuffer,\r\n normalBuffer: ensuredState.normalBuffer\r\n };\r\n meshBindings.set(mesh, binding);\r\n }\r\n return binding;\r\n}\r\n\r\nexport async function restoreGeometryCacheMeshBinding(mesh: Mesh) {\r\n const meshState = geometryCacheMeshStates.get(mesh);\r\n if (!meshState) {\r\n return false;\r\n }\r\n const primitiveToRestore = await resolveOriginalPrimitive(meshState);\r\n if (mesh.primitive === meshState.cachePrimitive) {\r\n mesh.primitive = primitiveToRestore;\r\n }\r\n mesh.setAnimatedBoundingBox(null);\r\n mesh.scene?.queueUpdateNode(mesh);\r\n geometryCacheMeshStates.delete(mesh);\r\n return true;\r\n}\r\n\r\nfunction validateGeometryCacheState(primitive: Primitive, state: GeometryCacheState, errorPrefix: string) {\r\n const expectedPositionLength = primitive.getNumVertices() * 3;\r\n if (state.positions.length !== expectedPositionLength) {\r\n throw new Error(\r\n `${errorPrefix}: position count mismatch, expected ${expectedPositionLength}, got ${state.positions.length}`\r\n );\r\n }\r\n if (state.normals) {\r\n const expectedNormalLength = primitive.getNumVertices() * 3;\r\n if (state.normals.length !== expectedNormalLength) {\r\n throw new Error(\r\n `${errorPrefix}: normal count mismatch, expected ${expectedNormalLength}, got ${state.normals.length}`\r\n );\r\n }\r\n }\r\n}\r\n\r\nfunction createGeometryCacheMeshState(\r\n originalPrimitive: Primitive,\r\n state: GeometryCacheState\r\n): GeometryCacheMeshState {\r\n const cachePrimitive = originalPrimitive.clone();\r\n cachePrimitive.setBoundingVolume(originalPrimitive.getBoundingVolume()!);\r\n const primitiveAssetId = getEngine().resourceManager.getAssetId(originalPrimitive);\r\n if (primitiveAssetId) {\r\n getEngine().resourceManager.setAssetId(cachePrimitive, primitiveAssetId);\r\n }\r\n cachePrimitive.removeVertexBuffer('position');\r\n const positionBuffer = getDevice().createVertexBuffer(\r\n 'position_f32x3',\r\n state.positions as unknown as Float32Array<ArrayBuffer>,\r\n {\r\n dynamic: true\r\n }\r\n )!;\r\n cachePrimitive.setVertexBuffer(positionBuffer);\r\n let normalBuffer: Nullable<StructuredBuffer> = null;\r\n if (state.normals) {\r\n cachePrimitive.removeVertexBuffer('normal');\r\n normalBuffer = getDevice().createVertexBuffer(\r\n 'normal_f32x3',\r\n state.normals as unknown as Float32Array<ArrayBuffer>,\r\n {\r\n dynamic: true\r\n }\r\n )!;\r\n cachePrimitive.setVertexBuffer(normalBuffer);\r\n }\r\n return {\r\n originalPrimitive,\r\n originalPrimitiveAssetId: primitiveAssetId ?? '',\r\n cachePrimitive,\r\n positionBuffer,\r\n normalBuffer\r\n };\r\n}\r\n\r\nfunction ensureGeometryCacheNormalBuffer(\r\n meshState: GeometryCacheMeshState,\r\n originalPrimitive: Primitive,\r\n state: GeometryCacheState,\r\n errorPrefix: string\r\n) {\r\n if (state.normals && !meshState.normalBuffer) {\r\n const expectedNormalLength = originalPrimitive.getNumVertices() * 3;\r\n if (state.normals.length !== expectedNormalLength) {\r\n throw new Error(\r\n `${errorPrefix}: normal count mismatch, expected ${expectedNormalLength}, got ${state.normals.length}`\r\n );\r\n }\r\n meshState.cachePrimitive.removeVertexBuffer('normal');\r\n meshState.normalBuffer = getDevice().createVertexBuffer(\r\n 'normal_f32x3',\r\n state.normals as unknown as Float32Array<ArrayBuffer>,\r\n {\r\n dynamic: true\r\n }\r\n )!;\r\n meshState.cachePrimitive.setVertexBuffer(meshState.normalBuffer);\r\n }\r\n return meshState;\r\n}\r\n\r\nasync function resolveOriginalPrimitive(meshState: GeometryCacheMeshState) {\r\n if (meshState.originalPrimitiveAssetId) {\r\n const restoredPrimitive = await getEngine().resourceManager.fetchPrimitive(\r\n meshState.originalPrimitiveAssetId\r\n );\r\n if (restoredPrimitive) {\r\n return restoredPrimitive;\r\n }\r\n }\r\n return meshState.originalPrimitive;\r\n}\r\n"],"names":["geometryCacheMeshStates","WeakMap","createGeometryCacheState","frame","positions","Float32Array","length","normals","boundingBox","BoundingBox","mixGeometryCacheBoundingBox","a","b","t","Vector3","minPoint","x","y","z","maxPoint","ensureGeometryCacheMeshBinding","meshBindings","mesh","state","errorPrefix","binding","get","primitive","meshState","originalPrimitive","Error","validateGeometryCacheState","ensuredState","ensureGeometryCacheNormalBuffer","createGeometryCacheMeshState","set","cachePrimitive","positionBuffer","normalBuffer","restoreGeometryCacheMeshBinding","primitiveToRestore","resolveOriginalPrimitive","setAnimatedBoundingBox","scene","queueUpdateNode","delete","expectedPositionLength","getNumVertices","expectedNormalLength","clone","setBoundingVolume","getBoundingVolume","primitiveAssetId","getEngine","resourceManager","getAssetId","setAssetId","removeVertexBuffer","getDevice","createVertexBuffer","dynamic","setVertexBuffer","originalPrimitiveAssetId","restoredPrimitive","fetchPrimitive"],"mappings":";;;;AAmCA,MAAMA,0BAA0B,IAAIC,OAAAA,EAAAA;AAE7B,SAASC,yBACdC,KAAwD,EAAA;IAExD,OAAO;AACLC,QAAAA,SAAAA,EAAW,IAAIC,YAAAA,CAAaF,KAAMC,CAAAA,SAAS,CAACE,MAAM,CAAA;QAClDC,OAASJ,EAAAA,KAAAA,CAAMI,OAAO,GAAG,IAAIF,aAAaF,KAAMI,CAAAA,OAAO,CAACD,MAAM,CAAI,GAAA,IAAA;AAClEE,QAAAA,WAAAA,EAAa,IAAIC,WAAAA;AACnB,KAAA;AACF;AAEO,SAASC,2BAA4BC,CAAAA,CAAc,EAAEC,CAAc,EAAEC,CAAS,EAAA;IACnF,OAAO,IAAIJ,WACT,CAAA,IAAIK,OACFH,CAAAA,CAAAA,CAAEI,QAAQ,CAACC,CAAC,GAAG,CAACJ,CAAEG,CAAAA,QAAQ,CAACC,CAAC,GAAGL,CAAEI,CAAAA,QAAQ,CAACC,CAAC,IAAIH,CAC/CF,EAAAA,CAAAA,CAAEI,QAAQ,CAACE,CAAC,GAAG,CAACL,CAAAA,CAAEG,QAAQ,CAACE,CAAC,GAAGN,CAAEI,CAAAA,QAAQ,CAACE,CAAC,IAAIJ,CAC/CF,EAAAA,CAAAA,CAAEI,QAAQ,CAACG,CAAC,GAAG,CAACN,CAAEG,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D,OAAS,EAAA;AACX,SAAA,CAAA;AAEFhC,QAAAA,SAAAA,CAAUQ,cAAc,CAACyB,eAAe,CAACjC,UAAUU,YAAY,CAAA;AACjE;IACA,OAAOV,SAAAA;AACT;AAEA,eAAea,yBAAyBb,SAAiC,EAAA;IACvE,IAAIA,SAAAA,CAAUkC,wBAAwB,EAAE;QACtC,MAAMC,iBAAAA,GAAoB,MAAMV,SAAYC,EAAAA,CAAAA,eAAe,CAACU,cAAc,CACxEpC,UAAUkC,wBAAwB,CAAA;AAEpC,QAAA,IAAIC,iBAAmB,EAAA;YACrB,OAAOA,iBAAAA;AACT;AACF;AACA,IAAA,OAAOnC,UAAUC,iBAAiB;AACpC;;;;"}
1
+ {"version":3,"file":"geometry_cache_utils.js","sources":["../../src/animation/geometry_cache_utils.ts"],"sourcesContent":["import { getDevice, getEngine } from '../app/api';\r\nimport type { Mesh } from '../scene';\r\nimport type { Primitive } from '../render/primitive';\r\nimport { BoundingBox } from '../utility/bounding_volume';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport { Vector3 } from '@zephyr3d/base';\r\nimport type { StructuredBuffer } from '@zephyr3d/device';\r\n\r\n/**\r\n * Geometry cache frame data for a single sampled time.\r\n *\r\n * @public\r\n */\r\nexport type GeometryCacheFrame = {\r\n positions: Float32Array;\r\n normals?: Nullable<Float32Array>;\r\n boundingBox: BoundingBox;\r\n};\r\n\r\n/**\r\n * Mutable working state used while evaluating geometry cache tracks.\r\n *\r\n * @public\r\n */\r\nexport type GeometryCacheState = {\r\n positions: Float32Array;\r\n normals?: Nullable<Float32Array>;\r\n boundingBox: BoundingBox;\r\n};\r\n\r\n/**\r\n * GPU resources bound to a mesh while a geometry cache track is active.\r\n *\r\n * @public\r\n */\r\nexport type GeometryCacheMeshBinding = {\r\n originalPrimitive: Primitive;\r\n primitive: Primitive;\r\n positionBuffer: StructuredBuffer;\r\n normalBuffer: Nullable<StructuredBuffer>;\r\n};\r\n\r\ntype GeometryCacheMeshState = {\r\n originalPrimitive: Primitive;\r\n originalPrimitiveAssetId: string;\r\n cachePrimitive: Primitive;\r\n positionBuffer: StructuredBuffer;\r\n normalBuffer: Nullable<StructuredBuffer>;\r\n};\r\n\r\nconst geometryCacheMeshStates = new WeakMap<Mesh, GeometryCacheMeshState>();\r\n\r\n/**\r\n * Creates a reusable geometry cache state buffer for a frame layout.\r\n *\r\n * @public\r\n */\r\nexport function createGeometryCacheState(\r\n frame: Pick<GeometryCacheFrame, 'positions' | 'normals'>\r\n): GeometryCacheState {\r\n return {\r\n positions: new Float32Array(frame.positions.length),\r\n normals: frame.normals ? new Float32Array(frame.normals.length) : null,\r\n boundingBox: new BoundingBox()\r\n };\r\n}\r\n\r\n/**\r\n * Linearly interpolates two geometry-cache bounding boxes.\r\n *\r\n * @public\r\n */\r\nexport function mixGeometryCacheBoundingBox(a: BoundingBox, b: BoundingBox, t: number) {\r\n return new BoundingBox(\r\n new Vector3(\r\n a.minPoint.x + (b.minPoint.x - a.minPoint.x) * t,\r\n a.minPoint.y + (b.minPoint.y - a.minPoint.y) * t,\r\n a.minPoint.z + (b.minPoint.z - a.minPoint.z) * t\r\n ),\r\n new Vector3(\r\n a.maxPoint.x + (b.maxPoint.x - a.maxPoint.x) * t,\r\n a.maxPoint.y + (b.maxPoint.y - a.maxPoint.y) * t,\r\n a.maxPoint.z + (b.maxPoint.z - a.maxPoint.z) * t\r\n )\r\n );\r\n}\r\n\r\n/**\r\n * Ensures the target mesh has GPU buffers compatible with the geometry cache state.\r\n *\r\n * @public\r\n */\r\nexport function ensureGeometryCacheMeshBinding(\r\n meshBindings: WeakMap<Mesh, GeometryCacheMeshBinding>,\r\n mesh: Mesh,\r\n state: GeometryCacheState,\r\n errorPrefix: string\r\n) {\r\n let binding = meshBindings.get(mesh);\r\n if (!binding) {\r\n const primitive = mesh.primitive;\r\n const meshState = geometryCacheMeshStates.get(mesh);\r\n const originalPrimitive = meshState?.originalPrimitive ?? primitive;\r\n if (!originalPrimitive) {\r\n throw new Error(`${errorPrefix}: target mesh has no primitive`);\r\n }\r\n validateGeometryCacheState(originalPrimitive, state, errorPrefix);\r\n const ensuredState = meshState\r\n ? ensureGeometryCacheNormalBuffer(meshState, originalPrimitive, state, errorPrefix)\r\n : createGeometryCacheMeshState(originalPrimitive, state);\r\n geometryCacheMeshStates.set(mesh, ensuredState);\r\n if (mesh.primitive !== ensuredState.cachePrimitive) {\r\n mesh.primitive = ensuredState.cachePrimitive;\r\n }\r\n binding = {\r\n originalPrimitive,\r\n primitive: ensuredState.cachePrimitive,\r\n positionBuffer: ensuredState.positionBuffer,\r\n normalBuffer: ensuredState.normalBuffer\r\n };\r\n meshBindings.set(mesh, binding);\r\n }\r\n return binding;\r\n}\r\n\r\n/**\r\n * Restores a mesh primitive after geometry cache playback.\r\n *\r\n * @public\r\n */\r\nexport async function restoreGeometryCacheMeshBinding(mesh: Mesh) {\r\n const meshState = geometryCacheMeshStates.get(mesh);\r\n if (!meshState) {\r\n return false;\r\n }\r\n const primitiveToRestore = await resolveOriginalPrimitive(meshState);\r\n if (mesh.primitive === meshState.cachePrimitive) {\r\n mesh.primitive = primitiveToRestore;\r\n }\r\n mesh.setAnimatedBoundingBox(null);\r\n mesh.scene?.queueUpdateNode(mesh);\r\n geometryCacheMeshStates.delete(mesh);\r\n return true;\r\n}\r\n\r\nfunction validateGeometryCacheState(primitive: Primitive, state: GeometryCacheState, errorPrefix: string) {\r\n const expectedPositionLength = primitive.getNumVertices() * 3;\r\n if (state.positions.length !== expectedPositionLength) {\r\n throw new Error(\r\n `${errorPrefix}: position count mismatch, expected ${expectedPositionLength}, got ${state.positions.length}`\r\n );\r\n }\r\n if (state.normals) {\r\n const expectedNormalLength = primitive.getNumVertices() * 3;\r\n if (state.normals.length !== expectedNormalLength) {\r\n throw new Error(\r\n `${errorPrefix}: normal count mismatch, expected ${expectedNormalLength}, got ${state.normals.length}`\r\n );\r\n }\r\n }\r\n}\r\n\r\nfunction createGeometryCacheMeshState(\r\n originalPrimitive: Primitive,\r\n state: GeometryCacheState\r\n): GeometryCacheMeshState {\r\n const cachePrimitive = originalPrimitive.clone();\r\n cachePrimitive.setBoundingVolume(originalPrimitive.getBoundingVolume()!);\r\n const primitiveAssetId = getEngine().resourceManager.getAssetId(originalPrimitive);\r\n if (primitiveAssetId) {\r\n getEngine().resourceManager.setAssetId(cachePrimitive, primitiveAssetId);\r\n }\r\n cachePrimitive.removeVertexBuffer('position');\r\n const positionBuffer = getDevice().createVertexBuffer(\r\n 'position_f32x3',\r\n state.positions as unknown as Float32Array<ArrayBuffer>,\r\n {\r\n dynamic: true\r\n }\r\n )!;\r\n cachePrimitive.setVertexBuffer(positionBuffer);\r\n let normalBuffer: Nullable<StructuredBuffer> = null;\r\n if (state.normals) {\r\n cachePrimitive.removeVertexBuffer('normal');\r\n normalBuffer = getDevice().createVertexBuffer(\r\n 'normal_f32x3',\r\n state.normals as unknown as Float32Array<ArrayBuffer>,\r\n {\r\n dynamic: true\r\n }\r\n )!;\r\n cachePrimitive.setVertexBuffer(normalBuffer);\r\n }\r\n return {\r\n originalPrimitive,\r\n originalPrimitiveAssetId: primitiveAssetId ?? '',\r\n cachePrimitive,\r\n positionBuffer,\r\n normalBuffer\r\n };\r\n}\r\n\r\nfunction ensureGeometryCacheNormalBuffer(\r\n meshState: GeometryCacheMeshState,\r\n originalPrimitive: Primitive,\r\n state: GeometryCacheState,\r\n errorPrefix: string\r\n) {\r\n if (state.normals && !meshState.normalBuffer) {\r\n const expectedNormalLength = originalPrimitive.getNumVertices() * 3;\r\n if (state.normals.length !== expectedNormalLength) {\r\n throw new Error(\r\n `${errorPrefix}: normal count mismatch, expected ${expectedNormalLength}, got ${state.normals.length}`\r\n );\r\n }\r\n meshState.cachePrimitive.removeVertexBuffer('normal');\r\n meshState.normalBuffer = getDevice().createVertexBuffer(\r\n 'normal_f32x3',\r\n state.normals as unknown as Float32Array<ArrayBuffer>,\r\n {\r\n dynamic: true\r\n }\r\n )!;\r\n meshState.cachePrimitive.setVertexBuffer(meshState.normalBuffer);\r\n }\r\n return meshState;\r\n}\r\n\r\nasync function resolveOriginalPrimitive(meshState: GeometryCacheMeshState) {\r\n if (meshState.originalPrimitiveAssetId) {\r\n const restoredPrimitive = await getEngine().resourceManager.fetchPrimitive(\r\n meshState.originalPrimitiveAssetId\r\n );\r\n if (restoredPrimitive) {\r\n return restoredPrimitive;\r\n }\r\n }\r\n return meshState.originalPrimitive;\r\n}\r\n"],"names":["geometryCacheMeshStates","WeakMap","createGeometryCacheState","frame","positions","Float32Array","length","normals","boundingBox","BoundingBox","mixGeometryCacheBoundingBox","a","b","t","Vector3","minPoint","x","y","z","maxPoint","ensureGeometryCacheMeshBinding","meshBindings","mesh","state","errorPrefix","binding","get","primitive","meshState","originalPrimitive","Error","validateGeometryCacheState","ensuredState","ensureGeometryCacheNormalBuffer","createGeometryCacheMeshState","set","cachePrimitive","positionBuffer","normalBuffer","restoreGeometryCacheMeshBinding","primitiveToRestore","resolveOriginalPrimitive","setAnimatedBoundingBox","scene","queueUpdateNode","delete","expectedPositionLength","getNumVertices","expectedNormalLength","clone","setBoundingVolume","getBoundingVolume","primitiveAssetId","getEngine","resourceManager","getAssetId","setAssetId","removeVertexBuffer","getDevice","createVertexBuffer","dynamic","setVertexBuffer","originalPrimitiveAssetId","restoredPrimitive","fetchPrimitive"],"mappings":";;;;AAkDA,MAAMA,0BAA0B,IAAIC,OAAAA,EAAAA;AAEpC;;;;IAKO,SAASC,wBAAAA,CACdC,KAAwD,EAAA;IAExD,OAAO;AACLC,QAAAA,SAAAA,EAAW,IAAIC,YAAAA,CAAaF,KAAMC,CAAAA,SAAS,CAACE,MAAM,CAAA;QAClDC,OAASJ,EAAAA,KAAAA,CAAMI,OAAO,GAAG,IAAIF,aAAaF,KAAMI,CAAAA,OAAO,CAACD,MAAM,CAAI,GAAA,IAAA;AAClEE,QAAAA,WAAAA,EAAa,IAAIC,WAAAA;AACnB,KAAA;AACF;AAEA;;;;AAIC,IACM,SAASC,2BAAAA,CAA4B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AkBkB,CAAAA,cAAc,EAAK,GAAA,CAAA;AAClE,QAAA,IAAIxB,KAAMhB,CAAAA,OAAO,CAACD,MAAM,KAAK0C,oBAAsB,EAAA;AACjD,YAAA,MAAM,IAAIlB,KAAAA,CACR,CAAGN,EAAAA,WAAAA,CAAY,kCAAkC,EAAEwB,oBAAqB,CAAA,MAAM,EAAEzB,KAAAA,CAAMhB,OAAO,CAACD,MAAM,CAAE,CAAA,CAAA;AAE1G;QACAsB,SAAUQ,CAAAA,cAAc,CAACqB,kBAAkB,CAAC,QAAA,CAAA;QAC5C7B,SAAUU,CAAAA,YAAY,GAAGoB,SAAYC,EAAAA,CAAAA,kBAAkB,CACrD,cACApC,EAAAA,KAAAA,CAAMhB,OAAO,EACb;YACEqD,OAAS,EAAA;AACX,SAAA,CAAA;AAEFhC,QAAAA,SAAAA,CAAUQ,cAAc,CAACyB,eAAe,CAACjC,UAAUU,YAAY,CAAA;AACjE;IACA,OAAOV,SAAAA;AACT;AAEA,eAAea,yBAAyBb,SAAiC,EAAA;IACvE,IAAIA,SAAAA,CAAUkC,wBAAwB,EAAE;QACtC,MAAMC,iBAAAA,GAAoB,MAAMV,SAAYC,EAAAA,CAAAA,eAAe,CAACU,cAAc,CACxEpC,UAAUkC,wBAAwB,CAAA;AAEpC,QAAA,IAAIC,iBAAmB,EAAA;YACrB,OAAOA,iBAAAA;AACT;AACF;AACA,IAAA,OAAOnC,UAAUC,iBAAiB;AACpC;;;;"}
@@ -34,9 +34,7 @@ import { IKConstraint } from './ik_constraint.js';
34
34
  */ get minAngle() {
35
35
  return this._minAngle;
36
36
  }
37
- /**
38
- * Set the minimum angle in degrees.
39
- */ set minAngle(value) {
37
+ set minAngle(value) {
40
38
  this._minAngle = Math.max(0, Math.min(value, this._maxAngle));
41
39
  }
42
40
  /**
@@ -44,9 +42,7 @@ import { IKConstraint } from './ik_constraint.js';
44
42
  */ get maxAngle() {
45
43
  return this._maxAngle;
46
44
  }
47
- /**
48
- * Set the maximum angle in degrees.
49
- */ set maxAngle(value) {
45
+ set maxAngle(value) {
50
46
  this._maxAngle = Math.min(180, Math.max(value, this._minAngle));
51
47
  }
52
48
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ik_angle_constraint.js","sources":["../../../src/animation/ik/ik_angle_constraint.ts"],"sourcesContent":["import { Vector3 } from '@zephyr3d/base';\r\nimport { IKConstraint } from './ik_constraint';\r\nimport type { IKJoint } from './ik_joint';\r\n\r\n/**\r\n * Angle constraint for IK joints.\r\n *\r\n * Limits the angle between the bone from parent to this joint\r\n * and the bone from this joint to child.\r\n *\r\n * @remarks\r\n * This is useful for joints like elbows and knees that have\r\n * limited range of motion.\r\n *\r\n * @public\r\n */\r\nexport class IKAngleConstraint extends IKConstraint {\r\n /** Minimum angle in degrees */\r\n private _minAngle: number;\r\n /** Maximum angle in degrees */\r\n private _maxAngle: number;\r\n\r\n /**\r\n * Create an angle constraint.\r\n *\r\n * @param jointIndex - Index of the joint in the chain\r\n * @param minAngle - Minimum angle in degrees (0 = straight)\r\n * @param maxAngle - Maximum angle in degrees (180 = fully bent)\r\n */\r\n constructor(jointIndex: number, minAngle: number, maxAngle: number) {\r\n super(jointIndex);\r\n this._minAngle = Math.max(0, minAngle);\r\n this._maxAngle = Math.min(180, maxAngle);\r\n\r\n if (this._minAngle > this._maxAngle) {\r\n throw new Error('IKAngleConstraint: minAngle must be <= maxAngle');\r\n }\r\n }\r\n\r\n /**\r\n * Get the minimum angle in degrees.\r\n */\r\n get minAngle(): number {\r\n return this._minAngle;\r\n }\r\n\r\n /**\r\n * Set the minimum angle in degrees.\r\n */\r\n set minAngle(value: number) {\r\n this._minAngle = Math.max(0, Math.min(value, this._maxAngle));\r\n }\r\n\r\n /**\r\n * Get the maximum angle in degrees.\r\n */\r\n get maxAngle(): number {\r\n return this._maxAngle;\r\n }\r\n\r\n /**\r\n * Set the maximum angle in degrees.\r\n */\r\n set maxAngle(value: number) {\r\n this._maxAngle = Math.min(180, Math.max(value, this._minAngle));\r\n }\r\n\r\n /**\r\n * Apply the angle constraint to limit joint bending.\r\n */\r\n apply(joints: IKJoint[]): void {\r\n const index = this._jointIndex;\r\n\r\n // For end effector (last joint), we constrain the angle between the last two bones\r\n // For other joints, we constrain the angle at the joint itself\r\n if (index === joints.length - 1) {\r\n // End effector: constrain angle between (parent-1 -> parent) and (parent -> this)\r\n if (index < 2) {\r\n return; // Need at least 3 joints total\r\n }\r\n this._applyEndEffectorConstraint(joints, index);\r\n } else {\r\n // Regular joint: constrain angle between (parent -> this) and (this -> child)\r\n if (index < 1) {\r\n return; // Root joint cannot be constrained this way\r\n }\r\n this._applyRegularConstraint(joints, index);\r\n }\r\n }\r\n\r\n /**\r\n * Apply constraint to end effector joint.\r\n */\r\n private _applyEndEffectorConstraint(joints: IKJoint[], index: number): void {\r\n const grandParentJoint = joints[index - 2];\r\n const parentJoint = joints[index - 1];\r\n const currentJoint = joints[index];\r\n\r\n // Calculate bone vectors\r\n const incomingBone = Vector3.sub(parentJoint.position, grandParentJoint.position, new Vector3());\r\n const outgoingBone = Vector3.sub(currentJoint.position, parentJoint.position, new Vector3());\r\n\r\n const incomingLen = incomingBone.magnitude;\r\n const outgoingLen = outgoingBone.magnitude;\r\n\r\n if (incomingLen < 0.000001 || outgoingLen < 0.000001) {\r\n return;\r\n }\r\n\r\n // Normalize\r\n const incomingNorm = Vector3.scale(incomingBone, 1 / incomingLen, new Vector3());\r\n const outgoingNorm = Vector3.scale(outgoingBone, 1 / outgoingLen, new Vector3());\r\n\r\n // Calculate current angle\r\n const dot = Vector3.dot(incomingNorm, outgoingNorm);\r\n const currentAngleDeg = Math.acos(Math.max(-1, Math.min(1, dot))) * (180 / Math.PI);\r\n\r\n // Check if constraint is violated\r\n let targetAngleDeg = currentAngleDeg;\r\n if (currentAngleDeg < this._minAngle) {\r\n targetAngleDeg = this._minAngle;\r\n } else if (currentAngleDeg > this._maxAngle) {\r\n targetAngleDeg = this._maxAngle;\r\n } else {\r\n return;\r\n }\r\n\r\n // Apply the same constraint logic as regular joints\r\n this._adjustJointAngle(\r\n incomingNorm,\r\n outgoingNorm,\r\n currentAngleDeg,\r\n targetAngleDeg,\r\n parentJoint,\r\n currentJoint\r\n );\r\n }\r\n\r\n /**\r\n * Apply constraint to regular joint.\r\n */\r\n private _applyRegularConstraint(joints: IKJoint[], index: number): void {\r\n const parentJoint = joints[index - 1];\r\n const currentJoint = joints[index];\r\n const childJoint = joints[index + 1];\r\n\r\n // Calculate bone vectors: incoming bone (parent->current) and outgoing bone (current->child)\r\n const incomingBone = Vector3.sub(currentJoint.position, parentJoint.position, new Vector3());\r\n const outgoingBone = Vector3.sub(childJoint.position, currentJoint.position, new Vector3());\r\n\r\n const incomingLen = incomingBone.magnitude;\r\n const outgoingLen = outgoingBone.magnitude;\r\n\r\n if (incomingLen < 0.000001 || outgoingLen < 0.000001) {\r\n return;\r\n }\r\n\r\n // Normalize\r\n const incomingNorm = Vector3.scale(incomingBone, 1 / incomingLen, new Vector3());\r\n const outgoingNorm = Vector3.scale(outgoingBone, 1 / outgoingLen, new Vector3());\r\n\r\n // Calculate current angle between incoming and outgoing bones (interior angle)\r\n const dot = Vector3.dot(incomingNorm, outgoingNorm);\r\n const currentAngleDeg = Math.acos(Math.max(-1, Math.min(1, dot))) * (180 / Math.PI);\r\n\r\n // Check if constraint is violated\r\n let targetAngleDeg = currentAngleDeg;\r\n if (currentAngleDeg < this._minAngle) {\r\n targetAngleDeg = this._minAngle;\r\n } else if (currentAngleDeg > this._maxAngle) {\r\n targetAngleDeg = this._maxAngle;\r\n } else {\r\n return;\r\n }\r\n\r\n // Apply the constraint\r\n this._adjustJointAngle(\r\n incomingNorm,\r\n outgoingNorm,\r\n currentAngleDeg,\r\n targetAngleDeg,\r\n currentJoint,\r\n childJoint\r\n );\r\n }\r\n\r\n /**\r\n * Adjust joint angle by rotating the outgoing bone.\r\n */\r\n private _adjustJointAngle(\r\n incomingNorm: Vector3,\r\n outgoingNorm: Vector3,\r\n currentAngleDeg: number,\r\n targetAngleDeg: number,\r\n pivotJoint: IKJoint,\r\n targetJoint: IKJoint\r\n ): void {\r\n // Add a dead zone to prevent oscillation\r\n const angleDifference = Math.abs(targetAngleDeg - currentAngleDeg);\r\n const isHardConstraint = Math.abs(this._maxAngle - this._minAngle) < 0.01;\r\n const deadZone = isHardConstraint ? 0.2 : 0.1;\r\n\r\n if (angleDifference < deadZone) {\r\n return; // Too close to target, avoid over-correction\r\n }\r\n\r\n // Calculate rotation axis (perpendicular to both bone vectors)\r\n const axis = Vector3.cross(incomingNorm, outgoingNorm, new Vector3());\r\n const axisLen = axis.magnitude;\r\n\r\n // Use a smaller threshold to allow constraint to work at small angles\r\n if (axisLen < 0.0001) {\r\n return; // Vectors are too close to parallel or anti-parallel\r\n }\r\n\r\n axis.scaleBy(1 / axisLen);\r\n\r\n // Calculate the angle we need to rotate\r\n const targetAngleRad = targetAngleDeg * (Math.PI / 180);\r\n const currentAngleRad = currentAngleDeg * (Math.PI / 180);\r\n let deltaAngle = targetAngleRad - currentAngleRad;\r\n\r\n // Apply full correction without damping to ensure constraints are enforced\r\n // This is necessary because FABRIK will try to undo the constraint in the next iteration\r\n // So we need strong constraint enforcement\r\n\r\n // Rotate the outgoing bone vector around the axis by deltaAngle\r\n const cos = Math.cos(deltaAngle);\r\n const sin = Math.sin(deltaAngle);\r\n const oneMinusCos = 1 - cos;\r\n\r\n // Rodrigues' rotation formula\r\n const rotated = new Vector3();\r\n rotated.x =\r\n outgoingNorm.x * (cos + axis.x * axis.x * oneMinusCos) +\r\n outgoingNorm.y * (axis.x * axis.y * oneMinusCos - axis.z * sin) +\r\n outgoingNorm.z * (axis.x * axis.z * oneMinusCos + axis.y * sin);\r\n\r\n rotated.y =\r\n outgoingNorm.x * (axis.y * axis.x * oneMinusCos + axis.z * sin) +\r\n outgoingNorm.y * (cos + axis.y * axis.y * oneMinusCos) +\r\n outgoingNorm.z * (axis.y * axis.z * oneMinusCos - axis.x * sin);\r\n\r\n rotated.z =\r\n outgoingNorm.x * (axis.z * axis.x * oneMinusCos - axis.y * sin) +\r\n outgoingNorm.y * (axis.z * axis.y * oneMinusCos + axis.x * sin) +\r\n outgoingNorm.z * (cos + axis.z * axis.z * oneMinusCos);\r\n\r\n // Update target joint position using the rotated bone vector\r\n const boneLength = pivotJoint.boneLength;\r\n rotated.scaleBy(boneLength);\r\n Vector3.add(pivotJoint.position, rotated, targetJoint.position);\r\n\r\n // Note: We do NOT recursively update subsequent joints here.\r\n // Instead, we let FABRIK algorithm handle the propagation in subsequent iterations.\r\n // This ensures that each joint's constraint is properly applied.\r\n }\r\n}\r\n"],"names":["IKAngleConstraint","IKConstraint","jointIndex","minAngle","maxAngle","_minAngle","Math","max","_maxAngle","min","Error","value","apply","joints","index","_jointIndex","length","_applyEndEffectorConstraint","_applyRegularConstraint","grandParentJoint","parentJoint","currentJoint","incomingBone","Vector3","sub","position","outgoingBone","incomingLen","magnitude","outgoingLen","incomingNorm","scale","outgoingNorm","dot","currentAngleDeg","acos","PI","targetAngleDeg","_adjustJointAngle","childJoint","pivotJoint","targetJoint","angleDifference","abs","isHardConstraint","deadZone","axis","cross","axisLen","scaleBy","targetAngleRad","currentAngleRad","deltaAngle","cos","sin","oneMinusCos","rotated","x","y","z","boneLength","add"],"mappings":";;;AAIA;;;;;;;;;;;IAYO,MAAMA,iBAA0BC,SAAAA,YAAAA,CAAAA;oCAErC,SAA0B;oCAE1B,SAA0B;AAE1B;;;;;;AAMC,MACD,YAAYC,UAAkB,EAAEC,QAAgB,EAAEC,QAAgB,CAAE;AAClE,QAAA,KAAK,CAACF,UAAAA,CAAAA;AACN,QAAA,IAAI,CAACG,SAAS,GAAGC,IAAKC,CAAAA,GAAG,CAAC,CAAGJ,EAAAA,QAAAA,CAAAA;AAC7B,QAAA,IAAI,CAACK,SAAS,GAAGF,IAAKG,CAAAA,GAAG,CAAC,GAAKL,EAAAA,QAAAA,CAAAA;AAE/B,QAAA,IAAI,IAAI,CAACC,SAAS,GAAG,IAAI,CAACG,SAA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AAAA,CAAa0B,CAAC,IAAIL,MAAMP,IAAKY,CAAAA,CAAC,GAAGZ,IAAKY,CAAAA,CAAC,GAAGH,WAAU,CAAA,GACpDvB,aAAa2B,CAAC,IAAIb,IAAKY,CAAAA,CAAC,GAAGZ,IAAKa,CAAAA,CAAC,GAAGJ,WAAcT,GAAAA,IAAAA,CAAKW,CAAC,GAAGH,GAAE,CAAA;QAE/DE,OAAQG,CAAAA,CAAC,GACP3B,YAAayB,CAAAA,CAAC,IAAIX,IAAAA,CAAKa,CAAC,GAAGb,IAAAA,CAAKW,CAAC,GAAGF,WAAAA,GAAcT,KAAKY,CAAC,GAAGJ,GAAE,CAC7DtB,GAAAA,YAAAA,CAAa0B,CAAC,IAAIZ,KAAKa,CAAC,GAAGb,KAAKY,CAAC,GAAGH,cAAcT,IAAKW,CAAAA,CAAC,GAAGH,GAAE,CAAA,GAC7DtB,aAAa2B,CAAC,IAAIN,GAAMP,GAAAA,IAAAA,CAAKa,CAAC,GAAGb,IAAAA,CAAKa,CAAC,GAAGJ,WAAU,CAAA;;QAGtD,MAAMK,UAAAA,GAAapB,WAAWoB,UAAU;AACxCJ,QAAAA,OAAAA,CAAQP,OAAO,CAACW,UAAAA,CAAAA;AAChBrC,QAAAA,OAAAA,CAAQsC,GAAG,CAACrB,UAAAA,CAAWf,QAAQ,EAAE+B,OAAAA,EAASf,YAAYhB,QAAQ,CAAA;;;;AAKhE;AACF;;;;"}
1
+ {"version":3,"file":"ik_angle_constraint.js","sources":["../../../src/animation/ik/ik_angle_constraint.ts"],"sourcesContent":["import { Vector3 } from '@zephyr3d/base';\r\nimport { IKConstraint } from './ik_constraint';\r\nimport type { IKJoint } from './ik_joint';\r\n\r\n/**\r\n * Angle constraint for IK joints.\r\n *\r\n * Limits the angle between the bone from parent to this joint\r\n * and the bone from this joint to child.\r\n *\r\n * @remarks\r\n * This is useful for joints like elbows and knees that have\r\n * limited range of motion.\r\n *\r\n * @public\r\n */\r\nexport class IKAngleConstraint extends IKConstraint {\r\n /** Minimum angle in degrees */\r\n private _minAngle: number;\r\n /** Maximum angle in degrees */\r\n private _maxAngle: number;\r\n\r\n /**\r\n * Create an angle constraint.\r\n *\r\n * @param jointIndex - Index of the joint in the chain\r\n * @param minAngle - Minimum angle in degrees (0 = straight)\r\n * @param maxAngle - Maximum angle in degrees (180 = fully bent)\r\n */\r\n constructor(jointIndex: number, minAngle: number, maxAngle: number) {\r\n super(jointIndex);\r\n this._minAngle = Math.max(0, minAngle);\r\n this._maxAngle = Math.min(180, maxAngle);\r\n\r\n if (this._minAngle > this._maxAngle) {\r\n throw new Error('IKAngleConstraint: minAngle must be <= maxAngle');\r\n }\r\n }\r\n\r\n /**\r\n * Get the minimum angle in degrees.\r\n */\r\n get minAngle(): number {\r\n return this._minAngle;\r\n }\r\n\r\n set minAngle(value: number) {\r\n this._minAngle = Math.max(0, Math.min(value, this._maxAngle));\r\n }\r\n\r\n /**\r\n * Get the maximum angle in degrees.\r\n */\r\n get maxAngle(): number {\r\n return this._maxAngle;\r\n }\r\n\r\n set maxAngle(value: number) {\r\n this._maxAngle = Math.min(180, Math.max(value, this._minAngle));\r\n }\r\n\r\n /**\r\n * Apply the angle constraint to limit joint bending.\r\n */\r\n apply(joints: IKJoint[]): void {\r\n const index = this._jointIndex;\r\n\r\n // For end effector (last joint), we constrain the angle between the last two bones\r\n // For other joints, we constrain the angle at the joint itself\r\n if (index === joints.length - 1) {\r\n // End effector: constrain angle between (parent-1 -> parent) and (parent -> this)\r\n if (index < 2) {\r\n return; // Need at least 3 joints total\r\n }\r\n this._applyEndEffectorConstraint(joints, index);\r\n } else {\r\n // Regular joint: constrain angle between (parent -> this) and (this -> child)\r\n if (index < 1) {\r\n return; // Root joint cannot be constrained this way\r\n }\r\n this._applyRegularConstraint(joints, index);\r\n }\r\n }\r\n\r\n /**\r\n * Apply constraint to end effector joint.\r\n */\r\n private _applyEndEffectorConstraint(joints: IKJoint[], index: number): void {\r\n const grandParentJoint = joints[index - 2];\r\n const parentJoint = joints[index - 1];\r\n const currentJoint = joints[index];\r\n\r\n // Calculate bone vectors\r\n const incomingBone = Vector3.sub(parentJoint.position, grandParentJoint.position, new Vector3());\r\n const outgoingBone = Vector3.sub(currentJoint.position, parentJoint.position, new Vector3());\r\n\r\n const incomingLen = incomingBone.magnitude;\r\n const outgoingLen = outgoingBone.magnitude;\r\n\r\n if (incomingLen < 0.000001 || outgoingLen < 0.000001) {\r\n return;\r\n }\r\n\r\n // Normalize\r\n const incomingNorm = Vector3.scale(incomingBone, 1 / incomingLen, new Vector3());\r\n const outgoingNorm = Vector3.scale(outgoingBone, 1 / outgoingLen, new Vector3());\r\n\r\n // Calculate current angle\r\n const dot = Vector3.dot(incomingNorm, outgoingNorm);\r\n const currentAngleDeg = Math.acos(Math.max(-1, Math.min(1, dot))) * (180 / Math.PI);\r\n\r\n // Check if constraint is violated\r\n let targetAngleDeg = currentAngleDeg;\r\n if (currentAngleDeg < this._minAngle) {\r\n targetAngleDeg = this._minAngle;\r\n } else if (currentAngleDeg > this._maxAngle) {\r\n targetAngleDeg = this._maxAngle;\r\n } else {\r\n return;\r\n }\r\n\r\n // Apply the same constraint logic as regular joints\r\n this._adjustJointAngle(\r\n incomingNorm,\r\n outgoingNorm,\r\n currentAngleDeg,\r\n targetAngleDeg,\r\n parentJoint,\r\n currentJoint\r\n );\r\n }\r\n\r\n /**\r\n * Apply constraint to regular joint.\r\n */\r\n private _applyRegularConstraint(joints: IKJoint[], index: number): void {\r\n const parentJoint = joints[index - 1];\r\n const currentJoint = joints[index];\r\n const childJoint = joints[index + 1];\r\n\r\n // Calculate bone vectors: incoming bone (parent->current) and outgoing bone (current->child)\r\n const incomingBone = Vector3.sub(currentJoint.position, parentJoint.position, new Vector3());\r\n const outgoingBone = Vector3.sub(childJoint.position, currentJoint.position, new Vector3());\r\n\r\n const incomingLen = incomingBone.magnitude;\r\n const outgoingLen = outgoingBone.magnitude;\r\n\r\n if (incomingLen < 0.000001 || outgoingLen < 0.000001) {\r\n return;\r\n }\r\n\r\n // Normalize\r\n const incomingNorm = Vector3.scale(incomingBone, 1 / incomingLen, new Vector3());\r\n const outgoingNorm = Vector3.scale(outgoingBone, 1 / outgoingLen, new Vector3());\r\n\r\n // Calculate current angle between incoming and outgoing bones (interior angle)\r\n const dot = Vector3.dot(incomingNorm, outgoingNorm);\r\n const currentAngleDeg = Math.acos(Math.max(-1, Math.min(1, dot))) * (180 / Math.PI);\r\n\r\n // Check if constraint is violated\r\n let targetAngleDeg = currentAngleDeg;\r\n if (currentAngleDeg < this._minAngle) {\r\n targetAngleDeg = this._minAngle;\r\n } else if (currentAngleDeg > this._maxAngle) {\r\n targetAngleDeg = this._maxAngle;\r\n } else {\r\n return;\r\n }\r\n\r\n // Apply the constraint\r\n this._adjustJointAngle(\r\n incomingNorm,\r\n outgoingNorm,\r\n currentAngleDeg,\r\n targetAngleDeg,\r\n currentJoint,\r\n childJoint\r\n );\r\n }\r\n\r\n /**\r\n * Adjust joint angle by rotating the outgoing bone.\r\n */\r\n private _adjustJointAngle(\r\n incomingNorm: Vector3,\r\n outgoingNorm: Vector3,\r\n currentAngleDeg: number,\r\n targetAngleDeg: number,\r\n pivotJoint: IKJoint,\r\n targetJoint: IKJoint\r\n ): void {\r\n // Add a dead zone to prevent oscillation\r\n const angleDifference = Math.abs(targetAngleDeg - currentAngleDeg);\r\n const isHardConstraint = Math.abs(this._maxAngle - this._minAngle) < 0.01;\r\n const deadZone = isHardConstraint ? 0.2 : 0.1;\r\n\r\n if (angleDifference < deadZone) {\r\n return; // Too close to target, avoid over-correction\r\n }\r\n\r\n // Calculate rotation axis (perpendicular to both bone vectors)\r\n const axis = Vector3.cross(incomingNorm, outgoingNorm, new Vector3());\r\n const axisLen = axis.magnitude;\r\n\r\n // Use a smaller threshold to allow constraint to work at small angles\r\n if (axisLen < 0.0001) {\r\n return; // Vectors are too close to parallel or anti-parallel\r\n }\r\n\r\n axis.scaleBy(1 / axisLen);\r\n\r\n // Calculate the angle we need to rotate\r\n const targetAngleRad = targetAngleDeg * (Math.PI / 180);\r\n const currentAngleRad = currentAngleDeg * (Math.PI / 180);\r\n let deltaAngle = targetAngleRad - currentAngleRad;\r\n\r\n // Apply full correction without damping to ensure constraints are enforced\r\n // This is necessary because FABRIK will try to undo the constraint in the next iteration\r\n // So we need strong constraint enforcement\r\n\r\n // Rotate the outgoing bone vector around the axis by deltaAngle\r\n const cos = Math.cos(deltaAngle);\r\n const sin = Math.sin(deltaAngle);\r\n const oneMinusCos = 1 - cos;\r\n\r\n // Rodrigues' rotation formula\r\n const rotated = new Vector3();\r\n rotated.x =\r\n outgoingNorm.x * (cos + axis.x * axis.x * oneMinusCos) +\r\n outgoingNorm.y * (axis.x * axis.y * oneMinusCos - axis.z * sin) +\r\n outgoingNorm.z * (axis.x * axis.z * oneMinusCos + axis.y * sin);\r\n\r\n rotated.y =\r\n outgoingNorm.x * (axis.y * axis.x * oneMinusCos + axis.z * sin) +\r\n outgoingNorm.y * (cos + axis.y * axis.y * oneMinusCos) +\r\n outgoingNorm.z * (axis.y * axis.z * oneMinusCos - axis.x * sin);\r\n\r\n rotated.z =\r\n outgoingNorm.x * (axis.z * axis.x * oneMinusCos - axis.y * sin) +\r\n outgoingNorm.y * (axis.z * axis.y * oneMinusCos + axis.x * sin) +\r\n outgoingNorm.z * (cos + axis.z * axis.z * oneMinusCos);\r\n\r\n // Update target joint position using the rotated bone vector\r\n const boneLength = pivotJoint.boneLength;\r\n rotated.scaleBy(boneLength);\r\n Vector3.add(pivotJoint.position, rotated, targetJoint.position);\r\n\r\n // Note: We do NOT recursively update subsequent joints here.\r\n // Instead, we let FABRIK algorithm handle the propagation in subsequent iterations.\r\n // This ensures that each joint's constraint is properly applied.\r\n }\r\n}\r\n"],"names":["IKAngleConstraint","IKConstraint","jointIndex","minAngle","maxAngle","_minAngle","Math","max","_maxAngle","min","Error","value","apply","joints","index","_jointIndex","length","_applyEndEffectorConstraint","_applyRegularConstraint","grandParentJoint","parentJoint","currentJoint","incomingBone","Vector3","sub","position","outgoingBone","incomingLen","magnitude","outgoingLen","incomingNorm","scale","outgoingNorm","dot","currentAngleDeg","acos","PI","targetAngleDeg","_adjustJointAngle","childJoint","pivotJoint","targetJoint","angleDifference","abs","isHardConstraint","deadZone","axis","cross","axisLen","scaleBy","targetAngleRad","currentAngleRad","deltaAngle","cos","sin","oneMinusCos","rotated","x","y","z","boneLength","add"],"mappings":";;;AAIA;;;;;;;;;;;IAYO,MAAMA,iBAA0BC,SAAAA,YAAAA,CAAAA;oCAErC,SAA0B;oCAE1B,SAA0B;AAE1B;;;;;;AAMC,MACD,YAAYC,UAAkB,EAAEC,QAAgB,EAAEC,QAAgB,CAAE;AAClE,QAAA,KAAK,CAACF,UAAAA,CAAAA;AACN,QAAA,IAAI,CAACG,SAAS,GAAGC,IAAKC,CAAAA,GAAG,CAAC,CAAGJ,EAAAA,QAAAA,CAAAA;AAC7B,QAAA,IAAI,CAACK,SAAS,GAAGF,IAAKG,CAAAA,GAAG,CAAC,GAAKL,EAAAA,QAAAA,CAAAA;AAE/B,QAAA,IAAI,IAAI,CAACC,SAAS,GAAG,IAAI,CAACG,SAAS,EAAE;AACnC,YAAA,MAAM,IAAIE,KAAM,CAAA,iDAAA,CAAA;AAClB;AACF;AAEA;;AAEC,MACD,IAAIP,QAAmB,GAAA;QACrB,OAAO,IAAI,CAACE,SAAS;AACvB;IAEA,IAAIF,QAAAA,CAASQ,KAAa,EAAE;AAC1B,QAAA,IAAI,CAACN,SAAS,GAAGC,IAAAA,CAAKC,GAAG,CAAC,CAAGD,EAAAA,IAAAA,CAAKG,GAAG,CAACE,KAAO,EAAA,IAAI,CAACH,SAAS,CAAA,CAAA;AAC7D;AAEA;;AAEC,MACD,IAAIJ,QAAmB,GAAA;QACrB,OAAO,IAAI,CAACI,SAAS;AACvB;IAEA,IAAIJ,QAAAA,CAASO,KAAa,EAAE;AAC1B,QAAA,IAAI,CAACH,SAAS,GAAGF,IAAAA,CAAKG,GAAG,CAAC,GAAKH,E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AC7DtB,aAAa2B,CAAC,IAAIN,GAAMP,GAAAA,IAAAA,CAAKa,CAAC,GAAGb,IAAAA,CAAKa,CAAC,GAAGJ,WAAU,CAAA;;QAGtD,MAAMK,UAAAA,GAAapB,WAAWoB,UAAU;AACxCJ,QAAAA,OAAAA,CAAQP,OAAO,CAACW,UAAAA,CAAAA;AAChBrC,QAAAA,OAAAA,CAAQsC,GAAG,CAACrB,UAAAA,CAAWf,QAAQ,EAAE+B,OAAAA,EAASf,YAAYhB,QAAQ,CAAA;;;;AAKhE;AACF;;;;"}
@@ -0,0 +1,68 @@
1
+ import { IKChain } from './ik_chain.js';
2
+
3
+ /**
4
+ * Helper class for building IK chains from various sources.
5
+ *
6
+ * @public
7
+ */ class IKChainBuilder {
8
+ /**
9
+ * Create an IK chain from an array of scene nodes.
10
+ *
11
+ * @param nodes - Array of scene nodes from root to end effector
12
+ * @returns The created IK chain
13
+ */ static fromNodes(nodes) {
14
+ return new IKChain(nodes);
15
+ }
16
+ /**
17
+ * Create an IK chain from a skeleton using joint indices.
18
+ *
19
+ * @param skeleton - The skeleton containing the joints
20
+ * @param jointIndices - Array of joint indices from root to end effector
21
+ * @returns The created IK chain
22
+ */ static fromSkeleton(skeleton, jointIndices) {
23
+ if (jointIndices.length < 2) {
24
+ throw new Error('IK chain must have at least 2 joints');
25
+ }
26
+ const joints = skeleton.joints;
27
+ const nodes = [];
28
+ for (const index of jointIndices){
29
+ if (index < 0 || index >= joints.length) {
30
+ throw new Error(`Invalid joint index: ${index}`);
31
+ }
32
+ nodes.push(joints[index]);
33
+ }
34
+ return new IKChain(nodes);
35
+ }
36
+ /**
37
+ * Create an IK chain by traversing from a start node to an end node.
38
+ *
39
+ * @remarks
40
+ * This method walks up the parent chain from the end node until it
41
+ * reaches the start node, building the joint chain in the process.
42
+ *
43
+ * @param startNode - The root joint of the chain
44
+ * @param endNode - The end effector joint
45
+ * @returns The created IK chain
46
+ */ static fromNodeHierarchy(startNode, endNode) {
47
+ const nodes = [];
48
+ let current = endNode;
49
+ // Walk up the hierarchy from end to start
50
+ while(current){
51
+ nodes.unshift(current); // Add to front
52
+ if (current === startNode) {
53
+ break;
54
+ }
55
+ current = current.parent;
56
+ }
57
+ if (nodes[0] !== startNode) {
58
+ throw new Error('End node is not a descendant of start node');
59
+ }
60
+ if (nodes.length < 2) {
61
+ throw new Error('IK chain must have at least 2 joints');
62
+ }
63
+ return new IKChain(nodes);
64
+ }
65
+ }
66
+
67
+ export { IKChainBuilder };
68
+ //# sourceMappingURL=ik_chain_builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ik_chain_builder.js","sources":["../../../src/animation/ik/ik_chain_builder.ts"],"sourcesContent":["import { IKChain } from './ik_chain';\r\nimport type { SceneNode } from '../../scene/scene_node';\r\nimport type { Skeleton } from '../skeleton';\r\n\r\n/**\r\n * Helper class for building IK chains from various sources.\r\n *\r\n * @public\r\n */\r\nexport class IKChainBuilder {\r\n /**\r\n * Create an IK chain from an array of scene nodes.\r\n *\r\n * @param nodes - Array of scene nodes from root to end effector\r\n * @returns The created IK chain\r\n */\r\n static fromNodes(nodes: SceneNode[]): IKChain {\r\n return new IKChain(nodes);\r\n }\r\n\r\n /**\r\n * Create an IK chain from a skeleton using joint indices.\r\n *\r\n * @param skeleton - The skeleton containing the joints\r\n * @param jointIndices - Array of joint indices from root to end effector\r\n * @returns The created IK chain\r\n */\r\n static fromSkeleton(skeleton: Skeleton, jointIndices: number[]): IKChain {\r\n if (jointIndices.length < 2) {\r\n throw new Error('IK chain must have at least 2 joints');\r\n }\r\n\r\n const joints = skeleton.joints;\r\n const nodes: SceneNode[] = [];\r\n\r\n for (const index of jointIndices) {\r\n if (index < 0 || index >= joints.length) {\r\n throw new Error(`Invalid joint index: ${index}`);\r\n }\r\n nodes.push(joints[index]);\r\n }\r\n\r\n return new IKChain(nodes);\r\n }\r\n\r\n /**\r\n * Create an IK chain by traversing from a start node to an end node.\r\n *\r\n * @remarks\r\n * This method walks up the parent chain from the end node until it\r\n * reaches the start node, building the joint chain in the process.\r\n *\r\n * @param startNode - The root joint of the chain\r\n * @param endNode - The end effector joint\r\n * @returns The created IK chain\r\n */\r\n static fromNodeHierarchy(startNode: SceneNode, endNode: SceneNode): IKChain {\r\n const nodes: SceneNode[] = [];\r\n let current: SceneNode | null = endNode;\r\n\r\n // Walk up the hierarchy from end to start\r\n while (current) {\r\n nodes.unshift(current); // Add to front\r\n\r\n if (current === startNode) {\r\n break;\r\n }\r\n\r\n current = current.parent as SceneNode | null;\r\n }\r\n\r\n if (nodes[0] !== startNode) {\r\n throw new Error('End node is not a descendant of start node');\r\n }\r\n\r\n if (nodes.length < 2) {\r\n throw new Error('IK chain must have at least 2 joints');\r\n }\r\n\r\n return new IKChain(nodes);\r\n }\r\n}\r\n"],"names":["IKChainBuilder","fromNodes","nodes","IKChain","fromSkeleton","skeleton","jointIndices","length","Error","joints","index","push","fromNodeHierarchy","startNode","endNode","current","unshift","parent"],"mappings":";;AAIA;;;;AAIC,IACM,MAAMA,cAAAA,CAAAA;AACX;;;;;MAMA,OAAOC,SAAUC,CAAAA,KAAkB,EAAW;AAC5C,QAAA,OAAO,IAAIC,OAAQD,CAAAA,KAAAA,CAAAA;AACrB;AAEA;;;;;;AAMC,MACD,OAAOE,YAAAA,CAAaC,QAAkB,EAAEC,YAAsB,EAAW;QACvE,IAAIA,YAAAA,CAAaC,MAAM,GAAG,CAAG,EAAA;AAC3B,YAAA,MAAM,IAAIC,KAAM,CAAA,sCAAA,CAAA;AAClB;QAEA,MAAMC,MAAAA,GAASJ,SAASI,MAAM;AAC9B,QAAA,MAAMP,QAAqB,EAAE;QAE7B,KAAK,MAAMQ,SAASJ,YAAc,CAAA;AAChC,YAAA,IAAII,KAAQ,GAAA,CAAA,IAAKA,KAASD,IAAAA,MAAAA,CAAOF,MAAM,EAAE;AACvC,gBAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,qBAAqB,EAAEE,KAAO,CAAA,CAAA,CAAA;AACjD;AACAR,YAAAA,KAAAA,CAAMS,IAAI,CAACF,MAAM,CAACC,KAAM,CAAA,CAAA;AAC1B;AAEA,QAAA,OAAO,IAAIP,OAAQD,CAAAA,KAAAA,CAAAA;AACrB;AAEA;;;;;;;;;;AAUC,MACD,OAAOU,iBAAAA,CAAkBC,SAAoB,EAAEC,OAAkB,EAAW;AAC1E,QAAA,MAAMZ,QAAqB,EAAE;AAC7B,QAAA,IAAIa,OAA4BD,GAAAA,OAAAA;;AAGhC,QAAA,MAAOC,OAAS,CAAA;YACdb,KAAMc,CAAAA,OAAO,CAACD,OAAAA,CAAAA,CAAAA;AAEd,YAAA,IAAIA,YAAYF,SAAW,EAAA;AACzB,gBAAA;AACF;AAEAE,YAAAA,OAAAA,GAAUA,QAAQE,MAAM;AAC1B;AAEA,QAAA,IAAIf,KAAK,CAAC,CAAE,CAAA,KAAKW,SAAW,EAAA;AAC1B,YAAA,MAAM,IAAIL,KAAM,CAAA,4CAAA,CAAA;AAClB;QAEA,IAAIN,KAAAA,CAAMK,MAAM,GAAG,CAAG,EAAA;AACpB,YAAA,MAAM,IAAIC,KAAM,CAAA,sCAAA,CAAA;AAClB;AAEA,QAAA,OAAO,IAAIL,OAAQD,CAAAA,KAAAA,CAAAA;AACrB;AACF;;;;"}
@@ -4,13 +4,8 @@ import { IKConstraint } from './ik_constraint.js';
4
4
  /**
5
5
  * Pole vector constraint for IK chains.
6
6
  *
7
- * @deprecated Use the built-in pole vector methods on IK solvers instead:
8
- * - {@link FABRIKSolver.setPoleVector}
9
- * - {@link CCDSolver.setPoleVector}
10
- * - {@link TwoBoneIKSolver.poleVector}
11
- *
12
- * This class is deprecated and will be removed in a future version.
13
- * The built-in pole vector methods provide better performance and more control.
7
+ * Controls the twist/rotation of a joint chain by ensuring the middle joint
8
+ * bends toward a specified pole vector position.
14
9
  *
15
10
  * @remarks
16
11
  * This is commonly used for arms and legs to control which direction
@@ -1 +1 @@
1
- {"version":3,"file":"ik_pole_constraint.js","sources":["../../../src/animation/ik/ik_pole_constraint.ts"],"sourcesContent":["import { Vector3 } from '@zephyr3d/base';\r\nimport { IKConstraint } from './ik_constraint';\r\nimport type { IKJoint } from './ik_joint';\r\n\r\n/**\r\n * Pole vector constraint for IK chains.\r\n *\r\n * @deprecated Use the built-in pole vector methods on IK solvers instead:\r\n * - {@link FABRIKSolver.setPoleVector}\r\n * - {@link CCDSolver.setPoleVector}\r\n * - {@link TwoBoneIKSolver.poleVector}\r\n *\r\n * This class is deprecated and will be removed in a future version.\r\n * The built-in pole vector methods provide better performance and more control.\r\n *\r\n * @remarks\r\n * This is commonly used for arms and legs to control which direction\r\n * the elbow or knee points. For example, ensuring an elbow points\r\n * backward or a knee points forward.\r\n *\r\n * The pole vector defines a plane, and the middle joint is constrained\r\n * to lie on this plane.\r\n *\r\n * @public\r\n */\r\nexport class IKPoleVectorConstraint extends IKConstraint {\r\n /** The pole vector position in world space */\r\n private _poleVector: Vector3;\r\n /** Weight of the constraint (0 = no effect, 1 = full effect) */\r\n private _weight: number;\r\n\r\n /**\r\n * Create a pole vector constraint.\r\n *\r\n * @param jointIndex - Index of the middle joint to constrain (typically elbow or knee)\r\n * @param poleVector - Position in world space that the joint should point toward\r\n * @param weight - Constraint weight (0-1, default: 1)\r\n */\r\n constructor(jointIndex: number, poleVector: Vector3, weight = 1) {\r\n super(jointIndex);\r\n this._poleVector = poleVector.clone();\r\n this._weight = Math.max(0, Math.min(1, weight));\r\n }\r\n\r\n /**\r\n * Get the pole vector position.\r\n */\r\n get poleVector(): Vector3 {\r\n return this._poleVector;\r\n }\r\n\r\n /**\r\n * Set the pole vector position.\r\n */\r\n set poleVector(value: Vector3) {\r\n this._poleVector.set(value);\r\n }\r\n\r\n /**\r\n * Get the constraint weight.\r\n */\r\n get weight(): number {\r\n return this._weight;\r\n }\r\n\r\n /**\r\n * Set the constraint weight (0-1).\r\n */\r\n set weight(value: number) {\r\n this._weight = Math.max(0, Math.min(1, value));\r\n }\r\n\r\n /**\r\n * Apply the pole vector constraint.\r\n *\r\n * This adjusts the middle joint position to align with the pole vector\r\n * while maintaining bone lengths.\r\n */\r\n apply(joints: IKJoint[]): void {\r\n const index = this._jointIndex;\r\n\r\n // Need at least 3 joints (parent, this, child)\r\n if (index < 1 || index >= joints.length - 1) {\r\n return;\r\n }\r\n\r\n if (this._weight < 0.001) {\r\n return; // No effect\r\n }\r\n\r\n const parentJoint = joints[index - 1];\r\n const currentJoint = joints[index];\r\n const childJoint = joints[index + 1];\r\n\r\n // Calculate the plane defined by parent, child, and pole vector\r\n const parentPos = parentJoint.position;\r\n const childPos = childJoint.position;\r\n const currentPos = currentJoint.position;\r\n\r\n // Vector from parent to child (the \"line\" we're bending around)\r\n const parentToChild = Vector3.sub(childPos, parentPos, new Vector3());\r\n const lineLength = parentToChild.magnitude;\r\n\r\n if (lineLength < 0.000001) {\r\n return; // Parent and child are at same position\r\n }\r\n\r\n const lineDir = Vector3.scale(parentToChild, 1 / lineLength, new Vector3());\r\n\r\n // Project current joint onto the parent-child line\r\n const parentToCurrent = Vector3.sub(currentPos, parentPos, new Vector3());\r\n const projectionLength = Vector3.dot(parentToCurrent, lineDir);\r\n const projectionPoint = Vector3.scale(lineDir, projectionLength, new Vector3());\r\n projectionPoint.addBy(parentPos);\r\n\r\n // Vector from projection point to current joint (perpendicular to line)\r\n const perpendicular = Vector3.sub(currentPos, projectionPoint, new Vector3());\r\n const perpLength = perpendicular.magnitude;\r\n\r\n if (perpLength < 0.000001) {\r\n return; // Current joint is on the line\r\n }\r\n\r\n // Calculate desired direction toward pole vector\r\n const parentToPole = Vector3.sub(this._poleVector, parentPos, new Vector3());\r\n const poleProjectionLength = Vector3.dot(parentToPole, lineDir);\r\n const poleProjectionPoint = Vector3.scale(lineDir, poleProjectionLength, new Vector3());\r\n poleProjectionPoint.addBy(parentPos);\r\n\r\n // Direction from projection to pole (perpendicular to line)\r\n const poleDirection = Vector3.sub(this._poleVector, poleProjectionPoint, new Vector3());\r\n const poleDirLength = poleDirection.magnitude;\r\n\r\n if (poleDirLength < 0.000001) {\r\n return; // Pole is on the line\r\n }\r\n\r\n poleDirection.scaleBy(1 / poleDirLength);\r\n\r\n // Calculate new position for current joint\r\n // Keep the same distance from the line, but rotate toward pole direction\r\n const desiredPerpendicular = Vector3.scale(poleDirection, perpLength, new Vector3());\r\n const newPosition = Vector3.add(projectionPoint, desiredPerpendicular, new Vector3());\r\n\r\n // Apply weight (blend between original and constrained position)\r\n if (this._weight < 0.999) {\r\n // Manual lerp: result = a + (b - a) * t\r\n const blended = new Vector3();\r\n blended.x = currentPos.x + (newPosition.x - currentPos.x) * this._weight;\r\n blended.y = currentPos.y + (newPosition.y - currentPos.y) * this._weight;\r\n blended.z = currentPos.z + (newPosition.z - currentPos.z) * this._weight;\r\n currentJoint.position.set(blended);\r\n } else {\r\n currentJoint.position.set(newPosition);\r\n }\r\n }\r\n}\r\n"],"names":["IKPoleVectorConstraint","IKConstraint","jointIndex","poleVector","weight","_poleVector","clone","_weight","Math","max","min","value","set","apply","joints","index","_jointIndex","length","parentJoint","currentJoint","childJoint","parentPos","position","childPos","currentPos","parentToChild","Vector3","sub","lineLength","magnitude","lineDir","scale","parentToCurrent","projectionLength","dot","projectionPoint","addBy","perpendicular","perpLength","parentToPole","poleProjectionLength","poleProjectionPoint","poleDirection","poleDirLength","scaleBy","desiredPerpendicular","newPosition","add","blended","x","y","z"],"mappings":";;;AAIA;;;;;;;;;;;;;;;;;;;;IAqBO,MAAMA,sBAA+BC,SAAAA,YAAAA,CAAAA;mDAE1C,WAA6B;qEAE7B,OAAwB;AAExB;;;;;;AAMC,MACD,YAAYC,UAAkB,EAAEC,UAAmB,EAAEC,MAAAA,GAAS,CAAC,CAAE;AAC/D,QAAA,KAAK,CAACF,UAAAA,CAAAA;AACN,QAAA,IAAI,CAACG,WAAW,GAAGF,UAAAA,CAAWG,KAAK,EAAA;QACnC,IAAI,CAACC,OAAO,GAAGC,IAAKC,CAAAA,GAAG,CAAC,CAAGD,EAAAA,IAAAA,CAAKE,GA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Content":["import { Vector3 } from '@zephyr3d/base';\r\nimport { IKConstraint } from './ik_constraint';\r\nimport type { IKJoint } from './ik_joint';\r\n\r\n/**\r\n * Pole vector constraint for IK chains.\r\n *\r\n * Controls the twist/rotation of a joint chain by ensuring the middle joint\r\n * bends toward a specified pole vector position.\r\n *\r\n * @remarks\r\n * This is commonly used for arms and legs to control which direction\r\n * the elbow or knee points. For example, ensuring an elbow points\r\n * backward or a knee points forward.\r\n *\r\n * The pole vector defines a plane, and the middle joint is constrained\r\n * to lie on this plane.\r\n *\r\n * @public\r\n */\r\nexport class IKPoleVectorConstraint extends IKConstraint {\r\n /** The pole vector position in world space */\r\n private _poleVector: Vector3;\r\n /** Weight of the constraint (0 = no effect, 1 = full effect) */\r\n private _weight: number;\r\n\r\n /**\r\n * Create a pole vector constraint.\r\n *\r\n * @param jointIndex - Index of the middle joint to constrain (typically elbow or knee)\r\n * @param poleVector - Position in world space that the joint should point toward\r\n * @param weight - Constraint weight (0-1, default: 1)\r\n */\r\n constructor(jointIndex: number, poleVector: Vector3, weight = 1) {\r\n super(jointIndex);\r\n this._poleVector = poleVector.clone();\r\n this._weight = Math.max(0, Math.min(1, weight));\r\n }\r\n\r\n /**\r\n * Get the pole vector position.\r\n */\r\n get poleVector(): Vector3 {\r\n return this._poleVector;\r\n }\r\n\r\n /**\r\n * Set the pole vector position.\r\n */\r\n set poleVector(value: Vector3) {\r\n this._poleVector.set(value);\r\n }\r\n\r\n /**\r\n * Get the constraint weight.\r\n */\r\n get weight(): number {\r\n return this._weight;\r\n }\r\n\r\n /**\r\n * Set the constraint weight (0-1).\r\n */\r\n set weight(value: number) {\r\n this._weight = Math.max(0, Math.min(1, value));\r\n }\r\n\r\n /**\r\n * Apply the pole vector constraint.\r\n *\r\n * This adjusts the middle joint position to align with the pole vector\r\n * while maintaining bone lengths.\r\n */\r\n apply(joints: IKJoint[]): void {\r\n const index = this._jointIndex;\r\n\r\n // Need at least 3 joints (parent, this, child)\r\n if (index < 1 || index >= joints.length - 1) {\r\n return;\r\n }\r\n\r\n if (this._weight < 0.001) {\r\n return; // No effect\r\n }\r\n\r\n const parentJoint = joints[index - 1];\r\n const currentJoint = joints[index];\r\n const childJoint = joints[index + 1];\r\n\r\n // Calculate the plane defined by parent, child, and pole vector\r\n const parentPos = parentJoint.position;\r\n const childPos = childJoint.position;\r\n const currentPos = currentJoint.position;\r\n\r\n // Vector from parent to child (the \"line\" we're bending around)\r\n const parentToChild = Vector3.sub(childPos, parentPos, new Vector3());\r\n const lineLength = parentToChild.magnitude;\r\n\r\n if (lineLength < 0.000001) {\r\n return; // Parent and child are at same position\r\n }\r\n\r\n const lineDir = Vector3.scale(parentToChild, 1 / lineLength, new Vector3());\r\n\r\n // Project current joint onto the parent-child line\r\n const parentToCurrent = Vector3.sub(currentPos, parentPos, new Vector3());\r\n const projectionLength = Vector3.dot(parentToCurrent, lineDir);\r\n const projectionPoint = Vector3.scale(lineDir, projectionLength, new Vector3());\r\n projectionPoint.addBy(parentPos);\r\n\r\n // Vector from projection point to current joint (perpendicular to line)\r\n const perpendicular = Vector3.sub(currentPos, projectionPoint, new Vector3());\r\n const perpLength = perpendicular.magnitude;\r\n\r\n if (perpLength < 0.000001) {\r\n return; // Current joint is on the line\r\n }\r\n\r\n // Calculate desired direction toward pole vector\r\n const parentToPole = Vector3.sub(this._poleVector, parentPos, new Vector3());\r\n const poleProjectionLength = Vector3.dot(parentToPole, lineDir);\r\n const poleProjectionPoint = Vector3.scale(lineDir, poleProjectionLength, new Vector3());\r\n poleProjectionPoint.addBy(parentPos);\r\n\r\n // Direction from projection to pole (perpendicular to line)\r\n const poleDirection = Vector3.sub(this._poleVector, poleProjectionPoint, new Vector3());\r\n const poleDirLength = poleDirection.magnitude;\r\n\r\n if (poleDirLength < 0.000001) {\r\n return; // Pole is on the line\r\n }\r\n\r\n poleDirection.scaleBy(1 / poleDirLength);\r\n\r\n // Calculate new position for current joint\r\n // Keep the same distance from the line, but rotate toward pole direction\r\n const desiredPerpendicular = Vector3.scale(poleDirection, perpLength, new Vector3());\r\n const newPosition = Vector3.add(projectionPoint, desiredPerpendicular, new Vector3());\r\n\r\n // Apply weight (blend between original and constrained position)\r\n if (this._weight < 0.999) {\r\n // Manual lerp: result = a + (b - a) * t\r\n const blended = new Vector3();\r\n blended.x = currentPos.x + (newPosition.x - currentPos.x) * this._weight;\r\n blended.y = currentPos.y + (newPosition.y - currentPos.y) * this._weight;\r\n blended.z = currentPos.z + (newPosition.z - currentPos.z) * this._weight;\r\n currentJoint.position.set(blended);\r\n } else {\r\n currentJoint.position.set(newPosition);\r\n }\r\n }\r\n}\r\n"],"names":["IKPoleVectorConstraint","IKConstraint","jointIndex","poleVector","weight","_poleVector","clone","_weight","Math","max","min","value","set","apply","joints","index","_jointIndex","length","parentJoint","currentJoint","childJoint","parentPos","position","childPos","currentPos","parentToChild","Vector3","sub","lineLength","magnitude","lineDir","scale","parentToCurrent","projectionLength","dot","projectionPoint","addBy","perpendicular","perpLength","parentToPole","poleProjectionLength","poleProjectionPoint","poleDirection","poleDirLength","scaleBy","desiredPerpendicular","newPosition","add","blended","x","y","z"],"mappings":";;;AAIA;;;;;;;;;;;;;;;IAgBO,MAAMA,sBAA+BC,SAAAA,YAAAA,CAAAA;mDAE1C,WAA6B;qEAE7B,OAAwB;AAExB;;;;;;AAMC,MACD,YAAYC,UAAkB,EAAEC,UAAmB,EAAEC,MAAAA,GAAS,CAAC,CAAE;AAC/D,QAAA,KAAK,CAACF,UAAAA,CAAAA;AACN,QAAA,IAAI,CAACG,WAAW,GAAGF,UAAAA,CAAWG,KAAK,EAAA;QACnC,IAAI,CAACC,OAAO,GAAGC,IAAKC,CAAAA,GAAG,CAAC,CAAGD,EAAAA,IAAAA,CAAKE,GAAG,CAAC,CAAGN,EAAAA,MAAAA,CAAAA,CAAAA;AACzC;AAEA;;AAEC,MACD,IAAID,UAAsB,GAAA;QACxB,OAAO,IAAI,CAACE,WAAW;AACzB;AAEA;;MAGA,IAAIF,UAAWQ,CA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F;QAEAD,aAAcE,CAAAA,OAAO,CAAC,CAAID,GAAAA,aAAAA,CAAAA;;;AAI1B,QAAA,MAAME,uBAAuBnB,OAAQK,CAAAA,KAAK,CAACW,aAAAA,EAAeJ,YAAY,IAAIZ,OAAAA,EAAAA,CAAAA;AAC1E,QAAA,MAAMoB,cAAcpB,OAAQqB,CAAAA,GAAG,CAACZ,eAAAA,EAAiBU,sBAAsB,IAAInB,OAAAA,EAAAA,CAAAA;;AAG3E,QAAA,IAAI,IAAI,CAACnB,OAAO,GAAG,KAAO,EAAA;;AAExB,YAAA,MAAMyC,UAAU,IAAItB,OAAAA,EAAAA;AACpBsB,YAAAA,OAAAA,CAAQC,CAAC,GAAGzB,UAAAA,CAAWyB,CAAC,GAAG,CAACH,WAAAA,CAAYG,CAAC,GAAGzB,WAAWyB,CAAAA,IAAK,IAAI,CAAC1C,OAAO;AACxEyC,YAAAA,OAAAA,CAAQE,CAAC,GAAG1B,UAAAA,CAAW0B,CAAC,GAAG,CAACJ,WAAAA,CAAYI,CAAC,GAAG1B,WAAW0B,CAAAA,IAAK,IAAI,CAAC3C,OAAO;AACxEyC,YAAAA,OAAAA,CAAQG,CAAC,GAAG3B,UAAAA,CAAW2B,CAAC,GAAG,CAACL,WAAAA,CAAYK,CAAC,GAAG3B,WAAW2B,CAAAA,IAAK,IAAI,CAAC5C,OAAO;YACxEY,YAAaG,CAAAA,QAAQ,CAACV,GAAG,CAACoC,OAAAA,CAAAA;SACrB,MAAA;YACL7B,YAAaG,CAAAA,QAAQ,CAACV,GAAG,CAACkC,WAAAA,CAAAA;AAC5B;AACF;AACF;;;;"}
@@ -89,9 +89,7 @@ import { IKUtils } from './ik_utils.js';
89
89
  */ get poleVector() {
90
90
  return this._poleVector;
91
91
  }
92
- /**
93
- * Set the pole vector position.
94
- */ set poleVector(value) {
92
+ set poleVector(value) {
95
93
  if (value) {
96
94
  if (!this._poleVector) {
97
95
  this._poleVector = value.clone();
@@ -107,9 +105,7 @@ import { IKUtils } from './ik_utils.js';
107
105
  */ get poleWeight() {
108
106
  return this._poleWeight;
109
107
  }
110
- /**
111
- * Set the pole vector weight (0-1).
112
- */ set poleWeight(value) {
108
+ set poleWeight(value) {
113
109
  this._poleWeight = Math.max(0, Math.min(1, value));
114
110
  }
115
111
  /**