@uxfront/scene 0.4.2 → 0.5.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/README.md +45 -1
- package/dist/experience.js +11 -0
- package/dist/formations/empty/index.d.ts +10 -0
- package/dist/formations/empty/index.js +50 -0
- package/dist/formations/empty/shader.js +10 -0
- package/dist/formations/index.d.ts +2 -1
- package/dist/formations/index.js +2 -1
- package/dist/gl/engine.js +50 -16
- package/dist/gl/wrap.d.ts +21 -0
- package/dist/gl/wrap.js +54 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The scroll-driven WebGL particle scene behind the uxfront.com family of homepages (UXFront, Open Components, Unframework, Styleframe, Inkline). One GPU particle system turns into a new **formation** for each section of the page as you scroll. The package has no framework dependency: `@uxfront/ui` wraps it in Vue components, and any other page can drive it directly.
|
|
4
4
|
|
|
5
5
|
- **A pipeline.** Morphs between formations under curl noise, an intro that rises from a floor line, a cursor lens, a click shockwave, a mirror floor, light trails, bloom and a filmic composite.
|
|
6
|
-
- **A catalog.**
|
|
6
|
+
- **A catalog.** Ten formations: `monolith`, `plates`, `prism`, `tokens`, `ink`, `corridor`, `stack`, `threshold`, `outline` and `empty`.
|
|
7
7
|
- **A controller.** `createExperience` maps the page's sections to formations, reveals copy, steps through highlights and pins DOM labels to the formations.
|
|
8
8
|
|
|
9
9
|
Pages stay fast. The engine and each formation's GLSL are separate chunks, imported only once the page is idle. Shaders compile without blocking the main thread. Slow GPUs get fewer particles at a lower resolution, and without a capable GPU (no WebGL2, a software rasterizer, a lost context) the state switches to `"fallback"`, so the page can show a static image instead.
|
|
@@ -89,6 +89,20 @@ Sections scroll freely, so don't pin them: the copy should move with the page. T
|
|
|
89
89
|
|
|
90
90
|
Portrait, squarish and small screens use each formation's `mobile` framing, which leaves the top of the screen to the formation. Lay the copy out with the same breakpoints, exported as `STACKED_QUERY`.
|
|
91
91
|
|
|
92
|
+
### The frame
|
|
93
|
+
|
|
94
|
+
On a screen wider than the page's frame, the copy sits in a centred column, and a formation drawn against the whole screen would drift away from it. So the scene reads the frame's width from `--ux-frame` on `root` when it measures, on load and on resize, and draws the layout it would draw on a screen as wide as the frame, centred, while the canvas still fills the screen. Anchors follow, since they're projected through the same camera.
|
|
95
|
+
|
|
96
|
+
The scene's frame is never squarer than 5:4 of the screen's height, since the formations' desktop views are built for that shape, and a view that reaches the frame's edge, like `plates`', would carry its labels past a narrower one. Up to 1536px tall, a `1920px` frame is the page's frame. On a taller screen, like a 4K screen at 100% scaling (3840 × 2030px), the scene draws a band 5:4 of the height wide instead, 2537px, still centred.
|
|
97
|
+
|
|
98
|
+
`--ux-frame` is a px length, like `1920px`, the default `@uxfront/ui` sets. Anything else, like `100vw` or no value at all, means no frame, and at or below the scene frame's width the camera is the same as without one. With `@uxfront/ui`, override it on `:root:has(.ux-site)`, so the gutter and the scene move together:
|
|
99
|
+
|
|
100
|
+
```css
|
|
101
|
+
:root:has(.ux-site) {
|
|
102
|
+
--ux-frame: 1200px;
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
92
106
|
## Catalog
|
|
93
107
|
|
|
94
108
|
Every factory takes `{ label, key?, views?, look? }`. `label` is shown in the HUD. `views` overrides the framing, for example to put a formation on the other side of the copy: `tokens({ label, views: { desktop: { shift: [0.42, 0.02] } } })`. `key` is only needed to use the same formation twice.
|
|
@@ -104,9 +118,39 @@ Every factory takes `{ label, key?, views?, look? }`. `label` is shown in the HU
|
|
|
104
118
|
| `stack` | Seven glass cards dealt as the chapter is read, one per rail, each holding the same component. `art` swaps it. | `stack:0`–`stack:6`, in the cards' headers |
|
|
105
119
|
| `threshold` | The prism's seven beams cross a soap film of light and converge into one white stream. | `threshold:stream`, above the stream |
|
|
106
120
|
| `outline` | Gathers around the section's `[data-outline]` element, like an image or a code panel. `lines` draws its code. | None |
|
|
121
|
+
| `empty` | Nothing, for a section without a formation. It frames the camera as `corridor` does. | None |
|
|
122
|
+
|
|
123
|
+
`empty` gives a section its place in the scene without drawing anything, since the scene needs one formation per section. Give each repeat its own `key`, like `empty({ label: "Pricing", key: "pricing" })`.
|
|
107
124
|
|
|
108
125
|
`outline` places its particles on the element itself, so it doesn't need `views`. With `lines: true`, it also draws the text lines of the `pre` blocks inside the element, scattering particles along each line's characters, before the code fades in. Its look turns `streak` off, so the outline stays crisp while the page scrolls. In the page's first section, which holds from the top, `--ux-reveal` is 1 at rest.
|
|
109
126
|
|
|
127
|
+
### Reusing a formation
|
|
128
|
+
|
|
129
|
+
Three helpers change a catalog formation in ways its options don't cover. They rely only on the shader contract (`$main`, and `$name` identifiers), so they work on any formation, yours included.
|
|
130
|
+
|
|
131
|
+
| Helper | Effect |
|
|
132
|
+
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
133
|
+
| `hold(formation, local)` | Holds the formation at a fixed `local`, whatever the scroll. Its GLSL, `update()` and anchors' `place()` and `render()` all see that `local`. |
|
|
134
|
+
| `wrapMain(formation, inner, body)` | Renames the formation's `$main` to `$<inner>` and adds a `$main` with `body`, which can call `$<inner>(id, sel, f)` and change its particle. |
|
|
135
|
+
| `editShader(formation, edit)` | Runs `edit` on the formation's shader once it loads, to change its GLSL or its `update()`. |
|
|
136
|
+
|
|
137
|
+
`hold` suits a hero. The first section starts at the top of the page, so it only gets a quarter screen of scroll (`HOLD_MARGIN`): a formation that moves with `local`, like `plates`, would rush to its end state the moment the page scrolls. Held, it stays put while it morphs into the next formation.
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { hold, wrapMain } from "@uxfront/scene";
|
|
141
|
+
import { monolith, plates } from "@uxfront/scene/formations";
|
|
142
|
+
|
|
143
|
+
const hero = hold(plates({ label: "Open Components" }), 1);
|
|
144
|
+
// Dims the monolith to half its brightness.
|
|
145
|
+
const dimmed = wrapMain(
|
|
146
|
+
monolith({ label: "Foundation" }),
|
|
147
|
+
"lit",
|
|
148
|
+
` Particle P = $lit(id, sel, f);
|
|
149
|
+
P.col *= 0.5;
|
|
150
|
+
return P;`,
|
|
151
|
+
);
|
|
152
|
+
```
|
|
153
|
+
|
|
110
154
|
### Look
|
|
111
155
|
|
|
112
156
|
`look` tunes the post-processing for one formation, and the scene blends it across the morphs on either side.
|
package/dist/experience.js
CHANGED
|
@@ -29,6 +29,13 @@ function pageTop(el) {
|
|
|
29
29
|
for (let node = el; node instanceof HTMLElement; node = node.offsetParent) top += node.offsetTop;
|
|
30
30
|
return top;
|
|
31
31
|
}
|
|
32
|
+
const PX = /^\s*(\d+(?:\.\d+)?|\.\d+)px\s*$/;
|
|
33
|
+
/** `--ux-frame` in CSS pixels, or null for anything but a px length, like `100vw`. */
|
|
34
|
+
function frameOf(value) {
|
|
35
|
+
const match = PX.exec(value);
|
|
36
|
+
const frame = match ? Number(match[1]) : 0;
|
|
37
|
+
return frame > 0 ? frame : null;
|
|
38
|
+
}
|
|
32
39
|
function detectQuality() {
|
|
33
40
|
if (Math.min(screen.width, screen.height) < 700) return "low";
|
|
34
41
|
if (matchMedia("(pointer: coarse)").matches) return "medium";
|
|
@@ -72,6 +79,7 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
72
79
|
let maxScroll = 1;
|
|
73
80
|
let canvasWidth = 1;
|
|
74
81
|
let canvasHeight = 1;
|
|
82
|
+
let frame = null;
|
|
75
83
|
const html = document.documentElement;
|
|
76
84
|
const fallBack = () => {
|
|
77
85
|
set({ status: "fallback" });
|
|
@@ -100,6 +108,8 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
100
108
|
...sectionSpan(rect.top + scrollY, rect.height, viewport, maxScroll)
|
|
101
109
|
};
|
|
102
110
|
});
|
|
111
|
+
frame = frameOf(getComputedStyle(root).getPropertyValue("--ux-frame"));
|
|
112
|
+
engine?.setFrame(frame);
|
|
103
113
|
engine?.resize();
|
|
104
114
|
};
|
|
105
115
|
const resizeObserver = new ResizeObserver(measure);
|
|
@@ -262,6 +272,7 @@ function createExperience({ root, canvas, formations, anchorRoots = [] }) {
|
|
|
262
272
|
shaders,
|
|
263
273
|
quality: detectQuality(),
|
|
264
274
|
reducedMotion: !state.motion,
|
|
275
|
+
frame,
|
|
265
276
|
onContextLost: () => {
|
|
266
277
|
engine?.destroy();
|
|
267
278
|
engine = null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Formation, FormationOptions } from "../../gl/types.js";
|
|
2
|
+
//#region src/formations/empty/index.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Draws nothing, for a section that holds no formation. The scene needs one
|
|
5
|
+
* formation per section, so give each repeat its own `key`. It frames the
|
|
6
|
+
* camera as `corridor` does, so the camera holds still into a closing
|
|
7
|
+
* corridor.
|
|
8
|
+
*/
|
|
9
|
+
export declare function empty(options: FormationOptions): Formation;
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineFormation, mergeViews } from "../../gl/formation.js";
|
|
2
|
+
//#region src/formations/empty/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Draws nothing, for a section that holds no formation. The scene needs one
|
|
5
|
+
* formation per section, so give each repeat its own `key`. It frames the
|
|
6
|
+
* camera as `corridor` does, so the camera holds still into a closing
|
|
7
|
+
* corridor.
|
|
8
|
+
*/
|
|
9
|
+
function empty(options) {
|
|
10
|
+
return defineFormation({
|
|
11
|
+
key: options.key ?? "empty",
|
|
12
|
+
label: options.label,
|
|
13
|
+
views: mergeViews({
|
|
14
|
+
desktop: {
|
|
15
|
+
eye: [
|
|
16
|
+
0,
|
|
17
|
+
0,
|
|
18
|
+
7
|
|
19
|
+
],
|
|
20
|
+
target: [
|
|
21
|
+
0,
|
|
22
|
+
0,
|
|
23
|
+
-12
|
|
24
|
+
],
|
|
25
|
+
fov: 56,
|
|
26
|
+
span: [0, 0],
|
|
27
|
+
shift: [0, 0]
|
|
28
|
+
},
|
|
29
|
+
mobile: {
|
|
30
|
+
eye: [
|
|
31
|
+
0,
|
|
32
|
+
0,
|
|
33
|
+
7
|
|
34
|
+
],
|
|
35
|
+
target: [
|
|
36
|
+
0,
|
|
37
|
+
0,
|
|
38
|
+
-12
|
|
39
|
+
],
|
|
40
|
+
fov: 64,
|
|
41
|
+
span: [0, 0],
|
|
42
|
+
shift: [0, 0]
|
|
43
|
+
}
|
|
44
|
+
}, options.views),
|
|
45
|
+
look: { ...options.look },
|
|
46
|
+
shader: () => import("./shader.js").then((m) => m.shader)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { empty };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { corridor } from "./corridor/index.js";
|
|
2
|
+
import { empty } from "./empty/index.js";
|
|
2
3
|
import { ink } from "./ink/index.js";
|
|
3
4
|
import { monolith } from "./monolith/index.js";
|
|
4
5
|
import { OutlineOptions, outline } from "./outline/index.js";
|
|
@@ -14,4 +15,4 @@ import { CARD, CARD_NAME } from "./stack/geometry.js";
|
|
|
14
15
|
import { threshold } from "./threshold/index.js";
|
|
15
16
|
import { THEMES, Theme } from "./tokens/geometry.js";
|
|
16
17
|
import { TokensFormation, tokens } from "./tokens/index.js";
|
|
17
|
-
export { CARD, CARD_NAME, CARD_ROLE, type CardRole, type CardShape, KNOB_TRAVEL, OPEN_COMPONENTS_ART, type OutlineOptions, PLATE, type PlateShape, type PlatesOptions, RAILS, SIGN_UP_FORM_ART, SPECTRUM, type StackOptions, THEMES, type Theme, type TokensFormation, circle, corridor, disc, fill, ink, monolith, outline, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
|
|
18
|
+
export { CARD, CARD_NAME, CARD_ROLE, type CardRole, type CardShape, KNOB_TRAVEL, OPEN_COMPONENTS_ART, type OutlineOptions, PLATE, type PlateShape, type PlatesOptions, RAILS, SIGN_UP_FORM_ART, SPECTRUM, type StackOptions, THEMES, type Theme, type TokensFormation, circle, corridor, disc, empty, fill, ink, monolith, outline, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
|
package/dist/formations/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { corridor } from "./corridor/index.js";
|
|
2
|
+
import { empty } from "./empty/index.js";
|
|
2
3
|
import { ink } from "./ink/index.js";
|
|
3
4
|
import { monolith } from "./monolith/index.js";
|
|
4
5
|
import { outline } from "./outline/index.js";
|
|
@@ -14,4 +15,4 @@ import { CARD_ROLE, KNOB_TRAVEL, SIGN_UP_FORM_ART } from "./stack/art.js";
|
|
|
14
15
|
import { threshold } from "./threshold/index.js";
|
|
15
16
|
import { THEMES } from "./tokens/geometry.js";
|
|
16
17
|
import { tokens } from "./tokens/index.js";
|
|
17
|
-
export { CARD, CARD_NAME, CARD_ROLE, KNOB_TRAVEL, OPEN_COMPONENTS_ART, PLATE, RAILS, SIGN_UP_FORM_ART, SPECTRUM, THEMES, circle, corridor, disc, fill, ink, monolith, outline, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
|
|
18
|
+
export { CARD, CARD_NAME, CARD_ROLE, KNOB_TRAVEL, OPEN_COMPONENTS_ART, PLATE, RAILS, SIGN_UP_FORM_ART, SPECTRUM, THEMES, circle, corridor, disc, empty, fill, ink, monolith, outline, plateBorder, plates, prism, rrect, seg, stack, threshold, tokens };
|
package/dist/gl/engine.js
CHANGED
|
@@ -63,6 +63,27 @@ function fitEye(stageView, aspect, out) {
|
|
|
63
63
|
return out;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
+
* The squarest frame the desktop views are built for: `STACKED_QUERY` keeps
|
|
67
|
+
* them on screens no squarer than 5:4.
|
|
68
|
+
*/
|
|
69
|
+
const MIN_FRAME_ASPECT = 5 / 4;
|
|
70
|
+
/**
|
|
71
|
+
* Fits a view to a canvas `aspect` wide. On a canvas wider than the frame
|
|
72
|
+
* (`frameAspect`, the frame's width over the canvas's height, and at least
|
|
73
|
+
* 5:4), it fits the view to the frame instead and narrows the lens shift to
|
|
74
|
+
* match, so the formation lands where a canvas as wide as the frame would
|
|
75
|
+
* draw it, centred. The vertical field of view stays, since the canvas is as
|
|
76
|
+
* tall as the frame.
|
|
77
|
+
*/
|
|
78
|
+
function frameView(stageView, aspect, frameAspect, out) {
|
|
79
|
+
const scene = Math.max(frameAspect, MIN_FRAME_ASPECT);
|
|
80
|
+
const framed = aspect > scene;
|
|
81
|
+
fitEye(stageView, framed ? scene : aspect, out.eye);
|
|
82
|
+
out.shift[0] = framed ? stageView.shift[0] * scene / aspect : stageView.shift[0];
|
|
83
|
+
out.shift[1] = stageView.shift[1];
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
66
87
|
* The trail's decay and the composite's colour fringe for a frame. Scrolling
|
|
67
88
|
* between formations lengthens the trail and widens the fringe by `boost`, as
|
|
68
89
|
* far as the look's `streak` lets it, and the intro rises through a long trail.
|
|
@@ -190,6 +211,8 @@ async function createEngine(canvas, options) {
|
|
|
190
211
|
deleteTarget(probe);
|
|
191
212
|
}
|
|
192
213
|
let quality = options.quality;
|
|
214
|
+
let frameWidth = options.frame;
|
|
215
|
+
let canvasHeight = 1;
|
|
193
216
|
let particleCount = PARTICLES[quality];
|
|
194
217
|
let renderScale = 1;
|
|
195
218
|
let scene = null;
|
|
@@ -199,6 +222,7 @@ async function createEngine(canvas, options) {
|
|
|
199
222
|
const dpr = Math.min(window.devicePixelRatio || 1, PIXEL_RATIO[quality]) * renderScale;
|
|
200
223
|
const cssWidth = Math.max(1, canvas.clientWidth);
|
|
201
224
|
const cssHeight = Math.max(1, canvas.clientHeight);
|
|
225
|
+
canvasHeight = cssHeight;
|
|
202
226
|
const fit = Math.min(1, maxBuffer / Math.max(cssWidth * dpr, cssHeight * dpr));
|
|
203
227
|
const width = Math.max(1, Math.round(cssWidth * dpr * fit));
|
|
204
228
|
const height = Math.max(1, Math.round(cssHeight * dpr * fit));
|
|
@@ -233,16 +257,22 @@ async function createEngine(canvas, options) {
|
|
|
233
257
|
0,
|
|
234
258
|
0
|
|
235
259
|
];
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
0,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
260
|
+
const viewA = {
|
|
261
|
+
eye: [
|
|
262
|
+
0,
|
|
263
|
+
0,
|
|
264
|
+
0
|
|
265
|
+
],
|
|
266
|
+
shift: [0, 0]
|
|
267
|
+
};
|
|
268
|
+
const viewB = {
|
|
269
|
+
eye: [
|
|
270
|
+
0,
|
|
271
|
+
0,
|
|
272
|
+
0
|
|
273
|
+
],
|
|
274
|
+
shift: [0, 0]
|
|
275
|
+
};
|
|
246
276
|
const rayDir = [
|
|
247
277
|
0,
|
|
248
278
|
0,
|
|
@@ -312,13 +342,14 @@ async function createEngine(canvas, options) {
|
|
|
312
342
|
const e = smoothstep(0, 1, stage - a);
|
|
313
343
|
const va = stacked ? formations[a].views.mobile : formations[a].views.desktop;
|
|
314
344
|
const vb = stacked ? formations[b].views.mobile : formations[b].views.desktop;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
345
|
+
const frameAspect = frameWidth === null ? Infinity : frameWidth / canvasHeight;
|
|
346
|
+
frameView(va, aspect, frameAspect, viewA);
|
|
347
|
+
frameView(vb, aspect, frameAspect, viewB);
|
|
348
|
+
lerp3(eye, viewA.eye, viewB.eye, e);
|
|
318
349
|
lerp3(target, va.target, vb.target, e);
|
|
319
350
|
fov = lerp(va.fov, vb.fov, e);
|
|
320
|
-
shift[0] = lerp(
|
|
321
|
-
shift[1] = lerp(
|
|
351
|
+
shift[0] = lerp(viewA.shift[0], viewB.shift[0], e);
|
|
352
|
+
shift[1] = lerp(viewA.shift[1], viewB.shift[1], e);
|
|
322
353
|
const yaw = (motion ? Math.sin(time * .11) * .06 : 0) + pointerX * .1;
|
|
323
354
|
const pitch = (motion ? Math.sin(time * .07) * .02 : 0) + pointerY * .05;
|
|
324
355
|
let ox = eye[0] - target[0];
|
|
@@ -548,6 +579,9 @@ async function createEngine(canvas, options) {
|
|
|
548
579
|
},
|
|
549
580
|
viewProjection,
|
|
550
581
|
render,
|
|
582
|
+
setFrame(frame) {
|
|
583
|
+
frameWidth = frame;
|
|
584
|
+
},
|
|
551
585
|
resize,
|
|
552
586
|
shock(ndcX, ndcY) {
|
|
553
587
|
if (lost) return;
|
|
@@ -579,4 +613,4 @@ async function createEngine(canvas, options) {
|
|
|
579
613
|
};
|
|
580
614
|
}
|
|
581
615
|
//#endregion
|
|
582
|
-
export { createEngine, fitEye, trailOf };
|
|
616
|
+
export { createEngine, fitEye, frameView, trailOf };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Formation, FormationShader } from "./types.js";
|
|
2
|
+
//#region src/gl/wrap.d.ts
|
|
3
|
+
/** Changes a formation's shader once it loads, like the GLSL or its `update()`. */
|
|
4
|
+
export declare const editShader: (formation: Formation, edit: (shader: FormationShader) => FormationShader) => Formation;
|
|
5
|
+
/**
|
|
6
|
+
* Renames the formation's `$main` to `$<inner>` and appends a new `$main`
|
|
7
|
+
* with the given body, which calls `$<inner>(id, sel, f)`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const wrapMain: (formation: Formation, inner: string, body: string) => Formation;
|
|
10
|
+
/**
|
|
11
|
+
* Holds a formation at a fixed `local` progress, whatever the scroll.
|
|
12
|
+
*
|
|
13
|
+
* A section plays its formation through (`local` 0 → 1) while it fills the
|
|
14
|
+
* screen, give or take `HOLD_MARGIN`. The hero starts at the top of the page,
|
|
15
|
+
* so it only gets the first quarter screen of scroll: a formation that moves
|
|
16
|
+
* with `local`, like `plates`, would rush to its end state the moment the
|
|
17
|
+
* page scrolls. Held, it stays put while it morphs into the next formation.
|
|
18
|
+
* Anchors and `update()` see the same `local`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function hold(formation: Formation, local: number): Formation;
|
|
21
|
+
//#endregion
|
package/dist/gl/wrap.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { glslFloat } from "./glsl.js";
|
|
2
|
+
//#region src/gl/wrap.ts
|
|
3
|
+
const MAIN = /\bParticle\s+\$main\s*\(/;
|
|
4
|
+
/** Changes a formation's shader once it loads, like the GLSL or its `update()`. */
|
|
5
|
+
const editShader = (formation, edit) => ({
|
|
6
|
+
...formation,
|
|
7
|
+
shader: () => formation.shader().then(edit)
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Renames the formation's `$main` to `$<inner>` and appends a new `$main`
|
|
11
|
+
* with the given body, which calls `$<inner>(id, sel, f)`.
|
|
12
|
+
*/
|
|
13
|
+
const wrapMain = (formation, inner, body) => editShader(formation, (shader) => {
|
|
14
|
+
if (!MAIN.test(shader.glsl)) throw new Error(`Formation "${formation.key}" has no Particle $main() to wrap.`);
|
|
15
|
+
return {
|
|
16
|
+
...shader,
|
|
17
|
+
glsl: `${shader.glsl.replace(MAIN, `Particle $${inner}(`)}
|
|
18
|
+
Particle $main(uint id, float sel, Frame f) {
|
|
19
|
+
${body}
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Holds a formation at a fixed `local` progress, whatever the scroll.
|
|
26
|
+
*
|
|
27
|
+
* A section plays its formation through (`local` 0 → 1) while it fills the
|
|
28
|
+
* screen, give or take `HOLD_MARGIN`. The hero starts at the top of the page,
|
|
29
|
+
* so it only gets the first quarter screen of scroll: a formation that moves
|
|
30
|
+
* with `local`, like `plates`, would rush to its end state the moment the
|
|
31
|
+
* page scrolls. Held, it stays put while it morphs into the next formation.
|
|
32
|
+
* Anchors and `update()` see the same `local`.
|
|
33
|
+
*/
|
|
34
|
+
function hold(formation, local) {
|
|
35
|
+
const at = (progress) => ({
|
|
36
|
+
...progress,
|
|
37
|
+
local
|
|
38
|
+
});
|
|
39
|
+
const held = wrapMain(formation, "held", ` f.local = ${glslFloat(local)};
|
|
40
|
+
return $held(id, sel, f);`);
|
|
41
|
+
return {
|
|
42
|
+
...editShader(held, (shader) => shader.update ? {
|
|
43
|
+
...shader,
|
|
44
|
+
update: (uniforms, frame) => shader.update?.(uniforms, at(frame))
|
|
45
|
+
} : shader),
|
|
46
|
+
anchors: formation.anchors.map((anchor) => ({
|
|
47
|
+
...anchor,
|
|
48
|
+
place: (progress, out) => anchor.place(at(progress), out),
|
|
49
|
+
...anchor.render && { render: (el, progress) => anchor.render?.(el, at(progress)) }
|
|
50
|
+
}))
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { editShader, hold, wrapMain };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ import { BASE_PARTICLES, FLOOR_Y } from "./gl/constants.js";
|
|
|
7
7
|
import { defineFormation, mergeViews } from "./gl/formation.js";
|
|
8
8
|
import { glslArray, glslFloat, glslVec } from "./gl/glsl.js";
|
|
9
9
|
import { HOLD_MARGIN, SectionSpan, approachOf, localOf, presenceOf, progressOf, sectionSpan, stageAt, stepAt } from "./gl/stage.js";
|
|
10
|
+
import { editShader, hold, wrapMain } from "./gl/wrap.js";
|
|
10
11
|
import { STACKED_QUERY } from "./layout.js";
|
|
11
|
-
export { type AnchorDef, BASE_PARTICLES, type Experience, type ExperienceOptions, type ExperienceState, FLOOR_Y, type Formation, type FormationDef, type FormationFrame, type FormationLook, type FormationOptions, type FormationProgress, type FormationShader, type FormationViews, type GlStatus, HOLD_MARGIN, type Mat4, type PackedShapes, STACKED_QUERY, type SectionSpan, type ShaderPart, type Shape, type StageView, type Uniforms, type Vec2, type Vec3, type Vec4, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslArray, glslFloat, glslVec, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, sectionSpan, smoothstep, stageAt, stepAt };
|
|
12
|
+
export { type AnchorDef, BASE_PARTICLES, type Experience, type ExperienceOptions, type ExperienceState, FLOOR_Y, type Formation, type FormationDef, type FormationFrame, type FormationLook, type FormationOptions, type FormationProgress, type FormationShader, type FormationViews, type GlStatus, HOLD_MARGIN, type Mat4, type PackedShapes, STACKED_QUERY, type SectionSpan, type ShaderPart, type Shape, type StageView, type Uniforms, type Vec2, type Vec3, type Vec4, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, editShader, glslArray, glslFloat, glslVec, hold, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, sectionSpan, smoothstep, stageAt, stepAt, wrapMain };
|
package/dist/index.js
CHANGED
|
@@ -6,5 +6,6 @@ import { packShapes } from "./gl/shapes.js";
|
|
|
6
6
|
import { glslArray, glslFloat, glslVec } from "./gl/glsl.js";
|
|
7
7
|
import { composeParticleShader, namespaceGlsl } from "./gl/compose.js";
|
|
8
8
|
import { defineFormation, mergeViews } from "./gl/formation.js";
|
|
9
|
+
import { editShader, hold, wrapMain } from "./gl/wrap.js";
|
|
9
10
|
import { STACKED_QUERY } from "./layout.js";
|
|
10
|
-
export { BASE_PARTICLES, FLOOR_Y, HOLD_MARGIN, STACKED_QUERY, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslArray, glslFloat, glslVec, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, sectionSpan, smoothstep, stageAt, stepAt };
|
|
11
|
+
export { BASE_PARTICLES, FLOOR_Y, HOLD_MARGIN, STACKED_QUERY, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, editShader, glslArray, glslFloat, glslVec, hold, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, packShapes, presenceOf, progressOf, projectToScreen, sectionSpan, smoothstep, stageAt, stepAt, wrapMain };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxfront/scene",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "The scroll-driven WebGL particle scene behind the uxfront.com family of homepages: a pluggable formation pipeline, a formation catalog and a framework-agnostic scroll controller.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"particles",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"webgl",
|
|
9
9
|
"webgl2"
|
|
10
10
|
],
|
|
11
|
-
"homepage": "https://
|
|
11
|
+
"homepage": "https://uxfront.com",
|
|
12
12
|
"bugs": "https://github.com/uxfront-com/uxfront/issues",
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|