brepjs 18.69.0 → 18.69.1

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
@@ -26,7 +26,7 @@ const require_measureFns = require("./measureFns-CrSEblGG.cjs");
26
26
  const require_cornerFinder = require("./cornerFinder-tTS3ny7e.cjs");
27
27
  const require_boolean2D = require("./boolean2D-xDBZQH_n.cjs");
28
28
  const require_blueprintFns = require("./blueprintFns-DULa6FpG.cjs");
29
- const require_importFns = require("./importFns-CwILDYiQ.cjs");
29
+ const require_importFns = require("./importFns-8zgPWa83.cjs");
30
30
  const require_extrudeFns = require("./extrudeFns-IvYW5-8y.cjs");
31
31
  const require_cameraFns = require("./cameraFns-Bk8frXwa.cjs");
32
32
  const require_textMetrics = require("./textMetrics-CnCjqf59.cjs");
package/dist/brepjs.js CHANGED
@@ -24,7 +24,7 @@ import { a as measureDistance, c as measureLinearProps, d as measureVolumeProps,
24
24
  import { t as cornerFinder } from "./cornerFinder-B8GvvW0U.js";
25
25
  import { a as fuseBlueprints, c as roundedRectangleBlueprint, i as cutBlueprints, n as fuse2D, o as intersectBlueprints, r as intersect2D, s as polysidesBlueprint, t as cut2D } from "./boolean2D-BNWuFXK_.js";
26
26
  import { S as reverseCurve, _ as curve2dIsOnCurve, a as isInside2D, b as curve2dSplitAt, c as scale2D, d as stretch2D, f as toSVGPathD, g as curve2dFirstPoint, h as curve2dDistanceFrom, i as getOrientation2D, l as sketchOnFace2D, m as curve2dBoundingBox, n as createCompoundBlueprint, o as mirror2D, p as translate2D, r as getBounds2D, s as rotate2D, t as createBlueprint, u as sketchOnPlane2D, v as curve2dLastPoint, x as curve2dTangentAt, y as curve2dParameter } from "./blueprintFns-BNhsXv6q.js";
27
- import { a as importSVG, c as blueprintToDXF, d as exportGltf, f as exportOBJ, i as exportSTEPConfigured, l as exportDXF, n as importSTEP, o as importSVGPathD, r as importSTL, s as exportThreeMF, t as importIGES, u as exportGlb } from "./importFns-1SHLSNtG.js";
27
+ import { a as importSVG, c as blueprintToDXF, d as exportGltf, f as exportOBJ, i as exportSTEPConfigured, l as exportDXF, n as importSTEP, o as importSVGPathD, r as importSTL, s as exportThreeMF, t as importIGES, u as exportGlb } from "./importFns-BAJm4qfD.js";
28
28
  import { a as guidedSweep, c as sweep$1, i as complexExtrude, l as twistExtrude, n as extrudeAll, o as multiSectionSweep, r as revolve$1, s as supportExtrude, t as extrude$1 } from "./extrudeFns-CMr1tf7I.js";
29
29
  import { a as Sketch, b as loftAll, c as compoundSketchLoft, d as sketchFace, f as sketchLoft, h as sketchWires, i as Sketches, l as compoundSketchRevolve, m as sketchSweep, n as getFont, o as compoundSketchExtrude, p as sketchRevolve, r as loadFont, s as compoundSketchFace, t as textBlueprints, u as sketchExtrude, v as CompoundSketch, y as loft$1 } from "./textBlueprints-BXGrW7Ak.js";
30
30
  import { a as makeProjectedEdges, i as projectEdges, n as cameraLookAt, r as createCamera, s as isProjectionPlane, t as cameraFromPlane } from "./cameraFns-k787od3u.js";
@@ -61,6 +61,24 @@ var FLOAT = 5126;
61
61
  var UNSIGNED_INT = 5125;
62
62
  var ARRAY_BUFFER = 34962;
63
63
  var ELEMENT_ARRAY_BUFFER = 34963;
64
+ var Y_UP_QUAT = [
65
+ -Math.SQRT1_2,
66
+ 0,
67
+ 0,
68
+ Math.SQRT1_2
69
+ ];
70
+ /**
71
+ * Scene-graph nodes for the single mesh. For Y-up (default) the mesh node is
72
+ * parented under a rotation node so the Z-up vertices display upright in glTF
73
+ * viewers; for Z-up the mesh node is the root with no transform.
74
+ */
75
+ function sceneNodes(upAxis) {
76
+ return upAxis === "Z" ? [{ mesh: 0 }] : [{
77
+ name: "Z_up_to_Y_up",
78
+ rotation: Y_UP_QUAT,
79
+ children: [1]
80
+ }, { mesh: 0 }];
81
+ }
64
82
  function computeMinMax(data) {
65
83
  const min = [
66
84
  Infinity,
@@ -209,7 +227,7 @@ function buildSingleBufferViews(indicesByteLength, verticesByteLength, normalsBy
209
227
  function buildGltfDocument(mesh, mode, options) {
210
228
  const { vertices, normals, triangles } = mesh;
211
229
  const materialMap = options?.materials;
212
- if (materialMap && materialMap.size > 0 && mesh.faceGroups.length > 0) return buildGltfDocumentWithMaterials(mesh, mode, materialMap);
230
+ if (materialMap && materialMap.size > 0 && mesh.faceGroups.length > 0) return buildGltfDocumentWithMaterials(mesh, mode, materialMap, options.upAxis ?? "Y");
213
231
  const indicesByteLength = triangles.byteLength;
214
232
  const verticesByteLength = vertices.byteLength;
215
233
  const normalsByteLength = normals.byteLength;
@@ -222,7 +240,7 @@ function buildGltfDocument(mesh, mode, options) {
222
240
  },
223
241
  scene: 0,
224
242
  scenes: [{ nodes: [0] }],
225
- nodes: [{ mesh: 0 }],
243
+ nodes: sceneNodes(options?.upAxis ?? "Y"),
226
244
  meshes: [{ primitives: [{
227
245
  attributes: {
228
246
  POSITION: 1,
@@ -250,14 +268,14 @@ function buildGltfDocument(mesh, mode, options) {
250
268
  function buildGlbData(mesh, options) {
251
269
  const materialMap = options?.materials;
252
270
  if (materialMap && materialMap.size > 0 && mesh.faceGroups.length > 0) {
253
- const { doc, binBuffer } = buildGltfDocumentAndBufferWithMaterials(mesh, materialMap);
271
+ const { doc, binBuffer } = buildGltfDocumentAndBufferWithMaterials(mesh, materialMap, options.upAxis ?? "Y");
254
272
  return {
255
273
  doc,
256
274
  binBuffer
257
275
  };
258
276
  }
259
277
  return {
260
- doc: buildGltfDocument(mesh, "glb"),
278
+ doc: buildGltfDocument(mesh, "glb", options),
261
279
  binBuffer: buildBinaryBuffer(mesh)
262
280
  };
263
281
  }
@@ -413,11 +431,12 @@ function appendIndexPrimitives(primitiveData, indexBufferInfos, verticesAccIdx,
413
431
  /**
414
432
  * Build a glTF document from material layout.
415
433
  */
416
- function buildGltfDocFromLayout(mesh, layout) {
434
+ function buildGltfDocFromLayout(mesh, layout, upAxis = "Y") {
417
435
  const { primitiveData, indexBufferInfos, verticesOffset, totalByteLength, uniqueMaterials } = layout;
418
436
  const accessors = [];
419
437
  const bufferViews = [];
420
438
  const { verticesAccIdx, normalsAccIdx } = appendVertexNormalSections(mesh, verticesOffset, accessors, bufferViews);
439
+ const primitives = appendIndexPrimitives(primitiveData, indexBufferInfos, verticesAccIdx, normalsAccIdx, accessors, bufferViews);
421
440
  return {
422
441
  asset: {
423
442
  version: "2.0",
@@ -425,8 +444,8 @@ function buildGltfDocFromLayout(mesh, layout) {
425
444
  },
426
445
  scene: 0,
427
446
  scenes: [{ nodes: [0] }],
428
- nodes: [{ mesh: 0 }],
429
- meshes: [{ primitives: appendIndexPrimitives(primitiveData, indexBufferInfos, verticesAccIdx, normalsAccIdx, accessors, bufferViews) }],
447
+ nodes: sceneNodes(upAxis),
448
+ meshes: [{ primitives }],
430
449
  accessors,
431
450
  bufferViews,
432
451
  buffers: [{ byteLength: totalByteLength }],
@@ -453,9 +472,9 @@ function buildBinaryBufferFromLayout(mesh, layout) {
453
472
  /**
454
473
  * Build a glTF document with per-material primitives (base64 mode).
455
474
  */
456
- function buildGltfDocumentWithMaterials(mesh, _mode, materialMap) {
475
+ function buildGltfDocumentWithMaterials(mesh, _mode, materialMap, upAxis = "Y") {
457
476
  const layout = computeMaterialLayout(mesh, materialMap);
458
- const doc = buildGltfDocFromLayout(mesh, layout);
477
+ const doc = buildGltfDocFromLayout(mesh, layout, upAxis);
459
478
  if (_mode === "base64") {
460
479
  const buffer = buildBinaryBufferFromLayout(mesh, layout);
461
480
  doc.buffers[0] = {
@@ -468,10 +487,10 @@ function buildGltfDocumentWithMaterials(mesh, _mode, materialMap) {
468
487
  /**
469
488
  * Build both glTF document and binary buffer for GLB with materials.
470
489
  */
471
- function buildGltfDocumentAndBufferWithMaterials(mesh, materialMap) {
490
+ function buildGltfDocumentAndBufferWithMaterials(mesh, materialMap, upAxis = "Y") {
472
491
  const layout = computeMaterialLayout(mesh, materialMap);
473
492
  return {
474
- doc: buildGltfDocFromLayout(mesh, layout),
493
+ doc: buildGltfDocFromLayout(mesh, layout, upAxis),
475
494
  binBuffer: buildBinaryBufferFromLayout(mesh, layout)
476
495
  };
477
496
  }
@@ -61,6 +61,24 @@ var FLOAT = 5126;
61
61
  var UNSIGNED_INT = 5125;
62
62
  var ARRAY_BUFFER = 34962;
63
63
  var ELEMENT_ARRAY_BUFFER = 34963;
64
+ var Y_UP_QUAT = [
65
+ -Math.SQRT1_2,
66
+ 0,
67
+ 0,
68
+ Math.SQRT1_2
69
+ ];
70
+ /**
71
+ * Scene-graph nodes for the single mesh. For Y-up (default) the mesh node is
72
+ * parented under a rotation node so the Z-up vertices display upright in glTF
73
+ * viewers; for Z-up the mesh node is the root with no transform.
74
+ */
75
+ function sceneNodes(upAxis) {
76
+ return upAxis === "Z" ? [{ mesh: 0 }] : [{
77
+ name: "Z_up_to_Y_up",
78
+ rotation: Y_UP_QUAT,
79
+ children: [1]
80
+ }, { mesh: 0 }];
81
+ }
64
82
  function computeMinMax(data) {
65
83
  const min = [
66
84
  Infinity,
@@ -209,7 +227,7 @@ function buildSingleBufferViews(indicesByteLength, verticesByteLength, normalsBy
209
227
  function buildGltfDocument(mesh, mode, options) {
210
228
  const { vertices, normals, triangles } = mesh;
211
229
  const materialMap = options?.materials;
212
- if (materialMap && materialMap.size > 0 && mesh.faceGroups.length > 0) return buildGltfDocumentWithMaterials(mesh, mode, materialMap);
230
+ if (materialMap && materialMap.size > 0 && mesh.faceGroups.length > 0) return buildGltfDocumentWithMaterials(mesh, mode, materialMap, options.upAxis ?? "Y");
213
231
  const indicesByteLength = triangles.byteLength;
214
232
  const verticesByteLength = vertices.byteLength;
215
233
  const normalsByteLength = normals.byteLength;
@@ -222,7 +240,7 @@ function buildGltfDocument(mesh, mode, options) {
222
240
  },
223
241
  scene: 0,
224
242
  scenes: [{ nodes: [0] }],
225
- nodes: [{ mesh: 0 }],
243
+ nodes: sceneNodes(options?.upAxis ?? "Y"),
226
244
  meshes: [{ primitives: [{
227
245
  attributes: {
228
246
  POSITION: 1,
@@ -250,14 +268,14 @@ function buildGltfDocument(mesh, mode, options) {
250
268
  function buildGlbData(mesh, options) {
251
269
  const materialMap = options?.materials;
252
270
  if (materialMap && materialMap.size > 0 && mesh.faceGroups.length > 0) {
253
- const { doc, binBuffer } = buildGltfDocumentAndBufferWithMaterials(mesh, materialMap);
271
+ const { doc, binBuffer } = buildGltfDocumentAndBufferWithMaterials(mesh, materialMap, options.upAxis ?? "Y");
254
272
  return {
255
273
  doc,
256
274
  binBuffer
257
275
  };
258
276
  }
259
277
  return {
260
- doc: buildGltfDocument(mesh, "glb"),
278
+ doc: buildGltfDocument(mesh, "glb", options),
261
279
  binBuffer: buildBinaryBuffer(mesh)
262
280
  };
263
281
  }
@@ -413,11 +431,12 @@ function appendIndexPrimitives(primitiveData, indexBufferInfos, verticesAccIdx,
413
431
  /**
414
432
  * Build a glTF document from material layout.
415
433
  */
416
- function buildGltfDocFromLayout(mesh, layout) {
434
+ function buildGltfDocFromLayout(mesh, layout, upAxis = "Y") {
417
435
  const { primitiveData, indexBufferInfos, verticesOffset, totalByteLength, uniqueMaterials } = layout;
418
436
  const accessors = [];
419
437
  const bufferViews = [];
420
438
  const { verticesAccIdx, normalsAccIdx } = appendVertexNormalSections(mesh, verticesOffset, accessors, bufferViews);
439
+ const primitives = appendIndexPrimitives(primitiveData, indexBufferInfos, verticesAccIdx, normalsAccIdx, accessors, bufferViews);
421
440
  return {
422
441
  asset: {
423
442
  version: "2.0",
@@ -425,8 +444,8 @@ function buildGltfDocFromLayout(mesh, layout) {
425
444
  },
426
445
  scene: 0,
427
446
  scenes: [{ nodes: [0] }],
428
- nodes: [{ mesh: 0 }],
429
- meshes: [{ primitives: appendIndexPrimitives(primitiveData, indexBufferInfos, verticesAccIdx, normalsAccIdx, accessors, bufferViews) }],
447
+ nodes: sceneNodes(upAxis),
448
+ meshes: [{ primitives }],
430
449
  accessors,
431
450
  bufferViews,
432
451
  buffers: [{ byteLength: totalByteLength }],
@@ -453,9 +472,9 @@ function buildBinaryBufferFromLayout(mesh, layout) {
453
472
  /**
454
473
  * Build a glTF document with per-material primitives (base64 mode).
455
474
  */
456
- function buildGltfDocumentWithMaterials(mesh, _mode, materialMap) {
475
+ function buildGltfDocumentWithMaterials(mesh, _mode, materialMap, upAxis = "Y") {
457
476
  const layout = computeMaterialLayout(mesh, materialMap);
458
- const doc = buildGltfDocFromLayout(mesh, layout);
477
+ const doc = buildGltfDocFromLayout(mesh, layout, upAxis);
459
478
  if (_mode === "base64") {
460
479
  const buffer = buildBinaryBufferFromLayout(mesh, layout);
461
480
  doc.buffers[0] = {
@@ -468,10 +487,10 @@ function buildGltfDocumentWithMaterials(mesh, _mode, materialMap) {
468
487
  /**
469
488
  * Build both glTF document and binary buffer for GLB with materials.
470
489
  */
471
- function buildGltfDocumentAndBufferWithMaterials(mesh, materialMap) {
490
+ function buildGltfDocumentAndBufferWithMaterials(mesh, materialMap, upAxis = "Y") {
472
491
  const layout = computeMaterialLayout(mesh, materialMap);
473
492
  return {
474
- doc: buildGltfDocFromLayout(mesh, layout),
493
+ doc: buildGltfDocFromLayout(mesh, layout, upAxis),
475
494
  binBuffer: buildBinaryBufferFromLayout(mesh, layout)
476
495
  };
477
496
  }
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ export { reverseCurve, curve2dBoundingBox, curve2dFirstPoint, curve2dLastPoint,
33
33
  export { createBlueprint, createCompoundBlueprint, getBounds2D, getOrientation2D, isInside2D, toSVGPathD, translate2D, rotate2D, scale2D, mirror2D, stretch2D, sketchOnPlane2D, sketchOnFace2D, } from './2d/blueprints/blueprintFns.js';
34
34
  export { getSingleFace, type SingleFace } from './query/helpers.js';
35
35
  export { exportOBJ } from './io/objExportFns.js';
36
- export { exportGltf, exportGlb, type GltfMaterial, type GltfExportOptions, } from './io/gltfExportFns.js';
36
+ export { exportGltf, exportGlb, type GltfMaterial, type GltfExportOptions, type GltfFace, type MaterialFn, } from './io/gltfExportFns.js';
37
37
  export { exportDXF, blueprintToDXF, type DXFEntity, type DXFExportOptions, } from './io/dxfExportFns.js';
38
38
  export { exportThreeMF, type ThreeMFExportOptions, type ThreeMFMaterial, } from './io/threemfExportFns.js';
39
39
  export { importSVGPathD, importSVG, type SVGImportOptions } from './io/svgImportFns.js';
@@ -14,6 +14,23 @@ export interface GltfMaterial {
14
14
  /** Roughness factor 0–1. Default: 0.5 */
15
15
  roughness?: number;
16
16
  }
17
+ /**
18
+ * A meshed face as presented to a {@link MaterialFn} — its stable id and the
19
+ * centroid of its triangles in part coordinates (Z-up, mm).
20
+ */
21
+ export interface GltfFace {
22
+ /** Stable face identifier — matches ShapeMesh.faceGroups[].faceId. */
23
+ faceId: number;
24
+ /** Centroid of the face's vertices, in part (Z-up, mm) coordinates. */
25
+ center: [number, number, number];
26
+ }
27
+ /**
28
+ * Per-face material selector. Called once per face group; return a material to
29
+ * paint that face, or `undefined` to leave it at the glTF default. Consumed by
30
+ * tooling (e.g. brepjs-verify's `export const materials`) that has the mesh and
31
+ * builds the faceId→material map passed to {@link GltfExportOptions.materials}.
32
+ */
33
+ export type MaterialFn = (face: GltfFace) => GltfMaterial | undefined;
17
34
  /**
18
35
  * Options for glTF/GLB export.
19
36
  *
@@ -23,6 +40,14 @@ export interface GltfMaterial {
23
40
  export interface GltfExportOptions {
24
41
  /** Map of faceId → material. FaceIds come from ShapeMesh.faceGroups[].faceId. */
25
42
  materials?: Map<number, GltfMaterial>;
43
+ /**
44
+ * Up-axis of the emitted document. brepjs geometry is Z-up (CAD convention),
45
+ * but glTF 2.0 mandates Y-up. With `'Y'` (the default) a root node carrying a
46
+ * −90° rotation about X is emitted so the part stands upright in standard glTF
47
+ * viewers (three.js, model-viewer, Blender); vertex data stays Z-up, matching
48
+ * the STEP/STL exports. Use `'Z'` to emit raw Z-up coordinates with no root node.
49
+ */
50
+ upAxis?: 'Y' | 'Z';
26
51
  }
27
52
  /**
28
53
  * Export a ShapeMesh to a glTF 2.0 JSON string with an embedded base64 buffer.
package/dist/io.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_meshFns = require("./meshFns-DwHAYqRN.cjs");
3
- const require_importFns = require("./importFns-CwILDYiQ.cjs");
3
+ const require_importFns = require("./importFns-8zgPWa83.cjs");
4
4
  exports.blueprintToDXF = require_importFns.blueprintToDXF;
5
5
  exports.exportDXF = require_importFns.exportDXF;
6
6
  exports.exportGlb = require_importFns.exportGlb;
package/dist/io.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  export { importSTEP, importSTL, importIGES } from './io/importFns.js';
10
10
  export { exportSTEP, exportSTL, exportIGES } from './topology/meshFns.js';
11
11
  export { exportOBJ } from './io/objExportFns.js';
12
- export { exportGltf, exportGlb, type GltfMaterial, type GltfExportOptions, } from './io/gltfExportFns.js';
12
+ export { exportGltf, exportGlb, type GltfMaterial, type GltfExportOptions, type GltfFace, type MaterialFn, } from './io/gltfExportFns.js';
13
13
  export { exportDXF, blueprintToDXF, type DXFEntity, type DXFExportOptions, } from './io/dxfExportFns.js';
14
14
  export { exportThreeMF, type ThreeMFExportOptions, type ThreeMFMaterial, } from './io/threemfExportFns.js';
15
15
  export { importSVGPathD, importSVG, type SVGImportOptions } from './io/svgImportFns.js';
package/dist/io.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import { n as exportSTEP, r as exportSTL, t as exportIGES } from "./meshFns-0RHalM3t.js";
2
- import { a as importSVG, c as blueprintToDXF, d as exportGltf, f as exportOBJ, i as exportSTEPConfigured, l as exportDXF, n as importSTEP, o as importSVGPathD, r as importSTL, s as exportThreeMF, t as importIGES, u as exportGlb } from "./importFns-1SHLSNtG.js";
2
+ import { a as importSVG, c as blueprintToDXF, d as exportGltf, f as exportOBJ, i as exportSTEPConfigured, l as exportDXF, n as importSTEP, o as importSVGPathD, r as importSTL, s as exportThreeMF, t as importIGES, u as exportGlb } from "./importFns-BAJm4qfD.js";
3
3
  export { blueprintToDXF, exportDXF, exportGlb, exportGltf, exportIGES, exportOBJ, exportSTEP, exportSTEPConfigured, exportSTL, exportThreeMF, importIGES, importSTEP, importSTL, importSVG, importSVGPathD };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brepjs",
3
- "version": "18.69.0",
3
+ "version": "18.69.1",
4
4
  "description": "Web CAD library with pluggable geometry kernel",
5
5
  "keywords": [
6
6
  "cad",