cozyclay 2.1.0 → 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 (583) hide show
  1. package/CHANGELOG.md +65 -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 +22 -6
  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-BlT33CGf.js → first-shot-handoff-CC4xe4HM.js} +1 -1
  33. package/dist/assets/{landing-BSesrCpL.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/llms.txt +14 -0
  40. package/dist/sw.js +3 -6
  41. package/dist/workflow/index.html +5 -4
  42. package/mcp/LIVE-PROTOCOL.md +7 -47
  43. package/mcp/README.md +16 -26
  44. package/mcp/live-hub.mjs +6 -10
  45. package/mcp/package.json +1 -3
  46. package/mcp/tool-handlers.mjs +4 -168
  47. package/package.json +3 -22
  48. package/src/App.jsx +174 -2639
  49. package/src/agent-progress.js +79 -0
  50. package/src/agent-turn-mark.js +30 -0
  51. package/src/analytics.js +1 -19
  52. package/src/app-context.js +5 -0
  53. package/src/app-stage.jsx +2 -34
  54. package/src/asset-pane.jsx +6 -5
  55. package/src/camera-block.js +21 -0
  56. package/src/camera-direction.js +120 -0
  57. package/src/character-kind.js +3 -9
  58. package/src/command-bus.js +8 -6
  59. package/src/commands/cast.js +5 -34
  60. package/src/commands/elements/character.js +1 -1
  61. package/src/commands/elements/motion.js +1 -6
  62. package/src/commands/elements/object.js +6 -2
  63. package/src/commands/elements/shot.js +4 -1
  64. package/src/commands/elements.js +38 -14
  65. package/src/commands/index.js +3 -1
  66. package/src/commands/kits.js +37 -0
  67. package/src/commands/motion-timing.js +57 -0
  68. package/src/commands/motion.js +9 -152
  69. package/src/commands/motion3-compile.js +65 -0
  70. package/src/commands/motion3.js +207 -0
  71. package/src/commands/objects.js +6 -4
  72. package/src/commands/shot.js +49 -11
  73. package/src/commands/stage.js +14 -1
  74. package/src/commands/view.js +4 -1
  75. package/src/document-mirrors.js +42 -0
  76. package/src/document-store.js +4 -0
  77. package/src/domains/cast.js +19 -194
  78. package/src/domains/motion/motion-range-pin-rules.js +1 -1
  79. package/src/domains/motion/take-source.js +51 -0
  80. package/src/domains/motion.js +60 -1838
  81. package/src/domains/scenes.js +12 -55
  82. package/src/domains/shots.js +2 -2
  83. package/src/domains/stage.js +4 -2
  84. package/src/draft-ghost.js +46 -0
  85. package/src/draft-ghost.jsx +129 -0
  86. package/src/dualview.jsx +4 -3
  87. package/src/effects/EffectsLayer.jsx +112 -0
  88. package/src/effects/effect-meshes.js +232 -0
  89. package/src/effects/effect-record.js +103 -0
  90. package/src/effects/emitter.js +59 -0
  91. package/src/effects/simulate.js +261 -0
  92. package/src/effects/state.js +59 -0
  93. package/src/execution-telemetry.js +2 -3
  94. package/src/first-success-guide.jsx +5 -5
  95. package/src/ghost-set.js +257 -0
  96. package/src/held-object-edit.jsx +113 -0
  97. package/src/held-object-pose.js +175 -0
  98. package/src/hierarchy-model.js +1 -1
  99. package/src/hierarchy-panel.jsx +1 -1
  100. package/src/imported-mesh.jsx +103 -0
  101. package/src/kits/held.js +84 -0
  102. package/src/kits/index.js +70 -0
  103. package/src/kits/smoking.js +57 -0
  104. package/src/light-blockers.js +93 -0
  105. package/src/motion/beat-board-model.js +84 -0
  106. package/src/motion/beat-board.css +124 -0
  107. package/src/motion/beat-board.jsx +59 -0
  108. package/src/motion/center-of-mass.js +66 -0
  109. package/src/motion/fix-collisions.js +850 -0
  110. package/src/motion/physics-review.js +118 -0
  111. package/src/{ardy → motion}/physics-support.js +1 -76
  112. package/src/motion/rig-snapshot.js +22 -0
  113. package/src/motion/take-segments.jsx +140 -0
  114. package/src/{ardy → motion}/timeline-coordinates.js +0 -21
  115. package/src/{ardy → motion}/timeline.css +1 -2
  116. package/src/{ardy → motion}/timeline.jsx +48 -419
  117. package/src/motion/waypoints.js +76 -0
  118. package/src/motion3/beats.js +83 -0
  119. package/src/motion3/body.js +158 -0
  120. package/src/motion3/bones.js +47 -0
  121. package/src/motion3/carried.js +47 -0
  122. package/src/motion3/compile-job.js +75 -0
  123. package/src/motion3/compile-worker.js +10 -0
  124. package/src/motion3/compiler/anchors.js +105 -0
  125. package/src/motion3/compiler/arm-orient.js +128 -0
  126. package/src/motion3/compiler/channels.js +125 -0
  127. package/src/motion3/compiler/compile.js +205 -0
  128. package/src/motion3/compiler/gait-rhythm.js +97 -0
  129. package/src/motion3/compiler/grip.js +171 -0
  130. package/src/motion3/compiler/head-steady.js +48 -0
  131. package/src/motion3/compiler/hold.js +134 -0
  132. package/src/motion3/compiler/idle.js +113 -0
  133. package/src/motion3/compiler/limbs.js +170 -0
  134. package/src/motion3/compiler/math.js +72 -0
  135. package/src/motion3/compiler/pose.js +162 -0
  136. package/src/motion3/compiler/quat.js +49 -0
  137. package/src/motion3/compiler/skeleton.js +74 -0
  138. package/src/motion3/compiler/validate-common.js +32 -0
  139. package/src/motion3/compiler/validate-goals.js +118 -0
  140. package/src/motion3/compiler/validate-objects.js +143 -0
  141. package/src/motion3/compiler/validate-parts.js +116 -0
  142. package/src/motion3/compiler/validate.js +122 -0
  143. package/src/motion3/compiler/vocab.js +73 -0
  144. package/src/motion3/compiler/walk-pelvis.js +275 -0
  145. package/src/motion3/compiler/walk.js +207 -0
  146. package/src/motion3/compiler/wrist-clamp.js +32 -0
  147. package/src/motion3/delta.js +47 -0
  148. package/src/motion3/describe.js +174 -0
  149. package/src/motion3/docs.js +27 -0
  150. package/src/motion3/edit-carry.js +21 -0
  151. package/src/motion3/fix/ease.js +16 -0
  152. package/src/motion3/fix/ground.js +37 -0
  153. package/src/motion3/fix/index.js +52 -0
  154. package/src/motion3/fix/push.js +71 -0
  155. package/src/motion3/fix/reach.js +46 -0
  156. package/src/motion3/fix/retime.js +79 -0
  157. package/src/motion3/fix/self.js +211 -0
  158. package/src/motion3/fix/slide.js +70 -0
  159. package/src/motion3/fix/turn.js +51 -0
  160. package/src/motion3/follow.js +39 -0
  161. package/src/motion3/free-motion.js +173 -0
  162. package/src/motion3/grip-choice.js +130 -0
  163. package/src/motion3/hold-plan.js +157 -0
  164. package/src/motion3/json-patch.js +77 -0
  165. package/src/motion3/key-aim.js +105 -0
  166. package/src/motion3/key-edit.js +82 -0
  167. package/src/motion3/lenient.js +127 -0
  168. package/src/motion3/object-keys.js +236 -0
  169. package/src/motion3/object-pose.js +182 -0
  170. package/src/motion3/object-tracks.js +12 -0
  171. package/src/motion3/pipeline.js +102 -0
  172. package/src/motion3/playback.js +51 -0
  173. package/src/motion3/probes.js +91 -0
  174. package/src/motion3/qa/body-checks.js +34 -0
  175. package/src/motion3/qa/check-names.js +14 -0
  176. package/src/motion3/qa/checks.js +121 -0
  177. package/src/motion3/qa/contact-checks.js +51 -0
  178. package/src/motion3/qa/explain.js +80 -0
  179. package/src/motion3/qa/fmt.js +5 -0
  180. package/src/motion3/qa/foot-checks.js +72 -0
  181. package/src/motion3/qa/geometry.js +77 -0
  182. package/src/motion3/qa/goals.js +191 -0
  183. package/src/motion3/qa/ground.js +60 -0
  184. package/src/motion3/qa/hints-contact.js +179 -0
  185. package/src/motion3/qa/hints-goal.js +160 -0
  186. package/src/motion3/qa/hints-knee.js +24 -0
  187. package/src/motion3/qa/hints-motion.js +209 -0
  188. package/src/motion3/qa/hints-object.js +91 -0
  189. package/src/motion3/qa/index.js +42 -0
  190. package/src/motion3/qa/key-checks.js +82 -0
  191. package/src/motion3/qa/near.js +96 -0
  192. package/src/motion3/qa/object-checks.js +135 -0
  193. package/src/motion3/qa/patch.js +161 -0
  194. package/src/motion3/qa/severity.js +38 -0
  195. package/src/motion3/qa/spec-checks.js +65 -0
  196. package/src/motion3/qa/style.js +218 -0
  197. package/src/motion3/qa/wrist-checks.js +69 -0
  198. package/src/motion3/qa/wrist-obs.js +60 -0
  199. package/src/motion3/refs.js +120 -0
  200. package/src/motion3/repair-tune.js +121 -0
  201. package/src/motion3/repair.js +83 -0
  202. package/src/motion3/report.js +67 -0
  203. package/src/motion3/rigs/index.js +14 -0
  204. package/src/motion3/rigs/x-bot-tpose-body.json +1 -0
  205. package/src/motion3/rigs/x-bot-tpose.json +1 -0
  206. package/src/motion3/rigs/y-bot-tpose-body.json +1 -0
  207. package/src/motion3/rigs/y-bot-tpose.json +1 -0
  208. package/src/motion3/scene.js +60 -0
  209. package/src/motion3/schema/brief.js +89 -0
  210. package/src/motion3/schema/fields.js +44 -0
  211. package/src/motion3/schema/spec-examples.js +46 -0
  212. package/src/motion3/schema/topics.js +111 -0
  213. package/src/motion3/schema/types.js +147 -0
  214. package/src/motion3/search.js +117 -0
  215. package/src/motion3/second-hand.js +112 -0
  216. package/src/motion3/skills/basic.js +82 -0
  217. package/src/motion3/skills/book.js +76 -0
  218. package/src/motion3/skills/car.js +145 -0
  219. package/src/motion3/skills/frames-auto.js +29 -0
  220. package/src/motion3/skills/index.js +83 -0
  221. package/src/motion3/skills/info.js +65 -0
  222. package/src/motion3/skills/smoke-kit.js +109 -0
  223. package/src/motion3/skills/smoke.js +160 -0
  224. package/src/motion3/spec-store.js +59 -0
  225. package/src/motion3/take-edit.js +155 -0
  226. package/src/motion3/take.js +63 -0
  227. package/src/motion3/timeline.js +127 -0
  228. package/src/motion3/views.js +121 -0
  229. package/src/motion3/walk-plan.js +119 -0
  230. package/src/object-catalog.jsx +7 -1
  231. package/src/object-colors.js +98 -0
  232. package/src/object-gizmo-parts.js +115 -0
  233. package/src/object-gizmo.jsx +37 -122
  234. package/src/object-glow.js +139 -0
  235. package/src/object-hidden.js +33 -0
  236. package/src/object-look.js +196 -0
  237. package/src/object-size.js +10 -0
  238. package/src/object-travel.js +71 -6
  239. package/src/panels/CameraPanel.jsx +7 -7
  240. package/src/panels/HdrEnvironmentControls.jsx +59 -0
  241. package/src/panels/LightPanel.jsx +25 -4
  242. package/src/panels/ObjectLookPanel.jsx +88 -0
  243. package/src/panels/PoseImagePanel.jsx +1 -1
  244. package/src/panels/PosePanel.jsx +2 -17
  245. package/src/panels/RigControlPanel.jsx +5 -53
  246. package/src/panels/SubjectBox.jsx +4 -1
  247. package/src/panels/details.css +14 -0
  248. package/src/posestudio.jsx +4 -27
  249. package/src/project-browser.jsx +3 -4
  250. package/src/project-resources.js +18 -31
  251. package/src/project.js +13 -104
  252. package/src/props.jsx +25 -280
  253. package/src/rail-dot-drag.js +23 -0
  254. package/src/render-passes.js +10 -0
  255. package/src/resource-status.jsx +1 -0
  256. package/src/result-modal.jsx +4 -19
  257. package/src/room.jsx +20 -12
  258. package/src/scene-assets.js +8 -6
  259. package/src/scene-light-place.js +72 -0
  260. package/src/scene-lights.jsx +148 -0
  261. package/src/scene-objects.js +31 -139
  262. package/src/scenes.js +15 -105
  263. package/src/semantic-edit.js +2 -5
  264. package/src/set-pieces.jsx +183 -0
  265. package/src/settings-menu.jsx +3 -11
  266. package/src/shell/BottomDock.jsx +11 -53
  267. package/src/shell/CompositionGuideButton.jsx +20 -0
  268. package/src/shell/DetailsSlot.jsx +16 -200
  269. package/src/shell/GhostsMenuGroup.jsx +74 -0
  270. package/src/shell/LibrarySlot.jsx +1 -3
  271. package/src/shell/MenuBar.jsx +3 -3
  272. package/src/shell/PreferencesDialog.jsx +15 -264
  273. package/src/shell/PreferencesSlot.jsx +2 -8
  274. package/src/shell/ShotPreviewHeader.jsx +17 -0
  275. package/src/shell/TopBar.jsx +5 -83
  276. package/src/shell/ViewportToolbar.jsx +23 -93
  277. package/src/shell/agent-glass.css +19 -6
  278. package/src/shell/details-selection.js +42 -0
  279. package/src/shell/ghosts-menu.css +22 -0
  280. package/src/shell/glass-regions.css +29 -3
  281. package/src/shell/preferences.css +6 -1
  282. package/src/shell/viewport.css +12 -0
  283. package/src/shot-authoring.js +4 -7
  284. package/src/soft-shadows.js +37 -0
  285. package/src/stage-attach-frames.js +12 -12
  286. package/src/stage-canvas-rigs.jsx +3 -3
  287. package/src/stage-capture.jsx +42 -8
  288. package/src/stage-characters.jsx +22 -216
  289. package/src/stage-editor-gizmos.jsx +6 -6
  290. package/src/stage-environment.js +93 -0
  291. package/src/stage-hdr-builtins.js +107 -0
  292. package/src/stage-hdr-image.js +116 -0
  293. package/src/stage-hdr-library.js +70 -0
  294. package/src/stage-hdr-map.js +94 -0
  295. package/src/stage-hdr.js +130 -0
  296. package/src/stage-lighting.js +149 -0
  297. package/src/stage-occlusion.js +210 -0
  298. package/src/stage-sky.jsx +159 -0
  299. package/src/stage-startup-defaults.js +5 -9
  300. package/src/studio-actions.js +12 -14
  301. package/src/studio-agent-commands.js +46 -16
  302. package/src/studio-agent-motion.js +9 -9
  303. package/src/studio-agent-protocol.js +46 -73
  304. package/src/studio-app-binding.js +29 -45
  305. package/src/studio-asset-list.js +17 -0
  306. package/src/studio-contact-sheet.js +37 -5
  307. package/src/studio-elements.js +27 -7
  308. package/src/studio-entity-bounds.js +18 -0
  309. package/src/studio-error-codes.js +8 -0
  310. package/src/studio-export-framing.js +152 -0
  311. package/src/studio-lighting-check.js +103 -0
  312. package/src/studio-motion-visual.js +150 -0
  313. package/src/studio-schema-errors.js +80 -0
  314. package/src/studio-support-gap.js +74 -0
  315. package/src/styles.css +1 -19
  316. package/src/timeline-defaults.js +5 -0
  317. package/src/timeline-extent.js +8 -20
  318. package/src/tutorial-walk.js +17 -0
  319. package/src/ui-scrub.js +1 -1
  320. package/src/use-shot-camera-tracks.js +12 -0
  321. package/src/view-ghosts.js +97 -0
  322. package/src/view-ghosts.jsx +49 -0
  323. package/src/workflow/AgentPanel.jsx +47 -166
  324. package/src/workflow/AgentProgressCard.jsx +107 -0
  325. package/src/workflow/AgentReplyText.jsx +37 -0
  326. package/src/workflow/AgentTurnSteps.jsx +84 -0
  327. package/src/workflow/LoginPanel.jsx +140 -0
  328. package/src/workflow/WorkflowBuilder.jsx +7 -23
  329. package/src/workflow/agent-client.js +54 -51
  330. package/src/workflow/agent-panel.css +71 -1
  331. package/src/workflow/agent-progress-card.css +167 -0
  332. package/src/workflow/agent-progress-view.js +47 -0
  333. package/src/workflow/agent-turn-steps.css +113 -0
  334. package/src/workflow/agent-turn.js +191 -0
  335. package/src/workflow/login-client.js +34 -0
  336. package/src/workflow/motion-input.js +18 -31
  337. package/src/workflow/node-schema.js +1 -1
  338. package/src/workflow/reply-markdown.js +69 -0
  339. package/src/workflow/scene-asset-sync.js +8 -8
  340. package/tools/agent-session-stats.mjs +61 -0
  341. package/tools/dev-full.mjs +5 -56
  342. package/tools/eslint-baseline.json +12 -13
  343. package/tools/headless-studio.mjs +85 -0
  344. package/tools/knip-baseline.json +0 -179
  345. package/tools/loc-baseline.json +33 -83
  346. package/tools/motion3/extract-body.mjs +103 -0
  347. package/tools/motion3/extract-rig.mjs +85 -0
  348. package/tools/process-supervisor.mjs +0 -88
  349. package/tools/run-tests.mjs +9 -124
  350. package/bin/agent/motion-runtime.mjs +0 -76
  351. package/dist/ardy/cskel27-rest.json +0 -557
  352. package/dist/assets/analytics-B41FmPYI.js +0 -1
  353. package/dist/assets/app-Do-Og5Pu.css +0 -1
  354. package/dist/assets/app-DwP-tl2x.js +0 -4920
  355. package/dist/assets/config-Bx7pYsD9.js +0 -1
  356. package/dist/assets/config-DeoFTYzb.css +0 -1
  357. package/dist/assets/demo-Dt0qZfS7.js +0 -1
  358. package/dist/assets/scene-asset-sync-BCWDJB1d.js +0 -19
  359. package/dist/assets/scene-asset-sync-DjJ_cJ2R.css +0 -1
  360. package/dist/assets/ticket-jqMhqL88.js +0 -1
  361. package/dist/assets/workflow-Br-K7Srs.js +0 -179
  362. package/dist/demo/walk-then-stop.npz +0 -0
  363. package/mcp/ardy-prompts.mjs +0 -218
  364. package/src/ardy/auto-fix-panel.css +0 -108
  365. package/src/ardy/auto-physics.js +0 -1194
  366. package/src/ardy/client.js +0 -153
  367. package/src/ardy/convert.js +0 -313
  368. package/src/ardy/cskel27-neutral.js +0 -39
  369. package/src/ardy/cskel27.js +0 -77
  370. package/src/ardy/export.js +0 -165
  371. package/src/ardy/fix-collisions.js +0 -2257
  372. package/src/ardy/foot-lock.js +0 -230
  373. package/src/ardy/motion-calibration.js +0 -118
  374. package/src/ardy/motion-edit.js +0 -213
  375. package/src/ardy/motion-url.js +0 -55
  376. package/src/ardy/mp4-duration.js +0 -102
  377. package/src/ardy/npz.js +0 -595
  378. package/src/ardy/physics-panel.css +0 -21
  379. package/src/ardy/physics-panel.jsx +0 -89
  380. package/src/ardy/physics-refine.js +0 -111
  381. package/src/ardy/physics-review.js +0 -567
  382. package/src/ardy/physics-temporal.js +0 -54
  383. package/src/ardy/platform-fit-panel.css +0 -64
  384. package/src/ardy/platform-fit-panel.jsx +0 -41
  385. package/src/ardy/platform-fit.js +0 -326
  386. package/src/ardy/playback.js +0 -711
  387. package/src/ardy/pose-pin.js +0 -97
  388. package/src/ardy/prompt-clips.js +0 -30
  389. package/src/ardy/retime.js +0 -211
  390. package/src/ardy/root-drop.js +0 -369
  391. package/src/ardy/timeline-resize.js +0 -13
  392. package/src/ardy/to-cskel27.js +0 -225
  393. package/src/ardy/trim.js +0 -33
  394. package/src/ardy/waypoints.js +0 -369
  395. package/src/ardy-bridge-contract.js +0 -281
  396. package/src/domains/motion/motion-video-capture.js +0 -664
  397. package/src/i2v-motion-client.js +0 -77
  398. package/src/i2v-motion-studio.jsx +0 -180
  399. package/src/line-edit.js +0 -1348
  400. package/src/motion/generation.js +0 -105
  401. package/src/motion-readiness-ui.jsx +0 -67
  402. package/src/motion-readiness.js +0 -40
  403. package/src/motion-resources.js +0 -177
  404. package/src/motion-store.js +0 -65
  405. package/src/motion-trail.js +0 -601
  406. package/src/multimodel-ingest.js +0 -394
  407. package/src/panels/PromptBlocksPanel.jsx +0 -444
  408. package/src/panels/VideoCapturePanel.jsx +0 -181
  409. package/src/pose-extract/browser.js +0 -42
  410. package/src/pose-extract/detector.js +0 -100
  411. package/src/pose-extract/fit.js +0 -227
  412. package/src/pose-extract/image-frame.js +0 -51
  413. package/src/pose-extract/index.js +0 -58
  414. package/src/pose-extract/keyframes.js +0 -74
  415. package/src/pose-extract/landmarks.js +0 -162
  416. package/src/pose-extract/mirror.js +0 -153
  417. package/src/pose-extract/take.js +0 -131
  418. package/src/pose-extract/video-frames.js +0 -91
  419. package/src/take-recipe.js +0 -165
  420. package/src/trail-key-conflicts.js +0 -39
  421. package/src/trail-pick.js +0 -59
  422. package/src/use-i2v-capture-modal.js +0 -15
  423. package/tools/ardy/BRIDGE.md +0 -37
  424. package/tools/ardy/GVHMR-NPZ.md +0 -68
  425. package/tools/ardy/README.md +0 -124
  426. package/tools/ardy/__pycache__/cclay_gvhmr_worker.cpython-313.pyc +0 -0
  427. package/tools/ardy/artifacts.mjs +0 -34
  428. package/tools/ardy/bridge.mjs +0 -1732
  429. package/tools/ardy/bvh-cskel27.mjs +0 -1265
  430. package/tools/ardy/cclay_constrained_generate.py +0 -561
  431. package/tools/ardy/cclay_gvhmr_worker.py +0 -264
  432. package/tools/ardy/cclay_motion_edit.py +0 -510
  433. package/tools/ardy/cclay_sequence_generate.py +0 -705
  434. package/tools/ardy/cclay_worker.py +0 -304
  435. package/tools/ardy/dump-npz.py +0 -205
  436. package/tools/ardy/extract-rest.mjs +0 -299
  437. package/tools/ardy/extract.mjs +0 -507
  438. package/tools/ardy/footage.mjs +0 -467
  439. package/tools/ardy/gvhmr-floor.mjs +0 -102
  440. package/tools/ardy/gvhmr-to-cskel27.mjs +0 -21
  441. package/tools/ardy/gvhmr_fastpath.py +0 -168
  442. package/tools/ardy/gvhmr_trajectory.py +0 -240
  443. package/tools/ardy/merge-text-encoder.py +0 -160
  444. package/tools/ardy/mocap-metrics.mjs +0 -200
  445. package/tools/ardy/mocap-quality-gate.mjs +0 -110
  446. package/tools/ardy/motion-stabilize.mjs +0 -348
  447. package/tools/ardy/npz.mjs +0 -414
  448. package/tools/ardy/pose-to-npz.mjs +0 -106
  449. package/tools/ardy/prompt-limits.mjs +0 -5
  450. package/tools/ardy/run-edit-on-box.sh +0 -73
  451. package/tools/ardy/run-local.mjs +0 -233
  452. package/tools/ardy/run-on-box.sh +0 -593
  453. package/tools/ardy/run-sequence-on-box.sh +0 -177
  454. package/tools/ardy/runners/gvhmr-worker.mjs +0 -206
  455. package/tools/ardy/runners/index.mjs +0 -18
  456. package/tools/ardy/runners/local.mjs +0 -455
  457. package/tools/ardy/runners/proc.mjs +0 -125
  458. package/tools/ardy/runners/remote.mjs +0 -252
  459. package/tools/ardy/setup-local.mjs +0 -189
  460. package/tools/ardy/setup-text-encoder-on-box.sh +0 -93
  461. package/tools/ardy/setup-text-encoder.py +0 -306
  462. package/tools/ardy/smpl-cskel27.mjs +0 -178
  463. package/tools/ardy/visual-qa.mjs +0 -196
  464. package/tools/ardy/vq-car.mjs +0 -52
  465. package/tools/bench/EXP3.md +0 -61
  466. package/tools/bench/cclay_bench_extract_incam.py +0 -125
  467. package/tools/bench/cclay_bench_extract_obs.py +0 -204
  468. package/tools/bench/cclay_bench_runner.py +0 -42
  469. package/tools/bench/cube-contact.mjs +0 -162
  470. package/tools/bench/exp3.mjs +0 -152
  471. package/tools/bench/extract-bench-lib.mjs +0 -216
  472. package/tools/bench/extract-bench.mjs +0 -302
  473. package/tools/bench/fal-generate.mjs +0 -88
  474. package/tools/bench/fit/README.md +0 -189
  475. package/tools/bench/fit/camera.mjs +0 -59
  476. package/tools/bench/fit/contact.mjs +0 -419
  477. package/tools/bench/fit/footlock.mjs +0 -234
  478. package/tools/bench/fit/motion.mjs +0 -85
  479. package/tools/bench/fit/pin.mjs +0 -27
  480. package/tools/bench/fit/remote.mjs +0 -105
  481. package/tools/bench/fit-bench.mjs +0 -126
  482. package/tools/bench/fit-sanity.mjs +0 -45
  483. package/tools/bench/metrics.mjs +0 -313
  484. package/tools/bench/obs/depth.mjs +0 -258
  485. package/tools/bench/obs/extrinsics.mjs +0 -175
  486. package/tools/bench/obs/fit_mannequin_betas.py +0 -340
  487. package/tools/bench/obs/ground.mjs +0 -294
  488. package/tools/bench/obs/heading.mjs +0 -151
  489. package/tools/bench/obs/ladder.mjs +0 -555
  490. package/tools/bench/obs/mannequin-betas.json +0 -124
  491. package/tools/bench/obs/remote.mjs +0 -83
  492. package/tools/bench/obs/rest_joints.py +0 -52
  493. package/tools/bench/obs/ybot-targets.mjs +0 -49
  494. package/tools/bench/obs-bench.mjs +0 -520
  495. package/tools/bench/score.mjs +0 -343
  496. package/tools/bench/summarize.mjs +0 -86
  497. package/tools/demo-worker/README.md +0 -137
  498. package/tools/demo-worker/api-client.mjs +0 -233
  499. package/tools/demo-worker/generate.mjs +0 -301
  500. package/tools/demo-worker/index.mjs +0 -466
  501. package/tools/demo-worker/sign-core.mjs +0 -112
  502. package/tools/demo-worker/sign.mjs +0 -161
  503. package/tools/gt-render/browser.mjs +0 -159
  504. package/tools/gt-render/camera-math.mjs +0 -276
  505. package/tools/gt-render/page.mjs +0 -267
  506. package/tools/gt-render/render.mjs +0 -514
  507. package/tools/gt-render/scene-box.mjs +0 -31
  508. package/tools/gt-render/take-transform.mjs +0 -87
  509. package/tools/kimodo/compare-seam.mjs +0 -108
  510. package/tools/kimodo/constraints.mjs +0 -244
  511. package/tools/kimodo/edit.mjs +0 -259
  512. package/tools/kimodo/effector-constraints.mjs +0 -200
  513. package/tools/kimodo/generate.mjs +0 -646
  514. package/tools/kimodo/local-output.mjs +0 -265
  515. package/tools/kimodo/measure-pose.mjs +0 -65
  516. package/tools/kimodo/measure-preserve.mjs +0 -899
  517. package/tools/kimodo/measure-waypoints.mjs +0 -55
  518. package/tools/kimodo/mlx-generate.py +0 -111
  519. package/tools/kimodo/pose-constraints.mjs +0 -248
  520. package/tools/kimodo/preserve-mask.mjs +0 -543
  521. package/tools/kimodo/read-npz.mjs +0 -189
  522. package/tools/kimodo/run-edit-on-box.mjs +0 -155
  523. package/tools/kimodo/run-sequence-on-box.mjs +0 -178
  524. package/tools/kimodo/runner.mjs +0 -284
  525. package/tools/kimodo/seam-batch.mjs +0 -77
  526. package/tools/kimodo/setup-local.mjs +0 -30
  527. package/tools/kimodo/setup-on-box.sh +0 -339
  528. package/tools/kimodo/soma77-to-cskel27.mjs +0 -305
  529. package/tools/morphgs/assets/gen_truth.py +0 -39
  530. package/tools/morphgs/assets/mesh_ori_rig.txt +0 -27
  531. package/tools/morphgs/assets/playback-check.mjs +0 -30
  532. package/tools/morphgs/demo-gate.sh +0 -26
  533. package/tools/morphgs/fbx2morphgs.mjs +0 -68
  534. package/tools/morphgs/morphgs-to-cskel27.mjs +0 -105
  535. package/tools/morphgs/patches/preprocess_src-none-mode.patch +0 -76
  536. package/tools/morphgs/setup-on-cluster.sh +0 -126
  537. package/tools/projflow/driver.py +0 -1069
  538. package/tools/projflow/generate.mjs +0 -805
  539. package/tools/projflow/hml22-to-cskel27.mjs +0 -735
  540. package/tools/projflow/line-edit-job.mjs +0 -547
  541. package/tools/projflow/replay.mjs +0 -452
  542. package/tools/projflow/runner.mjs +0 -269
  543. package/tools/projflow/service.mjs +0 -742
  544. package/tools/track/DESIGN.md +0 -513
  545. package/tools/track/backfill-provenance.mjs +0 -116
  546. package/tools/track/budget.mjs +0 -8
  547. package/tools/track/check-rig.mjs +0 -209
  548. package/tools/track/diagnostics.schema.json +0 -60
  549. package/tools/track/export-rig.mjs +0 -256
  550. package/tools/track/fallback.mjs +0 -7
  551. package/tools/track/fk-parity-fixture.mjs +0 -161
  552. package/tools/track/gate.mjs +0 -349
  553. package/tools/track/masks.mjs +0 -318
  554. package/tools/track/metrics.mjs +0 -201
  555. package/tools/track/publish-obs.mjs +0 -108
  556. package/tools/track/py/check_env.py +0 -61
  557. package/tools/track/py/eval_lr.py +0 -229
  558. package/tools/track/py/lr_viterbi.py +0 -294
  559. package/tools/track/py/masks.py +0 -405
  560. package/tools/track/py/objective.py +0 -382
  561. package/tools/track/py/rig.py +0 -508
  562. package/tools/track/py/scene.py +0 -326
  563. package/tools/track/py/test_joint_indices.py +0 -123
  564. package/tools/track/py/test_lr_viterbi.py +0 -195
  565. package/tools/track/py/test_masks.py +0 -229
  566. package/tools/track/py/test_rig.py +0 -288
  567. package/tools/track/py/test_scene.py +0 -354
  568. package/tools/track/py/test_track.py +0 -328
  569. package/tools/track/py/track.py +0 -411
  570. package/tools/track/remote.mjs +0 -140
  571. package/tools/track/rig-dump.mjs +0 -227
  572. package/tools/track/run-box-tests.mjs +0 -14
  573. package/tools/track/run-box.mjs +0 -168
  574. package/tools/track/setup-box.sh +0 -59
  575. package/tools/track/study-2d.mjs +0 -728
  576. /package/src/{ardy → motion}/collision-blockers.js +0 -0
  577. /package/src/{ardy → motion}/ground.js +0 -0
  578. /package/src/{ardy → motion}/ik-drag.js +0 -0
  579. /package/src/{ardy → motion}/ik-key-json.js +0 -0
  580. /package/src/{ardy → motion}/ik.js +0 -0
  581. /package/src/{ardy → motion}/physics-surface.js +0 -0
  582. /package/src/{ardy → motion}/playback-clock.js +0 -0
  583. /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
+ }