@zephyr3d/scene 0.7.1 → 0.8.1

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 (441) hide show
  1. package/dist/animation/animation.js +0 -18
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +200 -3
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/ik/ccd_solver.js +371 -0
  6. package/dist/animation/ik/ccd_solver.js.map +1 -0
  7. package/dist/animation/ik/fabrik_solver.js +398 -0
  8. package/dist/animation/ik/fabrik_solver.js.map +1 -0
  9. package/dist/animation/ik/ik_angle_constraint.js +181 -0
  10. package/dist/animation/ik/ik_angle_constraint.js.map +1 -0
  11. package/dist/animation/ik/ik_chain.js +163 -0
  12. package/dist/animation/ik/ik_chain.js.map +1 -0
  13. package/dist/animation/ik/ik_constraint.js +25 -0
  14. package/dist/animation/ik/ik_constraint.js.map +1 -0
  15. package/dist/animation/ik/ik_pole_constraint.js +128 -0
  16. package/dist/animation/ik/ik_pole_constraint.js.map +1 -0
  17. package/dist/animation/ik/ik_solver.js +48 -0
  18. package/dist/animation/ik/ik_solver.js.map +1 -0
  19. package/dist/animation/ik/ik_track.js +96 -0
  20. package/dist/animation/ik/ik_track.js.map +1 -0
  21. package/dist/animation/ik/ik_utils.js +191 -0
  22. package/dist/animation/ik/ik_utils.js.map +1 -0
  23. package/dist/animation/ik/two_bone_ik_solver.js +331 -0
  24. package/dist/animation/ik/two_bone_ik_solver.js.map +1 -0
  25. package/dist/animation/ik_modifier.js +61 -0
  26. package/dist/animation/ik_modifier.js.map +1 -0
  27. package/dist/animation/ik_postprocessor.js +71 -0
  28. package/dist/animation/ik_postprocessor.js.map +1 -0
  29. package/dist/animation/manual_transform_processor.js +156 -0
  30. package/dist/animation/manual_transform_processor.js.map +1 -0
  31. package/dist/animation/skeleton.js +55 -51
  32. package/dist/animation/skeleton.js.map +1 -1
  33. package/dist/animation/skeleton_modifier.js +38 -0
  34. package/dist/animation/skeleton_modifier.js.map +1 -0
  35. package/dist/animation/skeleton_postprocessor.js +50 -0
  36. package/dist/animation/skeleton_postprocessor.js.map +1 -0
  37. package/dist/animation/spring/multi_chain_spring_system.js +503 -0
  38. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -0
  39. package/dist/animation/spring/spring_bone.js +240 -0
  40. package/dist/animation/spring/spring_bone.js.map +1 -0
  41. package/dist/animation/spring/spring_bone_collider.js +198 -0
  42. package/dist/animation/spring/spring_bone_collider.js.map +1 -0
  43. package/dist/animation/spring/spring_bone_constraint.js +170 -0
  44. package/dist/animation/spring/spring_bone_constraint.js.map +1 -0
  45. package/dist/animation/spring/spring_bone_system.js +328 -0
  46. package/dist/animation/spring/spring_bone_system.js.map +1 -0
  47. package/dist/animation/spring/spring_chain.js +103 -0
  48. package/dist/animation/spring/spring_chain.js.map +1 -0
  49. package/dist/animation/spring/spring_collider.js +247 -0
  50. package/dist/animation/spring/spring_collider.js.map +1 -0
  51. package/dist/animation/spring/spring_constraint.js +21 -0
  52. package/dist/animation/spring/spring_constraint.js.map +1 -0
  53. package/dist/animation/spring/spring_particle.js +20 -0
  54. package/dist/animation/spring/spring_particle.js.map +1 -0
  55. package/dist/animation/spring/spring_system.js +526 -0
  56. package/dist/animation/spring/spring_system.js.map +1 -0
  57. package/dist/animation/spring_modifier.js +45 -0
  58. package/dist/animation/spring_modifier.js.map +1 -0
  59. package/dist/animation/spring_postprocessor.js +54 -0
  60. package/dist/animation/spring_postprocessor.js.map +1 -0
  61. package/dist/app/screen.js +1 -1
  62. package/dist/app/screen.js.map +1 -1
  63. package/dist/asset/model.js +10 -6
  64. package/dist/asset/model.js.map +1 -1
  65. package/dist/camera/perspectivecamera.js +3 -3
  66. package/dist/camera/perspectivecamera.js.map +1 -1
  67. package/dist/index.d.ts +1400 -4
  68. package/dist/index.js +16 -0
  69. package/dist/index.js.map +1 -1
  70. package/dist/material/mixins/lightmodel/blinnphong.js +66 -4
  71. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  72. package/dist/material/mixins/pbr/common.js +20 -17
  73. package/dist/material/mixins/pbr/common.js.map +1 -1
  74. package/dist/material/shader/helper.js +5 -3
  75. package/dist/material/shader/helper.js.map +1 -1
  76. package/dist/render/gpu_picking.js +100 -0
  77. package/dist/render/gpu_picking.js.map +1 -0
  78. package/dist/render/rendergraph/device_pool_allocator.js +41 -0
  79. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -0
  80. package/dist/render/rendergraph/executor.js +146 -0
  81. package/dist/render/rendergraph/executor.js.map +1 -0
  82. package/dist/render/rendergraph/forward_plus_builder.js +414 -0
  83. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -0
  84. package/dist/render/rendergraph/rendergraph.js +306 -0
  85. package/dist/render/rendergraph/rendergraph.js.map +1 -0
  86. package/dist/render/rendergraph/types.js +57 -0
  87. package/dist/render/rendergraph/types.js.map +1 -0
  88. package/dist/render/sky_motion_vector.js +85 -0
  89. package/dist/render/sky_motion_vector.js.map +1 -0
  90. package/dist/scene/mesh.js +15 -23
  91. package/dist/scene/mesh.js.map +1 -1
  92. package/dist/utility/serialization/scene/animation.js +24 -23
  93. package/dist/utility/serialization/scene/animation.js.map +1 -1
  94. package/dist/utility/serialization/scene/material.js +62 -0
  95. package/dist/utility/serialization/scene/material.js.map +1 -1
  96. package/dist/utility/serialization/scene/node.js +1 -1
  97. package/package.json +3 -3
  98. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +0 -38
  99. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +0 -1
  100. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +0 -10
  101. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +0 -1
  102. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +0 -127
  103. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +0 -1
  104. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +0 -263
  105. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +0 -1
  106. package/dist/src/animation/animation.js +0 -127
  107. package/dist/src/animation/animation.js.map +0 -1
  108. package/dist/src/animation/animationset.js +0 -255
  109. package/dist/src/animation/animationset.js.map +0 -1
  110. package/dist/src/animation/animationtrack.js +0 -34
  111. package/dist/src/animation/animationtrack.js.map +0 -1
  112. package/dist/src/animation/eulerrotationtrack.js +0 -52
  113. package/dist/src/animation/eulerrotationtrack.js.map +0 -1
  114. package/dist/src/animation/morphtarget.js +0 -93
  115. package/dist/src/animation/morphtarget.js.map +0 -1
  116. package/dist/src/animation/morphtrack.js +0 -70
  117. package/dist/src/animation/morphtrack.js.map +0 -1
  118. package/dist/src/animation/proptrack.js +0 -161
  119. package/dist/src/animation/proptrack.js.map +0 -1
  120. package/dist/src/animation/rotationtrack.js +0 -51
  121. package/dist/src/animation/rotationtrack.js.map +0 -1
  122. package/dist/src/animation/scaletrack.js +0 -50
  123. package/dist/src/animation/scaletrack.js.map +0 -1
  124. package/dist/src/animation/skeleton.js +0 -204
  125. package/dist/src/animation/skeleton.js.map +0 -1
  126. package/dist/src/animation/translationtrack.js +0 -50
  127. package/dist/src/animation/translationtrack.js.map +0 -1
  128. package/dist/src/app/app.js +0 -129
  129. package/dist/src/app/app.js.map +0 -1
  130. package/dist/src/app/inputmgr.js +0 -267
  131. package/dist/src/app/inputmgr.js.map +0 -1
  132. package/dist/src/asset/assetmanager.js +0 -404
  133. package/dist/src/asset/assetmanager.js.map +0 -1
  134. package/dist/src/asset/builtin.js +0 -337
  135. package/dist/src/asset/builtin.js.map +0 -1
  136. package/dist/src/asset/loaders/dds/dds.js +0 -470
  137. package/dist/src/asset/loaders/dds/dds.js.map +0 -1
  138. package/dist/src/asset/loaders/dds/dds_loader.js +0 -28
  139. package/dist/src/asset/loaders/dds/dds_loader.js.map +0 -1
  140. package/dist/src/asset/loaders/gltf/gltf_loader.js +0 -1265
  141. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +0 -1
  142. package/dist/src/asset/loaders/gltf/helpers.js +0 -327
  143. package/dist/src/asset/loaders/gltf/helpers.js.map +0 -1
  144. package/dist/src/asset/loaders/hdr/hdr.js +0 -180
  145. package/dist/src/asset/loaders/hdr/hdr.js.map +0 -1
  146. package/dist/src/asset/loaders/image/tga_Loader.js +0 -116
  147. package/dist/src/asset/loaders/image/tga_Loader.js.map +0 -1
  148. package/dist/src/asset/loaders/image/webimage_loader.js +0 -63
  149. package/dist/src/asset/loaders/image/webimage_loader.js.map +0 -1
  150. package/dist/src/asset/loaders/loader.js +0 -45
  151. package/dist/src/asset/loaders/loader.js.map +0 -1
  152. package/dist/src/asset/model.js +0 -414
  153. package/dist/src/asset/model.js.map +0 -1
  154. package/dist/src/blitter/bilateralblur.js +0 -221
  155. package/dist/src/blitter/bilateralblur.js.map +0 -1
  156. package/dist/src/blitter/blitter.js +0 -390
  157. package/dist/src/blitter/blitter.js.map +0 -1
  158. package/dist/src/blitter/box.js +0 -118
  159. package/dist/src/blitter/box.js.map +0 -1
  160. package/dist/src/blitter/copy.js +0 -22
  161. package/dist/src/blitter/copy.js.map +0 -1
  162. package/dist/src/blitter/gaussianblur.js +0 -228
  163. package/dist/src/blitter/gaussianblur.js.map +0 -1
  164. package/dist/src/camera/base.js +0 -92
  165. package/dist/src/camera/base.js.map +0 -1
  166. package/dist/src/camera/camera.js +0 -1005
  167. package/dist/src/camera/camera.js.map +0 -1
  168. package/dist/src/camera/fps.js +0 -238
  169. package/dist/src/camera/fps.js.map +0 -1
  170. package/dist/src/camera/orbit.js +0 -245
  171. package/dist/src/camera/orbit.js.map +0 -1
  172. package/dist/src/camera/orthocamera.js +0 -167
  173. package/dist/src/camera/orthocamera.js.map +0 -1
  174. package/dist/src/camera/perspectivecamera.js +0 -141
  175. package/dist/src/camera/perspectivecamera.js.map +0 -1
  176. package/dist/src/index.js +0 -120
  177. package/dist/src/index.js.map +0 -1
  178. package/dist/src/material/blinn.js +0 -81
  179. package/dist/src/material/blinn.js.map +0 -1
  180. package/dist/src/material/grassmaterial.js +0 -113
  181. package/dist/src/material/grassmaterial.js.map +0 -1
  182. package/dist/src/material/lambert.js +0 -92
  183. package/dist/src/material/lambert.js.map +0 -1
  184. package/dist/src/material/material.js +0 -301
  185. package/dist/src/material/material.js.map +0 -1
  186. package/dist/src/material/meshmaterial.js +0 -704
  187. package/dist/src/material/meshmaterial.js.map +0 -1
  188. package/dist/src/material/mixins/albedocolor.js +0 -76
  189. package/dist/src/material/mixins/albedocolor.js.map +0 -1
  190. package/dist/src/material/mixins/foliage.js +0 -47
  191. package/dist/src/material/mixins/foliage.js.map +0 -1
  192. package/dist/src/material/mixins/lightmodel/blinnphong.js +0 -112
  193. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +0 -1
  194. package/dist/src/material/mixins/lightmodel/lambert.js +0 -58
  195. package/dist/src/material/mixins/lightmodel/lambert.js.map +0 -1
  196. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +0 -178
  197. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +0 -1
  198. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +0 -139
  199. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +0 -1
  200. package/dist/src/material/mixins/lit.js +0 -476
  201. package/dist/src/material/mixins/lit.js.map +0 -1
  202. package/dist/src/material/mixins/pbr/common.js +0 -918
  203. package/dist/src/material/mixins/pbr/common.js.map +0 -1
  204. package/dist/src/material/mixins/texture.js +0 -172
  205. package/dist/src/material/mixins/texture.js.map +0 -1
  206. package/dist/src/material/mixins/vertexcolor.js +0 -56
  207. package/dist/src/material/mixins/vertexcolor.js.map +0 -1
  208. package/dist/src/material/particle.js +0 -178
  209. package/dist/src/material/particle.js.map +0 -1
  210. package/dist/src/material/pbrmr.js +0 -97
  211. package/dist/src/material/pbrmr.js.map +0 -1
  212. package/dist/src/material/pbrsg.js +0 -97
  213. package/dist/src/material/pbrsg.js.map +0 -1
  214. package/dist/src/material/shader/helper.js +0 -1209
  215. package/dist/src/material/shader/helper.js.map +0 -1
  216. package/dist/src/material/terrain-cm.js +0 -606
  217. package/dist/src/material/terrain-cm.js.map +0 -1
  218. package/dist/src/material/terrainmaterial.js +0 -375
  219. package/dist/src/material/terrainmaterial.js.map +0 -1
  220. package/dist/src/material/unlit.js +0 -41
  221. package/dist/src/material/unlit.js.map +0 -1
  222. package/dist/src/material/water.js +0 -417
  223. package/dist/src/material/water.js.map +0 -1
  224. package/dist/src/posteffect/bloom.js +0 -361
  225. package/dist/src/posteffect/bloom.js.map +0 -1
  226. package/dist/src/posteffect/compositor.js +0 -226
  227. package/dist/src/posteffect/compositor.js.map +0 -1
  228. package/dist/src/posteffect/fxaa.js +0 -273
  229. package/dist/src/posteffect/fxaa.js.map +0 -1
  230. package/dist/src/posteffect/grayscale.js +0 -69
  231. package/dist/src/posteffect/grayscale.js.map +0 -1
  232. package/dist/src/posteffect/motionblur.js +0 -96
  233. package/dist/src/posteffect/motionblur.js.map +0 -1
  234. package/dist/src/posteffect/posteffect.js +0 -126
  235. package/dist/src/posteffect/posteffect.js.map +0 -1
  236. package/dist/src/posteffect/sao.js +0 -324
  237. package/dist/src/posteffect/sao.js.map +0 -1
  238. package/dist/src/posteffect/ssr.js +0 -489
  239. package/dist/src/posteffect/ssr.js.map +0 -1
  240. package/dist/src/posteffect/taa.js +0 -172
  241. package/dist/src/posteffect/taa.js.map +0 -1
  242. package/dist/src/posteffect/tonemap.js +0 -94
  243. package/dist/src/posteffect/tonemap.js.map +0 -1
  244. package/dist/src/render/abuffer_oit.js +0 -361
  245. package/dist/src/render/abuffer_oit.js.map +0 -1
  246. package/dist/src/render/clipmap.js +0 -851
  247. package/dist/src/render/clipmap.js.map +0 -1
  248. package/dist/src/render/cluster_light.js +0 -333
  249. package/dist/src/render/cluster_light.js.map +0 -1
  250. package/dist/src/render/cull_visitor.js +0 -187
  251. package/dist/src/render/cull_visitor.js.map +0 -1
  252. package/dist/src/render/depthpass.js +0 -68
  253. package/dist/src/render/depthpass.js.map +0 -1
  254. package/dist/src/render/drawable_mixin.js +0 -227
  255. package/dist/src/render/drawable_mixin.js.map +0 -1
  256. package/dist/src/render/envlight.js +0 -463
  257. package/dist/src/render/envlight.js.map +0 -1
  258. package/dist/src/render/fbm_wavegenerator.js +0 -251
  259. package/dist/src/render/fbm_wavegenerator.js.map +0 -1
  260. package/dist/src/render/fft_wavegenerator.js +0 -1006
  261. package/dist/src/render/fft_wavegenerator.js.map +0 -1
  262. package/dist/src/render/fullscreenquad.js +0 -38
  263. package/dist/src/render/fullscreenquad.js.map +0 -1
  264. package/dist/src/render/gerstner_wavegenerator.js +0 -314
  265. package/dist/src/render/gerstner_wavegenerator.js.map +0 -1
  266. package/dist/src/render/globalbindgroup_allocator.js +0 -60
  267. package/dist/src/render/globalbindgroup_allocator.js.map +0 -1
  268. package/dist/src/render/hzb.js +0 -273
  269. package/dist/src/render/hzb.js.map +0 -1
  270. package/dist/src/render/lightpass.js +0 -172
  271. package/dist/src/render/lightpass.js.map +0 -1
  272. package/dist/src/render/objectcolorpass.js +0 -51
  273. package/dist/src/render/objectcolorpass.js.map +0 -1
  274. package/dist/src/render/primitive.js +0 -364
  275. package/dist/src/render/primitive.js.map +0 -1
  276. package/dist/src/render/render_queue.js +0 -467
  277. package/dist/src/render/render_queue.js.map +0 -1
  278. package/dist/src/render/renderbundle_wrapper.js +0 -152
  279. package/dist/src/render/renderbundle_wrapper.js.map +0 -1
  280. package/dist/src/render/renderer.js +0 -455
  281. package/dist/src/render/renderer.js.map +0 -1
  282. package/dist/src/render/renderpass.js +0 -200
  283. package/dist/src/render/renderpass.js.map +0 -1
  284. package/dist/src/render/shadowmap_pass.js +0 -56
  285. package/dist/src/render/shadowmap_pass.js.map +0 -1
  286. package/dist/src/render/sky.js +0 -1103
  287. package/dist/src/render/sky.js.map +0 -1
  288. package/dist/src/render/weightedblended_oit.js +0 -168
  289. package/dist/src/render/weightedblended_oit.js.map +0 -1
  290. package/dist/src/scene/batchgroup.js +0 -162
  291. package/dist/src/scene/batchgroup.js.map +0 -1
  292. package/dist/src/scene/environment.js +0 -209
  293. package/dist/src/scene/environment.js.map +0 -1
  294. package/dist/src/scene/graph_node.js +0 -72
  295. package/dist/src/scene/graph_node.js.map +0 -1
  296. package/dist/src/scene/light.js +0 -416
  297. package/dist/src/scene/light.js.map +0 -1
  298. package/dist/src/scene/mesh.js +0 -341
  299. package/dist/src/scene/mesh.js.map +0 -1
  300. package/dist/src/scene/octree.js +0 -649
  301. package/dist/src/scene/octree.js.map +0 -1
  302. package/dist/src/scene/particlesys.js +0 -738
  303. package/dist/src/scene/particlesys.js.map +0 -1
  304. package/dist/src/scene/raycast_visitor.js +0 -103
  305. package/dist/src/scene/raycast_visitor.js.map +0 -1
  306. package/dist/src/scene/scene.js +0 -284
  307. package/dist/src/scene/scene.js.map +0 -1
  308. package/dist/src/scene/scene_node.js +0 -732
  309. package/dist/src/scene/scene_node.js.map +0 -1
  310. package/dist/src/scene/terrain/grass.js +0 -278
  311. package/dist/src/scene/terrain/grass.js.map +0 -1
  312. package/dist/src/scene/terrain/heightfield.js +0 -475
  313. package/dist/src/scene/terrain/heightfield.js.map +0 -1
  314. package/dist/src/scene/terrain/patch.js +0 -530
  315. package/dist/src/scene/terrain/patch.js.map +0 -1
  316. package/dist/src/scene/terrain/quadtree.js +0 -461
  317. package/dist/src/scene/terrain/quadtree.js.map +0 -1
  318. package/dist/src/scene/terrain/terrain.js +0 -246
  319. package/dist/src/scene/terrain/terrain.js.map +0 -1
  320. package/dist/src/scene/terrain-cm/grass.js +0 -594
  321. package/dist/src/scene/terrain-cm/grass.js.map +0 -1
  322. package/dist/src/scene/terrain-cm/grassmaterial.js +0 -159
  323. package/dist/src/scene/terrain-cm/grassmaterial.js.map +0 -1
  324. package/dist/src/scene/terrain-cm/terrain-cm.js +0 -538
  325. package/dist/src/scene/terrain-cm/terrain-cm.js.map +0 -1
  326. package/dist/src/scene/water.js +0 -374
  327. package/dist/src/scene/water.js.map +0 -1
  328. package/dist/src/shaders/atmosphere.js +0 -957
  329. package/dist/src/shaders/atmosphere.js.map +0 -1
  330. package/dist/src/shaders/fog.js +0 -112
  331. package/dist/src/shaders/fog.js.map +0 -1
  332. package/dist/src/shaders/misc.js +0 -266
  333. package/dist/src/shaders/misc.js.map +0 -1
  334. package/dist/src/shaders/noise.js +0 -222
  335. package/dist/src/shaders/noise.js.map +0 -1
  336. package/dist/src/shaders/pbr.js +0 -51
  337. package/dist/src/shaders/pbr.js.map +0 -1
  338. package/dist/src/shaders/shadow.js +0 -636
  339. package/dist/src/shaders/shadow.js.map +0 -1
  340. package/dist/src/shaders/ssr.js +0 -490
  341. package/dist/src/shaders/ssr.js.map +0 -1
  342. package/dist/src/shaders/temporal.js +0 -215
  343. package/dist/src/shaders/temporal.js.map +0 -1
  344. package/dist/src/shaders/water.js +0 -756
  345. package/dist/src/shaders/water.js.map +0 -1
  346. package/dist/src/shadow/esm.js +0 -237
  347. package/dist/src/shadow/esm.js.map +0 -1
  348. package/dist/src/shadow/pcf_opt.js +0 -181
  349. package/dist/src/shadow/pcf_opt.js.map +0 -1
  350. package/dist/src/shadow/pcf_pd.js +0 -189
  351. package/dist/src/shadow/pcf_pd.js.map +0 -1
  352. package/dist/src/shadow/shader.js +0 -37
  353. package/dist/src/shadow/shader.js.map +0 -1
  354. package/dist/src/shadow/shadow_impl.js +0 -15
  355. package/dist/src/shadow/shadow_impl.js.map +0 -1
  356. package/dist/src/shadow/shadowmapper.js +0 -790
  357. package/dist/src/shadow/shadowmapper.js.map +0 -1
  358. package/dist/src/shadow/ssm.js +0 -159
  359. package/dist/src/shadow/ssm.js.map +0 -1
  360. package/dist/src/shadow/vsm.js +0 -297
  361. package/dist/src/shadow/vsm.js.map +0 -1
  362. package/dist/src/shapes/box.js +0 -386
  363. package/dist/src/shapes/box.js.map +0 -1
  364. package/dist/src/shapes/cylinder.js +0 -125
  365. package/dist/src/shapes/cylinder.js.map +0 -1
  366. package/dist/src/shapes/plane.js +0 -88
  367. package/dist/src/shapes/plane.js.map +0 -1
  368. package/dist/src/shapes/shape.js +0 -87
  369. package/dist/src/shapes/shape.js.map +0 -1
  370. package/dist/src/shapes/sphere.js +0 -114
  371. package/dist/src/shapes/sphere.js.map +0 -1
  372. package/dist/src/shapes/tetrahedron.js +0 -188
  373. package/dist/src/shapes/tetrahedron.js.map +0 -1
  374. package/dist/src/shapes/torus.js +0 -111
  375. package/dist/src/shapes/torus.js.map +0 -1
  376. package/dist/src/utility/aabbtree.js +0 -400
  377. package/dist/src/utility/aabbtree.js.map +0 -1
  378. package/dist/src/utility/bounding_volume.js +0 -29
  379. package/dist/src/utility/bounding_volume.js.map +0 -1
  380. package/dist/src/utility/debug.js +0 -28
  381. package/dist/src/utility/debug.js.map +0 -1
  382. package/dist/src/utility/draco/decoder.js +0 -116
  383. package/dist/src/utility/draco/decoder.js.map +0 -1
  384. package/dist/src/utility/misc.js +0 -105
  385. package/dist/src/utility/misc.js.map +0 -1
  386. package/dist/src/utility/panorama.js +0 -163
  387. package/dist/src/utility/panorama.js.map +0 -1
  388. package/dist/src/utility/pmrem.js +0 -354
  389. package/dist/src/utility/pmrem.js.map +0 -1
  390. package/dist/src/utility/rendermipmap.js +0 -115
  391. package/dist/src/utility/rendermipmap.js.map +0 -1
  392. package/dist/src/utility/serialization/json.js +0 -402
  393. package/dist/src/utility/serialization/json.js.map +0 -1
  394. package/dist/src/utility/serialization/manager.js +0 -623
  395. package/dist/src/utility/serialization/manager.js.map +0 -1
  396. package/dist/src/utility/serialization/scene/animation.js +0 -248
  397. package/dist/src/utility/serialization/scene/animation.js.map +0 -1
  398. package/dist/src/utility/serialization/scene/batch.js +0 -59
  399. package/dist/src/utility/serialization/scene/batch.js.map +0 -1
  400. package/dist/src/utility/serialization/scene/camera.js +0 -790
  401. package/dist/src/utility/serialization/scene/camera.js.map +0 -1
  402. package/dist/src/utility/serialization/scene/common.js +0 -222
  403. package/dist/src/utility/serialization/scene/common.js.map +0 -1
  404. package/dist/src/utility/serialization/scene/light.js +0 -575
  405. package/dist/src/utility/serialization/scene/light.js.map +0 -1
  406. package/dist/src/utility/serialization/scene/material.js +0 -1111
  407. package/dist/src/utility/serialization/scene/material.js.map +0 -1
  408. package/dist/src/utility/serialization/scene/mesh.js +0 -148
  409. package/dist/src/utility/serialization/scene/mesh.js.map +0 -1
  410. package/dist/src/utility/serialization/scene/misc.js +0 -39
  411. package/dist/src/utility/serialization/scene/misc.js.map +0 -1
  412. package/dist/src/utility/serialization/scene/node.js +0 -451
  413. package/dist/src/utility/serialization/scene/node.js.map +0 -1
  414. package/dist/src/utility/serialization/scene/particle.js +0 -425
  415. package/dist/src/utility/serialization/scene/particle.js.map +0 -1
  416. package/dist/src/utility/serialization/scene/primitive.js +0 -692
  417. package/dist/src/utility/serialization/scene/primitive.js.map +0 -1
  418. package/dist/src/utility/serialization/scene/scene.js +0 -704
  419. package/dist/src/utility/serialization/scene/scene.js.map +0 -1
  420. package/dist/src/utility/serialization/scene/terrain.js +0 -488
  421. package/dist/src/utility/serialization/scene/terrain.js.map +0 -1
  422. package/dist/src/utility/serialization/scene/water.js +0 -465
  423. package/dist/src/utility/serialization/scene/water.js.map +0 -1
  424. package/dist/src/utility/shprojector.js +0 -297
  425. package/dist/src/utility/shprojector.js.map +0 -1
  426. package/dist/src/utility/textures/ggxlut.js +0 -213
  427. package/dist/src/utility/textures/ggxlut.js.map +0 -1
  428. package/dist/src/utility/textures/gradientnoise.js +0 -62
  429. package/dist/src/utility/textures/gradientnoise.js.map +0 -1
  430. package/dist/src/utility/textures/randomnoise.js +0 -41
  431. package/dist/src/utility/textures/randomnoise.js.map +0 -1
  432. package/dist/src/values.js +0 -162
  433. package/dist/src/values.js.map +0 -1
  434. package/dist/utility/blueprint/material/common.js +0 -7
  435. package/dist/utility/blueprint/material/common.js.map +0 -1
  436. package/dist/utility/serialization/blueprint/constants.js +0 -255
  437. package/dist/utility/serialization/blueprint/constants.js.map +0 -1
  438. package/dist/utility/serialization/blueprint/material/constants.js +0 -203
  439. package/dist/utility/serialization/blueprint/material/constants.js.map +0 -1
  440. package/dist/utility/serialization/blueprint/material/texture.js +0 -165
  441. package/dist/utility/serialization/blueprint/material/texture.js.map +0 -1
