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

fix: load real HDRI in mesh viewer

[._.]/ Adam Eivy8251784f5ca2
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 62039e946e..dd67f6c15e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -8,8 +8,8 @@
## 3D
- **[issue-3033] 3D setup notices now stay in sync with each model's Hugging Face requirements** — the server now describes which gated repositories each image-to-3D target needs, so the 3D page, install guidance, and render-error help all draw from the same source. Adding a target with different (or no) gated dependencies no longer risks showing stale setup instructions.
-- **Mesh preview display controls moved out of the render, and the lighting sliders now actually change the lighting** — the settings panel was an always-mounted overlay pinned inside the canvas, covering the upper-right quadrant of every model; it now lives behind a small toggle in the corner and expands as a strip *below* the render, so it can never occlude the mesh. Two of the controls it exposed were also effectively inert. The procedural studio environment lit the model at full strength and drowned out Ambient/Key/Fill — a new **Environment** slider dials the image-based lighting down (to 0 for lights-only), and the three light defaults were rebalanced against it. **Show HDRI background** revealed a cube map whose unlit areas were pure black, so the studio read as hard-edged white panels floating in a void (and only ever lit the model from three directions); an inward-facing backdrop sphere fills the gaps, and the map is rendered at 256 instead of 128. The scene-level background color was dropped in favor of the surface's CSS color it duplicated — a scene background raced the environment's own `scene.background` save/restore every time the HDRI toggle or the color picker changed.
-- **Generated meshes are easier to inspect and get a denser texture atlas on high-memory Macs** — the GLB preview now has a 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.
+- **Mesh preview display controls moved out of the render, and the lighting sliders now actually change the lighting** — the settings panel was an always-mounted overlay pinned inside the canvas, covering the upper-right quadrant of every model; it now lives behind a small toggle in the corner and expands as a strip *below* the render, so it can never occlude the mesh. Two of the controls it exposed were also effectively inert. The procedural studio environment lit the model at full strength and drowned out Ambient/Key/Fill — a new **Environment** slider dials the image-based lighting down (to 0 for lights-only), and the three light defaults were rebalanced against it. **Show HDRI background** also revealed the procedural rig itself as hard-edged white planes on gray; the viewer now loads a bundled CC0 Poly Haven studio HDRI instead, shows its softly blurred background by default, and remains fully functional offline. The scene-level background color was dropped in favor of the surface's CSS color it duplicated — a scene background raced the environment's own `scene.background` save/restore every time the HDRI toggle or the color picker changed.
+- **Generated meshes are easier to inspect and get a denser texture atlas on high-memory Macs** — the GLB preview now has a background color picker, and a bundled studio HDRI 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/public/hdri/README.md b/client/public/hdri/README.md
new file mode 100644
index 0000000000..f3474f4fc6
--- /dev/null
+++ b/client/public/hdri/README.md
@@ -0,0 +1,12 @@
+# Mesh preview HDRI
+
+`studio-small-08-1k.hdr` is the 1K Radiance HDR version of
+[Studio Small 08](https://polyhaven.com/a/studio_small_08) by Sergej Majboroda
+from Poly Haven.
+
+- License: [CC0](https://polyhaven.com/license)
+- Source file: `studio_small_08_1k.hdr`
+- SHA-256: `f6a989f89432eb4eee3191364a9c1ceed195c4ec3544173a3c04fd96cb91d0ba`
+
+The file is bundled so mesh previews keep their image-based lighting and
+background when PortOS is offline.
diff --git a/client/public/hdri/studio-small-08-1k.hdr b/client/public/hdri/studio-small-08-1k.hdr
new file mode 100644
index 0000000000..fd9f69afe0
Binary files /dev/null and b/client/public/hdri/studio-small-08-1k.hdr differ
diff --git a/client/src/components/media/GlbViewer.jsx b/client/src/components/media/GlbViewer.jsx
index de53931cf1..415b25783d 100644
--- a/client/src/components/media/GlbViewer.jsx
+++ b/client/src/components/media/GlbViewer.jsx
@@ -3,19 +3,14 @@ import { Canvas, useThree } from '@react-three/fiber';
import {
Bounds,
Environment,
- Lightformer,
OrbitControls,
useGLTF,
} from '@react-three/drei';
import { Download, Rotate3d, SlidersHorizontal } from 'lucide-react';
-import { BackSide } from 'three';
const DEFAULT_BACKGROUND = '#050505';
-// The procedural environment renders into a cube map whose unlit areas would
-// otherwise be pure black — so "Show HDRI background" produced hard-edged white
-// panels floating in a void, and the IBL only ever lit from three directions. An
-// inward-facing sphere fills the gaps so the environment reads as a studio.
-const ENVIRONMENT_BACKDROP = '#2b2b2b';
+const ENVIRONMENT_HDRI = '/hdri/studio-small-08-1k.hdr';
+const ENVIRONMENT_BACKGROUND_BLUR = 0.2;
// Reusable viewer for a generated `.glb` mesh: drei `useGLTF` loads the model,
// `Bounds fit` frames it regardless of the source's scale, `OrbitControls` lets
@@ -79,28 +74,10 @@ function GlbModel({ src, forceOpaque }) {
return <primitive object={renderedScene} />;
}
-// The environment's contents never change, so keep this element identity stable:
-// drei re-bakes the cube map (six render passes + a PMREM regeneration) every
-// time `children` changes identity, which for inline JSX is every render — i.e.
-// once per pointer-move while dragging any other control on the panel.
-const ENVIRONMENT_CONTENTS = (
- <>
- <mesh scale={100}>
- <sphereGeometry args={[1, 32, 32]} />
- <meshBasicMaterial color={ENVIRONMENT_BACKDROP} side={BackSide} />
- </mesh>
- <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]} />
- </>
-);
-
// Own `scene.environmentIntensity` directly rather than passing drei's
// `environmentIntensity` prop: drei applies it from an effect that doesn't
-// declare it as a dependency, so the prop only lands while `children` changes
-// identity every render — coupling a user-facing control to an upstream bug AND
-// to the re-bake cost above. drei's `applyProps` skips `undefined`, so omitting
-// the prop leaves this write untouched when its effect *applies*.
+// declare it as a dependency. drei's `applyProps` skips `undefined`, so omitting
+// the prop leaves this write untouched when its effect applies.
//
// `reassertOn` exists because its *cleanup* does not: drei snapshots
// `scene.environmentIntensity` before we ever write it (so the snapshot is
@@ -157,7 +134,7 @@ export default function GlbViewer({
// sliders when left at full strength — exposing it as its own control is what
// makes Ambient/Key/Fill visibly matter (dial it to 0 for lights-only).
const [environmentIntensity, setEnvironmentIntensity] = useState(0.6);
- const [showEnvironmentBackground, setShowEnvironmentBackground] = useState(false);
+ const [showEnvironmentBackground, setShowEnvironmentBackground] = useState(true);
const [controlsOpen, setControlsOpen] = useState(false);
if (!src) return null;
const href = downloadHref || src;
@@ -194,13 +171,15 @@ export default function GlbViewer({
<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 background={showEnvironmentBackground} resolution={256}>
- {ENVIRONMENT_CONTENTS}
- </Environment>
- <EnvironmentIntensity value={environmentIntensity} reassertOn={showEnvironmentBackground} />
<Suspense fallback={null}>
+ {/* Keep the HDRI in public/ instead of using drei's remote presets:
+ preview lighting and the default backdrop must work offline. */}
+ <Environment
+ files={ENVIRONMENT_HDRI}
+ background={showEnvironmentBackground}
+ backgroundBlurriness={ENVIRONMENT_BACKGROUND_BLUR}
+ />
+ <EnvironmentIntensity value={environmentIntensity} reassertOn={showEnvironmentBackground} />
<Bounds fit clip observe margin={1.2}>
<GlbModel src={src} forceOpaque={forceOpaque} />
</Bounds>
diff --git a/client/src/components/media/GlbViewer.test.jsx b/client/src/components/media/GlbViewer.test.jsx
index 9a9e7dec95..59311e7599 100644
--- a/client/src/components/media/GlbViewer.test.jsx
+++ b/client/src/components/media/GlbViewer.test.jsx
@@ -1,6 +1,8 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { BoxGeometry, Group, Mesh, MeshStandardMaterial } from 'three';
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
// 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
@@ -21,12 +23,16 @@ vi.mock('@react-three/fiber', () => ({
vi.mock('@react-three/drei', () => ({
Canvas: () => null,
OrbitControls: () => null,
- Environment: ({ background, children }) => (
- <div data-testid="glb-environment" data-background={background ? 'visible' : 'hidden'}>
+ Environment: ({ background, backgroundBlurriness, files, children }) => (
+ <div
+ data-testid="glb-environment"
+ data-background={background ? 'visible' : 'hidden'}
+ data-background-blurriness={backgroundBlurriness}
+ data-files={files}
+ >
{children}
</div>
),
- Lightformer: () => null,
Bounds: () => null,
useGLTF: Object.assign(() => ({ scene: {} }), { clear: vi.fn() }),
}));
@@ -78,7 +84,7 @@ describe('GlbViewer', () => {
.toHaveStyle({ backgroundColor: '#f5f5f5' });
});
- it('offers basic lighting controls and can show the HDRI environment as the background', () => {
+ it('loads the bundled HDRI as a softly blurred background by default', () => {
render(<GlbViewer src="/data/models3d/robot-a1b2.glb" />);
openControls();
@@ -88,7 +94,16 @@ describe('GlbViewer', () => {
expect(ambient).toHaveValue('0.6');
expect(key).toHaveValue('1.2');
expect(fill).toHaveValue('0.4');
- expect(screen.getByTestId('glb-environment')).toHaveAttribute('data-background', 'hidden');
+ expect(screen.getByTestId('glb-environment')).toHaveAttribute(
+ 'data-files',
+ '/hdri/studio-small-08-1k.hdr',
+ );
+ expect(screen.getByTestId('glb-environment')).toHaveAttribute('data-background', 'visible');
+ expect(screen.getByTestId('glb-environment')).toHaveAttribute(
+ 'data-background-blurriness',
+ '0.2',
+ );
+ expect(screen.getByLabelText('Show HDRI background')).toBeChecked();
fireEvent.change(ambient, { target: { value: '1.4' } });
fireEvent.change(key, { target: { value: '2.2' } });
@@ -98,8 +113,14 @@ describe('GlbViewer', () => {
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');
+ expect(screen.getByLabelText('Show HDRI background')).not.toBeChecked();
+ expect(screen.getByTestId('glb-environment')).toHaveAttribute('data-background', 'hidden');
+ });
+
+ it('ships the referenced environment as a Radiance HDR asset', () => {
+ const hdriPath = resolve(process.cwd(), 'public/hdri/studio-small-08-1k.hdr');
+ const header = readFileSync(hdriPath).subarray(0, 128).toString('ascii');
+ expect(header).toMatch(/^#\?RADIANCE/);
});
// The image-based lighting drowned out the three light sliders at full