@uptimizr/sdk-core 0.1.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 +70 -0
- package/LICENSE +201 -0
- package/README.md +109 -0
- package/dist/client.d.ts +116 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +451 -0
- package/dist/client.js.map +1 -0
- package/dist/coordinates.d.ts +98 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +127 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/gesture.d.ts +96 -0
- package/dist/gesture.d.ts.map +1 -0
- package/dist/gesture.js +178 -0
- package/dist/gesture.js.map +1 -0
- package/dist/idgen.d.ts +8 -0
- package/dist/idgen.d.ts.map +1 -0
- package/dist/idgen.js +15 -0
- package/dist/idgen.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/matrix.d.ts +22 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +60 -0
- package/dist/matrix.js.map +1 -0
- package/dist/offloadProtocol.d.ts +40 -0
- package/dist/offloadProtocol.d.ts.map +1 -0
- package/dist/offloadProtocol.js +2 -0
- package/dist/offloadProtocol.js.map +1 -0
- package/dist/offloadWorker.d.ts +2 -0
- package/dist/offloadWorker.d.ts.map +1 -0
- package/dist/offloadWorker.js +41 -0
- package/dist/offloadWorker.js.map +1 -0
- package/dist/processor.d.ts +102 -0
- package/dist/processor.d.ts.map +1 -0
- package/dist/processor.js +145 -0
- package/dist/processor.js.map +1 -0
- package/dist/queue.d.ts +22 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +39 -0
- package/dist/queue.js.map +1 -0
- package/dist/sampling.d.ts +124 -0
- package/dist/sampling.d.ts.map +1 -0
- package/dist/sampling.js +36 -0
- package/dist/sampling.js.map +1 -0
- package/dist/transport.d.ts +10 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +37 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/xrInput.d.ts +54 -0
- package/dist/xrInput.d.ts.map +1 -0
- package/dist/xrInput.js +20 -0
- package/dist/xrInput.js.map +1 -0
- package/llms.txt +16 -0
- package/package.json +61 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical world coordinate frame for everything on the wire (ADR 0018):
|
|
3
|
+
* **left-handed, y-up, unit scale 1** (Babylon-native). Connectors normalize their
|
|
4
|
+
* engine's world-space data to this frame at the emission boundary and record their
|
|
5
|
+
* native frame as provenance on `session_start`.
|
|
6
|
+
*/
|
|
7
|
+
export const CANONICAL_FRAME = {
|
|
8
|
+
handedness: "left",
|
|
9
|
+
upAxis: "y",
|
|
10
|
+
unitScale: 1,
|
|
11
|
+
};
|
|
12
|
+
/** Normalize `-0` to `0` so converted payloads serialize cleanly. */
|
|
13
|
+
function nz(n) {
|
|
14
|
+
return n === 0 ? 0 : n;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Convert a **world-space position** from a source engine's frame to the canonical
|
|
18
|
+
* frame (left-handed, y-up).
|
|
19
|
+
*
|
|
20
|
+
* Assumes a **y-up** source (true for three.js, glTF, PlayCanvas, Babylon). For a
|
|
21
|
+
* right-handed source the handedness flip is the reflection `diag(1, 1, -1)` —
|
|
22
|
+
* i.e. negate Z. A left-handed source is already canonical and is returned
|
|
23
|
+
* unchanged (a fresh copy). Non-y-up sources are out of scope; the connector must
|
|
24
|
+
* rebase to y-up before calling.
|
|
25
|
+
*/
|
|
26
|
+
export function toCanonicalPosition(p, sourceHandedness) {
|
|
27
|
+
if (sourceHandedness === "left")
|
|
28
|
+
return [p[0], p[1], p[2]];
|
|
29
|
+
return [nz(p[0]), nz(p[1]), nz(-p[2])];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert a **world-space direction vector** (e.g. a camera's forward ray) from a
|
|
33
|
+
* source engine's frame to the canonical frame. Same reflection as
|
|
34
|
+
* {@link toCanonicalPosition} — directions ignore translation, so a right-handed
|
|
35
|
+
* source negates Z.
|
|
36
|
+
*
|
|
37
|
+
* ⚠️ Orientation is convention-dependent, and this is the common trap. A camera's
|
|
38
|
+
* *look direction* differs per engine: three.js cameras look along local **−Z**,
|
|
39
|
+
* the canonical (Babylon-style) camera looks along local **+Z**. This helper is
|
|
40
|
+
* correct **only when you pass a true world-space direction** (the actual look
|
|
41
|
+
* vector in world coordinates). If you instead reconstruct orientation from a
|
|
42
|
+
* **local quaternion / Euler**, reflecting components is **not** enough — you must
|
|
43
|
+
* also apply a rotation (a forward-axis flip / ~180° about the up axis) to account
|
|
44
|
+
* for the −Z vs +Z forward convention. Capture orientation as a world-space
|
|
45
|
+
* forward (and up) direction *before* converting.
|
|
46
|
+
*/
|
|
47
|
+
export function toCanonicalDirection(d, sourceHandedness) {
|
|
48
|
+
if (sourceHandedness === "left")
|
|
49
|
+
return [d[0], d[1], d[2]];
|
|
50
|
+
return [nz(d[0]), nz(d[1]), nz(-d[2])];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convert a world-space axis-aligned bounding box `[minX, minY, minZ, maxX, maxY,
|
|
54
|
+
* maxZ]` to the canonical frame. Negating the Z axis swaps the Z min/max, so the
|
|
55
|
+
* result stays a well-formed AABB (min ≤ max per axis).
|
|
56
|
+
*/
|
|
57
|
+
export function toCanonicalAabb(aabb, sourceHandedness) {
|
|
58
|
+
if (sourceHandedness === "left") {
|
|
59
|
+
return [aabb[0], aabb[1], aabb[2], aabb[3], aabb[4], aabb[5]];
|
|
60
|
+
}
|
|
61
|
+
// X/Y unchanged; Z reflects, so the old maxZ becomes the new minZ and vice versa.
|
|
62
|
+
return [nz(aabb[0]), nz(aabb[1]), nz(-aabb[5]), nz(aabb[3]), nz(aabb[4]), nz(-aabb[2])];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Convert a **world-space position** from the canonical frame back into a target
|
|
66
|
+
* engine's native frame — the inverse of {@link toCanonicalPosition}. Used by
|
|
67
|
+
* replay drivers, which read canonical events off the wire and write them into a
|
|
68
|
+
* host scene (e.g. re-driving a three.js camera).
|
|
69
|
+
*
|
|
70
|
+
* The handedness flip is the reflection `diag(1, 1, -1)`, which is its own
|
|
71
|
+
* inverse, so this delegates to the same basis change — but the named inverse
|
|
72
|
+
* keeps replay/host code self-documenting (canonical → engine).
|
|
73
|
+
*/
|
|
74
|
+
export function fromCanonicalPosition(p, targetHandedness) {
|
|
75
|
+
return toCanonicalPosition(p, targetHandedness);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convert a **world-space direction vector** from the canonical frame back into a
|
|
79
|
+
* target engine's native frame — the inverse of {@link toCanonicalDirection}.
|
|
80
|
+
*
|
|
81
|
+
* The same orientation caveat applies in reverse: this yields a correct
|
|
82
|
+
* world-space direction, but a host that needs a *camera orientation* should
|
|
83
|
+
* point the camera at a converted world-space target (e.g. `camera.lookAt`)
|
|
84
|
+
* rather than feeding this into a local-rotation reconstruction.
|
|
85
|
+
*/
|
|
86
|
+
export function fromCanonicalDirection(d, targetHandedness) {
|
|
87
|
+
return toCanonicalDirection(d, targetHandedness);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Convert a world-space AABB from the canonical frame back into a target engine's
|
|
91
|
+
* native frame — the inverse of {@link toCanonicalAabb} (Z min/max swap is its
|
|
92
|
+
* own inverse, so the box stays well-formed).
|
|
93
|
+
*/
|
|
94
|
+
export function fromCanonicalAabb(aabb, targetHandedness) {
|
|
95
|
+
return toCanonicalAabb(aabb, targetHandedness);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Convert a **world-space orientation quaternion** `[x, y, z, w]` from a source
|
|
99
|
+
* engine's frame to the canonical frame (left-handed, y-up). Used for
|
|
100
|
+
* `node_transform` (ADR 0027): a scene actor's world rotation.
|
|
101
|
+
*
|
|
102
|
+
* The handedness flip is the same reflection as {@link toCanonicalPosition}
|
|
103
|
+
* (`diag(1, 1, -1)`, i.e. negate Z). Conjugating a rotation by that reflection
|
|
104
|
+
* maps the quaternion `(x, y, z, w) → (-x, -y, z, w)`: the reflected rotation
|
|
105
|
+
* axis is `(ax, ay, -az)` while the handedness flip negates the angle, and the
|
|
106
|
+
* two sign changes combine to leave only `x` and `y` negated. A left-handed
|
|
107
|
+
* source is already canonical and returned as a copy.
|
|
108
|
+
*
|
|
109
|
+
* Unlike a camera's *look direction* (whose forward-axis convention differs per
|
|
110
|
+
* engine — see {@link toCanonicalDirection}), an object's world rotation has no
|
|
111
|
+
* such convention, so this conversion is exact for scene-actor orientation.
|
|
112
|
+
*/
|
|
113
|
+
export function toCanonicalQuat(q, sourceHandedness) {
|
|
114
|
+
if (sourceHandedness === "left")
|
|
115
|
+
return [q[0], q[1], q[2], q[3]];
|
|
116
|
+
return [nz(-q[0]), nz(-q[1]), nz(q[2]), nz(q[3])];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Convert a **world-space orientation quaternion** from the canonical frame back
|
|
120
|
+
* into a target engine's native frame — the inverse of {@link toCanonicalQuat}.
|
|
121
|
+
* The reflection is its own inverse, so this delegates to the same basis change;
|
|
122
|
+
* the named inverse keeps replay/host code self-documenting (canonical → engine).
|
|
123
|
+
*/
|
|
124
|
+
export function fromCanonicalQuat(q, targetHandedness) {
|
|
125
|
+
return toCanonicalQuat(q, targetHandedness);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=coordinates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinates.js","sourceRoot":"","sources":["../src/coordinates.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MA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CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAAO,EAAE,gBAAsC;IAC/E,OAAO,eAAe,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { CameraGestureKind, Vec3 } from "@uptimizr/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Shared, engine-agnostic camera-gesture classifier (ADR 0025).
|
|
4
|
+
*
|
|
5
|
+
* A gesture is a **discrete, user-initiated viewpoint change** bracketed by an
|
|
6
|
+
* input gesture (pointer down→up, XR thumbstick/grab). Connectors snapshot the
|
|
7
|
+
* camera at the bracket's start and end and hand both samples here; this module
|
|
8
|
+
* decides whether the camera moved enough to count as navigation and, if so,
|
|
9
|
+
* which kind (orbit / pan / dolly / zoom / roll / fly) dominated and by how much.
|
|
10
|
+
*
|
|
11
|
+
* It is pure (no engine, no DOM): it consumes only canonical-frame pose +
|
|
12
|
+
* optional intrinsics, so every connector shares one classification contract.
|
|
13
|
+
* Connectors that expose a real pivot/distance (Babylon `ArcRotateCamera`) get
|
|
14
|
+
* the most precise typing; connectors that expose only position + forward
|
|
15
|
+
* (three.js, PlayCanvas, where orbit controls are an external library) still get
|
|
16
|
+
* a good result because an **implied pivot** is inferred from the two view rays.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A camera snapshot at one instant of a gesture bracket, in the canonical world
|
|
20
|
+
* frame (ADR 0018). Only `position` and `forward` are required; the rest sharpen
|
|
21
|
+
* the classification when the camera exposes them.
|
|
22
|
+
*/
|
|
23
|
+
export interface CameraGestureSample {
|
|
24
|
+
/** World position. */
|
|
25
|
+
position: Vec3;
|
|
26
|
+
/** Normalized forward / look direction. */
|
|
27
|
+
forward: Vec3;
|
|
28
|
+
/** Normalized up direction. Enables roll detection when present. */
|
|
29
|
+
up?: Vec3;
|
|
30
|
+
/** Explicit pivot/target point (e.g. an arc-rotate camera's target). */
|
|
31
|
+
pivot?: Vec3;
|
|
32
|
+
/** Camera-to-pivot distance (e.g. an arc-rotate radius). */
|
|
33
|
+
distance?: number;
|
|
34
|
+
/** Vertical field of view in radians. Enables `zoom` (fov) detection. */
|
|
35
|
+
fov?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Per-axis motion dead-zones: the minimum change on each axis that counts as
|
|
39
|
+
* navigation rather than a click/select (ADR 0025). Below every threshold the
|
|
40
|
+
* gesture is not a navigation gesture and {@link classifyCameraGesture} returns
|
|
41
|
+
* `null`. A single {@link GestureClassifyOptions.sensitivity} dial scales all of
|
|
42
|
+
* them together; per-axis overrides are a rarely-needed escape hatch.
|
|
43
|
+
*/
|
|
44
|
+
export interface GestureThresholds {
|
|
45
|
+
/** Min forward/orbit rotation, in degrees. Default 1. */
|
|
46
|
+
orbitDeg: number;
|
|
47
|
+
/** Min roll about the forward axis, in degrees. Default 1. */
|
|
48
|
+
rollDeg: number;
|
|
49
|
+
/** Min magnification change `|zoomRatio - 1|` (dolly or fov). Default 0.02. */
|
|
50
|
+
zoom: number;
|
|
51
|
+
/** Min normalized pan/fly distance. Default 0.005. */
|
|
52
|
+
pan: number;
|
|
53
|
+
}
|
|
54
|
+
/** Default per-axis dead-zones (ADR 0025 §3). */
|
|
55
|
+
export declare const DEFAULT_GESTURE_THRESHOLDS: GestureThresholds;
|
|
56
|
+
export interface GestureClassifyOptions {
|
|
57
|
+
/** Per-axis dead-zone overrides. Omitted axes use {@link DEFAULT_GESTURE_THRESHOLDS}. */
|
|
58
|
+
thresholds?: Partial<GestureThresholds>;
|
|
59
|
+
/**
|
|
60
|
+
* Single sensitivity multiplier scaling every dead-zone (ADR 0025 §3). `< 1`
|
|
61
|
+
* makes the classifier more sensitive (smaller dead-zones), `> 1` less. Default 1.
|
|
62
|
+
*/
|
|
63
|
+
sensitivity?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Scene bounding radius, used to normalize `panDist` for pivot-less cameras
|
|
66
|
+
* (the fallback when no camera-to-pivot distance is available). Omit when
|
|
67
|
+
* unknown; pan magnitude then falls back to raw world units.
|
|
68
|
+
*/
|
|
69
|
+
sceneRadius?: number;
|
|
70
|
+
}
|
|
71
|
+
/** The classified gesture magnitudes + dominant {@link CameraGestureKind}. */
|
|
72
|
+
export interface ClassifiedGesture {
|
|
73
|
+
/** The dominant motion. */
|
|
74
|
+
kind: CameraGestureKind;
|
|
75
|
+
/** Angular sweep of the forward direction, in degrees, when it rotated. */
|
|
76
|
+
orbitDeg?: number;
|
|
77
|
+
/** Roll about the forward axis, in degrees, when it rolled. */
|
|
78
|
+
rollDeg?: number;
|
|
79
|
+
/** Magnification ratio (`> 1` = moved/zoomed in) for dolly or fov zoom. */
|
|
80
|
+
zoomRatio?: number;
|
|
81
|
+
/** Normalized lateral/free translation distance, when it panned or flew. */
|
|
82
|
+
panDist?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Classify a camera-navigation gesture (ADR 0025) from its start/end snapshots.
|
|
86
|
+
*
|
|
87
|
+
* Returns the dominant {@link ClassifiedGesture.kind} plus the magnitude of every
|
|
88
|
+
* axis that exceeded its dead-zone, or `null` when the camera did not move enough
|
|
89
|
+
* to be navigation (i.e. the bracket should remain a click/select).
|
|
90
|
+
*
|
|
91
|
+
* The dominant axis is the one most strongly exceeding its own dead-zone (its
|
|
92
|
+
* magnitude-over-threshold ratio), so kinds with different units (degrees vs.
|
|
93
|
+
* ratios vs. distances) are compared on a common "signal above noise" scale.
|
|
94
|
+
*/
|
|
95
|
+
export declare function classifyCameraGesture(start: CameraGestureSample, end: CameraGestureSample, options?: GestureClassifyOptions): ClassifiedGesture | null;
|
|
96
|
+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,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAoFD;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,mBAAmB,EAC1B,GAAG,EAAE,mBAAmB,EACxB,OAAO,GAAE,sBAA2B,GACnC,iBAAiB,GAAG,IAAI,CAuF1B"}
|
package/dist/gesture.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/** Default per-axis dead-zones (ADR 0025 §3). */
|
|
2
|
+
export const DEFAULT_GESTURE_THRESHOLDS = {
|
|
3
|
+
orbitDeg: 1,
|
|
4
|
+
rollDeg: 1,
|
|
5
|
+
zoom: 0.02,
|
|
6
|
+
pan: 0.005,
|
|
7
|
+
};
|
|
8
|
+
const RAD2DEG = 180 / Math.PI;
|
|
9
|
+
function sub(a, b) {
|
|
10
|
+
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
11
|
+
}
|
|
12
|
+
function dot(a, b) {
|
|
13
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
14
|
+
}
|
|
15
|
+
function len(a) {
|
|
16
|
+
return Math.hypot(a[0], a[1], a[2]);
|
|
17
|
+
}
|
|
18
|
+
function normalize(a) {
|
|
19
|
+
const l = len(a);
|
|
20
|
+
return l > 1e-9 ? [a[0] / l, a[1] / l, a[2] / l] : [0, 0, 0];
|
|
21
|
+
}
|
|
22
|
+
/** Angle between two vectors in degrees, clamped against floating-point drift. */
|
|
23
|
+
function angleDeg(a, b) {
|
|
24
|
+
const la = len(a);
|
|
25
|
+
const lb = len(b);
|
|
26
|
+
if (la < 1e-9 || lb < 1e-9)
|
|
27
|
+
return 0;
|
|
28
|
+
const c = Math.min(1, Math.max(-1, dot(a, b) / (la * lb)));
|
|
29
|
+
return Math.acos(c) * RAD2DEG;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Infer a pivot point from two view rays (origin + forward) when the camera does
|
|
33
|
+
* not expose one. If the forward direction rotated, the closest approach of the
|
|
34
|
+
* two rays approximates the point the user revolved around — letting pivot-less
|
|
35
|
+
* cameras (three.js / PlayCanvas orbit controls) be typed as `orbit`/`pan` and
|
|
36
|
+
* giving a distance to normalize `panDist`. Returns `null` when the rays are
|
|
37
|
+
* near-parallel (no rotation ⇒ no orbit) or converge behind the camera.
|
|
38
|
+
*/
|
|
39
|
+
function inferPivot(start, end) {
|
|
40
|
+
const p0 = start.position;
|
|
41
|
+
const d0 = normalize(start.forward);
|
|
42
|
+
const p1 = end.position;
|
|
43
|
+
const d1 = normalize(end.forward);
|
|
44
|
+
const r = sub(p0, p1);
|
|
45
|
+
const a = dot(d0, d0); // = 1
|
|
46
|
+
const b = dot(d0, d1);
|
|
47
|
+
const c = dot(d1, d1); // = 1
|
|
48
|
+
const d = dot(d0, r);
|
|
49
|
+
const e = dot(d1, r);
|
|
50
|
+
const denom = a * c - b * b;
|
|
51
|
+
// Near-parallel rays ⇒ no meaningful rotation/pivot.
|
|
52
|
+
if (denom < 1e-4)
|
|
53
|
+
return null;
|
|
54
|
+
const t0 = (b * e - c * d) / denom;
|
|
55
|
+
const t1 = (a * e - b * d) / denom;
|
|
56
|
+
// Pivot must be in front of both cameras to be a revolve target.
|
|
57
|
+
if (t0 <= 0 || t1 <= 0)
|
|
58
|
+
return null;
|
|
59
|
+
const c0 = [p0[0] + t0 * d0[0], p0[1] + t0 * d0[1], p0[2] + t0 * d0[2]];
|
|
60
|
+
const c1 = [p1[0] + t1 * d1[0], p1[1] + t1 * d1[1], p1[2] + t1 * d1[2]];
|
|
61
|
+
const pivot = [(c0[0] + c1[0]) / 2, (c0[1] + c1[1]) / 2, (c0[2] + c1[2]) / 2];
|
|
62
|
+
return { pivot, distance: (t0 + t1) / 2 };
|
|
63
|
+
}
|
|
64
|
+
/** Roll = rotation about the forward axis, read from the up vectors' twist. */
|
|
65
|
+
function computeRollDeg(start, end) {
|
|
66
|
+
if (!start.up || !end.up)
|
|
67
|
+
return 0;
|
|
68
|
+
// Project both up vectors onto the plane perpendicular to the (shared) forward
|
|
69
|
+
// axis, then measure the angle between the projections — that is the twist.
|
|
70
|
+
const f = normalize([
|
|
71
|
+
start.forward[0] + end.forward[0],
|
|
72
|
+
start.forward[1] + end.forward[1],
|
|
73
|
+
start.forward[2] + end.forward[2],
|
|
74
|
+
]);
|
|
75
|
+
if (len(f) < 1e-6)
|
|
76
|
+
return 0;
|
|
77
|
+
const u0 = normalize(sub(start.up, [f[0] * dot(start.up, f), f[1] * dot(start.up, f), f[2] * dot(start.up, f)]));
|
|
78
|
+
const u1 = normalize(sub(end.up, [f[0] * dot(end.up, f), f[1] * dot(end.up, f), f[2] * dot(end.up, f)]));
|
|
79
|
+
return angleDeg(u0, u1);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Classify a camera-navigation gesture (ADR 0025) from its start/end snapshots.
|
|
83
|
+
*
|
|
84
|
+
* Returns the dominant {@link ClassifiedGesture.kind} plus the magnitude of every
|
|
85
|
+
* axis that exceeded its dead-zone, or `null` when the camera did not move enough
|
|
86
|
+
* to be navigation (i.e. the bracket should remain a click/select).
|
|
87
|
+
*
|
|
88
|
+
* The dominant axis is the one most strongly exceeding its own dead-zone (its
|
|
89
|
+
* magnitude-over-threshold ratio), so kinds with different units (degrees vs.
|
|
90
|
+
* ratios vs. distances) are compared on a common "signal above noise" scale.
|
|
91
|
+
*/
|
|
92
|
+
export function classifyCameraGesture(start, end, options = {}) {
|
|
93
|
+
const sensitivity = options.sensitivity && options.sensitivity > 0 ? options.sensitivity : 1;
|
|
94
|
+
const t = {
|
|
95
|
+
orbitDeg: (options.thresholds?.orbitDeg ?? DEFAULT_GESTURE_THRESHOLDS.orbitDeg) * sensitivity,
|
|
96
|
+
rollDeg: (options.thresholds?.rollDeg ?? DEFAULT_GESTURE_THRESHOLDS.rollDeg) * sensitivity,
|
|
97
|
+
zoom: (options.thresholds?.zoom ?? DEFAULT_GESTURE_THRESHOLDS.zoom) * sensitivity,
|
|
98
|
+
pan: (options.thresholds?.pan ?? DEFAULT_GESTURE_THRESHOLDS.pan) * sensitivity,
|
|
99
|
+
};
|
|
100
|
+
// Resolve a pivot/distance: explicit (arc-rotate) first, else inferred from the
|
|
101
|
+
// two view rays. Pivot-less cameras with no rotation stay pivot-less (→ fly).
|
|
102
|
+
const explicitPivot = start.pivot && start.distance !== undefined
|
|
103
|
+
? { pivot: start.pivot, distance: start.distance, explicit: true }
|
|
104
|
+
: null;
|
|
105
|
+
const inferred = explicitPivot ? null : inferPivot(start, end);
|
|
106
|
+
const pivot = explicitPivot ?? (inferred ? { ...inferred, explicit: false } : null);
|
|
107
|
+
// --- Axis magnitudes -------------------------------------------------------
|
|
108
|
+
const orbitDeg = angleDeg(start.forward, end.forward);
|
|
109
|
+
const rollDeg = computeRollDeg(start, end);
|
|
110
|
+
// Magnification: prefer fov change (zoom); else a pivot-distance change (dolly).
|
|
111
|
+
let zoomRatio;
|
|
112
|
+
let zoomIsDolly = false;
|
|
113
|
+
if (start.fov !== undefined && end.fov !== undefined && end.fov > 1e-6) {
|
|
114
|
+
zoomRatio = start.fov / end.fov;
|
|
115
|
+
}
|
|
116
|
+
else if (explicitPivot &&
|
|
117
|
+
start.distance !== undefined &&
|
|
118
|
+
end.distance !== undefined &&
|
|
119
|
+
end.distance > 1e-6) {
|
|
120
|
+
zoomRatio = start.distance / end.distance;
|
|
121
|
+
zoomIsDolly = true;
|
|
122
|
+
}
|
|
123
|
+
// Translation: with a pivot, pan = lateral motion of the pivot (the framing
|
|
124
|
+
// slides); without a pivot, the whole position translation is free flight.
|
|
125
|
+
const translation = sub(end.position, start.position);
|
|
126
|
+
let panRaw;
|
|
127
|
+
let isFly = false;
|
|
128
|
+
if (pivot) {
|
|
129
|
+
const pivotEnd = explicitPivot
|
|
130
|
+
? (end.pivot ?? pivot.pivot)
|
|
131
|
+
: (inferPivot(end, start)?.pivot ?? pivot.pivot);
|
|
132
|
+
const pivotDelta = sub(pivotEnd, pivot.pivot);
|
|
133
|
+
// Lateral component (perpendicular to forward) of the pivot's movement.
|
|
134
|
+
const f = normalize(start.forward);
|
|
135
|
+
const along = dot(pivotDelta, f);
|
|
136
|
+
const lateral = sub(pivotDelta, [f[0] * along, f[1] * along, f[2] * along]);
|
|
137
|
+
panRaw = len(lateral);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
panRaw = len(translation);
|
|
141
|
+
isFly = panRaw > 0;
|
|
142
|
+
}
|
|
143
|
+
// Normalize pan by camera-to-pivot distance (perceptual), else scene radius.
|
|
144
|
+
const panNormalizer = pivot && pivot.distance > 1e-6
|
|
145
|
+
? pivot.distance
|
|
146
|
+
: options.sceneRadius && options.sceneRadius > 1e-6
|
|
147
|
+
? options.sceneRadius
|
|
148
|
+
: undefined;
|
|
149
|
+
const panDist = panNormalizer ? panRaw / panNormalizer : panRaw;
|
|
150
|
+
// --- Dead-zone gate + dominant axis ---------------------------------------
|
|
151
|
+
const zoomMag = zoomRatio !== undefined ? Math.abs(zoomRatio - 1) : 0;
|
|
152
|
+
const scores = [];
|
|
153
|
+
if (orbitDeg > t.orbitDeg)
|
|
154
|
+
scores.push({ kind: "orbit", ratio: orbitDeg / t.orbitDeg });
|
|
155
|
+
if (rollDeg > t.rollDeg)
|
|
156
|
+
scores.push({ kind: "roll", ratio: rollDeg / t.rollDeg });
|
|
157
|
+
if (zoomMag > t.zoom) {
|
|
158
|
+
scores.push({ kind: zoomIsDolly ? "dolly" : "zoom", ratio: zoomMag / t.zoom });
|
|
159
|
+
}
|
|
160
|
+
if (panDist > t.pan) {
|
|
161
|
+
scores.push({ kind: isFly ? "fly" : "pan", ratio: panDist / t.pan });
|
|
162
|
+
}
|
|
163
|
+
if (scores.length === 0)
|
|
164
|
+
return null;
|
|
165
|
+
scores.sort((x, y) => y.ratio - x.ratio);
|
|
166
|
+
const kind = scores[0].kind;
|
|
167
|
+
const result = { kind };
|
|
168
|
+
if (orbitDeg > t.orbitDeg)
|
|
169
|
+
result.orbitDeg = orbitDeg;
|
|
170
|
+
if (rollDeg > t.rollDeg)
|
|
171
|
+
result.rollDeg = rollDeg;
|
|
172
|
+
if (zoomMag > t.zoom && zoomRatio !== undefined)
|
|
173
|
+
result.zoomRatio = zoomRatio;
|
|
174
|
+
if (panDist > t.pan)
|
|
175
|
+
result.panDist = panDist;
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=gesture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gesture.js","sourceRoot":"","sources":["../src/gesture.ts"],"names":[],"mappings":"AAyDA,iDAAiD;AACjD,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC3D,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,KAAK;CACX,CAAC;AAgCF,MAAM,OAAO,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC;AAE9B,SAAS,GAAG,CAAC,CAAO,EAAE,CAAO;IAC3B,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC;AACD,SAAS,GAAG,CAAC,CAAO,EAAE,CAAO;IAC3B,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC;AACD,SAAS,GAAG,CAAC,CAAO;IAClB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,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E,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAErC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC;IAE7B,MAAM,MAAM,GAAsB,EAAE,IAAI,EAAE,CAAC;IAC3C,IAAI,QAAQ,GAAG,CAAC,CAAC,QAAQ;QAAE,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACtD,IAAI,OAAO,GAAG,CAAC,CAAC,OAAO;QAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAClD,IAAI,OAAO,GAAG,CAAC,CAAC,IAAI,IAAI,SAAS,KAAK,SAAS;QAAE,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9E,IAAI,OAAO,GAAG,CAAC,CAAC,GAAG;QAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/idgen.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random, non-persistent identifier.
|
|
3
|
+
*
|
|
4
|
+
* Used for in-memory session IDs only. Per ADR 0003 the SDK never stores a durable
|
|
5
|
+
* identifier on the client, so these IDs live only for the lifetime of the page.
|
|
6
|
+
*/
|
|
7
|
+
export declare function randomId(): string;
|
|
8
|
+
//# sourceMappingURL=idgen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idgen.d.ts","sourceRoot":"","sources":["../src/idgen.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,QAAQ,IAAI,MAAM,CAOjC"}
|
package/dist/idgen.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a random, non-persistent identifier.
|
|
3
|
+
*
|
|
4
|
+
* Used for in-memory session IDs only. Per ADR 0003 the SDK never stores a durable
|
|
5
|
+
* identifier on the client, so these IDs live only for the lifetime of the page.
|
|
6
|
+
*/
|
|
7
|
+
export function randomId() {
|
|
8
|
+
const c = globalThis.crypto;
|
|
9
|
+
if (c && typeof c.randomUUID === "function") {
|
|
10
|
+
return c.randomUUID();
|
|
11
|
+
}
|
|
12
|
+
// Fallback for environments without crypto.randomUUID.
|
|
13
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=idgen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"idgen.js","sourceRoot":"","sources":["../src/idgen.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,QAAQ;IACtB,MAAM,CAAC,GAAI,UAAkC,CAAC,MAAM,CAAC;IACrD,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC5C,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IACxB,CAAC;IACD,uDAAuD;IACvD,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACjF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@uptimizr/sdk-core` — the framework-agnostic Uptimizr capture runtime.
|
|
3
|
+
*
|
|
4
|
+
* Owns the session, an in-memory batching queue, flush scheduling, and a cookieless
|
|
5
|
+
* transport. Engine-specific capture (e.g. Babylon) plugs in via `client.use()`.
|
|
6
|
+
*/
|
|
7
|
+
export { UptimizrClient } from "./client.js";
|
|
8
|
+
export { EventQueue } from "./queue.js";
|
|
9
|
+
export { createBeaconTransport } from "./transport.js";
|
|
10
|
+
export { createMainProcessor, createWorkerProcessor, collectTransferables } from "./processor.js";
|
|
11
|
+
export { randomId } from "./idgen.js";
|
|
12
|
+
export { SDK_VERSION } from "./version.js";
|
|
13
|
+
export { resolveCadence } from "./sampling.js";
|
|
14
|
+
export { classifyCameraGesture, DEFAULT_GESTURE_THRESHOLDS } from "./gesture.js";
|
|
15
|
+
export { CANONICAL_FRAME, toCanonicalAabb, toCanonicalDirection, toCanonicalPosition, toCanonicalQuat, fromCanonicalAabb, fromCanonicalDirection, fromCanonicalPosition, fromCanonicalQuat, } from "./coordinates.js";
|
|
16
|
+
export { decomposeWorldMatrix } from "./matrix.js";
|
|
17
|
+
export type { DecomposedTransform } from "./matrix.js";
|
|
18
|
+
export { xrSource, xrHandedness } from "./xrInput.js";
|
|
19
|
+
export type { Collector, CollectorContext, CollectorHandle, BeforeSendHook, EventInput, ResolvedConfig, StartMeta, TrackInputOptions, CapabilityChangeReport, Transport, UptimizrConfig, } from "./types.js";
|
|
20
|
+
export type { Processor, WorkerLike, WorkerFactory, WorkerProcessorOptions } from "./processor.js";
|
|
21
|
+
export type { SampleRate, SamplingProfile, BoneSamplingConfig, NodeSamplingConfig, ResolvedCadence, } from "./sampling.js";
|
|
22
|
+
export type { CameraGestureSample, ClassifiedGesture, GestureThresholds, GestureClassifyOptions, } from "./gesture.js";
|
|
23
|
+
export type { XrInputSourceLike, XrCaptureOptions, XrRayHit, XrRayProbe } from "./xrInput.js";
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC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@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@uptimizr/sdk-core` — the framework-agnostic Uptimizr capture runtime.
|
|
3
|
+
*
|
|
4
|
+
* Owns the session, an in-memory batching queue, flush scheduling, and a cookieless
|
|
5
|
+
* transport. Engine-specific capture (e.g. Babylon) plugs in via `client.use()`.
|
|
6
|
+
*/
|
|
7
|
+
export { UptimizrClient } from "./client.js";
|
|
8
|
+
export { EventQueue } from "./queue.js";
|
|
9
|
+
export { createBeaconTransport } from "./transport.js";
|
|
10
|
+
export { createMainProcessor, createWorkerProcessor, collectTransferables } from "./processor.js";
|
|
11
|
+
export { randomId } from "./idgen.js";
|
|
12
|
+
export { SDK_VERSION } from "./version.js";
|
|
13
|
+
export { resolveCadence } from "./sampling.js";
|
|
14
|
+
export { classifyCameraGesture, DEFAULT_GESTURE_THRESHOLDS } from "./gesture.js";
|
|
15
|
+
export { CANONICAL_FRAME, toCanonicalAabb, toCanonicalDirection, toCanonicalPosition, toCanonicalQuat, fromCanonicalAabb, fromCanonicalDirection, fromCanonicalPosition, fromCanonicalQuat, } from "./coordinates.js";
|
|
16
|
+
export { decomposeWorldMatrix } from "./matrix.js";
|
|
17
|
+
export { xrSource, xrHandedness } from "./xrInput.js";
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/matrix.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Quat, Vec3 } from "@uptimizr/schema";
|
|
2
|
+
/**
|
|
3
|
+
* A decomposed world transform: position, rotation quaternion `[x,y,z,w]`, and
|
|
4
|
+
* scale — in the **source engine's native frame**. Apply the `toCanonical*`
|
|
5
|
+
* helpers to reflect into the canonical wire frame (ADR 0018).
|
|
6
|
+
*/
|
|
7
|
+
export interface DecomposedTransform {
|
|
8
|
+
position: Vec3;
|
|
9
|
+
rotation: Quat;
|
|
10
|
+
scale: Vec3;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Decompose a **column-major** world matrix (the layout three.js `Matrix4.elements`,
|
|
14
|
+
* Babylon `Matrix.m`, and PlayCanvas `Mat4.data` all share) into position /
|
|
15
|
+
* rotation quaternion / scale, using the same algorithm as `Matrix4.decompose`:
|
|
16
|
+
* scale is the length of each basis column (negate `sx` when the upper-left 3×3 has
|
|
17
|
+
* a negative determinant, to keep a proper rotation), then the scale-normalized
|
|
18
|
+
* basis is converted to a quaternion. The result is in the matrix's own frame; the
|
|
19
|
+
* caller converts to canonical with {@link toCanonicalPosition}/{@link toCanonicalQuat}.
|
|
20
|
+
*/
|
|
21
|
+
export declare function decomposeWorldMatrix(e: ArrayLike<number>): DecomposedTransform;
|
|
22
|
+
//# sourceMappingURL=matrix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,IAAI,CAAC;IACf,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE,IAAI,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAoD9E"}
|
package/dist/matrix.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decompose a **column-major** world matrix (the layout three.js `Matrix4.elements`,
|
|
3
|
+
* Babylon `Matrix.m`, and PlayCanvas `Mat4.data` all share) into position /
|
|
4
|
+
* rotation quaternion / scale, using the same algorithm as `Matrix4.decompose`:
|
|
5
|
+
* scale is the length of each basis column (negate `sx` when the upper-left 3×3 has
|
|
6
|
+
* a negative determinant, to keep a proper rotation), then the scale-normalized
|
|
7
|
+
* basis is converted to a quaternion. The result is in the matrix's own frame; the
|
|
8
|
+
* caller converts to canonical with {@link toCanonicalPosition}/{@link toCanonicalQuat}.
|
|
9
|
+
*/
|
|
10
|
+
export function decomposeWorldMatrix(e) {
|
|
11
|
+
const position = [e[12] ?? 0, e[13] ?? 0, e[14] ?? 0];
|
|
12
|
+
let sx = Math.hypot(e[0], e[1], e[2]);
|
|
13
|
+
const sy = Math.hypot(e[4], e[5], e[6]);
|
|
14
|
+
const sz = Math.hypot(e[8], e[9], e[10]);
|
|
15
|
+
const det = e[0] *
|
|
16
|
+
(e[5] * e[10] - e[6] * e[9]) -
|
|
17
|
+
e[4] *
|
|
18
|
+
(e[1] * e[10] - e[2] * e[9]) +
|
|
19
|
+
e[8] * (e[1] * e[6] - e[2] * e[5]);
|
|
20
|
+
if (det < 0)
|
|
21
|
+
sx = -sx;
|
|
22
|
+
const ix = sx !== 0 ? 1 / sx : 0;
|
|
23
|
+
const iy = sy !== 0 ? 1 / sy : 0;
|
|
24
|
+
const iz = sz !== 0 ? 1 / sz : 0;
|
|
25
|
+
const m11 = e[0] * ix, m21 = e[1] * ix, m31 = e[2] * ix;
|
|
26
|
+
const m12 = e[4] * iy, m22 = e[5] * iy, m32 = e[6] * iy;
|
|
27
|
+
const m13 = e[8] * iz, m23 = e[9] * iz, m33 = e[10] * iz;
|
|
28
|
+
const trace = m11 + m22 + m33;
|
|
29
|
+
let x, y, z, w;
|
|
30
|
+
if (trace > 0) {
|
|
31
|
+
const s = 0.5 / Math.sqrt(trace + 1);
|
|
32
|
+
w = 0.25 / s;
|
|
33
|
+
x = (m32 - m23) * s;
|
|
34
|
+
y = (m13 - m31) * s;
|
|
35
|
+
z = (m21 - m12) * s;
|
|
36
|
+
}
|
|
37
|
+
else if (m11 > m22 && m11 > m33) {
|
|
38
|
+
const s = 2 * Math.sqrt(1 + m11 - m22 - m33);
|
|
39
|
+
w = (m32 - m23) / s;
|
|
40
|
+
x = 0.25 * s;
|
|
41
|
+
y = (m12 + m21) / s;
|
|
42
|
+
z = (m13 + m31) / s;
|
|
43
|
+
}
|
|
44
|
+
else if (m22 > m33) {
|
|
45
|
+
const s = 2 * Math.sqrt(1 + m22 - m11 - m33);
|
|
46
|
+
w = (m13 - m31) / s;
|
|
47
|
+
x = (m12 + m21) / s;
|
|
48
|
+
y = 0.25 * s;
|
|
49
|
+
z = (m23 + m32) / s;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const s = 2 * Math.sqrt(1 + m33 - m11 - m22);
|
|
53
|
+
w = (m21 - m12) / s;
|
|
54
|
+
x = (m13 + m31) / s;
|
|
55
|
+
y = (m23 + m32) / s;
|
|
56
|
+
z = 0.25 * s;
|
|
57
|
+
}
|
|
58
|
+
return { position, rotation: [x, y, z, w], scale: [sx, sy, sz] };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=matrix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix.js","sourceRoot":"","sources":["../src/matrix.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,CAAoB;IACvD,MAAM,QAAQ,GAAS,CAAE,CAAC,CAAC,EAAE,CAAY,IAAI,CAAC,EAAG,CAAC,CAAC,EAAE,CAAY,IAAI,CAAC,EAAG,CAAC,CAAC,EAAE,CAAY,IAAI,CAAC,CAAC,CAAC;IAChG,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,CAAC,CAAC,CAAC,CAAW,EAAE,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC;IACpE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,CAAC,CAAC,CAAC,CAAW,EAAE,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC;IACtE,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,CAAC,CAAC,CAAC,CAAW,EAAE,CAAC,CAAC,EAAE,CAAW,CAAC,CAAC;IACvE,MAAM,GAAG,GACN,CAAC,CAAC,CAAC,CAAY;QACd,CAAE,CAAC,CAAC,CAAC,CAAY,GAAI,CAAC,CAAC,EAAE,CAAY,GAAI,CAAC,CAAC,CAAC,CAAY,GAAI,CAAC,CAAC,CAAC,CAAY,CAAC;QAC7E,CAAC,CAAC,CAAC,CAAY;YACd,CAAE,CAAC,CAAC,CAAC,CAAY,GAAI,CAAC,CAAC,EAAE,CAAY,GAAI,CAAC,CAAC,CAAC,CAAY,GAAI,CAAC,CAAC,CAAC,CAAY,CAAC;QAC7E,CAAC,CAAC,CAAC,CAAY,GAAG,CAAE,CAA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