feat: GPU rendering + material matching + perf improvements

- GPU: fix Cycles device activation order — set compute_device_type
  BEFORE engine init, re-set AFTER open_mainfile wipes preferences
- GPU: remove _mark_sharp_and_seams edit-mode loop (redundant with
  Blender 5.0 shade_smooth_by_angle), saves ~200s/render on 175 parts
- Material: fix _AFN suffix mismatch — build AF-stripped mat_map keys
  and add prefix fallback in _apply_material_library (blender_render.py)
- Material: production GLB now uses get_material_library_path() which
  checks active AssetLibrary instead of empty legacy system setting
- Admin: RenderTemplateTable multi-select output types (M2M frontend)
- Admin: MaterialLibraryPanel replaced with link to Asset Libraries
- UX: move Toaster to top-left to avoid dispatch button overlap
- SQLAlchemy: add .unique() to all RenderTemplate M2M collection queries
- Logging: flush=True on all Blender progress prints, stdout reconfigure

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 19:05:03 +01:00
parent 934728da77
commit ee6eb34b4c
34 changed files with 1274 additions and 511 deletions
+125 -66
View File
@@ -9,8 +9,6 @@ import PricingTierTable from '../components/admin/PricingTierTable'
import OutputTypeTable from '../components/admin/OutputTypeTable'
import RenderTemplateTable from '../components/admin/RenderTemplateTable'
import { useAuthStore } from '../store/auth'
import { getMaterialLibraryInfo, uploadMaterialLibrary, deleteMaterialLibrary } from '../api/renderTemplates'
import type { MaterialLibraryInfo } from '../api/renderTemplates'
import { listPricingTiers } from '../api/pricing'
import { listOutputTypes } from '../api/outputTypes'
import {
@@ -92,6 +90,10 @@ export default function AdminPage() {
gltf_material_quality: string
gltf_pbr_roughness: number
gltf_pbr_metallic: number
gltf_preview_linear_deflection: number
gltf_preview_angular_deflection: number
gltf_production_linear_deflection: number
gltf_production_angular_deflection: number
}
const { data: settings } = useQuery({
@@ -115,6 +117,9 @@ export default function AdminPage() {
const [viewerDraft, setViewerDraft] = useState<Partial<Settings>>({})
const viewer3d = { ...settings, ...viewerDraft } as Settings
const [tessellationDraft, setTessellationDraft] = useState<Partial<Settings>>({})
const tess = { ...settings, ...tessellationDraft } as Settings
const { data: rendererStatus, refetch: refetchStatus } = useQuery({
queryKey: ['renderer-status'],
queryFn: async () => {
@@ -166,6 +171,14 @@ export default function AdminPage() {
onError: (e: any) => toast.error(e.response?.data?.detail || 'Failed'),
})
const recoverStuckMut = useMutation({
mutationFn: () => api.post('/admin/settings/recover-stuck-processing'),
onSuccess: (res) => {
toast.success(res.data.message || 'Stuck files recovered')
},
onError: (e: any) => toast.error(e.response?.data?.detail || 'Failed'),
})
const seedWorkflowsMut = useMutation({
mutationFn: () => api.post('/admin/settings/seed-workflows'),
onSuccess: (res) => {
@@ -636,6 +649,18 @@ export default function AdminPage() {
<div className="space-y-3">
<p className="text-xs font-semibold text-content-secondary uppercase tracking-wide">Maintenance</p>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div className="flex flex-col gap-1">
<button
onClick={() => recoverStuckMut.mutate()}
disabled={recoverStuckMut.isPending}
className="btn-secondary text-sm w-full justify-start border-amber-400/40 text-amber-600 hover:bg-amber-50"
title="Reset CAD files stuck in 'processing' for more than 10 minutes to 'failed'. Runs automatically every 5 min."
>
<RefreshCw size={14} className={recoverStuckMut.isPending ? 'animate-spin' : ''} />
{recoverStuckMut.isPending ? 'Recovering…' : 'Recover Stuck Processing'}
</button>
<p className="text-xs text-content-muted">Resets files stuck in 'processing' to 'failed'. Runs automatically every 5 min.</p>
</div>
<div className="flex flex-col gap-1">
<button
onClick={() => processUnprocessedMut.mutate()}
@@ -1091,6 +1116,94 @@ export default function AdminPage() {
</div>
</div>
{/* ------------------------------------------------------------------ */}
{/* Tessellation Quality */}
{/* ------------------------------------------------------------------ */}
<div className="card">
<div className="p-4 border-b border-border-default">
<h2 className="font-semibold text-content">Tessellation Quality</h2>
<p className="text-sm text-content-muted mt-0.5">
OCC mesh precision for GLB export. Lower values = finer mesh + larger files + slower export.
</p>
</div>
<div className="p-4 space-y-6">
<div className="grid grid-cols-2 gap-6">
<div className="space-y-4">
<p className="text-xs font-semibold text-content-secondary uppercase tracking-wide">Preview (Geometry GLB)</p>
<div className="flex items-center gap-3">
<label className="text-sm text-content-secondary w-36 shrink-0">Linear deflection</label>
<input
type="number"
step="0.01"
min="0.001"
max="10"
value={tess.gltf_preview_linear_deflection ?? 0.1}
onChange={e => setTessellationDraft(d => ({ ...d, gltf_preview_linear_deflection: parseFloat(e.target.value) }))}
className="w-24 px-3 py-1.5 border border-border-default rounded-md text-sm focus:outline-none focus:border-blue-400"
/>
<span className="text-sm text-content-muted">mm</span>
</div>
<div className="flex items-center gap-3">
<label className="text-sm text-content-secondary w-36 shrink-0">Angular deflection</label>
<input
type="number"
step="0.05"
min="0.05"
max="1.5"
value={tess.gltf_preview_angular_deflection ?? 0.5}
onChange={e => setTessellationDraft(d => ({ ...d, gltf_preview_angular_deflection: parseFloat(e.target.value) }))}
className="w-24 px-3 py-1.5 border border-border-default rounded-md text-sm focus:outline-none focus:border-blue-400"
/>
<span className="text-sm text-content-muted">rad</span>
</div>
<p className="text-xs text-content-muted">Used when clicking "Generate Geometry GLB".</p>
</div>
<div className="space-y-4">
<p className="text-xs font-semibold text-content-secondary uppercase tracking-wide">Production (Production GLB)</p>
<div className="flex items-center gap-3">
<label className="text-sm text-content-secondary w-36 shrink-0">Linear deflection</label>
<input
type="number"
step="0.005"
min="0.001"
max="10"
value={tess.gltf_production_linear_deflection ?? 0.03}
onChange={e => setTessellationDraft(d => ({ ...d, gltf_production_linear_deflection: parseFloat(e.target.value) }))}
className="w-24 px-3 py-1.5 border border-border-default rounded-md text-sm focus:outline-none focus:border-blue-400"
/>
<span className="text-sm text-content-muted">mm</span>
</div>
<div className="flex items-center gap-3">
<label className="text-sm text-content-secondary w-36 shrink-0">Angular deflection</label>
<input
type="number"
step="0.05"
min="0.05"
max="1.5"
value={tess.gltf_production_angular_deflection ?? 0.2}
onChange={e => setTessellationDraft(d => ({ ...d, gltf_production_angular_deflection: parseFloat(e.target.value) }))}
className="w-24 px-3 py-1.5 border border-border-default rounded-md text-sm focus:outline-none focus:border-blue-400"
/>
<span className="text-sm text-content-muted">rad</span>
</div>
<p className="text-xs text-content-muted">Used when clicking "Generate Production GLB". Smaller = smoother surfaces.</p>
</div>
</div>
<div className="flex gap-2">
<button
onClick={() => { updateSettingsMut.mutate(tessellationDraft); setTessellationDraft({}) }}
disabled={Object.keys(tessellationDraft).length === 0 || updateSettingsMut.isPending}
className="btn-primary disabled:opacity-40"
>
Save Tessellation Settings
</button>
{Object.keys(tessellationDraft).length > 0 && (
<button onClick={() => setTessellationDraft({})} className="btn-secondary">Reset</button>
)}
</div>
</div>
</div>
{/* ------------------------------------------------------------------ */}
{/* Material Library link */}
{/* ------------------------------------------------------------------ */}
@@ -1111,73 +1224,19 @@ export default function AdminPage() {
function MaterialLibraryPanel() {
const qc = useQueryClient()
const { data: info } = useQuery({
queryKey: ['material-library-info'],
queryFn: getMaterialLibraryInfo,
})
const uploadMut = useMutation({
mutationFn: (file: File) => uploadMaterialLibrary(file),
onSuccess: () => {
toast.success('Material library uploaded')
qc.invalidateQueries({ queryKey: ['material-library-info'] })
},
onError: (e: any) => toast.error(e.response?.data?.detail || 'Upload failed'),
})
const deleteMut = useMutation({
mutationFn: deleteMaterialLibrary,
onSuccess: () => {
toast.success('Material library removed')
qc.invalidateQueries({ queryKey: ['material-library-info'] })
},
onError: (e: any) => toast.error(e.response?.data?.detail || 'Delete failed'),
})
function handleFileChange(e: React.ChangeEvent<HTMLInputElement>) {
const file = e.target.files?.[0]
if (file) uploadMut.mutate(file)
e.target.value = ''
}
return (
<div className="space-y-3">
<h4 className="text-sm font-semibold text-content-secondary">Material Library (.blend)</h4>
<div className="space-y-2">
<h4 className="text-sm font-semibold text-content-secondary">Material Library</h4>
<p className="text-xs text-content-muted">
Materials in this file can be assigned to product parts when "Material Replace" is enabled on a template.
Materials for "Material Replace" are now managed via Asset Libraries. The active asset library's materials are used at render time.
</p>
{info?.exists ? (
<div className="flex items-center gap-3 p-3 rounded-lg border border-border-default bg-status-success-bg">
<CheckCircle2 size={16} className="text-green-500 shrink-0" />
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-content">{info.filename}</p>
<p className="text-xs text-content-muted">
{info.size_bytes ? `${(info.size_bytes / 1024 / 1024).toFixed(1)} MB` : ''}
</p>
</div>
<label className="flex items-center gap-1 px-3 py-1.5 text-sm border border-border-default rounded-md bg-surface text-content-secondary hover:bg-surface-hover cursor-pointer">
<Upload size={14} /> Replace
<input type="file" accept=".blend" className="hidden" onChange={handleFileChange} />
</label>
<button
onClick={() => { if (confirm('Remove material library?')) deleteMut.mutate() }}
disabled={deleteMut.isPending}
className="p-1.5 text-red-500 hover:bg-red-50 rounded"
title="Remove library"
>
<Trash2 size={16} />
</button>
</div>
) : (
<label className="flex items-center gap-2 px-4 py-3 border-2 border-dashed border-border-default rounded-lg text-sm text-content-muted hover:border-blue-400 hover:text-blue-600 cursor-pointer transition-colors">
<Upload size={16} />
{uploadMut.isPending ? 'Uploading...' : 'Click to upload material library .blend file'}
<input type="file" accept=".blend" className="hidden" onChange={handleFileChange} />
</label>
)}
<Link
to="/asset-libraries"
className="inline-flex items-center gap-1 text-sm text-accent hover:text-accent-hover"
>
<Layers size={14} />
Manage Asset Libraries
</Link>
</div>
)
}