@snaptrude/plugin-core 0.0.0-dev-20260827135706 → 0.0.0-dev-20260907135026
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/api-manifest.json +177 -15
- package/dist/api/core/geom/create/index.d.ts +559 -86
- package/dist/api/core/geom/create/index.d.ts.map +1 -1
- package/dist/api/core/geom/query/brep.d.ts +50 -0
- package/dist/api/core/geom/query/brep.d.ts.map +1 -1
- package/dist/api/core/geom/query/curve.d.ts +58 -35
- package/dist/api/core/geom/query/curve.d.ts.map +1 -1
- package/dist/api/core/geom/query/edge.d.ts +2 -2
- package/dist/api/core/geom/query/face.d.ts +45 -0
- package/dist/api/core/geom/query/face.d.ts.map +1 -1
- package/dist/api/core/geom/update/curve.d.ts +5 -5
- package/dist/api/core/geom/update/profile.d.ts +1 -1
- package/dist/api/design/family.d.ts +152 -8
- package/dist/api/design/family.d.ts.map +1 -1
- package/dist/api/design/query/geometry/index.d.ts +27 -1
- package/dist/api/design/query/geometry/index.d.ts.map +1 -1
- package/dist/api/design/query/index.d.ts +54 -0
- package/dist/api/design/query/index.d.ts.map +1 -1
- package/dist/api/design/query/spaces.d.ts +5 -5
- package/dist/api/design/update/index.d.ts +87 -0
- package/dist/api/design/update/index.d.ts.map +1 -1
- package/dist/api/entity/referenceLine.d.ts +2 -2
- package/dist/api/entity/referenceLine.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +5 -4
- package/dist/api/entity/space.d.ts.map +1 -1
- package/dist/api/entity/story.d.ts +4 -4
- package/dist/api/program/spreadsheet.d.ts +4 -4
- package/dist/handles.d.ts +12 -3
- package/dist/handles.d.ts.map +1 -1
- package/dist/index.cjs +3044 -2707
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3007 -2707
- package/dist/index.js.map +1 -1
- package/dist/massParameters.d.ts +319 -0
- package/dist/massParameters.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/api/core/geom/create/index.ts +588 -84
- package/src/api/core/geom/query/brep.ts +51 -0
- package/src/api/core/geom/query/curve.ts +25 -2
- package/src/api/core/geom/query/edge.ts +2 -2
- package/src/api/core/geom/query/face.ts +49 -0
- package/src/api/design/family.ts +164 -8
- package/src/api/design/query/geometry/index.ts +29 -0
- package/src/api/design/query/index.ts +52 -0
- package/src/api/design/update/index.ts +94 -0
- package/src/handles.ts +15 -3
- package/src/index.ts +1 -0
- package/src/massParameters.ts +472 -0
- package/test/massParameters.test.mjs +500 -0
package/src/handles.ts
CHANGED
|
@@ -132,8 +132,16 @@ export type Vec3Handle = Handle<"vec3">
|
|
|
132
132
|
export type QuatHandle = Handle<"quat">
|
|
133
133
|
export type LineHandle = Handle<"line">
|
|
134
134
|
export type ArcHandle = Handle<"arc">
|
|
135
|
-
/**
|
|
136
|
-
|
|
135
|
+
/**
|
|
136
|
+
* A NURBS curve value handle (open B-spline curve). Minted by
|
|
137
|
+
* `core.geom.create.splineFromPoints` / `splineFromControlPoints`, accepted everywhere a
|
|
138
|
+
* {@linkcode CurveHandle} is (profileFromCurves, query.curve.*).
|
|
139
|
+
* Closed spline loops never exist as a single handle — a closed run is built
|
|
140
|
+
* directly as a profile via `core.geom.create.profileFromSplinePoints`.
|
|
141
|
+
*/
|
|
142
|
+
export type SplineHandle = Handle<"spline">
|
|
143
|
+
/** A curve is a line, an arc, or a spline — its handle is one of those kinds. */
|
|
144
|
+
export type CurveHandle = LineHandle | ArcHandle | SplineHandle
|
|
137
145
|
/**
|
|
138
146
|
* A circle value handle. A circle is a CLOSED curve — it deliberately does NOT
|
|
139
147
|
* join {@linkcode CurveHandle} (it has no stable start/end and would break the
|
|
@@ -238,7 +246,11 @@ export const Vec3Handle = handleSchema("vec3")
|
|
|
238
246
|
export const QuatHandle = handleSchema("quat")
|
|
239
247
|
export const LineHandle = handleSchema("line")
|
|
240
248
|
export const ArcHandle = handleSchema("arc")
|
|
241
|
-
export const
|
|
249
|
+
export const SplineHandle = handleSchema("spline")
|
|
250
|
+
// Explicitly typed (rather than inferred): the inferred union type prints its
|
|
251
|
+
// three fully-expanded member schemas into handles.d.ts, which is served to
|
|
252
|
+
// agents whole and has a size budget.
|
|
253
|
+
export const CurveHandle: z.ZodType<CurveHandle> = z.union([LineHandle, ArcHandle, SplineHandle])
|
|
242
254
|
export const CircleHandle = handleSchema("circle")
|
|
243
255
|
|
|
244
256
|
// BREP topology handle schemas (§2A.2.1). Prefix-shape validation only; existence,
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mass **creation-parameter records** — the recipe a parametric mass was built
|
|
5
|
+
* from, shared verbatim by plugin-core, the Snaptrude host, and the agent
|
|
6
|
+
* runtime (one schema, three repos — no hand-mirrored DTOs).
|
|
7
|
+
*
|
|
8
|
+
* A record is present on a mass committed from a `core.geom.create` brep
|
|
9
|
+
* constructor that carries a recipe (the four primitives, extrusion,
|
|
10
|
+
* revolution, loft, sweep). A fillet, chamfer, shell or offset of a **recorded**
|
|
11
|
+
* solid keeps the record: `kind` stays the base constructor and the step is
|
|
12
|
+
* appended to the record's `operations` list (see {@linkcode OperationRecord}).
|
|
13
|
+
* The record is absent — `null` — for everything
|
|
14
|
+
* else: drawn masses, imported geometry, booleans, split parts,
|
|
15
|
+
* `brepFromFaces`/`brepFromMesh`, and any operation on a solid that carried no
|
|
16
|
+
* record. Geometry there is not a pure function of a legible parameter set, and
|
|
17
|
+
* a record must never be a lie.
|
|
18
|
+
*
|
|
19
|
+
* Read one with `design.query.getParameters`.
|
|
20
|
+
*
|
|
21
|
+
* Everything here is **pure JSON** by construction — plain objects, numbers and
|
|
22
|
+
* arrays only, one `{x, y, z}` point shape everywhere (no tuples, no class
|
|
23
|
+
* instances): records are persisted by enumerable-field reflection, cloned with
|
|
24
|
+
* `structuredClone`, and round-tripped through the collaboration wire.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** A point in space. The single point shape used across every record. */
|
|
28
|
+
export type XYZ = { x: number; y: number; z: number }
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* One boundary curve of a profile record.
|
|
32
|
+
*
|
|
33
|
+
* The two spline forms are either/or, never both: a curve authored through
|
|
34
|
+
* points carries `splineThrough` (patch the points and the fit re-runs), and a
|
|
35
|
+
* curve with no through-point provenance — read back off an edge, or authored
|
|
36
|
+
* from control vertices — carries `splinePoles` and is re-minted verbatim.
|
|
37
|
+
* There is no variant holding both, so a `throughPoints` edit can never leave
|
|
38
|
+
* stale poles behind.
|
|
39
|
+
*/
|
|
40
|
+
export type CurveRecord =
|
|
41
|
+
| { type: "line"; start: XYZ; end: XYZ }
|
|
42
|
+
| { type: "arc"; start: XYZ; end: XYZ; centre: XYZ; axis: XYZ }
|
|
43
|
+
| { type: "circle"; centre: XYZ; axis: XYZ; radius: number }
|
|
44
|
+
/** Authored via splineFromPoints / profileFromSplinePoints. The through-points
|
|
45
|
+
* ARE the recipe; regeneration re-runs the versioned fit (fitVersion).
|
|
46
|
+
* Chained runs in one contour re-fit as ONE loop; use splinePoles to keep tangents. */
|
|
47
|
+
| { type: "splineThrough"; fitVersion: 1; throughPoints: XYZ[] }
|
|
48
|
+
/** No through-point provenance (authored from CVs, or read back off an edge).
|
|
49
|
+
* Regenerable verbatim — re-mint the curve from these exact data. */
|
|
50
|
+
| { type: "splinePoles"; degree: number; knots: number[]; mults: number[]; poles: XYZ[] }
|
|
51
|
+
|
|
52
|
+
/** A closed boundary loop, as an ordered list of curves. */
|
|
53
|
+
export type ProfileRecord = { curves: CurveRecord[] }
|
|
54
|
+
|
|
55
|
+
/** An outer loop plus its holes — the cross-section shape of a recipe. */
|
|
56
|
+
export type ContourRecord = { outer: ProfileRecord; holes: ProfileRecord[] }
|
|
57
|
+
|
|
58
|
+
/** Optional loft behaviour switches, mirroring `core.geom.create.brepFromLoft`. */
|
|
59
|
+
export type LoftOptions = {
|
|
60
|
+
compatibility?: "strict" | "auto"
|
|
61
|
+
seamAlignment?: "authored" | "auto"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Optional sweep scale law and corner transition, mirroring `core.geom.create.brepFromSweep`. */
|
|
65
|
+
export type SweepOptions = {
|
|
66
|
+
startScale?: number
|
|
67
|
+
endScale?: number
|
|
68
|
+
scales?: number[]
|
|
69
|
+
transition?: "miter" | "round" | { bevel: number }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A face's surface kind — the vocabulary of `core.geom.query.face.getSurfaceKind`. */
|
|
73
|
+
export type SurfaceKind = "plane" | "cylinder" | "cone" | "sphere" | "torus" | "spline"
|
|
74
|
+
|
|
75
|
+
/** An edge's curve kind. Both spline forms of {@linkcode CurveRecord} report `"spline"`. */
|
|
76
|
+
export type CurveKind = "line" | "arc" | "circle" | "spline"
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Which EDGE of the input solid an operation used: its index in
|
|
80
|
+
* `core.geom.query.brep.listEdges` order at authoring time, the indices of the
|
|
81
|
+
* two faces it lies between, and its curve kind. This is topology, not
|
|
82
|
+
* coordinates — it survives a scalar edit of the base recipe (which moves every
|
|
83
|
+
* edge) and trips on a reorder or a topology change. Read-only: to blend a
|
|
84
|
+
* different edge, re-select it on the new shape and re-apply the operation.
|
|
85
|
+
*/
|
|
86
|
+
export type EdgeSelector = { index: number; faces: [number, number]; curve: CurveKind }
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Which FACE of the input solid an operation used: its index in
|
|
90
|
+
* `core.geom.query.brep.listFaces` order, its surface kind, and the number of
|
|
91
|
+
* edges in its outer loop. Read-only, like {@linkcode EdgeSelector}.
|
|
92
|
+
*/
|
|
93
|
+
export type FaceSelector = { index: number; kind: SurfaceKind; edgeCount: number }
|
|
94
|
+
|
|
95
|
+
/** The input solid's topology at authoring time — the counts a replay checks first. */
|
|
96
|
+
export type TopologyCounts = { faceCount: number; edgeCount: number }
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* One kernel operation applied to the base recipe's solid, in order. `input`
|
|
100
|
+
* pins the topology the operation was authored against, so a base edit that
|
|
101
|
+
* changes the topology is refused rather than mis-applied.
|
|
102
|
+
*
|
|
103
|
+
* Edit one by patching the whole list back:
|
|
104
|
+
* `design.update.parameters(mass, { operations })`.
|
|
105
|
+
*/
|
|
106
|
+
export type OperationRecord =
|
|
107
|
+
| { op: "fillet"; edges: EdgeSelector[]; radius: number; input: TopologyCounts }
|
|
108
|
+
| { op: "chamfer"; edges: EdgeSelector[]; distance: number; input: TopologyCounts }
|
|
109
|
+
| { op: "shell"; openFaces: FaceSelector[]; thickness: number; input: TopologyCounts }
|
|
110
|
+
| { op: "offset"; distance: number; input: TopologyCounts }
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* A mass's creation recipe: the constructor `kind`, a schema `version`, the
|
|
114
|
+
* `values` that constructor was called with, and the kernel `operations`
|
|
115
|
+
* (fillet / chamfer / shell / offset) applied on top, in order. Points and axes
|
|
116
|
+
* are in the mass's own local frame when stored; `design.query.getParameters`
|
|
117
|
+
* returns them in world coordinates. `operations` is frame-free. One variant
|
|
118
|
+
* per constructor `kind`; its `values` are that constructor's own arguments.
|
|
119
|
+
*
|
|
120
|
+
* `kind` stays the base constructor even after operations: a shelled, filleted
|
|
121
|
+
* sphere is still `{ kind: "sphere", operations: [shell, fillet] }`.
|
|
122
|
+
*/
|
|
123
|
+
export type MassParametersRecord =
|
|
124
|
+
| {
|
|
125
|
+
kind: "sphere"
|
|
126
|
+
version: 1
|
|
127
|
+
values: { centre: XYZ; radius: number }
|
|
128
|
+
operations?: OperationRecord[]
|
|
129
|
+
}
|
|
130
|
+
| {
|
|
131
|
+
kind: "cylinder"
|
|
132
|
+
version: 1
|
|
133
|
+
values: { base: XYZ; axis: XYZ; radius: number; height: number }
|
|
134
|
+
operations?: OperationRecord[]
|
|
135
|
+
}
|
|
136
|
+
| {
|
|
137
|
+
kind: "cone"
|
|
138
|
+
version: 1
|
|
139
|
+
values: { base: XYZ; axis: XYZ; baseRadius: number; topRadius: number; height: number }
|
|
140
|
+
operations?: OperationRecord[]
|
|
141
|
+
}
|
|
142
|
+
| {
|
|
143
|
+
kind: "torus"
|
|
144
|
+
version: 1
|
|
145
|
+
values: { centre: XYZ; axis: XYZ; majorRadius: number; minorRadius: number }
|
|
146
|
+
operations?: OperationRecord[]
|
|
147
|
+
}
|
|
148
|
+
| {
|
|
149
|
+
kind: "extrusion"
|
|
150
|
+
version: 1
|
|
151
|
+
values: { contour: ContourRecord; direction: XYZ; amount: number }
|
|
152
|
+
operations?: OperationRecord[]
|
|
153
|
+
}
|
|
154
|
+
| {
|
|
155
|
+
kind: "revolution"
|
|
156
|
+
version: 1
|
|
157
|
+
values: {
|
|
158
|
+
contour: ContourRecord
|
|
159
|
+
axisOrigin: XYZ
|
|
160
|
+
axisDirection: XYZ
|
|
161
|
+
angleInDegrees: number
|
|
162
|
+
}
|
|
163
|
+
operations?: OperationRecord[]
|
|
164
|
+
}
|
|
165
|
+
| {
|
|
166
|
+
kind: "loft"
|
|
167
|
+
version: 1
|
|
168
|
+
values: { sections: ContourRecord[]; options?: LoftOptions }
|
|
169
|
+
operations?: OperationRecord[]
|
|
170
|
+
}
|
|
171
|
+
| {
|
|
172
|
+
kind: "sweep"
|
|
173
|
+
version: 1
|
|
174
|
+
values: { profile: ContourRecord; path: XYZ[]; options?: SweepOptions }
|
|
175
|
+
operations?: OperationRecord[]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* One value of a {@linkcode MassParametersPatch} — whatever a record's `values`
|
|
180
|
+
* key (or `operations`) may hold. Scalars and points merge by key; every array
|
|
181
|
+
* form replaces the list whole.
|
|
182
|
+
*/
|
|
183
|
+
export type ParameterPatchValue =
|
|
184
|
+
| number
|
|
185
|
+
| XYZ
|
|
186
|
+
| XYZ[]
|
|
187
|
+
| ContourRecord
|
|
188
|
+
| ContourRecord[]
|
|
189
|
+
| LoftOptions
|
|
190
|
+
| SweepOptions
|
|
191
|
+
| OperationRecord[]
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The argument of `design.update.parameters`: either a **partial** of a
|
|
195
|
+
* record's `values` (plus an optional `operations` list) — keys you leave out
|
|
196
|
+
* stay as they are — or the **whole record** you read from
|
|
197
|
+
* `design.query.getParameters`, edited. `kind` and `version` are immutable.
|
|
198
|
+
*/
|
|
199
|
+
export type MassParametersPatch = MassParametersRecord | Record<string, ParameterPatchValue>
|
|
200
|
+
|
|
201
|
+
// ── Schemas ─────────────────────────────────────────────────────────────────
|
|
202
|
+
// Array bounds are CONTRACT, not silent truncation: a record beyond them fails
|
|
203
|
+
// validation. They keep a record inside the serialization budget of the save
|
|
204
|
+
// and collaboration payloads it rides in. They bind RECORDS only — the shipped
|
|
205
|
+
// creator schemas (loft sections, sweep path, fillet/chamfer edges, shell faces)
|
|
206
|
+
// stay uncapped as in 0.9.x; an over-cap call builds and the host simply mints
|
|
207
|
+
// no record for it (the recipe-less fallback).
|
|
208
|
+
|
|
209
|
+
/** Maximum through-points in one authored spline curve record. */
|
|
210
|
+
export const MAX_SPLINE_THROUGH_POINTS = 256
|
|
211
|
+
/** Maximum control points in one exact-NURBS spline curve record. */
|
|
212
|
+
export const MAX_SPLINE_POLES = 512
|
|
213
|
+
/** Maximum path points in a sweep record. */
|
|
214
|
+
export const MAX_SWEEP_PATH_POINTS = 512
|
|
215
|
+
/** Maximum cross-sections in a loft record. */
|
|
216
|
+
export const MAX_LOFT_SECTIONS = 32
|
|
217
|
+
/** Maximum kernel operations chained onto one recipe. */
|
|
218
|
+
export const MAX_OPERATIONS = 8
|
|
219
|
+
/** Maximum boundary curves in one profile loop record. */
|
|
220
|
+
export const MAX_PROFILE_CURVES = 256
|
|
221
|
+
/** Maximum hole loops in one contour record. */
|
|
222
|
+
export const MAX_CONTOUR_HOLES = 64
|
|
223
|
+
/** Maximum edges one fillet/chamfer operation may select. */
|
|
224
|
+
export const MAX_OPERATION_EDGES = 64
|
|
225
|
+
/** Maximum faces one shell operation may open. */
|
|
226
|
+
export const MAX_OPERATION_FACES = 32
|
|
227
|
+
|
|
228
|
+
/** A point in space — `{ x, y, z }`, all finite. */
|
|
229
|
+
export const XYZ: z.ZodType<XYZ, XYZ> = z.strictObject({
|
|
230
|
+
x: z.number().finite(),
|
|
231
|
+
y: z.number().finite(),
|
|
232
|
+
z: z.number().finite(),
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
/** One boundary curve of a profile record. See {@linkcode CurveRecord}. */
|
|
236
|
+
export const CurveRecord: z.ZodType<CurveRecord, CurveRecord> = z.discriminatedUnion("type", [
|
|
237
|
+
z.strictObject({ type: z.literal("line"), start: XYZ, end: XYZ }),
|
|
238
|
+
z.strictObject({ type: z.literal("arc"), start: XYZ, end: XYZ, centre: XYZ, axis: XYZ }),
|
|
239
|
+
z.strictObject({
|
|
240
|
+
type: z.literal("circle"),
|
|
241
|
+
centre: XYZ,
|
|
242
|
+
axis: XYZ,
|
|
243
|
+
radius: z.number().finite().positive(),
|
|
244
|
+
}),
|
|
245
|
+
z.strictObject({
|
|
246
|
+
type: z.literal("splineThrough"),
|
|
247
|
+
fitVersion: z.literal(1),
|
|
248
|
+
throughPoints: z.array(XYZ).min(2).max(MAX_SPLINE_THROUGH_POINTS),
|
|
249
|
+
}),
|
|
250
|
+
z.strictObject({
|
|
251
|
+
type: z.literal("splinePoles"),
|
|
252
|
+
degree: z.number().int().positive(),
|
|
253
|
+
knots: z.array(z.number().finite()).min(2),
|
|
254
|
+
mults: z.array(z.number().int().positive()).min(2),
|
|
255
|
+
poles: z.array(XYZ).min(2).max(MAX_SPLINE_POLES),
|
|
256
|
+
}),
|
|
257
|
+
])
|
|
258
|
+
|
|
259
|
+
/** A closed boundary loop. See {@linkcode ProfileRecord}. */
|
|
260
|
+
export const ProfileRecord: z.ZodType<ProfileRecord, ProfileRecord> = z.strictObject({
|
|
261
|
+
curves: z.array(CurveRecord).min(1).max(MAX_PROFILE_CURVES),
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
/** An outer loop plus its holes. See {@linkcode ContourRecord}. */
|
|
265
|
+
export const ContourRecord: z.ZodType<ContourRecord, ContourRecord> = z.strictObject({
|
|
266
|
+
outer: ProfileRecord,
|
|
267
|
+
holes: z.array(ProfileRecord).max(MAX_CONTOUR_HOLES),
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
/** Optional loft behaviour switches. See {@linkcode LoftOptions}. */
|
|
271
|
+
export const LoftOptions: z.ZodType<LoftOptions, LoftOptions> = z.strictObject({
|
|
272
|
+
compatibility: z.enum(["strict", "auto"]).optional(),
|
|
273
|
+
seamAlignment: z.enum(["authored", "auto"]).optional(),
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
/** Optional sweep scale law and corner transition. See {@linkcode SweepOptions}. */
|
|
277
|
+
export const SweepOptions: z.ZodType<SweepOptions, SweepOptions> = z.strictObject({
|
|
278
|
+
startScale: z.number().finite().optional(),
|
|
279
|
+
endScale: z.number().finite().optional(),
|
|
280
|
+
scales: z.array(z.number().finite()).optional(),
|
|
281
|
+
transition: z
|
|
282
|
+
.union([
|
|
283
|
+
z.literal("miter"),
|
|
284
|
+
z.literal("round"),
|
|
285
|
+
z.strictObject({ bevel: z.number().finite() }),
|
|
286
|
+
])
|
|
287
|
+
.optional(),
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
const FaceIndex = z.number().int().nonnegative()
|
|
291
|
+
|
|
292
|
+
/** See {@linkcode EdgeSelector}. */
|
|
293
|
+
export const EdgeSelector: z.ZodType<EdgeSelector, EdgeSelector> = z.strictObject({
|
|
294
|
+
index: FaceIndex,
|
|
295
|
+
faces: z.tuple([FaceIndex, FaceIndex]),
|
|
296
|
+
curve: z.enum(["line", "arc", "circle", "spline"]),
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
/** See {@linkcode FaceSelector}. */
|
|
300
|
+
export const FaceSelector: z.ZodType<FaceSelector, FaceSelector> = z.strictObject({
|
|
301
|
+
index: FaceIndex,
|
|
302
|
+
kind: z.enum(["plane", "cylinder", "cone", "sphere", "torus", "spline"]),
|
|
303
|
+
edgeCount: z.number().int().positive(),
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
/** See {@linkcode TopologyCounts}. */
|
|
307
|
+
export const TopologyCounts: z.ZodType<TopologyCounts, TopologyCounts> = z.strictObject({
|
|
308
|
+
faceCount: z.number().int().positive(),
|
|
309
|
+
edgeCount: z.number().int().positive(),
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
/** See {@linkcode OperationRecord}. */
|
|
313
|
+
export const OperationRecord: z.ZodType<OperationRecord, OperationRecord> = z.discriminatedUnion(
|
|
314
|
+
"op",
|
|
315
|
+
[
|
|
316
|
+
z.strictObject({
|
|
317
|
+
op: z.literal("fillet"),
|
|
318
|
+
edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
|
|
319
|
+
radius: z.number().finite().positive(),
|
|
320
|
+
input: TopologyCounts,
|
|
321
|
+
}),
|
|
322
|
+
z.strictObject({
|
|
323
|
+
op: z.literal("chamfer"),
|
|
324
|
+
edges: z.array(EdgeSelector).min(1).max(MAX_OPERATION_EDGES),
|
|
325
|
+
distance: z.number().finite().positive(),
|
|
326
|
+
input: TopologyCounts,
|
|
327
|
+
}),
|
|
328
|
+
z.strictObject({
|
|
329
|
+
op: z.literal("shell"),
|
|
330
|
+
openFaces: z.array(FaceSelector).min(1).max(MAX_OPERATION_FACES),
|
|
331
|
+
thickness: z.number().finite().positive(),
|
|
332
|
+
input: TopologyCounts,
|
|
333
|
+
}),
|
|
334
|
+
z.strictObject({
|
|
335
|
+
op: z.literal("offset"),
|
|
336
|
+
distance: z
|
|
337
|
+
.number()
|
|
338
|
+
.finite()
|
|
339
|
+
.refine((value) => value !== 0, { message: "distance must be non-zero" }),
|
|
340
|
+
input: TopologyCounts,
|
|
341
|
+
}),
|
|
342
|
+
],
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
// `operations` rides beside `values` on every kind — additive and optional, so
|
|
346
|
+
// `version` stays 1. A 4A-era reader safeParse-fails on a record carrying one
|
|
347
|
+
// and degrades the mass to non-parametric; it never blocks a load.
|
|
348
|
+
// No `.min(1)`: `design.update.parameters` documents `{ operations: [] }` as the
|
|
349
|
+
// drop-every-operation idiom, and the whole record you read back — edited to an
|
|
350
|
+
// empty list — must patch the same way. The host normalises `[]` to an absent
|
|
351
|
+
// key before storing, so a stored record never carries one.
|
|
352
|
+
const RecordOperations = z.array(OperationRecord).max(MAX_OPERATIONS).optional()
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* A mass's creation recipe. See {@linkcode MassParametersRecord}.
|
|
356
|
+
*
|
|
357
|
+
* `version` is a literal `1`: a restore that reads an unknown version fails
|
|
358
|
+
* `safeParse` and the mass degrades to non-parametric — editability is lost,
|
|
359
|
+
* geometry never is, and load is never blocked. Future versions add a migration
|
|
360
|
+
* at the restore site.
|
|
361
|
+
*/
|
|
362
|
+
export const MassParametersRecord: z.ZodType<MassParametersRecord, MassParametersRecord> = z.discriminatedUnion("kind", [
|
|
363
|
+
z.strictObject({
|
|
364
|
+
kind: z.literal("sphere"),
|
|
365
|
+
version: z.literal(1),
|
|
366
|
+
values: z.strictObject({ centre: XYZ, radius: z.number().finite().positive() }),
|
|
367
|
+
operations: RecordOperations,
|
|
368
|
+
}),
|
|
369
|
+
z.strictObject({
|
|
370
|
+
kind: z.literal("cylinder"),
|
|
371
|
+
version: z.literal(1),
|
|
372
|
+
values: z.strictObject({
|
|
373
|
+
base: XYZ,
|
|
374
|
+
axis: XYZ,
|
|
375
|
+
radius: z.number().finite().positive(),
|
|
376
|
+
height: z.number().finite().positive(),
|
|
377
|
+
}),
|
|
378
|
+
operations: RecordOperations,
|
|
379
|
+
}),
|
|
380
|
+
z.strictObject({
|
|
381
|
+
kind: z.literal("cone"),
|
|
382
|
+
version: z.literal(1),
|
|
383
|
+
values: z.strictObject({
|
|
384
|
+
base: XYZ,
|
|
385
|
+
axis: XYZ,
|
|
386
|
+
baseRadius: z.number().finite().positive(),
|
|
387
|
+
topRadius: z.number().finite().nonnegative(),
|
|
388
|
+
height: z.number().finite().positive(),
|
|
389
|
+
}),
|
|
390
|
+
operations: RecordOperations,
|
|
391
|
+
}),
|
|
392
|
+
z.strictObject({
|
|
393
|
+
kind: z.literal("torus"),
|
|
394
|
+
version: z.literal(1),
|
|
395
|
+
values: z.strictObject({
|
|
396
|
+
centre: XYZ,
|
|
397
|
+
axis: XYZ,
|
|
398
|
+
majorRadius: z.number().finite().positive(),
|
|
399
|
+
minorRadius: z.number().finite().positive(),
|
|
400
|
+
}),
|
|
401
|
+
operations: RecordOperations,
|
|
402
|
+
}),
|
|
403
|
+
z.strictObject({
|
|
404
|
+
kind: z.literal("extrusion"),
|
|
405
|
+
version: z.literal(1),
|
|
406
|
+
values: z.strictObject({
|
|
407
|
+
contour: ContourRecord,
|
|
408
|
+
direction: XYZ,
|
|
409
|
+
amount: z.number().finite(),
|
|
410
|
+
}),
|
|
411
|
+
operations: RecordOperations,
|
|
412
|
+
}),
|
|
413
|
+
z.strictObject({
|
|
414
|
+
kind: z.literal("revolution"),
|
|
415
|
+
version: z.literal(1),
|
|
416
|
+
values: z.strictObject({
|
|
417
|
+
contour: ContourRecord,
|
|
418
|
+
axisOrigin: XYZ,
|
|
419
|
+
axisDirection: XYZ,
|
|
420
|
+
angleInDegrees: z.number().finite().positive().max(360),
|
|
421
|
+
}),
|
|
422
|
+
operations: RecordOperations,
|
|
423
|
+
}),
|
|
424
|
+
z.strictObject({
|
|
425
|
+
kind: z.literal("loft"),
|
|
426
|
+
version: z.literal(1),
|
|
427
|
+
values: z.strictObject({
|
|
428
|
+
sections: z.array(ContourRecord).min(2).max(MAX_LOFT_SECTIONS),
|
|
429
|
+
options: LoftOptions.optional(),
|
|
430
|
+
}),
|
|
431
|
+
operations: RecordOperations,
|
|
432
|
+
}),
|
|
433
|
+
z.strictObject({
|
|
434
|
+
kind: z.literal("sweep"),
|
|
435
|
+
version: z.literal(1),
|
|
436
|
+
values: z.strictObject({
|
|
437
|
+
profile: ContourRecord,
|
|
438
|
+
path: z.array(XYZ).min(2).max(MAX_SWEEP_PATH_POINTS),
|
|
439
|
+
options: SweepOptions.optional(),
|
|
440
|
+
}),
|
|
441
|
+
operations: RecordOperations,
|
|
442
|
+
}),
|
|
443
|
+
])
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* One value of a parameter patch. See {@linkcode ParameterPatchValue}.
|
|
447
|
+
*
|
|
448
|
+
* Deliberately a CLOSED union of the shapes a record's `values` actually hold —
|
|
449
|
+
* no `z.unknown()`, nothing recursive: an unrecognised value is a VALIDATION at
|
|
450
|
+
* the wire, not a silent write of nonsense onto a mass.
|
|
451
|
+
*/
|
|
452
|
+
export const ParameterPatchValue: z.ZodType<ParameterPatchValue, ParameterPatchValue> = z.union([
|
|
453
|
+
z.number().finite(),
|
|
454
|
+
XYZ,
|
|
455
|
+
z.array(XYZ).max(MAX_SWEEP_PATH_POINTS),
|
|
456
|
+
ContourRecord,
|
|
457
|
+
z.array(ContourRecord).max(MAX_LOFT_SECTIONS),
|
|
458
|
+
LoftOptions,
|
|
459
|
+
SweepOptions,
|
|
460
|
+
z.array(OperationRecord).max(MAX_OPERATIONS),
|
|
461
|
+
])
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* The argument of `design.update.parameters`. See {@linkcode MassParametersPatch}.
|
|
465
|
+
* The full-record form is recognised by carrying both `kind` and `values`;
|
|
466
|
+
* which keys a kind actually has is checked host-side, where the error can name
|
|
467
|
+
* them.
|
|
468
|
+
*/
|
|
469
|
+
export const MassParametersPatch: z.ZodType<MassParametersPatch, MassParametersPatch> = z.union([
|
|
470
|
+
MassParametersRecord,
|
|
471
|
+
z.record(z.string(), ParameterPatchValue),
|
|
472
|
+
])
|