@margoengine/brep 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +14 -0
  3. package/README.md +201 -3
  4. package/dist/geometry/curves.d.ts +31 -0
  5. package/dist/geometry/exact.d.ts +6 -0
  6. package/dist/geometry/nurbs.d.ts +35 -0
  7. package/dist/geometry/read.d.ts +22 -0
  8. package/dist/geometry/surfaces.d.ts +75 -0
  9. package/dist/geometry/vec.d.ts +33 -0
  10. package/dist/iges/file.d.ts +66 -0
  11. package/dist/iges/geometry.d.ts +148 -0
  12. package/dist/iges/shapes.d.ts +30 -0
  13. package/dist/iges/step.d.ts +19 -0
  14. package/dist/index.d.ts +90 -0
  15. package/dist/index.js +16185 -0
  16. package/dist/jt/codec.d.ts +29 -0
  17. package/dist/jt/file.d.ts +70 -0
  18. package/dist/jt/lsg.d.ts +82 -0
  19. package/dist/jt/lzma.d.ts +22 -0
  20. package/dist/jt/mesh.d.ts +17 -0
  21. package/dist/jt/read.d.ts +68 -0
  22. package/dist/mesh/cdt.d.ts +41 -0
  23. package/dist/mesh/tessellate.d.ts +106 -0
  24. package/dist/mesh/validate.d.ts +45 -0
  25. package/dist/model/blend.d.ts +38 -0
  26. package/dist/model/boolean.d.ts +37 -0
  27. package/dist/model/build.d.ts +75 -0
  28. package/dist/model/check.d.ts +8 -0
  29. package/dist/model/distance.d.ts +28 -0
  30. package/dist/model/export.d.ts +17 -0
  31. package/dist/model/faces.d.ts +183 -0
  32. package/dist/model/geometry.d.ts +103 -0
  33. package/dist/model/import.d.ts +30 -0
  34. package/dist/model/index.d.ts +27 -0
  35. package/dist/model/intersect.d.ts +28 -0
  36. package/dist/model/loft.d.ts +12 -0
  37. package/dist/model/march.d.ts +20 -0
  38. package/dist/model/mass.d.ts +28 -0
  39. package/dist/model/offset-surface.d.ts +16 -0
  40. package/dist/model/offset.d.ts +39 -0
  41. package/dist/model/seams.d.ts +26 -0
  42. package/dist/model/setback.d.ts +12 -0
  43. package/dist/model/sew.d.ts +47 -0
  44. package/dist/model/sweep.d.ts +37 -0
  45. package/dist/model/topology.d.ts +116 -0
  46. package/dist/model/validate.d.ts +16 -0
  47. package/dist/sat/read.d.ts +16 -0
  48. package/dist/step/file.d.ts +82 -0
  49. package/dist/step/structure.d.ts +131 -0
  50. package/dist/step/write.d.ts +57 -0
  51. package/dist/xt/read.d.ts +22 -0
  52. package/dist/xt/schema.d.ts +18 -0
  53. package/dist/xt/step.d.ts +19 -0
  54. package/package.json +52 -6
