Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions INTERFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,18 @@ the UI is a view `heph render` can reproduce; free orbit snapshots the nearest
readout shows camera state and scale — a screen-space fact, never rendered
through `<Fact>`.

**Appearance cluster — operator chrome, bound to the pin.** A small control
strip on the viewport drives the display authorship §3.11 already specified:
wireframe, fit, ortho, grid, axis triad, material override. Defaults match the
authored picture (shaded, orthographic, grid and triad on, material at
`--viewport-part` with the ≥4.5:1 part-vs-ground floor). Fit re-applies
`cameras.py`'s framing for the current named view. Wireframe hides the fill and
keeps the silhouette. Ortho off is a perspective viewing aid; the named views
and `heph render` remain orthographic. The cluster is **not** workspace state:
§4.5 stays closed. It authors no material the engine did not already project.
G4.5's thresholds are unchanged — the strip is fixed-size chrome and does not
move on a visibility toggle.

During a rebuild the viewport keeps the **last completed** artifact and the
header shows `stale` with the ref it is showing. `architecture.md` §3 already
guarantees a long build never blocks inspection; the UI's job is to express
Expand Down
3 changes: 2 additions & 1 deletion web/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ frames, so the two cameras agree by construction.
`[data-field]`, `[data-check]`+`[data-badge]`, `[data-dfm-finding]`,
`[data-dfm-descriptor]`, `[data-visibility-toggle]`, `[data-testid="viewport"]`
with `data-glb-state` / `data-artifact-ref` / `data-section-state`,
`[data-viewport-canvas]`, `[data-explode-t]`, `[data-section-control]` with
`[data-viewport-canvas]`, `[data-appearance]` / `[data-appearance-control]`,
`[data-explode-t]`, `[data-section-control]` with
`data-section-plane`, `[data-section-plate]`+`data-plate-ref`,
`[data-testid="stream-panel"|"transcript"]`, `[data-history-state]`,
`[data-history-pages]`, `[data-stream-state]`, `[data-session-tab]` with
Expand Down
16 changes: 16 additions & 0 deletions web/e2e/design-system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ test("the grid readout reports the grid that exists, and the triad names its axe
// colour never replaces the letter, so all three axes are named in words a
// screen reader and a monochrome print both keep.
await expect(page.locator("[data-axis-triad]")).toBeVisible();
// §5.5's operator cluster: present, defaults matching the authored picture.
// Existing selectors above are unchanged; this only adds the new strip.
await expect(page.locator("[data-appearance]")).toBeVisible();
for (const [control, pressed] of [
["wireframe", "false"],
["ortho", "true"],
["grid", "true"],
["triad", "true"],
["materialOverride", "true"],
] as const) {
await expect(page.locator(`[data-appearance-control="${control}"]`)).toHaveAttribute(
"aria-pressed",
pressed,
);
}
await expect(page.locator('[data-appearance-control="fit"]')).toBeEnabled();
for (const axis of ["x", "y", "z"]) {
await expect(page.locator(`[data-axis-label="${axis}"]`)).toHaveText(axis.toUpperCase());
await expect(page.locator(`[data-axis="${axis}"]`)).toHaveAttribute(
Expand Down
27 changes: 27 additions & 0 deletions web/src/components/stage/viewport/AppearanceControls.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2026 The Hephaestus Authors
* SPDX-License-Identifier: Apache-2.0
*
* Operator appearance cluster. Layout only — buttons are the system primitive.
*
* Top-left, opposite the view cube, so the two orientation surfaces do not
* share a corner. Fixed size: wrapping is allowed but the cluster does not
* grow when a solid is hidden, which is the G4.5 constraint GridReadout
* already documents.
*/

.cluster {
position: absolute;
top: var(--space-3);
left: var(--space-3);
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 2px; /* one-off: a control cluster is tighter than --gap-stack */
max-width: 22rem;
padding: var(--space-1);
border: 1px solid var(--border-strong);
border-radius: var(--radius-card);
background: var(--surface-overlay);
box-shadow: var(--elev-popover);
}
102 changes: 102 additions & 0 deletions web/src/components/stage/viewport/AppearanceControls.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2026 The Hephaestus Authors
// SPDX-License-Identifier: Apache-2.0
//
// Operator appearance cluster (INTERFACE.md §3.11, §5.5).
//
// §3.11 already authors the picture. This strip is the operator chrome that
// drives it: wireframe, fit, ortho, grid, axis triad, material override. It is
// a small cluster on the viewport that loads the pinned GLB — not a second
// inspector, and not a second toolbar.
//
// THE STORE IS THE AUTHORITY, the same way ExplodeSlider writes `explode_t`
// and never touches the scene. `Viewport.tsx` has one effect per flag and
// pushes it into the engine, so the canvas and the buttons cannot disagree.
// Fit is the exception that proves the rule: it is an action, not a flag, and
// it calls the engine's existing `frame()` — `cameras.py`'s construction —
// rather than inventing a second camera.
//
// DEFAULTS ARE THE AUTHORED PICTURE. A strip that arrived pressed-off would
// move G4.5's control-region pixels and §3.11.2's contrast floor by existing.
// The cluster is fixed-size chrome and does not grow on a visibility toggle.
//
// No new icon id: §3.12 is closed at 18. The words live in `copy.ts`.

import { useSyncExternalStore } from "react";
import { copy } from "../../../copy";
import { appearanceStore, type AppearanceToggle } from "../../../state/appearance";
import { Button } from "../../../system";
import styles from "./AppearanceControls.module.css";

export interface AppearanceControlsProps {
/** False when no pinned GLB is on the canvas — Fit has nothing to frame. */
readonly canFit: boolean;
/** Re-apply the current named view's framing. */
readonly onFit: () => void;
}

const TOGGLE_COPY: Readonly<Record<AppearanceToggle, { label: string; explain: string }>> = {
wireframe: copy.viewport.appearance.wireframe,
ortho: copy.viewport.appearance.ortho,
grid: copy.viewport.appearance.grid,
triad: copy.viewport.appearance.triad,
materialOverride: copy.viewport.appearance.material,
};

/** Issue #10's listed order: wireframe / fit / ortho / grid / triad / material. */
const CLUSTER_ORDER = ["wireframe", "fit", "ortho", "grid", "triad", "materialOverride"] as const;

export function AppearanceControls({ canFit, onFit }: AppearanceControlsProps): React.JSX.Element {
const appearance = useSyncExternalStore(
appearanceStore.subscribe,
appearanceStore.getSnapshot,
appearanceStore.getSnapshot,
);

return (
<div
className={styles["cluster"]}
data-appearance=""
role="toolbar"
aria-label={copy.viewport.appearance.label}
>
{CLUSTER_ORDER.map((field) =>
field === "fit" ? (
canFit ? (
<Button
key="fit"
variant="quiet"
data-appearance-control="fit"
title={copy.viewport.appearance.fit.explain}
onClick={onFit}
>
{copy.viewport.appearance.fit.label}
</Button>
) : (
<Button
key="fit"
variant="quiet"
data-appearance-control="fit"
disabled
reason={copy.viewport.appearance.fit.disabled}
>
{copy.viewport.appearance.fit.label}
</Button>
)
) : (
<Button
key={field}
variant="toggle"
pressed={appearance[field]}
data-appearance-control={field}
title={TOGGLE_COPY[field].explain}
onClick={() => {
appearanceStore.toggle(field);
}}
>
{TOGGLE_COPY[field].label}
</Button>
),
)}
</div>
);
}
4 changes: 4 additions & 0 deletions web/src/components/stage/viewport/AxisTriad.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* permitted against.
*/

.triad[data-axis-hidden] {
visibility: hidden;
}

.triad {
position: absolute;
/* One-off geometric offset: the readout is `--space-3` from the bottom and is
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/stage/viewport/AxisTriad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ const LABEL_REACH = 1.42;
export interface AxisTriadProps {
/** The live engine, or `null` before it exists / after it is disposed. */
readonly engine: ViewportEngine | null;
/** §5.5's operator toggle. Default on — the authored picture. */
readonly visible?: boolean;
}

export function AxisTriad({ engine }: AxisTriadProps): React.JSX.Element {
export function AxisTriad({ engine, visible = true }: AxisTriadProps): React.JSX.Element {
const lines = useRef<Partial<Record<Axis, SVGLineElement | null>>>({});
const labels = useRef<Partial<Record<Axis, SVGTextElement | null>>>({});

Expand Down Expand Up @@ -95,9 +97,11 @@ export function AxisTriad({ engine }: AxisTriadProps): React.JSX.Element {
<svg
className={styles["triad"]}
data-axis-triad=""
{...(visible ? {} : { "data-axis-hidden": "" })}
viewBox={`0 0 ${String(CENTRE * 2)} ${String(CENTRE * 2)}`}
role="img"
aria-label={copy.viewport.triad.label}
aria-hidden={!visible}
>
{AXES.map((axis) => (
<line
Expand Down
7 changes: 4 additions & 3 deletions web/src/components/stage/viewport/Viewport.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@
pointer-events: none;
}

/* §5.3: the live cut says, in words, that it is not an evidentiary render. */
/* §5.3: the live cut says, in words, that it is not an evidentiary render.
Sits under the appearance cluster so the two plates do not share a corner. */
.previewNote {
position: absolute;
top: var(--space-2);
left: var(--space-2);
top: calc(var(--space-3) + 5.5rem);
left: var(--space-3);
display: flex;
align-items: center;
gap: var(--space-1);
Expand Down
48 changes: 43 additions & 5 deletions web/src/components/stage/viewport/Viewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
//
// The viewport (INTERFACE.md §5), and the whole of the client's share of
// rendering: a three.js canvas over the **pinned** artifact's GLB, four overlay
// controls, and one server-rendered plate layer.
// rendering: a three.js canvas over the **pinned** artifact's GLB, the overlay
// controls (view cube, appearance cluster, explode, section), and one
// server-rendered plate layer.
//
// The component is a *driver*. `viewport/engine.ts` owns the renderer, the scene
// and the camera; every workspace field this viewport reads gets exactly one
Expand Down Expand Up @@ -39,6 +40,8 @@ import { useGlb } from "../../../viewport/useGlb";
import { labelsForPart, visibilityStore } from "../../../state/visibility";
import { Badge, Chip, EmptyState, type IconId } from "../../../system";
import type { SolidIndex } from "../../../viewport/scene";
import { appearanceStore } from "../../../state/appearance";
import { AppearanceControls } from "./AppearanceControls";
import { AxisTriad } from "./AxisTriad";
import { ExplodeSlider } from "./ExplodeSlider";
import { GridReadout } from "./GridReadout";
Expand Down Expand Up @@ -77,6 +80,11 @@ export function Viewport(): React.JSX.Element {
visibilityStore.getSnapshot,
);
const hidden = useMemo(() => new Set(labelsForPart(hiddenKeys, part)), [hiddenKeys, part]);
const appearance = useSyncExternalStore(
appearanceStore.subscribe,
appearanceStore.getSnapshot,
appearanceStore.getSnapshot,
);
const glb = useGlb(artifactRef);

const hostRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -114,6 +122,17 @@ export function Viewport(): React.JSX.Element {
workspaceStore.update({ view: viewName });
}, []);

const onFit = useCallback((): void => {
const live = engineRef.current;
if (live === null) return;
// Fit is an explicit re-frame of the *current* named view, including after
// an orbit: `framedRef` would otherwise skip `frame()` for the same key.
live.frame(view, explodeT > 0);
framedRef.current = framingKey;
setScale(live.scale());
setStep(live.gridStep());
}, [view, explodeT, framingKey]);

// -- the engine: one per canvas, for the canvas's life --------------------
useEffect(() => {
const canvas = canvasRef.current;
Expand Down Expand Up @@ -232,6 +251,22 @@ export function Viewport(): React.JSX.Element {
engineRef.current?.setHidden(hidden);
}, [hidden, engineReady]);

// -- appearance: the operator cluster (§3.11, §5.5) -----------------------
useEffect(() => {
engineRef.current?.setAppearance({
wireframe: appearance.wireframe,
materialOverride: appearance.materialOverride,
});
}, [appearance.wireframe, appearance.materialOverride, engineReady]);

useEffect(() => {
engineRef.current?.setGridVisible(appearance.grid);
}, [appearance.grid, engineReady]);

useEffect(() => {
engineRef.current?.setOrtho(appearance.ortho);
}, [appearance.ortho, engineReady]);

// -- section: the live clipping preview (§5.3) ----------------------------
const plane = useMemo(
() => (sectionPlane === null ? null : parseSectionPlane(sectionPlane)),
Expand Down Expand Up @@ -323,13 +358,16 @@ export function Viewport(): React.JSX.Element {
overlay that never changes size, because a Playwright element
screenshot composites what is painted over the canvas and G4.5's
control region is exactly that frame (see `GridReadout`'s header). */}
<AxisTriad engine={engine} />
<AxisTriad engine={engine} visible={appearance.triad} />
{/* The grid step is a fact about a grid, so it is reported only while
there is one. Derived at render rather than cleared from the load
effect: an effect that calls `setState` in its own body is the
cascading render `react-hooks/set-state-in-effect` refuses, and the
answer is a pure function of state we already hold. */}
<GridReadout scale={scale} step={displayedRef === null ? 0 : step} />
answer is a pure function of state we already hold. Off is the same
as "no framing": the readout must not describe a grid the operator
has hidden. */}
<GridReadout scale={scale} step={displayedRef === null || !appearance.grid ? 0 : step} />
<AppearanceControls canFit={displayedRef !== null && state === "ready"} onFit={onFit} />
<div className={styles["controls"]}>
<ExplodeSlider />
{/* The bounds belong to the *loaded* GLB: while none is loaded the
Expand Down
37 changes: 36 additions & 1 deletion web/src/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const copy = {
reset: "Reset to default",
},

/** §5. The viewport, its two overlays, and every named absence it can reach. */
/** §5. The viewport, its overlays, and every named absence it can reach. */
viewport: {
label: "Geometry",
/**
Expand Down Expand Up @@ -251,6 +251,41 @@ export const copy = {
label: "Axis orientation",
axis: { x: "X", y: "Y", z: "Z" },
},
/**
* Operator appearance cluster (§3.11, §5.5). Words, not icons: the sprite
* is closed at 18 ids and these controls are a scan, not a status.
*/
appearance: {
label: "Viewport appearance",
wireframe: {
label: "Wireframe",
explain: "Hide the fill and keep the silhouette. Hidden solids still disappear with their outline.",
},
fit: {
label: "Fit",
explain:
"Frame the pinned artifact the way the renderer frames this named view. Orbit and zoom return to that framing.",
disabled: "No pinned artifact is on the canvas, so there is nothing to frame.",
},
ortho: {
label: "Ortho",
explain:
"Orthographic projection, matching the named views the renderer can reproduce. Off is a perspective viewing aid; Fit and the view cube stay the same camera.",
},
grid: {
label: "Grid",
explain: "Ground grid, spaced at the step the readout reports.",
},
triad: {
label: "Axes",
explain: "Axis triad in the same Z-up frame as the camera.",
},
material: {
label: "Material",
explain:
"Override every solid with the viewport part colour, at least 4.5:1 against the ground. Off restores the exporter's own material; it does not invent a new one.",
},
},
viewCube: {
label: "Standard views",
namedLabel: "Named views",
Expand Down
Loading
Loading