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
@@ -1,514 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Ground-truth renderer (#428): cskel27 motion npz -> GVHMR-ready videos
4
- * rendered by the real CozyClay Studio from ONE fixed, known camera, with the
5
- * exact camera and joint ground truth written next to every video.
6
- *
7
- * node tools/gt-render/render.mjs --out <dir> [options] <motion.npz ...>
8
- *
9
- * Per motion it starts (or reuses, --url) a Vite dev server of this checkout
10
- * and a headless Chrome, loads the take through `?motion=`, and:
11
- * 1. pre-pass: scrubs every timeline frame, CPU-skins every drawable vertex
12
- * of the rig and reduces it (plus the joints) to five support values;
13
- * 2. solves the closest static camera at the requested azimuth/elevation and
14
- * integer GVHMR f-mm that keeps every vertex of every frame inside the
15
- * margin box (camera-math.mjs), identical for all variants;
16
- * 3. renders every timeline frame at 832x480 through the Studio's export
17
- * capture (`window.__cozyclay.captureFraming`), encodes H.264 yuv420p
18
- * 24 fps, and writes camera.json, joints.json and meta.json.
19
- *
20
- * Variants: `shaded` (part colours, shaded palette, what GVHMR's palette
21
- * detector expects), `skin` (part colours off), `hue+N` / `hue-N` (the shaded
22
- * frames through ffmpeg's `hue=h=N` filter; it rotates the chroma plane of
23
- * EVERY pixel by the same N degrees, so all hues shift uniformly and neutral
24
- * greys stay put. It does not reshuffle parts: the palette's relative layout is
25
- * preserved).
26
- *
27
- * Output per motion:
28
- * <out>/<motion>/plate.png the same framing with the character hidden
29
- * <out>/<motion>/mask/NNNNNN.png exact per-frame silhouette (gray, 255 = character),
30
- * the character re-drawn unlit in one colour
31
- * <out>/<motion>/<variant>/{video.mp4,camera.json,joints.json,meta.json}
32
- *
33
- * Scoring renders (#431): `--camera <camera.json>` renders through that exact
34
- * camera instead of solving one; `--no-video` captures only the silhouette
35
- * masks and writes <out>/<motion>/{camera.json,joints.json,meta.json,mask/};
36
- * `--transform` places the take in the scene first (take-transform.mjs, the
37
- * Studio's sceneCalibration semantics); `--box` also writes contact.json, the
38
- * per-frame signed distance of the closest skinned vertex to a scene box.
39
- */
40
- import { execFileSync } from "node:child_process";
41
- import { createHash } from "node:crypto";
42
- import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
43
- import { basename, dirname, join, resolve } from "node:path";
44
- import { parseArgs } from "node:util";
45
- import { installSignalCleanup } from "../process-supervisor.mjs";
46
- import { openStudioClean, startChrome, startVite, terminateAll, waitFor } from "./browser.mjs";
47
- import { decodeMotionNpz } from "../../src/ardy/npz.js";
48
- import { writeNpz } from "../ardy/npz.mjs";
49
- import { boxContactValues, contactFromSigned, parseBox } from "../bench/metrics.mjs";
50
- import { buildCamera, cameraFromRecord, marginSlopes, mergeSupports, projectPoint, supportArgs, supportValues, translateCamera } from "./camera-math.mjs";
51
- import { installPageHelpers, MASK_RGB, RIG_JOINTS } from "./page.mjs";
52
- import { boxCorners, parseSceneBox, sceneBoxRecord } from "./scene-box.mjs";
53
- import { isIdentityTransform, parseTransform, takeToNpzMembers, transformTake } from "./take-transform.mjs";
54
-
55
- const ROOT = resolve(dirname(new URL(import.meta.url).pathname), "../..");
56
- const WIDTH = 832;
57
- const HEIGHT = 480;
58
- const FPS = 24;
59
- const CACHE_DIR = join(ROOT, "node_modules/.cache/gt-render");
60
-
61
- const USAGE = `usage: node tools/gt-render/render.mjs --out <dir> [options] <motion.npz ...>
62
-
63
- --out <dir> output root; each motion goes to <dir>/<npz basename>/<variant>/
64
- --variants <list> comma list of shaded, skin, hue+N, hue-N (default shaded)
65
- --f-mm <int> GVHMR --f-mm the camera is built for (default 35)
66
- --azimuth <deg> camera azimuth around the subject; 0 = on +Z looking -Z (default 0)
67
- --elevation <deg> camera elevation; positive looks down (default 5)
68
- --margin <frac> fraction of each image side kept clear of the body (default 0.08)
69
- --crf <int> libx264 CRF (default 12)
70
- --keep-frames keep the rendered PNG frames in <variant>/frames/
71
- --url <origin> reuse a running Vite dev server of THIS checkout (default: start one)
72
- --port <n> Vite port when starting one (default 5191)
73
- --cdp-port <n> headless Chrome DevTools port (default 9231)
74
- --camera <file> render through this camera.json (from an earlier render) instead of
75
- solving one; --f-mm/--azimuth/--elevation/--margin are then unused
76
- and a joint near or past the edge is reported, not fatal
77
- --no-video masks + joints only: <dir>/<motion>/{camera.json,joints.json,meta.json,mask/}
78
- --transform <json> place the take first, Studio sceneCalibration semantics:
79
- '{"yawDeg":0,"offsetX":0,"offsetY":0,"offsetZ":0,"scale":1}'
80
- (yaw about the frame-0 anchor, offsets in scene metres)
81
- --scene-box <json> visible Studio cube: {x,z,rot,sx,sy,sz}; base at floor, sizes in metres
82
- --export-vertices write vertices.f32 (frame/vertex/xyz, little-endian float32) + vertices.json
83
- --box <json> '{"min":[x,y,z],"max":[x,y,z]}' scene box; writes <dir>/<motion>/contact.json
84
- (closest skinned vertex per frame: distance / penetration)
85
-
86
- writes <dir>/<motion>/{plate.png,mask/NNNNNN.png} and
87
- <dir>/<motion>/<variant>/{video.mp4,camera.json,joints.json,meta.json}`;
88
-
89
- function parseOptions(argv) {
90
- const { values, positionals } = parseArgs({
91
- args: argv,
92
- allowPositionals: true,
93
- options: {
94
- out: { type: "string" },
95
- variants: { type: "string", default: "shaded" },
96
- "f-mm": { type: "string", default: "35" },
97
- azimuth: { type: "string", default: "0" },
98
- elevation: { type: "string", default: "5" },
99
- margin: { type: "string", default: "0.08" },
100
- crf: { type: "string", default: "12" },
101
- "keep-frames": { type: "boolean", default: false },
102
- url: { type: "string" },
103
- port: { type: "string", default: "5191" },
104
- "cdp-port": { type: "string", default: "9231" },
105
- camera: { type: "string" },
106
- "no-video": { type: "boolean", default: false },
107
- transform: { type: "string" },
108
- box: { type: "string" },
109
- "scene-box": { type: "string" },
110
- "export-vertices": { type: "boolean", default: false },
111
- help: { type: "boolean", short: "h", default: false },
112
- },
113
- });
114
- if (values.help) {
115
- console.log(USAGE);
116
- process.exit(0);
117
- }
118
- const fail = (message) => {
119
- console.error(`${message}\n\n${USAGE}`);
120
- process.exit(2);
121
- };
122
- if (!values.out) fail("--out is required");
123
- if (!positionals.length) fail("at least one motion npz is required");
124
- const number = (name, integer = false) => {
125
- const value = Number(values[name]);
126
- if (!Number.isFinite(value) || (integer && !Number.isInteger(value))) fail(`--${name} must be ${integer ? "an integer" : "a number"}, got ${values[name]}`);
127
- return value;
128
- };
129
- const variants = values.variants.split(",").map((entry) => entry.trim()).filter(Boolean).map((name) => {
130
- if (name === "shaded" || name === "skin") return { name, kind: name };
131
- const hue = /^hue([+-]\d+(?:\.\d+)?)$/.exec(name);
132
- if (hue) return { name, kind: "hue", degrees: Number(hue[1]) };
133
- return fail(`unknown variant ${name}`);
134
- });
135
- if (new Set(variants.map((variant) => variant.name)).size !== variants.length) fail("duplicate variant");
136
- const motions = positionals.map((file) => resolve(file));
137
- for (const file of motions) if (!existsSync(file)) fail(`no such motion: ${file}`);
138
- const names = motions.map((file) => basename(file, ".npz"));
139
- if (new Set(names).size !== names.length) fail(`two motions share an output name: ${names.join(", ")}`);
140
- let camera = null;
141
- if (values.camera) {
142
- const file = resolve(values.camera);
143
- if (!existsSync(file)) fail(`no such camera: ${file}`);
144
- try {
145
- camera = cameraFromRecord(JSON.parse(readFileSync(file, "utf8")));
146
- } catch (error) {
147
- fail(`--camera ${file}: ${error.message}`);
148
- }
149
- if (camera.width !== WIDTH || camera.height !== HEIGHT) fail(`--camera is ${camera.width}x${camera.height}; the renderer draws ${WIDTH}x${HEIGHT}`);
150
- camera.source = file;
151
- }
152
- let transform = null;
153
- if (values.transform) {
154
- try {
155
- transform = parseTransform(values.transform);
156
- } catch (error) {
157
- fail(`--transform: ${error.message}`);
158
- }
159
- }
160
- let box = null;
161
- if (values.box) {
162
- try {
163
- box = parseBox(values.box);
164
- } catch (error) {
165
- fail(`--box: ${error.message}`);
166
- }
167
- }
168
- return {
169
- camera,
170
- sceneBox: values["scene-box"] ? parseSceneBox(values["scene-box"]) : null,
171
- exportVertices: values["export-vertices"],
172
- noVideo: values["no-video"],
173
- transform,
174
- box,
175
- out: resolve(values.out),
176
- variants,
177
- fMm: number("f-mm", true),
178
- azimuthDeg: number("azimuth"),
179
- elevationDeg: number("elevation"),
180
- margin: number("margin"),
181
- crf: number("crf", true),
182
- keepFrames: values["keep-frames"],
183
- url: values.url?.replace(/\/$/, "") ?? null,
184
- port: number("port", true),
185
- cdpPort: number("cdp-port", true),
186
- motions,
187
- };
188
- }
189
-
190
- const round = (value, digits) => Math.round(value * 10 ** digits) / 10 ** digits;
191
- const triples = (flat, digits = 6) => Array.from({ length: flat.length / 3 }, (_, i) => [round(flat[i * 3], digits), round(flat[i * 3 + 1], digits), round(flat[i * 3 + 2], digits)]);
192
-
193
- function toolVersion() {
194
- const pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8"));
195
- try {
196
- const commit = execFileSync("git", ["rev-parse", "--short", "HEAD"], { cwd: ROOT, encoding: "utf8" }).trim();
197
- const dirty = execFileSync("git", ["status", "--porcelain"], { cwd: ROOT, encoding: "utf8" }).trim() !== "";
198
- return `${pkg.version}+${commit}${dirty ? "-dirty" : ""}`;
199
- } catch {
200
- return pkg.version;
201
- }
202
- }
203
-
204
- function encode(framesDir, output, { crf, filter }) {
205
- execFileSync("ffmpeg", [
206
- "-hide_banner", "-loglevel", "error", "-y",
207
- "-framerate", String(FPS), "-i", join(framesDir, "%06d.png"),
208
- ...(filter ? ["-vf", filter] : []),
209
- "-c:v", "libx264", "-preset", "slow", "-crf", String(crf),
210
- "-pix_fmt", "yuv420p", "-colorspace", "smpte170m", "-color_primaries", "smpte170m", "-color_trc", "smpte170m", "-color_range", "tv",
211
- "-r", String(FPS), "-movflags", "+faststart", output,
212
- ], { stdio: ["ignore", "inherit", "inherit"] });
213
- }
214
-
215
- /** Magenta-on-scene mask captures -> gray PNGs, 255 where the pixel is at
216
- * least half character (the MSAA edge blends linearly with the scene). */
217
- function writeMasks(rawDir, maskDir) {
218
- rmSync(maskDir, { recursive: true, force: true });
219
- mkdirSync(maskDir, { recursive: true });
220
- const [r, g, b] = MASK_RGB;
221
- if (!(r === 255 && g === 0 && b === 255)) throw new Error("writeMasks expects the magenta mask colour");
222
- const test = "255*gt(r(X,Y)-g(X,Y),127)*gt(b(X,Y)-g(X,Y),127)";
223
- execFileSync("ffmpeg", [
224
- "-hide_banner", "-loglevel", "error", "-y",
225
- "-framerate", String(FPS), "-i", join(rawDir, "%06d.png"),
226
- "-vf", `format=gbrp,geq=r='${test}':g='${test}':b='${test}',format=gray`,
227
- "-start_number", "0", join(maskDir, "%06d.png"),
228
- ], { stdio: ["ignore", "inherit", "inherit"] });
229
- }
230
-
231
- function cameraRecord(camera, shotCam) {
232
- return {
233
- width: camera.width,
234
- height: camera.height,
235
- fovDeg: camera.fovDeg,
236
- fx: camera.fx,
237
- fy: camera.fy,
238
- cx: camera.cx,
239
- cy: camera.cy,
240
- K: [[camera.fx, 0, camera.cx], [0, camera.fy, camera.cy], [0, 0, 1]],
241
- gvhmrFMm: camera.gvhmrFMm,
242
- position: camera.position,
243
- yaw: camera.yaw,
244
- pitch: camera.pitch,
245
- rotationOrder: "YXZ",
246
- azimuthDeg: camera.azimuthDeg,
247
- elevationDeg: camera.elevationDeg,
248
- margin: camera.margin,
249
- bindingAxis: camera.bindingAxis,
250
- near: shotCam.near,
251
- far: shotCam.far,
252
- static: true,
253
- worldToCamera: camera.worldToCameraCv,
254
- worldToCameraGl: camera.worldToCameraGl,
255
- cameraToWorldRotationThree: [camera.cameraToWorldRotation.slice(0, 3), camera.cameraToWorldRotation.slice(3, 6), camera.cameraToWorldRotation.slice(6, 9)],
256
- convention: {
257
- world: "CozyClay Studio / Three.js scene: right-handed, +Y up, metres. The character's front is +Z at azimuth 0.",
258
- worldToCamera: "OpenCV: [X Y Z 1]^T = worldToCamera * [x y z 1]^T, camera x right, y DOWN, z forward (depth).",
259
- projection: "u = fx * X / Z + cx, v = fy * Y / Z + cy. Square pixels, no distortion, no skew.",
260
- image: "Pixels continuous from the top-left corner of the top-left pixel: u right, v DOWN; pixel (col,row) covers [col,col+1)x[row,row+1) and its centre is (col+0.5,row+0.5); cx = width/2, cy = height/2.",
261
- worldToCameraGl: "Three/OpenGL view matrix (camera.matrixWorldInverse): x right, y up, looking down -z.",
262
- threeCamera: "PerspectiveCamera(fov = fovDeg vertical, aspect = width/height), position, rotation.set(pitch, yaw, 0) with order YXZ (radians); rendered through the Studio export capture.",
263
- gvhmr: "Run GVHMR with --f-mm gvhmrFMm: f_px = sqrt(W^2 + H^2) / sqrt(24^2 + 36^2) * f_mm equals fx = fy here.",
264
- },
265
- };
266
- }
267
-
268
- async function main() {
269
- const options = parseOptions(process.argv.slice(2));
270
- const children = [];
271
- const cleanups = [];
272
- const runCleanups = () => {
273
- for (const cleanup of cleanups.splice(0)) cleanup();
274
- };
275
- const removeSignals = installSignalCleanup(() => children, () => {
276
- runCleanups();
277
- process.exit(130);
278
- });
279
- const version = toolVersion();
280
- try {
281
- const base = options.url ?? await startVite({ root: ROOT, port: options.port, children });
282
- const cdp = await startChrome({ port: options.cdpPort, children, cleanups });
283
- mkdirSync(CACHE_DIR, { recursive: true });
284
- for (const file of options.motions) {
285
- await renderMotion({ cdp, base, file, options, version });
286
- }
287
- cdp.close();
288
- } finally {
289
- removeSignals();
290
- await terminateAll(children);
291
- runCleanups();
292
- }
293
- }
294
-
295
- /** The npz the Studio loads: the file itself, or the file with --transform's
296
- * scale/offsetY/yaw baked in (take-transform.mjs). Either way it is put in
297
- * the (gitignored) node_modules cache, where Vite can serve it to ?motion=. */
298
- async function stageTake(file, bytes, transform) {
299
- if (isIdentityTransform(transform)) {
300
- const sha256 = createHash("sha256").update(bytes).digest("hex");
301
- const cached = join(CACHE_DIR, `${sha256.slice(0, 16)}.npz`);
302
- if (!existsSync(cached)) copyFileSync(file, cached);
303
- return { sha256, cacheName: `${sha256.slice(0, 16)}.npz`, sceneOffset: { x: 0, y: 0, z: 0 } };
304
- }
305
- const decoded = await decodeMotionNpz(new Uint8Array(bytes));
306
- const { motion, sceneOffset } = transformTake(decoded, transform);
307
- const staging = join(CACHE_DIR, `.staging-${process.pid}.npz`);
308
- writeNpz(staging, takeToNpzMembers(motion));
309
- const sha256 = createHash("sha256").update(readFileSync(staging)).digest("hex");
310
- const cacheName = `${sha256.slice(0, 16)}.npz`;
311
- copyFileSync(staging, join(CACHE_DIR, cacheName));
312
- rmSync(staging, { force: true });
313
- return { sha256, cacheName, sceneOffset };
314
- }
315
-
316
- async function renderMotion({ cdp, base, file, options, version }) {
317
- const started = Date.now();
318
- const bytes = readFileSync(file);
319
- const sha256 = createHash("sha256").update(bytes).digest("hex");
320
- const motionName = basename(file, ".npz");
321
- const staged = await stageTake(file, bytes, options.transform);
322
- // The page renders the take where playback anchors it; a scene offset is
323
- // the camera moved the opposite way, and every reported point is shifted
324
- // back into the scene by `offset`.
325
- const offset = staged.sceneOffset;
326
- const negOffset = { x: -offset.x, y: -offset.y, z: -offset.z };
327
- const pageBox = options.box ? { min: options.box.min.map((v, i) => v - [offset.x, offset.y, offset.z][i]), max: options.box.max.map((v, i) => v - [offset.x, offset.y, offset.z][i]) } : null;
328
- const motionUrl = `/node_modules/.cache/gt-render/${staged.cacheName}`;
329
- const studioUrl = `${base}/app/?motion=${encodeURIComponent(motionUrl)}`;
330
- const log = (message) => console.log(`[${motionName}] ${message}`);
331
-
332
- await openStudioClean(cdp, studioUrl);
333
- await waitFor("studio motion load", () => cdp.evaluate("!!(window.__cozyclay && window.__cozyclay.motion && window.__cozyclay.rigA && typeof window.__cozyclay.captureFraming === 'function')"), { timeoutMs: 180000, intervalMs: 250 });
334
- await cdp.evaluate(`(${installPageHelpers.toString()})(${supportValues.toString()}, ${JSON.stringify(RIG_JOINTS)}, ${JSON.stringify(MASK_RGB)}, ${boxContactValues.toString()})`);
335
- const state = await cdp.evaluate("window.__gtRender.state()");
336
- if (state.motionUrl !== motionUrl) throw new Error(`Studio loaded ${state.motionUrl} instead of ${motionUrl}`);
337
- if (state.fps !== FPS) throw new Error(`timeline runs at ${state.fps} fps, expected ${FPS}`);
338
- const frames = state.frameCount;
339
- log(`loaded ${frames} frames @ ${state.fps} fps, model ${state.characterModel}`);
340
- const motionDir = join(options.out, motionName);
341
- mkdirSync(motionDir, { recursive: true });
342
- if (options.exportVertices) writeFileSync(join(motionDir, "vertices.f32"), "");
343
- const sceneRecord = options.sceneBox ? { ...sceneBoxRecord(options.sceneBox), studio: await cdp.evaluate(`window.__gtRender.placeBox(${JSON.stringify(options.sceneBox)}, ${JSON.stringify(offset)})`) } : null;
344
-
345
- // Pre-pass: the camera must see every vertex of every frame (solved
346
- // camera), and --box needs every vertex anyway.
347
- const geometry = { width: WIDTH, height: HEIGHT, fMm: options.fMm, azimuthDeg: options.azimuthDeg, elevationDeg: options.elevationDeg, margin: options.margin };
348
- const givenMargin = options.camera ? (options.camera.margin ?? options.margin) : options.margin;
349
- const { R, kx, ky } = options.camera
350
- ? { R: options.camera.cameraToWorldRotation, ...marginSlopes(options.camera, givenMargin) }
351
- : supportArgs(geometry);
352
- await cdp.evaluate(`window.__gtRender.setOrientation(${JSON.stringify(R)}, ${kx}, ${ky})`);
353
- const sampleOptions = { vertices: !options.camera, box: pageBox, exportVertices: options.exportVertices };
354
- const supports = [];
355
- const prepassJoints = [];
356
- const contacts = [];
357
- let vertexCount = 0;
358
- for (let frame = 0; frame < frames; frame += 1) {
359
- const sample = await cdp.evaluate(`window.__gtRender.sample(${frame}, ${JSON.stringify(sampleOptions)})`);
360
- if (sample.support) supports.push(sample.support);
361
- if (sample.vertices) {
362
- const points = Buffer.allocUnsafe(sample.vertices.length * 4);
363
- sample.vertices.forEach((v, i) => points.writeFloatLE(v + [offset.x, offset.y, offset.z][i % 3], i * 4));
364
- appendFileSync(join(motionDir, "vertices.f32"), points);
365
- }
366
- prepassJoints.push(sample.joints);
367
- if (sample.contact) contacts.push(sample.contact);
368
- vertexCount = sample.vertexCount;
369
- }
370
- if (options.exportVertices) writeFileSync(join(motionDir, "vertices.json"), JSON.stringify({ frames, fps: FPS, vertexCount, file: "vertices.f32", layout: "frame,vertex,xyz; float32 LE; world metres" }));
371
- if (options.sceneBox && !options.camera) supports.push(supportValues(boxCorners(options.sceneBox).flatMap(p => p.map((v, i) => v - [offset.x, offset.y, offset.z][i])), R, kx, ky));
372
- // pageCamera renders the anchored take; camera (scene) is what is reported.
373
- const pageCamera = options.camera ? translateCamera(options.camera, negOffset) : buildCamera({ ...geometry, support: mergeSupports(supports) });
374
- const camera = options.camera ?? translateCamera(pageCamera, offset);
375
- const framing = { pos: pageCamera.position, yaw: pageCamera.yaw, pitch: pageCamera.pitch, fovDeg: pageCamera.fovDeg };
376
- const output = { width: WIDTH, height: HEIGHT };
377
- log(`camera at (${camera.position.x.toFixed(3)}, ${camera.position.y.toFixed(3)}, ${camera.position.z.toFixed(3)}), fov ${camera.fovDeg.toFixed(4)} deg, f ${camera.fy.toFixed(3)} px, ${options.camera ? `given (${options.camera.source})` : `${camera.bindingAxis}-bound`}, ${vertexCount} vertices/frame`);
378
-
379
- // Scene joints (page + offset) projected with camera.json. A solved
380
- // camera guarantees the margin box; a given one only reports it.
381
- const sceneJoints = prepassJoints.map((joints) => triples(joints, 12).map(([x, y, z]) => [x + offset.x, y + offset.y, z + offset.z]));
382
- const uv = sceneJoints.map((joints) => joints.map((point) => projectPoint(point, camera)));
383
- let minMarginPx = Infinity;
384
- for (const frameUv of uv) {
385
- for (const [u, v, depth] of frameUv) minMarginPx = Math.min(minMarginPx, depth > 0 ? Math.min(u, v, WIDTH - u, HEIGHT - v) : -Infinity);
386
- }
387
- const marginPx = givenMargin * Math.min(WIDTH, HEIGHT);
388
- if (!options.camera && minMarginPx < marginPx - 1e-6) throw new Error(`a joint projects ${minMarginPx.toFixed(2)} px from the edge, inside the ${marginPx} px margin`);
389
- if (options.camera && minMarginPx < marginPx - 1e-6) log(`warning: a joint projects ${minMarginPx.toFixed(2)} px from the edge (margin ${marginPx} px); negative = outside the image or behind the camera`);
390
-
391
- if (!options.noVideo) writeFileSync(join(motionDir, "plate.png"), Buffer.from(await cdp.evaluate(`window.__gtRender.plate(${JSON.stringify(framing)}, ${JSON.stringify(output)})`), "base64"));
392
-
393
- const wanted = new Set(options.noVideo ? [] : options.variants.map((variant) => variant.name));
394
- const needsShadedFrames = !options.noVideo && options.variants.some((variant) => variant.kind === "hue");
395
- const browserPasses = options.noVideo ? [{ name: "mask", partColours: null }] : [
396
- ...(wanted.has("shaded") || needsShadedFrames ? [{ name: "shaded", partColours: true }] : []),
397
- ...(wanted.has("skin") ? [{ name: "skin", partColours: false }] : []),
398
- ];
399
- const checks = { prepassVsRenderJointMaxM: 0, threeVsCameraJsonMaxPx: 0 };
400
- const framesDirs = {};
401
- const passState = {};
402
- const maskRawDir = join(motionDir, ".mask-raw");
403
- rmSync(maskRawDir, { recursive: true, force: true });
404
- mkdirSync(maskRawDir, { recursive: true });
405
- for (const [passIndex, pass] of browserPasses.entries()) {
406
- const withMask = passIndex === 0;
407
- const withColour = pass.partColours !== null;
408
- if (withColour) passState[pass.name] = await cdp.evaluate(`window.__gtRender.setPartColours(${pass.partColours})`);
409
- const framesDir = wanted.has(pass.name) ? join(motionDir, pass.name, "frames") : join(motionDir, `.${pass.name}-frames`);
410
- if (withColour) {
411
- rmSync(framesDir, { recursive: true, force: true });
412
- mkdirSync(framesDir, { recursive: true });
413
- framesDirs[pass.name] = framesDir;
414
- }
415
- for (let frame = 0; frame < frames; frame += 1) {
416
- const captured = await cdp.evaluate(`window.__gtRender.capture(${frame}, ${JSON.stringify(framing)}, ${JSON.stringify(output)}, ${withMask}, ${withColour})`);
417
- if (withColour) writeFileSync(join(framesDir, `${String(frame).padStart(6, "0")}.png`), Buffer.from(captured.png, "base64"));
418
- if (withMask) writeFileSync(join(maskRawDir, `${String(frame).padStart(6, "0")}.png`), Buffer.from(captured.mask, "base64"));
419
- for (let i = 0; i < captured.joints.length; i += 1) {
420
- checks.prepassVsRenderJointMaxM = Math.max(checks.prepassVsRenderJointMaxM, Math.abs(captured.joints[i] - prepassJoints[frame][i]));
421
- }
422
- triples(captured.joints, 12).forEach((point, j) => {
423
- const [u, v] = projectPoint(point, pageCamera);
424
- checks.threeVsCameraJsonMaxPx = Math.max(checks.threeVsCameraJsonMaxPx, Math.abs(u - captured.threeUv[j * 2]), Math.abs(v - captured.threeUv[j * 2 + 1]));
425
- });
426
- }
427
- log(`rendered ${pass.name}: ${frames} frames`);
428
- }
429
- writeMasks(maskRawDir, join(motionDir, "mask"));
430
- rmSync(maskRawDir, { recursive: true, force: true });
431
- // The pose must not depend on the pass: joints.json is the pre-pass pose.
432
- if (checks.prepassVsRenderJointMaxM > 1e-6) throw new Error(`rendered pose differs from the pre-pass by ${checks.prepassVsRenderJointMaxM} m`);
433
- if (checks.threeVsCameraJsonMaxPx > 1e-3) throw new Error(`camera.json projection differs from the Three capture camera by ${checks.threeVsCameraJsonMaxPx} px`);
434
-
435
- const cameraJson = cameraRecord(camera, passState[browserPasses[0].name]?.shotCam ?? state.shotCam);
436
- if (options.camera) cameraJson.source = options.camera.source;
437
- const placement = {
438
- transform: options.transform ?? null,
439
- sceneOffset: offset,
440
- anchor: state.motionAnchor,
441
- note: "Studio placement: playback anchors the take's frame-0 root XZ on the subject (anchor) with the Character group's yaw. --transform: scale/offsetY/yaw baked into the loaded npz (yaw about the anchor), offsetX/offsetZ applied as the opposite camera move; joints, uv and contact are in the scene frame with the offset included.",
442
- renderedNpzSha256: staged.sha256,
443
- };
444
- const contactJson = options.box ? {
445
- box: options.box,
446
- basis: "skinned-vertices",
447
- vertexCount,
448
- convention: "signedDistanceM: closest skinned vertex to the box, positive outside, negative inside (depth to the nearest face). minDistanceM = max(0, signed), maxPenetrationM = max(0, -signed). Scene metres, the placement's offset included.",
449
- frames: contacts.map((contact) => ({ signedDistanceM: round(contact.minSignedDistance, 6), ...Object.fromEntries(Object.entries(contactFromSigned(contact.minSignedDistance)).map(([key, value]) => [key, round(value, 6)])), verticesInside: contact.insideCount })),
450
- } : null;
451
- if (contactJson) writeFileSync(join(motionDir, "contact.json"), `${JSON.stringify(contactJson)}\n`);
452
- const jointsJson = {
453
- convention: "world: metres in the camera.json world frame; uv: pixels in the camera.json image convention (origin top-left, v down), projected with camera.json; depth: camera-space Z in metres.",
454
- fps: FPS,
455
- frames,
456
- joints: RIG_JOINTS.map(({ bone, cskel27 }) => ({ name: bone.replace(/^mixamorig/, ""), bone, cskel27 })),
457
- note: "Rig bones of the rendered character (the pose actually drawn). Mixamo Spine/Spine1/Spine2 correspond to cskel27 Spine1/Spine2/Spine3 (src/ardy/playback.js); the Mixamo body is not congruent with cskel27 and playback scales the take's root travel to the rig's leg length, so these are NOT the npz's posed_joints: they differ by centimetres, growing with distance travelled (about 1% of it on walk-then-stop). They are the truth for what the video shows.",
458
- world: sceneJoints.map((joints) => joints.map((point) => point.map((value) => round(value, 6)))),
459
- uv: uv.map((frameUv) => frameUv.map(([u, v]) => [round(u, 4), round(v, 4)])),
460
- depth: uv.map((frameUv) => frameUv.map(([, , z]) => round(z, 6))),
461
- };
462
- const shared = {
463
- tool: "tools/gt-render/render.mjs",
464
- toolVersion: version,
465
- createdAt: new Date().toISOString(),
466
- source: { path: file, sha256, bytes: bytes.length },
467
- motionName,
468
- frames,
469
- fps: FPS,
470
- placement,
471
- camera: options.camera ? { source: options.camera.source, given: true } : { given: false },
472
- video: { file: "video.mp4", width: WIDTH, height: HEIGHT, codec: "h264 (libx264)", pixFmt: "yuv420p", colorspace: "smpte170m, tv range", crf: options.crf },
473
- characterModel: state.characterModel,
474
- characterScale: state.characterScale,
475
- studio: { url: studioUrl, captureHook: "window.__cozyclay.captureFraming" },
476
- plate: "../plate.png (same camera, character hidden)",
477
- mask: "../mask/%06d.png (8-bit gray, 255 = character: the frame re-rendered with the character unlit in one colour, >= 50% pixel coverage)",
478
- checks: {
479
- ...checks,
480
- minJointEdgeDistancePx: minMarginPx,
481
- framingVerticesPerFrame: vertexCount,
482
- },
483
- };
484
- if (sceneRecord) writeFileSync(join(motionDir, "scene.json"), `${JSON.stringify(sceneRecord, null, 2)}\n`);
485
- if (options.noVideo) {
486
- const { video, plate, ...rest } = shared;
487
- writeFileSync(join(motionDir, "camera.json"), `${JSON.stringify(cameraJson, null, "\t")}\n`);
488
- writeFileSync(join(motionDir, "joints.json"), `${JSON.stringify(jointsJson)}\n`);
489
- writeFileSync(join(motionDir, "meta.json"), `${JSON.stringify({ ...rest, mask: "mask/%06d.png (8-bit gray, 255 = character: the frame re-rendered with the character unlit in one colour, >= 50% pixel coverage)", variant: null, noVideo: true, contact: contactJson ? "contact.json" : null }, null, "\t")}\n`);
490
- log(`wrote joints + masks (no video)`);
491
- }
492
- for (const variant of options.noVideo ? [] : options.variants) {
493
- const dir = join(motionDir, variant.name);
494
- mkdirSync(dir, { recursive: true });
495
- if (sceneRecord) writeFileSync(join(dir, "scene.json"), `${JSON.stringify(sceneRecord, null, 2)}\n`);
496
- const filter = variant.kind === "hue" ? `hue=h=${variant.degrees}` : null;
497
- encode(variant.kind === "hue" ? framesDirs.shaded : framesDirs[variant.name], join(dir, "video.mp4"), { crf: options.crf, filter });
498
- writeFileSync(join(dir, "camera.json"), `${JSON.stringify(cameraJson, null, "\t")}\n`);
499
- writeFileSync(join(dir, "joints.json"), `${JSON.stringify(jointsJson)}\n`);
500
- const variantDetail = variant.kind === "hue"
501
- ? { partColours: "shaded", postFilter: filter, note: `ffmpeg hue filter on the shaded frames: rotates every pixel's chroma by ${variant.degrees} degrees, so all hues shift uniformly and greys are unchanged.` }
502
- : { partColours: variant.kind === "shaded" ? "shaded" : "off", postFilter: null };
503
- writeFileSync(join(dir, "meta.json"), `${JSON.stringify({ ...shared, variant: variant.name, variantDetail }, null, "\t")}\n`);
504
- log(`wrote ${variant.name}`);
505
- }
506
- if (!options.keepFrames) for (const dir of Object.values(framesDirs)) rmSync(dir, { recursive: true, force: true });
507
- else if (framesDirs.shaded && !wanted.has("shaded")) rmSync(framesDirs.shaded, { recursive: true, force: true });
508
- log(`done in ${((Date.now() - started) / 1000).toFixed(1)} s`);
509
- }
510
-
511
- main().catch((error) => {
512
- console.error(error?.stack || String(error));
513
- process.exitCode = 1;
514
- });
@@ -1,31 +0,0 @@
1
- import { projectPoint } from "./camera-math.mjs";
2
- import { elementByPath } from "../../src/studio-elements.js";
3
-
4
- /** Studio cube is 1 m on each axis, origin at the floor/footprint centre. */
5
- export function parseSceneBox(value) {
6
- const b = typeof value === "string" ? JSON.parse(value) : value;
7
- const out = { x: b?.x, z: b?.z, rot: b?.rot ?? 0, sx: b?.sx ?? b?.scaleX, sy: b?.sy ?? b?.scaleY, sz: b?.sz ?? b?.scaleZ };
8
- if (!Object.values(out).every(Number.isFinite) || ![out.sx, out.sy, out.sz].every(v => v > 0)) throw new Error("scene-box needs finite x,z,rot and positive sx,sy,sz (scaleX/Y/Z also accepted)");
9
- const size = elementByPath("object.scale"), position = elementByPath("object.position");
10
- for (const axis of ["x", "y", "z"]) if (out[`s${axis}`] < size.min[axis] || out[`s${axis}`] > size.max[axis]) throw new Error(`scene-box s${axis} must be within Studio's ${size.min[axis]}..${size.max[axis]} m range`);
11
- for (const axis of ["x", "z"]) if (out[axis] < position.min[axis] || out[axis] > position.max[axis]) throw new Error(`scene-box ${axis} exceeds Studio position bounds`);
12
- out.rot = ((out.rot + 180) % 360 + 360) % 360 - 180;
13
- return out;
14
- }
15
- export function boxCorners(box) {
16
- const b = parseSceneBox(box), a = b.rot * Math.PI / 180, c = Math.cos(a), s = Math.sin(a);
17
- return Array.from({ length: 8 }, (_, i) => {
18
- const x = (i & 1 ? 1 : -1) * b.sx / 2, z = (i & 4 ? 1 : -1) * b.sz / 2;
19
- return [b.x + c * x + s * z, i & 2 ? b.sy : 0, b.z - s * x + c * z];
20
- });
21
- }
22
- export const BOX_EDGES = Array.from({ length: 8 }, (_, i) => [1, 2, 4].filter(bit => !(i & bit)).map(bit => [i, i | bit])).flat();
23
- export function sceneBoxRecord(box) {
24
- const b = parseSceneBox(box);
25
- return { kind: "cube", placement: b, centre: [b.x, b.sy / 2, b.z], halfExtents: [b.sx / 2, b.sy / 2, b.sz / 2], yawDeg: b.rot,
26
- ...(b.rot === 0 ? { min: [b.x - b.sx / 2, 0, b.z - b.sz / 2], max: [b.x + b.sx / 2, b.sy, b.z + b.sz / 2] } : {}),
27
- corners: boxCorners(b), convention: "World metres, +Y up; yaw degrees about +Y. Cube base at y=0." };
28
- }
29
- export function projectBox(box, camera) {
30
- return boxCorners(box).map(p => projectPoint(p, { ...camera, worldToCameraCv: camera.worldToCameraCv ?? camera.worldToCamera }));
31
- }
@@ -1,87 +0,0 @@
1
- /**
2
- * Scene transform of a cskel27 take for the renderer's --transform (#431),
3
- * with the Studio's sceneCalibration semantics (src/App.jsx loadMotion):
4
- *
5
- * scale, offsetY applied to the take's arrays (applyMotionCalibration),
6
- * exactly as the Studio's playback calibration does;
7
- * yawDeg rotation about +Y through the take's frame-0 anchor. The
8
- * Studio puts it on the Character group; here it is baked
9
- * into the take (joints rotated by applyMotionCalibration,
10
- * plus the root's local rotation, which that pass leaves
11
- * alone), which is the same rigid rotation because playback
12
- * subtracts the frame-0 root XZ before placing the rig;
13
- * offsetX/offsetZ scene metres added after the anchor. Playback anchors
14
- * frame 0 on the subject, so an offset baked into the take
15
- * would be cancelled; the renderer instead moves the camera
16
- * by the opposite amount (identical character pixels) and
17
- * adds the offset to every reported joint.
18
- */
19
- import { applyMotionCalibration, normalizeMotionCalibration } from "../../src/ardy/motion-calibration.js";
20
-
21
- const KEYS = new Set(["scale", "yawDeg", "offsetX", "offsetY", "offsetZ"]);
22
-
23
- /** Parse and normalise a --transform JSON object; unknown keys are refused. */
24
- export function parseTransform(value) {
25
- const raw = typeof value === "string" ? JSON.parse(value) : value;
26
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error("transform must be a JSON object");
27
- for (const [key, entry] of Object.entries(raw)) {
28
- if (!KEYS.has(key)) throw new Error(`transform: unknown key ${key} (allowed: ${[...KEYS].join(", ")})`);
29
- if (!Number.isFinite(Number(entry))) throw new Error(`transform: ${key} must be a finite number`);
30
- }
31
- const normalized = normalizeMotionCalibration(raw);
32
- for (const key of Object.keys(raw)) {
33
- const given = Number(raw[key]);
34
- // normalizeMotionCalibration clamps silently; a scorer must not.
35
- if (key !== "yawDeg" && Math.abs(normalized[key] - given) > 1e-12) throw new Error(`transform: ${key} ${given} is outside the Studio calibration range`);
36
- }
37
- return normalized;
38
- }
39
-
40
- export function isIdentityTransform(t) {
41
- return !t || (t.scale === 1 && t.yawDeg === 0 && t.offsetX === 0 && t.offsetY === 0 && t.offsetZ === 0);
42
- }
43
-
44
- /**
45
- * Bake scale, offsetY and yaw of `transform` into a decoded take
46
- * ({ frames, rotMats, rootPos, posedJoints, ... }, src/ardy/npz.js). Returns
47
- * the new take and the scene offset the caller still has to apply.
48
- */
49
- export function transformTake(motion, transform) {
50
- const { motion: moved } = applyMotionCalibration(motion, { ...transform, offsetX: 0, offsetZ: 0 });
51
- const rotMats = Float32Array.from(motion.rotMats);
52
- if (transform.yawDeg !== 0) {
53
- const a = (transform.yawDeg * Math.PI) / 180;
54
- const c = Math.cos(a);
55
- const s = Math.sin(a);
56
- // Ry with applyMotionCalibration's sign: x' = c x + s z, z' = -s x + c z.
57
- const Ry = [c, 0, s, 0, 1, 0, -s, 0, c];
58
- const stride = rotMats.length / motion.frames;
59
- for (let f = 0; f < motion.frames; f += 1) {
60
- const o = f * stride; // joint 0 (Hips) is the root: local == global
61
- const m = Array.from(rotMats.subarray(o, o + 9));
62
- for (let r = 0; r < 3; r += 1) {
63
- for (let col = 0; col < 3; col += 1) {
64
- rotMats[o + r * 3 + col] = Ry[r * 3] * m[col] + Ry[r * 3 + 1] * m[3 + col] + Ry[r * 3 + 2] * m[6 + col];
65
- }
66
- }
67
- }
68
- }
69
- return {
70
- motion: { ...moved, rotMats, rootPos: Float32Array.from(moved.rootPos), posedJoints: Float32Array.from(moved.posedJoints) },
71
- sceneOffset: { x: transform.offsetX, y: 0, z: transform.offsetZ },
72
- };
73
- }
74
-
75
- /** The npz members the Studio decoder reads, for tools/ardy/npz.mjs writeNpz. */
76
- export function takeToNpzMembers(motion) {
77
- const joints = motion.posedJoints.length / (motion.frames * 3);
78
- const members = {
79
- local_rot_mats: { data: Float32Array.from(motion.rotMats), shape: [motion.frames, joints, 3, 3] },
80
- root_positions: { data: Float32Array.from(motion.rootPos), shape: [motion.frames, 3] },
81
- posed_joints: { data: Float32Array.from(motion.posedJoints), shape: [motion.frames, joints, 3] },
82
- fps: { data: Int32Array.of(motion.fps), shape: [] },
83
- };
84
- if (motion.personScale !== undefined && motion.personScale !== 1) members.person_scale = { data: Float32Array.of(motion.personScale), shape: [] };
85
- if (motion.boneScale) members.bone_scale = { data: Float32Array.from(motion.boneScale), shape: [motion.boneScale.length] };
86
- return members;
87
- }