@margoengine/cameras 0.1.0 → 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 -201
- package/NOTICE +4 -4
- package/README.md +676 -621
- package/dist/clearance.d.ts +92 -0
- package/dist/clearance.js +138 -0
- package/dist/hologram.js +3 -3
- package/dist/offaxis.js +3 -3
- package/dist/origin.js +4 -4
- package/dist/panini.js +3 -3
- package/dist/panorama.js +2 -2
- package/dist/shots.d.ts +41 -0
- package/dist/shots.js +31 -0
- package/dist/src-_OQ7cR69.js +3 -3
- package/dist/stereo.js +3 -3
- package/dist/wide-cube.js +3 -3
- package/package.json +107 -99
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Vec3 } from '@margoengine/core/extension';
|
|
2
|
+
/** An upright cylinder in the way of a view: a trunk, a crown, a hedge bush or a post. Metres, y up. */
|
|
3
|
+
export interface Occluder {
|
|
4
|
+
readonly x: number;
|
|
5
|
+
readonly z: number;
|
|
6
|
+
/** Its lowest and highest y (world heights, not heights above the ground). */
|
|
7
|
+
readonly bottom: number;
|
|
8
|
+
readonly top: number;
|
|
9
|
+
readonly radius: number;
|
|
10
|
+
/** The share of a crossing ray it stops, 0 to 1. Default 1 (solid). */
|
|
11
|
+
readonly opacity?: number;
|
|
12
|
+
}
|
|
13
|
+
/** What can stand between a camera and its subject. */
|
|
14
|
+
export interface SightScene {
|
|
15
|
+
/** Ground height at `(x, z)`. Default none (nothing is below ground). */
|
|
16
|
+
readonly ground?: (x: number, z: number) => number;
|
|
17
|
+
readonly occluders?: readonly Occluder[];
|
|
18
|
+
}
|
|
19
|
+
/** A camera and what it films, world coordinates. */
|
|
20
|
+
export interface SightView {
|
|
21
|
+
readonly position: Vec3;
|
|
22
|
+
readonly target: Vec3;
|
|
23
|
+
/** Vertical field of view, degrees. */
|
|
24
|
+
readonly fov: number;
|
|
25
|
+
/** Width over height. Default 16 / 9. */
|
|
26
|
+
readonly aspect?: number;
|
|
27
|
+
/** The subject: its foot `centre`, `width` across and `height`, metres. Default a 1 m box centred on `target`. */
|
|
28
|
+
readonly subject?: {
|
|
29
|
+
readonly centre: Vec3;
|
|
30
|
+
readonly width: number;
|
|
31
|
+
readonly height: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** What {@link sightClearance} accepts as clear. */
|
|
35
|
+
export interface ClearanceLimits {
|
|
36
|
+
/** Least share of the subject seen, 0 to 1. Default 0.5. */
|
|
37
|
+
readonly subject?: number;
|
|
38
|
+
/** Foreground: nearer than this share of the distance to the subject, 0 to 1. Default 0.4. */
|
|
39
|
+
readonly near?: number;
|
|
40
|
+
/** Most of the frame the foreground occluders may cover, 0 to 1. Default 0.15. */
|
|
41
|
+
readonly foreground?: number;
|
|
42
|
+
/** Most of the frame's middle (half its width and height) they may cover, 0 to 1. Default 0.05. */
|
|
43
|
+
readonly centre?: number;
|
|
44
|
+
/** No occluder in frame nearer the lens than this, metres. Default 4. */
|
|
45
|
+
readonly lens?: number;
|
|
46
|
+
}
|
|
47
|
+
/** The measures of one view. */
|
|
48
|
+
export interface Clearance {
|
|
49
|
+
/** Share of the subject seen past the ground and the occluders, 0 to 1. */
|
|
50
|
+
readonly subject: number;
|
|
51
|
+
/** Share of the frame covered by foreground occluders, 0 to 1. */
|
|
52
|
+
readonly foreground: number;
|
|
53
|
+
/** The same for the frame's middle. */
|
|
54
|
+
readonly centre: number;
|
|
55
|
+
/** Distance to the nearest occluder in frame within the foreground or the lens limit, metres (`Infinity` for none). */
|
|
56
|
+
readonly lens: number;
|
|
57
|
+
/** Whether every measure is within the limits. */
|
|
58
|
+
readonly clear: boolean;
|
|
59
|
+
/** How far outside the limits the view is: 0 when clear, larger when worse. */
|
|
60
|
+
readonly penalty: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Measures what a camera sees of its subject past the ground and the occluders, and whether something covers the lens or
|
|
64
|
+
* the foreground. A long lens low over rising ground scores `subject` 0; a trunk a few metres off raises `centre`.
|
|
65
|
+
* @throws RangeError for a view with no direction, a field of view outside (0, 180) or an
|
|
66
|
+
* occluder with a radius or height range that is not positive.
|
|
67
|
+
* @example
|
|
68
|
+
* const seen = sightClearance(
|
|
69
|
+
* { position: [0, 2, 100], target: [0, 2, 0], fov: 20 },
|
|
70
|
+
* { ground: () => 0, occluders: [{ x: 0, z: 92, bottom: 0, top: 15, radius: 0.6 }] },
|
|
71
|
+
* );
|
|
72
|
+
* if (!seen.clear) console.log(seen.centre, seen.subject);
|
|
73
|
+
*/
|
|
74
|
+
export declare function sightClearance(view: SightView, scene?: SightScene, limits?: ClearanceLimits): Clearance;
|
|
75
|
+
/** The pick of {@link clearestShot}. */
|
|
76
|
+
export interface ClearShot<T> {
|
|
77
|
+
readonly choice: T;
|
|
78
|
+
/** Its worst view's measures. */
|
|
79
|
+
readonly clearance: Clearance;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The first camera choice, in the order given (best first: a turn before a lift), whose every view is clear; when none
|
|
83
|
+
* is, the one whose worst view is least bad. A moving shot passes its start, middle and end as its views.
|
|
84
|
+
* @throws RangeError for no choices or a choice with no views.
|
|
85
|
+
* @example
|
|
86
|
+
* const lifts = [1.7, 3, 6, 12];
|
|
87
|
+
* const best = clearestShot(lifts, (h) => [{ position: [0, h, 100], target: [0, 2, 0], fov: 20 }], {
|
|
88
|
+
* ground: (x, z) => (Math.abs(z - 50) < 10 ? 4 : 0),
|
|
89
|
+
* });
|
|
90
|
+
* console.log(best.choice, best.clearance.clear); // the lowest height that sees over the bank
|
|
91
|
+
*/
|
|
92
|
+
export declare function clearestShot<T>(choices: Iterable<T>, views: (choice: T) => readonly SightView[], scene?: SightScene, limits?: ClearanceLimits): ClearShot<T>;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { n as e } from "./errors-Cp7bu2gW.js";
|
|
2
|
+
//#region src/clearance.ts
|
|
3
|
+
var t = 32, n = 18, r = (t, n) => {
|
|
4
|
+
if (!t) throw e(`Camera clearance: ${n}`, "camera-clearance");
|
|
5
|
+
}, i = (e) => e?.length === 3 && [
|
|
6
|
+
e[0],
|
|
7
|
+
e[1],
|
|
8
|
+
e[2]
|
|
9
|
+
].every(Number.isFinite);
|
|
10
|
+
function a(e, t, n) {
|
|
11
|
+
let r = e[0] - n.x, i = e[2] - n.z, a = t[0] * t[0] + t[2] * t[2], o = r * t[0] + i * t[2], s = r * r + i * i - n.radius * n.radius, c = 0, l = Infinity;
|
|
12
|
+
if (a < 1e-12) {
|
|
13
|
+
if (s > 0) return Infinity;
|
|
14
|
+
} else {
|
|
15
|
+
let e = o * o - a * s;
|
|
16
|
+
if (e <= 0) return Infinity;
|
|
17
|
+
let t = Math.sqrt(e);
|
|
18
|
+
c = Math.max(0, (-o - t) / a), l = (-o + t) / a;
|
|
19
|
+
}
|
|
20
|
+
if (Math.abs(t[1]) < 1e-12) {
|
|
21
|
+
if (e[1] < n.bottom || e[1] > n.top) return Infinity;
|
|
22
|
+
} else {
|
|
23
|
+
let r = (n.bottom - e[1]) / t[1], i = (n.top - e[1]) / t[1];
|
|
24
|
+
c = Math.max(c, Math.min(r, i)), l = Math.min(l, Math.max(r, i));
|
|
25
|
+
}
|
|
26
|
+
return c < l ? c : Infinity;
|
|
27
|
+
}
|
|
28
|
+
function o(e, t, n, r) {
|
|
29
|
+
for (let i = .5; i < n; i += Math.max(.5, i * .01)) if (e[1] + t[1] * i < r(e[0] + t[0] * i, e[2] + t[2] * i)) return !0;
|
|
30
|
+
return !1;
|
|
31
|
+
}
|
|
32
|
+
function s(e, s = {}, c = {}) {
|
|
33
|
+
let { position: l, target: u, fov: d, aspect: f = 16 / 9 } = e;
|
|
34
|
+
r(i(l) && i(u), "position and target must be three finite numbers"), r(d > 0 && d < 180 && f > 0, "fov must be inside (0, 180) degrees and aspect above 0");
|
|
35
|
+
let p = {
|
|
36
|
+
subject: c.subject ?? .5,
|
|
37
|
+
near: c.near ?? .4,
|
|
38
|
+
foreground: c.foreground ?? .15,
|
|
39
|
+
centre: c.centre ?? .05,
|
|
40
|
+
lens: c.lens ?? 4
|
|
41
|
+
}, m = [
|
|
42
|
+
u[0] - l[0],
|
|
43
|
+
u[1] - l[1],
|
|
44
|
+
u[2] - l[2]
|
|
45
|
+
], h = Math.hypot(m[0], m[1], m[2]), g = Math.hypot(m[0], m[2]);
|
|
46
|
+
r(g > 1e-6, "the view must not be empty or straight up or down"), m[0] /= h, m[1] /= h, m[2] /= h;
|
|
47
|
+
let _ = [
|
|
48
|
+
-m[2] * (h / g),
|
|
49
|
+
0,
|
|
50
|
+
m[0] * (h / g)
|
|
51
|
+
], v = [
|
|
52
|
+
_[1] * m[2] - _[2] * m[1],
|
|
53
|
+
_[2] * m[0] - _[0] * m[2],
|
|
54
|
+
_[0] * m[1] - _[1] * m[0]
|
|
55
|
+
], y = Math.tan(d * Math.PI / 360), b = y * f, x = e.subject ?? {
|
|
56
|
+
centre: [
|
|
57
|
+
u[0],
|
|
58
|
+
u[1] - .5,
|
|
59
|
+
u[2]
|
|
60
|
+
],
|
|
61
|
+
width: 1,
|
|
62
|
+
height: 1
|
|
63
|
+
}, S = Math.hypot(x.centre[0] - l[0], x.centre[2] - l[2]), C = Math.max(0, S - x.width / 2), w = Math.atan(b), T = m[0] * (h / g), E = m[2] * (h / g), D = [];
|
|
64
|
+
for (let e of s.occluders ?? []) {
|
|
65
|
+
r(e.radius > 0 && e.top > e.bottom, "an occluder needs a radius above 0 and top above bottom");
|
|
66
|
+
let t = e.x - l[0], n = e.z - l[2], i = Math.hypot(t, n);
|
|
67
|
+
i - e.radius > Math.max(h, S) + x.width || i > e.radius && Math.abs(Math.atan2(t * E - n * T, t * T + n * E)) > w + Math.asin(e.radius / i) + .02 || D.push(e);
|
|
68
|
+
}
|
|
69
|
+
let O = p.near * S, k = Math.max(O, p.lens), A = D.filter((e) => Math.hypot(e.x - l[0], e.z - l[2]) - e.radius < k), j = 0, M = 0, N = 0, P = Infinity;
|
|
70
|
+
for (let e = 0; e < n; e++) for (let r = 0; r < t; r++) {
|
|
71
|
+
let i = ((r + .5) / t * 2 - 1) * b, c = ((e + .5) / n * 2 - 1) * y, u = [
|
|
72
|
+
m[0] + _[0] * i + v[0] * c,
|
|
73
|
+
m[1] + _[1] * i + v[1] * c,
|
|
74
|
+
m[2] + _[2] * i + v[2] * c
|
|
75
|
+
], d = Math.hypot(u[0], u[1], u[2]);
|
|
76
|
+
u[0] /= d, u[1] /= d, u[2] /= d;
|
|
77
|
+
let f = 1;
|
|
78
|
+
for (let e of A) {
|
|
79
|
+
let t = a(l, u, e);
|
|
80
|
+
t >= k || s.ground && t < P && o(l, u, t, s.ground) || (P = Math.min(P, t), t < O && (f *= 1 - (e.opacity ?? 1)));
|
|
81
|
+
}
|
|
82
|
+
j += 1 - f, Math.abs((r + .5) / t - .5) < .25 && Math.abs((e + .5) / n - .5) < .25 && (M += 1 - f, N++);
|
|
83
|
+
}
|
|
84
|
+
let F = [
|
|
85
|
+
_[0],
|
|
86
|
+
0,
|
|
87
|
+
_[2]
|
|
88
|
+
], I = 0, L = 0;
|
|
89
|
+
for (let e of [
|
|
90
|
+
.05,
|
|
91
|
+
.5,
|
|
92
|
+
.95
|
|
93
|
+
]) for (let t of [
|
|
94
|
+
-.4,
|
|
95
|
+
-.2,
|
|
96
|
+
0,
|
|
97
|
+
.2,
|
|
98
|
+
.4
|
|
99
|
+
]) {
|
|
100
|
+
let n = x.centre[0] + F[0] * t * x.width, r = x.centre[2] + F[2] * t * x.width, i = Math.max(x.centre[1], s.ground?.(n, r) ?? x.centre[1]), c = [
|
|
101
|
+
n - l[0],
|
|
102
|
+
i + e * x.height - l[1],
|
|
103
|
+
r - l[2]
|
|
104
|
+
], u = Math.hypot(c[0], c[1], c[2]);
|
|
105
|
+
if (L++, u < 1e-6 || (c[0] /= u, c[1] /= u, c[2] /= u, s.ground && o(l, c, u - Math.max(1, u * .01), s.ground))) continue;
|
|
106
|
+
let d = u * C / Math.max(S, 1e-6), f = 1;
|
|
107
|
+
for (let e of D) a(l, c, e) < d && (f *= 1 - (e.opacity ?? 1));
|
|
108
|
+
I += f;
|
|
109
|
+
}
|
|
110
|
+
let R = I / L, z = j / 576, B = M / N, V = Math.max(0, p.subject - R) * 4 + Math.max(0, z - p.foreground) * 2 + Math.max(0, B - p.centre) * 4 + (P < p.lens ? 1 + (p.lens - P) / p.lens : 0);
|
|
111
|
+
return {
|
|
112
|
+
subject: R,
|
|
113
|
+
foreground: z,
|
|
114
|
+
centre: B,
|
|
115
|
+
lens: P,
|
|
116
|
+
clear: V === 0,
|
|
117
|
+
penalty: V
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function c(e, t, n = {}, i = {}) {
|
|
121
|
+
let a;
|
|
122
|
+
for (let o of e) {
|
|
123
|
+
let e;
|
|
124
|
+
for (let r of t(o)) {
|
|
125
|
+
let t = s(r, n, i);
|
|
126
|
+
if ((!e || t.penalty > e.penalty) && (e = t), a && e.penalty >= a.clearance.penalty) break;
|
|
127
|
+
}
|
|
128
|
+
r(e !== void 0, "every choice needs at least one view");
|
|
129
|
+
let c = e;
|
|
130
|
+
if ((!a || c.penalty < a.clearance.penalty) && (a = {
|
|
131
|
+
choice: o,
|
|
132
|
+
clearance: c
|
|
133
|
+
}), a.clearance.clear) break;
|
|
134
|
+
}
|
|
135
|
+
return r(a !== void 0, "give at least one choice"), a;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { c as clearestShot, s as sightClearance };
|
package/dist/hologram.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
-
const a=(engine,version="
|
|
3
|
+
const a=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
4
|
import { n as e } from "./layers-CkdgcqTK.js";
|
|
5
5
|
import { n as t, r as n, t as r } from "./gpu-BRxrrZK3.js";
|
|
6
6
|
import { Camera as i, engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
@@ -86,7 +86,7 @@ var c = "; see https://margoengine.com/errors#camera-hologram", l = Object.freez
|
|
|
86
86
|
let l=textureSampleLevel(left,linearSampler,q,0.0);let r=textureSampleLevel(right,linearSampler,q,0.0);
|
|
87
87
|
if(side==0u){return a;} if(side==1u){return b;} if(side==2u){return l;} return r;
|
|
88
88
|
}`, p = class r {
|
|
89
|
-
static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("
|
|
89
|
+
static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
90
90
|
return new r(e, t);
|
|
91
91
|
}
|
|
92
92
|
constructor(e, t = {}) {
|
package/dist/offaxis.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
4
|
import { t as e } from "./errors-Cp7bu2gW.js";
|
|
@@ -42,7 +42,7 @@ function a(e, a, o) {
|
|
|
42
42
|
distance: g
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
var o = class t {coreRequirement=__margoCoreRequirement("
|
|
45
|
+
var o = class t {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
46
46
|
constructor(e, t = [
|
|
47
47
|
0,
|
|
48
48
|
0,
|
|
@@ -50,7 +50,7 @@ var o = class t {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url)
|
|
|
50
50
|
]) {
|
|
51
51
|
this.screen = e, this.name = "offaxis", this.eye = t;
|
|
52
52
|
}
|
|
53
|
-
static attach(e, n, r) {__margoAssertCore(e,__margoCoreRequirement("
|
|
53
|
+
static attach(e, n, r) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
54
54
|
let i = new t(n, r);
|
|
55
55
|
return e.use(i), i;
|
|
56
56
|
}
|
package/dist/origin.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
-
const t=(engine,version="
|
|
3
|
+
const t=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
4
|
import { t as e } from "./errors-Cp7bu2gW.js";
|
|
5
5
|
import { engineRuntime as __margoRuntime, meshRuntime as n } from "@margoengine/core/extension";
|
|
6
6
|
//#region src/origin.ts
|
|
7
|
-
var r = class r {coreRequirement=__margoCoreRequirement("
|
|
8
|
-
static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("
|
|
7
|
+
var r = class r {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
8
|
+
static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
9
9
|
let n = new r(t);
|
|
10
10
|
return e.use(n), n;
|
|
11
11
|
}
|
package/dist/panini.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
4
|
import { t as e } from "./errors-Cp7bu2gW.js";
|
|
@@ -109,7 +109,7 @@ const HALF_PI=1.5707963267948966;
|
|
|
109
109
|
let q=s/w.b.zw;
|
|
110
110
|
if (abs(q.x)>1.0000001||abs(q.y)>1.0000001) {return vec4f(0,0,0,1);}
|
|
111
111
|
return textureSampleLevel(frame,smp,vec2f(q.x*0.5+0.5,0.5-q.y*0.5),0);
|
|
112
|
-
}`, m = class a {coreRequirement=__margoCoreRequirement("
|
|
112
|
+
}`, m = class a {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
113
113
|
constructor(e = {}) {
|
|
114
114
|
this.options = e, this.name = "wide-angle", this.stacked = !1, this.disposed = !1, this.key = "", this.mapKey = "", this.values = /* @__PURE__ */ new Float32Array(8), this.attachment = {
|
|
115
115
|
view: void 0,
|
|
@@ -117,7 +117,7 @@ const HALF_PI=1.5707963267948966;
|
|
|
117
117
|
storeOp: "store"
|
|
118
118
|
}, this.descriptor = { colorAttachments: [this.attachment] }, this.map(60, 1);
|
|
119
119
|
}
|
|
120
|
-
static async attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("
|
|
120
|
+
static async attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
121
121
|
let { PostStack: n } = await import("@margoengine/post"), r = new a(t);
|
|
122
122
|
return r.stack = n.join(e, r), r;
|
|
123
123
|
}
|
package/dist/panorama.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
-
const r=(engine,version="
|
|
3
|
+
const r=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
4
|
import { n as e, r as t, t as n } from "./gpu-BRxrrZK3.js";
|
|
5
5
|
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
6
6
|
import { MargoError as i } from "@margoengine/math/errors";
|
package/dist/shots.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Camera, Vec3 } from '@margoengine/core/extension';
|
|
2
|
+
/** One framed view: the eye sits at `target + offset * max(1, fit * height / width)`. */
|
|
3
|
+
export interface Shot {
|
|
4
|
+
/** Point the camera looks at, in world units. Read on every update, so it may be changed in place. */
|
|
5
|
+
target: Vec3;
|
|
6
|
+
/** Eye position relative to `target` for a landscape view. */
|
|
7
|
+
offset: Vec3;
|
|
8
|
+
/** How much a portrait view backs away: the offset is scaled by max(1, fit * height / width). Default 1. */
|
|
9
|
+
fit?: number;
|
|
10
|
+
/** Vertical field of view in degrees. Set on the camera only when both shots give one. */
|
|
11
|
+
fov?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Options for {@link ShotBlend}. */
|
|
14
|
+
export interface ShotBlendOptions {
|
|
15
|
+
/** Exponential easing rate per second; 15 settles to 0.001 in about 0.46 s. Default 15. */
|
|
16
|
+
rate?: number;
|
|
17
|
+
/** Jumps straight to the goal while `matches` is true, as for `matchMedia('(prefers-reduced-motion: reduce)')`. */
|
|
18
|
+
still?: {
|
|
19
|
+
readonly matches: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Frames a camera at, or on the way between, two {@link Shot}s. */
|
|
23
|
+
export declare class ShotBlend {
|
|
24
|
+
#private;
|
|
25
|
+
/** Shot at blend 0. */
|
|
26
|
+
readonly from: Shot;
|
|
27
|
+
/** Shot at blend 1. */
|
|
28
|
+
readonly to: Shot;
|
|
29
|
+
/** Where the blend is heading: 0 for `from`, 1 for `to`, or any value between. Default 0. */
|
|
30
|
+
goal: number;
|
|
31
|
+
/** The current blend, which eases toward {@link goal} on each update. Starts at 0. */
|
|
32
|
+
blend: number;
|
|
33
|
+
constructor(camera: Camera, from: Shot, to: Shot, { rate, still }?: ShotBlendOptions);
|
|
34
|
+
/** True while the blend has not reached its goal. */
|
|
35
|
+
get moving(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Eases the blend toward the goal over `delta` seconds and frames the camera for a `width` x `height` view. Returns
|
|
38
|
+
* true while the blend is still moving, so a page that renders on demand knows to draw another frame.
|
|
39
|
+
*/
|
|
40
|
+
update(delta: number, width: number, height: number): boolean;
|
|
41
|
+
}
|
package/dist/shots.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { n as e } from "./errors-Cp7bu2gW.js";
|
|
2
|
+
import { lerp as t } from "@margoengine/math/mathutils";
|
|
3
|
+
//#region src/shots.ts
|
|
4
|
+
var n = class {
|
|
5
|
+
#e;
|
|
6
|
+
#t;
|
|
7
|
+
#n;
|
|
8
|
+
constructor(t, n, r, { rate: i = 15, still: a } = {}) {
|
|
9
|
+
if (this.goal = 0, this.blend = 0, !(i > 0) || !Number.isFinite(i)) throw e("ShotBlend rate must be a finite number above 0", "cameras");
|
|
10
|
+
this.#e = t, this.from = n, this.to = r, this.#t = i, this.#n = a;
|
|
11
|
+
}
|
|
12
|
+
get moving() {
|
|
13
|
+
return this.blend !== this.goal;
|
|
14
|
+
}
|
|
15
|
+
update(n, r, i) {
|
|
16
|
+
if (!(n >= 0) || !Number.isFinite(n)) throw e("ShotBlend delta must be a finite number of seconds >= 0", "cameras");
|
|
17
|
+
if (!(r > 0 && i > 0)) throw e("ShotBlend width and height must be above 0", "cameras");
|
|
18
|
+
let { from: a, to: o, goal: s } = this, c = this.blend = this.#n?.matches || Math.abs(this.blend - s) < .001 ? s : t(s, this.blend, Math.exp(-n * this.#t)), l = Math.max(1, t(a.fit ?? 1, o.fit ?? 1, c) * i / r), u = (e) => t(a.target[e], o.target[e], c), d = [
|
|
19
|
+
u(0),
|
|
20
|
+
u(1),
|
|
21
|
+
u(2)
|
|
22
|
+
], f = (e) => d[e] + l * t(a.offset[e], o.offset[e], c);
|
|
23
|
+
return this.#e.target = d, this.#e.position = [
|
|
24
|
+
f(0),
|
|
25
|
+
f(1),
|
|
26
|
+
f(2)
|
|
27
|
+
], a.fov !== void 0 && o.fov !== void 0 && (this.#e.fov = t(a.fov, o.fov, c)), this.moving;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { n as ShotBlend };
|
package/dist/src-_OQ7cR69.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
4
|
import { n as e, t } from "./errors-Cp7bu2gW.js";
|
|
@@ -127,8 +127,8 @@ function d(e, t, n, r = n) {
|
|
|
127
127
|
});
|
|
128
128
|
return i;
|
|
129
129
|
}
|
|
130
|
-
var f = 1e-9, p = class n {coreRequirement=__margoCoreRequirement("
|
|
131
|
-
static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("
|
|
130
|
+
var f = 1e-9, p = class n {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
131
|
+
static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
132
132
|
let r = new n(t);
|
|
133
133
|
return e.use(r), r;
|
|
134
134
|
}
|
package/dist/stereo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
-
const a=(engine,version="
|
|
3
|
+
const a=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
4
|
import { n as e } from "./layers-CkdgcqTK.js";
|
|
5
5
|
import { n as t, r as n, t as r } from "./gpu-BRxrrZK3.js";
|
|
6
6
|
import { Camera as i, engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
@@ -64,7 +64,7 @@ fn srgb(c:vec3f)->vec3f {let x=clamp(c,vec3f(0),vec3f(1));return select(1.055*po
|
|
|
64
64
|
}
|
|
65
65
|
return select(l,r,eye>0.5);
|
|
66
66
|
}`, u = class r {
|
|
67
|
-
static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("
|
|
67
|
+
static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
68
68
|
return new r(e, t);
|
|
69
69
|
}
|
|
70
70
|
constructor(e, t = {}) {
|
package/dist/wide-cube.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
3
|
|
|
4
4
|
import { t as e } from "./errors-Cp7bu2gW.js";
|
|
@@ -93,7 +93,7 @@ fn shown(c:vec3f)->vec4f {return vec4f(${e ? "c" : "toDisplay(c)"},1);}
|
|
|
93
93
|
}
|
|
94
94
|
let world=w.right.xyz*dir.x+w.up.xyz*dir.y+w.forward.xyz*dir.z;
|
|
95
95
|
return shown(textureSampleLevel(cube,smp,world,0).rgb);
|
|
96
|
-
}`, g = class a {coreRequirement=__margoCoreRequirement("
|
|
96
|
+
}`, g = class a {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
97
97
|
constructor(e = {}) {
|
|
98
98
|
this.options = e, this.name = "wide-angle-cube", this.ownsCube = !1, this.stacked = !1, this.disposed = !1, this.key = "", this.mapKey = "", this.values = /* @__PURE__ */ new Float32Array(20), this.attachment = {
|
|
99
99
|
view: void 0,
|
|
@@ -101,7 +101,7 @@ fn shown(c:vec3f)->vec4f {return vec4f(${e ? "c" : "toDisplay(c)"},1);}
|
|
|
101
101
|
storeOp: "store"
|
|
102
102
|
}, this.descriptor = { colorAttachments: [this.attachment] }, this.cube = e.cube, this.facesPerFrame = e.facesPerFrame ?? 6, this.map(1);
|
|
103
103
|
}
|
|
104
|
-
static async attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("
|
|
104
|
+
static async attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
105
105
|
let [{ PostStack: n }, { CubeCamera: r }] = await Promise.all([import("@margoengine/post"), import("@margoengine/environment/cube-camera")]), i = new a(t);
|
|
106
106
|
i.cube || (i.cube = r.attach(e, {
|
|
107
107
|
size: t.size ?? 512,
|