cozyclay 2.1.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (585) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +12 -30
  3. package/bin/agent/agent-routes.mjs +43 -116
  4. package/bin/agent/agent-runner.mjs +14 -15
  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/session-store.mjs +2 -2
  14. package/bin/agent/studio-context-budget.mjs +93 -0
  15. package/bin/agent/studio-motion-reference.mjs +23 -0
  16. package/bin/agent/studio-prompt.mjs +1 -1
  17. package/bin/agent/studio-rebase-text.mjs +32 -0
  18. package/bin/agent/studio-rebase.mjs +26 -39
  19. package/bin/agent/studio-tools.mjs +9 -28
  20. package/bin/agent/tool-arguments.mjs +49 -0
  21. package/bin/agent/turn-frames.mjs +66 -0
  22. package/bin/codex-auth.mjs +9 -2
  23. package/bin/cozyclay.mjs +10 -116
  24. package/bin/live/cli.mjs +3 -3
  25. package/bin/mcp-runtime.mjs +2 -12
  26. package/bin/package-signature.mjs +0 -4
  27. package/dist/app/index.html +7 -6
  28. package/dist/assets/EXRLoader-CvVIvGVE.js +1 -0
  29. package/dist/assets/analytics-BWCqdgWA.js +1 -0
  30. package/dist/assets/app-DfTCxaKk.js +5087 -0
  31. package/dist/assets/app-f-fkV5uP.css +1 -0
  32. package/dist/assets/compile-worker-BxKXh07s.js +5 -0
  33. package/dist/assets/fflate.module-KbGj5-H6.js +5 -0
  34. package/dist/assets/{first-shot-handoff-msLI71g1.js → first-shot-handoff-DNO8kv_N.js} +1 -1
  35. package/dist/assets/{landing-ChUvB_zL.js → landing-yfZaJkWc.js} +1 -1
  36. package/dist/assets/scene-asset-sync-U3kS2rvK.js +20 -0
  37. package/dist/assets/scene-asset-sync-_S8NQl5B.css +1 -0
  38. package/dist/assets/workflow-D78eiKTa.js +179 -0
  39. package/dist/cozyclay-package.json +1 -1
  40. package/dist/index.html +3 -3
  41. package/dist/sw.js +3 -6
  42. package/dist/workflow/index.html +5 -4
  43. package/mcp/LIVE-PROTOCOL.md +7 -47
  44. package/mcp/README.md +16 -26
  45. package/mcp/live-hub.mjs +6 -10
  46. package/mcp/package.json +1 -3
  47. package/mcp/tool-handlers.mjs +4 -168
  48. package/package.json +3 -22
  49. package/src/App.jsx +151 -2625
  50. package/src/agent-progress.js +80 -0
  51. package/src/agent-turn-mark.js +30 -0
  52. package/src/analytics.js +1 -19
  53. package/src/app-context.js +12 -2
  54. package/src/app-stage.jsx +2 -34
  55. package/src/asset-pane.jsx +6 -5
  56. package/src/camera-block.js +21 -0
  57. package/src/camera-direction.js +120 -0
  58. package/src/character-kind.js +3 -9
  59. package/src/command-bus.js +10 -8
  60. package/src/commands/cast.js +5 -34
  61. package/src/commands/elements/character.js +1 -1
  62. package/src/commands/elements/motion.js +1 -6
  63. package/src/commands/elements/object.js +6 -2
  64. package/src/commands/elements/shot.js +4 -1
  65. package/src/commands/elements.js +38 -14
  66. package/src/commands/index.js +3 -1
  67. package/src/commands/kits.js +37 -0
  68. package/src/commands/motion-timing.js +57 -0
  69. package/src/commands/motion.js +9 -152
  70. package/src/commands/motion3-compile.js +65 -0
  71. package/src/commands/motion3.js +214 -0
  72. package/src/commands/objects.js +6 -4
  73. package/src/commands/shot.js +55 -13
  74. package/src/commands/stage.js +14 -1
  75. package/src/commands/view.js +4 -1
  76. package/src/document-mirrors.js +42 -0
  77. package/src/document-store.js +4 -0
  78. package/src/domains/cast.js +19 -194
  79. package/src/domains/motion/motion-range-pin-rules.js +1 -1
  80. package/src/domains/motion/take-source.js +53 -0
  81. package/src/domains/motion.js +60 -1838
  82. package/src/domains/scenes.js +12 -55
  83. package/src/domains/shots.js +2 -2
  84. package/src/domains/stage.js +4 -2
  85. package/src/draft-ghost.js +47 -0
  86. package/src/draft-ghost.jsx +129 -0
  87. package/src/dualview.jsx +4 -3
  88. package/src/effects/EffectsLayer.jsx +112 -0
  89. package/src/effects/effect-meshes.js +232 -0
  90. package/src/effects/effect-record.js +103 -0
  91. package/src/effects/emitter.js +59 -0
  92. package/src/effects/simulate.js +261 -0
  93. package/src/effects/state.js +59 -0
  94. package/src/execution-telemetry.js +2 -3
  95. package/src/first-success-guide.jsx +5 -5
  96. package/src/ghost-set.js +257 -0
  97. package/src/held-object-edit.jsx +113 -0
  98. package/src/held-object-pose.js +175 -0
  99. package/src/hierarchy-model.js +1 -1
  100. package/src/hierarchy-panel.jsx +1 -1
  101. package/src/imported-mesh.jsx +103 -0
  102. package/src/kits/held.js +84 -0
  103. package/src/kits/index.js +70 -0
  104. package/src/kits/smoking.js +57 -0
  105. package/src/light-blockers.js +93 -0
  106. package/src/motion/beat-board-model.js +84 -0
  107. package/src/motion/beat-board.css +124 -0
  108. package/src/motion/beat-board.jsx +60 -0
  109. package/src/motion/center-of-mass.js +66 -0
  110. package/src/motion/fix-collisions.js +850 -0
  111. package/src/motion/physics-review.js +118 -0
  112. package/src/{ardy → motion}/physics-support.js +1 -76
  113. package/src/motion/rig-snapshot.js +22 -0
  114. package/src/motion/take-segments.jsx +140 -0
  115. package/src/{ardy → motion}/timeline-coordinates.js +0 -21
  116. package/src/{ardy → motion}/timeline.css +1 -2
  117. package/src/{ardy → motion}/timeline.jsx +42 -413
  118. package/src/motion/waypoints.js +76 -0
  119. package/src/motion3/beats.js +83 -0
  120. package/src/motion3/body.js +158 -0
  121. package/src/motion3/bones.js +47 -0
  122. package/src/motion3/carried.js +47 -0
  123. package/src/motion3/compile-job.js +79 -0
  124. package/src/motion3/compile-worker.js +10 -0
  125. package/src/motion3/compiler/anchors.js +113 -0
  126. package/src/motion3/compiler/arm-orient.js +128 -0
  127. package/src/motion3/compiler/channels.js +125 -0
  128. package/src/motion3/compiler/compile.js +205 -0
  129. package/src/motion3/compiler/gait-rhythm.js +97 -0
  130. package/src/motion3/compiler/grip.js +171 -0
  131. package/src/motion3/compiler/head-steady.js +48 -0
  132. package/src/motion3/compiler/hold.js +134 -0
  133. package/src/motion3/compiler/idle.js +113 -0
  134. package/src/motion3/compiler/limbs.js +197 -0
  135. package/src/motion3/compiler/math.js +72 -0
  136. package/src/motion3/compiler/pose.js +177 -0
  137. package/src/motion3/compiler/quat.js +49 -0
  138. package/src/motion3/compiler/skeleton.js +74 -0
  139. package/src/motion3/compiler/validate-common.js +32 -0
  140. package/src/motion3/compiler/validate-goals.js +118 -0
  141. package/src/motion3/compiler/validate-objects.js +144 -0
  142. package/src/motion3/compiler/validate-parts.js +118 -0
  143. package/src/motion3/compiler/validate.js +122 -0
  144. package/src/motion3/compiler/vocab.js +74 -0
  145. package/src/motion3/compiler/walk-pelvis.js +275 -0
  146. package/src/motion3/compiler/walk.js +207 -0
  147. package/src/motion3/compiler/wrist-clamp.js +32 -0
  148. package/src/motion3/delta.js +47 -0
  149. package/src/motion3/describe.js +177 -0
  150. package/src/motion3/docs.js +27 -0
  151. package/src/motion3/edit-carry.js +21 -0
  152. package/src/motion3/fix/ease.js +16 -0
  153. package/src/motion3/fix/ground.js +37 -0
  154. package/src/motion3/fix/index.js +52 -0
  155. package/src/motion3/fix/push.js +71 -0
  156. package/src/motion3/fix/reach.js +46 -0
  157. package/src/motion3/fix/retime.js +79 -0
  158. package/src/motion3/fix/self.js +211 -0
  159. package/src/motion3/fix/slide.js +70 -0
  160. package/src/motion3/fix/turn.js +51 -0
  161. package/src/motion3/follow.js +39 -0
  162. package/src/motion3/free-motion.js +204 -0
  163. package/src/motion3/grip-choice.js +130 -0
  164. package/src/motion3/hold-plan.js +157 -0
  165. package/src/motion3/json-patch.js +77 -0
  166. package/src/motion3/key-aim.js +105 -0
  167. package/src/motion3/key-edit.js +82 -0
  168. package/src/motion3/lenient.js +127 -0
  169. package/src/motion3/object-keys.js +236 -0
  170. package/src/motion3/object-pose.js +182 -0
  171. package/src/motion3/object-tracks.js +12 -0
  172. package/src/motion3/people.js +82 -0
  173. package/src/motion3/pipeline.js +102 -0
  174. package/src/motion3/playback.js +51 -0
  175. package/src/motion3/probes.js +91 -0
  176. package/src/motion3/qa/body-checks.js +34 -0
  177. package/src/motion3/qa/check-names.js +14 -0
  178. package/src/motion3/qa/checks.js +125 -0
  179. package/src/motion3/qa/contact-checks.js +51 -0
  180. package/src/motion3/qa/explain.js +80 -0
  181. package/src/motion3/qa/fmt.js +5 -0
  182. package/src/motion3/qa/foot-checks.js +72 -0
  183. package/src/motion3/qa/geometry.js +77 -0
  184. package/src/motion3/qa/goals.js +191 -0
  185. package/src/motion3/qa/ground.js +60 -0
  186. package/src/motion3/qa/hints-contact.js +195 -0
  187. package/src/motion3/qa/hints-goal.js +160 -0
  188. package/src/motion3/qa/hints-knee.js +24 -0
  189. package/src/motion3/qa/hints-motion.js +209 -0
  190. package/src/motion3/qa/hints-object.js +91 -0
  191. package/src/motion3/qa/index.js +44 -0
  192. package/src/motion3/qa/key-checks.js +82 -0
  193. package/src/motion3/qa/near.js +96 -0
  194. package/src/motion3/qa/object-checks.js +135 -0
  195. package/src/motion3/qa/patch.js +161 -0
  196. package/src/motion3/qa/people-checks.js +37 -0
  197. package/src/motion3/qa/severity.js +38 -0
  198. package/src/motion3/qa/spec-checks.js +65 -0
  199. package/src/motion3/qa/style.js +228 -0
  200. package/src/motion3/qa/wrist-checks.js +69 -0
  201. package/src/motion3/qa/wrist-obs.js +60 -0
  202. package/src/motion3/refs.js +129 -0
  203. package/src/motion3/repair-tune.js +121 -0
  204. package/src/motion3/repair.js +83 -0
  205. package/src/motion3/report.js +67 -0
  206. package/src/motion3/rigs/index.js +14 -0
  207. package/src/motion3/rigs/x-bot-tpose-body.json +1 -0
  208. package/src/motion3/rigs/x-bot-tpose.json +1 -0
  209. package/src/motion3/rigs/y-bot-tpose-body.json +1 -0
  210. package/src/motion3/rigs/y-bot-tpose.json +1 -0
  211. package/src/motion3/scene.js +60 -0
  212. package/src/motion3/schema/brief.js +89 -0
  213. package/src/motion3/schema/fields.js +44 -0
  214. package/src/motion3/schema/spec-examples.js +46 -0
  215. package/src/motion3/schema/topics.js +113 -0
  216. package/src/motion3/schema/types.js +149 -0
  217. package/src/motion3/search.js +117 -0
  218. package/src/motion3/second-hand.js +112 -0
  219. package/src/motion3/settle.js +136 -0
  220. package/src/motion3/skills/basic.js +83 -0
  221. package/src/motion3/skills/book.js +76 -0
  222. package/src/motion3/skills/car.js +145 -0
  223. package/src/motion3/skills/flip.js +200 -0
  224. package/src/motion3/skills/frames-auto.js +29 -0
  225. package/src/motion3/skills/impact.js +109 -0
  226. package/src/motion3/skills/index.js +85 -0
  227. package/src/motion3/skills/info.js +80 -0
  228. package/src/motion3/skills/smoke-kit.js +109 -0
  229. package/src/motion3/skills/smoke.js +160 -0
  230. package/src/motion3/spec-store.js +59 -0
  231. package/src/motion3/take-edit.js +155 -0
  232. package/src/motion3/take.js +63 -0
  233. package/src/motion3/timeline.js +127 -0
  234. package/src/motion3/views.js +121 -0
  235. package/src/motion3/walk-plan.js +119 -0
  236. package/src/object-catalog.jsx +7 -1
  237. package/src/object-colors.js +98 -0
  238. package/src/object-gizmo-parts.js +115 -0
  239. package/src/object-gizmo.jsx +37 -122
  240. package/src/object-glow.js +139 -0
  241. package/src/object-hidden.js +33 -0
  242. package/src/object-look.js +196 -0
  243. package/src/object-size.js +10 -0
  244. package/src/object-travel.js +71 -6
  245. package/src/panels/CameraPanel.jsx +7 -7
  246. package/src/panels/HdrEnvironmentControls.jsx +59 -0
  247. package/src/panels/LightPanel.jsx +25 -4
  248. package/src/panels/ObjectLookPanel.jsx +88 -0
  249. package/src/panels/PosePanel.jsx +2 -17
  250. package/src/panels/RigControlPanel.jsx +5 -53
  251. package/src/panels/SubjectBox.jsx +4 -1
  252. package/src/panels/details.css +14 -0
  253. package/src/posestudio.jsx +4 -27
  254. package/src/project-browser.jsx +3 -4
  255. package/src/project-resources.js +18 -31
  256. package/src/project.js +13 -104
  257. package/src/props.jsx +25 -280
  258. package/src/qa-label.js +25 -0
  259. package/src/rail-dot-drag.js +23 -0
  260. package/src/render-passes.js +10 -0
  261. package/src/resource-status.jsx +1 -0
  262. package/src/result-modal.jsx +4 -19
  263. package/src/room.jsx +20 -12
  264. package/src/scene-assets.js +8 -6
  265. package/src/scene-light-place.js +72 -0
  266. package/src/scene-lights.jsx +148 -0
  267. package/src/scene-objects.js +31 -139
  268. package/src/scenes.js +15 -105
  269. package/src/semantic-edit.js +2 -5
  270. package/src/set-pieces.jsx +183 -0
  271. package/src/settings-menu.jsx +3 -11
  272. package/src/shell/BottomDock.jsx +9 -51
  273. package/src/shell/DetailsSlot.jsx +16 -200
  274. package/src/shell/GhostsMenuGroup.jsx +74 -0
  275. package/src/shell/LibrarySlot.jsx +1 -3
  276. package/src/shell/MenuBar.jsx +3 -3
  277. package/src/shell/PreferencesDialog.jsx +15 -264
  278. package/src/shell/PreferencesSlot.jsx +2 -8
  279. package/src/shell/TopBar.jsx +5 -84
  280. package/src/shell/ViewportToolbar.jsx +10 -70
  281. package/src/shell/agent-glass.css +19 -6
  282. package/src/shell/details-selection.js +42 -0
  283. package/src/shell/ghosts-menu.css +22 -0
  284. package/src/shell/glass-regions.css +29 -3
  285. package/src/shell/preferences.css +6 -1
  286. package/src/shot-authoring.js +4 -7
  287. package/src/soft-shadows.js +37 -0
  288. package/src/stage-attach-frames.js +12 -12
  289. package/src/stage-canvas-rigs.jsx +3 -3
  290. package/src/stage-capture.jsx +42 -8
  291. package/src/stage-characters.jsx +22 -216
  292. package/src/stage-editor-gizmos.jsx +6 -6
  293. package/src/stage-environment.js +93 -0
  294. package/src/stage-hdr-builtins.js +107 -0
  295. package/src/stage-hdr-image.js +116 -0
  296. package/src/stage-hdr-library.js +70 -0
  297. package/src/stage-hdr-map.js +94 -0
  298. package/src/stage-hdr.js +130 -0
  299. package/src/stage-lighting.js +149 -0
  300. package/src/stage-occlusion.js +210 -0
  301. package/src/stage-sky.jsx +159 -0
  302. package/src/stage-startup-defaults.js +5 -9
  303. package/src/studio-actions.js +16 -14
  304. package/src/studio-agent-commands.js +19 -16
  305. package/src/studio-agent-motion.js +9 -9
  306. package/src/studio-agent-protocol.js +47 -77
  307. package/src/studio-app-binding.js +27 -47
  308. package/src/studio-asset-list.js +17 -0
  309. package/src/studio-contact-sheet.js +37 -5
  310. package/src/studio-elements.js +27 -7
  311. package/src/studio-entity-bounds.js +18 -0
  312. package/src/studio-error-codes.js +15 -0
  313. package/src/studio-export-framing.js +152 -0
  314. package/src/studio-lighting-check.js +103 -0
  315. package/src/studio-motion-visual.js +150 -0
  316. package/src/studio-schema-errors.js +80 -0
  317. package/src/studio-support-gap.js +74 -0
  318. package/src/styles.css +1 -19
  319. package/src/timeline-defaults.js +5 -0
  320. package/src/timeline-extent.js +8 -20
  321. package/src/tutorial-walk.js +17 -0
  322. package/src/ui-scrub.js +1 -1
  323. package/src/use-shot-camera-tracks.js +12 -0
  324. package/src/view-ghosts.js +97 -0
  325. package/src/view-ghosts.jsx +49 -0
  326. package/src/workflow/AgentPanel.jsx +47 -166
  327. package/src/workflow/AgentProgressCard.jsx +109 -0
  328. package/src/workflow/AgentReplyText.jsx +37 -0
  329. package/src/workflow/AgentTurnSteps.jsx +84 -0
  330. package/src/workflow/LoginPanel.jsx +140 -0
  331. package/src/workflow/WorkflowBuilder.jsx +7 -23
  332. package/src/workflow/agent-client.js +54 -51
  333. package/src/workflow/agent-panel.css +71 -1
  334. package/src/workflow/agent-progress-card.css +167 -0
  335. package/src/workflow/agent-progress-view.js +47 -0
  336. package/src/workflow/agent-turn-steps.css +113 -0
  337. package/src/workflow/agent-turn.js +191 -0
  338. package/src/workflow/login-client.js +34 -0
  339. package/src/workflow/motion-input.js +18 -31
  340. package/src/workflow/node-schema.js +1 -1
  341. package/src/workflow/reply-markdown.js +69 -0
  342. package/src/workflow/scene-asset-sync.js +8 -8
  343. package/tools/agent-session-stats.mjs +61 -0
  344. package/tools/dev-full.mjs +5 -56
  345. package/tools/eslint-baseline.json +12 -13
  346. package/tools/knip-baseline.json +0 -179
  347. package/tools/loc-baseline.json +31 -81
  348. package/tools/motion3/extract-body.mjs +103 -0
  349. package/tools/motion3/extract-rig.mjs +85 -0
  350. package/tools/process-supervisor.mjs +0 -88
  351. package/tools/run-tests.mjs +9 -125
  352. package/bin/agent/motion-runtime.mjs +0 -76
  353. package/dist/ardy/cskel27-rest.json +0 -557
  354. package/dist/assets/analytics-C9pMpW7s.js +0 -1
  355. package/dist/assets/app-B_2XB9rw.css +0 -1
  356. package/dist/assets/app-DAuvKPP8.js +0 -4920
  357. package/dist/assets/config-Bx7pYsD9.js +0 -1
  358. package/dist/assets/config-DeoFTYzb.css +0 -1
  359. package/dist/assets/demo-CvKuBgy5.js +0 -1
  360. package/dist/assets/scene-asset-sync-DKkpjKBV.js +0 -19
  361. package/dist/assets/scene-asset-sync-DjJ_cJ2R.css +0 -1
  362. package/dist/assets/ticket-BPk2Ni95.js +0 -1
  363. package/dist/assets/workflow-jJRBR94Z.js +0 -179
  364. package/dist/demo/walk-then-stop.npz +0 -0
  365. package/mcp/ardy-prompts.mjs +0 -218
  366. package/src/ardy/auto-fix-panel.css +0 -108
  367. package/src/ardy/auto-physics.js +0 -1194
  368. package/src/ardy/client.js +0 -153
  369. package/src/ardy/convert.js +0 -313
  370. package/src/ardy/cskel27-neutral.js +0 -39
  371. package/src/ardy/cskel27.js +0 -77
  372. package/src/ardy/export.js +0 -165
  373. package/src/ardy/fix-collisions.js +0 -2257
  374. package/src/ardy/foot-lock.js +0 -230
  375. package/src/ardy/motion-calibration.js +0 -118
  376. package/src/ardy/motion-edit.js +0 -213
  377. package/src/ardy/motion-url.js +0 -55
  378. package/src/ardy/mp4-duration.js +0 -102
  379. package/src/ardy/npz.js +0 -595
  380. package/src/ardy/physics-panel.css +0 -21
  381. package/src/ardy/physics-panel.jsx +0 -89
  382. package/src/ardy/physics-refine.js +0 -111
  383. package/src/ardy/physics-review.js +0 -567
  384. package/src/ardy/physics-temporal.js +0 -54
  385. package/src/ardy/platform-fit-panel.css +0 -64
  386. package/src/ardy/platform-fit-panel.jsx +0 -41
  387. package/src/ardy/platform-fit.js +0 -326
  388. package/src/ardy/playback.js +0 -711
  389. package/src/ardy/pose-pin.js +0 -97
  390. package/src/ardy/prompt-clips.js +0 -30
  391. package/src/ardy/retime.js +0 -211
  392. package/src/ardy/root-drop.js +0 -369
  393. package/src/ardy/timeline-resize.js +0 -13
  394. package/src/ardy/to-cskel27.js +0 -225
  395. package/src/ardy/trim.js +0 -33
  396. package/src/ardy/waypoints.js +0 -369
  397. package/src/ardy-bridge-contract.js +0 -281
  398. package/src/domains/motion/motion-video-capture.js +0 -664
  399. package/src/i2v-motion-client.js +0 -77
  400. package/src/i2v-motion-studio.jsx +0 -180
  401. package/src/line-edit.js +0 -1348
  402. package/src/motion/generation.js +0 -105
  403. package/src/motion-readiness-ui.jsx +0 -67
  404. package/src/motion-readiness.js +0 -40
  405. package/src/motion-resources.js +0 -177
  406. package/src/motion-store.js +0 -65
  407. package/src/motion-trail.js +0 -601
  408. package/src/multimodel-ingest.js +0 -394
  409. package/src/panels/PromptBlocksPanel.jsx +0 -444
  410. package/src/panels/VideoCapturePanel.jsx +0 -181
  411. package/src/pose-extract/browser.js +0 -42
  412. package/src/pose-extract/detector.js +0 -100
  413. package/src/pose-extract/fit.js +0 -227
  414. package/src/pose-extract/image-frame.js +0 -51
  415. package/src/pose-extract/index.js +0 -58
  416. package/src/pose-extract/keyframes.js +0 -74
  417. package/src/pose-extract/landmarks.js +0 -162
  418. package/src/pose-extract/mirror.js +0 -153
  419. package/src/pose-extract/take.js +0 -131
  420. package/src/pose-extract/video-frames.js +0 -91
  421. package/src/take-recipe.js +0 -165
  422. package/src/trail-key-conflicts.js +0 -39
  423. package/src/trail-pick.js +0 -59
  424. package/src/use-i2v-capture-modal.js +0 -15
  425. package/tools/ardy/BRIDGE.md +0 -37
  426. package/tools/ardy/GVHMR-NPZ.md +0 -68
  427. package/tools/ardy/README.md +0 -124
  428. package/tools/ardy/__pycache__/cclay_gvhmr_worker.cpython-313.pyc +0 -0
  429. package/tools/ardy/artifacts.mjs +0 -34
  430. package/tools/ardy/bridge.mjs +0 -1732
  431. package/tools/ardy/bvh-cskel27.mjs +0 -1265
  432. package/tools/ardy/cclay_constrained_generate.py +0 -561
  433. package/tools/ardy/cclay_gvhmr_worker.py +0 -264
  434. package/tools/ardy/cclay_motion_edit.py +0 -510
  435. package/tools/ardy/cclay_sequence_generate.py +0 -705
  436. package/tools/ardy/cclay_worker.py +0 -304
  437. package/tools/ardy/dump-npz.py +0 -205
  438. package/tools/ardy/extract-rest.mjs +0 -299
  439. package/tools/ardy/extract.mjs +0 -507
  440. package/tools/ardy/footage.mjs +0 -467
  441. package/tools/ardy/gvhmr-floor.mjs +0 -102
  442. package/tools/ardy/gvhmr-to-cskel27.mjs +0 -21
  443. package/tools/ardy/gvhmr_fastpath.py +0 -168
  444. package/tools/ardy/gvhmr_trajectory.py +0 -240
  445. package/tools/ardy/merge-text-encoder.py +0 -160
  446. package/tools/ardy/mocap-metrics.mjs +0 -200
  447. package/tools/ardy/mocap-quality-gate.mjs +0 -110
  448. package/tools/ardy/motion-stabilize.mjs +0 -348
  449. package/tools/ardy/npz.mjs +0 -414
  450. package/tools/ardy/pose-to-npz.mjs +0 -106
  451. package/tools/ardy/prompt-limits.mjs +0 -5
  452. package/tools/ardy/run-edit-on-box.sh +0 -73
  453. package/tools/ardy/run-local.mjs +0 -233
  454. package/tools/ardy/run-on-box.sh +0 -593
  455. package/tools/ardy/run-sequence-on-box.sh +0 -177
  456. package/tools/ardy/runners/gvhmr-worker.mjs +0 -206
  457. package/tools/ardy/runners/index.mjs +0 -18
  458. package/tools/ardy/runners/local.mjs +0 -455
  459. package/tools/ardy/runners/proc.mjs +0 -125
  460. package/tools/ardy/runners/remote.mjs +0 -252
  461. package/tools/ardy/setup-local.mjs +0 -189
  462. package/tools/ardy/setup-text-encoder-on-box.sh +0 -93
  463. package/tools/ardy/setup-text-encoder.py +0 -306
  464. package/tools/ardy/smpl-cskel27.mjs +0 -178
  465. package/tools/ardy/visual-qa.mjs +0 -196
  466. package/tools/ardy/vq-car.mjs +0 -52
  467. package/tools/bench/EXP3.md +0 -61
  468. package/tools/bench/cclay_bench_extract_incam.py +0 -125
  469. package/tools/bench/cclay_bench_extract_obs.py +0 -204
  470. package/tools/bench/cclay_bench_runner.py +0 -42
  471. package/tools/bench/cube-contact.mjs +0 -162
  472. package/tools/bench/exp3.mjs +0 -152
  473. package/tools/bench/extract-bench-lib.mjs +0 -216
  474. package/tools/bench/extract-bench.mjs +0 -302
  475. package/tools/bench/fal-generate.mjs +0 -88
  476. package/tools/bench/fit/README.md +0 -189
  477. package/tools/bench/fit/camera.mjs +0 -59
  478. package/tools/bench/fit/contact.mjs +0 -419
  479. package/tools/bench/fit/footlock.mjs +0 -234
  480. package/tools/bench/fit/motion.mjs +0 -85
  481. package/tools/bench/fit/pin.mjs +0 -27
  482. package/tools/bench/fit/remote.mjs +0 -105
  483. package/tools/bench/fit-bench.mjs +0 -126
  484. package/tools/bench/fit-sanity.mjs +0 -45
  485. package/tools/bench/metrics.mjs +0 -313
  486. package/tools/bench/obs/depth.mjs +0 -258
  487. package/tools/bench/obs/extrinsics.mjs +0 -175
  488. package/tools/bench/obs/fit_mannequin_betas.py +0 -340
  489. package/tools/bench/obs/ground.mjs +0 -294
  490. package/tools/bench/obs/heading.mjs +0 -151
  491. package/tools/bench/obs/ladder.mjs +0 -555
  492. package/tools/bench/obs/mannequin-betas.json +0 -124
  493. package/tools/bench/obs/remote.mjs +0 -83
  494. package/tools/bench/obs/rest_joints.py +0 -52
  495. package/tools/bench/obs/ybot-targets.mjs +0 -49
  496. package/tools/bench/obs-bench.mjs +0 -520
  497. package/tools/bench/score.mjs +0 -343
  498. package/tools/bench/summarize.mjs +0 -86
  499. package/tools/demo-worker/README.md +0 -137
  500. package/tools/demo-worker/api-client.mjs +0 -233
  501. package/tools/demo-worker/generate.mjs +0 -301
  502. package/tools/demo-worker/index.mjs +0 -466
  503. package/tools/demo-worker/sign-core.mjs +0 -112
  504. package/tools/demo-worker/sign.mjs +0 -161
  505. package/tools/gt-render/browser.mjs +0 -182
  506. package/tools/gt-render/camera-math.mjs +0 -276
  507. package/tools/gt-render/page.mjs +0 -267
  508. package/tools/gt-render/render.mjs +0 -514
  509. package/tools/gt-render/scene-box.mjs +0 -31
  510. package/tools/gt-render/take-transform.mjs +0 -87
  511. package/tools/kimodo/compare-seam.mjs +0 -108
  512. package/tools/kimodo/constraints.mjs +0 -244
  513. package/tools/kimodo/edit.mjs +0 -259
  514. package/tools/kimodo/effector-constraints.mjs +0 -200
  515. package/tools/kimodo/generate.mjs +0 -646
  516. package/tools/kimodo/local-output.mjs +0 -265
  517. package/tools/kimodo/measure-pose.mjs +0 -65
  518. package/tools/kimodo/measure-preserve.mjs +0 -899
  519. package/tools/kimodo/measure-waypoints.mjs +0 -55
  520. package/tools/kimodo/mlx-generate.py +0 -111
  521. package/tools/kimodo/pose-constraints.mjs +0 -248
  522. package/tools/kimodo/preserve-mask.mjs +0 -543
  523. package/tools/kimodo/read-npz.mjs +0 -189
  524. package/tools/kimodo/run-edit-on-box.mjs +0 -155
  525. package/tools/kimodo/run-sequence-on-box.mjs +0 -178
  526. package/tools/kimodo/runner.mjs +0 -284
  527. package/tools/kimodo/seam-batch.mjs +0 -77
  528. package/tools/kimodo/setup-local.mjs +0 -30
  529. package/tools/kimodo/setup-on-box.sh +0 -339
  530. package/tools/kimodo/soma77-to-cskel27.mjs +0 -305
  531. package/tools/morphgs/assets/gen_truth.py +0 -39
  532. package/tools/morphgs/assets/mesh_ori_rig.txt +0 -27
  533. package/tools/morphgs/assets/playback-check.mjs +0 -30
  534. package/tools/morphgs/demo-gate.sh +0 -26
  535. package/tools/morphgs/fbx2morphgs.mjs +0 -68
  536. package/tools/morphgs/morphgs-to-cskel27.mjs +0 -105
  537. package/tools/morphgs/patches/preprocess_src-none-mode.patch +0 -76
  538. package/tools/morphgs/setup-on-cluster.sh +0 -126
  539. package/tools/projflow/driver.py +0 -1069
  540. package/tools/projflow/generate.mjs +0 -805
  541. package/tools/projflow/hml22-to-cskel27.mjs +0 -735
  542. package/tools/projflow/line-edit-job.mjs +0 -547
  543. package/tools/projflow/replay.mjs +0 -452
  544. package/tools/projflow/runner.mjs +0 -269
  545. package/tools/projflow/service.mjs +0 -742
  546. package/tools/track/DESIGN.md +0 -513
  547. package/tools/track/backfill-provenance.mjs +0 -116
  548. package/tools/track/budget.mjs +0 -8
  549. package/tools/track/check-rig.mjs +0 -209
  550. package/tools/track/diagnostics.schema.json +0 -60
  551. package/tools/track/export-rig.mjs +0 -256
  552. package/tools/track/fallback.mjs +0 -7
  553. package/tools/track/fk-parity-fixture.mjs +0 -161
  554. package/tools/track/gate.mjs +0 -349
  555. package/tools/track/masks.mjs +0 -318
  556. package/tools/track/metrics.mjs +0 -201
  557. package/tools/track/publish-obs.mjs +0 -108
  558. package/tools/track/py/check_env.py +0 -61
  559. package/tools/track/py/eval_lr.py +0 -229
  560. package/tools/track/py/lr_viterbi.py +0 -294
  561. package/tools/track/py/masks.py +0 -405
  562. package/tools/track/py/objective.py +0 -382
  563. package/tools/track/py/rig.py +0 -508
  564. package/tools/track/py/scene.py +0 -326
  565. package/tools/track/py/test_joint_indices.py +0 -123
  566. package/tools/track/py/test_lr_viterbi.py +0 -195
  567. package/tools/track/py/test_masks.py +0 -229
  568. package/tools/track/py/test_rig.py +0 -288
  569. package/tools/track/py/test_scene.py +0 -354
  570. package/tools/track/py/test_track.py +0 -328
  571. package/tools/track/py/track.py +0 -411
  572. package/tools/track/remote.mjs +0 -140
  573. package/tools/track/rig-dump.mjs +0 -227
  574. package/tools/track/run-box-tests.mjs +0 -14
  575. package/tools/track/run-box.mjs +0 -168
  576. package/tools/track/setup-box.sh +0 -59
  577. package/tools/track/study-2d.mjs +0 -728
  578. /package/src/{ardy → motion}/collision-blockers.js +0 -0
  579. /package/src/{ardy → motion}/ground.js +0 -0
  580. /package/src/{ardy → motion}/ik-drag.js +0 -0
  581. /package/src/{ardy → motion}/ik-key-json.js +0 -0
  582. /package/src/{ardy → motion}/ik.js +0 -0
  583. /package/src/{ardy → motion}/physics-surface.js +0 -0
  584. /package/src/{ardy → motion}/playback-clock.js +0 -0
  585. /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,79 @@
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
+ import { keptPeople } from "./people.js";
14
+
15
+ const TIMELINE_FPS = 24;
16
+ const refuse = (code, message) => { throw Object.assign(new Error(message), { code }); };
17
+
18
+ /** Runs `run`, turning a MOTION_SPEC_INVALID error into INVALID_ARGUMENT with the exact message. */
19
+ function asArgument(run) {
20
+ try {
21
+ return run();
22
+ } catch (error) {
23
+ if (/^MOTION_SPEC_INVALID/.test(error.message)) refuse("INVALID_ARGUMENT", error.message.replace(/^MOTION_SPEC_INVALID:\s*/, ""));
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * The same plain data as fresh literals. Objects that came through a structured clone (a worker message) make
30
+ * the compiler's hot loops ~60% slower in V8 (their shapes); a copy built from literals runs at full speed and
31
+ * keeps every value exactly (unlike a JSON round trip: -0, NaN, Infinity).
32
+ */
33
+ const fresh = value => (Array.isArray(value) ? value.map(fresh) : value && typeof value === "object" && !ArrayBuffer.isView(value)
34
+ ? Object.fromEntries(Object.keys(value).map(k => [k, fresh(value[k])])) : value);
35
+
36
+ /**
37
+ * runCompileJob({ model, scene, spec, probes?, checks?, lenient?, repair?, bake? }) -> { stored, qa, observations,
38
+ * used, fixed, search, timeline, probes?, notes?, ms (+ repair: its wall ms), frameCount, label, repair?, take? }
39
+ * bake: { position, yaw, prompt? } bakes the final result's take (prompt: given, else the final spec's label).
40
+ */
41
+ export function runCompileJob({ model, scene, spec: asked, probes: sentProbes, checks, lenient, repair, bake }) {
42
+ const sk = skeletonFor(model);
43
+ const opts = { ...(checks ? { checks } : {}), ...(lenient ? { lenient: true } : {}) };
44
+ // spec.probes and bare moved ids are lifted before fps is filled in, so the specId stays the spec's own
45
+ const once = s => {
46
+ const { spec, probes } = liftRequest(s, sentProbes);
47
+ if (spec?.fps !== undefined && spec.fps !== TIMELINE_FPS) refuse("INVALID_ARGUMENT", `spec.fps must be ${TIMELINE_FPS}, the timeline rate.`);
48
+ const sent = { fps: TIMELINE_FPS, ...spec };
49
+ const r = asArgument(() => compileSpec(sent, { sk, scene }, { ...opts, probes }));
50
+ return { ...r, stored: r.spec === sent ? spec : r.spec };
51
+ };
52
+ const t0 = performance.now(), fixed = repair ? repairSpec(asked, repair, once) : { spec: asked, result: once(asked) };
53
+ // ms.repair: the whole repair's wall time, so a sweep that repairs every variant shows what it costs
54
+ const r = fixed.result, label = fixed.spec?.label ?? null, ms = fixed.repair ? { ...r.ms, repair: Math.round(performance.now() - t0) } : r.ms;
55
+ const take = bake ? bakeTake(sk, r.out, { position: bake.position, yaw: bake.yaw }, { spec: r.stored, prompt: ("prompt" in bake ? bake.prompt : label) ?? "" }) : undefined;
56
+ // a person anchor's joints ride with the take, so its saved source compiles the same without the others' takes (people.js)
57
+ const people = take && keptPeople(scene, [r.expanded, r.stored]);
58
+ if (people) take.people = people;
59
+ return { stored: r.stored, qa: r.qa, observations: r.observations, used: r.used, fixed: r.fixed, search: r.search, timeline: r.timeline,
60
+ ...(r.probes ? { probes: r.probes } : {}), ...(r.notes ? { notes: r.notes } : {}), ms, frameCount: r.out.frameCount, label,
61
+ ...(fixed.repair ? { repair: fixed.repair } : {}), ...(take ? { take } : {}) };
62
+ }
63
+
64
+ /** The ArrayBuffers under a job answer's typed arrays (each once), to transfer instead of copy. */
65
+ function buffersOf(value, found = new Set()) {
66
+ if (ArrayBuffer.isView(value)) found.add(value.buffer);
67
+ else if (value && typeof value === "object") for (const v of Object.values(value)) buffersOf(v, found);
68
+ return [...found];
69
+ }
70
+
71
+ /** The worker's answer to { id, job }: { message: { id, value }, transfer } or { message: { id, error: { message, code, name } }, transfer: [] }. */
72
+ export function answerOf({ id, job }) {
73
+ try {
74
+ const value = runCompileJob(fresh(job));
75
+ return { message: { id, value }, transfer: buffersOf(value) };
76
+ } catch (error) {
77
+ return { message: { id, error: { message: String(error?.message ?? error), code: error?.code ?? null, name: error?.name ?? "Error" } }, transfer: [] };
78
+ }
79
+ }
@@ -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,113 @@
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
+ // { kind: "person", person: "char-b", bone: "LeftArm", offset: [x,y,z] } world offset from another character's joint
14
+ // where its installed take has it at that frame (people.js)
15
+ // spec.props = { name: { hand: "r", origin: ["RightHandIndex2", "RightHandMiddle2"],
16
+ // points: { name: [d, l, n] } } } offsets along the palm axes (m)
17
+ import { add, sub, scale, len, apply, ry } from "./math.js";
18
+ import { bonePoint } from "./skeleton.js";
19
+ import { palmAxes } from "./limbs.js";
20
+ import { SIDES } from "./pose.js";
21
+ import { HAND_CLEAR, keepOut } from "../body.js";
22
+ import { groupsOf } from "../scene.js";
23
+ import { personJoint, peopleList } from "../people.js";
24
+
25
+ function armReach(sk, k) {
26
+ const side = SIDES[k], P = sk.restWorldPos, I = sk.index;
27
+ return len(sub(P[I[`${side}ForeArm`]], P[I[`${side}Arm`]])) + len(sub(P[I[`${side}Hand`]], P[I[`${side}ForeArm`]]));
28
+ }
29
+
30
+ /** Resolve a named anchor to a world point for the current (partial) frame state. */
31
+ /** Anchors placed off the root (a pocket): with fix.self (ctx.keepOut, compile.js) a point the pose put inside
32
+ * the skin resolves onto it, HAND_CLEAR off, for the hand and for every check alike. A bone's or a segment's
33
+ * anchor is the spec's own place on that limb (a hand resting on a thigh) and stays. */
34
+ const ON_BODY = new Set(["body"]);
35
+ /** side: the hand ("l" | "r") this point is a target for while the compiler solves it; none for a reader of a solved frame. */
36
+ export function resolveAnchor(ctx, name, s, diag, c, side) {
37
+ const a = ctx.spec.anchors?.[name];
38
+ if (!a) throw new Error(`MOTION_SPEC_INVALID: unknown anchor "${name}"`);
39
+ const p = anchorPoint(ctx, a, name, s, diag, c, side), skin = ON_BODY.has(a.kind) && ctx.keepOut;
40
+ return skin ? keepOut(skin.body, ctx.sk, s, keepOut(skin.body, ctx.sk, s, p, HAND_CLEAR, skin.skip), HAND_CLEAR, skin.skip) : p;
41
+ }
42
+
43
+ // pose.js solves the right arm, then the left
44
+ const ARMS = ["r", "l"], HAND = { l: "left", r: "right" };
45
+
46
+ /**
47
+ * The pose { pos, R } an object anchor's `local` is in at frame diag.frame: where the object is then (ctx.objectPose,
48
+ * the pose refs and probes read). A hand cannot aim at what rides on it: the hand that carries the object keeps the
49
+ * scene pose, where it took it. While the right arm is solved the left is not, so the right hand cannot aim at what
50
+ * the left carries (refused).
51
+ */
52
+ export function objectFrame(ctx, a, name, { s, diag, c }, side) {
53
+ const f = diag.frame, still = () => ctx.restingAt?.(a.object, f) ?? ctx.objectsAt(f)[a.object] ?? groupsOf(ctx.scene)[a.object];
54
+ const hand = ctx.objectPose && f !== undefined ? ctx.objectHand(a.object, f) : null;
55
+ 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`);
56
+ const pose = !ctx.objectPose || f === undefined || hand === side ? still() : nested(ctx, name, a.object, f, () => ctx.objectPose(a.object, f, { s, diag, c }));
57
+ if (!pose) throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" names unknown object "${a.object}"`);
58
+ return pose;
59
+ }
60
+
61
+ // Reading an object may solve another frame (a keyed carry's grab offset, object-keys.js), whose hands read objects
62
+ // again; legitimate reads nest a few deep, so a deeper chain is a loop and is refused instead of overflowing the stack.
63
+ const MAX_NEST = 16;
64
+ function nested(ctx, name, object, f, read) {
65
+ 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`);
66
+ ctx.nest = (ctx.nest ?? 0) + 1;
67
+ try { return read(); } finally { ctx.nest--; }
68
+ }
69
+
70
+ function anchorPoint(ctx, a, name, s, diag, c, side) {
71
+ const { sk } = ctx, I = sk.index;
72
+ switch (a.kind) {
73
+ case "world": return a.p.slice();
74
+ case "body": return add(c.root ?? s.P[I.Hips], apply(ry(c.yaw ?? 0), a.p));
75
+ case "bone": return add(s.P[I[a.bone]], a.offset ?? [0, 0, 0]);
76
+ case "segment": {
77
+ const A = s.P[I[a.from]], B = s.P[I[a.to]], off = a.offset ?? [0, 0, 0];
78
+ const at = t => add(add(A, scale(sub(B, A), t)), off);
79
+ if (!a.reach) return at(a.t ?? 0.5);
80
+ const sh = s.P[I[`${SIDES[a.reach]}Arm`]], r = 0.95 * armReach(sk, a.reach);
81
+ 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);
82
+ return at(a.tMin ?? 0.15);
83
+ }
84
+ case "object": { const o = objectFrame(ctx, a, name, { s, diag, c }, side); return add(o.pos, apply(o.R, a.local ?? [0, 0, 0])); }
85
+ case "landmark": return bonePoint(s, I.Head, sk.landmarks[a.name] ?? (() => { throw new Error(`MOTION_SPEC_INVALID: unknown landmark "${a.name}"`); })());
86
+ case "prop": {
87
+ const p = diag.props?.[a.prop]?.[a.point];
88
+ if (!p) throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" needs prop ${a.prop}.${a.point}, which is held by an arm solved later`);
89
+ return add(p, a.offset ?? [0, 0, 0]);
90
+ }
91
+ case "person": {
92
+ const p = personJoint(ctx.scene, a.person, a.bone, diag?.frame ?? 0);
93
+ if (!p) throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" names person "${a.person}" bone "${a.bone}", which the scene does not have (people: ${peopleList(ctx.scene)})`);
94
+ return add(p, a.offset ?? [0, 0, 0]);
95
+ }
96
+ default: throw new Error(`MOTION_SPEC_INVALID: anchor "${name}" has unknown kind "${a.kind}"`);
97
+ }
98
+ }
99
+
100
+ /** Points of every prop held by hand k, in world space, written to diag.props. */
101
+ export function measureProps(ctx, k, s, diag) {
102
+ const { sk } = ctx;
103
+ for (const [name, prop] of Object.entries(ctx.spec.props ?? {})) {
104
+ if (prop.hand !== k) continue;
105
+ const ax = palmAxes(sk, s, SIDES[k]);
106
+ 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);
107
+ const pts = {};
108
+ 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))));
109
+ pts.origin = origin;
110
+ pts.axes = ax;
111
+ (diag.props ??= {})[name] = pts;
112
+ }
113
+ }