@@ -0,0 +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,GA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C,GAAGZ,IAAAA,CAAKW,CAAC,GAAGF,WAAAA,GAAcT,KAAKa,CAAC,GAAGL,GAAE,CAC7DtB,GAAAA,YAAAA,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;;;;"}
@@ -0,0 +1,163 @@
1
+ import { Vector3, Quaternion } from '@zephyr3d/base';
2
+ import { IKUtils } from './ik_utils.js';
3
+
4
+ /**
5
+ * Represents a chain of joints for IK solving.
6
+ *
7
+ * @public
8
+ */ class IKChain {
9
+ /** Array of joints in the chain (root to end effector) */ _joints;
10
+ /** Total length of the chain */ _totalLength;
11
+ /** Constraints applied to joints */ _constraints;
12
+ /**
13
+ * Create an IK chain from an array of scene nodes.
14
+ *
15
+ * @param nodes - Array of scene nodes from root to end effector
16
+ */ constructor(nodes){
17
+ if (nodes.length < 2) {
18
+ throw new Error('IK chain must have at least 2 joints');
19
+ }
20
+ this._joints = [];
21
+ this._totalLength = 0;
22
+ this._constraints = [];
23
+ // Create joints from nodes
24
+ for(let i = 0; i < nodes.length; i++){
25
+ const node = nodes[i];
26
+ const position = new Vector3();
27
+ const rotation = new Quaternion();
28
+ node.worldMatrix.decompose(null, rotation, position);
29
+ let boneLength = 0;
30
+ if (i < nodes.length - 1) {
31
+ const nextPosition = new Vector3();
32
+ nodes[i + 1].worldMatrix.decompose(null, null, nextPosition);
33
+ boneLength = IKUtils.calculateBoneLength(position, nextPosition);
34
+ this._totalLength += boneLength;
35
+ }
36
+ this._joints.push({
37
+ node,
38
+ position: position.clone(),
39
+ originalPosition: position.clone(),
40
+ rotation: rotation.clone(),
41
+ originalRotation: rotation.clone(),
42
+ boneLength
43
+ });
44
+ }
45
+ }
46
+ /**
47
+ * Create an IK chain by traversing from a start node to an end node.
48
+ *
49
+ * @remarks
50
+ * This method walks up the parent chain from the end node until it
51
+ * reaches the start node, building the joint chain in the process.
52
+ *
53
+ * @param startNode - The root joint of the chain
54
+ * @param endNode - The end effector joint
55
+ * @returns The created IK chain
56
+ */ static fromNodeHierarchy(startNode, endNode) {
57
+ const nodes = [];
58
+ let current = endNode;
59
+ // Walk up the hierarchy from end to start
60
+ while(current){
61
+ nodes.unshift(current); // Add to front
62
+ if (current === startNode) {
63
+ break;
64
+ }
65
+ current = current.parent;
66
+ }
67
+ if (nodes[0] !== startNode) {
68
+ throw new Error('End node is not a descendant of start node');
69
+ }
70
+ if (nodes.length < 2) {
71
+ throw new Error('IK chain must have at least 2 joints');
72
+ }
73
+ return new IKChain(nodes);
74
+ }
75
+ /**
76
+ * Get all joints in the chain.
77
+ */ get joints() {
78
+ return this._joints;
79
+ }
80
+ /**
81
+ * Get the root joint (first joint in the chain).
82
+ */ get root() {
83
+ return this._joints[0];
84
+ }
85
+ /**
86
+ * Get the end effector (last joint in the chain).
87
+ */ get endEffector() {
88
+ return this._joints[this._joints.length - 1];
89
+ }
90
+ /**
91
+ * Get the total length of the chain.
92
+ */ get totalLength() {
93
+ return this._totalLength;
94
+ }
95
+ /**
96
+ * Get the number of joints in the chain.
97
+ */ get length() {
98
+ return this._joints.length;
99
+ }
100
+ /**
101
+ * Update joint positions from their scene nodes.
102
+ */ updateFromNodes() {
103
+ for (const joint of this._joints){
104
+ joint.node.worldMatrix.decompose(null, joint.rotation, joint.position);
105
+ }
106
+ }
107
+ /**
108
+ * Store current positions as original positions.
109
+ */ storeOriginalPositions() {
110
+ for (const joint of this._joints){
111
+ joint.originalPosition.set(joint.position);
112
+ joint.originalRotation.set(joint.rotation);
113
+ }
114
+ }
115
+ /**
116
+ * Restore joints to their original positions.
117
+ */ restoreOriginalPositions() {
118
+ for (const joint of this._joints){
119
+ joint.position.set(joint.originalPosition);
120
+ joint.rotation.set(joint.originalRotation);
121
+ }
122
+ }
123
+ /**
124
+ * Add a constraint to a specific joint.
125
+ *
126
+ * @param constraint - The constraint to add
127
+ */ addConstraint(constraint) {
128
+ this._constraints.push(constraint);
129
+ }
130
+ /**
131
+ * Remove a constraint from the chain.
132
+ *
133
+ * @param constraint - The constraint to remove
134
+ * @returns True if the constraint was found and removed
135
+ */ removeConstraint(constraint) {
136
+ const index = this._constraints.indexOf(constraint);
137
+ if (index >= 0) {
138
+ this._constraints.splice(index, 1);
139
+ return true;
140
+ }
141
+ return false;
142
+ }
143
+ /**
144
+ * Clear all constraints from the chain.
145
+ */ clearConstraints() {
146
+ this._constraints = [];
147
+ }
148
+ /**
149
+ * Get all constraints in the chain.
150
+ */ get constraints() {
151
+ return this._constraints;
152
+ }
153
+ /**
154
+ * Apply all constraints to the joint chain.
155
+ */ applyConstraints() {
156
+ for (const constraint of this._constraints){
157
+ constraint.apply(this._joints);
158
+ }
159
+ }
160
+ }
161
+
162
+ export { IKChain };
163
+ //# sourceMappingURL=ik_chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ik_chain.js","sources":["../../../src/animation/ik/ik_chain.ts"],"sourcesContent":["import { Vector3, Quaternion } from '@zephyr3d/base';\r\nimport type { IKJoint } from './ik_joint';\r\nimport type { SceneNode } from '../../scene/scene_node';\r\nimport type { IKConstraint } from './ik_constraint';\r\nimport { IKUtils } from './ik_utils';\r\n\r\n/**\r\n * Represents a chain of joints for IK solving.\r\n *\r\n * @public\r\n */\r\nexport class IKChain {\r\n /** Array of joints in the chain (root to end effector) */\r\n private _joints: IKJoint[];\r\n /** Total length of the chain */\r\n private _totalLength: number;\r\n /** Constraints applied to joints */\r\n private _constraints: IKConstraint[];\r\n\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 */\r\n constructor(nodes: SceneNode[]) {\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 this._joints = [];\r\n this._totalLength = 0;\r\n this._constraints = [];\r\n\r\n // Create joints from nodes\r\n for (let i = 0; i < nodes.length; i++) {\r\n const node = nodes[i];\r\n const position = new Vector3();\r\n const rotation = new Quaternion();\r\n node.worldMatrix.decompose(null, rotation, position);\r\n\r\n let boneLength = 0;\r\n if (i < nodes.length - 1) {\r\n const nextPosition = new Vector3();\r\n nodes[i + 1].worldMatrix.decompose(null, null, nextPosition);\r\n boneLength = IKUtils.calculateBoneLength(position, nextPosition);\r\n this._totalLength += boneLength;\r\n }\r\n\r\n this._joints.push({\r\n node,\r\n position: position.clone(),\r\n originalPosition: position.clone(),\r\n rotation: rotation.clone(),\r\n originalRotation: rotation.clone(),\r\n boneLength\r\n });\r\n }\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 /**\r\n * Get all joints in the chain.\r\n */\r\n get joints(): IKJoint[] {\r\n return this._joints;\r\n }\r\n\r\n /**\r\n * Get the root joint (first joint in the chain).\r\n */\r\n get root(): IKJoint {\r\n return this._joints[0];\r\n }\r\n\r\n /**\r\n * Get the end effector (last joint in the chain).\r\n */\r\n get endEffector(): IKJoint {\r\n return this._joints[this._joints.length - 1];\r\n }\r\n\r\n /**\r\n * Get the total length of the chain.\r\n */\r\n get totalLength(): number {\r\n return this._totalLength;\r\n }\r\n\r\n /**\r\n * Get the number of joints in the chain.\r\n */\r\n get length(): number {\r\n return this._joints.length;\r\n }\r\n\r\n /**\r\n * Update joint positions from their scene nodes.\r\n */\r\n updateFromNodes(): void {\r\n for (const joint of this._joints) {\r\n joint.node.worldMatrix.decompose(null, joint.rotation, joint.position);\r\n }\r\n }\r\n\r\n /**\r\n * Store current positions as original positions.\r\n */\r\n storeOriginalPositions(): void {\r\n for (const joint of this._joints) {\r\n joint.originalPosition.set(joint.position);\r\n joint.originalRotation.set(joint.rotation);\r\n }\r\n }\r\n\r\n /**\r\n * Restore joints to their original positions.\r\n */\r\n restoreOriginalPositions(): void {\r\n for (const joint of this._joints) {\r\n joint.position.set(joint.originalPosition);\r\n joint.rotation.set(joint.originalRotation);\r\n }\r\n }\r\n\r\n /**\r\n * Add a constraint to a specific joint.\r\n *\r\n * @param constraint - The constraint to add\r\n */\r\n addConstraint(constraint: IKConstraint): void {\r\n this._constraints.push(constraint);\r\n }\r\n\r\n /**\r\n * Remove a constraint from the chain.\r\n *\r\n * @param constraint - The constraint to remove\r\n * @returns True if the constraint was found and removed\r\n */\r\n removeConstraint(constraint: IKConstraint): boolean {\r\n const index = this._constraints.indexOf(constraint);\r\n if (index >= 0) {\r\n this._constraints.splice(index, 1);\r\n return true;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * Clear all constraints from the chain.\r\n */\r\n clearConstraints(): void {\r\n this._constraints = [];\r\n }\r\n\r\n /**\r\n * Get all constraints in the chain.\r\n */\r\n get constraints(): readonly IKConstraint[] {\r\n return this._constraints;\r\n }\r\n\r\n /**\r\n * Apply all constraints to the joint chain.\r\n */\r\n applyConstraints(): void {\r\n for (const constraint of this._constraints) {\r\n constraint.apply(this._joints);\r\n }\r\n }\r\n}\r\n"],"names":["IKChain","nodes","length","Error","_joints","_totalLength","_constraints","i","node","position","Vector3","rotation","Quaternion","worldMatrix","decompose","boneLength","nextPosition","IKUtils","calculateBoneLength","push","clone","originalPosition","originalRotation","fromNodeHierarchy","startNode","endNode","current","unshift","parent","joints","root","endEffector","totalLength","updateFromNodes","joint","storeOriginalPositions","set","restoreOriginalPositions","addConstraint","constraint","removeConstraint","index","indexOf","splice","clearConstraints","constraints","applyConstraints","apply"],"mappings":";;;AAMA;;;;AAIC,IACM,MAAMA,OAAAA,CAAAA;+DAEX,OAA2B;qCAE3B,YAA6B;yCAE7B,YAAqC;AAErC;;;;MAKA,WAAA,CAAYC,KAAkB,CAAE;QAC9B,IAAIA,KAAAA,CAAMC,MAAM,GAAG,CAAG,EAAA;AACpB,YAAA,MAAM,IAAIC,KAAM,CAAA,sCAAA,CAAA;AAClB;QAEA,IAAI,CAACC,OAAO,GAAG,EAAE;QACjB,IAAI,CAACC,YAAY,GAAG,CAAA;QACpB,IAAI,CAACC,YAAY,GAAG,E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A;AAC/B;AACF;AACF;;;;"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Base class for IK constraints.
3
+ *
4
+ * Constraints are applied after each FABRIK iteration to enforce
5
+ * joint limitations (angle limits, pole vectors, etc.).
6
+ *
7
+ * @public
8
+ */ class IKConstraint {
9
+ /** The joint index this constraint applies to */ _jointIndex;
10
+ /**
11
+ * Create an IK constraint.
12
+ *
13
+ * @param jointIndex - Index of the joint in the chain (0 = root)
14
+ */ constructor(jointIndex){
15
+ this._jointIndex = jointIndex;
16
+ }
17
+ /**
18
+ * Get the joint index this constraint applies to.
19
+ */ get jointIndex() {
20
+ return this._jointIndex;
21
+ }
22
+ }
23
+
24
+ export { IKConstraint };
25
+ //# sourceMappingURL=ik_constraint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ik_constraint.js","sources":["../../../src/animation/ik/ik_constraint.ts"],"sourcesContent":["import type { IKJoint } from './ik_joint';\r\n\r\n/**\r\n * Base class for IK constraints.\r\n *\r\n * Constraints are applied after each FABRIK iteration to enforce\r\n * joint limitations (angle limits, pole vectors, etc.).\r\n *\r\n * @public\r\n */\r\nexport abstract class IKConstraint {\r\n /** The joint index this constraint applies to */\r\n protected _jointIndex: number;\r\n\r\n /**\r\n * Create an IK constraint.\r\n *\r\n * @param jointIndex - Index of the joint in the chain (0 = root)\r\n */\r\n constructor(jointIndex: number) {\r\n this._jointIndex = jointIndex;\r\n }\r\n\r\n /**\r\n * Get the joint index this constraint applies to.\r\n */\r\n get jointIndex(): number {\r\n return this._jointIndex;\r\n }\r\n\r\n /**\r\n * Apply the constraint to the joint chain.\r\n *\r\n * This method modifies joint positions to satisfy the constraint.\r\n *\r\n * @param joints - Array of all joints in the chain\r\n */\r\n abstract apply(joints: IKJoint[]): void;\r\n}\r\n\r\n/**\r\n * Twist constraint configuration for a joint.\r\n *\r\n * @public\r\n */\r\nexport interface TwistConstraint {\r\n /** Minimum twist angle in radians */\r\n minTwist: number;\r\n /** Maximum twist angle in radians */\r\n maxTwist: number;\r\n /** Smoothing factor [0-1], 0 = no smoothing, 1 = full smoothing */\r\n smoothFactor: number;\r\n}\r\n"],"names":["IKConstraint","jointIndex","_jointIndex"],"mappings":"AAEA;;;;;;;AAOC,IACM,MAAeA,YAAAA,CAAAA;sDAEpB,WAA8B;AAE9B;;;;MAKA,WAAA,CAAYC,UAAkB,CAAE;QAC9B,IAAI,CAACC,WAAW,GAAGD,UAAAA;AACrB;AAEA;;AAEC,MACD,IAAIA,UAAqB,GAAA;QACvB,OAAO,IAAI,CAACC,WAAW;AACzB;AAUF;;;;"}
@@ -0,0 +1,128 @@
1
+ import { Vector3 } from '@zephyr3d/base';
2
+ import { IKConstraint } from './ik_constraint.js';
3
+
4
+ /**
5
+ * Pole vector constraint for IK chains.
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.
14
+ *
15
+ * @remarks
16
+ * This is commonly used for arms and legs to control which direction
17
+ * the elbow or knee points. For example, ensuring an elbow points
18
+ * backward or a knee points forward.
19
+ *
20
+ * The pole vector defines a plane, and the middle joint is constrained
21
+ * to lie on this plane.
22
+ *
23
+ * @public
24
+ */ class IKPoleVectorConstraint extends IKConstraint {
25
+ /** The pole vector position in world space */ _poleVector;
26
+ /** Weight of the constraint (0 = no effect, 1 = full effect) */ _weight;
27
+ /**
28
+ * Create a pole vector constraint.
29
+ *
30
+ * @param jointIndex - Index of the middle joint to constrain (typically elbow or knee)
31
+ * @param poleVector - Position in world space that the joint should point toward
32
+ * @param weight - Constraint weight (0-1, default: 1)
33
+ */ constructor(jointIndex, poleVector, weight = 1){
34
+ super(jointIndex);
35
+ this._poleVector = poleVector.clone();
36
+ this._weight = Math.max(0, Math.min(1, weight));
37
+ }
38
+ /**
39
+ * Get the pole vector position.
40
+ */ get poleVector() {
41
+ return this._poleVector;
42
+ }
43
+ /**
44
+ * Set the pole vector position.
45
+ */ set poleVector(value) {
46
+ this._poleVector.set(value);
47
+ }
48
+ /**
49
+ * Get the constraint weight.
50
+ */ get weight() {
51
+ return this._weight;
52
+ }
53
+ /**
54
+ * Set the constraint weight (0-1).
55
+ */ set weight(value) {
56
+ this._weight = Math.max(0, Math.min(1, value));
57
+ }
58
+ /**
59
+ * Apply the pole vector constraint.
60
+ *
61
+ * This adjusts the middle joint position to align with the pole vector
62
+ * while maintaining bone lengths.
63
+ */ apply(joints) {
64
+ const index = this._jointIndex;
65
+ // Need at least 3 joints (parent, this, child)
66
+ if (index < 1 || index >= joints.length - 1) {
67
+ return;
68
+ }
69
+ if (this._weight < 0.001) {
70
+ return; // No effect
71
+ }
72
+ const parentJoint = joints[index - 1];
73
+ const currentJoint = joints[index];
74
+ const childJoint = joints[index + 1];
75
+ // Calculate the plane defined by parent, child, and pole vector
76
+ const parentPos = parentJoint.position;
77
+ const childPos = childJoint.position;
78
+ const currentPos = currentJoint.position;
79
+ // Vector from parent to child (the "line" we're bending around)
80
+ const parentToChild = Vector3.sub(childPos, parentPos, new Vector3());
81
+ const lineLength = parentToChild.magnitude;
82
+ if (lineLength < 0.000001) {
83
+ return; // Parent and child are at same position
84
+ }
85
+ const lineDir = Vector3.scale(parentToChild, 1 / lineLength, new Vector3());
86
+ // Project current joint onto the parent-child line
87
+ const parentToCurrent = Vector3.sub(currentPos, parentPos, new Vector3());
88
+ const projectionLength = Vector3.dot(parentToCurrent, lineDir);
89
+ const projectionPoint = Vector3.scale(lineDir, projectionLength, new Vector3());
90
+ projectionPoint.addBy(parentPos);
91
+ // Vector from projection point to current joint (perpendicular to line)
92
+ const perpendicular = Vector3.sub(currentPos, projectionPoint, new Vector3());
93
+ const perpLength = perpendicular.magnitude;
94
+ if (perpLength < 0.000001) {
95
+ return; // Current joint is on the line
96
+ }
97
+ // Calculate desired direction toward pole vector
98
+ const parentToPole = Vector3.sub(this._poleVector, parentPos, new Vector3());
99
+ const poleProjectionLength = Vector3.dot(parentToPole, lineDir);
100
+ const poleProjectionPoint = Vector3.scale(lineDir, poleProjectionLength, new Vector3());
101
+ poleProjectionPoint.addBy(parentPos);
102
+ // Direction from projection to pole (perpendicular to line)
103
+ const poleDirection = Vector3.sub(this._poleVector, poleProjectionPoint, new Vector3());
104
+ const poleDirLength = poleDirection.magnitude;
105
+ if (poleDirLength < 0.000001) {
106
+ return; // Pole is on the line
107
+ }
108
+ poleDirection.scaleBy(1 / poleDirLength);
109
+ // Calculate new position for current joint
110
+ // Keep the same distance from the line, but rotate toward pole direction
111
+ const desiredPerpendicular = Vector3.scale(poleDirection, perpLength, new Vector3());
112
+ const newPosition = Vector3.add(projectionPoint, desiredPerpendicular, new Vector3());
113
+ // Apply weight (blend between original and constrained position)
114
+ if (this._weight < 0.999) {
115
+ // Manual lerp: result = a + (b - a) * t
116
+ const blended = new Vector3();
117
+ blended.x = currentPos.x + (newPosition.x - currentPos.x) * this._weight;
118
+ blended.y = currentPos.y + (newPosition.y - currentPos.y) * this._weight;
119
+ blended.z = currentPos.z + (newPosition.z - currentPos.z) * this._weight;
120
+ currentJoint.position.set(blended);
121
+ } else {
122
+ currentJoint.position.set(newPosition);
123
+ }
124
+ }
125
+ }
126
+
127
+ export { IKPoleVectorConstraint };
128
+ //# sourceMappingURL=ik_pole_constraint.js.map
@@ -0,0 +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,GAAG,CAAC,CAAGN,EAAAA,MAAAA,CAAAA,CAAAA;AACzC;AAEA;;AAEC,MACD,IAAID,UAAsB,GAAA;QACxB,OAAO,IAAI,CAACE,WAAW;AACzB;AAEA;;MAGA,IAAIF,UAAWQ,CAAAA,KAAc,EAAE;AAC7B,QAAA,IAAI,CAACN,WAAW,CAACO,GAAG,CAACD,KAAAA,CAAAA;AACvB;AAEA;;AAEC,MACD,IAAIP,MAAiB,GAAA;Q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AA,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;;;;"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Base class for IK solvers.
3
+ *
4
+ * @public
5
+ */ class IKSolver {
6
+ /** The IK chain to solve */ _chain;
7
+ /** Maximum number of iterations */ _maxIterations;
8
+ /** Convergence tolerance (distance threshold) */ _tolerance;
9
+ /**
10
+ * Create an IK solver.
11
+ *
12
+ * @param chain - The IK chain to solve
13
+ * @param maxIterations - Maximum number of iterations (default: 10)
14
+ * @param tolerance - Convergence tolerance in world units (default: 0.001)
15
+ */ constructor(chain, maxIterations = 10, tolerance = 0.001){
16
+ this._chain = chain;
17
+ this._maxIterations = maxIterations;
18
+ this._tolerance = tolerance;
19
+ }
20
+ /**
21
+ * Get the IK chain.
22
+ */ get chain() {
23
+ return this._chain;
24
+ }
25
+ /**
26
+ * Set maximum number of iterations.
27
+ */ setMaxIterations(value) {
28
+ this._maxIterations = Math.max(1, value);
29
+ }
30
+ /**
31
+ * Get maximum number of iterations.
32
+ */ getMaxIterations() {
33
+ return this._maxIterations;
34
+ }
35
+ /**
36
+ * Set convergence tolerance.
37
+ */ setTolerance(value) {
38
+ this._tolerance = Math.max(0, value);
39
+ }
40
+ /**
41
+ * Get convergence tolerance.
42
+ */ getTolerance() {
43
+ return this._tolerance;
44
+ }
45
+ }
46
+
47
+ export { IKSolver };
48
+ //# sourceMappingURL=ik_solver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ik_solver.js","sources":["../../../src/animation/ik/ik_solver.ts"],"sourcesContent":["import type { Vector3 } from '@zephyr3d/base';\r\nimport type { IKChain } from './ik_chain';\r\n\r\n/**\r\n * Base class for IK solvers.\r\n *\r\n * @public\r\n */\r\nexport abstract class IKSolver {\r\n /** The IK chain to solve */\r\n protected _chain: IKChain;\r\n /** Maximum number of iterations */\r\n protected _maxIterations: number;\r\n /** Convergence tolerance (distance threshold) */\r\n protected _tolerance: number;\r\n\r\n /**\r\n * Create an IK solver.\r\n *\r\n * @param chain - The IK chain to solve\r\n * @param maxIterations - Maximum number of iterations (default: 10)\r\n * @param tolerance - Convergence tolerance in world units (default: 0.001)\r\n */\r\n constructor(chain: IKChain, maxIterations = 10, tolerance = 0.001) {\r\n this._chain = chain;\r\n this._maxIterations = maxIterations;\r\n this._tolerance = tolerance;\r\n }\r\n\r\n /**\r\n * Get the IK chain.\r\n */\r\n get chain(): IKChain {\r\n return this._chain;\r\n }\r\n\r\n /**\r\n * Set maximum number of iterations.\r\n */\r\n setMaxIterations(value: number): void {\r\n this._maxIterations = Math.max(1, value);\r\n }\r\n\r\n /**\r\n * Get maximum number of iterations.\r\n */\r\n getMaxIterations(): number {\r\n return this._maxIterations;\r\n }\r\n\r\n /**\r\n * Set convergence tolerance.\r\n */\r\n setTolerance(value: number): void {\r\n this._tolerance = Math.max(0, value);\r\n }\r\n\r\n /**\r\n * Get convergence tolerance.\r\n */\r\n getTolerance(): number {\r\n return this._tolerance;\r\n }\r\n\r\n /**\r\n * Solve the IK chain to reach the target position.\r\n *\r\n * @param target - Target position for the end effector\r\n * @returns True if converged, false otherwise\r\n */\r\n abstract solve(target: Vector3): boolean;\r\n\r\n /**\r\n * Apply the solved positions to the scene nodes as rotations.\r\n *\r\n * @param weight - Blend weight (0 = original, 1 = full IK)\r\n */\r\n abstract applyToNodes(weight?: number): void;\r\n}\r\n"],"names":["IKSolver","chain","maxIterations","tolerance","_chain","_maxIterations","_tolerance","setMaxIterations","value","Math","max","getMaxIterations","setTolerance","getTolerance"],"mappings":"AAGA;;;;AAIC,IACM,MAAeA,QAAAA,CAAAA;iCAEpB,MAA0B;wCAE1B,cAAiC;sDAEjC,UAA6B;AAE7B;;;;;;MAOA,WAAA,CAAYC,KAAc,EAAEC,aAAAA,GAAgB,EAAE,EAAEC,SAAAA,GAAY,KAAK,CAAE;QACjE,IAAI,CAACC,MAAM,GAAGH,KAAAA;QACd,IAAI,CAACI,cAAc,GAAGH,aAAAA;QACtB,IAAI,CAACI,UAAU,GAAGH,SAAAA;AACpB;AAEA;;AAEC,MACD,IAAIF,KAAiB,GAAA;QACnB,OAAO,IAAI,CAACG,MAAM;AACpB;AAEA;;MAGAG,gBAAAA,CAAiBC,KAAa,EAAQ;AACpC,QAAA,IAAI,CAACH,cAAc,GAAGI,IAAKC,CAAAA,GAAG,CAAC,CAAGF,EAAAA,KAAAA,CAAAA;AACpC;AAEA;;AAEC,MACDG,gBAA2B,GAAA;QACzB,OAAO,IAAI,CAACN,cAAc;AAC5B;AAEA;;MAGAO,YAAAA,CAAaJ,KAAa,EAAQ;AAChC,QAAA,IAAI,CAACF,UAAU,GAAGG,IAAKC,CAAAA,GAAG,CAAC,CAAGF,EAAAA,KAAAA,CAAAA;AAChC;AAEA;;AAEC,MACDK,YAAuB,GAAA;QACrB,OAAO,IAAI,CAACP,UAAU;AACxB;AAgBF;;;;"}
@@ -0,0 +1,96 @@
1
+ import { Quaternion } from '@zephyr3d/base';
2
+ import { AnimationTrack } from '../animationtrack.js';
3
+
4
+ /**
5
+ * Animation track that applies IK solving.
6
+ *
7
+ * @remarks
8
+ * This track integrates IK solving into the animation system, allowing
9
+ * IK to be blended with other animations. The track solves the IK chain
10
+ * each frame and produces joint rotations that can be mixed with other
11
+ * animation tracks.
12
+ *
13
+ * @public
14
+ */ class IKTrack extends AnimationTrack {
15
+ /** The IK solver */ _solver;
16
+ /** Cached state for reuse */ _state;
17
+ /** Duration of the track (can be infinite for procedural IK) */ _duration;
18
+ /**
19
+ * Create an IK animation track.
20
+ *
21
+ * @param solver - The FABRIK solver to use
22
+ * @param duration - Duration of the track in seconds (default: Infinity for procedural)
23
+ */ constructor(solver, duration = Infinity){
24
+ super(false);
25
+ this._solver = solver;
26
+ this._duration = duration;
27
+ // Initialize state with identity rotations
28
+ const numJoints = solver.chain.joints.length - 1; // Exclude end effector
29
+ this._state = {
30
+ rotations: Array.from({
31
+ length: numJoints
32
+ }, ()=>new Quaternion())
33
+ };
34
+ }
35
+ /**
36
+ * Get the IK solver.
37
+ */ get solver() {
38
+ return this._solver;
39
+ }
40
+ /**
41
+ * Set the duration of the track.
42
+ */ setDuration(duration) {
43
+ this._duration = Math.max(0, duration);
44
+ }
45
+ /**
46
+ * Calculate IK state at the given time.
47
+ *
48
+ * @remarks
49
+ * For procedural IK, the time parameter is typically ignored.
50
+ * The solver uses the current target position set externally.
51
+ */ calculateState(_target, _currentTime) {
52
+ const joints = this._solver.chain.joints;
53
+ // Store current rotations as the calculated state
54
+ for(let i = 0; i < joints.length - 1; i++){
55
+ this._state.rotations[i].set(joints[i].rotation);
56
+ }
57
+ return this._state;
58
+ }
59
+ /**
60
+ * Apply IK state to the target scene nodes.
61
+ */ applyState(_target, state) {
62
+ const joints = this._solver.chain.joints;
63
+ // Apply rotations to scene nodes
64
+ for(let i = 0; i < state.rotations.length && i < joints.length - 1; i++){
65
+ joints[i].node.rotation = state.rotations[i];
66
+ }
67
+ }
68
+ /**
69
+ * Mix two IK states using spherical interpolation.
70
+ */ mixState(a, b, t) {
71
+ const result = {
72
+ rotations: []
73
+ };
74
+ const count = Math.min(a.rotations.length, b.rotations.length);
75
+ for(let i = 0; i < count; i++){
76
+ result.rotations.push(Quaternion.slerp(a.rotations[i], b.rotations[i], t));
77
+ }
78
+ return result;
79
+ }
80
+ /**
81
+ * Get the blend identifier for this track.
82
+ *
83
+ * IK tracks with the same root joint can be blended together.
84
+ */ getBlendId() {
85
+ const rootNode = this._solver.chain.root.node;
86
+ return `ik-chain-${rootNode.runtimeId}`;
87
+ }
88
+ /**
89
+ * Get the duration of this track.
90
+ */ getDuration() {
91
+ return this._duration;
92
+ }
93
+ }
94
+
95
+ export { IKTrack };
96
+ //# sourceMappingURL=ik_track.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ik_track.js","sources":["../../../src/animation/ik/ik_track.ts"],"sourcesContent":["import { Quaternion } from '@zephyr3d/base';\r\nimport { AnimationTrack } from '../animationtrack';\r\nimport type { FABRIKSolver } from './fabrik_solver';\r\n\r\n/**\r\n * IK animation track state.\r\n *\r\n * Represents the rotations of all joints in an IK chain at a specific time.\r\n */\r\ninterface IKState {\r\n /** Array of joint rotations (one per joint, excluding end effector) */\r\n rotations: Quaternion[];\r\n}\r\n\r\n/**\r\n * Animation track that applies IK solving.\r\n *\r\n * @remarks\r\n * This track integrates IK solving into the animation system, allowing\r\n * IK to be blended with other animations. The track solves the IK chain\r\n * each frame and produces joint rotations that can be mixed with other\r\n * animation tracks.\r\n *\r\n * @public\r\n */\r\nexport class IKTrack extends AnimationTrack<IKState> {\r\n /** The IK solver */\r\n private _solver: FABRIKSolver;\r\n /** Cached state for reuse */\r\n private _state: IKState;\r\n /** Duration of the track (can be infinite for procedural IK) */\r\n private _duration: number;\r\n\r\n /**\r\n * Create an IK animation track.\r\n *\r\n * @param solver - The FABRIK solver to use\r\n * @param duration - Duration of the track in seconds (default: Infinity for procedural)\r\n */\r\n constructor(solver: FABRIKSolver, duration = Infinity) {\r\n super(false);\r\n this._solver = solver;\r\n this._duration = duration;\r\n\r\n // Initialize state with identity rotations\r\n const numJoints = solver.chain.joints.length - 1; // Exclude end effector\r\n this._state = {\r\n rotations: Array.from({ length: numJoints }, () => new Quaternion())\r\n };\r\n }\r\n\r\n /**\r\n * Get the IK solver.\r\n */\r\n get solver(): FABRIKSolver {\r\n return this._solver;\r\n }\r\n\r\n /**\r\n * Set the duration of the track.\r\n */\r\n setDuration(duration: number): void {\r\n this._duration = Math.max(0, duration);\r\n }\r\n\r\n /**\r\n * Calculate IK state at the given time.\r\n *\r\n * @remarks\r\n * For procedural IK, the time parameter is typically ignored.\r\n * The solver uses the current target position set externally.\r\n */\r\n calculateState(_target: object, _currentTime: number): IKState {\r\n const joints = this._solver.chain.joints;\r\n\r\n // Store current rotations as the calculated state\r\n for (let i = 0; i < joints.length - 1; i++) {\r\n this._state.rotations[i].set(joints[i].rotation);\r\n }\r\n\r\n return this._state;\r\n }\r\n\r\n /**\r\n * Apply IK state to the target scene nodes.\r\n */\r\n applyState(_target: object, state: IKState): void {\r\n const joints = this._solver.chain.joints;\r\n\r\n // Apply rotations to scene nodes\r\n for (let i = 0; i < state.rotations.length && i < joints.length - 1; i++) {\r\n joints[i].node.rotation = state.rotations[i];\r\n }\r\n }\r\n\r\n /**\r\n * Mix two IK states using spherical interpolation.\r\n */\r\n mixState(a: IKState, b: IKState, t: number): IKState {\r\n const result: IKState = {\r\n rotations: []\r\n };\r\n\r\n const count = Math.min(a.rotations.length, b.rotations.length);\r\n for (let i = 0; i < count; i++) {\r\n result.rotations.push(Quaternion.slerp(a.rotations[i], b.rotations[i], t));\r\n }\r\n\r\n return result;\r\n }\r\n\r\n /**\r\n * Get the blend identifier for this track.\r\n *\r\n * IK tracks with the same root joint can be blended together.\r\n */\r\n getBlendId(): string {\r\n const rootNode = this._solver.chain.root.node;\r\n return `ik-chain-${rootNode.runtimeId}`;\r\n }\r\n\r\n /**\r\n * Get the duration of this track.\r\n */\r\n getDuration(): number {\r\n return this._duration;\r\n }\r\n}\r\n"],"names":["IKTrack","AnimationTrack","solver","duration","Infinity","_solver","_duration","numJoints","chain","joints","length","_state","rotations","Array","from","Quaternion","setDuration","Math","max","calculateState","_target","_currentTime","i","set","rotation","applyState","state","node","mixState","a","b","t","result","count","min","push","slerp","getBlendId","rootNode","root","runtimeId","getDuration"],"mappings":";;;AAcA;;;;;;;;;;IAWO,MAAMA,OAAgBC,SAAAA,cAAAA,CAAAA;yBAE3B,OAA8B;kCAE9B,MAAwB;qEAExB,SAA0B;AAE1B;;;;;AAKC,MACD,WAAYC,CAAAA,MAAoB,EAAEC,QAAAA,GAAWC,QAAQ,CAAE;AACrD,QAAA,KAAK,CAAC,KAAA,CAAA;QACN,IAAI,CAACC,OAAO,GAAGH,MAAAA;QACf,IAAI,CAACI,SAAS,GAAGH,QAAAA;;QAGjB,MAAMI,SAAAA,GAAYL,OAAOM,KAAK,CAACC,MAAM,CAACC,MAAM,GAAG,CAAA,CAAA;QAC/C,IAAI,CAACC,MAAM,GAAG;YACZC,SAAWC,EAAAA,KAAAA,CAAMC,IAAI,CAAC;gBAAEJ,MAAQH,EAAAA;AAAU,aAAA,EAAG,IAAM,IAAIQ,UAAAA,EAAAA;AACzD,SAAA;AACF;AAEA;;AAEC,MACD,IAAIb,MAAuB,GAAA;QACzB,OAAO,IAAI,CAACG,OAAO;AACrB;AAEA;;MAGAW,WAAAA,CAAYb,QAAgB,EAAQ;AAClC,QAAA,IAAI,CAACG,SAAS,GAAGW,IAAKC,CAAAA,GAAG,CAAC,CAAGf,EAAAA,QAAAA,CAAAA;AAC/B;AAEA;;;;;;AAMC,MACDgB,cAAeC,CAAAA,OAAe,EAAEC,YAAoB,EA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