Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

let a render choose its detail tier and transparency instead of inferring both

Adam Eivyd7119c876301
diff --git a/client/src/components/media/ImageTo3dRenderOptions.jsx b/client/src/components/media/ImageTo3dRenderOptions.jsx
index 7ce4c1c1bd..976d73a998 100644
--- a/client/src/components/media/ImageTo3dRenderOptions.jsx
+++ b/client/src/components/media/ImageTo3dRenderOptions.jsx
@@ -1,5 +1,7 @@
import FormField from '../ui/FormField';
-import { SEED_MAX, STEPS_PRESETS } from '../../lib/imageTo3dRenderOptions';
+import {
+ ALPHA_MODE_PRESETS, DETAIL_PRESETS, SEED_MAX, STEPS_PRESETS,
+} from '../../lib/imageTo3dRenderOptions';
// Per-run sampler knobs for image-to-3D generation, shared by the /3d
// workspace and the /3d/:id detail page. Controlled, with per-field props
@@ -9,12 +11,21 @@ import { SEED_MAX, STEPS_PRESETS } from '../../lib/imageTo3dRenderOptions';
//
// Not every target honors every knob — Pixal3D's upstream CLI has no per-phase step
// override — so `stepsSupported={false}` disables the Quality control and says why,
-// rather than offering a setting the runner silently drops.
+// rather than offering a setting the runner silently drops. `detailSupported` and
+// `alphaModeSupported` do the same for the other two: the TRELLIS.2 CUDA lane takes
+// no pipeline-type override at all, and Pixal3D derives its resolution from VRAM
+// (overriding it could hand a small card a config that OOMs mid-render).
+//
+// Detail and Transparency sit on their own row above the sampler knobs because they
+// change what gets built, while steps/seed/keying change how it is sampled.
//
// Value conventions (see lib/imageTo3dRenderOptions.js for the body mapping):
// - steps: '' = pipeline default, else a preset number string.
// - seed: '' = a fresh random seed every render; a value pins this run.
// - keyBackground: key a solid-color backdrop to transparency before render.
+// - detail: 'auto' = derive the pipeline tier from hardware, else a named tier.
+// - alphaMode: '' = leave PortOS's force-opaque normalization on (the default);
+// any explicit value turns it off so a transparent subject can stay transparent.
const FIELD_LABEL_CLASS = 'mb-1 block text-xs text-gray-400';
const FIELD_INPUT_CLASS = 'w-full rounded-md border border-port-border bg-port-bg px-2 py-1.5 text-xs text-gray-200 disabled:opacity-40';
@@ -26,11 +37,57 @@ export default function ImageTo3dRenderOptions({
onSeedChange,
keyBackground,
onKeyBackgroundChange,
+ detail = 'auto',
+ onDetailChange,
+ alphaMode = '',
+ onAlphaModeChange,
disabled = false,
stepsSupported = true,
+ detailSupported = true,
+ alphaModeSupported = true,
}) {
return (
<div className="flex flex-col gap-2">
+ <div className="grid gap-3 sm:grid-cols-2">
+ <FormField
+ label="Detail"
+ labelClassName={FIELD_LABEL_CLASS}
+ hint={detailSupported
+ ? undefined
+ : 'This model picks its own resolution from your hardware'}
+ >
+ <select
+ id="image-to-3d-detail"
+ value={detailSupported ? detail : 'auto'}
+ onChange={(e) => onDetailChange(e.target.value)}
+ disabled={disabled || !detailSupported}
+ className={FIELD_INPUT_CLASS}
+ >
+ {DETAIL_PRESETS.map((preset) => (
+ <option key={preset.value} value={preset.value}>{preset.label}</option>
+ ))}
+ </select>
+ </FormField>
+ <FormField
+ label="Transparency"
+ labelClassName={FIELD_LABEL_CLASS}
+ hint={alphaModeSupported
+ ? undefined
+ : 'This model always exports a solid material'}
+ >
+ <select
+ id="image-to-3d-alpha-mode"
+ value={alphaModeSupported ? alphaMode : ''}
+ onChange={(e) => onAlphaModeChange(e.target.value)}
+ disabled={disabled || !alphaModeSupported}
+ className={FIELD_INPUT_CLASS}
+ >
+ {ALPHA_MODE_PRESETS.map((preset) => (
+ <option key={preset.value || 'default'} value={preset.value}>{preset.label}</option>
+ ))}
+ </select>
+ </FormField>
+ </div>
<div className="grid gap-3 sm:grid-cols-3">
<FormField
label="Quality"
diff --git a/client/src/lib/imageTo3dRenderOptions.js b/client/src/lib/imageTo3dRenderOptions.js
index c3b4016d03..cd54453d64 100644
--- a/client/src/lib/imageTo3dRenderOptions.js
+++ b/client/src/lib/imageTo3dRenderOptions.js
@@ -23,17 +23,55 @@ export const STEPS_PRESETS = [
{ value: '48', label: 'Max (48 steps — ~4× slower)' },
];
+/**
+ * Detail tiers, mirroring the server's `DETAIL_TIERS`. The labels name the concrete
+ * TRELLIS.2 pipeline each tier maps to, because "fast/balanced/max" alone gives no
+ * sense of the time cost — and the cost is large (upstream benchmarks ~3m20s of
+ * generate+bake for 512, against 13-20 minutes measured for 1024_cascade).
+ *
+ * `auto` stays first and default: it derives the tier from unified memory, which is
+ * what every render did before the control existed.
+ */
+export const DETAIL_PRESETS = [
+ { value: 'auto', label: 'Auto (match this machine)' },
+ { value: 'fast', label: 'Fast preview (512)' },
+ { value: 'balanced', label: 'Balanced (1024)' },
+ { value: 'max', label: 'Max detail (1024 cascade — slowest)' },
+];
+
+/**
+ * Transparency options, mirroring the server's `ALPHA_MODES` plus the unset case.
+ *
+ * `''` (unset) is NOT the same as `OPAQUE`: unset leaves PortOS's force-opaque
+ * normalization in place, which is the historical default and what keeps ordinary
+ * objects from developing holes where the model predicted stray low alpha. Choosing
+ * a mode explicitly turns that normalization off, which is the only way a genuinely
+ * transparent subject (glass, liquid) can render as anything but solid.
+ */
+export const ALPHA_MODE_PRESETS = [
+ { value: '', label: 'Solid (recommended)' },
+ { value: 'auto', label: 'Detect transparency' },
+ { value: 'BLEND', label: 'Force transparent (glass, liquid)' },
+ { value: 'MASK', label: 'Cut-out (hard alpha edges)' },
+ { value: 'OPAQUE', label: 'Opaque (no normalization)' },
+];
+
/**
* Convert the option fields' string state into the API's per-run body. Unset
* fields are OMITTED (not null): absent steps → the pipeline default, absent
* seed → the server rolls a fresh random one for that run. Range/int validation
* is the server's job — the route 400s with a readable message.
*/
-export function renderOptionsBody({ steps, seed, keyBackground }) {
+export function renderOptionsBody({ steps, seed, keyBackground, detail, alphaMode }) {
return {
...(steps !== '' && { steps: Number(steps) }),
...(seed !== '' && { seed: Number(seed) }),
keyBackground,
+ // 'auto' is the server default, so omitting it keeps the body minimal and makes
+ // "the user didn't choose" and "the user chose auto" the same request — which
+ // they are, unlike alphaMode below.
+ ...(detail && detail !== 'auto' && { detail }),
+ ...(alphaMode !== '' && alphaMode != null && { alphaMode }),
};
}
@@ -50,5 +88,25 @@ export function fieldsFromRun(run) {
steps: Number.isInteger(run?.steps) ? String(run.steps) : '',
seed: '',
keyBackground: typeof run?.keyBackground === 'boolean' ? run.keyBackground : true,
+ // Both carry over like `steps` does — they are deliberate quality choices, not
+ // per-run randomness. A run predating these fields has neither, so fall back to
+ // the same defaults a fresh form starts at.
+ detail: DETAIL_PRESETS.some((p) => p.value === run?.detail) ? run.detail : 'auto',
+ alphaMode: typeof run?.alphaMode === 'string' ? run.alphaMode : '',
};
}
+
+/**
+ * Whether a run asked the exporter for a transparent material.
+ *
+ * The viewer's own force-opaque pass has to agree with the server's: with three
+ * layers able to flatten alpha (the exporter's `alpha_mode`, PortOS's GLB rewrite,
+ * and the viewer's `forceOpaque` prop), a run that requested BLEND would still
+ * render solid if the viewer kept flattening it — a silent no-op that reads as a
+ * broken exporter. `null`/absent (the historical default) stays opaque.
+ */
+export function runWantsTransparency(run) {
+ return typeof run?.alphaMode === 'string'
+ && run.alphaMode !== ''
+ && run.alphaMode !== 'OPAQUE';
+}
diff --git a/client/src/pages/Media3D.jsx b/client/src/pages/Media3D.jsx
index 3c28658c53..759618c98a 100644
--- a/client/src/pages/Media3D.jsx
+++ b/client/src/pages/Media3D.jsx
@@ -200,6 +200,8 @@ export default function Media3D() {
const [steps, setSteps] = useState('');
const [seed, setSeed] = useState('');
const [keyBackground, setKeyBackground] = useState(true);
+ const [detail, setDetail] = useState('auto');
+ const [alphaMode, setAlphaMode] = useState('');
// Existing image-to-3D records (newest-first) so the page doubles as a library:
// each links to its `/3d/:id` detail view.
const [records, setRecords] = useState([]);
@@ -296,7 +298,7 @@ export default function Media3D() {
name: nameFromImageFilename(selectedImage.filename),
filename: selectedImage.filename,
target: selectedTarget.id,
- ...renderOptionsBody({ steps, seed, keyBackground }),
+ ...renderOptionsBody({ steps, seed, keyBackground, detail, alphaMode }),
},
{ silent: true },
).catch((err) => {
@@ -398,6 +400,12 @@ export default function Media3D() {
<ImageTo3dRenderOptions
stepsSupported={selectedTarget?.supportsRenderOptions?.steps !== false}
+ detailSupported={selectedTarget?.supportsRenderOptions?.detail !== false}
+ alphaModeSupported={selectedTarget?.supportsRenderOptions?.alphaMode !== false}
+ detail={detail}
+ onDetailChange={setDetail}
+ alphaMode={alphaMode}
+ onAlphaModeChange={setAlphaMode}
steps={steps}
onStepsChange={setSteps}
seed={seed}
diff --git a/client/src/pages/Media3DDetail.jsx b/client/src/pages/Media3DDetail.jsx
index 2c19d05c04..b3389dba0d 100644
--- a/client/src/pages/Media3DDetail.jsx
+++ b/client/src/pages/Media3DDetail.jsx
@@ -9,7 +9,7 @@ import GlbViewer from '../components/media/GlbViewer';
import MediaImage from '../components/MediaImage';
import InlineConfirmRow from '../components/ui/InlineConfirmRow';
import ImageTo3dRenderOptions from '../components/media/ImageTo3dRenderOptions';
-import { fieldsFromRun, renderOptionsBody } from '../lib/imageTo3dRenderOptions';
+import { fieldsFromRun, renderOptionsBody, runWantsTransparency } from '../lib/imageTo3dRenderOptions';
import { imageTo3dStatusMeta } from '../components/media/imageTo3dStatus';
import toast from '../components/ui/Toast';
@@ -35,6 +35,8 @@ export default function Media3DDetail() {
const [steps, setSteps] = useState('');
const [seed, setSeed] = useState('');
const [keyBackground, setKeyBackground] = useState(true);
+ const [detail, setDetail] = useState('auto');
+ const [alphaMode, setAlphaMode] = useState('');
const optionsSeededFor = useRef(null);
const load = useCallback(async ({ initial = false } = {}) => {
@@ -74,6 +76,8 @@ export default function Media3DDetail() {
setSteps(fields.steps);
setSeed(fields.seed);
setKeyBackground(fields.keyBackground);
+ setDetail(fields.detail);
+ setAlphaMode(fields.alphaMode);
}, [record]);
const handleRegenerate = useCallback(async () => {
@@ -81,7 +85,7 @@ export default function Media3DDetail() {
setBusy(true);
const next = await generateImageTo3dModel(
id,
- renderOptionsBody({ steps, seed, keyBackground }),
+ renderOptionsBody({ steps, seed, keyBackground, detail, alphaMode }),
{ silent: true },
).catch((err) => {
toast.error(err?.message || 'Could not start the render.');
@@ -124,6 +128,9 @@ export default function Media3DDetail() {
// Re-renders overwrite the same model.glb path. Key the fetch to the completed
// generation so drei's URL cache loads the new bytes when this record is rendered
// again, while old records without generatedAt retain their historical URL.
+ // Read from the last run rather than the live form: the form is what the NEXT
+ // render will use, while the mesh on screen came from the last one.
+ const renderedTransparent = runWantsTransparency(record?.runs?.at?.(-1));
const meshSrc = record.generatedAt
? `${record.assetPath}?v=${encodeURIComponent(record.generatedAt)}`
: record.assetPath;
@@ -170,12 +177,18 @@ export default function Media3DDetail() {
<div className="mb-4 rounded-lg border border-port-border bg-port-card p-3">
<ImageTo3dRenderOptions
stepsSupported={record.supportsRenderOptions?.steps !== false}
+ detailSupported={record.supportsRenderOptions?.detail !== false}
+ alphaModeSupported={record.supportsRenderOptions?.alphaMode !== false}
steps={steps}
onStepsChange={setSteps}
seed={seed}
onSeedChange={setSeed}
keyBackground={keyBackground}
onKeyBackgroundChange={setKeyBackground}
+ detail={detail}
+ onDetailChange={setDetail}
+ alphaMode={alphaMode}
+ onAlphaModeChange={setAlphaMode}
disabled={busy || isGenerating}
/>
</div>
@@ -209,10 +222,14 @@ export default function Media3DDetail() {
<span className="mb-1 block text-xs text-gray-400">Mesh</span>
{record.status === 'ready' && record.assetPath ? (
<>
+ {/* The viewer is the THIRD layer that can flatten alpha, after the
+ exporter's own alpha_mode and PortOS's GLB rewrite. It has to agree
+ with the run's request, or a mesh exported as BLEND still renders
+ solid here and reads as a broken exporter. */}
<GlbViewer
src={meshSrc}
downloadHref={imageTo3dAssetUrl(record.id)}
- forceOpaque
+ forceOpaque={!renderedTransparent}
/>
{/* The viewer loads the decimated GLB because that is what a browser
can render; the decoder's full mesh is an order of magnitude
diff --git a/server/routes/imageTo3d.js b/server/routes/imageTo3d.js
index b9bf847dab..ad847899cd 100644
--- a/server/routes/imageTo3d.js
+++ b/server/routes/imageTo3d.js
@@ -15,7 +15,7 @@ import {
getModelFullMesh,
} from '../services/imageTo3d/models.js';
import {
- RENDER_STEPS_MIN, RENDER_STEPS_MAX, RENDER_SEED_MAX,
+ RENDER_STEPS_MIN, RENDER_STEPS_MAX, RENDER_SEED_MAX, DETAIL_TIERS, ALPHA_MODES,
} from '../services/imageTo3d/renderOptions.js';
import { createInstallLogger } from '../lib/installLogger.js';
import { openSseStream } from '../lib/sseDownload.js';
@@ -32,6 +32,11 @@ const renderOptionsSchema = z.object({
steps: z.number().int().min(RENDER_STEPS_MIN).max(RENDER_STEPS_MAX).optional(),
seed: z.number().int().min(0).max(RENDER_SEED_MAX).optional(),
keyBackground: z.boolean().optional(),
+ // Abstract tier, not a lane's raw pipeline value — the target maps it (see
+ // renderOptions.js). Enums come from there so the route can't accept a tier the
+ // normalizer would silently discard.
+ detail: z.enum([...DETAIL_TIERS]).optional(),
+ alphaMode: z.enum([...ALPHA_MODES]).optional(),
});
const createModelSchema = z.object({
diff --git a/server/routes/imageTo3d.test.js b/server/routes/imageTo3d.test.js
index ba5a439604..96f19ac511 100644
--- a/server/routes/imageTo3d.test.js
+++ b/server/routes/imageTo3d.test.js
@@ -174,16 +174,28 @@ describe('image-to-3d routes', () => {
models.getModel.mockResolvedValue(record('pixal3dCuda'));
models.createModel.mockResolvedValue(record('pixal3dCuda'));
models.startGeneration.mockResolvedValue(record('pixal3dCuda'));
+ // Read from the registry rather than restated, so adding a knob to a
+ // descriptor does not need an edit here to stay honest.
+ const expected = targets.renderOptionSupportFor('pixal3dCuda');
const get = await request(app).get('/api/image-to-3d/models/image3d-1');
- expect(get.body.supportsRenderOptions).toEqual({ steps: false });
+ expect(get.body.supportsRenderOptions).toEqual(expected);
const created = await request(app).post('/api/image-to-3d/models')
.send({ filename: 'example.png', name: 'x' });
- expect(created.body.supportsRenderOptions).toEqual({ steps: false });
+ expect(created.body.supportsRenderOptions).toEqual(expected);
const regen = await request(app).post('/api/image-to-3d/models/image3d-1/generate').send({});
- expect(regen.body.supportsRenderOptions).toEqual({ steps: false });
+ expect(regen.body.supportsRenderOptions).toEqual(expected);
+ });
+
+ it('tells the client the detail control is unusable on a VRAM-derived lane', () => {
+ // Pixal3D picks 1024/1536 from the card's VRAM, so a rendered-but-ignored
+ // Detail control would be a lie about what the render will do.
+ expect(targets.renderOptionSupportFor('pixal3dCuda').detail).toBe(false);
+ expect(targets.renderOptionSupportFor('trellis2Cuda').detail).toBe(false);
+ // The MPS lane is the one that honors it.
+ expect(targets.renderOptionSupportFor('trellis2')).toBeNull();
});
it('omits the field for a target that honors every knob', async () => {
diff --git a/server/services/imageTo3d/models.js b/server/services/imageTo3d/models.js
index 2ec037359c..54e55ea79c 100644
--- a/server/services/imageTo3d/models.js
+++ b/server/services/imageTo3d/models.js
@@ -366,6 +366,11 @@ async function beginRender(record, adapter, sourcePath, caps, requestOptions) {
steps: options.steps,
seed: options.seed,
keyBackground: options.keyBackground,
+ // Recorded so the detail view can render the knobs this run actually
+ // used — and so the viewer knows whether transparency was requested,
+ // which decides if its force-opaque pass should apply.
+ detail: options.detail,
+ alphaMode: options.alphaMode,
startedAt,
completedAt: null,
error: null,
diff --git a/server/services/imageTo3d/registry.test.js b/server/services/imageTo3d/registry.test.js
index f55a988670..1989c975f4 100644
--- a/server/services/imageTo3d/registry.test.js
+++ b/server/services/imageTo3d/registry.test.js
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import { IMAGE_TO_3D_TARGETS, IMAGE_TO_3D_TARGET_IDS, EXECUTION_LANES, OUTPUT_KINDS } from './targets.js';
import { TARGET_ADAPTERS } from './adapters.js';
+import { RENDER_OPTION_KEYS } from './renderOptions.js';
// Registry-wide invariants, asserted by LOOPING over the registry rather than by a
// hand-written block per target. The per-target blocks in targets.test.js only cover
@@ -46,7 +47,10 @@ describe('image-to-3D registry invariants', () => {
it('declares only boolean render-option support, when it declares any', () => {
if (target.supportsRenderOptions === undefined) return;
for (const [knob, supported] of Object.entries(target.supportsRenderOptions)) {
- expect(['steps', 'seed', 'keyBackground']).toContain(knob);
+ // Derived from normalizeRenderOptions rather than restated, so adding a
+ // per-run option cannot leave this invariant rejecting valid descriptors
+ // (which is exactly what happened when `detail`/`alphaMode` landed).
+ expect(RENDER_OPTION_KEYS).toContain(knob);
expect(typeof supported).toBe('boolean');
}
});
diff --git a/server/services/imageTo3d/renderOptions.js b/server/services/imageTo3d/renderOptions.js
index 4b1fce9766..e309f036d8 100644
--- a/server/services/imageTo3d/renderOptions.js
+++ b/server/services/imageTo3d/renderOptions.js
@@ -1,8 +1,8 @@
/**
* Lane-agnostic PER-RUN render options for image-to-3D generation (sampler
- * steps / seed / background keying). Shared by the route schema, the record
- * layer, and both TRELLIS.2 lanes so the accepted ranges and CLI flags can't
- * drift between them.
+ * steps / seed / background keying / detail tier / alpha mode). Shared by the
+ * route schema, the record layer, and every lane so the accepted ranges and CLI
+ * flags can't drift between them.
*
* These are deliberately per-run parameters, NOT a stored record preference:
* each generate request says what it wants, the run entry records the concrete
@@ -13,6 +13,10 @@
* - `seed: null` → roll a fresh random seed for this run, so "Re-render"
* actually samples a new model instead of deterministically reproducing the
* last one (the upstream CLI default is a fixed 42).
+ * - `detail: 'auto'` → derive the pipeline tier from host capability, which is
+ * what every lane did before the knob existed.
+ * - `alphaMode: null` → don't instruct the exporter, and keep PortOS's
+ * force-opaque normalization.
*/
import { randomInt } from 'node:crypto';
@@ -33,6 +37,41 @@ export function randomRenderSeed() {
return randomInt(0, RENDER_SEED_MAX + 1);
}
+/**
+ * Abstract detail tiers, mapped by each target to its OWN concrete parameter.
+ *
+ * Deliberately not the raw `--pipeline-type` string. Each lane has a different
+ * vocabulary for the same idea — the MPS port takes `512` / `1024` /
+ * `1024_cascade`, Pixal3D takes a 1024/1536 resolution, the TRELLIS.2 CUDA lane
+ * takes nothing at all — so a raw pass-through would leak one lane's enum into a
+ * shared API and render a control that is wrong for the others. The mapping lives
+ * on the target descriptor (`detailTiers`), so a lane that gains a tier is a
+ * registry edit rather than a change here.
+ *
+ * `'auto'` is the default and means "derive from host capability", which is the
+ * behaviour every lane had before this option existed. It is a real value rather
+ * than `null` because the user can pick it back deliberately after choosing a tier.
+ */
+export const DETAIL_TIERS = ['auto', 'fast', 'balanced', 'max'];
+export const DEFAULT_DETAIL_TIER = 'auto';
+
+/** Whether a value names a detail tier. */
+export const isValidDetailTier = (value) => DETAIL_TIERS.includes(value);
+
+/**
+ * glTF alpha modes a caller may request for the exported material.
+ *
+ * `'auto'` defers to the exporter's own heuristic (BLEND only when >1% of valid
+ * texels are meaningfully transparent). `null` means "don't ask", which keeps the
+ * historical behaviour: exporter default plus PortOS's force-opaque normalization.
+ * That normalization exists for older exporters that promoted to BLEND off a
+ * single low-alpha texel — see `glbMaterials.js`.
+ */
+export const ALPHA_MODES = ['OPAQUE', 'auto', 'BLEND', 'MASK'];
+
+/** Whether a value names an alpha mode (null/undefined are "unset"). */
+export const isValidAlphaMode = (value) => ALPHA_MODES.includes(value);
+
const intInRange = (value, min, max) => (
Number.isInteger(value) && value >= min && value <= max
);
@@ -47,17 +86,37 @@ export const isValidRenderSeed = (value) => intInRange(value, 0, RENDER_SEED_MAX
* Normalize a request's options into the per-run shape. Invalid/absent values
* collapse to the unset sentinel (`null`) rather than throwing — the route
* schema is the loud gate; this is the internal-caller normalizer.
- * @param {{steps?: number|null, seed?: number|null, keyBackground?: boolean}} [input]
- * @returns {{steps: number|null, seed: number|null, keyBackground: boolean}}
+ * @param {{steps?: number|null, seed?: number|null, keyBackground?: boolean,
+ * detail?: string, alphaMode?: string|null}} [input]
+ * @returns {{steps: number|null, seed: number|null, keyBackground: boolean,
+ * detail: string, alphaMode: string|null}}
*/
export function normalizeRenderOptions(input = {}) {
return {
steps: isValidRenderSteps(input.steps) ? input.steps : null,
seed: isValidRenderSeed(input.seed) ? input.seed : null,
keyBackground: input.keyBackground !== false,
+ // `detail` collapses to the explicit 'auto' sentinel rather than null: it is a
+ // choosable value, and a run entry recording 'auto' is what actually happened.
+ detail: isValidDetailTier(input.detail) ? input.detail : DEFAULT_DETAIL_TIER,
+ // `alphaMode` stays null-when-unset, because "don't ask the exporter" is a
+ // genuinely different instruction from any of the concrete modes.
+ alphaMode: isValidAlphaMode(input.alphaMode) ? input.alphaMode : null,
};
}
+/**
+ * The per-run option keys — i.e. exactly the keys `normalizeRenderOptions` returns.
+ *
+ * Exported so the registry invariant that validates a target's
+ * `supportsRenderOptions` can derive the legal knob names from here instead of
+ * restating them. That list had already drifted once: it still read
+ * `['steps','seed','keyBackground']` after `detail` and `alphaMode` were added, so a
+ * descriptor declaring support for a real knob failed the invariant while a typo'd
+ * knob name would have passed.
+ */
+export const RENDER_OPTION_KEYS = Object.freeze(Object.keys(normalizeRenderOptions()));
+
/**
* Validate steps/seed and emit their CLI flags — the single owner of both the
* bounds check and the flag names, shared by the MPS and CUDA arg builders so
@@ -106,11 +165,19 @@ export function validateRenderOptions(label, { steps = null, seed = null } = {})
* applied. `support` is the target descriptor's `supportsRenderOptions`; absent means
* everything is honored, so existing targets need no entry.
*
- * @param {{steps: number|null, seed: number|null, keyBackground: boolean}} options
- * @param {{steps?: boolean}} [support]
- * @returns {{steps: number|null, seed: number|null, keyBackground: boolean}}
+ * @param {object} options
+ * @param {{steps?: boolean, detail?: boolean, alphaMode?: boolean}} [support]
+ * @returns {object}
*/
export function honorTargetRenderSupport(options, support) {
if (!support) return options;
- return { ...options, ...(support.steps === false ? { steps: null } : {}) };
+ return {
+ ...options,
+ ...(support.steps === false ? { steps: null } : {}),
+ // Reset to the same sentinel `normalizeRenderOptions` uses for "unset", so a
+ // dropped option records as not-requested rather than as a value the
+ // subprocess never received.
+ ...(support.detail === false ? { detail: DEFAULT_DETAIL_TIER } : {}),
+ ...(support.alphaMode === false ? { alphaMode: null } : {}),
+ };
}
diff --git a/server/services/imageTo3d/renderOptions.parity.test.js b/server/services/imageTo3d/renderOptions.parity.test.js
index eba82ec9e2..a86c169416 100644
--- a/server/services/imageTo3d/renderOptions.parity.test.js
+++ b/server/services/imageTo3d/renderOptions.parity.test.js
@@ -11,10 +11,14 @@
import { describe, it, expect } from 'vitest';
import {
+ ALPHA_MODES,
+ DETAIL_TIERS,
RENDER_SEED_MAX,
isValidRenderSteps,
} from './renderOptions.js';
import {
+ ALPHA_MODE_PRESETS as CLIENT_ALPHA_MODE_PRESETS,
+ DETAIL_PRESETS as CLIENT_DETAIL_PRESETS,
SEED_MAX as CLIENT_SEED_MAX,
STEPS_PRESETS as CLIENT_STEPS_PRESETS,
} from '../../../client/src/lib/imageTo3dRenderOptions.js';
@@ -24,6 +28,20 @@ describe('image-to-3D render-option parity (server bounds ↔ client mirror)', (
expect(CLIENT_SEED_MAX).toBe(RENDER_SEED_MAX);
});
+ it('the client detail presets cover exactly the server tiers', () => {
+ // Both directions matter: a client tier the server rejects 400s the render, and
+ // a server tier with no client preset is a knob the user can never reach.
+ expect(CLIENT_DETAIL_PRESETS.map((p) => p.value).sort()).toEqual([...DETAIL_TIERS].sort());
+ });
+
+ it('every client alpha-mode preset is a server mode, plus the unset sentinel', () => {
+ const values = CLIENT_ALPHA_MODE_PRESETS.map((p) => p.value);
+ // '' is client-only and load-bearing: it means "leave PortOS's force-opaque
+ // normalization on", which is distinct from asking the exporter for OPAQUE.
+ expect(values).toContain('');
+ expect(values.filter((v) => v !== '').sort()).toEqual([...ALPHA_MODES].sort());
+ });
+
it('every non-default client steps preset is a value the server accepts', () => {
const numeric = CLIENT_STEPS_PRESETS
.map((preset) => preset.value)
diff --git a/server/services/imageTo3d/renderOptions.test.js b/server/services/imageTo3d/renderOptions.test.js
index 90b54a0f48..1a4fbea356 100644
--- a/server/services/imageTo3d/renderOptions.test.js
+++ b/server/services/imageTo3d/renderOptions.test.js
@@ -10,21 +10,25 @@ import {
renderOptionArgs,
validateRenderOptions,
honorTargetRenderSupport,
+ ALPHA_MODES,
+ DEFAULT_DETAIL_TIER,
+ DETAIL_TIERS,
+ RENDER_OPTION_KEYS,
} from './renderOptions.js';
describe('normalizeRenderOptions', () => {
it('defaults to unset steps/seed with keying enabled', () => {
- expect(normalizeRenderOptions()).toEqual({ steps: null, seed: null, keyBackground: true });
- expect(normalizeRenderOptions({})).toEqual({ steps: null, seed: null, keyBackground: true });
+ expect(normalizeRenderOptions()).toEqual({ steps: null, seed: null, keyBackground: true, detail: 'auto', alphaMode: null });
+ expect(normalizeRenderOptions({})).toEqual({ steps: null, seed: null, keyBackground: true, detail: 'auto', alphaMode: null });
});
it('keeps valid values and collapses invalid ones to the unset sentinel', () => {
expect(normalizeRenderOptions({ steps: 24, seed: 0, keyBackground: false }))
- .toEqual({ steps: 24, seed: 0, keyBackground: false });
+ .toEqual({ steps: 24, seed: 0, keyBackground: false, detail: 'auto', alphaMode: null });
expect(normalizeRenderOptions({ steps: RENDER_STEPS_MAX + 1, seed: RENDER_SEED_MAX + 1 }))
- .toEqual({ steps: null, seed: null, keyBackground: true });
+ .toEqual({ steps: null, seed: null, keyBackground: true, detail: 'auto', alphaMode: null });
expect(normalizeRenderOptions({ steps: 12.5, seed: '42' }))
- .toEqual({ steps: null, seed: null, keyBackground: true });
+ .toEqual({ steps: null, seed: null, keyBackground: true, detail: 'auto', alphaMode: null });
});
});
@@ -86,6 +90,43 @@ describe('validateRenderOptions', () => {
});
});
+describe('detail tier and alpha mode', () => {
+ it('defaults detail to the auto sentinel, not null', () => {
+ // 'auto' is a choosable value ("derive from host"), so a run entry recording it
+ // is the truth rather than an absence.
+ expect(normalizeRenderOptions().detail).toBe(DEFAULT_DETAIL_TIER);
+ expect(DETAIL_TIERS).toContain(DEFAULT_DETAIL_TIER);
+ });
+
+ it.each(DETAIL_TIERS)('keeps the valid tier %s', (tier) => {
+ expect(normalizeRenderOptions({ detail: tier }).detail).toBe(tier);
+ });
+
+ it.each(['ultra', '1024_cascade', '', null, 7])('collapses invalid tier %s to auto', (bad) => {
+ // Notably '1024_cascade' — a lane's concrete pipeline value is NOT a tier, and
+ // letting it through would leak one lane's vocabulary into the shared API.
+ expect(normalizeRenderOptions({ detail: bad }).detail).toBe(DEFAULT_DETAIL_TIER);
+ });
+
+ it.each(ALPHA_MODES)('keeps the valid alpha mode %s', (mode) => {
+ expect(normalizeRenderOptions({ alphaMode: mode }).alphaMode).toBe(mode);
+ });
+
+ it('keeps alphaMode null when unset, which is distinct from OPAQUE', () => {
+ // null = "don't instruct the exporter, and keep the force-opaque normalization".
+ // OPAQUE = "the exporter should emit OPAQUE". Collapsing them would make the
+ // normalization impossible to opt out of.
+ expect(normalizeRenderOptions().alphaMode).toBeNull();
+ expect(normalizeRenderOptions({ alphaMode: 'OPAQUE' }).alphaMode).toBe('OPAQUE');
+ });
+});
+
+describe('RENDER_OPTION_KEYS', () => {
+ it('matches exactly what normalizeRenderOptions returns', () => {
+ expect(RENDER_OPTION_KEYS).toEqual(Object.keys(normalizeRenderOptions()));
+ });
+});
+
describe('honorTargetRenderSupport', () => {
const opts = { steps: 24, seed: 7, keyBackground: true };
diff --git a/server/services/imageTo3d/targets.js b/server/services/imageTo3d/targets.js
index 7308b18bc0..597b7a50f8 100644
--- a/server/services/imageTo3d/targets.js
+++ b/server/services/imageTo3d/targets.js
@@ -80,6 +80,19 @@ export const IMAGE_TO_3D_TARGETS = Object.freeze({
diskGb: 15,
python: '3.11',
}),
+ // Maps the shared abstract detail tiers onto this port's own `--pipeline-type`
+ // values. `auto` is absent deliberately: it means "derive from unified memory"
+ // and is resolved by the runner, not by a lookup here.
+ //
+ // The 512 tier is genuinely fast rather than merely smaller — upstream's own
+ // benchmark is ~3m20s of generate+bake on an M4 Pro, against 13–20 minutes
+ // measured for 1024_cascade on a 64 GB M5 Max. It is worth exposing as a
+ // preview tier even on a host whose memory qualifies for max.
+ detailTiers: Object.freeze({
+ fast: '512',
+ balanced: '1024',
+ max: '1024_cascade',
+ }),
upstream: 'https://github.com/microsoft/TRELLIS.2',
// Community MPS port that makes the CUDA-only upstream run on Apple Silicon.
port: 'https://github.com/shivampkumar/trellis-mac',
@@ -127,6 +140,10 @@ export const IMAGE_TO_3D_TARGETS = Object.freeze({
diskGb: 15,
python: '3.10',
}),
+ // Upstream's CUDA entrypoint takes no pipeline-type override and PortOS's
+ // runner for it emits no alpha-mode flag, so both controls are declared
+ // unsupported rather than rendered as settings the runner would drop.
+ supportsRenderOptions: Object.freeze({ detail: false, alphaMode: false }),
upstream: 'https://github.com/microsoft/TRELLIS.2',
weightsRepo: 'microsoft/TRELLIS.2-4B',
installNotes:
@@ -173,7 +190,14 @@ export const IMAGE_TO_3D_TARGETS = Object.freeze({
// `steps` and drops it. Declared here so the UI disables the Quality control rather
// than offering a setting that silently does nothing, and so the run entry records
// `steps: null` instead of a value that never applied.
- supportsRenderOptions: Object.freeze({ steps: false }),
+ // `detail: false` even though this lane DOES have 1024/1536 resolutions, and
+ // that is deliberate rather than an oversight. Its tier is chosen from the
+ // card's actual VRAM by `selectPixal3dRenderBudget` (1536 wants up to ~36 GB),
+ // so letting a request override it would hand a 12 GB card a configuration
+ // that OOMs mid-render. Exposing it needs a VRAM-safety story first — until
+ // then the honest answer is that the runner does not honor a caller's choice.
+ // `alphaMode: false` because its runner emits no such flag.
+ supportsRenderOptions: Object.freeze({ steps: false, detail: false, alphaMode: false }),
installNotes:
'Creating a dedicated `pixal3d` conda environment (kept separate so Pixal3D\u2019s '
+ 'pinned dependencies cannot disturb the TRELLIS.2 target), cloning both repos, '
diff --git a/server/services/imageTo3d/targets.test.js b/server/services/imageTo3d/targets.test.js
index b51b46f0d4..6cd003c8d7 100644
--- a/server/services/imageTo3d/targets.test.js
+++ b/server/services/imageTo3d/targets.test.js
@@ -13,6 +13,7 @@ import {
detectHostCapabilities,
renderOptionSupportFor,
} from './targets.js';
+import { DEFAULT_DETAIL_TIER, DETAIL_TIERS } from './renderOptions.js';
// A host that can run TRELLIS.2's local-MPS lane, and one that can't.
const APPLE_128GB = { appleSilicon: true, unifiedMemoryGb: 128, cuda: false, cudaProbe: 'absent' };
@@ -331,15 +332,40 @@ describe('renderOptionSupportFor', () => {
it('reports the unsupported knobs a target declares', () => {
// Pixal3D's runner drops `steps`; the descriptor is what tells the UI to disable
// the control and `beginRender` to record null instead of the requested value.
- expect(renderOptionSupportFor('pixal3dCuda')).toEqual({ steps: false });
+ // `detail` is declared unsupported even though the lane HAS 1024/1536
+ // resolutions — they are picked from the card's VRAM, so honoring a caller's
+ // choice could hand a 12 GB card a config that OOMs mid-render.
+ expect(renderOptionSupportFor('pixal3dCuda'))
+ .toEqual({ steps: false, detail: false, alphaMode: false });
+ // Upstream's CUDA entrypoint takes no pipeline-type override at all.
+ expect(renderOptionSupportFor('trellis2Cuda'))
+ .toEqual({ detail: false, alphaMode: false });
});
it('returns null for a target that honors every knob, and for an unknown id', () => {
// Absent must mean "all supported", so existing targets need no descriptor entry
// and an unknown id can't be mistaken for "supports nothing".
expect(renderOptionSupportFor('trellis2')).toBeNull();
- expect(renderOptionSupportFor('trellis2Cuda')).toBeNull();
expect(renderOptionSupportFor('nope')).toBeNull();
expect(renderOptionSupportFor(undefined)).toBeNull();
});
+
+ // Guards the contract between the abstract tier and each lane's own vocabulary:
+ // a target that declares detail support must be able to resolve every tier, and
+ // one that declares it unsupported must not carry a half-filled mapping.
+ it('pairs detail support with a complete tier mapping', () => {
+ for (const id of IMAGE_TO_3D_TARGET_IDS) {
+ const target = IMAGE_TO_3D_TARGETS[id];
+ const supportsDetail = target.supportsRenderOptions?.detail !== false;
+ if (supportsDetail) {
+ expect(target.detailTiers, id).toBeDefined();
+ // Every non-auto tier must map, or picking it would silently fall back.
+ for (const tier of DETAIL_TIERS.filter((t) => t !== DEFAULT_DETAIL_TIER)) {
+ expect(target.detailTiers[tier], `${id}.${tier}`).toBeTruthy();
+ }
+ } else {
+ expect(target.detailTiers, id).toBeUndefined();
+ }
+ }
+ });
});
diff --git a/server/services/imageTo3d/trellis2.js b/server/services/imageTo3d/trellis2.js
index c054145885..7fd225b6ea 100644
--- a/server/services/imageTo3d/trellis2.js
+++ b/server/services/imageTo3d/trellis2.js
@@ -432,6 +432,48 @@ export function selectTrellis2PipelineType(unifiedMemoryGb) {
: TRELLIS2_BASELINE_PIPELINE_TYPE;
}
+/**
+ * Resolve a request's abstract detail tier to this port's `--pipeline-type`.
+ *
+ * `'auto'` (the default) keeps the historical hardware-derived behaviour; any other
+ * tier is looked up in the target descriptor's `detailTiers`, so the tier vocabulary
+ * lives in the registry rather than being restated here.
+ *
+ * An unmapped tier falls back to the hardware-derived choice rather than throwing.
+ * That is deliberate: the route enum and the descriptor are validated against each
+ * other by `targets.test.js`, so reaching this branch means a registry edit went
+ * wrong — and degrading to the tier the host would have picked anyway is a far better
+ * outcome than failing a render the user already waited on.
+ *
+ * The descriptor is read lazily, at call time, for the same reason `hfGatedRepoHelp`
+ * does: resolving it at module scope would make merely importing this file depend on
+ * `targets.js` being fully materialized, which a partial test mock of that module
+ * breaks.
+ *
+ * @param {string} detail one of DETAIL_TIERS
+ * @param {number} unifiedMemoryGb
+ * @returns {string} a value from TRELLIS2_PIPELINE_TYPES
+ */
+export function resolveTrellis2PipelineType(detail, unifiedMemoryGb) {
+ if (!detail || detail === 'auto') return selectTrellis2PipelineType(unifiedMemoryGb);
+ const mapped = getTarget('trellis2')?.detailTiers?.[detail];
+ if (mapped && TRELLIS2_PIPELINE_TYPES.includes(mapped)) {
+ // A tier ABOVE what this host's memory would have chosen is allowed on purpose:
+ // overriding the hardware heuristic is the point of the knob, and PortOS's
+ // 48 GB threshold is explicitly a conservative guess (the port publishes no
+ // 1024-cascade memory ceiling). But say so in the log, because the likely
+ // failure on an undersized host is an OOM or a watchdog kill many minutes in,
+ // and this line is what connects that to the choice.
+ const hostChoice = selectTrellis2PipelineType(unifiedMemoryGb);
+ if (mapped !== hostChoice) {
+ console.log(`🎚️ TRELLIS.2 detail '${detail}' → pipeline ${mapped} (host default for ${unifiedMemoryGb} GB is ${hostChoice})`);
+ }
+ return mapped;
+ }
+ console.warn(`⚠️ TRELLIS.2 detail tier '${detail}' is unmapped — falling back to the host-derived pipeline`);
+ return selectTrellis2PipelineType(unifiedMemoryGb);
+}
+
/**
* PortOS asks for at least a 2K atlas, overriding `generate.py`'s 1K default. The
* bake UV-unwraps a 200k-triangle mesh into a single atlas, so texel budget per
@@ -871,6 +913,7 @@ export function runTrellis2Generate({
unifiedMemoryGb = Math.round(totalmem() / 1024 ** 3),
steps = null,
seed = null,
+ detail = 'auto',
decimationTarget = null,
fillHoles = false,
remesh = false,
@@ -886,7 +929,9 @@ export function runTrellis2Generate({
err.code = 'TRELLIS2_NOT_INSTALLED';
return { promise: Promise.reject(err), kill: () => {} };
}
- const resolvedPipelineType = pipelineType ?? selectTrellis2PipelineType(unifiedMemoryGb);
+ // An explicit `pipelineType` still wins (direct callers and tests use it); a
+ // request expresses itself as a detail tier instead.
+ const resolvedPipelineType = pipelineType ?? resolveTrellis2PipelineType(detail, unifiedMemoryGb);
const resolvedTextureSize = textureSize ?? selectTrellis2TextureSize(unifiedMemoryGb);
const resolvedDecimationTarget = decimationTarget
?? selectTrellis2DecimationTarget(unifiedMemoryGb, TRELLIS2_HIGH_QUALITY_MIN_MEMORY_GB);