opengeometry 2.0.17 → 2.0.18
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/index.js +96 -25
- package/index.js.map +1 -1
- package/opengeometry/pkg/opengeometry.d.ts +2 -2
- package/opengeometry/pkg/opengeometry.js +5 -2
- package/opengeometry/pkg/opengeometry_bg.wasm +0 -0
- package/opengeometry/pkg/opengeometry_bg.wasm.d.ts +1 -1
- package/opengeometry_bg.wasm +0 -0
- package/opengeometry_bg.wasm.d.ts +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -582,10 +582,13 @@ class OGAnalyticBrep {
|
|
|
582
582
|
}
|
|
583
583
|
/**
|
|
584
584
|
* @param {number} deflection
|
|
585
|
+
* @param {string | null} [options_json]
|
|
585
586
|
* @returns {OGAnalyticTessellation}
|
|
586
587
|
*/
|
|
587
|
-
tessellate(deflection) {
|
|
588
|
-
|
|
588
|
+
tessellate(deflection, options_json) {
|
|
589
|
+
var ptr0 = isLikeNone(options_json) ? 0 : passStringToWasm0(options_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
590
|
+
var len0 = WASM_VECTOR_LEN;
|
|
591
|
+
const ret = wasm.oganalyticbrep_tessellate(this.__wbg_ptr, deflection, ptr0, len0);
|
|
589
592
|
if (ret[2]) {
|
|
590
593
|
throw takeFromExternrefTable0(ret[1]);
|
|
591
594
|
}
|
|
@@ -7133,7 +7136,7 @@ class AnalyticSolid extends THREE.Group {
|
|
|
7133
7136
|
throw new Error("STL deflection must be finite and positive");
|
|
7134
7137
|
}
|
|
7135
7138
|
const placed = this.worldKernel();
|
|
7136
|
-
const result =
|
|
7139
|
+
const result = placed.tessellate(deflection * GEOMETRY_DEFLECTION_SHARE);
|
|
7137
7140
|
try {
|
|
7138
7141
|
const positions = result.positions();
|
|
7139
7142
|
const indices = result.indices();
|
|
@@ -7260,7 +7263,7 @@ class AnalyticSolid extends THREE.Group {
|
|
|
7260
7263
|
&& (!Number.isSafeInteger(options.maxTriangles) || options.maxTriangles <= 0 || options.maxTriangles > 2000000)) {
|
|
7261
7264
|
throw new Error("maxTriangles must be an integer between 1 and 2000000");
|
|
7262
7265
|
}
|
|
7263
|
-
const result =
|
|
7266
|
+
const result = this.kernel.tessellate(deflection, options.maxTriangles === undefined ? undefined : JSON.stringify({ max_triangles: options.maxTriangles }));
|
|
7264
7267
|
try {
|
|
7265
7268
|
return {
|
|
7266
7269
|
positions: result.positions(), normals: result.normals(), indices: result.indices(),
|
|
@@ -7386,24 +7389,92 @@ class AnalyticSolid extends THREE.Group {
|
|
|
7386
7389
|
return this.kernel.placed(JSON.stringify(frame), scale);
|
|
7387
7390
|
}
|
|
7388
7391
|
}
|
|
7392
|
+
function arcBoxPointsOf(arc) {
|
|
7393
|
+
const quarterTurn = Math.PI / 2;
|
|
7394
|
+
const axisDirections = [[1, 0], [0, 1], [-1, 0], [0, -1]];
|
|
7395
|
+
const endAngle = arc.startAngle + arc.sweepAngle;
|
|
7396
|
+
const points = [arc.startAngle, endAngle].map((angle) => [
|
|
7397
|
+
arc.center[0] + arc.radius * Math.cos(angle), arc.center[1] + arc.radius * Math.sin(angle),
|
|
7398
|
+
]);
|
|
7399
|
+
const firstQuarter = Math.ceil(Math.min(arc.startAngle, endAngle) / quarterTurn);
|
|
7400
|
+
const lastStep = Number.isFinite(firstQuarter)
|
|
7401
|
+
? Math.min(Math.floor(Math.max(arc.startAngle, endAngle) / quarterTurn) - firstQuarter, 3)
|
|
7402
|
+
: -1;
|
|
7403
|
+
for (let step = 0; step <= lastStep; step += 1) {
|
|
7404
|
+
const direction = axisDirections[(((firstQuarter + step) % 4) + 4) % 4];
|
|
7405
|
+
points.push([arc.center[0] + arc.radius * direction[0], arc.center[1] + arc.radius * direction[1]]);
|
|
7406
|
+
}
|
|
7407
|
+
return points;
|
|
7408
|
+
}
|
|
7409
|
+
function pointBoxOf(options) {
|
|
7410
|
+
var _a;
|
|
7411
|
+
const points = options.kind === "polygonLoft"
|
|
7412
|
+
? [...options.lower, ...options.upper]
|
|
7413
|
+
: options.kind === "planarPolyhedron" ? [...options.vertices] : [];
|
|
7414
|
+
const addProfilePoint = (point, height) => {
|
|
7415
|
+
points.push([point[0], point[1], 0], [point[0], point[1], height]);
|
|
7416
|
+
};
|
|
7417
|
+
if (options.kind === "linearExtrusion") {
|
|
7418
|
+
for (const loop of [options.outer, ...options.holes]) {
|
|
7419
|
+
for (const point of loop)
|
|
7420
|
+
addProfilePoint(point, options.height);
|
|
7421
|
+
}
|
|
7422
|
+
}
|
|
7423
|
+
else if (options.kind === "arcEdgedExtrusion") {
|
|
7424
|
+
for (const ring of [options.outer, ...((_a = options.holes) !== null && _a !== void 0 ? _a : [])]) {
|
|
7425
|
+
for (const edge of ring) {
|
|
7426
|
+
const corners = edge.kind === "line" ? [edge.from, edge.to] : arcBoxPointsOf(edge);
|
|
7427
|
+
for (const corner of corners)
|
|
7428
|
+
addProfilePoint(corner, options.height);
|
|
7429
|
+
}
|
|
7430
|
+
}
|
|
7431
|
+
}
|
|
7432
|
+
if (points.length === 0)
|
|
7433
|
+
return undefined;
|
|
7434
|
+
const box = { lo: [Infinity, Infinity, Infinity], hi: [-Infinity, -Infinity, -Infinity] };
|
|
7435
|
+
for (const point of points) {
|
|
7436
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
7437
|
+
box.lo[axis] = Math.min(box.lo[axis], point[axis]);
|
|
7438
|
+
box.hi[axis] = Math.max(box.hi[axis], point[axis]);
|
|
7439
|
+
}
|
|
7440
|
+
}
|
|
7441
|
+
return box;
|
|
7442
|
+
}
|
|
7443
|
+
function reachBoxOf(options, box) {
|
|
7444
|
+
if (options.kind !== "arcEdgedExtrusion")
|
|
7445
|
+
return box;
|
|
7446
|
+
const reachBox = { lo: [box.lo[0], box.lo[1], box.lo[2]], hi: [box.hi[0], box.hi[1], box.hi[2]] };
|
|
7447
|
+
for (const edge of options.outer) {
|
|
7448
|
+
if (edge.kind === "line")
|
|
7449
|
+
continue;
|
|
7450
|
+
for (const axis of [0, 1]) {
|
|
7451
|
+
reachBox.lo[axis] = Math.min(reachBox.lo[axis], edge.center[axis] - edge.radius);
|
|
7452
|
+
reachBox.hi[axis] = Math.max(reachBox.hi[axis], edge.center[axis] + edge.radius);
|
|
7453
|
+
}
|
|
7454
|
+
}
|
|
7455
|
+
return reachBox;
|
|
7456
|
+
}
|
|
7457
|
+
function worldReachOf(frame, box) {
|
|
7458
|
+
const farthest = [0, 0, 0];
|
|
7459
|
+
for (const alongX of [box.lo[0], box.hi[0]]) {
|
|
7460
|
+
for (const alongY of [box.lo[1], box.hi[1]]) {
|
|
7461
|
+
for (const alongZ of [box.lo[2], box.hi[2]]) {
|
|
7462
|
+
for (let axis = 0; axis < 3; axis += 1) {
|
|
7463
|
+
const coordinate = frame.origin[axis] + alongX * frame.x[axis] + alongY * frame.y[axis] + alongZ * frame.z[axis];
|
|
7464
|
+
farthest[axis] = Math.max(farthest[axis], Math.abs(coordinate));
|
|
7465
|
+
}
|
|
7466
|
+
}
|
|
7467
|
+
}
|
|
7468
|
+
}
|
|
7469
|
+
return Math.hypot(farthest[0], farthest[1], farthest[2]);
|
|
7470
|
+
}
|
|
7389
7471
|
function createPrimitiveKernel(options, ogid) {
|
|
7390
|
-
var _a, _b, _c, _d
|
|
7472
|
+
var _a, _b, _c, _d;
|
|
7391
7473
|
const frame = (_a = options.frame) !== null && _a !== void 0 ? _a : (options.kind === "planarPolyhedron" || options.kind === "polygonLoft"
|
|
7392
7474
|
? { origin: [0, 0, 0], x: [1, 0, 0], y: [0, 1, 0], z: [0, 0, 1] }
|
|
7393
7475
|
: { origin: [0, 0, 0], x: [1, 0, 0], y: [0, 0, -1], z: [0, 1, 0] });
|
|
7394
|
-
const
|
|
7395
|
-
|
|
7396
|
-
: options.kind === "arcEdgedExtrusion"
|
|
7397
|
-
? [options.outer, ...((_b = options.holes) !== null && _b !== void 0 ? _b : [])].reduce((extent, ring) => ring.reduce((loopExtent, edge) => edge.kind === "line"
|
|
7398
|
-
? Math.max(loopExtent, ...edge.from.map(Math.abs), ...edge.to.map(Math.abs))
|
|
7399
|
-
: Math.max(loopExtent, Math.abs(edge.center[0]) + edge.radius, Math.abs(edge.center[1]) + edge.radius), extent), 0)
|
|
7400
|
-
: 0;
|
|
7401
|
-
const loftExtent = options.kind === "polygonLoft"
|
|
7402
|
-
? [...options.lower, ...options.upper].reduce((extent, point) => Math.max(extent, ...point.map(Math.abs)), 0)
|
|
7403
|
-
: 0;
|
|
7404
|
-
const polyhedronExtent = options.kind === "planarPolyhedron"
|
|
7405
|
-
? options.vertices.reduce((extent, point) => Math.max(extent, Math.abs(point[0]), Math.abs(point[1]), Math.abs(point[2])), 0)
|
|
7406
|
-
: 0;
|
|
7476
|
+
const pointBox = pointBoxOf(options);
|
|
7477
|
+
const pointSize = pointBox ? Math.max(...pointBox.hi.map((high, axis) => high - pointBox.lo[axis])) : 0;
|
|
7407
7478
|
const size = options.kind === "torus"
|
|
7408
7479
|
? 2 * (options.majorRadius + options.minorRadius)
|
|
7409
7480
|
: options.kind === "coaxialCircleLoft"
|
|
@@ -7413,13 +7484,13 @@ function createPrimitiveKernel(options, ogid) {
|
|
|
7413
7484
|
: options.kind === "chamferedCuboid"
|
|
7414
7485
|
? Math.max(options.width, options.depth, options.height)
|
|
7415
7486
|
: options.kind === "linearExtrusion" || options.kind === "arcEdgedExtrusion"
|
|
7416
|
-
?
|
|
7487
|
+
? pointSize
|
|
7417
7488
|
: options.kind === "polygonLoft"
|
|
7418
|
-
?
|
|
7489
|
+
? pointSize
|
|
7419
7490
|
: options.kind === "boxWithArchedOpening"
|
|
7420
7491
|
? Math.max(options.width, options.depth, options.height)
|
|
7421
7492
|
: options.kind === "planarPolyhedron"
|
|
7422
|
-
?
|
|
7493
|
+
? pointSize
|
|
7423
7494
|
: options.kind === "frustum"
|
|
7424
7495
|
? Math.max(2 * options.lowerRadius, 2 * options.upperRadius, options.height)
|
|
7425
7496
|
: options.kind === "annularSectorExtrusion" || options.kind === "annularSectorExtrusionWithOpenings" || options.kind === "annularSectorExtrusionWithArchedOpening"
|
|
@@ -7429,9 +7500,9 @@ function createPrimitiveKernel(options, ogid) {
|
|
|
7429
7500
|
: options.kind === "sphere"
|
|
7430
7501
|
? 2 * options.radius
|
|
7431
7502
|
: Math.max(2 * options.radius, options.height);
|
|
7432
|
-
const coordinateFloor =
|
|
7503
|
+
const coordinateFloor = 128 * Number.EPSILON * worldReachOf(frame, pointBox ? reachBoxOf(options, pointBox) : { lo: [-size, -size, -size], hi: [size, size, size] });
|
|
7433
7504
|
const geometric = Math.max(1e-9, size * 1e-8, coordinateFloor);
|
|
7434
|
-
const accuracy = (
|
|
7505
|
+
const accuracy = (_b = options.accuracy) !== null && _b !== void 0 ? _b : {
|
|
7435
7506
|
geometric, intersection: geometric / 4, tessellation: 0.001, exchange: 0.00001,
|
|
7436
7507
|
};
|
|
7437
7508
|
const dimensions = options.kind === "torus"
|
|
@@ -7450,7 +7521,7 @@ function createPrimitiveKernel(options, ogid) {
|
|
|
7450
7521
|
? { outer: options.outer.map((edge) => edge.kind === "line" ? edge : {
|
|
7451
7522
|
kind: "arc", center: edge.center, radius: edge.radius,
|
|
7452
7523
|
start_angle: edge.startAngle, sweep_angle: edge.sweepAngle,
|
|
7453
|
-
}), holes: ((
|
|
7524
|
+
}), holes: ((_c = options.holes) !== null && _c !== void 0 ? _c : []).map((ring) => ring.map((edge) => edge.kind === "line" ? edge : {
|
|
7454
7525
|
kind: "arc", center: edge.center, radius: edge.radius,
|
|
7455
7526
|
start_angle: edge.startAngle, sweep_angle: edge.sweepAngle,
|
|
7456
7527
|
})), height: options.height }
|
|
@@ -7463,7 +7534,7 @@ function createPrimitiveKernel(options, ogid) {
|
|
|
7463
7534
|
: {
|
|
7464
7535
|
kind: "indexed",
|
|
7465
7536
|
upper_start: options.alignment.upperStartIndex,
|
|
7466
|
-
reverse_upper: (
|
|
7537
|
+
reverse_upper: (_d = options.alignment.reverseUpper) !== null && _d !== void 0 ? _d : false,
|
|
7467
7538
|
},
|
|
7468
7539
|
}
|
|
7469
7540
|
: options.kind === "boxWithArchedOpening"
|