import type { CadStepReport, CadNormalizedStepReport } from '../../cad-features/index.mjs'; import type { NativeSldprtPreview } from '../../native-sldprt/index.mjs'; import type { MeshFeatureReport } from '../../mesh-features/index.mjs'; import type { MeshDepthReport } from '../../mesh-depth-features/index.mjs'; import type { Inspection } from '../../cad-obround/index.mjs'; type WithoutBase = T extends unknown ? Omit : never; export type ExactOpeningEvidence = WithoutBase>; export type DepthAnalysis = ({mode:'native_cache';report:NativeSldprtPreview;cache_features:MeshFeatureReport} | {mode:'step_brep';report:CadStepReport;exact_openings?:ExactOpeningEvidence;exact_openings_not_run?:string;kernel_source?:{kind:string;filename?:string;sha256?:string;package?:string}}) & {depth_features?:MeshDepthReport;depth_error?:string}; export type NormalizedAnalysis = {mode:'step_brep';report:CadNormalizedStepReport;kernel_source:{kind:'bundled';package:'occt-wasm@3.4.0'};exact_openings?:never;depth_features?:never;exact_openings_not_run:string;depth_error:string}; export type Analysis = DepthAnalysis | NormalizedAnalysis; /** Compact each STEP face: repeated global vertex arrays would multiply resource usage. */ export function depthMeshes(analysis:Analysis){ if(analysis.mode==='native_cache')return analysis.report.meshes; const m=analysis.report.mesh;if(!m)return[]; return m.face_groups.map(g=>{ const indices=m.indices.slice(g.triangle_start*3,(g.triangle_start+g.triangle_count)*3),refs=[...new Set(indices)],local=new Map(refs.map((n,i)=>[n,i])); return{id:g.face_id,positions_mm:refs.flatMap(i=>m.positions.slice(i*3,i*3+3)),normals:refs.flatMap(i=>m.normals.slice(i*3,i*3+3)),triangles:indices.map(i=>local.get(i)!)}; }); } export function depthBounds(analysis:Analysis):{min:[number,number,number];max:[number,number,number]}{ if(analysis.mode==='native_cache')return analysis.report.model.bounds_mm; const b=analysis.report.model.bounds_mm;return{min:[b.xmin,b.ymin,b.zmin],max:[b.xmax,b.ymax,b.zmax]}; }