@snaptrude/plugin-core 0.0.5 → 0.0.7

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 (63) hide show
  1. package/dist/api/core/geom/arc.d.ts +50 -1
  2. package/dist/api/core/geom/arc.d.ts.map +1 -1
  3. package/dist/api/core/geom/curve.d.ts +26 -1
  4. package/dist/api/core/geom/curve.d.ts.map +1 -1
  5. package/dist/api/core/geom/index.d.ts +16 -0
  6. package/dist/api/core/geom/index.d.ts.map +1 -1
  7. package/dist/api/core/geom/line.d.ts +35 -1
  8. package/dist/api/core/geom/line.d.ts.map +1 -1
  9. package/dist/api/core/geom/profile.d.ts +66 -2
  10. package/dist/api/core/geom/profile.d.ts.map +1 -1
  11. package/dist/api/core/index.d.ts +8 -0
  12. package/dist/api/core/index.d.ts.map +1 -1
  13. package/dist/api/core/math/index.d.ts +8 -0
  14. package/dist/api/core/math/index.d.ts.map +1 -1
  15. package/dist/api/core/math/quat.d.ts +156 -15
  16. package/dist/api/core/math/quat.d.ts.map +1 -1
  17. package/dist/api/core/math/vec3.d.ts +131 -14
  18. package/dist/api/core/math/vec3.d.ts.map +1 -1
  19. package/dist/api/entity/index.d.ts +13 -0
  20. package/dist/api/entity/index.d.ts.map +1 -1
  21. package/dist/api/entity/referenceLine.d.ts +259 -0
  22. package/dist/api/entity/referenceLine.d.ts.map +1 -0
  23. package/dist/api/entity/space.d.ts +467 -7
  24. package/dist/api/entity/space.d.ts.map +1 -1
  25. package/dist/api/entity/story.d.ts +166 -0
  26. package/dist/api/entity/story.d.ts.map +1 -1
  27. package/dist/api/index.d.ts +14 -0
  28. package/dist/api/index.d.ts.map +1 -1
  29. package/dist/api/tools/index.d.ts +8 -0
  30. package/dist/api/tools/index.d.ts.map +1 -1
  31. package/dist/api/tools/selection.d.ts +37 -0
  32. package/dist/api/tools/selection.d.ts.map +1 -1
  33. package/dist/api/tools/transform.d.ts +82 -0
  34. package/dist/api/tools/transform.d.ts.map +1 -1
  35. package/dist/api/units/index.d.ts +81 -13
  36. package/dist/api/units/index.d.ts.map +1 -1
  37. package/dist/index.cjs +547 -126
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.js +533 -126
  40. package/dist/index.js.map +1 -1
  41. package/dist/types.d.ts +8 -1
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +2 -2
  44. package/src/api/core/geom/arc.ts +50 -1
  45. package/src/api/core/geom/curve.ts +26 -1
  46. package/src/api/core/geom/index.ts +16 -0
  47. package/src/api/core/geom/line.ts +35 -1
  48. package/src/api/core/geom/profile.ts +66 -2
  49. package/src/api/core/index.ts +8 -0
  50. package/src/api/core/math/index.ts +8 -0
  51. package/src/api/core/math/quat.ts +156 -15
  52. package/src/api/core/math/vec3.ts +131 -14
  53. package/src/api/entity/index.ts +13 -0
  54. package/src/api/entity/referenceLine.ts +215 -0
  55. package/src/api/entity/space.ts +447 -11
  56. package/src/api/entity/story.ts +166 -0
  57. package/src/api/index.ts +14 -0
  58. package/src/api/tools/index.ts +8 -0
  59. package/src/api/tools/selection.ts +37 -0
  60. package/src/api/tools/transform.ts +82 -0
  61. package/src/api/units/index.ts +81 -13
  62. package/src/types.ts +8 -1
  63. package/tsup.config.ts +0 -1
@@ -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() {}
@@ -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
  })
@@ -2,14 +2,78 @@ import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../types"
3
3
  import { PVec3 } from "../core/math/vec3"
4
4
 
