brepjs 18.35.6 → 18.37.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/brepjs.cjs CHANGED
@@ -119,6 +119,151 @@ function vertexFinder() {
119
119
  return buildVertexFinder([]);
120
120
  }
121
121
  //#endregion
122
+ //#region src/voxel/registry.ts
123
+ var _engines = /* @__PURE__ */ new Map();
124
+ var _defaultId = null;
125
+ var _cached = null;
126
+ function registerVoxel(id, engine) {
127
+ _engines.set(id, engine);
128
+ if (!_defaultId) _defaultId = id;
129
+ if (id === _defaultId) _cached = engine;
130
+ }
131
+ /**
132
+ * Return a voxel engine by id, or the default engine if no id is given.
133
+ *
134
+ * @throws If no engine has been registered via {@link initVoxel} or
135
+ * {@link registerVoxel}.
136
+ */
137
+ function getVoxel(id) {
138
+ if (!id && _cached) return _cached;
139
+ const targetId = id ?? _defaultId;
140
+ if (!targetId) throw new Error("brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.");
141
+ const engine = _engines.get(targetId);
142
+ if (!engine) throw new Error(`brepjs: voxel engine '${targetId}' is not registered.`);
143
+ return engine;
144
+ }
145
+ /** Return the id of the active default engine, or `null` if none is registered. */
146
+ function getActiveVoxelId() {
147
+ return _defaultId;
148
+ }
149
+ /**
150
+ * Register a loaded voxel engine and make it the default.
151
+ *
152
+ * Mirrors {@link initFromOC} for the kernel: the loader package
153
+ * (`brepjs-voxel`) instantiates the wasm, then hands the engine here.
154
+ */
155
+ function initVoxel(engine, id = "voxel") {
156
+ registerVoxel(id, engine);
157
+ _defaultId = id;
158
+ _cached = engine;
159
+ }
160
+ //#endregion
161
+ //#region src/voxel/signFns.ts
162
+ /**
163
+ * Validate a triangle-soup mesh before it crosses into wasm: flat-xyz vertices,
164
+ * triangle-multiple indices, and every index in range. An out-of-range index
165
+ * would otherwise panic in Rust and surface as a wasm trap, escaping the Result
166
+ * contract — so it must be rejected here.
167
+ */
168
+ function validateMesh(mesh) {
169
+ if (mesh.vertices.length % 3 !== 0) return require_errors.validationError("VOXEL_INVALID_MESH", "mesh.vertices length must be a multiple of 3 (flat xyz).");
170
+ if (mesh.triangles.length % 3 !== 0) return require_errors.validationError("VOXEL_INVALID_MESH", "mesh.triangles length must be a multiple of 3.");
171
+ const vertexCount = mesh.vertices.length / 3;
172
+ for (let i = 0; i < mesh.triangles.length; i++) {
173
+ const idx = mesh.triangles[i];
174
+ if (idx === void 0 || idx >= vertexCount) return require_errors.validationError("VOXEL_INVALID_TRIANGLE_INDEX", `triangle index ${idx} at position ${i} is out of range for ${vertexCount} vertices.`);
175
+ }
176
+ return null;
177
+ }
178
+ function validateInputs(mesh, queries) {
179
+ const meshInvalid = validateMesh(mesh);
180
+ if (meshInvalid) return meshInvalid;
181
+ if (queries.length % 3 !== 0) return require_errors.validationError("VOXEL_INVALID_QUERIES", "queries length must be a multiple of 3 (flat xyz).");
182
+ return null;
183
+ }
184
+ /** Resolve a registered voxel engine, mapping an unregistered id to an error. */
185
+ function resolveEngine(id) {
186
+ try {
187
+ return require_errors.ok(getVoxel(id));
188
+ } catch (cause) {
189
+ return require_errors.err(require_errors.moduleInitError("VOXEL_NOT_INITIALIZED", cause instanceof Error ? cause.message : "voxel engine not initialized", cause));
190
+ }
191
+ }
192
+ /**
193
+ * Generalized winding number at each query point against a triangle-soup mesh.
194
+ *
195
+ * `queries` is flat xyz (length 3·Q); the result has length Q. ~1 inside, ~0
196
+ * outside for a closed mesh; degrades gracefully on holes (the keystone that
197
+ * makes non-watertight repair possible — ADR-0013 §11).
198
+ */
199
+ function windingNumbers(mesh, queries, id) {
200
+ const invalid = validateInputs(mesh, queries);
201
+ if (invalid) return require_errors.err(invalid);
202
+ const engine = resolveEngine(id);
203
+ if (require_errors.isErr(engine)) return engine;
204
+ return require_errors.ok(engine.value.winding_numbers(mesh.vertices, mesh.triangles, queries));
205
+ }
206
+ /**
207
+ * Inside/outside classification (winding number > 0.5) at each query point.
208
+ *
209
+ * `queries` is flat xyz (length 3·Q); the result has length Q.
210
+ */
211
+ function pointsInside(mesh, queries, id) {
212
+ const invalid = validateInputs(mesh, queries);
213
+ if (invalid) return require_errors.err(invalid);
214
+ const engine = resolveEngine(id);
215
+ if (require_errors.isErr(engine)) return engine;
216
+ const flags = engine.value.points_inside(mesh.vertices, mesh.triangles, queries);
217
+ return require_errors.ok(Array.from(flags, (flag) => flag === 1));
218
+ }
219
+ //#endregion
220
+ //#region src/voxel/repairFns.ts
221
+ var DEFAULT_RESOLUTION = 48;
222
+ var DEFAULT_PADDING = 2;
223
+ /**
224
+ * Repair a (possibly non-watertight) triangle-soup mesh into a closed surface:
225
+ * voxelize an FWN-signed SDF, then Surface-Nets contour it back to triangles.
226
+ *
227
+ * The FWN sign classifies inside/outside even on holey input, so a mesh with
228
+ * missing faces still yields a watertight result (ADR-0013 §11). Returns a
229
+ * {@link KernelMeshResult} in world coordinates (a single face group, no UVs).
230
+ */
231
+ function repairMesh(mesh, opts, id) {
232
+ const invalid = validateMesh(mesh);
233
+ if (invalid) return require_errors.err(invalid);
234
+ if (mesh.vertices.length === 0 || mesh.triangles.length === 0) return require_errors.err(require_errors.validationError("VOXEL_EMPTY_MESH", "repairMesh requires a non-empty triangle mesh."));
235
+ const resolution = opts?.resolution ?? DEFAULT_RESOLUTION;
236
+ const padding = opts?.padding ?? DEFAULT_PADDING;
237
+ if (!Number.isInteger(resolution) || resolution < 1) return require_errors.err(require_errors.validationError("VOXEL_INVALID_RESOLUTION", "resolution must be an integer >= 1."));
238
+ if (!Number.isInteger(padding) || padding < 1) return require_errors.err(require_errors.validationError("VOXEL_INVALID_PADDING", "padding must be an integer >= 1."));
239
+ const engine = resolveEngine(id);
240
+ if (require_errors.isErr(engine)) return engine;
241
+ try {
242
+ try {
243
+ var _usingCtx$4 = require_shapeTypes._usingCtx();
244
+ const repaired = _usingCtx$4.u(engine.value.repair_mesh(mesh.vertices, mesh.triangles, resolution, padding));
245
+ const vertexCount = repaired.positions.length / 3;
246
+ return require_errors.ok({
247
+ vertices: repaired.positions,
248
+ normals: repaired.normals,
249
+ triangles: repaired.indices,
250
+ uvs: new Float32Array(vertexCount * 2),
251
+ faceGroups: [{
252
+ start: 0,
253
+ count: repaired.indices.length / 3,
254
+ faceHash: 0
255
+ }]
256
+ });
257
+ } catch (_) {
258
+ _usingCtx$4.e = _;
259
+ } finally {
260
+ _usingCtx$4.d();
261
+ }
262
+ } catch (cause) {
263
+ return require_errors.err(require_errors.computationError("VOXEL_REPAIR_FAILED", cause instanceof Error ? cause.message : "voxel repair failed (grid too large?).", cause));
264
+ }
265
+ }
266
+ //#endregion
122
267
  //#region src/core/kernelBoundary.ts
