copper3d 3.7.4 → 3.8.1
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/Controls/cameraTransitions.d.ts +87 -0
- package/dist/Controls/cameraTransitions.js +285 -0
- package/dist/Controls/cameraTransitions.js.map +1 -0
- package/dist/Controls/fitView.d.ts +45 -0
- package/dist/Controls/fitView.js +40 -0
- package/dist/Controls/fitView.js.map +1 -0
- package/dist/Controls/orbitFraming.d.ts +39 -0
- package/dist/Controls/orbitFraming.js +39 -0
- package/dist/Controls/orbitFraming.js.map +1 -1
- package/dist/Loader/fastSliceRepaint.d.ts +56 -0
- package/dist/Loader/fastSliceRepaint.js +159 -0
- package/dist/Loader/fastSliceRepaint.js.map +1 -0
- package/dist/Renderer/copperRendererOnDemond.d.ts +10 -2
- package/dist/Renderer/copperRendererOnDemond.js +14 -0
- package/dist/Renderer/copperRendererOnDemond.js.map +1 -1
- package/dist/Renderer/disposeScene.d.ts +47 -0
- package/dist/Renderer/disposeScene.js +46 -0
- package/dist/Renderer/disposeScene.js.map +1 -0
- package/dist/Renderer/sceneBudget.d.ts +40 -0
- package/dist/Renderer/sceneBudget.js +86 -0
- package/dist/Renderer/sceneBudget.js.map +1 -0
- package/dist/Scene/copperSceneOnDemond.d.ts +12 -0
- package/dist/Scene/copperSceneOnDemond.js +18 -0
- package/dist/Scene/copperSceneOnDemond.js.map +1 -1
- package/dist/Utils/dispose.d.ts +48 -0
- package/dist/Utils/dispose.js +60 -0
- package/dist/Utils/dispose.js.map +1 -0
- package/dist/Utils/modelCrossfade.d.ts +36 -0
- package/dist/Utils/modelCrossfade.js +46 -0
- package/dist/Utils/modelCrossfade.js.map +1 -0
- package/dist/Utils/segmentation/coreTools/divControlTools.js +19 -0
- package/dist/Utils/segmentation/coreTools/divControlTools.js.map +1 -1
- package/dist/Utils/volumeExposure.d.ts +32 -0
- package/dist/Utils/volumeExposure.js +104 -0
- package/dist/Utils/volumeExposure.js.map +1 -0
- package/dist/bundle.esm.js +31521 -10006
- package/dist/bundle.umd.js +31549 -10012
- package/dist/index.d.ts +19 -2
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/types/Controls/cameraTransitions.d.ts +87 -0
- package/dist/types/Controls/fitView.d.ts +45 -0
- package/dist/types/Controls/orbitFraming.d.ts +39 -0
- package/dist/types/Loader/fastSliceRepaint.d.ts +56 -0
- package/dist/types/Renderer/copperRendererOnDemond.d.ts +10 -2
- package/dist/types/Renderer/disposeScene.d.ts +47 -0
- package/dist/types/Renderer/sceneBudget.d.ts +40 -0
- package/dist/types/Scene/copperSceneOnDemond.d.ts +12 -0
- package/dist/types/Utils/dispose.d.ts +48 -0
- package/dist/types/Utils/modelCrossfade.d.ts +36 -0
- package/dist/types/Utils/volumeExposure.d.ts +32 -0
- package/dist/types/index.d.ts +19 -2
- package/package.json +7 -3
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { CameraViewPreset } from './orbitFraming';
|
|
2
|
+
/**
|
|
3
|
+
* Camera pose interpolation: the math behind flying a camera from one view
|
|
4
|
+
* preset to another, orbiting it a step at a time, and zooming it.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately dependency-free -- plain numbers and `[x, y, z]` tuples, no
|
|
7
|
+
* `three` -- for two reasons. It is unit-testable with no WebGL, and a
|
|
8
|
+
* consumer that has its own copy of three (a bundler that did not dedupe, or
|
|
9
|
+
* an app importing three alongside a bundled build) can use it without any
|
|
10
|
+
* object crossing that boundary.
|
|
11
|
+
*/
|
|
12
|
+
/** A camera pose. `target` is the look-at point -- the controls' orbit
|
|
13
|
+
* pivot, not the camera's own position. */
|
|
14
|
+
export interface Pose {
|
|
15
|
+
position: [number, number, number];
|
|
16
|
+
up: [number, number, number];
|
|
17
|
+
target: [number, number, number];
|
|
18
|
+
}
|
|
19
|
+
export declare function easeInOutCubic(t: number): number;
|
|
20
|
+
/** Reads a view preset as a `Pose`, so a flight's destination is built from
|
|
21
|
+
* the same data an instant `loadView` would apply. */
|
|
22
|
+
export declare function viewPointToPose(vp: CameraViewPreset): Pose;
|
|
23
|
+
type Vec3Tuple = [number, number, number];
|
|
24
|
+
/**
|
|
25
|
+
* Rodrigues' rotation formula: rotates `v` by `angleRad` around `axis` (which
|
|
26
|
+
* need not be pre-normalized). Unlike slerping between two vectors, this has
|
|
27
|
+
* no degeneracy at any angle including a half turn -- the axis is given, not
|
|
28
|
+
* derived from a dot product between vectors that might be antiparallel.
|
|
29
|
+
*/
|
|
30
|
+
export declare function rotateAroundAxis(v: Vec3Tuple, axis: Vec3Tuple, angleRad: number): Vec3Tuple;
|
|
31
|
+
/**
|
|
32
|
+
* Interpolates a camera between two poses. `t` is expected already eased --
|
|
33
|
+
* this has no timing concerns of its own, which is what makes it testable
|
|
34
|
+
* without a clock.
|
|
35
|
+
*
|
|
36
|
+
* The pivot lerps from one target to the other, and the camera's ORIENTATION
|
|
37
|
+
* (both its direction from the pivot and its up vector) is carried by a
|
|
38
|
+
* single rotation built from the two poses' full orthonormal bases -- not by
|
|
39
|
+
* interpolating `dir` and `up` independently.
|
|
40
|
+
*
|
|
41
|
+
* That is a correctness requirement, not a style choice. Real preset data
|
|
42
|
+
* routinely contains antipodal up vectors on the same view axis (two views
|
|
43
|
+
* of the same volume authored from opposite conventions). A plain
|
|
44
|
+
* `lerp(upFrom, upTo, t)` passes through the zero vector at t=0.5, where
|
|
45
|
+
* `normalize` has no correct answer: the camera holds upside-down, then
|
|
46
|
+
* snaps 180 degrees in one frame. Composing the two bases into a relative
|
|
47
|
+
* rotation makes that case a well-defined 180-degree roll about the shared
|
|
48
|
+
* axis -- a smooth roll through the midpoint. The same construction covers
|
|
49
|
+
* two antipodal camera positions about one target.
|
|
50
|
+
*
|
|
51
|
+
* Reproduces `from.position` exactly at t=0 and `to.position` at t=1. `up` is
|
|
52
|
+
* likewise exact WHEN each pose's own `up` is already perpendicular to its
|
|
53
|
+
* own view direction; one that leans toward the view axis is silently
|
|
54
|
+
* squared up, which is by design -- it is not a meaningful camera roll.
|
|
55
|
+
*/
|
|
56
|
+
export declare function interpolateFlightPose(from: Pose, to: Pose, t: number): Pose;
|
|
57
|
+
/** The camera's orbit radius: how far `pose.position` sits from the pivot it
|
|
58
|
+
* looks at. Lets a push-in be expressed as an absolute target distance
|
|
59
|
+
* (idempotent) rather than a repeated fractional step. */
|
|
60
|
+
export declare function poseDistance(pose: Pose): number;
|
|
61
|
+
/**
|
|
62
|
+
* Orbits the camera around its own pivot by `yawRad` about its up vector,
|
|
63
|
+
* then by `pitchRad` about the RESULTING right vector. The pivot and the
|
|
64
|
+
* orbit radius are both untouched, so a run of steps can never walk the
|
|
65
|
+
* camera away from what it is looking at.
|
|
66
|
+
*
|
|
67
|
+
* Pitch about the yawed right vector, not the original: rotating about a
|
|
68
|
+
* stale axis makes a diagonal (left+up) combination drift off the sphere
|
|
69
|
+
* instead of tracing it.
|
|
70
|
+
*/
|
|
71
|
+
export declare function orbitStepPose(pose: Pose, yawRad: number, pitchRad: number): Pose;
|
|
72
|
+
/**
|
|
73
|
+
* Scales the camera's distance from its pivot by `factor` along the unchanged
|
|
74
|
+
* view direction. Clamped at `minDistance` because a zero radius has no
|
|
75
|
+
* direction to normalize -- a held zoom-in key would otherwise collapse the
|
|
76
|
+
* pose into NaN one frame after reaching the pivot.
|
|
77
|
+
*/
|
|
78
|
+
export declare function zoomPose(pose: Pose, factor: number, minDistance?: number): Pose;
|
|
79
|
+
/**
|
|
80
|
+
* Swing angle for an entrance orbit. `turns` is a SWING AMPLITUDE, not a net
|
|
81
|
+
* rotation: `sin(t*pi)` goes out and comes back to zero, so the camera always
|
|
82
|
+
* ends exactly on the framed preset view (t=1 -> angle 0) however large
|
|
83
|
+
* `turns` is. Do not "fix" this into a net rotation; that ends the intro
|
|
84
|
+
* off-preset.
|
|
85
|
+
*/
|
|
86
|
+
export declare function orbitSwingAngle(t: number, turns: number): number;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
function clamp01(t) {
|
|
2
|
+
return Math.min(1, Math.max(0, t));
|
|
3
|
+
}
|
|
4
|
+
export function easeInOutCubic(t) {
|
|
5
|
+
const x = clamp01(t);
|
|
6
|
+
return x < 0.5 ? 4 * x * x * x : 1 - Math.pow((-2 * x + 2), 3) / 2;
|
|
7
|
+
}
|
|
8
|
+
/** Reads a view preset as a `Pose`, so a flight's destination is built from
|
|
9
|
+
* the same data an instant `loadView` would apply. */
|
|
10
|
+
export function viewPointToPose(vp) {
|
|
11
|
+
return {
|
|
12
|
+
position: toTuple(vp.eyePosition),
|
|
13
|
+
up: toTuple(vp.upVector),
|
|
14
|
+
target: toTuple(vp.targetPosition),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function toTuple(v) {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
return [(_a = v[0]) !== null && _a !== void 0 ? _a : 0, (_b = v[1]) !== null && _b !== void 0 ? _b : 0, (_c = v[2]) !== null && _c !== void 0 ? _c : 0];
|
|
20
|
+
}
|
|
21
|
+
const IDENTITY_QUAT = [1, 0, 0, 0];
|
|
22
|
+
function sub(a, b) {
|
|
23
|
+
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
24
|
+
}
|
|
25
|
+
function add(a, b) {
|
|
26
|
+
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
27
|
+
}
|
|
28
|
+
function scale(v, s) {
|
|
29
|
+
return [v[0] * s, v[1] * s, v[2] * s];
|
|
30
|
+
}
|
|
31
|
+
function dot(a, b) {
|
|
32
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
33
|
+
}
|
|
34
|
+
function cross(a, b) {
|
|
35
|
+
return [
|
|
36
|
+
a[1] * b[2] - a[2] * b[1],
|
|
37
|
+
a[2] * b[0] - a[0] * b[2],
|
|
38
|
+
a[0] * b[1] - a[1] * b[0],
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
function length(v) {
|
|
42
|
+
return Math.hypot(v[0], v[1], v[2]);
|
|
43
|
+
}
|
|
44
|
+
/** Falls back to `[0, 0, 1]` for a zero-length input: there is no meaningful
|
|
45
|
+
* direction to normalize, and a fallback keeps every caller total instead of
|
|
46
|
+
* propagating NaN into a render. */
|
|
47
|
+
function normalize(v) {
|
|
48
|
+
const len = length(v);
|
|
49
|
+
return len > 1e-9 ? scale(v, 1 / len) : [0, 0, 1];
|
|
50
|
+
}
|
|
51
|
+
function lerpScalar(a, b, t) {
|
|
52
|
+
return a + (b - a) * t;
|
|
53
|
+
}
|
|
54
|
+
function lerpVec3(a, b, t) {
|
|
55
|
+
return [lerpScalar(a[0], b[0], t), lerpScalar(a[1], b[1], t), lerpScalar(a[2], b[2], t)];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Rodrigues' rotation formula: rotates `v` by `angleRad` around `axis` (which
|
|
59
|
+
* need not be pre-normalized). Unlike slerping between two vectors, this has
|
|
60
|
+
* no degeneracy at any angle including a half turn -- the axis is given, not
|
|
61
|
+
* derived from a dot product between vectors that might be antiparallel.
|
|
62
|
+
*/
|
|
63
|
+
export function rotateAroundAxis(v, axis, angleRad) {
|
|
64
|
+
const [ax, ay, az] = normalize(axis);
|
|
65
|
+
const cos = Math.cos(angleRad);
|
|
66
|
+
const sin = Math.sin(angleRad);
|
|
67
|
+
const d = dot(v, [ax, ay, az]);
|
|
68
|
+
const axisCross = [ay * v[2] - az * v[1], az * v[0] - ax * v[2], ax * v[1] - ay * v[0]];
|
|
69
|
+
return [
|
|
70
|
+
v[0] * cos + axisCross[0] * sin + ax * d * (1 - cos),
|
|
71
|
+
v[1] * cos + axisCross[1] * sin + ay * d * (1 - cos),
|
|
72
|
+
v[2] * cos + axisCross[2] * sin + az * d * (1 - cos),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
/** A unit vector perpendicular to `v`. Picks whichever world axis is least
|
|
76
|
+
* aligned with it, so the cross product is always well-conditioned. */
|
|
77
|
+
function arbitraryPerpendicular(v) {
|
|
78
|
+
const nv = normalize(v);
|
|
79
|
+
const axis = Math.abs(nv[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0];
|
|
80
|
+
return normalize(cross(axis, nv));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A right-handed orthonormal basis from a camera's offset-from-target and its
|
|
84
|
+
* (possibly only approximately perpendicular) up vector. Gram-Schmidt against
|
|
85
|
+
* `dir` guarantees the result is exactly orthogonal even when hand-authored
|
|
86
|
+
* preset data is not.
|
|
87
|
+
*/
|
|
88
|
+
function buildBasis(offset, upRaw) {
|
|
89
|
+
const dir = normalize(offset);
|
|
90
|
+
const rightRaw = cross(upRaw, dir);
|
|
91
|
+
const right = length(rightRaw) > 1e-6 ? normalize(rightRaw) : arbitraryPerpendicular(dir);
|
|
92
|
+
const up = cross(dir, right);
|
|
93
|
+
return { right, up, dir };
|
|
94
|
+
}
|
|
95
|
+
function basisToMatrix(right, up, dir) {
|
|
96
|
+
// Columns are the basis vectors, in world coordinates.
|
|
97
|
+
return [
|
|
98
|
+
right[0], up[0], dir[0],
|
|
99
|
+
right[1], up[1], dir[1],
|
|
100
|
+
right[2], up[2], dir[2],
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
function transposeMat3(m) {
|
|
104
|
+
return [m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8]];
|
|
105
|
+
}
|
|
106
|
+
function multiplyMat3(a, b) {
|
|
107
|
+
const r = new Array(9);
|
|
108
|
+
for (let row = 0; row < 3; row++) {
|
|
109
|
+
for (let col = 0; col < 3; col++) {
|
|
110
|
+
let sum = 0;
|
|
111
|
+
for (let k = 0; k < 3; k++)
|
|
112
|
+
sum += a[row * 3 + k] * b[k * 3 + col];
|
|
113
|
+
r[row * 3 + col] = sum;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return r;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Rotation matrix to quaternion, largest-diagonal-term method
|
|
120
|
+
* (Shepperd/Shoemake). No ill-conditioned input: for a valid rotation matrix
|
|
121
|
+
* at least one of `1+trace`, `1+m00-m11-m22`, `1+m11-m00-m22`,
|
|
122
|
+
* `1+m22-m00-m11` is always >= 1, so some branch's divisor is bounded away
|
|
123
|
+
* from zero. That is what makes it safe on the exact antipodal cases -- a
|
|
124
|
+
* 180-degree roll, or two opposite view directions.
|
|
125
|
+
*/
|
|
126
|
+
function matrixToQuaternion(m) {
|
|
127
|
+
const [m00, m01, m02, m10, m11, m12, m20, m21, m22] = m;
|
|
128
|
+
const trace = m00 + m11 + m22;
|
|
129
|
+
if (trace > 0) {
|
|
130
|
+
const s = Math.sqrt(trace + 1) * 2;
|
|
131
|
+
return [s / 4, (m21 - m12) / s, (m02 - m20) / s, (m10 - m01) / s];
|
|
132
|
+
}
|
|
133
|
+
if (m00 > m11 && m00 > m22) {
|
|
134
|
+
const s = Math.sqrt(1 + m00 - m11 - m22) * 2;
|
|
135
|
+
return [(m21 - m12) / s, s / 4, (m01 + m10) / s, (m02 + m20) / s];
|
|
136
|
+
}
|
|
137
|
+
if (m11 > m22) {
|
|
138
|
+
const s = Math.sqrt(1 + m11 - m00 - m22) * 2;
|
|
139
|
+
return [(m02 - m20) / s, (m01 + m10) / s, s / 4, (m12 + m21) / s];
|
|
140
|
+
}
|
|
141
|
+
const s = Math.sqrt(1 + m22 - m00 - m11) * 2;
|
|
142
|
+
return [(m10 - m01) / s, (m02 + m20) / s, (m12 + m21) / s, s / 4];
|
|
143
|
+
}
|
|
144
|
+
/** Quaternion slerp. Negates `b` on a negative dot product so the
|
|
145
|
+
* interpolation takes the shorter path (`q` and `-q` are the same rotation),
|
|
146
|
+
* and falls back to a normalized lerp where slerp's own division is
|
|
147
|
+
* ill-conditioned but visually indistinguishable. */
|
|
148
|
+
function slerpQuat(a, b, t) {
|
|
149
|
+
let [bw, bx, by, bz] = b;
|
|
150
|
+
const [aw, ax, ay, az] = a;
|
|
151
|
+
let cosHalfTheta = aw * bw + ax * bx + ay * by + az * bz;
|
|
152
|
+
if (cosHalfTheta < 0) {
|
|
153
|
+
bw = -bw;
|
|
154
|
+
bx = -bx;
|
|
155
|
+
by = -by;
|
|
156
|
+
bz = -bz;
|
|
157
|
+
cosHalfTheta = -cosHalfTheta;
|
|
158
|
+
}
|
|
159
|
+
if (cosHalfTheta > 1 - 1e-9) {
|
|
160
|
+
const lerped = [
|
|
161
|
+
lerpScalar(aw, bw, t),
|
|
162
|
+
lerpScalar(ax, bx, t),
|
|
163
|
+
lerpScalar(ay, by, t),
|
|
164
|
+
lerpScalar(az, bz, t),
|
|
165
|
+
];
|
|
166
|
+
const len = Math.hypot(...lerped) || 1;
|
|
167
|
+
return [lerped[0] / len, lerped[1] / len, lerped[2] / len, lerped[3] / len];
|
|
168
|
+
}
|
|
169
|
+
const halfTheta = Math.acos(cosHalfTheta);
|
|
170
|
+
const sinHalfTheta = Math.sqrt(1 - cosHalfTheta * cosHalfTheta);
|
|
171
|
+
const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
|
|
172
|
+
const ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
|
|
173
|
+
return [
|
|
174
|
+
aw * ratioA + bw * ratioB,
|
|
175
|
+
ax * ratioA + bx * ratioB,
|
|
176
|
+
ay * ratioA + by * ratioB,
|
|
177
|
+
az * ratioA + bz * ratioB,
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
/** Rotates a vector by a unit quaternion. */
|
|
181
|
+
function rotateByQuaternion(v, q) {
|
|
182
|
+
const [qw, qx, qy, qz] = q;
|
|
183
|
+
const qv = [qx, qy, qz];
|
|
184
|
+
const t2 = scale(cross(qv, v), 2);
|
|
185
|
+
const t3 = cross(qv, t2);
|
|
186
|
+
return [v[0] + qw * t2[0] + t3[0], v[1] + qw * t2[1] + t3[1], v[2] + qw * t2[2] + t3[2]];
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Interpolates a camera between two poses. `t` is expected already eased --
|
|
190
|
+
* this has no timing concerns of its own, which is what makes it testable
|
|
191
|
+
* without a clock.
|
|
192
|
+
*
|
|
193
|
+
* The pivot lerps from one target to the other, and the camera's ORIENTATION
|
|
194
|
+
* (both its direction from the pivot and its up vector) is carried by a
|
|
195
|
+
* single rotation built from the two poses' full orthonormal bases -- not by
|
|
196
|
+
* interpolating `dir` and `up` independently.
|
|
197
|
+
*
|
|
198
|
+
* That is a correctness requirement, not a style choice. Real preset data
|
|
199
|
+
* routinely contains antipodal up vectors on the same view axis (two views
|
|
200
|
+
* of the same volume authored from opposite conventions). A plain
|
|
201
|
+
* `lerp(upFrom, upTo, t)` passes through the zero vector at t=0.5, where
|
|
202
|
+
* `normalize` has no correct answer: the camera holds upside-down, then
|
|
203
|
+
* snaps 180 degrees in one frame. Composing the two bases into a relative
|
|
204
|
+
* rotation makes that case a well-defined 180-degree roll about the shared
|
|
205
|
+
* axis -- a smooth roll through the midpoint. The same construction covers
|
|
206
|
+
* two antipodal camera positions about one target.
|
|
207
|
+
*
|
|
208
|
+
* Reproduces `from.position` exactly at t=0 and `to.position` at t=1. `up` is
|
|
209
|
+
* likewise exact WHEN each pose's own `up` is already perpendicular to its
|
|
210
|
+
* own view direction; one that leans toward the view axis is silently
|
|
211
|
+
* squared up, which is by design -- it is not a meaningful camera roll.
|
|
212
|
+
*/
|
|
213
|
+
export function interpolateFlightPose(from, to, t) {
|
|
214
|
+
const u = clamp01(t);
|
|
215
|
+
const pivot = lerpVec3(from.target, to.target, u);
|
|
216
|
+
const fromOffset = sub(from.position, from.target);
|
|
217
|
+
const toOffset = sub(to.position, to.target);
|
|
218
|
+
const len = lerpScalar(length(fromOffset), length(toOffset), u);
|
|
219
|
+
const fromBasis = buildBasis(fromOffset, from.up);
|
|
220
|
+
const toBasis = buildBasis(toOffset, to.up);
|
|
221
|
+
const fromMatrix = basisToMatrix(fromBasis.right, fromBasis.up, fromBasis.dir);
|
|
222
|
+
const toMatrix = basisToMatrix(toBasis.right, toBasis.up, toBasis.dir);
|
|
223
|
+
// The rotation carrying the "from" frame onto the "to" frame. Both matrices
|
|
224
|
+
// are orthonormal, so transpose is inverse.
|
|
225
|
+
const relative = multiplyMat3(toMatrix, transposeMat3(fromMatrix));
|
|
226
|
+
const stepQuat = slerpQuat(IDENTITY_QUAT, matrixToQuaternion(relative), u);
|
|
227
|
+
const dir = rotateByQuaternion(fromBasis.dir, stepQuat);
|
|
228
|
+
const up = rotateByQuaternion(fromBasis.up, stepQuat);
|
|
229
|
+
return { position: add(pivot, scale(dir, len)), up: normalize(up), target: pivot };
|
|
230
|
+
}
|
|
231
|
+
/** The camera's orbit radius: how far `pose.position` sits from the pivot it
|
|
232
|
+
* looks at. Lets a push-in be expressed as an absolute target distance
|
|
233
|
+
* (idempotent) rather than a repeated fractional step. */
|
|
234
|
+
export function poseDistance(pose) {
|
|
235
|
+
return length(sub(pose.position, pose.target));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Orbits the camera around its own pivot by `yawRad` about its up vector,
|
|
239
|
+
* then by `pitchRad` about the RESULTING right vector. The pivot and the
|
|
240
|
+
* orbit radius are both untouched, so a run of steps can never walk the
|
|
241
|
+
* camera away from what it is looking at.
|
|
242
|
+
*
|
|
243
|
+
* Pitch about the yawed right vector, not the original: rotating about a
|
|
244
|
+
* stale axis makes a diagonal (left+up) combination drift off the sphere
|
|
245
|
+
* instead of tracing it.
|
|
246
|
+
*/
|
|
247
|
+
export function orbitStepPose(pose, yawRad, pitchRad) {
|
|
248
|
+
const offset = sub(pose.position, pose.target);
|
|
249
|
+
const { right, up } = buildBasis(offset, pose.up);
|
|
250
|
+
// Rotating a vector about itself is the identity, so `up` survives the yaw
|
|
251
|
+
// unchanged and only the pitch has to be applied to it.
|
|
252
|
+
const yawedOffset = rotateAroundAxis(offset, up, yawRad);
|
|
253
|
+
const yawedRight = rotateAroundAxis(right, up, yawRad);
|
|
254
|
+
return {
|
|
255
|
+
position: add(pose.target, rotateAroundAxis(yawedOffset, yawedRight, pitchRad)),
|
|
256
|
+
up: normalize(rotateAroundAxis(up, yawedRight, pitchRad)),
|
|
257
|
+
target: pose.target,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Scales the camera's distance from its pivot by `factor` along the unchanged
|
|
262
|
+
* view direction. Clamped at `minDistance` because a zero radius has no
|
|
263
|
+
* direction to normalize -- a held zoom-in key would otherwise collapse the
|
|
264
|
+
* pose into NaN one frame after reaching the pivot.
|
|
265
|
+
*/
|
|
266
|
+
export function zoomPose(pose, factor, minDistance = 1e-3) {
|
|
267
|
+
const offset = sub(pose.position, pose.target);
|
|
268
|
+
const next = Math.max(minDistance, length(offset) * factor);
|
|
269
|
+
return {
|
|
270
|
+
position: add(pose.target, scale(normalize(offset), next)),
|
|
271
|
+
up: pose.up,
|
|
272
|
+
target: pose.target,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Swing angle for an entrance orbit. `turns` is a SWING AMPLITUDE, not a net
|
|
277
|
+
* rotation: `sin(t*pi)` goes out and comes back to zero, so the camera always
|
|
278
|
+
* ends exactly on the framed preset view (t=1 -> angle 0) however large
|
|
279
|
+
* `turns` is. Do not "fix" this into a net rotation; that ends the intro
|
|
280
|
+
* off-preset.
|
|
281
|
+
*/
|
|
282
|
+
export function orbitSwingAngle(t, turns) {
|
|
283
|
+
return Math.sin(clamp01(t) * Math.PI) * turns * Math.PI * 2;
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=cameraTransitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cameraTransitions.js","sourceRoot":"","sources":["../../src/Controls/cameraTransitions.ts"],"names":[],"mappings":"AAqBA,SAAS,OAAO,CAAC,CAAS;IACxB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,cA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C,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;QAC1D,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,CAAS,EAAE,KAAa;IACtD,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAA;AAC7D,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CameraViewPreset, FitBounds } from './orbitFraming';
|
|
2
|
+
/**
|
|
3
|
+
* Re-frames a scene on its content, keeping the view preset's direction.
|
|
4
|
+
*
|
|
5
|
+
* A preset carries a hand-written `eyePosition`, which encodes both which way
|
|
6
|
+
* a reader should look at the data and how far away -- but only the direction
|
|
7
|
+
* is a decision. The distance has to follow the viewport: a fixed one cannot
|
|
8
|
+
* survive a viewport that is a third as wide as the one it was authored
|
|
9
|
+
* against, and hand-written values routinely leave the content filling a
|
|
10
|
+
* quarter of the frame.
|
|
11
|
+
*
|
|
12
|
+
* So the preset's view direction and up vector are kept exactly as authored
|
|
13
|
+
* and only the distance is recomputed.
|
|
14
|
+
*
|
|
15
|
+
* Written as a free function taking the scene as its first argument, so it
|
|
16
|
+
* can be called on an existing scene instance and unit-tested without a
|
|
17
|
+
* renderer. The scene class wraps it as a one-line method.
|
|
18
|
+
*/
|
|
19
|
+
interface Vec3Like {
|
|
20
|
+
set: (x: number, y: number, z: number) => void;
|
|
21
|
+
}
|
|
22
|
+
export interface FitViewScene {
|
|
23
|
+
camera: {
|
|
24
|
+
fov: number;
|
|
25
|
+
position: Vec3Like;
|
|
26
|
+
lookAt: (x: number, y: number, z: number) => void;
|
|
27
|
+
updateProjectionMatrix: () => void;
|
|
28
|
+
};
|
|
29
|
+
controls: {
|
|
30
|
+
/** OrbitControls / TrackballControls' orbit pivot. */
|
|
31
|
+
target?: Vec3Like;
|
|
32
|
+
/** TrackballControls caches the canvas's page box and recomputes it only
|
|
33
|
+
* here; OrbitControls measures per event and does not define this. */
|
|
34
|
+
handleResize?: () => void;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns false when there is nothing to do -- a preset whose eye sits
|
|
39
|
+
* exactly on its target has no direction to preserve.
|
|
40
|
+
*
|
|
41
|
+
* Does NOT render. The caller decides when to draw, which matters under
|
|
42
|
+
* on-demand rendering where this may be one of several changes in a frame.
|
|
43
|
+
*/
|
|
44
|
+
export declare function fitView(scene: FitViewScene, preset: CameraViewPreset, aspect: number, bounds: FitBounds, margin?: number): boolean;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { fitDistance } from './orbitFraming';
|
|
2
|
+
/**
|
|
3
|
+
* Returns false when there is nothing to do -- a preset whose eye sits
|
|
4
|
+
* exactly on its target has no direction to preserve.
|
|
5
|
+
*
|
|
6
|
+
* Does NOT render. The caller decides when to draw, which matters under
|
|
7
|
+
* on-demand rendering where this may be one of several changes in a frame.
|
|
8
|
+
*/
|
|
9
|
+
export function fitView(scene, preset, aspect, bounds, margin) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
const [px = 0, py = 0, pz = 0] = preset.targetPosition;
|
|
12
|
+
const [ex = 0, ey = 0, ez = 0] = preset.eyePosition;
|
|
13
|
+
const dx = ex - px;
|
|
14
|
+
const dy = ey - py;
|
|
15
|
+
const dz = ez - pz;
|
|
16
|
+
const length = Math.hypot(dx, dy, dz);
|
|
17
|
+
if (length === 0)
|
|
18
|
+
return false;
|
|
19
|
+
// Aim at the object's own centre, not at the preset's target. Presets
|
|
20
|
+
// target the origin, which is right for a volume whose RAS dimensions are
|
|
21
|
+
// centred there and wrong for a model whose bounding box is not -- framing
|
|
22
|
+
// one of those from the origin pushes part of it out of frame, which a
|
|
23
|
+
// narrow viewport makes obvious.
|
|
24
|
+
const [cx, cy, cz] = bounds.center;
|
|
25
|
+
const tx = px + cx;
|
|
26
|
+
const ty = py + cy;
|
|
27
|
+
const tz = pz + cz;
|
|
28
|
+
const distance = fitDistance(bounds, aspect, scene.camera.fov, margin);
|
|
29
|
+
scene.camera.position.set(tx + (dx / length) * distance, ty + (dy / length) * distance, tz + (dz / length) * distance);
|
|
30
|
+
scene.camera.lookAt(tx, ty, tz);
|
|
31
|
+
// LOAD-BEARING. Nothing syncs the controls' orbit pivot with
|
|
32
|
+
// `camera.lookAt()`, so without this the user's next drag calls
|
|
33
|
+
// `controls.update()`, which re-aims the camera at whatever `target` still
|
|
34
|
+
// held -- silently undoing everything above.
|
|
35
|
+
(_a = scene.controls.target) === null || _a === void 0 ? void 0 : _a.set(tx, ty, tz);
|
|
36
|
+
scene.camera.updateProjectionMatrix();
|
|
37
|
+
(_c = (_b = scene.controls).handleResize) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=fitView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fitView.js","sourceRoot":"","sources":["../../src/Controls/fitView.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAwC5C;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CACrB,KAAmB,EACnB,MAAwB,EACxB,MAAc,EACd,MAAiB,EACjB,MAAe;;IAEf,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,cAAc,CAAA;IACtD,MAAM,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,WAAW,CAAA;IACnD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;IACl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AAC,QAAQ,EAAC,YAAY,kDAAI,CAAA;IAC/B,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -69,3 +69,42 @@ export declare function resolveViewPose(preset: CameraViewPreset, pivot: THREE.V
|
|
|
69
69
|
* frameBox, OrbitControls' maxDistance is still the default Infinity.
|
|
70
70
|
*/
|
|
71
71
|
export declare function resolveFarPlane(presetFar: number, maxDistance: number, dist: number): number;
|
|
72
|
+
export interface FitBounds {
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
depth: number;
|
|
76
|
+
/** The box's centre in scene units. `[0, 0, 0]` for an NRRD volume, whose
|
|
77
|
+
* RAS dimensions describe a box centred on the origin; a GLB's is not,
|
|
78
|
+
* so framing one from the origin leaves part of it out of frame. Not read
|
|
79
|
+
* by `fitDistance`, which only needs the extents. */
|
|
80
|
+
center: [number, number, number];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* How far a perspective camera must sit from an object's centre for the whole
|
|
84
|
+
* object to fit in frame.
|
|
85
|
+
*
|
|
86
|
+
* Unlike `computeFraming` above this takes the viewport's ASPECT into
|
|
87
|
+
* account: below aspect 1 the horizontal field is the narrower of the two,
|
|
88
|
+
* and it is the narrower one that has to contain the object. A camera framed
|
|
89
|
+
* on vertical FOV alone under-frames every tall, narrow viewport.
|
|
90
|
+
*
|
|
91
|
+
* It also fits the bounding SPHERE rather than the box. Fitting the facing
|
|
92
|
+
* box face plus half the depth frames each object by whichever dimension
|
|
93
|
+
* happens to point at the camera, so a thin slab and a near-cubic volume of
|
|
94
|
+
* similar overall extent come out at wildly different sizes on screen. A
|
|
95
|
+
* sphere has no orientation, so comparable objects get comparable screen
|
|
96
|
+
* size -- and orbiting can no longer push a corner out of frame.
|
|
97
|
+
*
|
|
98
|
+
* @param aspect Viewport width / height. Zero or non-finite is treated as 1:
|
|
99
|
+
* a viewport mid-collapse measures 0 for a frame, and NaN in a
|
|
100
|
+
* projection matrix is unrecoverable.
|
|
101
|
+
* @param fovDeg The camera's VERTICAL field of view, in degrees.
|
|
102
|
+
* @param margin Multiplier applied at the end, and deliberately BELOW 1. A
|
|
103
|
+
* bounding sphere circumscribes the object -- a cube's has
|
|
104
|
+
* 1.73x its half-side -- so fitting the sphere exactly leaves
|
|
105
|
+
* the object filling well under half the frame. Letting the
|
|
106
|
+
* sphere overflow is what makes the object read at a sensible
|
|
107
|
+
* size. A tuning knob, not a correctness threshold: smaller
|
|
108
|
+
* means larger on screen.
|
|
109
|
+
*/
|
|
110
|
+
export declare function fitDistance(bounds: FitBounds, aspect: number, fovDeg: number, margin?: number): number;
|
|
@@ -78,6 +78,45 @@ export function resolveFarPlane(presetFar, maxDistance, dist) {
|
|
|
78
78
|
const zoomOutFar = Number.isFinite(maxDistance) ? maxDistance + dist : 0;
|
|
79
79
|
return Math.max(presetFar, zoomOutFar);
|
|
80
80
|
}
|
|
81
|
+
/** Nothing smaller than this, so a degenerate or not-yet-measured box can
|
|
82
|
+
* never put the camera at the origin looking at itself. */
|
|
83
|
+
const MIN_FIT_DISTANCE = 1e-3;
|
|
84
|
+
/**
|
|
85
|
+
* How far a perspective camera must sit from an object's centre for the whole
|
|
86
|
+
* object to fit in frame.
|
|
87
|
+
*
|
|
88
|
+
* Unlike `computeFraming` above this takes the viewport's ASPECT into
|
|
89
|
+
* account: below aspect 1 the horizontal field is the narrower of the two,
|
|
90
|
+
* and it is the narrower one that has to contain the object. A camera framed
|
|
91
|
+
* on vertical FOV alone under-frames every tall, narrow viewport.
|
|
92
|
+
*
|
|
93
|
+
* It also fits the bounding SPHERE rather than the box. Fitting the facing
|
|
94
|
+
* box face plus half the depth frames each object by whichever dimension
|
|
95
|
+
* happens to point at the camera, so a thin slab and a near-cubic volume of
|
|
96
|
+
* similar overall extent come out at wildly different sizes on screen. A
|
|
97
|
+
* sphere has no orientation, so comparable objects get comparable screen
|
|
98
|
+
* size -- and orbiting can no longer push a corner out of frame.
|
|
99
|
+
*
|
|
100
|
+
* @param aspect Viewport width / height. Zero or non-finite is treated as 1:
|
|
101
|
+
* a viewport mid-collapse measures 0 for a frame, and NaN in a
|
|
102
|
+
* projection matrix is unrecoverable.
|
|
103
|
+
* @param fovDeg The camera's VERTICAL field of view, in degrees.
|
|
104
|
+
* @param margin Multiplier applied at the end, and deliberately BELOW 1. A
|
|
105
|
+
* bounding sphere circumscribes the object -- a cube's has
|
|
106
|
+
* 1.73x its half-side -- so fitting the sphere exactly leaves
|
|
107
|
+
* the object filling well under half the frame. Letting the
|
|
108
|
+
* sphere overflow is what makes the object read at a sensible
|
|
109
|
+
* size. A tuning knob, not a correctness threshold: smaller
|
|
110
|
+
* means larger on screen.
|
|
111
|
+
*/
|
|
112
|
+
export function fitDistance(bounds, aspect, fovDeg, margin = 0.85) {
|
|
113
|
+
const safeAspect = Number.isFinite(aspect) && aspect > 0 ? aspect : 1;
|
|
114
|
+
const vHalf = (fovDeg * Math.PI) / 360;
|
|
115
|
+
const hHalf = Math.atan(Math.tan(vHalf) * safeAspect);
|
|
116
|
+
const half = Math.min(vHalf, hHalf);
|
|
117
|
+
const radius = Math.hypot(bounds.width, bounds.height, bounds.depth) / 2;
|
|
118
|
+
return Math.max((radius / Math.sin(half)) * margin, MIN_FIT_DISTANCE);
|
|
119
|
+
}
|
|
81
120
|
/** Project up onto the plane perpendicular to dir; fall back to any perpendicular axis when degenerate. */
|
|
82
121
|
function orthogonalize(up, dir) {
|
|
83
122
|
const d = up.dot(dir);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orbitFraming.js","sourceRoot":"","sources":["../../src/Controls/orbitFraming.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AA0B9B,uFAAuF;AACvF,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;AAEjC;;;;GAIG;AACH,MAAM,aAAa,GAAwB,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAE1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AAG,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAA;IAChF,CAAC;IACD,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAA;AAClE,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces a `VolumeSlice`'s `repaint` with an equivalent that does not
|
|
3
|
+
* rebuild the world on every scrub step, and can optionally lift its
|
|
4
|
+
* mid-tones.
|
|
5
|
+
*
|
|
6
|
+
* ## What the original does, per slice change
|
|
7
|
+
*
|
|
8
|
+
* Setting `slice.index` sets `geometryNeedsUpdate`, so the next `repaint()`
|
|
9
|
+
* runs `updateGeometry()` first. That method unconditionally:
|
|
10
|
+
*
|
|
11
|
+
* - assigns `canvas.width` / `canvas.height` and the same on `canvasBuffer`
|
|
12
|
+
* -- assigning either RESETS the whole 2D backing store even when the
|
|
13
|
+
* value is unchanged;
|
|
14
|
+
* - re-fetches both 2D contexts;
|
|
15
|
+
* - calls `geometry.dispose()` and builds a `new PlaneGeometry(...)`, i.e.
|
|
16
|
+
* deletes and recreates GPU buffers, every frame.
|
|
17
|
+
*
|
|
18
|
+
* Then `repaint()` calls `ctx.getImageData(...)`, a full canvas read-back
|
|
19
|
+
* that allocates a fresh `Uint8ClampedArray` -- every pixel of which is
|
|
20
|
+
* overwritten by the loop immediately below it, so the read is pure waste.
|
|
21
|
+
*
|
|
22
|
+
* Within one volume and one axis, `planeWidth`, `planeHeight`, `iLength` and
|
|
23
|
+
* `jLength` are the same for every slice; only `sliceAccess` and `matrix`
|
|
24
|
+
* differ. So all of the above is redundant on every scrub step but the first.
|
|
25
|
+
*
|
|
26
|
+
* Measured in a real browser while dragging a slice plane: 59 long tasks
|
|
27
|
+
* (>50ms) in ~2s and a p90 frame time of 61ms, against zero long tasks for
|
|
28
|
+
* the same drag on a scene that rotates but never repaints.
|
|
29
|
+
*
|
|
30
|
+
* `VolumeSlice` comes from three rather than from this library, and there is
|
|
31
|
+
* no option for any of this, so replacing the method per instance is the
|
|
32
|
+
* available lever.
|
|
33
|
+
*
|
|
34
|
+
* ## Fidelity
|
|
35
|
+
*
|
|
36
|
+
* The pixel loop is copied from the original, byte for byte in its
|
|
37
|
+
* arithmetic, threshold and window-level handling included. The differences
|
|
38
|
+
* are the ones above -- cached `ImageData`, geometry work skipped while the
|
|
39
|
+
* plane dimensions are unchanged -- plus the optional exposure LUT, which is
|
|
40
|
+
* the one thing here that changes what a pixel comes out as. `label` volumes
|
|
41
|
+
* are handed back to the original implementation.
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* Idempotent: patching an already-patched slice is a no-op.
|
|
45
|
+
*
|
|
46
|
+
* `exposure` is a gamma exponent, normally from `exposureExponent()`; 1
|
|
47
|
+
* leaves greyscale exactly as the original produced it.
|
|
48
|
+
*
|
|
49
|
+
* CALL THIS BEFORE THE FIRST PAINT. The LUT lives in the patched method, so
|
|
50
|
+
* painting first draws one un-lifted frame and corrects it on the reader's
|
|
51
|
+
* first scrub -- a visible colour change.
|
|
52
|
+
*
|
|
53
|
+
* Async only because `PlaneGeometry` is imported on demand, to keep three out
|
|
54
|
+
* of a consumer's initial chunk when nothing scrubs a slice.
|
|
55
|
+
*/
|
|
56
|
+
export declare function installFastSliceRepaint(rawSlice: unknown, exposure?: number): Promise<void>;
|