@snaptrude/plugin-core 0.9.13 → 0.9.14

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/api-manifest.json +778 -32
  3. package/dist/api/core/geom/create/index.d.ts +935 -100
  4. package/dist/api/core/geom/create/index.d.ts.map +1 -1
  5. package/dist/api/core/geom/query/brep.d.ts +59 -2
  6. package/dist/api/core/geom/query/brep.d.ts.map +1 -1
  7. package/dist/api/core/geom/query/curve.d.ts +59 -35
  8. package/dist/api/core/geom/query/curve.d.ts.map +1 -1
  9. package/dist/api/core/geom/query/edge.d.ts +2 -2
  10. package/dist/api/core/geom/query/face.d.ts +105 -0
  11. package/dist/api/core/geom/query/face.d.ts.map +1 -1
  12. package/dist/api/core/geom/update/contour.d.ts +2 -0
  13. package/dist/api/core/geom/update/contour.d.ts.map +1 -1
  14. package/dist/api/core/geom/update/curve.d.ts +5 -5
  15. package/dist/api/core/geom/update/profile.d.ts +3 -1
  16. package/dist/api/core/geom/update/profile.d.ts.map +1 -1
  17. package/dist/api/core/handles/index.d.ts +4 -2
  18. package/dist/api/core/handles/index.d.ts.map +1 -1
  19. package/dist/api/design/create/grids.d.ts +1 -1
  20. package/dist/api/design/family.d.ts +67 -10
  21. package/dist/api/design/family.d.ts.map +1 -1
  22. package/dist/api/design/query/geometry/index.d.ts +33 -5
  23. package/dist/api/design/query/geometry/index.d.ts.map +1 -1
  24. package/dist/api/design/query/grids.d.ts +3 -3
  25. package/dist/api/design/query/index.d.ts +47 -0
  26. package/dist/api/design/query/index.d.ts.map +1 -1
  27. package/dist/api/design/query/spaces.d.ts +5 -5
  28. package/dist/api/design/update/index.d.ts +99 -0
  29. package/dist/api/design/update/index.d.ts.map +1 -1
  30. package/dist/api/entity/referenceLine.d.ts +1 -1
  31. package/dist/api/entity/space.d.ts +4 -4
  32. package/dist/api/entity/story.d.ts +4 -4
  33. package/dist/api/program/site.d.ts +4 -4
  34. package/dist/api/program/spreadsheet.d.ts +4 -4
  35. package/dist/handles.d.ts +13 -3
  36. package/dist/handles.d.ts.map +1 -1
  37. package/dist/index.cjs +3417 -2946
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +3370 -2946
  42. package/dist/index.js.map +1 -1
  43. package/dist/massParameters.d.ts +287 -0
  44. package/dist/massParameters.d.ts.map +1 -0
  45. package/dist/massParameters.ops.d.ts +138 -0
  46. package/dist/massParameters.ops.d.ts.map +1 -0
  47. package/package.json +2 -1
  48. package/scripts/check-dist-fresh.mjs +22 -0
  49. package/src/api/core/geom/create/index.ts +1030 -101
  50. package/src/api/core/geom/query/brep.ts +60 -2
  51. package/src/api/core/geom/query/curve.ts +26 -2
  52. package/src/api/core/geom/query/edge.ts +2 -2
  53. package/src/api/core/geom/query/face.ts +109 -4
  54. package/src/api/core/geom/update/contour.ts +2 -0
  55. package/src/api/core/geom/update/profile.ts +2 -0
  56. package/src/api/core/handles/index.ts +3 -2
  57. package/src/api/design/family.ts +68 -10
  58. package/src/api/design/query/geometry/index.ts +35 -4
  59. package/src/api/design/query/index.ts +50 -0
  60. package/src/api/design/update/index.ts +106 -0
  61. package/src/handles.ts +18 -3
  62. package/src/index.ts +2 -0
  63. package/src/massParameters.ops.ts +246 -0
  64. package/src/massParameters.ts +427 -0
  65. package/test/massParameters.test.mjs +952 -0
