garage3d-webgpu-engine
Build or change the GARA-G 3D garage engine (three.js r186 WebGPURenderer + TSL, WebGL2 fallback) at a steady 60 fps on mid-range phones. Use when touching packages/app-pwa/src/garage/engine/, the garage scene, camera, part picking, health/x-ray view modes, adaptive quality, or the Svelte/Astro mounting of the canvas.
- License 许可
- MIT
- 所属仓库
- iberi22/skills
- 最近更新
- 2026-10-12
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- garage3d-webgpu-engine
- description
- Build or change the GARA-G 3D garage engine (three.js r186 WebGPURenderer + TSL, WebGL2 fallback) at a steady 60 fps on mid-range phones. Use when touching packages/app-pwa/src/garage/engine/, the garage scene, camera, part picking, health/x-ray view modes, adaptive quality, or the Svelte/Astro mounting of the canvas.
03 SKILL.md 正文
Garage 3D engine (WebGPU, 60 fps)
The engine is a facade (GarageEngineApi in src/garage/contracts.ts). The UI talks only to
that interface; nothing outside src/garage/engine/ imports three except templates and the lab.
Stack facts (verified on three 0.186.1)
import { WebGPURenderer, MeshPhysicalNodeMaterial, PMREMGenerator, ... } from 'three/webgpu'and TSL from'three/tsl'. Addons:three/addons/controls/OrbitControls.js,three/addons/environments/RoomEnvironment.js,three/addons/tsl/display/OutlineNode.js,three/addons/tsl/display/BloomNode.js.new WebGPURenderer({ canvas, antialias: true })picks WebGPU and falls back to WebGL2 by itself;forceWebGL: trueforces the fallback (use it for?gl=1).await renderer.init()before the first render (r186 throws on an uninitialized renderer).- Backend:
(renderer.backend as any).isWebGPUBackend ? 'webgpu' : 'webgl2'. - Stats:
renderer.info.render.drawCalls,renderer.info.render.triangles. - Headless Chromium in this repo does get WebGPU (verified: lab reports
backend: "webgpu"). - Post-processing:
new RenderPipeline(renderer)(r186 name;PostProcessingis the old alias) withpass(scene, camera)nodes. Only on thehightier.
Frame budget (60 fps = 16.7 ms; mid-range Android ≈ Adreno 610 / Mali-G57)
| Item | Budget |
|---|---|
| Scene draw calls | ≤ 120 (RENDER_BUDGET.sceneDrawCalls) |
| Vehicle triangles | ≤ 90k high / ≤ 35k low LOD |
| Pixel ratio | start min(dpr, 1.5) on touch devices, min(dpr, 2) desktop; governor may drop to 1.0 |
| Shadows | one directional shadow map, 1024 (medium) / 2048 (high), off on low (use the blob contact shadow) |
| Shadow updates | light.shadow.autoUpdate = false; set needsUpdate = true only when the vehicle or its pose changes |
| Environment | PMREM from RoomEnvironment once, sigma 0.04; never regenerate per frame |
| Post | none on low/medium; on high at most outline (selection) + light bloom on emissive strips |
| Materials | from the shared kit only (templates/common/materials.ts); each new material = a new pipeline compile |
Rules
- Render on demand. Run
setAnimationLoopwhile something moves (controls damping, camera tween, carousel transition, pulsing overdue part); after ~1.5 s with no change, stop the loop and re-arm it on input/resize/state change. Idle garages must not burn battery. - Adaptive quality governor: exponential moving average of frame time; if EMA > 18.5 ms for
~45 frames step down (dpr → shadows → tier), if < 12 ms for ~120 frames step up. Hysteresis
both ways, never oscillate faster than every 2 s. Expose the tier in
getStats(). - Disposal is mandatory. On vehicle switch dispose geometries of the outgoing vehicle (the
material kit is shared and survives); on
dispose()free everything: renderer, PMREM target, controls, listeners, ResizeObserver. Svelte remounts the page on SPA navigation (Astro ClientRouter): leaks show up as GPU memory growth after 5 navigations. - Picking with a single
Raycasteragainst the vehicle root only; readobject.userData.slotIdwalking up parents. Ignore drags (pointerdown→pointerup moved > 6 px). Hover highlight only on devices withmatchMedia('(hover: hover)'). - View modes
beauty: original materials; slots markedinternalinsrc/garage/parts.tshidden.health: every part gets one of 5 shared status materials (ok/warn/critical/overdue/unknown); keep the original inmesh.userData.baseMaterialand restore it.overduepulses (TSLsin(time)on emissive) – this is the only thing allowed to keep the loop alive.xray: body panels (category: 'carroceria') switch to one shared translucent fresnel material (TSL:normalView/positionViewdot → alpha), internals become visible.
- Carousel transition for
showVehicle(spec, { direction }): outgoing slides/rotates out on the turntable while the incoming one slides in (≈450 ms, ease-in-out). Build the incoming model before starting the animation so the build cost is not inside the transition. Respectprefers-reduced-motion(cut instead of slide). - Camera:
OrbitControlswith damping, polar angle clamped (no going under the floor), distance clamped to the vehicle size.focusPart(slot)tweens target and distance to the template'sfocusPoints[slot](fallback: bounding-box center of the part). Double-tap/nullresets. - Never block the main thread > 50 ms: building a template is ~5–30 ms; precompile with
await renderer.compileAsync(scene, camera)after adding a new vehicle when available. - SSR safety: the engine module must only be imported in the browser (dynamic
import()fromonMount, component rendered withclient:only="svelte"). Contracts/parts are SSR-safe.
Garage scene look ("game" garage, not a CAD viewer)
Dark-to-mid neutral room: polished concrete floor (roughness ~0.35 with subtle noise), a raised
circular turntable with a thin emissive rim, two or three emissive light strips on the back wall
(they also read well with bloom on high tier), a soft key light + hemisphere fill. The vehicle
must read clearly against the background in both light and dark UI themes — test with the lab
backgrounds #dfe3e8 and #0e1116.
Dev server en paralelo (obligatorio): Astro 7 detecta que lo corre un agente y fuerza UN servidor de fondo global por usuario:
pnpm astro deven tu worktree puede quedar conectado al servidor de OTRO agente, yastro dev stopo--forceapagan el de otro. Arranca el tuyo aislado y en primer plano:ASTRO_DEV_BACKGROUND=0 npx astro dev --port <puerto-unico> --host 127.0.0.1 --ignore-lock & echo $! > /tmp/<tu-id>.pidy paralo solo conkill $(cat /tmp/<tu-id>.pid). PROHIBIDOpkill/killall/astro dev stop/--force.
Verify (all three, every change)
# 1. types (scoped)
cd packages/app-pwa && npx tsc --noEmit -p tsconfig.json 2>&1 | grep src/garage
# 2. unit tests of the island
npx vitest run src/garage
# 3. real render: dev server + screenshot, then LOOK at the png
ASTRO_DEV_BACKGROUND=0 npx astro dev --port <port> --host 127.0.0.1 --ignore-lock & # ver nota
node scripts/garage-shot.mjs --base http://127.0.0.1:<port> --path /fleet/garage --out /tmp/g.png
Reading the PNG is part of the job: "tests green" says nothing about whether the scene looks right.
Report backend, fps sample, draw calls and triangles from window.__garage.stats in your REPORT.
04 同仓库更多 Skills
web-design-guidelines
暂无简介
blocked-page-recovery
Use when a fetch fails: 403/429, paywall, WAF, bot wall. Recovers the page via archives and provenance-checked fallbacks.
studio-coach
暂无简介
src-generator
暂无简介
sqlite-pro
暂无简介
rigor-evaluator
Use when you need a quick heuristic rigor score (10 criteria, 0-2 each) for the features in a .gitcore/features.json file, to decide which features are ready to ship.