@kerf-js/keel 0.0.0-stage → 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/LICENSE +16 -0
- package/README.md +306 -2
- package/package.json +59 -3
- package/src/blend-inset.ts +79 -0
- package/src/blend.ts +120 -0
- package/src/client.d.ts +9 -0
- package/src/generate/bust.ts +24 -0
- package/src/generate/bust.worker.ts +4 -0
- package/src/generate/pack.ts +69 -0
- package/src/generate/plate.ts +51 -0
- package/src/generate/plate.worker.ts +4 -0
- package/src/generate/serve.ts +56 -0
- package/src/generate/surface.ts +16 -0
- package/src/generate/surface.worker.ts +4 -0
- package/src/generate.ts +133 -0
- package/src/governor.ts +87 -0
- package/src/index.d.ts +15 -0
- package/src/index.mjs +63 -0
- package/src/lit.d.ts +384 -0
- package/src/paint-live.ts +60 -0
- package/src/paint-recipe.d.mts +29 -0
- package/src/paint-recipe.mjs +29 -0
- package/src/paint-worker.mjs +20 -0
- package/src/paint.d.mts +37 -0
- package/src/paint.mjs +180 -0
- package/src/runtime.ts +35 -0
- package/src/scene.ts +289 -0
- package/src/stage.ts +192 -0
- package/vendor/LICENSE +21 -0
- package/vendor/LICENSE-modules +21 -0
- package/vendor/NOTICE +24 -0
- package/vendor/README.md +13 -0
- package/vendor/lit.d.mts +1 -0
- package/vendor/lit.mjs +2 -0
- package/vendor/lock.json +177 -0
- package/vendor/modules/band/events.d.ts +20 -0
- package/vendor/modules/band/index.d.ts +29 -0
- package/vendor/modules/band/player.d.ts +43 -0
- package/vendor/modules/band/roll.d.ts +14 -0
- package/vendor/modules/band/score.d.ts +45 -0
- package/vendor/modules/band/styles.data.d.ts +37 -0
- package/vendor/modules/band/voices.d.ts +33 -0
- package/vendor/modules/band.d.mts +1 -0
- package/vendor/modules/band.mjs +2 -0
- package/vendor/modules/butterflies/butterflies.glsl.d.ts +2 -0
- package/vendor/modules/butterflies/flight.d.ts +68 -0
- package/vendor/modules/butterflies/index.d.ts +79 -0
- package/vendor/modules/butterflies/wing.d.ts +38 -0
- package/vendor/modules/butterflies.d.mts +1 -0
- package/vendor/modules/butterflies.inputs.json +73 -0
- package/vendor/modules/butterflies.mjs +39 -0
- package/vendor/modules/camera-rail/index.d.ts +113 -0
- package/vendor/modules/camera-rail.d.mts +1 -0
- package/vendor/modules/camera-rail.mjs +2 -0
- package/vendor/modules/device-profile/index.d.ts +47 -0
- package/vendor/modules/device-profile.d.mts +1 -0
- package/vendor/modules/device-profile.mjs +2 -0
- package/vendor/modules/lit-finish/dress.d.ts +34 -0
- package/vendor/modules/lit-finish/finish.glsl.d.ts +15 -0
- package/vendor/modules/lit-finish/index.d.ts +33 -0
- package/vendor/modules/lit-finish/lit.d.ts +52 -0
- package/vendor/modules/lit-finish/pass.d.ts +35 -0
- package/vendor/modules/lit-finish/settings.d.ts +88 -0
- package/vendor/modules/lit-finish.d.mts +1 -0
- package/vendor/modules/lit-finish.inputs.json +200 -0
- package/vendor/modules/lit-finish.mjs +267 -0
- package/vendor/modules/look/index.d.ts +159 -0
- package/vendor/modules/look.d.mts +1 -0
- package/vendor/modules/look.inputs.json +23 -0
- package/vendor/modules/look.mjs +2 -0
- package/vendor/modules/motes/index.d.ts +83 -0
- package/vendor/modules/motes/motes.glsl.d.ts +9 -0
- package/vendor/modules/motes/place.d.ts +59 -0
- package/vendor/modules/motes.d.mts +1 -0
- package/vendor/modules/motes.inputs.json +116 -0
- package/vendor/modules/motes.mjs +68 -0
- package/vendor/modules/plate-painter/dab.d.ts +44 -0
- package/vendor/modules/plate-painter/exact.d.ts +19 -0
- package/vendor/modules/plate-painter/foliage.d.ts +4 -0
- package/vendor/modules/plate-painter/gpu.d.ts +65 -0
- package/vendor/modules/plate-painter/index.d.ts +14 -0
- package/vendor/modules/plate-painter/paint.glsl.d.ts +14 -0
- package/vendor/modules/plate-painter/plan.d.ts +42 -0
- package/vendor/modules/plate-painter/recipe.d.ts +136 -0
- package/vendor/modules/plate-painter/scene.d.ts +4 -0
- package/vendor/modules/plate-painter.d.mts +1 -0
- package/vendor/modules/plate-painter.inputs.json +50 -0
- package/vendor/modules/plate-painter.mjs +384 -0
- package/vendor/modules/portrait/body.d.ts +25 -0
- package/vendor/modules/portrait/bust.d.ts +67 -0
- package/vendor/modules/portrait/cap.d.ts +12 -0
- package/vendor/modules/portrait/compile.d.ts +8 -0
- package/vendor/modules/portrait/exact.d.ts +17 -0
- package/vendor/modules/portrait/hair.d.ts +26 -0
- package/vendor/modules/portrait/hand.d.ts +30 -0
- package/vendor/modules/portrait/head.d.ts +18 -0
- package/vendor/modules/portrait/index.d.ts +12 -0
- package/vendor/modules/portrait/mesh.d.ts +24 -0
- package/vendor/modules/portrait/parts.d.ts +33 -0
- package/vendor/modules/portrait/portrait.glsl.d.ts +4 -0
- package/vendor/modules/portrait/render.d.ts +125 -0
- package/vendor/modules/portrait/sdf.d.ts +75 -0
- package/vendor/modules/portrait/settings.d.ts +27 -0
- package/vendor/modules/portrait.d.mts +1 -0
- package/vendor/modules/portrait.inputs.json +111 -0
- package/vendor/modules/portrait.mjs +2 -0
- package/vendor/modules/quality/index.d.ts +130 -0
- package/vendor/modules/quality.d.mts +1 -0
- package/vendor/modules/quality.inputs.json +34 -0
- package/vendor/modules/quality.mjs +2 -0
- package/vendor/modules/scene-blend/blend.d.ts +54 -0
- package/vendor/modules/scene-blend/blend.glsl.d.ts +8 -0
- package/vendor/modules/scene-blend/index.d.ts +25 -0
- package/vendor/modules/scene-blend/lit.d.ts +61 -0
- package/vendor/modules/scene-blend/noise.d.ts +13 -0
- package/vendor/modules/scene-blend/settings.d.ts +63 -0
- package/vendor/modules/scene-blend.d.mts +1 -0
- package/vendor/modules/scene-blend.inputs.json +133 -0
- package/vendor/modules/scene-blend.mjs +2 -0
- package/vendor/modules/section-post/index.d.ts +23 -0
- package/vendor/modules/section-post/lit.d.ts +47 -0
- package/vendor/modules/section-post/noise.d.ts +14 -0
- package/vendor/modules/section-post/post.d.ts +31 -0
- package/vendor/modules/section-post/post.glsl.d.ts +8 -0
- package/vendor/modules/section-post/settings.d.ts +84 -0
- package/vendor/modules/section-post.d.mts +1 -0
- package/vendor/modules/section-post.inputs.json +107 -0
- package/vendor/modules/section-post.mjs +53 -0
- package/vendor/modules/surfaces/exact.d.ts +8 -0
- package/vendor/modules/surfaces/field.d.ts +7 -0
- package/vendor/modules/surfaces/gpu.d.ts +19 -0
- package/vendor/modules/surfaces/index.d.ts +17 -0
- package/vendor/modules/surfaces/paint.d.ts +28 -0
- package/vendor/modules/surfaces/plan.d.ts +39 -0
- package/vendor/modules/surfaces/print.d.ts +55 -0
- package/vendor/modules/surfaces/recipe.d.ts +143 -0
- package/vendor/modules/surfaces/surface.glsl.d.ts +4 -0
- package/vendor/modules/surfaces.d.mts +1 -0
- package/vendor/modules/surfaces.inputs.json +54 -0
- package/vendor/modules/surfaces.mjs +172 -0
- package/vendor/modules/tracks/index.d.ts +66 -0
- package/vendor/modules/tracks.d.mts +1 -0
- package/vendor/modules/tracks.mjs +2 -0
- package/vendor/modules/tree-growth/bend.d.ts +28 -0
- package/vendor/modules/tree-growth/frame.d.ts +60 -0
- package/vendor/modules/tree-growth/index.d.ts +23 -0
- package/vendor/modules/tree-growth/light.d.ts +13 -0
- package/vendor/modules/tree-growth/math.d.ts +19 -0
- package/vendor/modules/tree-growth/model.d.ts +100 -0
- package/vendor/modules/tree-growth/sectors.d.ts +10 -0
- package/vendor/modules/tree-growth/simulation.d.ts +58 -0
- package/vendor/modules/tree-growth/species.d.ts +117 -0
- package/vendor/modules/tree-growth/species.data.d.ts +2 -0
- package/vendor/modules/tree-growth/year.d.ts +38 -0
- package/vendor/modules/tree-growth.d.mts +1 -0
- package/vendor/modules/tree-growth.inputs.json +75 -0
- package/vendor/modules/tree-growth.mjs +2 -0
- package/vendor/modules/tree-render/features.d.ts +9 -0
- package/vendor/modules/tree-render/forest/bake.d.ts +41 -0
- package/vendor/modules/tree-render/forest/cards.d.ts +28 -0
- package/vendor/modules/tree-render/forest/forest.d.ts +156 -0
- package/vendor/modules/tree-render/index.d.ts +52 -0
- package/vendor/modules/tree-render/inputs.d.ts +260 -0
- package/vendor/modules/tree-render/instances.d.ts +66 -0
- package/vendor/modules/tree-render/math.d.ts +8 -0
- package/vendor/modules/tree-render/tree/bark.d.ts +20 -0
- package/vendor/modules/tree-render/tree/leaves.d.ts +29 -0
- package/vendor/modules/tree-render/tree/litter.d.ts +21 -0
- package/vendor/modules/tree-render/tree/ornaments.d.ts +36 -0
- package/vendor/modules/tree-render/tree/roots.d.ts +75 -0
- package/vendor/modules/tree-render/tree/shapes.d.ts +49 -0
- package/vendor/modules/tree-render/tree/tree.d.ts +239 -0
- package/vendor/modules/tree-render/tree/wood.d.ts +27 -0
- package/vendor/modules/tree-render/wind.d.ts +51 -0
- package/vendor/modules/tree-render.d.mts +1 -0
- package/vendor/modules/tree-render.inputs.json +45 -0
- package/vendor/modules/tree-render.mjs +2 -0
- package/vendor/modules/voxel-dither/dither.glsl.d.ts +9 -0
- package/vendor/modules/voxel-dither/index.d.ts +35 -0
- package/vendor/modules/voxel-dither/light.d.ts +33 -0
- package/vendor/modules/voxel-dither/lit.d.ts +86 -0
- package/vendor/modules/voxel-dither/pass.d.ts +46 -0
- package/vendor/modules/voxel-dither/screens.d.ts +21 -0
- package/vendor/modules/voxel-dither/settings.d.ts +307 -0
- package/vendor/modules/voxel-dither/signals.d.ts +35 -0
- package/vendor/modules/voxel-dither.d.mts +1 -0
- package/vendor/modules/voxel-dither.inputs.json +295 -0
- package/vendor/modules/voxel-dither.mjs +452 -0
- package/vendor/modules/world-light/index.d.ts +133 -0
- package/vendor/modules/world-light.d.mts +1 -0
- package/vendor/modules/world-light.inputs.json +68 -0
- package/vendor/modules/world-light.mjs +2 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type PlannedRecipe, type SurfaceRecipe } from "./recipe.js";
|
|
2
|
+
/** Moves whenever the painters would paint the same plan differently, so a stored surface is not reused wrongly. */
|
|
3
|
+
export declare const PAINTER_VERSION = 1;
|
|
4
|
+
/** The most masses a painted ground holds. */
|
|
5
|
+
export declare const MAX_MASSES = 10;
|
|
6
|
+
/** Floats in a plan's uniforms. */
|
|
7
|
+
export declare const UNIFORMS = 232;
|
|
8
|
+
/** Each kind's number, as the digest and the shaders know it. */
|
|
9
|
+
export declare const KINDS: {
|
|
10
|
+
readonly paper: 0;
|
|
11
|
+
readonly knit: 1;
|
|
12
|
+
readonly painted: 2;
|
|
13
|
+
};
|
|
14
|
+
/** The size and seed to paint at. */
|
|
15
|
+
export interface SurfaceSettings {
|
|
16
|
+
/** A whole number from 0. Default 0. */
|
|
17
|
+
readonly seed?: number;
|
|
18
|
+
/** Pixels, 1..4096. Default 1024; the height defaults to the width. */
|
|
19
|
+
readonly width?: number;
|
|
20
|
+
readonly height?: number;
|
|
21
|
+
}
|
|
22
|
+
/** Everything a painter needs, worked out in exact arithmetic. */
|
|
23
|
+
export interface SurfacePlan {
|
|
24
|
+
readonly kind: SurfaceRecipe["kind"];
|
|
25
|
+
readonly width: number;
|
|
26
|
+
readonly height: number;
|
|
27
|
+
readonly depth: number;
|
|
28
|
+
readonly uniforms: Float32Array;
|
|
29
|
+
/** Covers the uniforms, the kind, the size, the depth and `PAINTER_VERSION`. */
|
|
30
|
+
readonly digest: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Plans a surface: validates the recipe and settings and works out every number the painters read.
|
|
34
|
+
*
|
|
35
|
+
* @param recipe What the surface holds.
|
|
36
|
+
* @param settings The seed and the size in pixels.
|
|
37
|
+
* @returns The plan, with its digest.
|
|
38
|
+
*/
|
|
39
|
+
export declare function planSurface(recipe: SurfaceRecipe | PlannedRecipe, settings?: SurfaceSettings): SurfacePlan;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Surface } from "./paint.js";
|
|
2
|
+
/** A 2D context, on the page or off it. */
|
|
3
|
+
export type Context2D = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
4
|
+
/** A canvas the host makes at the size asked. */
|
|
5
|
+
export type CanvasLike = HTMLCanvasElement | OffscreenCanvas;
|
|
6
|
+
/** The fields of a keel/lit texture these helpers set. */
|
|
7
|
+
export interface TextureLike {
|
|
8
|
+
colorSpace: string;
|
|
9
|
+
wrapS: string;
|
|
10
|
+
wrapT: string;
|
|
11
|
+
anisotropy: number;
|
|
12
|
+
needsUpdate: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface DataTextureLike extends TextureLike {
|
|
15
|
+
magFilter: string;
|
|
16
|
+
minFilter: string;
|
|
17
|
+
generateMipmaps: boolean;
|
|
18
|
+
flipY: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** The parts of keel/lit these helpers call. Pass the keel/lit namespace itself. */
|
|
21
|
+
export interface PrintLit<T extends TextureLike, D extends DataTextureLike> {
|
|
22
|
+
readonly CanvasTexture: new (canvas: CanvasLike) => T;
|
|
23
|
+
readonly DataTexture: new (data: Uint8Array, width: number, height: number) => D;
|
|
24
|
+
}
|
|
25
|
+
/** How a print is used: colour (sRGB) or data (roughness, metalness, a mask: no colour space). */
|
|
26
|
+
export interface PrintOptions {
|
|
27
|
+
readonly data?: boolean;
|
|
28
|
+
/** Repeat across the surface instead of clamping at the edges. */
|
|
29
|
+
readonly repeat?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Draws a print: the context, and the canvas's width and height in pixels. */
|
|
32
|
+
export type DrawPrint = (ctx: Context2D, width: number, height: number) => void;
|
|
33
|
+
/** `print(size, draw)`: a texture of what `draw` puts into a fresh canvas of that size. */
|
|
34
|
+
export type Print<T> = (size: number | readonly [number, number], draw: DrawPrint, options?: PrintOptions) => T;
|
|
35
|
+
/**
|
|
36
|
+
* Makes `print(size, draw)`. Draw again later into `texture.image` and set `texture.needsUpdate` to refresh it.
|
|
37
|
+
*
|
|
38
|
+
* @param lit The keel/lit namespace.
|
|
39
|
+
* @param canvasOf Makes a canvas of a size, e.g. `(w, h) => new OffscreenCanvas(w, h)`.
|
|
40
|
+
* @returns The print function.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createPrinter<T extends TextureLike, D extends DataTextureLike>(lit: PrintLit<T, D>, canvasOf: (width: number, height: number) => CanvasLike): Print<T>;
|
|
43
|
+
/** The colour that paints roughness and metalness into a data print: G roughness, B metalness, as lit reads them. */
|
|
44
|
+
export declare function pbr(roughness: number, metalness: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* A surface as two repeating, mipmapped lit textures: `map` (sRGB) and `normalMap` (its height in alpha).
|
|
47
|
+
*
|
|
48
|
+
* @param lit The keel/lit namespace.
|
|
49
|
+
* @param surface From a painter.
|
|
50
|
+
* @returns The textures; the image's top row is at the top of UV space.
|
|
51
|
+
*/
|
|
52
|
+
export declare function surfaceTextures<T extends TextureLike, D extends DataTextureLike>(lit: PrintLit<T, D>, surface: Surface): {
|
|
53
|
+
map: D;
|
|
54
|
+
normalMap: D;
|
|
55
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/** A direction as `[x, y]`, x to the right and y down; it need not be unit length. */
|
|
2
|
+
export type Axis = readonly [number, number];
|
|
3
|
+
/** Paper: fibre noise, flecks, soft stains and faint laid and chain lines. Tileable. */
|
|
4
|
+
export interface PaperRecipe {
|
|
5
|
+
readonly kind: "paper";
|
|
6
|
+
readonly tone: string;
|
|
7
|
+
/** The flecks' colour and how many of the fleck cells hold one. */
|
|
8
|
+
readonly fleck: string;
|
|
9
|
+
readonly flecks: number;
|
|
10
|
+
/** The stains' colour and how much they show. */
|
|
11
|
+
readonly stain: string;
|
|
12
|
+
readonly stains: number;
|
|
13
|
+
/** Fibre cells across the tile (a whole number, 4..512), and how much the fibres show. */
|
|
14
|
+
readonly cells: number;
|
|
15
|
+
readonly fibres: number;
|
|
16
|
+
/** The cloudy unevenness of the sheet: its contrast, and its lattice across the tile (a whole number, 1..64). */
|
|
17
|
+
readonly mottle: number;
|
|
18
|
+
readonly mottleScale: number;
|
|
19
|
+
/** Laid lines across and chain lines down the tile (whole numbers, 0 for none), and how much they show. */
|
|
20
|
+
readonly laid: number;
|
|
21
|
+
readonly chain: number;
|
|
22
|
+
readonly lines: number;
|
|
23
|
+
/** Relief: how tall a height of 1 stands, as a share of the surface's height (0..4), for the normal. */
|
|
24
|
+
readonly depth: number;
|
|
25
|
+
}
|
|
26
|
+
/** Rib knit: columns of knit stitches with purl between them, plied yarn and fuzz. Tileable. */
|
|
27
|
+
export interface KnitRecipe {
|
|
28
|
+
readonly kind: "knit";
|
|
29
|
+
readonly base: string;
|
|
30
|
+
readonly shadow: string;
|
|
31
|
+
readonly light: string;
|
|
32
|
+
/** Ribs across and courses (rows of stitches) down the tile: whole numbers, 1..256. */
|
|
33
|
+
readonly ribs: number;
|
|
34
|
+
readonly courses: number;
|
|
35
|
+
/** The share of a rib the knit column takes (0.3..0.9). */
|
|
36
|
+
readonly knit: number;
|
|
37
|
+
/** Ply turns along one leg of a stitch (0..8). */
|
|
38
|
+
readonly twist: number;
|
|
39
|
+
/** Loose fibres over the yarn, and how uneven the stitches are. */
|
|
40
|
+
readonly fuzz: number;
|
|
41
|
+
readonly jitter: number;
|
|
42
|
+
readonly depth: number;
|
|
43
|
+
}
|
|
44
|
+
/** One soft painted mass on a painted ground: a petal, a leaf, a bloom, a bud. */
|
|
45
|
+
export interface Mass {
|
|
46
|
+
/** Its centre as shares of the width and the height. */
|
|
47
|
+
readonly at: Axis;
|
|
48
|
+
/** Its half-length along `axis` and half-width across it, as shares of the height. */
|
|
49
|
+
readonly size: Axis;
|
|
50
|
+
readonly axis: Axis;
|
|
51
|
+
/** The shadowed and the lit colour. */
|
|
52
|
+
readonly colour: string;
|
|
53
|
+
readonly light: string;
|
|
54
|
+
/** How soft the edge is, how much the edge wanders, and how strong the brush streaks are in it. */
|
|
55
|
+
readonly soft: number;
|
|
56
|
+
readonly warp: number;
|
|
57
|
+
readonly streak: number;
|
|
58
|
+
/** Streaks around the centre (a bloom's ruffled petals) instead of along the axis. */
|
|
59
|
+
readonly ring?: boolean;
|
|
60
|
+
/** How far the ends narrow to points: 0 an oval, 1 a leaf. */
|
|
61
|
+
readonly point?: number;
|
|
62
|
+
}
|
|
63
|
+
/** Folded cloth under a painted ground: three crossing sets of creased folds with a sheen on their crests. */
|
|
64
|
+
export interface Folds {
|
|
65
|
+
readonly axis: Axis;
|
|
66
|
+
/** Folds per height (0.5..16), and how much they wander (0..2). */
|
|
67
|
+
readonly count: number;
|
|
68
|
+
readonly warp: number;
|
|
69
|
+
readonly deep: string;
|
|
70
|
+
readonly mid: string;
|
|
71
|
+
readonly light: string;
|
|
72
|
+
readonly sheen: number;
|
|
73
|
+
}
|
|
74
|
+
/** A soft painted field: a ground, folds or masses over it, brush texture and a glaze. Any size; not tileable. */
|
|
75
|
+
export interface PaintedRecipe {
|
|
76
|
+
readonly kind: "painted";
|
|
77
|
+
readonly ground: string;
|
|
78
|
+
/** How uneven the ground's colour is. */
|
|
79
|
+
readonly variation: number;
|
|
80
|
+
/** A thin transparent colour laid over everything, in broad patches. */
|
|
81
|
+
readonly glaze: string;
|
|
82
|
+
readonly glazeAmount: number;
|
|
83
|
+
/** Brush texture: its direction, stroke cells per height (1..64), and how much it shows. */
|
|
84
|
+
readonly brush: {
|
|
85
|
+
readonly axis: Axis;
|
|
86
|
+
readonly length: number;
|
|
87
|
+
readonly amount: number;
|
|
88
|
+
};
|
|
89
|
+
readonly folds?: Folds;
|
|
90
|
+
/** Up to ten masses, painted in order. */
|
|
91
|
+
readonly masses: readonly Mass[];
|
|
92
|
+
/** How far a seed moves a mass, as a share of the height (0..0.2). */
|
|
93
|
+
readonly jitter: number;
|
|
94
|
+
readonly depth: number;
|
|
95
|
+
}
|
|
96
|
+
/** Every recipe a painter takes. */
|
|
97
|
+
export type SurfaceRecipe = PaperRecipe | KnitRecipe | PaintedRecipe;
|
|
98
|
+
/** Planned: warped-noise veins through a stone, as marble. Tileable. */
|
|
99
|
+
export interface VeinsRecipe {
|
|
100
|
+
readonly kind: "veins";
|
|
101
|
+
readonly base: string;
|
|
102
|
+
readonly vein: string;
|
|
103
|
+
/** Veins across the tile, how far they wander, and how sharp they are. */
|
|
104
|
+
readonly count: number;
|
|
105
|
+
readonly warp: number;
|
|
106
|
+
readonly sharpness: number;
|
|
107
|
+
readonly depth: number;
|
|
108
|
+
}
|
|
109
|
+
/** Planned: a crackle of cells, as old varnish or dried paint. Tileable. */
|
|
110
|
+
export interface CracksRecipe {
|
|
111
|
+
readonly kind: "cracks";
|
|
112
|
+
readonly base: string;
|
|
113
|
+
readonly crack: string;
|
|
114
|
+
/** Cells across the tile, the cracks' width as a share of a cell, and how much they show. */
|
|
115
|
+
readonly cells: number;
|
|
116
|
+
readonly width: number;
|
|
117
|
+
readonly amount: number;
|
|
118
|
+
readonly depth: number;
|
|
119
|
+
}
|
|
120
|
+
/** Planned: a repeated motif with a gold ramp, as brocade or a printed pattern. Tileable. */
|
|
121
|
+
export interface MotifRecipe {
|
|
122
|
+
readonly kind: "motif";
|
|
123
|
+
readonly ground: string;
|
|
124
|
+
/** The ramp the motif is coloured with, dark to light. */
|
|
125
|
+
readonly ramp: readonly string[];
|
|
126
|
+
/** Repeats across and down the tile, and a half-drop between columns. */
|
|
127
|
+
readonly across: number;
|
|
128
|
+
readonly down: number;
|
|
129
|
+
readonly halfDrop: boolean;
|
|
130
|
+
readonly depth: number;
|
|
131
|
+
}
|
|
132
|
+
/** A recipe for a painter that is planned and not built yet. */
|
|
133
|
+
export type PlannedRecipe = VeinsRecipe | CracksRecipe | MotifRecipe;
|
|
134
|
+
/** The planned painters' kinds. */
|
|
135
|
+
export declare const PLANNED: readonly PlannedRecipe["kind"][];
|
|
136
|
+
/** A pale grey-green paper with fibres, specks and faint laid lines: a list band's ground. */
|
|
137
|
+
export declare const PAPER: PaperRecipe;
|
|
138
|
+
/** A hot pink rib knit, eight ribs and eighteen courses a tile: seven tiles go once around a cap of 56 ribs. */
|
|
139
|
+
export declare const KNIT: KnitRecipe;
|
|
140
|
+
/** A painted flower close-up: white petals at the left, a plum bloom top right, ochre and crimson below. */
|
|
141
|
+
export declare const PAINTED_FLORAL: PaintedRecipe;
|
|
142
|
+
/** Dark green cloth in soft diagonal folds with a satin sheen along them. */
|
|
143
|
+
export declare const PAINTED_CLOTH: PaintedRecipe;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** A triangle that covers the target. */
|
|
2
|
+
export declare const VERT = "#version 300 es\nvoid main() {\n vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));\n gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);\n}";
|
|
3
|
+
/** Each kind's fragment shader, by its number in `KINDS`. */
|
|
4
|
+
export declare const FRAGMENTS: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './surfaces/index.js'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": "keel-module-inputs@1",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"key": "surface",
|
|
6
|
+
"label": "Surface",
|
|
7
|
+
"required": false,
|
|
8
|
+
"help": "Which of the module's recipes to paint.",
|
|
9
|
+
"type": "select",
|
|
10
|
+
"options": [
|
|
11
|
+
{
|
|
12
|
+
"value": "paper",
|
|
13
|
+
"label": "Paper"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"value": "knit",
|
|
17
|
+
"label": "Rib knit"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"value": "floral",
|
|
21
|
+
"label": "Painted flowers"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"value": "cloth",
|
|
25
|
+
"label": "Painted cloth"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"default": "paper"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"key": "seed",
|
|
32
|
+
"label": "Seed",
|
|
33
|
+
"required": false,
|
|
34
|
+
"help": "Decides every fibre, stitch and stroke inside the recipe's bounds.",
|
|
35
|
+
"type": "number",
|
|
36
|
+
"min": 0,
|
|
37
|
+
"max": 999999,
|
|
38
|
+
"step": 1,
|
|
39
|
+
"default": 0
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"key": "size",
|
|
43
|
+
"label": "Size",
|
|
44
|
+
"required": false,
|
|
45
|
+
"help": "Pixels across; a tile is square.",
|
|
46
|
+
"placement": "advanced",
|
|
47
|
+
"type": "number",
|
|
48
|
+
"min": 16,
|
|
49
|
+
"max": 4096,
|
|
50
|
+
"step": 16,
|
|
51
|
+
"default": 1024
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// surfaces@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
|
|
2
|
+
var U=["veins","cracks","motif"],ne={kind:"paper",tone:"#dcdcd0",fleck:"#6f6d60",flecks:.14,stain:"#cfc8b2",stains:.35,cells:72,fibres:.5,mottle:.06,mottleScale:6,laid:0,chain:0,lines:.15,depth:.004},oe={kind:"knit",base:"#ff2f78",shadow:"#d91a5e",light:"#ff85ad",ribs:8,courses:18,knit:.62,twist:2.5,fuzz:.45,jitter:.35,depth:.025},ae={kind:"painted",ground:"#3f6b64",variation:.09,glaze:"#5a6a3c",glazeAmount:.16,brush:{axis:[1,-.35],length:14,amount:.1},jitter:.015,depth:.002,masses:[{at:[.1,.32],size:[.52,.2],axis:[.35,1],colour:"#a9a996",light:"#e8e6da",soft:.07,warp:.32,streak:.35,point:.3},{at:[.2,.06],size:[.34,.16],axis:[1,.3],colour:"#b4b3a0",light:"#e8e6da",soft:.07,warp:.28,streak:.35,point:.3},{at:[.04,.8],size:[.42,.08],axis:[.2,1],colour:"#2a4431",light:"#6f7f4a",soft:.07,warp:.12,streak:.3,point:1},{at:[.86,.1],size:[.34,.3],axis:[1,.25],colour:"#4a1d38",light:"#a83d6e",soft:.07,warp:.24,streak:.3,ring:!0},{at:[.65,.05],size:[.12,.09],axis:[1,.5],colour:"#6a2a4e",light:"#a83d6e",soft:.07,warp:.24,streak:.3,ring:!0},{at:[.82,.8],size:[.42,.12],axis:[1,-.55],colour:"#2a4431",light:"#7d8a4a",soft:.07,warp:.12,streak:.3,point:1},{at:[.42,.84],size:[.34,.06],axis:[1,-.8],colour:"#2a4431",light:"#6f7f4a",soft:.07,warp:.12,streak:.3,point:1},{at:[.66,.66],size:[.15,.06],axis:[.7,-1],colour:"#9a7a22",light:"#c9a233",soft:.07,warp:.24,streak:.35,point:.8},{at:[.3,.6],size:[.11,.05],axis:[.7,-1],colour:"#b7b39a",light:"#e8e6da",soft:.07,warp:.2,streak:.3,point:.7},{at:[.47,.98],size:[.11,.09],axis:[1,.2],colour:"#5e1520",light:"#8b1e2a",soft:.07,warp:.24,streak:.3,ring:!0}]},se={kind:"painted",ground:"#0e2b1d",variation:.06,glaze:"#14301f",glazeAmount:.2,brush:{axis:[1,.6],length:3,amount:.05},jitter:0,depth:.003,masses:[],folds:{axis:[1,.55],count:2.2,warp:.8,deep:"#0e2b1d",mid:"#2f5a3c",light:"#5c8a63",sheen:.5}};function A(e,r){let t=Math.imul(e^2654435769,2246822507)^Math.imul(r+1663821227,3266489909);return t=Math.imul(t^t>>>16,2146121005),t=Math.imul(t^t>>>15,2221713035),(t^t>>>16)>>>0}function V(e,r){let t=0;return(n,o)=>(t+=1,n+(o-n)*A(A(e,r),t)/4294967296)}function q(e,r,t=0){let n=1+t*t,o=(1-t*t)/n,a=2*t/n,u=e*o-r*a,i=e*a+r*o,s=Math.sqrt(u*u+i*i)||1;return[u/s,i/s]}function K(e){let r=2166136261,t=16777619;for(let n of e)for(let o of new Uint8Array(n.buffer,n.byteOffset,n.byteLength))r=Math.imul(r^o,16777619),t=Math.imul(t^o,16777629)^r>>>7;return(r>>>0).toString(16).padStart(8,"0")+(t>>>0).toString(16).padStart(8,"0")}var $=1,O=10,W=232,L={paper:0,knit:1,painted:2};function h(e,r,t,n){if(typeof e!="number"||!(e>=t&&e<=n))throw new RangeError(`surfaces: ${r} must be within ${t}..${n}.`);return e}function M(e,r,t,n){if(!Number.isInteger(e))throw new RangeError(`surfaces: ${r} must be a whole number within ${t}..${n}.`);return h(e,r,t,n)}function y(e,r,t){e.set(t,r)}function k(e){if(typeof e!="string"||!/^#[0-9a-f]{6}$/iu.test(e))throw new TypeError(`surfaces: ${JSON.stringify(e)} is not #rrggbb.`);let r=Number.parseInt(e.slice(1),16);return[(r>>16)/255,(r>>8&255)/255,(r&255)/255]}function j(e,r,t=0){let[n,o]=[h(e[0],r,-64,64),h(e[1],r,-64,64)];if(n===0&&o===0)throw new RangeError(`surfaces: ${r} must not be [0, 0].`);return q(n,o,t)}function ie(e,r){y(r,0,k(e.tone)),y(r,4,[...k(e.fleck),h(e.flecks,"flecks",0,1)]),y(r,8,[...k(e.stain),h(e.stains,"stains",0,1)]),y(r,12,[M(e.cells,"cells",4,512),h(e.fibres,"fibres",0,1),h(e.mottle,"mottle",0,1),M(e.mottleScale,"mottleScale",1,64)]),y(r,16,[M(e.laid,"laid",0,512),M(e.chain,"chain",0,64),h(e.lines,"lines",0,1)])}function ue(e,r){y(r,0,k(e.base)),y(r,4,[...k(e.shadow),M(e.ribs,"ribs",1,256)]),y(r,8,[...k(e.light),M(e.courses,"courses",1,256)]),y(r,12,[h(e.knit,"knit",.3,.9),h(e.twist,"twist",0,8),h(e.fuzz,"fuzz",0,1),h(e.jitter,"jitter",0,1)])}function ce(e,r,t,n){let o=V(n.seed,100+t),[a,u]=[h(e.at[0],"mass at",-.5,1.5),h(e.at[1],"mass at",-.5,1.5)],i=n.jitter;y(r,t,[(a+o(-i,i))*n.aspect,u+o(-i,i),h(e.size[0],"mass size",.005,2),h(e.size[1],"mass size",.005,2)]),y(r,t+4,[...j(e.axis,"mass axis",o(-i,i)*4),h(e.soft,"soft",.01,1),e.ring===!0?1:0]),y(r,t+8,[...k(e.colour),h(e.warp,"warp",0,2)]),y(r,t+12,[...k(e.light),h(e.streak,"streak",0,1)]),r[t+16]=h(e.point??0,"point",0,1)}function fe(e,r,t){if(e.masses.length>O)throw new RangeError(`surfaces: at most ${O} masses.`);y(r,0,k(e.ground)),y(r,4,[...k(e.glaze),h(e.glazeAmount,"glazeAmount",0,1)]),y(r,8,[...j(e.brush.axis,"brush axis"),h(e.brush.length,"brush length",1,64),h(e.brush.amount,"brush amount",0,1)]),y(r,12,[t.aspect,e.masses.length,h(e.variation,"variation",0,1)]);let n=e.folds;n&&(y(r,16,[...k(n.deep),h(n.count,"fold count",.5,16)]),y(r,20,[...k(n.mid),h(n.warp,"fold warp",0,2)]),y(r,24,[...k(n.light),h(n.sheen,"sheen",0,1)]),y(r,28,j(n.axis,"fold axis")));let o={...t,jitter:h(e.jitter,"jitter",0,.2)};e.masses.forEach((a,u)=>{ce(a,r,32+u*20,o)})}var me=e=>e.kind in L;function F(e,r={}){let t=e.kind;if(U.includes(t))throw new RangeError(`surfaces: ${t} is planned, not built yet.`);if(!me(e))throw new RangeError(`surfaces: no painter for ${JSON.stringify(t)}.`);let n=M(r.seed??0,"seed",0,2147483647),o=M(r.width??1024,"width",1,4096),a=M(r.height??o,"height",1,4096),u=h(e.depth,"depth",0,4),i=new Float32Array(W);i[3]=A(n,L[e.kind])>>>12,e.kind==="paper"?ie(e,i):e.kind==="knit"?ue(e,i):fe(e,i,{aspect:o/a,seed:n});let s=Float32Array.of(L[e.kind],o,a,u,$);return{kind:e.kind,width:o,height:a,depth:u,uniforms:i,digest:K([i,s])}}var N=e=>e-Math.floor(e),z=(e,r=0,t=1)=>Math.min(Math.max(e,r),t),S=(e,r,t)=>e+(r-e)*t;function R(e,r,t){let n=z((t-e)/(r-e));return n*n*(3-2*n)}var I=(e,r,t,n)=>(e+t)%t+((r+n)%n<<12),C=(e,r,t,n)=>A(I(e,r,t,t),n)/4294967296;function _(e,r,t,n){let o=Math.floor(e),a=Math.floor(r),[u,i]=[e-o,r-a],[s,f]=[u*u*(3-2*u),i*i*(3-2*i)],c=C(o,a,t,n),m=C(o+1,a,t,n),d=C(o,a+1,t,n),l=C(o+1,a+1,t,n),p=c+(m-c)*s;return p+(d+(l-d)*s-p)*f}function T(e,r,t,n){let[o,a,u,i,s,f]=[0,.5,0,e,r,t];for(let c=0;c<n.n;c+=1)o+=a*_(i,s,f,n.s+c),u+=a,[i,s,f,a]=[i*2,s*2,f*2,a*.5];return o/u}function B(e,r,t,n){let[o,a]=[e*t,r*t],[u,i]=[Math.floor(o),Math.floor(a)],s=[0,0];for(let f=-1;f<=1;f+=1)for(let c=-1;c<=1;c+=1){let m=I(u+c,i+f,t,t),[d,l]=[A(m,n.s),A(m,n.s+1)],[p,x]=[(l>>>16)/65536-.5,(l&65535)/65536-.5],b=Math.max(Math.sqrt(p*p+x*x),1e-4);[p,x]=[p/b,x/b];let[g,v]=[o-(u+c+(d>>>16)/65536),a-(i+f+(d&65535)/65536)],E=z(g*p+v*x,-n.len,n.len),w=1-R(n.wid*.5,n.wid,Math.hypot(g-p*E,v-x*E));w>s[0]&&(s=[w,(l&255)/255])}return s}var X=(e,r)=>1-R(0,r,Math.abs(N(e)-.5));function de(e,r,t,n){let[o,a]=[e*t,r*t],[u,i]=[Math.floor(o),Math.floor(a)],s=A(I(u,i,t,t),n.s);if((s&1023)/1024>=n.density)return 0;let[f,c]=[u+.3+.4*(s>>>22&1023)/1024,i+.3+.4*(s>>>12&1023)/1024],m=.04+.06*(s>>>10&3);return 1-R(m*.5,m,Math.hypot(o-f,a-c))}var le=(e,r,t,n)=>{let o=e(3),[a,u,i,s,f]=[e(12),e(15),e(13),e(14),e(18)],c=T(r*u,t*u,u,{s:o,n:4}),m=_(r*a*4,t*a*4,a*4,o+5),d=B(r,t,a,{s:o+10,len:.9,wid:.1}),l=B(r,t,a*2,{s:o+20,len:.8,wid:.12}),p=(e(16)>0?.6*X(t*e(16),.12):0)+(e(17)>0?X(r*e(17),.03):0),x=.5*c+.15*m+i*(.6*d[0]+.4*l[0])+f*p,b=(1+s*((c-.5)*2+(m-.5)*.6))*(1+i*(d[0]*(.03-.6*R(.95,.99,d[1]))+.03*l[0]))*(1+f*.08*p),g=T(r*3,t*3,3,{s:o+30,n:4}),v=R(.6,.66,g),E=e(11)*(.35*v+.5*v*(1-R(.66,.7,g))),w=de(r,t,a*3,{s:o+40,density:e(7)});for(let P=0;P<3;P+=1)n[P]=S(S(e(P)*b,e(8+P),E),e(4+P),w);return x};function be(e,r,t,n){let[o,a,u,i]=r,[s,f]=[u-o,i-a],c=z(((e[0]-o)*s+(e[1]-a)*f)/(s*s+f*f)),[m,d]=[e[0]-o-s*c,e[1]-a-f*c],l=Math.hypot(m,d)/t,p=(m*f-d*s)/(Math.hypot(s,f)*t),x=Math.abs(N(c*n+p*.35)-.5)*2;return[Math.sqrt(Math.max(0,1-l*l))*(.8+.8*c*(1-c)),x]}function pe(e,r,t){let[n,o,a]=[e(7),e(11),e(15)],u=o/n,i=e(12)*.5*u,[s,f]=[r*n,t*o],c=Math.floor(s),m=(s-c-.5)*u,d=[0,.5,.5];for(let g=-1;g<=1;g+=1){let v=Math.floor(f)+g,E=A(I(c,v,n,o),e(3)),w=a*((E&255)/255-.5);for(let P of[-1,1]){let te=[P*i*.72,-.18,P*i*.06,1.08],[G,re]=be([m+w*.06*u,f-v],te,i*.46,e(13));G*(1+.3*w)>d[0]&&(d=[G*(1+.3*w),re,(E>>>24)/255])}}let l=Math.max(.5*u-i,.001),[p,x]=[(.5*u-Math.abs(m))/l,(N(f)-.5)/.32],b=.4*Math.sqrt(Math.max(0,1-p*p-x*x));return[Math.max(d[0],b)+.12*(d[1]-.5)*d[0],d[1],d[2]]}var he=(e,r,t,n)=>{let[o,a,u]=[e(3),e(7),e(14)],[i,,s]=pe(e,r,t),f=T(r*a*16,t*a*16,a*16,{s:o+30,n:2}),c=B(r,t,a*12,{s:o+40,len:.6,wid:.08})[0],m=i*(1-.1*u)+u*(.1*f+.2*c),d=z(m);for(let l=0;l<3;l+=1){let[p,x,b]=[e(l),e(4+l),e(8+l)],g=S(S(x,p,R(.08,.6,d)),b,.6*R(.62,1,d))*(.96+.08*s);n[l]=S(g,b,u*.3*c)}return m};function xe(e,r,t,n){let[o,a]=[e(28),e(29)],[u,i]=[0,0];for(let c=0;c<3;c+=1){let m=1/(1+1.6*c),[d,l]=[o-a*(c-1)*.35,a+o*(c-1)*.35],p=Math.hypot(d,l),x=e(23)*T(r[0]*(1.5+c),r[1]*(1.5+c),1024,{s:t+10+c*4,n:3}),b=N((r[0]*d+r[1]*l)/p*e(19)*(1+.45*c)+x);u+=Math.cos(3.1415927*b)*m,i=Math.max(i,Math.sin(3.1415927*b)*m)}let s=z(.5+.3*u),f=R(.7,1,s)*i;for(let c=0;c<3;c+=1){let[m,d,l]=[e(16+c),e(20+c),e(24+c)];n[c]=S(S(m,d,R(.15,.6,s)),l,R(.6,.95,s))+e(27)*f*f*l}}function ye(e,r,t,n){let o=32+r*20,a=w=>e(o+w),[u,i,s,f,c,m]=[a(0),a(1),a(2),a(3),a(4),a(5)],[d,l]=[t.p[0]-u,t.p[1]-i],p=(d*c+l*m)/s,x=(l*c-d*m)/f/Math.max(S(1,Math.sqrt(Math.max(1-p*p,0)),a(16)),.05);if(Math.hypot(p,x)>1+.5*a(11))return[0,0];let b=Math.hypot(p,x)+a(11)*(T(t.p[0]*9,t.p[1]*9,1024,{s:t.s+60+r,n:4})-.5),g=1-R(1-a(6),1,b),v=a(7)>0?N(b*2.6+1.1*T((Math.atan2(x,p)/6.2831853+.5)*6,b,6,{s:t.s+80+r,n:2})):.6*T(p*2+r*7,x*4,1024,{s:t.s+80,n:2})+.4*_(p*3,x*14,1024,t.s+90),E=z(.5-.4*x+a(15)*(v-.5)*2);for(let w=0;w<3;w+=1){let P=S(a(8+w),a(12+w),R(.2,.9,E))*(.85+.15*(1-b*b));n[w]=S(n[w]??0,P,g)}return[v,g]}var we=(e,r,t,n)=>{let o=e(3),a=[r*e(12),t],[u,i,s,f]=[e(8),e(9),e(10),e(11)],c=T((a[0]*u+a[1]*i)*s,(a[1]*u-a[0]*i)*s*4,1024,{s:o,n:3}),m=_(a[0]*240,a[1]*240,1024,o+7)-.5,d=1+e(14)*(T(a[0]*3,a[1]*3,1024,{s:o+1,n:3})-.5)*2;for(let b=0;b<3;b+=1)n[b]=e(b)*d;e(19)>0&&xe(e,a,o,n);let l=0;for(let b=0;b<e(13);b+=1){let[g,v]=ye(e,b,{p:a,s:o},n);l=S(l,g,v)}let p=e(7)*T(a[0]*1.5,a[1]*1.5,1024,{s:o+3,n:3}),x=1+f*((c-.5)*1.2+m*.5);for(let b=0;b<3;b+=1)n[b]=S((n[b]??0)*x,e(4+b),p);return .5+f*(c-.5)+.15*l},H=[le,he,we];var D=e=>Math.round(Math.min(Math.max(e,0),1)*255);function ge(e,r){let{width:t,height:n}=r,o=new ArrayBuffer(t*n*4),a=new Uint8Array(o),u=.5*r.depth*n,i=(s,f)=>e[(f+n)%n*t+(s+t)%t]??0;for(let s=0;s<n;s+=1)for(let f=0;f<t;f+=1){let c=(i(f-1,s)-i(f+1,s))*u,m=(i(f,s+1)-i(f,s-1))*u,d=Math.sqrt(c*c+m*m+1);a.set([D(c/d/2+.5),D(m/d/2+.5),D(1/d/2+.5),D(i(f,s))],(s*t+f)*4)}return o}function Y(e){let r=H[L[e.kind]];if(!r)throw new RangeError(`surfaces: no painter for ${e.kind}.`);let{width:t,height:n,uniforms:o}=e,a=new ArrayBuffer(t*n*4),u=new Uint8Array(a),i=new Float32Array(t*n),s=[0,0,0],f=c=>o[c]??0;for(let c=0;c<n;c+=1)for(let m=0;m<t;m+=1)i[c*t+m]=r(f,(m+.5)/t,(c+.5)/n,s),u.set([D(s[0]),D(s[1]),D(s[2]),255],(c*t+m)*4);return{digest:e.digest,width:t,height:n,buffers:[a,ge(i,e)]}}function ve(e,r){return Y(F(e,r))}var J=`#version 300 es
|
|
3
|
+
void main() {
|
|
4
|
+
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
|
|
5
|
+
gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0);
|
|
6
|
+
}`,ke=`#version 300 es
|
|
7
|
+
precision highp float;
|
|
8
|
+
precision highp int;
|
|
9
|
+
uniform vec4 u[58];
|
|
10
|
+
uniform vec3 uView;
|
|
11
|
+
layout(location = 0) out vec4 oAlbedo;
|
|
12
|
+
layout(location = 1) out vec4 oRelief;
|
|
13
|
+
|
|
14
|
+
uint hh(uint a, uint b) {
|
|
15
|
+
uint h = ((a ^ 0x9e3779b9u) * 0x85ebca6bu) ^ ((b + 0x632be5abu) * 0xc2b2ae35u);
|
|
16
|
+
h = (h ^ (h >> 16u)) * 0x7feb352du;
|
|
17
|
+
h = (h ^ (h >> 15u)) * 0x846ca68bu;
|
|
18
|
+
return h ^ (h >> 16u);
|
|
19
|
+
}
|
|
20
|
+
uint cell(vec2 i, vec2 p) {
|
|
21
|
+
uvec2 m = uvec2(ivec2(i) + ivec2(p)) % uvec2(p);
|
|
22
|
+
return m.x + (m.y << 12u);
|
|
23
|
+
}
|
|
24
|
+
float rn(vec2 i, float p, uint s) { return float(hh(cell(i, vec2(p)), s)) / 4294967296.0; }
|
|
25
|
+
float vn(vec2 q, float p, uint s) {
|
|
26
|
+
vec2 i = floor(q), f = q - i, w = f * f * (3.0 - 2.0 * f);
|
|
27
|
+
float a = rn(i, p, s), b = rn(i + vec2(1, 0), p, s), c = rn(i + vec2(0, 1), p, s), d = rn(i + 1.0, p, s);
|
|
28
|
+
float top = a + (b - a) * w.x, bottom = c + (d - c) * w.x;
|
|
29
|
+
return top + (bottom - top) * w.y;
|
|
30
|
+
}
|
|
31
|
+
float fbm(vec2 q, float p, uint s, int n) {
|
|
32
|
+
float t = 0.0, a = 0.5, w = 0.0;
|
|
33
|
+
for (int k = 0; k < n; k++) { t += a * vn(q, p, s + uint(k)); w += a; q *= 2.0; p *= 2.0; a *= 0.5; }
|
|
34
|
+
return t / w;
|
|
35
|
+
}
|
|
36
|
+
vec2 fib(vec2 uv, float n, uint s, float len, float wid) {
|
|
37
|
+
vec2 g = uv * n, c = floor(g), r = vec2(0);
|
|
38
|
+
for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) {
|
|
39
|
+
vec2 i = c + vec2(x, y);
|
|
40
|
+
uint k = cell(i, vec2(n)), h1 = hh(k, s), h2 = hh(k, s + 1u);
|
|
41
|
+
vec2 o = i + vec2(h1 >> 16u, h1 & 65535u) / 65536.0;
|
|
42
|
+
vec2 d = vec2(h2 >> 16u, h2 & 65535u) / 65536.0 - 0.5;
|
|
43
|
+
d /= max(length(d), 1e-4);
|
|
44
|
+
vec2 q = g - o;
|
|
45
|
+
float t = clamp(dot(q, d), -len, len), e = 1.0 - smoothstep(wid * 0.5, wid, length(q - d * t));
|
|
46
|
+
if (e > r.x) r = vec2(e, float(h2 & 255u) / 255.0);
|
|
47
|
+
}
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
float band(float t, float w) { return 1.0 - smoothstep(0.0, w, abs(fract(t) - 0.5)); }
|
|
51
|
+
`,Re=`
|
|
52
|
+
float fleck(vec2 uv, float m, uint s, float density) {
|
|
53
|
+
vec2 g = uv * m, i = floor(g);
|
|
54
|
+
uint h = hh(cell(i, vec2(m)), s);
|
|
55
|
+
if (float(h & 1023u) / 1024.0 >= density) return 0.0;
|
|
56
|
+
vec2 o = i + 0.3 + 0.4 * vec2((h >> 22u) & 1023u, (h >> 12u) & 1023u) / 1024.0;
|
|
57
|
+
float r = 0.04 + 0.06 * float((h >> 10u) & 3u);
|
|
58
|
+
return 1.0 - smoothstep(r * 0.5, r, length(g - o));
|
|
59
|
+
}
|
|
60
|
+
void surface(vec2 uv, out float h, out vec3 c) {
|
|
61
|
+
uint s = uint(u[0].w);
|
|
62
|
+
float n = u[3].x, p = u[3].w;
|
|
63
|
+
float m = fbm(uv * p, p, s, 4), tooth = vn(uv * n * 4.0, n * 4.0, s + 5u);
|
|
64
|
+
vec2 a = fib(uv, n, s + 10u, 0.9, 0.1), b = fib(uv, n * 2.0, s + 20u, 0.8, 0.12);
|
|
65
|
+
float lines = (u[4].x > 0.0 ? 0.6 * band(uv.y * u[4].x, 0.12) : 0.0) + (u[4].y > 0.0 ? band(uv.x * u[4].y, 0.03) : 0.0);
|
|
66
|
+
float fibre = 0.6 * a.x + 0.4 * b.x;
|
|
67
|
+
h = 0.5 * m + 0.15 * tooth + u[3].y * fibre + u[4].z * lines;
|
|
68
|
+
c = u[0].rgb * (1.0 + u[3].z * ((m - 0.5) * 2.0 + (tooth - 0.5) * 0.6));
|
|
69
|
+
c *= 1.0 + u[3].y * (a.x * (0.03 - 0.6 * smoothstep(0.95, 0.99, a.y)) + 0.03 * b.x);
|
|
70
|
+
c *= 1.0 + u[4].z * 0.08 * lines;
|
|
71
|
+
float st = fbm(uv * 3.0, 3.0, s + 30u, 4), area = smoothstep(0.6, 0.66, st), rim = area * (1.0 - smoothstep(0.66, 0.7, st));
|
|
72
|
+
c = mix(c, u[2].rgb, u[2].w * (0.35 * area + 0.5 * rim));
|
|
73
|
+
c = mix(c, u[1].rgb, fleck(uv, n * 3.0, s + 40u, u[1].w));
|
|
74
|
+
}
|
|
75
|
+
`,Se=`
|
|
76
|
+
float leg(vec2 q, vec2 a, vec2 b, float r, out float ply) {
|
|
77
|
+
vec2 ab = b - a;
|
|
78
|
+
float t = clamp(dot(q - a, ab) / dot(ab, ab), 0.0, 1.0);
|
|
79
|
+
vec2 e = q - a - ab * t;
|
|
80
|
+
float d = length(e) / r, side = (e.x * ab.y - e.y * ab.x) / (length(ab) * r);
|
|
81
|
+
ply = abs(fract(t * u[3].y + side * 0.35) - 0.5) * 2.0;
|
|
82
|
+
return sqrt(max(0.0, 1.0 - d * d)) * (0.8 + 0.8 * t * (1.0 - t));
|
|
83
|
+
}
|
|
84
|
+
void surface(vec2 uv, out float h, out vec3 c) {
|
|
85
|
+
uint s = uint(u[0].w);
|
|
86
|
+
float ribs = u[1].w, rows = u[2].w, a = rows / ribs, hw = u[3].x * 0.5 * a;
|
|
87
|
+
float x = uv.x * ribs, y = uv.y * rows, col = floor(x), fx = (x - col - 0.5) * a;
|
|
88
|
+
float best = 0.0, ply = 0.5, tone = 0.5;
|
|
89
|
+
for (int k = -1; k <= 1; k++) {
|
|
90
|
+
float row = floor(y) + float(k);
|
|
91
|
+
uint hs = hh(cell(vec2(col, row), vec2(ribs, rows)), s);
|
|
92
|
+
float j = u[3].w * (float(hs & 255u) / 255.0 - 0.5);
|
|
93
|
+
for (int side = -1; side <= 1; side += 2) {
|
|
94
|
+
float sd = float(side), pl;
|
|
95
|
+
float e = leg(vec2(fx + j * 0.06 * a, y - row), vec2(sd * hw * 0.72, -0.18), vec2(sd * hw * 0.06, 1.08), hw * 0.46, pl);
|
|
96
|
+
e *= 1.0 + 0.3 * j;
|
|
97
|
+
if (e > best) { best = e; ply = pl; tone = float(hs >> 24u) / 255.0; }
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
float gw = max(0.5 * a - hw, 1e-3), gd = (0.5 * a - abs(fx)) / gw, gy = (fract(y) - 0.5) / 0.32;
|
|
101
|
+
float purl = 0.4 * sqrt(max(0.0, 1.0 - gd * gd - gy * gy));
|
|
102
|
+
float fuzz = u[3].z, n = fbm(uv * ribs * 16.0, ribs * 16.0, s + 30u, 2), hair = fib(uv, ribs * 12.0, s + 40u, 0.6, 0.08).x;
|
|
103
|
+
h = max(best, purl) + 0.12 * (ply - 0.5) * best;
|
|
104
|
+
h = h * (1.0 - 0.1 * fuzz) + fuzz * (0.1 * n + 0.2 * hair);
|
|
105
|
+
float k = clamp(h, 0.0, 1.0);
|
|
106
|
+
c = mix(u[1].rgb, u[0].rgb, smoothstep(0.08, 0.6, k));
|
|
107
|
+
c = mix(c, u[2].rgb, 0.6 * smoothstep(0.62, 1.0, k));
|
|
108
|
+
c *= 0.96 + 0.08 * tone;
|
|
109
|
+
c = mix(c, u[2].rgb, fuzz * 0.3 * hair);
|
|
110
|
+
}
|
|
111
|
+
`,Pe=`
|
|
112
|
+
vec3 folds(vec2 p, uint s) {
|
|
113
|
+
vec2 d = u[7].xy;
|
|
114
|
+
float slope = 0.0, crest = 0.0;
|
|
115
|
+
for (int k = 0; k < 3; k++) {
|
|
116
|
+
float f = float(k), wt = 1.0 / (1.0 + 1.6 * f);
|
|
117
|
+
vec2 e = normalize(d + vec2(-d.y, d.x) * (f - 1.0) * 0.35);
|
|
118
|
+
float ph = fract(dot(p, e) * u[4].w * (1.0 + 0.45 * f) + u[5].w * fbm(p * (1.5 + f), 1024.0, s + 10u + uint(k) * 4u, 3));
|
|
119
|
+
slope += cos(3.1415927 * ph) * wt;
|
|
120
|
+
crest = max(crest, sin(3.1415927 * ph) * wt);
|
|
121
|
+
}
|
|
122
|
+
float sh = clamp(0.5 + 0.3 * slope, 0.0, 1.0), gloss = smoothstep(0.7, 1.0, sh) * crest;
|
|
123
|
+
vec3 c = mix(u[4].rgb, u[5].rgb, smoothstep(0.15, 0.6, sh));
|
|
124
|
+
return mix(c, u[6].rgb, smoothstep(0.6, 0.95, sh)) + u[6].w * gloss * gloss * u[6].rgb;
|
|
125
|
+
}
|
|
126
|
+
void surface(vec2 uv, out float h, out vec3 c) {
|
|
127
|
+
uint s = uint(u[0].w);
|
|
128
|
+
vec2 p = vec2(uv.x * u[3].x, uv.y), bd = u[2].xy;
|
|
129
|
+
float len = u[2].z, b = fbm(vec2(dot(p, bd) * len, dot(p, vec2(-bd.y, bd.x)) * len * 4.0), 1024.0, s, 3);
|
|
130
|
+
c = u[0].rgb * (1.0 + u[3].z * (fbm(p * 3.0, 1024.0, s + 1u, 3) - 0.5) * 2.0);
|
|
131
|
+
if (u[4].w > 0.0) c = folds(p, s);
|
|
132
|
+
float top = 0.0;
|
|
133
|
+
int count = int(u[3].y);
|
|
134
|
+
for (int i = 0; i < 10; i++) {
|
|
135
|
+
if (i >= count) break;
|
|
136
|
+
int o = 8 + i * 5;
|
|
137
|
+
vec4 at = u[o], ax = u[o + 1], dark = u[o + 2], lit = u[o + 3];
|
|
138
|
+
vec2 d = p - at.xy, l = vec2(dot(d, ax.xy) / at.z, dot(d, vec2(-ax.y, ax.x)) / at.w);
|
|
139
|
+
l.y /= max(mix(1.0, sqrt(max(1.0 - l.x * l.x, 0.0)), u[o + 4].x), 0.05);
|
|
140
|
+
float r = length(l);
|
|
141
|
+
if (r > 1.0 + 0.5 * dark.w) continue;
|
|
142
|
+
r += dark.w * (fbm(p * 9.0, 1024.0, s + 60u + uint(i), 4) - 0.5);
|
|
143
|
+
float mask = 1.0 - smoothstep(1.0 - ax.z, 1.0, r);
|
|
144
|
+
float n = ax.w > 0.0
|
|
145
|
+
? fract(r * 2.6 + 1.1 * fbm(vec2((atan(l.y, l.x) / 6.2831853 + 0.5) * 6.0, r), 6.0, s + 80u + uint(i), 2))
|
|
146
|
+
: 0.6 * fbm(vec2(l.x * 2.0 + float(i) * 7.0, l.y * 4.0), 1024.0, s + 80u, 2) + 0.4 * vn(vec2(l.x * 3.0, l.y * 14.0), 1024.0, s + 90u);
|
|
147
|
+
float lt = clamp(0.5 - 0.4 * l.y + lit.w * (n - 0.5) * 2.0, 0.0, 1.0);
|
|
148
|
+
vec3 m = mix(dark.rgb, lit.rgb, smoothstep(0.2, 0.9, lt)) * (0.85 + 0.15 * (1.0 - r * r));
|
|
149
|
+
c = mix(c, m, mask);
|
|
150
|
+
top = mix(top, n, mask);
|
|
151
|
+
}
|
|
152
|
+
c *= 1.0 + u[2].w * ((b - 0.5) * 1.2 + (vn(p * 240.0, 1024.0, s + 7u) - 0.5) * 0.5);
|
|
153
|
+
c = mix(c, u[1].rgb, u[1].w * fbm(p * 1.5, 1024.0, s + 3u, 3));
|
|
154
|
+
h = 0.5 + u[2].w * (b - 0.5) + 0.15 * top;
|
|
155
|
+
}
|
|
156
|
+
`,Ae=`
|
|
157
|
+
void main() {
|
|
158
|
+
vec2 px = 1.0 / uView.xy, uv = gl_FragCoord.xy * px, dx = vec2(px.x, 0.0), dy = vec2(0.0, px.y);
|
|
159
|
+
float h, l, r, t, b;
|
|
160
|
+
vec3 c, z;
|
|
161
|
+
surface(uv, h, c);
|
|
162
|
+
surface(uv - dx, l, z);
|
|
163
|
+
surface(uv + dx, r, z);
|
|
164
|
+
surface(uv - dy, t, z);
|
|
165
|
+
surface(uv + dy, b, z);
|
|
166
|
+
float k = 0.5 * uView.z * uView.y;
|
|
167
|
+
oAlbedo = vec4(clamp(c, 0.0, 1.0), 1.0);
|
|
168
|
+
oRelief = vec4(normalize(vec3((l - r) * k, (b - t) * k, 1.0)) * 0.5 + 0.5, clamp(h, 0.0, 1.0));
|
|
169
|
+
}`,Q=[Re,Se,Pe].map(e=>ke+e+Ae);function Te(e,r){let t=e.createProgram();for(let[n,o]of[[e.VERTEX_SHADER,J],[e.FRAGMENT_SHADER,r]]){let a=e.createShader(n);if(!a)throw new Error("surfaces: no shader.");e.shaderSource(a,o),e.compileShader(a),e.attachShader(t,a),e.deleteShader(a)}if(e.linkProgram(t),!e.getProgramParameter(t,e.LINK_STATUS)){let n=(e.getAttachedShaders(t)??[]).map(o=>e.getShaderInfoLog(o)??"").join(`
|
|
170
|
+
`);throw new Error(`surfaces: a painter did not compile.
|
|
171
|
+
${e.getProgramInfoLog(t)??""}
|
|
172
|
+
${n}`)}return t}function Ee(e){let r=e.getParameter(e.FRAMEBUFFER_BINDING),t=e.getParameter(e.VIEWPORT),n=e.getParameter(e.CURRENT_PROGRAM),o=e.getParameter(e.VERTEX_ARRAY_BINDING),a=e.getParameter(e.TEXTURE_BINDING_2D),u=e.getParameter(e.PIXEL_PACK_BUFFER_BINDING),i=[e.BLEND,e.DEPTH_TEST,e.CULL_FACE,e.SCISSOR_TEST,e.STENCIL_TEST].map(s=>[s,e.isEnabled(s)]);for(let[s]of i)e.disable(s);return e.bindBuffer(e.PIXEL_PACK_BUFFER,null),()=>{for(let[s,f]of i)f&&e.enable(s);e.bindBuffer(e.PIXEL_PACK_BUFFER,u),e.bindTexture(e.TEXTURE_2D,a),e.bindFramebuffer(e.FRAMEBUFFER,r),e.viewport(t[0]??0,t[1]??0,t[2]??0,t[3]??0),e.useProgram(n),e.bindVertexArray(o)}}function Me(e,r){return[0,1].map(t=>{let n=e.createTexture();return e.bindTexture(e.TEXTURE_2D,n),e.texStorage2D(e.TEXTURE_2D,1,e.RGBA8,r.width,r.height),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.TEXTURE_2D,n,0),n})}function Z(e,r,t){let n=new ArrayBuffer(r.width*r.height*4);return e.readBuffer(t),e.readPixels(0,0,r.width,r.height,e.RGBA,e.UNSIGNED_BYTE,new Uint8Array(n)),n}function Le(e){let r=new Map,t=o=>{let a=r.get(o);if(a)return a;let u=Te(e,Q[o]??"");return r.set(o,u),u},n=o=>{let a=t(L[o.kind]),u=Ee(e),i=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,i);let s=Me(e,o);e.drawBuffers([e.COLOR_ATTACHMENT0,e.COLOR_ATTACHMENT1]),e.viewport(0,0,o.width,o.height),e.useProgram(a),e.uniform4fv(e.getUniformLocation(a,"u"),o.uniforms),e.uniform3f(e.getUniformLocation(a,"uView"),o.width,o.height,o.depth),e.bindVertexArray(null),e.drawArrays(e.TRIANGLES,0,3);let f=[Z(e,o,e.COLOR_ATTACHMENT0),Z(e,o,e.COLOR_ATTACHMENT1)];e.deleteFramebuffer(i);for(let c of s)e.deleteTexture(c);return u(),{digest:o.digest,width:o.width,height:o.height,buffers:f}};return{paint:(o,a)=>n(F(o,a)),paintPlan:n,dispose(){for(let o of r.values())e.deleteProgram(o);r.clear()}}}function ee(e,r){e.colorSpace=r.data===!0?"":"srgb",e.wrapS=r.repeat===!0?"repeat":"clamp",e.wrapT=e.wrapS,e.anisotropy=8,e.needsUpdate=!0}function De(e,r){return(t,n,o={})=>{let[a,u]=typeof t=="number"?[t,t]:t,i=r(a,u),s=i.getContext("2d");if(!s)throw new Error("surfaces: no 2D context for a print.");n(s,a,u);let f=new e.CanvasTexture(i);return ee(f,o),f}}function ze(e,r){let t=n=>Math.round(Math.min(Math.max(n,0),1)*255);return`rgb(255 ${t(e)} ${t(r)})`}function Fe(e,r){let[t,n]=r.buffers.map((o,a)=>{let u=new e.DataTexture(new Uint8Array(o),r.width,r.height);return ee(u,{data:a===1,repeat:!0}),u.magFilter="linear",u.minFilter="linear-mipmap-linear",u.generateMipmaps=!0,u.flipY=!0,u});return{map:t,normalMap:n}}export{L as KINDS,oe as KNIT,O as MAX_MASSES,se as PAINTED_CLOTH,ae as PAINTED_FLORAL,$ as PAINTER_VERSION,ne as PAPER,U as PLANNED,W as UNIFORMS,De as createPrinter,Le as createSurfacePainter,Y as paintPlan,ve as paintSurface,ze as pbr,F as planSurface,Fe as surfaceTextures};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tracks: keyed tracks sampled at a position. MIT.
|
|
3
|
+
*
|
|
4
|
+
* A track keys one property of one target. Each key is `[position, value,
|
|
5
|
+
* handles?]`: the position in the sequence's own units (a scrolled page uses
|
|
6
|
+
* one unit per viewport), the value there, and the cubic-bezier handle pair
|
|
7
|
+
* that eases the way from this key to the next, (.5, 0, .5, 1) when left out.
|
|
8
|
+
* Values are numbers, vectors (arrays of numbers) or `#rrggbb` colours. Before
|
|
9
|
+
* the first key and after the last the track holds. A clip's progress is a
|
|
10
|
+
* number track like any other. Pure arithmetic: no DOM, no renderer, nothing
|
|
11
|
+
* injected. The host samples and applies.
|
|
12
|
+
*/
|
|
13
|
+
/** A cubic-bezier handle pair, `[x1, y1, x2, y2]`, as CSS `cubic-bezier()` takes it. */
|
|
14
|
+
export type Handles = readonly [number, number, number, number];
|
|
15
|
+
/** What a key holds: a number, a vector or a `#rrggbb` colour. One track keeps to one kind. */
|
|
16
|
+
export type Value = number | readonly number[] | string;
|
|
17
|
+
/** One key: the position, the value there, and the handles easing the way to the next key. */
|
|
18
|
+
export type Key = readonly [position: number, value: Value, handles?: Handles];
|
|
19
|
+
/** One property of one target, keyed. `drive` says what samples it: scroll position (the default) or the clock. */
|
|
20
|
+
export interface Track {
|
|
21
|
+
readonly target: string;
|
|
22
|
+
readonly property: string;
|
|
23
|
+
readonly keys: readonly Key[];
|
|
24
|
+
readonly drive?: "scrub" | "time";
|
|
25
|
+
}
|
|
26
|
+
/** Sampled values by target, then property. */
|
|
27
|
+
export type Sampled = Record<string, Record<string, Value>>;
|
|
28
|
+
/** The handles a key gets when it names none: a symmetric ease in and out. */
|
|
29
|
+
export declare const EASE: Handles;
|
|
30
|
+
/**
|
|
31
|
+
* The eased share of a segment: the bezier's y where its x is `u`.
|
|
32
|
+
*
|
|
33
|
+
* @param handles The segment's handle pair; x1 and x2 in 0..1 so the curve is a function of x.
|
|
34
|
+
* @param u How far along the segment, 0..1; clamped.
|
|
35
|
+
* @returns The eased share, 0 at the start and 1 at the end.
|
|
36
|
+
*/
|
|
37
|
+
export declare function ease(handles: Handles, u: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Mixes two values of one kind: numbers, vectors element by element, colours channel by channel.
|
|
40
|
+
* Values of different kinds step from `a` to `b` at t = 1.
|
|
41
|
+
*
|
|
42
|
+
* @param a The value at t = 0.
|
|
43
|
+
* @param b The value at t = 1.
|
|
44
|
+
* @param t The share of `b`; may leave 0..1 when an ease overshoots.
|
|
45
|
+
* @returns The mixed value, of the kind `a` and `b` share.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mix(a: Value, b: Value, t: number): Value;
|
|
48
|
+
/**
|
|
49
|
+
* The value of one track at `at`: held before the first key and after the last, eased between.
|
|
50
|
+
*
|
|
51
|
+
* @param keys The track's keys in position order.
|
|
52
|
+
* @param at The position to sample.
|
|
53
|
+
* @returns The value there.
|
|
54
|
+
* @throws RangeError when the track has no key.
|
|
55
|
+
*/
|
|
56
|
+
export declare function sampleTrack(keys: readonly Key[], at: number): Value;
|
|
57
|
+
/**
|
|
58
|
+
* Samples every track: scrub tracks at `position`, time tracks at `time`. Without a `time`, time
|
|
59
|
+
* tracks are left out.
|
|
60
|
+
*
|
|
61
|
+
* @param tracks The tracks, as the motion spec lists them.
|
|
62
|
+
* @param position The scroll position in sequence units; may be below 0 or past the last key.
|
|
63
|
+
* @param time The clock, for tracks with `drive: "time"`.
|
|
64
|
+
* @returns Values by target, then property.
|
|
65
|
+
*/
|
|
66
|
+
export declare function sampleTracks(tracks: readonly Track[], position: number, time?: number): Sampled;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tracks/index.js'
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// tracks@0.1.0 from keel-modules 53c36d0 (MIT). Generated: don't edit.
|
|
2
|
+
var e=[.5,0,.5,1],t=(e,t,r)=>(((1-3*t+3*e)*r+(3*t-6*e))*r+3*e)*r;function r(e,r){if(r<=0)return 0;if(r>=1)return 1;let[n,o,a,i]=e,f=0,l=1,s=.5;for(let e=0;e<32;e+=1){s=(f+l)/2;let e=t(n,a,s);if(e===r)break;e<r?f=s:l=s}return t(o,i,s)}var n=(e,t)=>parseInt(e.slice(1+2*t,3+2*t),16);function o(e,t,r){return"number"==typeof e&&"number"==typeof t?e+(t-e)*r:"string"==typeof e&&"string"==typeof t?function(e,t,r){let o="#";for(let a=0;a<3;a+=1){let i=n(e,a),f=Math.min(255,Math.max(0,Math.round(i+(n(t,a)-i)*r)));o+=(f<16?"0":"")+f.toString(16)}return o}(e,t,r):"object"==typeof e&&"object"==typeof t?e.map((e,n)=>e+((t[n]??e)-e)*r):r<1?e:t}function a(t,n){let a=t[0];if(void 0===a)throw new RangeError("A track needs at least one key.");let i=0;for(let e=t[1];void 0!==e&&e[0]<=n;e=t[i+1])i+=1;let f=t[i]??a,l=t[i+1];return void 0===l||n<=f[0]?f[1]:o(f[1],l[1],r(f[2]??e,(n-f[0])/(l[0]-f[0])))}function i(e,t,r){let n={};for(let o of e){let e="time"===o.drive?r:t;void 0!==e&&((n[o.target]??={})[o.property]=a(o.keys,e))}return n}export{e as EASE,r as ease,o as mix,a as sampleTrack,i as sampleTracks};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TreeModel } from "./model.js";
|
|
2
|
+
import type { TreeFrame } from "./frame.js";
|
|
3
|
+
/**
|
|
4
|
+
* Weight resting on a node of the tree (an animal on a branch), pulling it down. A negative weight lifts it, as a limb
|
|
5
|
+
* springs back past rest.
|
|
6
|
+
*/
|
|
7
|
+
export interface Load {
|
|
8
|
+
readonly node: number;
|
|
9
|
+
readonly weight: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* How readily wood bends: each piece of the limb under a load turns by this
|
|
13
|
+
* × weight × lever × its length ÷ radius⁴, as a beam does. A thin twig dips
|
|
14
|
+
* under a songbird; a thick limb hardly moves under a monkey; the trunk never.
|
|
15
|
+
*/
|
|
16
|
+
export declare const WOOD_SAG = 0.000006;
|
|
17
|
+
/**
|
|
18
|
+
* The frame with branches bent under `loads`: a bird's twig dips, a monkey's
|
|
19
|
+
* limb sags, the trunk hardly moves. Pass `out` from the last call to reuse
|
|
20
|
+
* its arrays (the same object comes back, so a renderer can tell it is the
|
|
21
|
+
* same pose); everything but the positions is shared with `frame`. `sag` is
|
|
22
|
+
* how far a unit weight bends a unit limb, the wood's own when left out.
|
|
23
|
+
*/
|
|
24
|
+
export interface BendInto {
|
|
25
|
+
readonly out?: TreeFrame;
|
|
26
|
+
readonly sag?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function bendFrame(model: TreeModel, frame: TreeFrame, loads: readonly Load[], into?: BendInto): TreeFrame;
|