Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement minimal analytic-only rendering consumption path
Yuechen Libda972fb1b91
diff --git a/Aetheris.Server/Api/ApiMappings.cs b/Aetheris.Server/Api/ApiMappings.csindex d75b5527..b291dd27 100644--- a/Aetheris.Server/Api/ApiMappings.cs+++ b/Aetheris.Server/Api/ApiMappings.cs@@ -2,6 +2,7 @@ using Aetheris.Kernel.Core.Brep.Picking;using Aetheris.Kernel.Core.Brep.Queries;using Aetheris.Kernel.Core.Brep.Tessellation;using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Geometry.Surfaces;using Aetheris.Kernel.Core.Math;using Aetheris.Kernel.Core.Results;using Aetheris.Server.Contracts;@@ -77,7 +78,19 @@ public static class ApiMappingsface.SurfaceGeometryId.Value,face.SurfaceKind.ToString(),face.LoopCount,- face.DomainHint is { } hint ? new AnalyticDisplayFaceDomainHintDto(hint.MinV, hint.MaxV) : null)).ToArray(),+ face.DomainHint is { } hint ? new AnalyticDisplayFaceDomainHintDto(hint.MinV, hint.MaxV) : null,+ face.SurfaceGeometry.Plane is { } plane ? new AnalyticDisplayPlaneGeometryDto(+ ToPointDto(plane.Origin),+ ToVectorDto(plane.Normal.ToVector()),+ ToVectorDto(plane.UAxis.ToVector()),+ ToVectorDto(plane.VAxis.ToVector())) : null,+ face.SurfaceGeometry.Cylinder is { } cylinder ? new AnalyticDisplayCylinderGeometryDto(+ ToPointDto(cylinder.Origin),+ ToVectorDto(cylinder.Axis.ToVector()),+ ToVectorDto(cylinder.XAxis.ToVector()),+ ToVectorDto(cylinder.YAxis.ToVector()),+ cylinder.Radius) : null,+ face.SurfaceGeometry.Cone is { } cone ? ToConeGeometryDto(cone) : null)).ToArray(),packet.FallbackFaces.Select(face => new AnalyticDisplayFallbackFaceDto(face.FaceId.Value,face.ShellId.Value,@@ -139,4 +152,23 @@ public static class ApiMappingsoptions.SortTieTolerance ?? defaults.SortTieTolerance,options.MaxDistance ?? defaults.MaxDistance);}++ private static AnalyticDisplayConeGeometryDto ToConeGeometryDto(ConeSurface cone)+ {+ var axis = cone.Axis.ToVector();+ var projectedX = cone.ReferenceAxis.ToVector() - (axis * cone.ReferenceAxis.ToVector().Dot(axis));+ var xAxis = projectedX.TryNormalize(out var normalizedX) ? normalizedX : cone.ReferenceAxis.ToVector();+ var yAxis = axis.Cross(xAxis);+ if (!yAxis.TryNormalize(out var normalizedY))+ {+ normalizedY = yAxis;+ }++ return new AnalyticDisplayConeGeometryDto(+ ToPointDto(cone.Apex),+ ToVectorDto(axis),+ ToVectorDto(xAxis),+ ToVectorDto(normalizedY),+ cone.SemiAngleRadians);+ }}diff --git a/Aetheris.Server/Contracts/ApiContracts.cs b/Aetheris.Server/Contracts/ApiContracts.csindex 970ec77f..0a7dc39f 100644--- a/Aetheris.Server/Contracts/ApiContracts.cs+++ b/Aetheris.Server/Contracts/ApiContracts.cs@@ -76,6 +76,26 @@ public sealed record DisplayPrepareRequestDto(TessellationOptionsDto? Tessellatipublic sealed record AnalyticDisplayFaceDomainHintDto(double? MinV, double? MaxV);+public sealed record AnalyticDisplayPlaneGeometryDto(+ Point3Dto Origin,+ Vector3Dto Normal,+ Vector3Dto UAxis,+ Vector3Dto VAxis);++public sealed record AnalyticDisplayCylinderGeometryDto(+ Point3Dto Origin,+ Vector3Dto Axis,+ Vector3Dto XAxis,+ Vector3Dto YAxis,+ double Radius);++public sealed record AnalyticDisplayConeGeometryDto(+ Point3Dto Apex,+ Vector3Dto Axis,+ Vector3Dto XAxis,+ Vector3Dto YAxis,+ double SemiAngleRadians);+public sealed record AnalyticDisplayFaceDto(int FaceId,int ShellId,@@ -83,7 +103,10 @@ public sealed record AnalyticDisplayFaceDto(int SurfaceGeometryId,string SurfaceKind,int LoopCount,- AnalyticDisplayFaceDomainHintDto? DomainHint);+ AnalyticDisplayFaceDomainHintDto? DomainHint,+ AnalyticDisplayPlaneGeometryDto? PlaneGeometry,+ AnalyticDisplayCylinderGeometryDto? CylinderGeometry,+ AnalyticDisplayConeGeometryDto? ConeGeometry);public sealed record AnalyticDisplayFallbackFaceDto(int FaceId,diff --git a/aetheris.client/src/App.tsx b/aetheris.client/src/App.tsxindex 77325781..ef5ea1e4 100644--- a/aetheris.client/src/App.tsx+++ b/aetheris.client/src/App.tsx@@ -21,7 +21,7 @@ import {import { StepImportDropzone } from './components/StepImportDropzone';import { Button } from './components/ui/button';import { ViewerViewport } from './viewer/ViewerViewport';-import { mapTessellationToRenderData } from './viewer/tessellationMapper';+import { buildDisplaySceneData } from './viewer/displaySceneBuilder';import { STEP_UPLOAD_LIMIT_BYTES, STEP_UPLOAD_LIMIT_MB, formatMegabytes } from './config/stepUpload';type RequestStatus = 'idle' | 'loading' | 'success' | 'error';@@ -473,7 +473,8 @@ function App() {}}, [activeBodyId, documentId]);- const sceneData = useMemo(() => (tessellation ? mapTessellationToRenderData(tessellation) : null), [tessellation]);+ const displayScene = useMemo(() => buildDisplaySceneData(displayPreparation), [displayPreparation]);+ const sceneData = displayScene.sceneData;const nearestHit = pickHits[0] ?? null;const highlightedFaceId = nearestHit?.entityKind === 'Face' ? nearestHit.faceId : null;const highlightedEdgeId = nearestHit?.entityKind === 'Edge' ? nearestHit.edgeId : null;@@ -656,6 +657,7 @@ function App() {<p><strong>Definition ID:</strong> {activeOccurrence?.definitionId ?? 'None'}</p><p><strong>Occurrence ID:</strong> {activeBodyId ?? 'None'}</p><p><strong>Display lane:</strong> {displayPreparation?.lane ?? 'None'}</p>+ <p><strong>Render path:</strong> {displayScene.renderPath}</p><p><strong>Analytic faces:</strong> {displayPreparation?.analyticPacket.analyticFaces.length ?? 0}</p><p><strong>Fallback faces:</strong> {displayPreparation?.analyticPacket.fallbackFaces.length ?? 0}</p><p><strong>Face count:</strong> {tessellation?.facePatches.length ?? 0}</p>@@ -760,6 +762,7 @@ function App() {<p><strong>Active occurrence ID:</strong> {activeBodyId ?? 'None'}</p><p><strong>Occurrence count:</strong> {bodyIds.length}</p><p><strong>Display lane:</strong> {displayPreparation?.lane ?? 'None'}</p>+ <p><strong>Render path:</strong> {displayScene.renderPath}</p><p><strong>Analytic faces:</strong> {displayPreparation?.analyticPacket.analyticFaces.length ?? 0}</p><p><strong>Fallback faces:</strong> {displayPreparation?.analyticPacket.fallbackFaces.length ?? 0}</p><p><strong>Face patches:</strong> {tessellation?.facePatches.length ?? 0}</p>diff --git a/aetheris.client/src/__tests__/App.test.tsx b/aetheris.client/src/__tests__/App.test.tsxindex c212f4a0..bce3228d 100644--- a/aetheris.client/src/__tests__/App.test.tsx+++ b/aetheris.client/src/__tests__/App.test.tsx@@ -12,6 +12,7 @@ const apiMocks = vi.hoisted(() => ({getDocumentSummary: vi.fn(),importStep: vi.fn(),pickBody: vi.fn(),+ prepareBodyDisplay: vi.fn(),tessellateBody: vi.fn(),translateBody: vi.fn(),}));@@ -28,6 +29,7 @@ vi.mock('../api/aetherisApi', async () => {getDocumentSummary: apiMocks.getDocumentSummary,importStep: apiMocks.importStep,pickBody: apiMocks.pickBody,+ prepareBodyDisplay: apiMocks.prepareBodyDisplay,tessellateBody: apiMocks.tessellateBody,translateBody: apiMocks.translateBody,};@@ -61,6 +63,18 @@ function setupDocumentApiMocks(): void {}],});apiMocks.tessellateBody.mockResolvedValue({ facePatches: [], edgePolylines: [] });+ apiMocks.prepareBodyDisplay.mockResolvedValue({+ lane: 'fallback-only',+ analyticPacket: {+ bodyId: 1,+ analyticFaces: [],+ fallbackFaces: [],+ },+ tessellationFallback: {+ facePatches: [],+ edgePolylines: [],+ },+ });}describe('App STEP file upload flow', () => {@@ -77,7 +91,7 @@ describe('App STEP file upload flow', () => {render(<App />);expect(screen.getByRole('tab', { name: /STEP 242 Viewer/i }).getAttribute('aria-selected')).toBe('true');- expect(screen.getByText('Viewport')).toBeTruthy();+ expect(screen.getByTestId('viewer-viewport')).toBeTruthy();expect(screen.getByRole('button', { name: 'GRID' }).getAttribute('aria-pressed')).toBe('true');expect(screen.getByRole('button', { name: 'COORD' }).getAttribute('aria-pressed')).toBe('true');expect(screen.queryByText('Create Box')).toBeNull();diff --git a/aetheris.client/src/__tests__/displaySceneBuilder.test.ts b/aetheris.client/src/__tests__/displaySceneBuilder.test.tsnew file mode 100644index 00000000..d0dd5322--- /dev/null+++ b/aetheris.client/src/__tests__/displaySceneBuilder.test.ts@@ -0,0 +1,127 @@+import { describe, expect, it, vi } from 'vitest';+import type { DisplayPreparationResponseDto } from '../api/aetherisApi';+import { buildDisplaySceneData } from '../viewer/displaySceneBuilder';+import { mapAnalyticPacketToRenderData } from '../viewer/analyticMapper';++const analyticPreparation: DisplayPreparationResponseDto = {+ lane: 'analytic-only',+ analyticPacket: {+ bodyId: 1,+ analyticFaces: [+ {+ faceId: 10,+ shellId: 1,+ shellRole: 'Outer',+ surfaceGeometryId: 100,+ surfaceKind: 'Cylinder',+ loopCount: 1,+ domainHint: { minV: -1, maxV: 1 },+ planeGeometry: null,+ cylinderGeometry: {+ origin: { x: 0, y: 0, z: 0 },+ axis: { x: 0, y: 1, z: 0 },+ xAxis: { x: 1, y: 0, z: 0 },+ yAxis: { x: 0, y: 0, z: 1 },+ radius: 0.5,+ },+ coneGeometry: null,+ },+ ],+ fallbackFaces: [],+ },+ tessellationFallback: {+ facePatches: [+ {+ faceId: 999,+ positions: [{ x: 0, y: 0, z: 0 }],+ normals: [{ x: 0, y: 1, z: 0 }],+ triangleIndices: [0, 0, 0],+ },+ ],+ edgePolylines: [],+ },+};++const fallbackPreparation: DisplayPreparationResponseDto = {+ lane: 'fallback-only',+ analyticPacket: {+ bodyId: 1,+ analyticFaces: [],+ fallbackFaces: [+ {+ faceId: 3,+ shellId: 1,+ shellRole: 'Outer',+ reason: 'UnsupportedSurfaceKind',+ surfaceKind: 'BSplineSurfaceWithKnots',+ detail: null,+ },+ ],+ },+ tessellationFallback: {+ facePatches: [+ {+ faceId: 100,+ positions: [+ { x: 0, y: 0, z: 0 },+ { x: 1, y: 0, z: 0 },+ { x: 0, y: 1, z: 0 },+ ],+ normals: [+ { x: 0, y: 0, z: 1 },+ { x: 0, y: 0, z: 1 },+ { x: 0, y: 0, z: 1 },+ ],+ triangleIndices: [0, 1, 2],+ },+ ],+ edgePolylines: [],+ },+};++describe('buildDisplaySceneData', () => {+ it('routes analytic-only lane to analytic mapping and does not touch fallback mapping', () => {+ const mapAnalytic = vi.fn().mockReturnValue({ faces: [], edges: [] });+ const mapFallback = vi.fn().mockReturnValue({ faces: [], edges: [] });++ const result = buildDisplaySceneData(analyticPreparation, { mapAnalytic, mapFallback });++ expect(result.renderPath).toBe('analytic-only');+ expect(mapAnalytic).toHaveBeenCalledOnce();+ expect(mapFallback).not.toHaveBeenCalled();+ });++ it('routes fallback-only lane to tessellation fallback mapping', () => {+ const mapAnalytic = vi.fn().mockReturnValue({ faces: [], edges: [] });+ const mapFallback = vi.fn().mockReturnValue({ faces: [], edges: [] });++ const result = buildDisplaySceneData(fallbackPreparation, { mapAnalytic, mapFallback });++ expect(result.renderPath).toBe('fallback');+ expect(mapFallback).toHaveBeenCalledOnce();+ expect(mapAnalytic).not.toHaveBeenCalled();+ });++ it('routes mixed-fallback lane to tessellation fallback mapping', () => {+ const mapAnalytic = vi.fn().mockReturnValue({ faces: [], edges: [] });+ const mapFallback = vi.fn().mockReturnValue({ faces: [], edges: [] });++ const result = buildDisplaySceneData({ ...fallbackPreparation, lane: 'mixed-fallback' }, { mapAnalytic, mapFallback });++ expect(result.renderPath).toBe('fallback');+ expect(mapFallback).toHaveBeenCalledOnce();+ expect(mapAnalytic).not.toHaveBeenCalled();+ });+});++describe('mapAnalyticPacketToRenderData', () => {+ it('is deterministic for the same analytic packet input', () => {+ const first = mapAnalyticPacketToRenderData(analyticPreparation.analyticPacket);+ const second = mapAnalyticPacketToRenderData(analyticPreparation.analyticPacket);++ expect(first.faces).toHaveLength(second.faces.length);+ expect(Array.from(first.faces[0].positions)).toEqual(Array.from(second.faces[0].positions));+ expect(Array.from(first.faces[0].normals)).toEqual(Array.from(second.faces[0].normals));+ expect(Array.from(first.faces[0].indices)).toEqual(Array.from(second.faces[0].indices));+ });+});diff --git a/aetheris.client/src/api/aetherisApi.ts b/aetheris.client/src/api/aetherisApi.tsindex e6690764..f481083b 100644--- a/aetheris.client/src/api/aetherisApi.ts+++ b/aetheris.client/src/api/aetherisApi.ts@@ -108,6 +108,29 @@ export interface AnalyticDisplayFaceDomainHintDto {maxV: number | null;}+export interface AnalyticDisplayPlaneGeometryDto {+ origin: Point3Dto;+ normal: Vector3Dto;+ uAxis: Vector3Dto;+ vAxis: Vector3Dto;+}++export interface AnalyticDisplayCylinderGeometryDto {+ origin: Point3Dto;+ axis: Vector3Dto;+ xAxis: Vector3Dto;+ yAxis: Vector3Dto;+ radius: number;+}++export interface AnalyticDisplayConeGeometryDto {+ apex: Point3Dto;+ axis: Vector3Dto;+ xAxis: Vector3Dto;+ yAxis: Vector3Dto;+ semiAngleRadians: number;+}+export interface AnalyticDisplayFaceDto {faceId: number;shellId: number;@@ -116,6 +139,9 @@ export interface AnalyticDisplayFaceDto {surfaceKind: 'Plane' | 'Sphere' | 'Cylinder' | 'Cone' | 'Torus' | string;loopCount: number;domainHint: AnalyticDisplayFaceDomainHintDto | null;+ planeGeometry: AnalyticDisplayPlaneGeometryDto | null;+ cylinderGeometry: AnalyticDisplayCylinderGeometryDto | null;+ coneGeometry: AnalyticDisplayConeGeometryDto | null;}export interface AnalyticDisplayFallbackFaceDto {diff --git a/aetheris.client/src/viewer/analyticMapper.ts b/aetheris.client/src/viewer/analyticMapper.tsnew file mode 100644index 00000000..37539185--- /dev/null+++ b/aetheris.client/src/viewer/analyticMapper.ts@@ -0,0 +1,187 @@+import type {+ AnalyticDisplayFaceDto,+ AnalyticDisplayPacketDto,+ Point3Dto,+ Vector3Dto,+} from '../api/aetherisApi';+import type { RenderFacePatch, RenderSceneData } from './tessellationMapper';++const TAU = Math.PI * 2;++function toArray(point: Point3Dto | Vector3Dto): [number, number, number] {+ return [point.x, point.y, point.z];+}++function add(a: [number, number, number], b: [number, number, number]): [number, number, number] {+ return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];+}++function mul(v: [number, number, number], s: number): [number, number, number] {+ return [v[0] * s, v[1] * s, v[2] * s];+}++function normalize(v: [number, number, number]): [number, number, number] {+ const len = Math.hypot(v[0], v[1], v[2]);+ if (len <= 1e-9) {+ return [0, 1, 0];+ }++ return [v[0] / len, v[1] / len, v[2] / len];+}++function buildPlanePatch(face: AnalyticDisplayFaceDto): RenderFacePatch | null {+ if (!face.planeGeometry) {+ return null;+ }++ const origin = toArray(face.planeGeometry.origin);+ const normal = normalize(toArray(face.planeGeometry.normal));+ const uAxis = normalize(toArray(face.planeGeometry.uAxis));+ const vAxis = normalize(toArray(face.planeGeometry.vAxis));+ const halfSize = 0.5;++ const corners: [number, number, number][] = [+ add(add(origin, mul(uAxis, -halfSize)), mul(vAxis, -halfSize)),+ add(add(origin, mul(uAxis, halfSize)), mul(vAxis, -halfSize)),+ add(add(origin, mul(uAxis, halfSize)), mul(vAxis, halfSize)),+ add(add(origin, mul(uAxis, -halfSize)), mul(vAxis, halfSize)),+ ];++ return {+ faceId: face.faceId,+ positions: new Float32Array(corners.flat()),+ normals: new Float32Array([normal, normal, normal, normal].flat()),+ indices: new Uint32Array([0, 1, 2, 0, 2, 3]),+ };+}++function buildCylinderPatch(face: AnalyticDisplayFaceDto): RenderFacePatch | null {+ if (!face.cylinderGeometry) {+ return null;+ }++ const origin = toArray(face.cylinderGeometry.origin);+ const axis = toArray(face.cylinderGeometry.axis);+ const xAxis = toArray(face.cylinderGeometry.xAxis);+ const yAxis = toArray(face.cylinderGeometry.yAxis);+ const radius = face.cylinderGeometry.radius;+ const minV = face.domainHint?.minV ?? -0.5;+ const maxV = face.domainHint?.maxV ?? 0.5;+ const angularSegments = 24;++ const positions: number[] = [];+ const normals: number[] = [];+ const indices: number[] = [];++ for (let i = 0; i <= angularSegments; i += 1) {+ const u = (i / angularSegments) * TAU;+ const cosU = Math.cos(u);+ const sinU = Math.sin(u);+ const radial = add(mul(xAxis, radius * cosU), mul(yAxis, radius * sinU));+ const radialNormal = normalize(add(mul(xAxis, cosU), mul(yAxis, sinU)));++ const bottom = add(add(origin, mul(axis, minV)), radial);+ const top = add(add(origin, mul(axis, maxV)), radial);++ positions.push(...bottom, ...top);+ normals.push(...radialNormal, ...radialNormal);++ if (i < angularSegments) {+ const base = i * 2;+ indices.push(+ base,+ base + 1,+ base + 3,+ base,+ base + 3,+ base + 2,+ );+ }+ }++ return {+ faceId: face.faceId,+ positions: new Float32Array(positions),+ normals: new Float32Array(normals),+ indices: new Uint32Array(indices),+ };+}++function buildConePatch(face: AnalyticDisplayFaceDto): RenderFacePatch | null {+ if (!face.coneGeometry) {+ return null;+ }++ const apex = toArray(face.coneGeometry.apex);+ const axis = toArray(face.coneGeometry.axis);+ const xAxis = toArray(face.coneGeometry.xAxis);+ const yAxis = toArray(face.coneGeometry.yAxis);+ const minV = Math.max(face.domainHint?.minV ?? 0.1, 0.001);+ const maxV = Math.max(face.domainHint?.maxV ?? 1, minV + 0.001);+ const tanSemi = Math.tan(face.coneGeometry.semiAngleRadians);+ const angularSegments = 24;++ const positions: number[] = [];+ const normals: number[] = [];+ const indices: number[] = [];++ for (let i = 0; i <= angularSegments; i += 1) {+ const u = (i / angularSegments) * TAU;+ const cosU = Math.cos(u);+ const sinU = Math.sin(u);+ const radialDirection = normalize(add(mul(xAxis, cosU), mul(yAxis, sinU)));+ const lowerRadius = minV * tanSemi;+ const upperRadius = maxV * tanSemi;++ const lower = add(add(apex, mul(axis, minV)), mul(radialDirection, lowerRadius));+ const upper = add(add(apex, mul(axis, maxV)), mul(radialDirection, upperRadius));++ const normal = normalize([+ radialDirection[0] - axis[0] * tanSemi,+ radialDirection[1] - axis[1] * tanSemi,+ radialDirection[2] - axis[2] * tanSemi,+ ]);++ positions.push(...lower, ...upper);+ normals.push(...normal, ...normal);++ if (i < angularSegments) {+ const base = i * 2;+ indices.push(base, base + 1, base + 3, base, base + 3, base + 2);+ }+ }++ return {+ faceId: face.faceId,+ positions: new Float32Array(positions),+ normals: new Float32Array(normals),+ indices: new Uint32Array(indices),+ };+}++function mapFace(face: AnalyticDisplayFaceDto): RenderFacePatch | null {+ if (face.surfaceKind === 'Plane') {+ return buildPlanePatch(face);+ }++ if (face.surfaceKind === 'Cylinder') {+ return buildCylinderPatch(face);+ }++ if (face.surfaceKind === 'Cone') {+ return buildConePatch(face);+ }++ return null;+}++export function mapAnalyticPacketToRenderData(packet: AnalyticDisplayPacketDto): RenderSceneData {+ const faces = packet.analyticFaces+ .map(mapFace)+ .filter((patch): patch is RenderFacePatch => patch !== null);++ return {+ faces,+ edges: [],+ };+}diff --git a/aetheris.client/src/viewer/displaySceneBuilder.ts b/aetheris.client/src/viewer/displaySceneBuilder.tsnew file mode 100644index 00000000..efa7cbde--- /dev/null+++ b/aetheris.client/src/viewer/displaySceneBuilder.ts@@ -0,0 +1,44 @@+import type { DisplayPreparationResponseDto } from '../api/aetherisApi';+import { mapAnalyticPacketToRenderData } from './analyticMapper';+import { mapTessellationToRenderData, type RenderSceneData } from './tessellationMapper';++export type DisplayRenderPath = 'analytic-only' | 'fallback';++export interface DisplaySceneBuildResult {+ renderPath: DisplayRenderPath;+ sceneData: RenderSceneData | null;+}++interface BuildDependencies {+ mapAnalytic: typeof mapAnalyticPacketToRenderData;+ mapFallback: typeof mapTessellationToRenderData;+}++const defaultDependencies: BuildDependencies = {+ mapAnalytic: mapAnalyticPacketToRenderData,+ mapFallback: mapTessellationToRenderData,+};++export function buildDisplaySceneData(+ preparation: DisplayPreparationResponseDto | null,+ deps: BuildDependencies = defaultDependencies,+): DisplaySceneBuildResult {+ if (!preparation) {+ return {+ renderPath: 'fallback',+ sceneData: null,+ };+ }++ if (preparation.lane === 'analytic-only') {+ return {+ renderPath: 'analytic-only',+ sceneData: deps.mapAnalytic(preparation.analyticPacket),+ };+ }++ return {+ renderPath: 'fallback',+ sceneData: preparation.tessellationFallback ? deps.mapFallback(preparation.tessellationFallback) : null,+ };+}