@snaptrude/plugin-core 0.0.5 → 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.
Files changed (59) 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 +8 -0
  20. package/dist/api/entity/index.d.ts.map +1 -1
  21. package/dist/api/entity/space.d.ts +217 -4
  22. package/dist/api/entity/space.d.ts.map +1 -1
  23. package/dist/api/entity/story.d.ts +166 -0
  24. package/dist/api/entity/story.d.ts.map +1 -1
  25. package/dist/api/index.d.ts +14 -0
  26. package/dist/api/index.d.ts.map +1 -1
  27. package/dist/api/tools/index.d.ts +8 -0
  28. package/dist/api/tools/index.d.ts.map +1 -1
  29. package/dist/api/tools/selection.d.ts +37 -0
  30. package/dist/api/tools/selection.d.ts.map +1 -1
  31. package/dist/api/tools/transform.d.ts +82 -0
  32. package/dist/api/tools/transform.d.ts.map +1 -1
  33. package/dist/api/units/index.d.ts +72 -13
  34. package/dist/api/units/index.d.ts.map +1 -1
  35. package/dist/index.cjs +322 -36
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.js +321 -35
  38. package/dist/index.js.map +1 -1
  39. package/dist/types.d.ts +8 -1
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/api/core/geom/arc.ts +50 -1
  43. package/src/api/core/geom/curve.ts +26 -1
  44. package/src/api/core/geom/index.ts +16 -0
  45. package/src/api/core/geom/line.ts +35 -1
  46. package/src/api/core/geom/profile.ts +66 -2
  47. package/src/api/core/index.ts +8 -0
  48. package/src/api/core/math/index.ts +8 -0
  49. package/src/api/core/math/quat.ts +156 -15
  50. package/src/api/core/math/vec3.ts +131 -14
  51. package/src/api/entity/index.ts +8 -0
  52. package/src/api/entity/space.ts +218 -5
  53. package/src/api/entity/story.ts +166 -0
  54. package/src/api/index.ts +14 -0
  55. package/src/api/tools/index.ts +8 -0
  56. package/src/api/tools/selection.ts +37 -0
  57. package/src/api/tools/transform.ts +82 -0
  58. package/src/api/units/index.ts +72 -13
  59. package/src/types.ts +8 -1
@@ -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,41 @@
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
+ * @returns A {@linkcode PluginUnitsConvertFromResult} containing the converted
29
+ * `value` in Babylon units
16
30
  *
17
- * @example
31
+ * # Example
18
32
  * ```ts
33
+ * // Convert 5 meters to Babylon units for use in API calls
19
34
  * const result = await snaptrude.units.convertFrom({ unit: "meters", value: 5 })
20
- * // result.value is 5 meters expressed in Babylon units
35
+ * const { spaceId } = await snaptrude.entity.space.createRectangular({
36
+ * position: snaptrude.core.math.vec3.new(0, 0, 0),
37
+ * dimensions: { width: result.value, height: result.value, depth: result.value },
38
+ * })
21
39
  * ```
22
40
  */
23
41
  public abstract convertFrom(
@@ -25,19 +43,30 @@ export abstract class PluginUnitsApi {
25
43
  ): PluginApiReturn<PluginUnitsConvertFromResult>
26
44
 
27
45
  /**
28
- * Convert a value from Snaptrude's internal (Babylon) units to the given unit.
46
+ * Convert a value from Snaptrude's internal (Babylon) units to a real-world unit.
29
47
  *
30
48
  * Use this when you have a value in Snaptrude's internal coordinate system
31
49
  * and need to express it in real-world units (e.g. meters, feet).
32
50
  *
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
51
+ * @param args - An object containing:
52
+ * - {@linkcode PluginUnitsConvertToArgs.unit args.unit} The target unit
53
+ * to convert to. See {@linkcode PUnitType} for supported values.
54
+ * - {@linkcode PluginUnitsConvertToArgs.value args.value} — The numeric
55
+ * value in Babylon units
56
+ * @returns A {@linkcode PluginUnitsConvertToResult} containing the converted
57
+ * `value` in the target unit
36
58
  *
37
- * @example
59
+ * # Example
38
60
  * ```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
61
+ * // Get a space's area in square meters
62
+ * const info = await snaptrude.entity.space.get({
63
+ * spaceId: "some-id",
64
+ * properties: ["area"],
65
+ * })
66
+ * const areaInMeters = await snaptrude.units.convertTo({
67
+ * unit: "meters",
68
+ * value: info.area!,
69
+ * })
41
70
  * ```
42
71
  */
43
72
  public abstract convertTo(
@@ -68,6 +97,14 @@ export const PUnitType = z.enum([
68
97
 
69
98
  export type PUnitType = z.infer<typeof PUnitType>
70
99
 
100
+ /**
101
+ * Arguments for {@linkcode PluginUnitsApi.convertFrom}.
102
+ *
103
+ * | Property | Type | Description |
104
+ * |---|---|---|
105
+ * | `unit` | {@linkcode PUnitType} | Source real-world unit |
106
+ * | `value` | `number` | Numeric value in the source unit |
107
+ */
71
108
  export const PluginUnitsConvertFromArgs = z.object({
72
109
  unit: PUnitType,
73
110
  value: z.number(),
@@ -75,12 +112,27 @@ export const PluginUnitsConvertFromArgs = z.object({
75
112
 
76
113
  export type PluginUnitsConvertFromArgs = z.infer<typeof PluginUnitsConvertFromArgs>
77
114
 
115
+ /**
116
+ * Result of {@linkcode PluginUnitsApi.convertFrom}.
117
+ *
118
+ * | Property | Type | Description |
119
+ * |---|---|---|
120
+ * | `value` | `number` | The converted value in Babylon units |
121
+ */
78
122
  export const PluginUnitsConvertFromResult = z.object({
79
123
  value: z.number(),
80
124
  })
81
125
 
82
126
  export type PluginUnitsConvertFromResult = z.infer<typeof PluginUnitsConvertFromResult>
83
127
 
128
+ /**
129
+ * Arguments for {@linkcode PluginUnitsApi.convertTo}.
130
+ *
131
+ * | Property | Type | Description |
132
+ * |---|---|---|
133
+ * | `unit` | {@linkcode PUnitType} | Target real-world unit |
134
+ * | `value` | `number` | Numeric value in Babylon units |
135
+ */
84
136
  export const PluginUnitsConvertToArgs = z.object({
85
137
  unit: PUnitType,
86
138
  value: z.number(),
@@ -88,6 +140,13 @@ export const PluginUnitsConvertToArgs = z.object({
88
140
 
89
141
  export type PluginUnitsConvertToArgs = z.infer<typeof PluginUnitsConvertToArgs>
90
142
 
143
+ /**
144
+ * Result of {@linkcode PluginUnitsApi.convertTo}.
145
+ *
146
+ * | Property | Type | Description |
147
+ * |---|---|---|
148
+ * | `value` | `number` | The converted value in the target unit |
149
+ */
91
150
  export const PluginUnitsConvertToResult = z.object({
92
151
  value: z.number(),
93
152
  })
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