fix: media thumbnails, product dimensions, inline 3D viewer, GLB export

Bug A: Media Library thumbnails were gray because <img src> cannot send
JWT auth headers. Added useAuthBlob() hook (fetch + createObjectURL) in
MediaBrowser.tsx. Also fixed publish_asset Celery task to populate
product_id + cad_file_id on MediaAsset for thumbnail fallback resolution.

Bug B: Product dimensions now shown in Product Details card with Ruler
icon and "from CAD" label when cad_mesh_attributes.dimensions_mm exists.

Bug C: Replaced 128×128 CAD thumbnail with InlineCadViewer component.
Queries gltf_geometry MediaAssets, fetches GLB via auth fetch → blob URL
→ Three.js Canvas with OrbitControls. Falls back to thumbnail + "Load 3D
Model" button. Polling when GLB generation is in progress.

Bug D: trimesh was in [cad] optional extra but Dockerfile only installed
[dev]. Changed to pip install -e ".[dev,cad]" — trimesh now available in
backend container, GLB + Colors export works.

Also added bbox extraction (STL-first numpy parsing) in render_step_thumbnail
and admin "Re-extract CAD Metadata" bulk endpoint.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 13:27:46 +01:00
parent 10ed1b5e91
commit bfd58e3419
24 changed files with 1502 additions and 218 deletions
+174
View File
@@ -86,6 +86,13 @@ export default function AdminPage() {
smtp_user: string
smtp_password: string
smtp_from_address: string
gltf_scale_factor: number
gltf_smooth_normals: boolean
viewer_max_distance: number
viewer_min_distance: number
gltf_material_quality: string
gltf_pbr_roughness: number
gltf_pbr_metallic: number
}
const { data: settings } = useQuery({
@@ -106,6 +113,9 @@ export default function AdminPage() {
const [blenderDraft, setBlenderDraft] = useState<Partial<Settings>>({})
const blender = { ...settings, ...blenderDraft } as Settings
const [viewerDraft, setViewerDraft] = useState<Partial<Settings>>({})
const viewer3d = { ...settings, ...viewerDraft } as Settings
const { data: rendererStatus, refetch: refetchStatus } = useQuery({
queryKey: ['renderer-status'],
queryFn: async () => {
@@ -157,6 +167,14 @@ export default function AdminPage() {
onError: (e: any) => toast.error(e.response?.data?.detail || 'Failed'),
})
const reextractMetadataMut = useMutation({
mutationFn: () => api.post('/admin/settings/reextract-metadata'),
onSuccess: (res) => {
toast.success(res.data.message || 'Metadata re-extraction queued')
},
onError: (e: any) => toast.error(e.response?.data?.detail || 'Failed'),
})
const seedWorkflowsMut = useMutation({
mutationFn: () => api.post('/admin/settings/seed-workflows'),
onSuccess: (res) => {
@@ -698,6 +716,18 @@ export default function AdminPage() {
</button>
<p className="text-xs text-content-muted">Generates low + high STL files for completed STEP files missing them.</p>
</div>
<div className="flex flex-col gap-1">
<button
onClick={() => reextractMetadataMut.mutate()}
disabled={reextractMetadataMut.isPending}
className="btn-secondary text-sm w-full justify-start"
title="Re-extract OCC bounding box and sharp-edge data for all completed CAD files"
>
<RefreshCw size={14} className={reextractMetadataMut.isPending ? 'animate-spin' : ''} />
{reextractMetadataMut.isPending ? 'Queueing…' : 'Re-extract CAD Metadata'}
</button>
<p className="text-xs text-content-muted">Updates dimensions and edge data for existing files (no re-render).</p>
</div>
<div className="flex flex-col gap-1">
<button
onClick={() => seedWorkflowsMut.mutate()}
@@ -961,6 +991,150 @@ export default function AdminPage() {
/>
)}
{/* ------------------------------------------------------------------ */}
{/* 3D Viewer & GLB Export Settings */}
{/* ------------------------------------------------------------------ */}
<div className="card">
<div className="p-4 border-b border-border-default">
<h2 className="font-semibold text-content">3D Viewer & GLB Export</h2>
<p className="text-sm text-content-muted mt-0.5">
Settings for the 3D viewer and GLB geometry export
</p>
</div>
<div className="p-4 space-y-4">
{/* Scale Factor */}
<div className="grid grid-cols-2 gap-4">
<div>
<label className="text-sm font-medium text-content-muted block mb-1">
GLB Scale Factor (mm→m)
</label>
<input
type="number"
step="0.0001"
min="0.0001"
max="1"
value={viewer3d.gltf_scale_factor ?? 0.001}
onChange={e => setViewerDraft(d => ({ ...d, gltf_scale_factor: parseFloat(e.target.value) }))}
className="input w-full"
/>
<p className="text-xs text-content-muted mt-0.5">Default 0.001 converts mm to meters</p>
</div>
<div>
<label className="text-sm font-medium text-content-muted block mb-1">
Smooth Normals
</label>
<label className="flex items-center gap-2 mt-2 cursor-pointer">
<input
type="checkbox"
checked={viewer3d.gltf_smooth_normals ?? true}
onChange={e => setViewerDraft(d => ({ ...d, gltf_smooth_normals: e.target.checked }))}
className="w-4 h-4"
/>
<span className="text-sm text-content">Apply Laplacian smoothing on export</span>
</label>
</div>
</div>
{/* Camera / Zoom Limits */}
<div className="grid grid-cols-2 gap-4">
<div>
<label className="text-sm font-medium text-content-muted block mb-1">
Max Zoom-Out Distance
</label>
<input
type="number"
step="1"
min="1"
max="10000"
value={viewer3d.viewer_max_distance ?? 50}
onChange={e => setViewerDraft(d => ({ ...d, viewer_max_distance: parseFloat(e.target.value) }))}
className="input w-full"
/>
</div>
<div>
<label className="text-sm font-medium text-content-muted block mb-1">
Min Zoom-In Distance
</label>
<input
type="number"
step="0.001"
min="0.0001"
max="1"
value={viewer3d.viewer_min_distance ?? 0.001}
onChange={e => setViewerDraft(d => ({ ...d, viewer_min_distance: parseFloat(e.target.value) }))}
className="input w-full"
/>
</div>
</div>
{/* PBR Material Quality */}
<div className="grid grid-cols-3 gap-4">
<div>
<label className="text-sm font-medium text-content-muted block mb-1">
GLB Material Mode
</label>
<select
value={viewer3d.gltf_material_quality ?? 'pbr_colors'}
onChange={e => setViewerDraft(d => ({ ...d, gltf_material_quality: e.target.value }))}
className="input w-full"
>
<option value="none">None (geometry only)</option>
<option value="pbr_colors">PBR Colors (from part colors)</option>
</select>
</div>
<div>
<label className="text-sm font-medium text-content-muted block mb-1">
PBR Roughness (01)
</label>
<input
type="number"
step="0.05"
min="0"
max="1"
value={viewer3d.gltf_pbr_roughness ?? 0.4}
onChange={e => setViewerDraft(d => ({ ...d, gltf_pbr_roughness: parseFloat(e.target.value) }))}
className="input w-full"
/>
</div>
<div>
<label className="text-sm font-medium text-content-muted block mb-1">
PBR Metallic (01)
</label>
<input
type="number"
step="0.05"
min="0"
max="1"
value={viewer3d.gltf_pbr_metallic ?? 0.6}
onChange={e => setViewerDraft(d => ({ ...d, gltf_pbr_metallic: parseFloat(e.target.value) }))}
className="input w-full"
/>
</div>
</div>
<div className="flex gap-2">
<button
onClick={() => {
updateSettingsMut.mutate(viewerDraft)
setViewerDraft({})
}}
disabled={Object.keys(viewerDraft).length === 0 || updateSettingsMut.isPending}
className="btn-primary disabled:opacity-40"
>
Save 3D Settings
</button>
{Object.keys(viewerDraft).length > 0 && (
<button
onClick={() => setViewerDraft({})}
className="btn-secondary"
>
Reset
</button>
)}
</div>
</div>
</div>
{/* ------------------------------------------------------------------ */}
{/* Material Library link */}
{/* ------------------------------------------------------------------ */}