comfy-ts 2.22.0 → 2.24.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 (99) hide show
  1. package/dist/{ServeApp-DuxYdaZZ.js → ServeApp-fsHtW5zG.js} +51 -17
  2. package/dist/ServeApp-fsHtW5zG.js.map +1 -0
  3. package/dist/cli.js +5 -5
  4. package/dist/{exampleAssets-1NHndnNB.js → exampleAssets-DZynSkZm.js} +405 -39
  5. package/dist/exampleAssets-DZynSkZm.js.map +1 -0
  6. package/dist/{findDefinedWorkflow-CRsBTTJK.js → findDefinedWorkflow-qyqFea7q.js} +2 -2
  7. package/dist/{findDefinedWorkflow-CRsBTTJK.js.map → findDefinedWorkflow-qyqFea7q.js.map} +1 -1
  8. package/dist/index.cjs +428 -46
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +147 -1
  11. package/dist/index.d.ts +147 -1
  12. package/dist/index.js +428 -47
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-run-Y5ZI48vV.js → run-run-Cn2JzKlE.js} +5 -5
  15. package/dist/{run-run-Y5ZI48vV.js.map → run-run-Cn2JzKlE.js.map} +1 -1
  16. package/dist/{run-serve-CICU_wTL.js → run-serve-BhGegaCI.js} +4 -4
  17. package/dist/{run-serve-CICU_wTL.js.map → run-serve-BhGegaCI.js.map} +1 -1
  18. package/dist/{run-tui-CViJXsHL.js → run-tui-CrM4ijkH.js} +4 -4
  19. package/dist/{run-tui-CViJXsHL.js.map → run-tui-CrM4ijkH.js.map} +1 -1
  20. package/dist/{schemaDrift-CzjaIwZX.js → schemaDrift-BGYJZGMD.js} +18 -3
  21. package/dist/{schemaDrift-CzjaIwZX.js.map → schemaDrift-BGYJZGMD.js.map} +1 -1
  22. package/dist/serve-web.js +46 -43
  23. package/dist/web.d.ts +147 -1
  24. package/dist/web.js +428 -47
  25. package/dist/web.js.map +1 -1
  26. package/examples/README.md +1 -0
  27. package/examples/comfy-cloud/sdk.d.ts +102 -1
  28. package/examples/depth-explorer/models.ts +6 -56
  29. package/examples/depth-explorer/serve.ts +12 -133
  30. package/examples/depth-explorer/web/App.tsx +20 -91
  31. package/examples/depth-explorer/web/index.html +1 -0
  32. package/examples/depth-explorer/web/state.ts +26 -109
  33. package/examples/depth-explorer/web/styles.css +1 -286
  34. package/examples/explorer-kit/catalog.ts +80 -0
  35. package/examples/explorer-kit/server.ts +167 -0
  36. package/examples/explorer-kit/web/base.css +289 -0
  37. package/examples/explorer-kit/web/runs.ts +160 -0
  38. package/examples/explorer-kit/web/ui.tsx +125 -0
  39. package/examples/rvion/17-relight.cflow.ts +2 -1
  40. package/examples/rvion/18-world.cflow.ts +101 -0
  41. package/examples/rvion/19-flythrough.cflow.ts +312 -0
  42. package/examples/rvion/20-grow-splat.cflow.ts +88 -0
  43. package/examples/rvion/21-photo-to-model.cflow.ts +191 -0
  44. package/examples/rvion/flythroughChain.ts +171 -0
  45. package/examples/rvion/flythroughColmap.ts +157 -0
  46. package/examples/rvion/flythroughFuse.ts +199 -0
  47. package/examples/rvion/flythroughGuide.ts +300 -0
  48. package/examples/rvion/flythroughPalette.ts +310 -0
  49. package/examples/rvion/flythroughPath.ts +177 -0
  50. package/examples/rvion/flythroughSplat.ts +73 -0
  51. package/examples/rvion/grow-splat/align.ts +114 -0
  52. package/examples/rvion/grow-splat/grow.ts +198 -0
  53. package/examples/rvion/grow-splat/ply.ts +166 -0
  54. package/examples/rvion/grow-splat/raster.ts +207 -0
  55. package/examples/rvion/grow-splat/sharp.ts +45 -0
  56. package/examples/rvion/splatDataset.ts +80 -0
  57. package/examples/rvion/splatEval.ts +380 -0
  58. package/examples/upscale-explorer/models.ts +341 -0
  59. package/examples/upscale-explorer/serve.ts +19 -0
  60. package/examples/upscale-explorer/web/App.tsx +250 -0
  61. package/examples/upscale-explorer/web/compare.tsx +285 -0
  62. package/examples/upscale-explorer/web/index.html +15 -0
  63. package/examples/upscale-explorer/web/main.tsx +12 -0
  64. package/examples/upscale-explorer/web/state.ts +279 -0
  65. package/examples/upscale-explorer/web/styles.css +241 -0
  66. package/examples/upscale-explorer/web/tsconfig.json +16 -0
  67. package/examples/upscale-explorer/web/viewport.tsx +130 -0
  68. package/examples/world-explorer/serve.ts +171 -0
  69. package/examples/world-explorer/web/index.html +14 -0
  70. package/examples/world-explorer/web/main.tsx +200 -0
  71. package/examples/world-explorer/web/state.ts +212 -0
  72. package/examples/world-explorer/web/styles.css +131 -0
  73. package/examples/world-explorer/web/thumb.ts +21 -0
  74. package/examples/world-explorer/web/tsconfig.json +11 -0
  75. package/examples/world-explorer/world-state.ts +40 -0
  76. package/package.json +7 -8
  77. package/src/cli/serve/ServeApp.ts +27 -2
  78. package/src/cli/serve/resultHistory.ts +22 -4
  79. package/src/cli/serve/thumbs.ts +19 -8
  80. package/src/cli/serve/web/api.ts +4 -0
  81. package/src/cli/serve/web/components/Gallery.tsx +24 -1
  82. package/src/cli/serve/web/styles.ts +3 -0
  83. package/src/coreExports.ts +6 -0
  84. package/src/graph/ComfyNode.ts +12 -2
  85. package/src/host/ComfyHost.ts +159 -2
  86. package/src/host/ResilientWebsocket.ts +10 -0
  87. package/src/manager/script-update-manager.bun.ts +0 -7
  88. package/src/runner/ComfyExecution.ts +185 -23
  89. package/src/runner/ComfyWorkflow.ts +22 -0
  90. package/src/runner/ComfyWsApi.ts +3 -1
  91. package/src/runner/comfyOrgApiKey.ts +44 -0
  92. package/src/runner/historyReplay.ts +53 -0
  93. package/src/runner/outputs3d.ts +18 -0
  94. package/src/sdk-generator/ComfyUIObjectInfoTypes.ts +2 -0
  95. package/src/sdk-generator/comfyui-sdk-codegen.ts +7 -2
  96. package/src/state.ts +2 -0
  97. package/src/vars/DefinedWorkflow.ts +1 -0
  98. package/dist/ServeApp-DuxYdaZZ.js.map +0 -1
  99. package/dist/exampleAssets-1NHndnNB.js.map +0 -1
