The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Motion Mix: combine two camera motions or effects, each with a strength
Clauded4b10188f7bc
diff --git a/src/app/api/generations/route.ts b/src/app/api/generations/route.tsindex add034cf..a2056520 100644--- a/src/app/api/generations/route.ts+++ b/src/app/api/generations/route.ts@@ -42,6 +42,8 @@ const RequestSchema = z.object({}).optional(),presetOptions: z.record(z.string(), z.string()).optional(),+ presetStrength: z.number().min(0).max(1).optional(),+ mix: z.object({ presetId: z.string().max(120), strength: z.number().min(0).max(1) }).optional(),});export async function GET(request: Request) {diff --git a/src/components/studio/composer.tsx b/src/components/studio/composer.tsxindex 7230cfd7..7c94f61a 100644--- a/src/components/studio/composer.tsx+++ b/src/components/studio/composer.tsx@@ -21,6 +21,7 @@ import { useEffect, useMemo, useRef, useState } from "react";import { toast } from "sonner";import { Button } from "@/components/ui/button";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { Slider } from "@/components/ui/slider";import { Switch } from "@/components/ui/switch";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";import { Kbd } from "@/components/ui/kbd";@@ -168,11 +169,48 @@ function SegmentChip<T extends string | number>({);}+function PresetGrid({ list, value, onPick }: { list: Preset[]; value?: string; onPick: (id: string) => void }) {+ const [cat, setCat] = useState<string>("All");+ const cats = ["All", ...new Set(list.map((p) => p.category))];+ return (+ <>+ <div className="scrollbar-none mb-2 flex gap-1 overflow-x-auto">+ {cats.map((c) => (+ <button+ key={c}+ onClick={() => setCat(c)}+ className={cn("h-7 shrink-0 rounded-full px-2.5 text-[12px] font-medium text-muted-foreground hover:bg-accent", cat === c && "bg-secondary text-foreground")}+ >+ {c}+ </button>+ ))}+ </div>+ <div className="grid max-h-72 grid-cols-3 gap-1.5 overflow-y-auto">+ {list+ .filter((p) => cat === "All" || p.category === cat)+ .map((p) => {+ const PI = PRESET_ICONS[p.look.icon] ?? Film;+ return (+ <button+ key={p.id}+ onClick={() => onPick(p.id)}+ className={cn("group flex flex-col items-start gap-1 overflow-hidden rounded-lg p-1 text-left ring-primary transition hover:bg-accent", value === p.id && "ring-2")}+ >+ <span className="grid aspect-video w-full place-items-center rounded-md text-white" style={{ background: `linear-gradient(135deg, ${p.look.from}, ${p.look.to})` }}>+ <PI className="size-5 transition-transform duration-300 group-hover:scale-125" />+ </span>+ <span className="truncate px-0.5 text-[12px] font-medium">{p.name}</span>+ </button>+ );+ })}+ </div>+ </>+ );+}+function PresetChip({ type, value, onChange }: { type: "motion" | "effect"; value?: string; onChange: (id?: string) => void }) {const [open, setOpen] = useState(false);- const [cat, setCat] = useState<string>("All");const list = type === "motion" ? MOTIONS : EFFECTS;- const cats = ["All", ...new Set(list.map((p) => p.category))];const selected = value ? getPreset(value) : undefined;const Icon = selected ? (PRESET_ICONS[selected.look.icon] ?? Film) : Film;return (@@ -192,48 +230,77 @@ function PresetChip({ type, value, onChange }: { type: "motion" | "effect"; valu</Chip></PopoverTrigger><PopoverContent className="w-[min(92vw,460px)] p-2" align="start" side="top" collisionPadding={12}>- <div className="scrollbar-none mb-2 flex gap-1 overflow-x-auto">- {cats.map((c) => (- <button- key={c}- onClick={() => setCat(c)}- className={cn(- "h-7 shrink-0 rounded-full px-2.5 text-[12px] font-medium text-muted-foreground hover:bg-accent",- cat === c && "bg-secondary text-foreground",- )}- >- {c}- </button>- ))}- </div>- <div className="grid max-h-80 grid-cols-3 gap-1.5 overflow-y-auto">- {list- .filter((p) => cat === "All" || p.category === cat)- .map((p) => {- const PI = PRESET_ICONS[p.look.icon] ?? Film;- return (- <button- key={p.id}- onClick={() => {- onChange(p.id);- setOpen(false);- }}- className={cn(- "group flex flex-col items-start gap-1 overflow-hidden rounded-lg p-1 text-left ring-primary transition hover:bg-accent",- value === p.id && "ring-2",- )}- >- <span- className="grid aspect-video w-full place-items-center rounded-md text-white"- style={{ background: `linear-gradient(135deg, ${p.look.from}, ${p.look.to})` }}- >- <PI className="size-5 transition-transform duration-300 group-hover:scale-125" />- </span>- <span className="truncate px-0.5 text-[12px] font-medium">{p.name}</span>- </button>- );- })}+ <PresetGrid+ list={list}+ value={value}+ onPick={(id) => {+ onChange(id);+ setOpen(false);+ }}+ />+ </PopoverContent>+ </Popover>+ );+}++const MIXABLE = [...MOTIONS, ...EFFECTS];+const pct = (n: number) => `${Math.round(n * 100)}%`;++/** Higgsfield's Mix: a second motion or effect on top of the first, each with a strength. */+function MixChip({+ primary,+ strength,+ mix,+ onChange,+}: {+ primary: Preset;+ strength: number;+ mix?: { presetId: string; strength: number };+ onChange: (patch: { presetStrength?: number; mix?: { presetId: string; strength: number } | undefined }) => void;+}) {+ const [open, setOpen] = useState(false);+ const second = mix ? getPreset(mix.presetId) : undefined;+ return (+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ <Chip icon={Shuffle} active={!!second}>+ {second ? `+ ${second.name}` : "Mix"}+ {second && (+ <X+ className="-mr-1 size-3.5 opacity-70 hover:opacity-100"+ onClick={(e) => {+ e.stopPropagation();+ onChange({ mix: undefined });+ }}+ />+ )}+ </Chip>+ </PopoverTrigger>+ <PopoverContent className="w-[min(92vw,460px)] space-y-3 p-3" align="start" side="top" collisionPadding={12}>+ <div className="space-y-2.5">+ <div className="space-y-1.5">+ <div className="flex items-center justify-between text-[12px]">+ <span className="font-medium">{primary.name}</span>+ <span className="font-mono text-muted-foreground">{pct(strength)}</span>+ </div>+ <Slider min={0.1} max={1} step={0.05} value={[strength]} onValueChange={([v]) => onChange({ presetStrength: v })} aria-label={`${primary.name} strength`} />+ </div>+ {second && mix && (+ <div className="space-y-1.5">+ <div className="flex items-center justify-between text-[12px]">+ <span className="font-medium">{second.name}</span>+ <span className="font-mono text-muted-foreground">{pct(mix.strength)}</span>+ </div>+ <Slider min={0.1} max={1} step={0.05} value={[mix.strength]} onValueChange={([v]) => onChange({ mix: { ...mix, strength: v } })} aria-label={`${second.name} strength`} />+ </div>+ )}</div>+ <p className="text-[12px] text-muted-foreground">{second ? "Swap the second preset:" : "Pick a second motion or effect to combine with it:"}</p>+ <PresetGrid+ list={MIXABLE.filter((p) => p.id !== primary.id && !p.inputs.some((i) => i.key === "endImage"))}+ value={mix?.presetId}+ onPick={(id) => onChange({ mix: { presetId: id, strength: mix?.strength ?? 0.6 } })}+ /></PopoverContent></Popover>);@@ -272,6 +339,8 @@ function buildRequest(},params: draft.params,presetOptions: draft.presetOptions,+ ...(draft.presetId && draft.presetStrength !== undefined && draft.presetStrength < 1 && { presetStrength: draft.presetStrength }),+ ...(draft.presetId && draft.mix && { mix: draft.mix }),};}@@ -568,9 +637,12 @@ export function Composer({ docked }: { docked: boolean }) {<PresetChiptype={config.presetPicker}value={draft.presetId}- onChange={(id) => setDraft({ presetId: id })}+ onChange={(id) => setDraft(id ? { presetId: id } : { presetId: undefined, mix: undefined, presetStrength: undefined })}/>)}+ {preset && (preset.type === "motion" || preset.type === "effect") && (+ <MixChip primary={preset} strength={draft.presetStrength ?? 1} mix={draft.mix} onChange={(patch) => setDraft(patch)} />+ )}{opts.aspectRatios && opts.aspectRatios.length > 1 && op !== "i2v" && op !== "flf2v" && (<AspectChip options={opts.aspectRatios} value={p.aspectRatio} onChange={(v) => setP({ aspectRatio: v })} />)}diff --git a/src/components/studio/studio-context.tsx b/src/components/studio/studio-context.tsxindex 2ddf1400..0910518d 100644--- a/src/components/studio/studio-context.tsx+++ b/src/components/studio/studio-context.tsx@@ -47,6 +47,9 @@ export interface Draft {refs: SlotValue[];presetId?: string;presetOptions: Record<string, string>;+ /** Motions/effects: strength of the preset, and an optional second one mixed in (Mix). */+ presetStrength?: number;+ mix?: { presetId: string; strength: number };}interface Ctx {diff --git a/src/components/studio/studio-page.tsx b/src/components/studio/studio-page.tsxindex e28d9988..3b7dd7bd 100644--- a/src/components/studio/studio-page.tsx+++ b/src/components/studio/studio-page.tsx@@ -77,6 +77,8 @@ function draftFromGeneration(g: Generation, config: StudioConfig): Partial<Draftrefs,presetId: r.presetId,presetOptions: r.presetOptions ?? {},+ presetStrength: r.presetStrength,+ mix: r.mix,};}diff --git a/src/lib/catalog/plan.ts b/src/lib/catalog/plan.tsindex 25b30a76..248a29da 100644--- a/src/lib/catalog/plan.ts+++ b/src/lib/catalog/plan.ts@@ -39,6 +39,9 @@ export function routesFor(model: ModelDef, op: Operation): ModelRoute[] {return model.routes.filter((r) => r.op === op);}+const clamp01 = (n: number) => Math.max(0, Math.min(1, Number.isFinite(n) ? n : 1));+const round2 = (n: number) => Math.round(n * 100) / 100;+/** Fill a preset prompt template: {prompt} and {option:key}. Collapses leftover whitespace. */export function composePrompt(template: string,@@ -122,6 +125,25 @@ export function planGeneration(if (sameModel) op = op ?? route.op;}+ if (preset && /motion|effect/.test(preset.type)) {+ const k = clamp01(req.presetStrength ?? 1);+ if (k < 1) loras = loras.map((l) => ({ ...l, strength: round2((l.strength ?? 1) * k) }));+ if (req.mix) {+ const second = getPreset(req.mix.presetId);+ if (!second || !/motion|effect/.test(second.type)) throw new Error("Pick a camera motion or effect to mix in");+ if (second.id !== preset.id) {+ const m = clamp01(req.mix.strength);+ // The second preset's own words, without the user's prompt; worded by strength.+ const words = composePrompt(second.promptTemplate.replace(/\{prompt\}\.?/g, ""), "", second, undefined).replace(/[.\s]+$/, "");+ const lead = m >= 0.75 ? "At the same time" : m >= 0.4 ? "Also, more subtly" : "With a slight hint of this";+ prompt = `${prompt.replace(/[.\s]+$/, "")}. ${lead}: ${words.charAt(0).toLowerCase()}${words.slice(1)}.`;+ // Its LoRAs stack on the same open model, scaled by the mix strength.+ const route = presetRoute(second, model.engine);+ if (route?.modelId === model.id && route.loras?.length) loras = [...loras, ...route.loras.map((l) => ({ ...l, strength: round2((l.strength ?? 1) * m) }))];+ }+ }+ }+if (req.loras?.length) loras = [...loras, ...req.loras];// Multi-shot: the clip is as long as its shots, and models without per-shot prompts get them written out.diff --git a/src/lib/catalog/types.ts b/src/lib/catalog/types.tsindex 0e315cb9..13603477 100644--- a/src/lib/catalog/types.ts+++ b/src/lib/catalog/types.ts@@ -321,6 +321,10 @@ export interface GenerationRequest {params?: GenParams;/** Values for preset option pickers (apps). */presetOptions?: Record<string, string>;+ /** Motions/effects: how strongly the preset applies (0–1, default 1). */+ presetStrength?: number;+ /** Higgsfield's Mix: a second motion or effect on top of the first, with its own strength. */+ mix?: { presetId: string; strength: number };/** Server-side only: LoRAs added by @element mentions (trained identities). */loras?: LoraRef[];/** Chained jobs: where the previous job's image goes among `inputs.images` (one dependency). */diff --git a/tests/plan.test.ts b/tests/plan.test.tsindex 18889ecd..76d36cf7 100644--- a/tests/plan.test.ts+++ b/tests/plan.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { getModel, getPreset } from "@/lib/catalog";+import { getModel, getPreset, PRESETS } from "@/lib/catalog";import { composePrompt, estimateCost, inferOperation, missingInputs, planGeneration } from "@/lib/catalog/plan";describe("inferOperation", () => {@@ -63,3 +63,27 @@ describe("estimateCost", () => {expect(estimateCost(getModel("oss-wan22-14b")!, {})).toBe(0);});});++describe("motion mix", () => {+ const base = { feature: "motion", presetId: "motion-crash-zoom-in", prompt: "a boxer in the ring" };+ it("adds the second preset's words, worded by strength", () => {+ const strong = planGeneration({ ...base, modelId: "kling-2-5-turbo", inputs: { images: ["a.png"] }, mix: { presetId: "motion-handheld", strength: 0.9 } }, getModel, getPreset);+ expect(strong.prompt).toMatch(/^a boxer in the ring\. .+ At the same time: /);+ const faint = planGeneration({ ...base, modelId: "kling-2-5-turbo", inputs: { images: ["a.png"] }, mix: { presetId: "motion-handheld", strength: 0.2 } }, getModel, getPreset);+ expect(faint.prompt).toMatch(/With a slight hint of this: /);+ expect(() => planGeneration({ ...base, modelId: "kling-2-5-turbo", inputs: { images: ["a.png"] }, mix: { presetId: "app-relight", strength: 0.5 } }, getModel, getPreset)).toThrow(/camera motion or effect/);+ });++ it("stacks LoRAs on the open model, scaled by each strength", () => {+ const withLora = PRESETS.filter((p) => /motion|effect/.test(p.type) && p.open?.modelId === "oss-wan22-14b" && p.open.loras?.length);+ const [a, b] = withLora;+ const plan = planGeneration(+ { feature: "motion", presetId: a.id, modelId: "oss-wan22-14b", prompt: "x", inputs: { images: ["a.png"] }, presetStrength: 0.5, mix: { presetId: b.id, strength: 0.5 } },+ getModel,+ getPreset,+ );+ expect(plan.loras).toHaveLength(a.open!.loras!.length + b.open!.loras!.length);+ expect(plan.loras[0].strength).toBeCloseTo((a.open!.loras![0].strength ?? 1) * 0.5);+ expect(plan.loras.at(-1)!.strength).toBeCloseTo((b.open!.loras!.at(-1)!.strength ?? 1) * 0.5);+ });+});