cozyclay 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (583) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +12 -30
  3. package/bin/agent/agent-routes.mjs +40 -113
  4. package/bin/agent/agent-runner.mjs +9 -10
  5. package/bin/agent/cliproxy-provider.mjs +135 -0
  6. package/bin/agent/credential-store.mjs +30 -7
  7. package/bin/agent/pi-tools.mjs +4 -1
  8. package/bin/agent/provider-keys.mjs +32 -0
  9. package/bin/agent/provider-login.mjs +110 -0
  10. package/bin/agent/provider-routes.mjs +99 -0
  11. package/bin/agent/providers.mjs +19 -97
  12. package/bin/agent/script-tool.mjs +17 -4
  13. package/bin/agent/studio-motion-reference.mjs +23 -0
  14. package/bin/agent/studio-prompt.mjs +1 -1
  15. package/bin/agent/studio-rebase-text.mjs +32 -0
  16. package/bin/agent/studio-rebase.mjs +26 -39
  17. package/bin/agent/studio-tools.mjs +9 -28
  18. package/bin/agent/tool-arguments.mjs +49 -0
  19. package/bin/agent/turn-frames.mjs +66 -0
  20. package/bin/codex-auth.mjs +9 -2
  21. package/bin/cozyclay.mjs +10 -116
  22. package/bin/live/cli.mjs +22 -6
  23. package/bin/mcp-runtime.mjs +2 -12
  24. package/bin/package-signature.mjs +0 -4
  25. package/dist/app/index.html +7 -6
  26. package/dist/assets/EXRLoader-CvVIvGVE.js +1 -0
  27. package/dist/assets/analytics-C9sUnndd.js +1 -0
  28. package/dist/assets/app-CCh--1Hc.js +5087 -0
  29. package/dist/assets/app-f-fkV5uP.css +1 -0
  30. package/dist/assets/compile-worker-CkxiD6lH.js +5 -0
  31. package/dist/assets/fflate.module-KbGj5-H6.js +5 -0
  32. package/dist/assets/{first-shot-handoff-BlT33CGf.js → first-shot-handoff-CC4xe4HM.js} +1 -1
  33. package/dist/assets/{landing-BSesrCpL.js → landing-DjHD8u7k.js} +1 -1
  34. package/dist/assets/scene-asset-sync-Hx_FzdOH.js +20 -0
  35. package/dist/assets/scene-asset-sync-_S8NQl5B.css +1 -0
  36. package/dist/assets/workflow-C4yKH1p4.js +179 -0
  37. package/dist/cozyclay-package.json +1 -1
  38. package/dist/index.html +3 -3
  39. package/dist/llms.txt +14 -0
  40. package/dist/sw.js +3 -6
  41. package/dist/workflow/index.html +5 -4
  42. package/mcp/LIVE-PROTOCOL.md +7 -47
  43. package/mcp/README.md +16 -26
  44. package/mcp/live-hub.mjs +6 -10
  45. package/mcp/package.json +1 -3
  46. package/mcp/tool-handlers.mjs +4 -168
  47. package/package.json +3 -22
  48. package/src/App.jsx +174 -2639
  49. package/src/agent-progress.js +79 -0
  50. package/src/agent-turn-mark.js +30 -0
  51. package/src/analytics.js +1 -19
  52. package/src/app-context.js +5 -0
  53. package/src/app-stage.jsx +2 -34
  54. package/src/asset-pane.jsx +6 -5
  55. package/src/camera-block.js +21 -0
  56. package/src/camera-direction.js +120 -0
  57. package/src/character-kind.js +3 -9
  58. package/src/command-bus.js +8 -6
  59. package/src/commands/cast.js +5 -34
  60. package/src/commands/elements/character.js +1 -1
  61. package/src/commands/elements/motion.js +1 -6
  62. package/src/commands/elements/object.js +6 -2
  63. package/src/commands/elements/shot.js +4 -1
  64. package/src/commands/elements.js +38 -14
  65. package/src/commands/index.js +3 -1
  66. package/src/commands/kits.js +37 -0
  67. package/src/commands/motion-timing.js +57 -0
  68. package/src/commands/motion.js +9 -152
  69. package/src/commands/motion3-compile.js +65 -0
  70. package/src/commands/motion3.js +207 -0
  71. package/src/commands/objects.js +6 -4
  72. package/src/commands/shot.js +49 -11
  73. package/src/commands/stage.js +14 -1
  74. package/src/commands/view.js +4 -1
  75. package/src/document-mirrors.js +42 -0
  76. package/src/document-store.js +4 -0
  77. package/src/domains/cast.js +19 -194
  78. package/src/domains/motion/motion-range-pin-rules.js +1 -1
  79. package/src/domains/motion/take-source.js +51 -0
  80. package/src/domains/motion.js +60 -1838
  81. package/src/domains/scenes.js +12 -55
  82. package/src/domains/shots.js +2 -2
  83. package/src/domains/stage.js +4 -2
  84. package/src/draft-ghost.js +46 -0
  85. package/src/draft-ghost.jsx +129 -0
  86. package/src/dualview.jsx +4 -3
  87. package/src/effects/EffectsLayer.jsx +112 -0
  88. package/src/effects/effect-meshes.js +232 -0
  89. package/src/effects/effect-record.js +103 -0
  90. package/src/effects/emitter.js +59 -0
  91. package/src/effects/simulate.js +261 -0
  92. package/src/effects/state.js +59 -0
  93. package/src/execution-telemetry.js +2 -3
  94. package/src/first-success-guide.jsx +5 -5
  95. package/src/ghost-set.js +257 -0
  96. package/src/held-object-edit.jsx +113 -0
  97. package/src/held-object-pose.js +175 -0
  98. package/src/hierarchy-model.js +1 -1
  99. package/src/hierarchy-panel.jsx +1 -1
  100. package/src/imported-mesh.jsx +103 -0
  101. package/src/kits/held.js +84 -0
  102. package/src/kits/index.js +70 -0
  103. package/src/kits/smoking.js +57 -0
  104. package/src/light-blockers.js +93 -0
  105. package/src/motion/beat-board-model.js +84 -0
  106. package/src/motion/beat-board.css +124 -0
  107. package/src/motion/beat-board.jsx +59 -0
  108. package/src/motion/center-of-mass.js +66 -0
  109. package/src/motion/fix-collisions.js +850 -0
  110. package/src/motion/physics-review.js +118 -0
  111. package/src/{ardy → motion}/physics-support.js +1 -76
  112. package/src/motion/rig-snapshot.js +22 -0
  113. package/src/motion/take-segments.jsx +140 -0
  114. package/src/{ardy → motion}/timeline-coordinates.js +0 -21
  115. package/src/{ardy → motion}/timeline.css +1 -2
  116. package/src/{ardy → motion}/timeline.jsx +48 -419
  117. package/src/motion/waypoints.js +76 -0
  118. package/src/motion3/beats.js +83 -0
  119. package/src/motion3/body.js +158 -0
  120. package/src/motion3/bones.js +47 -0
  121. package/src/motion3/carried.js +47 -0
  122. package/src/motion3/compile-job.js +75 -0
  123. package/src/motion3/compile-worker.js +10 -0
  124. package/src/motion3/compiler/anchors.js +105 -0
  125. package/src/motion3/compiler/arm-orient.js +128 -0
  126. package/src/motion3/compiler/channels.js +125 -0
  127. package/src/motion3/compiler/compile.js +205 -0
  128. package/src/motion3/compiler/gait-rhythm.js +97 -0
  129. package/src/motion3/compiler/grip.js +171 -0
  130. package/src/motion3/compiler/head-steady.js +48 -0
  131. package/src/motion3/compiler/hold.js +134 -0
  132. package/src/motion3/compiler/idle.js +113 -0
  133. package/src/motion3/compiler/limbs.js +170 -0
  134. package/src/motion3/compiler/math.js +72 -0
  135. package/src/motion3/compiler/pose.js +162 -0
  136. package/src/motion3/compiler/quat.js +49 -0
  137. package/src/motion3/compiler/skeleton.js +74 -0
  138. package/src/motion3/compiler/validate-common.js +32 -0
  139. package/src/motion3/compiler/validate-goals.js +118 -0
  140. package/src/motion3/compiler/validate-objects.js +143 -0
  141. package/src/motion3/compiler/validate-parts.js +116 -0
  142. package/src/motion3/compiler/validate.js +122 -0
  143. package/src/motion3/compiler/vocab.js +73 -0
  144. package/src/motion3/compiler/walk-pelvis.js +275 -0
  145. package/src/motion3/compiler/walk.js +207 -0
  146. package/src/motion3/compiler/wrist-clamp.js +32 -0
  147. package/src/motion3/delta.js +47 -0
  148. package/src/motion3/describe.js +174 -0
  149. package/src/motion3/docs.js +27 -0
  150. package/src/motion3/edit-carry.js +21 -0
  151. package/src/motion3/fix/ease.js +16 -0
  152. package/src/motion3/fix/ground.js +37 -0
  153. package/src/motion3/fix/index.js +52 -0
  154. package/src/motion3/fix/push.js +71 -0
  155. package/src/motion3/fix/reach.js +46 -0
  156. package/src/motion3/fix/retime.js +79 -0
  157. package/src/motion3/fix/self.js +211 -0
  158. package/src/motion3/fix/slide.js +70 -0
  159. package/src/motion3/fix/turn.js +51 -0
  160. package/src/motion3/follow.js +39 -0
  161. package/src/motion3/free-motion.js +173 -0
  162. package/src/motion3/grip-choice.js +130 -0
  163. package/src/motion3/hold-plan.js +157 -0
  164. package/src/motion3/json-patch.js +77 -0
  165. package/src/motion3/key-aim.js +105 -0
  166. package/src/motion3/key-edit.js +82 -0
  167. package/src/motion3/lenient.js +127 -0
  168. package/src/motion3/object-keys.js +236 -0
  169. package/src/motion3/object-pose.js +182 -0
  170. package/src/motion3/object-tracks.js +12 -0
  171. package/src/motion3/pipeline.js +102 -0
  172. package/src/motion3/playback.js +51 -0
  173. package/src/motion3/probes.js +91 -0
  174. package/src/motion3/qa/body-checks.js +34 -0
  175. package/src/motion3/qa/check-names.js +14 -0
  176. package/src/motion3/qa/checks.js +121 -0
  177. package/src/motion3/qa/contact-checks.js +51 -0
  178. package/src/motion3/qa/explain.js +80 -0
  179. package/src/motion3/qa/fmt.js +5 -0
  180. package/src/motion3/qa/foot-checks.js +72 -0
  181. package/src/motion3/qa/geometry.js +77 -0
  182. package/src/motion3/qa/goals.js +191 -0
  183. package/src/motion3/qa/ground.js +60 -0
  184. package/src/motion3/qa/hints-contact.js +179 -0
  185. package/src/motion3/qa/hints-goal.js +160 -0
  186. package/src/motion3/qa/hints-knee.js +24 -0
  187. package/src/motion3/qa/hints-motion.js +209 -0
  188. package/src/motion3/qa/hints-object.js +91 -0
  189. package/src/motion3/qa/index.js +42 -0
  190. package/src/motion3/qa/key-checks.js +82 -0
  191. package/src/motion3/qa/near.js +96 -0
  192. package/src/motion3/qa/object-checks.js +135 -0
  193. package/src/motion3/qa/patch.js +161 -0
  194. package/src/motion3/qa/severity.js +38 -0
  195. package/src/motion3/qa/spec-checks.js +65 -0
  196. package/src/motion3/qa/style.js +218 -0
  197. package/src/motion3/qa/wrist-checks.js +69 -0
  198. package/src/motion3/qa/wrist-obs.js +60 -0
  199. package/src/motion3/refs.js +120 -0
  200. package/src/motion3/repair-tune.js +121 -0
  201. package/src/motion3/repair.js +83 -0
  202. package/src/motion3/report.js +67 -0
  203. package/src/motion3/rigs/index.js +14 -0
  204. package/src/motion3/rigs/x-bot-tpose-body.json +1 -0
  205. package/src/motion3/rigs/x-bot-tpose.json +1 -0
  206. package/src/motion3/rigs/y-bot-tpose-body.json +1 -0
  207. package/src/motion3/rigs/y-bot-tpose.json +1 -0
  208. package/src/motion3/scene.js +60 -0
  209. package/src/motion3/schema/brief.js +89 -0
  210. package/src/motion3/schema/fields.js +44 -0
  211. package/src/motion3/schema/spec-examples.js +46 -0
  212. package/src/motion3/schema/topics.js +111 -0
  213. package/src/motion3/schema/types.js +147 -0
  214. package/src/motion3/search.js +117 -0
  215. package/src/motion3/second-hand.js +112 -0
  216. package/src/motion3/skills/basic.js +82 -0
  217. package/src/motion3/skills/book.js +76 -0
  218. package/src/motion3/skills/car.js +145 -0
  219. package/src/motion3/skills/frames-auto.js +29 -0
  220. package/src/motion3/skills/index.js +83 -0
  221. package/src/motion3/skills/info.js +65 -0
  222. package/src/motion3/skills/smoke-kit.js +109 -0
  223. package/src/motion3/skills/smoke.js +160 -0
  224. package/src/motion3/spec-store.js +59 -0
  225. package/src/motion3/take-edit.js +155 -0
  226. package/src/motion3/take.js +63 -0
  227. package/src/motion3/timeline.js +127 -0
  228. package/src/motion3/views.js +121 -0
  229. package/src/motion3/walk-plan.js +119 -0
  230. package/src/object-catalog.jsx +7 -1
  231. package/src/object-colors.js +98 -0
  232. package/src/object-gizmo-parts.js +115 -0
  233. package/src/object-gizmo.jsx +37 -122
  234. package/src/object-glow.js +139 -0
  235. package/src/object-hidden.js +33 -0
  236. package/src/object-look.js +196 -0
  237. package/src/object-size.js +10 -0
  238. package/src/object-travel.js +71 -6
  239. package/src/panels/CameraPanel.jsx +7 -7
  240. package/src/panels/HdrEnvironmentControls.jsx +59 -0
  241. package/src/panels/LightPanel.jsx +25 -4
  242. package/src/panels/ObjectLookPanel.jsx +88 -0
  243. package/src/panels/PoseImagePanel.jsx +1 -1
  244. package/src/panels/PosePanel.jsx +2 -17
  245. package/src/panels/RigControlPanel.jsx +5 -53
  246. package/src/panels/SubjectBox.jsx +4 -1
  247. package/src/panels/details.css +14 -0
  248. package/src/posestudio.jsx +4 -27
  249. package/src/project-browser.jsx +3 -4
  250. package/src/project-resources.js +18 -31
  251. package/src/project.js +13 -104
  252. package/src/props.jsx +25 -280
  253. package/src/rail-dot-drag.js +23 -0
  254. package/src/render-passes.js +10 -0
  255. package/src/resource-status.jsx +1 -0
  256. package/src/result-modal.jsx +4 -19
  257. package/src/room.jsx +20 -12
  258. package/src/scene-assets.js +8 -6
  259. package/src/scene-light-place.js +72 -0
  260. package/src/scene-lights.jsx +148 -0
  261. package/src/scene-objects.js +31 -139
  262. package/src/scenes.js +15 -105
  263. package/src/semantic-edit.js +2 -5
  264. package/src/set-pieces.jsx +183 -0
  265. package/src/settings-menu.jsx +3 -11
  266. package/src/shell/BottomDock.jsx +11 -53
  267. package/src/shell/CompositionGuideButton.jsx +20 -0
  268. package/src/shell/DetailsSlot.jsx +16 -200
  269. package/src/shell/GhostsMenuGroup.jsx +74 -0
  270. package/src/shell/LibrarySlot.jsx +1 -3
  271. package/src/shell/MenuBar.jsx +3 -3
  272. package/src/shell/PreferencesDialog.jsx +15 -264
  273. package/src/shell/PreferencesSlot.jsx +2 -8
  274. package/src/shell/ShotPreviewHeader.jsx +17 -0
  275. package/src/shell/TopBar.jsx +5 -83
  276. package/src/shell/ViewportToolbar.jsx +23 -93
  277. package/src/shell/agent-glass.css +19 -6
  278. package/src/shell/details-selection.js +42 -0
  279. package/src/shell/ghosts-menu.css +22 -0
  280. package/src/shell/glass-regions.css +29 -3
  281. package/src/shell/preferences.css +6 -1
  282. package/src/shell/viewport.css +12 -0
  283. package/src/shot-authoring.js +4 -7
  284. package/src/soft-shadows.js +37 -0
  285. package/src/stage-attach-frames.js +12 -12
  286. package/src/stage-canvas-rigs.jsx +3 -3
  287. package/src/stage-capture.jsx +42 -8
  288. package/src/stage-characters.jsx +22 -216
  289. package/src/stage-editor-gizmos.jsx +6 -6
  290. package/src/stage-environment.js +93 -0
  291. package/src/stage-hdr-builtins.js +107 -0
  292. package/src/stage-hdr-image.js +116 -0
  293. package/src/stage-hdr-library.js +70 -0
  294. package/src/stage-hdr-map.js +94 -0
  295. package/src/stage-hdr.js +130 -0
  296. package/src/stage-lighting.js +149 -0
  297. package/src/stage-occlusion.js +210 -0
  298. package/src/stage-sky.jsx +159 -0
  299. package/src/stage-startup-defaults.js +5 -9
  300. package/src/studio-actions.js +12 -14
  301. package/src/studio-agent-commands.js +46 -16
  302. package/src/studio-agent-motion.js +9 -9
  303. package/src/studio-agent-protocol.js +46 -73
  304. package/src/studio-app-binding.js +29 -45
  305. package/src/studio-asset-list.js +17 -0
  306. package/src/studio-contact-sheet.js +37 -5
  307. package/src/studio-elements.js +27 -7
  308. package/src/studio-entity-bounds.js +18 -0
  309. package/src/studio-error-codes.js +8 -0
  310. package/src/studio-export-framing.js +152 -0
  311. package/src/studio-lighting-check.js +103 -0
  312. package/src/studio-motion-visual.js +150 -0
  313. package/src/studio-schema-errors.js +80 -0
  314. package/src/studio-support-gap.js +74 -0
  315. package/src/styles.css +1 -19
  316. package/src/timeline-defaults.js +5 -0
  317. package/src/timeline-extent.js +8 -20
  318. package/src/tutorial-walk.js +17 -0
  319. package/src/ui-scrub.js +1 -1
  320. package/src/use-shot-camera-tracks.js +12 -0
  321. package/src/view-ghosts.js +97 -0
  322. package/src/view-ghosts.jsx +49 -0
  323. package/src/workflow/AgentPanel.jsx +47 -166
  324. package/src/workflow/AgentProgressCard.jsx +107 -0
  325. package/src/workflow/AgentReplyText.jsx +37 -0
  326. package/src/workflow/AgentTurnSteps.jsx +84 -0
  327. package/src/workflow/LoginPanel.jsx +140 -0
  328. package/src/workflow/WorkflowBuilder.jsx +7 -23
  329. package/src/workflow/agent-client.js +54 -51
  330. package/src/workflow/agent-panel.css +71 -1
  331. package/src/workflow/agent-progress-card.css +167 -0
  332. package/src/workflow/agent-progress-view.js +47 -0
  333. package/src/workflow/agent-turn-steps.css +113 -0
  334. package/src/workflow/agent-turn.js +191 -0
  335. package/src/workflow/login-client.js +34 -0
  336. package/src/workflow/motion-input.js +18 -31
  337. package/src/workflow/node-schema.js +1 -1
  338. package/src/workflow/reply-markdown.js +69 -0
  339. package/src/workflow/scene-asset-sync.js +8 -8
  340. package/tools/agent-session-stats.mjs +61 -0
  341. package/tools/dev-full.mjs +5 -56
  342. package/tools/eslint-baseline.json +12 -13
  343. package/tools/headless-studio.mjs +85 -0
  344. package/tools/knip-baseline.json +0 -179
  345. package/tools/loc-baseline.json +33 -83
  346. package/tools/motion3/extract-body.mjs +103 -0
  347. package/tools/motion3/extract-rig.mjs +85 -0
  348. package/tools/process-supervisor.mjs +0 -88
  349. package/tools/run-tests.mjs +9 -124
  350. package/bin/agent/motion-runtime.mjs +0 -76
  351. package/dist/ardy/cskel27-rest.json +0 -557
  352. package/dist/assets/analytics-B41FmPYI.js +0 -1
  353. package/dist/assets/app-Do-Og5Pu.css +0 -1
  354. package/dist/assets/app-DwP-tl2x.js +0 -4920
  355. package/dist/assets/config-Bx7pYsD9.js +0 -1
  356. package/dist/assets/config-DeoFTYzb.css +0 -1
  357. package/dist/assets/demo-Dt0qZfS7.js +0 -1
  358. package/dist/assets/scene-asset-sync-BCWDJB1d.js +0 -19
  359. package/dist/assets/scene-asset-sync-DjJ_cJ2R.css +0 -1
  360. package/dist/assets/ticket-jqMhqL88.js +0 -1
  361. package/dist/assets/workflow-Br-K7Srs.js +0 -179
  362. package/dist/demo/walk-then-stop.npz +0 -0
  363. package/mcp/ardy-prompts.mjs +0 -218
  364. package/src/ardy/auto-fix-panel.css +0 -108
  365. package/src/ardy/auto-physics.js +0 -1194
  366. package/src/ardy/client.js +0 -153
  367. package/src/ardy/convert.js +0 -313
  368. package/src/ardy/cskel27-neutral.js +0 -39
  369. package/src/ardy/cskel27.js +0 -77
  370. package/src/ardy/export.js +0 -165
  371. package/src/ardy/fix-collisions.js +0 -2257
  372. package/src/ardy/foot-lock.js +0 -230
  373. package/src/ardy/motion-calibration.js +0 -118
  374. package/src/ardy/motion-edit.js +0 -213
  375. package/src/ardy/motion-url.js +0 -55
  376. package/src/ardy/mp4-duration.js +0 -102
  377. package/src/ardy/npz.js +0 -595
  378. package/src/ardy/physics-panel.css +0 -21
  379. package/src/ardy/physics-panel.jsx +0 -89
  380. package/src/ardy/physics-refine.js +0 -111
  381. package/src/ardy/physics-review.js +0 -567
  382. package/src/ardy/physics-temporal.js +0 -54
  383. package/src/ardy/platform-fit-panel.css +0 -64
  384. package/src/ardy/platform-fit-panel.jsx +0 -41
  385. package/src/ardy/platform-fit.js +0 -326
  386. package/src/ardy/playback.js +0 -711
  387. package/src/ardy/pose-pin.js +0 -97
  388. package/src/ardy/prompt-clips.js +0 -30
  389. package/src/ardy/retime.js +0 -211
  390. package/src/ardy/root-drop.js +0 -369
  391. package/src/ardy/timeline-resize.js +0 -13
  392. package/src/ardy/to-cskel27.js +0 -225
  393. package/src/ardy/trim.js +0 -33
  394. package/src/ardy/waypoints.js +0 -369
  395. package/src/ardy-bridge-contract.js +0 -281
  396. package/src/domains/motion/motion-video-capture.js +0 -664
  397. package/src/i2v-motion-client.js +0 -77
  398. package/src/i2v-motion-studio.jsx +0 -180
  399. package/src/line-edit.js +0 -1348
  400. package/src/motion/generation.js +0 -105
  401. package/src/motion-readiness-ui.jsx +0 -67
  402. package/src/motion-readiness.js +0 -40
  403. package/src/motion-resources.js +0 -177
  404. package/src/motion-store.js +0 -65
  405. package/src/motion-trail.js +0 -601
  406. package/src/multimodel-ingest.js +0 -394
  407. package/src/panels/PromptBlocksPanel.jsx +0 -444
  408. package/src/panels/VideoCapturePanel.jsx +0 -181
  409. package/src/pose-extract/browser.js +0 -42
  410. package/src/pose-extract/detector.js +0 -100
  411. package/src/pose-extract/fit.js +0 -227
  412. package/src/pose-extract/image-frame.js +0 -51
  413. package/src/pose-extract/index.js +0 -58
  414. package/src/pose-extract/keyframes.js +0 -74
  415. package/src/pose-extract/landmarks.js +0 -162
  416. package/src/pose-extract/mirror.js +0 -153
  417. package/src/pose-extract/take.js +0 -131
  418. package/src/pose-extract/video-frames.js +0 -91
  419. package/src/take-recipe.js +0 -165
  420. package/src/trail-key-conflicts.js +0 -39
  421. package/src/trail-pick.js +0 -59
  422. package/src/use-i2v-capture-modal.js +0 -15
  423. package/tools/ardy/BRIDGE.md +0 -37
  424. package/tools/ardy/GVHMR-NPZ.md +0 -68
  425. package/tools/ardy/README.md +0 -124
  426. package/tools/ardy/__pycache__/cclay_gvhmr_worker.cpython-313.pyc +0 -0
  427. package/tools/ardy/artifacts.mjs +0 -34
  428. package/tools/ardy/bridge.mjs +0 -1732
  429. package/tools/ardy/bvh-cskel27.mjs +0 -1265
  430. package/tools/ardy/cclay_constrained_generate.py +0 -561
  431. package/tools/ardy/cclay_gvhmr_worker.py +0 -264
  432. package/tools/ardy/cclay_motion_edit.py +0 -510
  433. package/tools/ardy/cclay_sequence_generate.py +0 -705
  434. package/tools/ardy/cclay_worker.py +0 -304
  435. package/tools/ardy/dump-npz.py +0 -205
  436. package/tools/ardy/extract-rest.mjs +0 -299
  437. package/tools/ardy/extract.mjs +0 -507
  438. package/tools/ardy/footage.mjs +0 -467
  439. package/tools/ardy/gvhmr-floor.mjs +0 -102
  440. package/tools/ardy/gvhmr-to-cskel27.mjs +0 -21
  441. package/tools/ardy/gvhmr_fastpath.py +0 -168
  442. package/tools/ardy/gvhmr_trajectory.py +0 -240
  443. package/tools/ardy/merge-text-encoder.py +0 -160
  444. package/tools/ardy/mocap-metrics.mjs +0 -200
  445. package/tools/ardy/mocap-quality-gate.mjs +0 -110
  446. package/tools/ardy/motion-stabilize.mjs +0 -348
  447. package/tools/ardy/npz.mjs +0 -414
  448. package/tools/ardy/pose-to-npz.mjs +0 -106
  449. package/tools/ardy/prompt-limits.mjs +0 -5
  450. package/tools/ardy/run-edit-on-box.sh +0 -73
  451. package/tools/ardy/run-local.mjs +0 -233
  452. package/tools/ardy/run-on-box.sh +0 -593
  453. package/tools/ardy/run-sequence-on-box.sh +0 -177
  454. package/tools/ardy/runners/gvhmr-worker.mjs +0 -206
  455. package/tools/ardy/runners/index.mjs +0 -18
  456. package/tools/ardy/runners/local.mjs +0 -455
  457. package/tools/ardy/runners/proc.mjs +0 -125
  458. package/tools/ardy/runners/remote.mjs +0 -252
  459. package/tools/ardy/setup-local.mjs +0 -189
  460. package/tools/ardy/setup-text-encoder-on-box.sh +0 -93
  461. package/tools/ardy/setup-text-encoder.py +0 -306
  462. package/tools/ardy/smpl-cskel27.mjs +0 -178
  463. package/tools/ardy/visual-qa.mjs +0 -196
  464. package/tools/ardy/vq-car.mjs +0 -52
  465. package/tools/bench/EXP3.md +0 -61
  466. package/tools/bench/cclay_bench_extract_incam.py +0 -125
  467. package/tools/bench/cclay_bench_extract_obs.py +0 -204
  468. package/tools/bench/cclay_bench_runner.py +0 -42
  469. package/tools/bench/cube-contact.mjs +0 -162
  470. package/tools/bench/exp3.mjs +0 -152
  471. package/tools/bench/extract-bench-lib.mjs +0 -216
  472. package/tools/bench/extract-bench.mjs +0 -302
  473. package/tools/bench/fal-generate.mjs +0 -88
  474. package/tools/bench/fit/README.md +0 -189
  475. package/tools/bench/fit/camera.mjs +0 -59
  476. package/tools/bench/fit/contact.mjs +0 -419
  477. package/tools/bench/fit/footlock.mjs +0 -234
  478. package/tools/bench/fit/motion.mjs +0 -85
  479. package/tools/bench/fit/pin.mjs +0 -27
  480. package/tools/bench/fit/remote.mjs +0 -105
  481. package/tools/bench/fit-bench.mjs +0 -126
  482. package/tools/bench/fit-sanity.mjs +0 -45
  483. package/tools/bench/metrics.mjs +0 -313
  484. package/tools/bench/obs/depth.mjs +0 -258
  485. package/tools/bench/obs/extrinsics.mjs +0 -175
  486. package/tools/bench/obs/fit_mannequin_betas.py +0 -340
  487. package/tools/bench/obs/ground.mjs +0 -294
  488. package/tools/bench/obs/heading.mjs +0 -151
  489. package/tools/bench/obs/ladder.mjs +0 -555
  490. package/tools/bench/obs/mannequin-betas.json +0 -124
  491. package/tools/bench/obs/remote.mjs +0 -83
  492. package/tools/bench/obs/rest_joints.py +0 -52
  493. package/tools/bench/obs/ybot-targets.mjs +0 -49
  494. package/tools/bench/obs-bench.mjs +0 -520
  495. package/tools/bench/score.mjs +0 -343
  496. package/tools/bench/summarize.mjs +0 -86
  497. package/tools/demo-worker/README.md +0 -137
  498. package/tools/demo-worker/api-client.mjs +0 -233
  499. package/tools/demo-worker/generate.mjs +0 -301
  500. package/tools/demo-worker/index.mjs +0 -466
  501. package/tools/demo-worker/sign-core.mjs +0 -112
  502. package/tools/demo-worker/sign.mjs +0 -161
  503. package/tools/gt-render/browser.mjs +0 -159
  504. package/tools/gt-render/camera-math.mjs +0 -276
  505. package/tools/gt-render/page.mjs +0 -267
  506. package/tools/gt-render/render.mjs +0 -514
  507. package/tools/gt-render/scene-box.mjs +0 -31
  508. package/tools/gt-render/take-transform.mjs +0 -87
  509. package/tools/kimodo/compare-seam.mjs +0 -108
  510. package/tools/kimodo/constraints.mjs +0 -244
  511. package/tools/kimodo/edit.mjs +0 -259
  512. package/tools/kimodo/effector-constraints.mjs +0 -200
  513. package/tools/kimodo/generate.mjs +0 -646
  514. package/tools/kimodo/local-output.mjs +0 -265
  515. package/tools/kimodo/measure-pose.mjs +0 -65
  516. package/tools/kimodo/measure-preserve.mjs +0 -899
  517. package/tools/kimodo/measure-waypoints.mjs +0 -55
  518. package/tools/kimodo/mlx-generate.py +0 -111
  519. package/tools/kimodo/pose-constraints.mjs +0 -248
  520. package/tools/kimodo/preserve-mask.mjs +0 -543
  521. package/tools/kimodo/read-npz.mjs +0 -189
  522. package/tools/kimodo/run-edit-on-box.mjs +0 -155
  523. package/tools/kimodo/run-sequence-on-box.mjs +0 -178
  524. package/tools/kimodo/runner.mjs +0 -284
  525. package/tools/kimodo/seam-batch.mjs +0 -77
  526. package/tools/kimodo/setup-local.mjs +0 -30
  527. package/tools/kimodo/setup-on-box.sh +0 -339
  528. package/tools/kimodo/soma77-to-cskel27.mjs +0 -305
  529. package/tools/morphgs/assets/gen_truth.py +0 -39
  530. package/tools/morphgs/assets/mesh_ori_rig.txt +0 -27
  531. package/tools/morphgs/assets/playback-check.mjs +0 -30
  532. package/tools/morphgs/demo-gate.sh +0 -26
  533. package/tools/morphgs/fbx2morphgs.mjs +0 -68
  534. package/tools/morphgs/morphgs-to-cskel27.mjs +0 -105
  535. package/tools/morphgs/patches/preprocess_src-none-mode.patch +0 -76
  536. package/tools/morphgs/setup-on-cluster.sh +0 -126
  537. package/tools/projflow/driver.py +0 -1069
  538. package/tools/projflow/generate.mjs +0 -805
  539. package/tools/projflow/hml22-to-cskel27.mjs +0 -735
  540. package/tools/projflow/line-edit-job.mjs +0 -547
  541. package/tools/projflow/replay.mjs +0 -452
  542. package/tools/projflow/runner.mjs +0 -269
  543. package/tools/projflow/service.mjs +0 -742
  544. package/tools/track/DESIGN.md +0 -513
  545. package/tools/track/backfill-provenance.mjs +0 -116
  546. package/tools/track/budget.mjs +0 -8
  547. package/tools/track/check-rig.mjs +0 -209
  548. package/tools/track/diagnostics.schema.json +0 -60
  549. package/tools/track/export-rig.mjs +0 -256
  550. package/tools/track/fallback.mjs +0 -7
  551. package/tools/track/fk-parity-fixture.mjs +0 -161
  552. package/tools/track/gate.mjs +0 -349
  553. package/tools/track/masks.mjs +0 -318
  554. package/tools/track/metrics.mjs +0 -201
  555. package/tools/track/publish-obs.mjs +0 -108
  556. package/tools/track/py/check_env.py +0 -61
  557. package/tools/track/py/eval_lr.py +0 -229
  558. package/tools/track/py/lr_viterbi.py +0 -294
  559. package/tools/track/py/masks.py +0 -405
  560. package/tools/track/py/objective.py +0 -382
  561. package/tools/track/py/rig.py +0 -508
  562. package/tools/track/py/scene.py +0 -326
  563. package/tools/track/py/test_joint_indices.py +0 -123
  564. package/tools/track/py/test_lr_viterbi.py +0 -195
  565. package/tools/track/py/test_masks.py +0 -229
  566. package/tools/track/py/test_rig.py +0 -288
  567. package/tools/track/py/test_scene.py +0 -354
  568. package/tools/track/py/test_track.py +0 -328
  569. package/tools/track/py/track.py +0 -411
  570. package/tools/track/remote.mjs +0 -140
  571. package/tools/track/rig-dump.mjs +0 -227
  572. package/tools/track/run-box-tests.mjs +0 -14
  573. package/tools/track/run-box.mjs +0 -168
  574. package/tools/track/setup-box.sh +0 -59
  575. package/tools/track/study-2d.mjs +0 -728
  576. /package/src/{ardy → motion}/collision-blockers.js +0 -0
  577. /package/src/{ardy → motion}/ground.js +0 -0
  578. /package/src/{ardy → motion}/ik-drag.js +0 -0
  579. /package/src/{ardy → motion}/ik-key-json.js +0 -0
  580. /package/src/{ardy → motion}/ik.js +0 -0
  581. /package/src/{ardy → motion}/physics-surface.js +0 -0
  582. /package/src/{ardy → motion}/playback-clock.js +0 -0
  583. /package/src/{ardy → motion}/range-pin.js +0 -0
