Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat(viewer): camera-following headlamp + tighter settled card

Sidwebworks47614c01c725
diff --git a/apps/erp/app/components/CadModel.tsx b/apps/erp/app/components/CadModel.tsx
index 513a04ad95..552ce55987 100644
--- a/apps/erp/app/components/CadModel.tsx
+++ b/apps/erp/app/components/CadModel.tsx
@@ -437,11 +437,6 @@ const CadModel = ({
? "Retry"
: "Load Preview"
}
- settledHint={
- artifacts?.optimizeStatus === "Failed"
- ? "The last attempt didn't finish. You can try again."
- : undefined
- }
onCancelWait={modelPath ? onCancelWait : undefined}
onDelete={canDelete ? deleteModal.onOpen : undefined}
/>
diff --git a/packages/viewer/src/AssemblyViewer.tsx b/packages/viewer/src/AssemblyViewer.tsx
index 562ca2a445..a161873a9b 100644
--- a/packages/viewer/src/AssemblyViewer.tsx
+++ b/packages/viewer/src/AssemblyViewer.tsx
@@ -1,7 +1,7 @@
import { GizmoHelper, GizmoViewcube, OrbitControls } from "@react-three/drei";
import { Canvas, useFrame, useThree } from "@react-three/fiber";
-import { type ReactNode, useEffect, useRef } from "react";
-import { Vector3 } from "three";
+import { type ReactNode, useEffect, useMemo, useRef } from "react";
+import { type DirectionalLight, Object3D, Vector3 } from "three";
import type { OrbitControls as OrbitControlsImpl } from "three-stdlib";
import { cn } from "./utils";
@@ -72,8 +72,12 @@ export function AssemblyViewer({
groundColor={isDarkMode ? 0x202329 : 0xd4d4d8}
intensity={0.5}
/>
- <directionalLight position={[1, 1, 1]} intensity={1.6} />
- <directionalLight position={[-1, 0.5, -1]} intensity={0.8} />
+ {/* CAD-style headlamp: the key light follows the camera so the facing
+ side is always lit (static world-space lights leave the model's far
+ side dark once you orbit around). See HeadLight below. */}
+ <HeadLight intensity={1.6} />
+ {/* Weak static back fill so silhouettes keep a rim of depth. */}
+ <directionalLight position={[-1, 0.5, -1]} intensity={0.4} />
<OrbitControls
makeDefault
enabled={interactive}
@@ -106,6 +110,47 @@ export function AssemblyViewer({
);
}
+/**
+ * Camera-following key light (CAD headlamp). Repositioned every frame at the
+ * camera, offset toward the camera's up+right so the lighting keeps some
+ * directionality (a light exactly on the view axis flattens all shading), and
+ * aimed at the orbit target so the lit side is always the one facing the user.
+ */
+function HeadLight({ intensity }: { intensity: number }) {
+ const camera = useThree((state) => state.camera);
+ const controls = useThree(
+ (state) => state.controls
+ ) as unknown as OrbitControlsImpl | null;
+ const light = useRef<DirectionalLight>(null);
+ // The directional light aims at a target object, which must live in the
+ // scene graph for its matrix to update — see the <primitive> below.
+ const target = useMemo(() => new Object3D(), []);
+ const up = useRef(new Vector3());
+ const right = useRef(new Vector3());
+
+ useFrame(() => {
+ const l = light.current;
+ if (!l) return;
+ const anchor = controls?.target ?? target.position;
+ const dist = Math.max(camera.position.distanceTo(anchor), 1);
+ up.current.set(0, 1, 0).applyQuaternion(camera.quaternion);
+ right.current.set(1, 0, 0).applyQuaternion(camera.quaternion);
+ l.position
+ .copy(camera.position)
+ .addScaledVector(up.current, dist * 0.35)
+ .addScaledVector(right.current, dist * 0.35);
+ if (controls) target.position.copy(controls.target);
+ target.updateMatrixWorld();
+ });
+
+ return (
+ <>
+ <directionalLight ref={light} target={target} intensity={intensity} />
+ <primitive object={target} />
+ </>
+ );
+}
+
// Wheel → zoom impulse (accumulated into velocity). Larger = zoom reaches further
// per notch.
const ZOOM_SENSITIVITY = 0.00016;
diff --git a/packages/viewer/src/ModelPreview.tsx b/packages/viewer/src/ModelPreview.tsx
index 3c8cd86d0c..80e5a7ab81 100644
--- a/packages/viewer/src/ModelPreview.tsx
+++ b/packages/viewer/src/ModelPreview.tsx
@@ -59,9 +59,6 @@ export type ModelPreviewProps = {
/** Label for the retry action — e.g. "Load Preview" when the model was never
* optimised (first-time affordance) vs the default "Retry" after a failure. */
retryLabel?: string;
- /** Supporting line under the settled-state title — the host can explain a
- * failed attempt; defaults to the generate-on-demand invitation. */
- settledHint?: string;
/** Called when the user cancels the "preparing" wait — the host should cancel
* the in-flight optimise (job + run) so the row doesn't stay stuck. */
onCancelWait?: () => void;
@@ -90,7 +87,6 @@ export function ModelPreview({
downloadName,
onRetry,
retryLabel = "Retry",
- settledHint,
onCancelWait,
mode = "dark",
onDelete,
@@ -286,29 +282,8 @@ export function ModelPreview({
<div className="flex size-11 items-center justify-center rounded-full bg-muted/60">
<LuBox className="size-5 text-muted-foreground" />
</div>
- <div className="flex flex-col gap-1">
- <p className="text-sm font-medium text-foreground">3D preview</p>
- <p className="max-w-[240px] text-xs text-pretty text-muted-foreground">
- {settledHint ??
- "Generate an interactive view of this model on demand."}
- </p>
- </div>
- <div className="flex items-center gap-2">
- {onRetry && (
- <Button size="sm" onClick={onRetry}>
- {retryLabel}
- </Button>
- )}
- {onDelete && (
- <IconButton
- aria-label="Delete model"
- className="text-muted-foreground hover:bg-destructive hover:text-destructive-foreground"
- icon={<LuTrash2 />}
- variant="ghost"
- onClick={onDelete}
- />
- )}
- </div>
+ <p className="text-sm font-medium text-foreground">3D preview</p>
+ {onRetry && <Button onClick={onRetry}>{retryLabel}</Button>}
</div>
) : null}
</div>