okgeometry-api 1.2.1 → 1.5.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.
@@ -12,6 +12,21 @@ export function arc_length(radius: number, start_angle: number, end_angle: numbe
12
12
  */
13
13
  export function arc_point_at(cx: number, cy: number, cz: number, nx: number, ny: number, nz: number, radius: number, start_angle: number, end_angle: number, t: number): Float64Array;
14
14
 
15
+ /**
16
+ * Build a NURBS curve from raw control points with kernel-managed knots and weights.
17
+ *
18
+ * * `degree` - Requested degree (clamped to the valid range for the point count)
19
+ * * `coords` - Flat control points [x,y,z, x,y,z, ...]. For closed curves the
20
+ * first point must NOT be repeated at the end.
21
+ * * `closed` - When true, builds a periodic (C^{degree-1}) closed loop;
22
+ * otherwise a clamped curve interpolating the first/last control points.
23
+ *
24
+ * Returns the encoded curve [degree, num_cp, cp_xyz..., weights..., knots...]
25
+ * (the same format consumed by `sample_nurbs_curve` / `evaluate_nurbs_curve_at`),
26
+ * or an empty buffer on failure.
27
+ */
28
+ export function build_nurbs_curve(degree: number, coords: Float64Array, closed: boolean): Float64Array;
29
+
15
30
  /**
16
31
  * Chamfer corners of a polyline by cutting each corner with a straight segment.
17
32
  * Input: flat coords [x1,y1,z1, ...], distance from corner to cut.
@@ -145,6 +160,23 @@ export function loft_nurbs_surface(data: Float64Array): Float64Array;
145
160
  */
146
161
  export function loft_polylines(polyline_data: Float64Array, _segments: number, with_caps: boolean): Float64Array;
147
162
 
163
+ /**
164
+ * Loft between raw profile polylines with kernel-managed compatibility
165
+ * (resampling to a common count, seam alignment, direction matching).
166
+ *
167
+ * # Parameters
168
+ * * `profile_data` - Flat array where each profile is prefixed by its point count:
169
+ * [count1, x1, y1, z1, ..., count2, x1, y1, z1, ...]
170
+ * * `closed` - Whether profiles are closed loops (input must NOT repeat the
171
+ * first point). Closed profiles loft into a tube, open profiles into a sheet.
172
+ * * `with_caps` - Cap the first/last profiles (closed profiles only) to produce
173
+ * a watertight solid ready for booleans.
174
+ *
175
+ * # Returns
176
+ * Mesh buffers for the lofted surface (empty on failure)
177
+ */
178
+ export function loft_profiles(profile_data: Float64Array, closed: boolean, with_caps: boolean): Float64Array;
179
+
148
180
  /**
149
181
  * Make multiple NURBS curves compatible (same knot vectors, same CP count).
150
182
  * Input: [curve_count, curve1_data..., curve2_data..., ...]
@@ -159,6 +191,16 @@ export function make_nurbs_curves_compatible(curves_data: Float64Array): Float64
159
191
  */
160
192
  export function mesh_apply_matrix(vertex_count: number, buffer: Float64Array, matrix: Float64Array): Float64Array;
161
193
 
194
+ /**
195
+ * Subtract all cutter meshes from the host in one WASM call.
196
+ *
197
+ * `packed` layout matches `mesh_boolean_union_all`; the FIRST mesh is the
198
+ * host and every following mesh is a cutter.
199
+ * `flags`: `""` or `"trustedInput"`.
200
+ * Returns a standard result mesh buffer, or an empty vector on failure.
201
+ */
202
+ export function mesh_boolean_difference_all(packed: Float64Array, flags: string): Float64Array;
203
+
162
204
  /**
163
205
  * Perform boolean intersection on two meshes
164
206
  */
@@ -236,6 +278,15 @@ export function mesh_boolean_subtraction(vertex_count_a: number, buffer_a: Float
236
278
  */
237
279
  export function mesh_boolean_union(vertex_count_a: number, buffer_a: Float64Array, vertex_count_b: number, buffer_b: Float64Array): Float64Array;
238
280
 
281
+ /**
282
+ * Union all meshes in the packed buffer into a single mesh in one WASM call.
283
+ *
284
+ * `packed` layout: `[meshCount, (bufferLen, [vertexCount, positions..., indices...])...]`.
285
+ * `flags`: `""` or `"trustedInput"`.
286
+ * Returns a standard result mesh buffer, or an empty vector on failure.
287
+ */
288
+ export function mesh_boolean_union_all(packed: Float64Array, flags: string): Float64Array;
289
+
239
290
  /**
240
291
  * Extract boundary (perimeter) edges from a mesh as polylines.
241
292
  * Returns polyline buffer: [num_polylines, n1, x,y,z,..., n2, x,y,z,...]
@@ -249,6 +300,19 @@ export function mesh_boundary_polylines(vertex_count: number, buffer: Float64Arr
249
300
  */
250
301
  export function mesh_build_coplanar_connected_face_groups(vertex_count: number, buffer: Float64Array): Float64Array;
251
302
 
303
+ /**
304
+ * Display-ready render buffers: creased (split) vertex normals plus feature
305
+ * edges, computed in one pass. Replaces THREE's toCreasedNormals +
306
+ * EdgesGeometry in app layers (orders of magnitude faster on large meshes).
307
+ *
308
+ * Output (f32-packed):
309
+ * [vertexCount, positions (vertexCount*3), normals (vertexCount*3),
310
+ * edgeSegmentCount, edgePositions (edgeSegmentCount*6)]
311
+ * Vertices are non-indexed in input triangle order, so raycast face indices
312
+ * against the source mesh stay valid.
313
+ */
314
+ export function mesh_build_render_buffers(vertex_count: number, buffer: Float64Array, crease_angle_deg: number): Float32Array;
315
+
252
316
  /**
253
317
  * Chamfer all edges of a primitive mesh (flat bevel)
254
318
  *
@@ -378,6 +442,15 @@ export function mesh_get_face_centroid(vertex_count: number, buffer: Float64Arra
378
442
  */
379
443
  export function mesh_get_face_normal(vertex_count: number, buffer: Float64Array, face_index: number): Float64Array;
380
444
 
445
+ /**
446
+ * Edge-connected smooth face group (dihedral angle below `max_angle_deg`).
447
+ * Output format: [count, isPlanar (0|1), tri0, tri1, ...]
448
+ * `isPlanar` is 1 when every triangle normal in the group aligns with the
449
+ * seed triangle's normal (i.e. the group is a flat face), 0 for curved
450
+ * regions such as cylinder walls or lofted patches.
451
+ */
452
+ export function mesh_get_smooth_face_group(vertex_count: number, buffer: Float64Array, face_index: number, max_angle_deg: number): Float64Array;
453
+
381
454
  /**
382
455
  * Get mesh statistics
383
456
  * Returns [vertex_count, face_count, edge_count]
@@ -664,6 +737,7 @@ export interface InitOutput {
664
737
  readonly memory: WebAssembly.Memory;
665
738
  readonly arc_length: (a: number, b: number, c: number) => number;
666
739
  readonly arc_point_at: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number];
740
+ readonly build_nurbs_curve: (a: number, b: number, c: number, d: number) => [number, number];
667
741
  readonly chamfer_polycurve: (a: number, b: number, c: number) => [number, number];
668
742
  readonly circle_length: (a: number) => number;
669
743
  readonly circle_point_at: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
@@ -684,8 +758,10 @@ export interface InitOutput {
684
758
  readonly loft_circles: (a: number, b: number, c: number, d: number) => [number, number];
685
759
  readonly loft_nurbs_surface: (a: number, b: number) => [number, number];
686
760
  readonly loft_polylines: (a: number, b: number, c: number, d: number) => [number, number];
761
+ readonly loft_profiles: (a: number, b: number, c: number, d: number) => [number, number];
687
762
  readonly make_nurbs_curves_compatible: (a: number, b: number) => [number, number];
688
763
  readonly mesh_apply_matrix: (a: number, b: number, c: number, d: number, e: number) => [number, number];
764
+ readonly mesh_boolean_difference_all: (a: number, b: number, c: number, d: number) => [number, number];
689
765
  readonly mesh_boolean_intersection: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
690
766
  readonly mesh_boolean_kernel_mesh_debug: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
691
767
  readonly mesh_boolean_last_debug_marker: () => number;
@@ -710,8 +786,10 @@ export interface InitOutput {
710
786
  readonly mesh_boolean_split: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
711
787
  readonly mesh_boolean_subtraction: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
712
788
  readonly mesh_boolean_union: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
789
+ readonly mesh_boolean_union_all: (a: number, b: number, c: number, d: number) => [number, number];
713
790
  readonly mesh_boundary_polylines: (a: number, b: number, c: number) => [number, number];
714
791
  readonly mesh_build_coplanar_connected_face_groups: (a: number, b: number, c: number) => [number, number];
792
+ readonly mesh_build_render_buffers: (a: number, b: number, c: number, d: number) => [number, number];
715
793
  readonly mesh_chamfer_all_edges: (a: number, b: number, c: number, d: number, e: number) => [number, number];
716
794
  readonly mesh_compute_planar_curve_normal: (a: number, b: number, c: number) => [number, number];
717
795
  readonly mesh_contains_point: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
@@ -734,6 +812,7 @@ export interface InitOutput {
734
812
  readonly mesh_get_face_area: (a: number, b: number, c: number, d: number) => number;
735
813
  readonly mesh_get_face_centroid: (a: number, b: number, c: number, d: number) => [number, number];
736
814
  readonly mesh_get_face_normal: (a: number, b: number, c: number, d: number) => [number, number];
815
+ readonly mesh_get_smooth_face_group: (a: number, b: number, c: number, d: number, e: number) => [number, number];
737
816
  readonly mesh_get_stats: (a: number, b: number, c: number) => [number, number];
738
817
  readonly mesh_import_obj: (a: number, b: number) => [number, number];
739
818
  readonly mesh_is_closed_volume: (a: number, b: number, c: number) => number;
@@ -34,6 +34,32 @@ export function arc_point_at(cx, cy, cz, nx, ny, nz, radius, start_angle, end_an
34
34
  return v1;
35
35
  }
36
36
 
37
+ /**
38
+ * Build a NURBS curve from raw control points with kernel-managed knots and weights.
39
+ *
40
+ * * `degree` - Requested degree (clamped to the valid range for the point count)
41
+ * * `coords` - Flat control points [x,y,z, x,y,z, ...]. For closed curves the
42
+ * first point must NOT be repeated at the end.
43
+ * * `closed` - When true, builds a periodic (C^{degree-1}) closed loop;
44
+ * otherwise a clamped curve interpolating the first/last control points.
45
+ *
46
+ * Returns the encoded curve [degree, num_cp, cp_xyz..., weights..., knots...]
47
+ * (the same format consumed by `sample_nurbs_curve` / `evaluate_nurbs_curve_at`),
48
+ * or an empty buffer on failure.
49
+ * @param {number} degree
50
+ * @param {Float64Array} coords
51
+ * @param {boolean} closed
52
+ * @returns {Float64Array}
53
+ */
54
+ export function build_nurbs_curve(degree, coords, closed) {
55
+ const ptr0 = passArrayF64ToWasm0(coords, wasm.__wbindgen_malloc);
56
+ const len0 = WASM_VECTOR_LEN;
57
+ const ret = wasm.build_nurbs_curve(degree, ptr0, len0, closed);
58
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
59
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
60
+ return v2;
61
+ }
62
+
37
63
  /**
38
64
  * Chamfer corners of a polyline by cutting each corner with a straight segment.
39
65
  * Input: flat coords [x1,y1,z1, ...], distance from corner to cut.
@@ -415,6 +441,34 @@ export function loft_polylines(polyline_data, _segments, with_caps) {
415
441
  return v2;
416
442
  }
417
443
 
444
+ /**
445
+ * Loft between raw profile polylines with kernel-managed compatibility
446
+ * (resampling to a common count, seam alignment, direction matching).
447
+ *
448
+ * # Parameters
449
+ * * `profile_data` - Flat array where each profile is prefixed by its point count:
450
+ * [count1, x1, y1, z1, ..., count2, x1, y1, z1, ...]
451
+ * * `closed` - Whether profiles are closed loops (input must NOT repeat the
452
+ * first point). Closed profiles loft into a tube, open profiles into a sheet.
453
+ * * `with_caps` - Cap the first/last profiles (closed profiles only) to produce
454
+ * a watertight solid ready for booleans.
455
+ *
456
+ * # Returns
457
+ * Mesh buffers for the lofted surface (empty on failure)
458
+ * @param {Float64Array} profile_data
459
+ * @param {boolean} closed
460
+ * @param {boolean} with_caps
461
+ * @returns {Float64Array}
462
+ */
463
+ export function loft_profiles(profile_data, closed, with_caps) {
464
+ const ptr0 = passArrayF64ToWasm0(profile_data, wasm.__wbindgen_malloc);
465
+ const len0 = WASM_VECTOR_LEN;
466
+ const ret = wasm.loft_profiles(ptr0, len0, closed, with_caps);
467
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
468
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
469
+ return v2;
470
+ }
471
+
418
472
  /**
419
473
  * Make multiple NURBS curves compatible (same knot vectors, same CP count).
420
474
  * Input: [curve_count, curve1_data..., curve2_data..., ...]
@@ -451,6 +505,28 @@ export function mesh_apply_matrix(vertex_count, buffer, matrix) {
451
505
  return v3;
452
506
  }
453
507
 
508
+ /**
509
+ * Subtract all cutter meshes from the host in one WASM call.
510
+ *
511
+ * `packed` layout matches `mesh_boolean_union_all`; the FIRST mesh is the
512
+ * host and every following mesh is a cutter.
513
+ * `flags`: `""` or `"trustedInput"`.
514
+ * Returns a standard result mesh buffer, or an empty vector on failure.
515
+ * @param {Float64Array} packed
516
+ * @param {string} flags
517
+ * @returns {Float64Array}
518
+ */
519
+ export function mesh_boolean_difference_all(packed, flags) {
520
+ const ptr0 = passArrayF64ToWasm0(packed, wasm.__wbindgen_malloc);
521
+ const len0 = WASM_VECTOR_LEN;
522
+ const ptr1 = passStringToWasm0(flags, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
523
+ const len1 = WASM_VECTOR_LEN;
524
+ const ret = wasm.mesh_boolean_difference_all(ptr0, len0, ptr1, len1);
525
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
526
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
527
+ return v3;
528
+ }
529
+
454
530
  /**
455
531
  * Perform boolean intersection on two meshes
456
532
  * @param {number} vertex_count_a
@@ -1051,6 +1127,27 @@ export function mesh_boolean_union(vertex_count_a, buffer_a, vertex_count_b, buf
1051
1127
  return v3;
1052
1128
  }
1053
1129
 
1130
+ /**
1131
+ * Union all meshes in the packed buffer into a single mesh in one WASM call.
1132
+ *
1133
+ * `packed` layout: `[meshCount, (bufferLen, [vertexCount, positions..., indices...])...]`.
1134
+ * `flags`: `""` or `"trustedInput"`.
1135
+ * Returns a standard result mesh buffer, or an empty vector on failure.
1136
+ * @param {Float64Array} packed
1137
+ * @param {string} flags
1138
+ * @returns {Float64Array}
1139
+ */
1140
+ export function mesh_boolean_union_all(packed, flags) {
1141
+ const ptr0 = passArrayF64ToWasm0(packed, wasm.__wbindgen_malloc);
1142
+ const len0 = WASM_VECTOR_LEN;
1143
+ const ptr1 = passStringToWasm0(flags, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1144
+ const len1 = WASM_VECTOR_LEN;
1145
+ const ret = wasm.mesh_boolean_union_all(ptr0, len0, ptr1, len1);
1146
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1147
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1148
+ return v3;
1149
+ }
1150
+
1054
1151
  /**
1055
1152
  * Extract boundary (perimeter) edges from a mesh as polylines.
1056
1153
  * Returns polyline buffer: [num_polylines, n1, x,y,z,..., n2, x,y,z,...]
@@ -1084,6 +1181,30 @@ export function mesh_build_coplanar_connected_face_groups(vertex_count, buffer)
1084
1181
  return v2;
1085
1182
  }
1086
1183
 
1184
+ /**
1185
+ * Display-ready render buffers: creased (split) vertex normals plus feature
1186
+ * edges, computed in one pass. Replaces THREE's toCreasedNormals +
1187
+ * EdgesGeometry in app layers (orders of magnitude faster on large meshes).
1188
+ *
1189
+ * Output (f32-packed):
1190
+ * [vertexCount, positions (vertexCount*3), normals (vertexCount*3),
1191
+ * edgeSegmentCount, edgePositions (edgeSegmentCount*6)]
1192
+ * Vertices are non-indexed in input triangle order, so raycast face indices
1193
+ * against the source mesh stay valid.
1194
+ * @param {number} vertex_count
1195
+ * @param {Float64Array} buffer
1196
+ * @param {number} crease_angle_deg
1197
+ * @returns {Float32Array}
1198
+ */
1199
+ export function mesh_build_render_buffers(vertex_count, buffer, crease_angle_deg) {
1200
+ const ptr0 = passArrayF64ToWasm0(buffer, wasm.__wbindgen_malloc);
1201
+ const len0 = WASM_VECTOR_LEN;
1202
+ const ret = wasm.mesh_build_render_buffers(vertex_count, ptr0, len0, crease_angle_deg);
1203
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
1204
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1205
+ return v2;
1206
+ }
1207
+
1087
1208
  /**
1088
1209
  * Chamfer all edges of a primitive mesh (flat bevel)
1089
1210
  *
@@ -1469,6 +1590,27 @@ export function mesh_get_face_normal(vertex_count, buffer, face_index) {
1469
1590
  return v2;
1470
1591
  }
1471
1592
 
1593
+ /**
1594
+ * Edge-connected smooth face group (dihedral angle below `max_angle_deg`).
1595
+ * Output format: [count, isPlanar (0|1), tri0, tri1, ...]
1596
+ * `isPlanar` is 1 when every triangle normal in the group aligns with the
1597
+ * seed triangle's normal (i.e. the group is a flat face), 0 for curved
1598
+ * regions such as cylinder walls or lofted patches.
1599
+ * @param {number} vertex_count
1600
+ * @param {Float64Array} buffer
1601
+ * @param {number} face_index
1602
+ * @param {number} max_angle_deg
1603
+ * @returns {Float64Array}
1604
+ */
1605
+ export function mesh_get_smooth_face_group(vertex_count, buffer, face_index, max_angle_deg) {
1606
+ const ptr0 = passArrayF64ToWasm0(buffer, wasm.__wbindgen_malloc);
1607
+ const len0 = WASM_VECTOR_LEN;
1608
+ const ret = wasm.mesh_get_smooth_face_group(vertex_count, ptr0, len0, face_index, max_angle_deg);
1609
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1610
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1611
+ return v2;
1612
+ }
1613
+
1472
1614
  /**
1473
1615
  * Get mesh statistics
1474
1616
  * Returns [vertex_count, face_count, edge_count]
@@ -2386,11 +2528,24 @@ function __wbg_get_imports() {
2386
2528
  };
2387
2529
  }
2388
2530
 
2531
+ function getArrayF32FromWasm0(ptr, len) {
2532
+ ptr = ptr >>> 0;
2533
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
2534
+ }
2535
+
2389
2536
  function getArrayF64FromWasm0(ptr, len) {
2390
2537
  ptr = ptr >>> 0;
2391
2538
  return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
2392
2539
  }
2393
2540
 
2541
+ let cachedFloat32ArrayMemory0 = null;
2542
+ function getFloat32ArrayMemory0() {
2543
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
2544
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
2545
+ }
2546
+ return cachedFloat32ArrayMemory0;
2547
+ }
2548
+
2394
2549
  let cachedFloat64ArrayMemory0 = null;
2395
2550
  function getFloat64ArrayMemory0() {
2396
2551
  if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
@@ -2489,6 +2644,7 @@ let wasmModule, wasm;
2489
2644
  function __wbg_finalize_init(instance, module) {
2490
2645
  wasm = instance.exports;
2491
2646
  wasmModule = module;
2647
+ cachedFloat32ArrayMemory0 = null;
2492
2648
  cachedFloat64ArrayMemory0 = null;
2493
2649
  cachedUint8ArrayMemory0 = null;
2494
2650
  wasm.__wbindgen_start();