@@ -0,0 +1,232 @@
1
+ /**
2
+ * GPU side of the effects: one instanced quad mesh for every particle in the
3
+ * scene and one for every trail-ribbon quad, written from evaluateEffects.
4
+ *
5
+ * Quads face whichever camera draws them (the editor, the shot camera, a
6
+ * contact-sheet view), so the CPU only redoes work when the frame changes.
7
+ * Blending is premultiplied: a particle writes (rgb x a, a) to blend normally
8
+ * or (rgb x a, cover x a) to mostly add, so smoke and fire share one draw. Smoke-like
9
+ * particles are lit by the stage's lights (wrapped, from the camera side);
10
+ * additive ones are emissive. Both take the stage fog, write no depth and
11
+ * cast no shadow. Their instance matrices are all zero, so a pass that
12
+ * swaps in its own material (depth, normal) collapses them to nothing.
13
+ */
14
+ import * as THREE from "three";
15
+ import { EFFECT_PARTICLE_CAP, EFFECT_SEGMENT_CAP, evaluateEffects } from "./simulate.js";
16
+
17
+ /** How much of what is behind an emissive (fire, sparks) particle it hides:
18
+ * 0 would be purely additive, which vanishes over a light stage; at 0.85 a
19
+ * flame stays orange on the daylight grey and still glows on a night sky. */
20
+ const EMISSIVE_COVER = 0.85;
21
+ const SHADE = /* glsl */ `
22
+ vec3 effectLight(vec3 base, vec3 viewPos) {
23
+ vec3 n = vec3(0.0, 0.0, 1.0);
24
+ vec3 irradiance = getAmbientLightIrradiance(ambientLightColor);
25
+ #if NUM_HEMI_LIGHTS > 0
26
+ for (int i = 0; i < NUM_HEMI_LIGHTS; i++) irradiance += getHemisphereLightIrradiance(hemisphereLights[i], n);
27
+ #endif
28
+ #if NUM_DIR_LIGHTS > 0
29
+ for (int i = 0; i < NUM_DIR_LIGHTS; i++) irradiance += directionalLights[i].color * (0.55 + 0.45 * dot(n, directionalLights[i].direction));
30
+ #endif
31
+ #if NUM_POINT_LIGHTS > 0
32
+ for (int i = 0; i < NUM_POINT_LIGHTS; i++) {
33
+ vec3 toLight = pointLights[i].position - viewPos; float d = length(toLight);
34
+ irradiance += pointLights[i].color * getDistanceAttenuation(d, pointLights[i].distance, pointLights[i].decay) * (0.55 + 0.45 * dot(n, toLight / max(d, 1e-4)));
35
+ }
36
+ #endif
37
+ #if NUM_SPOT_LIGHTS > 0
38
+ for (int i = 0; i < NUM_SPOT_LIGHTS; i++) {
39
+ vec3 toLight = spotLights[i].position - viewPos; float d = length(toLight); vec3 l = toLight / max(d, 1e-4);
40
+ float cone = getSpotAttenuation(spotLights[i].coneCos, spotLights[i].penumbraCos, dot(l, spotLights[i].direction));
41
+ irradiance += spotLights[i].color * cone * getDistanceAttenuation(d, spotLights[i].distance, spotLights[i].decay) * (0.55 + 0.45 * dot(n, l));
42
+ }
43
+ #endif
44
+ return base * irradiance * RECIPROCAL_PI;
45
+ }
46
+ // Tone map and encode like every stage material, then fog (additive light
47
+ // fades into it instead), then premultiply.
48
+ vec4 effectOut(vec3 color, float alpha, float additive) {
49
+ gl_FragColor = vec4(color, 1.0);
50
+ #include <tonemapping_fragment>
51
+ #include <colorspace_fragment>
52
+ #ifdef USE_FOG
53
+ #ifdef FOG_EXP2
54
+ float fogF = 1.0 - exp(-fogDensity * fogDensity * vFogDepth * vFogDepth);
55
+ #else
56
+ float fogF = smoothstep(fogNear, fogFar, vFogDepth);
57
+ #endif
58
+ gl_FragColor.rgb = additive > 0.5 ? gl_FragColor.rgb * (1.0 - fogF) : mix(gl_FragColor.rgb, fogColor, fogF);
59
+ #endif
60
+ return vec4(gl_FragColor.rgb * alpha, additive > 0.5 ? alpha * ${EMISSIVE_COVER.toFixed(2)} : alpha);
61
+ }
62
+ `;
63
+ const FRAGMENT_HEAD = /* glsl */ `
64
+ #include <common>
65
+ #include <lights_pars_begin>
66
+ #include <fog_pars_fragment>
67
+ uniform float globalOpacity;
68
+ ${SHADE}`;
69
+
70
+ const PARTICLE_VERTEX = /* glsl */ `
71
+ attribute vec3 iPos; attribute vec4 iParams; attribute vec4 iColor; attribute vec4 iStreak;
72
+ varying vec2 vUv; varying vec4 vColor; varying float vLit; varying float vAdd; varying vec3 vViewPos;
73
+ #include <fog_pars_vertex>
74
+ void main() {
75
+ vec4 center = viewMatrix * vec4(iPos, 1.0);
76
+ vec3 streak = (viewMatrix * vec4(iStreak.xyz, 0.0)).xyz;
77
+ float size = iParams.x, len = length(streak.xy);
78
+ vec2 offset;
79
+ if (len > size * 0.25) {
80
+ vec2 along = streak.xy / len;
81
+ offset = along * position.y * (size + len) + vec2(-along.y, along.x) * position.x * size;
82
+ } else {
83
+ float c = cos(iParams.y), s = sin(iParams.y);
84
+ offset = size * vec2(c * position.x - s * position.y, s * position.x + c * position.y);
85
+ }
86
+ vec4 mvPosition = center + vec4(offset, 0.0, 0.0);
87
+ gl_Position = projectionMatrix * mvPosition;
88
+ vUv = (uv + vec2(mod(iParams.z, 2.0), floor(iParams.z / 2.0))) * 0.5;
89
+ vColor = iColor; vLit = iParams.w; vAdd = iStreak.w; vViewPos = mvPosition.xyz;
90
+ #include <fog_vertex>
91
+ }`;
92
+ const PARTICLE_FRAGMENT = /* glsl */ `
93
+ uniform sampler2D map;
94
+ varying vec2 vUv; varying vec4 vColor; varying float vLit; varying float vAdd; varying vec3 vViewPos;
95
+ ${FRAGMENT_HEAD}
96
+ void main() {
97
+ float alpha = vColor.a * texture2D(map, vUv).r * globalOpacity;
98
+ if (alpha < 0.002) discard;
99
+ gl_FragColor = effectOut(vLit > 0.5 ? effectLight(vColor.rgb, vViewPos) : vColor.rgb, alpha, vAdd);
100
+ }`;
101
+
102
+ const RIBBON_VERTEX = /* glsl */ `
103
+ attribute vec3 rA0; attribute vec3 rB0; attribute vec3 rA1; attribute vec3 rB1; attribute vec2 rAlpha; attribute vec4 rColor;
104
+ varying float vAlpha; varying float vAcross; varying vec3 vColor; varying float vAdd; varying vec3 vViewPos;
105
+ #include <fog_pars_vertex>
106
+ void main() {
107
+ float along = position.x + 0.5, across = position.y + 0.5;
108
+ vec3 world = mix(mix(rA0, rB0, across), mix(rA1, rB1, across), along);
109
+ vec4 mvPosition = viewMatrix * vec4(world, 1.0);
110
+ gl_Position = projectionMatrix * mvPosition;
111
+ vAlpha = mix(rAlpha.x, rAlpha.y, along); vAcross = across; vColor = rColor.rgb; vAdd = rColor.a; vViewPos = mvPosition.xyz;
112
+ #include <fog_vertex>
113
+ }`;
114
+ const RIBBON_FRAGMENT = /* glsl */ `
115
+ varying float vAlpha; varying float vAcross; varying vec3 vColor; varying float vAdd; varying vec3 vViewPos;
116
+ ${FRAGMENT_HEAD}
117
+ void main() {
118
+ float alpha = vAlpha * pow(sin(PI * vAcross), 0.6) * globalOpacity;
119
+ if (alpha < 0.002) discard;
120
+ gl_FragColor = effectOut(vAdd > 0.5 ? vColor : effectLight(vColor, vViewPos), alpha, vAdd);
121
+ }`;
122
+
123
+ /** A 2x2 atlas of soft puffs: cell 0 a clean round falloff, cells 1-3 seeded wisps. */
124
+ function puffAtlas() {
125
+ const size = 128, cell = 64, data = new Uint8Array(size * size * 4);
126
+ const hash = (x, y, v) => { const h = Math.sin(x * 127.1 + y * 311.7 + v * 74.7) * 43758.5453; return h - Math.floor(h); };
127
+ const noise = (x, y, v) => {
128
+ const ix = Math.floor(x), iy = Math.floor(y), fx = x - ix, fy = y - iy, sx = fx * fx * (3 - 2 * fx), sy = fy * fy * (3 - 2 * fy);
129
+ const top = hash(ix, iy, v) + (hash(ix + 1, iy, v) - hash(ix, iy, v)) * sx, bottom = hash(ix, iy + 1, v) + (hash(ix + 1, iy + 1, v) - hash(ix, iy + 1, v)) * sx;
130
+ return top + (bottom - top) * sy;
131
+ };
132
+ for (let v = 0; v < 4; v += 1) {
133
+ for (let y = 0; y < cell; y += 1) {
134
+ for (let x = 0; x < cell; x += 1) {
135
+ const nx = (x + 0.5) / cell * 2 - 1, ny = (y + 0.5) / cell * 2 - 1, r = Math.hypot(nx, ny);
136
+ let a = Math.exp(-r * r * 4.2) * (1 - Math.min(1, Math.max(0, (r - 0.82) / 0.18)));
137
+ if (v > 0) {
138
+ const fbm = 0.55 * noise(nx * 3 + 5, ny * 3, v) + 0.3 * noise(nx * 6, ny * 6 + 3, v) + 0.15 * noise(nx * 12 + 1, ny * 12, v);
139
+ a *= Math.min(1, Math.max(0, 1.6 * fbm - 0.25));
140
+ }
141
+ const i = (((v >> 1) * cell + y) * size + (v & 1) * cell + x) * 4;
142
+ data[i] = data[i + 1] = data[i + 2] = data[i + 3] = Math.round(255 * Math.min(1, a));
143
+ }
144
+ }
145
+ }
146
+ const texture = new THREE.DataTexture(data, size, size, THREE.RGBAFormat);
147
+ texture.minFilter = THREE.LinearMipmapLinearFilter;
148
+ texture.magFilter = THREE.LinearFilter;
149
+ texture.generateMipmaps = true;
150
+ texture.needsUpdate = true;
151
+ return texture;
152
+ }
153
+
154
+ function effectMaterial(vertexShader, fragmentShader, extra = {}) {
155
+ return new THREE.ShaderMaterial({
156
+ uniforms: { ...THREE.UniformsUtils.merge([THREE.UniformsLib.lights, THREE.UniformsLib.fog]), globalOpacity: { value: 1 }, ...extra },
157
+ vertexShader, fragmentShader, lights: true, fog: true, transparent: true, depthWrite: false, side: THREE.DoubleSide,
158
+ blending: THREE.CustomBlending, blendEquation: THREE.AddEquation, blendSrc: THREE.OneFactor, blendDst: THREE.OneMinusSrcAlphaFactor,
159
+ blendSrcAlpha: THREE.OneFactor, blendDstAlpha: THREE.OneMinusSrcAlphaFactor,
160
+ });
161
+ }
162
+
163
+ function instancedQuads(material, capacity, layout) {
164
+ const geometry = new THREE.PlaneGeometry(1, 1);
165
+ const attributes = {};
166
+ for (const [name, width] of Object.entries(layout)) {
167
+ attributes[name] = new THREE.InstancedBufferAttribute(new Float32Array(capacity * width), width).setUsage(THREE.DynamicDrawUsage);
168
+ geometry.setAttribute(name, attributes[name]);
169
+ }
170
+ const mesh = new THREE.InstancedMesh(geometry, material, capacity);
171
+ mesh.instanceMatrix.array.fill(0);
172
+ mesh.count = 0;
173
+ mesh.frustumCulled = false;
174
+ mesh.renderOrder = 5;
175
+ mesh.raycast = () => {};
176
+ // The editor's ink prepass outlines geometry; a puff of smoke is none.
177
+ mesh.userData.noInk = true;
178
+ return { mesh, attributes };
179
+ }
180
+
181
+ const flush = (attributes, count) => {
182
+ for (const attribute of Object.values(attributes)) {
183
+ attribute.clearUpdateRanges();
184
+ attribute.addUpdateRange(0, count * attribute.itemSize);
185
+ attribute.needsUpdate = true;
186
+ }
187
+ };
188
+
189
+ /** The two meshes and `update(scene, frame, opacity)`, which redraws every effect at `frame`. */
190
+ export function createEffectMeshes() {
191
+ const map = puffAtlas();
192
+ const particles = instancedQuads(effectMaterial(PARTICLE_VERTEX, PARTICLE_FRAGMENT, { map: { value: map } }), EFFECT_PARTICLE_CAP, { iPos: 3, iParams: 4, iColor: 4, iStreak: 4 });
193
+ const ribbons = instancedQuads(effectMaterial(RIBBON_VERTEX, RIBBON_FRAGMENT), EFFECT_SEGMENT_CAP, { rA0: 3, rB0: 3, rA1: 3, rB1: 3, rAlpha: 2, rColor: 4 });
194
+ const p = particles.attributes, r = ribbons.attributes;
195
+ return {
196
+ particles: particles.mesh,
197
+ ribbons: ribbons.mesh,
198
+ update(scene, frame, opacity = 1) {
199
+ let n = 0, m = 0;
200
+ evaluateEffects(scene.records, scene, frame, {
201
+ particle(q) {
202
+ if (n >= EFFECT_PARTICLE_CAP) return;
203
+ p.iPos.array.set([q.x, q.y, q.z], n * 3);
204
+ p.iParams.array.set([q.size, q.angle, q.variant, q.additive ? 0 : 1], n * 4);
205
+ p.iColor.array.set([q.r, q.g, q.b, q.alpha], n * 4);
206
+ p.iStreak.array.set([q.sx, q.sy, q.sz, q.additive ? 1 : 0], n * 4);
207
+ n += 1;
208
+ },
209
+ segment(sg, em) {
210
+ if (m >= EFFECT_SEGMENT_CAP) return;
211
+ r.rA0.array.set(sg.a0, m * 3); r.rB0.array.set(sg.b0, m * 3); r.rA1.array.set(sg.a1, m * 3); r.rB1.array.set(sg.b1, m * 3);
212
+ r.rAlpha.array.set([sg.alpha0, sg.alpha1], m * 2);
213
+ r.rColor.array.set([...em.rgb, em.effect.additive ? 1 : 0], m * 4);
214
+ m += 1;
215
+ },
216
+ });
217
+ particles.mesh.count = n;
218
+ ribbons.mesh.count = m;
219
+ flush(p, n);
220
+ flush(r, m);
221
+ for (const mesh of [particles.mesh, ribbons.mesh]) mesh.material.uniforms.globalOpacity.value = opacity;
222
+ },
223
+ dispose() {
224
+ map.dispose();
225
+ for (const mesh of [particles.mesh, ribbons.mesh]) {
226
+ mesh.geometry.dispose();
227
+ mesh.material.dispose();
228
+ mesh.dispose?.();
229
+ }
230
+ },
231
+ };
232
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The `object.effect` record: an emitter of smoke, fire, rain or a motion
3
+ * trail. Pure data and clamps, shared by the object store, the agent schema
4
+ * and the simulation (src/effects/simulate.js).
5
+ *
6
+ * A preset fills every field, and explicit fields override it. The record
7
+ * stores the MERGED numbers, so a readback shows exactly what is drawn.
8
+ * Units: metres, seconds, m/s, m/s² (+ gravity falls).
9
+ */
10
+ import { normalizeObjectColor } from "../object-colors.js";
11
+
12
+ export const EFFECT_KIND = "effect";
13
+
14
+ /** Zero size on purpose, like an Empty: an effect is never a blocker, a
15
+ * support or a collision box; only its particles are seen. */
16
+ export const EFFECT_ENTRY = { kind: EFFECT_KIND, label: "Effect", group: "Effects", footprint: { width: 0, depth: 0 }, height: 0, color: "#7fd4f0" };
17
+
18
+ const vec = (x, y, z) => ({ x, y, z });
19
+ const ZERO = vec(0, 0, 0);
20
+
21
+ /**
22
+ * Each preset at its natural scale. Smoke is a cigarette's: a 12 mm wisp that
23
+ * rises ~0.45 m over ~2.8 s while it widens 7x. Fire is a small campfire
24
+ * (~0.4 m of flame); scale size/area/life down for a lighter.
25
+ */
26
+ export const EFFECT_PRESETS = Object.freeze({
27
+ smoke: { rate: 60, life: 2.8, size: 0.012, grow: 6, speed: 0.05, spread: 0.1, gravity: -0.3, wind: vec(0.02, 0, 0), color: "#7d8a99", opacity: 0.42, additive: false, area: ZERO, width: 0 },
28
+ exhale: { rate: 120, life: 2.4, size: 0.035, grow: 8, speed: 0.9, spread: 0.35, gravity: -0.35, wind: vec(0.02, 0, 0), color: "#a3abb4", opacity: 0.3, additive: false, area: vec(0.01, 0, 0.01), width: 0 },
29
+ steam: { rate: 26, life: 2, size: 0.03, grow: 4, speed: 0.1, spread: 0.2, gravity: -0.45, wind: vec(0.02, 0, 0), color: "#bcc5ce", opacity: 0.2, additive: false, area: vec(0.07, 0, 0.07), width: 0 },
30
+ fire: { rate: 140, life: 0.75, size: 0.12, grow: 0.3, speed: 0.4, spread: 0.15, gravity: -2.2, wind: ZERO, color: "#ff7a1f", opacity: 1, additive: true, area: vec(0.22, 0, 0.22), width: 0 },
31
+ sparks: { rate: 40, life: 1, size: 0.012, grow: 0.6, speed: 2.6, spread: 0.55, gravity: 6, wind: ZERO, color: "#ff9d33", opacity: 1, additive: true, area: vec(0.05, 0, 0.05), width: 0 },
32
+ dust: { rate: 30, life: 7, size: 0.014, grow: 1.2, speed: 0, spread: 1, gravity: 0.01, wind: vec(0.04, 0, 0.01), color: "#a89a82", opacity: 0.55, additive: false, area: vec(3, 2.2, 3), width: 0 },
33
+ rain: { rate: 1600, life: 1.2, size: 0.01, grow: 1, speed: 0, spread: 0, gravity: 9.8, wind: ZERO, color: "#9aabbd", opacity: 0.4, additive: false, area: vec(8, 5, 8), width: 0 },
34
+ snow: { rate: 220, life: 8, size: 0.025, grow: 1, speed: 0, spread: 0, gravity: 9.8, wind: vec(0.1, 0, 0), color: "#ffffff", opacity: 0.85, additive: false, area: vec(8, 4, 8), width: 0 },
35
+ trail: { rate: 0, life: 0.3, size: 0, grow: 1, speed: 0, spread: 0, gravity: 0, wind: ZERO, color: "#a7b8ca", opacity: 0.75, additive: false, area: ZERO, width: 0.5 },
36
+ });
37
+ const EFFECT_PRESET_NAMES = Object.freeze(Object.keys(EFFECT_PRESETS));
38
+
39
+ const LIMITS = { rate: [0, 2000], life: [0.05, 12], size: [0.001, 5], grow: [0.05, 20], speed: [0, 60], spread: [0, 1], gravity: [-30, 30], opacity: [0, 1], width: [0, 10] };
40
+ const VEC_LIMITS = { wind: [-20, 20], area: [0, 100] };
41
+ const SEED_MAX = 2147483647;
42
+
43
+ const clampTo = ([min, max], value, fallback) => {
44
+ const n = Number(value);
45
+ return Number.isFinite(n) ? Math.min(max, Math.max(min, n)) : fallback;
46
+ };
47
+
48
+ /** The stored effect: `value`'s preset filled in, its explicit fields clamped over it. */
49
+ export function normalizeEffect(value) {
50
+ const given = value && typeof value === "object" && !Array.isArray(value) ? value : {};
51
+ const preset = EFFECT_PRESET_NAMES.includes(given.preset) ? given.preset : "smoke";
52
+ const base = EFFECT_PRESETS[preset];
53
+ const out = { preset };
54
+ for (const [key, range] of Object.entries(LIMITS)) out[key] = clampTo(range, given[key], base[key]);
55
+ for (const [key, range] of Object.entries(VEC_LIMITS)) {
56
+ const v = given[key] && typeof given[key] === "object" ? given[key] : {};
57
+ out[key] = vec(...["x", "y", "z"].map((axis) => clampTo(range, v[axis], base[key][axis])));
58
+ }
59
+ out.color = normalizeObjectColor(given.color) ?? base.color;
60
+ out.additive = typeof given.additive === "boolean" ? given.additive : base.additive;
61
+ const seed = Number(given.seed);
62
+ out.seed = Number.isFinite(seed) ? Math.min(SEED_MAX, Math.max(0, Math.round(seed))) : 1;
63
+ return out;
64
+ }
65
+
66
+ /** The record fields an effect carries (none for any other renderer): one
67
+ * spread in normalizeSceneObject and createSceneObject. */
68
+ export function effectFields(record) {
69
+ return record?.renderer === EFFECT_KIND ? { effect: normalizeEffect(record.effect) } : {};
70
+ }
71
+
72
+ /**
73
+ * An `object.set` op with a NEW preset gets that preset's defaults written
74
+ * out, so the set merges onto the preset rather than onto the old preset's
75
+ * numbers: { preset: "fire" } on a smoke emitter becomes fire, and
76
+ * { preset: "fire", rate: 40 } is fire at 40/s. Any other op is returned as is.
77
+ */
78
+ export function effectPresetSet(op, objects) {
79
+ const preset = op?.set?.effect?.preset;
80
+ if (!EFFECT_PRESET_NAMES.includes(preset)) return op;
81
+ const current = objects?.find?.((object) => object.id === op.id)?.effect;
82
+ if (current?.preset === preset) return op;
83
+ const defaults = structuredClone(EFFECT_PRESETS[preset]);
84
+ return { ...op, set: { ...op.set, effect: { ...defaults, seed: current?.seed ?? 1, ...op.set.effect } } };
85
+ }
86
+
87
+ const num = (minimum, maximum) => ({ type: "number", minimum, maximum });
88
+ const vecSchema = ([min, max]) => ({ type: "object", properties: { x: num(min, max), y: num(min, max), z: num(min, max) }, required: [], additionalProperties: false });
89
+
90
+ /** The wire shape of `object.effect` for object.set / patch_elements (every member optional). */
91
+ export const EFFECT_VALUE_SCHEMA = Object.freeze({
92
+ type: "object",
93
+ properties: {
94
+ preset: { type: "string", enum: [...EFFECT_PRESET_NAMES] },
95
+ ...Object.fromEntries(Object.entries(LIMITS).map(([key, [min, max]]) => [key, num(min, max)])),
96
+ ...Object.fromEntries(Object.entries(VEC_LIMITS).map(([key, range]) => [key, vecSchema(range)])),
97
+ color: { type: "string", minLength: 1, maxLength: 32, pattern: "^#[0-9a-fA-F]{6}$" },
98
+ additive: { type: "boolean" },
99
+ seed: { type: "integer", minimum: 0, maximum: SEED_MAX },
100
+ },
101
+ required: [],
102
+ additionalProperties: false,
103
+ });
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Where an effect emitter is, whether it is shown and how strongly it emits,
3
+ * at any frame: the one place the simulation reads the scene from.
4
+ *
5
+ * Everything here is a pure function of (records, take, frame), so a frame
6
+ * evaluates the same whether it is scrubbed to, played into or exported.
7
+ */
8
+ import { Euler, Matrix4, Quaternion, Vector3 } from "three";
9
+ import { sceneObjectTravelMatrixAt, trackShown } from "../object-travel.js";
10
+
11
+ const DEG = Math.PI / 180;
12
+ const scratchMatrix = new Matrix4();
13
+ const scratchPos = new Vector3();
14
+ const scratchQuat = new Quaternion();
15
+ const scratchScale = new Vector3();
16
+ const scratchEuler = new Euler();
17
+
18
+ /** False while the take hides the record or any record it is grouped under
19
+ * (a smoke emitter on a cigarette still in the pocket), and for a
20
+ * showOnlyInTake emitter no take drives (a kit's tip smoke in a static scene). */
21
+ export function emitterShown(lookup, record, frame, take) {
22
+ return trackShown(record.id, frame, take, lookup);
23
+ }
24
+
25
+ function authoredPose(record) {
26
+ scratchPos.set(record.x ?? 0, record.y ?? 0, record.z ?? 0);
27
+ scratchQuat.setFromEuler(scratchEuler.set((record.rotX ?? 0) * DEG, (record.rot ?? 0) * DEG, (record.rotZ ?? 0) * DEG, "XYZ"));
28
+ }
29
+
30
+ /**
31
+ * The emitter's world position and orientation at `frame`, scale left out:
32
+ * effect sizes are metres whatever the record's scale.
33
+ *
34
+ * Routed, hinged, take-carried and parented records come from
35
+ * sceneObjectTravelMatrixAt. A record pinned to a character bone (`attach`)
36
+ * has no pose at other frames outside the live rig, so `live(id, out)` gives
37
+ * its current world matrix for every frame (null falls back to the numbers).
38
+ *
39
+ * @returns {{ p: number[], q: number[] }}
40
+ */
41
+ export function emitterPoseAt(lookup, record, frame, take, live = null) {
42
+ const world = record.attach ? live?.(record.id, scratchMatrix) ?? null : sceneObjectTravelMatrixAt(lookup, record.id, frame, take ?? {}, scratchMatrix);
43
+ if (world) world.decompose(scratchPos, scratchQuat, scratchScale);
44
+ else authoredPose(record);
45
+ return { p: [scratchPos.x, scratchPos.y, scratchPos.z], q: [scratchQuat.x, scratchQuat.y, scratchQuat.z, scratchQuat.w] };
46
+ }
47
+
48
+ /** `v` (3 numbers) turned by unit quaternion `q`, into `out`. */
49
+ export function rotate(q, x, y, z, out) {
50
+ const [qx, qy, qz, qw] = q;
51
+ const ix = qw * x + qy * z - qz * y;
52
+ const iy = qw * y + qz * x - qx * z;
53
+ const iz = qw * z + qx * y - qy * x;
54
+ const iw = -qx * x - qy * y - qz * z;
55
+ out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
56
+ out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
57
+ out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
58
+ return out;
59
+ }
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Effect particles at a frame, computed from nothing but the frame.
3
+ *
4
+ * Particle k of an emitter belongs to integer frame s when the seeded count
5
+ * for s (rate x take level / fps, stochastically rounded) exceeds k, and only
6
+ * while the emitter is shown at s. It is born a seeded u in [0, 1) frames
7
+ * before s, where the emitter was then: its pose at s, moved back along the
8
+ * step from s - 1 by u (exactly the pose at s for u = 0). Its state at frame
9
+ * f is analytic in its age (f - s + u) / fps: drag toward wind plus
10
+ * gravity, a seeded sway/curl drift, size growth and an opacity fade. No
11
+ * state is carried between frames, so scrubbing, playback, capture and
12
+ * export all draw the same particles. A trail is a ribbon through the
13
+ * emitter's own pose over the last `life` seconds instead.
14
+ */
15
+ import { emitterPoseAt, emitterShown, rotate } from "./emitter.js";
16
+ import { trackLevel } from "../object-travel.js";
17
+ import { EFFECT_KIND, normalizeEffect } from "./effect-record.js";
18
+
19
+ /** Live particles drawn per scene; beyond it every emitter is thinned evenly. */
20
+ export const EFFECT_PARTICLE_CAP = 2000;
21
+ /** Trail ribbon quads per scene, shared evenly by the trail emitters. */
22
+ export const EFFECT_SEGMENT_CAP = 512;
23
+ const TRAIL_SUBSTEPS = 4;
24
+ /** Edge travel per frame (m) under which a trail stretch counts as still. */
25
+ const TRAIL_STILL_M = 0.002;
26
+ /** Edge speed (m/s) at which a swoosh is fully opaque; slower motion fades it. */
27
+ const TRAIL_FULL_SPEED = 2;
28
+
29
+ // The shape of each preset that is not authored: drag (1/s), sway/curl/jitter
30
+ // drift (m), fades, spread of life/size, spin (rad/s), streak (s of velocity),
31
+ // flicker, a lift of the birth point (x start size, so a flame on the deck
32
+ // starts above it), a droop of the throw (a share of the speed turned down),
33
+ // and whether births fill a volume (rain/snow/dust).
34
+ const LOOK = { drag: 1.5, sway: 0, curl: 0, curlRate: 2, jitter: 0, fadeIn: 0.05, fadeOut: 1, lifeVar: 0.2, sizeVar: 0.3, growPow: 1, spin: 0, streak: 0, flicker: 0, twinkle: 0, lift: 0, droop: 0, tint: null, clean: false, volume: false, top: false };
35
+ const LOOKS = {
36
+ smoke: { ...LOOK, drag: 1.7, sway: 0.012, curl: 0.01, curlRate: 2.2, jitter: 0.005, fadeIn: 0.04, fadeOut: 1, lifeVar: 0.25, sizeVar: 0.25, growPow: 0.8, spin: 0.6 },
37
+ // a breath leaves the lips forward and a little down (droop: a downward share of the speed), then rises and spreads
38
+ exhale: { ...LOOK, drag: 3.2, sway: 0.02, curl: 0.03, curlRate: 1.6, jitter: 0.03, fadeIn: 0.03, fadeOut: 1.5, lifeVar: 0.3, sizeVar: 0.35, growPow: 0.6, spin: 0.8, droop: 0.25 },
39
+ steam: { ...LOOK, drag: 1.8, sway: 0.03, curl: 0.025, curlRate: 2.5, jitter: 0.015, fadeIn: 0.12, fadeOut: 1.8, lifeVar: 0.3, sizeVar: 0.35, growPow: 0.8, spin: 0.5 },
40
+ fire: { ...LOOK, drag: 3, sway: 0.01, curl: 0.03, curlRate: 5, jitter: 0.03, fadeIn: 0.06, fadeOut: 2.2, lifeVar: 0.35, spin: 1.5, streak: 0.15, flicker: 0.35, lift: 0.5, tint: "fire", clean: true },
41
+ sparks: { ...LOOK, drag: 0.8, jitter: 0.05, fadeIn: 0, fadeOut: 0.7, lifeVar: 0.5, sizeVar: 0.4, streak: 0.035, flicker: 0.5, tint: "spark", clean: true },
42
+ dust: { ...LOOK, drag: 0.8, curl: 0.04, curlRate: 0.7, jitter: 0.04, fadeIn: 0.2, fadeOut: 0.25, lifeVar: 0.3, sizeVar: 0.4, twinkle: 0.4, clean: true, volume: true },
43
+ rain: { ...LOOK, drag: 1.4, fadeIn: 0.04, fadeOut: 0, lifeVar: 0, sizeVar: 0.2, streak: 0.035, clean: true, volume: true, top: true },
44
+ snow: { ...LOOK, drag: 12, curl: 0.08, curlRate: 1.3, jitter: 0.05, fadeIn: 0.04, fadeOut: 0.1, lifeVar: 0, sizeVar: 0.35, spin: 1, clean: true, volume: true, top: true },
45
+ trail: LOOK,
46
+ };
47
+
48
+ const mix32 = (h) => {
49
+ h = Math.imul(h ^ (h >>> 16), 0x7feb352d);
50
+ h = Math.imul(h ^ (h >>> 15), 0x846ca68b);
51
+ return (h ^ (h >>> 16)) >>> 0;
52
+ };
53
+ /** Uniform [0, 1) for (seed, birth frame, particle, channel); pure. */
54
+ const rnd = (seed, s, k, c) => mix32(mix32(mix32(seed + Math.imul(s, 0x27d4eb2f)) ^ Math.imul(k + 7, 0x165667b1)) + c) / 4294967296;
55
+ const hashText = (text) => {
56
+ let h = 0x811c9dc5;
57
+ for (let i = 0; i < text.length; i += 1) h = Math.imul(h ^ text.charCodeAt(i), 0x01000193);
58
+ return h >>> 0;
59
+ };
60
+ const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
61
+ const linearRgb = (hex) => [1, 3, 5].map((i) => toLinear(parseInt(hex.slice(i, i + 2), 16) / 255));
62
+ const smooth = (x) => (x >= 1 ? 1 : x <= 0 ? 0 : x * x * (3 - 2 * x));
63
+
64
+ function emitterOf(record, scene) {
65
+ const effect = record.effect?.preset ? record.effect : normalizeEffect(record.effect);
66
+ const seed = mix32(effect.seed ^ hashText(record.id));
67
+ const poses = new Map();
68
+ const hidden = scene.hidden?.has?.(record.id) === true;
69
+ const at = (s) => Math.max(0, s);
70
+ const look = LOOKS[effect.preset] ?? LOOK, fall = effect.gravity / look.drag - effect.wind.y;
71
+ return {
72
+ id: record.id, effect, seed, look, trail: effect.preset === "trail", rgb: linearRgb(effect.color),
73
+ // Rain and snow fall from the box's top at terminal speed: they are gone once they reach its floor.
74
+ fallLife: look.top && fall > 0 ? effect.area.y / fall : Infinity,
75
+ phase: [0, 1, 2, 3].map((c) => 2 * Math.PI * rnd(seed, 0, -1, 90 + c)),
76
+ pose(s) {
77
+ let pose = poses.get(at(s));
78
+ if (!pose) poses.set(at(s), (pose = emitterPoseAt(scene.lookup, record, at(s), scene.take, scene.live)));
79
+ return pose;
80
+ },
81
+ /** Emission strength at frame s: 0 hidden, else the take level (1 without a track). */
82
+ level: (s) => (hidden || !emitterShown(scene.lookup, record, at(s), scene.take) ? 0 : trackLevel(record.id, at(s), scene.take)),
83
+ };
84
+ }
85
+
86
+ /** How many times the births at s are split so a fast emitter still lays a
87
+ * continuous stream (one particle per half a start size of travel, at most 8);
88
+ * the smoke emitted is the same, each part carries a share of the opacity. */
89
+ function splitAt(em, s, perFrame) {
90
+ if (em.look.volume || !(em.effect.size > 0)) return 1;
91
+ const [a, b] = [em.pose(s).p, em.pose(s - 1).p];
92
+ const need = Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]) / (0.5 * em.effect.size);
93
+ return Math.min(8, Math.max(1, need / perFrame));
94
+ }
95
+
96
+ /** Every particle alive at `frame`, oldest birth first: visit(s, k, u, age, life, split). */
97
+ function forEachLive(em, frame, fps, visit) {
98
+ const { effect, look, seed } = em;
99
+ const last = Math.floor(frame);
100
+ for (let s = Math.floor(frame - effect.life * (1 + look.lifeVar) * fps) - 1; s <= last; s += 1) {
101
+ const perFrame = (effect.rate * em.level(s)) / fps;
102
+ if (!(perFrame > 0)) continue;
103
+ const split = splitAt(em, s, perFrame);
104
+ const count = Math.floor(perFrame * split + rnd(seed, s, -1, 0));
105
+ for (let k = 0; k < count; k += 1) {
106
+ const life = Math.min(em.fallLife, effect.life * (1 + look.lifeVar * (2 * rnd(seed, s, k, 1) - 1)));
107
+ const u = rnd(seed, s, k, 2);
108
+ const age = (frame - s + u) / fps;
109
+ if (age >= 0 && age <= life) visit(s, k, u, age, life, split);
110
+ }
111
+ }
112
+ }
113
+
114
+ const turn = [0, 0, 0];
115
+
116
+ /** Particle (s, k) at `frame` into `out`; false when it is gone (under a volume's floor). */
117
+ function particleAt(em, s, k, u, age, life, split, frame, fps, out) {
118
+ const { effect, look, seed } = em;
119
+ const r = (c) => rnd(seed, s, k, c);
120
+ const pose = em.pose(s);
121
+ const a = age / life;
122
+ let ox = (r(3) - 0.5) * effect.area.x, oy = (look.top ? effect.area.y : r(4) * effect.area.y) + look.lift * effect.size, oz = (r(5) - 0.5) * effect.area.z;
123
+ if (!look.volume) [ox, oy, oz] = rotate(pose.q, ox, oy, oz, turn);
124
+ // Born u frames before frame s (age counts from there), so on the line the
125
+ // emitter swept from s - 1 to s: a fast hand leaves a stream, not beads.
126
+ const before = em.pose(s - 1).p;
127
+ out.s = s; out.k = k; out.u = u;
128
+ out.bx = pose.p[0] + (before[0] - pose.p[0]) * u + ox; out.by = pose.p[1] + (before[1] - pose.p[1]) * u + oy; out.bz = pose.p[2] + (before[2] - pose.p[2]) * u + oz;
129
+ // A cone of half-angle spread x 90 deg about the emitter's local +Y.
130
+ const cosT = 1 - r(6) * (1 - Math.cos((effect.spread * Math.PI) / 2)), sinT = Math.sqrt(Math.max(0, 1 - cosT * cosT)), phi = 2 * Math.PI * r(7);
131
+ let [dx, dy, dz] = [sinT * Math.cos(phi), cosT, sinT * Math.sin(phi)];
132
+ if (!look.volume) [dx, dy, dz] = rotate(pose.q, dx, dy, dz, turn);
133
+ const speed = effect.speed * (0.75 + 0.5 * r(8)), drag = look.drag;
134
+ // Velocity relaxes to the terminal one: the wind plus gravity / drag.
135
+ const tx = effect.wind.x, ty = effect.wind.y - effect.gravity / drag, tz = effect.wind.z;
136
+ const v0x = dx * speed + (look.volume ? tx : 0), v0y = (dy - look.droop) * speed + (look.volume ? ty : 0), v0z = dz * speed + (look.volume ? tz : 0);
137
+ const e = Math.exp(-drag * age), f1 = (1 - e) / drag;
138
+ let x = out.bx + tx * age + (v0x - tx) * f1, y = out.by + ty * age + (v0y - ty) * f1, z = out.bz + tz * age + (v0z - tz) * f1;
139
+ // Drift: a sway frozen at birth (so the column snakes as it rises), a slow
140
+ // lean of the whole plume, a per-particle curl and a little jitter.
141
+ const tau = (s + u) / fps, time = frame / fps, rise = age * Math.sqrt(age);
142
+ x += look.sway * (rise * Math.sin(1.7 * tau + em.phase[0]) + 0.6 * age * Math.sin(0.45 * time + em.phase[2]));
143
+ z += look.sway * (rise * Math.sin(1.3 * tau + em.phase[1]) + 0.6 * age * Math.cos(0.37 * time + em.phase[3]));
144
+ const curl = look.curlRate * age + 2 * Math.PI * r(9);
145
+ x += look.curl * age * Math.cos(curl) + look.jitter * age * (2 * r(10) - 1);
146
+ y += look.jitter * 0.5 * age * (2 * r(11) - 1);
147
+ z += look.curl * age * Math.sin(curl) + look.jitter * age * (2 * r(12) - 1);
148
+ // Nothing falls through the deck, and a volume's drops end at its floor.
149
+ if (y < 0 || (look.volume && y < pose.p[1])) return false;
150
+ let size = effect.size * (1 + look.sizeVar * (2 * r(13) - 1)) * (1 + (effect.grow - 1) * a ** look.growPow);
151
+ let alpha = (effect.opacity / split) * (look.fadeIn > 0 ? smooth(a / look.fadeIn) : 1) * Math.max(0, 1 - a) ** look.fadeOut;
152
+ if (look.twinkle) alpha *= 1 - look.twinkle * (0.5 + 0.5 * Math.sin(3 * age + 2 * Math.PI * r(17)));
153
+ // Fire: a yellow core that reddens and dims as it rises; sparks cool too.
154
+ let bright = 1, g = 1, b = 1, hot = 0;
155
+ if (look.tint === "fire") [bright, g, b, hot] = [1.2 * (1 - 0.35 * a), 1 - 0.3 * a, 1 - 0.85 * a, (1 - a) ** 3];
156
+ if (look.tint === "spark") [bright, g, b, hot] = [1.6 * (1 - 0.4 * a), 1 - 0.3 * a, 1 - 0.6 * a, 0.5 * (1 - a) ** 2];
157
+ if (look.flicker) {
158
+ const flick = rnd(seed, s, k, 1000 + Math.floor(frame));
159
+ bright *= 1 + look.flicker * (2 * flick - 1);
160
+ size *= 1 + 0.3 * look.flicker * (flick - 0.5);
161
+ }
162
+ const vx = tx + (v0x - tx) * e, vy = ty + (v0y - ty) * e, vz = tz + (v0z - tz) * e;
163
+ Object.assign(out, { x, y, z, size, alpha, angle: 2 * Math.PI * r(14) + look.spin * (2 * r(15) - 1) * age, variant: look.clean ? 0 : 1 + Math.floor(r(16) * 3),
164
+ r: em.rgb[0] * bright, g: (em.rgb[1] * g + 0.45 * hot) * bright, b: (em.rgb[2] * b + 0.12 * hot) * bright, additive: effect.additive, sx: vx * look.streak, sy: vy * look.streak, sz: vz * look.streak });
165
+ return true;
166
+ }
167
+
168
+ const catmull = (p0, p1, p2, p3, t, out) => {
169
+ for (let i = 0; i < 3; i += 1) out[i] = 0.5 * (2 * p1[i] + (p2[i] - p0[i]) * t + (2 * p0[i] - 5 * p1[i] + 4 * p2[i] - p3[i]) * t * t + (3 * p1[i] - p0[i] - 3 * p2[i] + p3[i]) * t * t * t);
170
+ return out;
171
+ };
172
+ const dist = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
173
+
174
+ /** The trail ribbon at `frame` as quads: visit({ a0, b0, a1, b1, alpha0, alpha1 }) older end first. */
175
+ function forEachSegment(em, frame, fps, cap, visit) {
176
+ const { effect } = em;
177
+ const half = effect.width / 2, span = effect.life * fps, last = Math.floor(frame), first = Math.floor(frame - span);
178
+ const edges = new Map();
179
+ const edge = (s) => {
180
+ const at = Math.min(last, s);
181
+ if (!edges.has(at)) {
182
+ const { p, q } = em.pose(at), off = rotate(q, 0, half, 0, [0, 0, 0]);
183
+ edges.set(at, { a: [p[0] - off[0], p[1] - off[1], p[2] - off[2]], b: [p[0] + off[0], p[1] + off[1], p[2] + off[2]] });
184
+ }
185
+ return edges.get(at);
186
+ };
187
+ const alphaAt = (s, t, level) => effect.opacity * level * Math.max(0, 1 - (frame - s - t) / span) ** 1.5;
188
+ let drawn = 0, clamped = 0;
189
+ for (let s = first; s < last; s += 1) {
190
+ const level = Math.min(em.level(s), em.level(s + 1));
191
+ const e0 = edge(s), e1 = edge(s + 1);
192
+ const move = Math.max(dist(e0.a, e1.a), dist(e0.b, e1.b));
193
+ if (!(level > 0) || move < TRAIL_STILL_M) continue;
194
+ const fast = Math.min(1, (move * fps) / TRAIL_FULL_SPEED), before = edge(s - 1), after = edge(s + 2);
195
+ for (let j = 0; j < TRAIL_SUBSTEPS; j += 1) {
196
+ const t0 = j / TRAIL_SUBSTEPS, t1 = (j + 1) / TRAIL_SUBSTEPS;
197
+ const alpha0 = alphaAt(s, t0, level) * fast, alpha1 = alphaAt(s, t1, level) * fast;
198
+ if (alpha0 <= 0 && alpha1 <= 0) continue;
199
+ if (drawn >= cap) { clamped += 1; continue; }
200
+ drawn += 1;
201
+ visit({ a0: catmull(before.a, e0.a, e1.a, after.a, t0, [0, 0, 0]), b0: catmull(before.b, e0.b, e1.b, after.b, t0, [0, 0, 0]),
202
+ a1: catmull(before.a, e0.a, e1.a, after.a, t1, [0, 0, 0]), b1: catmull(before.b, e0.b, e1.b, after.b, t1, [0, 0, 0]), alpha0, alpha1 });
203
+ }
204
+ }
205
+ return clamped;
206
+ }
207
+
208
+ /**
209
+ * Every effect record's particles and ribbons at `frame`.
210
+ *
211
+ * `scene`: { lookup: Map of AUTHORED records by id, take: { fps, objectTracks },
212
+ * live?: (id, out) => world matrix of an attached record, hidden?: Set of ids
213
+ * that emit nothing }. `particle(p, em)` / `segment(sg, em)` receive what is
214
+ * drawn (p is reused between calls); `only` limits the work to one emitter
215
+ * while keeping the scene-wide cap the renderer applies.
216
+ *
217
+ * @returns {Map<string, { alive: number, clamped: number, emitter: number[], min: number[], max: number[] }>}
218
+ */
219
+ export function evaluateEffects(records, scene, frame, { only = null, particle = null, segment = null } = {}) {
220
+ const fps = scene.take?.fps > 0 ? scene.take.fps : 24;
221
+ const emitters = records.filter((record) => record?.renderer === EFFECT_KIND).map((record) => emitterOf(record, scene));
222
+ const counts = emitters.map((em) => {
223
+ let count = 0;
224
+ if (!em.trail) forEachLive(em, frame, fps, () => { count += 1; });
225
+ return count;
226
+ });
227
+ const total = counts.reduce((sum, count) => sum + count, 0);
228
+ const trailCap = Math.floor(EFFECT_SEGMENT_CAP / Math.max(1, emitters.filter((em) => em.trail).length));
229
+ const stats = new Map();
230
+ const scratch = {};
231
+ emitters.forEach((em, index) => {
232
+ const st = { alive: 0, clamped: 0, emitter: em.pose(Math.floor(frame)).p, min: [Infinity, Infinity, Infinity], max: [-Infinity, -Infinity, -Infinity] };
233
+ stats.set(em.id, st);
234
+ if (only && em.id !== only) return;
235
+ const grow = (x, y, z, pad) => {
236
+ const { min, max } = st;
237
+ min[0] = Math.min(min[0], x - pad); min[1] = Math.min(min[1], y - pad); min[2] = Math.min(min[2], z - pad);
238
+ max[0] = Math.max(max[0], x + pad); max[1] = Math.max(max[1], y + pad); max[2] = Math.max(max[2], z + pad);
239
+ };
240
+ if (em.trail) {
241
+ st.clamped = forEachSegment(em, frame, fps, trailCap, (sg) => {
242
+ st.alive += 1;
243
+ for (const point of [sg.a0, sg.b0, sg.a1, sg.b1]) grow(point[0], point[1], point[2], 0);
244
+ segment?.(sg, em);
245
+ });
246
+ return;
247
+ }
248
+ const n = counts[index], keep = total > EFFECT_PARTICLE_CAP ? Math.floor((n * EFFECT_PARTICLE_CAP) / total) : n;
249
+ st.clamped = n - keep;
250
+ let order = 0;
251
+ forEachLive(em, frame, fps, (s, k, u, age, life, split) => {
252
+ const i = order++;
253
+ if (keep < n && Math.floor(((i + 1) * keep) / n) === Math.floor((i * keep) / n)) return;
254
+ if (!particleAt(em, s, k, u, age, life, split, frame, fps, scratch) || scratch.alpha < 5e-4) return;
255
+ st.alive += 1;
256
+ grow(scratch.x, scratch.y, scratch.z, scratch.size / 2);
257
+ particle?.(scratch, em);
258
+ });
259
+ });
260
+ return stats;
261
+ }