Files
Hartmut ca62319688 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>
2026-03-11 14:40:36 +01:00

103 lines
3.5 KiB
Python

"""MediaAsset service."""
import uuid
from sqlalchemy import select, update as sql_update
from sqlalchemy.ext.asyncio import AsyncSession
from app.domains.media.models import MediaAsset, MediaAssetType
_SORT_COLUMNS = {
"created_at": MediaAsset.created_at,
"file_size_bytes": MediaAsset.file_size_bytes,
"storage_key": MediaAsset.storage_key,
}
async def list_media_assets(
db: AsyncSession,
product_id: uuid.UUID | None = None,
order_line_id: uuid.UUID | None = None,
cad_file_id: uuid.UUID | None = None,
asset_type: MediaAssetType | None = None,
asset_types: list[MediaAssetType] | None = None,
is_archived: bool | None = False,
skip: int = 0,
limit: int = 50,
sort_by: str = "created_at",
sort_dir: str = "desc",
) -> list[MediaAsset]:
from sqlalchemy import asc, desc
col = _SORT_COLUMNS.get(sort_by, MediaAsset.created_at)
order = desc(col) if sort_dir == "desc" else asc(col)
q = select(MediaAsset).order_by(order)
if product_id:
q = q.where(MediaAsset.product_id == product_id)
if order_line_id:
q = q.where(MediaAsset.order_line_id == order_line_id)
if cad_file_id:
q = q.where(MediaAsset.cad_file_id == cad_file_id)
if asset_types:
q = q.where(MediaAsset.asset_type.in_(asset_types))
elif asset_type is not None:
q = q.where(MediaAsset.asset_type == asset_type)
if is_archived is not None:
q = q.where(MediaAsset.is_archived == is_archived)
q = q.offset(skip).limit(limit)
result = await db.execute(q)
return list(result.scalars().all())
async def get_media_asset(db: AsyncSession, asset_id: uuid.UUID) -> MediaAsset | None:
result = await db.execute(select(MediaAsset).where(MediaAsset.id == asset_id))
return result.scalar_one_or_none()
async def create_media_asset(db: AsyncSession, **kwargs) -> MediaAsset:
asset = MediaAsset(**kwargs)
db.add(asset)
await db.commit()
await db.refresh(asset)
return asset
async def archive_media_asset(db: AsyncSession, asset_id: uuid.UUID) -> MediaAsset | None:
await db.execute(
sql_update(MediaAsset).where(MediaAsset.id == asset_id).values(is_archived=True)
)
await db.commit()
return await get_media_asset(db, asset_id)
async def delete_media_asset(db: AsyncSession, asset_id: uuid.UUID) -> bool:
asset = await get_media_asset(db, asset_id)
if not asset:
return False
await db.delete(asset)
await db.commit()
return True
def get_download_url(asset: MediaAsset) -> str | None:
"""Return a backend proxy URL so the browser can always download the file.
Appends ?v={file_size_bytes} as a cache-buster: when a file is regenerated
in-place (same asset UUID, new content), the size changes and the URL changes,
which triggers a fresh fetch in InlineCadViewer's useEffect.
"""
v = asset.file_size_bytes or 0
return f"/api/media/{asset.id}/download?v={v}"
def get_thumbnail_url(asset: MediaAsset) -> str | None:
"""Return a no-auth preview URL for the asset.
Priority:
1. For image-type assets (still, thumbnail): the no-auth /thumbnail endpoint.
2. For any asset with a cad_file_id: the CAD thumbnail (also no-auth).
3. Otherwise None (caller may use _resolve_thumbnails_bulk for fallback).
"""
if asset.asset_type in (MediaAssetType.still, MediaAssetType.thumbnail):
return f"/api/media/{asset.id}/thumbnail"
if asset.cad_file_id:
return f"/api/cad/{asset.cad_file_id}/thumbnail"
return None