@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.
- 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
|
@@ -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(),
|
package/src/api/units/index.ts
CHANGED
|
@@ -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
|
|
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
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
34
|
-
* @
|
|
35
|
-
*
|
|
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
|
-
*
|
|
59
|
+
* # Example
|
|
38
60
|
* ```ts
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
|
|
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
|