okgeometry-api 1.21.0 → 1.23.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.
- package/dist/Brep.d.ts +11 -0
- package/dist/Brep.d.ts.map +1 -1
- package/dist/Brep.js +21 -0
- package/dist/Brep.js.map +1 -1
- package/dist/Mesh.d.ts +15 -0
- package/dist/Mesh.d.ts.map +1 -1
- package/dist/Mesh.js +31 -0
- package/dist/Mesh.js.map +1 -1
- package/dist/NurbsCurve.d.ts +13 -11
- package/dist/NurbsCurve.d.ts.map +1 -1
- package/dist/NurbsCurve.js +22 -19
- package/dist/NurbsCurve.js.map +1 -1
- package/dist/NurbsSurface.d.ts +12 -0
- package/dist/NurbsSurface.d.ts.map +1 -1
- package/dist/NurbsSurface.js +17 -0
- package/dist/NurbsSurface.js.map +1 -1
- package/dist/Polyline.d.ts +11 -0
- package/dist/Polyline.d.ts.map +1 -1
- package/dist/Polyline.js +41 -0
- package/dist/Polyline.js.map +1 -1
- package/dist/wasm-base64.d.ts +1 -1
- package/dist/wasm-base64.d.ts.map +1 -1
- package/dist/wasm-base64.js +1 -1
- package/dist/wasm-base64.js.map +1 -1
- package/dist/wasm-bindings.d.ts +70 -0
- package/dist/wasm-bindings.d.ts.map +1 -1
- package/dist/wasm-bindings.js +121 -0
- package/dist/wasm-bindings.js.map +1 -1
- package/package.json +3 -2
- package/src/Brep.ts +24 -0
- package/src/Mesh.ts +37 -0
- package/src/NurbsCurve.ts +35 -26
- package/src/NurbsSurface.ts +20 -0
- package/src/Polyline.ts +45 -0
- package/src/wasm-base64.ts +1 -1
- package/src/wasm-bindings.d.ts +56 -0
- package/src/wasm-bindings.js +126 -0
package/src/Brep.ts
CHANGED
|
@@ -485,6 +485,30 @@ export class Brep {
|
|
|
485
485
|
);
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
+
/**
|
|
489
|
+
* Wireframe of the whole BREP in ONE WASM crossing: per face, `uCount`
|
|
490
|
+
* curves running along u plus `vCount` along v, at evenly spaced INTERIOR
|
|
491
|
+
* normalized parameters (i+1)/(count+1), each clipped to that face's
|
|
492
|
+
* trimmed region. The body JSON is parsed once for the entire sweep, so
|
|
493
|
+
* this scales to large face counts where per-face
|
|
494
|
+
* {@link faceIsoCurvesTrimmedNormalized} calls would re-parse the body
|
|
495
|
+
* repeatedly. Boundary parameters are excluded (they coincide with the
|
|
496
|
+
* BREP's edges); faces that fail to evaluate are skipped atomically.
|
|
497
|
+
*/
|
|
498
|
+
wireframeCurves(uCount: number, vCount: number): NurbsCurve[] {
|
|
499
|
+
ensureInit();
|
|
500
|
+
const buf = wasm.brep_wireframe_curves(this.json, uCount, vCount);
|
|
501
|
+
// An empty buffer (not even a zero count header) means the call failed
|
|
502
|
+
// outright, e.g. unparseable JSON — surface the reason instead of
|
|
503
|
+
// pretending the wireframe is empty.
|
|
504
|
+
if (buf.length < 1) {
|
|
505
|
+
throw new Error(
|
|
506
|
+
`Brep.wireframeCurves() failed: ${wasm.geometry_last_error() || "unknown error"}`,
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
return Brep.parseCurveList(buf);
|
|
510
|
+
}
|
|
511
|
+
|
|
488
512
|
/** Parse [count, (bufLen, curveData…)·count] into NurbsCurves. */
|
|
489
513
|
private static parseCurveList(buf: Float64Array): NurbsCurve[] {
|
|
490
514
|
if (buf.length < 1) return [];
|
package/src/Mesh.ts
CHANGED
|
@@ -3809,6 +3809,43 @@ export class Mesh {
|
|
|
3809
3809
|
return wasm.mesh_boundary_edge_segments(this._vertexCount, this._buffer);
|
|
3810
3810
|
}
|
|
3811
3811
|
|
|
3812
|
+
/**
|
|
3813
|
+
* Chamfer feature edges of this closed solid. Each entry in `edges` is one
|
|
3814
|
+
* picked segment `{ a, b }` on a feature edge; the kernel expands it to the
|
|
3815
|
+
* full chain separating the same two smooth face groups (a straight box
|
|
3816
|
+
* edge, or a whole tessellated rim loop from a single pick). `distance` is
|
|
3817
|
+
* the setback along each adjacent face, Rhino-style. Convex edges cut a
|
|
3818
|
+
* flat; concave edges fill the notch. The result is watertight.
|
|
3819
|
+
*
|
|
3820
|
+
* Throws for open meshes, smooth (non-feature) picks, or when the distance
|
|
3821
|
+
* exceeds what the adjacent faces allow.
|
|
3822
|
+
*/
|
|
3823
|
+
chamferEdges(
|
|
3824
|
+
edges: Array<{ a: Point | Vec3; b: Point | Vec3 }>,
|
|
3825
|
+
distance: number,
|
|
3826
|
+
): Mesh {
|
|
3827
|
+
ensureInit();
|
|
3828
|
+
if (edges.length === 0) {
|
|
3829
|
+
throw new Error("Mesh.chamferEdges() requires at least one edge");
|
|
3830
|
+
}
|
|
3831
|
+
const edgeBuf = new Float64Array(edges.length * 6);
|
|
3832
|
+
edges.forEach((edge, i) => {
|
|
3833
|
+
edgeBuf[i * 6] = edge.a.x;
|
|
3834
|
+
edgeBuf[i * 6 + 1] = edge.a.y;
|
|
3835
|
+
edgeBuf[i * 6 + 2] = edge.a.z;
|
|
3836
|
+
edgeBuf[i * 6 + 3] = edge.b.x;
|
|
3837
|
+
edgeBuf[i * 6 + 4] = edge.b.y;
|
|
3838
|
+
edgeBuf[i * 6 + 5] = edge.b.z;
|
|
3839
|
+
});
|
|
3840
|
+
const r = wasm.mesh_chamfer_edges(this._vertexCount, this._buffer, edgeBuf, distance);
|
|
3841
|
+
if (!r.length) {
|
|
3842
|
+
throw new Error(
|
|
3843
|
+
`Mesh.chamferEdges() failed: ${wasm.geometry_last_error() || "unknown error"}`,
|
|
3844
|
+
);
|
|
3845
|
+
}
|
|
3846
|
+
return Mesh.fromTrustedBuffer(r as Float64Array);
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3812
3849
|
/**
|
|
3813
3850
|
* Geometry-preserving repair: weld coincident vertices, drop degenerate /
|
|
3814
3851
|
* duplicate triangles, remove orphan vertices, make winding consistent +
|
package/src/NurbsCurve.ts
CHANGED
|
@@ -394,32 +394,9 @@ export class NurbsCurve {
|
|
|
394
394
|
);
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
* @param distance - Offset distance
|
|
401
|
-
* @param normal - Reference normal for determining offset direction
|
|
402
|
-
* @param samples - Number of sample points (default 64)
|
|
403
|
-
* @param arcSamples - Number of samples per exact arc segment in the returned polyline(s)
|
|
404
|
-
* @param options - Offset options such as join style
|
|
405
|
-
* @returns Offset polyline approximation
|
|
406
|
-
*/
|
|
407
|
-
offset(
|
|
408
|
-
distance: number,
|
|
409
|
-
normal?: Vec3,
|
|
410
|
-
samples = 64,
|
|
411
|
-
arcSamples = 32,
|
|
412
|
-
options: CurveOffsetOptions = {},
|
|
413
|
-
): Polyline {
|
|
414
|
-
const results = this.offsetAll(distance, normal, samples, arcSamples, options);
|
|
415
|
-
if (results.length === 1) return results[0];
|
|
416
|
-
if (results.length === 0) {
|
|
417
|
-
throw new Error("NurbsCurve.offset() collapsed and produced no valid result polylines");
|
|
418
|
-
}
|
|
419
|
-
throw new Error(
|
|
420
|
-
`NurbsCurve.offset() produced ${results.length} result polylines. Use NurbsCurve.offsetAll() instead.`,
|
|
421
|
-
);
|
|
422
|
-
}
|
|
397
|
+
// NOTE: `offset()` (exact NURBS offset, kernel-refit to tolerance) lives
|
|
398
|
+
// further down next to `data`. The former sampled-polyline `offset()` was
|
|
399
|
+
// replaced by it; the sampled multi-result path remains as `offsetAll()`.
|
|
423
400
|
|
|
424
401
|
/**
|
|
425
402
|
* Offset this curve by a distance and return every sampled result polyline.
|
|
@@ -566,6 +543,38 @@ export class NurbsCurve {
|
|
|
566
543
|
return NurbsCurve.fromData(buf);
|
|
567
544
|
}
|
|
568
545
|
|
|
546
|
+
/**
|
|
547
|
+
* Offset this planar curve by `distance` within the plane with the given
|
|
548
|
+
* `normal`. Positive distance offsets toward `normal × tangent` (the same
|
|
549
|
+
* convention as Polyline/PolyCurve offsets). The result is refit to
|
|
550
|
+
* `tolerance` (default 1e-6) against the exact offset locus; rational
|
|
551
|
+
* curves (exact arcs) offset exactly. Closed curves stay closed.
|
|
552
|
+
*
|
|
553
|
+
* Throws for non-planar or kinked curves, or when the offset cannot reach
|
|
554
|
+
* tolerance (for example offsetting inward past the curvature radius).
|
|
555
|
+
*/
|
|
556
|
+
offset(
|
|
557
|
+
distance: number,
|
|
558
|
+
normal: Vec3 = Vec3.Z,
|
|
559
|
+
options: { tolerance?: number } = {},
|
|
560
|
+
): NurbsCurve {
|
|
561
|
+
ensureInit();
|
|
562
|
+
const buf = wasm.nurbs_curve_offset(
|
|
563
|
+
this.data,
|
|
564
|
+
distance,
|
|
565
|
+
normal.x,
|
|
566
|
+
normal.y,
|
|
567
|
+
normal.z,
|
|
568
|
+
options.tolerance ?? 1e-6,
|
|
569
|
+
);
|
|
570
|
+
if (buf.length < 2) {
|
|
571
|
+
throw new Error(
|
|
572
|
+
`NurbsCurve.offset() failed: ${wasm.geometry_last_error() || "unknown error"}`,
|
|
573
|
+
);
|
|
574
|
+
}
|
|
575
|
+
return NurbsCurve.fromData(buf);
|
|
576
|
+
}
|
|
577
|
+
|
|
569
578
|
/**
|
|
570
579
|
* Get internal WASM data buffer.
|
|
571
580
|
* For advanced use cases requiring direct WASM interop.
|
package/src/NurbsSurface.ts
CHANGED
|
@@ -312,6 +312,26 @@ export class NurbsSurface implements Surface {
|
|
|
312
312
|
return this._data;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Offset this surface by `distance` along its oriented normal field,
|
|
317
|
+
* refit to `tolerance` (default 1e-4) against the exact offset. Rational
|
|
318
|
+
* surfaces (cylinders, spheres, revolves) offset exactly; closed seams
|
|
319
|
+
* stay closed and degenerate poles stay degenerate.
|
|
320
|
+
*
|
|
321
|
+
* Throws for creased surfaces or when the offset cannot reach tolerance
|
|
322
|
+
* (for example offsetting inward past the curvature radius).
|
|
323
|
+
*/
|
|
324
|
+
offset(distance: number, options: { tolerance?: number } = {}): NurbsSurface {
|
|
325
|
+
ensureInit();
|
|
326
|
+
const buf = wasm.nurbs_surface_offset(this.data, distance, options.tolerance ?? 1e-4);
|
|
327
|
+
if (buf.length < 4) {
|
|
328
|
+
throw new Error(
|
|
329
|
+
`NurbsSurface.offset() failed: ${wasm.geometry_last_error() || "unknown error"}`,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
return NurbsSurface.fromData(buf);
|
|
333
|
+
}
|
|
334
|
+
|
|
315
335
|
// ── Analytic queries ──
|
|
316
336
|
|
|
317
337
|
/**
|
package/src/Polyline.ts
CHANGED
|
@@ -240,6 +240,51 @@ export class Polyline {
|
|
|
240
240
|
return PolyCurve.fromSegmentData(buf);
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Chamfer corners of this polyline with straight cuts of the given
|
|
245
|
+
* setback distance (clamped per corner to half the shorter adjacent
|
|
246
|
+
* segment). Closed polylines (duplicated end point) chamfer every corner
|
|
247
|
+
* including the seam and stay closed; open polylines never touch their
|
|
248
|
+
* endpoints. `options.corners` selects vertex indices to chamfer
|
|
249
|
+
* (indices into the unique point list, seam duplicate excluded).
|
|
250
|
+
*/
|
|
251
|
+
chamfer(distance: number, options: { corners?: number[] } = {}): Polyline {
|
|
252
|
+
ensureInit();
|
|
253
|
+
const pts = this.points;
|
|
254
|
+
if (pts.length < 3) {
|
|
255
|
+
throw new Error("Polyline.chamfer() requires at least 3 points");
|
|
256
|
+
}
|
|
257
|
+
const first = pts[0];
|
|
258
|
+
const last = pts[pts.length - 1];
|
|
259
|
+
const closed =
|
|
260
|
+
pts.length >= 4 &&
|
|
261
|
+
Math.abs(first.x - last.x) < 1e-10 &&
|
|
262
|
+
Math.abs(first.y - last.y) < 1e-10 &&
|
|
263
|
+
Math.abs(first.z - last.z) < 1e-10;
|
|
264
|
+
const unique = closed ? pts.slice(0, -1) : pts;
|
|
265
|
+
const coords = new Float64Array(unique.length * 3);
|
|
266
|
+
unique.forEach((p, i) => {
|
|
267
|
+
coords[i * 3] = p.x;
|
|
268
|
+
coords[i * 3 + 1] = p.y;
|
|
269
|
+
coords[i * 3 + 2] = p.z;
|
|
270
|
+
});
|
|
271
|
+
const cornerBuf = new Float64Array(options.corners ?? []);
|
|
272
|
+
const buf = wasm.chamfer_polyline_corners(coords, closed, distance, cornerBuf);
|
|
273
|
+
if (buf.length < 6) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Polyline.chamfer() failed: ${wasm.geometry_last_error() || "unknown error"}`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
const out: Point[] = [];
|
|
279
|
+
for (let i = 0; i + 2 < buf.length; i += 3) {
|
|
280
|
+
out.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
|
|
281
|
+
}
|
|
282
|
+
if (closed && out.length > 0) {
|
|
283
|
+
out.push(out[0]);
|
|
284
|
+
}
|
|
285
|
+
return new Polyline(out);
|
|
286
|
+
}
|
|
287
|
+
|
|
243
288
|
/**
|
|
244
289
|
* Convert this polyline to a PolyCurve (line segments only).
|
|
245
290
|
* @returns PolyCurve with Line segments connecting consecutive points
|