cozyclay 2.1.1 → 3.0.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 (577) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +12 -30
  3. package/bin/agent/agent-routes.mjs +40 -113
  4. package/bin/agent/agent-runner.mjs +9 -10
  5. package/bin/agent/cliproxy-provider.mjs +135 -0
  6. package/bin/agent/credential-store.mjs +30 -7
  7. package/bin/agent/pi-tools.mjs +4 -1
  8. package/bin/agent/provider-keys.mjs +32 -0
  9. package/bin/agent/provider-login.mjs +110 -0
  10. package/bin/agent/provider-routes.mjs +99 -0
  11. package/bin/agent/providers.mjs +19 -97
  12. package/bin/agent/script-tool.mjs +17 -4
  13. package/bin/agent/studio-motion-reference.mjs +23 -0
  14. package/bin/agent/studio-prompt.mjs +1 -1
  15. package/bin/agent/studio-rebase-text.mjs +32 -0
  16. package/bin/agent/studio-rebase.mjs +26 -39
  17. package/bin/agent/studio-tools.mjs +9 -28
  18. package/bin/agent/tool-arguments.mjs +49 -0
  19. package/bin/agent/turn-frames.mjs +66 -0
  20. package/bin/codex-auth.mjs +9 -2
  21. package/bin/cozyclay.mjs +10 -116
  22. package/bin/live/cli.mjs +3 -3
  23. package/bin/mcp-runtime.mjs +2 -12
  24. package/bin/package-signature.mjs +0 -4
  25. package/dist/app/index.html +7 -6
  26. package/dist/assets/EXRLoader-CvVIvGVE.js +1 -0
  27. package/dist/assets/analytics-C9sUnndd.js +1 -0
  28. package/dist/assets/app-CCh--1Hc.js +5087 -0
  29. package/dist/assets/app-f-fkV5uP.css +1 -0
  30. package/dist/assets/compile-worker-CkxiD6lH.js +5 -0
  31. package/dist/assets/fflate.module-KbGj5-H6.js +5 -0
  32. package/dist/assets/{first-shot-handoff-msLI71g1.js → first-shot-handoff-CC4xe4HM.js} +1 -1
  33. package/dist/assets/{landing-ChUvB_zL.js → landing-DjHD8u7k.js} +1 -1
  34. package/dist/assets/scene-asset-sync-Hx_FzdOH.js +20 -0
  35. package/dist/assets/scene-asset-sync-_S8NQl5B.css +1 -0
  36. package/dist/assets/workflow-C4yKH1p4.js +179 -0
  37. package/dist/cozyclay-package.json +1 -1
  38. package/dist/index.html +3 -3
  39. package/dist/sw.js +3 -6
  40. package/dist/workflow/index.html +5 -4
  41. package/mcp/LIVE-PROTOCOL.md +7 -47
  42. package/mcp/README.md +16 -26
  43. package/mcp/live-hub.mjs +6 -10
  44. package/mcp/package.json +1 -3
  45. package/mcp/tool-handlers.mjs +4 -168
  46. package/package.json +3 -22
  47. package/src/App.jsx +150 -2624
  48. package/src/agent-progress.js +79 -0
  49. package/src/agent-turn-mark.js +30 -0
  50. package/src/analytics.js +1 -19
  51. package/src/app-context.js +5 -0
  52. package/src/app-stage.jsx +2 -34
  53. package/src/asset-pane.jsx +6 -5
  54. package/src/camera-block.js +21 -0
  55. package/src/camera-direction.js +120 -0
  56. package/src/character-kind.js +3 -9
  57. package/src/command-bus.js +8 -6
  58. package/src/commands/cast.js +5 -34
  59. package/src/commands/elements/character.js +1 -1
  60. package/src/commands/elements/motion.js +1 -6
  61. package/src/commands/elements/object.js +6 -2
  62. package/src/commands/elements/shot.js +4 -1
  63. package/src/commands/elements.js +38 -14
  64. package/src/commands/index.js +3 -1
  65. package/src/commands/kits.js +37 -0
  66. package/src/commands/motion-timing.js +57 -0
  67. package/src/commands/motion.js +9 -152
  68. package/src/commands/motion3-compile.js +65 -0
  69. package/src/commands/motion3.js +207 -0
  70. package/src/commands/objects.js +6 -4
  71. package/src/commands/shot.js +49 -11
  72. package/src/commands/stage.js +14 -1
  73. package/src/commands/view.js +4 -1
  74. package/src/document-mirrors.js +42 -0
  75. package/src/document-store.js +4 -0
  76. package/src/domains/cast.js +19 -194
  77. package/src/domains/motion/motion-range-pin-rules.js +1 -1
  78. package/src/domains/motion/take-source.js +51 -0
  79. package/src/domains/motion.js +60 -1838
  80. package/src/domains/scenes.js +12 -55
  81. package/src/domains/shots.js +2 -2
  82. package/src/domains/stage.js +4 -2
  83. package/src/draft-ghost.js +46 -0
  84. package/src/draft-ghost.jsx +129 -0
  85. package/src/dualview.jsx +4 -3
  86. package/src/effects/EffectsLayer.jsx +112 -0
  87. package/src/effects/effect-meshes.js +232 -0
  88. package/src/effects/effect-record.js +103 -0
  89. package/src/effects/emitter.js +59 -0
  90. package/src/effects/simulate.js +261 -0
  91. package/src/effects/state.js +59 -0
  92. package/src/execution-telemetry.js +2 -3
  93. package/src/first-success-guide.jsx +5 -5
  94. package/src/ghost-set.js +257 -0
  95. package/src/held-object-edit.jsx +113 -0
  96. package/src/held-object-pose.js +175 -0
  97. package/src/hierarchy-model.js +1 -1
  98. package/src/hierarchy-panel.jsx +1 -1
  99. package/src/imported-mesh.jsx +103 -0
  100. package/src/kits/held.js +84 -0
  101. package/src/kits/index.js +70 -0
  102. package/src/kits/smoking.js +57 -0
  103. package/src/light-blockers.js +93 -0
  104. package/src/motion/beat-board-model.js +84 -0
  105. package/src/motion/beat-board.css +124 -0
  106. package/src/motion/beat-board.jsx +59 -0
  107. package/src/motion/center-of-mass.js +66 -0
  108. package/src/motion/fix-collisions.js +850 -0
  109. package/src/motion/physics-review.js +118 -0
  110. package/src/{ardy → motion}/physics-support.js +1 -76
  111. package/src/motion/rig-snapshot.js +22 -0
  112. package/src/motion/take-segments.jsx +140 -0
  113. package/src/{ardy → motion}/timeline-coordinates.js +0 -21
  114. package/src/{ardy → motion}/timeline.css +1 -2
  115. package/src/{ardy → motion}/timeline.jsx +42 -413
  116. package/src/motion/waypoints.js +76 -0
  117. package/src/motion3/beats.js +83 -0
  118. package/src/motion3/body.js +158 -0
  119. package/src/motion3/bones.js +47 -0
  120. package/src/motion3/carried.js +47 -0
  121. package/src/motion3/compile-job.js +75 -0
  122. package/src/motion3/compile-worker.js +10 -0
  123. package/src/motion3/compiler/anchors.js +105 -0
  124. package/src/motion3/compiler/arm-orient.js +128 -0
  125. package/src/motion3/compiler/channels.js +125 -0
  126. package/src/motion3/compiler/compile.js +205 -0
  127. package/src/motion3/compiler/gait-rhythm.js +97 -0
  128. package/src/motion3/compiler/grip.js +171 -0
  129. package/src/motion3/compiler/head-steady.js +48 -0
  130. package/src/motion3/compiler/hold.js +134 -0
  131. package/src/motion3/compiler/idle.js +113 -0
  132. package/src/motion3/compiler/limbs.js +170 -0
  133. package/src/motion3/compiler/math.js +72 -0
  134. package/src/motion3/compiler/pose.js +162 -0
  135. package/src/motion3/compiler/quat.js +49 -0
  136. package/src/motion3/compiler/skeleton.js +74 -0
  137. package/src/motion3/compiler/validate-common.js +32 -0
  138. package/src/motion3/compiler/validate-goals.js +118 -0
  139. package/src/motion3/compiler/validate-objects.js +143 -0
  140. package/src/motion3/compiler/validate-parts.js +116 -0
  141. package/src/motion3/compiler/validate.js +122 -0
  142. package/src/motion3/compiler/vocab.js +73 -0
  143. package/src/motion3/compiler/walk-pelvis.js +275 -0
  144. package/src/motion3/compiler/walk.js +207 -0
  145. package/src/motion3/compiler/wrist-clamp.js +32 -0
  146. package/src/motion3/delta.js +47 -0
  147. package/src/motion3/describe.js +174 -0
  148. package/src/motion3/docs.js +27 -0
  149. package/src/motion3/edit-carry.js +21 -0
  150. package/src/motion3/fix/ease.js +16 -0
  151. package/src/motion3/fix/ground.js +37 -0
  152. package/src/motion3/fix/index.js +52 -0
  153. package/src/motion3/fix/push.js +71 -0
  154. package/src/motion3/fix/reach.js +46 -0
  155. package/src/motion3/fix/retime.js +79 -0
  156. package/src/motion3/fix/self.js +211 -0
  157. package/src/motion3/fix/slide.js +70 -0
  158. package/src/motion3/fix/turn.js +51 -0
  159. package/src/motion3/follow.js +39 -0
  160. package/src/motion3/free-motion.js +173 -0
  161. package/src/motion3/grip-choice.js +130 -0
  162. package/src/motion3/hold-plan.js +157 -0
  163. package/src/motion3/json-patch.js +77 -0
  164. package/src/motion3/key-aim.js +105 -0
  165. package/src/motion3/key-edit.js +82 -0
  166. package/src/motion3/lenient.js +127 -0
  167. package/src/motion3/object-keys.js +236 -0
  168. package/src/motion3/object-pose.js +182 -0
  169. package/src/motion3/object-tracks.js +12 -0
  170. package/src/motion3/pipeline.js +102 -0
  171. package/src/motion3/playback.js +51 -0
  172. package/src/motion3/probes.js +91 -0
  173. package/src/motion3/qa/body-checks.js +34 -0
  174. package/src/motion3/qa/check-names.js +14 -0
  175. package/src/motion3/qa/checks.js +121 -0
  176. package/src/motion3/qa/contact-checks.js +51 -0
  177. package/src/motion3/qa/explain.js +80 -0
  178. package/src/motion3/qa/fmt.js +5 -0
  179. package/src/motion3/qa/foot-checks.js +72 -0
  180. package/src/motion3/qa/geometry.js +77 -0
  181. package/src/motion3/qa/goals.js +191 -0
  182. package/src/motion3/qa/ground.js +60 -0
  183. package/src/motion3/qa/hints-contact.js +179 -0
  184. package/src/motion3/qa/hints-goal.js +160 -0
  185. package/src/motion3/qa/hints-knee.js +24 -0
  186. package/src/motion3/qa/hints-motion.js +209 -0
  187. package/src/motion3/qa/hints-object.js +91 -0
  188. package/src/motion3/qa/index.js +42 -0
  189. package/src/motion3/qa/key-checks.js +82 -0
  190. package/src/motion3/qa/near.js +96 -0
  191. package/src/motion3/qa/object-checks.js +135 -0
  192. package/src/motion3/qa/patch.js +161 -0
  193. package/src/motion3/qa/severity.js +38 -0
  194. package/src/motion3/qa/spec-checks.js +65 -0
  195. package/src/motion3/qa/style.js +218 -0
  196. package/src/motion3/qa/wrist-checks.js +69 -0
  197. package/src/motion3/qa/wrist-obs.js +60 -0
  198. package/src/motion3/refs.js +120 -0
  199. package/src/motion3/repair-tune.js +121 -0
  200. package/src/motion3/repair.js +83 -0
  201. package/src/motion3/report.js +67 -0
  202. package/src/motion3/rigs/index.js +14 -0
  203. package/src/motion3/rigs/x-bot-tpose-body.json +1 -0
  204. package/src/motion3/rigs/x-bot-tpose.json +1 -0
  205. package/src/motion3/rigs/y-bot-tpose-body.json +1 -0
  206. package/src/motion3/rigs/y-bot-tpose.json +1 -0
  207. package/src/motion3/scene.js +60 -0
  208. package/src/motion3/schema/brief.js +89 -0
  209. package/src/motion3/schema/fields.js +44 -0
  210. package/src/motion3/schema/spec-examples.js +46 -0
  211. package/src/motion3/schema/topics.js +111 -0
  212. package/src/motion3/schema/types.js +147 -0
  213. package/src/motion3/search.js +117 -0
  214. package/src/motion3/second-hand.js +112 -0
  215. package/src/motion3/skills/basic.js +82 -0
  216. package/src/motion3/skills/book.js +76 -0
  217. package/src/motion3/skills/car.js +145 -0
  218. package/src/motion3/skills/frames-auto.js +29 -0
  219. package/src/motion3/skills/index.js +83 -0
  220. package/src/motion3/skills/info.js +65 -0
  221. package/src/motion3/skills/smoke-kit.js +109 -0
  222. package/src/motion3/skills/smoke.js +160 -0
  223. package/src/motion3/spec-store.js +59 -0
  224. package/src/motion3/take-edit.js +155 -0
  225. package/src/motion3/take.js +63 -0
  226. package/src/motion3/timeline.js +127 -0
  227. package/src/motion3/views.js +121 -0
  228. package/src/motion3/walk-plan.js +119 -0
  229. package/src/object-catalog.jsx +7 -1
  230. package/src/object-colors.js +98 -0
  231. package/src/object-gizmo-parts.js +115 -0
  232. package/src/object-gizmo.jsx +37 -122
  233. package/src/object-glow.js +139 -0
  234. package/src/object-hidden.js +33 -0
  235. package/src/object-look.js +196 -0
  236. package/src/object-size.js +10 -0
  237. package/src/object-travel.js +71 -6
  238. package/src/panels/CameraPanel.jsx +7 -7
  239. package/src/panels/HdrEnvironmentControls.jsx +59 -0
  240. package/src/panels/LightPanel.jsx +25 -4
  241. package/src/panels/ObjectLookPanel.jsx +88 -0
  242. package/src/panels/PosePanel.jsx +2 -17
  243. package/src/panels/RigControlPanel.jsx +5 -53
  244. package/src/panels/SubjectBox.jsx +4 -1
  245. package/src/panels/details.css +14 -0
  246. package/src/posestudio.jsx +4 -27
  247. package/src/project-browser.jsx +3 -4
  248. package/src/project-resources.js +18 -31
  249. package/src/project.js +13 -104
  250. package/src/props.jsx +25 -280
  251. package/src/rail-dot-drag.js +23 -0
  252. package/src/render-passes.js +10 -0
  253. package/src/resource-status.jsx +1 -0
  254. package/src/result-modal.jsx +4 -19
  255. package/src/room.jsx +20 -12
  256. package/src/scene-assets.js +8 -6
  257. package/src/scene-light-place.js +72 -0
  258. package/src/scene-lights.jsx +148 -0
  259. package/src/scene-objects.js +31 -139
  260. package/src/scenes.js +15 -105
  261. package/src/semantic-edit.js +2 -5
  262. package/src/set-pieces.jsx +183 -0
  263. package/src/settings-menu.jsx +3 -11
  264. package/src/shell/BottomDock.jsx +9 -51
  265. package/src/shell/DetailsSlot.jsx +16 -200
  266. package/src/shell/GhostsMenuGroup.jsx +74 -0
  267. package/src/shell/LibrarySlot.jsx +1 -3
  268. package/src/shell/MenuBar.jsx +3 -3
  269. package/src/shell/PreferencesDialog.jsx +15 -264
  270. package/src/shell/PreferencesSlot.jsx +2 -8
  271. package/src/shell/TopBar.jsx +5 -84
  272. package/src/shell/ViewportToolbar.jsx +10 -70
  273. package/src/shell/agent-glass.css +19 -6
  274. package/src/shell/details-selection.js +42 -0
  275. package/src/shell/ghosts-menu.css +22 -0
  276. package/src/shell/glass-regions.css +29 -3
  277. package/src/shell/preferences.css +6 -1
  278. package/src/shot-authoring.js +4 -7
  279. package/src/soft-shadows.js +37 -0
  280. package/src/stage-attach-frames.js +12 -12
  281. package/src/stage-canvas-rigs.jsx +3 -3
  282. package/src/stage-capture.jsx +42 -8
  283. package/src/stage-characters.jsx +22 -216
  284. package/src/stage-editor-gizmos.jsx +6 -6
  285. package/src/stage-environment.js +93 -0
  286. package/src/stage-hdr-builtins.js +107 -0
  287. package/src/stage-hdr-image.js +116 -0
  288. package/src/stage-hdr-library.js +70 -0
  289. package/src/stage-hdr-map.js +94 -0
  290. package/src/stage-hdr.js +130 -0
  291. package/src/stage-lighting.js +149 -0
  292. package/src/stage-occlusion.js +210 -0
  293. package/src/stage-sky.jsx +159 -0
  294. package/src/stage-startup-defaults.js +5 -9
  295. package/src/studio-actions.js +12 -14
  296. package/src/studio-agent-commands.js +19 -16
  297. package/src/studio-agent-motion.js +9 -9
  298. package/src/studio-agent-protocol.js +41 -71
  299. package/src/studio-app-binding.js +25 -45
  300. package/src/studio-asset-list.js +17 -0
  301. package/src/studio-contact-sheet.js +37 -5
  302. package/src/studio-elements.js +27 -7
  303. package/src/studio-entity-bounds.js +18 -0
  304. package/src/studio-error-codes.js +8 -0
  305. package/src/studio-export-framing.js +152 -0
  306. package/src/studio-lighting-check.js +103 -0
  307. package/src/studio-motion-visual.js +150 -0
  308. package/src/studio-schema-errors.js +80 -0
  309. package/src/studio-support-gap.js +74 -0
  310. package/src/styles.css +1 -19
  311. package/src/timeline-defaults.js +5 -0
  312. package/src/timeline-extent.js +8 -20
  313. package/src/tutorial-walk.js +17 -0
  314. package/src/ui-scrub.js +1 -1
  315. package/src/use-shot-camera-tracks.js +12 -0
  316. package/src/view-ghosts.js +97 -0
  317. package/src/view-ghosts.jsx +49 -0
  318. package/src/workflow/AgentPanel.jsx +47 -166
  319. package/src/workflow/AgentProgressCard.jsx +107 -0
  320. package/src/workflow/AgentReplyText.jsx +37 -0
  321. package/src/workflow/AgentTurnSteps.jsx +84 -0
  322. package/src/workflow/LoginPanel.jsx +140 -0
  323. package/src/workflow/WorkflowBuilder.jsx +7 -23
  324. package/src/workflow/agent-client.js +54 -51
  325. package/src/workflow/agent-panel.css +71 -1
  326. package/src/workflow/agent-progress-card.css +167 -0
  327. package/src/workflow/agent-progress-view.js +47 -0
  328. package/src/workflow/agent-turn-steps.css +113 -0
  329. package/src/workflow/agent-turn.js +191 -0
  330. package/src/workflow/login-client.js +34 -0
  331. package/src/workflow/motion-input.js +18 -31
  332. package/src/workflow/node-schema.js +1 -1
  333. package/src/workflow/reply-markdown.js +69 -0
  334. package/src/workflow/scene-asset-sync.js +8 -8
  335. package/tools/agent-session-stats.mjs +61 -0
  336. package/tools/dev-full.mjs +5 -56
  337. package/tools/eslint-baseline.json +12 -13
  338. package/tools/knip-baseline.json +0 -179
  339. package/tools/loc-baseline.json +31 -81
  340. package/tools/motion3/extract-body.mjs +103 -0
  341. package/tools/motion3/extract-rig.mjs +85 -0
  342. package/tools/process-supervisor.mjs +0 -88
  343. package/tools/run-tests.mjs +8 -124
  344. package/bin/agent/motion-runtime.mjs +0 -76
  345. package/dist/ardy/cskel27-rest.json +0 -557
  346. package/dist/assets/analytics-C9pMpW7s.js +0 -1
  347. package/dist/assets/app-B_2XB9rw.css +0 -1
  348. package/dist/assets/app-DAuvKPP8.js +0 -4920
  349. package/dist/assets/config-Bx7pYsD9.js +0 -1
  350. package/dist/assets/config-DeoFTYzb.css +0 -1
  351. package/dist/assets/demo-CvKuBgy5.js +0 -1
  352. package/dist/assets/scene-asset-sync-DKkpjKBV.js +0 -19
  353. package/dist/assets/scene-asset-sync-DjJ_cJ2R.css +0 -1
  354. package/dist/assets/ticket-BPk2Ni95.js +0 -1
  355. package/dist/assets/workflow-jJRBR94Z.js +0 -179
  356. package/dist/demo/walk-then-stop.npz +0 -0
  357. package/mcp/ardy-prompts.mjs +0 -218
  358. package/src/ardy/auto-fix-panel.css +0 -108
  359. package/src/ardy/auto-physics.js +0 -1194
  360. package/src/ardy/client.js +0 -153
  361. package/src/ardy/convert.js +0 -313
  362. package/src/ardy/cskel27-neutral.js +0 -39
  363. package/src/ardy/cskel27.js +0 -77
  364. package/src/ardy/export.js +0 -165
  365. package/src/ardy/fix-collisions.js +0 -2257
  366. package/src/ardy/foot-lock.js +0 -230
  367. package/src/ardy/motion-calibration.js +0 -118
  368. package/src/ardy/motion-edit.js +0 -213
  369. package/src/ardy/motion-url.js +0 -55
  370. package/src/ardy/mp4-duration.js +0 -102
  371. package/src/ardy/npz.js +0 -595
  372. package/src/ardy/physics-panel.css +0 -21
  373. package/src/ardy/physics-panel.jsx +0 -89
  374. package/src/ardy/physics-refine.js +0 -111
  375. package/src/ardy/physics-review.js +0 -567
  376. package/src/ardy/physics-temporal.js +0 -54
  377. package/src/ardy/platform-fit-panel.css +0 -64
  378. package/src/ardy/platform-fit-panel.jsx +0 -41
  379. package/src/ardy/platform-fit.js +0 -326
  380. package/src/ardy/playback.js +0 -711
  381. package/src/ardy/pose-pin.js +0 -97
  382. package/src/ardy/prompt-clips.js +0 -30
  383. package/src/ardy/retime.js +0 -211
  384. package/src/ardy/root-drop.js +0 -369
  385. package/src/ardy/timeline-resize.js +0 -13
  386. package/src/ardy/to-cskel27.js +0 -225
  387. package/src/ardy/trim.js +0 -33
  388. package/src/ardy/waypoints.js +0 -369
  389. package/src/ardy-bridge-contract.js +0 -281
  390. package/src/domains/motion/motion-video-capture.js +0 -664
  391. package/src/i2v-motion-client.js +0 -77
  392. package/src/i2v-motion-studio.jsx +0 -180
  393. package/src/line-edit.js +0 -1348
  394. package/src/motion/generation.js +0 -105
  395. package/src/motion-readiness-ui.jsx +0 -67
  396. package/src/motion-readiness.js +0 -40
  397. package/src/motion-resources.js +0 -177
  398. package/src/motion-store.js +0 -65
  399. package/src/motion-trail.js +0 -601
  400. package/src/multimodel-ingest.js +0 -394
  401. package/src/panels/PromptBlocksPanel.jsx +0 -444
  402. package/src/panels/VideoCapturePanel.jsx +0 -181
  403. package/src/pose-extract/browser.js +0 -42
  404. package/src/pose-extract/detector.js +0 -100
  405. package/src/pose-extract/fit.js +0 -227
  406. package/src/pose-extract/image-frame.js +0 -51
  407. package/src/pose-extract/index.js +0 -58
  408. package/src/pose-extract/keyframes.js +0 -74
  409. package/src/pose-extract/landmarks.js +0 -162
  410. package/src/pose-extract/mirror.js +0 -153
  411. package/src/pose-extract/take.js +0 -131
  412. package/src/pose-extract/video-frames.js +0 -91
  413. package/src/take-recipe.js +0 -165
  414. package/src/trail-key-conflicts.js +0 -39
  415. package/src/trail-pick.js +0 -59
  416. package/src/use-i2v-capture-modal.js +0 -15
  417. package/tools/ardy/BRIDGE.md +0 -37
  418. package/tools/ardy/GVHMR-NPZ.md +0 -68
  419. package/tools/ardy/README.md +0 -124
  420. package/tools/ardy/__pycache__/cclay_gvhmr_worker.cpython-313.pyc +0 -0
  421. package/tools/ardy/artifacts.mjs +0 -34
  422. package/tools/ardy/bridge.mjs +0 -1732
  423. package/tools/ardy/bvh-cskel27.mjs +0 -1265
  424. package/tools/ardy/cclay_constrained_generate.py +0 -561
  425. package/tools/ardy/cclay_gvhmr_worker.py +0 -264
  426. package/tools/ardy/cclay_motion_edit.py +0 -510
  427. package/tools/ardy/cclay_sequence_generate.py +0 -705
  428. package/tools/ardy/cclay_worker.py +0 -304
  429. package/tools/ardy/dump-npz.py +0 -205
  430. package/tools/ardy/extract-rest.mjs +0 -299
  431. package/tools/ardy/extract.mjs +0 -507
  432. package/tools/ardy/footage.mjs +0 -467
  433. package/tools/ardy/gvhmr-floor.mjs +0 -102
  434. package/tools/ardy/gvhmr-to-cskel27.mjs +0 -21
  435. package/tools/ardy/gvhmr_fastpath.py +0 -168
  436. package/tools/ardy/gvhmr_trajectory.py +0 -240
  437. package/tools/ardy/merge-text-encoder.py +0 -160
  438. package/tools/ardy/mocap-metrics.mjs +0 -200
  439. package/tools/ardy/mocap-quality-gate.mjs +0 -110
  440. package/tools/ardy/motion-stabilize.mjs +0 -348
  441. package/tools/ardy/npz.mjs +0 -414
  442. package/tools/ardy/pose-to-npz.mjs +0 -106
  443. package/tools/ardy/prompt-limits.mjs +0 -5
  444. package/tools/ardy/run-edit-on-box.sh +0 -73
  445. package/tools/ardy/run-local.mjs +0 -233
  446. package/tools/ardy/run-on-box.sh +0 -593
  447. package/tools/ardy/run-sequence-on-box.sh +0 -177
  448. package/tools/ardy/runners/gvhmr-worker.mjs +0 -206
  449. package/tools/ardy/runners/index.mjs +0 -18
  450. package/tools/ardy/runners/local.mjs +0 -455
  451. package/tools/ardy/runners/proc.mjs +0 -125
  452. package/tools/ardy/runners/remote.mjs +0 -252
  453. package/tools/ardy/setup-local.mjs +0 -189
  454. package/tools/ardy/setup-text-encoder-on-box.sh +0 -93
  455. package/tools/ardy/setup-text-encoder.py +0 -306
  456. package/tools/ardy/smpl-cskel27.mjs +0 -178
  457. package/tools/ardy/visual-qa.mjs +0 -196
  458. package/tools/ardy/vq-car.mjs +0 -52
  459. package/tools/bench/EXP3.md +0 -61
  460. package/tools/bench/cclay_bench_extract_incam.py +0 -125
  461. package/tools/bench/cclay_bench_extract_obs.py +0 -204
  462. package/tools/bench/cclay_bench_runner.py +0 -42
  463. package/tools/bench/cube-contact.mjs +0 -162
  464. package/tools/bench/exp3.mjs +0 -152
  465. package/tools/bench/extract-bench-lib.mjs +0 -216
  466. package/tools/bench/extract-bench.mjs +0 -302
  467. package/tools/bench/fal-generate.mjs +0 -88
  468. package/tools/bench/fit/README.md +0 -189
  469. package/tools/bench/fit/camera.mjs +0 -59
  470. package/tools/bench/fit/contact.mjs +0 -419
  471. package/tools/bench/fit/footlock.mjs +0 -234
  472. package/tools/bench/fit/motion.mjs +0 -85
  473. package/tools/bench/fit/pin.mjs +0 -27
  474. package/tools/bench/fit/remote.mjs +0 -105
  475. package/tools/bench/fit-bench.mjs +0 -126
  476. package/tools/bench/fit-sanity.mjs +0 -45
  477. package/tools/bench/metrics.mjs +0 -313
  478. package/tools/bench/obs/depth.mjs +0 -258
  479. package/tools/bench/obs/extrinsics.mjs +0 -175
  480. package/tools/bench/obs/fit_mannequin_betas.py +0 -340
  481. package/tools/bench/obs/ground.mjs +0 -294
  482. package/tools/bench/obs/heading.mjs +0 -151
  483. package/tools/bench/obs/ladder.mjs +0 -555
  484. package/tools/bench/obs/mannequin-betas.json +0 -124
  485. package/tools/bench/obs/remote.mjs +0 -83
  486. package/tools/bench/obs/rest_joints.py +0 -52
  487. package/tools/bench/obs/ybot-targets.mjs +0 -49
  488. package/tools/bench/obs-bench.mjs +0 -520
  489. package/tools/bench/score.mjs +0 -343
  490. package/tools/bench/summarize.mjs +0 -86
  491. package/tools/demo-worker/README.md +0 -137
  492. package/tools/demo-worker/api-client.mjs +0 -233
  493. package/tools/demo-worker/generate.mjs +0 -301
  494. package/tools/demo-worker/index.mjs +0 -466
  495. package/tools/demo-worker/sign-core.mjs +0 -112
  496. package/tools/demo-worker/sign.mjs +0 -161
  497. package/tools/gt-render/browser.mjs +0 -182
  498. package/tools/gt-render/camera-math.mjs +0 -276
  499. package/tools/gt-render/page.mjs +0 -267
  500. package/tools/gt-render/render.mjs +0 -514
  501. package/tools/gt-render/scene-box.mjs +0 -31
  502. package/tools/gt-render/take-transform.mjs +0 -87
  503. package/tools/kimodo/compare-seam.mjs +0 -108
  504. package/tools/kimodo/constraints.mjs +0 -244
  505. package/tools/kimodo/edit.mjs +0 -259
  506. package/tools/kimodo/effector-constraints.mjs +0 -200
  507. package/tools/kimodo/generate.mjs +0 -646
  508. package/tools/kimodo/local-output.mjs +0 -265
  509. package/tools/kimodo/measure-pose.mjs +0 -65
  510. package/tools/kimodo/measure-preserve.mjs +0 -899
  511. package/tools/kimodo/measure-waypoints.mjs +0 -55
  512. package/tools/kimodo/mlx-generate.py +0 -111
  513. package/tools/kimodo/pose-constraints.mjs +0 -248
  514. package/tools/kimodo/preserve-mask.mjs +0 -543
  515. package/tools/kimodo/read-npz.mjs +0 -189
  516. package/tools/kimodo/run-edit-on-box.mjs +0 -155
  517. package/tools/kimodo/run-sequence-on-box.mjs +0 -178
  518. package/tools/kimodo/runner.mjs +0 -284
  519. package/tools/kimodo/seam-batch.mjs +0 -77
  520. package/tools/kimodo/setup-local.mjs +0 -30
  521. package/tools/kimodo/setup-on-box.sh +0 -339
  522. package/tools/kimodo/soma77-to-cskel27.mjs +0 -305
  523. package/tools/morphgs/assets/gen_truth.py +0 -39
  524. package/tools/morphgs/assets/mesh_ori_rig.txt +0 -27
  525. package/tools/morphgs/assets/playback-check.mjs +0 -30
  526. package/tools/morphgs/demo-gate.sh +0 -26
  527. package/tools/morphgs/fbx2morphgs.mjs +0 -68
  528. package/tools/morphgs/morphgs-to-cskel27.mjs +0 -105
  529. package/tools/morphgs/patches/preprocess_src-none-mode.patch +0 -76
  530. package/tools/morphgs/setup-on-cluster.sh +0 -126
  531. package/tools/projflow/driver.py +0 -1069
  532. package/tools/projflow/generate.mjs +0 -805
  533. package/tools/projflow/hml22-to-cskel27.mjs +0 -735
  534. package/tools/projflow/line-edit-job.mjs +0 -547
  535. package/tools/projflow/replay.mjs +0 -452
  536. package/tools/projflow/runner.mjs +0 -269
  537. package/tools/projflow/service.mjs +0 -742
  538. package/tools/track/DESIGN.md +0 -513
  539. package/tools/track/backfill-provenance.mjs +0 -116
  540. package/tools/track/budget.mjs +0 -8
  541. package/tools/track/check-rig.mjs +0 -209
  542. package/tools/track/diagnostics.schema.json +0 -60
  543. package/tools/track/export-rig.mjs +0 -256
  544. package/tools/track/fallback.mjs +0 -7
  545. package/tools/track/fk-parity-fixture.mjs +0 -161
  546. package/tools/track/gate.mjs +0 -349
  547. package/tools/track/masks.mjs +0 -318
  548. package/tools/track/metrics.mjs +0 -201
  549. package/tools/track/publish-obs.mjs +0 -108
  550. package/tools/track/py/check_env.py +0 -61
  551. package/tools/track/py/eval_lr.py +0 -229
  552. package/tools/track/py/lr_viterbi.py +0 -294
  553. package/tools/track/py/masks.py +0 -405
  554. package/tools/track/py/objective.py +0 -382
  555. package/tools/track/py/rig.py +0 -508
  556. package/tools/track/py/scene.py +0 -326
  557. package/tools/track/py/test_joint_indices.py +0 -123
  558. package/tools/track/py/test_lr_viterbi.py +0 -195
  559. package/tools/track/py/test_masks.py +0 -229
  560. package/tools/track/py/test_rig.py +0 -288
  561. package/tools/track/py/test_scene.py +0 -354
  562. package/tools/track/py/test_track.py +0 -328
  563. package/tools/track/py/track.py +0 -411
  564. package/tools/track/remote.mjs +0 -140
  565. package/tools/track/rig-dump.mjs +0 -227
  566. package/tools/track/run-box-tests.mjs +0 -14
  567. package/tools/track/run-box.mjs +0 -168
  568. package/tools/track/setup-box.sh +0 -59
  569. package/tools/track/study-2d.mjs +0 -728
  570. /package/src/{ardy → motion}/collision-blockers.js +0 -0
  571. /package/src/{ardy → motion}/ground.js +0 -0
  572. /package/src/{ardy → motion}/ik-drag.js +0 -0
  573. /package/src/{ardy → motion}/ik-key-json.js +0 -0
  574. /package/src/{ardy → motion}/ik.js +0 -0
  575. /package/src/{ardy → motion}/physics-surface.js +0 -0
  576. /package/src/{ardy → motion}/playback-clock.js +0 -0
  577. /package/src/{ardy → motion}/range-pin.js +0 -0
