feat: sharp edge pipeline V02, tessellation presets, media cache-bust, GMSH plan

Sharp Edge Pipeline V02:
- export_step_to_gltf.py: replace BRep_Tool.Polygon3D_s (returns None in XCAF) with
  GCPnts_UniformAbscissa curve sampling at 0.3mm step — extracts 17,129 segment pairs
- Inject sharp_edge_pairs + sharp_threshold_deg into GLB extras (scenes[0].extras)
  via binary GLB JSON-chunk patching (no extra dependency)
- export_gltf.py: read schaeffler_sharp_edge_pairs from Blender scene custom props,
  apply via KD-tree to mark edges sharp=True + seam=True (OCC mm Z-up → Blender transform)
- tools/restore_sharp_marks.py: dual-pass (dihedral angle + OCC pairs), updated coordinate
  transform (X, -Z, Y) * 0.001

Tessellation:
- Admin UI: Draft / Standard / Fine preset buttons with active-state highlighting
- Default angular deflection: preview 0.5→0.1 rad, production 0.2→0.05 rad
- export_glb.py: read updated defaults from system_settings

Media / Cache:
- media/service.py: get_download_url appends ?v={file_size_bytes} cache-buster
- media/router.py: Cache-Control: no-cache for all download/thumbnail endpoints

Render pipeline:
- still_render.py / turntable_render.py: shared GPU activation + camera improvements
- render_order_line.py: global render position support
- render_thumbnail.py: updated defaults

Frontend:
- InlineCadViewer: file_size_bytes-aware URL update triggers re-fetch on regeneration
- ThreeDViewer: material panel, part selection, PBR mode improvements
- Admin.tsx: tessellation preset cards, GMSH setting dropdown
- MediaBrowser, ProductDetail, OrderDetail, Orders: various UI improvements
- New: MaterialPanel, GlobalRenderPositionsPanel, StepIndicator components
- New: renderPositions.ts API client

Plans / Docs:
- plan.md: GMSH Frontal-Delaunay tessellation plan (6 tasks)
- LEARNINGS.md: OCC Polygon3D_s None issue + GCPnts fix
- .gitignore: add backend/core (core dump from root process)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 14:40:36 +01:00
parent 202b06a026
commit ca62319688
70 changed files with 6551 additions and 1130 deletions
+61 -4
View File
@@ -2,6 +2,7 @@
import uuid
from datetime import datetime
from pathlib import Path
from typing import Literal
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.responses import FileResponse
@@ -15,12 +16,26 @@ from app.models.cad_file import CadFile, ProcessingStatus
from app.models.order import Order
from app.models.order_item import OrderItem
from app.models.user import User
from app.utils.auth import get_current_user
from app.utils.auth import get_current_user, is_privileged
from app.services.product_service import link_cad_to_product, lookup_product
router = APIRouter(prefix="/cad", tags=["cad"])
# ---------------------------------------------------------------------------
# Part-materials schemas
# ---------------------------------------------------------------------------
class PartMaterialEntry(BaseModel):
type: Literal["library", "hex"]
value: str # material name or hex color string
class PartMaterialsResponse(BaseModel):
cad_file_id: str
part_materials: dict[str, PartMaterialEntry] | None
# ---------------------------------------------------------------------------
# Schemas for match-to-order
# ---------------------------------------------------------------------------
@@ -273,7 +288,7 @@ async def generate_gltf_geometry(
Stores the result as a MediaAsset with asset_type='gltf_geometry'.
Uses export_step_to_gltf.py (OCP/pythonocc) — no Blender needed.
"""
if user.role.value not in ("admin", "project_manager"):
if not is_privileged(user):
raise HTTPException(status_code=403, detail="Insufficient permissions")
cad = await _get_cad_file(id, db)
@@ -296,7 +311,7 @@ async def generate_gltf_production(
Requires a gltf_geometry MediaAsset to already exist (run generate-gltf-geometry first).
Stores result as a MediaAsset with asset_type='gltf_production'.
"""
if user.role.value not in ("admin", "project_manager"):
if not is_privileged(user):
raise HTTPException(status_code=403, detail="Insufficient permissions")
cad = await _get_cad_file(id, db)
@@ -359,7 +374,7 @@ async def reset_stuck_processing(
Use when a file shows 'processing' indefinitely due to a worker crash.
After resetting, click 'Regen thumbnail' to retry.
"""
if user.role.value not in ("admin", "project_manager"):
if not is_privileged(user):
raise HTTPException(status_code=403, detail="Insufficient permissions")
cad = await _get_cad_file(id, db)
@@ -377,3 +392,45 @@ async def reset_stuck_processing(
return {"cad_file_id": str(cad.id), "status": "failed", "message": "Reset to 'failed'. Use 'Regen thumbnail' to retry."}
# ---------------------------------------------------------------------------
# Part-material assignment endpoints
# ---------------------------------------------------------------------------
@router.get("/{id}/part-materials", response_model=PartMaterialsResponse)
async def get_part_materials(
id: uuid.UUID,
user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
"""Return the saved part-material assignments for a CAD file."""
cad = await _get_cad_file(id, db)
return PartMaterialsResponse(
cad_file_id=str(cad.id),
part_materials=cad.part_materials,
)
@router.put("/{id}/part-materials", response_model=PartMaterialsResponse)
async def save_part_materials(
id: uuid.UUID,
body: dict[str, PartMaterialEntry],
user: User = Depends(get_current_user),
db: AsyncSession = Depends(get_db),
):
"""Replace the part-material assignment map for a CAD file.
Accepts a full dict of part-name -> {type, value} and overwrites the existing
assignment. Pass an empty dict to clear all assignments.
"""
if not is_privileged(user):
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Insufficient permissions")
cad = await _get_cad_file(id, db)
# Serialise Pydantic models to plain dicts for JSONB storage
cad.part_materials = {name: entry.model_dump() for name, entry in body.items()}
cad.updated_at = datetime.utcnow()
await db.commit()
await db.refresh(cad)
return PartMaterialsResponse(
cad_file_id=str(cad.id),
part_materials=cad.part_materials,
)