okgeometry-api 1.2.1 → 1.4.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..., ...]
@@ -249,6 +281,19 @@ export function mesh_boundary_polylines(vertex_count: number, buffer: Float64Arr
249
281
  */
250
282
  export function mesh_build_coplanar_connected_face_groups(vertex_count: number, buffer: Float64Array): Float64Array;
251
283
 
284
+ /**
285
+ * Display-ready render buffers: creased (split) vertex normals plus feature
286
+ * edges, computed in one pass. Replaces THREE's toCreasedNormals +
287
+ * EdgesGeometry in app layers (orders of magnitude faster on large meshes).
288
+ *
289
+ * Output (f32-packed):
290
+ * [vertexCount, positions (vertexCount*3), normals (vertexCount*3),
291
+ * edgeSegmentCount, edgePositions (edgeSegmentCount*6)]
292
+ * Vertices are non-indexed in input triangle order, so raycast face indices
293
+ * against the source mesh stay valid.
294
+ */
295
+ export function mesh_build_render_buffers(vertex_count: number, buffer: Float64Array, crease_angle_deg: number): Float32Array;
296
+
252
297
  /**
253
298
  * Chamfer all edges of a primitive mesh (flat bevel)
254
299
  *
@@ -378,6 +423,15 @@ export function mesh_get_face_centroid(vertex_count: number, buffer: Float64Arra
378
423
  */
379
424
  export function mesh_get_face_normal(vertex_count: number, buffer: Float64Array, face_index: number): Float64Array;
380
425
 
426
+ /**
427
+ * Edge-connected smooth face group (dihedral angle below `max_angle_deg`).
428
+ * Output format: [count, isPlanar (0|1), tri0, tri1, ...]
429
+ * `isPlanar` is 1 when every triangle normal in the group aligns with the
430
+ * seed triangle's normal (i.e. the group is a flat face), 0 for curved
431
+ * regions such as cylinder walls or lofted patches.
432
+ */
433
+ export function mesh_get_smooth_face_group(vertex_count: number, buffer: Float64Array, face_index: number, max_angle_deg: number): Float64Array;
434
+
381
435
  /**
382
436
  * Get mesh statistics
383
437
  * Returns [vertex_count, face_count, edge_count]
@@ -664,6 +718,7 @@ export interface InitOutput {
664
718
  readonly memory: WebAssembly.Memory;
665
719
  readonly arc_length: (a: number, b: number, c: number) => number;
666
720
  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];
721
+ readonly build_nurbs_curve: (a: number, b: number, c: number, d: number) => [number, number];
667
722
  readonly chamfer_polycurve: (a: number, b: number, c: number) => [number, number];
668
723
  readonly circle_length: (a: number) => number;
669
724
  readonly circle_point_at: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number];
@@ -684,6 +739,7 @@ export interface InitOutput {
684
739
  readonly loft_circles: (a: number, b: number, c: number, d: number) => [number, number];
685
740
  readonly loft_nurbs_surface: (a: number, b: number) => [number, number];
686
741
  readonly loft_polylines: (a: number, b: number, c: number, d: number) => [number, number];
742
+ readonly loft_profiles: (a: number, b: number, c: number, d: number) => [number, number];
687
743
  readonly make_nurbs_curves_compatible: (a: number, b: number) => [number, number];
688
744
  readonly mesh_apply_matrix: (a: number, b: number, c: number, d: number, e: number) => [number, number];
689
745
  readonly mesh_boolean_intersection: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
@@ -712,6 +768,7 @@ export interface InitOutput {
712
768
  readonly mesh_boolean_union: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
713
769
  readonly mesh_boundary_polylines: (a: number, b: number, c: number) => [number, number];
714
770
  readonly mesh_build_coplanar_connected_face_groups: (a: number, b: number, c: number) => [number, number];
771
+ readonly mesh_build_render_buffers: (a: number, b: number, c: number, d: number) => [number, number];
715
772
  readonly mesh_chamfer_all_edges: (a: number, b: number, c: number, d: number, e: number) => [number, number];
716
773
  readonly mesh_compute_planar_curve_normal: (a: number, b: number, c: number) => [number, number];
717
774
  readonly mesh_contains_point: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
@@ -734,6 +791,7 @@ export interface InitOutput {
734
791
  readonly mesh_get_face_area: (a: number, b: number, c: number, d: number) => number;
735
792
  readonly mesh_get_face_centroid: (a: number, b: number, c: number, d: number) => [number, number];
736
793
  readonly mesh_get_face_normal: (a: number, b: number, c: number, d: number) => [number, number];
794
+ readonly mesh_get_smooth_face_group: (a: number, b: number, c: number, d: number, e: number) => [number, number];
737
795
  readonly mesh_get_stats: (a: number, b: number, c: number) => [number, number];
738
796
  readonly mesh_import_obj: (a: number, b: number) => [number, number];
739
797
  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..., ...]
@@ -1084,6 +1138,30 @@ export function mesh_build_coplanar_connected_face_groups(vertex_count, buffer)
1084
1138
  return v2;
1085
1139
  }
1086
1140
 
1141
+ /**
1142
+ * Display-ready render buffers: creased (split) vertex normals plus feature
1143
+ * edges, computed in one pass. Replaces THREE's toCreasedNormals +
1144
+ * EdgesGeometry in app layers (orders of magnitude faster on large meshes).
1145
+ *
1146
+ * Output (f32-packed):
1147
+ * [vertexCount, positions (vertexCount*3), normals (vertexCount*3),
1148
+ * edgeSegmentCount, edgePositions (edgeSegmentCount*6)]
1149
+ * Vertices are non-indexed in input triangle order, so raycast face indices
1150
+ * against the source mesh stay valid.
1151
+ * @param {number} vertex_count
1152
+ * @param {Float64Array} buffer
1153
+ * @param {number} crease_angle_deg
1154
+ * @returns {Float32Array}
1155
+ */
1156
+ export function mesh_build_render_buffers(vertex_count, buffer, crease_angle_deg) {
1157
+ const ptr0 = passArrayF64ToWasm0(buffer, wasm.__wbindgen_malloc);
1158
+ const len0 = WASM_VECTOR_LEN;
1159
+ const ret = wasm.mesh_build_render_buffers(vertex_count, ptr0, len0, crease_angle_deg);
1160
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
1161
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1162
+ return v2;
1163
+ }
1164
+
1087
1165
  /**
1088
1166
  * Chamfer all edges of a primitive mesh (flat bevel)
1089
1167
  *
@@ -1469,6 +1547,27 @@ export function mesh_get_face_normal(vertex_count, buffer, face_index) {
1469
1547
  return v2;
1470
1548
  }
1471
1549
 
1550
+ /**
1551
+ * Edge-connected smooth face group (dihedral angle below `max_angle_deg`).
1552
+ * Output format: [count, isPlanar (0|1), tri0, tri1, ...]
1553
+ * `isPlanar` is 1 when every triangle normal in the group aligns with the
1554
+ * seed triangle's normal (i.e. the group is a flat face), 0 for curved
1555
+ * regions such as cylinder walls or lofted patches.
1556
+ * @param {number} vertex_count
1557
+ * @param {Float64Array} buffer
1558
+ * @param {number} face_index
1559
+ * @param {number} max_angle_deg
1560
+ * @returns {Float64Array}
1561
+ */
1562
+ export function mesh_get_smooth_face_group(vertex_count, buffer, face_index, max_angle_deg) {
1563
+ const ptr0 = passArrayF64ToWasm0(buffer, wasm.__wbindgen_malloc);
1564
+ const len0 = WASM_VECTOR_LEN;
1565
+ const ret = wasm.mesh_get_smooth_face_group(vertex_count, ptr0, len0, face_index, max_angle_deg);
1566
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1567
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1568
+ return v2;
1569
+ }
1570
+
1472
1571
  /**
1473
1572
  * Get mesh statistics
1474
1573
  * Returns [vertex_count, face_count, edge_count]
@@ -2386,11 +2485,24 @@ function __wbg_get_imports() {
2386
2485
  };
2387
2486
  }
2388
2487
 
2488
+ function getArrayF32FromWasm0(ptr, len) {
2489
+ ptr = ptr >>> 0;
2490
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
2491
+ }
2492
+
2389
2493
  function getArrayF64FromWasm0(ptr, len) {
2390
2494
  ptr = ptr >>> 0;
2391
2495
  return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
2392
2496
  }
2393
2497
 
2498
+ let cachedFloat32ArrayMemory0 = null;
2499
+ function getFloat32ArrayMemory0() {
2500
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
2501
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
2502
+ }
2503
+ return cachedFloat32ArrayMemory0;
2504
+ }
2505
+
2394
2506
  let cachedFloat64ArrayMemory0 = null;
2395
2507
  function getFloat64ArrayMemory0() {
2396
2508
  if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
@@ -2489,6 +2601,7 @@ let wasmModule, wasm;
2489
2601
  function __wbg_finalize_init(instance, module) {
2490
2602
  wasm = instance.exports;
2491
2603
  wasmModule = module;
2604
+ cachedFloat32ArrayMemory0 = null;
2492
2605
  cachedFloat64ArrayMemory0 = null;
2493
2606
  cachedUint8ArrayMemory0 = null;
2494
2607
  wasm.__wbindgen_start();