@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,67 @@
|
|
|
1
|
+
import { capFrame } from "./cap.js";
|
|
2
|
+
import { type Part } from "./parts.js";
|
|
3
|
+
import type { Features } from "./head.js";
|
|
4
|
+
import type { M3, V3 } from "./sdf.js";
|
|
5
|
+
export { type Part } from "./parts.js";
|
|
6
|
+
/** Which material a part draws with. */
|
|
7
|
+
export declare const PARTS: {
|
|
8
|
+
skin: number;
|
|
9
|
+
hand: number;
|
|
10
|
+
eye: number;
|
|
11
|
+
cap: number;
|
|
12
|
+
hair: number;
|
|
13
|
+
dress: number;
|
|
14
|
+
chemise: number;
|
|
15
|
+
gown: number;
|
|
16
|
+
gold: number;
|
|
17
|
+
card: number;
|
|
18
|
+
};
|
|
19
|
+
/** How a part sits: a rotation (rows take a point in) and where its origin is. */
|
|
20
|
+
export interface Pose {
|
|
21
|
+
readonly turn: M3;
|
|
22
|
+
readonly at: V3;
|
|
23
|
+
}
|
|
24
|
+
export interface Detail {
|
|
25
|
+
/** Cell sizes in metres: the face, the rest of the skin, the hand, cloth and the cap. */
|
|
26
|
+
readonly face: number;
|
|
27
|
+
readonly body: number;
|
|
28
|
+
readonly hand: number;
|
|
29
|
+
readonly cloth: number;
|
|
30
|
+
/** Rings of an eye; locks of hair, and each lock's segments and sides. */
|
|
31
|
+
readonly eye: number;
|
|
32
|
+
readonly locks: number;
|
|
33
|
+
readonly segments: number;
|
|
34
|
+
readonly sides: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const DETAIL: Readonly<Record<"hero" | "mid" | "far", Detail>>;
|
|
37
|
+
/** Where the head's frame sits for each face version: A frontal, B turned and pitched down about the skull. */
|
|
38
|
+
export declare function headPose(face: "A" | "B"): Pose;
|
|
39
|
+
export interface BustRecipe {
|
|
40
|
+
readonly seed: number;
|
|
41
|
+
readonly face: "A" | "B";
|
|
42
|
+
readonly detail: Detail;
|
|
43
|
+
/** The hand: index raised with the card floating above it, or the card pinched. */
|
|
44
|
+
readonly hand: "point" | "pinch";
|
|
45
|
+
}
|
|
46
|
+
export interface Bust {
|
|
47
|
+
readonly parts: readonly Part[];
|
|
48
|
+
readonly pose: Pose;
|
|
49
|
+
readonly eyes: readonly [V3, V3];
|
|
50
|
+
readonly cap: ReturnType<typeof capFrame>;
|
|
51
|
+
/** Where the card is, in the bust's frame. */
|
|
52
|
+
readonly card: Pose;
|
|
53
|
+
readonly nails: readonly Nail[];
|
|
54
|
+
}
|
|
55
|
+
/** What a seed decides of the face, each a small share either side of the mean. */
|
|
56
|
+
export declare function featuresOf(seed: number): Features;
|
|
57
|
+
/** The last bone of each finger and the thumb, in the hand's frame: its two ends, its radius and its back. */
|
|
58
|
+
export interface Nail {
|
|
59
|
+
readonly from: V3;
|
|
60
|
+
readonly to: V3;
|
|
61
|
+
readonly radius: number;
|
|
62
|
+
readonly back: V3;
|
|
63
|
+
}
|
|
64
|
+
/** The recipe's digest: what the cache is keyed by. */
|
|
65
|
+
export declare function digestOf(recipe: BustRecipe): string;
|
|
66
|
+
/** The bust for a recipe, meshed once and then taken from the cache. */
|
|
67
|
+
export declare function buildBust(recipe: BustRecipe): Bust;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node, V3 } from "./sdf.js";
|
|
2
|
+
/** The cap's measures: the plane of the cuff's lower edge (`normal`·p = `edge`), the cuff's height, its axis. */
|
|
3
|
+
export interface CapFrame {
|
|
4
|
+
readonly normal: V3;
|
|
5
|
+
readonly edge: number;
|
|
6
|
+
readonly cuff: number;
|
|
7
|
+
readonly centre: V3;
|
|
8
|
+
}
|
|
9
|
+
/** Where the cap sits: version B pulls it 1 cm lower, so its shadow falls over the eyes. */
|
|
10
|
+
export declare function capFrame(face: "A" | "B"): CapFrame;
|
|
11
|
+
/** The cap: its body above the cuff's edge, the folded cuff a little proud of it. */
|
|
12
|
+
export declare function capShape(frame: CapFrame): Node;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Field, Node } from "./sdf.js";
|
|
2
|
+
/** A ball of space: a centre and a radius. */
|
|
3
|
+
export type Ball = readonly [number, number, number, number];
|
|
4
|
+
/**
|
|
5
|
+
* The distance function of `node` for points within `ball`, correct wherever the surface is within `slack`, or null
|
|
6
|
+
* if nothing of it comes within `slack` of the ball.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compile(node: Node, ball: Ball, slack: number): Field | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { M3 } from "./sdf.js";
|
|
2
|
+
/** The sine of an angle of any size, within 5e-16 of Math.sin's. */
|
|
3
|
+
export declare function sine(x: number): number;
|
|
4
|
+
export declare function cosine(x: number): number;
|
|
5
|
+
/** Degrees to radians. */
|
|
6
|
+
export declare const deg: (d: number) => number;
|
|
7
|
+
/**
|
|
8
|
+
* A rotation from turns about x (pitch, + tips the top forward so the front looks down), y (yaw, + turns the front
|
|
9
|
+
* toward +x) and z (roll, + tips the top toward -x), applied z, then x, then y. Rows take a point into the frame.
|
|
10
|
+
*/
|
|
11
|
+
export declare function turn(pitch: number, yaw: number, roll: number): M3;
|
|
12
|
+
/** A 32-bit hash of whole numbers (integer only). */
|
|
13
|
+
export declare function hash32(...values: number[]): number;
|
|
14
|
+
/** A share in [0, 1) from whole numbers. */
|
|
15
|
+
export declare function unit(...values: number[]): number;
|
|
16
|
+
/** A number between `lo` and `hi`, decided by a seed and a name. */
|
|
17
|
+
export declare function pick(seed: number, slot: number, lo: number, hi: number): number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Field, M3, V3 } from "./sdf.js";
|
|
2
|
+
import type { CapFrame } from "./cap.js";
|
|
3
|
+
export interface HairRecipe {
|
|
4
|
+
readonly seed: number;
|
|
5
|
+
/** How many locks, and the rings and segments of each. */
|
|
6
|
+
readonly locks: number;
|
|
7
|
+
readonly segments: number;
|
|
8
|
+
readonly sides: number;
|
|
9
|
+
/** How long the hair falls, in metres. */
|
|
10
|
+
readonly length: number;
|
|
11
|
+
}
|
|
12
|
+
/** Where the head sits in the bust: hair is built in the bust's frame, its roots placed by the head. */
|
|
13
|
+
export interface HairPlace {
|
|
14
|
+
readonly turn: M3;
|
|
15
|
+
readonly at: V3;
|
|
16
|
+
}
|
|
17
|
+
/** The locks as tubes: position, normal, rest (round the tube, along it, the lock's tone) and flow (the tangent). */
|
|
18
|
+
export interface HairMesh {
|
|
19
|
+
readonly position: Float32Array;
|
|
20
|
+
readonly normal: Float32Array;
|
|
21
|
+
readonly rest: Float32Array;
|
|
22
|
+
readonly flow: Float32Array;
|
|
23
|
+
readonly open: Float32Array;
|
|
24
|
+
readonly index: Uint32Array;
|
|
25
|
+
}
|
|
26
|
+
export declare function hairMesh(recipe: HairRecipe, cap: CapFrame, body: Field, place: HairPlace): HairMesh;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Node, V3 } from "./sdf.js";
|
|
2
|
+
/** How each finger's three joints bend (degrees, index to little), and where the thumb's tip goes. */
|
|
3
|
+
export interface HandPose {
|
|
4
|
+
readonly bend: readonly (readonly [number, number, number])[];
|
|
5
|
+
readonly spread: readonly number[];
|
|
6
|
+
/** The thumb's tip: a finger (0 index, 1 middle) and a share along its last bone, or null for the thumb's rest. */
|
|
7
|
+
readonly thumbTo: readonly [number, number] | null;
|
|
8
|
+
}
|
|
9
|
+
/** Index raised, the thumb ringed with the middle finger, the others curled. */
|
|
10
|
+
export declare const POINT: HandPose;
|
|
11
|
+
/** Index and thumb pads together, as holding a card's edge; the others curled behind. */
|
|
12
|
+
export declare const PINCH: HandPose;
|
|
13
|
+
export interface Finger {
|
|
14
|
+
/** Joints from the knuckle to the tip. */
|
|
15
|
+
readonly joints: readonly V3[];
|
|
16
|
+
readonly radius: number;
|
|
17
|
+
/** The back of the last bone, a unit direction (where its nail is). */
|
|
18
|
+
readonly back: V3;
|
|
19
|
+
}
|
|
20
|
+
/** A finger's joints: each bone turned toward the palm by the bend so far, and out by its spread. */
|
|
21
|
+
export declare function finger(i: number, pose: HandPose): Finger;
|
|
22
|
+
/** The thumb's joints: its base fixed, its two outer bones bent to reach the target. */
|
|
23
|
+
export declare function thumb(pose: HandPose, fingers: readonly Finger[]): Finger;
|
|
24
|
+
export interface HandShape {
|
|
25
|
+
readonly node: Node;
|
|
26
|
+
readonly fingers: readonly Finger[];
|
|
27
|
+
readonly thumb: Finger;
|
|
28
|
+
}
|
|
29
|
+
/** The hand posed. Each finger melts into the palm on its own, then the hand is their union. */
|
|
30
|
+
export declare function handShape(pose: HandPose): HandShape;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Node } from "./sdf.js";
|
|
2
|
+
/** What a seed decides of a face, each a share around 1. */
|
|
3
|
+
export interface Features {
|
|
4
|
+
/** Half the distance between the eyes' centres, in metres. */
|
|
5
|
+
readonly eyes: number;
|
|
6
|
+
readonly nose: number;
|
|
7
|
+
readonly lips: number;
|
|
8
|
+
readonly jaw: number;
|
|
9
|
+
readonly chin: number;
|
|
10
|
+
readonly cheeks: number;
|
|
11
|
+
}
|
|
12
|
+
/** The eyeball's radius, and how far its centre sits in front of the head frame's origin. */
|
|
13
|
+
export declare const EYE = 0.0118;
|
|
14
|
+
export declare const EYE_Z = 0.005;
|
|
15
|
+
/** How far the open upper lid's edge plane sits below the eye's centre (the shader shares it). */
|
|
16
|
+
export declare const LID_DROP = 0.0018;
|
|
17
|
+
/** The head as one shape, in its own frame. */
|
|
18
|
+
export declare function headShape(p: Features): Node;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* portrait: a seeded waist-up bust at hero detail, sculpted from signed distances and meshed when it is generated,
|
|
3
|
+
* with a portrait shading path for keel/lit (soft warm key, cool fill, wrap and under-skin light). MIT.
|
|
4
|
+
*/
|
|
5
|
+
export { buildBust, digestOf, featuresOf, DETAIL, PARTS, headPose } from "./bust.js";
|
|
6
|
+
export type { Bust, BustRecipe, Detail, Nail, Part, Pose } from "./bust.js";
|
|
7
|
+
export { createPortrait, LIGHT, PALETTE } from "./render.js";
|
|
8
|
+
export type { FaceState, Palette, Portrait, PortraitLight, PortraitLit } from "./render.js";
|
|
9
|
+
export { DEFAULT_PORTRAIT_SETTINGS, portraitSettings, sitterOf } from "./settings.js";
|
|
10
|
+
export type { PortraitSettings } from "./settings.js";
|
|
11
|
+
export { cosine, deg, hash32, sine, turn } from "./exact.js";
|
|
12
|
+
export type { Features } from "./head.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Field, Node, V3 } from "./sdf.js";
|
|
2
|
+
/** A mesh as flat arrays. */
|
|
3
|
+
export interface Surface {
|
|
4
|
+
readonly position: Float32Array;
|
|
5
|
+
readonly normal: Float32Array;
|
|
6
|
+
/** How open each vertex lies, 0 shut to 1 open. */
|
|
7
|
+
readonly open: Float32Array;
|
|
8
|
+
readonly index: Uint32Array;
|
|
9
|
+
}
|
|
10
|
+
export interface Grid {
|
|
11
|
+
/** The box to mesh within. */
|
|
12
|
+
readonly lo: V3;
|
|
13
|
+
readonly hi: V3;
|
|
14
|
+
/** A cell's edge in metres. */
|
|
15
|
+
readonly cell: number;
|
|
16
|
+
/** How far out the openness looks, in metres; 0 for none. */
|
|
17
|
+
readonly reach: number;
|
|
18
|
+
/** Other shapes that shade this one but are not meshed with it. */
|
|
19
|
+
readonly shade?: Node;
|
|
20
|
+
}
|
|
21
|
+
/** The field's gradient at `p`, by four samples on a tetrahedron `e` across, normalised. */
|
|
22
|
+
export declare function gradient(f: Field, p: readonly [number, number, number], e: number): [number, number, number];
|
|
23
|
+
/** Mesh a shape within a box at a cell size. */
|
|
24
|
+
export declare function surface(node: Node, grid: Grid): Surface;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { M3, Node, V3 } from "./sdf.js";
|
|
2
|
+
export interface Part {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
/** Its material, one of `PARTS`. */
|
|
5
|
+
readonly kind: number;
|
|
6
|
+
readonly position: Float32Array;
|
|
7
|
+
readonly normal: Float32Array;
|
|
8
|
+
/** How open each vertex lies, 0 to 1. */
|
|
9
|
+
readonly open: Float32Array;
|
|
10
|
+
/** Where each vertex lies in the part's own frame, for what is painted on it. */
|
|
11
|
+
readonly rest: Float32Array;
|
|
12
|
+
/** A direction along the surface and a fourth number, for what has a grain (hair). */
|
|
13
|
+
readonly flow?: Float32Array | undefined;
|
|
14
|
+
readonly index: Uint32Array;
|
|
15
|
+
}
|
|
16
|
+
interface Placing {
|
|
17
|
+
readonly turn: M3;
|
|
18
|
+
readonly at: V3;
|
|
19
|
+
}
|
|
20
|
+
/** A part built in its own frame, moved into the bust's by a pose. Its rest coordinates stay its own. */
|
|
21
|
+
export declare function placed(part: Part, pose: Placing): Part;
|
|
22
|
+
/** A ball of rings and segments, as an eye; its rest coordinates are in the head's frame. */
|
|
23
|
+
export declare function eyeball(kind: number, ball: {
|
|
24
|
+
centre: V3;
|
|
25
|
+
radius: number;
|
|
26
|
+
}, rings: number, pose: Placing): Part;
|
|
27
|
+
/** The card's size: its width (1.586 : 1) and thickness, metres. */
|
|
28
|
+
export declare const CARD: readonly [number, number, number];
|
|
29
|
+
/** A card: a rounded rectangle with thickness, its rest coordinates its own (x across, y up, z through). */
|
|
30
|
+
export declare function cardPart(kind: number, pose: Placing): Part;
|
|
31
|
+
/** A fine chain laid on the body: a thin tube along `path`, pressed onto the surface of `body`. */
|
|
32
|
+
export declare function chainPart(kind: number, path: readonly V3[], body: Node): Part;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const VERTEX_GLSL = "\nattribute float aOpen;\nattribute vec3 aRest;\nattribute vec4 aFlow;\nvarying vec3 vWorld;\nvarying vec3 vNormal;\nvarying vec3 vRest;\nvarying vec4 vFlow;\nvarying float vOpen;\nvarying vec4 vShadowAt;\nuniform mat4 uShadowMatrix; // the world into the key light's view\nvoid main() {\n vec4 world = modelMatrix * vec4(position, 1.0);\n vWorld = world.xyz;\n vNormal = normalize(mat3(modelMatrix) * normal);\n vRest = aRest;\n vFlow = vec4(normalize(mat3(modelMatrix) * (aFlow.xyz + vec3(0.0, 1e-6, 0.0))), aFlow.w);\n vOpen = aOpen;\n vShadowAt = uShadowMatrix * world;\n gl_Position = projectionMatrix * viewMatrix * world;\n}\n";
|
|
2
|
+
export declare const SHADOW_VERTEX_GLSL = "\nvarying float vDepth;\nuniform float uShadowFar;\nvoid main() {\n vec4 view = viewMatrix * modelMatrix * vec4(position, 1.0);\n vDepth = -view.z / uShadowFar;\n gl_Position = projectionMatrix * view;\n}\n";
|
|
3
|
+
export declare const SHADOW_FRAGMENT_GLSL = "\nvarying float vDepth;\nvoid main() { gl_FragColor = vec4(vDepth, 0.0, 0.0, 1.0); }\n";
|
|
4
|
+
export declare const FRAGMENT_GLSL = "\n\nuniform vec3 uKey; // toward the key light\nuniform vec3 uKeyColor;\nuniform vec3 uSky; // the fill's sky and ground colours\nuniform vec3 uGround;\nuniform vec3 uFillDir;\nuniform sampler2D uShadowMap;\nuniform vec4 uShadow; // texel, softness in texels, bias, on\nuniform vec2 uShadowBox; // the light view's half width and far plane\nuniform float uTime;\nvarying vec3 vWorld;\nvarying vec3 vNormal;\nvarying vec3 vRest;\nvarying vec4 vFlow;\nvarying float vOpen;\nvarying vec4 vShadowAt;\n\nfloat hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }\nfloat noise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = fract(p);\n f = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);\n}\nfloat fbm(vec2 p) { return 0.5 * noise(p) + 0.3 * noise(p * 2.03 + 7.1) + 0.2 * noise(p * 4.1 + 3.3); }\n\n// The key's soft shadow: a ring of samples in the light's depth map.\nfloat keyShadow(vec3 n) {\n if (uShadow.w < 0.5) return 1.0;\n vec2 uv = vShadowAt.xy / uShadowBox.x * 0.5 + 0.5;\n if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) return 1.0;\n float depth = -vShadowAt.z / uShadowBox.y;\n float bias = uShadow.z * (1.0 + 3.0 * (1.0 - clamp(dot(n, uKey), 0.0, 1.0)));\n float lit = 0.0;\n float spin = hash(gl_FragCoord.xy) * 6.2832;\n for (int i = 0; i < 12; i++) {\n float a = spin + float(i) * 2.39996;\n float r = sqrt((float(i) + 0.5) / 12.0) * uShadow.y;\n vec2 o = vec2(cos(a), sin(a)) * r * uShadow.x;\n lit += texture2D(uShadowMap, uv + o).r + bias < depth ? 0.0 : 1.0;\n }\n return lit / 12.0;\n}\n\nvec3 fill(vec3 n) { return mix(uGround, uSky, dot(n, uFillDir) * 0.5 + 0.5); }\n\n\nuniform vec4 uEyeL; // the eyes' centres in the head's frame, and the eye's radius\nuniform vec4 uEyeR;\nuniform vec4 uLid; // how far the lids are down (0 open, 1 shut), tilt's sine and cosine\nuniform vec3 uSkinTone;\nuniform vec3 uLipTone;\nuniform vec3 uBlushTone;\nuniform vec3 uBrowTone;\n\n// How far below the eye's centre the open upper lid's edge sits (head.ts, LID_DROP).\nconst float LID_DROP = 0.0018;\n\nfloat ellipse(vec2 p, vec2 c, vec2 r) { vec2 q = (p - c) / r; return dot(q, q); }\n\n// Where the upper lid's edge is, as a distance past it (+ on the lid), in the eye's own frame.\nvec3 eyeFrame(vec3 p, vec4 eye, float side) {\n vec3 q = p - eye.xyz;\n float s = uLid.y * side;\n return vec3(uLid.z * q.x + s * q.y, -s * q.x + uLid.z * q.y, q.z);\n}\n\n// Lips, blush, brows, the line of the lashes: painted from where the skin lies on the head at rest.\nvec3 skinAlbedo(vec3 r, out float gloss) {\n vec3 base = uSkinTone;\n gloss = 0.25;\n float front = smoothstep(0.005, 0.02, r.z);\n float ax = abs(r.x);\n // Blush on the cheeks, the nose's tip, the ears and the chin.\n float blush = exp(-ellipse(vec2(ax, r.y), vec2(0.036, -0.026), vec2(0.022, 0.018)));\n blush += 0.45 * exp(-ellipse(r.xy, vec2(0.0, -0.041), vec2(0.009, 0.008)));\n blush += 0.25 * exp(-ellipse(r.xy, vec2(0.0, -0.098), vec2(0.012, 0.01)));\n blush += 0.6 * smoothstep(0.06, 0.075, ax) * (1.0 - smoothstep(-0.045, -0.06, r.z));\n base = mix(base, uBlushTone, clamp(blush * 0.5, 0.0, 0.6));\n // Lips.\n float upper = min(ellipse(vec2(ax, r.y), vec2(0.009, -0.0643), vec2(0.0138, 0.0033)),\n ellipse(r.xy, vec2(0.0, -0.0655), vec2(0.005, 0.0032)));\n float lower = ellipse(r.xy, vec2(0.0, -0.0718), vec2(0.0172, 0.0056));\n float lip = (1.0 - smoothstep(0.55, 1.15, min(upper, lower))) * front;\n base = mix(base, uLipTone, lip);\n gloss = mix(gloss, 0.55, lip);\n // Brows: a soft arch of fine hairs above each eye, thinning to the tail.\n float bx = (ax - 0.029) / 0.021;\n float arch = 0.0195 + 0.0032 * (1.0 - bx * bx) - 0.0015 * max(bx, 0.0);\n float thick = 0.0024 * (1.0 - 0.55 * smoothstep(-0.6, 1.0, bx));\n float slant = mix(1.2, 0.25, smoothstep(-1.0, 0.0, bx));\n vec2 hp = vec2(ax * 2600.0 + (r.y - arch) * 2600.0 * slant, (r.y - arch) * 700.0);\n float hairs = 0.45 + 0.55 * noise(hp);\n float brow = (1.0 - smoothstep(0.0, thick, abs(r.y - arch))) * (1.0 - smoothstep(0.8, 1.15, abs(bx)));\n base = mix(base, uBrowTone, brow * hairs * 0.55 * front);\n return base;\n}\n\n// The line of the lashes along each upper lid, a lighter one along the lower.\nfloat lashes(vec3 r) {\n float side = r.x > 0.0 ? 1.0 : -1.0;\n vec4 eye = side > 0.0 ? uEyeL : uEyeR;\n vec3 q = eyeFrame(r, eye, side);\n float len2 = length(q);\n if (len2 > eye.w * 1.25 || q.z < -0.002) return 0.0;\n float up = 0.9 * q.y - 0.436 * q.z + LID_DROP;\n float low = -(0.93 * q.y + 0.37 * q.z);\n float outer = smoothstep(-0.2, 0.9, side * q.x / eye.w);\n float top = (1.0 - smoothstep(0.0, 0.0011 + 0.0007 * outer, up)) * step(0.0, up + 0.0004);\n float bottom = (1.0 - smoothstep(0.0, 0.0006, low)) * step(0.0, low + 0.0003) * 0.45;\n return max(top, bottom) * smoothstep(eye.w * 1.25, eye.w * 1.05, len2);\n}\n\nvec3 shadeSkin(vec3 albedo, float gloss, vec3 n, vec3 v, float shadow, float open) {\n float nl = dot(n, uKey);\n float wrap = clamp((nl + 0.38) / 1.38, 0.0, 1.0);\n float lit = wrap * mix(0.35, 1.0, shadow);\n // Light crossing under the skin reddens the terminator and the shadow's edge.\n float under = smoothstep(-0.35, 0.15, nl) * (1.0 - smoothstep(0.15, 0.6, nl * shadow));\n vec3 scatter = vec3(0.9, 0.28, 0.16) * under * 0.22;\n // Half-tones run cool, lights warm.\n float halftone = smoothstep(0.0, 0.35, nl) * (1.0 - smoothstep(0.35, 0.8, nl * shadow));\n vec3 tone = mix(vec3(1.0), vec3(0.9, 0.97, 1.02), halftone * 0.6);\n vec3 key = uKeyColor * (lit * tone + scatter);\n vec3 sky = fill(n) * open * (0.55 + 0.45 * open);\n vec3 h = normalize(uKey + v);\n float spec = pow(max(dot(n, h), 0.0), mix(18.0, 60.0, gloss)) * (0.03 + 0.12 * gloss) * shadow;\n return albedo * (key + sky) + uKeyColor * spec;\n}\n\n\nuniform vec3 uLookL; // where each iris faces, in the head's frame\nuniform vec3 uLookR;\nuniform vec3 uIris;\nuniform vec3 uSclera;\n\nvec3 shadeEye(vec3 n, vec3 v, float shadow) {\n float side = vRest.x > 0.0 ? 1.0 : -1.0;\n vec4 eye = side > 0.0 ? uEyeL : uEyeR;\n vec3 q = vRest - eye.xyz;\n vec3 d = normalize(q);\n vec3 look = side > 0.0 ? uLookL : uLookR;\n float c = dot(d, look);\n float r = sqrt(max(0.0, 1.0 - c * c)); // the sine off the look\n vec3 across = normalize(d - look * c + 1e-6);\n float ang = atan(dot(across, normalize(cross(look, vec3(0.0, 1.0, 0.0)))), dot(across, vec3(0.0, 1.0, 0.0)));\n float iris = 1.0 - smoothstep(0.47, 0.5, r);\n float pupil = 1.0 - smoothstep(0.15, 0.175, r);\n float fibres = 0.75 + 0.25 * noise(vec2(ang * 18.0, r * 9.0)) + 0.15 * sin(ang * 60.0);\n vec3 irisCol = uIris * fibres;\n irisCol = mix(irisCol * 1.35 + vec3(0.06, 0.03, 0.0), irisCol, smoothstep(0.17, 0.3, r));\n irisCol = mix(irisCol, irisCol * 0.35, smoothstep(0.36, 0.5, r));\n vec3 sclera = uSclera * mix(1.0, 0.82, smoothstep(0.55, 0.95, r));\n vec3 col = mix(sclera, irisCol, iris);\n col = mix(col, vec3(0.012), pupil);\n // The upper lid and its lashes shade the top of the eye.\n vec3 f = eyeFrame(vRest, eye, side);\n float up = 0.9 * f.y - 0.436 * f.z + LID_DROP;\n float lidShade = smoothstep(-0.0045, -0.0003, up);\n // Open, the lid's edge is its geometry's (a plane LID_DROP below the eye's centre); shut, it closes to the\n // lower lid.\n float covered = step(0.0, mix(up, f.y + 0.4 * f.z, uLid.x));\n vec3 wn = n;\n float nl = clamp(dot(wn, uKey), 0.0, 1.0);\n vec3 lit = uKeyColor * (0.25 + 0.75 * nl) * shadow * (1.0 - 0.75 * lidShade) + fill(wn) * 0.55 * (1.0 - 0.5 * lidShade);\n vec3 h = normalize(uKey + v);\n float glint = pow(max(dot(wn, h), 0.0), 900.0) * 9.0 * shadow * (1.0 - lidShade);\n vec3 eyeOut = col * lit + uKeyColor * glint;\n float g;\n vec3 lidOut = shadeSkin(skinAlbedo(vRest, g), 0.3, n, v, shadow, 0.8);\n return mix(eyeOut, lidOut, covered);\n}\n\nuniform vec3 uColor;\n\n// A height painted on a surface, turned into a tilt of its normal from how it changes across the screen.\nvec3 bumped(vec3 n, float height) {\n vec3 dx = dFdx(vWorld);\n vec3 dy = dFdy(vWorld);\n float hx = dFdx(height);\n float hy = dFdy(height);\n vec3 r1 = cross(dy, n);\n vec3 r2 = cross(n, dx);\n float det = dot(dx, r1);\n vec3 grad = sign(det) * (hx * r1 + hy * r2);\n return normalize(abs(det) * n - grad);\n}\n\n// Light from a soft sky and warm ground for shiny things, with the key as a soft box.\nvec3 reflected(vec3 n, vec3 v, float sharp) {\n vec3 r = reflect(-v, n);\n vec3 env = mix(uGround * 0.8, uSky * 1.3, smoothstep(-0.4, 0.6, r.y));\n float box = pow(max(dot(r, uKey), 0.0), sharp);\n return env + uKeyColor * box * 1.2;\n}\n\nvec3 diffuse(vec3 albedo, vec3 n, float shadow, float open, float wrap) {\n float nl = clamp((dot(n, uKey) + wrap) / (1.0 + wrap), 0.0, 1.0);\n return albedo * (uKeyColor * nl * shadow + fill(n) * open);\n}\n\n\nuniform vec4 uCapAxis; // the cap's axis (its cuff plane's normal) and the cuff edge's height along it\nuniform vec4 uCapCentre; // a point on the axis, and the cuff's height\nuniform vec3 uCapTones[3];\nuniform vec3 uHairTones[3];\nuniform vec3 uWrist;\nuniform vec3 uElbow;\n\nvec3 shadeCap(vec3 n, vec3 v, float shadow) {\n vec3 r = vRest;\n vec3 axis = uCapAxis.xyz;\n float h = dot(r, axis) - uCapAxis.w;\n vec3 q = r - uCapCentre.xyz;\n q -= axis * dot(q, axis);\n float around = atan(q.x, q.z);\n float cols = around * 56.0 / 6.2832;\n float rib = pow(abs(sin(cols * 3.14159)), 0.55);\n float row = h / 0.0026 + abs(fract(cols) - 0.5) * 1.4;\n float loop = smoothstep(0.15, 0.5, abs(fract(row) - 0.5));\n float height = rib * 0.0011 + loop * rib * 0.00025 + noise(vec2(cols * 4.0, h * 900.0)) * 0.00012;\n // Two woven labels on the cuff: an oblong one front left, a small square on the right.\n float onCuff = step(0.0, h) * step(h, uCapCentre.w);\n float oblong = step(-0.62, around) * step(around, -0.18) * step(0.013, h) * step(h, 0.034);\n float square = step(0.72, around) * step(around, 0.9) * step(0.016, h) * step(h, 0.031);\n float label = max(oblong, square) * onCuff;\n vec3 nn = label > 0.5 ? n : bumped(n, height);\n vec3 base = mix(uCapTones[1], uCapTones[0], rib) * (0.92 + 0.08 * loop);\n float print = oblong * step(0.5, fract((around + 0.62) * 70.0)) *\n (step(0.018, h) * step(h, 0.021) + step(0.025, h) * step(h, 0.0275) * step(around, -0.3));\n print += square * smoothstep(0.004, 0.003, length(vec2((around - 0.81) * 0.09, h - 0.0235)));\n base = mix(base, vec3(0.012), label);\n base = mix(base, vec3(0.8), clamp(print, 0.0, 1.0) * label);\n vec3 col = diffuse(base, nn, shadow, vOpen, 0.45);\n float rim = pow(1.0 - clamp(dot(nn, v), 0.0, 1.0), 3.0);\n col += uCapTones[2] * rim * 0.18 * (0.4 + 0.6 * shadow) * (1.0 - label);\n return col;\n}\n\nvec3 shadeHair(vec3 n, vec3 v, float shadow) {\n if (dot(vFlow.xyz, vFlow.xyz) < 0.5) return diffuse(uHairTones[0] * 0.55, n, shadow, vOpen * 0.7, 0.3);\n vec3 t = normalize(vFlow.xyz);\n float tone = vRest.z;\n float strands = 0.72 + 0.4 * noise(vec2(vRest.x * 24.0 + tone * 97.0, vRest.y * 6.0 + tone * 13.0));\n vec3 base = mix(uHairTones[0], uHairTones[1], tone) * strands;\n base = mix(base, uHairTones[2], smoothstep(0.6, 1.0, vRest.y) * 0.2);\n float tl = dot(t, uKey);\n float diff = mix(0.25, 1.0, sqrt(max(0.0, 1.0 - tl * tl))) * clamp(dot(n, uKey) * 0.6 + 0.4, 0.0, 1.0);\n vec3 h = normalize(uKey + v);\n float th = dot(t + n * 0.12, h);\n float spec = pow(sqrt(max(0.0, 1.0 - th * th)), 80.0) * 0.12;\n float th2 = dot(t - n * 0.1, h);\n float spec2 = pow(sqrt(max(0.0, 1.0 - th2 * th2)), 24.0) * 0.18;\n vec3 col = base * (uKeyColor * diff * shadow + fill(n) * vOpen * 0.9);\n col += (uKeyColor * spec + base * uKeyColor * spec2 * 1.5) * shadow * vOpen;\n return col;\n}\n\nvec3 shadeDress(vec3 n, vec3 v, float shadow) {\n vec3 r = vRest;\n vec3 base = uColor;\n // The embroidered band under the neckline: olive and black diamonds between fine light lines.\n float band = step(-0.142, r.y) * step(r.y, -0.106) * step(0.0, r.z) * step(abs(r.x), 0.15);\n vec2 d = vec2(r.x / 0.0105, (r.y + 0.124) / 0.0105);\n float diamond = abs(fract(d.x) - 0.5) + abs(d.y) ;\n float edge = step(abs(r.y + 0.108), 0.0012) + step(abs(r.y + 0.14), 0.0012);\n vec3 stitch = mix(vec3(0.02, 0.025, 0.018), vec3(0.17, 0.18, 0.09), step(diamond, 0.42));\n stitch = mix(stitch, vec3(0.55, 0.5, 0.36), clamp(edge, 0.0, 1.0));\n base = mix(base, stitch, band);\n // The sleeve's cuff at the wrist, with a pale lace edge.\n vec3 arm = uWrist - uElbow;\n float along = dot(r - uElbow, arm) / dot(arm, arm);\n float cuff = smoothstep(0.78, 0.8, along);\n base = mix(base, vec3(0.16, 0.19, 0.13), cuff);\n float lace = smoothstep(0.93, 0.95, along) * (0.6 + 0.4 * sin(atan(r.x - uWrist.x, r.z - uWrist.z) * 18.0));\n base = mix(base, vec3(0.78, 0.76, 0.68), clamp(lace, 0.0, 1.0));\n vec3 nn = bumped(n, noise(r.xy * 2600.0) * 0.00004);\n vec3 col = diffuse(base, nn, shadow, vOpen, 0.35);\n vec3 h = normalize(uKey + v);\n col += uKeyColor * pow(max(dot(nn, h), 0.0), 26.0) * 0.12 * shadow * (1.0 - band);\n return col;\n}\n\nvec3 shadeVelvet(vec3 n, vec3 v, float shadow) {\n float facing = clamp(dot(n, v), 0.0, 1.0);\n float sheen = pow(1.0 - facing, 2.2);\n vec3 base = uColor;\n vec3 col = diffuse(base, n, shadow, vOpen, 0.2);\n col += vec3(0.11, 0.13, 0.135) * sheen * (uKeyColor * 0.35 * (0.3 + 0.7 * shadow) + fill(n) * 0.6) * vOpen;\n return col;\n}\n\nvec3 shadeGold(vec3 n, vec3 v, float shadow) {\n float link = 0.65 + 0.35 * step(0.5, fract(vRest.x * 420.0));\n return uColor * reflected(n, v, 60.0) * link * mix(0.55, 1.0, shadow) * vOpen;\n}\n\nvec3 shadeCard(vec3 n, vec3 v, float shadow) {\n vec3 r = vRest;\n vec2 c = r.xy;\n // The chip, a bevelled gold plate with contact grooves.\n vec2 chipAt = vec2(0.03, 0.006);\n vec2 cq = abs(c - chipAt) - vec2(0.0084, 0.0072);\n float chip = step(max(cq.x, cq.y), 0.0) * step(0.0, r.z);\n float groove = chip * (step(abs(c.y - chipAt.y), 0.0004) + step(abs(abs(c.x - chipAt.x) - 0.003), 0.0003));\n float grain = noise(c * 2400.0) * 0.6 + noise(c * 5200.0) * 0.4;\n float digits = step(0.0, r.z) * step(abs(c.y + 0.016), 0.0026) * step(abs(c.x + 0.004), 0.046) *\n step(0.35, fract(c.x / 0.0058)) * step(fract(c.x / 0.026), 0.82);\n float mark = step(0.0, r.z) * step(abs(c.y + 0.03), 0.0022) * step(abs(c.x + 0.038), 0.014);\n float height = (1.0 - chip) * (grain * 0.00006 + digits * 0.00012);\n vec3 nn = bumped(n, height);\n vec3 base = mix(uColor, vec3(1.0, 0.27, 0.42), mark * 0.6);\n vec3 col = diffuse(base, nn, shadow, vOpen, 0.25);\n vec3 h = normalize(uKey + v);\n col += uKeyColor * pow(max(dot(nn, h), 0.0), 40.0) * 0.35 * shadow;\n vec3 gold = vec3(0.6, 0.38, 0.06) * reflected(nn, v, 40.0) * mix(0.5, 1.0, shadow);\n gold = mix(gold, vec3(0.1, 0.06, 0.01), clamp(groove, 0.0, 1.0));\n return mix(col, gold, chip);\n}\n\n\nuniform vec4 uTips[5]; // each finger's last joint and tip, in the hand's frame; the radius in w\nuniform vec4 uTipEnds[5];\nuniform vec3 uBacks[5]; // the back of each last bone\n\nfloat nails(vec3 r) {\n float best = 0.0;\n for (int i = 0; i < 5; i++) {\n vec3 a = uTips[i].xyz;\n vec3 b = uTipEnds[i].xyz;\n vec3 ab = b - a;\n float t = clamp(dot(r - a, ab) / dot(ab, ab), 0.0, 1.0);\n vec3 off = r - (a + ab * t);\n float back = dot(normalize(off), uBacks[i]);\n float on = smoothstep(0.38, 0.5, t) * smoothstep(0.55, 0.75, back) * step(length(off), uTips[i].w * 1.6);\n best = max(best, on);\n }\n return best;\n}\n\nvoid main() {\n vec3 n = normalize(vNormal);\n vec3 v = normalize(cameraPosition - vWorld);\n if (!gl_FrontFacing) n = -n;\n float shadow = keyShadow(n);\n vec3 col;\n#if PART == 0\n float gloss;\n vec3 albedo = skinAlbedo(vRest, gloss);\n albedo = mix(albedo, uBrowTone * 0.35, lashes(vRest));\n col = shadeSkin(albedo, gloss, n, v, shadow, vOpen);\n#elif PART == 1\n float nail = nails(vRest);\n vec3 albedo = mix(uSkinTone * vec3(1.0, 0.97, 0.95), vec3(0.85, 0.62, 0.56), nail);\n col = shadeSkin(albedo, 0.25 + nail * 0.6, n, v, shadow, vOpen);\n#elif PART == 2\n col = shadeEye(n, v, shadow);\n#elif PART == 3\n col = shadeCap(n, v, shadow);\n#elif PART == 4\n col = shadeHair(n, v, shadow);\n#elif PART == 5\n col = shadeDress(n, v, shadow);\n#elif PART == 6\n col = diffuse(uColor, bumped(n, noise(vRest.xy * 1800.0) * 0.00003), shadow, vOpen, 0.5);\n#elif PART == 7\n col = shadeVelvet(n, v, shadow);\n#elif PART == 8\n col = shadeGold(n, v, shadow);\n#else\n col = shadeCard(n, v, shadow);\n#endif\n gl_FragColor = vec4(col, 1.0);\n}\n";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Bust } from "./bust.js";
|
|
2
|
+
import type { V3 } from "./sdf.js";
|
|
3
|
+
interface V3Like {
|
|
4
|
+
set(x: number, y: number, z: number): unknown;
|
|
5
|
+
}
|
|
6
|
+
interface ColorLike {
|
|
7
|
+
r: number;
|
|
8
|
+
g: number;
|
|
9
|
+
b: number;
|
|
10
|
+
}
|
|
11
|
+
interface NodeLike {
|
|
12
|
+
add(...nodes: unknown[]): void;
|
|
13
|
+
matrixAutoUpdate: boolean;
|
|
14
|
+
matrixWorldNeedsUpdate: boolean;
|
|
15
|
+
matrix: {
|
|
16
|
+
copy(m: unknown): unknown;
|
|
17
|
+
};
|
|
18
|
+
frustumCulled: boolean;
|
|
19
|
+
matrixWorld: {
|
|
20
|
+
elements: ArrayLike<number>;
|
|
21
|
+
};
|
|
22
|
+
updateMatrixWorld(force?: boolean): void;
|
|
23
|
+
}
|
|
24
|
+
interface Disposable {
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
interface GeometryLike extends Disposable {
|
|
28
|
+
setAttribute(name: string, attribute: unknown): void;
|
|
29
|
+
setIndex(attribute: unknown): void;
|
|
30
|
+
}
|
|
31
|
+
interface TargetLike extends Disposable {
|
|
32
|
+
readonly texture: unknown;
|
|
33
|
+
}
|
|
34
|
+
interface CameraLike {
|
|
35
|
+
position: V3Like;
|
|
36
|
+
updateProjectionMatrix(): void;
|
|
37
|
+
lookAt(x: number, y: number, z: number): void;
|
|
38
|
+
updateMatrixWorld(force?: boolean): void;
|
|
39
|
+
projectionMatrix: {
|
|
40
|
+
elements: ArrayLike<number>;
|
|
41
|
+
};
|
|
42
|
+
matrixWorldInverse: {
|
|
43
|
+
elements: ArrayLike<number>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
interface RendererLike {
|
|
47
|
+
setClearColor(color: number | ColorLike, alpha: number): void;
|
|
48
|
+
getClearColor(target: ColorLike): ColorLike;
|
|
49
|
+
getClearAlpha(): number;
|
|
50
|
+
clear(color: boolean, depth: boolean, stencil: boolean): void;
|
|
51
|
+
getRenderTarget(): unknown;
|
|
52
|
+
setRenderTarget(target: unknown): void;
|
|
53
|
+
render(scene: unknown, camera: unknown): void;
|
|
54
|
+
}
|
|
55
|
+
/** What this module uses of keel/lit. Pass the keel/lit namespace itself. */
|
|
56
|
+
export interface PortraitLit {
|
|
57
|
+
readonly Group: new () => NodeLike;
|
|
58
|
+
readonly Stage: new () => NodeLike;
|
|
59
|
+
readonly Mesh: new (geometry: unknown, material: unknown) => NodeLike;
|
|
60
|
+
readonly Geometry: new () => GeometryLike;
|
|
61
|
+
readonly Attribute: new (array: Float32Array | Uint32Array, size: number) => unknown;
|
|
62
|
+
readonly CustomMaterial: new (parameters: Readonly<Record<string, unknown>>) => Disposable;
|
|
63
|
+
readonly Vector2: new (x?: number, y?: number) => {
|
|
64
|
+
set(x: number, y: number): unknown;
|
|
65
|
+
};
|
|
66
|
+
readonly Vector3: new (x?: number, y?: number, z?: number) => V3Like;
|
|
67
|
+
readonly Vector4: new (x?: number, y?: number, z?: number, w?: number) => unknown;
|
|
68
|
+
readonly Matrix3: new () => {
|
|
69
|
+
set(...n: number[]): unknown;
|
|
70
|
+
};
|
|
71
|
+
readonly Matrix4: new () => {
|
|
72
|
+
set(...n: number[]): unknown;
|
|
73
|
+
elements: number[];
|
|
74
|
+
};
|
|
75
|
+
readonly Color: new (value?: string) => ColorLike;
|
|
76
|
+
readonly RenderTarget: new (w: number, h: number, options: Readonly<Record<string, unknown>>) => TargetLike;
|
|
77
|
+
readonly OrthoCamera: new (l: number, r: number, t: number, b: number, n: number, f: number) => CameraLike;
|
|
78
|
+
}
|
|
79
|
+
/** The colours of a sitter, as hex. */
|
|
80
|
+
export interface Palette {
|
|
81
|
+
readonly skin: string;
|
|
82
|
+
readonly lip: string;
|
|
83
|
+
readonly blush: string;
|
|
84
|
+
readonly brow: string;
|
|
85
|
+
readonly iris: string;
|
|
86
|
+
readonly sclera: string;
|
|
87
|
+
readonly cap: string;
|
|
88
|
+
readonly hair: string;
|
|
89
|
+
readonly dress: string;
|
|
90
|
+
readonly chemise: string;
|
|
91
|
+
readonly gown: string;
|
|
92
|
+
readonly gold: string;
|
|
93
|
+
readonly card: string;
|
|
94
|
+
}
|
|
95
|
+
export declare const PALETTE: Palette;
|
|
96
|
+
/** The light: the key's direction (toward it) and colour, the fill's sky and ground. */
|
|
97
|
+
export interface PortraitLight {
|
|
98
|
+
readonly key: V3;
|
|
99
|
+
readonly keyColor: string;
|
|
100
|
+
readonly keyStrength: number;
|
|
101
|
+
readonly sky: string;
|
|
102
|
+
readonly ground: string;
|
|
103
|
+
readonly fillStrength: number;
|
|
104
|
+
}
|
|
105
|
+
/** One soft warm key from the upper left (azimuth -40°, elevation 35°), a cool fill at half of it. */
|
|
106
|
+
export declare const LIGHT: PortraitLight;
|
|
107
|
+
export interface FaceState {
|
|
108
|
+
/** How far the lids are down, 0 open to 1 shut. */
|
|
109
|
+
readonly lid: number;
|
|
110
|
+
/** Where the eyes look, in the world. */
|
|
111
|
+
readonly at: V3;
|
|
112
|
+
}
|
|
113
|
+
export interface Portrait {
|
|
114
|
+
/** Everything drawn, under one node: place, turn and scale it. */
|
|
115
|
+
readonly group: NodeLike;
|
|
116
|
+
light(light: PortraitLight): void;
|
|
117
|
+
/** The lids and the gaze this frame. */
|
|
118
|
+
face(state: FaceState): void;
|
|
119
|
+
/** Draw the key's shadow map; call before each frame is drawn when the bust or the light has moved. */
|
|
120
|
+
shadows(renderer: RendererLike): void;
|
|
121
|
+
dispose(): void;
|
|
122
|
+
}
|
|
123
|
+
/** The bust as meshes for keel/lit, under one group. */
|
|
124
|
+
export declare function createPortrait(lit: PortraitLit, bust: Bust, palette?: Palette): Portrait;
|
|
125
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** A distance at a point. */
|
|
2
|
+
export type Field = (x: number, y: number, z: number) => number;
|
|
3
|
+
/** A point or a direction. */
|
|
4
|
+
export type V3 = readonly [number, number, number];
|
|
5
|
+
/** A rotation as three rows. */
|
|
6
|
+
export type M3 = readonly [number, number, number, number, number, number, number, number, number];
|
|
7
|
+
export interface Prim {
|
|
8
|
+
readonly kind: "prim";
|
|
9
|
+
/** Where it lies within: a centre and a radius (Infinity for a plane). */
|
|
10
|
+
readonly bound: readonly [number, number, number, number];
|
|
11
|
+
readonly f: Field;
|
|
12
|
+
}
|
|
13
|
+
export interface Op {
|
|
14
|
+
readonly kind: "blend" | "carve" | "cut" | "fan";
|
|
15
|
+
/** How far it melts, in metres. */
|
|
16
|
+
readonly k: number;
|
|
17
|
+
/** For a fan, how far each kid after the first melts into the first. */
|
|
18
|
+
readonly ks?: readonly number[];
|
|
19
|
+
readonly kids: readonly Node[];
|
|
20
|
+
readonly bound: readonly [number, number, number, number];
|
|
21
|
+
}
|
|
22
|
+
/** A shape moved by a rotation and an offset: inside it, points are taken into the shape's own frame. */
|
|
23
|
+
export interface Frame {
|
|
24
|
+
readonly kind: "frame";
|
|
25
|
+
readonly rot: M3;
|
|
26
|
+
readonly at: V3;
|
|
27
|
+
readonly kid: Node;
|
|
28
|
+
readonly bound: readonly [number, number, number, number];
|
|
29
|
+
}
|
|
30
|
+
/** A shape with a small field added to its distance: folds, ribs, a wave. */
|
|
31
|
+
export interface Bumped {
|
|
32
|
+
readonly kind: "bump";
|
|
33
|
+
readonly kid: Node;
|
|
34
|
+
readonly f: Field;
|
|
35
|
+
readonly bound: readonly [number, number, number, number];
|
|
36
|
+
}
|
|
37
|
+
export type Node = Prim | Op | Frame | Bumped;
|
|
38
|
+
export declare const IDENTITY: M3;
|
|
39
|
+
/** Smooth minimum (polynomial, quadratic): a and b melt within k. */
|
|
40
|
+
export declare function smin(a: number, b: number, k: number): number;
|
|
41
|
+
/** Smooth maximum. */
|
|
42
|
+
export declare function smax(a: number, b: number, k: number): number;
|
|
43
|
+
/** Apply a rotation's rows to a vector (into the frame) */
|
|
44
|
+
export declare function rotIn(m: M3, x: number, y: number, z: number): [number, number, number];
|
|
45
|
+
/** Apply a rotation's columns to a vector (out of the frame). */
|
|
46
|
+
export declare function rotOut(m: M3, x: number, y: number, z: number): [number, number, number];
|
|
47
|
+
/** The product of two rotations: `mul(a, b)` takes a point into b's frame, then a's. */
|
|
48
|
+
export declare function mul(a: M3, b: M3): M3;
|
|
49
|
+
/** A sphere. */
|
|
50
|
+
export declare function sphere(c: V3, r: number): Prim;
|
|
51
|
+
/** An ellipsoid with radii along its own axes, turned by `rot` (rows take a point into its frame). */
|
|
52
|
+
export declare function ellipsoid(c: V3, radii: V3, rot?: M3): Prim;
|
|
53
|
+
/** A cone with round ends: radius `ra` at `a`, `rb` at `b`. */
|
|
54
|
+
export declare function cone(a: V3, b: V3, ra: number, rb: number): Prim;
|
|
55
|
+
/** A capsule of one radius. */
|
|
56
|
+
export declare function capsule(a: V3, b: V3, r: number): Prim;
|
|
57
|
+
/** A box with rounded edges, half sizes `h`, turned by `rot`. */
|
|
58
|
+
export declare function box(c: V3, h: V3, round: number, rot?: M3): Prim;
|
|
59
|
+
/** Everything on the side of a plane its normal points away from: n·p < d. */
|
|
60
|
+
export declare function half(n: V3, d: number): Prim;
|
|
61
|
+
/** Shapes melted together within `k`. */
|
|
62
|
+
export declare function blend(k: number, ...kids: Node[]): Op;
|
|
63
|
+
/**
|
|
64
|
+
* Each of `kids` melted into `base` by its own `ks`, and the union of those: fingers that melt into the palm but
|
|
65
|
+
* never into each other, with the palm asked once per point.
|
|
66
|
+
*/
|
|
67
|
+
export declare function fan(base: Node, kids: readonly Node[], ks: readonly number[]): Op;
|
|
68
|
+
/** The first shape with the rest cut out of it, the cuts' edges melted within `k`. */
|
|
69
|
+
export declare function carve(k: number, base: Node, ...cuts: Node[]): Op;
|
|
70
|
+
/** Where every shape is: the first shape trimmed by the rest. */
|
|
71
|
+
export declare function cut(k: number, ...kids: Node[]): Op;
|
|
72
|
+
/** A shape built in its own frame, placed by `rot` (rows take a point in) and `at`. */
|
|
73
|
+
export declare function frame(rot: M3, at: V3, kid: Node): Frame;
|
|
74
|
+
/** A shape with `f` added to its distance; `amp` is the most `f` moves it. */
|
|
75
|
+
export declare function bump(kid: Node, f: Field, amp: number): Bumped;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BustRecipe } from "./bust.js";
|
|
2
|
+
import type { Palette } from "./render.js";
|
|
3
|
+
export interface PortraitSettings {
|
|
4
|
+
/** What decides the face and the hair, a whole number. */
|
|
5
|
+
readonly seed: number;
|
|
6
|
+
/** A frontal, eyes to camera; B turned 25° and looking down, the cap pulled lower. */
|
|
7
|
+
readonly face: "A" | "B";
|
|
8
|
+
readonly detail: "hero" | "mid" | "far";
|
|
9
|
+
/** The card pinched between finger and thumb, or floating over a raised finger. */
|
|
10
|
+
readonly hand: "pinch" | "point";
|
|
11
|
+
/** The cap's, the hair's and the card's colours, #rrggbb. */
|
|
12
|
+
readonly cap: string;
|
|
13
|
+
readonly hair: string;
|
|
14
|
+
readonly card: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const DEFAULT_PORTRAIT_SETTINGS: PortraitSettings;
|
|
17
|
+
/**
|
|
18
|
+
* Normalises untrusted settings, usually `KEEL_INPUTS.portrait`, into complete `PortraitSettings`.
|
|
19
|
+
*
|
|
20
|
+
* @param input Plain settings object, or undefined for all defaults.
|
|
21
|
+
*/
|
|
22
|
+
export declare function portraitSettings(input?: unknown): PortraitSettings;
|
|
23
|
+
/** The recipe and the palette a sitter's settings give. */
|
|
24
|
+
export declare function sitterOf(settings: PortraitSettings): {
|
|
25
|
+
recipe: BustRecipe;
|
|
26
|
+
palette: Palette;
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './portrait/index.js'
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": "keel-module-inputs@1",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"key": "seed",
|
|
6
|
+
"label": "Seed",
|
|
7
|
+
"required": false,
|
|
8
|
+
"help": "Decides the face's proportions and the hair's locks.",
|
|
9
|
+
"type": "number",
|
|
10
|
+
"min": 0,
|
|
11
|
+
"max": 2147483647,
|
|
12
|
+
"step": 1,
|
|
13
|
+
"default": 7
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"key": "face",
|
|
17
|
+
"label": "Face",
|
|
18
|
+
"required": false,
|
|
19
|
+
"type": "select",
|
|
20
|
+
"options": [
|
|
21
|
+
{
|
|
22
|
+
"value": "A",
|
|
23
|
+
"label": "Frontal, eyes to camera"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"value": "B",
|
|
27
|
+
"label": "Turned and looking down"
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"default": "A"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"key": "hand",
|
|
34
|
+
"label": "Hand",
|
|
35
|
+
"required": false,
|
|
36
|
+
"type": "select",
|
|
37
|
+
"options": [
|
|
38
|
+
{
|
|
39
|
+
"value": "pinch",
|
|
40
|
+
"label": "Card pinched"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"value": "point",
|
|
44
|
+
"label": "Card over a raised finger"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"default": "pinch"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"key": "detail",
|
|
51
|
+
"label": "Detail",
|
|
52
|
+
"required": false,
|
|
53
|
+
"placement": "advanced",
|
|
54
|
+
"type": "select",
|
|
55
|
+
"options": [
|
|
56
|
+
{
|
|
57
|
+
"value": "hero",
|
|
58
|
+
"label": "Hero"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"value": "mid",
|
|
62
|
+
"label": "Mid"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"value": "far",
|
|
66
|
+
"label": "Far"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"default": "hero"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"key": "cap",
|
|
73
|
+
"label": "Cap",
|
|
74
|
+
"required": false,
|
|
75
|
+
"type": "color",
|
|
76
|
+
"swatches": [
|
|
77
|
+
"#ff2f78",
|
|
78
|
+
"#2f6bff",
|
|
79
|
+
"#f2c14e",
|
|
80
|
+
"#1f1f24"
|
|
81
|
+
],
|
|
82
|
+
"default": "#ff2f78"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"key": "hair",
|
|
86
|
+
"label": "Hair",
|
|
87
|
+
"required": false,
|
|
88
|
+
"type": "color",
|
|
89
|
+
"swatches": [
|
|
90
|
+
"#b0562a",
|
|
91
|
+
"#3a2418",
|
|
92
|
+
"#d9b26f",
|
|
93
|
+
"#1a1210"
|
|
94
|
+
],
|
|
95
|
+
"default": "#b0562a"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"key": "card",
|
|
99
|
+
"label": "Card",
|
|
100
|
+
"required": false,
|
|
101
|
+
"placement": "advanced",
|
|
102
|
+
"type": "color",
|
|
103
|
+
"swatches": [
|
|
104
|
+
"#ff2a62",
|
|
105
|
+
"#e8e4d8",
|
|
106
|
+
"#20242a"
|
|
107
|
+
],
|
|
108
|
+
"default": "#ff2a62"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
}
|