@@ -0,0 +1,125 @@
1
+ // the widgets every explorer page shares: a segmented choice, the source picker (drop, click,
2
+ // paste or a sample) and a card's body before its result shows.
3
+ import { observer } from 'mobx-react-lite'
4
+ import { useEffect, useRef, useState, type ReactNode } from 'react'
5
+ import type { CardInfo, RunSt, Source } from './runs.ts'
6
+
7
+ export function Seg<T extends string | number>(p: {
8
+ value: T
9
+ options: [T, string][]
10
+ onChange: (v: T) => void
11
+ tips?: string[]
12
+ }) {
13
+ return (
14
+ <div className="seg">
15
+ {p.options.map(([v, label], i) => (
16
+ <button key={String(v)} className={v === p.value ? 'on' : ''} title={p.tips?.[i]} onClick={() => p.onChange(v)}>
17
+ {label}
18
+ </button>
19
+ ))}
20
+ </div>
21
+ )
22
+ }
23
+
24
+ /** a finished run's time; a result ComfyUI took from its cache has none of its own */
25
+ export const timeOf = (r: RunSt): string =>
26
+ r.cached === 'box' ? 'box cache' : r.ms != null ? `${(r.ms / 1000).toFixed(1)} s` : ''
27
+
28
+ /** the source image: drop a file, click to pick one, paste anywhere on the page, or a sample */
29
+ export function SourcePicker(p: {
30
+ source: Source | null
31
+ samples: string[]
32
+ onFile: (f: Blob, name: string) => void
33
+ onSample: (name: string) => void
34
+ }) {
35
+ const [drag, setDrag] = useState(false)
36
+ const fileRef = useRef<HTMLInputElement>(null)
37
+ const take = (f: File | undefined): void => {
38
+ if (f != null && f.type.startsWith('image/')) p.onFile(f, f.name)
39
+ }
40
+ useEffect(() => {
41
+ const onPaste = (e: ClipboardEvent): void => {
42
+ take([...(e.clipboardData?.files ?? [])].find((x) => x.type.startsWith('image/')))
43
+ }
44
+ window.addEventListener('paste', onPaste)
45
+ return () => window.removeEventListener('paste', onPaste)
46
+ })
47
+ return (
48
+ <>
49
+ <div
50
+ className={`drop ${drag ? 'over' : ''}`}
51
+ onDragOver={(e) => {
52
+ e.preventDefault()
53
+ setDrag(true)
54
+ }}
55
+ onDragLeave={() => setDrag(false)}
56
+ onDrop={(e) => {
57
+ e.preventDefault()
58
+ setDrag(false)
59
+ take(e.dataTransfer.files[0])
60
+ }}
61
+ onClick={() => fileRef.current?.click()}
62
+ >
63
+ {p.source != null ? <img src={p.source.url} alt={p.source.name} /> : <span>drop an image</span>}
64
+ <input ref={fileRef} type="file" accept="image/*" hidden onChange={(e) => take(e.target.files?.[0])} />
65
+ </div>
66
+ <div className="dim small">
67
+ {p.source != null ? `${p.source.name} · ${p.source.width}×${p.source.height}` : ''}
68
+ <br />
69
+ drop, click or paste an image
70
+ </div>
71
+ <div className="samples">
72
+ {p.samples.map((s) => (
73
+ <img key={s} src={`/api/samples/${s}`} alt={s} title={s} onClick={() => p.onSample(s)} />
74
+ ))}
75
+ </div>
76
+ </>
77
+ )
78
+ }
79
+
80
+ /** a card's frame before its result: the missing files, a run button, queued, the timer, the error */
81
+ export const RunBody = observer(function RunBody(p: {
82
+ model: CardInfo
83
+ run: RunSt | undefined
84
+ now: number
85
+ canRun: boolean
86
+ onRun: () => void
87
+ }): ReactNode {
88
+ const r = p.run
89
+ if (!p.model.ok)
90
+ return (
91
+ <div className="missing">
92
+ <b>not on this host</b>
93
+ {p.model.missingNodes.length > 0 && <span>nodes: {p.model.missingNodes.join(', ')}</span>}
94
+ {p.model.missingFiles.map((f) => (
95
+ <a key={f.file} href={f.url} target="_blank" rel="noreferrer">
96
+ models/{f.folder}/{f.file}
97
+ </a>
98
+ ))}
99
+ </div>
100
+ )
101
+ if (r == null)
102
+ return (
103
+ <button className="ghost" onClick={p.onRun} disabled={!p.canRun}>
104
+ run
105
+ </button>
106
+ )
107
+ if (r.status === 'queued') return <span className="dim">queued</span>
108
+ if (r.status === 'running')
109
+ return (
110
+ <span className="dim">
111
+ <span className="spin" /> {((p.now - r.startedAt) / 1000).toFixed(1)} s
112
+ {p.model.autoDownload && p.now - r.startedAt > 8000 && <small>first run downloads the weights</small>}
113
+ </span>
114
+ )
115
+ if (r.status === 'error')
116
+ return (
117
+ <div className="err">
118
+ <span>{r.error}</span>
119
+ <button className="ghost" onClick={p.onRun}>
120
+ retry
121
+ </button>
122
+ </div>
123
+ )
124
+ return null
125
+ })
@@ -9,7 +9,8 @@
9
9
  //
