lecodes-sdk 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/README.md +114 -0
  2. package/dist/global.d.ts +503 -0
  3. package/dist/host.d.ts +61 -0
  4. package/dist/inject.js +4730 -0
  5. package/dist/types/animate/animate.d.ts +20 -0
  6. package/dist/types/animate/bezier.d.ts +2 -0
  7. package/dist/types/animate/easings.d.ts +21 -0
  8. package/dist/types/canvas/Canvas.d.ts +168 -0
  9. package/dist/types/core/Aspect.d.ts +171 -0
  10. package/dist/types/core/InspectorUI.d.ts +88 -0
  11. package/dist/types/core/StateMachine.d.ts +81 -0
  12. package/dist/types/core/color.d.ts +13 -0
  13. package/dist/types/core/compWrite.d.ts +11 -0
  14. package/dist/types/core/events.d.ts +11 -0
  15. package/dist/types/core/fields.d.ts +58 -0
  16. package/dist/types/core/registry.d.ts +7 -0
  17. package/dist/types/core/signals.d.ts +29 -0
  18. package/dist/types/core/time.d.ts +31 -0
  19. package/dist/types/g2/Camera2D.d.ts +19 -0
  20. package/dist/types/g2/CharacterController2D.d.ts +134 -0
  21. package/dist/types/g2/Node2D.d.ts +91 -0
  22. package/dist/types/g2/OneWay2D.d.ts +24 -0
  23. package/dist/types/g2/Physics2D.d.ts +147 -0
  24. package/dist/types/g2/Scene2D.d.ts +72 -0
  25. package/dist/types/g2/Shape2D.d.ts +58 -0
  26. package/dist/types/g2/Sprite.d.ts +51 -0
  27. package/dist/types/g2/SpriteAnimation.d.ts +50 -0
  28. package/dist/types/g2/SpriteSheet.d.ts +69 -0
  29. package/dist/types/g2/Texture2D.d.ts +16 -0
  30. package/dist/types/g2/Tilemap.d.ts +20 -0
  31. package/dist/types/g2/Tileset.d.ts +32 -0
  32. package/dist/types/g2/Trigger2D.d.ts +20 -0
  33. package/dist/types/g2/autotile.d.ts +133 -0
  34. package/dist/types/g2/cells.d.ts +14 -0
  35. package/dist/types/g2/defineScene2d.d.ts +141 -0
  36. package/dist/types/g2/groups2d.d.ts +16 -0
  37. package/dist/types/g2/loop.d.ts +4 -0
  38. package/dist/types/g2/scenarios2d.d.ts +30 -0
  39. package/dist/types/g2/touch.d.ts +2 -0
  40. package/dist/types/gl/Camera.d.ts +79 -0
  41. package/dist/types/gl/CameraPlace.d.ts +26 -0
  42. package/dist/types/gl/CharacterController.d.ts +98 -0
  43. package/dist/types/gl/Gearbox.d.ts +86 -0
  44. package/dist/types/gl/Geometry.d.ts +39 -0
  45. package/dist/types/gl/IK.d.ts +53 -0
  46. package/dist/types/gl/InstancedMesh.d.ts +46 -0
  47. package/dist/types/gl/Light.d.ts +73 -0
  48. package/dist/types/gl/Lightmap.d.ts +85 -0
  49. package/dist/types/gl/Locomotion.d.ts +279 -0
  50. package/dist/types/gl/Material.d.ts +100 -0
  51. package/dist/types/gl/Mesh.d.ts +33 -0
  52. package/dist/types/gl/Model.d.ts +53 -0
  53. package/dist/types/gl/NavAgent.d.ts +99 -0
  54. package/dist/types/gl/NavMesh.d.ts +169 -0
  55. package/dist/types/gl/Node.d.ts +99 -0
  56. package/dist/types/gl/Noise.d.ts +20 -0
  57. package/dist/types/gl/Particles.d.ts +277 -0
  58. package/dist/types/gl/Physics.d.ts +91 -0
  59. package/dist/types/gl/Plane.d.ts +19 -0
  60. package/dist/types/gl/Ragdoll.d.ts +86 -0
  61. package/dist/types/gl/Ray.d.ts +8 -0
  62. package/dist/types/gl/Scene.d.ts +221 -0
  63. package/dist/types/gl/Shape.d.ts +122 -0
  64. package/dist/types/gl/Terrain.d.ts +280 -0
  65. package/dist/types/gl/Texture.d.ts +27 -0
  66. package/dist/types/gl/Trigger.d.ts +10 -0
  67. package/dist/types/gl/Vehicle.d.ts +191 -0
  68. package/dist/types/gl/Wheel.d.ts +95 -0
  69. package/dist/types/gl/animation/AnimationClip.d.ts +60 -0
  70. package/dist/types/gl/animation/Animator.d.ts +219 -0
  71. package/dist/types/gl/animation/Layer.d.ts +31 -0
  72. package/dist/types/gl/animation/Loop.d.ts +17 -0
  73. package/dist/types/gl/animation/Playback.d.ts +36 -0
  74. package/dist/types/gl/animation/core.d.ts +367 -0
  75. package/dist/types/gl/controls.d.ts +19 -0
  76. package/dist/types/gl/physicsEvents.d.ts +1 -0
  77. package/dist/types/gl/scenarios.d.ts +98 -0
  78. package/dist/types/gl/state.d.ts +5 -0
  79. package/dist/types/gl/terrainMesh.d.ts +46 -0
  80. package/dist/types/gl/touch.d.ts +2 -0
  81. package/dist/types/inject.d.ts +123 -0
  82. package/dist/types/math/Mathf.d.ts +39 -0
  83. package/dist/types/math/mat4.d.ts +66 -0
  84. package/dist/types/math/quat.d.ts +53 -0
  85. package/dist/types/math/vec.d.ts +129 -0
  86. package/dist/types/net/codec.d.ts +25 -0
  87. package/dist/types/net/core.d.ts +106 -0
  88. package/dist/types/net/index.d.ts +80 -0
  89. package/dist/types/net/replication.d.ts +101 -0
  90. package/dist/types/plugins/camera.d.ts +25 -0
  91. package/dist/types/plugins/geolocation.d.ts +39 -0
  92. package/dist/types/plugins/oauth.d.ts +25 -0
  93. package/dist/types/plugins/permission.d.ts +1 -0
  94. package/dist/types/plugins/push.d.ts +46 -0
  95. package/dist/types/plugins/qr.d.ts +21 -0
  96. package/dist/types/plugins/service.d.ts +33 -0
  97. package/dist/types/runtime/app.d.ts +67 -0
  98. package/dist/types/runtime/appEvents.d.ts +7 -0
  99. package/dist/types/runtime/channel.d.ts +1 -0
  100. package/dist/types/runtime/clipboard.d.ts +7 -0
  101. package/dist/types/runtime/datetime.d.ts +80 -0
  102. package/dist/types/runtime/device.d.ts +126 -0
  103. package/dist/types/runtime/fetch.d.ts +31 -0
  104. package/dist/types/runtime/files.d.ts +33 -0
  105. package/dist/types/runtime/input.d.ts +121 -0
  106. package/dist/types/runtime/media.d.ts +46 -0
  107. package/dist/types/runtime/misc.d.ts +11 -0
  108. package/dist/types/runtime/net.d.ts +15 -0
  109. package/dist/types/runtime/rpc.d.ts +44 -0
  110. package/dist/types/runtime/service.d.ts +1 -0
  111. package/dist/types/runtime/share.d.ts +2 -0
  112. package/dist/types/runtime/storage.d.ts +5 -0
  113. package/dist/types/runtime/touch.d.ts +56 -0
  114. package/dist/types/scene/defineScene.d.ts +296 -0
  115. package/dist/types/scene/editorPlugins.d.ts +82 -0
  116. package/dist/types/scene/gizmos.d.ts +56 -0
  117. package/dist/types/scene/grammar.d.ts +56 -0
  118. package/dist/types/scene/level.d.ts +98 -0
  119. package/dist/types/scene/material.d.ts +76 -0
  120. package/dist/types/server/auth/appConfig.d.ts +16 -0
  121. package/dist/types/server/auth/global.d.ts +56 -0
  122. package/dist/types/server/auth/models.d.ts +164 -0
  123. package/dist/types/server/auth/types.d.ts +56 -0
  124. package/dist/types/server/channel.d.ts +28 -0
  125. package/dist/types/server/context.d.ts +27 -0
  126. package/dist/types/server/db/defineDb.d.ts +36 -0
  127. package/dist/types/server/db/fields.d.ts +146 -0
  128. package/dist/types/server/db/index.d.ts +6 -0
  129. package/dist/types/server/db/marci/query.d.ts +326 -0
  130. package/dist/types/server/db/types.d.ts +163 -0
  131. package/dist/types/server/errors.d.ts +8 -0
  132. package/dist/types/server/inject.d.ts +5 -0
  133. package/dist/types/ui/NativeView.d.ts +38 -0
  134. package/dist/types/ui/UI.d.ts +27 -0
  135. package/dist/types/ui/UIBottomSheet.d.ts +71 -0
  136. package/dist/types/ui/UIButton.d.ts +30 -0
  137. package/dist/types/ui/UIContainer.d.ts +33 -0
  138. package/dist/types/ui/UIImage.d.ts +35 -0
  139. package/dist/types/ui/UIInput.d.ts +110 -0
  140. package/dist/types/ui/UIModal.d.ts +70 -0
  141. package/dist/types/ui/UINode.d.ts +363 -0
  142. package/dist/types/ui/UIPager.d.ts +123 -0
  143. package/dist/types/ui/UIPopover.d.ts +39 -0
  144. package/dist/types/ui/UIScreen.d.ts +57 -0
  145. package/dist/types/ui/UIScrollable.d.ts +40 -0
  146. package/dist/types/ui/UISpacer.d.ts +9 -0
  147. package/dist/types/ui/UITabs.d.ts +96 -0
  148. package/dist/types/ui/UIText.d.ts +19 -0
  149. package/dist/types/ui/UIVideo.d.ts +28 -0
  150. package/dist/types/ui/UIVirtualizedList.d.ts +97 -0
  151. package/dist/types/ui/UIWidget.d.ts +65 -0
  152. package/dist/types/ui/fonts.d.ts +9 -0
  153. package/dist/types/ui/presentable.d.ts +68 -0
  154. package/dist/types/ui/router.d.ts +40 -0
  155. package/dist/types/ui/theme.d.ts +26 -0
  156. package/dist/types.json +1 -0
  157. package/package.json +46 -0
  158. package/prompts/2d.md +395 -0
  159. package/prompts/3d-scene-files.md +113 -0
  160. package/prompts/3d-scene.md +119 -0
  161. package/prompts/3d.md +303 -0
  162. package/prompts/README.md +142 -0
  163. package/prompts/ar.md +109 -0
  164. package/prompts/canvas.md +27 -0
  165. package/prompts/compose.ts +46 -0
  166. package/prompts/concept.md +49 -0
  167. package/prompts/core-design.md +75 -0
  168. package/prompts/core.md +264 -0
  169. package/prompts/design.md +218 -0
  170. package/prompts/dist/2d-game.md +1530 -0
  171. package/prompts/dist/3d-app.md +1672 -0
  172. package/prompts/dist/ar-app.md +1548 -0
  173. package/prompts/dist/concept.md +49 -0
  174. package/prompts/dist/design.md +498 -0
  175. package/prompts/dist/ui-app.md +1134 -0
  176. package/prompts/index.md +37 -0
  177. package/prompts/intake-prompt.md +33 -0
  178. package/prompts/namer-prompt.md +12 -0
  179. package/prompts/router-prompt.md +50 -0
  180. package/prompts/select.ts +111 -0
  181. package/prompts/ui-design.md +203 -0
  182. package/prompts/ui.md +803 -0
  183. package/src/animate/animate.ts +238 -0
  184. package/src/animate/bezier.ts +138 -0
  185. package/src/animate/easings.ts +126 -0
  186. package/src/bridges.d.ts +1345 -0
  187. package/src/canvas/Canvas.ts +305 -0
  188. package/src/compile/__tests__/assetIconMacro.test.ts +219 -0
  189. package/src/compile/__tests__/assetMacro.test.ts +74 -0
  190. package/src/compile/__tests__/assetName.test.ts +55 -0
  191. package/src/compile/__tests__/compile.test.ts +287 -0
  192. package/src/compile/__tests__/detectEntry.test.ts +132 -0
  193. package/src/compile/__tests__/fontMacro.test.ts +199 -0
  194. package/src/compile/aspectMacro.ts +86 -0
  195. package/src/compile/assetIconMacro.ts +384 -0
  196. package/src/compile/assetMacro.ts +146 -0
  197. package/src/compile/assetName.ts +50 -0
  198. package/src/compile/bundler.ts +287 -0
  199. package/src/compile/compileProject.ts +127 -0
  200. package/src/compile/detectEntry.ts +128 -0
  201. package/src/compile/fontMacro.ts +459 -0
  202. package/src/compile/fontRegistry.ts +78 -0
  203. package/src/compile/header.ts +67 -0
  204. package/src/compile/index.ts +100 -0
  205. package/src/compile/libraryImports.ts +52 -0
  206. package/src/compile/liteMaterial.ts +247 -0
  207. package/src/compile/sceneEditor.ts +88 -0
  208. package/src/compile/serverSplit.ts +233 -0
  209. package/src/compile/serverTypes.ts +227 -0
  210. package/src/compile/sfnt.ts +98 -0
  211. package/src/compile/shaderSchema.ts +202 -0
  212. package/src/compile/shaderTargets.ts +77 -0
  213. package/src/compile/sourcemap.ts +25 -0
  214. package/src/core/Aspect.ts +568 -0
  215. package/src/core/InspectorUI.ts +212 -0
  216. package/src/core/StateMachine.ts +308 -0
  217. package/src/core/__tests__/stateMachine.test.ts +132 -0
  218. package/src/core/color.ts +66 -0
  219. package/src/core/compWrite.ts +42 -0
  220. package/src/core/events.ts +38 -0
  221. package/src/core/fields.ts +120 -0
  222. package/src/core/registry.ts +23 -0
  223. package/src/core/signals.ts +277 -0
  224. package/src/core/time.ts +84 -0
  225. package/src/g2/Camera2D.ts +40 -0
  226. package/src/g2/CharacterController2D.ts +276 -0
  227. package/src/g2/Node2D.ts +267 -0
  228. package/src/g2/OneWay2D.ts +66 -0
  229. package/src/g2/Physics2D.ts +346 -0
  230. package/src/g2/Scene2D.ts +209 -0
  231. package/src/g2/Shape2D.ts +259 -0
  232. package/src/g2/Sprite.ts +89 -0
  233. package/src/g2/SpriteAnimation.ts +171 -0
  234. package/src/g2/SpriteSheet.ts +166 -0
  235. package/src/g2/Texture2D.ts +47 -0
  236. package/src/g2/Tilemap.ts +41 -0
  237. package/src/g2/Tileset.ts +71 -0
  238. package/src/g2/Trigger2D.ts +77 -0
  239. package/src/g2/autotile.ts +433 -0
  240. package/src/g2/cells.ts +91 -0
  241. package/src/g2/defineScene2d.ts +381 -0
  242. package/src/g2/groups2d.ts +106 -0
  243. package/src/g2/loop.ts +50 -0
  244. package/src/g2/scenarios2d.ts +69 -0
  245. package/src/g2/touch.ts +83 -0
  246. package/src/gl/Camera.ts +160 -0
  247. package/src/gl/CameraPlace.ts +52 -0
  248. package/src/gl/CharacterController.ts +238 -0
  249. package/src/gl/Gearbox.ts +212 -0
  250. package/src/gl/Geometry.ts +279 -0
  251. package/src/gl/IK.ts +193 -0
  252. package/src/gl/InstancedMesh.ts +132 -0
  253. package/src/gl/Light.ts +135 -0
  254. package/src/gl/Lightmap.ts +402 -0
  255. package/src/gl/Locomotion.ts +498 -0
  256. package/src/gl/Material.ts +279 -0
  257. package/src/gl/Mesh.ts +83 -0
  258. package/src/gl/Model.ts +124 -0
  259. package/src/gl/NavAgent.ts +337 -0
  260. package/src/gl/NavMesh.ts +397 -0
  261. package/src/gl/Node.ts +350 -0
  262. package/src/gl/Noise.ts +30 -0
  263. package/src/gl/Particles.ts +676 -0
  264. package/src/gl/Physics.ts +222 -0
  265. package/src/gl/Plane.ts +53 -0
  266. package/src/gl/Ragdoll.ts +270 -0
  267. package/src/gl/Ray.ts +16 -0
  268. package/src/gl/Scene.ts +505 -0
  269. package/src/gl/Shape.ts +409 -0
  270. package/src/gl/Terrain.ts +1092 -0
  271. package/src/gl/Texture.ts +63 -0
  272. package/src/gl/Trigger.ts +45 -0
  273. package/src/gl/Vehicle.ts +473 -0
  274. package/src/gl/Wheel.ts +240 -0
  275. package/src/gl/animation/AnimationClip.ts +204 -0
  276. package/src/gl/animation/Animator.ts +329 -0
  277. package/src/gl/animation/Layer.ts +39 -0
  278. package/src/gl/animation/Loop.ts +31 -0
  279. package/src/gl/animation/Playback.ts +52 -0
  280. package/src/gl/animation/core.ts +670 -0
  281. package/src/gl/controls.ts +95 -0
  282. package/src/gl/physicsEvents.ts +20 -0
  283. package/src/gl/scenarios.ts +291 -0
  284. package/src/gl/state.ts +6 -0
  285. package/src/gl/terrainMesh.ts +219 -0
  286. package/src/gl/touch.ts +68 -0
  287. package/src/host.d.ts +61 -0
  288. package/src/inject.ts +203 -0
  289. package/src/math/Mathf.ts +118 -0
  290. package/src/math/mat4.ts +278 -0
  291. package/src/math/quat.ts +232 -0
  292. package/src/math/vec.ts +255 -0
  293. package/src/net/codec.ts +119 -0
  294. package/src/net/core.ts +384 -0
  295. package/src/net/index.ts +181 -0
  296. package/src/net/replication.ts +622 -0
  297. package/src/plugins/camera.ts +81 -0
  298. package/src/plugins/geolocation.ts +123 -0
  299. package/src/plugins/oauth.ts +61 -0
  300. package/src/plugins/permission.ts +7 -0
  301. package/src/plugins/push.ts +132 -0
  302. package/src/plugins/qr.ts +73 -0
  303. package/src/plugins/service.ts +47 -0
  304. package/src/runtime/app.ts +101 -0
  305. package/src/runtime/appEvents.ts +54 -0
  306. package/src/runtime/channel.ts +61 -0
  307. package/src/runtime/clipboard.ts +20 -0
  308. package/src/runtime/datetime.ts +329 -0
  309. package/src/runtime/device.ts +293 -0
  310. package/src/runtime/fetch.ts +77 -0
  311. package/src/runtime/files.ts +108 -0
  312. package/src/runtime/input.ts +175 -0
  313. package/src/runtime/media.ts +111 -0
  314. package/src/runtime/misc.ts +16 -0
  315. package/src/runtime/net.ts +36 -0
  316. package/src/runtime/rpc.ts +218 -0
  317. package/src/runtime/service.ts +83 -0
  318. package/src/runtime/share.ts +9 -0
  319. package/src/runtime/storage.ts +13 -0
  320. package/src/runtime/touch.ts +76 -0
  321. package/src/scene/defineScene.ts +1396 -0
  322. package/src/scene/editorPlugins.ts +110 -0
  323. package/src/scene/gizmos.ts +148 -0
  324. package/src/scene/grammar.ts +120 -0
  325. package/src/scene/level.ts +296 -0
  326. package/src/scene/material.ts +188 -0
  327. package/src/server/auth/appConfig.ts +12 -0
  328. package/src/server/auth/global.ts +80 -0
  329. package/src/server/auth/host.ts +318 -0
  330. package/src/server/auth/models.ts +83 -0
  331. package/src/server/auth/types.ts +50 -0
  332. package/src/server/channel.ts +56 -0
  333. package/src/server/context.ts +36 -0
  334. package/src/server/db/defineDb.ts +237 -0
  335. package/src/server/db/fields.ts +132 -0
  336. package/src/server/db/httpTransport.ts +93 -0
  337. package/src/server/db/index.ts +7 -0
  338. package/src/server/db/marci/query.ts +412 -0
  339. package/src/server/db/types.ts +202 -0
  340. package/src/server/errors.ts +12 -0
  341. package/src/server/host.ts +74 -0
  342. package/src/server/inject.ts +13 -0
  343. package/src/server/runtime.ts +133 -0
  344. package/src/server/validate.ts +87 -0
  345. package/src/ui/NativeView.ts +142 -0
  346. package/src/ui/UI.ts +39 -0
  347. package/src/ui/UIBottomSheet.ts +139 -0
  348. package/src/ui/UIButton.ts +101 -0
  349. package/src/ui/UIContainer.ts +60 -0
  350. package/src/ui/UIImage.ts +83 -0
  351. package/src/ui/UIInput.ts +185 -0
  352. package/src/ui/UIModal.ts +139 -0
  353. package/src/ui/UINode.ts +830 -0
  354. package/src/ui/UIPager.ts +362 -0
  355. package/src/ui/UIPopover.ts +100 -0
  356. package/src/ui/UIScreen.ts +123 -0
  357. package/src/ui/UIScrollable.ts +87 -0
  358. package/src/ui/UISpacer.ts +14 -0
  359. package/src/ui/UITabs.ts +236 -0
  360. package/src/ui/UIText.ts +51 -0
  361. package/src/ui/UIVideo.ts +88 -0
  362. package/src/ui/UIVirtualizedList.ts +241 -0
  363. package/src/ui/UIWidget.ts +127 -0
  364. package/src/ui/fonts.ts +13 -0
  365. package/src/ui/presentable.ts +117 -0
  366. package/src/ui/router.ts +132 -0
  367. package/src/ui/theme.ts +84 -0
