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

feat: add mesh preview lighting controls

[._.]/ Adam Eivy5739b8e40e1b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 08cddc8166..a64c8eb646 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,7 @@
## 3D
+- **Mesh previews now support lighting adjustments and an HDRI backdrop** — tune ambient, key, and fill lights while inspecting a 3D model, and optionally show the studio environment as its background.
- **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.
diff --git a/client/src/components/media/GlbViewer.jsx b/client/src/components/media/GlbViewer.jsx
index c25afef94b..1cbc3f99a0 100644
--- a/client/src/components/media/GlbViewer.jsx
+++ b/client/src/components/media/GlbViewer.jsx
@@ -73,6 +73,25 @@ function GlbModel({ src, forceOpaque }) {
return <primitive object={renderedScene} />;
}
+function LightingControl({ label, max, value, onChange }) {
+ return (
+ <label className="mb-1 flex items-center gap-2 last:mb-0">
+ <span className="w-12">{label}</span>
+ <input
+ type="range"
+ min="0"
+ max={max}
+ step="0.1"
+ value={value}
+ onChange={(event) => onChange(Number(event.target.value))}
+ aria-label={`${label} light`}
+ className="min-w-0 flex-1 accent-port-accent"
+ />
+ <output className="w-5 text-right tabular-nums text-gray-300">{value.toFixed(1)}</output>
+ </label>
+ );
+}
+
// `downloadHref` (optional) overrides where the Download button points — pass a
// dedicated asset endpoint that sets its own `Content-Disposition` filename, so
// the server owns the name instead of the client re-deriving it. Falls back to
@@ -87,6 +106,10 @@ export default function GlbViewer({
}) {
const backgroundInputId = useId();
const [background, setBackground] = useState(initialBackground);
+ const [ambientIntensity, setAmbientIntensity] = useState(0.9);
+ const [keyIntensity, setKeyIntensity] = useState(1.1);
+ const [fillIntensity, setFillIntensity] = useState(0.4);
+ const [showEnvironmentBackground, setShowEnvironmentBackground] = useState(false);
if (!src) return null;
const href = downloadHref || src;
// With an explicit download endpoint the server's Content-Disposition wins, so
@@ -99,25 +122,42 @@ export default function GlbViewer({
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 className="absolute right-2 top-2 z-10 w-52 rounded-lg border border-white/20 bg-black/70 p-2 text-xs text-white shadow-lg backdrop-blur-sm">
+ <div className="flex items-center justify-between gap-2">
+ <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>
+ <div className="mt-2 border-t border-white/15 pt-2">
+ <p className="mb-1.5 text-[10px] font-medium uppercase tracking-wide text-gray-300">Lighting</p>
+ <LightingControl label="Ambient" max={2} value={ambientIntensity} onChange={setAmbientIntensity} />
+ <LightingControl label="Key" max={3} value={keyIntensity} onChange={setKeyIntensity} />
+ <LightingControl label="Fill" max={2} value={fillIntensity} onChange={setFillIntensity} />
+ <label className="mt-2 flex items-center gap-2 border-t border-white/15 pt-2 text-gray-200">
+ <input
+ type="checkbox"
+ checked={showEnvironmentBackground}
+ onChange={(event) => setShowEnvironmentBackground(event.target.checked)}
+ className="accent-port-accent"
+ />
+ Show HDRI background
+ </label>
+ </div>
</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} />
+ <ambientLight intensity={ambientIntensity} />
+ <directionalLight position={[4, 6, 5]} intensity={keyIntensity} />
+ <directionalLight position={[-4, -2, -5]} intensity={fillIntensity} />
{/* A procedural environment keeps metallic PBR textures readable without
downloading an HDR preset — PortOS installs can be fully offline. */}
- <Environment resolution={128}>
+ <Environment background={showEnvironmentBackground} resolution={128}>
<Lightformer
form="rect"
intensity={3}
diff --git a/client/src/components/media/GlbViewer.test.jsx b/client/src/components/media/GlbViewer.test.jsx
index ea3a9273b9..fbbddea6f1 100644
--- a/client/src/components/media/GlbViewer.test.jsx
+++ b/client/src/components/media/GlbViewer.test.jsx
@@ -4,16 +4,19 @@ import { BoxGeometry, Group, Mesh, MeshStandardMaterial } from 'three';
// The three.js stack can't run in jsdom (no WebGL context) and none of it is
// under test here — this file covers the chrome AROUND the canvas (the download
-// link + the empty-src guard). The Canvas stub deliberately drops `children`:
-// mounting <primitive>/<mesh> would surface unknown DOM elements and r3f hands
-// back HTMLElement refs without the three.js API.
-vi.mock('@react-three/fiber', () => ({ Canvas: () => <div data-testid="glb-canvas" /> }));
+// link + the empty-src guard). Bounds drops the model subtree: mounting
+// <primitive>/<mesh> would surface unknown DOM elements and r3f hands back
+// HTMLElement refs without the three.js API. Canvas retains the lighting and
+// environment elements so their interactive wiring stays covered.
+vi.mock('@react-three/fiber', () => ({ Canvas: ({ children }) => <div data-testid="glb-canvas">{children}</div> }));
vi.mock('@react-three/drei', () => ({
Canvas: () => null,
OrbitControls: () => null,
- Environment: ({ children }) => children,
+ Environment: ({ background, children }) => (
+ <div data-testid="glb-environment" data-background={background ? 'visible' : 'hidden'}>{children}</div>
+ ),
Lightformer: () => null,
- Bounds: ({ children }) => children,
+ Bounds: () => null,
useGLTF: Object.assign(() => ({ scene: {} }), { clear: vi.fn() }),
}));
@@ -45,6 +48,29 @@ describe('GlbViewer', () => {
.toHaveStyle({ backgroundColor: '#f5f5f5' });
});
+ it('offers basic lighting controls and can show the HDRI environment as the background', () => {
+ render(<GlbViewer src="/data/models3d/robot-a1b2.glb" />);
+
+ const ambient = screen.getByLabelText('Ambient light');
+ const key = screen.getByLabelText('Key light');
+ const fill = screen.getByLabelText('Fill light');
+ expect(ambient).toHaveValue('0.9');
+ expect(key).toHaveValue('1.1');
+ expect(fill).toHaveValue('0.4');
+ expect(screen.getByTestId('glb-environment')).toHaveAttribute('data-background', 'hidden');
+
+ fireEvent.change(ambient, { target: { value: '1.4' } });
+ fireEvent.change(key, { target: { value: '2.2' } });
+ fireEvent.change(fill, { target: { value: '0.8' } });
+ fireEvent.click(screen.getByLabelText('Show HDRI background'));
+
+ expect(ambient).toHaveValue('1.4');
+ expect(key).toHaveValue('2.2');
+ expect(fill).toHaveValue('0.8');
+ expect(screen.getByLabelText('Show HDRI background')).toBeChecked();
+ expect(screen.getByTestId('glb-environment')).toHaveAttribute('data-background', 'visible');
+ });
+
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');