10
10
  // run directly: bun examples/rvion/17-relight.cflow.ts [path/to/image.png]
11
11
  import { asAbsolutePath, type BaseNodeInputs, ComfyTS, exampleImagePath, MediaImage, v, widget } from 'comfy-ts'
12
- import { availability, MODELS, optionLook, type ModelEntry } from '../depth-explorer/models.ts'
12
+ import { MODELS, optionLook, type ModelEntry } from '../depth-explorer/models.ts'
13
+ import { availability } from '../explorer-kit/catalog.ts'
13
14
 
14
15
  const comfy = ComfyTS.create()
15
16
  const host = comfy.host({ id: 'windows-1' })
@@ -0,0 +1,101 @@
1
+ // turn one picture into a 360° world: Qwen-Image-Edit-2509 with Tencent's HY-Pano 2.0 LoRA (from
2
+ // HY-World 2.0) expands the picture into an equirectangular panorama, the same prompt template,
3
+ // size, steps and guidance as their pipeline_with_qwen_image.py. Its left and right edges meet:
4
+ // the viewer wraps it around you. MoGe then measures the panorama's depth all around and the
5
+ // world is saved as a textured mesh (glb) seen from its middle.
6
+ //
7
+ // run directly: bun examples/rvion/18-world.cflow.ts [path/to/image.png] [seed]
8
+ import { ComfyTS, exampleImagePath, v } from 'comfy-ts'
9
+
10
+ const comfy = ComfyTS.create()
11
+ const host = comfy.host({ id: 'windows-1' })
12
+ await host.loadSchemaFromCache()
13
+
14
+ /** HY-Pano 2.0's own prompt template (hyworld2/panogen/pipeline_with_qwen_image.py) */
15
+ const PANO_PREFIX =
16
+ 'Create a **ERP** panoramic expansion of the provided image. Preserve the original style, lighting, and fine details seamlessly throughout the extended areas, extend according to: '
17
+ const PANO_SUFFIX = ' 8k UHD, masterpiece, razor-sharp details.'
18
+ const PANO_NEGATIVE =
19
+ '低分辨率,低画质,模糊。杂乱的背景,结构扭曲,模糊纹理,物体融合。构图混乱。过度光滑,画面具有AI感。人脸畸形。巨大物体,巨大建筑,近景特写,近景压迫,比例失调。车,车辆。画面上方的树叶。'
20
+ const PANO_LORA = 'world\\hy-pano-2-qwen-lora.safetensors'
21
+ /** HY-Pano's canvas and its edge blend width: 1952 - 32 = 1920, 2:1 */
22
+ const PANO_W = 1952
23
+ const PANO_H = 960
24
+ const BLEND = 32
25
+
26
+ const image = v.image(exampleImagePath('lioness_768x768.jpg'), {
27
+ presets: {
28
+ lioness: exampleImagePath('lioness_768x768.jpg'),
29
+ bear: exampleImagePath('bear_1024x1024.jpg'),
30
+ walrus: exampleImagePath('walrus_1344x768.jpg'),
31
+ deer: exampleImagePath('deer_768x1344.jpg'),
32
+ },
33
+ })
34
+
35
+ export const world = host.defineWorkflow({
36
+ id: 'world',
37
+ vars: {
38
+ image,
39
+ /** what the unseen sides hold; empty lets the model continue the picture */
40
+ extend: v.text(''),
41
+ seed: v.seed(42),
42
+ steps: v.int(40, { min: 8, max: 60 }),
43
+ cfg: v.float(7.5, { min: 1, max: 12 }),
44
+ },
45
+ build: async (b, vars, wf) => {
46
+ const picture = await image.loadInWorkflow(wf)
47
+ const clip = b.CLIPLoader({ clip_name: 'qwen_2.5_vl_7b_fp8_scaled.safetensors', type: 'qwen_image' })
48
+ const vae = b.VAELoader({ vae_name: 'qwen_image_vae.safetensors' })
49
+ const unet = b.UNETLoader({ unet_name: 'qwen_image_edit_2509_int8_convrot.safetensors', weight_dtype: 'default' })
50
+ const withLora = b.LoraLoaderModelOnly({ model: unet, lora_name: PANO_LORA, strength_model: 1 })
51
+ const encode = (prompt: string) =>
52
+ b.TextEncodeQwenImageEditPlus({ clip, prompt, vae, image1: picture })
53
+ const samples = b.KSampler({
54
+ model: b.ModelSamplingAuraFlow({ model: withLora, shift: 3.1 }),
55
+ positive: encode(`${PANO_PREFIX}${vars.extend}${PANO_SUFFIX}`),
56
+ negative: encode(PANO_NEGATIVE),
57
+ latent_image: b.EmptySD3LatentImage({ width: PANO_W, height: PANO_H, batch_size: 1 }),
58
+ seed: vars.seed,
59
+ steps: vars.steps,
60
+ cfg: vars.cfg,
61
+ sampler_name: 'euler',
62
+ scheduler: 'simple',
63
+ denoise: 1,
64
+ })
65
+ const raw = b.VAEDecode({ samples, vae })
66
+ // the seam: HY-Pano's own edge blend (circular_blend_edges), the last BLEND columns fade into
67
+ // the first ones, then leave; 1952 wide becomes an exact 2:1 that wraps without a cut
68
+ const strip = (x: number) => b.ImageCrop({ image: raw, width: BLEND, height: PANO_H, x, y: 0 })
69
+ const joined = b.ImageCompositeMasked({
70
+ destination: strip(PANO_W - BLEND),
71
+ source: strip(0),
72
+ x: 0,
73
+ y: 0,
74
+ mask: b['kjnodes.CreateGradientMask']({ invert: true, frames: 1, width: BLEND, height: PANO_H }),
75
+ })
76
+ const panorama = b.ImageCompositeMasked({
77
+ destination: b.ImageCrop({ image: raw, width: PANO_W - BLEND, height: PANO_H, x: 0, y: 0 }),
78
+ source: joined,
79
+ x: 0,
80
+ y: 0,
81
+ })
82
+ b.SaveImageWebsocket({ images: panorama }, { tag: 'panorama' })
83
+ // the world: MoGe reads 12 perspective views of the panorama, merges one distance map all
84
+ // around, and the textured mesh is that map seen from the middle
85
+ const geometry = b.MoGePanoramaInference({
86
+ moge_model: b.LoadMoGeModel({ model_name: 'moge_2_vitl_normal_fp16.safetensors' }),
87
+ image: panorama,
88
+ })
89
+ b.SaveGLB({ mesh: b.MoGePointMapToMesh({ moge_geometry: geometry }), filename_prefix: 'comfy-ts/world' })
90
+ },
91
+ })
92
+
93
+ export default world
94
+
95
+ if (import.meta.main) {
96
+ if (process.argv[2]) world.vars.image.set(process.argv[2])
97
+ if (process.argv[3]) world.vars.seed.set(Number(process.argv[3]))
98
+ const execution = await world.run({ log: true, save: { prefix: 'comfy-ts-example/world' } })
99
+ for (const img of execution.images) console.log(`🟢 ${img.tags.join(',')} ${img.absPath}`)
100
+ host.disconnect()
101
+ }
@@ -0,0 +1,312 @@
1
+ // fly into a picture: MoGe measures the picture's depth and turns it into a textured mesh, a camera
2
+ // moves through that mesh along a path we choose (a walk, or round a thing), and every step is
3
+ // rendered. That render, with holes where the picture never looked, guides the video model: Wan 2.2
4
+ // Fun Control (14B, two stages, the 4-step lightx2v LoRAs), or MiniMax H3 with its Fun ControlNet
5
+ // (the 4-step turbo LoRA). The picture is the first frame, the render the control video, and the
6
+ // video is the camera move with the holes filled. The camera of each frame is known, so the clip
7
+ // can be fitted back into a 3D world. Videos persist on the host under comfy-ts-example/.
8
+ //
9
+ // run directly: bun examples/rvion/19-flythrough.cflow.ts [path/to/image.png] [seed]
10
+ import { ComfyTS, exampleImagePath, v } from 'comfy-ts'
11
+ import { clipFrames, ENGINES, frameFovY, pathCameras } from './flythroughPath.ts'
12
+
13
+ const comfy = ComfyTS.create()
14
+ const host = comfy.host({ id: 'windows-1' })
15
+ await host.loadSchemaFromCache()
16
+
17
+ /** Wan 2.2's own negative prompt (the Fun Control template), plus the camera moves we do not want */
18
+ const NEGATIVE =
19
+ '色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走'
20
+ const need = <T,>(x: T | undefined, what: string): T => {
21
+ if (x == null) throw new Error(`flythrough: ${what}`)
22
+ return x
23
+ }
24
+ /** BatchCameras takes at most this many cameras per node; longer paths nest batches */
25
+ const BATCH_MAX = 50
26
+
27
+ const image = v.image(exampleImagePath('walrus_1344x768.jpg'), {
28
+ presets: {
29
+ walrus: exampleImagePath('walrus_1344x768.jpg'),
30
+ bear: exampleImagePath('bear_1024x1024.jpg'),
31
+ deer: exampleImagePath('deer_768x1344.jpg'),
32
+ },
33
+ })
34
+ /** the frame the video model makes; it shows the picture's own size as a pick */
35
+ const frameSize = v.size({ width: 832, height: 480 }, { image })
36
+ /** where a chained clip starts: the last frame of the clip before it; empty = the picture. Not a
37
+ * workflow var (an empty media var fails the run): the script that chains the clips sets it */
38
+ export const chainStart = v.image('')
39
+ /** a guide video drawn elsewhere (flythroughChain.ts draws it on this machine, in milliseconds a
40
+ * frame): when set, the box skips MoGe and its ray traced render. Not a workflow var, as chainStart */
41
+ export const premadeGuide = v.video('')
42
+ /** with premadeGuide: the colour render and its coverage (white where the mesh has data), for H3's
43
+ * keep mode */
44
+ export const premadeRender = v.video('')
45
+ export const premadeCoverage = v.video('')
46
+
47
+ export const flythrough = host.defineWorkflow({
48
+ id: 'flythrough',
49
+ tags: ['video', '3d', 'camera'],
50
+ vars: {
51
+ image,
52
+ prompt: v.prompt(
53
+ 'a slow steady camera walks forward into the scene, smooth dolly shot, the same place and the same light, detailed, sharp\n- shaky camera, zoom, cut, morphing, flicker',
54
+ ),
55
+ /** the picture's horizontal field of view in degrees: MoGe builds the mesh with it, the render uses it */
56
+ fov: v.float(60, { min: 20, max: 120 }),
57
+ /** walk: forward with a turn; orbit: toward the aimed thing, then around it */
58
+ path: v.choice(['walk', 'orbit'], 'walk'),
59
+ /** clips the path is cut into, each `seconds` long, chained by their last frame */
60
+ clips: v.int(1, { min: 1, max: 16 }),
61
+ /** which clip of the path this run makes, from 0 */
62
+ clip: v.int(0, { min: 0, max: 15 }),
63
+ /** walk: metres forward along the path, in MoGe's metric scale */
64
+ distance: v.float(2.5, { min: 0, max: 20 }),
65
+ /** degrees the heading turns over the walk, positive = to the right */
66
+ turn: v.float(12, { min: -90, max: 90 }),
67
+ /** metres the eye rises over the walk */
68
+ rise: v.float(0, { min: -5, max: 5 }),
69
+ /** orbit: the aimed thing's column in the picture, 0 = left edge, 1 = right edge */
70
+ aim: v.float(0.5, { min: 0, max: 1 }),
71
+ /** orbit: the aimed thing's row in the picture, 0 = top edge, 1 = bottom edge */
72
+ aimRow: v.float(0.5, { min: 0, max: 1 }),
73
+ /** orbit: metres from the picture's camera to the aimed thing's centre, along its ray */
74
+ aimDistance: v.float(8, { min: 0.5, max: 100 }),
75
+ /** orbit: metres from that centre the camera circles at */
76
+ radius: v.float(4, { min: 0.2, max: 50 }),
77
+ /** orbit: degrees around it, positive = round by the right */
78
+ sweep: v.float(180, { min: -720, max: 720 }),
79
+ /** degrees the picture looks down at its floor (a picture's mesh measures it): the orbit circles
80
+ * round the floor's vertical. Needs the guide drawn on this machine (flythroughChain.ts), which
81
+ * levels the mesh by it */
82
+ pitch: v.float(0, { min: -80, max: 80 }),
83
+ /** the video model: Wan 2.2 Fun Control 14B (16 fps), or MiniMax H3 with its Fun ControlNet (24 fps) */
84
+ engine: v.choice(['wan', 'h3'], 'wan'),
85
+ /** seconds of one clip, snapped to the frame counts the engine takes */
86
+ seconds: v.float(5, { min: 1, max: 15 }),
87
+ size: frameSize,
88
+ /** what steers the video: the depth of the render (what Fun Control was trained on) or its colours */
89
+ guide: v.choice(['depth', 'color'], 'depth'),
90
+ /** the guide's holes (what the picture never showed): black, or filled with the depth around them
91
+ * (the guide drawn on this machine only): a video model that follows its guide closely paints
92
+ * a black hole as a black void */
93
+ holes: v.choice(['black', 'filled'], 'black'),
94
+ /** the guide render's size against the frame: 0.5 renders four times faster */
95
+ guideScale: v.float(0.5, { min: 0.25, max: 1 }),
96
+ seed: v.seed(42),
97
+ /** sampling steps; Wan runs the first half on its high noise model */
98
+ steps: v.int(4, { min: 2, max: 40 }),
99
+ /** Wan: 1 with the 4-step LoRAs; raise it (with more steps) when they are off */
100
+ cfg: v.float(1, { min: 1, max: 8 }),
101
+ lightning: v.toggle(true, '4-step LoRAs'),
102
+ /** H3: how hard its Fun ControlNet holds the guide */
103
+ control: v.float(1, { min: 0, max: 2 }),
104
+ /** H3: the share of the sampling steps the guide steers, from the first: below 1 the last steps
105
+ * paint freely over the layout it set */
106
+ controlEnd: v.float(1, { min: 0.05, max: 1 }),
107
+ /** H3: control = the guide steers everything; keep = the render's pixels stay where the mesh
108
+ * has data and only the holes are made (its ControlNet's mask and source video) */
109
+ h3Mode: v.choice(['control', 'keep'], 'control'),
110
+ /** H3: how the picture conditions the clip. frame = the start frame alone (the picture, or the
111
+ * last frame of the clip before); reference = the picture also as a reference image every clip
112
+ * (its look held beyond frame 0), the start frame anchored at frame 0 */
113
+ h3Look: v.choice(['frame', 'reference'], 'frame'),
114
+ },
115
+ build: async (b, vars, wf) => {
116
+ const picture = await image.loadInWorkflow(wf)
117
+ const source = frameSize.imageSize()
118
+ if (source == null) throw new Error(`flythrough: cannot read the size of the picture '${image.value}'`)
119
+ const size = vars.size
120
+ const step = vars.engine === 'wan' ? 16 : 32
121
+ if (size.width % step !== 0 || size.height % step !== 0)
122
+ throw new Error(`flythrough: ${vars.engine} needs a size in multiples of ${step}, got ${size.width}×${size.height}`)
123
+ const length = clipFrames(vars.engine, vars.seconds)
124
+ const fps = ENGINES[vars.engine].fps
125
+ const fov = frameFovY({ picture: source, fovX: vars.fov, size })
126
+ if (vars.clip >= vars.clips) throw new Error(`flythrough: clip ${vars.clip} of a path of ${vars.clips} clips`)
127
+ // chained clips start from the last frame of the clip before; the mesh stays the picture's
128
+ // cover-cropped to the frame: H3 stretches a first frame of another shape, and the guide's
129
+ // cameras see the cropped picture (frameFovY)
130
+ const reference = b.ImageScale({
131
+ image: chainStart.isSet() ? await chainStart.loadInWorkflow(wf) : picture,
132
+ upscale_method: 'lanczos',
133
+ width: size.width,
134
+ height: size.height,
135
+ crop: 'center',
136
+ })
137
+
138
+ const save = (images: Comfy.Windows1.Accepts['IMAGE'], tag: string) =>
139
+ b.SaveVideo(
140
+ {
141
+ video: b.CreateVideo({ images, fps }),
142
+ filename_prefix: `comfy-ts-example/flythrough-${tag}`,
143
+ format: 'mp4',
144
+ codec: 'h264',
145
+ },
146
+ { tag },
147
+ )
148
+ // the guide: the picture as a textured mesh, rendered from every camera of the path; drawn on
149
+ // this machine by the chain script (premadeGuide), or here by the box (MoGe, then RenderMesh)
150
+ const boxGuide = () => {
151
+ if (vars.pitch !== 0) throw new Error('flythrough: a pitched path needs the guide drawn by flythroughChain.ts, which levels the mesh')
152
+ const geometry = b.MoGeInference({
153
+ moge_model: b.LoadMoGeModel({ model_name: 'moge_2_vitl_normal_fp16.safetensors' }),
154
+ image: picture,
155
+ fov_x_degrees: vars.fov,
156
+ })
157
+ const mesh = b.MoGePointMapToMesh({ moge_geometry: geometry })
158
+ const first = vars.clip * (length - 1)
159
+ const cameras = pathCameras({ ...vars, fovX: vars.fov, aspect: source.height / source.width, length })
160
+ .slice(first, first + length)
161
+ .map((c) =>
162
+ b.CreateCameraInfo({
163
+ mode: 'look_at',
164
+ 'mode.position_x': c.position[0],
165
+ 'mode.position_y': c.position[1],
166
+ 'mode.position_z': c.position[2],
167
+ target_x: c.target[0],
168
+ target_y: c.target[1],
169
+ target_z: c.target[2],
170
+ fov,
171
+ camera_type: 'perspective',
172
+ }),
173
+ )
174
+ const batch = (list: Comfy.Windows1.Accepts['LOAD3D_CAMERA'][]): Comfy.Windows1.Accepts['LOAD3D_CAMERA'] => {
175
+ const [first, ...rest] = list
176
+ if (first == null) throw new Error('flythrough: a camera batch needs one camera at least')
177
+ const more: Record<string, Comfy.Windows1.Accepts['LOAD3D_CAMERA']> = {}
178
+ rest.forEach((cam, i) => (more[`cameras.camera_info${i + 1}`] = cam))
179
+ return b.BatchCameras({ 'cameras.camera_info0': first, ...more })
180
+ }
181
+ const chunks: Comfy.Windows1.Accepts['LOAD3D_CAMERA'][] = []
182
+ for (let i = 0; i < cameras.length; i += BATCH_MAX) chunks.push(batch(cameras.slice(i, i + BATCH_MAX)))
183
+ const path = chunks.length === 1 ? chunks[0] : batch(chunks)
184
+ // the mesh is ray traced frame by frame (seconds a frame at full size): a smaller guide costs a
185
+ // fraction of that, and Wan scales its control video to the frame anyway
186
+ const guideSize = (side: number) => Math.max(64, Math.round((side * vars.guideScale) / 8) * 8)
187
+ const render = (mode: 'texture' | 'depth') =>
188
+ b.RenderMesh({
189
+ mesh,
190
+ mode,
191
+ width: guideSize(size.width),
192
+ height: guideSize(size.height),
193
+ background: '#000000',
194
+ camera_info: path,
195
+ })
196
+ const colour = render('texture')
197
+ const control = vars.guide === 'depth' ? render('depth') : colour
198
+ // what a reconstruction needs beside the clip: the guide, the render in colour, and its holes
199
+ save(control.outputs.image, 'guide')
200
+ if (vars.guide === 'depth') save(colour.outputs.image, 'render')
201
+ save(b.MaskToImage({ mask: colour.outputs.mask }), 'coverage')
202
+ return { control: control.outputs.image, render: colour.outputs.image, holes: b.InvertMask({ mask: colour.outputs.mask }) }
203
+ }
204
+ const frames = async (video: typeof premadeGuide) => b.GetVideoComponents({ video: await video.loadInWorkflow(wf) }).outputs.images
205
+ const premade = async () => ({
206
+ control: await frames(premadeGuide),
207
+ render: premadeRender.isSet() ? await frames(premadeRender) : undefined,
208
+ holes: premadeCoverage.isSet()
209
+ ? b.InvertMask({ mask: b.ImageToMask({ image: await frames(premadeCoverage), channel: 'red' }) })
210
+ : undefined,
211
+ })
212
+ const guide = premadeGuide.isSet() ? await premade() : boxGuide()
213
+ const control = guide.control
214
+
215
+ if (vars.engine === 'h3') {
216
+ // MiniMax H3: the first frame and the prompt condition the clip, its Fun ControlNet patches
217
+ // the model with the guide; one sampler, 4 steps with the turbo LoRA (its own template's graph)
218
+ const vae = b.VAELoader({ vae_name: 'minimax_h3_video_vae_fp16.safetensors' })
219
+ const unet = b.UNETLoader({ unet_name: 'minimax_h3_fl2va_pruned_fp8_scaled.safetensors', weight_dtype: 'default' })
220
+ const base = vars.lightning
221
+ ? b.LoraLoaderModelOnly({ model: unet, lora_name: 'minimax_h3_fl2v_turbo_4step_v1.0_768p_comfyui_bf16.safetensors', strength_model: 1 })
222
+ : unet
223
+ const model = b.MiniMaxH3FunControlNetApply({
224
+ model: base,
225
+ model_patch: b.ModelPatchLoader({ name: 'minimax_h3_fun_controlnet_union_2.0_pruned_int8_convrot.safetensors' }),
226
+ vae,
227
+ strength: vars.control,
228
+ end_percent: vars.controlEnd,
229
+ control_video: control,
230
+ ...(vars.h3Mode === 'keep' ? { mask: need(guide.holes, 'h3 keep mode needs the coverage'), source_video: need(guide.render, 'h3 keep mode needs the colour render') } : {}),
231
+ })
232
+ const clip = b.CLIPLoader({ clip_name: 'qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors', type: 'minimax' })
233
+ const start =
234
+ vars.h3Look === 'reference'
235
+ ? b.MiniMaxH3ReferenceToVideo({
236
+ clip,
237
+ vae,
238
+ prompt: vars.prompt.positive,
239
+ width: size.width,
240
+ height: size.height,
241
+ length,
242
+ 'ref_images.ref_image_0': b.ImageScale({ image: picture, upscale_method: 'lanczos', width: size.width, height: size.height, crop: 'center' }),
243
+ })
244
+ : b.MiniMaxH3ImageToVideo({ clip, vae, prompt: vars.prompt.positive, width: size.width, height: size.height, length, first_frame: reference })
245
+ const positive =
246
+ vars.h3Look === 'reference'
247
+ ? b.MiniMaxH3AddGuide({ positive: start.outputs.positive, latent: start.outputs.LATENT, vae, image: reference, frame_idx: 0 }).outputs.positive
248
+ : start.outputs.positive
249
+ const sampled = b.SamplerCustomAdvanced({
250
+ noise: b.RandomNoise({ noise_seed: vars.seed }),
251
+ guider: b.BasicGuider({ model, conditioning: positive }),
252
+ sampler: b.KSamplerSelect({ sampler_name: 'res_multistep' }),
253
+ sigmas: b.BasicScheduler({ model, scheduler: 'simple', steps: vars.steps, denoise: 1 }),
254
+ latent_image: start.outputs.LATENT,
255
+ })
256
+ save(b.VAEDecode({ samples: sampled.outputs.output, vae }), 'clip')
257
+ return
258
+ }
259
+
260
+ // Wan 2.2 Fun Control, two stages: the high noise model lays out the motion, the low noise
261
+ // model the detail
262
+ const clip = b.CLIPLoader({ clip_name: 'umt5_xxl_fp8_e4m3fn_scaled.safetensors', type: 'wan' })
263
+ const vae = b.VAELoader({ vae_name: 'wan_2.1_vae.safetensors' })
264
+ const stage = (noise: 'high' | 'low') => {
265
+ const unet = b.UNETLoader({ unet_name: `wan2.2_fun_control_${noise}_noise_14B_fp8_scaled.safetensors`, weight_dtype: 'default' })
266
+ const model = vars.lightning
267
+ ? b.LoraLoaderModelOnly({ model: unet, lora_name: `wan2.2_i2v_lightx2v_4steps_lora_v1_${noise}_noise.safetensors`, strength_model: 1 })
268
+ : unet
269
+ return b.ModelSamplingSD3({ model, shift: 8 })
270
+ }
271
+ const conditioning = b.Wan22FunControlToVideo({
272
+ positive: b.CLIPTextEncode({ clip, text: vars.prompt.positive }),
273
+ negative: b.CLIPTextEncode({ clip, text: `${NEGATIVE}${vars.prompt.negative === '' ? '' : `, ${vars.prompt.negative}`}` }),
274
+ vae,
275
+ width: size.width,
276
+ height: size.height,
277
+ length,
278
+ ref_image: reference,
279
+ control_video: control,
280
+ })
281
+ const split = Math.max(1, Math.floor(vars.steps / 2))
282
+ const sample = (p: { noise: 'high' | 'low'; latent: Comfy.Windows1.Accepts['LATENT']; first: boolean }) =>
283
+ b.KSamplerAdvanced({
284
+ model: stage(p.noise),
285
+ add_noise: p.first ? 'enable' : 'disable',
286
+ noise_seed: vars.seed,
287
+ steps: vars.steps,
288
+ cfg: vars.cfg,
289
+ sampler_name: 'euler',
290
+ scheduler: 'simple',
291
+ positive: conditioning.outputs.positive,
292
+ negative: conditioning.outputs.negative,
293
+ latent_image: p.latent,
294
+ start_at_step: p.first ? 0 : split,
295
+ end_at_step: p.first ? split : 10000,
296
+ return_with_leftover_noise: p.first ? 'enable' : 'disable',
297
+ })
298
+ const high = sample({ noise: 'high', latent: conditioning.outputs.latent, first: true })
299
+ const low = sample({ noise: 'low', latent: high, first: false })
300
+ save(b.VAEDecode({ samples: low, vae }), 'clip')
301
+ },
302
+ })
303
+
304
+ export default flythrough
305
+
306
+ if (import.meta.main) {
307
+ if (process.argv[2]) flythrough.vars.image.set(process.argv[2])
308
+ if (process.argv[3]) flythrough.vars.seed.set(Number(process.argv[3]))
309
+ const execution = await flythrough.run({ log: true, save: { prefix: 'comfy-ts-example/flythrough' } })
310
+ for (const clip of execution.videos) console.log(`🟢 ${clip.tags.join(',')} ${clip.absPath}`)
311
+ host.disconnect()
312
+ }
@@ -0,0 +1,88 @@
1
+ // fill the holes of a splat seen from a new camera: the one ComfyUI step of the grow loop (grow-splat/grow.ts).
2
+ // The input is the render as a png whose alpha is how much of each pixel the splat covers; LoadImage turns that
3
+ // alpha into the mask (1 = empty). Qwen-Image-Edit-2509 repaints only the empty part (a latent noise mask), with
4
+ // the whole render as its reference, so the new part keeps the style, the light and the perspective of the rest.
5
+ // The covered pixels come back untouched (composited over the result).
6
+ //
7
+ // run directly: bun examples/rvion/20-grow-splat.cflow.ts [path/to/render-rgba.png] [seed]
8
+ import { ComfyTS, exampleImagePath, v } from 'comfy-ts'
9
+
10
+ const comfy = ComfyTS.create()
11
+ const host = comfy.host({ id: 'windows-1' })
12
+ await host.loadSchemaFromCache()
13
+
14
+ /** what the model is told; a world's own words (what lies beyond) go after it */
15
+ export const FILL_PROMPT =
16
+ 'Fill the empty black areas so the scene continues seamlessly beyond its edges and behind its objects: the same place, the same architecture, materials, lighting, colours and painting style, the same camera perspective. Keep everything that is already visible unchanged.'
17
+
18
+ const render = v.image(exampleImagePath('walrus_1344x768.jpg'))
19
+
20
+ export const growSplatFill = host.defineWorkflow({
21
+ id: 'grow-splat-fill',
22
+ vars: {
23
+ render,
24
+ prompt: v.prompt(FILL_PROMPT),
25
+ /** a pixel covered less than this counts as empty */
26
+ covered: v.float(0.9, { min: 0.05, max: 1 }),
27
+ /** pixels added around the empty part, so the seam is painted again too */
28
+ grow: v.int(12, { min: 0, max: 128 }),
29
+ seed: v.seed(42),
30
+ steps: v.int(20, { min: 4, max: 60 }),
31
+ cfg: v.float(4, { min: 1, max: 10 }),
32
+ },
33
+ build: async (b, vars, wf) => {
34
+ const loaded = await render.loadInWorkflow(wf)
35
+ const hole = b.GrowMask({
36
+ mask: b.ThresholdMask({ mask: loaded.outputs.MASK, value: 1 - vars.covered }),
37
+ expand: vars.grow,
38
+ tapered_corners: true,
39
+ })
40
+ // the model never sees black: the hole starts as a smooth continuation of its border
41
+ const prefilled = b['inpaint-nodes.INPAINT_MaskedFill']({ image: loaded.outputs.IMAGE, mask: hole, fill: 'telea', falloff: 0 })
42
+ const clip = b.CLIPLoader({ clip_name: 'qwen_2.5_vl_7b_fp8_scaled.safetensors', type: 'qwen_image' })
43
+ const vae = b.VAELoader({ vae_name: 'qwen_image_vae.safetensors' })
44
+ const unet = b.UNETLoader({ unet_name: 'qwen_image_edit_2509_int8_convrot.safetensors', weight_dtype: 'default' })
45
+ const encode = (prompt: string) => b.TextEncodeQwenImageEditPlus({ clip, prompt, vae, image1: prefilled })
46
+ const samples = b.KSampler({
47
+ model: b.ModelSamplingAuraFlow({ model: unet, shift: 3.1 }),
48
+ positive: encode(vars.prompt.positive),
49
+ negative: encode(vars.prompt.negative),
50
+ latent_image: b.SetLatentNoiseMask({ samples: b.VAEEncode({ pixels: prefilled, vae }), mask: hole }),
51
+ seed: vars.seed,
52
+ steps: vars.steps,
53
+ cfg: vars.cfg,
54
+ sampler_name: 'euler',
55
+ scheduler: 'simple',
56
+ denoise: 1,
57
+ })
58
+ // a soft edge, so the seam between the kept pixels and the painted ones does not show
59
+ const soft = b['kjnodes.GrowMaskWithBlur']({
60
+ mask: hole,
61
+ expand: 0,
62
+ incremental_expandrate: 0,
63
+ tapered_corners: true,
64
+ flip_input: false,
65
+ blur_radius: 6,
66
+ lerp_alpha: 1,
67
+ decay_factor: 1,
68
+ })
69
+ const filled = b.ImageCompositeMasked({
70
+ destination: loaded.outputs.IMAGE,
71
+ source: b.VAEDecode({ samples, vae }),
72
+ x: 0,
73
+ y: 0,
74
+ mask: soft.outputs.mask,
75
+ })
76
+ b.SaveImageWebsocket({ images: filled }, { tag: 'filled' })
77
+ },
78
+ })
79
+
80
+ export default growSplatFill
81
+
82
+ if (import.meta.main) {
83
+ if (process.argv[2]) growSplatFill.vars.render.set(process.argv[2])
84
+ if (process.argv[3]) growSplatFill.vars.seed.set(Number(process.argv[3]))
85
+ const execution = await growSplatFill.run({ log: true, save: { prefix: 'comfy-ts-example/grow-splat-fill' } })
86
+ for (const img of execution.images) console.log(`🟢 ${img.tags.join(',')} ${img.absPath}`)
87
+ host.disconnect()
88
+ }