okgeometry-api 1.26.1 → 1.27.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/Arc.js +1 -1
- package/dist/Arc.js.map +1 -1
- package/dist/Brep.js +1 -1
- package/dist/Brep.js.map +1 -1
- package/dist/Circle.js +1 -1
- package/dist/Circle.js.map +1 -1
- package/dist/Line.js +1 -1
- package/dist/Line.js.map +1 -1
- package/dist/Mesh.d.ts +41 -0
- package/dist/Mesh.d.ts.map +1 -1
- package/dist/Mesh.js +235 -21
- package/dist/Mesh.js.map +1 -1
- package/dist/MeshSurface.js +1 -1
- package/dist/MeshSurface.js.map +1 -1
- package/dist/NurbsCurve.js +1 -1
- package/dist/NurbsCurve.js.map +1 -1
- package/dist/NurbsSurface.js +1 -1
- package/dist/NurbsSurface.js.map +1 -1
- package/dist/PolyCurve.js +1 -1
- package/dist/PolyCurve.js.map +1 -1
- package/dist/Polyline.js +1 -1
- package/dist/Polyline.js.map +1 -1
- package/dist/Ray.js +1 -1
- package/dist/Ray.js.map +1 -1
- package/dist/SculptSession.js +1 -1
- package/dist/SculptSession.js.map +1 -1
- package/dist/engine-threaded.d.ts +2 -0
- package/dist/engine-threaded.d.ts.map +1 -0
- package/dist/engine-threaded.js +33 -0
- package/dist/engine-threaded.js.map +1 -0
- package/dist/engine.d.ts +21 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +42 -0
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mesh-boolean.pool.d.ts +23 -1
- package/dist/mesh-boolean.pool.d.ts.map +1 -1
- package/dist/mesh-boolean.pool.js +97 -12
- package/dist/mesh-boolean.pool.js.map +1 -1
- package/dist/mesh-boolean.protocol.d.ts +21 -1
- package/dist/mesh-boolean.protocol.d.ts.map +1 -1
- package/dist/mesh-boolean.protocol.js.map +1 -1
- package/dist/mesh-boolean.worker.d.ts.map +1 -1
- package/dist/mesh-boolean.worker.js +94 -1
- package/dist/mesh-boolean.worker.js.map +1 -1
- package/dist/wasm-active.d.ts +20 -0
- package/dist/wasm-active.d.ts.map +1 -0
- package/dist/wasm-active.js +26 -0
- package/dist/wasm-active.js.map +1 -0
- package/dist/wasm-base64-threaded.d.ts +2 -0
- package/dist/wasm-base64-threaded.d.ts.map +1 -0
- package/dist/wasm-base64-threaded.js +3 -0
- package/dist/wasm-base64-threaded.js.map +1 -0
- 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-threaded.d.ts +2664 -0
- package/dist/wasm-bindings-threaded.d.ts.map +1 -0
- package/dist/wasm-bindings-threaded.js +5008 -0
- package/dist/wasm-bindings-threaded.js.map +1 -0
- package/dist/wasm-bindings.d.ts +130 -0
- package/dist/wasm-bindings.d.ts.map +1 -1
- package/dist/wasm-bindings.js +208 -0
- package/dist/wasm-bindings.js.map +1 -1
- package/dist/workerHelpers-threaded.d.ts +2 -0
- package/dist/workerHelpers-threaded.d.ts.map +1 -0
- package/dist/workerHelpers-threaded.js +100 -0
- package/dist/workerHelpers-threaded.js.map +1 -0
- package/package.json +8 -3
- package/src/Arc.ts +117 -117
- package/src/Brep.ts +1 -1
- package/src/Circle.ts +166 -166
- package/src/Line.ts +171 -171
- package/src/Mesh.ts +300 -45
- package/src/MeshSurface.ts +1 -1
- package/src/NurbsCurve.ts +655 -655
- package/src/NurbsSurface.ts +721 -721
- package/src/PolyCurve.ts +203 -203
- package/src/Polyline.ts +316 -316
- package/src/Ray.ts +90 -90
- package/src/SculptSession.ts +377 -377
- package/src/engine-threaded.ts +39 -0
- package/src/engine.ts +46 -0
- package/src/index.ts +1 -1
- package/src/mesh-boolean.pool.ts +208 -86
- package/src/mesh-boolean.protocol.ts +44 -1
- package/src/mesh-boolean.worker.ts +170 -56
- package/src/wasm-active.ts +31 -0
- package/src/wasm-base64-threaded.ts +2 -0
- package/src/wasm-base64.ts +1 -1
- package/src/wasm-bindings-threaded.d.ts +1989 -0
- package/src/wasm-bindings-threaded.js +5235 -0
- package/src/wasm-bindings.d.ts +104 -0
- package/src/wasm-bindings.js +225 -0
- package/src/workerHelpers-threaded.js +107 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerHelpers-threaded.d.ts","sourceRoot":"","sources":["../src/workerHelpers-threaded.js"],"names":[],"mappings":"AAoEA,oFAsCC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Google Inc. All Rights Reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
* See the License for the specific language governing permissions and
|
|
11
|
+
* limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
// Note: we use `wasm_bindgen_worker_`-prefixed message types to make sure
|
|
14
|
+
// we can handle bundling into other files, which might happen to have their
|
|
15
|
+
// own `postMessage`/`onmessage` communication channels.
|
|
16
|
+
//
|
|
17
|
+
// If we didn't take that into the account, we could send much simpler signals
|
|
18
|
+
// like just `0` or whatever, but the code would be less resilient.
|
|
19
|
+
function waitForMsgType(target, type) {
|
|
20
|
+
return new Promise(resolve => {
|
|
21
|
+
target.addEventListener('message', function onMsg({ data }) {
|
|
22
|
+
if (data?.type !== type)
|
|
23
|
+
return;
|
|
24
|
+
target.removeEventListener('message', onMsg);
|
|
25
|
+
resolve(data);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
waitForMsgType(self, 'wasm_bindgen_worker_init').then(async ({ init, receiver }) => {
|
|
30
|
+
// # Note 1
|
|
31
|
+
// Our JS should have been generated in
|
|
32
|
+
// `[out-dir]/snippets/wasm-bindgen-rayon-[hash]/workerHelpers.js`,
|
|
33
|
+
// resolve the main module via `../../..`.
|
|
34
|
+
//
|
|
35
|
+
// This might need updating if the generated structure changes on wasm-bindgen
|
|
36
|
+
// side ever in the future, but works well with bundlers today. The whole
|
|
37
|
+
// point of this crate, after all, is to abstract away unstable features
|
|
38
|
+
// and temporary bugs so that you don't need to deal with them in your code.
|
|
39
|
+
//
|
|
40
|
+
// # Note 2
|
|
41
|
+
// This could be a regular import, but then some bundlers complain about
|
|
42
|
+
// circular deps.
|
|
43
|
+
//
|
|
44
|
+
// Dynamic import could be cheap if this file was inlined into the parent,
|
|
45
|
+
// which would require us just using `../../..` in `new Worker` below,
|
|
46
|
+
// but that doesn't work because wasm-pack unconditionally adds
|
|
47
|
+
// "sideEffects":false (see below).
|
|
48
|
+
//
|
|
49
|
+
// OTOH, even though it can't be inlined, it should be still reasonably
|
|
50
|
+
// cheap since the requested file is already in cache (it was loaded by
|
|
51
|
+
// the main thread).
|
|
52
|
+
const pkg = await import('./wasm-bindings-threaded.js');
|
|
53
|
+
await pkg.default(init);
|
|
54
|
+
postMessage({ type: 'wasm_bindgen_worker_ready' });
|
|
55
|
+
pkg.wbg_rayon_start_worker(receiver);
|
|
56
|
+
});
|
|
57
|
+
// Note: this is never used, but necessary to prevent a bug in Firefox
|
|
58
|
+
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1702191) where it collects
|
|
59
|
+
// Web Workers that have a shared WebAssembly memory with the main thread,
|
|
60
|
+
// but are not explicitly rooted via a `Worker` instance.
|
|
61
|
+
//
|
|
62
|
+
// By storing them in a variable, we can keep `Worker` objects around and
|
|
63
|
+
// prevent them from getting GC-d.
|
|
64
|
+
let _workers;
|
|
65
|
+
export async function startWorkers(module, memory, builder) {
|
|
66
|
+
if (builder.numThreads() === 0) {
|
|
67
|
+
throw new Error(`num_threads must be > 0.`);
|
|
68
|
+
}
|
|
69
|
+
const workerInit = {
|
|
70
|
+
type: 'wasm_bindgen_worker_init',
|
|
71
|
+
init: { module_or_path: module, memory },
|
|
72
|
+
receiver: builder.receiver()
|
|
73
|
+
};
|
|
74
|
+
_workers = await Promise.all(Array.from({ length: builder.numThreads() }, async () => {
|
|
75
|
+
// Self-spawn into a new Worker.
|
|
76
|
+
//
|
|
77
|
+
// TODO: while `new URL('...', import.meta.url) becomes a semi-standard
|
|
78
|
+
// way to get asset URLs relative to the module across various bundlers
|
|
79
|
+
// and browser, ideally we should switch to `import.meta.resolve`
|
|
80
|
+
// once it becomes a standard.
|
|
81
|
+
//
|
|
82
|
+
// Note: we could use `../../..` as the URL here to inline workerHelpers.js
|
|
83
|
+
// into the parent entry instead of creating another split point -
|
|
84
|
+
// this would be preferable from optimization perspective -
|
|
85
|
+
// however, Webpack then eliminates all message handler code
|
|
86
|
+
// because wasm-pack produces "sideEffects":false in package.json
|
|
87
|
+
// unconditionally.
|
|
88
|
+
//
|
|
89
|
+
// The only way to work around that is to have side effect code
|
|
90
|
+
// in an entry point such as Worker file itself.
|
|
91
|
+
const worker = new Worker(new URL('./workerHelpers-threaded.js', import.meta.url), {
|
|
92
|
+
type: 'module'
|
|
93
|
+
});
|
|
94
|
+
worker.postMessage(workerInit);
|
|
95
|
+
await waitForMsgType(worker, 'wasm_bindgen_worker_ready');
|
|
96
|
+
return worker;
|
|
97
|
+
}));
|
|
98
|
+
builder.build();
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=workerHelpers-threaded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workerHelpers-threaded.js","sourceRoot":"","sources":["../src/workerHelpers-threaded.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,0EAA0E;AAC1E,4EAA4E;AAC5E,wDAAwD;AACxD,E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"description": "Geometry engine API for AEC applications - NURBS, meshes, booleans, intersections. Powered by Rust/WASM.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,11 @@
|
|
|
36
36
|
"smoke:curve-region": "tsx scripts/smoke-curve-region.ts",
|
|
37
37
|
"smoke:sculpt": "tsx scripts/smoke-sculpt.ts",
|
|
38
38
|
"smoke:offset-chamfer": "tsx scripts/smoke-offset-chamfer.ts",
|
|
39
|
-
"smoke:rebuild": "tsx scripts/smoke-rebuild.ts"
|
|
39
|
+
"smoke:rebuild": "tsx scripts/smoke-rebuild.ts",
|
|
40
|
+
"smoke:mesh-residency": "tsx scripts/smoke-mesh-residency.ts",
|
|
41
|
+
"build:wasm-threaded": "node scripts/build-threaded.mjs",
|
|
42
|
+
"smoke:browser-threaded": "node scripts/browser-smoke-threaded.mjs",
|
|
43
|
+
"smoke:browser-heavy": "node scripts/browser-smoke-heavy-worker.mjs"
|
|
40
44
|
},
|
|
41
45
|
"keywords": [
|
|
42
46
|
"geometry",
|
|
@@ -56,6 +60,7 @@
|
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
58
62
|
"tsx": "^4.7.0",
|
|
59
|
-
"typescript": "^5.4.0"
|
|
63
|
+
"typescript": "^5.4.0",
|
|
64
|
+
"playwright": "^1.49.0"
|
|
60
65
|
}
|
|
61
66
|
}
|
package/src/Arc.ts
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import { ensureInit } from "./engine.js";
|
|
2
|
-
import { Point } from "./Point.js";
|
|
3
|
-
import { Vec3 } from "./Vec3.js";
|
|
4
|
-
import { Polyline } from "./Polyline.js";
|
|
5
|
-
import type { Plane } from "./Plane.js";
|
|
6
|
-
import type { RotationAxis } from "./types.js";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Immutable circular arc defined by center, radius, and angular span.
|
|
11
|
-
* Angles are in radians, measured counter-clockwise from the positive X axis
|
|
12
|
-
* in the plane defined by the normal.
|
|
13
|
-
*/
|
|
14
|
-
export class Arc {
|
|
15
|
-
/**
|
|
16
|
-
* Create a new arc.
|
|
17
|
-
* @param center - Center point
|
|
18
|
-
* @param radius - Arc radius
|
|
19
|
-
* @param startAngle - Start angle in radians
|
|
20
|
-
* @param endAngle - End angle in radians
|
|
21
|
-
* @param normal - Normal vector defining the arc's plane (default Z axis)
|
|
22
|
-
*/
|
|
23
|
-
constructor(
|
|
24
|
-
public readonly center: Point,
|
|
25
|
-
public readonly radius: number,
|
|
26
|
-
public readonly startAngle: number,
|
|
27
|
-
public readonly endAngle: number,
|
|
28
|
-
public readonly normal: Vec3 = Vec3.Z
|
|
29
|
-
) {}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Evaluate a point on the arc at normalized parameter t.
|
|
33
|
-
* @param t - Parameter in [0, 1] (0 = start angle, 1 = end angle)
|
|
34
|
-
* @returns Point on arc at parameter t
|
|
35
|
-
*/
|
|
36
|
-
pointAt(t: number): Point {
|
|
37
|
-
ensureInit();
|
|
38
|
-
const r = wasm.arc_point_at(
|
|
39
|
-
this.center.x, this.center.y, this.center.z,
|
|
40
|
-
this.normal.x, this.normal.y, this.normal.z,
|
|
41
|
-
this.radius, this.startAngle, this.endAngle, t
|
|
42
|
-
);
|
|
43
|
-
return new Point(r[0], r[1], r[2]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get the arc length.
|
|
48
|
-
* @returns Arc length = radius * angular span
|
|
49
|
-
*/
|
|
50
|
-
length(): number {
|
|
51
|
-
ensureInit();
|
|
52
|
-
return wasm.arc_length(this.radius, this.startAngle, this.endAngle);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Translate this arc by an offset vector.
|
|
57
|
-
* @param offset - Translation vector
|
|
58
|
-
* @returns New translated arc
|
|
59
|
-
*/
|
|
60
|
-
translate(offset: Vec3): Arc {
|
|
61
|
-
return new Arc(this.center.add(offset), this.radius, this.startAngle, this.endAngle, this.normal);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Rotate this arc around an axis.
|
|
66
|
-
* @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
|
|
67
|
-
* @param angle - Rotation angle in radians
|
|
68
|
-
* @returns New rotated arc
|
|
69
|
-
*/
|
|
70
|
-
rotate(axis: RotationAxis, angle: number): Arc {
|
|
71
|
-
const n = this.normal;
|
|
72
|
-
const dirAxis = 'start' in axis ? new Vec3(axis.end.x - axis.start.x, axis.end.y - axis.start.y, axis.end.z - axis.start.z) : axis;
|
|
73
|
-
const rn = new Point(n.x, n.y, n.z).rotate(dirAxis, angle);
|
|
74
|
-
return new Arc(this.center.rotate(axis, angle), this.radius, this.startAngle, this.endAngle, new Vec3(rn.x, rn.y, rn.z));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Offset this arc by changing its radius.
|
|
79
|
-
* @param distance - Distance to offset (positive = larger, negative = smaller)
|
|
80
|
-
* @returns New arc with adjusted radius
|
|
81
|
-
*/
|
|
82
|
-
offset(distance: number): Arc {
|
|
83
|
-
return new Arc(this.center, this.radius + distance, this.startAngle, this.endAngle, this.normal);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Project onto plane. Returns a Polyline because a tilted arc projects to an elliptical arc.
|
|
88
|
-
* @param plane - Target plane
|
|
89
|
-
* @param direction - Optional projection direction (default: perpendicular to plane)
|
|
90
|
-
* @param samples - Number of sample points for approximation (default 64)
|
|
91
|
-
* @returns Polyline approximating the projected arc
|
|
92
|
-
*/
|
|
93
|
-
projectOntoPlane(plane: Plane, direction?: Vec3, samples = 64): Polyline {
|
|
94
|
-
const pts = this.sample(samples);
|
|
95
|
-
const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
|
|
96
|
-
return new Polyline(pts.map(proj));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Sample the arc into evenly-spaced points.
|
|
101
|
-
* @param n - Number of points to generate
|
|
102
|
-
* @returns Array of n points along the arc
|
|
103
|
-
*/
|
|
104
|
-
sample(n: number): Point[] {
|
|
105
|
-
ensureInit();
|
|
106
|
-
const buf = wasm.create_arc(
|
|
107
|
-
this.center.x, this.center.y, this.center.z,
|
|
108
|
-
this.normal.x, this.normal.y, this.normal.z,
|
|
109
|
-
this.radius, this.startAngle, this.endAngle, n
|
|
110
|
-
);
|
|
111
|
-
const pts: Point[] = [];
|
|
112
|
-
for (let i = 0; i < buf.length; i += 3) {
|
|
113
|
-
pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
|
|
114
|
-
}
|
|
115
|
-
return pts;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import { Vec3 } from "./Vec3.js";
|
|
4
|
+
import { Polyline } from "./Polyline.js";
|
|
5
|
+
import type { Plane } from "./Plane.js";
|
|
6
|
+
import type { RotationAxis } from "./types.js";
|
|
7
|
+
import { wasm } from "./wasm-active.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Immutable circular arc defined by center, radius, and angular span.
|
|
11
|
+
* Angles are in radians, measured counter-clockwise from the positive X axis
|
|
12
|
+
* in the plane defined by the normal.
|
|
13
|
+
*/
|
|
14
|
+
export class Arc {
|
|
15
|
+
/**
|
|
16
|
+
* Create a new arc.
|
|
17
|
+
* @param center - Center point
|
|
18
|
+
* @param radius - Arc radius
|
|
19
|
+
* @param startAngle - Start angle in radians
|
|
20
|
+
* @param endAngle - End angle in radians
|
|
21
|
+
* @param normal - Normal vector defining the arc's plane (default Z axis)
|
|
22
|
+
*/
|
|
23
|
+
constructor(
|
|
24
|
+
public readonly center: Point,
|
|
25
|
+
public readonly radius: number,
|
|
26
|
+
public readonly startAngle: number,
|
|
27
|
+
public readonly endAngle: number,
|
|
28
|
+
public readonly normal: Vec3 = Vec3.Z
|
|
29
|
+
) {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Evaluate a point on the arc at normalized parameter t.
|
|
33
|
+
* @param t - Parameter in [0, 1] (0 = start angle, 1 = end angle)
|
|
34
|
+
* @returns Point on arc at parameter t
|
|
35
|
+
*/
|
|
36
|
+
pointAt(t: number): Point {
|
|
37
|
+
ensureInit();
|
|
38
|
+
const r = wasm.arc_point_at(
|
|
39
|
+
this.center.x, this.center.y, this.center.z,
|
|
40
|
+
this.normal.x, this.normal.y, this.normal.z,
|
|
41
|
+
this.radius, this.startAngle, this.endAngle, t
|
|
42
|
+
);
|
|
43
|
+
return new Point(r[0], r[1], r[2]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the arc length.
|
|
48
|
+
* @returns Arc length = radius * angular span
|
|
49
|
+
*/
|
|
50
|
+
length(): number {
|
|
51
|
+
ensureInit();
|
|
52
|
+
return wasm.arc_length(this.radius, this.startAngle, this.endAngle);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Translate this arc by an offset vector.
|
|
57
|
+
* @param offset - Translation vector
|
|
58
|
+
* @returns New translated arc
|
|
59
|
+
*/
|
|
60
|
+
translate(offset: Vec3): Arc {
|
|
61
|
+
return new Arc(this.center.add(offset), this.radius, this.startAngle, this.endAngle, this.normal);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Rotate this arc around an axis.
|
|
66
|
+
* @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
|
|
67
|
+
* @param angle - Rotation angle in radians
|
|
68
|
+
* @returns New rotated arc
|
|
69
|
+
*/
|
|
70
|
+
rotate(axis: RotationAxis, angle: number): Arc {
|
|
71
|
+
const n = this.normal;
|
|
72
|
+
const dirAxis = 'start' in axis ? new Vec3(axis.end.x - axis.start.x, axis.end.y - axis.start.y, axis.end.z - axis.start.z) : axis;
|
|
73
|
+
const rn = new Point(n.x, n.y, n.z).rotate(dirAxis, angle);
|
|
74
|
+
return new Arc(this.center.rotate(axis, angle), this.radius, this.startAngle, this.endAngle, new Vec3(rn.x, rn.y, rn.z));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Offset this arc by changing its radius.
|
|
79
|
+
* @param distance - Distance to offset (positive = larger, negative = smaller)
|
|
80
|
+
* @returns New arc with adjusted radius
|
|
81
|
+
*/
|
|
82
|
+
offset(distance: number): Arc {
|
|
83
|
+
return new Arc(this.center, this.radius + distance, this.startAngle, this.endAngle, this.normal);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Project onto plane. Returns a Polyline because a tilted arc projects to an elliptical arc.
|
|
88
|
+
* @param plane - Target plane
|
|
89
|
+
* @param direction - Optional projection direction (default: perpendicular to plane)
|
|
90
|
+
* @param samples - Number of sample points for approximation (default 64)
|
|
91
|
+
* @returns Polyline approximating the projected arc
|
|
92
|
+
*/
|
|
93
|
+
projectOntoPlane(plane: Plane, direction?: Vec3, samples = 64): Polyline {
|
|
94
|
+
const pts = this.sample(samples);
|
|
95
|
+
const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
|
|
96
|
+
return new Polyline(pts.map(proj));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Sample the arc into evenly-spaced points.
|
|
101
|
+
* @param n - Number of points to generate
|
|
102
|
+
* @returns Array of n points along the arc
|
|
103
|
+
*/
|
|
104
|
+
sample(n: number): Point[] {
|
|
105
|
+
ensureInit();
|
|
106
|
+
const buf = wasm.create_arc(
|
|
107
|
+
this.center.x, this.center.y, this.center.z,
|
|
108
|
+
this.normal.x, this.normal.y, this.normal.z,
|
|
109
|
+
this.radius, this.startAngle, this.endAngle, n
|
|
110
|
+
);
|
|
111
|
+
const pts: Point[] = [];
|
|
112
|
+
for (let i = 0; i < buf.length; i += 3) {
|
|
113
|
+
pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
|
|
114
|
+
}
|
|
115
|
+
return pts;
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/Brep.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Mesh, type MeshBooleanOptions } from "./Mesh.js";
|
|
|
6
6
|
import { Polyline } from "./Polyline.js";
|
|
7
7
|
import { NurbsCurve } from "./NurbsCurve.js";
|
|
8
8
|
import { NurbsSurface } from "./NurbsSurface.js";
|
|
9
|
-
import
|
|
9
|
+
import { wasm } from "./wasm-active.js";
|
|
10
10
|
|
|
11
11
|
/** Options for Brep boolean operations. */
|
|
12
12
|
export interface BrepBooleanOptions extends MeshBooleanOptions {
|