@@ -0,0 +1,76 @@
1
+ import { isKo } from "../locale.js";
2
+
3
+ // Root path pins: the limits keep an authored path a person could walk, and a
4
+ // capsule figure that rides the path moves at a believable pace.
5
+ const PATH_LIMITS = Object.freeze({
6
+ speedMinMps: 0.5, // below this, "walking" cannot cycle a gait — feet slide
7
+ speedMaxMps: 3.0, // above this is out of the locomotion band entirely
8
+ holdEpsM: 0.05, // a displacement this small is a deliberate hold, any duration
9
+ minPinGapFrames: 8, // authored pins closer than this over-rail the root
10
+ speedRatioWarn: 2, // adjacent legs differing more than 2x force a gait change
11
+ turnRateWarnDegPerS: 120, // sharper turns need wider arcs than the path gives
12
+ });
13
+
14
+ const NATURAL_WALK_MPS = 1.4;
15
+
16
+ /**
17
+ * Judge the segment a candidate pin would create after `last`. Returns
18
+ * { ok, error?, warnings: [] } — `error` blocks the placement and always
19
+ * names the fix (a workable frame or distance), `warnings` accompany a
20
+ * placement that is legal but will read oddly.
21
+ * @param {{frame:number,x:number,z:number}} last the previous pin (or the frame-0 start)
22
+ * @param {{frame:number,x:number,z:number}} candidate the pin being authored
23
+ * @param {number} fps
24
+ * @param {{frame:number,x:number,z:number}|null} prev the pin before `last`, for ratio/turn warnings
25
+ */
26
+ export function judgeNextWaypoint(last, candidate, fps, prev = null) {
27
+ const gap = candidate.frame - last.frame;
28
+ if (gap < PATH_LIMITS.minPinGapFrames) {
29
+ return {
30
+ ok: false,
31
+ error: isKo ? `핀 사이에는 최소 ${PATH_LIMITS.minPinGapFrames}프레임(${(PATH_LIMITS.minPinGapFrames / fps).toFixed(1)}초)이 필요해요 — ${last.frame + PATH_LIMITS.minPinGapFrames}프레임 이후로 이동해 주세요` : `pins need at least ${PATH_LIMITS.minPinGapFrames} frames between them (${(PATH_LIMITS.minPinGapFrames / fps).toFixed(1)} s) — scrub past frame ${last.frame + PATH_LIMITS.minPinGapFrames}`,
32
+ warnings: [],
33
+ };
34
+ }
35
+ const dist = Math.hypot(candidate.x - last.x, candidate.z - last.z);
36
+ if (dist <= PATH_LIMITS.holdEpsM) return { ok: true, warnings: [] }; // a hold: legal at any length
37
+ const dt = gap / fps;
38
+ const speed = dist / dt;
39
+ if (speed > PATH_LIMITS.speedMaxMps) {
40
+ const neededFrames = Math.ceil((dist / PATH_LIMITS.speedMaxMps) * fps);
41
+ return {
42
+ ok: false,
43
+ error: isKo ? `${speed.toFixed(1)} m/s는 사람이 움직이기엔 너무 빨라요(최대 ${PATH_LIMITS.speedMaxMps}) — ${last.frame + neededFrames}프레임 이후에 핀을 찍거나 더 가까운 곳을 눌러 주세요` : `${speed.toFixed(1)} m/s is faster than anyone moves (max ${PATH_LIMITS.speedMaxMps}) — pin frame ${last.frame + neededFrames} or later, or click closer`,
44
+ warnings: [],
45
+ };
46
+ }
47
+ if (speed < PATH_LIMITS.speedMinMps) {
48
+ const walkFrame = last.frame + Math.max(PATH_LIMITS.minPinGapFrames, Math.round((dist / NATURAL_WALK_MPS) * fps));
49
+ const neededDist = (PATH_LIMITS.speedMinMps * dt).toFixed(1);
50
+ return {
51
+ ok: false,
52
+ error: isKo ? `${speed.toFixed(2)} m/s는 자연스럽게 걷기엔 너무 느려요(최소 ${PATH_LIMITS.speedMinMps}) — 대신 약 ${walkFrame}프레임에 핀을 찍거나 최소 ${neededDist} m 이상 떨어진 곳을 눌러 주세요` : `${speed.toFixed(2)} m/s is below a sustainable walk (min ${PATH_LIMITS.speedMinMps}) — pin frame ~${walkFrame} instead, or click at least ${neededDist} m away`,
53
+ warnings: [],
54
+ };
55
+ }
56
+ const warnings = [];
57
+ if (prev) {
58
+ const prevDist = Math.hypot(last.x - prev.x, last.z - prev.z);
59
+ if (prevDist > PATH_LIMITS.holdEpsM) {
60
+ const prevSpeed = prevDist / ((last.frame - prev.frame) / fps);
61
+ const ratio = Math.max(speed, prevSpeed) / Math.max(Math.min(speed, prevSpeed), 1e-6);
62
+ if (ratio > PATH_LIMITS.speedRatioWarn) {
63
+ warnings.push(isKo ? `이전 구간보다 속도가 ${ratio.toFixed(1)}배 달라요 — 걸음 변화가 눈에 보일 수 있어요` : `${ratio.toFixed(1)}x speed change from the previous leg — expect a visible gait shift`);
64
+ }
65
+ const before = Math.atan2(last.x - prev.x, last.z - prev.z);
66
+ const after = Math.atan2(candidate.x - last.x, candidate.z - last.z);
67
+ let turn = Math.abs(after - before);
68
+ if (turn > Math.PI) turn = 2 * Math.PI - turn;
69
+ const turnRate = (turn * 180) / Math.PI / dt;
70
+ if (turnRate > PATH_LIMITS.turnRateWarnDegPerS) {
71
+ warnings.push(isKo ? `${dt.toFixed(1)}초 동안 ${Math.round((turn * 180) / Math.PI)}° 회전은 걷는 동선치고 너무 급해요 — 프레임이나 거리를 더 주세요` : `${Math.round((turn * 180) / Math.PI)}° turn in ${dt.toFixed(1)} s is sharper than a walking arc — give it more frames or distance`);
72
+ }
73
+ }
74
+ }
75
+ return { ok: true, warnings };
76
+ }
@@ -0,0 +1,83 @@
1
+ // C11. What a beats contact sheet shows and what a trace plots, read from one compile of the
2
+ // installed take (pipeline.js compileSpec: out, qa, timeline, the expanded spec). Pure; see
3
+ // docs/motion-api-v3.1.md C11. Frames are absolute timeline frames (a whole compile has f0 = 0).
4
+ import { refPoint, refDistance } from "./refs.js";
5
+
6
+ const NEAR = 3, MAX_SERIES = 6;
7
+ export const TRACE_COLORS = ["#d1495b", "#2e86ab", "#edae49", "#66a182", "#a06cd5", "#f28f3b"];
8
+ const round3 = v => Math.round(v * 1000) / 1000;
9
+
10
+ /** Grab and release frames: the timeline's events (lane C), then the spec.objects grab/release
11
+ * fields (C3), so a take still shows them when the timeline lists no event. */
12
+ export function grabReleases(timeline = [], objects = {}) {
13
+ const rows = [];
14
+ for (const entry of timeline) for (const e of entry.events ?? []) if (e.event === "grab" || e.event === "release") rows.push({ f: e.f, why: `${e.event} ${e.object}` });
15
+ for (const [id, o] of Object.entries(objects ?? {})) for (const event of ["grab", "release"]) if (Number.isFinite(o?.[event])) rows.push({ f: o[event], why: `${event} ${id}` });
16
+ return rows.sort((a, b) => a.f - b.f);
17
+ }
18
+
19
+ /**
20
+ * Up to `count` frames inside [lo, hi], in this order: grab and release frames, beat starts
21
+ * (timeline f[0]), the worstFrame of the top 2 QA groups (qa.groups is ranked), then even fill:
22
+ * the `even` frames, then any frame, each time the one farthest from the frames picked so far.
23
+ * A frame within +-3 of a pick is dropped. Deterministic; answers { frames, picks: [{ f, why }] },
24
+ * ascending. With nothing to read it answers the even frames.
25
+ */
26
+ export function beatFrames({ range: [lo, hi], even = [], timeline = [], groups = [], objects = {}, count = 6 }) {
27
+ const picks = [], gap = f => picks.reduce((d, p) => Math.min(d, Math.abs(p.f - f)), Infinity);
28
+ const offer = (f, why) => {
29
+ if (!Number.isFinite(f)) return;
30
+ f = Math.round(f);
31
+ if (picks.length < count && f >= lo && f <= hi && gap(f) > NEAR) picks.push({ f, why });
32
+ };
33
+ for (const row of grabReleases(timeline, objects)) offer(row.f, row.why);
34
+ for (const entry of timeline) offer(entry.f?.[0], `start ${entry.beat}`);
35
+ for (const g of groups.slice(0, 2)) offer(g.worstFrame, `worst ${g.kind} ${String(g.subject).split(": ")[0]}`);
36
+ const every = Array.from({ length: Math.max(0, hi - lo + 1) }, (_, i) => lo + i);
37
+ for (const pool of [even.filter(f => f >= lo && f <= hi), every]) {
38
+ while (picks.length < count) {
39
+ let best = null, far = NEAR;
40
+ for (const f of pool) { const d = gap(f); if (d > far) { best = f; far = d; } }
41
+ if (best === null) break;
42
+ picks.push({ f: best, why: "even" });
43
+ }
44
+ }
45
+ picks.sort((a, b) => a.f - b.f);
46
+ return { frames: picks.map(p => p.f), picks };
47
+ }
48
+
49
+ /** What a trace plots: both hand heights, the distance of every `near` goal and every distance
50
+ * probe the spec carries, and each carried object's prop origin to the object's surface. */
51
+ function traceDefs(spec = {}) {
52
+ const defs = [
53
+ { name: "hand_l.y", at: (out, f) => refPoint(out, f, "joint:LeftHand")?.[1] },
54
+ { name: "hand_r.y", at: (out, f) => refPoint(out, f, "joint:RightHand")?.[1] },
55
+ ];
56
+ const pair = (name, [a, b]) => defs.push({ name, at: (out, f) => refDistance(out, f, a, b) });
57
+ (spec.goals ?? []).forEach((g, i) => { if (Array.isArray(g?.near)) pair(`near ${g.name ?? `goals[${i}]`}`, g.near); });
58
+ (spec.probes ?? []).forEach((p, i) => { if (Array.isArray(p?.distance)) pair(p.name ?? `probes[${i}]`, p.distance); });
59
+ for (const [id, o] of Object.entries(spec.objects ?? {})) if (typeof o?.prop === "string") pair(`${o.prop} to ${id}`, [`prop:${o.prop}.origin`, `object:${id}`]);
60
+ return defs.slice(0, MAX_SERIES);
61
+ }
62
+
63
+ /**
64
+ * Series over absolute frames lo..hi (clamped to the compiled frames): { name, color, unit,
65
+ * min, minAt, max, maxAt, values } with values[i] the value at frame lo + i, or null. A series
66
+ * with no value anywhere is left out.
67
+ */
68
+ export function traceSeries(out, spec, [lo, hi]) {
69
+ const f0 = out.f0 ?? 0, last = Math.min(hi, f0 + out.frames.length - 1), first = Math.max(lo, f0), series = [];
70
+ for (const def of traceDefs(spec)) {
71
+ const values = [];
72
+ let min = Infinity, minAt = null, max = -Infinity, maxAt = null;
73
+ for (let f = first; f <= last; f++) {
74
+ const raw = def.at(out, f), v = Number.isFinite(raw) ? round3(raw) : null;
75
+ values.push(v);
76
+ if (v === null) continue;
77
+ if (v < min) { min = v; minAt = f; }
78
+ if (v > max) { max = v; maxAt = f; }
79
+ }
80
+ if (minAt !== null) series.push({ name: def.name, color: TRACE_COLORS[series.length], unit: "m", min, minAt, max, maxAt, values });
81
+ }
82
+ return { range: [first, last], series };
83
+ }
@@ -0,0 +1,158 @@
1
+ // The body a limb must stay out of, fitted from the rig's skin (tools/motion3/extract-body.mjs):
2
+ // a signed distance grid per skinned bone in that bone's bind frame (the bone carries it rigidly;
3
+ // outside positive, metres) and, for the limbs, the skin radius along the bone. A limb collides as
4
+ // spheres on its bone axis (limbProbes); bodyDistance is the nearest skin of every other bone but
5
+ // the limb's own neighbours (SKIP), so an arm reads the torso, the head, the legs and the other arm.
6
+ import yBody from "./rigs/y-bot-tpose-body.json" with { type: "json" };
7
+ import xBody from "./rigs/x-bot-tpose-body.json" with { type: "json" };
8
+ import { add, sub, scale, apply, T, len, dot, clamp } from "./compiler/math.js";
9
+
10
+ const BODIES = { "y-bot-tpose": yBody, "x-bot-tpose": xBody };
11
+ /** Distance read outside a grid: far enough that no probe counts it as touching. */
12
+ const FAR = 0.1;
13
+ const cache = new Map();
14
+
15
+ function decode(text) {
16
+ const bytes = typeof Buffer !== "undefined" ? Buffer.from(text, "base64") : Uint8Array.from(atob(text), c => c.charCodeAt(0));
17
+ return new Int8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
18
+ }
19
+
20
+ /** The neighbours a limb bone may touch without colliding: itself, its parent, its children, and for
21
+ * an upper arm the collarbone and chest it hangs from (only near the shoulder: see limbProbes). */
22
+ function skipOf(sk, b) {
23
+ const out = new Set([b, sk.parent[b], ...sk.children[b]]);
24
+ if (/^(Left|Right)Arm$/.test(sk.names[b])) out.add(sk.parent[sk.parent[b]]);
25
+ if (/^(Left|Right)UpLeg$/.test(sk.names[b])) out.add(sk.index.Spine);
26
+ return out;
27
+ }
28
+
29
+ /** The fitted body of skeleton sk, or null for a rig without one. */
30
+ export function bodyFor(sk) {
31
+ const fit = BODIES[sk.model];
32
+ if (!fit) return null;
33
+ if (cache.has(sk.model)) return cache.get(sk.model);
34
+ const grids = Object.entries(fit.grids).map(([name, g]) => {
35
+ const half = g.dims.map(d => ((d - 1) * fit.step) / 2), centre = g.min.map((m, k) => m + half[k]);
36
+ return { b: sk.index[name], min: g.min, dims: g.dims, data: decode(g.data), centre, reach: len(half) };
37
+ });
38
+ const radii = Object.fromEntries(Object.entries(fit.radii).map(([name, r]) => [sk.index[name], r]));
39
+ const body = { step: fit.step, grids, radii, skip: new Map(Object.keys(radii).map(b => [+b, skipOf(sk, +b)])) };
40
+ cache.set(sk.model, body);
41
+ return body;
42
+ }
43
+
44
+ /** Trilinear signed distance (m) of a point in grid g's bone frame. */
45
+ function sample(body, g, q) {
46
+ const [nx, ny, nz] = g.dims, step = body.step;
47
+ const fx = (q[0] - g.min[0]) / step, fy = (q[1] - g.min[1]) / step, fz = (q[2] - g.min[2]) / step;
48
+ if (fx < 0 || fy < 0 || fz < 0 || fx > nx - 1 || fy > ny - 1 || fz > nz - 1) return FAR;
49
+ const x = Math.min(nx - 2, Math.floor(fx)), y = Math.min(ny - 2, Math.floor(fy)), z = Math.min(nz - 2, Math.floor(fz));
50
+ const u = fx - x, v = fy - y, w = fz - z, at = (i, j, k) => g.data[((x + i) * ny + y + j) * nz + z + k];
51
+ const c00 = at(0, 0, 0) * (1 - u) + at(1, 0, 0) * u, c01 = at(0, 0, 1) * (1 - u) + at(1, 0, 1) * u;
52
+ const c10 = at(0, 1, 0) * (1 - u) + at(1, 1, 0) * u, c11 = at(0, 1, 1) * (1 - u) + at(1, 1, 1) * u;
53
+ return ((c00 * (1 - v) + c10 * v) * (1 - w) + (c01 * (1 - v) + c11 * v) * w) / 1000;
54
+ }
55
+
56
+ /** Each grid's centre in the world at state s (cached per state: a planner asks thousands of points of one pose). */
57
+ const centres = new WeakMap();
58
+ function centresAt(body, s) {
59
+ let c = centres.get(s);
60
+ if (!c) { c = body.grids.map(g => add(s.P[g.b], apply(s.R[g.b], g.centre))); centres.set(s, c); }
61
+ return c;
62
+ }
63
+
64
+ /** Signed distance (m) from p to the skin of every bone not in `skip`, with the bone it came from. */
65
+ export function bodyDistance(body, s, p, skip = null) {
66
+ let best = FAR, bone = -1;
67
+ const c = centresAt(body, s);
68
+ body.grids.forEach((g, i) => {
69
+ if (skip?.has(g.b) || len(sub(p, c[i])) - g.reach > best) return;
70
+ const d = sample(body, g, apply(T(s.R[g.b]), sub(p, s.P[g.b])));
71
+ if (d < best) { best = d; bone = g.b; }
72
+ });
73
+ return { d: best, bone };
74
+ }
75
+
76
+ /** Unit direction out of the skin at p (central differences of bodyDistance). */
77
+ export function bodyNormal(body, s, p, skip = null, h = 0.01) {
78
+ const g = [0, 1, 2].map(k => {
79
+ const e = [0, 0, 0]; e[k] = h;
80
+ return bodyDistance(body, s, add(p, e), skip).d - bodyDistance(body, s, sub(p, e), skip).d;
81
+ });
82
+ const l = len(g);
83
+ return l > 1e-9 ? scale(g, 1 / l) : null;
84
+ }
85
+
86
+ /** Spheres { p, r, t } on limb bone b's axis (to its first child), from the fitted skin radius. Near an
87
+ * upper arm's shoulder (its armpit half: arm and chest skin are one there) or a thigh's hip the trunk is
88
+ * its neighbour, so those stations are left out. */
89
+ const rootOf = name => (/^(Left|Right)Arm$/.test(name) ? 0.5 : /^(Left|Right)UpLeg$/.test(name) ? 0.3 : 0);
90
+ /** Where limb bone b's axis ends: its child joint, for a hand the middle finger's knuckle (the first
91
+ * child is a thumb or a ring finger, rig by rig). */
92
+ export const axisEnd = (sk, b) => (/Hand$/.test(sk.names[b]) ? sk.index[sk.names[b].replace(/Hand$/, "HandMiddle1")] : sk.children[b][0]);
93
+ function limbProbes(body, sk, s, b) {
94
+ const prof = body.radii[b], child = axisEnd(sk, b);
95
+ if (!prof || child === undefined) return [];
96
+ const A = s.P[b], axis = sub(s.P[child], A), root = rootOf(sk.names[b]);
97
+ return prof.filter(([t]) => t >= root).map(([t, r]) => ({ p: add(A, scale(axis, t)), r, t }));
98
+ }
99
+
100
+ /** The trunk runs Hips-Spine-Spine1-Spine2-Neck: a trunk bone's axis goes to its trunk child, a limb's to axisEnd. */
101
+ const TRUNK = /^(Spine\d?|Neck|Head)$/;
102
+ const axisOf = (sk, b) => sk.children[b].find(j => TRUNK.test(sk.names[j])) ?? axisEnd(sk, b);
103
+
104
+ /**
105
+ * Point p moved out of the body (bones not in `skip`) until its skin distance is at least `clear`, along
106
+ * the line from the axis of the bone it is in: deep inside, the skin's normal turns with every millimetre,
107
+ * the way out from the bone does not, so a target sliding through a thigh slides out of it smoothly.
108
+ * The distance along that line is found by bisection. p itself when it is clear already.
109
+ */
110
+ const OUT_MAX = 0.25;
111
+ export function keepOut(body, sk, s, p, clear, skip = null) {
112
+ const hit = bodyDistance(body, s, p, skip);
113
+ if (hit.d >= clear || hit.bone < 0) return p;
114
+ const A = s.P[hit.bone], end = axisOf(sk, hit.bone), B = end === undefined ? A : s.P[end], ab = sub(B, A);
115
+ const t = dot(ab, ab) > 1e-9 ? clamp(dot(sub(p, A), ab) / dot(ab, ab), 0, 1) : 0, off = sub(p, add(A, scale(ab, t)));
116
+ const dir = len(off) > 1e-4 ? scale(off, 1 / len(off)) : bodyNormal(body, s, p, skip);
117
+ if (!dir) return p;
118
+ // clear of the bone it is in (another bone on the way out is the next call's: one bone at a time stays bounded)
119
+ const only = new Set(body.grids.map(g => g.b).filter(b => b !== hit.bone)), clearAt = k => bodyDistance(body, s, add(p, scale(dir, k)), only).d >= clear;
120
+ let lo = 0, hi = 0.02;
121
+ while (!clearAt(hi) && hi < OUT_MAX) { lo = hi; hi = Math.min(OUT_MAX, hi * 2); }
122
+ for (let i = 0; i < 10; i++) { const mid = (lo + hi) / 2; if (clearAt(mid)) hi = mid; else lo = mid; }
123
+ return add(p, scale(dir, hi));
124
+ }
125
+
126
+ /** How far (m) a wrist target stays off the skin (the hand's radius at the wrist, and a little). */
127
+ export const HAND_CLEAR = 0.03;
128
+ /** What a wrist target keeps out of: the body but the arms (they move with it) and the head and neck (a hand
129
+ * comes to the mouth or the face on purpose: QA's BODY and FACE report what goes too deep). null without a body. */
130
+ export function wristBody(sk) {
131
+ const body = bodyFor(sk);
132
+ return body && { body, skip: new Set(sk.names.map((n, b) => (/(Arm|ForeArm|Hand|Neck|Head.*)$/.test(n) ? b : -1)).filter(b => b >= 0)) };
133
+ }
134
+
135
+ /** How deep (m) limb bone b goes into the rest of the body were its axis A-B (its own pose may differ:
136
+ * a planner trying an elbow), 0 when clear. */
137
+ export function segmentDepth(body, sk, s, b, A, B) {
138
+ let worst = 0;
139
+ const root = rootOf(sk.names[b]);
140
+ for (const [t, r] of body.radii[b] ?? []) {
141
+ if (t < root) continue;
142
+ const { d, bone } = bodyDistance(body, s, add(A, scale(sub(B, A), t)), body.skip.get(b));
143
+ if (bone >= 0) worst = Math.max(worst, r - d);
144
+ }
145
+ return worst;
146
+ }
147
+
148
+ /** How far (m) limb bone b's skin goes into the rest of the body at state s (0 when clear), where, and into which bone. */
149
+ export function limbDepth(body, sk, s, b) {
150
+ let worst = { depth: 0, p: null, into: -1 };
151
+ for (const probe of limbProbes(body, sk, s, b)) {
152
+ const { d, bone } = bodyDistance(body, s, probe.p, body.skip.get(b));
153
+ const depth = probe.r - d;
154
+ if (bone >= 0 && depth > worst.depth) worst = { depth, p: probe.p, into: bone, r: probe.r };
155
+ }
156
+ return worst;
157
+ }
158
+
@@ -0,0 +1,47 @@
1
+ // Bone names as the agent writes them -> the rig's bone. Tried in order: the exact name, the
2
+ // name in any case ("hips", "lefthand"), the name without a "mixamorig:" prefix, then aliases
3
+ // ("pelvis" -> Hips, "hand_l" / "l_hand" / "left hand" -> LeftHand, "thigh_r" -> RightUpLeg).
4
+ // Nothing found: a "did you mean" suggestion. Callers that hand the name on to code that needs
5
+ // the exact name (validate-common.js boneOk, sk.index) use the answered `bone`.
6
+ import { didYouMean } from "./compiler/vocab.js";
7
+
8
+ // Unsided aliases (lower case, no separators) -> the rig's name.
9
+ const ALIAS = { pelvis: "Hips", hip: "Hips", hips: "Hips", root: "Hips", chest: "Spine2", upperchest: "Spine2", torso: "Spine1", belly: "Spine",
10
+ abdomen: "Spine", neck: "Neck", head: "Head" };
11
+ // Sided part aliases -> the part after Left/Right.
12
+ const PART = { hand: "Hand", wrist: "Hand", foot: "Foot", ankle: "Foot", toe: "ToeBase", toes: "ToeBase", ball: "ToeBase", arm: "Arm", upperarm: "Arm",
13
+ forearm: "ForeArm", lowerarm: "ForeArm", elbow: "ForeArm", shoulder: "Shoulder", clavicle: "Shoulder", thigh: "UpLeg", upleg: "UpLeg",
14
+ upperleg: "UpLeg", leg: "Leg", lowerleg: "Leg", shin: "Leg", calf: "Leg", knee: "Leg" };
15
+ const SIDE = { l: "Left", left: "Left", r: "Right", right: "Right" };
16
+
17
+ const squash = s => s.toLowerCase().replace(/[\s_.-]+/g, "");
18
+
19
+ function caseless(sk, name) {
20
+ const want = name.toLowerCase();
21
+ return sk.names.find(n => n.toLowerCase() === want) ?? null;
22
+ }
23
+
24
+ function alias(sk, name) {
25
+ const flat = squash(name);
26
+ if (ALIAS[flat]) return caseless(sk, ALIAS[flat]);
27
+ const low = name.toLowerCase().trim();
28
+ const pre = /^(l|r|left|right)[\s_.-]+(.+)$/.exec(low) ?? /^(left|right)(.+)$/.exec(low);
29
+ const post = /^(.+?)[\s_.-]+(l|r|left|right)$/.exec(low) ?? /^(.+?)(left|right)$/.exec(low);
30
+ const [side, part] = pre ? [pre[1], pre[2]] : post ? [post[2], post[1]] : [];
31
+ if (!side) return null;
32
+ return caseless(sk, `${SIDE[side]}${PART[squash(part)] ?? squash(part)}`);
33
+ }
34
+
35
+ /**
36
+ * @param {{ index: Record<string, number>, names: string[] }} sk the rig (rigs/index.js skeletonFor)
37
+ * @param {string} name
38
+ * @returns {{ bone: string | null, hint: string }} bone = the rig's own name, or null; hint = the
39
+ * suffix for an error message when bone is null ('; did you mean "LeftHand"?' or "").
40
+ */
41
+ export function resolveBone(sk, name) {
42
+ if (typeof name !== "string" || !name) return { bone: null, hint: "" };
43
+ if (sk.index[name] !== undefined) return { bone: name, hint: "" };
44
+ const bare = name.replace(/^mixamorig\d*:/i, "");
45
+ const bone = caseless(sk, name) ?? caseless(sk, bare) ?? alias(sk, bare);
46
+ return bone ? { bone, hint: "" } : { bone: null, hint: didYouMean(bare, sk.names) };
47
+ }
@@ -0,0 +1,47 @@
1
+ // Scene objects a hand carries: spec.objects[id] = { prop, grab?, release?, at?, along?, visible? }
2
+ // puts the record (a body, or a group root) on prop `prop` (spec.props). `at` is the record's base
3
+ // along the palm axes [d, l, n] from the prop origin, `along` the palm direction its +Y (a
4
+ // cylinder's length) takes, and `visible` a channel that shows the record while it is above 0.5
5
+ // (a step key in the pocket). Without at/along a grabbed record keeps the transform it had
6
+ // against the palm at the grab frame (object-pose.js). Also the rigid-pose algebra and the hinge
7
+ // pose the compiler, the take and QA share.
8
+ import { palmAxes } from "./compiler/limbs.js";
9
+ import { SIDES } from "./compiler/pose.js";
10
+ import { add, scale, norm, sub, dot, cross, apply, mul, T, axisRot, I3 } from "./compiler/math.js";
11
+
12
+ export const isCarried = o => typeof o?.prop === "string";
13
+ /** A follow entry { follow: <ref>, offset?, aim?, visible?, level? } (C16, follow.js): the record rides a point of the body. */
14
+ export const isFollow = o => !isCarried(o) && o?.follow !== undefined;
15
+ /** A switch entry { visible?, level? } (C15): no prop, follow, hinge, keys or fall field (C17), so it moves nothing; it shows, hides or dims its record. */
16
+ export const isSwitch = o => !!o && typeof o === "object" && !Array.isArray(o) && ["prop", "follow", "pivot", "axis", "channel", "keys", "fall"].every(k => o[k] === undefined);
17
+ /** An entry that moves its record (a carry, a follow or a hinge), as opposed to a switch. */
18
+ export const movesRecord = o => !!o && typeof o === "object" && !isSwitch(o);
19
+
20
+ /** Mean of the prop's origin joints on pose s (the point the hand holds the prop by). */
21
+ export function propOrigin(sk, spec, s, o) {
22
+ const prop = spec.props[o.prop];
23
+ return scale(prop.origin.map(b => s.P[sk.index[b]]).reduce((a, p) => add(a, p), [0, 0, 0]), 1 / prop.origin.length);
24
+ }
25
+
26
+ /** World { pos, R } of a carried record on pose s (at/along offset, PR #14). */
27
+ export function carriedPose(sk, spec, s, o) {
28
+ const ax = palmAxes(sk, s, SIDES[spec.props[o.prop].hand]), origin = propOrigin(sk, spec, s, o);
29
+ const palm = v => add(scale(ax.d, v[0]), add(scale(ax.l, v[1]), scale(ax.n, v[2])));
30
+ const y = norm(palm(o.along ?? [0, 0, 1]));
31
+ let x = sub(ax.d, scale(y, dot(ax.d, y)));
32
+ if (Math.hypot(...x) < 1e-6) x = sub(ax.l, scale(y, dot(ax.l, y)));
33
+ x = norm(x);
34
+ const z = cross(x, y);
35
+ return { pos: add(origin, palm(o.at ?? [0, 0, 0])), R: [[x[0], y[0], z[0]], [x[1], y[1], z[1]], [x[2], y[2], z[2]]] };
36
+ }
37
+
38
+ /** a * b for rigid poses { pos, R }. */
39
+ export const compose = (a, b) => ({ pos: add(a.pos, apply(a.R, b.pos)), R: mul(a.R, b.R) });
40
+ /** a^-1 * b: b in a's frame. */
41
+ export const relative = (a, b) => ({ pos: apply(T(a.R), sub(b.pos, a.pos)), R: mul(T(a.R), b.R) });
42
+
43
+ /** A record at `rest` turned by hinge { pivot, axis, channel } at frame f of the baked channels. */
44
+ export function hingePose(hinge, rest, baked, f) {
45
+ const angle = baked[hinge.channel]?.[f] ?? 0, R = axisRot(hinge.axis ?? [0, 1, 0], angle);
46
+ return { pos: add(hinge.pivot, apply(R, sub(rest.pos, hinge.pivot))), R: mul(R, rest.R ?? I3()), angle };
47
+ }
@@ -0,0 +1,75 @@
1
+ // One motion compile as a job of plain data, the same in the compile worker (compile-worker.js) and on
2
+ // the calling thread (commands/motion3-compile.js, where no worker runs: Node, tests): the rig by model
3
+ // name, the motion scene (scene.js motionScene of the editor's objects: boxes only), the spec as sent, and
4
+ // what to do with it (probes, checks, lenient, repair, bake). The answer is plain data and typed arrays
5
+ // only (the compiler's out holds closures), so it crosses a worker boundary: QA, observations, the stored
6
+ // spec, and the baked take when asked.
7
+ // A refusal is an Error with a code (INVALID_ARGUMENT, MOTION_SPEC_INVALID turned into it), which the
8
+ // client turns back into the Studio's protocol error.
9
+ import { compileSpec, liftRequest } from "./pipeline.js";
10
+ import { repairSpec } from "./repair.js";
11
+ import { bakeTake } from "./take.js";
12
+ import { skeletonFor } from "./rigs/index.js";
13
+
14
+ const TIMELINE_FPS = 24;
15
+ const refuse = (code, message) => { throw Object.assign(new Error(message), { code }); };
16
+
17
+ /** Runs `run`, turning a MOTION_SPEC_INVALID error into INVALID_ARGUMENT with the exact message. */
18
+ function asArgument(run) {
19
+ try {
20
+ return run();
21
+ } catch (error) {
22
+ if (/^MOTION_SPEC_INVALID/.test(error.message)) refuse("INVALID_ARGUMENT", error.message.replace(/^MOTION_SPEC_INVALID:\s*/, ""));
23
+ throw error;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * The same plain data as fresh literals. Objects that came through a structured clone (a worker message) make
29
+ * the compiler's hot loops ~60% slower in V8 (their shapes); a copy built from literals runs at full speed and
30
+ * keeps every value exactly (unlike a JSON round trip: -0, NaN, Infinity).
31
+ */
32
+ const fresh = value => (Array.isArray(value) ? value.map(fresh) : value && typeof value === "object" && !ArrayBuffer.isView(value)
33
+ ? Object.fromEntries(Object.keys(value).map(k => [k, fresh(value[k])])) : value);
34
+
35
+ /**
36
+ * runCompileJob({ model, scene, spec, probes?, checks?, lenient?, repair?, bake? }) -> { stored, qa, observations,
37
+ * used, fixed, search, timeline, probes?, notes?, ms (+ repair: its wall ms), frameCount, label, repair?, take? }
38
+ * bake: { position, yaw, prompt? } bakes the final result's take (prompt: given, else the final spec's label).
39
+ */
40
+ export function runCompileJob({ model, scene, spec: asked, probes: sentProbes, checks, lenient, repair, bake }) {
41
+ const sk = skeletonFor(model);
42
+ const opts = { ...(checks ? { checks } : {}), ...(lenient ? { lenient: true } : {}) };
43
+ // spec.probes and bare moved ids are lifted before fps is filled in, so the specId stays the spec's own
44
+ const once = s => {
45
+ const { spec, probes } = liftRequest(s, sentProbes);
46
+ if (spec?.fps !== undefined && spec.fps !== TIMELINE_FPS) refuse("INVALID_ARGUMENT", `spec.fps must be ${TIMELINE_FPS}, the timeline rate.`);
47
+ const sent = { fps: TIMELINE_FPS, ...spec };
48
+ const r = asArgument(() => compileSpec(sent, { sk, scene }, { ...opts, probes }));
49
+ return { ...r, stored: r.spec === sent ? spec : r.spec };
50
+ };
51
+ const t0 = performance.now(), fixed = repair ? repairSpec(asked, repair, once) : { spec: asked, result: once(asked) };
52
+ // ms.repair: the whole repair's wall time, so a sweep that repairs every variant shows what it costs
53
+ const r = fixed.result, label = fixed.spec?.label ?? null, ms = fixed.repair ? { ...r.ms, repair: Math.round(performance.now() - t0) } : r.ms;
54
+ const take = bake ? bakeTake(sk, r.out, { position: bake.position, yaw: bake.yaw }, { spec: r.stored, prompt: ("prompt" in bake ? bake.prompt : label) ?? "" }) : undefined;
55
+ return { stored: r.stored, qa: r.qa, observations: r.observations, used: r.used, fixed: r.fixed, search: r.search, timeline: r.timeline,
56
+ ...(r.probes ? { probes: r.probes } : {}), ...(r.notes ? { notes: r.notes } : {}), ms, frameCount: r.out.frameCount, label,
57
+ ...(fixed.repair ? { repair: fixed.repair } : {}), ...(take ? { take } : {}) };
58
+ }
59
+
60
+ /** The ArrayBuffers under a job answer's typed arrays (each once), to transfer instead of copy. */
61
+ function buffersOf(value, found = new Set()) {
62
+ if (ArrayBuffer.isView(value)) found.add(value.buffer);
63
+ else if (value && typeof value === "object") for (const v of Object.values(value)) buffersOf(v, found);
64
+ return [...found];
65
+ }
66
+
67
+ /** The worker's answer to { id, job }: { message: { id, value }, transfer } or { message: { id, error: { message, code, name } }, transfer: [] }. */
68
+ export function answerOf({ id, job }) {
69
+ try {
70
+ const value = runCompileJob(fresh(job));
71
+ return { message: { id, value }, transfer: buffersOf(value) };
72
+ } catch (error) {
73
+ return { message: { id, error: { message: String(error?.message ?? error), code: error?.code ?? null, name: error?.name ?? "Error" } }, transfer: [] };
74
+ }
75
+ }
@@ -0,0 +1,10 @@
1
+ // The motion compile worker: runs compile jobs (compile-job.js) off the editor's main thread, one at a time
2
+ // in arrival order, and answers each { id } with { id, value } (typed arrays transferred) or { id, error }.
3
+ // On the main thread the compiler runs about 4x slower than here (measured: 6.2 s against 1.5 s for a
4
+ // 240-frame carry) and blocks the viewport and the agent panel for the whole compile.
5
+ import { answerOf } from "./compile-job.js";
6
+
7
+ self.onmessage = ({ data }) => {
8
+ const { message, transfer } = answerOf(data);
9
+ self.postMessage(message, transfer);
10
+ };
@@ -0,0 +1,105 @@
1
+ // Hand-target anchors and hand-held props for the motion3 compiler.
2
+ //
3
+ // spec.anchors = { name: anchor }, an anchor being one of
4
+ // { kind: "world", p: [x,y,z] } fixed world point (m)
5
+ // { kind: "body", p: [x,y,z] } root-relative, rotated by root yaw
6
+ // { kind: "bone", bone: "LeftLeg", offset: [x,y,z] } world offset from a bone joint
7
+ // { kind: "segment", from: "LeftUpLeg", to: "LeftLeg", t: 0.4, offset: [x,y,z], reach: "l" }
8
+ // point along a segment; with reach, slides toward `from` until the arm reaches
9
+ // { kind: "object", object: "Car_Door_L", local: [x,y,z] } point fixed to a scene object or group where it is at
10
+ // that frame (hinged, carried, following; object-pose.js objectPoseAt), in its own axes
11
+ // { kind: "landmark", name: "mouth" } measured face landmark on the Head bone
12
+ // { kind: "prop", prop: "cig", point: "tip", offset: [x,y,z] } a point on a prop held by the other hand
13
+ // spec.props = { name: { hand: "r", origin: ["RightHandIndex2", "RightHandMiddle2"],
14
+ // points: { name: [d, l, n] } } } offsets along the palm axes (m)
15
+ import { add, sub, scale, len, apply, ry } from "./math.js";
16
+ import { bonePoint } from "./skeleton.js";
17
+ import { palmAxes } from "./limbs.js";
18
+ import { SIDES } from "./pose.js";
19
+ import { HAND_CLEAR, keepOut } from "../body.js";
20
+ import { groupsOf } from "../scene.js";
21
+
22
+ function armReach(sk, k) {
23
+ const side = SIDES[k], P = sk.restWorldPos, I = sk.index;
24
+ return len(sub(P[I[`${side}ForeArm`]], P[I[`${side}Arm`]])) + len(sub(P[I[`${side}Hand`]], P[I[`${side}ForeArm`]]));
25
+ }
26
+
27
+ /** Resolve a named anchor to a world point for the current (partial) frame state. */
28
+ /** Anchors placed off the root (a pocket): with fix.self (ctx.keepOut, compile.js) a point the pose put inside
29
+ * the skin resolves onto it, HAND_CLEAR off, for the hand and for every check alike. A bone's or a segment's
30
+ * anchor is the spec's own place on that limb (a hand resting on a thigh) and stays. */
31
+ const ON_BODY = new Set(["body"]);
32
+ /** side: the hand ("l" | "r") this point is a target for while the compiler solves it; none for a reader of a solved frame. */
33
+ export function resolveAnchor(ctx, name, s, diag, c, side) {
34
+ const a = ctx.spec.anchors?.[name];
35
+ if (!a) throw new Error(`MOTION_SPEC_INVALID: unknown anchor "${name}"`);
36
+ const p = anchorPoint(ctx, a, name, s, diag, c, side), skin = ON_BODY.has(a.kind) && ctx.keepOut;
37
+ return skin ? keepOut(skin.body, ctx.sk, s, keepOut(skin.body, ctx.sk, s, p, HAND_CLEAR, skin.skip), HAND_CLEAR, skin.skip) : p;
38
+ }
39
+
40
+ // pose.js solves the right arm, then the left
41
+ const ARMS = ["r", "l"], HAND = { l: "left", r: "right" };
42
+
43
+ /**
44
+ * The pose { pos, R } an object anchor's `local` is in at frame diag.frame: where the object is then (ctx.objectPose,
45
+ * the pose refs and probes read). A hand cannot aim at what rides on it: the hand that carries the object keeps the
46
+ * scene pose, where it took it. While the right arm is solved the left is not, so the right hand cannot aim at what
47
+ * the left carries (refused).
48
+ */
49
+ export function objectFrame(ctx, a, name, { s, diag, c }, side) {
50
+ const f = diag.frame, still = () => ctx.restingAt?.(a.object, f) ?? ctx.objectsAt(f)[a.object] ?? groupsOf(ctx.scene)[a.object];
51
+ const hand = ctx.objectPose && f !== undefined ? ctx.objectHand(a.object, f) : null;
52
+ if (side && hand && ARMS.indexOf(hand) > ARMS.indexOf(side)) throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" is on "${a.object}", which the ${HAND[hand]} hand holds at f${f}; the right arm is solved before the left, so the right hand cannot follow it. Carry "${a.object}" in the right hand (a right-hand prop) and put the left hand on it, or give the right hand another anchor`);
53
+ const pose = !ctx.objectPose || f === undefined || hand === side ? still() : nested(ctx, name, a.object, f, () => ctx.objectPose(a.object, f, { s, diag, c }));
54
+ if (!pose) throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" names unknown object "${a.object}"`);
55
+ return pose;
56
+ }
57
+
58
+ // Reading an object may solve another frame (a keyed carry's grab offset, object-keys.js), whose hands read objects
59
+ // again; legitimate reads nest a few deep, so a deeper chain is a loop and is refused instead of overflowing the stack.
60
+ const MAX_NEST = 16;
61
+ function nested(ctx, name, object, f, read) {
62
+ if ((ctx.nest ?? 0) >= MAX_NEST) throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" on "${object}" at f${f} reads a pose that needs this frame solved again (an anchor and carry loop); anchor the hand on a point that does not ride on the hand it moves`);
63
+ ctx.nest = (ctx.nest ?? 0) + 1;
64
+ try { return read(); } finally { ctx.nest--; }
65
+ }
66
+
67
+ function anchorPoint(ctx, a, name, s, diag, c, side) {
68
+ const { sk } = ctx, I = sk.index;
69
+ switch (a.kind) {
70
+ case "world": return a.p.slice();
71
+ case "body": return add(c.root ?? s.P[I.Hips], apply(ry(c.yaw ?? 0), a.p));
72
+ case "bone": return add(s.P[I[a.bone]], a.offset ?? [0, 0, 0]);
73
+ case "segment": {
74
+ const A = s.P[I[a.from]], B = s.P[I[a.to]], off = a.offset ?? [0, 0, 0];
75
+ const at = t => add(add(A, scale(sub(B, A), t)), off);
76
+ if (!a.reach) return at(a.t ?? 0.5);
77
+ const sh = s.P[I[`${SIDES[a.reach]}Arm`]], r = 0.95 * armReach(sk, a.reach);
78
+ for (let t = a.t ?? 0.45; t >= (a.tMin ?? 0.15); t -= 0.01) if (len(sub(at(t), sh)) <= r) return at(t);
79
+ return at(a.tMin ?? 0.15);
80
+ }
81
+ case "object": { const o = objectFrame(ctx, a, name, { s, diag, c }, side); return add(o.pos, apply(o.R, a.local ?? [0, 0, 0])); }
82
+ case "landmark": return bonePoint(s, I.Head, sk.landmarks[a.name] ?? (() => { throw new Error(`MOTION_SPEC_INVALID: unknown landmark "${a.name}"`); })());
83
+ case "prop": {
84
+ const p = diag.props?.[a.prop]?.[a.point];
85
+ if (!p) throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" needs prop ${a.prop}.${a.point}, which is held by an arm solved later`);
86
+ return add(p, a.offset ?? [0, 0, 0]);
87
+ }
88
+ default: throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" has unknown kind "${a.kind}"`);
89
+ }
90
+ }
91
+
92
+ /** Points of every prop held by hand k, in world space, written to diag.props. */
93
+ export function measureProps(ctx, k, s, diag) {
94
+ const { sk } = ctx;
95
+ for (const [name, prop] of Object.entries(ctx.spec.props ?? {})) {
96
+ if (prop.hand !== k) continue;
97
+ const ax = palmAxes(sk, s, SIDES[k]);
98
+ const origin = scale(prop.origin.map(b => s.P[sk.index[b]]).reduce((acc, p) => add(acc, p), [0, 0, 0]), 1 / prop.origin.length);
99
+ const pts = {};
100
+ for (const [pn, [d, l, n]] of Object.entries(prop.points ?? {})) pts[pn] = add(origin, add(scale(ax.d, d), add(scale(ax.l, l), scale(ax.n, n))));
101
+ pts.origin = origin;
102
+ pts.axes = ax;
103
+ (diag.props ??= {})[name] = pts;
104
+ }
105
+ }