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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: improve mesh preview and texture detail
[._.]/ Adam Eivy93ae6f7a8b79
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 601e4eab10..08cddc8166 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,6 +2,7 @@## 3D+- **Generated meshes are easier to inspect and get a denser texture atlas on high-memory Macs** — the GLB preview now has an always-visible background color picker, and an offline procedural light environment makes TRELLIS's metallic PBR surfaces readable instead of turning details such as dark glass into black patches. Newly generated models use a 4K texture bake when at least 48 GB of unified memory is available (four times the 2K texel budget); supported 24 GB systems keep the proven 2K path.- **TRELLIS.2 models no longer render with transparent holes, and high-memory Macs use the sharper texture pipeline** — existing generated meshes now display as solid in the 3D viewer, while newly generated GLBs are normalized to the opaque material mode TRELLIS intended. Macs with at least 48 GB of unified memory now use 1024-cascade generation for better surface-detail placement; supported 24 GB systems stay on the proven lower-memory lane. Re-rendering the same record also refreshes the viewer immediately instead of showing its URL-cached previous mesh.- **[issue-3041] Installing TRELLIS.2 now fetches the Apple toolchain it needs, instead of telling you to run a command** — #2952 made the "correct shape, confetti surface" problem *visible*, but the fix was still a terminal command you had to copy out of a warning and run yourself — leaving every new install one manual step away from bad-looking renders. Installing (or repairing) TRELLIS.2 now downloads Apple's Xcode Metal Toolchain itself when it's missing, before the setup that needs it, so a fresh install produces properly textured meshes with nothing extra to do. No password is required and the download is skipped entirely when you already have it. **Repair install** on an existing degraded copy now genuinely fixes it rather than re-running the same broken setup. Two honest edge cases: if the download fails the install continues anyway (your geometry is unaffected, and the finished install tells you textures will be reduced), and on a Mac with only the Command Line Tools — where nothing PortOS runs can fetch the toolchain — you get a note naming Xcode as the prerequisite and no Repair button that would only fail.- **[issue-2952] The 3D page now catches the install problem that made meshes come out as colorful static** — a TRELLIS.2 render could produce a perfectly accurate 3D shape wrapped in a scrambled, speckled surface, with nothing anywhere saying why. The cause is an install that only *looked* finished: TRELLIS.2's setup builds its high-quality texture painter from Metal source, and on a Mac without Apple's Xcode Metal Toolchain that build quietly fails, the setup still reports success, and every later render silently falls back to a low-resolution painter that can't cover a detailed mesh — so the shape is right and the paint job is confetti. PortOS now checks for the Metal Toolchain **before** you commit to the multi-hour install and warns you if it's missing, verifies after installing whether the good texture painter actually landed, and shows any already-installed copy as **Ready · degraded textures** with a plain explanation and a one-click **Repair install** that rebuilds just the missing piece (your downloaded models are kept). Renders also now bake textures at the highest resolution TRELLIS.2 offers, so surfaces hold more detail either way.diff --git a/client/src/components/media/GlbViewer.jsx b/client/src/components/media/GlbViewer.jsxindex 711f7e4121..c25afef94b 100644--- a/client/src/components/media/GlbViewer.jsx+++ b/client/src/components/media/GlbViewer.jsx@@ -1,8 +1,16 @@-import { Suspense, useEffect, useMemo } from 'react';+import { Suspense, useEffect, useId, useMemo, useState } from 'react';import { Canvas } from '@react-three/fiber';-import { Bounds, OrbitControls, useGLTF } from '@react-three/drei';+import {+ Bounds,+ Environment,+ Lightformer,+ OrbitControls,+ useGLTF,+} from '@react-three/drei';import { Download, Rotate3d } from 'lucide-react';+const DEFAULT_BACKGROUND = '#050505';+// Reusable viewer for a generated `.glb` mesh: drei `useGLTF` loads the model,// `Bounds fit` frames it regardless of the source's scale, `OrbitControls` lets// the user rotate/zoom, and a Download button saves the raw `.glb`. Deliberately@@ -75,7 +83,10 @@ export default function GlbViewer({downloadName,className = '',forceOpaque = false,+ initialBackground = DEFAULT_BACKGROUND,}) {+ const backgroundInputId = useId();+ const [background, setBackground] = useState(initialBackground);if (!src) return null;const href = downloadHref || src;// With an explicit download endpoint the server's Content-Disposition wins, so@@ -83,14 +94,52 @@ export default function GlbViewer({const download = downloadHref ? '' : (downloadName || filenameFromSrc(src));return (<div className={`overflow-hidden rounded-xl border border-port-border bg-port-bg ${className}`}>- <div className="relative aspect-square w-full">- {/* No environment/HDR preset here on purpose — those fetch from a CDN and- would fail on an offline / air-gapped install. Two plain lights are- enough to read an untextured or PBR mesh. */}+ <div+ data-testid="glb-preview-surface"+ className="relative aspect-square w-full"+ style={{ backgroundColor: background }}+ >+ <div className="absolute right-2 top-2 z-10 flex items-center gap-2 rounded-lg border border-white/20 bg-black/70 px-2 py-1.5 text-xs text-white shadow-lg backdrop-blur-sm">+ <label htmlFor={backgroundInputId}>Background</label>+ <input+ id={backgroundInputId}+ type="color"+ value={background}+ onChange={(event) => setBackground(event.target.value)}+ aria-label="Mesh preview background"+ className="h-7 w-9 cursor-pointer rounded border border-white/30 bg-transparent p-0.5"+ />+ </div><Canvas camera={{ position: [0, 0, 3], fov: 45 }} dpr={[1, 2]}>+ <color attach="background" args={[background]} /><ambientLight intensity={0.9} /><directionalLight position={[4, 6, 5]} intensity={1.1} /><directionalLight position={[-4, -2, -5]} intensity={0.4} />+ {/* A procedural environment keeps metallic PBR textures readable without+ downloading an HDR preset — PortOS installs can be fully offline. */}+ <Environment resolution={128}>+ <Lightformer+ form="rect"+ intensity={3}+ position={[0, 4, 4]}+ rotation-x={Math.PI / 2}+ scale={[5, 5, 1]}+ />+ <Lightformer+ form="rect"+ intensity={1.5}+ position={[-4, 1, 2]}+ rotation-y={Math.PI / 2}+ scale={[3, 5, 1]}+ />+ <Lightformer+ form="rect"+ intensity={1}+ position={[4, -1, -2]}+ rotation-y={-Math.PI / 2}+ scale={[3, 5, 1]}+ />+ </Environment><Suspense fallback={null}><Bounds fit clip observe margin={1.2}><GlbModel src={src} forceOpaque={forceOpaque} />diff --git a/client/src/components/media/GlbViewer.test.jsx b/client/src/components/media/GlbViewer.test.jsxindex 79da0347d7..ea3a9273b9 100644--- a/client/src/components/media/GlbViewer.test.jsx+++ b/client/src/components/media/GlbViewer.test.jsx@@ -1,4 +1,4 @@-import { render, screen } from '@testing-library/react';+import { fireEvent, render, screen } from '@testing-library/react';import { describe, expect, it, vi } from 'vitest';import { BoxGeometry, Group, Mesh, MeshStandardMaterial } from 'three';@@ -11,6 +11,8 @@ vi.mock('@react-three/fiber', () => ({ Canvas: () => <div data-testid="glb-canvavi.mock('@react-three/drei', () => ({Canvas: () => null,OrbitControls: () => null,+ Environment: ({ children }) => children,+ Lightformer: () => null,Bounds: ({ children }) => children,useGLTF: Object.assign(() => ({ scene: {} }), { clear: vi.fn() }),}));@@ -31,6 +33,18 @@ describe('GlbViewer', () => {expect(link).toHaveAttribute('download', 'robot-a1b2.glb');});+ it('lets the user change the mesh preview background', () => {+ render(<GlbViewer src="/data/models3d/robot-a1b2.glb" />);+ const picker = screen.getByLabelText('Mesh preview background');+ expect(picker).toHaveValue('#050505');++ fireEvent.change(picker, { target: { value: '#f5f5f5' } });++ expect(picker).toHaveValue('#f5f5f5');+ expect(screen.getByTestId('glb-preview-surface'))+ .toHaveStyle({ backgroundColor: '#f5f5f5' });+ });+it('honors an explicit downloadName over the derived one', () => {render(<GlbViewer src="/data/models3d/x.glb?v=2" downloadName="my-mesh.glb" />);expect(screen.getByRole('link', { name: /Download \.glb/i })).toHaveAttribute('download', 'my-mesh.glb');diff --git a/server/services/imageTo3d/trellis2.js b/server/services/imageTo3d/trellis2.jsindex af33d7ea4c..17e1fe19a9 100644--- a/server/services/imageTo3d/trellis2.js+++ b/server/services/imageTo3d/trellis2.js@@ -21,6 +21,7 @@import { existsSync } from 'node:fs';import { homedir, platform, totalmem } from 'node:os';import { join } from 'node:path';+import { fileURLToPath } from 'node:url';import { spawn, execFile } from 'node:child_process';import { killWithEscalation } from '../../lib/killWithEscalation.js';import { rewriteGlbMaterialsOpaque } from './glbMaterials.js';@@ -74,6 +75,11 @@ export function trellis2GenerateScript(base) {return join(trellis2Root(base), 'generate.py');}+/** PortOS adapter that exposes the upstream exporter's supported 4K atlas size. */+export function trellis2GenerateRunnerScript() {+ return fileURLToPath(new URL('./trellis2GenerateRunner.py', import.meta.url));+}+/*** Installed ⇔ the venv Python AND the generate script both exist. `exists` is* injectable so the check is deterministic in tests.@@ -310,10 +316,11 @@ export function trellis2OutputStem(outputPath) {}/**- * `generate.py --texture-size` accepts only these three values (an argparse- * `choices=` list) — anything else aborts the render before it starts.+ * trellis-mac exposes the first three sizes directly. For high-memory machines,+ * PortOS's runner also exposes the underlying TRELLIS.2 exporter's supported 4K+ * bake without forking the generation pipeline.*/-export const TRELLIS2_TEXTURE_SIZES = [512, 1024, 2048];+export const TRELLIS2_TEXTURE_SIZES = [512, 1024, 2048, 4096];/*** `generate.py` supports a fast 512 pipeline and two higher-resolution variants.@@ -346,21 +353,33 @@ export function selectTrellis2PipelineType(unifiedMemoryGb) {}/**- * PortOS asks for the largest atlas the port offers, overriding `generate.py`'s- * 1024 default. The bake UV-unwraps a 200k-triangle mesh into a single atlas, so- * texel budget per triangle is the binding constraint on surface quality: at 1024²- * that is a median ~1.9 texels/triangle, and 2048² quadruples it. This matters most- * on the KDTree fallback baker (see `TRELLIS2_FALLBACK_BAKE_HELP`) but helps the- * Metal path too, and costs only bake time plus a larger texture in the GLB.+ * 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+ * triangle is the binding constraint on surface quality. Hosts with the same+ * conservative memory headroom used for 1024-cascade get a 4K bake (four times+ * the 2K texel budget); supported 24 GB hosts stay on the proven 2K path.*/export const TRELLIS2_DEFAULT_TEXTURE_SIZE = 2048;+export const TRELLIS2_HIGH_QUALITY_TEXTURE_SIZE = 4096;++/**+ * Pick the UV-atlas resolution from physical unified memory.+ *+ * @param {number} unifiedMemoryGb+ * @returns {2048|4096}+ */+export function selectTrellis2TextureSize(unifiedMemoryGb) {+ return Number(unifiedMemoryGb) >= TRELLIS2_HIGH_QUALITY_MIN_MEMORY_GB+ ? TRELLIS2_HIGH_QUALITY_TEXTURE_SIZE+ : TRELLIS2_DEFAULT_TEXTURE_SIZE;+}/*** The generate invocation:- * `<venv-python> generate.py <image> [--output <stem>] --texture-size <n>`.+ * `<venv-python> [4k-adapter] generate.py <image> [--output <stem>] --texture-size <n>`.** Pure. Throws when no source image is given (a render with no input is a bug, not- * an empty run), and when `textureSize` is not one of the port's accepted `choices`+ * an empty run), and when `textureSize` is not one of PortOS's accepted values* — better to fail here than to have argparse abort a job we already queued.* `outputPath` is the desired `.glb` disk path; it is reduced to the stem the port* expects (see `trellis2OutputStem`).@@ -387,7 +406,10 @@ export function buildGenerateArgs({`buildGenerateArgs: pipelineType must be one of ${TRELLIS2_PIPELINE_TYPES.join(', ')}`,);}- const args = [trellis2GenerateScript(base), imagePath];+ const generateScript = trellis2GenerateScript(base);+ const args = textureSize === TRELLIS2_HIGH_QUALITY_TEXTURE_SIZE+ ? [trellis2GenerateRunnerScript(), generateScript, imagePath]+ : [generateScript, imagePath];if (outputPath) args.push('--output', trellis2OutputStem(outputPath));args.push('--pipeline-type', pipelineType);args.push('--texture-size', String(textureSize));@@ -742,11 +764,12 @@ export function runTrellis2Generate({return { promise: Promise.reject(err), kill: () => {} };}const resolvedPipelineType = pipelineType ?? selectTrellis2PipelineType(unifiedMemoryGb);+ const resolvedTextureSize = textureSize ?? selectTrellis2TextureSize(unifiedMemoryGb);const { command, args } = buildGenerateArgs({imagePath,outputPath,base,- textureSize,+ textureSize: resolvedTextureSize,pipelineType: resolvedPipelineType,});// Child-process boundary — errors surface via the 'error'/'close' events, not adiff --git a/server/services/imageTo3d/trellis2.test.js b/server/services/imageTo3d/trellis2.test.jsindex 5105534d60..9997f5eae0 100644--- a/server/services/imageTo3d/trellis2.test.js+++ b/server/services/imageTo3d/trellis2.test.js@@ -5,6 +5,7 @@ import {trellis2Root,trellis2VenvPython,trellis2GenerateScript,+ trellis2GenerateRunnerScript,isTrellis2Installed,buildInstallSteps,trellis2OutputStem,@@ -22,12 +23,14 @@ import {TRELLIS2_METAL_TOOLCHAIN_HINT,TRELLIS2_REQUIRES_XCODE_HINT,TRELLIS2_DEFAULT_TEXTURE_SIZE,+ TRELLIS2_HIGH_QUALITY_TEXTURE_SIZE,TRELLIS2_TEXTURE_SIZES,TRELLIS2_PIPELINE_TYPES,TRELLIS2_BASELINE_PIPELINE_TYPE,TRELLIS2_HIGH_QUALITY_PIPELINE_TYPE,TRELLIS2_HIGH_QUALITY_MIN_MEMORY_GB,selectTrellis2PipelineType,+ selectTrellis2TextureSize,} from './trellis2.js';const flush = () => new Promise((resolve) => setTimeout(resolve, 0));@@ -39,6 +42,7 @@ describe('trellis2 path resolution', () => {expect(trellis2Root(BASE)).toBe('/tmp/portos-test-home/trellis2');expect(trellis2VenvPython(BASE)).toMatch(/trellis2\/\.venv\/(bin\/python3|Scripts\/python\.exe)$/);expect(trellis2GenerateScript(BASE)).toBe('/tmp/portos-test-home/trellis2/generate.py');+ expect(trellis2GenerateRunnerScript()).toMatch(/trellis2GenerateRunner\.py$/);});});@@ -142,7 +146,7 @@ describe('buildGenerateArgs', () => {expect(args.slice(0, 4)).toEqual([trellis2GenerateScript(BASE), 'in.png', '--output', '/out/model']);});- it('defaults to the largest atlas the port offers (texel budget per triangle is the binding constraint)', () => {+ it('defaults direct command building to the proven 2K atlas', () => {expect(TRELLIS2_DEFAULT_TEXTURE_SIZE).toBe(2048);expect(TRELLIS2_TEXTURE_SIZES).toContain(TRELLIS2_DEFAULT_TEXTURE_SIZE);});@@ -156,8 +160,17 @@ describe('buildGenerateArgs', () => {]);});- it('rejects a texture size outside the port\'s argparse choices instead of letting the render abort', () => {- expect(() => buildGenerateArgs({ imagePath: 'in.png', base: BASE, textureSize: 4096 }))+ it('uses the compatibility runner for the underlying exporter\'s 4K atlas size', () => {+ const { args } = buildGenerateArgs({ imagePath: 'in.png', base: BASE, textureSize: 4096 });+ expect(args).toEqual([+ trellis2GenerateRunnerScript(), trellis2GenerateScript(BASE), 'in.png',+ '--pipeline-type', TRELLIS2_BASELINE_PIPELINE_TYPE,+ '--texture-size', '4096',+ ]);+ });++ it('rejects a texture size outside the supported baker sizes instead of letting the render abort', () => {+ expect(() => buildGenerateArgs({ imagePath: 'in.png', base: BASE, textureSize: 8192 })).toThrow(/textureSize must be one of/);});@@ -189,6 +202,18 @@ describe('selectTrellis2PipelineType', () => {});});+describe('selectTrellis2TextureSize', () => {+ it('keeps supported 24 GB hosts on the proven 2K atlas', () => {+ expect(selectTrellis2TextureSize(24)).toBe(TRELLIS2_DEFAULT_TEXTURE_SIZE);+ });++ it('uses a 4K atlas when the host has conservative memory headroom', () => {+ expect(selectTrellis2TextureSize(TRELLIS2_HIGH_QUALITY_MIN_MEMORY_GB))+ .toBe(TRELLIS2_HIGH_QUALITY_TEXTURE_SIZE);+ expect(TRELLIS2_TEXTURE_SIZES).toContain(TRELLIS2_HIGH_QUALITY_TEXTURE_SIZE);+ });+});+describe('probeTrellis2TextureBake', () => {// The probe shells to the venv python with an importlib.util.find_spec one-liner.// Fake execFile lets us assert each outcome without a real venv.@@ -422,7 +447,7 @@ describe('runTrellis2Generate', () => {expect(frames.map((f) => f.percent)).toEqual([10, 30, 50, 92]);});- it('selects the 1024-cascade texture model on a high-memory host', async () => {+ it('selects the high-quality pipeline and 4K atlas on a high-memory host', async () => {const child = makeChild();const spawnImpl = vi.fn(() => child);const { promise } = runTrellis2Generate({@@ -434,7 +459,13 @@ describe('runTrellis2Generate', () => {spawnImpl,postprocessGlb: vi.fn(async () => {}),});- expect(spawnImpl.mock.calls[0][1]).toContain(TRELLIS2_HIGH_QUALITY_PIPELINE_TYPE);+ const args = spawnImpl.mock.calls[0][1];+ expect(args).toContain(TRELLIS2_HIGH_QUALITY_PIPELINE_TYPE);+ expect(args).toContain(String(TRELLIS2_HIGH_QUALITY_TEXTURE_SIZE));+ expect(args.slice(0, 2)).toEqual([+ trellis2GenerateRunnerScript(),+ trellis2GenerateScript(BASE),+ ]);child.emit('close', 0);await expect(promise).resolves.toEqual({ assetPath: '/out/a.glb' });});diff --git a/server/services/imageTo3d/trellis2GenerateRunner.py b/server/services/imageTo3d/trellis2GenerateRunner.pynew file mode 100644index 0000000000..92549841f6--- /dev/null+++ b/server/services/imageTo3d/trellis2GenerateRunner.py@@ -0,0 +1,41 @@+"""Run trellis-mac's generate.py with its supported 4K baker exposed.++Microsoft TRELLIS.2's texture exporter accepts arbitrary atlas sizes and its+official app exposes 4096, but trellis-mac's argparse wrapper caps the same+exporter at 2048. PortOS uses this tiny adapter only for the high-memory 4K lane;+all model loading, sampling, UV unwrapping, baking, and export remain upstream.+"""++import argparse+import runpy+import sys+++UPSTREAM_TEXTURE_SIZES = [512, 1024, 2048]+PORTOS_TEXTURE_SIZES = [*UPSTREAM_TEXTURE_SIZES, 4096]+++def main():+ if len(sys.argv) < 2:+ raise RuntimeError("trellis2GenerateRunner.py requires the upstream generate.py path")++ generate_script = sys.argv[1]+ original_add_argument = argparse.ArgumentParser.add_argument++ def add_argument(parser, *name_or_flags, **kwargs):+ if "--texture-size" in name_or_flags:+ if kwargs.get("choices") != UPSTREAM_TEXTURE_SIZES:+ raise RuntimeError(+ "trellis-mac changed its texture-size interface; "+ "the PortOS 4K adapter needs to be updated"+ )+ kwargs = {**kwargs, "choices": PORTOS_TEXTURE_SIZES}+ return original_add_argument(parser, *name_or_flags, **kwargs)++ argparse.ArgumentParser.add_argument = add_argument+ sys.argv = [generate_script, *sys.argv[2:]]+ runpy.run_path(generate_script, run_name="__main__")+++if __name__ == "__main__":+ main()