@@ -0,0 +1,329 @@
1
+ // Animator — THE animation system, reached as `node.anim`. Every Model carries one pre-attached (its
2
+ // clip list = the GLB's embedded clips; nothing native exists until the first play()). The whole
3
+ // per-frame loop — transitions, blend spaces, one-shot hand-over, root motion — runs in the engine;
4
+ // the SDK only issues calls. See docs/animation-v2-plan.md.
5
+ //
6
+ // A layer shows ONE source at a time (its one-shot, its loop, or nothing) and every switch is an
7
+ // INERTIALIZED transition: the pose the layer showed does not fade away, its difference to the new
8
+ // source decays over `fade` (default 0.2 s; `fade: 0` = cut). Nothing stacks, so a clip may be
9
+ // replaced however far along it is, as often as you like — a planted foot the two clips share stays
10
+ // planted through the transition.
11
+ //
12
+ // const hero = await Model.load(asset('./hero.glb'))
13
+ // hero.anim.playLoop('Idle') // the layer's LOOP: what it rests on
14
+ // await hero.anim.play('Jump', { fadeIn: 0.1, fadeOut: 0.2 }) // a one-shot over it, back to the loop after
15
+ //
16
+ // hero.anim.addClip('slash', slash) // clips from other files / procedural / sliced
17
+ // const loco = hero.anim.playLoop({ Idle: 0, Walking: 2, 'Fast Run': 6 }) // a blend as the loop
18
+ // loco.value = hero.controller.velocity.length // where we are on the blend axis
19
+ // const kick = hero.anim.play('slash', { fadeIn: 0.1, fadeOut: 0.3 }) // resolves at its hand-over
20
+ // kick.clip.addEvent(0.4, 'hit'); hero.anim.on('hit', () => …)
21
+ // if (await kick) hero.anim.playLoop('Crouch', { fade: 0.3 }) // resolved at the hand-over: what you start now is what it fades into
22
+ // const upper = hero.anim.addLayer({ mask: 'Spine1' })
23
+ // upper.playLoop('Aim', { fade: 0.3 }) // arms aim, legs keep walking
24
+ //
25
+ // Any Node hierarchy works, not just Models: tracks bind to child names (a robot arm of meshes).
26
+
27
+ import { Aspect } from "../../core/Aspect"
28
+ import { Vec3 } from "../../math/vec"
29
+ import type { Node } from "../Node"
30
+ import type { AnimationClip } from "./AnimationClip"
31
+ import { Core, type ActiveClip, type ClipCurves, type ClipEventHandler, type KneeAxisReport, type LayerOptions, type LoopDef, type LoopOptions, type PlayOptions, type StepHandler, type StopOptions } from "./core"
32
+ import type { Loop } from "./Loop"
33
+ import type { Layer } from "./Layer"
34
+ import type { Playback } from "./Playback"
35
+
36
+ /** Level of detail for a GLB instance (docs/lod-plan.md): `'auto'` = the engine's pick by screen size and
37
+ * visibility, or a fixed level 0 (full) … 3 (coarsest mesh, animation every 4th frame without fingers). */
38
+ export type LodMode = "auto" | 0 | 1 | 2 | 3
39
+
40
+ /** @internal Push a node's LOD override to the host: the Model's mesh level and the Animator's rate
41
+ * (an Animator set to 'full' wins over a model level — the pose stays exact, the mesh may still coarsen). */
42
+ export const _pushLod = (node: Node): void => {
43
+ if (!_creator.setLod) return
44
+ const mesh = (node as { _lodMesh?: number })._lodMesh ?? -1
45
+ const anim = node.get(Animator)
46
+ _creator.setLod(node.id, mesh, anim?._lod === "full" ? 0 : mesh)
47
+ }
48
+
49
+ /** What `Animator.warp` turns on. Speeds are m/s, angles degrees, distances metres. */
50
+ export type WarpOptions = {
51
+ /** Fit the stride to the speed the body actually travels at. `[min, max]` clamps the scale
52
+ * (default 0.85…1.2). It is a CORRECTION: a pack whose takes already read right at the speeds it
53
+ * is played at wants none of this, and a wide range only lets the legs be stretched into shapes
54
+ * nobody recorded. Open it for a pack that must cover speeds it was never recorded at. */
55
+ stride?: boolean | [number, number]
56
+ /** Turn the lower body toward where the body really travels; a number caps the turn in degrees
57
+ * (default 20). The spine counter-turns, so the chest keeps facing where it faced — the whole twist
58
+ * lives in one joint, which is why a few degrees read as a lean and a lot reads as a broken back.
59
+ * Only applied while the gait LOOP shows: a start, a turn or a stop walks a path of its own. */
60
+ orientation?: boolean | number
61
+ /** Below this speed — the game's or the clip's — both warps are off (default 0.2). */
62
+ minSpeed?: number
63
+ /** How far the pelvis may drop to keep a stretched leg from locking straight (default 0.25). */
64
+ pelvis?: number
65
+ /** The stride scale's own spring, seconds (default 0.15). The body's speed is continuous but the
66
+ * shown clip's recorded one steps at every switch, so the scale is smoothed rather than followed. */
67
+ strideTime?: number
68
+ }
69
+
70
+ const WARP = { STRIDE: 0, STRIDE_MIN: 1, STRIDE_MAX: 2, ORIENT: 3, ORIENT_MAX: 4, ORIENT_TIME: 5, MIN_SPEED: 6, PELVIS: 7, STRIDE_TIME: 8, COUNT: 9 }
71
+
72
+ /** What `Animator.feet` sets: which bones the feet are, and what the engine does with them. Distances
73
+ * are metres, times seconds. Every key is optional and only the keys given change — set the bones
74
+ * once, switch the lock on somewhere else. */
75
+ export type FeetOptions = {
76
+ /** The contact bones per side — `'LeftFoot'`, or with a toe / ball `['LeftFoot', 'LeftToeBase']`.
77
+ * Default: classified from the bone names (Mixamo / Unity / Blender / UE). Set them for a rig the
78
+ * classifier misses; it re-bakes every clip's contacts and phase. */
79
+ left?: string | string[]
80
+ right?: string | string[]
81
+ /** FOOT LOCK: a foot the shown clip calls planted (its baked contacts, else a runtime detector) is
82
+ * pinned where it landed — heel to ball, rolling as the clip rolls — and the leg re-solved to keep it
83
+ * there while the body moves on. What hides the last of a transition's slide: the pose the new clip
84
+ * starts from is not the one the old clip ended in, and the difference used to be dragged out of
85
+ * the standing foot over the blend. Off by default; a `Locomotion` turns it on. */
86
+ lock?: boolean
87
+ /** GROUND IK: each foot is put on the ground the engine probes under it (stairs, a slope, a kerb),
88
+ * aligned to its normal, and the pelvis lowered so the lower leg can reach — the feet stop hanging
89
+ * in the air on a step down and sinking into a step up. Needs a physics world to probe; without
90
+ * one the ground is the node's own plane. Off by default. */
91
+ ik?: boolean
92
+ /** How far the pelvis may drop for the ground (default 0.35). */
93
+ pelvis?: number
94
+ /** The anchor's leash: a locked foot never absorbs more residual than this — beyond it the anchor
95
+ * follows the animation instead of fighting it (default 0.10). */
96
+ unlockDistance?: number
97
+ /** The lock's ease in / out, seconds (default 0.08 / 0.12). */
98
+ lockIn?: number
99
+ lockOut?: number
100
+ /** 0..1: how much the foot tilts onto the ground normal (default 1). */
101
+ align?: number
102
+ /** The probe ray's reach above and below the ankle (default 0.6) — a step taller than this is a
103
+ * hole to the probe. */
104
+ probe?: number
105
+ /** The lock plants only once the animated ankle moves slower than this, m/s (default 0.2: a foot
106
+ * the take itself holds still). Raise it to pin a foot a transition is still dragging — a run
107
+ * entered from standing lands its first foot while the offset from the idle still decays. */
108
+ plantSpeed?: number
109
+ }
110
+
111
+ /** One foot after this frame's evaluation (`Animator.foot`): whether the lock holds it, the lock's
112
+ * weight (eased 0…1), where it was pinned and where the leg was asked to put the ankle — all world. */
113
+ export type FootState = { locked: boolean, weight: number, anchor: Vec3, target: Vec3 }
114
+
115
+ const FEET = { IK: 0, LOCK: 1, PELVIS: 2, UNLOCK_DIST: 3, LOCK_IN: 4, LOCK_OUT: 5, PELVIS_TIME: 6, ALIGN: 7, PROBE: 8, DETECT_SPEED: 9, DETECT_HEIGHT: 10, PLANT_SPEED: 11, COUNT: 12 }
116
+ const footBuf = new Float32Array(8)
117
+
118
+ export class Animator extends Aspect<"anim", Node> {
119
+ static readonly aspect = "anim"
120
+ private _c!: Core
121
+ private _rootMotion = false
122
+ private _rootRotation = false
123
+ /** @internal */
124
+ _lod: "auto" | "full" = "auto"
125
+
126
+ /** Animation level of detail. `'auto'` (default): a character small on screen or out of view is
127
+ * evaluated every 2nd / 4th frame and stops sampling its finger, toe and twist joints; `'full'`:
128
+ * every frame, every joint, whatever the distance — a hero seen through a scope, a cutscene actor.
129
+ * Independent of `Model.lod` (the mesh level). No-op on hosts without the LOD pass. */
130
+ get lod(): "auto" | "full" { return this._lod }
131
+ set lod(v: "auto" | "full") { this._lod = v; _pushLod(this.node) }
132
+
133
+ onAttach(): void { this._c = new Core(this.node) }
134
+ onDetach(): void { this._c.destroy() }
135
+
136
+ // ---- clips ----
137
+ /** The clip list, in order: the GLB's embedded clips (file order), then the clips you added. An
138
+ * added clip with an embedded clip's name takes its place. */
139
+ get clips(): readonly AnimationClip[] { return this._c.clips() }
140
+ /** One clip by name, or by index into `clips` — e.g. to `slice()` it. `undefined` if there is none. */
141
+ clip(ref: string | number): AnimationClip | undefined { return this._c.resolveClip(ref)?.[1] }
142
+ /** Add a clip under a name (default: its own `name`) — from another file, procedural, or sliced.
143
+ * Overrides an embedded clip of the same name. Chainable. */
144
+ addClip(name: string | AnimationClip, clip?: AnimationClip): this {
145
+ const c = typeof name === "string" ? clip : name
146
+ const n = typeof name === "string" ? name : name.name
147
+ if (!c) { console.warn(`Animator.addClip('${n}'): no clip`); return this }
148
+ this._c.addClip(n, c)
149
+ return this
150
+ }
151
+
152
+ // ---- playing (the base layer) ----
153
+ /** Play a one-shot on the base layer — by name, index, or the first clip with no argument. It
154
+ * takes the layer over from whatever it showed, transitioned over `fade` (default 0.2 s).
155
+ * Returns a Playback: `await` it — it resolves at the clip's hand-over (`true`; `false` if cut
156
+ * short), and what you start right after is what the clip hands the layer to (another one-shot,
157
+ * `playLoop(next)`; nothing = back to the loop). */
158
+ play(clip?: string | number, options: PlayOptions = {}): Playback { return this._c.play(this._c.layers[0], clip, options) }
159
+ /** Set the base layer's LOOP — what it shows when no one-shot plays: a clip (`playLoop('Idle')`) or
160
+ * a blend space (`playLoop({ Idle: 0, Run: 6 })`, drive the returned object's `value`). Takes the
161
+ * layer over from whatever plays — a one-shot included (it is cut short) — transitioned over
162
+ * `fade`. `stop()` removes it. */
163
+ playLoop(def: LoopDef, options: LoopOptions = {}): Loop | undefined { return this._c.loop(this._c.layers[0], def, options) }
164
+ /** Fade everything out, on every layer (loops included) → rest pose. */
165
+ stop(options: StopOptions = {}): this { this._c.stopAll(options.fade ?? 0); return this }
166
+ /** The base layer's current loop (the object the last `playLoop()` returned), if any. */
167
+ get loop(): Loop | undefined { return this._c.layers[0].loop?.view }
168
+ /** A one-shot on the base layer hasn't handed over yet. */
169
+ get busy(): boolean { return this._c.busy(this._c.layers[0]) }
170
+ /** What every layer shows this frame with its weight: one one-shot, or a loop's members with their
171
+ * blend shares (a debug overlay's list). */
172
+ get active(): ActiveClip[] { return this._c.layers.flatMap((L) => this._c.active(L)) }
173
+
174
+ /** Where the base layer is in the GAIT CYCLE: 0 at a left-foot-down, 0.5 at a right-foot-down,
175
+ * whether a loop or a one-shot shows it. -1 when what plays has no cycle (an idle, a hit reaction).
176
+ * This is the number `play(clip, { phase: 'match' })` matches against. */
177
+ get phase(): number { return this._c.layerPhase(this._c.layers[0]) }
178
+
179
+ /** The native animator's id — 0 until something is played or bound. Engine-facing code only. */
180
+ get _id(): number { return this._c.id }
181
+ /** Bind a clip to the base layer without playing it and return its native slot (-1 = no such clip);
182
+ * creates the native animator on first use. What a Locomotion registers its set with. */
183
+ _slot(clip: string | number): number { return this._c.slotIndex(clip) }
184
+
185
+ /** What the engine measured on a clip once it was bound to this skeleton: foot contacts, the gait
186
+ * phase φ(t), and the root's travel / yaw / speed — a controller reads these instead of shipping
187
+ * measured tables. Binds the clip on first ask. `undefined` if there is no such clip. */
188
+ curves(clip: string | number): ClipCurves | undefined { return this._c.curves(clip) }
189
+
190
+ /** The skeleton's calibrated KNEE HINGE AXIS for a side (thigh-local, unit) with its confidence
191
+ * report — measured once over every bound clip's knee rotation track; the ground truth
192
+ * `curves(clip).kneePoleAt` predicts bend planes from. Undefined = no leg chain, or no knee
193
+ * motion bound to calibrate from. */
194
+ kneeAxis(side: "left" | "right"): KneeAxisReport | undefined { return this._c.kneeAxis(side) }
195
+
196
+ /** STEP WARP v2 knobs (the warp rewrite): `stride` scales each foot's travel-direction offset
197
+ * from its hip (the step shortens / lengthens), `lift` = metres ADDED to its height
198
+ * (swing-gated; 0 = neutral, negative = a shuffle; half of what it adds raises the pelvis —
199
+ * the body steps higher with the foot), `pitch` (degrees, + = toes up) rotates each foot about
200
+ * its lateral axis, `slope` (degrees, + = ascending) the invisible staircase — feet on the
201
+ * incline + auto pitch; raise the character by tan(slope) × the stride-scaled clip travel to
202
+ * hold each planted foot on its tread. Solved in the calibrated knee hinge plane.
203
+ * Omit / null = off. A tuning bench's dial — locomotion will drive this itself later. */
204
+ setStepWarp(options?: { stride?: number, lift?: number, pitch?: number, slope?: number } | null): void { this._c.setStepWarp(options) }
205
+
206
+ /** Scrub: set `clip`'s playhead directly, seconds — for inspectors and debug boards (pair with
207
+ * `speed = 0`). The clip should be the one showing; nothing is faded or re-picked. */
208
+ seek(clip: string | number, time: number): void { this._c.seekTime(clip, time) }
209
+ /** `clip`'s current playhead, seconds (-1 = not bound). */
210
+ time(clip: string | number): number { return this._c.timeOf(clip) }
211
+ /** Re-aim a playing turn clip's warp (`play({ turn })`) to `deg` for the whole clip — the scale lands on what is
212
+ * still to come; `undefined` = off. */
213
+ setTurn(clip: string | number, deg: number | undefined): void { this._c.setTurnOf(clip, deg) }
214
+
215
+ /** THE FEET (docs/animation-v2-plan.md §2.9): which bones they are, and what the engine does with
216
+ * them after the clips are composited — the foot LOCK (a planted foot stays where it landed while the
217
+ * body moves on) and GROUND IK (each foot on the ground probed under it, the pelvis lowered). Only
218
+ * the keys given change, so the bones and the behaviour can be set from different places:
219
+ *
220
+ * model.anim.feet = { left: 'LeftFoot', right: 'RightFoot' } // a rig the classifier misses
221
+ * model.anim.feet = { lock: true } // (a Locomotion does this itself)
222
+ * model.anim.feet = { lock: true, ik: true, pelvis: 0.3 } // stairs and slopes
223
+ *
224
+ * The engine probes the ground itself (against what a character can stand on) and reads the
225
+ * CharacterController's ground state; nothing is fed per frame. See `FeetOptions`. */
226
+ set feet(f: FeetOptions) {
227
+ const o = this._feetOpts
228
+ Object.assign(o, f)
229
+ if (f.left !== undefined || f.right !== undefined) {
230
+ const join = (v: string | string[] | undefined): string => v === undefined ? "" : Array.isArray(v) ? v.join("\n") : v
231
+ this._c.setFeet(join(o.left), join(o.right))
232
+ }
233
+ const p = new Float32Array(FEET.COUNT)
234
+ // the engine's own defaults (canimAnimatorFeetDefaults)
235
+ p[FEET.PELVIS] = 0.35; p[FEET.UNLOCK_DIST] = 0.10; p[FEET.LOCK_IN] = 0.08; p[FEET.LOCK_OUT] = 0.12
236
+ p[FEET.PELVIS_TIME] = 0.15; p[FEET.ALIGN] = 1; p[FEET.PROBE] = 0.6; p[FEET.DETECT_SPEED] = 0.35; p[FEET.DETECT_HEIGHT] = 0.12
237
+ p[FEET.PLANT_SPEED] = 0.2
238
+ if (o.ik) p[FEET.IK] = 1
239
+ if (o.lock) p[FEET.LOCK] = 1
240
+ if (o.pelvis !== undefined) p[FEET.PELVIS] = o.pelvis
241
+ if (o.unlockDistance !== undefined) p[FEET.UNLOCK_DIST] = o.unlockDistance
242
+ if (o.lockIn !== undefined) p[FEET.LOCK_IN] = o.lockIn
243
+ if (o.lockOut !== undefined) p[FEET.LOCK_OUT] = o.lockOut
244
+ if (o.align !== undefined) p[FEET.ALIGN] = o.align
245
+ if (o.probe !== undefined) p[FEET.PROBE] = o.probe
246
+ if (o.plantSpeed !== undefined) p[FEET.PLANT_SPEED] = o.plantSpeed
247
+ this._c.setFeetParams(p)
248
+ }
249
+ private readonly _feetOpts: FeetOptions = {}
250
+
251
+ /** One foot's state after this frame's evaluation — where the lock holds it and with what weight
252
+ * (a debug beam under the foot). `undefined` on a host without the feet stage, or before anything
253
+ * played. */
254
+ foot(side: "left" | "right"): FootState | undefined {
255
+ if (!this._c.footState(side === "left" ? 0 : 1, footBuf)) return undefined
256
+ return { locked: footBuf[0] > 0.5, weight: footBuf[1], anchor: new Vec3(footBuf[2], footBuf[3], footBuf[4]), target: new Vec3(footBuf[5], footBuf[6], footBuf[7]) }
257
+ }
258
+
259
+ /** WARPING (docs/animation-v2-plan.md §2.7) — the pose is fitted to what the body actually does,
260
+ * after the clips are composited and before the feet:
261
+ *
262
+ * `stride` — each leg's hip→foot vector is scaled ALONG the travel direction by the ratio of the
263
+ * game speed to the shown clip's own (clamped, default 0.6…1.5), the foot height kept, and the
264
+ * pelvis lowered when that would overextend a leg. A walk played at 1.9 m/s stops skating; a
265
+ * speed between two gaits becomes continuous instead of "two clips and a crossfade".
266
+ * `orientation` — the lower body turns from the clip's travel direction toward the one the body
267
+ * really travels in (capped, default 60°) and the spine counter-turns, so the chest keeps its
268
+ * facing. Arcs and strafing stop needing a clip per angle.
269
+ *
270
+ * Both need to know the body's motion, which a `Locomotion` feeds every frame; without one, set
271
+ * `_creator.animatorSetMotion` yourself or leave warping off. Off by default.
272
+ *
273
+ * model.anim.warp = true // both, with the defaults
274
+ * model.anim.warp = { stride: [0.7, 1.4], orientation: 45 }
275
+ */
276
+ set warp(w: WarpOptions | boolean) {
277
+ const o: WarpOptions = w === true ? { stride: true, orientation: true } : w === false ? {} : w
278
+ const p = new Float32Array(WARP.COUNT)
279
+ // the engine's own defaults (canimAnimatorWarpDefaults): what is not asked for stays neutral
280
+ p[WARP.STRIDE_MIN] = 0.85; p[WARP.STRIDE_MAX] = 1.2; p[WARP.ORIENT_MAX] = 20
281
+ p[WARP.ORIENT_TIME] = 0.15; p[WARP.MIN_SPEED] = 0.2; p[WARP.PELVIS] = 0.25
282
+ p[WARP.STRIDE_TIME] = 0.15
283
+ if (o.stride) {
284
+ p[WARP.STRIDE] = 1
285
+ if (Array.isArray(o.stride)) { p[WARP.STRIDE_MIN] = o.stride[0]; p[WARP.STRIDE_MAX] = o.stride[1] }
286
+ }
287
+ if (o.orientation) {
288
+ p[WARP.ORIENT] = 1
289
+ if (typeof o.orientation === "number") p[WARP.ORIENT_MAX] = o.orientation
290
+ }
291
+ if (o.minSpeed !== undefined) p[WARP.MIN_SPEED] = o.minSpeed
292
+ if (o.pelvis !== undefined) p[WARP.PELVIS] = o.pelvis
293
+ if (o.strideTime !== undefined) p[WARP.STRIDE_TIME] = o.strideTime
294
+ this._c.setWarp(p)
295
+ }
296
+
297
+ // ---- footsteps ----
298
+ /** A foot planted (world position) — audio, dust, decals. Fires for what the BASE layer shows,
299
+ * from the clip's own contacts; a clip with no contacts fires nothing. */
300
+ onStep(cb: StepHandler): this { this._c.onStepHandler(cb); return this }
301
+ offStep(cb: StepHandler): this { this._c.offStepHandler(cb); return this }
302
+
303
+ // ---- layers ----
304
+ /** A new layer on top (masked override / additive). The returned object is its handle. */
305
+ addLayer(options: LayerOptions = {}): Layer { return this._c.addLayer(options) }
306
+
307
+ // ---- clip events (`clip.addEvent(0.4, 'hit')`) ----
308
+ on(event: string, cb: ClipEventHandler): this { this._c.on(event, cb); return this }
309
+ off(event: string, cb: ClipEventHandler): this { this._c.off(event, cb); return this }
310
+
311
+ // ---- props ----
312
+ /** Global playback rate: 0.3 = slow-mo, 0 = pause. */
313
+ get speed(): number { return this._c.speed }
314
+ set speed(v: number) { this._c.setSpeed(v) }
315
+ /** Root motion: the root bone's horizontal travel comes OFF the pose and moves the node instead —
316
+ * or its CharacterController (on this node or an ancestor) as a velocity, so it collides. For
317
+ * clips whose hips actually travel (Mixamo without "In Place", lunges, rolls). A character that
318
+ * moves under a `Locomotion` gets this from its displacement mode instead. */
319
+ get rootMotion(): boolean { return this._rootMotion }
320
+ set rootMotion(on: boolean) { this._rootMotion = on; this._c.setRootMotion(on, this._rootRotation) }
321
+ /** With `rootMotion`, the root bone's TURN (its yaw about the node's up, since the clip's first
322
+ * frame) is root motion too: it comes off the pose and turns the node the travel lands on — the
323
+ * character (or the model) faces where a turn-start / turn-in-place / arc clip took it, and the
324
+ * crossfade into the next clip keeps that heading instead of swinging back. Off by default: a
325
+ * walk cycle's hip sway is a turn too, and most rigs want it in the pose; turn it on for a rig
326
+ * whose root bone carries the heading (`lecodes assets retarget --root-rotation yaw`). */
327
+ get rootRotation(): boolean { return this._rootRotation }
328
+ set rootRotation(on: boolean) { this._rootRotation = on; if (this._rootMotion) this._c.setRootMotion(true, on) }
329
+ }
@@ -0,0 +1,39 @@
1
+ // Layer — one layer of an Animator (`anim.addLayer({ mask: 'Spine1' })` for the upper body,
2
+ // `{ additive: true }` for deltas stacked on top). The Animator's own play/stop/playLoop ARE its base
3
+ // layer; extra layers composite over it in creation order. The object is the layer's only handle.
4
+
5
+ import type { ActiveClip, Core, LayerRec, LoopDef, LoopOptions, PlayOptions, StopOptions } from "./core"
6
+ import type { Loop } from "./Loop"
7
+ import type { Playback } from "./Playback"
8
+
9
+ export class Layer {
10
+ private readonly _r: LayerRec
11
+ private readonly _c: Core
12
+ /** @internal — created by the Animator. */
13
+ constructor(rec: LayerRec, core: Core) { this._r = rec; this._c = core }
14
+
15
+ /** Play a one-shot on this layer (transitioned over `fade`); resolves at its hand-over. */
16
+ play(clip?: string | number, options: PlayOptions = {}): Playback { return this._c.play(this._r, clip, options) }
17
+ /** Set / transition this layer's loop (a clip, or a blend space) — over `fade` from whatever the
18
+ * layer shows, a one-shot included (it is cut short). */
19
+ playLoop(def: LoopDef, options: LoopOptions = {}): Loop | undefined { return this._c.loop(this._r, def, options) }
20
+ /** Fade everything on this layer out — one-shots and its loop. */
21
+ stop(options: StopOptions = {}): this { this._c.stopLayer(this._r, options.fade ?? 0); return this }
22
+ /** ANTICIPATION for the NEXT play / playLoop on this layer (consumed by it): the transition begins with
23
+ * every joint moving AGAINST the new clip's motion - `amount` x its velocity - and the transition's
24
+ * spring brings it round: a wind-up before the swing. Position and rotation, the joints the layer
25
+ * drives. 0.3-1 reads as a natural anticipation; the duration is the transition's own fade.
26
+ * Ignored by hosts without it. */
27
+ anticipate(amount: number): this { this._c.anticipate(this._r, amount); return this }
28
+ /** This layer's current loop (the object the last `playLoop()` returned), if any. */
29
+ get loop(): Loop | undefined { return this._r.loop?.view }
30
+ /** Where this layer is in the gait cycle, 0–1 (-1 = what it shows has no cycle). */
31
+ get phase(): number { return this._c.layerPhase(this._r) }
32
+ /** Layer contribution 0–1. */
33
+ get weight(): number { return this._r.weight }
34
+ set weight(v: number) { this._r.weight = v; this._c.pushLayer(this._r) }
35
+ /** A one-shot on this layer hasn't handed over yet. */
36
+ get busy(): boolean { return this._c.busy(this._r) }
37
+ /** What this layer shows this frame with its weight — its one-shot, or its loop's members. */
38
+ get active(): ActiveClip[] { return this._c.active(this._r) }
39
+ }
@@ -0,0 +1,31 @@
1
+ // Loop — a layer's LOOP: what it shows when no one-shot plays (`anim.playLoop('Idle')` — one looping clip,
2
+ // or `anim.playLoop({ Idle: 0, Walking: 2, Run: 6 })` — a blend whose members cycle in phase and `value`
3
+ // picks the mix: 1D linear between neighbours, `[x, y]` positions = a 2D gradient band). A one-shot takes
4
+ // the layer over and hands it back; `playLoop(next)` transitions to another; `stop()` removes it. The
5
+ // object returned by `playLoop()` (also `anim.loop`) is the handle; a replaced loop's object goes dead.
6
+
7
+ import type { BlendPosition, Core, LoopRec } from "./core"
8
+
9
+ export class Loop {
10
+ private readonly _r: LoopRec
11
+ private readonly _c: Core
12
+ /** @internal — created by playLoop(). */
13
+ constructor(rec: LoopRec, core: Core) { this._r = rec; this._c = core }
14
+
15
+ /** Position on the axis (number) or plane (`[x, y]`) — units are whatever the positions use. Live
16
+ * even while a one-shot plays (the loop returns at the new mix). */
17
+ get value(): BlendPosition { return this._r.value }
18
+ set value(v: BlendPosition) { this._c.setLoopValue(this._r, v) }
19
+ /** Where the loop is in its GAIT cycle, 0–1: 0 at a left-foot-down, 0.5 at a right-foot-down —
20
+ * one clock for every member, aligned by their contacts (a walk and a run whose feet land at
21
+ * different fractions of their clips still agree). Set it to jump the cycle: `playLoop(def,
22
+ * { phase })` on the way in, or here to re-sync with something else. */
23
+ get phase(): number { return this._c.loopPhase(this._r) }
24
+ set phase(v: number) { this._c.setLoopPhase(this._r, v) }
25
+ /** Each member's share of the mix, 0–1. */
26
+ get weights(): Record<string, number> {
27
+ const out: Record<string, number> = {}
28
+ for (const m of this._r.members) out[m.name] = this._c.slotWeight(m.slot)
29
+ return out
30
+ }
31
+ }
@@ -0,0 +1,52 @@
1
+ // Playback — the handle `play()` returns (docs/animator-plan.md). Thenable: `await anim.play('slash')`
2
+ // resolves at the clip's HAND-OVER — where its fade-back starts (`end − fadeOut`; the end when there
3
+ // is no fadeOut) — with `true`; `false` when it was cut short (replaced / stopped). What
4
+ // you call right after the await is what the clip fades into: `anim.play(next)` (a chained one-shot,
5
+ // crossfaded), `anim.playLoop(next)` — nothing = back to the loop (or hold, on a layer without one).
6
+ // Returning one from an `async` function flattens it into `Promise<boolean>` — return `p.done` (or
7
+ // make the function sync) when the caller needs the handle.
8
+
9
+ import type { AnimationClip } from "./AnimationClip"
10
+ import type { Core, PlaybackRec, StopOptions } from "./core"
11
+ import type { Layer } from "./Layer"
12
+
13
+ export class Playback implements PromiseLike<boolean> {
14
+ private readonly _r: PlaybackRec
15
+ private readonly _c: Core
16
+ /** @internal — created by play(). */
17
+ constructor(rec: PlaybackRec, core: Core) { this._r = rec; this._c = core }
18
+
19
+ /** The clip that plays. */
20
+ get clip(): AnimationClip { return this._r.slot.clip }
21
+ /** The layer it plays on. */
22
+ get layer(): Layer { return this._r.slot.layer.view }
23
+ /** Clock (s). */
24
+ get time(): number { return this._r.slot.playback === this._r ? this._c.slotTime(this._r.slot) : 0 }
25
+ /** 0–1 through the clip (the current cycle, when looping). */
26
+ get progress(): number { const d = this.clip.duration; return d > 0 ? this.time / d : 0 }
27
+ /** Where this clip is in the GAIT cycle now, 0–1 (-1 when it has none). */
28
+ get phase(): number { return this._c.slotPhase(this._r.slot) }
29
+ /** The root yaw the clip has turned the body by so far, radians (+ = left) — a turn clip's progress. */
30
+ get turned(): number { return this._c.slotCurveAt(this._r.slot, 2) }
31
+ /** The root yaw still to come: where this clip will leave the body facing, relative to now (rad). */
32
+ get turnLeft(): number { return this._c.slotTurn(this._r.slot) - this.turned }
33
+ /** The horizontal distance the clip's root has travelled so far, metres. */
34
+ get travelled(): number { return this._c.slotCurveAt(this._r.slot, 1) }
35
+ /** Not handed over yet (the clip still owns the layer). */
36
+ get playing(): boolean { return this._r.playing }
37
+ /** Contribution to the pose: 1 while this clip is the layer's source, 0 once something else took
38
+ * the layer over (the difference between the two poses is what decays, not this weight). */
39
+ get weight(): number { return this._r.slot.playback === this._r ? this._c.slotWeight(this._r.slot) : 0 }
40
+ /** Resolves at the hand-over (`true`) or when cut short (`false`) — the promise `await playback`
41
+ * uses; the one to return from async functions or put in `Promise.all`. */
42
+ get done(): Promise<boolean> { return this._r.done }
43
+
44
+ then<A = boolean, B = never>(onFulfilled?: ((v: boolean) => A | PromiseLike<A>) | null, onRejected?: ((e: unknown) => B | PromiseLike<B>) | null): Promise<A | B> {
45
+ return this._r.done.then(onFulfilled, onRejected)
46
+ }
47
+
48
+ /** Move the clock (s). */
49
+ seek(time: number): this { this._c.seek(this._r.slot, time); return this }
50
+ /** Cut this clip short (the layer's loop comes back if nothing else takes over), over `fade`. */
51
+ stop(options: StopOptions = {}): this { this._c.stopSlot(this._r.slot, options.fade ?? 0); return this }
52
+ }