Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
M17d integrate analytic display packet into app/view pipeline
Yuechen Li41f926b7e222
diff --git a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs b/Aetheris.Server.Tests/KernelApiIntegrationTests.csindex e85c2f9a..d2b86a2b 100644--- a/Aetheris.Server.Tests/KernelApiIntegrationTests.cs+++ b/Aetheris.Server.Tests/KernelApiIntegrationTests.cs@@ -1,6 +1,7 @@using System.Net;using System.Net.Http.Json;using System.Text;+using System.Text.Json;using Aetheris.Server.Contracts;using Microsoft.AspNetCore.Mvc.Testing;@@ -85,6 +86,105 @@ public sealed class KernelApiIntegrationTests : IClassFixture<WebApplicationFactAssert.Empty(pick.Diagnostics);}+ [Fact]+ public async Task DisplayPrepare_BoxCylinderThroughHole_UsesAnalyticLaneWithoutTessellationFallback()+ {+ var document = await CreateDocumentAsync("/api/v1/documents");+ var box = await CreateBoxAsync("/api/v1/documents", document.Data!.DocumentId, 40, 30, 12);++ var cylinderResponse = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data.DocumentId}/bodies/primitives/cylinder",+ new CylinderCreateRequestDto(4, 20));+ cylinderResponse.EnsureSuccessStatusCode();+ var cylinder = await cylinderResponse.Content.ReadFromJsonAsync<ApiResponseDto<BodyCreatedResponseDto>>();+ Assert.NotNull(cylinder);+ Assert.True(cylinder!.Success);++ var translateResponse = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data.DocumentId}/bodies/{cylinder.Data!.BodyId}/transform",+ new TranslateBodyRequestDto(new Vector3Dto(3, -2, 6)));+ translateResponse.EnsureSuccessStatusCode();++ var booleanResponse = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data.DocumentId}/operations/boolean",+ new BooleanRequestDto(box.Data!.BodyId, cylinder.Data.BodyId, "subtract"));+ booleanResponse.EnsureSuccessStatusCode();+ var resultBody = await booleanResponse.Content.ReadFromJsonAsync<ApiResponseDto<BodyCreatedResponseDto>>();+ Assert.NotNull(resultBody);+ Assert.True(resultBody!.Success);++ var prepared = await PrepareDisplayAsync(document.Data.DocumentId, resultBody.Data!.BodyId);++ Assert.Equal("analytic-only", prepared.Data!.Lane);+ Assert.NotEmpty(prepared.Data.AnalyticPacket.AnalyticFaces);+ Assert.Contains(prepared.Data.AnalyticPacket.AnalyticFaces, face => face.SurfaceKind == "Cylinder");+ Assert.Empty(prepared.Data.AnalyticPacket.FallbackFaces);+ Assert.Null(prepared.Data.TessellationFallback);+ }++ [Fact]+ public async Task DisplayPrepare_ImportedUnsupportedBody_PreservesFallbackRouting()+ {+ var document = await CreateDocumentAsync("/api/v1/documents");+ var unsupportedStepText = await File.ReadAllTextAsync(GetRepositoryPath("testdata/step242/handcrafted/edge-trimming/block-full-round.step"));++ var importResponse = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data!.DocumentId}/import/step",+ new StepImportRequestDto(unsupportedStepText, "Unsupported"));+ importResponse.EnsureSuccessStatusCode();+ var imported = await importResponse.Content.ReadFromJsonAsync<ApiResponseDto<StepImportResponseDto>>();+ Assert.NotNull(imported);+ Assert.True(imported!.Success);++ var prepared = await PrepareDisplayAsync(document.Data.DocumentId, imported.Data!.OccurrenceId);++ Assert.NotEqual("analytic-only", prepared.Data!.Lane);+ Assert.NotEmpty(prepared.Data.AnalyticPacket.FallbackFaces);+ Assert.Contains(prepared.Data.AnalyticPacket.FallbackFaces, face => face.Reason is "UnsupportedSurfaceKind" or "UnsupportedTrim");+ Assert.NotNull(prepared.Data.TessellationFallback);+ Assert.NotEmpty(prepared.Data.TessellationFallback!.FacePatches);+ }++ [Fact]+ public async Task DisplayPrepare_SameBodyTwice_IsDeterministic()+ {+ var document = await CreateDocumentAsync("/api/v1/documents");+ var box = await CreateBoxAsync("/api/v1/documents", document.Data!.DocumentId, 2, 2, 2);++ var first = await PrepareDisplayAsync(document.Data.DocumentId, box.Data!.BodyId);+ var second = await PrepareDisplayAsync(document.Data.DocumentId, box.Data.BodyId);++ Assert.NotNull(first.Data);+ Assert.NotNull(second.Data);+ var firstSignature = JsonSerializer.Serialize(first.Data);+ var secondSignature = JsonSerializer.Serialize(second.Data);+ Assert.Equal(firstSignature, secondSignature);+ }++ [Fact]+ public async Task Tessellate_UnsupportedImportedBody_StillWorksAfterDisplayPrepareIntegration()+ {+ var document = await CreateDocumentAsync("/api/v1/documents");+ var unsupportedStepText = await File.ReadAllTextAsync(GetRepositoryPath("testdata/step242/handcrafted/edge-trimming/block-full-round.step"));+ var importResponse = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data!.DocumentId}/import/step",+ new StepImportRequestDto(unsupportedStepText, "Unsupported"));+ importResponse.EnsureSuccessStatusCode();+ var imported = await importResponse.Content.ReadFromJsonAsync<ApiResponseDto<StepImportResponseDto>>();++ var displayPrepared = await PrepareDisplayAsync(document.Data.DocumentId, imported!.Data!.OccurrenceId);+ Assert.NotNull(displayPrepared.Data!.TessellationFallback);++ var tessellationResponse = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{document.Data.DocumentId}/bodies/{imported.Data.OccurrenceId}/tessellate",+ new TessellateRequestDto(null));+ tessellationResponse.EnsureSuccessStatusCode();+ var tessellation = await tessellationResponse.Content.ReadFromJsonAsync<ApiResponseDto<TessellationResponseDto>>();+ Assert.NotNull(tessellation);+ Assert.True(tessellation!.Success);+ Assert.NotEmpty(tessellation.Data!.FacePatches);+ }+[Fact]public async Task BodyTranslation_UpdatesTessellationAndPickCoordinates()@@ -532,4 +632,19 @@ public sealed class KernelApiIntegrationTests : IClassFixture<WebApplicationFactvar body = await response.Content.ReadFromJsonAsync<ApiResponseDto<BodyCreatedResponseDto>>();return body!;}++ private async Task<ApiResponseDto<DisplayPreparationResponseDto>> PrepareDisplayAsync(Guid documentId, Guid bodyId)+ {+ var response = await _client.PostAsJsonAsync(+ $"/api/v1/documents/{documentId}/bodies/{bodyId}/display/prepare",+ new DisplayPrepareRequestDto(null));+ response.EnsureSuccessStatusCode();+ var prepared = await response.Content.ReadFromJsonAsync<ApiResponseDto<DisplayPreparationResponseDto>>();+ Assert.NotNull(prepared);+ Assert.True(prepared!.Success);+ return prepared;+ }++ private static string GetRepositoryPath(string relativePath)+ => Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", relativePath));}diff --git a/Aetheris.Server/Api/ApiMappings.cs b/Aetheris.Server/Api/ApiMappings.csindex f14e77d4..d75b5527 100644--- a/Aetheris.Server/Api/ApiMappings.cs+++ b/Aetheris.Server/Api/ApiMappings.cs@@ -1,4 +1,5 @@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.Math;@@ -66,6 +67,25 @@ public static class ApiMappingse.Points.Select(point => ToPointDto(transform.Apply(point))).ToArray(),e.IsClosed)).ToArray());+ public static AnalyticDisplayPacketDto ToAnalyticDisplayPacketResponse(AnalyticDisplayPacket packet)+ => new(+ packet.BodyId.Value,+ packet.AnalyticFaces.Select(face => new AnalyticDisplayFaceDto(+ face.FaceId.Value,+ face.ShellId.Value,+ face.ShellRole.ToString(),+ face.SurfaceGeometryId.Value,+ face.SurfaceKind.ToString(),+ face.LoopCount,+ face.DomainHint is { } hint ? new AnalyticDisplayFaceDomainHintDto(hint.MinV, hint.MaxV) : null)).ToArray(),+ packet.FallbackFaces.Select(face => new AnalyticDisplayFallbackFaceDto(+ face.FaceId.Value,+ face.ShellId.Value,+ face.ShellRole.ToString(),+ face.Reason.ToString(),+ face.SurfaceKind?.ToString(),+ face.Detail)).ToArray());+public static PickResponseDto ToPickResponse(IReadOnlyList<PickHit> hits, Guid occurrenceId)=> ToPickResponse(hits, Transform3D.Identity, occurrenceId);diff --git a/Aetheris.Server/Api/KernelEndpoints.cs b/Aetheris.Server/Api/KernelEndpoints.csindex b8c511cb..59965fd6 100644--- a/Aetheris.Server/Api/KernelEndpoints.cs+++ b/Aetheris.Server/Api/KernelEndpoints.cs@@ -2,6 +2,7 @@ using Aetheris.Kernel.Core.Brep;using Aetheris.Kernel.Core.Brep.Boolean;using Aetheris.Kernel.Core.Brep.Features;using Aetheris.Kernel.Core.Brep.Picking;+using Aetheris.Kernel.Core.Brep.Queries;using Aetheris.Kernel.Core.Brep.Tessellation;using Aetheris.Kernel.Core.Math;using Aetheris.Kernel.Core.Step242;@@ -292,6 +293,32 @@ public static class KernelEndpointsreturn ApiMappings.Ok(ApiMappings.ToTessellationResponse(kernel.Value));}));+ documents.MapPost("/{documentId:guid}/bodies/{bodyId:guid}/display/prepare", (Guid documentId, Guid bodyId, DisplayPrepareRequestDto? request, KernelDocumentStore store) =>+ WithDocumentOccurrence(store, documentId, bodyId, (document, body) =>+ {+ var analyticPacket = AnalyticDisplayPacketBuilder.Build(body);+ var lane = ResolveDisplayLane(analyticPacket);+ TessellationResponseDto? tessellationFallback = null;++ if (lane is not "analytic-only")+ {+ var tessellateKernel = BrepDisplayTessellator.Tessellate(body, ApiMappings.BuildTessellationOptions(request?.TessellationOptions));+ if (!tessellateKernel.IsSuccess)+ {+ return ApiMappings.KernelFailure(tessellateKernel.Diagnostics);+ }++ tessellationFallback = document.TryGetBodyTransform(bodyId, out var fallbackTransform)+ ? ApiMappings.ToTessellationResponse(tessellateKernel.Value, fallbackTransform)+ : ApiMappings.ToTessellationResponse(tessellateKernel.Value);+ }++ return ApiMappings.Ok(new DisplayPreparationResponseDto(+ lane,+ ApiMappings.ToAnalyticDisplayPacketResponse(analyticPacket),+ tessellationFallback));+ }));+documents.MapPost("/{documentId:guid}/bodies/{bodyId:guid}/pick", (Guid documentId, Guid bodyId, PickRequestDto request, KernelDocumentStore store) =>WithDocumentOccurrence(store, documentId, bodyId, (document, body) =>{@@ -399,4 +426,19 @@ public static class KernelEndpointsreturn false;}}++ private static string ResolveDisplayLane(AnalyticDisplayPacket packet)+ {+ if (packet.AnalyticFaces.Count > 0 && packet.FallbackFaces.Count == 0)+ {+ return "analytic-only";+ }++ if (packet.AnalyticFaces.Count > 0)+ {+ return "mixed-fallback";+ }++ return "fallback-only";+ }}diff --git a/Aetheris.Server/Contracts/ApiContracts.cs b/Aetheris.Server/Contracts/ApiContracts.csindex edcab452..970ec77f 100644--- a/Aetheris.Server/Contracts/ApiContracts.cs+++ b/Aetheris.Server/Contracts/ApiContracts.cs@@ -72,6 +72,37 @@ public sealed record FacePatchDto(int FaceId, IReadOnlyList<Point3Dto> Positionspublic sealed record EdgePolylineDto(int EdgeId, IReadOnlyList<Point3Dto> Points, bool IsClosed);+public sealed record DisplayPrepareRequestDto(TessellationOptionsDto? TessellationOptions);++public sealed record AnalyticDisplayFaceDomainHintDto(double? MinV, double? MaxV);++public sealed record AnalyticDisplayFaceDto(+ int FaceId,+ int ShellId,+ string ShellRole,+ int SurfaceGeometryId,+ string SurfaceKind,+ int LoopCount,+ AnalyticDisplayFaceDomainHintDto? DomainHint);++public sealed record AnalyticDisplayFallbackFaceDto(+ int FaceId,+ int ShellId,+ string ShellRole,+ string Reason,+ string? SurfaceKind,+ string? Detail);++public sealed record AnalyticDisplayPacketDto(+ int BodyId,+ IReadOnlyList<AnalyticDisplayFaceDto> AnalyticFaces,+ IReadOnlyList<AnalyticDisplayFallbackFaceDto> FallbackFaces);++public sealed record DisplayPreparationResponseDto(+ string Lane,+ AnalyticDisplayPacketDto AnalyticPacket,+ TessellationResponseDto? TessellationFallback);+public sealed record PickOptionsDto(bool? NearestOnly, bool? IncludeBackfaces, double? EdgeTolerance, double? SortTieTolerance, double? MaxDistance);public sealed record PickRequestDto(Point3Dto Origin, Vector3Dto Direction, TessellationOptionsDto? TessellationOptions, PickOptionsDto? PickOptions);diff --git a/aetheris.client/src/App.tsx b/aetheris.client/src/App.tsxindex 34b317a3..77325781 100644--- a/aetheris.client/src/App.tsx+++ b/aetheris.client/src/App.tsx@@ -9,12 +9,13 @@ import {getDocumentSummary,importStep,pickBody,- tessellateBody,+ prepareBodyDisplay,translateBody,type BooleanOperation,type BodyOccurrenceSummaryDto,type DiagnosticDto,type PickHitDto,+ type DisplayPreparationResponseDto,type TessellationResponseDto,} from './api/aetherisApi';import { StepImportDropzone } from './components/StepImportDropzone';@@ -43,6 +44,7 @@ function App() {const [occurrences, setOccurrences] = useState<BodyOccurrenceSummaryDto[]>([]);const [activeBodyId, setActiveBodyId] = useState<string | null>(null);const [tessellation, setTessellation] = useState<TessellationResponseDto | null>(null);+ const [displayPreparation, setDisplayPreparation] = useState<DisplayPreparationResponseDto | null>(null);const [status, setStatus] = useState<RequestStatus>('idle');const [statusMessage, setStatusMessage] = useState<string>('Ready. Create a document to begin.');const [serverStatus, setServerStatus] = useState<ServerStatus>('connecting');@@ -79,6 +81,7 @@ function App() {setActiveBodyId(null);setOccurrences([]);setTessellation(null);+ setDisplayPreparation(null);setPickStatus('idle');setPickMessage('Click in the viewport to run nearest-hit pick.');setPickDiagnostics([]);@@ -161,10 +164,12 @@ function App() {setActiveBodyId(selected ?? null);if (selected) {- const tessellated = await tessellateBody(documentId, selected);- setTessellation(tessellated);+ const preparedDisplay = await prepareBodyDisplay(documentId, selected);+ setDisplayPreparation(preparedDisplay);+ setTessellation(preparedDisplay.tessellationFallback);} else {setTessellation(null);+ setDisplayPreparation(null);}}, [activeBodyId, documentId]);@@ -210,9 +215,10 @@ function App() {}await runAction('Select active body', async () => {- const tessellated = await tessellateBody(documentId, nextBodyId);+ const preparedDisplay = await prepareBodyDisplay(documentId, nextBodyId);setActiveBodyId(nextBodyId);- setTessellation(tessellated);+ setDisplayPreparation(preparedDisplay);+ setTessellation(preparedDisplay.tessellationFallback);setPickStatus('idle');setPickMessage('Active body changed. Click in viewport to pick nearest hit.');setPickDiagnostics([]);@@ -245,15 +251,16 @@ function App() {});}, [activeBodyId, documentId, refreshSummaryAndActiveTessellation, runAction, tx, ty, tz]);- const handleRefreshTessellation = useCallback(async () => {+ const handleRefreshDisplay = useCallback(async () => {if (!documentId || !activeBodyId) {return;}setIsRefreshing(true);- await runAction('Refresh tessellation', async () => {- const tessellated = await tessellateBody(documentId, activeBodyId);- setTessellation(tessellated);+ await runAction('Refresh display data', async () => {+ const preparedDisplay = await prepareBodyDisplay(documentId, activeBodyId);+ setDisplayPreparation(preparedDisplay);+ setTessellation(preparedDisplay.tessellationFallback);});setIsRefreshing(false);}, [activeBodyId, documentId, runAction]);@@ -512,9 +519,9 @@ function App() {<Buttontype="button"variant="outline"- onClick={() => void handleRefreshTessellation()}+ onClick={() => void handleRefreshDisplay()}disabled={documentStatus !== 'ready' || !activeBodyId || status === 'loading' || isRefreshing}>- Refresh Tessellation+ Refresh Display Data</Button></div><div className="status-row" role="status" aria-live="polite">@@ -648,6 +655,9 @@ function App() {{copyHashMessage ? <p>{copyHashMessage}</p> : null}<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>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><p><strong>Edge count:</strong> {tessellation?.edgePolylines.length ?? 0}</p><p><strong>Shell count:</strong> {activeBodyId ? 1 : 0}</p>@@ -749,6 +759,9 @@ function App() {<p><strong>Document ID:</strong> {documentId ?? 'None'}</p><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>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><p><strong>Edge polylines:</strong> {tessellation?.edgePolylines.length ?? 0}</p><h3 className="section-title section-title--sub">Pick Diagnostics (active body only)</h3>diff --git a/aetheris.client/src/api/aetherisApi.ts b/aetheris.client/src/api/aetherisApi.tsindex 41afdc3e..e6690764 100644--- a/aetheris.client/src/api/aetherisApi.ts+++ b/aetheris.client/src/api/aetherisApi.ts@@ -103,6 +103,42 @@ export interface TessellationResponseDto {edgePolylines: EdgePolylineDto[];}+export interface AnalyticDisplayFaceDomainHintDto {+ minV: number | null;+ maxV: number | null;+}++export interface AnalyticDisplayFaceDto {+ faceId: number;+ shellId: number;+ shellRole: 'Outer' | 'InnerVoid' | 'Unknown';+ surfaceGeometryId: number;+ surfaceKind: 'Plane' | 'Sphere' | 'Cylinder' | 'Cone' | 'Torus' | string;+ loopCount: number;+ domainHint: AnalyticDisplayFaceDomainHintDto | null;+}++export interface AnalyticDisplayFallbackFaceDto {+ faceId: number;+ shellId: number;+ shellRole: 'Outer' | 'InnerVoid' | 'Unknown';+ reason: 'MissingFaceBinding' | 'MissingSurfaceGeometry' | 'UnsupportedSurfaceKind' | 'UnsupportedTrim' | string;+ surfaceKind: string | null;+ detail: string | null;+}++export interface AnalyticDisplayPacketDto {+ bodyId: number;+ analyticFaces: AnalyticDisplayFaceDto[];+ fallbackFaces: AnalyticDisplayFallbackFaceDto[];+}++export interface DisplayPreparationResponseDto {+ lane: 'analytic-only' | 'mixed-fallback' | 'fallback-only' | string;+ analyticPacket: AnalyticDisplayPacketDto;+ tessellationFallback: TessellationResponseDto | null;+}+export interface PickOptionsDto {nearestOnly?: boolean;includeBackfaces?: boolean;@@ -202,6 +238,13 @@ export async function tessellateBody(documentId: string, bodyId: string): Promis});}+export async function prepareBodyDisplay(documentId: string, bodyId: string): Promise<DisplayPreparationResponseDto> {+ return request<DisplayPreparationResponseDto>(`/api/v1/documents/${documentId}/bodies/${bodyId}/display/prepare`, {+ method: 'POST',+ body: JSON.stringify({ tessellationOptions: null }),+ });+}+export async function pickBody(documentId: string, bodyId: string, pickRequest: PickRequestDto): Promise<PickResponseDto> {return request<PickResponseDto>(`/api/v1/documents/${documentId}/bodies/${bodyId}/pick`, {method: 'POST',