@uxfront/scene 0.1.0 → 0.3.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.
@@ -0,0 +1,171 @@
1
+ import { CARD_NAME } from "./geometry.js";
2
+ //#region src/formations/stack/art.ts
3
+ /**
4
+ * What a shape does while the formation plays. Every card fills its form in on
5
+ * the same beat, because every card holds the same component: the `typing`
6
+ * line grows as the email is typed, with its `caret`, the toggle switches on
7
+ * (its `track` lights up and its `knob` slides `KNOB_TRAVEL` to the right) and
8
+ * the `button` is pressed.
9
+ */
10
+ const CARD_ROLE = {
11
+ still: 0,
12
+ knob: 1,
13
+ track: 2,
14
+ button: 3,
15
+ typing: 4,
16
+ caret: 5
17
+ };
18
+ /** How far a toggle's knob slides when it switches on. */
19
+ const KNOB_TRAVEL = .08;
20
+ /** The email being typed: where the text starts, and how long it gets. */
21
+ const TYPED_FROM = [-.53, -.1];
22
+ const TYPED_LENGTH = .46;
23
+ const FIELD_H = .052;
24
+ const ACTIONS_Y = -.36;
25
+ const TOGGLE = [-.5, ACTIONS_Y];
26
+ const CANCEL = [.2, ACTIONS_Y];
27
+ const SUBMIT = [.47, ACTIONS_Y];
28
+ const BUTTON_H = [.12, .058];
29
+ /** A labelled text field: the label above, the input and its placeholder. */
30
+ const field = (x, y, halfWidth, placeholder) => [
31
+ {
32
+ kind: "seg",
33
+ a: [x - halfWidth + .01, y + .1],
34
+ b: [x - halfWidth + .15, y + .1],
35
+ bright: .55
36
+ },
37
+ {
38
+ kind: "rrect",
39
+ c: [x, y],
40
+ h: [halfWidth, FIELD_H],
41
+ r: .03,
42
+ bright: .7
43
+ },
44
+ ...placeholder > 0 ? [{
45
+ kind: "seg",
46
+ a: [x - halfWidth + .05, y],
47
+ b: [x - halfWidth + .05 + placeholder, y],
48
+ bright: .25
49
+ }] : []
50
+ ];
51
+ /**
52
+ * Unframework: one component, the same on every card. A sign-up form, with a
53
+ * header (the part that shows above the card in front), first and last name,
54
+ * an email, a "remember me" toggle, and cancel and submit buttons.
55
+ */
56
+ const SIGN_UP_FORM_ART = [
57
+ {
58
+ kind: "circle",
59
+ c: [-.55, .415],
60
+ r: .045,
61
+ bright: 1
62
+ },
63
+ {
64
+ kind: "disc",
65
+ c: [-.55, .415],
66
+ r: .016,
67
+ bright: .9
68
+ },
69
+ {
70
+ kind: "seg",
71
+ a: [CARD_NAME[0], .385],
72
+ b: [-.12, .385],
73
+ bright: .45
74
+ },
75
+ {
76
+ kind: "disc",
77
+ c: [.56, .415],
78
+ r: .02,
79
+ bright: 1.2
80
+ },
81
+ {
82
+ kind: "seg",
83
+ a: [-.6, .3],
84
+ b: [.6, .3],
85
+ bright: .25
86
+ },
87
+ ...field(-.29, .12, .27, .16),
88
+ ...field(.29, .12, .27, .12),
89
+ ...field(0, -.1, .58, 0),
90
+ {
91
+ kind: "seg",
92
+ a: TYPED_FROM,
93
+ b: [TYPED_FROM[0] + TYPED_LENGTH, TYPED_FROM[1]],
94
+ bright: .9,
95
+ role: CARD_ROLE.typing
96
+ },
97
+ {
98
+ kind: "seg",
99
+ a: [TYPED_FROM[0] + .012, TYPED_FROM[1] - .03],
100
+ b: [TYPED_FROM[0] + .012, TYPED_FROM[1] + .03],
101
+ bright: 1.2,
102
+ role: CARD_ROLE.caret
103
+ },
104
+ {
105
+ kind: "fill",
106
+ c: TOGGLE,
107
+ h: [.085, .045],
108
+ r: .045,
109
+ bright: .3,
110
+ role: CARD_ROLE.track
111
+ },
112
+ {
113
+ kind: "rrect",
114
+ c: TOGGLE,
115
+ h: [.085, .045],
116
+ r: .045,
117
+ bright: .8,
118
+ role: CARD_ROLE.track
119
+ },
120
+ {
121
+ kind: "disc",
122
+ c: [TOGGLE[0] - KNOB_TRAVEL / 2, TOGGLE[1]],
123
+ r: .03,
124
+ bright: 1.3,
125
+ role: CARD_ROLE.knob
126
+ },
127
+ {
128
+ kind: "seg",
129
+ a: [-.38, ACTIONS_Y],
130
+ b: [-.14, ACTIONS_Y],
131
+ bright: .55
132
+ },
133
+ {
134
+ kind: "rrect",
135
+ c: CANCEL,
136
+ h: BUTTON_H,
137
+ r: BUTTON_H[1],
138
+ bright: .6
139
+ },
140
+ {
141
+ kind: "seg",
142
+ a: [CANCEL[0] - .05, ACTIONS_Y],
143
+ b: [CANCEL[0] + .05, ACTIONS_Y],
144
+ bright: .5
145
+ },
146
+ {
147
+ kind: "fill",
148
+ c: SUBMIT,
149
+ h: BUTTON_H,
150
+ r: BUTTON_H[1],
151
+ bright: .35,
152
+ role: CARD_ROLE.button
153
+ },
154
+ {
155
+ kind: "rrect",
156
+ c: SUBMIT,
157
+ h: BUTTON_H,
158
+ r: BUTTON_H[1],
159
+ bright: 1.1,
160
+ role: CARD_ROLE.button
161
+ },
162
+ {
163
+ kind: "seg",
164
+ a: [SUBMIT[0] - .05, ACTIONS_Y],
165
+ b: [SUBMIT[0] + .05, ACTIONS_Y],
166
+ bright: 1,
167
+ role: CARD_ROLE.button
168
+ }
169
+ ];
170
+ //#endregion
171
+ export { CARD_ROLE, KNOB_TRAVEL, SIGN_UP_FORM_ART };
@@ -0,0 +1,10 @@
1
+ import { Vec2 } from "../../gl/math.js";
2
+ //#region src/formations/stack/geometry.d.ts
3
+ /** Half size of a card, in art units (see `art.ts`). */
4
+ export declare const CARD: Vec2;
5
+ /**
6
+ * Where the card's label goes, in its header, in art units: anchors `stack:0`
7
+ * to `stack:6` sit just before it, so the artwork leaves the spot empty.
8
+ */
9
+ export declare const CARD_NAME: Vec2;
10
+ //#endregion
@@ -0,0 +1,48 @@
1
+ import { lerp, smoothstep } from "../../gl/math.js";
2
+ import "../prism/geometry.js";
3
+ //#region src/formations/stack/geometry.ts
4
+ /** One card per rail of the prism, front to back in its order: rail `i` flows into card `i`. */
5
+ const CARDS = 7;
6
+ /** Half size of a card, in art units (see `art.ts`). */
7
+ const CARD = [.64, .52];
8
+ /** Corner radius of a card's border, in art units. */
9
+ const CARD_CORNER = .06;
10
+ /**
11
+ * Where the card's label goes, in its header, in art units: anchors `stack:0`
12
+ * to `stack:6` sit just before it, so the artwork leaves the spot empty.
13
+ */
14
+ const CARD_NAME = [-.46, .44];
15
+ /** World units per art unit. */
16
+ const CARD_SCALE = 1.4;
17
+ /** Centre of the front card, the first one dealt. */
18
+ const FRONT = [
19
+ 0,
20
+ -.4,
21
+ 0
22
+ ];
23
+ /**
24
+ * From one card to the card behind it: up and to the right at about 45°, and
25
+ * away, so each card peeks out above and beside the one in front of it.
26
+ */
27
+ const BEHIND = [
28
+ .33,
29
+ .28,
30
+ -.5
31
+ ];
32
+ /** Cards are dealt one after another as the chapter is read, like the prism's rails. */
33
+ const cardReach = (index, progress) => smoothstep(index * .08, index * .08 + .45, progress);
34
+ /** Share of the dealing that happens while the chapter scrolls in. */
35
+ const CARD_APPROACH = .35;
36
+ /** Deal progress: starts with the morph into the formation, not once it's held. */
37
+ const cardProgress = (approach, local) => approach < 1 ? approach * CARD_APPROACH : lerp(CARD_APPROACH, 1, local);
38
+ /** The stack floats. The engine clock only runs with motion on. */
39
+ const stackBob = (time) => Math.sin(time * .7) * .03;
40
+ /** Where the point `q` (card-local, in art units) of a card at rest is in the world. */
41
+ function cardPoint(index, q, time, out) {
42
+ out[0] = FRONT[0] + index * BEHIND[0] + q[0] * CARD_SCALE;
43
+ out[1] = FRONT[1] + index * BEHIND[1] + q[1] * CARD_SCALE + stackBob(time);
44
+ out[2] = FRONT[2] + index * BEHIND[2];
45
+ return out;
46
+ }
47
+ //#endregion
48
+ export { BEHIND, CARD, CARDS, CARD_APPROACH, CARD_CORNER, CARD_NAME, CARD_SCALE, FRONT, cardPoint, cardProgress, cardReach, stackBob };
@@ -0,0 +1,25 @@
1
+ import { Formation, FormationOptions } from "../../gl/types.js";
2
+ import { CardShape } from "./art.js";
3
+ //#region src/formations/stack/index.d.ts
4
+ export interface StackOptions extends FormationOptions {
5
+ /**
6
+ * What every card holds, in card-local art units (`CARD` half extents), x to
7
+ * the right and y up, with `role`s to bring it to life. Leave `CARD_NAME`
8
+ * free for the label. Defaults to Unframework's sign-up form.
9
+ */
10
+ art?: CardShape[];
11
+ }
12
+ /**
13
+ * A stack of seven glass cards, one per rail of the prism, each holding the
14
+ * same component, drawn in light and tinted in its rail's colour. They're
15
+ * dealt one after another as the chapter is read: the first lands in front,
16
+ * and each next one fans out from behind the one before it. The component
17
+ * plays on the same beat on all of them: the default sign-up form types its
18
+ * email, switches "remember me" on and presses submit. Follows the prism:
19
+ * rail `i` flows into card `i`.
20
+ *
21
+ * Anchors `stack:0` to `stack:6` sit in the cards' headers, front to back,
22
+ * where the name goes, and show once each card is in place.
23
+ */
24
+ export declare function stack(options: StackOptions): Formation;
25
+ //#endregion
@@ -0,0 +1,76 @@
1
+ import { smoothstep } from "../../gl/math.js";
2
+ import { defineFormation, mergeViews } from "../../gl/formation.js";
3
+ import { CARDS, CARD_NAME, cardPoint, cardProgress, cardReach } from "./geometry.js";
4
+ //#region src/formations/stack/index.ts
5
+ /**
6
+ * Each card's label is its framework's name, in the card's header: the
7
+ * `UxAnchor` tag starts a little to the right of the anchor, so the anchor sits
8
+ * just before the spot the artwork leaves for it.
9
+ */
10
+ const LABEL = [CARD_NAME[0] - .07, CARD_NAME[1]];
11
+ /**
12
+ * A stack of seven glass cards, one per rail of the prism, each holding the
13
+ * same component, drawn in light and tinted in its rail's colour. They're
14
+ * dealt one after another as the chapter is read: the first lands in front,
15
+ * and each next one fans out from behind the one before it. The component
16
+ * plays on the same beat on all of them: the default sign-up form types its
17
+ * email, switches "remember me" on and presses submit. Follows the prism:
18
+ * rail `i` flows into card `i`.
19
+ *
20
+ * Anchors `stack:0` to `stack:6` sit in the cards' headers, front to back,
21
+ * where the name goes, and show once each card is in place.
22
+ */
23
+ function stack(options) {
24
+ const anchors = Array.from({ length: CARDS }, (_, index) => ({
25
+ id: String(index),
26
+ place: ({ approach, local, time }, out) => {
27
+ cardPoint(index, LABEL, time, out);
28
+ return smoothstep(.85, 1, cardReach(index, cardProgress(approach, local)));
29
+ }
30
+ }));
31
+ return defineFormation({
32
+ key: options.key ?? "stack",
33
+ label: options.label,
34
+ views: mergeViews({
35
+ desktop: {
36
+ eye: [
37
+ 0,
38
+ 2.7,
39
+ 9.8
40
+ ],
41
+ target: [
42
+ .99,
43
+ .44,
44
+ -1.5
45
+ ],
46
+ fov: 30,
47
+ span: [1.8, 1.55],
48
+ shift: [.34, 0]
49
+ },
50
+ mobile: {
51
+ eye: [
52
+ 0,
53
+ 2.5,
54
+ 9.6
55
+ ],
56
+ target: [
57
+ .84,
58
+ .44,
59
+ -1.5
60
+ ],
61
+ fov: 34,
62
+ span: [2.05, 2.1],
63
+ shift: [0, .2]
64
+ }
65
+ }, options.views),
66
+ look: {
67
+ bloom: 1,
68
+ reflect: .5,
69
+ ...options.look
70
+ },
71
+ anchors,
72
+ shader: () => import("./shader.js").then((m) => m.createShader(options.art))
73
+ });
74
+ }
75
+ //#endregion
76
+ export { stack };
@@ -0,0 +1,193 @@
1
+ import { BASE_PARTICLES } from "../../gl/constants.js";
2
+ import { packShapes } from "../../gl/shapes.js";
3
+ import { glslArray, glslFloat, glslVec } from "../../gl/glsl.js";
4
+ import { SPECTRUM } from "../prism/spectrum.js";
5
+ import { BEHIND, CARD, CARDS, CARD_APPROACH, CARD_CORNER, CARD_SCALE, FRONT } from "./geometry.js";
6
+ import { CARD_ROLE, KNOB_TRAVEL, SIGN_UP_FORM_ART } from "./art.js";
7
+ //#region src/formations/stack/shader.ts
8
+ const ART_SHARE = .57;
9
+ const LAST = CARDS - 1;
10
+ /** The card's own border, drawn before its artwork. */
11
+ const BORDER = {
12
+ kind: "rrect",
13
+ c: [0, 0],
14
+ h: CARD,
15
+ r: CARD_CORNER,
16
+ bright: .75
17
+ };
18
+ function createShader(art = SIGN_UP_FORM_ART) {
19
+ const table = packShapes([BORDER, ...art], (shape) => shape.role ?? CARD_ROLE.still);
20
+ const typing = art.find((shape) => shape.role === CARD_ROLE.typing);
21
+ const typedLength = typing?.kind === "seg" ? typing.b[0] - typing.a[0] : 0;
22
+ return { glsl: `
23
+ const vec2 $CARD = ${glslVec(CARD)};
24
+ const float $CORNER = ${glslFloat(CARD_CORNER)};
25
+ const float $SCALE = ${glslFloat(CARD_SCALE)};
26
+ const vec3 $FRONT = ${glslVec(FRONT)};
27
+ const vec3 $BEHIND = ${glslVec(BEHIND)};
28
+ const float $KNOB_TRAVEL = ${glslFloat(KNOB_TRAVEL)};
29
+ const float $TYPED_LENGTH = ${glslFloat(typedLength)};
30
+
31
+ // The prism's spectrum, so each rail keeps its colour as it becomes a card.
32
+ const vec3 $SPECTRUM[${CARDS}] = ${glslArray("vec3", SPECTRUM.map(glslVec))};
33
+
34
+ const int $SHAPES = ${table.cdf.length};
35
+ const vec4 $SHAPE_A[$SHAPES] = ${glslArray("vec4", table.a.map(glslVec))};
36
+ const vec4 $SHAPE_B[$SHAPES] = ${glslArray("vec4", table.b.map(glslVec))};
37
+ const float $SHAPE_CDF[$SHAPES] = ${glslArray("float", table.cdf.map(glslFloat))};
38
+ // Line brightness independent of how much artwork a card carries.
39
+ const float $GAIN = ${glslFloat(table.totalWeight / (BASE_PARTICLES * ART_SHARE / CARDS) * 120)};
40
+
41
+ // Cards are dealt as the chapter scrolls in and is read (see cardProgress).
42
+ float $progress(Frame f) {
43
+ if (f.approach < 1.0) return f.approach * ${glslFloat(CARD_APPROACH)};
44
+ return mix(${glslFloat(CARD_APPROACH)}, 1.0, f.local);
45
+ }
46
+ float $reach(int i, float progress) {
47
+ float o = float(i) * 0.08;
48
+ return smoothstep(o, o + 0.45, progress);
49
+ }
50
+
51
+ // The same beat on every card, every four seconds: the email is typed, one
52
+ // character at a time, "remember me" switches on, submit is pressed, and the
53
+ // form clears. x: toggle, y: press, z: typed share of the email, w: caret.
54
+ vec4 $beat(float time) {
55
+ float ph = fract(time * 0.25);
56
+ float clear = 1.0 - smoothstep(0.9, 0.95, ph);
57
+ float typed = floor(clamp((ph - 0.04) / 0.3, 0.0, 1.0) * 18.0) / 18.0 * clear;
58
+ float on = smoothstep(0.42, 0.5, ph) * clear;
59
+ float press = exp(-pow((ph - 0.64) * 16.0, 2.0));
60
+ float caret = step(0.5, fract(time * 1.8)) * clear;
61
+ return vec4(on, press, typed, caret);
62
+ }
63
+
64
+ float $ease(float reach) {
65
+ return 1.0 - pow(1.0 - reach, 3.0);
66
+ }
67
+
68
+ // How far back card i sits, in cards. Card 0 is the front card; each next card
69
+ // fans out from behind the one before it as it's dealt.
70
+ float $depth(int i, float progress) {
71
+ if (i == 0) return 0.0;
72
+ return float(i) - 1.0 + $ease($reach(i, progress));
73
+ }
74
+
75
+ vec3 $slot(float depth, float time) {
76
+ return $FRONT + $BEHIND * depth + vec3(0.0, sin(time * 0.7) * 0.03, 0.0);
77
+ }
78
+
79
+ // Card-local point q (art units) of card i in the world. The front card flies
80
+ // in from below and in front, tipped towards the viewer.
81
+ vec3 $place(int i, vec2 q, float progress, float time) {
82
+ vec3 w = vec3(q * $SCALE, 0.0);
83
+ if (i > 0) return $slot($depth(i, progress), time) + w;
84
+ float e = $ease($reach(0, progress));
85
+ float tip = (1.0 - e) * 0.9;
86
+ vec3 tipped = vec3(w.x, w.y * cos(tip), w.y * sin(tip));
87
+ return $slot(0.0, time) + tipped + vec3(0.3, -1.4, 2.2) * (1.0 - e);
88
+ }
89
+
90
+ float $sdCard(vec2 p) {
91
+ vec2 d = abs(p) - $CARD + $CORNER;
92
+ return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - $CORNER;
93
+ }
94
+
95
+ // How much of card i, at q, the cards in front of it hide. The renderer has no
96
+ // depth test, so what's behind is dimmed instead, as through frosted glass. A
97
+ // card's place hides what's behind it from the start of its deal, so the next
98
+ // card only shows once it fans out past it.
99
+ float $covered(int i, vec2 q, float progress) {
100
+ float depth = $depth(i, progress);
101
+ float cover = 0.0;
102
+ for (int j = 0; j < i; j++) {
103
+ vec2 rel = q + (depth - $depth(j, progress)) * $BEHIND.xy / $SCALE;
104
+ float inside = 1.0 - smoothstep(-0.03, 0.02, $sdCard(rel));
105
+ cover = max(cover, inside * smoothstep(0.0, 0.15, $reach(j, progress)));
106
+ }
107
+ return cover;
108
+ }
109
+
110
+ int $findShape(float x) {
111
+ for (int k = 0; k < $SHAPES - 1; k++) {
112
+ if (x < $SHAPE_CDF[k]) return k;
113
+ }
114
+ return $SHAPES - 1;
115
+ }
116
+
117
+ vec2 $shapePoint(int k, float b, float c, vec4 beat, out float light) {
118
+ vec4 A = $SHAPE_A[k];
119
+ vec4 B = $SHAPE_B[k];
120
+ int role = int(B.z + 0.5);
121
+ light = B.w;
122
+ // The line being typed grows with the email.
123
+ vec2 q = shapePoint(A, B, role == ${CARD_ROLE.typing} ? b * beat.z : b, c);
124
+ if (role == ${CARD_ROLE.knob}) {
125
+ q.x += beat.x * $KNOB_TRAVEL;
126
+ light *= mix(0.8, 1.3, beat.x);
127
+ } else if (role == ${CARD_ROLE.track}) {
128
+ light *= mix(0.25, 1.6, beat.x);
129
+ } else if (role == ${CARD_ROLE.button}) {
130
+ // Pressed in towards its centre.
131
+ vec2 centre = int(B.x + 0.5) == 0 ? (A.xy + A.zw) * 0.5 : A.xy;
132
+ q = centre + (q - centre) * (1.0 - beat.y * 0.06);
133
+ light *= 1.0 + beat.y * 1.8;
134
+ } else if (role == ${CARD_ROLE.typing}) {
135
+ // The same particles over a shorter line: keep its brightness even.
136
+ light *= max(beat.z, 0.001);
137
+ } else if (role == ${CARD_ROLE.caret}) {
138
+ q.x += beat.z * $TYPED_LENGTH;
139
+ light *= beat.w;
140
+ }
141
+ return q;
142
+ }
143
+
144
+ Particle $main(uint id, float sel, Frame f) {
145
+ float progress = $progress(f);
146
+ float time = f.time;
147
+ uint s = seedOf(id, 0x5AC4ED07u);
148
+ float a = rnd(s);
149
+ float b = rnd(s);
150
+ float c = rnd(s);
151
+ float d = rnd(s);
152
+ Particle P = blank();
153
+ float sweep = mod(time * 0.5, 7.0) - 3.0;
154
+
155
+ if (sel < ${glslFloat(.3500000000000001)}) {
156
+ // Frosted glass, with a glint sweeping across the stack.
157
+ int i = min(int(a * ${glslFloat(CARDS)}), ${LAST});
158
+ float e = $reach(i, progress);
159
+ vec2 q = (vec2(b, c) * 2.0 - 1.0) * $CARD;
160
+ P.pos = $place(i, q, progress, time);
161
+ float glint = exp(-pow((P.pos.x - sweep) * 2.2, 2.0));
162
+ P.col = mix($SPECTRUM[i], vec3(1.0), 0.4) * (0.016 + glint * 0.035) * smoothstep(0.0, 0.3, e);
163
+ P.col *= 1.0 - 0.9 * $covered(i, q, progress);
164
+ P.size = 0.75;
165
+ P.refl = 1.0;
166
+ } else if (sel < 0.92) {
167
+ // Seven cards, one per rail, each holding the same component.
168
+ int i = min(int((sel - ${glslFloat(.3500000000000001)}) / ${glslFloat(ART_SHARE)} * ${glslFloat(CARDS)}), ${LAST});
169
+ float e = $reach(i, progress);
170
+ float light;
171
+ vec2 q = $shapePoint($findShape(a), b, c, $beat(time), light);
172
+ P.pos = $place(i, q, progress, time);
173
+ float glint = exp(-pow((P.pos.x - sweep) * 2.2, 2.0));
174
+ float landed = exp(-pow((e - 0.97) * 10.0, 2.0));
175
+ vec3 tint = mix($SPECTRUM[i], vec3(1.0), 0.18);
176
+ P.col = tint * light * $GAIN * (1.0 + glint * 0.8 + landed) * smoothstep(0.0, 0.3, e);
177
+ P.col *= 1.0 - 0.97 * $covered(i, q, progress);
178
+ P.size = 0.75;
179
+ P.refl = 1.0;
180
+ } else {
181
+ // Dust caught in the light.
182
+ vec3 p = vec3(mix(-5.0, 5.0, a), mix(-1.35, 2.6, b), mix(-4.0, 2.5, c));
183
+ p.x = mod(p.x + time * 0.04 + 5.0, 10.0) - 5.0;
184
+ P.pos = p;
185
+ P.col = vec3(0.7, 0.75, 0.9) * 0.05 * step(0.4, d);
186
+ P.size = 0.9;
187
+ }
188
+ return P;
189
+ }
190
+ ` };
191
+ }
192
+ //#endregion
193
+ export { createShader };
@@ -0,0 +1,98 @@
1
+ import { lerp, smoothstep } from "../../gl/math.js";
2
+ import "../prism/geometry.js";
3
+ //#region src/formations/threshold/geometry.ts
4
+ /** One beam per rail of the prism, top to bottom in its order. */
5
+ const BEAMS = 7;
6
+ /** The film: a disc of light standing in the dark, its centre and radius. */
7
+ const CENTER = [
8
+ 0,
9
+ .15,
10
+ 0
11
+ ];
12
+ const RADIUS = 1.35;
13
+ const deg = (d) => d * Math.PI / 180;
14
+ const unit = (v) => {
15
+ const l = Math.hypot(...v);
16
+ return [
17
+ v[0] / l,
18
+ v[1] / l,
19
+ v[2] / l
20
+ ];
21
+ };
22
+ /**
23
+ * The film stands turned about the vertical: its normal points right and away,
24
+ * so its right-hand side comes towards the viewer.
25
+ */
26
+ const TURN = deg(40);
27
+ const NORMAL = [
28
+ Math.cos(TURN),
29
+ 0,
30
+ -Math.sin(TURN)
31
+ ];
32
+ /** In the film's plane: across (horizontal, towards the viewer) and up. */
33
+ const ACROSS = [
34
+ Math.sin(TURN),
35
+ 0,
36
+ Math.cos(TURN)
37
+ ];
38
+ const UP = [
39
+ 0,
40
+ 1,
41
+ 0
42
+ ];
43
+ /**
44
+ * The beams come in from the left, parallel, and go through the film. Beyond
45
+ * it they're `FASTER` times faster: they turn the corner and converge, over
46
+ * `CONVERGE` world units, into one white stream that races off into the
47
+ * distance, the prism in reverse.
48
+ */
49
+ const IN_DIR = [
50
+ 1,
51
+ 0,
52
+ 0
53
+ ];
54
+ const OUT_DIR = unit([
55
+ .28,
56
+ 0,
57
+ -1
58
+ ]);
59
+ const CONVERGE = 2.6;
60
+ const FASTER = 2.2;
61
+ /**
62
+ * Where the beams cross the film: down its vertical diameter, like the prism's
63
+ * rails. The height of the first above the centre, and the step to the next.
64
+ */
65
+ const CROSSING = [.84, .28];
66
+ /**
67
+ * Beams break through one after another as the chapter is read: beam `i` from
68
+ * `from + i * step`, over `span` of the progress.
69
+ */
70
+ const BREAK = {
71
+ from: .22,
72
+ step: .05,
73
+ span: .25
74
+ };
75
+ /** Share of the progress that happens while the chapter scrolls in. */
76
+ const BEAM_APPROACH = .3;
77
+ /** Progress: starts with the morph into the formation, not once it's held. */
78
+ const beamProgress = (approach, local) => approach < 1 ? approach * BEAM_APPROACH : lerp(BEAM_APPROACH, 1, local);
79
+ /** How far beam `index` has broken through the film, 0 → 1 (see `BREAK`). */
80
+ const beamReach = (index, progress) => {
81
+ const from = BREAK.from + index * BREAK.step;
82
+ return smoothstep(from, from + BREAK.span, progress);
83
+ };
84
+ /** Where the seven meet, level with the middle beam: past the film, round the corner. */
85
+ const MERGE = [
86
+ CENTER[0] + IN_DIR[0] * .9 + OUT_DIR[0] * 1.5,
87
+ CENTER[1] + CROSSING[0] - 3 * CROSSING[1],
88
+ CENTER[2] + IN_DIR[2] * .9 + OUT_DIR[2] * 1.5
89
+ ];
90
+ /** A point `t` world units down the white stream, past where the seven meet. */
91
+ function streamPoint(t, out) {
92
+ out[0] = MERGE[0] + OUT_DIR[0] * t;
93
+ out[1] = MERGE[1] + OUT_DIR[1] * t;
94
+ out[2] = MERGE[2] + OUT_DIR[2] * t;
95
+ return out;
96
+ }
97
+ //#endregion
98
+ export { ACROSS, BEAMS, BEAM_APPROACH, BREAK, CENTER, CONVERGE, CROSSING, FASTER, IN_DIR, MERGE, NORMAL, OUT_DIR, RADIUS, UP, beamProgress, beamReach, streamPoint };
@@ -0,0 +1,16 @@
1
+ import { Formation, FormationOptions } from "../../gl/types.js";
2
+ //#region src/formations/threshold/index.d.ts
3
+ /**
4
+ * The seven beams of light, one per rail of the prism, cross a film of light
5
+ * into whatever comes next. The film is a soap film on a ring: its colours
6
+ * swirl as it drains, and ripples spread from where each beam goes through.
7
+ * Beyond it the light is faster: the beams turn the corner and converge into
8
+ * one white stream, the prism in reverse, which races off into the distance,
9
+ * its pulses stretched into streaks. They break through one after another as
10
+ * the chapter is read, and the stream brightens as each one joins it.
11
+ *
12
+ * Anchor `threshold:stream` sits just above the white stream, for its label,
13
+ * and shows once every beam has joined it.
14
+ */
15
+ export declare function threshold(options: FormationOptions): Formation;
16
+ //#endregion