@snaptrude/plugin-core 0.2.1 → 0.2.2

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.
@@ -0,0 +1,277 @@
1
+ import * as z from "zod"
2
+ import { PluginApiReturn } from "../../types"
3
+
4
+ /**
5
+ * Buildable Envelope management — create and update parametric zoning envelopes.
6
+ *
7
+ * A **buildable envelope** is the regulated volume inside which a building may
8
+ * be massed. The host owns envelope identity: {@linkcode PluginBuildableEnvelopeApi.create create}
9
+ * mints a `buildableEnvelopeId` and returns it; {@linkcode PluginBuildableEnvelopeApi.update update}
10
+ * requires that id to target the existing envelope.
11
+ *
12
+ * Accessed via `snaptrude.entity.buildableEnvelope`.
13
+ */
14
+ export abstract class PluginBuildableEnvelopeApi {
15
+ constructor() {}
16
+
17
+ /**
18
+ * Create a new parametric buildable envelope.
19
+ *
20
+ * @param args - A {@linkcode PluginBuildableEnvelopeCreateArgs} object.
21
+ * @returns A {@linkcode PluginBuildableEnvelopeCreateResult} with the
22
+ * `buildableEnvelopeId` of the created envelope.
23
+ * @throws If validation fails or generation produces no renderable geometry.
24
+ *
25
+ * # Example
26
+ * ```ts
27
+ * const { buildableEnvelopeId } = await snaptrude.entity.buildableEnvelope.create({
28
+ * sitePolygon: [
29
+ * { x: 0, z: 0 },
30
+ * { x: 100, z: 0 },
31
+ * { x: 100, z: 80 },
32
+ * { x: 0, z: 80 },
33
+ * ],
34
+ * lengthUnit: "ft",
35
+ * setbacks: [
36
+ * { aboveHeight: 0, front: 10, side: 5, rear: 10 },
37
+ * { aboveHeight: 100, front: 20, side: 10, rear: 20 },
38
+ * ],
39
+ * verticalCap: { kind: "max_height", maxHeight: 150 },
40
+ * floorToFloor: 12,
41
+ * })
42
+ * ```
43
+ */
44
+ public abstract create(
45
+ args: PluginBuildableEnvelopeCreateArgs
46
+ ): PluginApiReturn<PluginBuildableEnvelopeCreateResult>
47
+
48
+ /**
49
+ * Update an existing parametric buildable envelope.
50
+ *
51
+ * @param args - A {@linkcode PluginBuildableEnvelopeUpdateArgs} object.
52
+ * `buildableEnvelopeId` is required and must match an existing envelope on
53
+ * the canvas.
54
+ * @returns A {@linkcode PluginBuildableEnvelopeUpdateResult} with the
55
+ * `buildableEnvelopeId` of the updated envelope.
56
+ * @throws If validation fails, the envelope does not exist, or generation
57
+ * produces no renderable geometry.
58
+ *
59
+ * # Example
60
+ * ```ts
61
+ * const { buildableEnvelopeId } = await snaptrude.entity.buildableEnvelope.update({
62
+ * buildableEnvelopeId: existingId,
63
+ * sitePolygon: [
64
+ * { x: 0, z: 0 },
65
+ * { x: 100, z: 0 },
66
+ * { x: 100, z: 80 },
67
+ * { x: 0, z: 80 },
68
+ * ],
69
+ * lengthUnit: "ft",
70
+ * setbacks: [{ aboveHeight: 0, front: 10, side: 5, rear: 10 }],
71
+ * verticalCap: { kind: "max_height", maxHeight: 175 },
72
+ * floorToFloor: 12,
73
+ * })
74
+ * ```
75
+ */
76
+ public abstract update(
77
+ args: PluginBuildableEnvelopeUpdateArgs
78
+ ): PluginApiReturn<PluginBuildableEnvelopeUpdateResult>
79
+ }
80
+
81
+ /**
82
+ * Site polygon vertex in the request `lengthUnit`.
83
+ *
84
+ * Vertices may be passed as `{x, z}` objects or `[x, z]` tuples. Numeric
85
+ * values must be finite (no `NaN` or `±Infinity`).
86
+ */
87
+ export const PluginBuildableEnvelopePolygonVertex = z.union([
88
+ z.object({ x: z.number().finite(), z: z.number().finite() }).strict(),
89
+ z.tuple([z.number().finite(), z.number().finite()]),
90
+ ])
91
+
92
+ export type PluginBuildableEnvelopePolygonVertex = z.infer<
93
+ typeof PluginBuildableEnvelopePolygonVertex
94
+ >
95
+
96
+ /**
97
+ * Vertical cap for a buildable envelope.
98
+ *
99
+ * Use exactly one shape:
100
+ * - `{ kind: "max_height", maxHeight }`
101
+ * - `{ kind: "max_floors", maxFloors }`
102
+ *
103
+ * Floor-to-floor height is not nested here; it is always supplied as the
104
+ * top-level `floorToFloor` argument.
105
+ */
106
+ export const PluginBuildableEnvelopeVerticalCap = z.discriminatedUnion("kind", [
107
+ z.object({
108
+ kind: z.literal("max_height"),
109
+ maxHeight: z.number().finite().positive(),
110
+ }).strict(),
111
+ z.object({
112
+ kind: z.literal("max_floors"),
113
+ maxFloors: z.number().finite().int().positive(),
114
+ }).strict(),
115
+ ])
116
+
117
+ export type PluginBuildableEnvelopeVerticalCap = z.infer<
118
+ typeof PluginBuildableEnvelopeVerticalCap
119
+ >
120
+
121
+ /**
122
+ * One tier of a buildable envelope's setback profile.
123
+ *
124
+ * Tiers are ordered by `aboveHeight`. The first tier (index 0) must have
125
+ * `aboveHeight: 0` and describes the ground footprint; each subsequent tier
126
+ * describes the complete setback at a strictly greater height. Each tier
127
+ * carries its own `front`, `side`, and `rear` values — there is no
128
+ * inheritance from earlier tiers.
129
+ *
130
+ * All numeric values must be finite and nonnegative, in the request
131
+ * `lengthUnit`.
132
+ *
133
+ * | Property | Type | Description |
134
+ * |---|---|---|
135
+ * | `aboveHeight` | `number` | Height at or above which this tier applies; the ground tier uses `0` |
136
+ * | `front` | `number` | Front setback for this tier |
137
+ * | `side` | `number` | Side setback for this tier |
138
+ * | `rear` | `number` | Rear setback for this tier |
139
+ */
140
+ export const PluginBuildableEnvelopeSetbackTier = z.object({
141
+ aboveHeight: z.number().finite().nonnegative(),
142
+ front: z.number().finite().nonnegative(),
143
+ side: z.number().finite().nonnegative(),
144
+ rear: z.number().finite().nonnegative(),
145
+ }).strict()
146
+
147
+ export type PluginBuildableEnvelopeSetbackTier = z.infer<
148
+ typeof PluginBuildableEnvelopeSetbackTier
149
+ >
150
+
151
+ // Enforces setback tier ordering invariants on the parsed args shape:
152
+ // - setbacks[0].aboveHeight === 0
153
+ // - aboveHeight strictly increasing thereafter
154
+ // Length >= 1 is enforced earlier by z.array(...).min(1).
155
+ function refineSetbackTiers(
156
+ args: { setbacks: PluginBuildableEnvelopeSetbackTier[] },
157
+ ctx: z.RefinementCtx
158
+ ): void {
159
+ const tiers = args.setbacks
160
+ if (tiers.length === 0) return
161
+ if (tiers[0].aboveHeight !== 0) {
162
+ ctx.addIssue({
163
+ code: z.ZodIssueCode.custom,
164
+ path: ["setbacks", 0, "aboveHeight"],
165
+ message: "Ground tier required: setbacks[0].aboveHeight must be 0.",
166
+ })
167
+ }
168
+ for (let i = 1; i < tiers.length; i++) {
169
+ if (!(tiers[i].aboveHeight > tiers[i - 1].aboveHeight)) {
170
+ ctx.addIssue({
171
+ code: z.ZodIssueCode.custom,
172
+ path: ["setbacks", i, "aboveHeight"],
173
+ message:
174
+ "Setback tiers must be ordered by strictly increasing aboveHeight.",
175
+ })
176
+ }
177
+ }
178
+ }
179
+
180
+ /**
181
+ * Arguments for {@linkcode PluginBuildableEnvelopeApi.create}.
182
+ *
183
+ * Strict schema. The host owns identity — no `buildableEnvelopeId` is accepted
184
+ * on create; the id is minted by the host and returned in
185
+ * {@linkcode PluginBuildableEnvelopeCreateResult}.
186
+ *
187
+ * | Property | Type | Description |
188
+ * |---|---|---|
189
+ * | `sitePolygon` | {@linkcode PluginBuildableEnvelopePolygonVertex}`[]` | Site polygon vertices in `lengthUnit`; minimum 3 vertices |
190
+ * | `lengthUnit` | `"ft" \| "m"` | Unit used by all length fields |
191
+ * | `setbacks` | {@linkcode PluginBuildableEnvelopeSetbackTier}`[]` | Setback profile, ground tier first; minimum 1 tier |
192
+ * | `verticalCap` | {@linkcode PluginBuildableEnvelopeVerticalCap} | Maximum height or floor count |
193
+ * | `floorToFloor` | `number` | Required floor-to-floor height in `lengthUnit` |
194
+ * | `farRatio` | `number?` | Optional FAR value, positive when provided |
195
+ * | `lotCoverageMaxPct` | `number?` | Optional lot coverage cap, `0..100` |
196
+ */
197
+ export const PluginBuildableEnvelopeCreateArgs = z
198
+ .object({
199
+ sitePolygon: z.array(PluginBuildableEnvelopePolygonVertex).min(3),
200
+ lengthUnit: z.union([z.literal("ft"), z.literal("m")]),
201
+ setbacks: z.array(PluginBuildableEnvelopeSetbackTier).min(1),
202
+ verticalCap: PluginBuildableEnvelopeVerticalCap,
203
+ floorToFloor: z.number().finite().positive(),
204
+ farRatio: z.number().finite().positive().optional(),
205
+ lotCoverageMaxPct: z.number().finite().min(0).max(100).optional(),
206
+ })
207
+ .strict()
208
+ .superRefine(refineSetbackTiers)
209
+
210
+ export type PluginBuildableEnvelopeCreateArgs = z.infer<
211
+ typeof PluginBuildableEnvelopeCreateArgs
212
+ >
213
+
214
+ /**
215
+ * Result of {@linkcode PluginBuildableEnvelopeApi.create}.
216
+ *
217
+ * | Property | Type | Description |
218
+ * |---|---|---|
219
+ * | `buildableEnvelopeId` | `string` | Non-empty unique ID of the created buildable envelope |
220
+ */
221
+ export const PluginBuildableEnvelopeCreateResult = z.object({
222
+ buildableEnvelopeId: z.string().min(1),
223
+ }).strict()
224
+
225
+ export type PluginBuildableEnvelopeCreateResult = z.infer<
226
+ typeof PluginBuildableEnvelopeCreateResult
227
+ >
228
+
229
+ /**
230
+ * Arguments for {@linkcode PluginBuildableEnvelopeApi.update}.
231
+ *
232
+ * Strict schema. `buildableEnvelopeId` is required and identifies the prior
233
+ * envelope on the canvas to update.
234
+ *
235
+ * | Property | Type | Description |
236
+ * |---|---|---|
237
+ * | `buildableEnvelopeId` | `string` | Existing envelope ID to update; non-empty |
238
+ * | `sitePolygon` | {@linkcode PluginBuildableEnvelopePolygonVertex}`[]` | Site polygon vertices in `lengthUnit`; minimum 3 vertices |
239
+ * | `lengthUnit` | `"ft" \| "m"` | Unit used by all length fields |
240
+ * | `setbacks` | {@linkcode PluginBuildableEnvelopeSetbackTier}`[]` | Setback profile, ground tier first; minimum 1 tier |
241
+ * | `verticalCap` | {@linkcode PluginBuildableEnvelopeVerticalCap} | Maximum height or floor count |
242
+ * | `floorToFloor` | `number` | Required floor-to-floor height in `lengthUnit` |
243
+ * | `farRatio` | `number?` | Optional FAR value, positive when provided |
244
+ * | `lotCoverageMaxPct` | `number?` | Optional lot coverage cap, `0..100` |
245
+ */
246
+ export const PluginBuildableEnvelopeUpdateArgs = z
247
+ .object({
248
+ buildableEnvelopeId: z.string().min(1),
249
+ sitePolygon: z.array(PluginBuildableEnvelopePolygonVertex).min(3),
250
+ lengthUnit: z.union([z.literal("ft"), z.literal("m")]),
251
+ setbacks: z.array(PluginBuildableEnvelopeSetbackTier).min(1),
252
+ verticalCap: PluginBuildableEnvelopeVerticalCap,
253
+ floorToFloor: z.number().finite().positive(),
254
+ farRatio: z.number().finite().positive().optional(),
255
+ lotCoverageMaxPct: z.number().finite().min(0).max(100).optional(),
256
+ })
257
+ .strict()
258
+ .superRefine(refineSetbackTiers)
259
+
260
+ export type PluginBuildableEnvelopeUpdateArgs = z.infer<
261
+ typeof PluginBuildableEnvelopeUpdateArgs
262
+ >
263
+
264
+ /**
265
+ * Result of {@linkcode PluginBuildableEnvelopeApi.update}.
266
+ *
267
+ * | Property | Type | Description |
268
+ * |---|---|---|
269
+ * | `buildableEnvelopeId` | `string` | Non-empty unique ID of the updated buildable envelope |
270
+ */
271
+ export const PluginBuildableEnvelopeUpdateResult = z.object({
272
+ buildableEnvelopeId: z.string().min(1),
273
+ }).strict()
274
+
275
+ export type PluginBuildableEnvelopeUpdateResult = z.infer<
276
+ typeof PluginBuildableEnvelopeUpdateResult
277
+ >
@@ -1,3 +1,4 @@
1
+ import { PluginBuildableEnvelopeApi } from "./buildableEnvelope"
1
2
  import { PluginDepartmentApi } from "./department"
