@margoengine/scenes 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.
@@ -0,0 +1,108 @@
1
+ import type { ScatterImage, ScatterTextures } from '@margoengine/scatter';
2
+ /** Options of {@link libraryMesh}. */
3
+ export interface LibraryMeshOptions {
4
+ /** The look the part takes in a biome scatter. Default `'stone'`. */
5
+ readonly kind?: 'bark' | 'foliage' | 'stone';
6
+ /**
7
+ * Albedo, linear RGB 0..1: the part draws this one colour and no maps. Default: a model whose material has a base
8
+ * colour map draws its maps (the part carries `textures`; a model of several textured materials needs
9
+ * `libraryParts`, one part per material); any other model draws the mean of its materials' `baseColorFactor`.
10
+ */
11
+ readonly color?: readonly [number, number, number];
12
+ /** Decodes a map's file (textured models). Default `createImageBitmap` on the fetched bytes. */
13
+ readonly decode?: (bytes: ArrayBuffer, mimeType: string) => Promise<ScatterImage>;
14
+ /** Most triangles the merged mesh may hold (it is drawn once per placed object). Default 40,000. */
15
+ readonly maxTriangles?: number;
16
+ /** Uniform scale to metres. Default 1. */
17
+ readonly scale?: number;
18
+ readonly signal?: AbortSignal;
19
+ /** The fetch to use. Default the global one. */
20
+ readonly fetch?: (url: string, init?: {
21
+ signal?: AbortSignal;
22
+ }) => Promise<{
23
+ ok: boolean;
24
+ status: number;
25
+ json(): Promise<unknown>;
26
+ arrayBuffer(): Promise<ArrayBuffer>;
27
+ }>;
28
+ }
29
+ /** A merged library mesh, ready for `BiomeViewOptions.meshes` (`{ 'procedural:rock': [part] }`). */
30
+ export interface LibraryMeshPart {
31
+ readonly geometry: {
32
+ readonly positions: Float32Array;
33
+ readonly normals: Float32Array;
34
+ readonly indices: Uint32Array;
35
+ };
36
+ /** Albedo, or the factor that multiplies the base colour map when there is one. */
37
+ readonly color: readonly [number, number, number];
38
+ readonly kind: 'bark' | 'foliage' | 'stone';
39
+ /** The model's maps and texture coordinates, when its material has a base colour map and no `color` was given. */
40
+ readonly textures?: ScatterTextures;
41
+ /** The glTF material name of a textured part. */
42
+ readonly name?: string;
43
+ }
44
+ export type Node = {
45
+ mesh?: number;
46
+ children?: number[];
47
+ matrix?: number[];
48
+ translation?: number[];
49
+ rotation?: number[];
50
+ scale?: number[];
51
+ };
52
+ export type Doc = {
53
+ buffers?: {
54
+ uri?: string;
55
+ byteLength: number;
56
+ }[];
57
+ bufferViews?: {
58
+ buffer: number;
59
+ byteOffset?: number;
60
+ byteLength: number;
61
+ byteStride?: number;
62
+ }[];
63
+ accessors?: {
64
+ bufferView?: number;
65
+ byteOffset?: number;
66
+ componentType: number;
67
+ count: number;
68
+ type: string;
69
+ }[];
70
+ meshes?: {
71
+ primitives: {
72
+ attributes: Record<string, number>;
73
+ indices?: number;
74
+ material?: number;
75
+ mode?: number;
76
+ }[];
77
+ }[];
78
+ nodes?: Node[];
79
+ scenes?: {
80
+ nodes?: number[];
81
+ }[];
82
+ scene?: number;
83
+ materials?: {
84
+ pbrMetallicRoughness?: {
85
+ baseColorFactor?: number[];
86
+ baseColorTexture?: {
87
+ index: number;
88
+ };
89
+ };
90
+ }[];
91
+ };
92
+ /** Column-major 4x4 of a node's matrix, or of its translation, rotation and scale (glTF 2.0 section 5.25). */
93
+ export declare function nodeMatrix(n: Node): number[];
94
+ export declare const mul: (a: number[], b: number[]) => number[];
95
+ /** Component types: bytes and reader. */
96
+ export declare const KINDS: Record<number, [number, (d: DataView, o: number) => number]>;
97
+ /**
98
+ * Loads a glTF model (`.gltf` with external buffers) as one merged mesh part for a biome scatter: every triangle
99
+ * primitive of the default scene under its node transforms, its base on y = 0 and centred on x = z = 0, so a placed
100
+ * object stands on the ground. A model with a base colour map (and no `color`) keeps its maps: the part carries its
101
+ * texture coordinates and its base colour, normal and occlusion-roughness-metal images, so it draws textured.
102
+ * @throws TypeError for a document with no triangles with float positions and normals; RangeError for a mesh over
103
+ * `maxTriangles`; Error for a file that does not load.
104
+ * @example
105
+ * const rock = await libraryMesh('/asset-library/big-burn-1910/rocks/rock_07/rock_07_2k.gltf', { color: [0.3, 0.29, 0.27] });
106
+ * const scene = await attach(engine, { meshes: { 'procedural:rock': [rock] } });
107
+ */
108
+ export declare function libraryMesh(url: string, options?: LibraryMeshOptions): Promise<LibraryMeshPart>;
@@ -0,0 +1,45 @@
1
+ import type { ScatterImage, ScatterTextures } from '@margoengine/scatter';
2
+ import { type LibraryMeshOptions } from './library-mesh.js';
3
+ /** Options of {@link libraryParts}. */
4
+ export interface LibraryPartsOptions extends Omit<LibraryMeshOptions, 'color' | 'kind'> {
5
+ /** The look of materials that are not foliage. Default `'bark'`. */
6
+ readonly kind?: 'bark' | 'stone';
7
+ /**
8
+ * Whether a material is foliage (sways, shades as clusters, follows the seasons). Default: alphaMode MASK or BLEND,
9
+ * or a name with twig, leaf, needle, foliage or frond in it.
10
+ */
11
+ readonly foliage?: (name: string) => boolean;
12
+ /** Decodes an image file. Default `createImageBitmap` on the fetched bytes. */
13
+ readonly decode?: (bytes: ArrayBuffer, mimeType: string) => Promise<ScatterImage>;
14
+ }
15
+ /** Vertices of one part (one level). */
16
+ export interface LibraryGeometry {
17
+ readonly positions: Float32Array;
18
+ readonly normals: Float32Array;
19
+ readonly indices: Uint32Array;
20
+ }
21
+ /** One textured part, ready for `BiomeViewOptions.meshes`. */
22
+ export interface LibraryTexturedPart {
23
+ readonly geometry: LibraryGeometry | readonly [LibraryGeometry, LibraryGeometry, LibraryGeometry];
24
+ /** The material's baseColorFactor (white for most scans): it multiplies the base colour map. */
25
+ readonly color: readonly [number, number, number];
26
+ readonly kind: 'bark' | 'foliage' | 'stone';
27
+ readonly textures: ScatterTextures;
28
+ /** The glTF material name. */
29
+ readonly name: string;
30
+ }
31
+ /**
32
+ * Loads a glTF model (`.gltf` with external buffers and images) as one textured part per material, every triangle
33
+ * primitive of the default scene under its node transforms, its base on y = 0 and centred on x = z = 0. Each part
34
+ * carries its TEXCOORD_0 (with the material's KHR_texture_transform applied) and its base colour, normal and
35
+ * metallic-roughness images; the metallic-roughness image is read as occlusion-roughness-metal (R occlusion, the
36
+ * packing of Poly Haven and most scan libraries). BLEND materials draw as MASK (a scatter has no sorted blending).
37
+ * Heavy scans need a lighter level first (`maxTriangles`, counted per part). Three URLs (near, middle, far levels of
38
+ * one model, such as decimations of a scan) give each part one geometry per LOD ring, matched by material name.
39
+ * @throws TypeError for a document with no textured triangles; RangeError for a part over `maxTriangles`; Error for a
40
+ * file that does not load.
41
+ * @example
42
+ * const fir = await libraryParts('/asset-library/big-burn-1910/plants/fir_tree_01/forest/fir_tree_01_a_near.gltf');
43
+ * const scene = await attach(engine, { meshes: { 'procedural:conifer': fir } });
44
+ */
45
+ export declare function libraryParts(url: string | readonly [near: string, middle: string, far: string], options?: LibraryPartsOptions): Promise<LibraryTexturedPart[]>;
@@ -0,0 +1,52 @@
1
+ /** What an asset is: a `model` (glTF), a `sky` (an HDR panorama) or a `texture`. */
2
+ export type AssetType = 'model' | 'sky' | 'texture';
3
+ /** One asset of the library. */
4
+ export interface LibraryAsset {
5
+ /** Unique across the library, as the source names it (`ocean_buoy`). */
6
+ readonly id: string;
7
+ /** The film or subject folder it sits in (`japan-2011-coast`). */
8
+ readonly subject: string;
9
+ /** The folder kind (`boats`, `buildings`, `plants`, `hdri` ...). */
10
+ readonly kind: string;
11
+ readonly type: AssetType;
12
+ /** Path of the file to load, relative to the library root, with forward slashes. */
13
+ readonly file: string;
14
+ /** Bytes of the file (0 when unknown). */
15
+ readonly bytes: number;
16
+ }
17
+ /** The checked index. */
18
+ export interface Library {
19
+ readonly root: string;
20
+ readonly assets: readonly LibraryAsset[];
21
+ readonly byId: ReadonlyMap<string, LibraryAsset>;
22
+ }
23
+ /** The asset types an index may hold. */
24
+ export declare const ASSET_TYPES: readonly AssetType[];
25
+ /**
26
+ * Checks an index (`{ version: 1, assets: [...] }`) and returns it with a lookup by id.
27
+ * @throws TypeError when `data` is not an index object; RangeError for a missing or repeated id, an unknown type, or a
28
+ * file path that is empty, absolute or climbs out of the root. The message names the asset.
29
+ */
30
+ export declare function parseLibrary(data: unknown, root?: string): Library;
31
+ /**
32
+ * Fetches and checks `library.json` under `root` (a URL, with or without the closing slash). The request aborts with
33
+ * `signal`.
34
+ * @throws RangeError when the request fails (the message names the URL and status); a bad index throws as {@link parseLibrary}.
35
+ */
36
+ export declare function fetchLibrary(root: string, options?: {
37
+ signal?: AbortSignal;
38
+ fetch?: typeof fetch;
39
+ }): Promise<Library>;
40
+ /**
41
+ * The URL of an asset's file under the library root.
42
+ * @throws RangeError for an id not in the library.
43
+ */
44
+ export declare function assetUrl(library: Library, id: string): string;
45
+ /** The assets of a subject and/or kind and/or type, in index order. */
46
+ export declare function findAssets(library: Library, match?: {
47
+ subject?: string;
48
+ kind?: string;
49
+ type?: AssetType;
50
+ }): LibraryAsset[];
51
+ export { libraryMesh, type LibraryMeshOptions, type LibraryMeshPart } from './library-mesh.js';
52
+ export { libraryParts, type LibraryGeometry, type LibraryPartsOptions, type LibraryTexturedPart, } from './library-parts.js';
@@ -0,0 +1,48 @@
1
+ import { n as e, t } from "./library-mesh-BRk4Ycnn.js";
2
+ //#region src/library.ts
3
+ var n = [
4
+ "model",
5
+ "sky",
6
+ "texture"
7
+ ], r = /^[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*$/, i = (e, t) => (e.endsWith("/") || e === "" ? e : e + "/") + t;
8
+ function a(e, t = "") {
9
+ let i = e;
10
+ if (typeof i != "object" || !i || i.version !== 1 || !Array.isArray(i.assets)) throw TypeError("A library index is { version: 1, assets: [...] }; build it with tools/library-index.mjs.");
11
+ let a = /* @__PURE__ */ new Map();
12
+ for (let [e, t] of i.assets.entries()) {
13
+ let i = t?.id;
14
+ if (typeof i != "string" || !i) throw RangeError(`Library asset ${e} has no id; give each asset a unique id.`);
15
+ if (a.has(i)) throw RangeError(`Library asset ${i} is listed twice; ids are unique across the library.`);
16
+ if (!n.includes(t.type)) throw RangeError(`Library asset ${i} has type ${String(t.type)}; use ${n.join(", ")}.`);
17
+ let o = t.file;
18
+ if (typeof o != "string" || !r.test(o) || o.split("/").some((e) => e === ".." || e === ".")) throw RangeError(`Library asset ${i} has file ${String(o)}; use a relative path of letters, digits, dot, dash and underscore inside the root.`);
19
+ a.set(i, {
20
+ id: i,
21
+ subject: String(t.subject ?? ""),
22
+ kind: String(t.kind ?? ""),
23
+ type: t.type,
24
+ file: o,
25
+ bytes: typeof t.bytes == "number" && t.bytes >= 0 ? t.bytes : 0
26
+ });
27
+ }
28
+ return Object.freeze({
29
+ root: t,
30
+ assets: Object.freeze([...a.values()]),
31
+ byId: a
32
+ });
33
+ }
34
+ async function o(e, t = {}) {
35
+ let n = t.fetch ?? fetch, r = i(e, "library.json"), o = await n(r, { signal: t.signal });
36
+ if (!o.ok) throw RangeError(`Could not load the asset library index ${r} (status ${o.status}); serve the library folder and run tools/library-index.mjs.`);
37
+ return a(await o.json(), e);
38
+ }
39
+ function s(e, t) {
40
+ let n = e.byId.get(t);
41
+ if (!n) throw RangeError(`Unknown library asset ${t}; use an id from library.assets.`);
42
+ return i(e.root, n.file);
43
+ }
44
+ function c(e, t = {}) {
45
+ return e.assets.filter((e) => (t.subject === void 0 || e.subject === t.subject) && (t.kind === void 0 || e.kind === t.kind) && (t.type === void 0 || e.type === t.type));
46
+ }
47
+ //#endregion
48
+ export { n as ASSET_TYPES, s as assetUrl, o as fetchLibrary, c as findAssets, t as libraryMesh, e as libraryParts, a as parseLibrary };
@@ -0,0 +1,48 @@
1
+ import { applySkySettings } from '@margoengine/sky/settings';
2
+ import { applyWaterSettings } from '@margoengine/water/settings';
3
+ import { applyTerrainSettings } from '@margoengine/terrain/settings';
4
+ import { applyWeatherSettings } from '@margoengine/weather/settings';
5
+ import { applyEnvironmentSettings } from '@margoengine/environment/settings';
6
+ import { applyFlameSettings, applySandSettings, applySmokeSettings } from '@margoengine/vfx/settings';
7
+ import { applyTonemapSettings } from '@margoengine/tonemap/settings';
8
+ import { applyPostSettings } from '@margoengine/post/settings';
9
+ import { type MaterialLook } from '@margoengine/biomes/settings';
10
+ /** The look families: `natural` is every package's own defaults, `animatedFeature` the animated-feature picture style. */
11
+ export declare const LOOK_FAMILIES: readonly ['natural', 'animatedFeature'];
12
+ /** The name of a look family in {@link LOOK_FAMILIES}. */
13
+ export type LookFamilyName = (typeof LOOK_FAMILIES)[number];
14
+ /** The parts of a scene a family can look after; each one given is written through its package's apply function. */
15
+ export interface LookFamilyTargets {
16
+ /** For `applySkySettings`: the sky, and optionally its tonemap, grade and volumetric clouds. */
17
+ readonly sky?: Parameters<typeof applySkySettings>[0];
18
+ readonly water?: Parameters<typeof applyWaterSettings>[0];
19
+ readonly terrain?: Parameters<typeof applyTerrainSettings>[0];
20
+ readonly weather?: Parameters<typeof applyWeatherSettings>[0];
21
+ readonly environment?: Parameters<typeof applyEnvironmentSettings>[0];
22
+ /** A `BlownSand` (or any target of `applySandSettings`). */
23
+ readonly sand?: Parameters<typeof applySandSettings>[0];
24
+ /** A `Smoke`, or a `FireFront` for its smoke columns (any target of `applySmokeSettings`). */
25
+ readonly smoke?: Parameters<typeof applySmokeSettings>[0];
26
+ /** A `Fire` (or any target of `applyFlameSettings`): its flames and embers. */
27
+ readonly fire?: Parameters<typeof applyFlameSettings>[0];
28
+ readonly tonemap?: Parameters<typeof applyTonemapSettings>[0];
29
+ readonly post?: Parameters<typeof applyPostSettings>[0];
30
+ /**
31
+ * The options of a `BiomeView` before `BiomeView.attach` (the ground materials are read when the view is built): its
32
+ * `materials` becomes `biomeMaterials(name)`, the built-in `MATERIALS` with the family's multipliers.
33
+ */
34
+ readonly biomes?: {
35
+ materials?: Readonly<Record<string, MaterialLook>>;
36
+ };
37
+ }
38
+ /**
39
+ * Applies the look family `name` to every part of the scene in `targets`: each part gets that family's entry of its own
40
+ * package's LOOKS table (`natural` is every row at its default, so the part draws as it does with no settings), through
41
+ * that package's apply function. A part left out is left alone. The sky keeps the scene's time of day: its clock
42
+ * (`hours`, `timeScale`) and sun direction stay as the scene set them, so a family never moves the sun. The weather part writes the family's state onto the
43
+ * weather target, so give it only when nothing else (a recorded storm, a drive) owns the weather.
44
+ * @throws RangeError for a family not in {@link LOOK_FAMILIES}; whatever an apply function throws for a part that cannot
45
+ * take the family's values (a post look that turns GTAO on needs a GTAO in `post`).
46
+ * @example applyLookFamily('animatedFeature', { sky: { sky }, water, terrain: colors });
47
+ */
48
+ export declare function applyLookFamily(name: LookFamilyName, targets: LookFamilyTargets): void;
@@ -0,0 +1,34 @@
1
+ import { SKY_LOOKS as e, applySkySettings as t } from "@margoengine/sky/settings";
2
+ import { WATER_LOOKS as n, applyWaterSettings as r } from "@margoengine/water/settings";
3
+ import { TERRAIN_LOOKS as i, applyTerrainSettings as a } from "@margoengine/terrain/settings";
4
+ import { WEATHER_LOOKS as o, applyWeatherSettings as s } from "@margoengine/weather/settings";
5
+ import { ENVIRONMENT_LOOKS as c, applyEnvironmentSettings as l } from "@margoengine/environment/settings";
6
+ import { FLAME_LOOKS as u, SAND_LOOKS as d, SMOKE_LOOKS as f, applyFlameSettings as p, applySandSettings as m, applySmokeSettings as h } from "@margoengine/vfx/settings";
7
+ import { TONEMAP_LOOKS as g, applyTonemapSettings as _ } from "@margoengine/tonemap/settings";
8
+ import { POST_LOOKS as v, applyPostSettings as y } from "@margoengine/post/settings";
9
+ import { biomeMaterials as b } from "@margoengine/biomes/settings";
10
+ //#region src/look-family.ts
11
+ var x = ["natural", "animatedFeature"], S = x, C = [
12
+ "hours",
13
+ "timeScale",
14
+ "sun.mode",
15
+ "sun.azimuth",
16
+ "sun.elevation"
17
+ ], w = [
18
+ "hours",
19
+ "timeScale",
20
+ "sunDirection"
21
+ ];
22
+ function T(T, E) {
23
+ if (!S.includes(T)) throw RangeError(`Unknown look family ${String(T)}; use one of ${x.join(", ")}.`);
24
+ let D = (e) => e[T];
25
+ if (E.sky) {
26
+ let n = E.sky.sky.options, r = w.map((e) => [e, n[e]]), i = { ...D(e) };
27
+ for (let e of C) delete i[e];
28
+ t(E.sky, i);
29
+ for (let [e, t] of r) t === void 0 ? delete n[e] : n[e] = Array.isArray(t) ? [...t] : t;
30
+ }
31
+ E.water && r(E.water, D(n)), E.terrain && a(E.terrain, D(i)), E.weather && s(E.weather, D(o)), E.environment && l(E.environment, D(c)), E.sand && m(E.sand, D(d)), E.smoke && h(E.smoke, D(f)), E.fire && p(E.fire, D(u)), E.tonemap && _(E.tonemap, D(g)), E.post && y(E.post, D(v)), E.biomes && (E.biomes.materials = b(T));
32
+ }
33
+ //#endregion
34
+ export { x as LOOK_FAMILIES, T as applyLookFamily };
@@ -0,0 +1,89 @@
1
+ /** A colour value: linear RGB. */
2
+ export type SettingColor = readonly [number, number, number];
3
+ /** One gradient stop: a colour at a position (`elevation` unless the row's `stopKey` says otherwise). */
4
+ export type SettingStop = { readonly color: SettingColor };
5
+ /** One value of a setting: a number, a colour, a choice, gradient stops, or null where `nullable`. */
6
+ export type SettingValue = number | SettingColor | string | readonly SettingStop[] | null;
7
+ /** Values by setting name; a name left out takes its default. */
8
+ export type SettingValues = Readonly<Record<string, SettingValue>>;
9
+ /** One slider row, the shape every package's `/settings` entry shares. */
10
+ export interface SettingRow {
11
+ readonly name: string;
12
+ readonly group: string;
13
+ /** `number` is a slider, `color` three sliders or a picker, `choice` a list, `gradient` a stop editor. */
14
+ readonly kind: 'number' | 'color' | 'choice' | 'gradient';
15
+ /** The value with which the target draws exactly as it does without the option (null: follow the weather). */
16
+ readonly default: SettingValue;
17
+ readonly min?: number;
18
+ readonly max?: number;
19
+ readonly step?: number;
20
+ readonly choices?: readonly string[];
21
+ /** May be null: the target uses its own value, or follows the weather when `weather` is set. */
22
+ readonly nullable?: boolean;
23
+ /** The weather master slider that drives this row while it is null. */
24
+ readonly weather?: string;
25
+ /** The key a gradient stop is placed by (default `elevation`). */
26
+ readonly stopKey?: string;
27
+ readonly unit: string;
28
+ readonly about: string;
29
+ /** True: cheap to write every frame (no pipeline, buffer or texture is created), so it can be keyed over a shot. False: writing it rebuilds something. */
30
+ readonly live: boolean;
31
+ }
32
+ export declare const numberSetting: (
33
+ name: string,
34
+ group: string,
35
+ value: number,
36
+ min: number,
37
+ max: number,
38
+ step: number,
39
+ unit: string,
40
+ about: string,
41
+ live?: boolean,
42
+ ) => SettingRow;
43
+ export declare const colorSetting: (
44
+ name: string,
45
+ group: string,
46
+ value: SettingColor,
47
+ min: number,
48
+ max: number,
49
+ about: string,
50
+ live?: boolean,
51
+ ) => SettingRow;
52
+ export declare const choiceSetting: (
53
+ name: string,
54
+ group: string,
55
+ choices: readonly string[],
56
+ about: string,
57
+ live?: boolean,
58
+ ) => SettingRow;
59
+ /** The row with a null default that follows the weather master slider `weather` until a value is given. */
60
+ export declare const followsWeather: (row: SettingRow, weather: string) => SettingRow;
61
+ /** Marks `key` of `target` as set by hand (`held` true) or hands it back to the weather (false). */
62
+ export declare function holdFromWeather(target: object, key: string, held?: boolean): void;
63
+ /** True while `key` of `target` holds a value set by hand, which the weather drive leaves alone. */
64
+ export declare const heldFromWeather: (target: object, key: string) => boolean;
65
+ export declare const sameSettingValue: (a: unknown, b: unknown) => boolean;
66
+ export declare function copySettingValue(v: SettingValue): SettingValue;
67
+ /** A fresh object holding every row at its default (a slider panel's state). */
68
+ export declare function settingDefaults(rows: readonly SettingRow[]): Record<string, SettingValue>;
69
+ /** The rows that may change every frame without a rebuild. */
70
+ export declare const liveSettings: (rows: readonly SettingRow[]) => SettingRow[];
71
+ /** A name to row map. */
72
+ export declare const settingIndex: (rows: readonly SettingRow[]) => Map<string, SettingRow>;
73
+ /** @throws RangeError when `v` is not a value of `row`. */
74
+ export declare function checkSettingValue(row: SettingRow, v: unknown, label: string): void;
75
+ /** @throws TypeError for an unknown name; RangeError for a bad value or a null on a row that is not nullable. */
76
+ export declare function checkSettings(
77
+ rows: readonly SettingRow[] | ReadonlyMap<string, SettingRow>,
78
+ values: SettingValues,
79
+ label: string,
80
+ entry?: string,
81
+ ): void;
82
+ /** Checks `values`, then calls `write` once per row (or per row `only` accepts) with the given value or the default. */
83
+ export declare function applySettings(
84
+ rows: readonly SettingRow[],
85
+ values: SettingValues,
86
+ label: string,
87
+ write: (row: SettingRow, value: SettingValue) => void,
88
+ only?: (row: SettingRow) => boolean,
89
+ ): void;
@@ -0,0 +1,40 @@
1
+ import { type SettingRow } from './shared/settings.js';
2
+ /** How the value moves from a key to the next: `linear`, `in` (slow start), `out` (slow end) or `inOut` (smoothstep). */
3
+ export type ShotEase = 'linear' | 'in' | 'out' | 'inOut';
4
+ /** One key of a keyed row: at `time` seconds into the shot the row has `value`; `ease` shapes the way to the next key. */
5
+ export interface ShotKey {
6
+ readonly time: number;
7
+ readonly value: unknown;
8
+ readonly ease?: ShotEase;
9
+ }
10
+ /** A row held for the whole shot (a plain value) or keyed over it. */
11
+ export type ShotRowValue = unknown | {
12
+ readonly keys: readonly ShotKey[];
13
+ };
14
+ /** The settings of one shot: target name, then row name, then a held value or keys. */
15
+ export type ShotSettingsBlock = Readonly<Record<string, Readonly<Record<string, ShotRowValue>>>>;
16
+ /** The rows of each target, by target name. */
17
+ export type ShotTables = Readonly<Record<string, readonly SettingRow[]>>;
18
+ /** The values at one time: target name, then row name, then value. */
19
+ export type ShotValues = Record<string, Record<string, unknown>>;
20
+ /**
21
+ * Checks a shot's settings against the tables before a render starts: every target and row exists, each held value and
22
+ * each key's value is a value of its row (the package's own check), a keyed row is `live`, key times rise and lie inside
23
+ * `[0, seconds]` (when `seconds` is given) and an ease is one of `linear`, `in`, `out`, `inOut`.
24
+ * @throws TypeError for an unknown target or row; RangeError for a bad value, a keyed row that is not live, key times
25
+ * that do not rise or leave the shot, or an unknown ease. The message names the target and the row.
26
+ * @example checkShotSettings({ weather: { 'wind.speed': { keys: [{ time: 0, value: 4 }, { time: 8, value: 20 }] } } }, { weather: WEATHER_SETTINGS }, 8);
27
+ */
28
+ export declare function checkShotSettings(block: ShotSettingsBlock, tables: ShotTables, seconds?: number): void;
29
+ /**
30
+ * The values of a (checked) shot block `seconds` into the shot: held rows as given, keyed rows between their keys (a
31
+ * number linearly through the key's ease, a colour per channel in linear RGB, a gradient stop by stop when both keys
32
+ * have the same stops; a choice, a null and a gradient with other stops step at each key), the first key's value
33
+ * before it and the last key's after it. Equal inputs give equal bytes.
34
+ */
35
+ export declare function shotSettingsAt(block: ShotSettingsBlock, tables: ShotTables, seconds: number): ShotValues;
36
+ /**
37
+ * The held rows that are not live (a row the package rebuilds something for): applied once before the shot's warm-up,
38
+ * never every frame. Returned in the shape of {@link shotSettingsAt}.
39
+ */
40
+ export declare function shotHeldRebuilds(block: ShotSettingsBlock, tables: ShotTables): ShotValues;
@@ -0,0 +1,94 @@
1
+ //#region ../shared/settings.js
2
+ var e = (e, t, n) => typeof e == "number" && e >= t && e <= n, t = (t, n, r) => Array.isArray(t) && t.length === 3 && t.every((t) => e(t, n, r)), n = (e) => e.stopKey ?? "elevation";
3
+ function r(e) {
4
+ return Array.isArray(e) ? typeof e[0] == "object" ? e.map((e) => ({
5
+ ...e,
6
+ color: [...e.color]
7
+ })) : [...e] : e;
8
+ }
9
+ var i = (e) => new Map(e.map((e) => [e.name, e]));
10
+ function a(r, i, a) {
11
+ let o = r.min ?? -Infinity, s = r.max ?? Infinity, c;
12
+ if (i === null) c = !!r.nullable;
13
+ else if (r.kind === "number") c = e(i, o, s);
14
+ else if (r.kind === "color") c = t(i, o, s);
15
+ else if (r.kind === "choice") c = r.choices.includes(i);
16
+ else {
17
+ let a = n(r);
18
+ c = Array.isArray(i) && i.length >= 2 && i.length <= 8 && i.every((n, r) => typeof n == "object" && !!n && e(n[a], o, s) && t(n.color, 0, 1) && (r === 0 || n[a] > i[r - 1][a]));
19
+ }
20
+ if (c) return;
21
+ let l = r.nullable ? r.weather ? ` or null (follow the weather's ${r.weather})` : " or null" : "", u = r.kind === "number" ? `a number from ${o} to ${s}${l}` : r.kind === "color" ? `three numbers from ${o} to ${s} (linear RGB)${l}` : r.kind === "choice" ? r.choices.map((e) => `'${e}'`).join(" or ") + l : `2 to 8 stops {${n(r)}, color}, ${n(r)} ${o} to ${s} rising, colours 0 to 1${l}`;
22
+ throw RangeError(`Invalid ${a} setting ${r.name}; use ${u}`);
23
+ }
24
+ //#endregion
25
+ //#region src/shot-settings.ts
26
+ var o = [
27
+ "linear",
28
+ "in",
29
+ "out",
30
+ "inOut"
31
+ ], s = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "keys" in e, c = (e, t) => e === "in" ? t * t : e === "out" ? 1 - (1 - t) * (1 - t) : e === "inOut" ? t * t * (3 - 2 * t) : t, l = (e) => e.stopKey ?? "elevation";
32
+ function u(e, t, n) {
33
+ if (typeof e != "object" || !e) throw TypeError("Shot settings must be an object of targets; pass { target: { row: value } }.");
34
+ for (let [r, c] of Object.entries(e)) {
35
+ if (!(r in t)) throw TypeError(`Unknown shot target ${r}; use one of ${Object.keys(t).join(", ")}.`);
36
+ let e = i(t[r]);
37
+ for (let [t, i] of Object.entries(c)) {
38
+ let c = `shot target ${r} row ${t}`, l = e.get(t);
39
+ if (!l) throw TypeError(`Unknown ${c}; use a name from the ${r} settings table.`);
40
+ if (!s(i)) {
41
+ a(l, i, c);
42
+ continue;
43
+ }
44
+ if (!l.live) throw RangeError(`Invalid ${c}; it is not live, so hold a single value instead of keys.`);
45
+ let u = i.keys;
46
+ if (!Array.isArray(u) || u.length < 1) throw RangeError(`Invalid ${c}; keys needs at least one { time, value }.`);
47
+ let d = -Infinity;
48
+ for (let e of u) {
49
+ if (typeof e?.time != "number" || !Number.isFinite(e.time) || e.time < 0 || n !== void 0 && e.time > n) throw RangeError(`Invalid ${c}; key times must be seconds inside the shot (0 to ${n ?? "its length"}).`);
50
+ if (!(e.time > d)) throw RangeError(`Invalid ${c}; key times must rise.`);
51
+ if (d = e.time, e.ease !== void 0 && !o.includes(e.ease)) throw RangeError(`Invalid ${c}; ease is one of ${o.join(", ")}.`);
52
+ a(l, e.value, c);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ function d(e, t, n, r) {
58
+ if (t === null || n === null) return t;
59
+ if (e.kind === "number") return t + (n - t) * r;
60
+ if (e.kind === "color") return t.map((e, t) => e + (n[t] - e) * r);
61
+ if (e.kind === "choice") return t;
62
+ let i = l(e), a = t, o = n;
63
+ return a.length !== o.length || !a.every((e, t) => e[i] === o[t][i]) ? t : a.map((e, t) => ({
64
+ ...e,
65
+ color: e.color.map((e, n) => e + (o[t].color[n] - e) * r)
66
+ }));
67
+ }
68
+ function f(e, t, n) {
69
+ if (n <= t[0].time) return r(t[0].value);
70
+ let i = t[t.length - 1];
71
+ if (n >= i.time) return r(i.value);
72
+ let a = 0;
73
+ for (; t[a + 1].time <= n;) a++;
74
+ let o = t[a], s = t[a + 1], l = c(o.ease, (n - o.time) / (s.time - o.time));
75
+ return r(d(e, o.value, s.value, l));
76
+ }
77
+ function p(e, t, n) {
78
+ let a = {};
79
+ for (let [o, c] of Object.entries(e)) {
80
+ let e = i(t[o]), l = a[o] = {};
81
+ for (let [t, i] of Object.entries(c)) l[t] = s(i) ? f(e.get(t), i.keys, n) : r(i);
82
+ }
83
+ return a;
84
+ }
85
+ function m(e, t) {
86
+ let n = {};
87
+ for (let [a, o] of Object.entries(e)) {
88
+ let e = i(t[a]);
89
+ for (let [t, i] of Object.entries(o)) !e.get(t).live && !s(i) && ((n[a] ??= {})[t] = r(i));
90
+ }
91
+ return n;
92
+ }
93
+ //#endregion
94
+ export { u as checkShotSettings, m as shotHeldRebuilds, p as shotSettingsAt };