@uxfront/scene 0.1.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/README.md +128 -0
- package/dist/experience.d.ts +40 -0
- package/dist/experience.js +306 -0
- package/dist/formations/corridor/index.d.ts +8 -0
- package/dist/formations/corridor/index.js +52 -0
- package/dist/formations/corridor/shader.js +37 -0
- package/dist/formations/index.d.ts +11 -0
- package/dist/formations/index.js +11 -0
- package/dist/formations/ink/index.d.ts +10 -0
- package/dist/formations/ink/index.js +53 -0
- package/dist/formations/ink/shader.js +177 -0
- package/dist/formations/monolith/index.d.ts +5 -0
- package/dist/formations/monolith/index.js +49 -0
- package/dist/formations/monolith/mark.js +89 -0
- package/dist/formations/monolith/shader.js +120 -0
- package/dist/formations/plates/art.d.ts +46 -0
- package/dist/formations/plates/art.js +238 -0
- package/dist/formations/plates/geometry.d.ts +5 -0
- package/dist/formations/plates/geometry.js +8 -0
- package/dist/formations/plates/index.d.ts +13 -0
- package/dist/formations/plates/index.js +67 -0
- package/dist/formations/plates/shader.js +97 -0
- package/dist/formations/prism/geometry.d.ts +4 -0
- package/dist/formations/prism/geometry.js +15 -0
- package/dist/formations/prism/index.d.ts +9 -0
- package/dist/formations/prism/index.js +64 -0
- package/dist/formations/prism/shader.js +140 -0
- package/dist/formations/tokens/geometry.d.ts +4 -0
- package/dist/formations/tokens/geometry.js +22 -0
- package/dist/formations/tokens/index.d.ts +18 -0
- package/dist/formations/tokens/index.js +79 -0
- package/dist/formations/tokens/shader.js +125 -0
- package/dist/gl/compose.d.ts +14 -0
- package/dist/gl/compose.js +52 -0
- package/dist/gl/constants.d.ts +6 -0
- package/dist/gl/constants.js +7 -0
- package/dist/gl/engine.js +559 -0
- package/dist/gl/formation.d.ts +7 -0
- package/dist/gl/formation.js +39 -0
- package/dist/gl/glsl.d.ts +9 -0
- package/dist/gl/glsl.js +419 -0
- package/dist/gl/math.d.ts +16 -0
- package/dist/gl/math.js +102 -0
- package/dist/gl/stage.d.ts +28 -0
- package/dist/gl/stage.js +55 -0
- package/dist/gl/types.d.ts +103 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +9 -0
- package/dist/layout.d.ts +9 -0
- package/dist/layout.js +10 -0
- package/package.json +51 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Formation, FormationOptions } from "../../gl/types.js";
|
|
2
|
+
import { Theme } from "./geometry.js";
|
|
3
|
+
//#region src/formations/tokens/index.d.ts
|
|
4
|
+
export interface TokensFormation extends Formation {
|
|
5
|
+
readonly themes: readonly Theme[];
|
|
6
|
+
/**
|
|
7
|
+
* Lands the whole matrix on the next theme. The shader eases there, so the
|
|
8
|
+
* change sweeps across as one more wave.
|
|
9
|
+
*/
|
|
10
|
+
next(): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A framed matrix of design tokens, re-themed by slow waves of configuration.
|
|
14
|
+
* Anchor `tokens:theme` sits above the frame's top-left corner and writes the
|
|
15
|
+
* current theme's name into its `[data-theme-name]` element.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tokens(options: FormationOptions): TokensFormation;
|
|
18
|
+
//#endregion
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { defineFormation, mergeViews } from "../../gl/formation.js";
|
|
2
|
+
import { THEMES, TOKEN_FRAME, skipThemes, themePhase, themeStep } from "./geometry.js";
|
|
3
|
+
//#region src/formations/tokens/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* A framed matrix of design tokens, re-themed by slow waves of configuration.
|
|
6
|
+
* Anchor `tokens:theme` sits above the frame's top-left corner and writes the
|
|
7
|
+
* current theme's name into its `[data-theme-name]` element.
|
|
8
|
+
*/
|
|
9
|
+
function tokens(options) {
|
|
10
|
+
const state = {
|
|
11
|
+
shift: 0,
|
|
12
|
+
time: 0,
|
|
13
|
+
local: 0
|
|
14
|
+
};
|
|
15
|
+
const formation = defineFormation({
|
|
16
|
+
key: options.key ?? "tokens",
|
|
17
|
+
label: options.label,
|
|
18
|
+
views: mergeViews({
|
|
19
|
+
desktop: {
|
|
20
|
+
eye: [
|
|
21
|
+
-1.9,
|
|
22
|
+
-2.7,
|
|
23
|
+
10.2
|
|
24
|
+
],
|
|
25
|
+
target: [
|
|
26
|
+
0,
|
|
27
|
+
.1,
|
|
28
|
+
0
|
|
29
|
+
],
|
|
30
|
+
fov: 30,
|
|
31
|
+
span: [3.3, 2.2],
|
|
32
|
+
shift: [-.42, .02]
|
|
33
|
+
},
|
|
34
|
+
mobile: {
|
|
35
|
+
eye: [
|
|
36
|
+
-1.2,
|
|
37
|
+
-2,
|
|
38
|
+
8
|
|
39
|
+
],
|
|
40
|
+
target: [
|
|
41
|
+
0,
|
|
42
|
+
.1,
|
|
43
|
+
0
|
|
44
|
+
],
|
|
45
|
+
fov: 34,
|
|
46
|
+
span: [3.1, 2.1],
|
|
47
|
+
shift: [0, .5]
|
|
48
|
+
}
|
|
49
|
+
}, options.views),
|
|
50
|
+
look: {
|
|
51
|
+
bloom: 1,
|
|
52
|
+
...options.look
|
|
53
|
+
},
|
|
54
|
+
anchors: [{
|
|
55
|
+
id: "theme",
|
|
56
|
+
place: (_, out) => {
|
|
57
|
+
out[0] = -TOKEN_FRAME[0];
|
|
58
|
+
out[1] = TOKEN_FRAME[1] + .34;
|
|
59
|
+
out[2] = 0;
|
|
60
|
+
return 1;
|
|
61
|
+
},
|
|
62
|
+
render: (el, { time, local }) => {
|
|
63
|
+
const label = el.querySelector("[data-theme-name]");
|
|
64
|
+
if (!label) return;
|
|
65
|
+
const name = THEMES[themeStep(themePhase(time, local, state.shift)) % THEMES.length];
|
|
66
|
+
if (label.textContent !== name) label.textContent = name;
|
|
67
|
+
}
|
|
68
|
+
}],
|
|
69
|
+
shader: () => import("./shader.js").then((m) => m.createShader(state))
|
|
70
|
+
});
|
|
71
|
+
return Object.assign(formation, {
|
|
72
|
+
themes: THEMES,
|
|
73
|
+
next() {
|
|
74
|
+
state.shift = skipThemes(state, 1);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { tokens };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { damp } from "../../gl/math.js";
|
|
2
|
+
import { glslFloat } from "../../gl/glsl.js";
|
|
3
|
+
import { TOKEN_FRAME, TOKEN_PITCH } from "./geometry.js";
|
|
4
|
+
//#region src/formations/tokens/shader.ts
|
|
5
|
+
const glsl = `
|
|
6
|
+
const float $PITCH = ${glslFloat(TOKEN_PITCH)};
|
|
7
|
+
const vec2 $FRAME = vec2(${glslFloat(TOKEN_FRAME[0])}, ${glslFloat(TOKEN_FRAME[1])});
|
|
8
|
+
const uint $COLS = 12u;
|
|
9
|
+
const uint $CELLS = 84u;
|
|
10
|
+
|
|
11
|
+
uniform float $themeShift;
|
|
12
|
+
|
|
13
|
+
const vec3 $AURORA[7] = vec3[7](
|
|
14
|
+
vec3(0.55, 0.3, 1.0), vec3(0.35, 0.35, 1.0), vec3(0.2, 0.55, 1.0), vec3(0.15, 0.85, 1.0),
|
|
15
|
+
vec3(0.15, 1.0, 0.75), vec3(0.35, 1.0, 0.4), vec3(0.7, 1.0, 0.25)
|
|
16
|
+
);
|
|
17
|
+
const vec3 $EMBER[7] = vec3[7](
|
|
18
|
+
vec3(1.0, 0.3, 0.55), vec3(1.0, 0.2, 0.2), vec3(1.0, 0.35, 0.1), vec3(1.0, 0.55, 0.1),
|
|
19
|
+
vec3(1.0, 0.75, 0.15), vec3(1.0, 0.9, 0.35), vec3(0.85, 0.25, 1.0)
|
|
20
|
+
);
|
|
21
|
+
const vec3 $MONOTONE[7] = vec3[7](
|
|
22
|
+
vec3(0.8, 0.85, 1.0), vec3(0.8, 0.85, 1.0), vec3(0.8, 0.85, 1.0), vec3(1.0, 0.42, 0.2),
|
|
23
|
+
vec3(0.8, 0.85, 1.0), vec3(0.8, 0.85, 1.0), vec3(0.8, 0.85, 1.0)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
vec3 $themeColor(int theme, int row) {
|
|
27
|
+
if (theme == 0) return $AURORA[row];
|
|
28
|
+
if (theme == 1) return $EMBER[row];
|
|
29
|
+
return $MONOTONE[row];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Particle $main(uint id, float sel, Frame f) {
|
|
33
|
+
float local = f.local;
|
|
34
|
+
float time = f.time;
|
|
35
|
+
uint s = seedOf(id, 0xB5297A4Du);
|
|
36
|
+
float a = rnd(s);
|
|
37
|
+
float b = rnd(s);
|
|
38
|
+
float c = rnd(s);
|
|
39
|
+
Particle P = blank();
|
|
40
|
+
|
|
41
|
+
if (sel < 0.86) {
|
|
42
|
+
uint cell = id % $CELLS;
|
|
43
|
+
float col = float(cell % $COLS);
|
|
44
|
+
float row = float(cell / $COLS);
|
|
45
|
+
vec2 center = vec2((col - ${glslFloat(11 / 2)}) * $PITCH, (${glslFloat(3)} - row) * $PITCH);
|
|
46
|
+
float ph = col * 0.5 + row * 0.8 - time * 0.8 - local * 5.0;
|
|
47
|
+
float w = 0.5 + 0.5 * sin(ph);
|
|
48
|
+
float shapeW = smoothstep(0.15, 0.85, 0.5 + 0.5 * sin(ph * 0.5 + 1.2 + row * 0.35 - col * 0.1));
|
|
49
|
+
// Superellipse exponent: star (n < 1), circle (2), squircle, square (8+).
|
|
50
|
+
float n = exp2(mix(-0.6, 3.3, shapeW));
|
|
51
|
+
float size = mix(0.075, 0.185, w);
|
|
52
|
+
float th = a * TAU;
|
|
53
|
+
vec2 cs = vec2(cos(th), sin(th));
|
|
54
|
+
float R = pow(pow(abs(cs.x), n) + pow(abs(cs.y), n), -1.0 / n);
|
|
55
|
+
bool edge = b < 0.32;
|
|
56
|
+
float rho = edge ? 1.0 : sqrt(c);
|
|
57
|
+
vec2 q = center + size * rho * R * cs;
|
|
58
|
+
P.pos = vec3(q, w * 0.34);
|
|
59
|
+
|
|
60
|
+
float themeT = time * 0.06 + (col + row) * 0.04 + local * 0.75 + $themeShift;
|
|
61
|
+
float ti = floor(themeT);
|
|
62
|
+
float tf = smoothstep(0.7, 1.0, themeT - ti);
|
|
63
|
+
int r = int(row);
|
|
64
|
+
vec3 hue = mix($themeColor(int(mod(ti, 3.0)), r), $themeColor(int(mod(ti + 1.0, 3.0)), r), tf);
|
|
65
|
+
float light = mix(0.3, 1.25, col / ${glslFloat(11)});
|
|
66
|
+
P.col = hue * light * (edge ? 0.2 : 0.075) * (0.75 + 0.5 * w);
|
|
67
|
+
P.size = 0.8;
|
|
68
|
+
} else if (sel < 0.965) {
|
|
69
|
+
// The frame: trim box, crop marks, registration marks and a ruler.
|
|
70
|
+
float sub = (sel - 0.86) / 0.105;
|
|
71
|
+
vec2 q;
|
|
72
|
+
float br = 0.5;
|
|
73
|
+
if (sub < 0.45) {
|
|
74
|
+
q = rrectPoint(vec4(0.0, 0.0, $FRAME), 0.0, a);
|
|
75
|
+
} else if (sub < 0.65) {
|
|
76
|
+
int k = min(int(a * 8.0), 7);
|
|
77
|
+
vec2 corner = vec2((k & 2) == 0 ? -1.0 : 1.0, (k & 4) == 0 ? -1.0 : 1.0) * $FRAME;
|
|
78
|
+
float len = mix(0.12, 0.45, b);
|
|
79
|
+
q = (k & 1) == 0 ? corner + vec2(sign(corner.x) * len, 0.0) : corner + vec2(0.0, sign(corner.y) * len);
|
|
80
|
+
br = 0.8;
|
|
81
|
+
} else if (sub < 0.85) {
|
|
82
|
+
int k = min(int(a * 4.0), 3);
|
|
83
|
+
vec2 m = k == 0 ? vec2(0.0, $FRAME.y + 0.32)
|
|
84
|
+
: k == 1 ? vec2(0.0, -$FRAME.y - 0.32)
|
|
85
|
+
: k == 2 ? vec2($FRAME.x + 0.32, 0.0)
|
|
86
|
+
: vec2(-$FRAME.x - 0.32, 0.0);
|
|
87
|
+
float t = c * 2.0 - 1.0;
|
|
88
|
+
q = b < 0.6 ? m + 0.1 * vec2(cos(c * TAU), sin(c * TAU))
|
|
89
|
+
: b < 0.8 ? m + vec2(t * 0.17, 0.0)
|
|
90
|
+
: m + vec2(0.0, t * 0.17);
|
|
91
|
+
br = 0.7;
|
|
92
|
+
} else {
|
|
93
|
+
float x = (a * 2.0 - 1.0) * $FRAME.x;
|
|
94
|
+
float tick = floor(x / ($PITCH * 0.25) + 0.5) * $PITCH * 0.25;
|
|
95
|
+
float major = step(abs(fract(tick / $PITCH + 0.5) - 0.5), 0.01);
|
|
96
|
+
q = vec2(tick, $FRAME.y + 0.06 + b * mix(0.05, 0.13, major));
|
|
97
|
+
br = 0.45;
|
|
98
|
+
}
|
|
99
|
+
P.pos = vec3(q, 0.0);
|
|
100
|
+
P.col = vec3(0.85, 0.87, 0.95) * br * 0.12;
|
|
101
|
+
P.size = 0.7;
|
|
102
|
+
} else {
|
|
103
|
+
vec3 p = vec3(mix(-4.5, 4.5, a), mix(-3.0, 3.0, b), mix(-2.0, 2.5, c));
|
|
104
|
+
p.y = mod(p.y + time * 0.03 + 3.0, 6.0) - 3.0;
|
|
105
|
+
P.pos = p;
|
|
106
|
+
P.col = vec3(0.7, 0.72, 0.9) * 0.04;
|
|
107
|
+
P.size = 0.9;
|
|
108
|
+
}
|
|
109
|
+
return P;
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
function createShader(state) {
|
|
113
|
+
let shift = state.shift;
|
|
114
|
+
return {
|
|
115
|
+
glsl,
|
|
116
|
+
update({ gl, get }, frame) {
|
|
117
|
+
state.time = frame.time;
|
|
118
|
+
state.local = frame.local;
|
|
119
|
+
shift = frame.motion ? damp(shift, state.shift, 2.5, frame.dt) : state.shift;
|
|
120
|
+
gl.uniform1f(get("themeShift"), shift);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { createShader };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/gl/compose.d.ts
|
|
2
|
+
export interface ShaderPart {
|
|
3
|
+
key: string;
|
|
4
|
+
glsl: string;
|
|
5
|
+
}
|
|
6
|
+
/** Rewrites a formation's `$name` identifiers to `key_name`. */
|
|
7
|
+
export declare function namespaceGlsl(key: string, glsl: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Builds the particle vertex shader: the shared helpers, every formation
|
|
10
|
+
* (namespaced by its key), a dispatcher that picks formation `k`, and the
|
|
11
|
+
* pipeline's `main()`, which morphs between neighbouring formations.
|
|
12
|
+
*/
|
|
13
|
+
export declare function composeParticleShader(parts: readonly ShaderPart[]): string;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FLOOR_Y } from "./constants.js";
|
|
2
|
+
import { COMMON, PARTICLE_MAIN, PARTICLE_TYPES, PARTICLE_UNIFORMS, glslFloat } from "./glsl.js";
|
|
3
|
+
//#region src/gl/compose.ts
|
|
4
|
+
const PRIVATE = /\$([A-Za-z][A-Za-z0-9_]*)/g;
|
|
5
|
+
const MAIN = /\bParticle\s+\$main\s*\(/;
|
|
6
|
+
/** Rewrites a formation's `$name` identifiers to `key_name`. */
|
|
7
|
+
function namespaceGlsl(key, glsl) {
|
|
8
|
+
const out = glsl.replace(PRIVATE, (_, name) => `${key}_${name}`);
|
|
9
|
+
if (out.includes("$")) throw new Error(`Formation "${key}": "$" must start a private identifier, like $main.`);
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds the particle vertex shader: the shared helpers, every formation
|
|
14
|
+
* (namespaced by its key), a dispatcher that picks formation `k`, and the
|
|
15
|
+
* pipeline's `main()`, which morphs between neighbouring formations.
|
|
16
|
+
*/
|
|
17
|
+
function composeParticleShader(parts) {
|
|
18
|
+
if (parts.length === 0) throw new Error("A scene needs at least one formation.");
|
|
19
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20
|
+
for (const { key, glsl } of parts) {
|
|
21
|
+
if (seen.has(key)) throw new Error(`Formation key "${key}" is used twice in one scene.`);
|
|
22
|
+
seen.add(key);
|
|
23
|
+
if (!MAIN.test(glsl)) throw new Error(`Formation "${key}" must define Particle $main(uint id, float sel, Frame f).`);
|
|
24
|
+
}
|
|
25
|
+
const dispatch = parts.map(({ key }, k) => k === parts.length - 1 ? ` return ${key}_main(id, sel, frameOf(${k}));` : ` if (k == ${k}) return ${key}_main(id, sel, frameOf(${k}));`).join("\n");
|
|
26
|
+
return `#version 300 es
|
|
27
|
+
precision highp float;
|
|
28
|
+
precision highp int;
|
|
29
|
+
${PARTICLE_UNIFORMS}
|
|
30
|
+
out vec3 vColor;
|
|
31
|
+
${COMMON}
|
|
32
|
+
${PARTICLE_TYPES}
|
|
33
|
+
const float FLOOR_Y = ${glslFloat(FLOOR_Y)};
|
|
34
|
+
const int LAST_STAGE = ${parts.length - 1};
|
|
35
|
+
|
|
36
|
+
Frame frameOf(int k) {
|
|
37
|
+
float fk = float(k);
|
|
38
|
+
Frame f;
|
|
39
|
+
f.local = uStage > fk + 0.0001 ? 1.0 : (uStage < fk - 0.0001 ? 0.0 : uLocal);
|
|
40
|
+
f.approach = clamp(uStage - fk + 1.0, 0.0, 1.0);
|
|
41
|
+
f.time = uTime;
|
|
42
|
+
return f;
|
|
43
|
+
}
|
|
44
|
+
${parts.map(({ key, glsl }) => `\n// ${key} ${"-".repeat(70 - key.length)}\n${namespaceGlsl(key, glsl)}`).join("\n")}
|
|
45
|
+
|
|
46
|
+
Particle formation(int k, uint id, float sel) {
|
|
47
|
+
${dispatch}
|
|
48
|
+
}
|
|
49
|
+
${PARTICLE_MAIN}`;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { composeParticleShader, namespaceGlsl };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/gl/constants.d.ts
|
|
2
|
+
/** Height of the mirror floor the intro rises from and reflections fold around. */
|
|
3
|
+
export declare const FLOOR_Y = -1.35;
|
|
4
|
+
/** Particles at the highest quality. Brightness is normalized to this count. */
|
|
5
|
+
export declare const BASE_PARTICLES: number;
|
|
6
|
+
//#endregion
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/gl/constants.ts
|
|
2
|
+
/** Height of the mirror floor the intro rises from and reflections fold around. */
|
|
3
|
+
const FLOOR_Y = -1.35;
|
|
4
|
+
/** Particles at the highest quality. Brightness is normalized to this count. */
|
|
5
|
+
const BASE_PARTICLES = 262144;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { BASE_PARTICLES, FLOOR_Y };
|