123
268
  /** Convert Vec3 to a kernel 3D vector. Caller must call .delete() when done. */
124
269
  function toKernelVec(v) {
@@ -5364,6 +5509,7 @@ exports.fuseAllBisect = require_primitiveFns.fuseAllBisect;
5364
5509
  exports.fuseBlueprints = require_boolean2D.fuseBlueprints;
5365
5510
  exports.fuseWithEvolution = require_primitiveFns.fuseWithEvolution;
5366
5511
  exports.gearGeometry = gearGeometry;
5512
+ exports.getActiveVoxelId = getActiveVoxelId;
5367
5513
  exports.getBounds = require_topologyQueryFns.getBounds;
5368
5514
  exports.getBounds2D = require_blueprintFns.getBounds2D;
5369
5515
  exports.getCompSolids = require_topologyQueryFns.getCompSolids;
@@ -5391,6 +5537,7 @@ exports.getSolids = require_topologyQueryFns.getSolids;
5391
5537
  exports.getSurfaceType = require_faceFns.getSurfaceType;
5392
5538
  exports.getTagMetadata = require_shapeFns.getTagMetadata;
5393
5539
  exports.getVertices = require_topologyQueryFns.getVertices;
5540
+ exports.getVoxel = getVoxel;
5394
5541
  exports.getWires = require_topologyQueryFns.getWires;
5395
5542
  exports.guidedSweep = require_extrudeFns.guidedSweep;
5396
5543
  exports.heal = heal;
@@ -5411,6 +5558,7 @@ exports.importThreeMF = importThreeMF;
5411
5558
  exports.init = require_shapeTypes.init;
5412
5559
  exports.initFromManifold = require_shapeTypes.initFromManifold;
5413
5560
  exports.initFromOC = require_shapeTypes.initFromOC;
5561
+ exports.initVoxel = initVoxel;
5414
5562
  exports.innerWires = require_faceFns.innerWires;
5415
5563
  exports.interpolateCurve = require_curveFns.interpolateCurve;
5416
5564
  exports.intersect = intersect;
@@ -5546,6 +5694,7 @@ exports.planarWire = require_shapeTypes.planarWire;
5546
5694
  exports.planetPlacements = planetPlacements;
5547
5695
  exports.pocket = pocket;
5548
5696
  exports.pointOnSurface = require_faceFns.pointOnSurface;
5697
+ exports.pointsInside = pointsInside;
5549
5698
  exports.polygon = require_primitiveFns.polygon;
5550
5699
  exports.polyhedron = polyhedron;
5551
5700
  exports.polysideInnerRadius = require_drawFns.polysideInnerRadius;
@@ -5572,9 +5721,11 @@ exports.registerHandler = require_workerHandler.registerHandler;
5572
5721
  exports.registerKernel = require_shapeTypes.registerKernel;
5573
5722
  exports.registerOperation = require_historyFns.registerOperation;
5574
5723
  exports.registerShape = require_historyFns.registerShape;
5724
+ exports.registerVoxel = registerVoxel;
5575
5725
  exports.rejectAll = require_workerHandler.rejectAll;
5576
5726
  exports.removeChild = require_historyFns.removeChild;
5577
5727
  exports.removeHolesFromFace = require_faceFns.removeHolesFromFace;
5728
+ exports.repairMesh = repairMesh;
5578
5729
  exports.replayFrom = require_historyFns.replayFrom;
5579
5730
  exports.replayHistory = require_historyFns.replayHistory;
5580
5731
  exports.resetDisposalStats = require_shapeTypes.resetDisposalStats;
@@ -5709,6 +5860,7 @@ exports.vertexFinder = vertexFinder;
5709
5860
  exports.vertexPosition = require_topologyQueryFns.vertexPosition;
5710
5861
  exports.verticesOfEdge = require_primitiveFns.verticesOfEdge;
5711
5862
  exports.walkAssembly = require_historyFns.walkAssembly;
5863
+ exports.windingNumbers = windingNumbers;
5712
5864
  exports.wire = require_primitiveFns.wire;
5713
5865
  exports.wireFinder = require_helpers.wireFinder;
5714
5866
  exports.wireLoop = require_primitiveFns.wireLoop;
package/dist/brepjs.js CHANGED
@@ -130,6 +130,151 @@ function vertexFinder() {
130
130
  return buildVertexFinder([]);
131
131
  }
132
132
  //#endregion
133
+ //#region src/voxel/registry.ts
134
+ var _engines = /* @__PURE__ */ new Map();
135
+ var _defaultId = null;
136
+ var _cached = null;
137
+ function registerVoxel(id, engine) {
138
+ _engines.set(id, engine);
139
+ if (!_defaultId) _defaultId = id;
140
+ if (id === _defaultId) _cached = engine;
141
+ }
142
+ /**
143
+ * Return a voxel engine by id, or the default engine if no id is given.
144
+ *
145
+ * @throws If no engine has been registered via {@link initVoxel} or
146
+ * {@link registerVoxel}.
147
+ */
148
+ function getVoxel(id) {
149
+ if (!id && _cached) return _cached;
150
+ const targetId = id ?? _defaultId;
151
+ if (!targetId) throw new Error("brepjs voxel engine not initialized. Call initVoxel() (or registerVoxel()) before using voxel operations.");
152
+ const engine = _engines.get(targetId);
153
+ if (!engine) throw new Error(`brepjs: voxel engine '${targetId}' is not registered.`);
154
+ return engine;
155
+ }
156
+ /** Return the id of the active default engine, or `null` if none is registered. */
157
+ function getActiveVoxelId() {
158
+ return _defaultId;
159
+ }
160
+ /**
161
+ * Register a loaded voxel engine and make it the default.
162
+ *
163
+ * Mirrors {@link initFromOC} for the kernel: the loader package
164
+ * (`brepjs-voxel`) instantiates the wasm, then hands the engine here.
165
+ */
166
+ function initVoxel(engine, id = "voxel") {
167
+ registerVoxel(id, engine);
168
+ _defaultId = id;
169
+ _cached = engine;
170
+ }
171
+ //#endregion
172
+ //#region src/voxel/signFns.ts
173
+ /**
174
+ * Validate a triangle-soup mesh before it crosses into wasm: flat-xyz vertices,
175
+ * triangle-multiple indices, and every index in range. An out-of-range index
176
+ * would otherwise panic in Rust and surface as a wasm trap, escaping the Result
177
+ * contract — so it must be rejected here.
178
+ */
179
+ function validateMesh(mesh) {
180
+ if (mesh.vertices.length % 3 !== 0) return validationError("VOXEL_INVALID_MESH", "mesh.vertices length must be a multiple of 3 (flat xyz).");
181
+ if (mesh.triangles.length % 3 !== 0) return validationError("VOXEL_INVALID_MESH", "mesh.triangles length must be a multiple of 3.");
182
+ const vertexCount = mesh.vertices.length / 3;
183
+ for (let i = 0; i < mesh.triangles.length; i++) {
184
+ const idx = mesh.triangles[i];
185
+ if (idx === void 0 || idx >= vertexCount) return validationError("VOXEL_INVALID_TRIANGLE_INDEX", `triangle index ${idx} at position ${i} is out of range for ${vertexCount} vertices.`);
186
+ }
187
+ return null;
188
+ }
189
+ function validateInputs(mesh, queries) {
190
+ const meshInvalid = validateMesh(mesh);
191
+ if (meshInvalid) return meshInvalid;
192
+ if (queries.length % 3 !== 0) return validationError("VOXEL_INVALID_QUERIES", "queries length must be a multiple of 3 (flat xyz).");
193
+ return null;
194
+ }
195
+ /** Resolve a registered voxel engine, mapping an unregistered id to an error. */
196
+ function resolveEngine(id) {
197
+ try {
198
+ return ok(getVoxel(id));
199
+ } catch (cause) {
200
+ return err(moduleInitError("VOXEL_NOT_INITIALIZED", cause instanceof Error ? cause.message : "voxel engine not initialized", cause));
201
+ }
202
+ }
203
+ /**
204
+ * Generalized winding number at each query point against a triangle-soup mesh.
205
+ *
206
+ * `queries` is flat xyz (length 3·Q); the result has length Q. ~1 inside, ~0
207
+ * outside for a closed mesh; degrades gracefully on holes (the keystone that
208
+ * makes non-watertight repair possible — ADR-0013 §11).
209
+ */
210
+ function windingNumbers(mesh, queries, id) {
211
+ const invalid = validateInputs(mesh, queries);
212
+ if (invalid) return err(invalid);
213
+ const engine = resolveEngine(id);
214
+ if (isErr(engine)) return engine;
215
+ return ok(engine.value.winding_numbers(mesh.vertices, mesh.triangles, queries));
216
+ }
217
+ /**
218
+ * Inside/outside classification (winding number > 0.5) at each query point.
219
+ *
220
+ * `queries` is flat xyz (length 3·Q); the result has length Q.
221
+ */
222
+ function pointsInside(mesh, queries, id) {
223
+ const invalid = validateInputs(mesh, queries);
224
+ if (invalid) return err(invalid);
225
+ const engine = resolveEngine(id);
226
+ if (isErr(engine)) return engine;
227
+ const flags = engine.value.points_inside(mesh.vertices, mesh.triangles, queries);
228
+ return ok(Array.from(flags, (flag) => flag === 1));
229
+ }
230
+ //#endregion
231
+ //#region src/voxel/repairFns.ts
232
+ var DEFAULT_RESOLUTION = 48;
233
+ var DEFAULT_PADDING = 2;
234
+ /**
235
+ * Repair a (possibly non-watertight) triangle-soup mesh into a closed surface:
236
+ * voxelize an FWN-signed SDF, then Surface-Nets contour it back to triangles.
237
+ *
238
+ * The FWN sign classifies inside/outside even on holey input, so a mesh with
239
+ * missing faces still yields a watertight result (ADR-0013 §11). Returns a
240
+ * {@link KernelMeshResult} in world coordinates (a single face group, no UVs).
241
+ */
242
+ function repairMesh(mesh, opts, id) {
243
+ const invalid = validateMesh(mesh);
244
+ if (invalid) return err(invalid);
245
+ if (mesh.vertices.length === 0 || mesh.triangles.length === 0) return err(validationError("VOXEL_EMPTY_MESH", "repairMesh requires a non-empty triangle mesh."));
246
+ const resolution = opts?.resolution ?? DEFAULT_RESOLUTION;
247
+ const padding = opts?.padding ?? DEFAULT_PADDING;
248
+ if (!Number.isInteger(resolution) || resolution < 1) return err(validationError("VOXEL_INVALID_RESOLUTION", "resolution must be an integer >= 1."));
249
+ if (!Number.isInteger(padding) || padding < 1) return err(validationError("VOXEL_INVALID_PADDING", "padding must be an integer >= 1."));
250
+ const engine = resolveEngine(id);
251
+ if (isErr(engine)) return engine;
252
+ try {
253
+ try {
254
+ var _usingCtx$4 = _usingCtx();
255
+ const repaired = _usingCtx$4.u(engine.value.repair_mesh(mesh.vertices, mesh.triangles, resolution, padding));
256
+ const vertexCount = repaired.positions.length / 3;
257
+ return ok({
258
+ vertices: repaired.positions,
259
+ normals: repaired.normals,
260
+ triangles: repaired.indices,
261
+ uvs: new Float32Array(vertexCount * 2),
262
+ faceGroups: [{
263
+ start: 0,
264
+ count: repaired.indices.length / 3,
265
+ faceHash: 0
266
+ }]
267
+ });
268
+ } catch (_) {
269
+ _usingCtx$4.e = _;
270
+ } finally {
271
+ _usingCtx$4.d();
272
+ }
273
+ } catch (cause) {
274
+ return err(computationError("VOXEL_REPAIR_FAILED", cause instanceof Error ? cause.message : "voxel repair failed (grid too large?).", cause));
275
+ }
276
+ }
277
+ //#endregion
133
278
  //#region src/core/kernelBoundary.ts
134
279
  /** Convert Vec3 to a kernel 3D vector. Caller must call .delete() when done. */
135
280
  function toKernelVec(v) {
@@ -5148,4 +5293,4 @@ var csg_exports = /* @__PURE__ */ __exportAll({
5148
5293
  withEvaluator: () => withEvaluator
5149
5294
  });
5150
5295
  //#endregion
5151
- export { BaseSketcher2d, BlueprintSketcher, BrepBugError, BrepErrorCode, BrepWrapperError, BrepkitAdapter, CompoundSketch, DEG2RAD, DisposalScope, FaceSketcher, HASH_CODE_MAX, OK, OcctWasmAdapter, RAD2DEG, Sketch, Sketcher, Sketches, addChild, addHoles, addMate, addStep, adjacentFaces, all, andThen, applyGlue, applyMatrix, approximateCurve, as2D, as3D, asTopo, assignRoles, autoHeal, bezier, blueprintToDXF, booleanPipeline, booleans_exports as booleans, boss, box, bsplineApprox, bug, cameraFromPlane, cameraLookAt, captureHint, cast, castShape, castShape3D, chamfer, chamferDistAngle as chamferDistAngleShape, chamferWithEvolution, checkAllInterferences, checkBoolean, checkInterference, circle, circularPattern, classifyPointOnFace, clearMeshCache, clone, closedWire, collect, collectShapes, colorFaces, colorShape, complexExtrude, composeTransforms, compound, compoundSketchExtrude, compoundSketchFace, compoundSketchLoft, compoundSketchRevolve, computationError, computeStraightSkeleton, cone, construction_exports as construction, convexHull, cornerFinder, countNodes, createAssembly, createAssemblyNode, createBlueprint, createCamera, createCompound, createCompoundBlueprint, createDistanceQuery, createEdge, createFace, createHandle, createHistory, createKernelHandle, createMeshCache, createNamedPlane, createOperationRegistry, createPlane, createRef, createRegistry, createShell, createSolid, createTaskQueue, createVertex, createWire, createWorkerClient, createWorkerHandler, csg_exports as csg, curve2dBoundingBox, curve2dDistanceFrom, curve2dFirstPoint, curve2dIsOnCurve, curve2dLastPoint, curve2dParameter, curve2dSplitAt, curve2dTangentAt, curveEndPoint, curveIsClosed, curveIsPeriodic, curveLength, curvePeriod, curvePointAt, curveStartPoint, curveTangentAt, cut, cut2D, cutAll, cutAllBisect, cutBlueprints, cutWithEvolution, cylinder, defaultScorer, dequeueTask, describe, deserializeDrawing, deserializeHistory, fromBREP as deserializeShape, downcast, draft, draw, drawCircle, drawEllipse, drawFaceOutline, drawParametricFunction, drawPointsInterpolation, drawPolysides, drawProjection, drawRectangle, drawRoundedRectangle, drawSingleCircle, drawSingleEllipse, drawText, drawingChamfer, drawingCut, drawingFillet, drawingFuse, drawingIntersect, drawingToSketchOnPlane, drill, edgeFinder, edgesOfFace, ellipse, ellipseArc, ellipsoid, enqueueTask, err, exportAssemblySTEP, exportDXF, exportGlb, exportGltf, exportIGES, exportOBJ, exportSTEP, exportSTEPConfigured, exportSTL, exportThreeMF, extrude, extrudeAll, face, faceCenter, faceFinder, faceGeomType, faceOrientation, facesOfEdge, fill, filledFace, fillet, filletWithEvolution, findFacesByTag, findNode, findStep, fixSelfIntersection, fixShape, flatMap, flatten, flipFaceOrientation, flipOrientation, fontMetrics, fromBREP$1 as fromBREP, fromKernelDir, fromKernelPnt, fromKernelVec, fromNullable, fuse, fuse2D, fuseAll, fuseAllBisect, fuseBlueprints, fuseWithEvolution, gearGeometry, getBounds, getBounds2D, getCompSolids, getCurveType, getDisposalStats, getEdges, getFaceColor, getFaceOrigins, getFaceTags, getFaces, getFont, getHashCode, getShape as getHistoryShape, getKernel, getNurbsCurveData, getNurbsSurfaceData, getOrientation, getOrientation2D, getPerformanceStats, getShapeColor, getShapeKind, getShells, getSingleFace, getSolids, getSurfaceType, getTagMetadata, getVertices, getWires, guidedSweep, heal, healFace, healSolid, healWire, helix, hull, importDXF, importGLB, importIGES, importOBJ, importSTEP, importSTL, importSVG, importSVGPathD, importThreeMF, init, initFromManifold, initFromOC, innerWires, interpolateCurve, intersect, intersect2D, intersectBlueprints, intersectWithEvolution, invalidateShapeCache, ioNs_exports as io, ioError, is2D, is3D, isChamferRadius, isClosedWire, isCompSolid, isCompound, isDisposeRequest, isEdge, isEmpty, isEqualShape, isErr, isErrorResponse, isFace, isFilletRadius, isInitRequest, isInside2D, isLive, isManifoldShell, isNumber, isOk, isOperationRequest, isOrientedFace, isPlanarFace, isPlanarWire, isProjectionPlane, isEmpty$1 as isQueueEmpty, isSameShape, isShape1D, isShape3D, isShell, isSolid, isSuccessResponse, isValid, isValidSolid, isVertex, isWire, iterCompSolids, iterEdges, iterFaces, iterShells, iterSolids, iterTopo, iterVertices, iterWires, kernelCall, kernelCallRaw, kernelCallScoped, kernelError, line, linearPattern, loadFont, loft, loftAll, makeBaseBox, makeExternalGear, makeInternalGear, makePlane, makePlanetaryGear, makeProjectedEdges, manifoldShell, map, mapBoth, mapErr, match, measureArea, measureCurvatureAt, measureCurvatureAtMid, measureDistance, measureDistanceProps, measureLength, measureLinearProps, measureSurfaceProps, measureVolume, measureVolumeProps, measurement_exports as measurement, mesh, meshEdges, meshMultiLOD, minkowski, mirror, mirror2D, mirrorDrawing, mirrorJoin, modifiers_exports as modifiers, modifyStep, moduleInitError, multiSectionSweep, normalAt, offset, offsetFace, offsetWire2D, ok, or, orElse, organiseBlueprints, orientedFace, outerWire, patterns_exports as patterns, pendingCount, pipeline, pivotPlane, planarFace, planarWire, planetPlacements, pocket, pointOnSurface, polygon, polyhedron, polysideInnerRadius, polysidesBlueprint, positionOnCurve, prewarm, primitives_exports as primitives, projectEdges, projectPointOnFace, query_exports as query, queryError, rectangularPattern, registerHandler, registerKernel, registerOperation, registerShape, rejectAll, removeChild, removeHolesFromFace, replayFrom, replayHistory, resetDisposalStats, resetPerformanceStats, resize, resolve, resolve3D, resolveDirection, resolvePlane, resolveRef, reverseCurve, revolve, roof, rotate, rotate2D, rotateDrawing, roundedRectangleBlueprint, scale, scale2D, scaleDrawing, section, sectionToFace, serializeHistory, setShapeOrigin, setTagMetadata, sewShells, shape, shapeType, sharedEdges, shell, shellWithEvolution, simplify, sketchCircle, sketchEllipse, sketchExtrude, sketchFace, sketchFaceOffset, sketchHelix, sketchLoft, sketchOnFace2D, sketchOnPlane2D, sketchParametricFunction, sketchPolysides, sketchRectangle, sketchRevolve, sketchRoundedRectangle, sketchSweep, sketchText, sketchWires, sketcherStateError, slice, solid, solidFromShell, solveAssembly, sphere, split, stepCount, stepsFrom, stretch2D, subFace, supportExtrude, supportsConstraintSketch, supportsProjection, surfaceFromGrid, surfaceFromImage, sweep, tagFaces, tangentArc, tap, tapErr, textBlueprints, textMetrics, thicken, threePointArc, toBREP, toBufferGeometryData, toGroupedBufferGeometryData, toKernelVec, toLODGeometryData, toLineGeometryData, toSVGPathD, toVec2, toVec3, torus, transformCopy, transforms_exports as transforms, translate, translate2D, translateDrawing, translatePlane, tryCatch, tryCatchAsync, twistExtrude, typeCastError, undoLast, unsupportedError, unwrap, unwrapErr, unwrapOr, unwrapOrElse, updateNode, updateRoles, uvBounds, uvCoordinates, validSolid, validatePlanetary, validationError, variableFillet, vecAdd, vecAngle, vecCross, vecDistance, vecDot, vecEquals, vecIsZero, vecLength, vecLengthSq, vecNegate, vecNormalize, vecProjectToPlane, vecRepr, vecRotate, vecScale, vecSub, vertex, vertexFinder, vertexPosition, verticesOfEdge, walkAssembly, wire, wireFinder, wireLoop, wiresOfFace, withKernel, withKernelDir, withKernelPnt, withKernelVec, withScope, withScopeResult, withScopeResultAsync, zip as zipResults };
5296
+ export { BaseSketcher2d, BlueprintSketcher, BrepBugError, BrepErrorCode, BrepWrapperError, BrepkitAdapter, CompoundSketch, DEG2RAD, DisposalScope, FaceSketcher, HASH_CODE_MAX, OK, OcctWasmAdapter, RAD2DEG, Sketch, Sketcher, Sketches, addChild, addHoles, addMate, addStep, adjacentFaces, all, andThen, applyGlue, applyMatrix, approximateCurve, as2D, as3D, asTopo, assignRoles, autoHeal, bezier, blueprintToDXF, booleanPipeline, booleans_exports as booleans, boss, box, bsplineApprox, bug, cameraFromPlane, cameraLookAt, captureHint, cast, castShape, castShape3D, chamfer, chamferDistAngle as chamferDistAngleShape, chamferWithEvolution, checkAllInterferences, checkBoolean, checkInterference, circle, circularPattern, classifyPointOnFace, clearMeshCache, clone, closedWire, collect, collectShapes, colorFaces, colorShape, complexExtrude, composeTransforms, compound, compoundSketchExtrude, compoundSketchFace, compoundSketchLoft, compoundSketchRevolve, computationError, computeStraightSkeleton, cone, construction_exports as construction, convexHull, cornerFinder, countNodes, createAssembly, createAssemblyNode, createBlueprint, createCamera, createCompound, createCompoundBlueprint, createDistanceQuery, createEdge, createFace, createHandle, createHistory, createKernelHandle, createMeshCache, createNamedPlane, createOperationRegistry, createPlane, createRef, createRegistry, createShell, createSolid, createTaskQueue, createVertex, createWire, createWorkerClient, createWorkerHandler, csg_exports as csg, curve2dBoundingBox, curve2dDistanceFrom, curve2dFirstPoint, curve2dIsOnCurve, curve2dLastPoint, curve2dParameter, curve2dSplitAt, curve2dTangentAt, curveEndPoint, curveIsClosed, curveIsPeriodic, curveLength, curvePeriod, curvePointAt, curveStartPoint, curveTangentAt, cut, cut2D, cutAll, cutAllBisect, cutBlueprints, cutWithEvolution, cylinder, defaultScorer, dequeueTask, describe, deserializeDrawing, deserializeHistory, fromBREP as deserializeShape, downcast, draft, draw, drawCircle, drawEllipse, drawFaceOutline, drawParametricFunction, drawPointsInterpolation, drawPolysides, drawProjection, drawRectangle, drawRoundedRectangle, drawSingleCircle, drawSingleEllipse, drawText, drawingChamfer, drawingCut, drawingFillet, drawingFuse, drawingIntersect, drawingToSketchOnPlane, drill, edgeFinder, edgesOfFace, ellipse, ellipseArc, ellipsoid, enqueueTask, err, exportAssemblySTEP, exportDXF, exportGlb, exportGltf, exportIGES, exportOBJ, exportSTEP, exportSTEPConfigured, exportSTL, exportThreeMF, extrude, extrudeAll, face, faceCenter, faceFinder, faceGeomType, faceOrientation, facesOfEdge, fill, filledFace, fillet, filletWithEvolution, findFacesByTag, findNode, findStep, fixSelfIntersection, fixShape, flatMap, flatten, flipFaceOrientation, flipOrientation, fontMetrics, fromBREP$1 as fromBREP, fromKernelDir, fromKernelPnt, fromKernelVec, fromNullable, fuse, fuse2D, fuseAll, fuseAllBisect, fuseBlueprints, fuseWithEvolution, gearGeometry, getActiveVoxelId, getBounds, getBounds2D, getCompSolids, getCurveType, getDisposalStats, getEdges, getFaceColor, getFaceOrigins, getFaceTags, getFaces, getFont, getHashCode, getShape as getHistoryShape, getKernel, getNurbsCurveData, getNurbsSurfaceData, getOrientation, getOrientation2D, getPerformanceStats, getShapeColor, getShapeKind, getShells, getSingleFace, getSolids, getSurfaceType, getTagMetadata, getVertices, getVoxel, getWires, guidedSweep, heal, healFace, healSolid, healWire, helix, hull, importDXF, importGLB, importIGES, importOBJ, importSTEP, importSTL, importSVG, importSVGPathD, importThreeMF, init, initFromManifold, initFromOC, initVoxel, innerWires, interpolateCurve, intersect, intersect2D, intersectBlueprints, intersectWithEvolution, invalidateShapeCache, ioNs_exports as io, ioError, is2D, is3D, isChamferRadius, isClosedWire, isCompSolid, isCompound, isDisposeRequest, isEdge, isEmpty, isEqualShape, isErr, isErrorResponse, isFace, isFilletRadius, isInitRequest, isInside2D, isLive, isManifoldShell, isNumber, isOk, isOperationRequest, isOrientedFace, isPlanarFace, isPlanarWire, isProjectionPlane, isEmpty$1 as isQueueEmpty, isSameShape, isShape1D, isShape3D, isShell, isSolid, isSuccessResponse, isValid, isValidSolid, isVertex, isWire, iterCompSolids, iterEdges, iterFaces, iterShells, iterSolids, iterTopo, iterVertices, iterWires, kernelCall, kernelCallRaw, kernelCallScoped, kernelError, line, linearPattern, loadFont, loft, loftAll, makeBaseBox, makeExternalGear, makeInternalGear, makePlane, makePlanetaryGear, makeProjectedEdges, manifoldShell, map, mapBoth, mapErr, match, measureArea, measureCurvatureAt, measureCurvatureAtMid, measureDistance, measureDistanceProps, measureLength, measureLinearProps, measureSurfaceProps, measureVolume, measureVolumeProps, measurement_exports as measurement, mesh, meshEdges, meshMultiLOD, minkowski, mirror, mirror2D, mirrorDrawing, mirrorJoin, modifiers_exports as modifiers, modifyStep, moduleInitError, multiSectionSweep, normalAt, offset, offsetFace, offsetWire2D, ok, or, orElse, organiseBlueprints, orientedFace, outerWire, patterns_exports as patterns, pendingCount, pipeline, pivotPlane, planarFace, planarWire, planetPlacements, pocket, pointOnSurface, pointsInside, polygon, polyhedron, polysideInnerRadius, polysidesBlueprint, positionOnCurve, prewarm, primitives_exports as primitives, projectEdges, projectPointOnFace, query_exports as query, queryError, rectangularPattern, registerHandler, registerKernel, registerOperation, registerShape, registerVoxel, rejectAll, removeChild, removeHolesFromFace, repairMesh, replayFrom, replayHistory, resetDisposalStats, resetPerformanceStats, resize, resolve, resolve3D, resolveDirection, resolvePlane, resolveRef, reverseCurve, revolve, roof, rotate, rotate2D, rotateDrawing, roundedRectangleBlueprint, scale, scale2D, scaleDrawing, section, sectionToFace, serializeHistory, setShapeOrigin, setTagMetadata, sewShells, shape, shapeType, sharedEdges, shell, shellWithEvolution, simplify, sketchCircle, sketchEllipse, sketchExtrude, sketchFace, sketchFaceOffset, sketchHelix, sketchLoft, sketchOnFace2D, sketchOnPlane2D, sketchParametricFunction, sketchPolysides, sketchRectangle, sketchRevolve, sketchRoundedRectangle, sketchSweep, sketchText, sketchWires, sketcherStateError, slice, solid, solidFromShell, solveAssembly, sphere, split, stepCount, stepsFrom, stretch2D, subFace, supportExtrude, supportsConstraintSketch, supportsProjection, surfaceFromGrid, surfaceFromImage, sweep, tagFaces, tangentArc, tap, tapErr, textBlueprints, textMetrics, thicken, threePointArc, toBREP, toBufferGeometryData, toGroupedBufferGeometryData, toKernelVec, toLODGeometryData, toLineGeometryData, toSVGPathD, toVec2, toVec3, torus, transformCopy, transforms_exports as transforms, translate, translate2D, translateDrawing, translatePlane, tryCatch, tryCatchAsync, twistExtrude, typeCastError, undoLast, unsupportedError, unwrap, unwrapErr, unwrapOr, unwrapOrElse, updateNode, updateRoles, uvBounds, uvCoordinates, validSolid, validatePlanetary, validationError, variableFillet, vecAdd, vecAngle, vecCross, vecDistance, vecDot, vecEquals, vecIsZero, vecLength, vecLengthSq, vecNegate, vecNormalize, vecProjectToPlane, vecRepr, vecRotate, vecScale, vecSub, vertex, vertexFinder, vertexPosition, verticesOfEdge, walkAssembly, windingNumbers, wire, wireFinder, wireLoop, wiresOfFace, withKernel, withKernelDir, withKernelPnt, withKernelVec, withScope, withScopeResult, withScopeResultAsync, zip as zipResults };
package/dist/index.d.ts CHANGED
@@ -34,6 +34,8 @@ export { exportDXF, blueprintToDXF, type DXFEntity, type DXFExportOptions, } fro
34
34
  export { exportThreeMF, type ThreeMFExportOptions, type ThreeMFMaterial, } from './io/threemfExportFns.js';
35
35
  export { importSVGPathD, importSVG, type SVGImportOptions } from './io/svgImportFns.js';
36
36
  export { exportSTEPConfigured, type StepExportOptions, type StepExportPart, } from './io/stepConfigFns.js';
37
+ export { initVoxel, registerVoxel, getVoxel, getActiveVoxelId, windingNumbers, pointsInside, repairMesh, } from './voxel/index.js';
38
+ export type { VoxelEngine, VoxelMeshInput, VoxelRepairResult, RepairOptions, } from './voxel/index.js';
37
39
  export { default as Sketcher } from './sketching/sketcher.js';
38
40
  export { default as FaceSketcher } from './sketching/faceSketcher.js';
39
41
  export { BaseSketcher2d } from './2d/blueprints/baseSketcher2d.js';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The wasm surface the voxel domain depends on — structurally satisfied by the
3
+ * loaded `brepjs-voxel-wasm` module. Kept snake_case to match the wasm-bindgen
4
+ * exports exactly, so the raw module is a zero-adapter `VoxelEngine`.
5
+ *
6
+ * All buffers are flat (no zero-copy across the wasm boundary, per ADR-0013):
7
+ * `verts` is xyz·V, `tris` is index·T, `queries` is xyz·Q.
8
+ */
9
+ export interface VoxelEngine {
10
+ /** Generalized winding number per query point (~1 inside, ~0 outside). */
11
+ winding_numbers(verts: Float32Array, tris: Uint32Array, queries: Float32Array): Float32Array;
12
+ /** Inside/outside classification per query point (1 = inside, 0 = outside). */
13
+ points_inside(verts: Float32Array, tris: Uint32Array, queries: Float32Array): Uint8Array;
14
+ /** Voxelize-and-contour a mesh into a closed surface (FWN sign keystone). */
15
+ repair_mesh(verts: Float32Array, tris: Uint32Array, resolution: number, padding: number): VoxelRepairResult;
16
+ /** Engine artifact version, for loader/artifact compatibility checks. */
17
+ version(): string;
18
+ }
19
+ /**
20
+ * The repaired-mesh handle the wasm `repair_mesh` returns. Flat xyz
21
+ * `positions`/`normals` (length 3·V) and a triangle-list `indices` (3 per tri),
22
+ * in world space. Structurally satisfied by the generated `RepairResult` class.
23
+ */
24
+ export interface VoxelRepairResult {
25
+ readonly positions: Float32Array;
26
+ readonly normals: Float32Array;
27
+ readonly indices: Uint32Array;
28
+ /** Release the backing WASM allocation (wasm-bindgen lifecycle). */
29
+ free(): void;
30
+ [Symbol.dispose](): void;
31
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Voxel / SDF geometry domain (ADR-0013).
3
+ *
4
+ * A parallel domain to the B-rep kernel: its own engine registry and functional
5
+ * API. v1 surfaces the repair-slice keystone (Generalized Winding Number sign);
6
+ * grid / contour / bridge seams land behind the same registry.
7
+ */
8
+ export type { VoxelEngine, VoxelRepairResult } from './engine.js';
9
+ export type { VoxelMeshInput } from './signFns.js';
10
+ export type { RepairOptions } from './repairFns.js';
11
+ export { registerVoxel, getVoxel, getActiveVoxelId, initVoxel } from './registry.js';
12
+ export { windingNumbers, pointsInside } from './signFns.js';
13
+ export { repairMesh } from './repairFns.js';
@@ -0,0 +1,18 @@
1
+ import { VoxelEngine } from './engine.js';
2
+ export declare function registerVoxel(id: string, engine: VoxelEngine): void;
3
+ /**
4
+ * Return a voxel engine by id, or the default engine if no id is given.
5
+ *
6
+ * @throws If no engine has been registered via {@link initVoxel} or
7
+ * {@link registerVoxel}.
8
+ */
9
+ export declare function getVoxel(id?: string): VoxelEngine;
10
+ /** Return the id of the active default engine, or `null` if none is registered. */
11
+ export declare function getActiveVoxelId(): string | null;
12
+ /**
13
+ * Register a loaded voxel engine and make it the default.
14
+ *
15
+ * Mirrors {@link initFromOC} for the kernel: the loader package
16
+ * (`brepjs-voxel`) instantiates the wasm, then hands the engine here.
17
+ */
18
+ export declare function initVoxel(engine: VoxelEngine, id?: string): void;
@@ -0,0 +1,18 @@
1
+ import { Result } from '../core/result.js';
2
+ import { KernelMeshResult } from '../kernel/types.js';
3
+ import { VoxelMeshInput } from './signFns.js';
4
+ /** Voxel-repair tuning. `resolution` sizes the longest bbox axis in voxels;
5
+ * `padding` is the positive air-margin ring (>= 1) Surface Nets needs. */
6
+ export interface RepairOptions {
7
+ resolution?: number;
8
+ padding?: number;
9
+ }
10
+ /**
11
+ * Repair a (possibly non-watertight) triangle-soup mesh into a closed surface:
12
+ * voxelize an FWN-signed SDF, then Surface-Nets contour it back to triangles.
13
+ *
14
+ * The FWN sign classifies inside/outside even on holey input, so a mesh with
15
+ * missing faces still yields a watertight result (ADR-0013 §11). Returns a
16
+ * {@link KernelMeshResult} in world coordinates (a single face group, no UVs).
17
+ */
18
+ export declare function repairMesh(mesh: VoxelMeshInput, opts?: RepairOptions, id?: string): Result<KernelMeshResult>;
@@ -0,0 +1,34 @@
1
+ import { Result } from '../core/result.js';
2
+ import { BrepError } from '../core/errors.js';
3
+ import { VoxelEngine } from './engine.js';
4
+ /**
5
+ * Minimal triangle-soup input for sign queries. Structurally satisfied by a
6
+ * {@link KernelMeshResult} (which also carries normals/uvs/faceGroups).
7
+ */
8
+ export interface VoxelMeshInput {
9
+ vertices: Float32Array;
10
+ triangles: Uint32Array;
11
+ }
12
+ /**
13
+ * Validate a triangle-soup mesh before it crosses into wasm: flat-xyz vertices,
14
+ * triangle-multiple indices, and every index in range. An out-of-range index
15
+ * would otherwise panic in Rust and surface as a wasm trap, escaping the Result
16
+ * contract — so it must be rejected here.
17
+ */
18
+ export declare function validateMesh(mesh: VoxelMeshInput): BrepError | null;
19
+ /** Resolve a registered voxel engine, mapping an unregistered id to an error. */
20
+ export declare function resolveEngine(id: string | undefined): Result<VoxelEngine>;
21
+ /**
22
+ * Generalized winding number at each query point against a triangle-soup mesh.
23
+ *
24
+ * `queries` is flat xyz (length 3·Q); the result has length Q. ~1 inside, ~0
25
+ * outside for a closed mesh; degrades gracefully on holes (the keystone that
26
+ * makes non-watertight repair possible — ADR-0013 §11).
27
+ */
28
+ export declare function windingNumbers(mesh: VoxelMeshInput, queries: Float32Array, id?: string): Result<Float32Array>;
29
+ /**
30
+ * Inside/outside classification (winding number > 0.5) at each query point.
31
+ *
32
+ * `queries` is flat xyz (length 3·Q); the result has length Q.
33
+ */
34
+ export declare function pointsInside(mesh: VoxelMeshInput, queries: Float32Array, id?: string): Result<boolean[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brepjs",
3
- "version": "18.35.6",
3
+ "version": "18.37.0",
4
4
  "description": "Web CAD library with pluggable geometry kernel",
5
5
  "keywords": [
6
6
  "cad",
@@ -25,6 +25,8 @@
25
25
  "packages/brepjs-opencascade",
26
26
  "packages/brepjs-bim",
27
27
  "packages/brepjs-manifold",
28
+ "packages/brepjs-voxel-wasm",
29
+ "packages/brepjs-voxel",
28
30
  "packages/brepjs-agent",
29
31
  "packages/brepjs-viewer",
30
32
  "apps/playground",