Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Move Telos mesh and line shaders to WGSL files
Yuechen Li965ea8859d4e
diff --git a/Aetheris.Web.Runtime/telos/README.md b/Aetheris.Web.Runtime/telos/README.mdindex 450c2437..d5a47639 100644--- a/Aetheris.Web.Runtime/telos/README.md+++ b/Aetheris.Web.Runtime/telos/README.md@@ -4,6 +4,8 @@ Three Telos is an engineering display layer that uses Three.js where Three.js isReuse upstream data structures. Own downstream GPU behavior.+Mesh and line shaders are standalone `src/shaders/*.wgsl` source files. The TypeScript loader fetches their static asset URLs before requesting a GPU device; load failures fail initialization with `telos-shader-load`. Package and native browser witness builds copy these files alongside the emitted modules. Vite rewrites the same URLs for production assets. WebGPU validates WGSL during module/pipeline creation. CIR field shaders continue through Copeland's typed VTS compiler.+This package owns the device, attachments, camera, ray query, raw mesh/field/line submission and lifetime. Three 0.183.2 supplies math and input adapters, never a GPU renderer. See `docs/release/THREE-TELOS-X0.md` and `docs/release/THREE-TELOS-X1.md` in the repository for qualification and product boundaries.World-space meshes and lines accept explicit `depthMode`: `depth-tested`, `depth-biased`, or `always-on-top`. Overlay meshes can be unlit with alpha blending and do not write depth. Line widths are CSS pixels. Products may project DOM text with `camera.project`/`unproject`; `beforeFrame` supplies the host-owned projection cadence after camera matrices update and before GPU drawing. No React or font engine lives here.diff --git a/Aetheris.Web.Runtime/telos/package.json b/Aetheris.Web.Runtime/telos/package.jsonindex 9351b7e9..4de77161 100644--- a/Aetheris.Web.Runtime/telos/package.json+++ b/Aetheris.Web.Runtime/telos/package.json@@ -25,8 +25,8 @@"typescript": "~5.9.3"},"scripts": {- "build": "tsc",+ "build": "tsc && node scripts/copy-shaders.mts dist","test": "npm run build && tsc -p tsconfig.tests.json && node --test tests/*.test.ts",- "build:witness": "tsc -p tsconfig.browser.json"+ "build:witness": "tsc -p tsconfig.browser.json && node scripts/copy-shaders.mts ../../artifacts/local/three-telos/browser/src"}}diff --git a/Aetheris.Web.Runtime/telos/scripts/copy-shaders.mts b/Aetheris.Web.Runtime/telos/scripts/copy-shaders.mtsnew file mode 100644index 00000000..fa7c742c--- /dev/null+++ b/Aetheris.Web.Runtime/telos/scripts/copy-shaders.mts@@ -0,0 +1,11 @@+import { cp, mkdir, rm } from "node:fs/promises";++const destination = process.argv[2];+if (!destination) throw new Error("Pass the TypeScript output directory.");+await mkdir(`${destination}/shaders`, { recursive: true });+await cp(new URL("../src/shaders/", import.meta.url), `${destination}/shaders`, {+ recursive: true,+});+// Remove output from the former embedded-source module after incremental builds.+await rm(`${destination}/shaders.js`, { force: true });+await rm(`${destination}/shaders.d.ts`, { force: true });diff --git a/Aetheris.Web.Runtime/telos/src/device.ts b/Aetheris.Web.Runtime/telos/src/device.tsindex 6858311d..c13b637f 100644--- a/Aetheris.Web.Runtime/telos/src/device.ts+++ b/Aetheris.Web.Runtime/telos/src/device.ts@@ -1,3 +1,5 @@+import { loadTelosShaders, type TelosShaderSources } from "./shaderSources.js";+export class TelosResources {device: GPUDevice;buffers: Set<GPUBuffer>;@@ -57,6 +59,7 @@ export class TelosResources {}export class TelosDevice {+ shaders: TelosShaderSources;adapter: GPUAdapter;device: GPUDevice;context: GPUCanvasContext;@@ -78,13 +81,14 @@ export class TelosDevice {);const adapter = await navigator.gpu.requestAdapter();if (!adapter) throw new Error("telos-adapter-unavailable");+ const shaders = await loadTelosShaders();const device = await adapter.requestDevice();const context = canvas.getContext("webgpu");if (!context) {device.destroy();throw new Error("telos-context-unavailable");}- return new TelosDevice(adapter, device, context, canvas, diagnostic);+ return new TelosDevice(adapter, device, context, canvas, diagnostic, shaders);}constructor(adapter: GPUAdapter,@@ -92,7 +96,9 @@ export class TelosDevice {context: GPUCanvasContext,canvas: HTMLCanvasElement,diagnostic: (message: string) => void,+ shaders: TelosShaderSources,) {+ this.shaders = shaders;this.adapter = adapter;this.device = device;this.context = context;diff --git a/Aetheris.Web.Runtime/telos/src/pipelines.ts b/Aetheris.Web.Runtime/telos/src/pipelines.tsindex 474dc893..3c00bab8 100644--- a/Aetheris.Web.Runtime/telos/src/pipelines.ts+++ b/Aetheris.Web.Runtime/telos/src/pipelines.ts@@ -1,6 +1,5 @@import type { TelosDevice } from "./device.js";import type { TelosField, TelosDepthMode } from "./contracts.js";-import { meshShader, lineShader } from "./shaders.js";const vertexLayout: GPUVertexBufferLayout = {arrayStride: 12,attributes: [{ shaderLocation: 0, offset: 0, format: "float32x3" }],@@ -37,7 +36,7 @@ export function telosPipeline(]);const shader = resources.module(id,- artifact?.wgsl ?? (kind.includes("mesh") ? meshShader : lineShader),+ artifact?.wgsl ?? (kind.includes("mesh") ? owner.shaders.mesh : owner.shaders.line),);return resources.pipeline(key, () =>owner.device.createRenderPipeline({diff --git a/Aetheris.Web.Runtime/telos/src/shaderSources.ts b/Aetheris.Web.Runtime/telos/src/shaderSources.tsnew file mode 100644index 00000000..16b3ee58--- /dev/null+++ b/Aetheris.Web.Runtime/telos/src/shaderSources.ts@@ -0,0 +1,23 @@+export interface TelosShaderSources {+ mesh: string;+ line: string;+}++async function loadShader(url: URL): Promise<string> {+ try {+ const response = await fetch(url);+ if (!response.ok) throw new Error(`HTTP ${response.status}`);+ return await response.text();+ } catch (cause) {+ throw new Error(`telos-shader-load: ${url.pathname}`, { cause });+ }+}++/** Static asset URLs work in native ESM and are rewritten by browser bundlers. */+export async function loadTelosShaders(): Promise<TelosShaderSources> {+ const [mesh, line] = await Promise.all([+ loadShader(new URL("./shaders/mesh.wgsl", import.meta.url)),+ loadShader(new URL("./shaders/line.wgsl", import.meta.url)),+ ]);+ return { mesh, line };+}diff --git a/Aetheris.Web.Runtime/telos/src/shaders.ts b/Aetheris.Web.Runtime/telos/src/shaders.tsdeleted file mode 100644index 2856d2f5..00000000--- a/Aetheris.Web.Runtime/telos/src/shaders.ts+++ /dev/null@@ -1,37 +0,0 @@-export const meshShader = `-struct State { vp: mat4x4<f32>, model: mat4x4<f32>, normal: mat4x4<f32>, color: vec4<f32>, parameters: vec4<f32> }-@group(0) @binding(0) var<uniform> state: State;-struct Output { @builtin(position) position: vec4<f32>, @location(0) normal: vec3<f32> }-@vertex fn vertex(@location(0) position: vec3<f32>, @location(1) normal: vec3<f32>) -> Output {- var out: Output; out.position = state.vp * state.model * vec4(position, 1);- out.normal = (state.normal * vec4(normal, 0)).xyz; return out;-}-@fragment fn fragment(input: Output) -> @location(0) vec4<f32> {- let n = normalize(input.normal); let light = normalize(vec3<f32>(0.3, 0.8, 0.6));- let diffuse = 0.28 + 0.72 * abs(dot(n, light));- let roughness = clamp(state.parameters.x, 0.04, 1.0); let metallic = clamp(state.parameters.y, 0.0, 1.0);- let specular = pow(abs(dot(n, normalize(light + vec3<f32>(0,0,1)))), mix(64.0, 2.0, roughness)) * (0.05 + metallic * 0.2);- let linear = select(state.color.rgb * diffuse + vec3<f32>(specular), state.color.rgb, state.parameters.z > 0.5);- return vec4(pow(max(linear, vec3<f32>(0)), vec3<f32>(1.0 / 2.2)), state.color.a);-}`;--// Expanded segment quads. Width is CSS pixels; bias is 2e-6 in normalized depth.-export const lineShader = `-struct State { vp: mat4x4<f32>, model: mat4x4<f32>, color: vec4<f32>, viewport: vec4<f32> }-@group(0) @binding(0) var<uniform> state: State;-@vertex fn vertex(@builtin(vertex_index) vertex: u32, @location(0) start: vec3<f32>, @location(1) end: vec3<f32>) -> @builtin(position) vec4<f32> {- var a = state.vp * state.model * vec4(start,1); var b = state.vp * state.model * vec4(end,1);- // Clip before dividing by w: segments crossing the near plane remain finite.- if (a.z < 0 && b.z >= 0) { a = mix(a,b, -a.z / (b.z-a.z)); }- if (b.z < 0 && a.z >= 0) { b = mix(b,a, -b.z / (a.z-b.z)); }- if (a.z < 0 && b.z < 0) { return vec4<f32>(2,2,2,1); }- let delta = (b.xy/b.w-a.xy/a.w) * state.viewport.xy;- let direction = delta / max(length(delta), 0.00001);- let perpendicular = vec2(-direction.y, direction.x);- let corners = array<vec2<f32>,6>(vec2(0,-1),vec2(1,-1),vec2(0,1),vec2(0,1),vec2(1,-1),vec2(1,1));- let corner = corners[vertex]; var p = mix(a,b,corner.x);- p = vec4(p.xy + perpendicular * corner.y * state.viewport.z / state.viewport.xy * p.w, p.z - state.viewport.w * p.w, p.w);- return p;-}-@fragment fn fragment() -> @location(0) vec4<f32> { return state.color; }-`;diff --git a/Aetheris.Web.Runtime/telos/src/shaders/line.wgsl b/Aetheris.Web.Runtime/telos/src/shaders/line.wgslnew file mode 100644index 00000000..3194f7de--- /dev/null+++ b/Aetheris.Web.Runtime/telos/src/shaders/line.wgsl@@ -0,0 +1,17 @@+struct State { vp: mat4x4<f32>, model: mat4x4<f32>, color: vec4<f32>, viewport: vec4<f32> }+@group(0) @binding(0) var<uniform> state: State;+@vertex fn vertex(@builtin(vertex_index) vertex: u32, @location(0) start: vec3<f32>, @location(1) end: vec3<f32>) -> @builtin(position) vec4<f32> {+ var a = state.vp * state.model * vec4(start,1); var b = state.vp * state.model * vec4(end,1);+ // Clip before dividing by w: segments crossing the near plane remain finite.+ if (a.z < 0 && b.z >= 0) { a = mix(a,b, -a.z / (b.z-a.z)); }+ if (b.z < 0 && a.z >= 0) { b = mix(b,a, -b.z / (a.z-b.z)); }+ if (a.z < 0 && b.z < 0) { return vec4<f32>(2,2,2,1); }+ let delta = (b.xy/b.w-a.xy/a.w) * state.viewport.xy;+ let direction = delta / max(length(delta), 0.00001);+ let perpendicular = vec2(-direction.y, direction.x);+ let corners = array<vec2<f32>,6>(vec2(0,-1),vec2(1,-1),vec2(0,1),vec2(0,1),vec2(1,-1),vec2(1,1));+ let corner = corners[vertex]; var p = mix(a,b,corner.x);+ p = vec4(p.xy + perpendicular * corner.y * state.viewport.z / state.viewport.xy * p.w, p.z - state.viewport.w * p.w, p.w);+ return p;+}+@fragment fn fragment() -> @location(0) vec4<f32> { return state.color; }diff --git a/Aetheris.Web.Runtime/telos/src/shaders/mesh.wgsl b/Aetheris.Web.Runtime/telos/src/shaders/mesh.wgslnew file mode 100644index 00000000..4c089b80--- /dev/null+++ b/Aetheris.Web.Runtime/telos/src/shaders/mesh.wgsl@@ -0,0 +1,15 @@+struct State { vp: mat4x4<f32>, model: mat4x4<f32>, normal: mat4x4<f32>, color: vec4<f32>, parameters: vec4<f32> }+@group(0) @binding(0) var<uniform> state: State;+struct Output { @builtin(position) position: vec4<f32>, @location(0) normal: vec3<f32> }+@vertex fn vertex(@location(0) position: vec3<f32>, @location(1) normal: vec3<f32>) -> Output {+ var out: Output; out.position = state.vp * state.model * vec4(position, 1);+ out.normal = (state.normal * vec4(normal, 0)).xyz; return out;+}+@fragment fn fragment(input: Output) -> @location(0) vec4<f32> {+ let n = normalize(input.normal); let light = normalize(vec3<f32>(0.3, 0.8, 0.6));+ let diffuse = 0.28 + 0.72 * abs(dot(n, light));+ let roughness = clamp(state.parameters.x, 0.04, 1.0); let metallic = clamp(state.parameters.y, 0.0, 1.0);+ let specular = pow(abs(dot(n, normalize(light + vec3<f32>(0,0,1)))), mix(64.0, 2.0, roughness)) * (0.05 + metallic * 0.2);+ let linear = select(state.color.rgb * diffuse + vec3<f32>(specular), state.color.rgb, state.parameters.z > 0.5);+ return vec4(pow(max(linear, vec3<f32>(0)), vec3<f32>(1.0 / 2.2)), state.color.a);+}diff --git a/docs/public/three-telos.md b/docs/public/three-telos.mdindex 87b740da..37b72426 100644--- a/docs/public/three-telos.md+++ b/docs/public/three-telos.md@@ -2,6 +2,8 @@Cadmata's model, assembly, authoring overlays and PMI presentation share the Three Telos WebGPU host with Helios. It owns the camera, grid, mesh drawing, semantic topology lines, GPU leaders, selection projection and GPU resources. A supported browser/GPU is required for that path.+The shared mesh and line shaders live in standalone `.wgsl` files, loaded through TypeScript during host initialization. Builds carry the shader assets with the package; WebGPU validates their code. CIR field shaders continue through Copeland's typed Visual TypeScript compiler.+When WebGPU is unavailable, both products label their WebGL fallback. Cadmata loads that renderer only at the unsupported-browser boundary. Semantic authoring or PMI never selects it in a supported browser.PMI panels remain React DOM buttons, projected through TelosCamera in CSS pixels. They preserve semantic targets, camera-facing text, category filters, deterministic collision layout, selection and presentation-only dragging. Their leaders use retained Telos GPU buffers. Selecting a face highlights its published related PMI without broadening the face selection.diff --git a/docs/release/THREE-TELOS-X1.md b/docs/release/THREE-TELOS-X1.mdindex c1e0ec72..b15b7917 100644--- a/docs/release/THREE-TELOS-X1.md+++ b/docs/release/THREE-TELOS-X1.md@@ -6,6 +6,12 @@ Cadmata's supported-browser model, assembly, construction overlays and semanticThe motivating case is the original CADMATA-PMI-X1 CTC-03 manufacturing AP242 STEP, loaded through the actual application import UI and server bridge. Its 173 published entities include 29 semantic callouts: 3 datums, 13 dimensions/diameters, 5 position controls and 8 notes. Default presentation shows 8 datum/position panels. The all-category witness preserves all 29 objects; the unchanged dense-layout policy displays 26 and hides 3 low-priority notes in the measured viewport.+## Shader source follow-up++Mesh and line WGSL now live in `Aetheris.Web.Runtime/telos/src/shaders/mesh.wgsl` and `line.wgsl`, rather than TypeScript template strings. `shaderSources.ts` loads static asset URLs during device initialization, before allocating a GPU device. HTTP/network failures carry `telos-shader-load` diagnostics. The TypeScript build copies source assets alongside emitted modules; native ESM and Vite use the same loader. CIR artifacts retain the existing Copeland typed compiler path. This change does not introduce another compiler or require changes to Copeland's material ABI.++Follow-up validation passed the native WebGPU browser witness and a production-served CTC03 import/Datum A selection with 8 panels and zero browser errors/alerts (`artifacts/local/three-telos/shader-production.json`). The existing development browser driver's module-download fence stops on production HTML's preloaded R3F/Drei vendor chunks; this is an existing production bundling limitation, separate from renderer activation and shader loading.+## Remaining WebGL surface auditThe audit found no existing transform gizmo, snap tool, dashed GPU leader or arrowhead to migrate. Whole-part notes use dashed **CSS borders**, not stippled GPU lines. New arrow/dash/font frameworks would therefore invent product behavior.