@@ -174,16 +174,26 @@ export abstract class PluginGeomQueryBrepApi {
174
174
  * | `"line"` | `startPoint`, `endPoint`, `length` |
175
175
  * | `"arc"` | `startPoint`, `endPoint`, `centre`, `axis`, `radius`, `length` |
176
176
  * | `"circle"` | `centre`, `axis`, `radius`, `length` — a full-circle edge (e.g. a cylinder cap rim) |
177
+ * | `"spline"` | `startPoint`, `endPoint`, `degree`, `controlPoints`, `knots`, `length` — a free-form NURBS edge |
178
+ *
179
+ * For a `"spline"` edge, `knots` is the **expanded** knot vector — each knot
180
+ * repeated by its multiplicity, the textbook NURBS form — so
181
+ * `knots.length === controlPoints.length + degree + 1`.
177
182
  *
178
183
  * @param brep The brep the edge belongs to
179
184
  * @param edge The edge whose curve to read
180
185
  * @returns The curve data as a discriminated union on `type` (see table above)
181
186
  * @throws VALIDATION if the edge is not on `brep`
187
+ * @throws PRECONDITION_FAILED if the edge is a RATIONAL (weighted) spline —
188
+ * e.g. a NURBS-converted elliptical intersection edge. The wire form
189
+ * carries no weights, so such an edge is refused rather than reported as a
190
+ * different curve; sample it instead.
182
191
  *
183
192
  * @examplePrompt Read the radius of this curved edge
184
193
  * @examplePrompt Is this edge straight or an arc?
185
194
  * @examplePrompt Get the exact start and end points of this edge
186
195
  * @examplePrompt Measure the length of each edge of this mass
196
+ * @examplePrompt Read the control points of this curved edge
187
197
  *
188
198
  * # Example
189
199
  * ```ts
@@ -219,6 +229,16 @@ export abstract class PluginGeomQueryBrepApi {
219
229
  radius: number
220
230
  length: number
221
231
  }
232
+ | {
233
+ type: "spline"
234
+ startPoint: Vec3Components
235
+ endPoint: Vec3Components
236
+ degree: number
237
+ controlPoints: Vec3Components[]
238
+ /** Expanded by multiplicity: `controlPoints.length + degree + 1` entries. */
239
+ knots: number[]
240
+ length: number
241
+ }
222
242
  >
223
243
 
224
244
  /**
@@ -263,7 +283,10 @@ export abstract class PluginGeomQueryBrepApi {
263
283
  public abstract listVertexPositions(brep: BrepHandle): PluginApiReturn<Vec3Components[]>
264
284
 
265
285
  /**
266
- * Get the centroid (mean of all vertex positions) of a brep.
286
+ * Get the centroid of a brep: the mean of its vertex positions for planar
287
+ * and cylinder-sided solids; for a solid with sphere, cone, torus or spline
288
+ * geometry, its exact centre of mass (integrated over the surfaces; the
289
+ * vertex mean again if the kernel cannot integrate it, e.g. an open brep).
267
290
  * @param brep The brep to query
268
291
  * @returns The centroid as {@linkcode Vec3Components}
269
292
  *
@@ -366,6 +389,37 @@ export abstract class PluginGeomQueryBrepApi {
366
389
  */
367
390
  public abstract getBoundingBox(brep: BrepHandle): PluginApiReturn<BBoxComponents>
368
391
 
392
+ /**
393
+ * Get the enclosed **volume** of a closed solid, integrated from its exact
394
+ * surfaces. Curved faces are measured analytically, not from their
395
+ * tessellation — a real sphere of radius 5 reports 523.6, whatever its
396
+ * triangle count. That makes this the reliable way to confirm a solid is the
397
+ * shape you intended (a torus should measure 2·π²·R·r²).
398
+ *
399
+ * Runs on the OpenCascade kernel (the first kernel call loads a wasm of tens
400
+ * of MB — expect a pause of seconds).
401
+ *
402
+ * @param brep The solid to measure
403
+ * @returns The enclosed volume in cubic internal length units
404
+ * @throws OPERATION_FAILED if the kernel cannot compute the volume (the brep
405
+ * is not a closed solid)
406
+ *
407
+ * @examplePrompt What is the volume of this mass?
408
+ * @examplePrompt How much concrete is in this shape?
409
+ * @examplePrompt Check the volume of the dome I just made
410
+ *
411
+ * # Example
412
+ * ```ts
413
+ * const [mass] = await snaptrude.design.query.listMasses()
414
+ * const brep = await snaptrude.design.query.geometry.getBrep(mass)
415
+ * if (brep) {
416
+ * const volume = await snaptrude.core.geom.query.brep.getVolume(brep)
417
+ * console.log("volume:", volume)
418
+ * }
419
+ * ```
420
+ */
421
+ public abstract getVolume(brep: BrepHandle): PluginApiReturn<number>
422
+
369
423
  /**
370
424
  * Test whether two breps are geometrically equal.
371
425
  * @param brepA First brep
@@ -388,7 +442,7 @@ export abstract class PluginGeomQueryBrepApi {
388
442
  public abstract isEqual(brepA: BrepHandle, brepB: BrepHandle): PluginApiReturn<boolean>
389
443
 
390
444
  /**
391
- * Measures the minimum distance between two solids, with the closest witness
445
+ * Measures the minimum distance between two solids, with the closest
392
446
  * point on each. Touching or overlapping solids report a distance of 0 with
393
447
  * contact points.
394
448
  *
@@ -534,6 +588,10 @@ export type PluginGeomQueryBrepGetBoundingBoxArgs = z.infer<
534
588
  typeof PluginGeomQueryBrepGetBoundingBoxArgs
535
589
  >
536
590
 
591
+ /** Arguments for {@linkcode PluginGeomQueryBrepApi.getVolume}. `{ brep: BrepHandle }` */
592
+ export const PluginGeomQueryBrepGetVolumeArgs = brepArg
593
+ export type PluginGeomQueryBrepGetVolumeArgs = z.infer<typeof PluginGeomQueryBrepGetVolumeArgs>
594
+
537
595
  /**
538
596
  * Arguments for {@linkcode PluginGeomQueryBrepApi.isEqual}.
539
597
  *
@@ -3,8 +3,8 @@ import { PluginApiReturn } from "../../../../types"
3
3
  import { Vec3Handle, CurveHandle, LineHandle, Vec3Components } from "../../../../handles"
4
4
 
5
5
  /**
6
- * Curve queries — read-only geometric questions about curves (lines and arcs)
7
- * and the relationships between two curves (all-handle model, §11).
6
+ * Curve queries — read-only geometric questions about curves (lines, arcs and
7
+ * splines) and the relationships between two curves.
8
8
  *
9
9
  * Every method takes opaque curve handles ({@linkcode CurveHandle}/{@linkcode LineHandle})
10
10
  * and point handles ({@linkcode Vec3Handle}) and returns plain values — points as
@@ -13,6 +13,30 @@ import { Vec3Handle, CurveHandle, LineHandle, Vec3Components } from "../../../..
13
13
  * {@linkcode CurveHandle} (or `null` when there is no result). No query mutates its
14
14
  * inputs.
15
15
  *
16
+ * ## Splines
17
+ *
18
+ * A {@linkcode CurveHandle} is a line, an arc, or a NURBS spline (minted by
19
+ * `core.geom.create.splineFromPoints` / `splineFromControlPoints`, and returned by
20
+ * `edge.getCurve`, `profile.listCurves` and `update.curve.reverse` for a spline run). Every method here accepts a spline at
21
+ * compile time, but only the reads backed by the engine's spline math answer
22
+ * for one today. The rest throw `PRECONDITION_FAILED` ("not supported for
23
+ * splines yet") — a typed refusal, never a quietly wrong answer.
24
+ *
25
+ * | Splines | Members |
26
+ * |---|---|
27
+ * | **supported** | {@linkcode PluginGeomQueryCurveApi.getStartPoint}, {@linkcode PluginGeomQueryCurveApi.getEndPoint}, {@linkcode PluginGeomQueryCurveApi.getLength}, {@linkcode PluginGeomQueryCurveApi.getTangent}, {@linkcode PluginGeomQueryCurveApi.listPoints}, {@linkcode PluginGeomQueryCurveApi.getNearestPoint} |
28
+ * | **not yet** | `getMidPoint`, `getChordLength`, `getNormal`, `getProjection`, `getPointAtDistance`, `getParameterAtPoint`, `getCurvature`, `getDistanceToPoint`, `getDistanceAlong`, `listSubdivisions`, `isLinear`, `isOnCurve`, `hasPoint`, `isEqual`, `isOverlapping`, `getCommonPart`, `listIntersections`, `getMergedCurve`, `isContinuous`, `isParallel`, `getShortestGap`, `getDistanceBetween` |
29
+ *
30
+ * {@linkcode PluginGeomQueryCurveApi.isOverlapping} is deliberately in the
31
+ * second row: its line/arc path falls back to structural equality, which would
32
+ * answer a spline pair wrongly rather than not at all.
33
+ *
34
+ * To work around the second row, sample the curve —
35
+ * {@linkcode PluginGeomQueryCurveApi.listPoints} then the ordinary
36
+ * `core.math.vec3` operations — or read a spline brep edge exactly with
37
+ * `core.geom.query.brep.getEdgeCurve`, which returns its degree, control points
38
+ * and knots.
39
+ *
16
40
  * Accessed via `snaptrude.core.geom.query.curve`.
17
41
  */
18
42
  export abstract class PluginGeomQueryCurveApi {
@@ -69,9 +69,9 @@ export abstract class PluginGeomQueryEdgeApi {
69
69
  public abstract listVertices(edge: EdgeHandle): PluginApiReturn<VertexHandle[]>
70
70
 
71
71
  /**
72
- * Get the underlying curve geometry of an edge (a line or arc).
72
+ * Get the underlying curve geometry of an edge (a line, arc or spline).
73
73
  * @param edge The edge to query
74
- * @returns The curve as a {@linkcode CurveHandle}, or `null` if it is a circle or unset
74
+ * @returns The curve as a {@linkcode CurveHandle} (`line_`, `arc_` or `spline_`), or `null` if it is a circle or unset
75
75
  *
76
76
  * # Example
77
77
  * ```ts
@@ -59,6 +59,49 @@ export abstract class PluginGeomQueryFaceApi {
59
59
  */
60
60
  public abstract getMaterialIndex(face: FaceHandle): PluginApiReturn<number>
61
61
 
62
+ /**
63
+ * Read what KIND of surface a face lies on. This is the one read that tells a
64
+ * genuinely curved face from a faceted approximation of one: every face of a
65
+ * 200-triangle "dome" answers `"plane"`, while a real dome has faces
66
+ * answering `"sphere"`. Use it to confirm a curved solid actually came out
67
+ * curved.
68
+ *
69
+ * | Value | Surface |
70
+ * |---|---|
71
+ * | `"plane"` | Flat face |
72
+ * | `"cylinder"` | Cylindrical face — constant radius about an axis |
73
+ * | `"cone"` | Conical face — a tapered ring (a cone or frustum side) |
74
+ * | `"sphere"` | Spherical face |
75
+ * | `"torus"` | Toroidal face — the ring surface of a donut |
76
+ * | `"spline"` | Free-form NURBS face |
77
+ *
78
+ * Pure read: no geometry kernel is loaded.
79
+ *
80
+ * @param face The face to query
81
+ * @returns The surface kind (see the table), or `null` when the face carries
82
+ * no surface classification
83
+ *
84
+ * @examplePrompt Is this face flat or curved?
85
+ * @examplePrompt Check that this dome is a real sphere, not a faceted approximation
86
+ * @examplePrompt What kind of surface is this face?
87
+ * @examplePrompt How many curved faces does this mass have?
88
+ *
89
+ * # Example
90
+ * ```ts
91
+ * const [mass] = await snaptrude.design.query.listMasses()
92
+ * const brep = await snaptrude.design.query.geometry.getBrep(mass)
93
+ * if (brep) {
94
+ * const faces = await snaptrude.core.geom.query.brep.listFaces(brep)
95
+ * const kinds = []
96
+ * for (const face of faces) kinds.push(await snaptrude.core.geom.query.face.getSurfaceKind(face))
97
+ * console.log("spherical faces:", kinds.filter((k) => k === "sphere").length)
98
+ * }
99
+ * ```
100
+ */
101
+ public abstract getSurfaceKind(
102
+ face: FaceHandle,
103
+ ): PluginApiReturn<"plane" | "cylinder" | "cone" | "sphere" | "torus" | "spline" | null>
104
+
62
105
  /**
63
106
  * Get a seed half-edge of a face's outer loop.
64
107
  * @param face The face to query
@@ -257,6 +300,56 @@ export abstract class PluginGeomQueryFaceApi {
257
300
  brep: BrepHandle,
258
301
  ): PluginApiReturn<Vec3Components[]>
259
302
 
303
+ /**
304
+ * Exact surface area of one face of `brep`, in internal length units SQUARED —
305
+ * integrated off the face's own surface, not its facets, so a curved patch
306
+ * reads exactly rather than as its triangles. Needs the parent brep: a face
307
+ * handle cannot name its own solid.
308
+ * @param face The face to measure
309
+ * @param brep The parent brep (owner last, as in
310
+ * {@linkcode PluginGeomQueryFaceApi.listVertexPositions})
311
+ * @returns The area as a `number`
312
+ * @throws VALIDATION if `face` is not a face of `brep`
313
+ * @throws OPERATION_FAILED if the kernel could not measure the face
314
+ *
315
+ * @examplePrompt How big is this roof patch?
316
+ * @examplePrompt Which face of this mass has the largest area?
317
+ *
318
+ * # Example
319
+ * ```ts
320
+ * const [mass] = await snaptrude.design.query.listMasses()
321
+ * const brep = await snaptrude.design.query.geometry.getBrep(mass)
322
+ * if (brep) {
323
+ * const faces = await snaptrude.core.geom.query.brep.listFaces(brep)
324
+ * const areas = await Promise.all(
325
+ * faces.map((f) => snaptrude.core.geom.query.face.getArea(f, brep)),
326
+ * )
327
+ * }
328
+ * ```
329
+ */
330
+ public abstract getArea(face: FaceHandle, brep: BrepHandle): PluginApiReturn<number>
331
+
332
+ /**
333
+ * Centre of area of one face of `brep`, as a point in that brep's frame
334
+ * (internal length units). On a solid whose every face reads `"spline"` this
335
+ * is the read that tells two patches apart — the top of a thickened patch from
336
+ * its bottom, one quarter of a closed surface from the next.
337
+ * @param face The face to measure
338
+ * @param brep The parent brep (owner last)
339
+ * @returns The centroid as {@linkcode Vec3Components}
340
+ * @throws VALIDATION if `face` is not a face of `brep`
341
+ * @throws OPERATION_FAILED if the kernel could not measure the face
342
+ *
343
+ * @examplePrompt Where is the middle of this face?
344
+ * @examplePrompt Pick the topmost face of this curved mass
345
+ *
346
+ * # Example
347
+ * ```ts
348
+ * const centre = await snaptrude.core.geom.query.face.getCentroid(face, brep)
349
+ * ```
350
+ */
351
+ public abstract getCentroid(face: FaceHandle, brep: BrepHandle): PluginApiReturn<Vec3Components>
352
+
260
353
  /**
261
354
  * List the tessellated boundary points of a face's outer loop (arcs sampled,
262
355
  * sense-corrected). Not cardinality-equal to {@linkcode PluginGeomQueryFaceApi.listVertexPositions}.
@@ -301,6 +394,7 @@ export abstract class PluginGeomQueryFaceApi {
301
394
  }
302
395
 
303
396
  const faceArg = z.object({ face: FaceHandle })
397
+ const faceWithBrepArg = z.object({ face: FaceHandle, brep: BrepHandle })
304
398
 
305
399
  /** Arguments for {@linkcode PluginGeomQueryFaceApi.getIndex}. `{ face: FaceHandle }` */
306
400
  export const PluginGeomQueryFaceGetIndexArgs = faceArg
@@ -312,6 +406,12 @@ export type PluginGeomQueryFaceGetMaterialIndexArgs = z.infer<
312
406
  typeof PluginGeomQueryFaceGetMaterialIndexArgs
313
407
  >
314
408
 
409
+ /** Arguments for {@linkcode PluginGeomQueryFaceApi.getSurfaceKind}. `{ face: FaceHandle }` */
410
+ export const PluginGeomQueryFaceGetSurfaceKindArgs = faceArg
411
+ export type PluginGeomQueryFaceGetSurfaceKindArgs = z.infer<
412
+ typeof PluginGeomQueryFaceGetSurfaceKindArgs
413
+ >
414
+
315
415
  /** Arguments for {@linkcode PluginGeomQueryFaceApi.getHalfEdge}. `{ face: FaceHandle }` */
316
416
  export const PluginGeomQueryFaceGetHalfEdgeArgs = faceArg
317
417
  export type PluginGeomQueryFaceGetHalfEdgeArgs = z.infer<typeof PluginGeomQueryFaceGetHalfEdgeArgs>
@@ -382,14 +482,19 @@ export type PluginGeomQueryFaceGetHoleContainingHalfEdgeArgs = z.infer<
382
482
  * | `face` | {@linkcode FaceHandle} | The face to query |
383
483
  * | `brep` | {@linkcode BrepHandle} | The parent brep (source of vertex coordinates) |
384
484
  */
385
- export const PluginGeomQueryFaceListVertexPositionsArgs = z.object({
386
- face: FaceHandle,
387
- brep: BrepHandle,
388
- })
485
+ export const PluginGeomQueryFaceListVertexPositionsArgs = faceWithBrepArg
389
486
  export type PluginGeomQueryFaceListVertexPositionsArgs = z.infer<
390
487
  typeof PluginGeomQueryFaceListVertexPositionsArgs
391
488
  >
392
489
 
490
+ /** Arguments for {@linkcode PluginGeomQueryFaceApi.getArea}. `{ face: FaceHandle, brep: BrepHandle }` */
491
+ export const PluginGeomQueryFaceGetAreaArgs = faceWithBrepArg
492
+ export type PluginGeomQueryFaceGetAreaArgs = z.infer<typeof PluginGeomQueryFaceGetAreaArgs>
493
+
494
+ /** Arguments for {@linkcode PluginGeomQueryFaceApi.getCentroid}. `{ face: FaceHandle, brep: BrepHandle }` */
495
+ export const PluginGeomQueryFaceGetCentroidArgs = faceWithBrepArg
496
+ export type PluginGeomQueryFaceGetCentroidArgs = z.infer<typeof PluginGeomQueryFaceGetCentroidArgs>
497
+
393
498
  /** Arguments for {@linkcode PluginGeomQueryFaceApi.listVertexPositionsWithCurves}. `{ face: FaceHandle }` */
394
499
  export const PluginGeomQueryFaceListVertexPositionsWithCurvesArgs = faceArg
395
500
  export type PluginGeomQueryFaceListVertexPositionsWithCurvesArgs = z.infer<
@@ -29,6 +29,8 @@ export abstract class PluginGeomUpdateContourApi {
29
29
  * @param contour The contour to offset
30
30
  * @param distance Signed offset distance (outward when positive, inward when negative)
31
31
  * @returns The offset contour as a NEW {@linkcode ContourHandle}
32
+ * @throws PRECONDITION_FAILED if the outline or a hole has a spline run
33
+ * (splines cannot be offset yet)
32
34
  *
33
35
  * @examplePrompt Offset this boundary 500mm inward
34
36
  * @examplePrompt Shrink this floor outline by half a metre all around
@@ -28,6 +28,8 @@ export abstract class PluginGeomUpdateProfileApi {
28
28
  * @param profile The closed profile to offset
29
29
  * @param distance Signed offset distance (outward when positive, inward when negative)
30
30
  * @returns The offset profile as a NEW {@linkcode ProfileHandle}
31
+ * @throws PRECONDITION_FAILED if the profile has a spline run (splines cannot
32
+ * be offset yet)
31
33
  *
32
34
  * @examplePrompt Offset this outline 300mm inward
33
35
  * @examplePrompt Inset this boundary by a foot all around
@@ -6,7 +6,7 @@ import type { AnyArenaHandle } from "../../../handles"
6
6
  import { Handle } from "../../../handles"
7
7
 
8
8
  /**
9
- * The 12 registry-arena handle kinds — the releasable families. Entity-style
9
+ * The 13 registry-arena handle kinds — the releasable families. Entity-style
10
10
  * handles (component / material / underlay / terrain / importJob / comment) are
11
11
  * raw engine ids with no arena entry and therefore no lifecycle: passing one to
12
12
  * `release` is a silent no-op like any other unknown id.
@@ -16,6 +16,7 @@ export const ArenaKind = z.enum([
16
16
  "quat",
17
17
  "line",
18
18
  "arc",
19
+ "spline",
19
20
  "circle",
20
21
  "profile",
21
22
  "contour",
@@ -216,7 +217,7 @@ export type PluginHandlesEndScopeArgs = z.infer<typeof PluginHandlesEndScopeArgs
216
217
  * | Property | Type | Description |
217
218
  * |---|---|---|
218
219
  * | `resources` | `number` | Live resource-arena entries (profile/contour) |
219
- * | `values` | `number` | Live value-arena entries (vec3/quat/line/arc/circle) |
220
+ * | `values` | `number` | Live value-arena entries (vec3/quat/line/arc/spline/circle) |
220
221
  * | `topology` | `number` | Live topology-arena entries (brep/face/edge/halfedge/vertex) |
221
222
  * | `scopes` | `number` | Currently open handle scopes |
222
223
  * | `hostHeapUsedBytes` | `number \| null` | Host page `usedJSHeapSize` (null where unsupported) |
@@ -1,6 +1,6 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../types"
3
- import { ComponentHandle, Vec3Components } from "../../handles"
3
+ import { BrepHandle, ComponentHandle, Vec3Components } from "../../handles"
4
4
 
5
5
  /**
6
6
  * `snaptrude.design.family.*` — author NATIVE parametric families from a JSON spec.
@@ -18,15 +18,21 @@ import { ComponentHandle, Vec3Components } from "../../handles"
18
18
  * getReference() read the spec DSL once — grammar, ops, expressions, example
19
19
  * prepare({ bundle }) validate + compile + show a live ghost; nothing committed
20
20
  * flex({ values }) re-run at new values; returns the geometry delta
21
- * place() arm placement — the USER clicks to drop it
22
- * create({ name }) commit it to the project's family library
21
+ * place({ position }) put it in the model — saves the family as the first instance drops
22
+ * place() save the family, then arm placement — the USER clicks to drop it
23
+ * create({ teamId }) share with a team; a save with nothing placed also drops one instance
23
24
  * ```
24
25
  *
26
+ * `place` saves the prepared family to the user's personal library, so it
27
+ * survives reload with no extra step; finish on `place`, not on `create`.
28
+ *
25
29
  * ## Read getReference() first
26
30
  *
27
31
  * The spec DSL is a closed expression language with its own op set, coordinate
28
- * convention (**+Y up, Snaptrude units** — the scene's own unit, 1 SU = 254 mm;
29
- * literals may carry a unit suffix such as `600mm` or `2ft`)
32
+ * convention (**+Y up, Snaptrude units** — the scene's own unit, 1 SU = 254 mm,
33
+ * the same unit `core.units.getBabylonType()` names and every geometry API
34
+ * takes; literals inside spec expressions may carry a unit suffix such as
35
+ * `600mm` or `2ft`)
30
36
  * and part-naming law. It is deliberately NOT duplicated in these types:
31
37
  * {@linkcode PluginDesignFamilyApi.getReference} returns the whole reference,
32
38
  * generated from a family that is actually registered in the host, so the
@@ -41,6 +47,18 @@ import { ComponentHandle, Vec3Components } from "../../handles"
41
47
  * leaves the previous good draft standing, so it costs nothing but the node you
42
48
  * broke. Re-authoring from scratch throws away everything already correct.
43
49
  *
50
+ * ## Curved parts are exact
51
+ *
52
+ * A part whose sketch has a curved edge — any `revolve`, or an `extrude` /
53
+ * `sweep` / `loft` with an arc or circle in its profile (or an arc in a sweep
54
+ * path) — is built by the exact geometry kernel, the same one behind curved
55
+ * masses. Straight-edged parts keep the fast mesh builder. `getParameters` on a
56
+ * placed component reports which built each part in `parts[].engine`, and a
57
+ * kernel part carries a `brep`: read it with `core.geom.query.brep.*` and
58
+ * `core.geom.query.face.getSurfaceKind` — the same face-kind check as for a
59
+ * curved mass. If the kernel is unavailable a part falls back to the mesh
60
+ * builder (`engine: "mesh"`) rather than failing the family.
61
+ *
44
62
  * Accessed via `snaptrude.design.family`.
45
63
  */
46
64
  export abstract class PluginDesignFamilyApi {
@@ -68,20 +86,25 @@ export abstract class PluginDesignFamilyApi {
68
86
 
69
87
  /**
70
88
  * Validate, compile and preview a family spec. Nothing is committed to the
71
- * model or the library — call {@linkcode PluginDesignFamilyApi.place} or
72
- * {@linkcode PluginDesignFamilyApi.create} for that.
89
+ * model or the library — call {@linkcode PluginDesignFamilyApi.place} to put
90
+ * it in the model, which also saves it.
73
91
  *
74
92
  * Safe to call repeatedly while iterating. On success, check `partCount` and
75
93
  * `bbox` against what you intended before treating the family as correct — a
76
94
  * facade that built 3 parts, or a 3 m screen reporting 40 m of height, is a
77
95
  * visible bug the validator cannot catch.
78
96
  *
97
+ * Lengths — the spec's bare numbers, `bbox`, the sheet's `length` values — are
98
+ * Snaptrude units: the same 254 mm unit as the kernel's internal (`"babylon"`)
99
+ * unit. A unit suffix (`600mm`) is legal only inside a spec expression.
100
+ *
79
101
  * @param args The spec bundle, as `{ bundle }` or `{ spec }`
80
102
  * @returns Build report, or `{ ok: false, errors }` with JSON-pointer paths
81
103
  *
82
104
  * @examplePrompt Make a louvre screen with adjustable blade count and tilt
83
105
  * @examplePrompt Design a curtain wall panel family with 8 bays
84
106
  * @examplePrompt Create a railing family I can adjust
107
+ * @examplePrompt Make a pendant lamp family with a domed shade I can resize
85
108
  *
86
109
  * # Example
87
110
  * ```ts
@@ -147,6 +170,9 @@ export abstract class PluginDesignFamilyApi {
147
170
  * Put a family into the model — either the prepared draft or any family from
148
171
  * {@linkcode PluginDesignFamilyApi.list}.
149
172
  *
173
+ * Placing the prepared draft saves it to the user's personal library first,
174
+ * so its instances survive reload.
175
+ *
150
176
  * Two modes, chosen by whether you pass `position`:
151
177
  *
152
178
  * **With `position`** the component is created there and then, undoably. Use
@@ -195,6 +221,9 @@ export abstract class PluginDesignFamilyApi {
195
221
  * label the user says, and a Revit-imported family carries parameters that
196
222
  * do not drive geometry at all.
197
223
  *
224
+ * `length` values are Snaptrude units: the same 254 mm unit as the kernel's
225
+ * internal (`"babylon"`) unit — convert with `core.units.convert` to report.
226
+ *
198
227
  * @param args The component to read
199
228
  * @returns Its definition, current values, and the parameter sheet
200
229
  *
@@ -220,6 +249,11 @@ export abstract class PluginDesignFamilyApi {
220
249
  * that does not is accepted and stored (it round-trips to Revit) but nothing
221
250
  * visible happens — say so rather than claiming a change the user cannot see.
222
251
  *
252
+ * `length` values are Snaptrude units: the same 254 mm unit as the kernel's
253
+ * internal (`"babylon"`) unit — convert the user's number with
254
+ * `core.units.convert` first; a bare `400` is 400 SU, not 400 mm. Kernel part
255
+ * breps read before the edit are stale: re-read `getParameters`.
256
+ *
223
257
  * @param args The component and the values to change
224
258
  * @returns The values now in effect
225
259
  *
@@ -236,8 +270,11 @@ export abstract class PluginDesignFamilyApi {
236
270
  ): PluginApiReturn<PluginFamilyInstanceParameters>
237
271
 
238
272
  /**
239
- * Commit the prepared bundle to the project's parametric-definition library,
240
- * so it survives the session and appears in the Families panel.
273
+ * Save the prepared bundle to the library — the user's personal library
274
+ * unless `teamId` is given. {@linkcode PluginDesignFamilyApi.place} already
275
+ * saves, so `create` is for sharing with a team. When nothing of the family is
276
+ * in the model yet, one instance is also dropped at the centre of the current
277
+ * view on the active storey (`placed: true`), so a save is never invisible.
241
278
  *
242
279
  * @param args Optional library name and team scope
243
280
  * @returns The catalogued definition's id and version
@@ -318,7 +355,7 @@ export interface PluginFamilyParameter {
318
355
  key: string
319
356
  label: string
320
357
  type: "length" | "integer" | "enum" | "text" | "boolean"
321
- /** Current value. `length`/`integer` are numbers; the rest are strings. */
358
+ /** Current value. `length` (Snaptrude units) and `integer` are numbers; the rest are strings. */
322
359
  value: string | number
323
360
  default: string | number
324
361
  /**
@@ -354,6 +391,25 @@ export interface PluginFamilyDiagnostic {
354
391
  hint?: string
355
392
  }
356
393
 
394
+ /**
395
+ * One placed part and which engine built it, from `getParameters`. `"kernel"` —
396
+ * a curved sketch built exactly; `"mesh"` — straight-edged, or the kernel
397
+ * fallback.
398
+ */
399
+ export interface PluginFamilyPart {
400
+ name: string
401
+ engine: "kernel" | "mesh"
402
+ /**
403
+ * Kernel parts only: the part's exact solid, for `core.geom.query.brep.*` /
404
+ * `core.geom.query.face.getSurfaceKind`. READ-ONLY and PART-LOCAL — in the
405
+ * part's own frame, not where the component sits, so never pass it to a
406
+ * boolean or `design.create.massFromBrep` (a family changes only through
407
+ * `setParameters`). Valid until the next parameter change: re-read
408
+ * `getParameters` after `setParameters`.
409
+ */
410
+ brep?: BrepHandle
411
+ }
412
+
357
413
  /** What `prepare` reports. */
358
414
  export interface PluginFamilyPrepareResult {
359
415
  /** `false` means the spec was rejected — read `errors`, fix, re-prepare. */
@@ -455,6 +511,8 @@ export interface PluginFamilyInstanceParameters {
455
511
  values: Record<string, number | string>
456
512
  /** The sheet: what each key means, its bounds, and whether it moves geometry. */
457
513
  parameters: PluginFamilyParameter[]
514
+ /** The placed parts; kernel parts carry their exact `brep`. */
515
+ parts?: PluginFamilyPart[]
458
516
  /** Present when `getParameters` was asked for a `snapshot`. */
459
517
  snapshot?: PluginFamilySnapshot
460
518
  }
@@ -19,8 +19,8 @@ import {
19
19
  * {@linkcode PluginDesignQueryGeometryApi.getCenterline} mints a
20
20
  * {@linkcode CurveHandle} for a wall's core curve.
21
21
  * {@linkcode PluginDesignQueryGeometryApi.getTriangulatedMeshes} is the
22
- * handle-free exception: it returns the triangulated render meshes as plain
23
- * world-space arrays.
22
+ * handle-free exception: it returns `{ meshes }` — the triangulated render
23
+ * meshes as plain world-space arrays, wrapped in an object, never bare.
24
24
  *
25
25
  * Returned handles are session-ephemeral and go stale on undo/redo/re-topologize
26
26
  * — re-fetch a fresh one after edits.
@@ -34,10 +34,26 @@ export abstract class PluginDesignQueryGeometryApi {
34
34
  * scene entity, as a reusable {@linkcode BrepHandle} for the
35
35
  * `core.geom.query.brep.*` reads.
36
36
  *
37
+ * **Frame.** By default the brep comes back in the component's own LOCAL frame
38
+ * (its vertices are relative to the mesh origin, exactly as stored). This is
39
+ * the long-standing default, and existing callers rely on it. Pass
40
+ * `{ frame: "world" }` to get the same solid placed where it sits in the
41
+ * scene (world coordinates, like
42
+ * `getBottomContour` / `getTriangulatedMeshes` and every `design.query.measure`
43
+ * read). Use `"world"` whenever the handle will be COMBINED with other scene
44
+ * geometry or committed back beside its source: booleans between two scene
45
+ * masses, `brepFromFillet` / `brepFromShell` / `brepFromOffset` /
46
+ * `brepFromChamfer` on a scene mass followed by `massFromBrep`, or comparing
47
+ * its vertices with a bounding box. A world-frame handle from a parametrically
48
+ * live mass also carries that mass's recipe, so an operation result keeps an
49
+ * editable record.
50
+ *
37
51
  * @param component - The scene component to read
38
- * @returns The brep as a {@linkcode BrepHandle}, or `null` if the component has no brep geometry
52
+ * @param options - `frame`: `"local"` (default, mesh-local coordinates) or `"world"` (scene coordinates)
53
+ * @returns The brep as a {@linkcode BrepHandle}, or `null` if the component has no brep geometry — also `null` for a parametric family: read `design.family.getParameters({ component }).parts[].brep`
39
54
  *
40
55
  * @examplePrompt Get the 3D solid geometry of the selected wall
56
+ * @examplePrompt Round the top rim of this column and put it back where it is
41
57
  * @examplePrompt How many faces does this mass have?
42
58
  * @examplePrompt Inspect the mesh of this slab so I can look at its faces and edges
43
59
  * @examplePrompt Read the vertices of the selected column's geometry
@@ -48,10 +64,16 @@ export abstract class PluginDesignQueryGeometryApi {
48
64
  * if (brep) {
49
65
  * const faces = await snaptrude.core.geom.query.brep.listFaces(brep)
50
66
  * }
67
+ *
68
+ * // Operate on a scene mass and commit the result where the mass sits:
69
+ * const placed = await snaptrude.design.query.geometry.getBrep(mass, { frame: "world" })
70
+ * const rounded = await snaptrude.core.geom.create.brepFromFillet(placed, edges, 0.2)
71
+ * await snaptrude.design.create.massFromBrep(rounded, "Rounded")
51
72
  * ```
52
73
  */
53
74
  public abstract getBrep(
54
75
  component: ComponentHandle,
76
+ options?: PluginDesignQueryGeometryGetBrepOptions,
55
77
  ): PluginApiReturn<BrepHandle | null>
56
78
 
57
79
  /**
@@ -126,7 +148,8 @@ export abstract class PluginDesignQueryGeometryApi {
126
148
  * Get the **triangulated render meshes** of scene components as plain,
127
149
  * serializable arrays — flat world-space vertex `positions` (`[x0, y0, z0,
128
150
  * x1, …]`) and triangle `indices` (three per triangle), one record per
129
- * requested component.
151
+ * requested component. The result is `{ meshes }`, not a bare array —
152
+ * destructure it before iterating.
130
153
  *
131
154
  * Unlike the other `geometry.*` reads this does NOT mint kernel handles — the
132
155
  * raw arrays cross the boundary directly, ready for export, custom analysis,
@@ -189,8 +212,16 @@ export abstract class PluginDesignQueryGeometryApi {
189
212
  * |---|---|---|
190
213
  * | `component` | {@linkcode ComponentHandle} | The scene component to read |
191
214
  */
215
+ /** Options for {@linkcode PluginDesignQueryGeometryApi.getBrep}: `frame` defaults to `"local"`. */
216
+ export type PluginDesignQueryGeometryGetBrepOptions = { frame?: "local" | "world" }
217
+ export const PluginDesignQueryGeometryGetBrepOptions: z.ZodType<
218
+ PluginDesignQueryGeometryGetBrepOptions,
219
+ PluginDesignQueryGeometryGetBrepOptions
220
+ > = z.object({ frame: z.enum(["local", "world"]).optional() })
221
+
192
222
  export const PluginDesignQueryGeometryGetBrepArgs = z.object({
193
223
  component: ComponentHandle,
224
+ options: PluginDesignQueryGeometryGetBrepOptions.optional(),
194
225
  })
195
226
 
196
227
  export type PluginDesignQueryGeometryGetBrepArgs = z.infer<