@snaptrude/plugin-core 0.2.9 → 0.5.0
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/AGENTS.md +128 -50
- package/CHANGELOG.md +52 -6
- package/api-manifest.full.json +3999 -0
- package/api-manifest.json +3845 -0
- package/dist/api/core/buildings.d.ts +427 -0
- package/dist/api/core/buildings.d.ts.map +1 -0
- package/dist/api/core/comment/index.d.ts +230 -0
- package/dist/api/core/comment/index.d.ts.map +1 -0
- package/dist/api/core/geom/create/index.d.ts +247 -0
- package/dist/api/core/geom/create/index.d.ts.map +1 -0
- package/dist/api/core/geom/delete/index.d.ts +72 -0
- package/dist/api/core/geom/delete/index.d.ts.map +1 -0
- package/dist/api/core/geom/index.d.ts +24 -23
- package/dist/api/core/geom/index.d.ts.map +1 -1
- package/dist/api/core/geom/query/arc.d.ts +169 -0
- package/dist/api/core/geom/query/arc.d.ts.map +1 -0
- package/dist/api/core/geom/query/brep.d.ts +402 -0
- package/dist/api/core/geom/query/brep.d.ts.map +1 -0
- package/dist/api/core/geom/query/circle.d.ts +378 -0
- package/dist/api/core/geom/query/circle.d.ts.map +1 -0
- package/dist/api/core/geom/query/contour.d.ts +450 -0
- package/dist/api/core/geom/query/contour.d.ts.map +1 -0
- package/dist/api/core/geom/query/curve.d.ts +918 -0
- package/dist/api/core/geom/query/curve.d.ts.map +1 -0
- package/dist/api/core/geom/query/edge.d.ts +128 -0
- package/dist/api/core/geom/query/edge.d.ts.map +1 -0
- package/dist/api/core/geom/query/face.d.ts +363 -0
- package/dist/api/core/geom/query/face.d.ts.map +1 -0
- package/dist/api/core/geom/query/halfedge.d.ts +206 -0
- package/dist/api/core/geom/query/halfedge.d.ts.map +1 -0
- package/dist/api/core/geom/query/index.d.ts +61 -0
- package/dist/api/core/geom/query/index.d.ts.map +1 -0
- package/dist/api/core/geom/query/profile.d.ts +410 -0
- package/dist/api/core/geom/query/profile.d.ts.map +1 -0
- package/dist/api/core/geom/query/vertex.d.ts +187 -0
- package/dist/api/core/geom/query/vertex.d.ts.map +1 -0
- package/dist/api/core/geom/update/contour.d.ts +272 -0
- package/dist/api/core/geom/update/contour.d.ts.map +1 -0
- package/dist/api/core/geom/update/curve.d.ts +180 -0
- package/dist/api/core/geom/update/curve.d.ts.map +1 -0
- package/dist/api/core/geom/update/index.d.ts +27 -0
- package/dist/api/core/geom/update/index.d.ts.map +1 -0
- package/dist/api/core/geom/update/profile.d.ts +329 -0
- package/dist/api/core/geom/update/profile.d.ts.map +1 -0
- package/dist/api/core/groups.d.ts +485 -0
- package/dist/api/core/groups.d.ts.map +1 -0
- package/dist/api/core/history/index.d.ts +78 -0
- package/dist/api/core/history/index.d.ts.map +1 -0
- package/dist/api/core/index.d.ts +46 -1
- package/dist/api/core/index.d.ts.map +1 -1
- package/dist/api/core/layers.d.ts +402 -0
- package/dist/api/core/layers.d.ts.map +1 -0
- package/dist/api/core/math/quat.d.ts +111 -128
- package/dist/api/core/math/quat.d.ts.map +1 -1
- package/dist/api/core/math/vec3.d.ts +120 -102
- package/dist/api/core/math/vec3.d.ts.map +1 -1
- package/dist/api/core/project/index.d.ts +399 -0
- package/dist/api/core/project/index.d.ts.map +1 -0
- package/dist/api/core/tags.d.ts +755 -0
- package/dist/api/core/tags.d.ts.map +1 -0
- package/dist/api/core/units/index.d.ts +175 -0
- package/dist/api/core/units/index.d.ts.map +1 -0
- package/dist/api/core/zoom/index.d.ts +45 -0
- package/dist/api/core/zoom/index.d.ts.map +1 -0
- package/dist/api/design/boolean/index.d.ts +168 -0
- package/dist/api/design/boolean/index.d.ts.map +1 -0
- package/dist/api/design/create/index.d.ts +828 -0
- package/dist/api/design/create/index.d.ts.map +1 -0
- package/dist/api/design/delete/index.d.ts +63 -0
- package/dist/api/design/delete/index.d.ts.map +1 -0
- package/dist/api/design/doors/index.d.ts +268 -0
- package/dist/api/design/doors/index.d.ts.map +1 -0
- package/dist/api/design/edit/index.d.ts +49 -0
- package/dist/api/design/edit/index.d.ts.map +1 -0
- package/dist/api/design/erase/index.d.ts +160 -0
- package/dist/api/design/erase/index.d.ts.map +1 -0
- package/dist/api/design/furniture/index.d.ts +123 -0
- package/dist/api/design/furniture/index.d.ts.map +1 -0
- package/dist/api/design/index.d.ts +153 -0
- package/dist/api/design/index.d.ts.map +1 -0
- package/dist/api/design/lock.d.ts +41 -0
- package/dist/api/design/lock.d.ts.map +1 -0
- package/dist/api/design/materials/index.d.ts +297 -0
- package/dist/api/design/materials/index.d.ts.map +1 -0
- package/dist/api/design/query/geometry/index.d.ts +140 -0
- package/dist/api/design/query/geometry/index.d.ts.map +1 -0
- package/dist/api/design/query/index.d.ts +1011 -0
- package/dist/api/design/query/index.d.ts.map +1 -0
- package/dist/api/design/query/spaces.d.ts +221 -0
- package/dist/api/design/query/spaces.d.ts.map +1 -0
- package/dist/api/design/selection/index.d.ts +138 -0
- package/dist/api/design/selection/index.d.ts.map +1 -0
- package/dist/api/design/shared.d.ts +38 -0
- package/dist/api/design/shared.d.ts.map +1 -0
- package/dist/api/design/transform/index.d.ts +87 -0
- package/dist/api/design/transform/index.d.ts.map +1 -0
- package/dist/api/design/update/index.d.ts +178 -0
- package/dist/api/design/update/index.d.ts.map +1 -0
- package/dist/api/design/windows/index.d.ts +189 -0
- package/dist/api/design/windows/index.d.ts.map +1 -0
- package/dist/api/entity/buildableEnvelope.d.ts +51 -23
- package/dist/api/entity/buildableEnvelope.d.ts.map +1 -1
- package/dist/api/entity/department.d.ts +0 -98
- package/dist/api/entity/department.d.ts.map +1 -1
- package/dist/api/entity/index.d.ts +4 -9
- package/dist/api/entity/index.d.ts.map +1 -1
- package/dist/api/entity/referenceLine.d.ts +49 -106
- package/dist/api/entity/referenceLine.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +76 -828
- package/dist/api/entity/space.d.ts.map +1 -1
- package/dist/api/entity/story.d.ts +47 -37
- package/dist/api/entity/story.d.ts.map +1 -1
- package/dist/api/index.d.ts +17 -17
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/presentation/aiInspiration.d.ts +440 -0
- package/dist/api/presentation/aiInspiration.d.ts.map +1 -0
- package/dist/api/presentation/diagrams.d.ts +81 -0
- package/dist/api/presentation/diagrams.d.ts.map +1 -0
- package/dist/api/presentation/import.d.ts +113 -0
- package/dist/api/presentation/import.d.ts.map +1 -0
- package/dist/api/presentation/index.d.ts +46 -0
- package/dist/api/presentation/index.d.ts.map +1 -0
- package/dist/api/presentation/sheets.d.ts +176 -0
- package/dist/api/presentation/sheets.d.ts.map +1 -0
- package/dist/api/presentation/views.d.ts +296 -0
- package/dist/api/presentation/views.d.ts.map +1 -0
- package/dist/api/program/adjacency.d.ts +155 -0
- package/dist/api/program/adjacency.d.ts.map +1 -0
- package/dist/api/program/areas.d.ts +360 -0
- package/dist/api/program/areas.d.ts.map +1 -0
- package/dist/api/program/classification.d.ts +135 -0
- package/dist/api/program/classification.d.ts.map +1 -0
- package/dist/api/program/cores.d.ts +174 -0
- package/dist/api/program/cores.d.ts.map +1 -0
- package/dist/api/program/departments.d.ts +431 -0
- package/dist/api/program/departments.d.ts.map +1 -0
- package/dist/api/program/index.d.ts +69 -0
- package/dist/api/program/index.d.ts.map +1 -0
- package/dist/api/program/layout.d.ts +63 -0
- package/dist/api/program/layout.d.ts.map +1 -0
- package/dist/api/program/metrics.d.ts +108 -0
- package/dist/api/program/metrics.d.ts.map +1 -0
- package/dist/api/program/site.d.ts +367 -0
- package/dist/api/program/site.d.ts.map +1 -0
- package/dist/api/program/spreadsheet.d.ts +2041 -0
- package/dist/api/program/spreadsheet.d.ts.map +1 -0
- package/dist/handles.d.ts +138 -0
- package/dist/handles.d.ts.map +1 -0
- package/dist/host-utils.d.ts +7 -5
- package/dist/host-utils.d.ts.map +1 -1
- package/dist/index.cjs +3897 -1542
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3326 -1462
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/scripts/generate-manifest.mjs +193 -0
- package/scripts/generate-manifest.test.mjs +193 -0
- package/src/api/core/buildings.ts +485 -0
- package/src/api/core/comment/index.ts +258 -0
- package/src/api/core/geom/create/index.ts +293 -0
- package/src/api/core/geom/delete/index.ts +78 -0
- package/src/api/core/geom/index.ts +24 -23
- package/src/api/core/geom/query/arc.ts +169 -0
- package/src/api/core/geom/query/brep.ts +444 -0
- package/src/api/core/geom/query/circle.ts +404 -0
- package/src/api/core/geom/query/contour.ts +540 -0
- package/src/api/core/geom/query/curve.ts +1078 -0
- package/src/api/core/geom/query/edge.ts +130 -0
- package/src/api/core/geom/query/face.ts +403 -0
- package/src/api/core/geom/query/halfedge.ts +210 -0
- package/src/api/core/geom/query/index.ts +63 -0
- package/src/api/core/geom/query/profile.ts +473 -0
- package/src/api/core/geom/query/vertex.ts +205 -0
- package/src/api/core/geom/update/contour.ts +315 -0
- package/src/api/core/geom/update/curve.ts +209 -0
- package/src/api/core/geom/update/index.ts +29 -0
- package/src/api/core/geom/update/profile.ts +377 -0
- package/src/api/core/groups.ts +521 -0
- package/src/api/core/history/index.ts +84 -0
- package/src/api/core/index.ts +46 -1
- package/src/api/core/layers.ts +333 -0
- package/src/api/core/math/quat.ts +112 -235
- package/src/api/core/math/vec3.ts +124 -159
- package/src/api/core/project/index.ts +418 -0
- package/src/api/core/tags.ts +808 -0
- package/src/api/core/units/index.ts +164 -0
- package/src/api/core/zoom/index.ts +47 -0
- package/src/api/design/boolean/index.ts +179 -0
- package/src/api/design/create/index.ts +886 -0
- package/src/api/design/delete/index.ts +67 -0
- package/src/api/design/doors/index.ts +285 -0
- package/src/api/design/edit/index.ts +54 -0
- package/src/api/design/erase/index.ts +151 -0
- package/src/api/design/furniture/index.ts +130 -0
- package/src/api/design/index.ts +162 -0
- package/src/api/design/lock.ts +42 -0
- package/src/api/design/materials/index.ts +301 -0
- package/src/api/design/query/geometry/index.ts +166 -0
- package/src/api/design/query/index.ts +937 -0
- package/src/api/design/query/spaces.ts +132 -0
- package/src/api/design/selection/index.ts +144 -0
- package/src/api/design/shared.ts +40 -0
- package/src/api/design/transform/index.ts +93 -0
- package/src/api/design/update/index.ts +117 -0
- package/src/api/design/windows/index.ts +207 -0
- package/src/api/entity/buildableEnvelope.ts +64 -23
- package/src/api/entity/department.ts +0 -113
- package/src/api/entity/index.ts +4 -9
- package/src/api/entity/referenceLine.ts +50 -38
- package/src/api/entity/space.ts +84 -440
- package/src/api/entity/story.ts +53 -42
- package/src/api/index.ts +17 -17
- package/src/api/presentation/aiInspiration.ts +362 -0
- package/src/api/presentation/diagrams.ts +84 -0
- package/src/api/presentation/import.ts +112 -0
- package/src/api/presentation/index.ts +48 -0
- package/src/api/presentation/sheets.ts +198 -0
- package/src/api/presentation/views.ts +303 -0
- package/src/api/program/adjacency.ts +164 -0
- package/src/api/program/areas.ts +335 -0
- package/src/api/program/classification.ts +138 -0
- package/src/api/program/cores.ts +171 -0
- package/src/api/program/departments.ts +465 -0
- package/src/api/program/index.ts +71 -0
- package/src/api/program/layout.ts +68 -0
- package/src/api/program/metrics.ts +120 -0
- package/src/api/program/site.ts +326 -0
- package/src/api/program/spreadsheet.ts +2075 -0
- package/src/handles.ts +148 -0
- package/src/host-utils.ts +10 -6
- package/src/index.ts +1 -0
- package/dist/api/core/geom/arc.d.ts +0 -81
- package/dist/api/core/geom/arc.d.ts.map +0 -1
- package/dist/api/core/geom/curve.d.ts +0 -70
- package/dist/api/core/geom/curve.d.ts.map +0 -1
- package/dist/api/core/geom/line.d.ts +0 -56
- package/dist/api/core/geom/line.d.ts.map +0 -1
- package/dist/api/core/geom/profile.d.ts +0 -121
- package/dist/api/core/geom/profile.d.ts.map +0 -1
- package/dist/api/documentation/aiInspiration.d.ts +0 -2155
- package/dist/api/documentation/aiInspiration.d.ts.map +0 -1
- package/dist/api/documentation/index.d.ts +0 -13
- package/dist/api/documentation/index.d.ts.map +0 -1
- package/dist/api/tools/copy.d.ts +0 -59
- package/dist/api/tools/copy.d.ts.map +0 -1
- package/dist/api/tools/index.d.ts +0 -29
- package/dist/api/tools/index.d.ts.map +0 -1
- package/dist/api/tools/offset.d.ts +0 -43
- package/dist/api/tools/offset.d.ts.map +0 -1
- package/dist/api/tools/selection.d.ts +0 -48
- package/dist/api/tools/selection.d.ts.map +0 -1
- package/dist/api/tools/transform.d.ts +0 -114
- package/dist/api/tools/transform.d.ts.map +0 -1
- package/dist/api/units/index.d.ts +0 -163
- package/dist/api/units/index.d.ts.map +0 -1
- package/src/api/core/geom/arc.ts +0 -70
- package/src/api/core/geom/curve.ts +0 -41
- package/src/api/core/geom/line.ts +0 -53
- package/src/api/core/geom/profile.ts +0 -94
- package/src/api/documentation/aiInspiration.ts +0 -871
- package/src/api/documentation/index.ts +0 -15
- package/src/api/tools/copy.ts +0 -55
- package/src/api/tools/index.ts +0 -35
- package/src/api/tools/offset.ts +0 -43
- package/src/api/tools/selection.ts +0 -51
- package/src/api/tools/transform.ts +0 -117
- package/src/api/units/index.ts +0 -163
|
@@ -1,295 +1,172 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { PluginApiReturn } from "../../../types"
|
|
2
|
+
import { Vec3Handle, QuatHandle, QuatComponents } from "../../../handles"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Quaternion operations
|
|
5
|
+
* Quaternion operations (all-handle model, §11).
|
|
6
6
|
*
|
|
7
|
-
* Quaternions
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Accessed via `snaptrude.core.math.quat`.
|
|
7
|
+
* Quaternions are opaque {@linkcode QuatHandle}s; every operation is a host call
|
|
8
|
+
* returning a new handle. Read primitive components back with
|
|
9
|
+
* {@linkcode PluginQuatApi.components}. Accessed via `snaptrude.core.math.quat`.
|
|
12
10
|
*/
|
|
13
11
|
export abstract class PluginQuatApi {
|
|
14
12
|
constructor() {}
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
|
-
* Create a
|
|
18
|
-
*
|
|
19
|
-
* For most use cases prefer {@linkcode PluginQuatApi.fromAxisAngle}
|
|
20
|
-
* or {@linkcode PluginQuatApi.fromEuler} instead.
|
|
15
|
+
* Create a quaternion from primitive components.
|
|
21
16
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
17
|
+
* # Example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const q = await snaptrude.core.math.quat.new(0, 0, 0, 1)
|
|
20
|
+
* const { x, y, z, w } = await snaptrude.core.math.quat.components(q)
|
|
21
|
+
* ```
|
|
27
22
|
*/
|
|
28
|
-
new(x: number, y: number, z: number, w: number):
|
|
29
|
-
return { x, y, z, w }
|
|
30
|
-
}
|
|
31
|
-
|
|
23
|
+
abstract new(x: number, y: number, z: number, w: number): PluginApiReturn<QuatHandle>
|
|
32
24
|
/**
|
|
33
|
-
*
|
|
25
|
+
* Return the identity quaternion (no rotation).
|
|
34
26
|
*
|
|
35
|
-
*
|
|
27
|
+
* # Example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const noRotation = await snaptrude.core.math.quat.identity()
|
|
30
|
+
* ```
|
|
36
31
|
*/
|
|
37
|
-
identity():
|
|
38
|
-
return { x: 0, y: 0, z: 0, w: 1 }
|
|
39
|
-
}
|
|
40
|
-
|
|
32
|
+
abstract identity(): PluginApiReturn<QuatHandle>
|
|
41
33
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @param axis - The rotation axis as a {@linkcode PVec3} (will be normalized internally)
|
|
45
|
-
* @param angle - The rotation angle in **radians**
|
|
46
|
-
* @returns A new unit {@linkcode PQuat}, or identity if {@linkcode axis} has zero length
|
|
34
|
+
* Build a quaternion from a rotation axis and an angle in radians.
|
|
47
35
|
*
|
|
48
36
|
* # Example
|
|
49
37
|
* ```ts
|
|
50
|
-
* const
|
|
51
|
-
*
|
|
52
|
-
* const rot = quat.fromAxisAngle(vec3.new(0, 1, 0), Math.PI / 2)
|
|
38
|
+
* const axis = await snaptrude.core.math.vec3.new(0, 0, 1)
|
|
39
|
+
* const quarterTurn = await snaptrude.core.math.quat.fromAxisAngle(axis, Math.PI / 2)
|
|
53
40
|
* ```
|
|
54
41
|
*/
|
|
55
|
-
fromAxisAngle(axis:
|
|
56
|
-
const halfAngle = angle / 2
|
|
57
|
-
const s = Math.sin(halfAngle)
|
|
58
|
-
const len = Math.sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z)
|
|
59
|
-
if (len === 0) return { x: 0, y: 0, z: 0, w: 1 }
|
|
60
|
-
return {
|
|
61
|
-
x: (axis.x / len) * s,
|
|
62
|
-
y: (axis.y / len) * s,
|
|
63
|
-
z: (axis.z / len) * s,
|
|
64
|
-
w: Math.cos(halfAngle),
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
42
|
+
abstract fromAxisAngle(axis: Vec3Handle, angle: number): PluginApiReturn<QuatHandle>
|
|
68
43
|
/**
|
|
69
|
-
*
|
|
44
|
+
* Build a quaternion from Euler angles in radians.
|
|
70
45
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
46
|
+
* # Example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const q = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 2, 0)
|
|
49
|
+
* ```
|
|
75
50
|
*/
|
|
76
|
-
fromEuler(x: number, y: number, z: number):
|
|
77
|
-
const cx = Math.cos(x / 2)
|
|
78
|
-
const sx = Math.sin(x / 2)
|
|
79
|
-
const cy = Math.cos(y / 2)
|
|
80
|
-
const sy = Math.sin(y / 2)
|
|
81
|
-
const cz = Math.cos(z / 2)
|
|
82
|
-
const sz = Math.sin(z / 2)
|
|
83
|
-
return {
|
|
84
|
-
x: sx * cy * cz + cx * sy * sz,
|
|
85
|
-
y: cx * sy * cz - sx * cy * sz,
|
|
86
|
-
z: cx * cy * sz + sx * sy * cz,
|
|
87
|
-
w: cx * cy * cz - sx * sy * sz,
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
51
|
+
abstract fromEuler(x: number, y: number, z: number): PluginApiReturn<QuatHandle>
|
|
91
52
|
/**
|
|
92
|
-
*
|
|
53
|
+
* Compose two rotations with the Hamilton product `a * b` (apply `b` then `a`).
|
|
93
54
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
55
|
+
* # Example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const a = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 2, 0)
|
|
58
|
+
* const b = await snaptrude.core.math.quat.fromEuler(Math.PI / 4, 0, 0)
|
|
59
|
+
* const combined = await snaptrude.core.math.quat.multiply(a, b) // b first, then a
|
|
60
|
+
* ```
|
|
100
61
|
*/
|
|
101
|
-
multiply(a:
|
|
102
|
-
return {
|
|
103
|
-
x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
|
|
104
|
-
y: a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
|
|
105
|
-
z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
|
|
106
|
-
w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
62
|
+
abstract multiply(a: QuatHandle, b: QuatHandle): PluginApiReturn<QuatHandle>
|
|
110
63
|
/**
|
|
111
|
-
* Compute the conjugate of a quaternion.
|
|
64
|
+
* Compute the conjugate of a quaternion (negated vector part).
|
|
112
65
|
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
66
|
+
* # Example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const q = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 4, 0)
|
|
69
|
+
* const conj = await snaptrude.core.math.quat.conjugate(q)
|
|
70
|
+
* ```
|
|
117
71
|
*/
|
|
118
|
-
conjugate(q:
|
|
119
|
-
return { x: -q.x, y: -q.y, z: -q.z, w: q.w }
|
|
120
|
-
}
|
|
121
|
-
|
|
72
|
+
abstract conjugate(q: QuatHandle): PluginApiReturn<QuatHandle>
|
|
122
73
|
/**
|
|
123
|
-
* Compute the
|
|
74
|
+
* Compute the magnitude (norm) of a quaternion.
|
|
124
75
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
76
|
+
* # Example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const q = await snaptrude.core.math.quat.new(0, 0, 0, 1)
|
|
79
|
+
* const len = await snaptrude.core.math.quat.length(q) // 1
|
|
80
|
+
* ```
|
|
127
81
|
*/
|
|
128
|
-
length(q:
|
|
129
|
-
return Math.sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w)
|
|
130
|
-
}
|
|
131
|
-
|
|
82
|
+
abstract length(q: QuatHandle): PluginApiReturn<number>
|
|
132
83
|
/**
|
|
133
84
|
* Normalize a quaternion to unit length.
|
|
134
85
|
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
86
|
+
* # Example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const q = await snaptrude.core.math.quat.new(0, 0, 1, 1)
|
|
89
|
+
* const unit = await snaptrude.core.math.quat.normalize(q)
|
|
90
|
+
* ```
|
|
137
91
|
*/
|
|
138
|
-
normalize(q:
|
|
139
|
-
const len = this.length(q)
|
|
140
|
-
if (len === 0) return { x: 0, y: 0, z: 0, w: 1 }
|
|
141
|
-
return { x: q.x / len, y: q.y / len, z: q.z / len, w: q.w / len }
|
|
142
|
-
}
|
|
143
|
-
|
|
92
|
+
abstract normalize(q: QuatHandle): PluginApiReturn<QuatHandle>
|
|
144
93
|
/**
|
|
145
|
-
* Compute the inverse
|
|
94
|
+
* Compute the inverse quaternion — the rotation that undoes `q`.
|
|
146
95
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
96
|
+
* # Example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const q = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 2, 0)
|
|
99
|
+
* const undo = await snaptrude.core.math.quat.inverse(q)
|
|
100
|
+
* ```
|
|
152
101
|
*/
|
|
153
|
-
inverse(q:
|
|
154
|
-
const lenSq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w
|
|
155
|
-
if (lenSq === 0) return { x: 0, y: 0, z: 0, w: 1 }
|
|
156
|
-
return { x: -q.x / lenSq, y: -q.y / lenSq, z: -q.z / lenSq, w: q.w / lenSq }
|
|
157
|
-
}
|
|
158
|
-
|
|
102
|
+
abstract inverse(q: QuatHandle): PluginApiReturn<QuatHandle>
|
|
159
103
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* Computes `q * v * conjugate(q)` using the Hamilton product.
|
|
163
|
-
*
|
|
164
|
-
* @param q - The rotation quaternion (should be unit-length)
|
|
165
|
-
* @param v - The vector to rotate as a {@linkcode PVec3}
|
|
166
|
-
* @returns A new rotated {@linkcode PVec3}
|
|
104
|
+
* Decompose a quaternion into its rotation axis and angle (radians).
|
|
167
105
|
*
|
|
168
106
|
* # Example
|
|
169
107
|
* ```ts
|
|
170
|
-
* const
|
|
171
|
-
* const
|
|
172
|
-
* const
|
|
173
|
-
* // ≈ { x: 0, y: 0, z: -1 }
|
|
108
|
+
* const q = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 3, 0)
|
|
109
|
+
* const { axis, angle } = await snaptrude.core.math.quat.toAxisAngle(q)
|
|
110
|
+
* const { x, y, z } = await snaptrude.core.math.vec3.components(axis)
|
|
174
111
|
* ```
|
|
175
112
|
*/
|
|
176
|
-
|
|
177
|
-
const vq: PQuat = { x: v.x, y: v.y, z: v.z, w: 0 }
|
|
178
|
-
const conj = this.conjugate(q)
|
|
179
|
-
const result = this.multiply(this.multiply(q, vq), conj)
|
|
180
|
-
return { x: result.x, y: result.y, z: result.z }
|
|
181
|
-
}
|
|
182
|
-
|
|
113
|
+
abstract toAxisAngle(q: QuatHandle): PluginApiReturn<{ axis: Vec3Handle; angle: number }>
|
|
183
114
|
/**
|
|
184
|
-
*
|
|
115
|
+
* Spherically interpolate (slerp) between two rotations by factor `t`.
|
|
185
116
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
117
|
+
* # Example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const start = await snaptrude.core.math.quat.identity()
|
|
120
|
+
* const end = await snaptrude.core.math.quat.fromEuler(0, Math.PI, 0)
|
|
121
|
+
* const halfway = await snaptrude.core.math.quat.slerp(start, end, 0.5)
|
|
122
|
+
* ```
|
|
191
123
|
*/
|
|
192
|
-
|
|
193
|
-
const nq = this.normalize(q)
|
|
194
|
-
const angle = 2 * Math.acos(Math.min(1, Math.max(-1, nq.w)))
|
|
195
|
-
const s = Math.sin(angle / 2)
|
|
196
|
-
if (s < 1e-6) {
|
|
197
|
-
return { axis: { x: 1, y: 0, z: 0 }, angle: 0 }
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
axis: { x: nq.x / s, y: nq.y / s, z: nq.z / s },
|
|
201
|
-
angle,
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
124
|
+
abstract slerp(a: QuatHandle, b: QuatHandle, t: number): PluginApiReturn<QuatHandle>
|
|
205
125
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* Produces smooth constant-speed rotation between {@linkcode a} and {@linkcode b}.
|
|
126
|
+
* Compute the dot product of two quaternions.
|
|
209
127
|
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
128
|
+
* # Example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const a = await snaptrude.core.math.quat.identity()
|
|
131
|
+
* const b = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 2, 0)
|
|
132
|
+
* const d = await snaptrude.core.math.quat.dot(a, b)
|
|
133
|
+
* ```
|
|
214
134
|
*/
|
|
215
|
-
|
|
216
|
-
let cosHalf = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w
|
|
217
|
-
let bx = b.x, by = b.y, bz = b.z, bw = b.w
|
|
218
|
-
if (cosHalf < 0) {
|
|
219
|
-
cosHalf = -cosHalf
|
|
220
|
-
bx = -bx; by = -by; bz = -bz; bw = -bw
|
|
221
|
-
}
|
|
222
|
-
if (cosHalf >= 1.0) {
|
|
223
|
-
return { x: a.x, y: a.y, z: a.z, w: a.w }
|
|
224
|
-
}
|
|
225
|
-
const halfAngle = Math.acos(cosHalf)
|
|
226
|
-
const sinHalf = Math.sin(halfAngle)
|
|
227
|
-
const ratioA = Math.sin((1 - t) * halfAngle) / sinHalf
|
|
228
|
-
const ratioB = Math.sin(t * halfAngle) / sinHalf
|
|
229
|
-
return {
|
|
230
|
-
x: a.x * ratioA + bx * ratioB,
|
|
231
|
-
y: a.y * ratioA + by * ratioB,
|
|
232
|
-
z: a.z * ratioA + bz * ratioB,
|
|
233
|
-
w: a.w * ratioA + bw * ratioB,
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
135
|
+
abstract dot(a: QuatHandle, b: QuatHandle): PluginApiReturn<number>
|
|
237
136
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* A value close to `1` or `-1` indicates similar orientations;
|
|
241
|
-
* a value close to `0` indicates maximally different orientations.
|
|
137
|
+
* Test whether two quaternions have exactly equal components.
|
|
242
138
|
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
139
|
+
* # Example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const a = await snaptrude.core.math.quat.new(0, 0, 0, 1)
|
|
142
|
+
* const b = await snaptrude.core.math.quat.identity()
|
|
143
|
+
* const same = await snaptrude.core.math.quat.equals(a, b) // true
|
|
144
|
+
* ```
|
|
246
145
|
*/
|
|
247
|
-
|
|
248
|
-
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w
|
|
249
|
-
}
|
|
250
|
-
|
|
146
|
+
abstract equals(a: QuatHandle, b: QuatHandle): PluginApiReturn<boolean>
|
|
251
147
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* For floating-point comparisons, prefer {@linkcode PluginQuatApi.equalsApprox}.
|
|
148
|
+
* Test whether two quaternions are equal within a tolerance `epsilon` (default `1e-6`).
|
|
255
149
|
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
150
|
+
* # Example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const a = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 2, 0)
|
|
153
|
+
* const b = await snaptrude.core.math.quat.fromEuler(0, 1.5711, 0)
|
|
154
|
+
* const close = await snaptrude.core.math.quat.equalsApprox(a, b, 1e-3) // true
|
|
155
|
+
* ```
|
|
259
156
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
157
|
+
abstract equalsApprox(
|
|
158
|
+
a: QuatHandle,
|
|
159
|
+
b: QuatHandle,
|
|
160
|
+
epsilon?: number,
|
|
161
|
+
): PluginApiReturn<boolean>
|
|
264
162
|
/**
|
|
265
|
-
*
|
|
163
|
+
* Read the primitive `{ x, y, z, w }` components of a quaternion handle.
|
|
266
164
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
165
|
+
* # Example
|
|
166
|
+
* ```ts
|
|
167
|
+
* const q = await snaptrude.core.math.quat.fromEuler(0, Math.PI / 2, 0)
|
|
168
|
+
* const { x, y, z, w } = await snaptrude.core.math.quat.components(q)
|
|
169
|
+
* ```
|
|
271
170
|
*/
|
|
272
|
-
|
|
273
|
-
return (
|
|
274
|
-
Math.abs(a.x - b.x) < epsilon &&
|
|
275
|
-
Math.abs(a.y - b.y) < epsilon &&
|
|
276
|
-
Math.abs(a.z - b.z) < epsilon &&
|
|
277
|
-
Math.abs(a.w - b.w) < epsilon
|
|
278
|
-
)
|
|
279
|
-
}
|
|
171
|
+
abstract components(q: QuatHandle): PluginApiReturn<QuatComponents>
|
|
280
172
|
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* A quaternion with `x`, `y`, `z`, and `w` components.
|
|
284
|
-
*
|
|
285
|
-
* Used for representing 3D rotations without gimbal lock.
|
|
286
|
-
* Equivalent to `BABYLON.Quaternion`.
|
|
287
|
-
*/
|
|
288
|
-
export const PQuat = z.object({
|
|
289
|
-
x: z.number(),
|
|
290
|
-
y: z.number(),
|
|
291
|
-
z: z.number(),
|
|
292
|
-
w: z.number(),
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
export type PQuat = z.infer<typeof PQuat>
|