@@ -0,0 +1,29 @@
1
+ import { type JTReader } from './file.js';
2
+ /**
3
+ * Reads an Int32 Compressed Data Packet: Mk. 2 (JT 9.5 8.1.2), or with `jt10` the third generation (ISO 14306 13.1.1),
4
+ * which adds the move-to-front codec, marks the escape entry of its context with a flag, and gives the out-of-band
5
+ * packet only when the context has an escape entry.
6
+ */
7
+ export declare function int32Packet(r: JTReader, jt10: boolean, depth?: number): Int32Array;
8
+ /** Residual predictors (Appendix C 1.3). */
9
+ export declare const Predictor: {
10
+ readonly Lag1: 0;
11
+ readonly Lag2: 1;
12
+ readonly Stride1: 2;
13
+ readonly Stride2: 3;
14
+ readonly StripIndex: 4;
15
+ readonly Ramp: 5;
16
+ readonly Xor1: 6;
17
+ readonly Xor2: 7;
18
+ readonly None: 8;
19
+ };
20
+ export type Predictor = (typeof Predictor)[keyof typeof Predictor];
21
+ /** Rebuilds values from predictor residuals: the first four are primers, the rest residual plus (or xor) prediction. */
22
+ export declare function unpack(residuals: Int32Array, predictor: Predictor): Int32Array;
23
+ /**
24
+ * The format's hash of 32-bit words (Appendix D `hash32`, Jenkins' `hash2`): the words taken three at a time, then
25
+ * the length folded in, counted in words as real files do.
26
+ */
27
+ export declare function hash32(words: ArrayLike<number>, seed: number): number;
28
+ /** The format's hash of 16-bit values (Appendix D `hash16`): two to a word, the length counted in values. */
29
+ export declare function hash16(values: ArrayLike<number>, seed: number): number;
@@ -0,0 +1,70 @@
1
+ export declare const fail: (message: string) => never;
2
+ /** Bounds-checked reader over a byte range in the file's byte order. */
3
+ export declare class JTReader {
4
+ readonly bytes: Uint8Array;
5
+ readonly little: boolean;
6
+ readonly end: number;
7
+ at: number;
8
+ private readonly view;
9
+ constructor(bytes: Uint8Array, little: boolean, at?: number, end?: number);
10
+ get left(): number;
11
+ need(n: number): number;
12
+ u8(): number;
13
+ i16(): number;
14
+ u16(): number;
15
+ i32(): number;
16
+ u32(): number;
17
+ u64(): number;
18
+ f32(): number;
19
+ f64(): number;
20
+ /** A GUID as lower-case hex `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` (U32, two U16, eight U8). */
21
+ guid(): string;
22
+ /** A count, checked against the bytes left (`size` bytes per item). */
23
+ count(size: number): number;
24
+ /** MbString: I32 count, then UTF-16 code units. */
25
+ mbString(): string;
26
+ /** String: I32 count, then single-byte characters. */
27
+ string(): string;
28
+ vecI32(): Int32Array;
29
+ vecU32(): Uint32Array;
30
+ vecF32(): Float32Array;
31
+ f32s(n: number): number[];
32
+ /** A reader over the next `n` bytes; this reader moves past them. */
33
+ sub(n: number): JTReader;
34
+ }
35
+ /** One TOC entry: a data segment's ID, place in the file and type. */
36
+ interface JTSegment {
37
+ readonly id: string;
38
+ readonly offset: number;
39
+ readonly length: number;
40
+ /** Segment type: 1 LSG, 2 JT B-rep, 3 PMI, 4 meta data, 6 shape, 7-16 shape LODs, 17 XT B-rep, 18 wireframe. */
41
+ readonly type: number;
42
+ }
43
+ /** One element: object type ID, base type, object ID and its data (a reader positioned after the header). */
44
+ export interface JTElement {
45
+ readonly type: string;
46
+ readonly baseType: number;
47
+ readonly id: number;
48
+ readonly data: JTReader;
49
+ }
50
+ /** The file header and table of contents of a JT file. */
51
+ export declare class JTContainer {
52
+ readonly bytes: Uint8Array;
53
+ /** Format version, e.g. 9.5 or 10.0. */
54
+ readonly version: number;
55
+ /** The 80-character version string, trimmed. */
56
+ readonly versionText: string;
57
+ readonly little: boolean;
58
+ /** The LSG segment's ID. */
59
+ readonly lsg: string;
60
+ readonly segments: ReadonlyMap<string, JTSegment>;
61
+ constructor(bytes: Uint8Array);
62
+ /**
63
+ * A segment's element data: a reader at its first element, the whole segment decompressed when it is stored
64
+ * compressed. Throws a TypeError for a segment the TOC does not list or a header that does not match it.
65
+ */
66
+ data(id: string): JTReader;
67
+ }
68
+ /** The next element of `r`, or undefined at an end-of-elements marker (which is read past). */
69
+ export declare function readElement(r: JTReader): JTElement | undefined;
70
+ export {};
@@ -0,0 +1,82 @@
1
+ import { type JTContainer } from './file.js';
2
+ /** Object type IDs (JT File Format Reference Appendix A; ISO 14306 Annex A). */
3
+ export declare const JT_TYPES: {
4
+ readonly baseNode: '10dd1035-2ac8-11d1-9b6b-0080c7bb5997';
5
+ readonly group: '10dd101b-2ac8-11d1-9b6b-0080c7bb5997';
6
+ readonly instance: '10dd102a-2ac8-11d1-9b6b-0080c7bb5997';
7
+ readonly lod: '10dd102c-2ac8-11d1-9b6b-0080c7bb5997';
8
+ readonly metaData: 'ce357245-38fb-11d1-a506-006097bdc6e1';
9
+ readonly part: 'ce357244-38fb-11d1-a506-006097bdc6e1';
10
+ readonly partition: '10dd103e-2ac8-11d1-9b6b-0080c7bb5997';
11
+ readonly rangeLod: '10dd104c-2ac8-11d1-9b6b-0080c7bb5997';
12
+ readonly switch: '10dd10f3-2ac8-11d1-9b6b-0080c7bb5997';
13
+ readonly material: '10dd1030-2ac8-11d1-9b6b-0080c7bb5997';
14
+ readonly transform: '10dd1083-2ac8-11d1-9b6b-0080c7bb5997';
15
+ readonly baseProperty: '10dd104b-2ac8-11d1-9b6b-0080c7bb5997';
16
+ readonly stringProperty: '10dd106e-2ac8-11d1-9b6b-0080c7bb5997';
17
+ readonly integerProperty: '10dd102b-2ac8-11d1-9b6b-0080c7bb5997';
18
+ readonly floatProperty: '10dd1019-2ac8-11d1-9b6b-0080c7bb5997';
19
+ readonly referenceProperty: '10dd1004-2ac8-11d1-9b6b-0080c7bb5997';
20
+ readonly dateProperty: 'ce357246-38fb-11d1-a506-006097bdc6e1';
21
+ readonly lateLoadedProperty: 'e0b05be5-fbbd-11d1-a3a7-00aa00d10954';
22
+ readonly vector4Property: '2e7db4be-c71a-4b18-9d07-c7227e9fef76';
23
+ readonly xtBRep: '873a70e0-2ac9-11d1-9b6b-0080c7bb5997';
24
+ /** The MultiXT segment's element (not in the published texts; seen in JT 10.5 files). */
25
+ readonly multiXTBRep: '49829521-1835-49c3-8bef-ddc43bfe5e88';
26
+ };
27
+ /** What a shape node draws. */
28
+ export type JTShapeKind = 'shape' | 'tri-strip' | 'polygon' | 'polyline' | 'point' | 'primitive' | 'vertex' | 'null';
29
+ /** How a node's children are used. */
30
+ export type JTNodeKind = 'node' | 'group' | 'partition' | 'instance' | 'part' | 'meta-data' | 'lod' | 'range-lod' | 'switch' | 'shape';
31
+ /** A node of the scene graph. */
32
+ export interface JTNode {
33
+ readonly id: number;
34
+ /** Object type ID. */
35
+ readonly type: string;
36
+ readonly kind: JTNodeKind;
37
+ /** For a shape node, what it draws. */
38
+ readonly shape?: JTShapeKind;
39
+ /** The node's ignore flag: traversals skip it and everything below it. */
40
+ readonly ignore: boolean;
41
+ /** Attribute object IDs (transforms, materials and others), in order. */
42
+ readonly attributes: readonly number[];
43
+ /** Child node object IDs, in order (an instance node's one child; an LOD node's alternatives, finest first). */
44
+ readonly children: readonly number[];
45
+ /** A switch node's selected child index (-1 for none). */
46
+ readonly selected?: number;
47
+ /** A partition node's file name, relative to this file (empty for the file's own root partition). */
48
+ readonly file?: string;
49
+ }
50
+ /** An attribute of the scene graph. */
51
+ export interface JTAttribute {
52
+ readonly id: number;
53
+ readonly type: string;
54
+ readonly kind: 'transform' | 'material' | 'other';
55
+ /** A transform's 4x4 matrix as stored: row-major for row vectors (p' = p A), which is column-major for column vectors. */
56
+ readonly matrix?: readonly number[];
57
+ /** A material's diffuse colour and alpha. */
58
+ readonly diffuse?: readonly [number, number, number, number];
59
+ }
60
+ /** A late-loaded property: data in another segment. */
61
+ export interface JTLateLoaded {
62
+ readonly segment: string;
63
+ readonly segmentType: number;
64
+ readonly payload: number;
65
+ }
66
+ /** A property value. */
67
+ export type JTPropertyValue = string | number | readonly number[] | JTLateLoaded | {
68
+ readonly object: number;
69
+ } | {
70
+ readonly date: string;
71
+ };
72
+ /** The scene graph: nodes and attributes by object ID, and each element's properties. */
73
+ export interface JTSceneGraph {
74
+ readonly nodes: ReadonlyMap<number, JTNode>;
75
+ readonly attributes: ReadonlyMap<number, JTAttribute>;
76
+ /** Properties by node or attribute object ID, keyed by the key atom's value (usually a string). */
77
+ readonly properties: ReadonlyMap<number, ReadonlyMap<string, JTPropertyValue>>;
78
+ /** The first graph element (the file's root partition node). */
79
+ readonly root: number | undefined;
80
+ }
81
+ /** Reads the LSG segment of a JT file. Throws a TypeError for malformed data. */
82
+ export declare function readSceneGraph(container: JTContainer): JTSceneGraph;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Decodes an LZMA stream as JT 10 stores it: properties byte and 4-byte dictionary size, then either an 8-byte unpacked
3
+ * size (the .lzma "alone" header; all ones = unknown) or directly the range-coded data ending in an end marker.
4
+ * Returns the decoded bytes (a view of exactly the produced length).
5
+ * @param input - The compressed segment bytes.
6
+ * @param limit - The most output bytes accepted (default 2^30).
7
+ * @throws TypeError for malformed data or output past `limit` bytes (default 2^30).
8
+ */
9
+ export declare function inflateLZMA(input: Uint8Array, limit?: number): Uint8Array;
10
+ /**
11
+ * True when input starts with the XZ stream magic FD 37 7A 58 5A 00 (false for shorter input).
12
+ * @param input - The bytes to test.
13
+ */
14
+ export declare const isXZ: (input: Uint8Array) => boolean;
15
+ /**
16
+ * Decodes one XZ stream whose blocks each use the single filter LZMA2. Checks (CRC32/CRC64/SHA-256) and header CRCs are
17
+ * not verified; index and footer are not read. Returns all blocks' output concatenated.
18
+ * @param input - The XZ stream bytes.
19
+ * @param limit - The most output bytes accepted (default 2^30).
20
+ * @throws TypeError for malformed data, any other filter chain, or output past `limit` bytes (default 2^30).
21
+ */
22
+ export declare function inflateXZ(input: Uint8Array, limit?: number): Uint8Array;
@@ -0,0 +1,17 @@
1
+ import { type JTContainer } from './file.js';
2
+ /** A tessellated shape. */
3
+ export interface JTMesh {
4
+ /** Vertex positions in metres, three per vertex. */
5
+ readonly positions: Float32Array;
6
+ /** Unit vertex normals, three per vertex, when the file stores them. */
7
+ readonly normals?: Float32Array;
8
+ /** Three vertex indices per triangle, counter-clockwise seen from outside. */
9
+ readonly indices: Uint32Array;
10
+ /** Face group of each triangle (by the format's convention, the B-rep face it came from). */
11
+ readonly groups: Int32Array;
12
+ }
13
+ /**
14
+ * Reads a Tri-Strip Set Shape LOD segment into a triangle mesh in metres (`unit` metres per file unit). Throws a
15
+ * TypeError for malformed or inconsistent data and a RangeError for a coding this reader does not support yet.
16
+ */
17
+ export declare function readTriStripLOD(container: JTContainer, segment: string, unit: number): JTMesh;
@@ -0,0 +1,68 @@
1
+ import type { STEPModel, STEPOptions } from '../index.js';
2
+ import { type JTLateLoaded, type JTSceneGraph, type JTShapeKind } from './lsg.js';
3
+ import { type JTMesh } from './mesh.js';
4
+ /** A shape of a part: a tessellated representation stored in shape LOD segments. */
5
+ export interface JTShape {
6
+ /** The shape node's object ID. */
7
+ readonly node: number;
8
+ readonly kind: JTShapeKind;
9
+ /** Column-major 4x4 from the shape's coordinates (in the file's unit) to its part's, translation in metres. */
10
+ readonly matrix: Float64Array;
11
+ /** Its late-loaded shape LOD segments (segment types 6 to 16), finest first. */
12
+ readonly lods: readonly JTLateLoaded[];
13
+ /** The finest LOD's triangles (tri-strip set shapes of JT 9 files), in the part's coordinates in metres. */
14
+ readonly mesh?: JTMesh;
15
+ }
16
+ /** A part: one part node (or a shape outside any part), however many times the assembly places it. */
17
+ export interface JTPart {
18
+ /** The part node's object ID. */
19
+ readonly node: number;
20
+ readonly name: string;
21
+ /**
22
+ * The exact B-rep from the part's XT B-rep segment (or, for a subordinate one, its bodies in the file's MultiXT
23
+ * segment), read like a Parasolid file; undefined without one.
24
+ */
25
+ readonly brep?: STEPModel;
26
+ readonly shapes: readonly JTShape[];
27
+ }
28
+ /** One placement of a part. */
29
+ export interface JTInstance {
30
+ /** Index into `parts`. */
31
+ readonly part: number;
32
+ /** Column-major 4x4 from the part's coordinates in metres to the model's, in metres. */
33
+ readonly matrix: Float64Array;
34
+ /** The diffuse colour of the nearest material above the part, if any. */
35
+ readonly color?: readonly [number, number, number, number];
36
+ /** Names of the nodes from the root down to the part. */
37
+ readonly path: readonly string[];
38
+ }
39
+ /** Options of {@link parseJT}. */
40
+ export interface JTOptions extends STEPOptions {
41
+ /** Read each part's XT B-rep segment (default true). */
42
+ readonly brep?: boolean;
43
+ /** Decode each shape's finest LOD into `mesh` (default true). */
44
+ readonly meshes?: boolean;
45
+ }
46
+ /** A parsed JT file. */
47
+ export interface JTModel {
48
+ /** Format version, e.g. 9.5 or 10. */
49
+ readonly version: number;
50
+ readonly versionText: string;
51
+ /** Metres per unit of the file's coordinates (from JT_PROP_MEASUREMENT_UNITS). */
52
+ readonly unit: number;
53
+ readonly sceneGraph: JTSceneGraph;
54
+ readonly parts: readonly JTPart[];
55
+ readonly instances: readonly JTInstance[];
56
+ /** What the reader left out or assumed. */
57
+ readonly warnings: readonly string[];
58
+ }
59
+ /**
60
+ * Reads a JT file (ISO 14306; JT 9.5 and later) into its parts, their placements, names and colours, each part's exact
61
+ * B-rep from its XT B-rep segment (meshed with {@link tessellateJT}) and the shape LOD segments of its tessellated
62
+ * representation. Coordinates are in metres. Throws a TypeError for a malformed file and a RangeError for a JT version
63
+ * before 9.5.
64
+ * @example
65
+ * const model = parseJT(await (await fetch('/assembly.jt')).arrayBuffer());
66
+ * for (const instance of model.instances) console.log(instance.path.join('/'), model.parts[instance.part].brep?.bodies.length);
67
+ */
68
+ export declare function parseJT(input: ArrayBuffer | ArrayBufferView, options?: JTOptions): JTModel;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Orientation of three points: positive when a, b, c turn counter-clockwise, negative when they turn clockwise, zero
3
+ * when they are collinear. The sign is exact (Shewchuk's filtered predicate); the magnitude approximates twice the
4
+ * triangle's signed area.
5
+ */
6
+ export declare function orient2d(ax: number, ay: number, bx: number, by: number, cx: number, cy: number): number;
7
+ /**
8
+ * In-circle test: positive when d lies inside the circle through a, b, c (given counter-clockwise), negative when it
9
+ * lies outside, zero when the four points are cocircular. The sign is exact (Shewchuk's filtered predicate).
10
+ */
11
+ export declare function incircle(ax: number, ay: number, bx: number, by: number, cx: number, cy: number, dx: number, dy: number): number;
12
+ /**
13
+ * Constrained Delaunay triangulation of a 2D domain bounded by closed loops: a trimmed B-rep face in its surface's
14
+ * parameter space.
15
+ *
16
+ * - `xy`: interleaved x, y coordinates of every point (Float64Array or number[]).
17
+ * - `loops`: arrays of point indices; each loop is a closed boundary (the last point connects to the first) whose
18
+ * edges become constraint edges. Orientation does not matter; nesting decides inside by the even-odd rule (a point
19
+ * is in the domain when it is inside an odd number of loops). Loops may share points and touch at them; repeated
20
+ * consecutive indices (a degenerate pole) count as one point.
21
+ * - Points no loop references are free interior (Steiner) points; those outside the domain are ignored.
22
+ * - Points with identical coordinates are merged: the triangles use the first (lowest) index. A point lying exactly
23
+ * on a loop edge splits that edge.
24
+ *
25
+ * Exact predicates make collinear and cocircular inputs safe, and the output is deterministic. Throws a TypeError for
26
+ * non-finite coordinates, a loop with fewer than 3 distinct points, or loops that cross; a RangeError for an index out
27
+ * of range or a pathological input that would need an unbounded number of flips.
28
+ * @returns Triangle vertex indices, 3 per triangle, counter-clockwise in xy, covering exactly the domain.
29
+ * @example
30
+ * // A unit square with a free point in the middle: 4 triangles.
31
+ * const triangles = triangulate([0, 0, 1, 0, 1, 1, 0, 1, 0.5, 0.5], [[0, 1, 2, 3]]);
32
+ */
33
+ export declare function triangulate(xy: ArrayLike<number>, loops: readonly ArrayLike<number>[]): Uint32Array;
34
+ /**
35
+ * The edges of a triangulation that are not constraint edges: those shared by two triangles that are not an edge of
36
+ * any loop. The tessellator tests these for refinement and calls {@link triangulate} again with more free points.
37
+ * @param triangles Triangle vertex indices as {@link triangulate} returns them.
38
+ * @param loops The loops given to {@link triangulate}.
39
+ * @returns Point index pairs, 2 per edge (smaller index first), each edge once, in order of first appearance.
40
+ */
41
+ export declare function interiorEdges(triangles: Uint32Array, loops: readonly ArrayLike<number>[]): Uint32Array;
@@ -0,0 +1,106 @@
1
+ import { type STEPFile } from '../step/file.js';
2
+ import type { STEPBody, STEPColor } from '../step/structure.js';
3
+ /**
4
+ * Options of {@link Tessellator} and {@link tessellateSTEP}. Deflection is the largest distance between a triangle
5
+ * (or an edge's chord) and the exact geometry; angle is the largest turn between neighbouring samples' tangents or
6
+ * normals. Edges use `deflection` and `angle`; face interiors use the `interior` values, which default to them.
7
+ */
8
+ export interface TessellationOptions {
9
+ /** Deflection as a fraction of each body's bounding-box diagonal (default 0.001). Ignored when `deflection` is given. */
10
+ readonly relativeDeflection?: number;
11
+ /** Deflection in metres, the same for every body. */
12
+ readonly deflection?: number;
13
+ /** Largest turn between neighbouring edge samples, in radians (default 0.5). */
14
+ readonly angle?: number;
15
+ /** Deflection inside faces, in metres (default: the edges' deflection). */
16
+ readonly interiorDeflection?: number;
17
+ /** Largest turn between neighbouring normals inside faces, in radians (default: `angle`). */
18
+ readonly interiorAngle?: number;
19
+ /** Shortest triangle edge that refinement may create, in metres (default: a tenth of the deflection). */
20
+ readonly minSize?: number;
21
+ /** Most vertices per face (default 50,000); a face that needs more stays at that density. */
22
+ readonly maxFaceVertices?: number;
23
+ }
24
+ /** One face's triangles in a body mesh. */
25
+ export interface BodyMeshFace {
26
+ /** The face's entity id. */
27
+ readonly id: number;
28
+ /** First index into `indices` of the face's triangles. */
29
+ readonly first: number;
30
+ /** Number of indices (3 per triangle). */
31
+ readonly count: number;
32
+ /** The face's own style colour, when the file gives one. */
33
+ readonly color?: STEPColor;
34
+ }
35
+ /** A tessellated body: vertices per face (so B-rep edges stay hard), exact surface normals, triangle indices. */
36
+ export interface BodyMesh {
37
+ /** The body's entity id. */
38
+ readonly id: number;
39
+ /** Positions in the body's coordinates (multiply by `unit` for metres), 3 per vertex. */
40
+ readonly positions: Float32Array;
41
+ /** Unit normals, 3 per vertex. */
42
+ readonly normals: Float32Array;
43
+ /** Triangle vertex indices, counter-clockwise seen from outside the solid. */
44
+ readonly indices: Uint32Array;
45
+ /** The faces in order, each a run of `indices`. */
46
+ readonly faces: readonly BodyMeshFace[];
47
+ /** Faces left out, with the reason (a surface or curve the kernel lacks, or bounds it could not resolve). */
48
+ readonly failures: readonly {
49
+ readonly id: number;
50
+ readonly reason: string;
51
+ }[];
52
+ /** Metres per body unit. */
53
+ readonly unit: number;
54
+ /** The edge deflection used, in body units. */
55
+ readonly deflection: number;
56
+ /** Triangles as a tessellated body writes them, degenerate strip joins included (tessellated bodies only). */
57
+ readonly facets?: number;
58
+ }
59
+ /** Tessellates the bodies of one STEP file, caching curves, surfaces and edge discretizations. */
60
+ export declare class Tessellator {
61
+ private readonly file;
62
+ private readonly faceColors;
63
+ private readonly options;
64
+ private readonly curves;
65
+ private readonly surfaces;
66
+ private readonly edges;
67
+ /** Triangles of the body being meshed whose corners are all bound samples, by their corners' positions. */
68
+ private rim;
69
+ /** Curve parameters an edge must be sampled at: where it passes through a pole of a surface it bounds. */
70
+ private readonly through;
71
+ /** Surfaces an edge bounds faces of whose (u, v) chords may stray from it (`Surface.skewed`). */
72
+ private readonly skewedOn;
73
+ private readonly turn;
74
+ private readonly maxFaceVertices;
75
+ /**
76
+ * @param file - The parsed STEP file.
77
+ * @param faceColors - Face style colours by face id (`STEPStructure.faceColors`).
78
+ * @param options - Deflection, angle and size limits.
79
+ */
80
+ constructor(file: STEPFile, faceColors?: ReadonlyMap<number, STEPColor>, options?: TessellationOptions);
81
+ private curve;
82
+ private surface;
83
+ private vertex;
84
+ /** Points of edge `id` from its start vertex to its end vertex (the vertex alone for a degenerate edge). */
85
+ private edge;
86
+ /** A face bound's points in order (the face on their left seen from the face's normal side), or its single vertex. */
87
+ private bound;
88
+ /** Tessellates face `id`; throws a TypeError when its geometry or bounds cannot be resolved. */
89
+ private face;
90
+ /** A body's tolerances in its units: from the options in metres, or relative to its vertices' bounding box. */
91
+ private tolerances;
92
+ /** Tessellates a body. Faces that fail are listed in `failures`; the rest form the mesh. */
93
+ /**
94
+ * Before a body is meshed: an edge whose curve runs through a pole of a surface it bounds (a great circle over a
95
+ * sphere's poles) is sampled at the pole, so the face whose bound crosses the pole and its neighbour share that point.
96
+ * An edge on a skewed surface (`Surface.skewed`) is noted, to be sampled until its (u, v) chords there follow it.
97
+ */
98
+ private findPoleCrossings;
99
+ /**
100
+ * A tessellated body (AP242): TESSELLATED_SOLID or TESSELLATED_SHELL of triangulated faces, or one face or surface set
101
+ * on its own. Triangles come from lists, strips (alternating winding) or fans; 1-based indices go through pnindex to
102
+ * the coordinates list. Normals are the file's (one per point, or one for the face), else area-weighted per face.
103
+ */
104
+ private tessellatedBody;
105
+ body(body: STEPBody): BodyMesh;
106
+ }
@@ -0,0 +1,45 @@
1
+ import { type STEPPoint, type STEPStructure, type STEPValidationProperty } from '../step/structure.js';
2
+ import type { BodyMesh } from './tessellate.js';
3
+ /** Options of {@link validateSTEP}. */
4
+ export interface ValidationOptions {
5
+ /**
6
+ * Largest difference that passes (default 0.005): of volume and area relative to the stated value, of the centre and
7
+ * the box corners relative to the box's diagonal. Facet counts must match exactly.
8
+ */
9
+ readonly tolerance?: number;
10
+ }
11
+ /** What the meshes measure for the quantities a property states, in its frame and units (metres). */
12
+ export interface STEPMeasured {
13
+ readonly volume?: number;
14
+ readonly area?: number;
15
+ readonly centroid?: STEPPoint;
16
+ readonly box?: readonly [STEPPoint, STEPPoint];
17
+ readonly facets?: number;
18
+ }
19
+ /** One stated property checked against the meshes. */
20
+ export interface STEPValidationCheck {
21
+ readonly property: STEPValidationProperty;
22
+ readonly measured: STEPMeasured;
23
+ /** Volume and area: |measured / stated - 1|; centroid and box: largest distance over the box diagonal; facets: count. */
24
+ readonly differences: {
25
+ readonly volume?: number;
26
+ readonly area?: number;
27
+ readonly centroid?: number;
28
+ readonly box?: number;
29
+ readonly facets?: number;
30
+ };
31
+ /** Every stated quantity within tolerance, measured on meshes with no failed face. */
32
+ readonly ok: boolean;
33
+ /** Why a quantity could not be measured, or which bodies' faces failed. */
34
+ readonly note?: string;
35
+ }
36
+ /**
37
+ * Checks meshes of a STEP model against the validation properties the file states (`model.validation`): volume, area,
38
+ * centre, bounding box and facet count, each measured in the property's own frame. A product's property covers its
39
+ * components' solids (its surface bodies when it has no solid; its independent surfaces for those properties), and
40
+ * its area may count its surface bodies too, as some exporters do; a tessellated property is checked against the
41
+ * tessellated bodies, a geometric one against the B-rep.
42
+ *
43
+ * @param meshes One mesh per body, in `model.bodies` order (what `tessellateSTEP` returns).
44
+ */
45
+ export declare function validateSTEP(model: STEPStructure, meshes: readonly BodyMesh[], { tolerance }?: ValidationOptions): STEPValidationCheck[];
@@ -0,0 +1,38 @@
1
+ import { type XYZ } from '../geometry/vec.js';
2
+ import type { Body, History, Edge, Face, Name } from './topology.js';
3
+ /** A rounding of one radius, or a bevel one distance along each face. */
4
+ export type Blend = {
5
+ kind: 'fillet';
6
+ radius: number;
7
+ } | {
8
+ kind: 'chamfer';
9
+ distance: number;
10
+ };
11
+ /**
12
+ * Rounds the named edges of `body` to `radius` (metres): straight edges between two planar faces, convex or concave,
13
+ * at any angle between the faces; corners where three rounded edges meet at right angles get a sphere. Returns a new
14
+ * solid `name`; `history` gets each step (the rounding of edge `<edge>` is `<name>:<edge>/face:round`). Throws a
15
+ * RangeError for an edge it cannot find or round.
16
+ */
17
+ export declare function fillet(name: Name, body: Body, edges: readonly Name[], radius: number, options?: {
18
+ history?: History;
19
+ }): Body;
20
+ /**
21
+ * Bevels the named edges of `body` by `distance` (metres) along each of its two faces: straight edges between two
22
+ * planar faces, convex or concave. The bevel of edge `<edge>` is `<name>:<edge>/face:bevel`.
23
+ */
24
+ export declare function chamfer(name: Name, body: Body, edges: readonly Name[], distance: number, options?: {
25
+ history?: History;
26
+ }): Body;
27
+ /** One edge to blend, as the body gives it. */
28
+ export interface Selected {
29
+ name: Name;
30
+ edge: Edge;
31
+ /** Into each of its two faces from the edge, across it, and those faces. */
32
+ u1: XYZ;
33
+ u2: XYZ;
34
+ f1: Face;
35
+ f2: Face;
36
+ angle: number;
37
+ convex: boolean;
38
+ }
@@ -0,0 +1,37 @@
1
+ import { FaceUV } from './faces.js';
2
+ import type { Box3 } from './march.js';
3
+ import { Body, type History, type Name } from './topology.js';
4
+ /** What a Boolean keeps: material in either solid, in the first but not the second, or in both. */
5
+ export type BooleanOperation = 'union' | 'subtract' | 'intersect';
6
+ /**
7
+ * `op` of solids `a` and `b` into a new solid `name`, with persistent names: faces and edges that come through keep
8
+ * theirs, a face split into several kept pieces gives `<face>#k`, a split edge `<edge>#k`, and intersection edges
9
+ * `<name>/edge:<face of a>|<face of b>#k`; `history` records splits as modifications, intersection edges as generated
10
+ * from their two faces, and what was removed as deleted. Supported: faces on planes, cylinders, cones, spheres, tori
11
+ * and spline surfaces in any position: faces on one surface, edges along edges and vertices on faces meet within 1e-6
12
+ * of the model, and a vertex lies on the faces it bounds within its own tolerance (an imported edge a little off its
13
+ * face) but on the other solid's within the 1e-6 alone: faces further apart than that, though within their vertices'
14
+ * tolerance (1e-7 m), are cut apart, a box 50 nm taller than another beside it keeping its 50 nm step. Faces left on
15
+ * one surface facing the same way, and edges split along one curve, are joined; a region thinner than its edges'
16
+ * samples stray from their curves is traced again from finer samples. Surfaces touching at a point (two of their curves
17
+ * crossing there) or along a line (a plane along a cylinder) are cut there, and so are surfaces that come within the
18
+ * 1e-6 of touching; where the result's surface touches itself, its sheets meet at a point or along a line without
19
+ * sharing a vertex or edge there; where they come a little further than that from touching, the curves passing each
20
+ * other there a few micrometres apart are cut apart, and a curve passing that far inside a face's edge (or cutting a
21
+ * sliver that thin off a face) splits the face there. Surfaces touching along a circle or a curve (a ball in a bore or
22
+ * in a torus's tube, a pipe running on from an elbow) cut neither face along it, exactly or within the tolerance; the
23
+ * curves crossing it cross it at a vertex. A torus is cut round its tube as well as round its axis, and spline faces
24
+ * lying on one surface (copies, pieces of one patch with their own control points) overlap as planes do. Throws a
25
+ * RangeError for what is not supported yet (a loop going round a torus both ways: a plane touching it twice cuts it
26
+ * along its Villarceau circles) and when the result is not a valid solid.
27
+ */
28
+ export declare function boolean(name: Name, op: BooleanOperation, a: Body, b: Body, { history }?: {
29
+ history?: History;
30
+ }): Body;
31
+ /**
32
+ * A box round a face, generous rather than tight: its boundary samples, and on a curved surface a grid over its
33
+ * (u, v) bounds as well (the face can bulge past its boundary); a sphere or torus is boxed whole.
34
+ */
35
+ export declare function faceBox(fuv: FaceUV, merge: number): Box3;
36
+ /** The common part of two boxes, or undefined when they are apart. */
37
+ export declare function overlap(a: Box3, b: Box3): Box3 | undefined;
@@ -0,0 +1,75 @@
1
+ import { type XYZ } from '../geometry/vec.js';
2
+ import { type Frame } from './geometry.js';
3
+ import { Body, type History, type Name } from './topology.js';
4
+ /** One piece of a profile: a line to `to`, or an arc to `to` about `center` (counter-clockwise about the profile normal unless `clockwise`). */
5
+ export interface ProfileSegment {
6
+ readonly kind: 'line' | 'arc';
7
+ readonly to: XYZ;
8
+ readonly center?: XYZ;
9
+ readonly clockwise?: boolean;
10
+ /** The name the side face made from this segment takes after the operation's name. */
11
+ readonly name?: Name;
12
+ }
13
+ /** A closed planar profile: from `start`, segment by segment, back to `start`. */
14
+ export interface Profile {
15
+ readonly name: Name;
16
+ readonly start: XYZ;
17
+ /** Normal of the profile's plane. */
18
+ readonly normal: XYZ;
19
+ readonly segments: readonly ProfileSegment[];
20
+ }
21
+ /** A profile's own size (its box with its arcs' circles), the same wherever it sits (see `modelSize`). */
22
+ export declare const profileSize: (profile: Profile) => number;
23
+ /** The angle an arc from `at` turns about `n`: positive counter-clockwise, a whole turn when it ends where it starts. */
24
+ export declare function sweepOf(at: XYZ, s: ProfileSegment, n: XYZ): number;
25
+ /** Signed area of a profile about `n` (counter-clockwise positive), arcs included. */
26
+ export declare function signedArea(profile: Profile, n: XYZ): number;
27
+ /**
28
+ * Throws a RangeError when a profile crosses or touches itself anywhere but where one segment meets the next (arcs
29
+ * are followed as chords of 1/128 turn), or turns straight back on itself.
30
+ */
31
+ export declare function refuseSelfContact(profile: Profile, n: XYZ, tolerance: number): void;
32
+ export declare const fmt: (p: XYZ) => string;
33
+ /** The same profile run the other way. */
34
+ export declare function reversed(profile: Profile): Profile;
35
+ /**
36
+ * Extrudes a closed planar profile along `vector` into a solid named `name`: a bottom and top face, and a side face
37
+ * per segment (a plane for a line; for an arc, a cylinder: arcs need `vector` along the profile normal). Throws a
38
+ * RangeError for an open, degenerate or self-touching profile, and for arcs under an oblique extrusion.
39
+ */
40
+ export declare function extrude(name: Name, profile: Profile, vector: XYZ, { history, bottom, top }?: {
41
+ history?: History;
42
+ bottom?: Name;
43
+ top?: Name;
44
+ }): Body;
45
+ /** A box of the given sizes from `frame`'s origin along its x, y and z axes, faces named -x, +x, -y, +y, -z, +z. */
46
+ export declare function box(name: Name, size: XYZ, frame?: Frame, history?: History): Body;
47
+ /** A cylinder of `radius` about `frame`'s z axis from its origin up `height`; faces side, -z, +z. */
48
+ export declare function cylinder(name: Name, radius: number, height: number, frame?: Frame, history?: History): Body;
49
+ /** A solid sphere: one face with no edges. */
50
+ export declare function sphere(name: Name, radius: number, frame?: Frame, history?: History): Body;
51
+ /** A solid torus about `frame`'s z axis: one face with no edges. */
52
+ export declare function torus(name: Name, major: number, minor: number, frame?: Frame, history?: History): Body;
53
+ /**
54
+ * A solid cone or frustum about `frame`'s z axis: radius `radius` at its origin and `topRadius` at `height` up the
55
+ * axis, either of them 0 for an apex (a vertex where the side's seam ends). Faces side, -z and +z (a disc at each end
56
+ * that is not an apex). Equal radii make a cylinder. Throws a RangeError for a negative or non-finite size, a height
57
+ * that is not positive, and two radii of 0.
58
+ */
59
+ export declare function cone(name: Name, radius: number, topRadius: number, height: number, frame?: Frame, history?: History): Body;
60
+ /**
61
+ * Turns a closed planar profile of lines and arcs once round an axis lying in its plane, into a solid named `name`: a
62
+ * face per segment (a plane, cylinder or cone for a line; a torus, or a sphere for an arc centred on the axis), each
63
+ * closed by its own seam, and a circle at every profile point off the axis. The profile may touch the axis: a segment
64
+ * along the axis makes no face, a line ending on the axis makes a disc (a plane bounded by its circle alone) or a cone
65
+ * up to its apex vertex, and an arc centred on the axis makes a sphere up to its pole (a whole sphere, with no edges,
66
+ * when both its ends are on the axis). Throws a RangeError for an open, degenerate or self-touching profile, one that
67
+ * leaves the axis's plane or crosses the axis, a point on the axis where the solid would pinch to that point (one
68
+ * with no segment along the axis next to it), and an arc not centred on the axis that reaches it.
69
+ */
70
+ export declare function revolve(name: Name, profile: Profile, axis: {
71
+ readonly origin: XYZ;
72
+ readonly direction: XYZ;
73
+ }, { history }?: {
74
+ history?: History;
75
+ }): Body;
@@ -0,0 +1,8 @@
1
+ import type { Body } from './topology.js';
2
+ import { type ValidityProblem } from './validate.js';
3
+ /**
4
+ * Every problem with `body` that validateBody finds and, when it finds none, these too: a solid's shell facing into its
5
+ * material (or a cavity's out of the cavity), two edges of a face crossing, and an edge passing through or lying inside
6
+ * a face it does not bound. Empty when the body is valid.
7
+ */
8
+ export declare function checkBody(body: Body): ValidityProblem[];