Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(create-3d): picture first in the cloud, an open image model then TRELLIS.2

purplea367c853c284
diff --git a/src/components/create/experimental/Composer.tsx b/src/components/create/experimental/Composer.tsx
index 6c6b8cd9..b2623f80 100644
--- a/src/components/create/experimental/Composer.tsx
+++ b/src/components/create/experimental/Composer.tsx
@@ -38,6 +38,7 @@ import { PromptAssistant } from './PromptAssistant'
import { SpecialControls } from './SpecialIntentControls'
import { ThreeDControls } from './ThreeDControls'
import { threeDControlFacts } from '../../../lib/three/three-d-models'
+import { isPictureFirstRun, pictureStepCredits } from '../../../lib/three/picture-first'
import { CreditsMeter } from './CreditsMeter'
import { Button } from '../ui/Button'
import { PromptField } from '../ui/PromptField'
@@ -273,7 +274,7 @@ export function Composer({ onOpenAdvanced, onOpenWorkflows }: Props) {
meterState(
quota,
imageCount * (studioPick
- ? (studioPrice?.credits ?? costFallback)
+ ? (studioPrice?.credits ?? costFallback) + pictureStepCredits(intent, threeDWay, studioPick, prompt)
: lengthRate
? (cloudStudioCredits ?? lengthShown ?? costFallback)
: runCredits(intentKind, intentOp, runModel, runSeconds, costFallback, targetResolution)),
@@ -394,7 +395,7 @@ export function Composer({ onOpenAdvanced, onOpenWorkflows }: Props) {
Befund und hier nicht behoben. */}
<div className="mx-auto w-full max-w-[660px] space-y-2.5">
{special && <SpecialControls intent={intent} />}
- {intent === '3d' && <ThreeDControls {...threeDControlFacts(backend, studioPick)} studioId={studioPick} />}
+ {intent === '3d' && <ThreeDControls {...threeDControlFacts(backend, studioPick)} studioId={studioPick} pictureFirst={backend === 'local' || isPictureFirstRun(threeDWay, studioPick)} />}
{!isUtility && <LaneControls />}
<CharacterNote />
{inputNote && (
diff --git a/src/components/create/experimental/ModelChip.tsx b/src/components/create/experimental/ModelChip.tsx
index 354bab82..c6e0fd09 100644
--- a/src/components/create/experimental/ModelChip.tsx
+++ b/src/components/create/experimental/ModelChip.tsx
@@ -1,4 +1,5 @@
import { MAC_3D_MODEL, PC_3D_MODEL } from '../../../lib/three/run-local-3d'
+import { isPictureFirstRun, pictureFirstPictureCredits } from '../../../lib/three/picture-first'
import { useCreateStore } from '../../../stores/createStore'
import {
useCloudCatalogStore, cloudModelById, defaultCloudModel, opPickerModels, modelCostHint, shortCount,
@@ -179,7 +180,10 @@ function CloudModelChip() {
? groupForPicker(roleModels).map(({ model: m, group }) => ({
value: m.id,
label: m.label,
- sublabel: pickerCostHint(m, musicDuration),
+ // "Picture first" costs the picture and the model together.
+ sublabel: pickIntent === '3d-text' && isPictureFirstRun('text', m.id)
+ ? `${shortCount(createStudioCost(m.id, {}, 100) + pictureFirstPictureCredits(''))} cr`
+ : pickerCostHint(m, musicDuration),
group,
tags: tierMarks(m),
badge: m.adult
diff --git a/src/components/create/experimental/Stage.tsx b/src/components/create/experimental/Stage.tsx
index d8d03d42..33a55863 100644
--- a/src/components/create/experimental/Stage.tsx
+++ b/src/components/create/experimental/Stage.tsx
@@ -594,6 +594,8 @@ function SourcePreview({ onOpenMaskEditor }: { onOpenMaskEditor: () => void }) {
: `Write your prompt below, then Create. All ${batchCount} images get the same edit.`
) : meta.id === 'removebg' ? 'Hit Create to cut out the subject and export a transparent PNG.'
: meta.id === 'upscale' ? 'Hit Create to upscale the image.'
+ // 3D reads no prompt from a picture: the picture is all it needs.
+ : meta.id === '3d' ? THREE_D_TEXT.stageReady
: meta.id === 'eraser' ? (mask ? 'Mask ready. Hit Create.' : 'Paint a mask over the object to remove, then hit Create.')
: noMask ? 'Write the edit prompt below, then Create. This model needs no mask.'
// A cloud model that edits through a mask does not start without
diff --git a/src/components/create/experimental/ThreeDControls.tsx b/src/components/create/experimental/ThreeDControls.tsx
index c356f4e6..aa5cbebc 100644
--- a/src/components/create/experimental/ThreeDControls.tsx
+++ b/src/components/create/experimental/ThreeDControls.tsx
@@ -29,9 +29,12 @@ export interface ThreeDControlsProps {
hasCutout: boolean
/** The cloud model that will run, when there is one. */
studioId?: string
+ /** "From text" paints a picture first (always locally, in the cloud on
+ * "Picture first"). */
+ pictureFirst?: boolean
}
-export function ThreeDControls({ maxViews, hasDetail, hasCutout, studioId }: ThreeDControlsProps) {
+export function ThreeDControls({ maxViews, hasDetail, hasCutout, studioId, pictureFirst }: ThreeDControlsProps) {
const way = useCreateStore((s) => s.threeDWay)
const setWay = useCreateStore((s) => s.setThreeDWay)
const cutout = useCreateStore((s) => s.threeDCutout)
@@ -58,7 +61,7 @@ export function ThreeDControls({ maxViews, hasDetail, hasCutout, studioId }: Thr
onChange={setWay}
options={WAYS.map((w) => ({ value: w, label: T.ways[w] }))}
/>
- {way === 'text' && backend === 'local' && <p className="t-meta text-gray-400" data-testid="three-d-picture-first">{T.pictureFirst}</p>}
+ {way === 'text' && pictureFirst && <p className="t-meta text-gray-400" data-testid="three-d-picture-first">{T.pictureFirst}</p>}
{way === 'image' && maxViews > 1 && <SideStrip maxViews={maxViews} />}
{way === 'video' && <VideoFrames maxViews={maxViews} />}
<div className="flex flex-wrap items-center gap-4">
diff --git a/src/components/create/experimental/useRunCredits.ts b/src/components/create/experimental/useRunCredits.ts
index 83b072f7..95b19916 100644
--- a/src/components/create/experimental/useRunCredits.ts
+++ b/src/components/create/experimental/useRunCredits.ts
@@ -5,6 +5,7 @@ import { lengthCredits, lengthPrice, runCredits } from '../../../stores/cloudCat
import { createRunModel, createStudioCost, isStudioModel, startImageCount, studioIntentOf } from '../../../lib/render/create-studio'
import { STUDIO_MODELS } from '../../../lib/render/studio-contract'
import { runImageCount } from '../../../lib/render/image-count'
+import { pictureStepCredits } from '../../../lib/three/picture-first'
/** What the cloud run on screen costs. One reader for the meter chip and for
* the list of several source images, so both name the same number. */
@@ -92,7 +93,8 @@ export function useRunCredits(): RunCredits | null {
const unitCost = lengthRate
? cloudStudioCredits ?? lengthCredits(model, lengthRate.basis === 'chars' ? Array.from(prompt).length || undefined : undefined)
: studioPick
- ? cloudStudioCredits ?? createStudioCost(studioPick, cloudStudioOptions, Array.from(prompt).length, undefined, startImageCount(studioPick, extraPhotos) ?? 1)
+ ? (cloudStudioCredits ?? createStudioCost(studioPick, cloudStudioOptions, Array.from(prompt).length, undefined, startImageCount(studioPick, extraPhotos) ?? 1))
+ + pictureStepCredits(intent, threeDWay, studioPick, prompt)
: runCredits(kind, op, model, seconds, quota.costs[quotaCostKind(kind)], targetResolution)
// Mehrere Bilder: jedes ist ein eigener Auftrag zum vollen Preis, die Summe
// ist, was der Lauf bindet. Der Zaehler "noch N Bilder" rechnet je Bild.
diff --git a/src/hooks/useCloudCreate.ts b/src/hooks/useCloudCreate.ts
index 6073e172..87442ff0 100644
--- a/src/hooks/useCloudCreate.ts
+++ b/src/hooks/useCloudCreate.ts
@@ -25,6 +25,7 @@ import {
pollJob,
submitCloudJob,
uploadInput,
+ adoptInput,
CloudJobError,
QuoteChangedError,
type CloudJobParams,
@@ -40,6 +41,9 @@ import { intentRoles, intentRequiredInputs, isStudioModel, resolveIntentPick, st
import { threeDMaxViews } from '../lib/three/three-d-models'
import { threeDProvenance } from '../lib/three/run-local-3d'
import { THREE_D_TEXT } from '../lib/three/three-d-text'
+import { isPictureFirstRun, pictureFirstPictureCredits, pictureFirstPictureModel } from '../lib/three/picture-first'
+import { runCloudPictureFirst } from '../lib/three/cloud-picture-first'
+import { loadImageRef } from '../components/create/experimental/loadImage'
import { bumpSeed, runImageCount } from '../lib/render/image-count'
import { STUDIO_MODELS, studioFields } from '../lib/render/studio-contract'
import { modelLabel } from '../lib/render/preset-models'
@@ -249,6 +253,10 @@ let activeJobId: string | null = null
// activeJobId. Cancel bricht jeden einzelnen ab.
let activeJobIds: string[] = []
let activeAbort: AbortController | null = null
+// Cancel was pressed during this run. A chain of two runs ("Picture first")
+// reads it before it books the second, also when the first could no longer
+// be stopped.
+let stopAsked = false
/** True while a cloud run (generate or enhance) is in flight. CreateContext
* routes Cancel by the backend that STARTED the run, not the current axis —
@@ -268,6 +276,146 @@ export function takeCloudRunStop(): CloudRunStop | null {
return stop
}
+/**
+ * "Picture first" (lib/three/picture-first.ts) with the real cloud calls and
+ * the store. Errors that are not about this chain (429, 401, a dropped line)
+ * go to the caller's catch, like every other run.
+ */
+async function runPictureFirst(args: {
+ prompt: string
+ meshModel: string
+ meshOptions: Record<string, unknown>
+ requestId: string
+ ac: AbortController
+ onQuotaChange?: () => void
+}): Promise<void> {
+ const { prompt, meshModel, meshOptions, ac, onQuotaChange } = args
+ const s = useCreateStore.getState()
+ const pictureModel = pictureFirstPictureModel()
+ if (!pictureModel) {
+ s.setError('Picture first is not available right now. Pick another model.')
+ return
+ }
+ const pictureShown = pictureFirstPictureCredits(prompt, pictureModel)
+ const timeoutMs = runDeadlineMs('3d', 'studio')
+ const startedAt = Date.now()
+ let stepStarted = startedAt
+ // What each job adds to the bare job in the gallery (also the entry a
+ // phone lands after a restart, lib/pending-cloud-jobs.ts).
+ const pictureFields = (picturePrompt: string) => ({
+ model: pictureModel, prompt: picturePrompt, negativePrompt: '', seed: 0,
+ steps: 0, cfgScale: 0, sampler: '', scheduler: '', width: 1024, height: 1024, intent: 'image' as const,
+ })
+ const meshFields = () => ({
+ model: meshModel, prompt: '', label: prompt.trim().slice(0, 120) || THREE_D_TEXT.gallery.text, negativePrompt: '', seed: 0,
+ steps: 0, cfgScale: 0, sampler: '', scheduler: '', width: 0, height: 0, intent: '3d' as const,
+ })
+ const outcome = await runCloudPictureFirst({
+ prompt, pictureModel, meshModel, meshOptions,
+ shown: { mesh: s.cloudStudioCredits, picture: pictureShown },
+ requestIds: [args.requestId, crypto.randomUUID()],
+ }, {
+ gate: (text) => clientSafety(text),
+ quote: async (model, text, options, images) => {
+ s.setProgress(4, 'Confirming the price…')
+ return (await studioQuote(model, text, { op: 'studio', studio_options: options }, images)).credits
+ },
+ submit: async (job) => {
+ s.setProgress(job.kind === 'image' ? 6 : 52, 'Submitting to the render queue…')
+ const step = job.kind === 'image' ? pictureFields(job.prompt) : meshFields()
+ const out = await submitNoted({ kind: job.kind, model: job.model, prompt: job.prompt, params: job.params }, {
+ op: 'studio', prompt: job.prompt || step.label || '', timeoutMs, landing: 'gallery', items: [step],
+ })
+ const now = Date.now()
+ notePendingCloudJob({
+ id: out.id, kind: job.kind, op: 'studio', model: job.model, prompt: job.prompt || step.label || '',
+ startedAt: now, deadlineAt: now + timeoutMs, landing: 'gallery', item: step,
+ })
+ if (job.params.client_request_id) settleCloudSubmitIntent(job.params.client_request_id, true)
+ return out
+ },
+ onBooked: (id, step) => {
+ activeJobId = id
+ activeJobIds = [id]
+ stepStarted = Date.now()
+ onQuotaChange?.()
+ if (step === 1 && prompt.trim()) useCreateStore.getState().addToPromptHistory(prompt.trim())
+ },
+ poll: (id, step) => pollTracked(id, {
+ timeoutMs,
+ signal: ac.signal,
+ onTick: (j) => {
+ const st = useCreateStore.getState()
+ const elapsed = Math.round((Date.now() - stepStarted) / 1000)
+ const verb = step === 1 ? THREE_D_TEXT.cloudPicture : THREE_D_TEXT.cloudPhase
+ if (j.status === 'queued') {
+ st.setProgressPhase('queued')
+ st.setProgress(step === 1 ? 10 : 55, `Waiting for a cloud GPU… ${elapsed}s`)
+ } else if (j.status === 'running') {
+ st.setProgressPhase('sampling')
+ st.setProgress(step === 1 ? Math.min(45, 12 + elapsed) : Math.min(95, 58 + elapsed), `${verb} ${elapsed}s`)
+ }
+ },
+ }),
+ adopt: (jobId) => adoptInput(jobId, 'image'),
+ onPicture: async (job, picturePrompt) => {
+ // The first job is over: Cancel from here on only stops the chain.
+ activeJobId = null
+ activeJobIds = []
+ const st = useCreateStore.getState()
+ // The picture is a result of its own. Landing it must not change the
+ // model the Image tab has picked.
+ const imagePick = st.cloudImageModel
+ st.addToGallery({ ...galleryItemFromJob(job), ...pictureFields(picturePrompt) })
+ if (useCreateStore.getState().cloudImageModel !== imagePick) useCreateStore.getState().setCloudImageModel(imagePick)
+ st.setProgress(50, THREE_D_TEXT.afterPicture)
+ // Onto the Stage under "From image", like the local way: the user sees
+ // it while the model is built, and "Make it 3D" runs it again.
+ try {
+ const res = await fetch(job.result_url!)
+ if (!res.ok) throw new Error('picture')
+ const blob = await res.blob()
+ const ref = await loadImageRef(new File([blob], 'picture.png', { type: blob.type || 'image/png' }))
+ const now = useCreateStore.getState()
+ now.setThreeDWay('image')
+ now.setSource(ref)
+ } catch {
+ // The Stage is a view. The picture is in the gallery, the chain goes on.
+ }
+ },
+ stopped: () => stopAsked || ac.signal.aborted,
+ })
+ const st = useCreateStore.getState()
+ switch (outcome.kind) {
+ case 'blocked':
+ st.setError(blockMessageFor(outcome.reason))
+ return
+ case 'price':
+ // Same rule as a single studio run: show the new sum, book nothing.
+ st.setCloudStudioCredits(outcome.mesh)
+ st.setError(`The price changed to ${outcome.total.toLocaleString('en-US')} credits. Review it, then hit Create again.`)
+ lastRunStop = { reason: 'price' }
+ return
+ case 'stopped':
+ st.setError(null)
+ onQuotaChange?.()
+ return
+ case 'picture-failed':
+ st.setError(outcome.job.error ?? 'Cloud render failed.')
+ onQuotaChange?.()
+ return
+ case 'mesh-failed':
+ st.setError([THREE_D_TEXT.meshFailed, outcome.job.error, THREE_D_TEXT.meshRetry].filter(Boolean).join(' '))
+ onQuotaChange?.()
+ return
+ case 'done':
+ st.setProgressPhase('complete')
+ st.setProgress(100, 'Complete!')
+ st.addToGallery({ ...galleryItemFromJob(outcome.mesh), ...meshFields() })
+ return
+ }
+}
+
export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {
const { onQuotaChange } = opts
@@ -275,6 +423,7 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {
const s = useCreateStore.getState()
if (s.isGenerating) return
lastRunStop = null
+ stopAsked = false
const intent = s.intent()
let { kind, op } = intentToJob(intent)
// Character-Studio 'use' surface: a plain image generate with the trained
@@ -468,6 +617,12 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {
const requestId = crypto.randomUUID()
try {
+ // 3D from words on an image-to-3D model: a picture first, then the
+ // model from it (lib/three/cloud-picture-first.ts).
+ if (studioModel && isPictureFirstRun(intent === '3d' ? s.threeDWay : undefined, studioModel)) {
+ await runPictureFirst({ prompt, meshModel: studioModel, meshOptions: studioOptionsFiltered ?? {}, requestId, ac, onQuotaChange })
+ return
+ }
// Utility endpoints (removebg/upscale/eraser) and the 2.5.8 specialized
// ops take no generation knobs — send only what the op consumes so the
// submit schema stays honest.
@@ -1011,6 +1166,7 @@ export function useCloudCreate(opts: { onQuotaChange?: () => void } = {}) {
}, [onQuotaChange])
const cancel = useCallback(async () => {
+ stopAsked = true
const ids = activeJobIds.length ? activeJobIds : activeJobId ? [activeJobId] : []
if (!ids.length) {
activeAbort?.abort()
diff --git a/src/lib/render/create-studio.ts b/src/lib/render/create-studio.ts
index 46cbd56b..b48c9f54 100644
--- a/src/lib/render/create-studio.ts
+++ b/src/lib/render/create-studio.ts
@@ -14,6 +14,8 @@ import { STUDIO_MODELS, studioBaseCredits, studioFields, studioPreviewCredits, s
import { presetModels, requiredRoleInputs, type PresetModel, type StepRole } from './preset-models'
import { cloudModelById, defaultCloudModel, modelForOp, opPickerModels, resolveCharacterModel, resolveOpPick } from '../../stores/cloudCatalogStore'
import { intentToJob, type CreateIntentLike } from './cloud-jobs'
+import { PICTURE_FIRST_MESH, pictureFirstOffered } from '../three/picture-first'
+import { THREE_D_TEXT } from '../three/three-d-text'
// Desktop port (P2, checked again in P9): the web's CreateIntent already
// carries 'video_upscale' as a distinct intent from the plain 'upscale'
@@ -92,6 +94,13 @@ export function intentPickerModels(intent: StudioIntent): PresetModel[] {
if (intent === 'lipsync') for (const m of opPickerModels('lipsync')) {
add({ id: m.id, label: m.label, kind: m.kind, op: 'lipsync', adult: m.adult === true, tier: m.tier, weights: m.weights })
}
+ // 3D from words: "Picture first" leads the list, as the image-to-3D model
+ // it ends on (lib/three/picture-first.ts). It is the one way from words
+ // that no text-to-3D filter stands in.
+ if (intent === '3d-text' && pictureFirstOffered()) {
+ const mesh = presetModels('mesh-image').find((m) => m.id === PICTURE_FIRST_MESH)
+ if (mesh) add({ ...mesh, label: THREE_D_TEXT.pictureFirstSwitch })
+ }
for (const role of roles) for (const m of presetModels(role)) add(m)
return out
}
diff --git a/src/lib/three/cloud-picture-first.ts b/src/lib/three/cloud-picture-first.ts
new file mode 100644
index 00000000..ca78de92
--- /dev/null
+++ b/src/lib/three/cloud-picture-first.ts
@@ -0,0 +1,116 @@
+// The two cloud runs of "Picture first" (lib/three/picture-first.ts), in
+// order, with everything that talks to the cloud handed in. The hook
+// (hooks/useCloudCreate.ts) hands in the real calls and the store, the tests
+// hand in fakes.
+//
+// 1. The content gate reads the prompt and the words added for the picture.
+// 2. Both prices are confirmed before anything is booked. Their sum is what
+// the button showed; a higher sum stops here and shows the new number.
+// 3. The open image model paints the picture. It lands in the gallery as a
+// picture and on the Stage under "From image", whatever happens after.
+// 4. The gate reads again, now with where the picture came from (the user's
+// words), as it does for every picture a 3D run takes.
+// 5. The server copies the picture into the inputs (POST /api/jobs/adopt), it
+// never goes through the customer's line again, and the image-to-3D model
+// builds from it. The words go along as `source_prompt` for the server's
+// own gate.
+//
+// A failed or stopped second step costs nothing (the server refunds it) and
+// takes nothing away: the picture stays, and "Make it 3D" runs it again.
+import type { CloudJob, CloudJobParams } from '../../api/cloud/jobs'
+import type { SafetyVerdict } from '../render/safety'
+import { THREE_D_TEXT } from './three-d-text'
+import { threeDPicturePrompt } from './picture-prompt'
+
+export interface PictureFirstPlan {
+ /** What the user typed. */
+ prompt: string
+ /** The open image model that paints (pictureFirstPictureModel). */
+ pictureModel: string
+ /** The image-to-3D model the user picked as "Picture first". */
+ meshModel: string
+ /** The studio options of the mesh model (detail step, drawer). */
+ meshOptions: Record<string, unknown>
+ /** What the button showed: the mesh price (null before the first paint)
+ * and the picture price. */
+ shown: { mesh: number | null; picture: number }
+ /** One idempotency key per booking. */
+ requestIds: [string, string]
+}
+
+export interface PictureFirstDeps {
+ gate: (text: string) => SafetyVerdict
+ quote: (model: string, prompt: string, options: Record<string, unknown>, images?: number) => Promise<number>
+ submit: (job: { kind: 'image' | '3d'; model: string; prompt: string; params: CloudJobParams }) => Promise<{ id: string }>
+ poll: (id: string, step: 1 | 2) => Promise<CloudJob>
+ adopt: (jobId: string) => Promise<string>
+ /** The picture is done: into the gallery and onto the Stage. */
+ onPicture: (job: CloudJob, picturePrompt: string) => Promise<void>
+ /** A job was booked (for Cancel and the progress line). */
+ onBooked: (id: string, step: 1 | 2) => void
+ /** The user asked to stop. Checked before every booking. */
+ stopped: () => boolean
+}
+
+export type PictureFirstOutcome =
+ | { kind: 'blocked'; step: 1 | 2; reason?: string }
+ /** The confirmed sum is higher than the shown one: nothing was booked. */
+ | { kind: 'price'; total: number; mesh: number }
+ | { kind: 'stopped'; picture?: CloudJob }
+ | { kind: 'picture-failed'; job: CloudJob }
+ | { kind: 'mesh-failed'; picture: CloudJob; job: CloudJob }
+ | { kind: 'done'; picture: CloudJob; mesh: CloudJob }
+
+/** The text the gate and the server read for the second step: the user's
+ * words and the words the picture was painted with. */
+export function pictureFirstProvenance(prompt: string): string {
+ return `${prompt.trim()} ${threeDPicturePrompt(prompt)}`
+}
+
+export async function runCloudPictureFirst(plan: PictureFirstPlan, deps: PictureFirstDeps): Promise<PictureFirstOutcome> {
+ const picturePrompt = threeDPicturePrompt(plan.prompt)
+ const first = deps.gate(`${plan.prompt} ${picturePrompt}`)
+ if (first.blocked) return { kind: 'blocked', step: 1, reason: first.reason }
+
+ // Both prices before the first booking. The mesh is priced for the one
+ // picture it will read, before that picture exists.
+ const [picture, mesh] = await Promise.all([
+ deps.quote(plan.pictureModel, picturePrompt, {}),
+ deps.quote(plan.meshModel, '', plan.meshOptions, 1),
+ ])
+ if (plan.shown.mesh !== null && picture + mesh > plan.shown.mesh + plan.shown.picture) {
+ return { kind: 'price', total: picture + mesh, mesh: picture + mesh - plan.shown.picture }
+ }
+ if (deps.stopped()) return { kind: 'stopped' }
+
+ const one = await deps.submit({
+ kind: 'image', model: plan.pictureModel, prompt: picturePrompt,
+ params: { op: 'studio', studio_options: {}, client_request_id: plan.requestIds[0], max_credits: picture },
+ })
+ deps.onBooked(one.id, 1)
+ const pictureJob = await deps.poll(one.id, 1)
+ if (pictureJob.status === 'canceled') return { kind: 'stopped' }
+ if (pictureJob.status !== 'succeeded' || !pictureJob.result_url) return { kind: 'picture-failed', job: pictureJob }
+ await deps.onPicture(pictureJob, picturePrompt)
+
+ const provenance = pictureFirstProvenance(plan.prompt)
+ const second = deps.gate(provenance)
+ if (second.blocked) return { kind: 'blocked', step: 2, reason: second.reason }
+ if (deps.stopped()) return { kind: 'stopped', picture: pictureJob }
+
+ const sourcePath = await deps.adopt(pictureJob.id)
+ if (deps.stopped()) return { kind: 'stopped', picture: pictureJob }
+ const two = await deps.submit({
+ kind: '3d', model: plan.meshModel, prompt: '',
+ params: {
+ op: 'studio', studio_options: plan.meshOptions, client_request_id: plan.requestIds[1],
+ max_credits: mesh, source_path: sourcePath, source_prompt: provenance,
+ label: plan.prompt.trim().slice(0, 120) || THREE_D_TEXT.gallery.text,
+ },
+ })
+ deps.onBooked(two.id, 2)
+ const meshJob = await deps.poll(two.id, 2)
+ if (meshJob.status === 'canceled') return { kind: 'stopped', picture: pictureJob }
+ if (meshJob.status !== 'succeeded' || !meshJob.result_url) return { kind: 'mesh-failed', picture: pictureJob, job: meshJob }
+ return { kind: 'done', picture: pictureJob, mesh: meshJob }
+}
diff --git a/src/lib/three/picture-first.ts b/src/lib/three/picture-first.ts
new file mode 100644
index 00000000..268b3d7a
--- /dev/null
+++ b/src/lib/three/picture-first.ts
@@ -0,0 +1,58 @@
+// "Picture first" in the cloud (3.1.0, C3D-PLAN 1.2): 3D from words as two
+// cloud runs. An open image model paints one object, then an image-to-3D
+// model builds the mesh from that picture. The text-to-3D endpoints filter
+// (one blocked a museum statue in the measurement run); this way needs none
+// of them.
+//
+// The pick is the image-to-3D model itself: in the "From text" list it stands
+// as "Picture first", so price, detail step and settings drawer read its own
+// schema like any studio model. Only the start (hooks/useCloudCreate.ts)
+// knows it paints a picture before.
+import { STUDIO_MODELS, studioBaseCredits, studioPreviewCredits } from '../render/studio-contract'
+import { studioEntries } from '../../stores/cloudCatalogStore'
+import { contentPolicyCap } from '../content-policy-cap'
+import { threeDPicturePrompt } from './picture-prompt'
+
+/** The image-to-3D model that builds from the painted picture. */
+export const PICTURE_FIRST_MESH = 'trellis-2'
+
+/** Open image models the provider runs with its own filter off, best first.
+ * Z-Image Base: open weights, the cheapest flat price of the open ones. */
+const OPEN_PICTURE_MODELS = ['z-image']
+
+/** A build that caps the content policy (a store build of the phone app) does
+ * not list the models without a filter, so it does not run one unseen
+ * either. It paints with an open model that keeps the provider's filter. */
+const CAPPED_PICTURE_MODELS = ['qwen-image-2.1']
+
+/** The image model that paints the picture, or undefined when the server
+ * lists none of them. */
+export function pictureFirstPictureModel(): string | undefined {
+ const ids = contentPolicyCap() ? CAPPED_PICTURE_MODELS : OPEN_PICTURE_MODELS
+ return studioEntries(ids)[0]?.id
+}
+
+/** True when the server lists both halves of the chain. */
+export function pictureFirstOffered(): boolean {
+ return !!pictureFirstPictureModel() && studioEntries([PICTURE_FIRST_MESH]).length > 0
+}
+
+/** A run of the "From text" way on a model that reads a picture is a
+ * picture-first run. */
+export function isPictureFirstRun(way: string | undefined, model: string | undefined): boolean {
+ const m = model ? STUDIO_MODELS[model] : undefined
+ return way === 'text' && m?.kind === '3d' && Object.values(m.inputs).includes('source_path')
+}
+
+/** The credits of the picture step, from the image model's own flat price. */
+export function pictureFirstPictureCredits(prompt: string, model = pictureFirstPictureModel()): number {
+ if (!model) return 0
+ return studioPreviewCredits(model, {}, undefined, 1, Array.from(threeDPicturePrompt(prompt)).length) ?? studioBaseCredits(model)
+}
+
+/** What a run adds to the price of its model: the picture step of a
+ * picture-first run, 0 for every other run. Meter, button and picker add
+ * it to the model's own price, so they show the sum the two runs book. */
+export function pictureStepCredits(intent: string, way: string | undefined, model: string | undefined, prompt: string): number {
+ return intent === '3d' && isPictureFirstRun(way, model) ? pictureFirstPictureCredits(prompt) : 0
+}
diff --git a/src/lib/three/picture-prompt.ts b/src/lib/three/picture-prompt.ts
new file mode 100644
index 00000000..62f6267c
--- /dev/null
+++ b/src/lib/three/picture-prompt.ts
@@ -0,0 +1,9 @@
+// The words a two-step "From text" adds to the prompt of its picture, locally
+// (hooks/useCreate.ts) and in the cloud (lib/three/cloud-picture-first.ts).
+
+/** Steers the picture towards what an image-to-3D model reads best: one
+ * object, whole, on a plain ground. */
+export function threeDPicturePrompt(prompt: string): string {
+ const p = prompt.trim().replace(/[.,;\s]+$/, '')
+ return `${p}, a single object, whole and centered, plain light background, soft studio light, three-quarter view`
+}
diff --git a/src/lib/three/run-local-3d.ts b/src/lib/three/run-local-3d.ts
index 15da6e7f..27949437 100644
--- a/src/lib/three/run-local-3d.ts
+++ b/src/lib/three/run-local-3d.ts
@@ -14,12 +14,7 @@ import { THREE_D_TEXT } from './three-d-text'
export const MAC_3D_MODEL = 'TripoSR'
export const PC_3D_MODEL = 'TRELLIS.2'
-/** The words that steer the picture of a two-step "From text" towards what an
- * image-to-3D model reads best: one object, whole, on a plain ground. */
-export function threeDPicturePrompt(prompt: string): string {
- const p = prompt.trim().replace(/[.,;\s]+$/, '')
- return `${p}, a single object, whole and centered, plain light background, soft studio light, three-quarter view`
-}
+export { threeDPicturePrompt } from './picture-prompt'
/** The text the content gate reads besides the prompt: the names of every
* picture the run takes, and what the gallery knows about where they came
diff --git a/src/lib/three/three-d-text.ts b/src/lib/three/three-d-text.ts
index 0dd544a4..bb1d7004 100644
--- a/src/lib/three/three-d-text.ts
+++ b/src/lib/three/three-d-text.ts
@@ -1,6 +1,6 @@
// Every sentence of the 3D tab (C3D-PLAN 1.8), in one place for the desktop
// and the phone. English, short, plain, no closing phrase.
-import type { ThreeDDetail, ThreeDWay } from '../../stores/createStore'
+import type { ThreeDDetail, ThreeDWay } from './three-d-types'
export const THREE_D_TEXT = {
ways: { text: 'From text', image: 'From image', video: 'From video' } as Record<ThreeDWay, string>,
@@ -34,6 +34,10 @@ export const THREE_D_TEXT = {
save: 'Saving your model…',
},
cloudPhase: 'Building your model in the cloud…',
+ cloudPicture: 'Painting your picture in the cloud…',
+ meshFailed: 'Your picture is in the gallery and on the Stage. The 3D step failed and was refunded.',
+ meshRetry: 'Press Create to try again.',
+ stageReady: 'Hit Create to make it 3D.',
cloudPhaseSub: 'This takes about a minute. You can keep working, it lands in your gallery.',
noObject: 'LU could not find a clear object in this picture. Try one with a plain background.',
needImageModel: 'Local 3D from text needs an image model first. Get one in the Model Manager, or start from a picture.',
diff --git a/src/lib/three/three-d-types.ts b/src/lib/three/three-d-types.ts
new file mode 100644
index 00000000..3e494301
--- /dev/null
+++ b/src/lib/three/three-d-types.ts
@@ -0,0 +1,7 @@
+// The two words of the 3D tab, apart from the store, so the texts and the
+// cloud pick can name them without importing the store (no import cycle).
+
+/** The three ways of the 3D tab (3.1.0). */
+export type ThreeDWay = 'text' | 'image' | 'video'
+/** The Detail step of the 3D tab. Each model maps it onto its own field. */
+export type ThreeDDetail = 'draft' | 'standard' | 'fine'
diff --git a/src/mobile/screens/create/parts/ThreeDCards.tsx b/src/mobile/screens/create/parts/ThreeDCards.tsx
index b9cd62e5..1f097f5d 100644
--- a/src/mobile/screens/create/parts/ThreeDCards.tsx
+++ b/src/mobile/screens/create/parts/ThreeDCards.tsx
@@ -30,6 +30,7 @@ export function ThreeDWaySwitch({ f, disabled }: { f: CreateFacts; disabled: boo
options={THREE_D_WAYS.map((way) => ({ value: way, label: S.ways[way], disabled, testid: `m-create-3d-way-${way}` }))}
testid="m-create-3d-way"
/>
+ {f.threeDWay === 'text' && f.threeD?.pictureFirst ? <span className="m-k-card-sub" data-testid="m-create-3d-picture-first">{S.pictureFirst}</span> : null}
</div>
)
}
diff --git a/src/mobile/screens/create/parts/catalog.ts b/src/mobile/screens/create/parts/catalog.ts
index 159ae7fd..1679c813 100644
--- a/src/mobile/screens/create/parts/catalog.ts
+++ b/src/mobile/screens/create/parts/catalog.ts
@@ -27,6 +27,7 @@ import { effectiveVideoDurations } from '../../../../lib/render/video-duration'
import { STUDIO_MODELS } from '../../../../lib/render/studio-contract'
import { shownCreateLabel, shownCreateModel } from './policy'
import { toolFacts, type ToolId, type ToolProbe } from './tools'
+import { pictureStepCredits } from '../../../../lib/three/picture-first'
/** Re-render when the catalog changes. Returns a number that only serves as a dependency. */
export function useCatalogVersion(): number {
@@ -106,6 +107,12 @@ function rowCredits(id: string, tool: ToolId, musicSeconds: number, fallback: nu
return { credits: c.base, quoted: m?.quote_required === true }
}
+/** "Picture first" (lib/three/picture-first.ts) costs the picture and the model together. */
+function withPictureStep<R extends { credits: number | null }>(row: R, tool: ToolId, way: ThreeDWay | undefined, id: string): R {
+ const extra = row.credits === null ? 0 : pictureStepCredits(tool, way, id, '')
+ return extra ? { ...row, credits: (row.credits ?? 0) + extra } : row
+}
+
/** The models of a tool, grouped and marked the way the desktop picker does it. */
export function toolModels(tool: ToolId, opts: { character: CharacterRef | null; characterUse: boolean; musicSeconds: number; fallbackCredits: Record<'image' | 'video' | 'audio', number | null>; threeDWay?: ThreeDWay }): ModelRow[] {
const facts = toolFacts(tool, opts.threeDWay)
@@ -127,7 +134,7 @@ export function toolModels(tool: ToolId, opts: { character: CharacterRef | null;
label: shownCreateModel(model).name,
direct: shownCreateModel(model).direct,
group: group ? shownCreateLabel(group) : group,
- ...rowCredits(model.id, tool, opts.musicSeconds, fallback),
+ ...withPictureStep(rowCredits(model.id, tool, opts.musicSeconds, fallback), tool, opts.threeDWay, model.id),
tags: tierMarks(model).map((t) => ({ label: t.label, accent: t.tone === 'accent' })),
adult: model.adult === true,
}))
diff --git a/src/mobile/screens/create/parts/facts.ts b/src/mobile/screens/create/parts/facts.ts
index 8869ba11..9b343b64 100644
--- a/src/mobile/screens/create/parts/facts.ts
+++ b/src/mobile/screens/create/parts/facts.ts
@@ -27,6 +27,7 @@ import { aspectKey, qualityKey, runParams, summaryParts, type AspectKey, type Qu
import { blockReason, walletVerdict, type BlockReason, type WalletVerdict } from './run-state'
import { toolFacts, toolNeedsMask, type ToolFacts, type ToolId } from './tools'
import { threeDModelFacts, type ThreeDModelFacts } from './three-d'
+import { pictureStepCredits } from '../../../../lib/three/picture-first'
// ---------- the confirmed price, shared ----------
@@ -176,7 +177,7 @@ export function useCreateFacts(): CreateFacts {
const facts = toolFacts(tool, threeDWay)
const characterUse = tool === 'character' && characterTab === 'use'
const model = runModel(tool, { cloudImageModel, cloudVideoModel, cloudOpModel }, character, characterUse, threeDWay)
- const threeD = tool === '3d' ? threeDModelFacts(model.studio ? model.id : undefined) : null
+ const threeD = tool === '3d' ? threeDModelFacts(model.studio ? model.id : undefined, threeDWay) : null
let { kind, op } = intentToJob(tool)
if (characterUse) {
kind = 'image'
@@ -223,6 +224,8 @@ export function useCreateFacts(): CreateFacts {
unit = null
}
}
+ // "Picture first" books the picture and the model: the button shows both.
+ if (unit !== null) unit += pictureStepCredits(tool, threeDWay, model.id, prompt)
} else if (model.id && lengthPrice(model.id, op)) {
// Billed by the length of the input (credits.length). The number PriceOwner left is the price of the
// measured length, or after a 409 the price the server measured; until it is there, the rule itself answers.
diff --git a/src/mobile/screens/create/parts/three-d.ts b/src/mobile/screens/create/parts/three-d.ts
index 3644bee2..f29f5e0f 100644
--- a/src/mobile/screens/create/parts/three-d.ts
+++ b/src/mobile/screens/create/parts/three-d.ts
@@ -12,6 +12,7 @@ import { create } from 'zustand'
import { useCreateStore, type ImageRef, type ThreeDDetail, type ThreeDWay } from '../../../../stores/createStore'
import { cloudDetailOf, threeDControlFacts, threeDDetailField } from '../../../../lib/three/three-d-models'
import { framesAcrossVideo } from '../../../../lib/video-frames'
+import { isPictureFirstRun } from '../../../../lib/three/picture-first'
import { checkFileAgainst } from '../../../../lib/media-file'
import { loadPhoneImageFromBlob } from './photos'
@@ -25,12 +26,14 @@ export interface ThreeDModelFacts {
maxViews: number
/** The model has a detail step. */
hasDetail: boolean
+ /** "From text" paints a picture first, then builds from it (lib/three/picture-first.ts). */
+ pictureFirst: boolean
}
/** What the cloud model `studioId` takes. A model the registry does not know takes one picture and no step. */
-export function threeDModelFacts(studioId: string | undefined): ThreeDModelFacts {
+export function threeDModelFacts(studioId: string | undefined, way?: ThreeDWay): ThreeDModelFacts {
const f = threeDControlFacts('cloud', studioId)
- return { maxViews: f.maxViews, hasDetail: f.hasDetail }
+ return { maxViews: f.maxViews, hasDetail: f.hasDetail, pictureFirst: isPictureFirstRun(way, studioId) }
}
/** `want` indices spread evenly over `n` frames: 0, 2, 4, 5 of eight. Same rule as the desktop. */
diff --git a/src/mobile/strings/create.ts b/src/mobile/strings/create.ts
index ab848b04..88ed6018 100644
--- a/src/mobile/strings/create.ts
+++ b/src/mobile/strings/create.ts
@@ -966,6 +966,7 @@ export const CREATE_STRINGS = {
threeD: {
wayLabel: 'How to make the model',
ways: THREE_D_TEXT.waysShort,
+ pictureFirst: THREE_D_TEXT.pictureFirst,
sourceTitle: 'Photo of one object',
sourceSub: 'One thing, fully in frame. A plain background works best.',
moreSides: THREE_D_TEXT.moreSides,
diff --git a/src/stores/createStore.ts b/src/stores/createStore.ts
index 8e94bcd8..792056a0 100644
--- a/src/stores/createStore.ts
+++ b/src/stores/createStore.ts
@@ -112,10 +112,10 @@ export const LOCAL_UTILITY_OPS: ReadonlySet<UtilityOp> = new Set(['upscale'])
* over the image/video mode axis: when set it wins the intent derivation. */
export type CloudOp = 'character' | 'lipsync' | 'music' | 'extend' | 'motion' | '3d'
-/** The three ways of the 3D tab (3.1.0). */
-export type ThreeDWay = 'text' | 'image' | 'video'
-/** The Detail step of the 3D tab. Each model maps it onto its own field. */
-export type ThreeDDetail = 'draft' | 'standard' | 'fine'
+// The three ways and the Detail step of the 3D tab (3.1.0) live in
+// lib/three/three-d-types.ts, so the 3D texts need not import the store.
+import type { ThreeDWay, ThreeDDetail } from '../lib/three/three-d-types'
+export type { ThreeDWay, ThreeDDetail }
/** Which of the specialized categories ALSO run on the local ComfyUI backend
* (2.5.8 local lanes: ACE music, Wan S2V talking character, last-frame-chain