@margoengine/cinematic 0.0.0-stage → 1.0.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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +320 -2
- package/dist/brain.d.ts +227 -0
- package/dist/brain.js +272 -0
- package/dist/composer.d.ts +62 -0
- package/dist/composer.js +65 -0
- package/dist/confine.d.ts +50 -0
- package/dist/confine.js +97 -0
- package/dist/dolly.d.ts +59 -0
- package/dist/dolly.js +64 -0
- package/dist/group.d.ts +72 -0
- package/dist/group.js +90 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +115 -0
- package/dist/lens.d.ts +68 -0
- package/dist/lens.js +29 -0
- package/dist/noise.d.ts +71 -0
- package/dist/noise.js +166 -0
- package/dist/ortho.d.ts +104 -0
- package/dist/ortho.js +130 -0
- package/dist/physical-lens.d.ts +61 -0
- package/dist/physical-lens.js +35 -0
- package/dist/target-CZNe0IXh.js +13 -0
- package/dist/target.d.ts +9 -0
- package/package.json +89 -4
package/dist/lens.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { CameraPose, CameraStage } from './brain.js';
|
|
2
|
+
import { type CameraTarget } from './target.js';
|
|
3
|
+
export type { CameraTarget } from './target.js';
|
|
4
|
+
/** Settings of a {@link FocusTracker}. */
|
|
5
|
+
export interface FocusTrackerOptions {
|
|
6
|
+
/** How fast focus follows, in 1/seconds, above 0. Lower is a slow rack. Default 6. */
|
|
7
|
+
focusDamping?: number;
|
|
8
|
+
/** Added to the distance, to focus in front of or behind the point (a face, not the feet). Finite. Default 0. */
|
|
9
|
+
focusOffset?: number;
|
|
10
|
+
/** Nearest focus, above 0. Keep it beyond the lens's focal length. Default 0.1. */
|
|
11
|
+
minFocus?: number;
|
|
12
|
+
/** Height of the subject in world units, above 0. With `screenHeight` it drives the field of view. Default none. */
|
|
13
|
+
size?: number;
|
|
14
|
+
/** Share of the screen height the subject should fill, above 0 and at most 1. Default 0.5. */
|
|
15
|
+
screenHeight?: number;
|
|
16
|
+
/** How fast the field of view follows, in 1/seconds, above 0. Default 4. */
|
|
17
|
+
fovDamping?: number;
|
|
18
|
+
/** Narrowest field of view in degrees. Default 10. */
|
|
19
|
+
minFov?: number;
|
|
20
|
+
/** Widest field of view in degrees, at least `minFov`, below 180. Default 100. */
|
|
21
|
+
maxFov?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A stage that sets `pose.focusDistance` from `target`, and `pose.fov` too when `size` is given. Put it after the stages
|
|
25
|
+
* that place and aim the camera. The focus reaches a lens through {@link focusOutput}.
|
|
26
|
+
*/
|
|
27
|
+
export declare class FocusTracker {
|
|
28
|
+
/** What stays in focus; change it at any time. */
|
|
29
|
+
target: CameraTarget;
|
|
30
|
+
/** The focus after the last update, in world units along the view. */
|
|
31
|
+
focus: number;
|
|
32
|
+
/** The field of view after the last update, in degrees; 0 before the first update or without `size`. */
|
|
33
|
+
fov: number;
|
|
34
|
+
private readonly focusRate;
|
|
35
|
+
private readonly offset;
|
|
36
|
+
private readonly minFocus;
|
|
37
|
+
private readonly size?;
|
|
38
|
+
private readonly share;
|
|
39
|
+
private readonly fovRate;
|
|
40
|
+
private readonly minFov;
|
|
41
|
+
private readonly maxFov;
|
|
42
|
+
private readonly point;
|
|
43
|
+
private started;
|
|
44
|
+
/** @throws RangeError for a value outside what {@link FocusTrackerOptions} allows. */
|
|
45
|
+
constructor(target: CameraTarget, options?: FocusTrackerOptions);
|
|
46
|
+
/** Forgets the focus: the next update is sharp on the subject at once, as on a cut. */
|
|
47
|
+
reset(): void;
|
|
48
|
+
/** Stage hook. @throws RangeError for a bad target. */
|
|
49
|
+
update(pose: CameraPose, delta: number): void;
|
|
50
|
+
}
|
|
51
|
+
/** Where {@link focusOutput} sends the focus. Each is optional and only touched when given. */
|
|
52
|
+
export interface FocusTargets {
|
|
53
|
+
/** A `PhysicalCamera` from `@margoengine/cameras/physical`, or anything with `focusDistance`. */
|
|
54
|
+
physical?: {
|
|
55
|
+
focusDistance: number;
|
|
56
|
+
};
|
|
57
|
+
/** A `DOF` effect from `@margoengine/dof`. */
|
|
58
|
+
dof?: {
|
|
59
|
+
options: {
|
|
60
|
+
focalDistance?: number;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A stage for `brain.stages` that hands the pose's focus to a lens, so a blend racks focus from one camera to the next.
|
|
66
|
+
* With no focus on the pose it leaves the lens alone.
|
|
67
|
+
*/
|
|
68
|
+
export declare const focusOutput: ({ physical, dof }: FocusTargets) => CameraStage;
|
package/dist/lens.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { t as e } from "./target-CZNe0IXh.js";
|
|
2
|
+
//#region src/lens.ts
|
|
3
|
+
var t = class {
|
|
4
|
+
constructor(e, t = {}) {
|
|
5
|
+
this.focus = 0, this.fov = 0, this.point = /* @__PURE__ */ new Float64Array(3), this.started = !1;
|
|
6
|
+
let { focusDamping: n = 6, focusOffset: r = 0, minFocus: i = .1, size: a, screenHeight: o = .5, fovDamping: s = 4, minFov: c = 10, maxFov: l = 100 } = t;
|
|
7
|
+
if (!(n > 0 && n < Infinity) || !(s > 0 && s < Infinity)) throw RangeError("Invalid lens damping; pass a rate above 0");
|
|
8
|
+
if (!Number.isFinite(r) || !(i > 0 && i < Infinity)) throw RangeError("Invalid lens focus; pass a finite focusOffset and a minFocus above 0");
|
|
9
|
+
if (a !== void 0 && !(a > 0 && a < Infinity)) throw RangeError("Invalid lens size; pass a subject height above 0");
|
|
10
|
+
if (!(o > 0 && o <= 1)) throw RangeError("Invalid lens screenHeight; pass a share of the screen above 0 and at most 1");
|
|
11
|
+
if (!(c > 0 && l >= c && l < 180)) throw RangeError("Invalid lens fov; pass a minFov above 0 and a maxFov at least as large, below 180");
|
|
12
|
+
this.target = e, this.focusRate = n, this.offset = r, this.minFocus = i, this.size = a, this.share = o, this.fovRate = s, this.minFov = c, this.maxFov = l;
|
|
13
|
+
}
|
|
14
|
+
reset() {
|
|
15
|
+
this.started = !1;
|
|
16
|
+
}
|
|
17
|
+
update(t, n) {
|
|
18
|
+
let { position: r, target: i } = t, a = e(this.target, this.point), o = i[0] - r[0], s = i[1] - r[1], c = i[2] - r[2], l = Math.hypot(o, s, c);
|
|
19
|
+
if (!(l > 0)) return;
|
|
20
|
+
o /= l, s /= l, c /= l;
|
|
21
|
+
let u = (a[0] - r[0]) * o + (a[1] - r[1]) * s + (a[2] - r[2]) * c, d = Math.max(this.minFocus, u + this.offset), f = this.size, p = f ? u > 0 ? Math.min(this.maxFov, Math.max(this.minFov, Math.atan(f / (2 * this.share * u)) * 360 / Math.PI)) : this.maxFov : 0;
|
|
22
|
+
this.started ? (this.focus = d + (this.focus - d) * Math.exp(-this.focusRate * n), this.fov = p + (this.fov - p) * Math.exp(-this.fovRate * n)) : (this.focus = d, this.fov = p), this.started = !0, t.focusDistance = this.focus, f && (t.fov = this.fov);
|
|
23
|
+
}
|
|
24
|
+
}, n = ({ physical: e, dof: t }) => (n) => {
|
|
25
|
+
let r = n.focusDistance;
|
|
26
|
+
r && (e && (e.focusDistance = r), t && (t.options.focalDistance = r));
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { t as FocusTracker, n as focusOutput };
|
package/dist/noise.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { CameraPose } from './brain.js';
|
|
2
|
+
/** One layer of noise on one axis. */
|
|
3
|
+
export interface NoiseBand {
|
|
4
|
+
/** Hertz, above 0: the middle of the band's power. It is noise, so the power spreads about this. */
|
|
5
|
+
frequency: number;
|
|
6
|
+
/** The most this band can add: world units for `position`, radians for `rotation`. 0 or more. */
|
|
7
|
+
amplitude: number;
|
|
8
|
+
}
|
|
9
|
+
/** Noise on each axis of the camera, as plain data you can save as JSON. An axis left out stays still. */
|
|
10
|
+
export interface NoiseProfile {
|
|
11
|
+
/** Along the camera's own right, up and back axes, before its roll. */
|
|
12
|
+
position?: {
|
|
13
|
+
x?: readonly NoiseBand[];
|
|
14
|
+
y?: readonly NoiseBand[];
|
|
15
|
+
z?: readonly NoiseBand[];
|
|
16
|
+
};
|
|
17
|
+
/** Turns of the view: up and down, left and right, and about the view. */
|
|
18
|
+
rotation?: {
|
|
19
|
+
pitch?: readonly NoiseBand[];
|
|
20
|
+
yaw?: readonly NoiseBand[];
|
|
21
|
+
roll?: readonly NoiseBand[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Settings of a {@link CameraNoise}. */
|
|
25
|
+
export interface CameraNoiseOptions {
|
|
26
|
+
/** Scales every amplitude, 0 or more. Change it at any time, or tween it to fade the noise. Default 1. */
|
|
27
|
+
gain?: number;
|
|
28
|
+
/** Scales every frequency, 0 or more. Change it at any time. Default 1. */
|
|
29
|
+
speed?: number;
|
|
30
|
+
/** The same seed gives the same motion. It wraps to a 32 bit integer. Default 0. */
|
|
31
|
+
seed?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A hand-held camera: slow sway of the arms, and hand tremor near the 5 to 12 Hz of published physiological tremor. The
|
|
35
|
+
* amplitudes are our own choice by eye, not measured.
|
|
36
|
+
*/
|
|
37
|
+
export declare const handheld: NoiseProfile;
|
|
38
|
+
/** A camera carried at a walk: the step near 2 Hz up and down, the sway of each leg at half that. Amplitudes by eye. */
|
|
39
|
+
export declare const walking: NoiseProfile;
|
|
40
|
+
/**
|
|
41
|
+
* A camera on a road vehicle: body bounce and pitch near the 1 to 2 Hz of a sprung mass, and the buzz of wheel hop near
|
|
42
|
+
* 10 to 15 Hz. Amplitudes by eye.
|
|
43
|
+
*/
|
|
44
|
+
export declare const vehicle: NoiseProfile;
|
|
45
|
+
/**
|
|
46
|
+
* A stage that shakes the camera by a profile. Put it after the stages that aim. It runs until you stop it: set `gain`
|
|
47
|
+
* to 0, or tween it. For one short hit use `Cinematic.shake`.
|
|
48
|
+
*/
|
|
49
|
+
export declare class CameraNoise {
|
|
50
|
+
readonly profile: NoiseProfile;
|
|
51
|
+
/** Scales every amplitude; change it at any time. */
|
|
52
|
+
gain: number;
|
|
53
|
+
/** Scales every frequency; change it at any time. */
|
|
54
|
+
speed: number;
|
|
55
|
+
/** Seconds of noise so far, after `speed`. Set it to replay a moment. */
|
|
56
|
+
time: number;
|
|
57
|
+
/** The current value of each axis, in the order x, y, z, pitch, yaw, roll, with `gain` applied. */
|
|
58
|
+
readonly values: Float64Array<ArrayBuffer>;
|
|
59
|
+
private readonly bands;
|
|
60
|
+
private readonly view;
|
|
61
|
+
/** @throws RangeError for a band or option outside the allowed range. */
|
|
62
|
+
constructor(profile: NoiseProfile, options?: CameraNoiseOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Moves the noise clock by `delta` seconds times `speed` without touching a pose. The stage hook runs it; pass the
|
|
65
|
+
* noise to `seek` from `@margoengine/cutscene/seek` as an `extra` clock to start a film scene on the shake a continuous
|
|
66
|
+
* run shows. @throws RangeError when `gain` or `speed` was set out of range.
|
|
67
|
+
*/
|
|
68
|
+
advanceTime(delta: number): void;
|
|
69
|
+
/** Stage hook. @throws RangeError when `gain` or `speed` was set out of range. */
|
|
70
|
+
update(pose: CameraPose, delta: number): void;
|
|
71
|
+
}
|
package/dist/noise.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { createRandom as e } from "@margoengine/math/mathutils";
|
|
2
|
+
//#region src/noise.ts
|
|
3
|
+
var t = Math.PI / 180, n = {
|
|
4
|
+
position: {
|
|
5
|
+
x: [{
|
|
6
|
+
frequency: .4,
|
|
7
|
+
amplitude: .012
|
|
8
|
+
}],
|
|
9
|
+
y: [{
|
|
10
|
+
frequency: .5,
|
|
11
|
+
amplitude: .012
|
|
12
|
+
}],
|
|
13
|
+
z: [{
|
|
14
|
+
frequency: .3,
|
|
15
|
+
amplitude: .01
|
|
16
|
+
}]
|
|
17
|
+
},
|
|
18
|
+
rotation: {
|
|
19
|
+
pitch: [
|
|
20
|
+
{
|
|
21
|
+
frequency: .5,
|
|
22
|
+
amplitude: .5 * t
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
frequency: 1.7,
|
|
26
|
+
amplitude: .12 * t
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
frequency: 8,
|
|
30
|
+
amplitude: .02 * t
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
yaw: [
|
|
34
|
+
{
|
|
35
|
+
frequency: .4,
|
|
36
|
+
amplitude: .6 * t
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
frequency: 1.3,
|
|
40
|
+
amplitude: .12 * t
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
frequency: 7,
|
|
44
|
+
amplitude: .02 * t
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
roll: [{
|
|
48
|
+
frequency: .3,
|
|
49
|
+
amplitude: .3 * t
|
|
50
|
+
}]
|
|
51
|
+
}
|
|
52
|
+
}, r = {
|
|
53
|
+
position: {
|
|
54
|
+
x: [{
|
|
55
|
+
frequency: 1,
|
|
56
|
+
amplitude: .02
|
|
57
|
+
}],
|
|
58
|
+
y: [{
|
|
59
|
+
frequency: 2,
|
|
60
|
+
amplitude: .025
|
|
61
|
+
}]
|
|
62
|
+
},
|
|
63
|
+
rotation: {
|
|
64
|
+
pitch: [{
|
|
65
|
+
frequency: 2,
|
|
66
|
+
amplitude: .25 * t
|
|
67
|
+
}],
|
|
68
|
+
yaw: [{
|
|
69
|
+
frequency: .4,
|
|
70
|
+
amplitude: .3 * t
|
|
71
|
+
}],
|
|
72
|
+
roll: [{
|
|
73
|
+
frequency: 1,
|
|
74
|
+
amplitude: .35 * t
|
|
75
|
+
}]
|
|
76
|
+
}
|
|
77
|
+
}, i = {
|
|
78
|
+
position: { y: [{
|
|
79
|
+
frequency: 1.2,
|
|
80
|
+
amplitude: .02
|
|
81
|
+
}, {
|
|
82
|
+
frequency: 12,
|
|
83
|
+
amplitude: .003
|
|
84
|
+
}] },
|
|
85
|
+
rotation: {
|
|
86
|
+
pitch: [{
|
|
87
|
+
frequency: 1.4,
|
|
88
|
+
amplitude: .3 * t
|
|
89
|
+
}, {
|
|
90
|
+
frequency: 12,
|
|
91
|
+
amplitude: .04 * t
|
|
92
|
+
}],
|
|
93
|
+
roll: [{
|
|
94
|
+
frequency: 1,
|
|
95
|
+
amplitude: .2 * t
|
|
96
|
+
}]
|
|
97
|
+
}
|
|
98
|
+
}, a = (e, t) => {
|
|
99
|
+
let n = Math.imul(e ^ t, 2654435761);
|
|
100
|
+
return n = Math.imul(n ^ n >>> 15, 2246822507), n = Math.imul(n ^ n >>> 13, 3266489909), ((n ^ n >>> 16) >>> 0) / 2147483648 - 1;
|
|
101
|
+
}, o = (e, t) => {
|
|
102
|
+
let n = Math.floor(e), r = e - n, i = r * r * r * (r * (r * 6 - 15) + 10), o = a(n, t) * r;
|
|
103
|
+
return 2 * (o + (a(n + 1, t) * (r - 1) - o) * i);
|
|
104
|
+
}, s = [
|
|
105
|
+
"x",
|
|
106
|
+
"y",
|
|
107
|
+
"z",
|
|
108
|
+
"pitch",
|
|
109
|
+
"yaw",
|
|
110
|
+
"roll"
|
|
111
|
+
], c = (e, t, n, r, i) => {
|
|
112
|
+
let a = Math.cos(i), o = Math.sin(i), s = (t * e[0] + n * e[1] + r * e[2]) * (1 - a), c = e[0] * a + (n * e[2] - r * e[1]) * o + t * s, l = e[1] * a + (r * e[0] - t * e[2]) * o + n * s, u = e[2] * a + (t * e[1] - n * e[0]) * o + r * s;
|
|
113
|
+
e[0] = c, e[1] = l, e[2] = u;
|
|
114
|
+
}, l = class {
|
|
115
|
+
constructor(t, n = {}) {
|
|
116
|
+
this.profile = t, this.time = 0, this.values = /* @__PURE__ */ new Float64Array(6), this.view = /* @__PURE__ */ new Float64Array(3);
|
|
117
|
+
let { gain: r = 1, speed: i = 1, seed: a = 0 } = n;
|
|
118
|
+
if (!(r >= 0 && r < Infinity) || !(i >= 0 && i < Infinity) || !Number.isFinite(a)) throw RangeError("Invalid camera noise; pass a gain and speed of 0 or more and a finite seed");
|
|
119
|
+
this.gain = r, this.speed = i;
|
|
120
|
+
let o = e(a), c = [
|
|
121
|
+
t?.position?.x,
|
|
122
|
+
t?.position?.y,
|
|
123
|
+
t?.position?.z,
|
|
124
|
+
t?.rotation?.pitch,
|
|
125
|
+
t?.rotation?.yaw,
|
|
126
|
+
t?.rotation?.roll
|
|
127
|
+
];
|
|
128
|
+
this.bands = s.map((e, t) => {
|
|
129
|
+
let n = c[t] ?? [], r = new Float64Array(n.length * 3);
|
|
130
|
+
return n.forEach((e, t) => {
|
|
131
|
+
if (!(e?.frequency > 0 && e.frequency < Infinity && e.amplitude >= 0 && e.amplitude < Infinity)) throw RangeError("Invalid noise band; pass a frequency above 0 and an amplitude of 0 or more");
|
|
132
|
+
r[t * 3] = e.frequency * 2, r[t * 3 + 1] = e.amplitude, r[t * 3 + 2] = Math.floor(o() * 2147483647);
|
|
133
|
+
}), r;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
advanceTime(e) {
|
|
137
|
+
let { gain: t, speed: n } = this;
|
|
138
|
+
if (!(t >= 0 && t < Infinity) || !(n >= 0 && n < Infinity)) throw RangeError("Invalid camera noise; pass a gain and speed of 0 or more");
|
|
139
|
+
this.time += e * n;
|
|
140
|
+
}
|
|
141
|
+
update(e, t) {
|
|
142
|
+
this.advanceTime(t);
|
|
143
|
+
let { gain: n, values: r, view: i } = this;
|
|
144
|
+
for (let e = 0; e < 6; e++) {
|
|
145
|
+
let t = this.bands[e], i = 0;
|
|
146
|
+
for (let e = 0; e < t.length; e += 3) i += t[e + 1] * o(this.time * t[e], t[e + 2]);
|
|
147
|
+
r[e] = i * n;
|
|
148
|
+
}
|
|
149
|
+
let { position: a, target: s, up: l } = e;
|
|
150
|
+
i[0] = s[0] - a[0], i[1] = s[1] - a[1], i[2] = s[2] - a[2];
|
|
151
|
+
let u = Math.hypot(i[0], i[1], i[2]);
|
|
152
|
+
if (!(u > 0)) return;
|
|
153
|
+
let d = i[0] / u, f = i[1] / u, p = i[2] / u, m = f * l[2] - p * l[1], h = p * l[0] - d * l[2], g = d * l[1] - f * l[0], _ = Math.hypot(m, h, g);
|
|
154
|
+
if (_ < 1e-9) {
|
|
155
|
+
let e = Math.abs(d) < .9;
|
|
156
|
+
m = e ? 0 : -p, h = e ? p : 0, g = e ? -f : d, _ = Math.hypot(m, h, g);
|
|
157
|
+
}
|
|
158
|
+
m /= _, h /= _, g /= _;
|
|
159
|
+
let v = h * p - g * f, y = g * d - m * p, b = m * f - h * d;
|
|
160
|
+
c(i, m, h, g, r[3]), c(i, v, y, b, r[4]);
|
|
161
|
+
let [x, S, C] = r;
|
|
162
|
+
a[0] += m * x + v * S - d * C, a[1] += h * x + y * S - f * C, a[2] += g * x + b * S - p * C, s[0] = a[0] + i[0], s[1] = a[1] + i[1], s[2] = a[2] + i[2], e.roll += r[5];
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
//#endregion
|
|
166
|
+
export { l as CameraNoise, n as handheld, i as vehicle, r as walking };
|
package/dist/ortho.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { VirtualCamera, type CameraPose, type CameraStage, type StageContext, type VirtualCameraOptions } from './brain.js';
|
|
2
|
+
import type { FramingComposerOptions } from './composer.js';
|
|
3
|
+
import type { GroupMember } from './group.js';
|
|
4
|
+
import { type CameraTarget } from './target.js';
|
|
5
|
+
/** A virtual camera with an orthographic world height instead of a perspective field of view. */
|
|
6
|
+
export interface OrthographicCameraOptions extends Omit<VirtualCameraOptions, 'orthographicHeight'> {
|
|
7
|
+
/** Full visible world height; width is height times aspect. Default 10. */
|
|
8
|
+
height?: number;
|
|
9
|
+
}
|
|
10
|
+
/** Add this camera to a CameraBrain; ordinary rigStage follow, noise, dolly and confiner stages still work. */
|
|
11
|
+
export declare class OrthographicCamera extends VirtualCamera {
|
|
12
|
+
/** @throws RangeError for invalid camera options or height. */
|
|
13
|
+
constructor({ height, ...options }?: OrthographicCameraOptions);
|
|
14
|
+
/** Full visible world height; changes the base pose before stages. */
|
|
15
|
+
get height(): number;
|
|
16
|
+
/** @throws RangeError for a nonpositive or nonfinite height. */
|
|
17
|
+
set height(value: number);
|
|
18
|
+
}
|
|
19
|
+
/** A CameraProjection from cameras, structurally typed so this entry does not import that package. */
|
|
20
|
+
export interface OrthographicProjectionTarget {
|
|
21
|
+
mode: 'orthographic' | 'perspective';
|
|
22
|
+
height?: number;
|
|
23
|
+
zoom: number;
|
|
24
|
+
left?: number;
|
|
25
|
+
right?: number;
|
|
26
|
+
top?: number;
|
|
27
|
+
bottom?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Brain output stage: copy the blended world height to CameraProjection, replacing explicit bounds and zoom.
|
|
31
|
+
* Perspective poses switch the projection back to perspective. Put this after the stages that change height.
|
|
32
|
+
* @throws RangeError for a nonpositive or nonfinite authored orthographic height.
|
|
33
|
+
*/
|
|
34
|
+
export declare function orthographicOutput(projection: OrthographicProjectionTarget): CameraStage;
|
|
35
|
+
/**
|
|
36
|
+
* Translate an orthographic view to frame a subject, preserving its direction and distance. Uses the same screen,
|
|
37
|
+
* zones, damping and lookahead options as FramingComposer, including arbitrary up and camera roll.
|
|
38
|
+
*/
|
|
39
|
+
export declare class OrthographicFraming {
|
|
40
|
+
/** Subject to frame; call reset after changing it when an immediate snap is desired. */
|
|
41
|
+
target: CameraTarget;
|
|
42
|
+
/** Predicted subject's screen point, from top left, after the last update. */
|
|
43
|
+
readonly onScreen: Float64Array<ArrayBuffer>;
|
|
44
|
+
/** Subject position after velocity lookahead, in world units. */
|
|
45
|
+
readonly aimPoint: Float64Array<ArrayBuffer>;
|
|
46
|
+
private readonly screen;
|
|
47
|
+
private readonly dead;
|
|
48
|
+
private readonly soft;
|
|
49
|
+
private readonly rate;
|
|
50
|
+
private readonly lookahead;
|
|
51
|
+
private readonly smoothing;
|
|
52
|
+
private readonly vertical;
|
|
53
|
+
private readonly point;
|
|
54
|
+
private readonly previous;
|
|
55
|
+
private readonly velocity;
|
|
56
|
+
private readonly offset;
|
|
57
|
+
private readonly right;
|
|
58
|
+
private readonly up;
|
|
59
|
+
private readonly relative;
|
|
60
|
+
private started;
|
|
61
|
+
/** @throws RangeError for invalid screen shares, zone sizes, damping or lookahead. */
|
|
62
|
+
constructor(target: CameraTarget, { screen, deadZone, softZone, damping, lookahead, lookaheadSmoothing, lookaheadVertical, }?: FramingComposerOptions);
|
|
63
|
+
/** Forget translation and measured velocity; the next update snaps to the screen point. */
|
|
64
|
+
reset(): void;
|
|
65
|
+
/** Stage hook. @throws RangeError for invalid pose, delta, aspect or target. */
|
|
66
|
+
update(pose: CameraPose, delta: number, { aspect }: StageContext): void;
|
|
67
|
+
}
|
|
68
|
+
/** Orthographic group fit settings; radii and weights have the same meanings as GroupFraming. */
|
|
69
|
+
export interface OrthographicGroupOptions {
|
|
70
|
+
/** Screen share kept clear at every edge, 0 to below 0.5. Default 0.1. */
|
|
71
|
+
padding?: number;
|
|
72
|
+
/** Minimum full world height. Default 0.01. */
|
|
73
|
+
minHeight?: number;
|
|
74
|
+
/** Maximum full world height, at least minHeight; Infinity is allowed. Default Infinity. */
|
|
75
|
+
maxHeight?: number;
|
|
76
|
+
/** Exponential catch-up rate in inverse seconds. Default 4. */
|
|
77
|
+
damping?: number;
|
|
78
|
+
}
|
|
79
|
+
/** Aim at a weighted group centre and fit projected spheres by changing orthographic height, preserving view angle. */
|
|
80
|
+
export declare class OrthographicGroupFraming {
|
|
81
|
+
/** Mutable group membership. Weight 0 omits a member. */
|
|
82
|
+
readonly members: GroupMember[];
|
|
83
|
+
/** Smoothed weighted centre after the last update. */
|
|
84
|
+
readonly center: Float64Array<ArrayBuffer>;
|
|
85
|
+
/** Whether all participating spheres fit the padded screen at the actual output height. */
|
|
86
|
+
fits: boolean;
|
|
87
|
+
private readonly padding;
|
|
88
|
+
private readonly min;
|
|
89
|
+
private readonly max;
|
|
90
|
+
private readonly rate;
|
|
91
|
+
private readonly points;
|
|
92
|
+
private readonly right;
|
|
93
|
+
private readonly up;
|
|
94
|
+
private readonly relative;
|
|
95
|
+
private readonly goal;
|
|
96
|
+
private height;
|
|
97
|
+
private started;
|
|
98
|
+
/** @throws RangeError for invalid padding, size limits or damping. */
|
|
99
|
+
constructor(members: readonly (CameraTarget | GroupMember)[], { padding, minHeight, maxHeight, damping }?: OrthographicGroupOptions);
|
|
100
|
+
/** Forget smoothing; the next update fits immediately. */
|
|
101
|
+
reset(): void;
|
|
102
|
+
/** Stage hook. @throws RangeError for an invalid pose, delta, aspect, member radius, weight or target. */
|
|
103
|
+
update(pose: CameraPose, delta: number, { aspect }: StageContext): void;
|
|
104
|
+
}
|
package/dist/ortho.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { VirtualCamera as e } from "./brain.js";
|
|
2
|
+
import { t } from "./target-CZNe0IXh.js";
|
|
3
|
+
//#region src/ortho.ts
|
|
4
|
+
var n = (e, t) => {
|
|
5
|
+
if (!(e > 0 && Number.isFinite(e))) throw RangeError(`Invalid orthographic ${t}; pass a finite value above 0. https://margoengine.com/llms/packages/cinematic.md`);
|
|
6
|
+
}, r = (e) => {
|
|
7
|
+
let t = e.orthographicHeight ?? 0;
|
|
8
|
+
return n(t, "height"), t;
|
|
9
|
+
}, i = (e) => {
|
|
10
|
+
if (!(e >= 0 && Number.isFinite(e))) throw RangeError("Invalid orthographic delta; pass finite seconds of 0 or more");
|
|
11
|
+
}, a = class extends e {
|
|
12
|
+
constructor({ height: e = 10, ...t } = {}) {
|
|
13
|
+
n(e, "height"), super({
|
|
14
|
+
...t,
|
|
15
|
+
orthographicHeight: e
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
get height() {
|
|
19
|
+
return this.base.orthographicHeight;
|
|
20
|
+
}
|
|
21
|
+
set height(e) {
|
|
22
|
+
n(e, "height"), this.base.orthographicHeight = e;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function o(e) {
|
|
26
|
+
return (t) => {
|
|
27
|
+
let r = t.orthographicHeight;
|
|
28
|
+
r === void 0 ? e.mode = "perspective" : (n(r, "height"), e.mode = "orthographic", e.height = r, e.zoom = 1, e.left = e.right = e.top = e.bottom = void 0);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function s(e, t, r) {
|
|
32
|
+
let i = e.target[0] - e.position[0], a = e.target[1] - e.position[1], o = e.target[2] - e.position[2], s = Math.hypot(i, a, o);
|
|
33
|
+
n(s, "view direction"), i /= s, a /= s, o /= s;
|
|
34
|
+
let c = e.up[0], l = e.up[1], u = e.up[2];
|
|
35
|
+
n(Math.hypot(c, l, u), "up direction");
|
|
36
|
+
let d = a * u - o * l, f = o * c - i * u, p = i * l - a * c, m = Math.hypot(d, f, p);
|
|
37
|
+
m <= 1e-9 * Math.hypot(c, l, u) && (c = +(Math.abs(i) < .9), l = Math.abs(i) < .9 ? 0 : 1, u = 0, d = a * u - o * l, f = o * c - i * u, p = i * l - a * c, m = Math.hypot(d, f, p)), d /= m, f /= m, p /= m, c = f * o - p * a, l = p * i - d * o, u = d * a - f * i;
|
|
38
|
+
let h = Math.cos(e.roll), g = Math.sin(e.roll);
|
|
39
|
+
t.set([
|
|
40
|
+
d * h - c * g,
|
|
41
|
+
f * h - l * g,
|
|
42
|
+
p * h - u * g
|
|
43
|
+
]), r.set([
|
|
44
|
+
c * h + d * g,
|
|
45
|
+
l * h + f * g,
|
|
46
|
+
u * h + p * g
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
var c = (e, t) => e[0] * t[0] + e[1] * t[1] + e[2] * t[2], l = (e, t, n) => Math.max(t, Math.min(n, e)), u = (e, t) => {
|
|
50
|
+
let n = typeof e == "number" ? [e, e] : e;
|
|
51
|
+
if (n?.length !== 2 || !n.every(Number.isFinite)) throw RangeError(`Invalid orthographic ${t}; pass two finite numbers`);
|
|
52
|
+
return n;
|
|
53
|
+
}, d = class {
|
|
54
|
+
constructor(e, { screen: t = [.5, .5], deadZone: r = [.1, .1], softZone: i = [.8, .8], damping: a = 4, lookahead: o = 0, lookaheadSmoothing: s = 6, lookaheadVertical: c = !0 } = {}) {
|
|
55
|
+
this.onScreen = new Float64Array([.5, .5]), this.aimPoint = /* @__PURE__ */ new Float64Array(3), this.point = /* @__PURE__ */ new Float64Array(3), this.previous = /* @__PURE__ */ new Float64Array(3), this.velocity = /* @__PURE__ */ new Float64Array(3), this.offset = /* @__PURE__ */ new Float64Array(3), this.right = /* @__PURE__ */ new Float64Array(3), this.up = /* @__PURE__ */ new Float64Array(3), this.relative = /* @__PURE__ */ new Float64Array(3), this.started = !1, this.target = e, this.screen = [...u(t, "screen")], this.dead = [...u(r, "deadZone")], this.soft = [...u(i, "softZone")], this.rate = [...u(a, "damping")];
|
|
56
|
+
for (let e = 0; e < 2; e++) {
|
|
57
|
+
if (!(this.screen[e] >= 0 && this.screen[e] <= 1 && this.dead[e] >= 0 && this.soft[e] >= this.dead[e])) throw RangeError("Invalid orthographic zones; pass screen in 0..1 and nonnegative deadZone no larger than softZone");
|
|
58
|
+
n(this.rate[e], "damping");
|
|
59
|
+
}
|
|
60
|
+
if (!(o >= 0 && Number.isFinite(o))) throw RangeError("Invalid orthographic lookahead; pass finite seconds of 0 or more");
|
|
61
|
+
n(s, "lookahead smoothing"), this.lookahead = o, this.smoothing = s, this.vertical = c;
|
|
62
|
+
}
|
|
63
|
+
reset() {
|
|
64
|
+
this.started = !1, this.offset.fill(0), this.velocity.fill(0);
|
|
65
|
+
}
|
|
66
|
+
update(e, a, { aspect: o }) {
|
|
67
|
+
i(a), n(o, "aspect");
|
|
68
|
+
let u = r(e), { point: d, previous: f, velocity: p, offset: m, right: h, up: g, relative: _ } = this;
|
|
69
|
+
t(this.target, d), s(e, h, g);
|
|
70
|
+
let v = Math.exp(-this.smoothing * a);
|
|
71
|
+
for (let e = 0; e < 3; e++) this.started && a > 0 && (p[e] += ((d[e] - f[e]) / a - p[e]) * (1 - v)), f[e] = d[e];
|
|
72
|
+
let y = Math.hypot(...e.up), b = this.vertical ? 0 : c(p, e.up) / (y * y);
|
|
73
|
+
for (let t = 0; t < 3; t++) this.aimPoint[t] = d[t] + (p[t] - b * e.up[t]) * this.lookahead, _[t] = this.aimPoint[t] - e.position[t] - m[t];
|
|
74
|
+
let x = .5 + c(_, h) / (u * o), S = .5 - c(_, g) / u, C = [x, S], w = [this.screen[0], this.screen[1]];
|
|
75
|
+
if (this.started) for (let e = 0; e < 2; e++) {
|
|
76
|
+
let t = C[e] - this.screen[e], n = l(t, -this.dead[e] / 2, this.dead[e] / 2);
|
|
77
|
+
w[e] += l(n + (t - n) * Math.exp(-this.rate[e] * a), -this.soft[e] / 2, this.soft[e] / 2);
|
|
78
|
+
}
|
|
79
|
+
let T = (x - w[0]) * u * o, E = (w[1] - S) * u;
|
|
80
|
+
for (let t = 0; t < 3; t++) m[t] += T * h[t] + E * g[t], e.position[t] += m[t], e.target[t] += m[t];
|
|
81
|
+
this.onScreen.set(w), this.started = !0;
|
|
82
|
+
}
|
|
83
|
+
}, f = class {
|
|
84
|
+
constructor(e, { padding: t = .1, minHeight: r = .01, maxHeight: i = Infinity, damping: a = 4 } = {}) {
|
|
85
|
+
if (this.center = /* @__PURE__ */ new Float64Array(3), this.fits = !0, this.points = [], this.right = /* @__PURE__ */ new Float64Array(3), this.up = /* @__PURE__ */ new Float64Array(3), this.relative = /* @__PURE__ */ new Float64Array(3), this.goal = /* @__PURE__ */ new Float64Array(3), this.height = 0, this.started = !1, n(r, "minimum height"), n(a, "damping"), !(i >= r && t >= 0 && t < .5)) throw RangeError("Invalid orthographic group; pass maxHeight at least minHeight and padding from 0 to below 0.5");
|
|
86
|
+
this.padding = t, this.min = r, this.max = i, this.rate = a, this.members = e.map((e) => "target" in e ? { ...e } : { target: e });
|
|
87
|
+
}
|
|
88
|
+
reset() {
|
|
89
|
+
this.started = !1;
|
|
90
|
+
}
|
|
91
|
+
update(e, a, { aspect: o }) {
|
|
92
|
+
i(a), n(o, "aspect"), r(e);
|
|
93
|
+
let { goal: u, relative: d, right: f, up: p } = this;
|
|
94
|
+
s(e, f, p), u.fill(0);
|
|
95
|
+
let m = 0;
|
|
96
|
+
for (let e of this.members) {
|
|
97
|
+
let t = e.weight ?? 1, n = e.radius ?? 0;
|
|
98
|
+
if (!(t >= 0 && Number.isFinite(t) && n >= 0 && Number.isFinite(n))) throw RangeError("Invalid orthographic member; pass finite nonnegative radius and weight");
|
|
99
|
+
m += t;
|
|
100
|
+
}
|
|
101
|
+
if (!Number.isFinite(m)) throw RangeError("Invalid orthographic group weight; reduce weights to a finite sum");
|
|
102
|
+
if (!m) {
|
|
103
|
+
this.fits = !0, this.started = !1;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
for (let e = 0; e < this.members.length; e++) {
|
|
107
|
+
let n = this.members[e], r = n.weight ?? 1;
|
|
108
|
+
if (!r) continue;
|
|
109
|
+
let i = this.points[e] ??= /* @__PURE__ */ new Float64Array(3);
|
|
110
|
+
t(n.target, i);
|
|
111
|
+
for (let e = 0; e < 3; e++) u[e] += i[e] * (r / m);
|
|
112
|
+
}
|
|
113
|
+
let h = this.started ? Math.exp(-this.rate * a) : 0;
|
|
114
|
+
for (let e = 0; e < 3; e++) this.center[e] = u[e] + (this.center[e] - u[e]) * h;
|
|
115
|
+
let g = this.min;
|
|
116
|
+
for (let e = 0; e < this.members.length; e++) {
|
|
117
|
+
let t = this.members[e];
|
|
118
|
+
if (!(t.weight ?? 1)) continue;
|
|
119
|
+
for (let t = 0; t < 3; t++) d[t] = this.points[e][t] - this.center[t];
|
|
120
|
+
let n = t.radius ?? 0;
|
|
121
|
+
g = Math.max(g, 2 * (Math.abs(c(d, f)) + n) / (o * (1 - 2 * this.padding)), 2 * (Math.abs(c(d, p)) + n) / (1 - 2 * this.padding));
|
|
122
|
+
}
|
|
123
|
+
let _ = l(g, this.min, this.max);
|
|
124
|
+
this.height = _ + (this.height - _) * h, this.fits = g <= this.height * (1 + 1e-12);
|
|
125
|
+
for (let t = 0; t < 3; t++) e.position[t] += this.center[t] - e.target[t], e.target[t] = this.center[t];
|
|
126
|
+
e.orthographicHeight = this.height, this.started = !0;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
//#endregion
|
|
130
|
+
export { a as OrthographicCamera, d as OrthographicFraming, f as OrthographicGroupFraming, o as orthographicOutput };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { CameraPose, StageContext } from './brain.js';
|
|
2
|
+
/** Physical settings shared by the camera projection and depth of field. */
|
|
3
|
+
export interface PhysicalLensOptions {
|
|
4
|
+
/** Focal length in millimetres. Default 50. */
|
|
5
|
+
focalLength?: number;
|
|
6
|
+
/** Sensor size in millimetres on `sensorFit`'s axis. Default 36. */
|
|
7
|
+
filmGauge?: number;
|
|
8
|
+
/** Sensor axis; auto fits the longer image side. Default 'auto'. */
|
|
9
|
+
sensorFit?: 'auto' | 'horizontal' | 'vertical';
|
|
10
|
+
/** F-number, focal length divided by aperture diameter. Default 2.8. */
|
|
11
|
+
fStop?: number;
|
|
12
|
+
/** Focus distance in metres, beyond the focal length. Default 5. */
|
|
13
|
+
focusDistance?: number;
|
|
14
|
+
}
|
|
15
|
+
/** Outputs of {@link PhysicalLens.apply}; omitted targets are left alone. */
|
|
16
|
+
export interface PhysicalLensTargets {
|
|
17
|
+
/** Camera to receive the vertical field of view. */
|
|
18
|
+
camera?: {
|
|
19
|
+
fov: number;
|
|
20
|
+
};
|
|
21
|
+
/** DOF effect; sensor fit, focal length, aperture and focus are kept coherent. */
|
|
22
|
+
dof?: {
|
|
23
|
+
options: {
|
|
24
|
+
focalLength?: number;
|
|
25
|
+
filmGauge?: number;
|
|
26
|
+
sensorFit?: 'auto' | 'horizontal' | 'vertical';
|
|
27
|
+
aperture?: number;
|
|
28
|
+
focalDistance?: number;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** View width divided by height. Default 16/9. */
|
|
32
|
+
aspect?: number;
|
|
33
|
+
/** Override focus, for example with a blended pose's focusDistance. Default the lens's focusDistance. */
|
|
34
|
+
focusDistance?: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A physical lens stage: millimetres and f-number drive both FOV and DOF. Put it in `brain.stages` after focus tracking,
|
|
38
|
+
* then use `apply` to send its settings to DOF. The lens has no effect on exposure or shutter time.
|
|
39
|
+
*/
|
|
40
|
+
export declare class PhysicalLens implements Required<PhysicalLensOptions> {
|
|
41
|
+
focalLength: number;
|
|
42
|
+
filmGauge: number;
|
|
43
|
+
sensorFit: 'auto' | 'horizontal' | 'vertical';
|
|
44
|
+
fStop: number;
|
|
45
|
+
focusDistance: number;
|
|
46
|
+
/** @throws RangeError for nonphysical settings; see {@link PhysicalLensOptions}. */
|
|
47
|
+
constructor({ focalLength, filmGauge, sensorFit, fStop, focusDistance, }?: PhysicalLensOptions);
|
|
48
|
+
private check;
|
|
49
|
+
/** Vertical FOV in degrees for this sensor and view. @throws RangeError for invalid mutable settings or aspect. */
|
|
50
|
+
fov(aspect?: number): number;
|
|
51
|
+
/**
|
|
52
|
+
* Write FOV and focus to a pose, preserving focus set by an earlier tracker.
|
|
53
|
+
* @throws RangeError for invalid mutable settings, aspect or tracked focus.
|
|
54
|
+
*/
|
|
55
|
+
update(pose: CameraPose, _delta: number, { aspect }: StageContext): void;
|
|
56
|
+
/**
|
|
57
|
+
* Write coherent settings to the actual camera and DOF effect. Call after the brain updates when using tracked focus.
|
|
58
|
+
* @throws RangeError for invalid mutable settings, aspect or focus; outputs are unchanged on error.
|
|
59
|
+
*/
|
|
60
|
+
apply({ camera, dof, aspect, focusDistance }: PhysicalLensTargets): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/physical-lens.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
constructor({ focalLength: e = 50, filmGauge: t = 36, sensorFit: n = "auto", fStop: r = 2.8, focusDistance: i = 5 } = {}) {
|
|
4
|
+
this.focalLength = e, this.filmGauge = t, this.sensorFit = n, this.fStop = r, this.focusDistance = i, this.check(16 / 9, i);
|
|
5
|
+
}
|
|
6
|
+
check(e, t) {
|
|
7
|
+
if (![
|
|
8
|
+
this.focalLength,
|
|
9
|
+
this.filmGauge,
|
|
10
|
+
this.fStop,
|
|
11
|
+
t,
|
|
12
|
+
e
|
|
13
|
+
].every((e) => e > 0 && Number.isFinite(e)) || t <= this.focalLength / 1e3 || ![
|
|
14
|
+
"auto",
|
|
15
|
+
"horizontal",
|
|
16
|
+
"vertical"
|
|
17
|
+
].includes(this.sensorFit)) throw RangeError("Invalid physical lens; use positive finite settings, a valid sensorFit and focus beyond focal length. https://margoengine.com/llms/packages/cinematic.md");
|
|
18
|
+
}
|
|
19
|
+
fov(e = 16 / 9) {
|
|
20
|
+
this.check(e, this.focusDistance);
|
|
21
|
+
let t = this.sensorFit === "horizontal" || this.sensorFit === "auto" && e >= 1;
|
|
22
|
+
return 360 / Math.PI * Math.atan(this.filmGauge / (2 * this.focalLength) / (t ? e : 1));
|
|
23
|
+
}
|
|
24
|
+
update(e, t, { aspect: n }) {
|
|
25
|
+
let r = e.focusDistance || this.focusDistance;
|
|
26
|
+
this.check(n, r), e.fov = this.fov(n), e.focusDistance = r;
|
|
27
|
+
}
|
|
28
|
+
apply({ camera: e, dof: t, aspect: n = 16 / 9, focusDistance: r = this.focusDistance }) {
|
|
29
|
+
this.check(n, r);
|
|
30
|
+
let i = this.fov(n);
|
|
31
|
+
e && (e.fov = i), t && (t.options.focalLength = this.focalLength / 1e3, t.options.filmGauge = this.filmGauge, t.options.sensorFit = this.sensorFit, t.options.aperture = this.fStop, t.options.focalDistance = r);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { e as PhysicalLens };
|