@snaptrude/plugin-core 0.0.4 → 0.0.6
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/api/core/geom/arc.d.ts +50 -1
- package/dist/api/core/geom/arc.d.ts.map +1 -1
- package/dist/api/core/geom/curve.d.ts +26 -1
- package/dist/api/core/geom/curve.d.ts.map +1 -1
- package/dist/api/core/geom/index.d.ts +16 -0
- package/dist/api/core/geom/index.d.ts.map +1 -1
- package/dist/api/core/geom/line.d.ts +35 -1
- package/dist/api/core/geom/line.d.ts.map +1 -1
- package/dist/api/core/geom/profile.d.ts +66 -2
- package/dist/api/core/geom/profile.d.ts.map +1 -1
- package/dist/api/core/index.d.ts +8 -0
- package/dist/api/core/index.d.ts.map +1 -1
- package/dist/api/core/math/index.d.ts +8 -0
- package/dist/api/core/math/index.d.ts.map +1 -1
- package/dist/api/core/math/quat.d.ts +156 -15
- package/dist/api/core/math/quat.d.ts.map +1 -1
- package/dist/api/core/math/vec3.d.ts +131 -14
- package/dist/api/core/math/vec3.d.ts.map +1 -1
- package/dist/api/entity/index.d.ts +8 -0
- package/dist/api/entity/index.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +217 -4
- package/dist/api/entity/space.d.ts.map +1 -1
- package/dist/api/entity/story.d.ts +166 -0
- package/dist/api/entity/story.d.ts.map +1 -1
- package/dist/api/index.d.ts +14 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/tools/index.d.ts +8 -0
- package/dist/api/tools/index.d.ts.map +1 -1
- package/dist/api/tools/selection.d.ts +37 -0
- package/dist/api/tools/selection.d.ts.map +1 -1
- package/dist/api/tools/transform.d.ts +82 -0
- package/dist/api/tools/transform.d.ts.map +1 -1
- package/dist/api/units/index.d.ts +72 -13
- package/dist/api/units/index.d.ts.map +1 -1
- package/dist/index.cjs +322 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +321 -35
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/core/geom/arc.ts +50 -1
- package/src/api/core/geom/curve.ts +26 -1
- package/src/api/core/geom/index.ts +16 -0
- package/src/api/core/geom/line.ts +35 -1
- package/src/api/core/geom/profile.ts +66 -2
- package/src/api/core/index.ts +8 -0
- package/src/api/core/math/index.ts +8 -0
- package/src/api/core/math/quat.ts +156 -15
- package/src/api/core/math/vec3.ts +131 -14
- package/src/api/entity/index.ts +8 -0
- package/src/api/entity/space.ts +218 -5
- package/src/api/entity/story.ts +166 -0
- package/src/api/index.ts +14 -0
- package/src/api/tools/index.ts +8 -0
- package/src/api/tools/selection.ts +37 -0
- package/src/api/tools/transform.ts +82 -0
- package/src/api/units/index.ts +72 -13
- package/src/types.ts +8 -1
package/src/api/entity/space.ts
CHANGED
|
@@ -4,32 +4,177 @@ import { PVec3 } from "../core/math/vec3"
|
|
|
4
4
|
import { PQuat } from "../core/math/quat"
|
|
5
5
|
import { PProfile } from "../core/geom/profile"
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Space (room/mass) management — create, query, and delete spaces.
|
|
9
|
+
*
|
|
10
|
+
* A **space** is a 3D volume representing a room or mass in the
|
|
11
|
+
* Snaptrude scene. Spaces live on a particular story and carry
|
|
12
|
+
* properties such as name, area, department, and room type.
|
|
13
|
+
*
|
|
14
|
+
* All methods are **host API calls** that return Promises and support
|
|
15
|
+
* undo/redo via Snaptrude's command system.
|
|
16
|
+
*
|
|
17
|
+
* Accessed via `snaptrude.entity.space`.
|
|
18
|
+
*/
|
|
7
19
|
export abstract class PluginSpaceApi {
|
|
8
20
|
constructor() {}
|
|
9
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Create a rectangular (box) space.
|
|
24
|
+
*
|
|
25
|
+
* Generates an axis-aligned box with the given dimensions at the
|
|
26
|
+
* specified position. The created space is automatically assigned
|
|
27
|
+
* to the active story and a default department.
|
|
28
|
+
*
|
|
29
|
+
* @param args - An object containing:
|
|
30
|
+
* - {@linkcode PluginSpaceCreateRectangularArgs.position args.position} — Origin
|
|
31
|
+
* position as a {@linkcode PVec3} in Babylon units
|
|
32
|
+
* - {@linkcode PluginSpaceCreateRectangularArgs.dimensions args.dimensions} — Box
|
|
33
|
+
* dimensions `{ width, height, depth }` in Babylon units
|
|
34
|
+
* @returns A {@linkcode PluginSpaceCreateRectangularResult} with the `spaceId`
|
|
35
|
+
* of the created space
|
|
36
|
+
* @throws If space creation fails
|
|
37
|
+
*
|
|
38
|
+
* # Example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const { vec3 } = snaptrude.core.math
|
|
41
|
+
*
|
|
42
|
+
* const { spaceId } = await snaptrude.entity.space.createRectangular({
|
|
43
|
+
* position: vec3.new(0, 0, 0),
|
|
44
|
+
* dimensions: { width: 5, height: 3, depth: 4 },
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
10
48
|
public abstract createRectangular({
|
|
11
49
|
position,
|
|
12
50
|
dimensions,
|
|
13
51
|
}: PluginSpaceCreateRectangularArgs): PluginApiReturn<PluginSpaceCreateRectangularResult>
|
|
14
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Create a space by extruding a 2D profile.
|
|
55
|
+
*
|
|
56
|
+
* The {@linkcode PluginSpaceCreateFromProfileArgs.profile profile} is extruded
|
|
57
|
+
* upward (along the Y axis) by {@linkcode PluginSpaceCreateFromProfileArgs.extrudeHeight
|
|
58
|
+
* extrudeHeight}, then offset by {@linkcode PluginSpaceCreateFromProfileArgs.position
|
|
59
|
+
* position}. The created space is automatically assigned to the active story
|
|
60
|
+
* and a default department.
|
|
61
|
+
*
|
|
62
|
+
* Use {@linkcode PluginProfileApi.fromLinePoints} to quickly build a profile
|
|
63
|
+
* from a list of points.
|
|
64
|
+
*
|
|
65
|
+
* @param args - An object containing:
|
|
66
|
+
* - {@linkcode PluginSpaceCreateFromProfileArgs.profile args.profile} — A closed
|
|
67
|
+
* {@linkcode PProfile} defining the floor shape
|
|
68
|
+
* - {@linkcode PluginSpaceCreateFromProfileArgs.extrudeHeight args.extrudeHeight} —
|
|
69
|
+
* Extrusion height in Babylon units
|
|
70
|
+
* - {@linkcode PluginSpaceCreateFromProfileArgs.position args.position} — Offset
|
|
71
|
+
* position as a {@linkcode PVec3} in Babylon units
|
|
72
|
+
* @returns A {@linkcode PluginSpaceCreateFromProfileResult} with the `spaceId`
|
|
73
|
+
* of the created space
|
|
74
|
+
* @throws If the profile is invalid or mesh creation fails
|
|
75
|
+
*
|
|
76
|
+
* # Example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const { vec3 } = snaptrude.core.math
|
|
79
|
+
*
|
|
80
|
+
* const profile = await snaptrude.core.geom.profile.fromLinePoints({
|
|
81
|
+
* points: [
|
|
82
|
+
* vec3.new(0, 0, 0),
|
|
83
|
+
* vec3.new(10, 0, 0),
|
|
84
|
+
* vec3.new(10, 0, 8),
|
|
85
|
+
* vec3.new(0, 0, 8),
|
|
86
|
+
* ],
|
|
87
|
+
* })
|
|
88
|
+
*
|
|
89
|
+
* const { spaceId } = await snaptrude.entity.space.createFromProfile({
|
|
90
|
+
* profile,
|
|
91
|
+
* extrudeHeight: 3,
|
|
92
|
+
* position: vec3.new(0, 0, 0),
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
15
96
|
public abstract createFromProfile({
|
|
16
97
|
profile,
|
|
17
98
|
extrudeHeight,
|
|
18
99
|
position,
|
|
19
100
|
}: PluginSpaceCreateFromProfileArgs): PluginApiReturn<PluginSpaceCreateFromProfileResult>
|
|
20
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Get the IDs of all spaces in the current project.
|
|
104
|
+
*
|
|
105
|
+
* Returns every space (mass that is not a building) across all stories.
|
|
106
|
+
* Use the returned IDs with {@linkcode PluginSpaceApi.get} to query
|
|
107
|
+
* individual space properties.
|
|
108
|
+
*
|
|
109
|
+
* @returns A {@linkcode PluginSpaceGetAllResult} with a `spacesIds` array
|
|
110
|
+
*
|
|
111
|
+
* # Example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const { spacesIds } = await snaptrude.entity.space.getAll()
|
|
114
|
+
* console.log(`Project has ${spacesIds.length} spaces`)
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
21
117
|
public abstract getAll(): PluginApiReturn<PluginSpaceGetAllResult>
|
|
22
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Get properties of a space by its ID.
|
|
121
|
+
*
|
|
122
|
+
* Only the properties listed in {@linkcode PluginSpaceGetArgs.properties
|
|
123
|
+
* args.properties} are returned — unlisted properties will be `undefined`
|
|
124
|
+
* in the result.
|
|
125
|
+
*
|
|
126
|
+
* @param args - An object containing:
|
|
127
|
+
* - {@linkcode PluginSpaceGetArgs.spaceId args.spaceId} — The unique space ID
|
|
128
|
+
* (as returned by creation methods or {@linkcode PluginSpaceApi.getAll})
|
|
129
|
+
* - {@linkcode PluginSpaceGetArgs.properties args.properties} — Array of property
|
|
130
|
+
* names to retrieve. See {@linkcode PluginSpaceGetProperty} for available values.
|
|
131
|
+
* @returns A partial {@linkcode PluginSpaceGetResult} containing only the requested
|
|
132
|
+
* properties
|
|
133
|
+
* @throws If the space does not exist or the component is not a space/mass
|
|
134
|
+
*
|
|
135
|
+
* # Example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const info = await snaptrude.entity.space.get({
|
|
138
|
+
* spaceId: "some-space-id",
|
|
139
|
+
* properties: ["name", "area", "position"],
|
|
140
|
+
* })
|
|
141
|
+
* console.log(info.name, info.area, info.position)
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
23
144
|
public abstract get({
|
|
24
145
|
spaceId,
|
|
25
146
|
properties,
|
|
26
147
|
}: PluginSpaceGetArgs): PluginApiReturn<PluginSpaceGetResult>
|
|
27
148
|
|
|
28
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Delete a space by its ID.
|
|
151
|
+
*
|
|
152
|
+
* Permanently removes the space and its associated mesh from the scene.
|
|
153
|
+
* This operation is undoable via Snaptrude's command system.
|
|
154
|
+
*
|
|
155
|
+
* @param args - An object containing:
|
|
156
|
+
* - {@linkcode PluginSpaceDeleteArgs.spaceId args.spaceId} — The unique space ID
|
|
157
|
+
* to delete
|
|
158
|
+
* @throws If the space does not exist or the component is not a space/mass
|
|
159
|
+
*
|
|
160
|
+
* # Example
|
|
161
|
+
* ```ts
|
|
162
|
+
* await snaptrude.entity.space.delete({ spaceId: "some-space-id" })
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
public abstract delete({
|
|
29
166
|
spaceId,
|
|
30
|
-
}:
|
|
167
|
+
}: PluginSpaceDeleteArgs): PluginApiReturn<PluginSpaceDeleteResult>
|
|
31
168
|
}
|
|
32
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Arguments for {@linkcode PluginSpaceApi.createRectangular}.
|
|
172
|
+
*
|
|
173
|
+
* | Property | Type | Description |
|
|
174
|
+
* |---|---|---|
|
|
175
|
+
* | `position` | {@linkcode PVec3} | Origin position in Babylon units |
|
|
176
|
+
* | `dimensions` | `{ width, height, depth }` | Box dimensions in Babylon units |
|
|
177
|
+
*/
|
|
33
178
|
export const PluginSpaceCreateRectangularArgs = z.object({
|
|
34
179
|
position: PVec3,
|
|
35
180
|
dimensions: z.object({
|
|
@@ -41,12 +186,28 @@ export const PluginSpaceCreateRectangularArgs = z.object({
|
|
|
41
186
|
|
|
42
187
|
export type PluginSpaceCreateRectangularArgs = z.infer<typeof PluginSpaceCreateRectangularArgs>
|
|
43
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Result of {@linkcode PluginSpaceApi.createRectangular}.
|
|
191
|
+
*
|
|
192
|
+
* | Property | Type | Description |
|
|
193
|
+
* |---|---|---|
|
|
194
|
+
* | `spaceId` | `string` | Unique ID of the created space |
|
|
195
|
+
*/
|
|
44
196
|
export const PluginSpaceCreateRectangularResult = z.object({
|
|
45
197
|
spaceId: z.string(),
|
|
46
198
|
})
|
|
47
199
|
|
|
48
200
|
export type PluginSpaceCreateRectangularResult = z.infer<typeof PluginSpaceCreateRectangularResult>
|
|
49
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Arguments for {@linkcode PluginSpaceApi.createFromProfile}.
|
|
204
|
+
*
|
|
205
|
+
* | Property | Type | Description |
|
|
206
|
+
* |---|---|---|
|
|
207
|
+
* | `profile` | {@linkcode PProfile} | Closed 2D profile defining the floor shape |
|
|
208
|
+
* | `extrudeHeight` | `number` | Extrusion height in Babylon units |
|
|
209
|
+
* | `position` | {@linkcode PVec3} | Offset position in Babylon units |
|
|
210
|
+
*/
|
|
50
211
|
export const PluginSpaceCreateFromProfileArgs = z.object({
|
|
51
212
|
profile: PProfile,
|
|
52
213
|
extrudeHeight: z.number(),
|
|
@@ -55,12 +216,35 @@ export const PluginSpaceCreateFromProfileArgs = z.object({
|
|
|
55
216
|
|
|
56
217
|
export type PluginSpaceCreateFromProfileArgs = z.infer<typeof PluginSpaceCreateFromProfileArgs>
|
|
57
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Result of {@linkcode PluginSpaceApi.createFromProfile}.
|
|
221
|
+
*
|
|
222
|
+
* | Property | Type | Description |
|
|
223
|
+
* |---|---|---|
|
|
224
|
+
* | `spaceId` | `string` | Unique ID of the created space |
|
|
225
|
+
*/
|
|
58
226
|
export const PluginSpaceCreateFromProfileResult = z.object({
|
|
59
227
|
spaceId: z.string(),
|
|
60
228
|
})
|
|
61
229
|
|
|
62
230
|
export type PluginSpaceCreateFromProfileResult = z.infer<typeof PluginSpaceCreateFromProfileResult>
|
|
63
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Available properties that can be queried on a space.
|
|
234
|
+
*
|
|
235
|
+
* | Value | Return Type | Description |
|
|
236
|
+
* |---|---|---|
|
|
237
|
+
* | `"id"` | `string` | Unique space identifier |
|
|
238
|
+
* | `"type"` | `string` | Component type |
|
|
239
|
+
* | `"room_type"` | `string` | Room type classification |
|
|
240
|
+
* | `"name"` | `string` | Display name of the space |
|
|
241
|
+
* | `"area"` | `number` | Bottom (floor) area |
|
|
242
|
+
* | `"department"` | `string` | Assigned department name |
|
|
243
|
+
* | `"position"` | {@linkcode PVec3} | Local position relative to parent |
|
|
244
|
+
* | `"absolutePosition"` | {@linkcode PVec3} | Absolute position in the scene |
|
|
245
|
+
* | `"rotation"` | {@linkcode PVec3} | Euler rotation angles (radians) |
|
|
246
|
+
* | `"rotationQuaternion"` | {@linkcode PQuat} \| `null` | Quaternion rotation, or `null` if unset |
|
|
247
|
+
*/
|
|
64
248
|
export const PluginSpaceGetProperty = z.enum([
|
|
65
249
|
"id",
|
|
66
250
|
"type",
|
|
@@ -74,6 +258,14 @@ export const PluginSpaceGetProperty = z.enum([
|
|
|
74
258
|
"rotationQuaternion",
|
|
75
259
|
])
|
|
76
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Arguments for {@linkcode PluginSpaceApi.get}.
|
|
263
|
+
*
|
|
264
|
+
* | Property | Type | Description |
|
|
265
|
+
* |---|---|---|
|
|
266
|
+
* | `spaceId` | `string` | The space ID to query |
|
|
267
|
+
* | `properties` | {@linkcode PluginSpaceGetProperty}`[]` | Properties to retrieve |
|
|
268
|
+
*/
|
|
77
269
|
export const PluginSpaceGetArgs = z.object({
|
|
78
270
|
spaceId: z.string(),
|
|
79
271
|
properties: z.array(PluginSpaceGetProperty),
|
|
@@ -81,6 +273,12 @@ export const PluginSpaceGetArgs = z.object({
|
|
|
81
273
|
|
|
82
274
|
export type PluginSpaceGetArgs = z.infer<typeof PluginSpaceGetArgs>
|
|
83
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Result of {@linkcode PluginSpaceApi.get}.
|
|
278
|
+
*
|
|
279
|
+
* A partial object — only the properties that were requested in
|
|
280
|
+
* {@linkcode PluginSpaceGetArgs.properties} will be present.
|
|
281
|
+
*/
|
|
84
282
|
export const PluginSpaceGetResult = z
|
|
85
283
|
.object({
|
|
86
284
|
id: z.string(),
|
|
@@ -98,16 +296,31 @@ export const PluginSpaceGetResult = z
|
|
|
98
296
|
|
|
99
297
|
export type PluginSpaceGetResult = z.infer<typeof PluginSpaceGetResult>
|
|
100
298
|
|
|
299
|
+
/**
|
|
300
|
+
* Result of {@linkcode PluginSpaceApi.getAll}.
|
|
301
|
+
*
|
|
302
|
+
* | Property | Type | Description |
|
|
303
|
+
* |---|---|---|
|
|
304
|
+
* | `spacesIds` | `string[]` | IDs of all spaces in the project |
|
|
305
|
+
*/
|
|
101
306
|
export const PluginSpaceGetAllResult = z.object({
|
|
102
307
|
spacesIds: z.array(z.string()),
|
|
103
308
|
})
|
|
104
309
|
|
|
105
310
|
export type PluginSpaceGetAllResult = z.infer<typeof PluginSpaceGetAllResult>
|
|
106
311
|
|
|
107
|
-
|
|
312
|
+
/**
|
|
313
|
+
* Arguments for {@linkcode PluginSpaceApi.delete}.
|
|
314
|
+
*
|
|
315
|
+
* | Property | Type | Description |
|
|
316
|
+
* |---|---|---|
|
|
317
|
+
* | `spaceId` | `string` | The space ID to delete |
|
|
318
|
+
*/
|
|
319
|
+
export const PluginSpaceDeleteArgs = z.object({
|
|
108
320
|
spaceId: z.string(),
|
|
109
321
|
})
|
|
110
322
|
|
|
111
|
-
export type
|
|
323
|
+
export type PluginSpaceDeleteArgs = z.infer<typeof PluginSpaceDeleteArgs>
|
|
112
324
|
|
|
113
|
-
|
|
325
|
+
/** Result type for {@linkcode PluginSpaceApi.delete} — returns nothing on success. */
|
|
326
|
+
export type PluginSpaceDeleteResult = void
|
package/src/api/entity/story.ts
CHANGED
|
@@ -1,27 +1,140 @@
|
|
|
1
1
|
import * as z from "zod"
|
|
2
2
|
import { PluginApiReturn } from "../../types"
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Story (floor/storey) management.
|
|
6
|
+
*
|
|
7
|
+
* A story represents a building floor in the Snaptrude project. Stories
|
|
8
|
+
* are identified by their integer **story value** (e.g. `1` for ground
|
|
9
|
+
* floor, `2` for first floor, `-1` for a basement).
|
|
10
|
+
*
|
|
11
|
+
* All methods are **host API calls** that return Promises and support
|
|
12
|
+
* undo/redo via Snaptrude's command system.
|
|
13
|
+
*
|
|
14
|
+
* Accessed via `snaptrude.entity.story`.
|
|
15
|
+
*/
|
|
4
16
|
export abstract class PluginStoryApi {
|
|
5
17
|
constructor() {}
|
|
6
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Get properties of a story by its storey number.
|
|
21
|
+
*
|
|
22
|
+
* Only the properties listed in {@linkcode PluginStoryGetArgs.properties args.properties}
|
|
23
|
+
* are returned — unlisted properties will be `undefined` in the result.
|
|
24
|
+
*
|
|
25
|
+
* @param args - An object containing:
|
|
26
|
+
* - {@linkcode PluginStoryGetArgs.storyValue args.storyValue} — Integer storey number
|
|
27
|
+
* (e.g. `1` for ground floor, `2` for first floor, `-1` for basement)
|
|
28
|
+
* - {@linkcode PluginStoryGetArgs.properties args.properties} — Array of property names
|
|
29
|
+
* to retrieve. See {@linkcode PluginStoryGetProperty} for available values.
|
|
30
|
+
* @returns A partial {@linkcode PluginStoryGetResult} containing only the requested properties
|
|
31
|
+
* @throws If the story with the given value does not exist
|
|
32
|
+
*
|
|
33
|
+
* # Example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const info = await snaptrude.entity.story.get({
|
|
36
|
+
* storyValue: 1,
|
|
37
|
+
* properties: ["height", "name", "spacesCount"],
|
|
38
|
+
* })
|
|
39
|
+
* console.log(info.name, info.height, info.spacesCount)
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
7
42
|
public abstract get({
|
|
8
43
|
storyValue,
|
|
9
44
|
properties,
|
|
10
45
|
}: PluginStoryGetArgs): PluginApiReturn<PluginStoryGetResult>
|
|
11
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Get all stories in the current project.
|
|
49
|
+
*
|
|
50
|
+
* Returns basic identification data for every storey. Stories are sorted
|
|
51
|
+
* from **top to bottom** (highest story value first).
|
|
52
|
+
*
|
|
53
|
+
* @returns A {@linkcode PluginStoryGetAllResult} with a `stories` array,
|
|
54
|
+
* each entry containing `value`, `id`, and `name`
|
|
55
|
+
*
|
|
56
|
+
* # Example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const { stories } = await snaptrude.entity.story.getAll()
|
|
59
|
+
* for (const s of stories) {
|
|
60
|
+
* console.log(`Story ${s.value}: ${s.name} (id: ${s.id})`)
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
12
64
|
public abstract getAll(): PluginApiReturn<PluginStoryGetAllResult>
|
|
13
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Create a new story (floor) in the project.
|
|
68
|
+
*
|
|
69
|
+
* The new story is inserted at the position specified by
|
|
70
|
+
* {@linkcode PluginStoryCreateArgs.storyValue args.storyValue}. This
|
|
71
|
+
* operation is undoable.
|
|
72
|
+
*
|
|
73
|
+
* @param args - An object containing:
|
|
74
|
+
* - {@linkcode PluginStoryCreateArgs.storyValue args.storyValue} — Integer storey number
|
|
75
|
+
* to create (e.g. `3` to add a third floor)
|
|
76
|
+
* - {@linkcode PluginStoryCreateArgs.height args.height} — Optional height in Babylon
|
|
77
|
+
* units. If omitted, the project's default storey height is used.
|
|
78
|
+
* @returns A {@linkcode PluginStoryCreateResult} with `storyId` and `storyValue`
|
|
79
|
+
* @throws If a story with the given value already exists or creation fails
|
|
80
|
+
*
|
|
81
|
+
* # Example
|
|
82
|
+
* ```ts
|
|
83
|
+
* // Create a new third floor with custom height
|
|
84
|
+
* const { storyId } = await snaptrude.entity.story.create({
|
|
85
|
+
* storyValue: 3,
|
|
86
|
+
* height: 4.5,
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
14
90
|
public abstract create({
|
|
15
91
|
storyValue,
|
|
16
92
|
height,
|
|
17
93
|
}: PluginStoryCreateArgs): PluginApiReturn<PluginStoryCreateResult>
|
|
18
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Update a story's height.
|
|
97
|
+
*
|
|
98
|
+
* Changes the floor-to-floor height of the specified story. This
|
|
99
|
+
* operation is undoable.
|
|
100
|
+
*
|
|
101
|
+
* @param args - An object containing:
|
|
102
|
+
* - {@linkcode PluginStoryUpdateArgs.storyValue args.storyValue} — Integer storey number
|
|
103
|
+
* identifying the story to update
|
|
104
|
+
* - {@linkcode PluginStoryUpdateArgs.height args.height} — New height value in Babylon
|
|
105
|
+
* units
|
|
106
|
+
* @returns A {@linkcode PluginStoryUpdateResult} with the updated `storyValue` and `height`
|
|
107
|
+
* @throws If the story does not exist or the update fails
|
|
108
|
+
*
|
|
109
|
+
* # Example
|
|
110
|
+
* ```ts
|
|
111
|
+
* // Set ground floor height to 5 Babylon units
|
|
112
|
+
* const result = await snaptrude.entity.story.update({
|
|
113
|
+
* storyValue: 1,
|
|
114
|
+
* height: 5,
|
|
115
|
+
* })
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
19
118
|
public abstract update({
|
|
20
119
|
storyValue,
|
|
21
120
|
height,
|
|
22
121
|
}: PluginStoryUpdateArgs): PluginApiReturn<PluginStoryUpdateResult>
|
|
23
122
|
}
|
|
24
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Available properties that can be queried on a story.
|
|
126
|
+
*
|
|
127
|
+
* | Value | Type | Description |
|
|
128
|
+
* |---|---|---|
|
|
129
|
+
* | `"value"` | `number` | The integer storey number |
|
|
130
|
+
* | `"id"` | `string` | Unique story identifier |
|
|
131
|
+
* | `"name"` | `string` | Display name of the story |
|
|
132
|
+
* | `"height"` | `number` | Floor-to-floor height in Babylon units |
|
|
133
|
+
* | `"base"` | `number` | Base elevation in Babylon units |
|
|
134
|
+
* | `"hidden"` | `boolean` | Whether the story is hidden in the viewport |
|
|
135
|
+
* | `"spacesCount"` | `number` | Number of spaces on this story |
|
|
136
|
+
* | `"totalArea"` | `number` | Total floor area of this story |
|
|
137
|
+
*/
|
|
25
138
|
export const PluginStoryGetProperty = z.enum([
|
|
26
139
|
"value",
|
|
27
140
|
"id",
|
|
@@ -33,6 +146,14 @@ export const PluginStoryGetProperty = z.enum([
|
|
|
33
146
|
"totalArea",
|
|
34
147
|
])
|
|
35
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Arguments for {@linkcode PluginStoryApi.get}.
|
|
151
|
+
*
|
|
152
|
+
* | Property | Type | Description |
|
|
153
|
+
* |---|---|---|
|
|
154
|
+
* | `storyValue` | `number` (int) | The storey number to query |
|
|
155
|
+
* | `properties` | {@linkcode PluginStoryGetProperty}`[]` | Properties to retrieve |
|
|
156
|
+
*/
|
|
36
157
|
export const PluginStoryGetArgs = z.object({
|
|
37
158
|
storyValue: z.number().int(),
|
|
38
159
|
properties: z.array(PluginStoryGetProperty),
|
|
@@ -40,6 +161,12 @@ export const PluginStoryGetArgs = z.object({
|
|
|
40
161
|
|
|
41
162
|
export type PluginStoryGetArgs = z.infer<typeof PluginStoryGetArgs>
|
|
42
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Result of {@linkcode PluginStoryApi.get}.
|
|
166
|
+
*
|
|
167
|
+
* A partial object — only the properties that were requested in
|
|
168
|
+
* {@linkcode PluginStoryGetArgs.properties} will be present.
|
|
169
|
+
*/
|
|
43
170
|
export const PluginStoryGetResult = z
|
|
44
171
|
.object({
|
|
45
172
|
value: z.number(),
|
|
@@ -55,6 +182,13 @@ export const PluginStoryGetResult = z
|
|
|
55
182
|
|
|
56
183
|
export type PluginStoryGetResult = z.infer<typeof PluginStoryGetResult>
|
|
57
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Result of {@linkcode PluginStoryApi.getAll}.
|
|
187
|
+
*
|
|
188
|
+
* | Property | Type | Description |
|
|
189
|
+
* |---|---|---|
|
|
190
|
+
* | `stories` | `Array<{ value, id, name }>` | All stories, sorted top to bottom |
|
|
191
|
+
*/
|
|
58
192
|
export const PluginStoryGetAllResult = z.object({
|
|
59
193
|
stories: z.array(
|
|
60
194
|
z.object({
|
|
@@ -67,6 +201,14 @@ export const PluginStoryGetAllResult = z.object({
|
|
|
67
201
|
|
|
68
202
|
export type PluginStoryGetAllResult = z.infer<typeof PluginStoryGetAllResult>
|
|
69
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Arguments for {@linkcode PluginStoryApi.create}.
|
|
206
|
+
*
|
|
207
|
+
* | Property | Type | Description |
|
|
208
|
+
* |---|---|---|
|
|
209
|
+
* | `storyValue` | `number` (int) | The storey number for the new story |
|
|
210
|
+
* | `height` | `number?` | Optional height in Babylon units |
|
|
211
|
+
*/
|
|
70
212
|
export const PluginStoryCreateArgs = z.object({
|
|
71
213
|
storyValue: z.number().int(),
|
|
72
214
|
height: z.number().optional(),
|
|
@@ -74,6 +216,14 @@ export const PluginStoryCreateArgs = z.object({
|
|
|
74
216
|
|
|
75
217
|
export type PluginStoryCreateArgs = z.infer<typeof PluginStoryCreateArgs>
|
|
76
218
|
|
|
219
|
+
/**
|
|
220
|
+
* Result of {@linkcode PluginStoryApi.create}.
|
|
221
|
+
*
|
|
222
|
+
* | Property | Type | Description |
|
|
223
|
+
* |---|---|---|
|
|
224
|
+
* | `storyId` | `string` | Unique ID of the created story |
|
|
225
|
+
* | `storyValue` | `number` | The storey number of the created story |
|
|
226
|
+
*/
|
|
77
227
|
export const PluginStoryCreateResult = z.object({
|
|
78
228
|
storyId: z.string(),
|
|
79
229
|
storyValue: z.number(),
|
|
@@ -81,6 +231,14 @@ export const PluginStoryCreateResult = z.object({
|
|
|
81
231
|
|
|
82
232
|
export type PluginStoryCreateResult = z.infer<typeof PluginStoryCreateResult>
|
|
83
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Arguments for {@linkcode PluginStoryApi.update}.
|
|
236
|
+
*
|
|
237
|
+
* | Property | Type | Description |
|
|
238
|
+
* |---|---|---|
|
|
239
|
+
* | `storyValue` | `number` (int) | Storey number of the story to update |
|
|
240
|
+
* | `height` | `number` | New height in Babylon units |
|
|
241
|
+
*/
|
|
84
242
|
export const PluginStoryUpdateArgs = z.object({
|
|
85
243
|
storyValue: z.number().int(),
|
|
86
244
|
height: z.number(),
|
|
@@ -88,6 +246,14 @@ export const PluginStoryUpdateArgs = z.object({
|
|
|
88
246
|
|
|
89
247
|
export type PluginStoryUpdateArgs = z.infer<typeof PluginStoryUpdateArgs>
|
|
90
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Result of {@linkcode PluginStoryApi.update}.
|
|
251
|
+
*
|
|
252
|
+
* | Property | Type | Description |
|
|
253
|
+
* |---|---|---|
|
|
254
|
+
* | `storyValue` | `number` | The storey number of the updated story |
|
|
255
|
+
* | `height` | `number` | The new height after the update |
|
|
256
|
+
*/
|
|
91
257
|
export const PluginStoryUpdateResult = z.object({
|
|
92
258
|
storyValue: z.number(),
|
|
93
259
|
height: z.number(),
|
package/src/api/index.ts
CHANGED
|
@@ -3,10 +3,24 @@ import { PluginEntityApi } from "./entity"
|
|
|
3
3
|
import { PluginToolsApi } from "./tools"
|
|
4
4
|
import { PluginUnitsApi } from "./units"
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Root API surface for Snaptrude plugins.
|
|
8
|
+
*
|
|
9
|
+
* Access all plugin capabilities through the namespaced properties:
|
|
10
|
+
*
|
|
11
|
+
* - {@linkcode PluginApi.core} — Math and geometry primitives
|
|
12
|
+
* - {@linkcode PluginApi.entity} — CRUD operations on Snaptrude entities (spaces, stories)
|
|
13
|
+
* - {@linkcode PluginApi.tools} — Selection and transform tools
|
|
14
|
+
* - {@linkcode PluginApi.units} — Unit conversion utilities
|
|
15
|
+
*/
|
|
6
16
|
export abstract class PluginApi {
|
|
17
|
+
/** Core math and geometry primitives. See {@linkcode PluginCoreApi}. */
|
|
7
18
|
public abstract core: PluginCoreApi
|
|
19
|
+
/** Selection and transform tools. See {@linkcode PluginToolsApi}. */
|
|
8
20
|
public abstract tools: PluginToolsApi
|
|
21
|
+
/** CRUD operations on Snaptrude entities. See {@linkcode PluginEntityApi}. */
|
|
9
22
|
public abstract entity: PluginEntityApi
|
|
23
|
+
/** Unit conversion utilities. See {@linkcode PluginUnitsApi}. */
|
|
10
24
|
public abstract units: PluginUnitsApi
|
|
11
25
|
|
|
12
26
|
constructor() {}
|
package/src/api/tools/index.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { PluginSelectionApi } from "./selection"
|
|
2
2
|
import { PluginTransformApi } from "./transform"
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Snaptrude editor tools for querying and manipulating scene components.
|
|
6
|
+
*
|
|
7
|
+
* - {@linkcode PluginToolsApi.selection} — Query the current user selection
|
|
8
|
+
* - {@linkcode PluginToolsApi.transform} — Move and rotate components
|
|
9
|
+
*/
|
|
4
10
|
export abstract class PluginToolsApi {
|
|
11
|
+
/** Query the current selection. See {@linkcode PluginSelectionApi}. */
|
|
5
12
|
public abstract selection: PluginSelectionApi
|
|
13
|
+
/** Move and rotate components. See {@linkcode PluginTransformApi}. */
|
|
6
14
|
public abstract transform: PluginTransformApi
|
|
7
15
|
|
|
8
16
|
constructor() {}
|
|
@@ -1,12 +1,49 @@
|
|
|
1
1
|
import * as z from "zod"
|
|
2
2
|
import { PluginApiReturn } from "../../types"
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Query the current user selection in the Snaptrude editor.
|
|
6
|
+
*
|
|
7
|
+
* Accessed via `snaptrude.tools.selection`.
|
|
8
|
+
*/
|
|
4
9
|
export abstract class PluginSelectionApi {
|
|
5
10
|
constructor() {}
|
|
6
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Get the IDs of all currently selected components.
|
|
14
|
+
*
|
|
15
|
+
* Returns the component IDs from the editor's active selection stack.
|
|
16
|
+
* If nothing is selected, returns an empty array.
|
|
17
|
+
*
|
|
18
|
+
* The returned IDs can be used with {@linkcode PluginTransformApi.move},
|
|
19
|
+
* {@linkcode PluginTransformApi.rotate}, or entity query methods like
|
|
20
|
+
* {@linkcode PluginSpaceApi.get}.
|
|
21
|
+
*
|
|
22
|
+
* @returns A {@linkcode PluginSelectionGetResult} with a `selected` array
|
|
23
|
+
* of component ID strings
|
|
24
|
+
*
|
|
25
|
+
* # Example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const { selected } = await snaptrude.tools.selection.get()
|
|
28
|
+
* if (selected.length > 0) {
|
|
29
|
+
* // Move selected components 5 units along X
|
|
30
|
+
* await snaptrude.tools.transform.move({
|
|
31
|
+
* componentIds: selected,
|
|
32
|
+
* displacement: snaptrude.core.math.vec3.new(5, 0, 0),
|
|
33
|
+
* })
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
7
37
|
public abstract get(): PluginApiReturn<PluginSelectionGetResult>
|
|
8
38
|
}
|
|
9
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Result of {@linkcode PluginSelectionApi.get}.
|
|
42
|
+
*
|
|
43
|
+
* | Property | Type | Description |
|
|
44
|
+
* |---|---|---|
|
|
45
|
+
* | `selected` | `string[]` | Component IDs of the current selection |
|
|
46
|
+
*/
|
|
10
47
|
export const PluginSelectionGetResult = z.object({
|
|
11
48
|
selected: z.array(z.string()),
|
|
12
49
|
})
|