5
+ /**
6
+ * Transform operations — move and rotate scene components.
7
+ *
8
+ * All transform methods accept an array of component IDs and apply the
9
+ * transformation to each. Operations are recorded in Snaptrude's
10
+ * command system for undo/redo support.
11
+ *
12
+ * Accessed via `snaptrude.tools.transform`.
13
+ */
5
14
  export abstract class PluginTransformApi {
6
15
  constructor() {}
7
16
 
17
+ /**
18
+ * Translate components by a displacement vector.
19
+ *
20
+ * Each component's position is offset by the given
21
+ * {@linkcode PluginMoveArgs.displacement displacement} vector.
22
+ * This operation is undoable.
23
+ *
24
+ * @param args - An object containing:
25
+ * - {@linkcode PluginMoveArgs.componentIds args.componentIds} — Array of component
26
+ * ID strings to move
27
+ * - {@linkcode PluginMoveArgs.displacement args.displacement} — Translation vector
28
+ * as a {@linkcode PVec3} in Babylon units
29
+ * @throws If any component ID is not found in the scene
30
+ *
31
+ * # Example
32
+ * ```ts
33
+ * const { vec3 } = snaptrude.core.math
34
+ *
35
+ * // Move a space 10 units along the X axis
36
+ * await snaptrude.tools.transform.move({
37
+ * componentIds: ["some-space-id"],
38
+ * displacement: vec3.new(10, 0, 0),
39
+ * })
40
+ * ```
41
+ */
8
42
  public abstract move({
9
43
  componentIds,
10
44
  displacement,
11
45
  }: PluginMoveArgs): PluginApiReturn<void>
12
46
 
47
+ /**
48
+ * Rotate components around an axis through a pivot point.
49
+ *
50
+ * Each component is rotated by {@linkcode PluginRotateArgs.angle angle}
51
+ * radians around the {@linkcode PluginRotateArgs.axis axis} vector,
52
+ * pivoting about the {@linkcode PluginRotateArgs.pivot pivot} point.
53
+ * This operation is undoable.
54
+ *
55
+ * @param args - An object containing:
56
+ * - {@linkcode PluginRotateArgs.componentIds args.componentIds} — Array of component
57
+ * ID strings to rotate
58
+ * - {@linkcode PluginRotateArgs.angle args.angle} — Rotation angle in **radians**
59
+ * - {@linkcode PluginRotateArgs.axis args.axis} — Rotation axis as a {@linkcode PVec3}
60
+ * - {@linkcode PluginRotateArgs.pivot args.pivot} — Pivot point as a {@linkcode PVec3}
61
+ * in Babylon units
62
+ * @throws If any component ID is not found in the scene
63
+ *
64
+ * # Example
65
+ * ```ts
66
+ * const { vec3 } = snaptrude.core.math
67
+ *
68
+ * // Rotate a space 45° around the Y axis at the origin
69
+ * await snaptrude.tools.transform.rotate({
70
+ * componentIds: ["some-space-id"],
71
+ * angle: Math.PI / 4,
72
+ * axis: vec3.new(0, 1, 0),
73
+ * pivot: vec3.new(0, 0, 0),
74
+ * })
75
+ * ```
76
+ */
13
77
  public abstract rotate({
14
78
  componentIds,
15
79
  angle,
@@ -18,6 +82,14 @@ export abstract class PluginTransformApi {
18
82
  }: PluginRotateArgs): PluginApiReturn<void>
19
83
  }
20
84
 
85
+ /**
86
+ * Arguments for {@linkcode PluginTransformApi.move}.
87
+ *
88
+ * | Property | Type | Description |
89
+ * |---|---|---|
90
+ * | `componentIds` | `string[]` | Component IDs to move |
91
+ * | `displacement` | {@linkcode PVec3} | Translation vector in Babylon units |
92
+ */
21
93
  export const PluginMoveArgs = z.object({
22
94
  componentIds: z.array(z.string()),
23
95
  displacement: PVec3,
@@ -25,6 +97,16 @@ export const PluginMoveArgs = z.object({
25
97
 
26
98
  export type PluginMoveArgs = z.infer<typeof PluginMoveArgs>
27
99
 
100
+ /**
101
+ * Arguments for {@linkcode PluginTransformApi.rotate}.
102
+ *
103
+ * | Property | Type | Description |
104
+ * |---|---|---|
105
+ * | `componentIds` | `string[]` | Component IDs to rotate |
106
+ * | `angle` | `number` | Rotation angle in radians |
107
+ * | `axis` | {@linkcode PVec3} | Rotation axis direction |
108
+ * | `pivot` | {@linkcode PVec3} | Pivot point in Babylon units |
109
+ */
28
110
  export const PluginRotateArgs = z.object({
29
111
  componentIds: z.array(z.string()),
30
112
  angle: z.number(),
@@ -1,23 +1,43 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../types"
3
3
 
4
+ /**
5
+ * Unit conversion between real-world units and Snaptrude's internal
6
+ * (Babylon) coordinate system.
7
+ *
8
+ * Snaptrude uses an internal unit system (Babylon units) for all
9
+ * coordinates and dimensions. Use these methods to convert between
10
+ * real-world measurements and Babylon units.
11
+ *
12
+ * Accessed via `snaptrude.units`.
13
+ */
4
14
  export abstract class PluginUnitsApi {
5
15
  constructor() {}
6
16
 
7
17
  /**
8
- * Convert a value from the given unit to Snaptrude's internal (Babylon) units.
18
+ * Convert a value from a real-world unit to Snaptrude's internal (Babylon) units.
9
19
  *
10
20
  * Use this when you have a measurement in real-world units (e.g. meters, feet)
11
21
  * and need to convert it to the coordinate system used by Snaptrude internally.
12
22
  *
13
- * @param args.unit - The source unit to convert from (e.g. `"meters"`, `"feet-inches"`)
14
- * @param args.value - The numeric value in the source unit
15
- * @returns An object containing the converted `value` in Snaptrude/Babylon units
23
+ * @param args - An object containing:
24
+ * - {@linkcode PluginUnitsConvertFromArgs.unit args.unit} The source unit
25
+ * to convert from. See {@linkcode PUnitType} for supported values.
26
+ * - {@linkcode PluginUnitsConvertFromArgs.value args.value} — The numeric
27
+ * value in the source unit
28
+ * - {@linkcode PluginUnitsConvertFromArgs.degree args.degree} — (Optional)
29
+ * Degree of the unit: 1 for length, 2 for area, 3 for volume. Defaults to 1
30
+ * @returns A {@linkcode PluginUnitsConvertFromResult} containing the converted
31
+ * `value` in Babylon units
16
32
  *
17
- * @example
33
+ * # Example
18
34
  * ```ts
35
+ * // Convert 5 meters to Babylon units for use in API calls
19
36
  * const result = await snaptrude.units.convertFrom({ unit: "meters", value: 5 })
20
- * // result.value is 5 meters expressed in Babylon units
37
+ * const { spaceId } = await snaptrude.entity.space.createRectangular({
38
+ * position: snaptrude.core.math.vec3.new(0, 0, 0),
39
+ * dimensions: { width: result.value, height: result.value, depth: result.value },
40
+ * })
21
41
  * ```
22
42
  */
23
43
  public abstract convertFrom(
@@ -25,19 +45,33 @@ export abstract class PluginUnitsApi {
25
45
  ): PluginApiReturn<PluginUnitsConvertFromResult>
26
46
 
27
47
  /**
28
- * Convert a value from Snaptrude's internal (Babylon) units to the given unit.
48
+ * Convert a value from Snaptrude's internal (Babylon) units to a real-world unit.
29
49
  *
30
50
  * Use this when you have a value in Snaptrude's internal coordinate system
31
51
  * and need to express it in real-world units (e.g. meters, feet).
32
52
  *
33
- * @param args.unit - The target unit to convert to (e.g. `"meters"`, `"feet-inches"`)
34
- * @param args.value - The numeric value in Snaptrude/Babylon units
35
- * @returns An object containing the converted `value` in the target unit
53
+ * @param args - An object containing:
54
+ * - {@linkcode PluginUnitsConvertToArgs.unit args.unit} The target unit
55
+ * to convert to. See {@linkcode PUnitType} for supported values.
56
+ * - {@linkcode PluginUnitsConvertToArgs.value args.value} — The numeric
57
+ * value in Babylon units
58
+ * - {@linkcode PluginUnitsConvertToArgs.degree args.degree} — (Optional)
59
+ * Degree of the unit: 1 for length, 2 for area, 3 for volume. Defaults to 1
60
+ * @returns A {@linkcode PluginUnitsConvertToResult} containing the converted
61
+ * `value` in the target unit
36
62
  *
37
- * @example
63
+ * # Example
38
64
  * ```ts
39
- * const result = await snaptrude.units.convertTo({ unit: "feet-inches", value: 1.2 })
40
- * // result.value is 1.2 Babylon units expressed in feet
65
+ * // Get a space's area in square meters
66
+ * const info = await snaptrude.entity.space.get({
67
+ * spaceId: "some-id",
68
+ * properties: ["area"],
69
+ * })
70
+ * const areaInMeters = await snaptrude.units.convertTo({
71
+ * unit: "meters",
72
+ * value: info.area!,
73
+ * degree: 2,
74
+ * })
41
75
  * ```
42
76
  */
43
77
  public abstract convertTo(
@@ -68,26 +102,60 @@ export const PUnitType = z.enum([
68
102
 
69
103
  export type PUnitType = z.infer<typeof PUnitType>
70
104
 
105
+ /**
106
+ * Arguments for {@linkcode PluginUnitsApi.convertFrom}.
107
+ *
108
+ * | Property | Type | Description |
109
+ * |---|---|---|
110
+ * | `unit` | {@linkcode PUnitType} | Source real-world unit |
111
+ * | `value` | `number` | Numeric value in the source unit |
112
+ * | `degree` | `1 \| 2 \| 3` | (Optional) Degree of the unit (e.g. 1 for length, 2 for area, 3 for volume). Defaults to 1 |
113
+ */
71
114
  export const PluginUnitsConvertFromArgs = z.object({
72
115
  unit: PUnitType,
73
116
  value: z.number(),
117
+ degree: z.number().int().min(1).max(3).optional(),
74
118
  })
75
119
 
76
120
  export type PluginUnitsConvertFromArgs = z.infer<typeof PluginUnitsConvertFromArgs>
77
121
 
122
+ /**
123
+ * Result of {@linkcode PluginUnitsApi.convertFrom}.
124
+ *
125
+ * | Property | Type | Description |
126
+ * |---|---|---|
127
+ * | `value` | `number` | The converted value in Babylon units |
128
+ */
78
129
  export const PluginUnitsConvertFromResult = z.object({
79
130
  value: z.number(),
80
131
  })
81
132
 
82
133
  export type PluginUnitsConvertFromResult = z.infer<typeof PluginUnitsConvertFromResult>
83
134
 
135
+ /**
136
+ * Arguments for {@linkcode PluginUnitsApi.convertTo}.
137
+ *
138
+ * | Property | Type | Description |
139
+ * |---|---|---|
140
+ * | `unit` | {@linkcode PUnitType} | Target real-world unit |
141
+ * | `value` | `number` | Numeric value in Babylon units |
142
+ * | `degree` | `1 \| 2 \| 3` | (Optional) Degree of the unit (e.g. 1 for length, 2 for area, 3 for volume). Defaults to 1 |
143
+ */
84
144
  export const PluginUnitsConvertToArgs = z.object({
85
145
  unit: PUnitType,
86
146
  value: z.number(),
147
+ degree: z.number().int().min(1).max(3).optional(),
87
148
  })
88
149
 
89
150
  export type PluginUnitsConvertToArgs = z.infer<typeof PluginUnitsConvertToArgs>
90
151
 
152
+ /**
153
+ * Result of {@linkcode PluginUnitsApi.convertTo}.
154
+ *
155
+ * | Property | Type | Description |
156
+ * |---|---|---|
157
+ * | `value` | `number` | The converted value in the target unit |
158
+ */
91
159
  export const PluginUnitsConvertToResult = z.object({
92
160
  value: z.number(),
93
161
  })
package/src/types.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  /**
2
- * A ComponentId is a unique identifier for a component in the scene.
2
+ * A unique identifier for a component in the Snaptrude scene.
3
+ *
4
+ * Component IDs are returned by entity creation methods (e.g.
5
+ * {@linkcode PluginSpaceApi.createRectangular}) and can be used with
6
+ * query and transform methods throughout the API.
3
7
  */
4
8
  export type ComponentId = string
5
9
 
6
10
  /**
7
11
  * Return type for a plugin API method.
12
+ *
13
+ * Methods that require a host round-trip return `Promise<T>`,
14
+ * while pure local computations may return `T` directly.
8
15
  */
9
16
  export type PluginApiReturn<T> = Promise<T> | T
package/tsup.config.ts CHANGED
@@ -6,7 +6,6 @@ export default defineConfig( (options) => {
6
6
  format: ["cjs", "esm"],
7
7
  dts: false,
8
8
  sourcemap: true,
9
- clean: true,
10
9
  onSuccess: "tsc", // Run tsc to generate d.ts and d.ts.map
11
10
  watch: options.watch,
12
11
  }