@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,103 @@
|
|
|
1
|
+
import { Vec2, Vec3 } from "./math.js";
|
|
2
|
+
//#region src/gl/types.d.ts
|
|
3
|
+
export interface StageView {
|
|
4
|
+
eye: Vec3;
|
|
5
|
+
target: Vec3;
|
|
6
|
+
/** Vertical field of view in degrees. */
|
|
7
|
+
fov: number;
|
|
8
|
+
/** Half extents (world units) around the target that must stay in frame. */
|
|
9
|
+
span: Vec2;
|
|
10
|
+
/** Lens shift in NDC: moves the formation beside the copy. */
|
|
11
|
+
shift: Vec2;
|
|
12
|
+
}
|
|
13
|
+
export interface FormationViews {
|
|
14
|
+
/** Wide landscape screens: the formation sits beside the copy. */
|
|
15
|
+
desktop: StageView;
|
|
16
|
+
/** Everything else (see `STACKED_QUERY`): the formation holds the top, the copy scrolls over. */
|
|
17
|
+
mobile: StageView;
|
|
18
|
+
}
|
|
19
|
+
/** Post-processing, blended across the transition between two formations. */
|
|
20
|
+
export interface FormationLook {
|
|
21
|
+
bloom: number;
|
|
22
|
+
/** Light-trail persistence, 0 (none) to 1. */
|
|
23
|
+
trail: number;
|
|
24
|
+
exposure: number;
|
|
25
|
+
/** Strength of the mirror-floor reflection. */
|
|
26
|
+
reflect: number;
|
|
27
|
+
}
|
|
28
|
+
/** Where a formation stands in the scroll. */
|
|
29
|
+
export interface FormationProgress {
|
|
30
|
+
/** Scene stage: a formation index plus the progress of the morph to the next one. */
|
|
31
|
+
stage: number;
|
|
32
|
+
/** Progress through the formation while its section is pinned: 0 before, 1 after. */
|
|
33
|
+
local: number;
|
|
34
|
+
/** 0 → 1 while the formation's section scrolls in, 1 from then on. */
|
|
35
|
+
approach: number;
|
|
36
|
+
/** 1 while the formation is held, fading to 0 across the morphs on either side. */
|
|
37
|
+
presence: number;
|
|
38
|
+
/** Engine clock in seconds. It only runs with motion enabled. */
|
|
39
|
+
time: number;
|
|
40
|
+
}
|
|
41
|
+
export interface FormationFrame extends FormationProgress {
|
|
42
|
+
/** Seconds since the last frame, whether or not motion is enabled. */
|
|
43
|
+
dt: number;
|
|
44
|
+
motion: boolean;
|
|
45
|
+
/** Viewport heights scrolled since the last frame, in either direction. */
|
|
46
|
+
scrolled: number;
|
|
47
|
+
}
|
|
48
|
+
/** A DOM label pinned to a point of a formation (`data-anchor` on the element). */
|
|
49
|
+
export interface AnchorDef {
|
|
50
|
+
/** Local to the formation; the scene prefixes it with the formation key (`plates:0`). */
|
|
51
|
+
id: string;
|
|
52
|
+
/** Writes the world position; returns extra visibility in [0, 1]. */
|
|
53
|
+
place(progress: FormationProgress, out: Vec3): number;
|
|
54
|
+
/** Updates the label's content every frame while the formation shows. */
|
|
55
|
+
render?(el: HTMLElement, progress: FormationProgress): void;
|
|
56
|
+
}
|
|
57
|
+
/** The particle program's uniforms, as a formation sees them. */
|
|
58
|
+
export interface Uniforms {
|
|
59
|
+
readonly gl: WebGL2RenderingContext;
|
|
60
|
+
/** Location of the formation's own `$name` uniform, or null if the compiler dropped it. */
|
|
61
|
+
get: (name: string) => WebGLUniformLocation | null;
|
|
62
|
+
}
|
|
63
|
+
/** The GPU half of a formation, loaded once the page is idle. */
|
|
64
|
+
export interface FormationShader {
|
|
65
|
+
/**
|
|
66
|
+
* GLSL for the particle vertex shader. Identifiers written `$name` are
|
|
67
|
+
* private to the formation (the scene prefixes them with its key), and it
|
|
68
|
+
* must define `Particle $main(uint id, float sel, Frame f)`: the position,
|
|
69
|
+
* colour, size and reflectivity of particle `id`. `sel` spreads evenly over
|
|
70
|
+
* [0, 1) across the particles, to split them between the parts of a formation.
|
|
71
|
+
*/
|
|
72
|
+
glsl: string;
|
|
73
|
+
/** Uploads uniforms that never change. The particle program is bound. */
|
|
74
|
+
setup?(uniforms: Uniforms): void;
|
|
75
|
+
/** Uploads per-frame uniforms. The particle program is bound. */
|
|
76
|
+
update?(uniforms: Uniforms, frame: FormationFrame): void;
|
|
77
|
+
}
|
|
78
|
+
export interface FormationDef {
|
|
79
|
+
/** Unique within a scene. Letters and digits only: it namespaces GLSL identifiers. */
|
|
80
|
+
key: string;
|
|
81
|
+
/** Shown in the HUD while the formation is held. */
|
|
82
|
+
label: string;
|
|
83
|
+
views: FormationViews;
|
|
84
|
+
look?: Partial<FormationLook>;
|
|
85
|
+
anchors?: AnchorDef[];
|
|
86
|
+
/** Loads the shader. Use a dynamic `import()`, so the GLSL stays out of the page's bundle. */
|
|
87
|
+
shader: () => Promise<FormationShader>;
|
|
88
|
+
}
|
|
89
|
+
export interface Formation extends FormationDef {
|
|
90
|
+
look: FormationLook;
|
|
91
|
+
anchors: AnchorDef[];
|
|
92
|
+
}
|
|
93
|
+
type DeepPartial<T> = { [K in keyof T]?: T[K] extends number[] ? T[K] : DeepPartial<T[K]>; };
|
|
94
|
+
/** What every catalog formation accepts. */
|
|
95
|
+
export interface FormationOptions {
|
|
96
|
+
label: string;
|
|
97
|
+
/** Needed only to show the same formation twice in one scene. */
|
|
98
|
+
key?: string;
|
|
99
|
+
/** Overrides the framing, e.g. to put the formation on the other side of the copy. */
|
|
100
|
+
views?: DeepPartial<FormationViews>;
|
|
101
|
+
look?: Partial<FormationLook>;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Mat4, Vec2, Vec3, clamp, damp, lerp, lerp3, projectToScreen, smoothstep } from "./gl/math.js";
|
|
2
|
+
import { AnchorDef, Formation, FormationDef, FormationFrame, FormationLook, FormationOptions, FormationProgress, FormationShader, FormationViews, StageView, Uniforms } from "./gl/types.js";
|
|
3
|
+
import { Experience, ExperienceOptions, ExperienceState, GlStatus, createExperience, initialExperienceState } from "./experience.js";
|
|
4
|
+
import { ShaderPart, composeParticleShader, namespaceGlsl } from "./gl/compose.js";
|
|
5
|
+
import { BASE_PARTICLES, FLOOR_Y } from "./gl/constants.js";
|
|
6
|
+
import { defineFormation, mergeViews } from "./gl/formation.js";
|
|
7
|
+
import { glslFloat } from "./gl/glsl.js";
|
|
8
|
+
import { SectionSpan, approachOf, localOf, presenceOf, progressOf, stageAt } from "./gl/stage.js";
|
|
9
|
+
import { STACKED_QUERY } from "./layout.js";
|
|
10
|
+
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, type Mat4, STACKED_QUERY, type SectionSpan, type ShaderPart, type StageView, type Uniforms, type Vec2, type Vec3, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslFloat, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, presenceOf, progressOf, projectToScreen, smoothstep, stageAt };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { clamp, damp, lerp, lerp3, projectToScreen, smoothstep } from "./gl/math.js";
|
|
2
|
+
import { approachOf, localOf, presenceOf, progressOf, stageAt } from "./gl/stage.js";
|
|
3
|
+
import { createExperience, initialExperienceState } from "./experience.js";
|
|
4
|
+
import { BASE_PARTICLES, FLOOR_Y } from "./gl/constants.js";
|
|
5
|
+
import { glslFloat } from "./gl/glsl.js";
|
|
6
|
+
import { composeParticleShader, namespaceGlsl } from "./gl/compose.js";
|
|
7
|
+
import { defineFormation, mergeViews } from "./gl/formation.js";
|
|
8
|
+
import { STACKED_QUERY } from "./layout.js";
|
|
9
|
+
export { BASE_PARTICLES, FLOOR_Y, STACKED_QUERY, approachOf, clamp, composeParticleShader, createExperience, damp, defineFormation, glslFloat, initialExperienceState, lerp, lerp3, localOf, mergeViews, namespaceGlsl, presenceOf, progressOf, projectToScreen, smoothstep, stageAt };
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/layout.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Portrait, squarish and small screens stack the formation above the copy,
|
|
4
|
+
* except wide landscape phones, which keep it beside the copy. The engine
|
|
5
|
+
* frames its camera with this query and the `@uxfront/ui` components lay out
|
|
6
|
+
* their copy with the same media query: keep them identical.
|
|
7
|
+
*/
|
|
8
|
+
export declare const STACKED_QUERY = "(max-aspect-ratio: 5/4), (max-width: 1099px) and (max-aspect-ratio: 8/5)";
|
|
9
|
+
//#endregion
|
package/dist/layout.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/layout.ts
|
|
2
|
+
/**
|
|
3
|
+
* Portrait, squarish and small screens stack the formation above the copy,
|
|
4
|
+
* except wide landscape phones, which keep it beside the copy. The engine
|
|
5
|
+
* frames its camera with this query and the `@uxfront/ui` components lay out
|
|
6
|
+
* their copy with the same media query: keep them identical.
|
|
7
|
+
*/
|
|
8
|
+
const STACKED_QUERY = "(max-aspect-ratio: 5/4), (max-width: 1099px) and (max-aspect-ratio: 8/5)";
|
|
9
|
+
//#endregion
|
|
10
|
+
export { STACKED_QUERY };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uxfront/scene",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"keywords": [
|
|
6
|
+
"particles",
|
|
7
|
+
"scroll",
|
|
8
|
+
"webgl",
|
|
9
|
+
"webgl2"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/uxfront-com/uxfront/tree/main/packages/scene#readme",
|
|
12
|
+
"bugs": "https://github.com/uxfront-com/uxfront/issues",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/uxfront-com/uxfront.git",
|
|
17
|
+
"directory": "packages/scene"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./formations": {
|
|
30
|
+
"types": "./dist/formations/index.d.ts",
|
|
31
|
+
"default": "./dist/formations/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./package.json": "./package.json"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"lenis": "^1.3.26"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@uxfront/typescript-config": "0.1.0",
|
|
43
|
+
"tsdown": "^0.23.0",
|
|
44
|
+
"vitest": "^5.0.1"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsdown",
|
|
48
|
+
"check-types": "tsc --noEmit",
|
|
49
|
+
"test": "vitest run"
|
|
50
|
+
}
|
|
51
|
+
}
|