2
3
  import { PluginReferenceLineApi } from "./referenceLine"
3
4
  import { PluginSpaceApi } from "./space"
@@ -10,6 +11,7 @@ import { PluginStoryApi } from "./story"
10
11
  * - {@linkcode PluginEntityApi.story} — Create, query, and update stories (floors)
11
12
  * - {@linkcode PluginEntityApi.referenceLine} — Create, query, and delete reference lines
12
13
  * - {@linkcode PluginEntityApi.department} — Create and query departments
14
+ * - {@linkcode PluginEntityApi.buildableEnvelope} — Create or update parametric buildable envelopes
13
15
  */
14
16
  export abstract class PluginEntityApi {
15
17
  /** Space (room/mass) operations. See {@linkcode PluginSpaceApi}. */
@@ -20,10 +22,13 @@ export abstract class PluginEntityApi {
20
22
  public abstract referenceLine: PluginReferenceLineApi
21
23
  /** Department operations. See {@linkcode PluginDepartmentApi}. */
22
24
  public abstract department: PluginDepartmentApi
25
+ /** Buildable Envelope operations. See {@linkcode PluginBuildableEnvelopeApi}. */
26
+ public abstract buildableEnvelope: PluginBuildableEnvelopeApi
23
27
 
24
28
  constructor() {}
25
29
  }
26
30
 
31
+ export * from "./buildableEnvelope"
27
32
  export * from "./department"
28
33
  export * from "./referenceLine"
29
34
  export * from "./space"
@@ -5,7 +5,7 @@ import { PQuat } from "../core/math/quat"
5
5
  import { PProfile } from "../core/geom/profile"
6
6
 
7
7
  /**
8
- * Space (room/mass) management — create, query, update, and delete spaces.
8
+ * Space (room/mass) management — create, query, and delete spaces.
9
9
  *
10
10
  * A **space** is a 3D volume representing a room or mass in the
11
11
  * Snaptrude scene. Spaces live on a particular story and carry
@@ -99,63 +99,6 @@ export abstract class PluginSpaceApi {
99
99
  position,
100
100
  }: PluginSpaceCreateFromProfileArgs): PluginApiReturn<PluginSpaceCreateFromProfileResult>
101
101
 
102
- /**
103
- * Update a space's BRep and mesh geometry by extruding a 2D profile.
104
- *
105
- * The {@linkcode PluginSpaceUpdateGeometryFromProfileArgs.profile profile} is
106
- * extruded upward (along the Y axis) by
107
- * {@linkcode PluginSpaceUpdateGeometryFromProfileArgs.extrudeHeight extrudeHeight}
108
- * and applied to the existing space. The space keeps the same `spaceId`,
109
- * metadata, department, and transform; only its geometry is replaced.
110
- *
111
- * Profile points are interpreted in scene coordinates. Profiles returned by
112
- * {@linkcode PluginSpaceApi.get} with `"profile"` can be passed back directly;
113
- * `"planPoints"` can be used to construct line-only profiles in the same X/Z
114
- * plan coordinate space.
115
- *
116
- * Use {@linkcode PluginProfileApi.fromLinePoints} to quickly build a profile
117
- * from a list of points.
118
- *
119
- * @param args - An object containing:
120
- * - {@linkcode PluginSpaceUpdateGeometryFromProfileArgs.spaceId args.spaceId} —
121
- * The unique space ID to update
122
- * - {@linkcode PluginSpaceUpdateGeometryFromProfileArgs.profile args.profile} —
123
- * A closed {@linkcode PProfile} defining the new floor shape
124
- * - {@linkcode PluginSpaceUpdateGeometryFromProfileArgs.extrudeHeight
125
- * args.extrudeHeight} — New extrusion height in Babylon units
126
- * @returns A {@linkcode PluginSpaceUpdateGeometryFromProfileResult} with the
127
- * `spaceId` of the updated space
128
- * @throws If the space does not exist, the component is not a space/mass, the
129
- * height is not positive, or the profile cannot create valid geometry
130
- *
131
- * # Example
132
- * ```ts
133
- * const { vec3 } = snaptrude.core.math
134
- *
135
- * const profile = await snaptrude.core.geom.profile.fromLinePoints({
136
- * points: [
137
- * vec3.new(0, 0, 0),
138
- * vec3.new(12, 0, 0),
139
- * vec3.new(12, 0, 6),
140
- * vec3.new(0, 0, 6),
141
- * ],
142
- * })
143
- *
144
- * const { spaceId } = await snaptrude.entity.space.updateGeometryFromProfile({
145
- * spaceId: "some-space-id",
146
- * profile,
147
- * extrudeHeight: 4,
148
- * })
149
- * ```
150
- */
151
- public abstract updateGeometryFromProfile({
152
- spaceId,
153
- profile,
154
- extrudeHeight,
155
- }: PluginSpaceUpdateGeometryFromProfileArgs): PluginApiReturn<
156
- PluginSpaceUpdateGeometryFromProfileResult
157
- >
158
-
159
102
  /**
160
103
  * Get the IDs of all spaces in the current project.
161
104
  *
@@ -326,40 +269,6 @@ export type PluginSpaceCreateFromProfileResult = z.infer<
326
269
  typeof PluginSpaceCreateFromProfileResult
327
270
  >
328
271
 
329
- /**
330
- * Arguments for {@linkcode PluginSpaceApi.updateGeometryFromProfile}.
331
- *
332
- * | Property | Type | Description |
333
- * |---|---|---|
334
- * | `spaceId` | `string` | Space to update |
335
- * | `profile` | {@linkcode PProfile} | Closed 2D profile defining the new floor shape |
336
- * | `extrudeHeight` | `number` | New extrusion height in Babylon units |
337
- */
338
- export const PluginSpaceUpdateGeometryFromProfileArgs = z.object({
339
- spaceId: z.string(),
340
- profile: PProfile,
341
- extrudeHeight: z.number(),
342
- })
343
-
344
- export type PluginSpaceUpdateGeometryFromProfileArgs = z.infer<
345
- typeof PluginSpaceUpdateGeometryFromProfileArgs
346
- >
347
-
348
- /**
349
- * Result of {@linkcode PluginSpaceApi.updateGeometryFromProfile}.
350
- *
351
- * | Property | Type | Description |
352
- * |---|---|---|
353
- * | `spaceId` | `string` | Unique ID of the updated space |
354
- */
355
- export const PluginSpaceUpdateGeometryFromProfileResult = z.object({
356
- spaceId: z.string(),
357
- })
358
-
359
- export type PluginSpaceUpdateGeometryFromProfileResult = z.infer<
360
- typeof PluginSpaceUpdateGeometryFromProfileResult
361
- >
362
-
363
272
  /**
364
273
  * Available properties that can be queried on a space.
365
274
  *
@@ -397,7 +306,6 @@ export type PluginSpaceUpdateGeometryFromProfileResult = z.infer<
397
306
  * | Value | Return Type | Description |
398
307
  * |---|---|---|
399
308
  * | `"planPoints"` | {@linkcode PVec3}`[]` | Bottom outer profile points in world space with `y = 0` (2D plan). No closing duplicate point. |
400
- * | `"profile"` | {@linkcode PProfile} | Bottom outer profile in world space, preserving line/arc curve data. |
401
309
  */
402
310
  export const PluginSpaceGetProperty = z.enum([
403
311
  // Basic
@@ -423,7 +331,6 @@ export const PluginSpaceGetProperty = z.enum([
423
331
  "rotationQuaternion",
424
332
  // Derived from brep
425
333
  "planPoints",
426
- "profile",
427
334
  ])
428
335
 
429
336
  /**
@@ -503,7 +410,6 @@ export const PluginSpaceGetResult = z
503
410
  rotationQuaternion: PQuat.nullable(),
504
411
  // Derived from brep
505
412
  planPoints: z.array(PVec3),
506
- profile: PProfile,
507
413
  })
508
414
  .partial()
509
415