@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +387 -3
- package/dist/dune-coast-info-e8eDZXBu.js +208 -0
- package/dist/dune-coast-info.d.ts +3 -0
- package/dist/dune-coast.d.ts +160 -0
- package/dist/dune-coast.js +591 -0
- package/dist/fauld-blast.d.ts +67 -0
- package/dist/fauld-blast.js +283 -0
- package/dist/fauld-countryside.d.ts +13 -0
- package/dist/fauld-countryside.js +10 -0
- package/dist/fauld-crater.d.ts +13 -0
- package/dist/fauld-crater.js +10 -0
- package/dist/fauld-tunnels-info-8qv9X4OJ.js +70 -0
- package/dist/fauld-tunnels-info.d.ts +5 -0
- package/dist/fauld-tunnels-plan.d.ts +1069 -0
- package/dist/fauld-tunnels.d.ts +208 -0
- package/dist/fauld-tunnels.js +6476 -0
- package/dist/fauld-world-85dg03jo.js +582 -0
- package/dist/fauld-world-info.d.ts +7 -0
- package/dist/fauld-world.d.ts +160 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +160 -0
- package/dist/library-mesh-BRk4Ycnn.js +306 -0
- package/dist/library-mesh.d.ts +108 -0
- package/dist/library-parts.d.ts +45 -0
- package/dist/library.d.ts +52 -0
- package/dist/library.js +48 -0
- package/dist/look-family.d.ts +48 -0
- package/dist/look-family.js +34 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/shot-settings.d.ts +40 -0
- package/dist/shot-settings.js +94 -0
- package/dist/timber-valley-info-BB6GvcsL.js +242 -0
- package/dist/timber-valley-info.d.ts +3 -0
- package/dist/timber-valley.d.ts +163 -0
- package/dist/timber-valley.js +362 -0
- package/package.json +104 -6
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel, Mesh, Vec3 } from '@margoengine/core';
|
|
3
|
+
import { BiomeWorld } from '@margoengine/biomes';
|
|
4
|
+
import '@margoengine/biomes/splines';
|
|
5
|
+
import { type Farmland } from '@margoengine/biomes/farmland';
|
|
6
|
+
import { BiomeView } from '@margoengine/biomes/view';
|
|
7
|
+
import { PresetScene } from '@margoengine/sky/scenes';
|
|
8
|
+
import { VolumetricClouds } from '@margoengine/sky/volumetric-clouds';
|
|
9
|
+
import { WeatherMachine } from '@margoengine/weather';
|
|
10
|
+
import { type Model } from '@margoengine/gltf';
|
|
11
|
+
import { Shadows } from '@margoengine/shadows';
|
|
12
|
+
import { DOF } from '@margoengine/dof';
|
|
13
|
+
/** World size, metres. */
|
|
14
|
+
export declare const FAULD_SIZE = 6400;
|
|
15
|
+
/** The world's centre (the crater) on the OS grid, metres. */
|
|
16
|
+
export declare const FAULD_CENTRE: Readonly<{
|
|
17
|
+
easting: 418225;
|
|
18
|
+
northing: 327725;
|
|
19
|
+
}>;
|
|
20
|
+
/** Height samples, metres apart. */
|
|
21
|
+
export declare const FAULD_STEP = 5;
|
|
22
|
+
/** Places on the ground, `[x, z]` metres from the crater. */
|
|
23
|
+
export declare const FAULD_PLACES: Readonly<{
|
|
24
|
+
crater: readonly [0, 0];
|
|
25
|
+
farm: readonly [0, 10];
|
|
26
|
+
hanbury: readonly [-1225, -175];
|
|
27
|
+
church: readonly [-1190, -190];
|
|
28
|
+
inn: readonly [-1120, -120];
|
|
29
|
+
works: readonly [120, -780];
|
|
30
|
+
reservoir: readonly [210, -430];
|
|
31
|
+
dove: readonly [-300, -2600];
|
|
32
|
+
tutbury: readonly [3100, -1300];
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* The buildings, vehicles and cattle (Tripo models by Scott, 2026-11-24, decimated in Blender to real size): where each
|
|
36
|
+
* stands, its turn about the vertical in fractions of a full turn, the library model under
|
|
37
|
+
* `margo-library/fauld/buildings/` and the eras it stands in. Shots keep buildings at 150 m or more and under a quarter
|
|
38
|
+
* of the frame height (channel-films fauld-recut-plan section 4). The farmhouse slot has no model yet (drawn as nothing).
|
|
39
|
+
*/
|
|
40
|
+
export declare const FAULD_SLOTS: Readonly<{
|
|
41
|
+
church: {
|
|
42
|
+
at: readonly [-1190, -190];
|
|
43
|
+
turn: number;
|
|
44
|
+
model: string;
|
|
45
|
+
eras: string[];
|
|
46
|
+
};
|
|
47
|
+
inn: {
|
|
48
|
+
at: readonly [-1120, -120];
|
|
49
|
+
turn: number;
|
|
50
|
+
model: string;
|
|
51
|
+
eras: string[];
|
|
52
|
+
};
|
|
53
|
+
cottages: {
|
|
54
|
+
at: readonly [-1260, -90];
|
|
55
|
+
turn: number;
|
|
56
|
+
model: string;
|
|
57
|
+
eras: string[];
|
|
58
|
+
};
|
|
59
|
+
farmhouse: {
|
|
60
|
+
at: readonly [0, 10];
|
|
61
|
+
turn: number;
|
|
62
|
+
model: undefined;
|
|
63
|
+
eras: string[];
|
|
64
|
+
};
|
|
65
|
+
kilnWorks: {
|
|
66
|
+
at: readonly [120, -780];
|
|
67
|
+
turn: number;
|
|
68
|
+
model: string;
|
|
69
|
+
eras: string[];
|
|
70
|
+
};
|
|
71
|
+
guardHut: {
|
|
72
|
+
at: readonly [150, 120];
|
|
73
|
+
turn: number;
|
|
74
|
+
model: string;
|
|
75
|
+
eras: string[];
|
|
76
|
+
};
|
|
77
|
+
nfsTender: {
|
|
78
|
+
at: readonly [205, 150];
|
|
79
|
+
turn: number;
|
|
80
|
+
model: string;
|
|
81
|
+
eras: string[];
|
|
82
|
+
};
|
|
83
|
+
wvsVan: {
|
|
84
|
+
at: readonly [222, 162];
|
|
85
|
+
turn: number;
|
|
86
|
+
model: string;
|
|
87
|
+
eras: string[];
|
|
88
|
+
};
|
|
89
|
+
cattle: {
|
|
90
|
+
at: readonly [-160, 220];
|
|
91
|
+
turn: number;
|
|
92
|
+
model: string;
|
|
93
|
+
eras: string[];
|
|
94
|
+
};
|
|
95
|
+
}>;
|
|
96
|
+
/** The era of the ground: the farm before the explosion, the fresh 1944 crater, or the wooded crater today. */
|
|
97
|
+
export type FauldEra = 'before' | '1944' | 'today';
|
|
98
|
+
/** Sky and weather of a shot. */
|
|
99
|
+
export type FauldSky = 'dawn' | 'lowSun' | 'overcast' | 'grey' | 'dusk' | 'night' | 'snow' | 'rain' | 'mist';
|
|
100
|
+
/** Settings shared by both places. */
|
|
101
|
+
export interface FauldWorldSettings {
|
|
102
|
+
readonly era?: FauldEra;
|
|
103
|
+
readonly sky?: FauldSky;
|
|
104
|
+
/** Local solar time, hours. Default by `sky`. */
|
|
105
|
+
readonly hour?: number;
|
|
106
|
+
/** The shot's subject, `[x, z]` metres (kept for the shot files; the view draws round the camera). Default the crater. */
|
|
107
|
+
readonly focus?: readonly [number, number];
|
|
108
|
+
/** How far round the camera the view grows plants (hedges, trees, woods), metres, 200 to 3,000. Default 2,500. */
|
|
109
|
+
readonly radius?: number;
|
|
110
|
+
/** URL of the height grid (`fauld_sk12_sk23.f32` with its `.json` beside it). Default under `library`. */
|
|
111
|
+
readonly dem?: string;
|
|
112
|
+
/** URL of the asset library root. Default `/asset-library/`. */
|
|
113
|
+
readonly library?: string;
|
|
114
|
+
/** Whether the buildings, vehicles and cattle of `FAULD_SLOTS` are drawn. Default true. */
|
|
115
|
+
readonly buildings?: boolean;
|
|
116
|
+
/** The lens: an f-number (`stop`) and a focus distance in metres, drawn by `DOF` of @margoengine/dof on a Super 35
|
|
117
|
+
* sensor (24.89 mm across), so the focal length follows the camera's field of view. Default f/8 focused at 1,000 m
|
|
118
|
+
* (a landscape lens: the blur at f/8 on a 24 mm lens is under a pixel from about 12 m out). */
|
|
119
|
+
readonly lens?: {
|
|
120
|
+
readonly stop?: number;
|
|
121
|
+
readonly focusDistance?: number;
|
|
122
|
+
};
|
|
123
|
+
readonly seed?: number;
|
|
124
|
+
readonly signal?: AbortSignal;
|
|
125
|
+
}
|
|
126
|
+
/** The world handle. */
|
|
127
|
+
export interface FauldWorld extends Disposable {
|
|
128
|
+
readonly era: FauldEra;
|
|
129
|
+
readonly world: BiomeWorld;
|
|
130
|
+
readonly farm: Farmland;
|
|
131
|
+
readonly view: BiomeView;
|
|
132
|
+
readonly preset: PresetScene;
|
|
133
|
+
readonly clouds: VolumetricClouds;
|
|
134
|
+
readonly weather: WeatherMachine;
|
|
135
|
+
readonly shadows: Shadows;
|
|
136
|
+
/** The lens's depth of field (`settings.lens`). */
|
|
137
|
+
readonly dof: DOF;
|
|
138
|
+
readonly meshes: readonly Mesh[];
|
|
139
|
+
/** The slot models drawn, by slot name (cattle are one model per animal). */
|
|
140
|
+
readonly buildings: Readonly<Record<string, readonly Model[]>>;
|
|
141
|
+
height(x: number, z: number): number;
|
|
142
|
+
/** Puts the camera at a position looking at a target (field of view in degrees). */
|
|
143
|
+
look(position: Vec3, target: Vec3, fov?: number): void;
|
|
144
|
+
advanceTime(seconds: number): void;
|
|
145
|
+
settle(): Promise<void>;
|
|
146
|
+
dispose(): void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The overcast deck of a grey November day, metres above the ground: a stratocumulus sheet, the common winter overcast
|
|
150
|
+
* over the English Midlands, with its base at 1,000 m and tops at 1,600 m (WMO International Cloud Atlas 2017,
|
|
151
|
+
* stratocumulus: base usually 500 to 2,000 m, https://cloudatlas.wmo.int/en/stratocumulus.html). The volumetric
|
|
152
|
+
* stratus default (300 to 900 m) put the film's 400 to 700 m drone cameras inside the cloud, so every aerial shot read
|
|
153
|
+
* as thick haze; a drone films under the deck, so its base stays above the highest camera plus the highest ground.
|
|
154
|
+
*/
|
|
155
|
+
export declare const FAULD_CLOUD_DECK: Readonly<{
|
|
156
|
+
bottom: 1000;
|
|
157
|
+
top: 1600;
|
|
158
|
+
}>;
|
|
159
|
+
/** Builds the shared Fauld ground, farmland, sky and weather into `engine`. */
|
|
160
|
+
export declare function attachFauldWorld(engine: EngineKernel, settings?: FauldWorldSettings): Promise<FauldWorld>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** One setting of a scene: its default, and its range, unit or allowed values. */
|
|
2
|
+
export interface SceneSetting {
|
|
3
|
+
readonly default: unknown;
|
|
4
|
+
/** Lowest and highest allowed value of a number setting. */
|
|
5
|
+
readonly range?: readonly [number, number];
|
|
6
|
+
/** Unit of a number setting, such as `m`, `m/s`, `deg` or `h`. */
|
|
7
|
+
readonly unit?: string;
|
|
8
|
+
/** Allowed values of a choice setting. */
|
|
9
|
+
readonly options?: readonly string[];
|
|
10
|
+
readonly about: string;
|
|
11
|
+
}
|
|
12
|
+
/** One shot of a scene: how long, which camera keys it uses, the settings it holds or keys per target, what to check. */
|
|
13
|
+
export interface SceneShot {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
/** Length in seconds. */
|
|
16
|
+
readonly seconds: number;
|
|
17
|
+
/** The scene's camera keys (view or anchor names) the shot moves between. */
|
|
18
|
+
readonly camera: readonly string[];
|
|
19
|
+
/** Per-target rows held or keyed over the shot, as `@margoengine/scenes/shot-settings` checks and evaluates them. */
|
|
20
|
+
readonly settings?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
21
|
+
/** Named look probes the shot is judged on (three per shot). */
|
|
22
|
+
readonly probes?: readonly string[];
|
|
23
|
+
readonly about: string;
|
|
24
|
+
}
|
|
25
|
+
/** A catalogue entry: what the scene is, its settings, presets, anchors and views, and the entry that builds it. */
|
|
26
|
+
export interface SceneInfo {
|
|
27
|
+
/** Short name, also the entry's last path part. */
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly title: string;
|
|
30
|
+
readonly about: string;
|
|
31
|
+
/** The module to import; it exports `attach(engine, settings)` and `info`. */
|
|
32
|
+
readonly entry: string;
|
|
33
|
+
readonly settings: Readonly<Record<string, SceneSetting>>;
|
|
34
|
+
/** Named setting sets, merged over the defaults. */
|
|
35
|
+
readonly presets: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
36
|
+
/** Named places the scene's handle gives (`scene.anchors`). */
|
|
37
|
+
readonly anchors: readonly string[];
|
|
38
|
+
/** Named camera views (`scene.view(name)`). */
|
|
39
|
+
readonly views: readonly string[];
|
|
40
|
+
/** Names of the looks (picture styles) the scene takes: the families a film or shot may name, such as `natural`. */
|
|
41
|
+
readonly looks?: readonly string[];
|
|
42
|
+
/** The shots the scene is filmed in; `tools/shot` writes each shot file from these, so a shot is authored once. */
|
|
43
|
+
readonly shots?: readonly SceneShot[];
|
|
44
|
+
/** Target name to the package settings entry whose table it uses (`weather` to `@margoengine/weather/settings`); the names a shot's `settings` use. */
|
|
45
|
+
readonly targets?: Readonly<Record<string, string>>;
|
|
46
|
+
}
|
|
47
|
+
/** Every scene in the catalogue. Import an entry's `attach` to build it. */
|
|
48
|
+
export declare const scenes: readonly SceneInfo[];
|
|
49
|
+
/**
|
|
50
|
+
* The catalogue entry named `name`.
|
|
51
|
+
* @throws RangeError for a name not in the catalogue.
|
|
52
|
+
*/
|
|
53
|
+
export declare function sceneInfo(name: string): SceneInfo;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { t as e } from "./dune-coast-info-e8eDZXBu.js";
|
|
2
|
+
import { t } from "./timber-valley-info-BB6GvcsL.js";
|
|
3
|
+
import { n } from "./fauld-tunnels-info-8qv9X4OJ.js";
|
|
4
|
+
//#region src/fauld-world-info.ts
|
|
5
|
+
var r = {
|
|
6
|
+
era: {
|
|
7
|
+
default: "before",
|
|
8
|
+
options: [
|
|
9
|
+
"before",
|
|
10
|
+
"1944",
|
|
11
|
+
"today"
|
|
12
|
+
],
|
|
13
|
+
about: "the farm before, the fresh 1944 crater, or the wooded crater today"
|
|
14
|
+
},
|
|
15
|
+
sky: {
|
|
16
|
+
default: "lowSun",
|
|
17
|
+
options: [
|
|
18
|
+
"dawn",
|
|
19
|
+
"lowSun",
|
|
20
|
+
"overcast",
|
|
21
|
+
"grey",
|
|
22
|
+
"dusk",
|
|
23
|
+
"night",
|
|
24
|
+
"snow",
|
|
25
|
+
"rain",
|
|
26
|
+
"mist"
|
|
27
|
+
],
|
|
28
|
+
about: "sky and weather of a late-November day at Fauld"
|
|
29
|
+
},
|
|
30
|
+
hour: {
|
|
31
|
+
default: 11.5,
|
|
32
|
+
range: [0, 24],
|
|
33
|
+
unit: "h",
|
|
34
|
+
about: "local solar time on 27 November (default by sky)"
|
|
35
|
+
},
|
|
36
|
+
radius: {
|
|
37
|
+
default: 2500,
|
|
38
|
+
range: [200, 3e3],
|
|
39
|
+
unit: "m",
|
|
40
|
+
about: "how far round the camera the view grows plants"
|
|
41
|
+
},
|
|
42
|
+
buildings: {
|
|
43
|
+
default: !0,
|
|
44
|
+
about: "draws the Tripo buildings, vehicles and cattle of FAULD_SLOTS for the era"
|
|
45
|
+
},
|
|
46
|
+
library: {
|
|
47
|
+
default: "/asset-library/",
|
|
48
|
+
about: "URL root of the asset library (margo-library/fauld and dem)"
|
|
49
|
+
}
|
|
50
|
+
}, i = [
|
|
51
|
+
"crater",
|
|
52
|
+
"farm",
|
|
53
|
+
"hanbury",
|
|
54
|
+
"church",
|
|
55
|
+
"inn",
|
|
56
|
+
"works",
|
|
57
|
+
"reservoir",
|
|
58
|
+
"dove",
|
|
59
|
+
"tutbury"
|
|
60
|
+
], a = {
|
|
61
|
+
name: "fauld-countryside",
|
|
62
|
+
title: "The countryside round Fauld and Hanbury (Staffordshire, November 1944)",
|
|
63
|
+
about: "The real hills round Hanbury and Fauld from Ordnance Survey OS Terrain 50, the hedged field quilt of the English lowland farm world, hedgerows and woods from library trees, Hanbury church, the Cock Inn, cottages, the kiln works and a grazing herd, under a late-November sky.",
|
|
64
|
+
entry: "@margoengine/scenes/fauld-countryside",
|
|
65
|
+
settings: r,
|
|
66
|
+
presets: {
|
|
67
|
+
morning: { sky: "dawn" },
|
|
68
|
+
day: { sky: "lowSun" },
|
|
69
|
+
after: {
|
|
70
|
+
era: "1944",
|
|
71
|
+
sky: "grey"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
anchors: i,
|
|
75
|
+
views: [
|
|
76
|
+
"aerial",
|
|
77
|
+
"lane",
|
|
78
|
+
"pasture"
|
|
79
|
+
]
|
|
80
|
+
}, o = {
|
|
81
|
+
name: "fauld-crater",
|
|
82
|
+
title: "The Fauld crater (Staffordshire, 1944 and today)",
|
|
83
|
+
about: "The crater the explosion of 27 November 1944 left where Upper Castle Hayes Farm stood, stamped into the real ground from its model: bare marl and gypsum in 1944, the wooded hollow today, with the farm quilt round it.",
|
|
84
|
+
entry: "@margoengine/scenes/fauld-crater",
|
|
85
|
+
settings: {
|
|
86
|
+
...r,
|
|
87
|
+
era: {
|
|
88
|
+
...r.era,
|
|
89
|
+
default: "1944"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
presets: {
|
|
93
|
+
fresh: {
|
|
94
|
+
era: "1944",
|
|
95
|
+
sky: "grey"
|
|
96
|
+
},
|
|
97
|
+
snow: {
|
|
98
|
+
era: "1944",
|
|
99
|
+
sky: "snow"
|
|
100
|
+
},
|
|
101
|
+
today: { era: "today" }
|
|
102
|
+
},
|
|
103
|
+
anchors: i,
|
|
104
|
+
views: [
|
|
105
|
+
"rim",
|
|
106
|
+
"aerial",
|
|
107
|
+
"floor"
|
|
108
|
+
]
|
|
109
|
+
}, s = {
|
|
110
|
+
name: "fauld-blast",
|
|
111
|
+
title: "The Fauld explosion (Staffordshire, 11:11 on 27 November 1944)",
|
|
112
|
+
about: "The countryside round Fauld at the moment of the explosion: two releases seconds apart rising as one merging mushroom cloud with fire at its foot, earth clods and gypsum blocks thrown out and landing with dust, the incendiary dump burning, and the mud of the burst reservoir pouring down to the works; every part on film time, so a seek shows the same frame.",
|
|
113
|
+
entry: "@margoengine/scenes/fauld-blast",
|
|
114
|
+
settings: {
|
|
115
|
+
...r,
|
|
116
|
+
sky: {
|
|
117
|
+
...r.sky,
|
|
118
|
+
default: "overcast"
|
|
119
|
+
},
|
|
120
|
+
time: {
|
|
121
|
+
default: 0,
|
|
122
|
+
range: [0, 3600],
|
|
123
|
+
unit: "s",
|
|
124
|
+
about: "film seconds since the first explosion"
|
|
125
|
+
},
|
|
126
|
+
mud: {
|
|
127
|
+
default: !1,
|
|
128
|
+
about: "the mud of the burst reservoir flows to the works (a GPU flood solver)"
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
presets: {
|
|
132
|
+
eruption: { time: 2 },
|
|
133
|
+
column: { time: 60 },
|
|
134
|
+
mud: {
|
|
135
|
+
era: "1944",
|
|
136
|
+
time: 90,
|
|
137
|
+
mud: !0
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
anchors: i,
|
|
141
|
+
views: [
|
|
142
|
+
"aerial",
|
|
143
|
+
"valley",
|
|
144
|
+
"field"
|
|
145
|
+
]
|
|
146
|
+
}, c = Object.freeze([
|
|
147
|
+
e,
|
|
148
|
+
t,
|
|
149
|
+
n,
|
|
150
|
+
a,
|
|
151
|
+
o,
|
|
152
|
+
s
|
|
153
|
+
]);
|
|
154
|
+
function l(e) {
|
|
155
|
+
let t = c.find((t) => t.name === e);
|
|
156
|
+
if (!t) throw RangeError(`Unknown scene ${e}; pass one of ${c.map((e) => e.name).join(", ")}.`);
|
|
157
|
+
return t;
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
export { l as sceneInfo, c as scenes };
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
//#region ../shared/errors.js
|
|
2
|
+
var e = (e, t) => Object.assign(Error(t), {
|
|
3
|
+
name: "MargoError",
|
|
4
|
+
code: e
|
|
5
|
+
}), t = /twig|leaf|leaves|needle|foliage|frond/i;
|
|
6
|
+
async function n(o, s = {}) {
|
|
7
|
+
if (typeof o != "string") {
|
|
8
|
+
if (!Array.isArray(o) || o.length !== 3) throw TypeError("libraryParts takes one URL or three; pass a string or [near, middle, far]");
|
|
9
|
+
let e = await Promise.all(o.map((e) => n(e, s)));
|
|
10
|
+
return e[0].map((t) => {
|
|
11
|
+
let n = e.map((e) => e.find((e) => e.name === t.name));
|
|
12
|
+
if (n.some((e) => !e)) throw TypeError(`libraryParts: material ${t.name} is missing from a level; export every level with the same materials`);
|
|
13
|
+
let [r, i, a] = n;
|
|
14
|
+
return {
|
|
15
|
+
...t,
|
|
16
|
+
geometry: [
|
|
17
|
+
r.geometry,
|
|
18
|
+
i.geometry,
|
|
19
|
+
a.geometry
|
|
20
|
+
],
|
|
21
|
+
textures: {
|
|
22
|
+
...t.textures,
|
|
23
|
+
uvs: [
|
|
24
|
+
r.textures.uvs,
|
|
25
|
+
i.textures.uvs,
|
|
26
|
+
a.textures.uvs
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
let c = s.fetch ?? globalThis.fetch, l = s.signal ? { signal: s.signal } : {}, u = await c(o, l);
|
|
33
|
+
if (!u.ok) throw e("failed", `libraryParts: ${o} answered ${u.status}; check the URL and that the server serves the file`);
|
|
34
|
+
let d = await u.json(), f = o.slice(0, o.lastIndexOf("/") + 1);
|
|
35
|
+
if (!d.meshes?.length || !d.accessors || !d.bufferViews || !d.buffers || !d.nodes) throw TypeError(`libraryParts: ${o} holds no meshes; pass a .gltf with meshes, nodes and buffers`);
|
|
36
|
+
let p = async (t) => {
|
|
37
|
+
if (t.startsWith("data:")) throw TypeError("libraryParts reads a .gltf with external buffers and images; export the model as glTF separate");
|
|
38
|
+
let n = await c(f + t, l);
|
|
39
|
+
if (!n.ok) throw e("failed", `libraryParts: ${f + t} answered ${n.status}; check that the file sits beside the .gltf`);
|
|
40
|
+
return n.arrayBuffer();
|
|
41
|
+
}, m = await Promise.all(d.buffers.map((e) => p(e.uri ?? "data:"))), h = (e, t, n) => {
|
|
42
|
+
let r = d.accessors[e], i = r ? d.bufferViews[r.bufferView ?? -1] : void 0, o = r ? a[r.componentType] : void 0;
|
|
43
|
+
if (!r || !i) throw TypeError("libraryParts: an accessor without a buffer view; use a model whose accessors all have buffer views");
|
|
44
|
+
if (!o || n === (r.componentType === 5126)) throw TypeError(`libraryParts: unsupported accessor component type ${r.componentType}; use float vertices and uvs and integer indices`);
|
|
45
|
+
let [s, c] = o, l = i.byteStride ?? s * t, u = new DataView(m[i.buffer], (i.byteOffset ?? 0) + (r.byteOffset ?? 0)), f = n ? new Uint32Array(r.count * t) : new Float32Array(r.count * t);
|
|
46
|
+
for (let e = 0; e < r.count; e++) for (let n = 0; n < t; n++) f[e * t + n] = c(u, e * l + n * s);
|
|
47
|
+
return f;
|
|
48
|
+
}, g = /* @__PURE__ */ new Map(), _ = (e, t) => {
|
|
49
|
+
let n = d.nodes[e], a = i(t, r(n));
|
|
50
|
+
if (n.mesh !== void 0) for (let e of d.meshes[n.mesh].primitives) {
|
|
51
|
+
let t = e.attributes;
|
|
52
|
+
if ((e.mode ?? 4) !== 4 || t.POSITION === void 0 || t.NORMAL === void 0 || t.TEXCOORD_0 === void 0) continue;
|
|
53
|
+
let n = e.material ?? -1, r = g.get(n) ?? {
|
|
54
|
+
positions: [],
|
|
55
|
+
normals: [],
|
|
56
|
+
uvs: [],
|
|
57
|
+
indices: []
|
|
58
|
+
}, i = h(t.POSITION, 3, !1), o = h(t.NORMAL, 3, !1), s = h(t.TEXCOORD_0, 2, !1), c = r.positions.length / 3, l = i.length / 3;
|
|
59
|
+
g.set(n, r);
|
|
60
|
+
for (let e = 0; e < l; e++) {
|
|
61
|
+
let [t, n, c] = [
|
|
62
|
+
i[e * 3],
|
|
63
|
+
i[e * 3 + 1],
|
|
64
|
+
i[e * 3 + 2]
|
|
65
|
+
], [l, u, d] = [
|
|
66
|
+
o[e * 3],
|
|
67
|
+
o[e * 3 + 1],
|
|
68
|
+
o[e * 3 + 2]
|
|
69
|
+
];
|
|
70
|
+
r.positions.push(a[0] * t + a[4] * n + a[8] * c + a[12], a[1] * t + a[5] * n + a[9] * c + a[13], a[2] * t + a[6] * n + a[10] * c + a[14]);
|
|
71
|
+
let f = a[0] * l + a[4] * u + a[8] * d, p = a[1] * l + a[5] * u + a[9] * d, m = a[2] * l + a[6] * u + a[10] * d, h = Math.hypot(f, p, m) || 1;
|
|
72
|
+
r.normals.push(f / h, p / h, m / h), r.uvs.push(s[e * 2], s[e * 2 + 1]);
|
|
73
|
+
}
|
|
74
|
+
let u = e.indices === void 0 ? Uint32Array.from({ length: l }, (e, t) => t) : h(e.indices, 1, !0);
|
|
75
|
+
for (let e of u) r.indices.push(c + e);
|
|
76
|
+
}
|
|
77
|
+
for (let e of n.children ?? []) _(e, a);
|
|
78
|
+
}, v = [
|
|
79
|
+
1,
|
|
80
|
+
0,
|
|
81
|
+
0,
|
|
82
|
+
0,
|
|
83
|
+
0,
|
|
84
|
+
1,
|
|
85
|
+
0,
|
|
86
|
+
0,
|
|
87
|
+
0,
|
|
88
|
+
0,
|
|
89
|
+
1,
|
|
90
|
+
0,
|
|
91
|
+
0,
|
|
92
|
+
0,
|
|
93
|
+
0,
|
|
94
|
+
1
|
|
95
|
+
];
|
|
96
|
+
for (let e of d.scenes?.[d.scene ?? 0]?.nodes ?? d.nodes.map((e, t) => t)) _(e, v);
|
|
97
|
+
if (!g.size) throw TypeError(`libraryParts: ${o} holds no triangles with positions, normals and uvs; export the model with normals and TEXCOORD_0`);
|
|
98
|
+
let y = Infinity, b = Infinity, x = -Infinity, S = Infinity, C = -Infinity;
|
|
99
|
+
for (let e of g.values()) for (let t = 0; t < e.positions.length; t += 3) y = Math.min(y, e.positions[t + 1]), b = Math.min(b, e.positions[t]), x = Math.max(x, e.positions[t]), S = Math.min(S, e.positions[t + 2]), C = Math.max(C, e.positions[t + 2]);
|
|
100
|
+
let w = s.scale ?? 1, T = (b + x) / 2, E = (S + C) / 2, D = s.maxTriangles ?? 12e4, O = s.foliage ?? ((e) => t.test(e)), k = s.decode ?? (async (e, t) => createImageBitmap(new Blob([e], { type: t }), {
|
|
101
|
+
colorSpaceConversion: "none",
|
|
102
|
+
premultiplyAlpha: "none"
|
|
103
|
+
})), A = /* @__PURE__ */ new Map(), j = (e) => {
|
|
104
|
+
let t = e === void 0 ? void 0 : d.textures?.[e.index]?.source;
|
|
105
|
+
if (t === void 0) return;
|
|
106
|
+
let n = d.images?.[t];
|
|
107
|
+
if (!n?.uri) throw TypeError("libraryParts reads images by uri; export the model as glTF separate");
|
|
108
|
+
return A.has(t) || A.set(t, p(n.uri).then((e) => k(e, n.mimeType ?? (n.uri.endsWith(".png") ? "image/png" : "image/jpeg")))), A.get(t);
|
|
109
|
+
}, M = [];
|
|
110
|
+
for (let [e, t] of g) {
|
|
111
|
+
let n = t.indices.length / 3;
|
|
112
|
+
if (n > D) throw RangeError(`libraryParts: ${o} has ${n} triangles in one part, over maxTriangles ${D}; export a lighter level of it`);
|
|
113
|
+
let r = d.materials?.[e] ?? {}, i = r.pbrMetallicRoughness ?? {}, a = r.name ?? `material ${e}`, c = new Float32Array(t.positions.length);
|
|
114
|
+
for (let e = 0; e < c.length; e += 3) c[e] = (t.positions[e] - T) * w, c[e + 1] = (t.positions[e + 1] - y) * w, c[e + 2] = (t.positions[e + 2] - E) * w;
|
|
115
|
+
let l = i.baseColorTexture?.extensions?.KHR_texture_transform, [u, f] = l?.offset ?? [0, 0], [p, m] = l?.scale ?? [1, 1], h = Math.cos(l?.rotation ?? 0), g = Math.sin(l?.rotation ?? 0), _ = new Float32Array(t.uvs.length);
|
|
116
|
+
for (let e = 0; e < _.length; e += 2) {
|
|
117
|
+
let n = t.uvs[e] * p, r = t.uvs[e + 1] * m;
|
|
118
|
+
_[e] = h * n + g * r + u, _[e + 1] = -g * n + h * r + f;
|
|
119
|
+
}
|
|
120
|
+
let v = r.alphaMode === "MASK" || r.alphaMode === "BLEND", b = i.baseColorFactor ?? [
|
|
121
|
+
1,
|
|
122
|
+
1,
|
|
123
|
+
1,
|
|
124
|
+
1
|
|
125
|
+
], [x, S, C] = [
|
|
126
|
+
j(i.baseColorTexture),
|
|
127
|
+
j(r.normalTexture),
|
|
128
|
+
j(i.metallicRoughnessTexture)
|
|
129
|
+
];
|
|
130
|
+
M.push(Promise.all([
|
|
131
|
+
x,
|
|
132
|
+
S,
|
|
133
|
+
C
|
|
134
|
+
]).then(([e, n, i]) => ({
|
|
135
|
+
geometry: {
|
|
136
|
+
positions: c,
|
|
137
|
+
normals: Float32Array.from(t.normals),
|
|
138
|
+
indices: Uint32Array.from(t.indices)
|
|
139
|
+
},
|
|
140
|
+
color: [
|
|
141
|
+
b[0],
|
|
142
|
+
b[1],
|
|
143
|
+
b[2]
|
|
144
|
+
],
|
|
145
|
+
kind: v || O(a) ? "foliage" : s.kind ?? "bark",
|
|
146
|
+
name: a,
|
|
147
|
+
textures: {
|
|
148
|
+
uvs: _,
|
|
149
|
+
...e ? { baseColor: e } : {},
|
|
150
|
+
...n ? { normal: n } : {},
|
|
151
|
+
...i ? { occlusionRoughnessMetal: i } : {},
|
|
152
|
+
alphaCutoff: v && e ? r.alphaCutoff ?? .5 : 0
|
|
153
|
+
}
|
|
154
|
+
})));
|
|
155
|
+
}
|
|
156
|
+
return Promise.all(M);
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/library-mesh.ts
|
|
160
|
+
function r(e) {
|
|
161
|
+
if (e.matrix) return e.matrix;
|
|
162
|
+
let [t, n, r, i] = e.rotation ?? [
|
|
163
|
+
0,
|
|
164
|
+
0,
|
|
165
|
+
0,
|
|
166
|
+
1
|
|
167
|
+
], [a, o, s] = e.scale ?? [
|
|
168
|
+
1,
|
|
169
|
+
1,
|
|
170
|
+
1
|
|
171
|
+
], [c, l, u] = e.translation ?? [
|
|
172
|
+
0,
|
|
173
|
+
0,
|
|
174
|
+
0
|
|
175
|
+
];
|
|
176
|
+
return [
|
|
177
|
+
(1 - 2 * (n * n + r * r)) * a,
|
|
178
|
+
2 * (t * n + r * i) * a,
|
|
179
|
+
2 * (t * r - n * i) * a,
|
|
180
|
+
0,
|
|
181
|
+
2 * (t * n - r * i) * o,
|
|
182
|
+
(1 - 2 * (t * t + r * r)) * o,
|
|
183
|
+
2 * (n * r + t * i) * o,
|
|
184
|
+
0,
|
|
185
|
+
2 * (t * r + n * i) * s,
|
|
186
|
+
2 * (n * r - t * i) * s,
|
|
187
|
+
(1 - 2 * (t * t + n * n)) * s,
|
|
188
|
+
0,
|
|
189
|
+
c,
|
|
190
|
+
l,
|
|
191
|
+
u,
|
|
192
|
+
1
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
var i = (e, t) => Array.from({ length: 16 }, (n, r) => {
|
|
196
|
+
let i = Math.floor(r / 4), a = r % 4;
|
|
197
|
+
return e[a] * t[i * 4] + e[4 + a] * t[i * 4 + 1] + e[8 + a] * t[i * 4 + 2] + e[12 + a] * t[i * 4 + 3];
|
|
198
|
+
}), a = {
|
|
199
|
+
5126: [4, (e, t) => e.getFloat32(t, !0)],
|
|
200
|
+
5125: [4, (e, t) => e.getUint32(t, !0)],
|
|
201
|
+
5123: [2, (e, t) => e.getUint16(t, !0)],
|
|
202
|
+
5121: [1, (e, t) => e.getUint8(t)]
|
|
203
|
+
};
|
|
204
|
+
async function o(t, o = {}) {
|
|
205
|
+
let s = o.fetch ?? globalThis.fetch, c = o.signal ? { signal: o.signal } : {}, l = await s(t, c);
|
|
206
|
+
if (!l.ok) throw TypeError(`libraryMesh: ${t} answered ${l.status}; check the URL and that the server is up`);
|
|
207
|
+
let u = await l.json(), d = t.slice(0, t.lastIndexOf("/") + 1), f = [];
|
|
208
|
+
if (!u.meshes?.length || !u.accessors || !u.bufferViews || !u.buffers || !u.nodes) throw TypeError(`libraryMesh: ${t} holds no meshes; pass a .gltf with meshes, accessors, buffer views, buffers and nodes`);
|
|
209
|
+
if (!o.color && u.materials?.some((e) => e.pbrMetallicRoughness?.baseColorTexture)) {
|
|
210
|
+
let r = await n(t, {
|
|
211
|
+
fetch: async (e, n) => e === t ? {
|
|
212
|
+
ok: !0,
|
|
213
|
+
status: 200,
|
|
214
|
+
json: async () => u,
|
|
215
|
+
arrayBuffer: async () => /* @__PURE__ */ new ArrayBuffer(0)
|
|
216
|
+
} : s(e, n),
|
|
217
|
+
signal: o.signal,
|
|
218
|
+
scale: o.scale,
|
|
219
|
+
maxTriangles: o.maxTriangles ?? 4e4,
|
|
220
|
+
decode: o.decode,
|
|
221
|
+
kind: o.kind === "bark" ? "bark" : "stone",
|
|
222
|
+
...o.kind === "foliage" ? { foliage: () => !0 } : {}
|
|
223
|
+
});
|
|
224
|
+
if (r.length !== 1) throw e("unsupported", `libraryMesh: ${t} has ${r.length} textured materials and one part draws one; load it with libraryParts (one part per material), or pass color to draw it flat`);
|
|
225
|
+
let [i] = r;
|
|
226
|
+
return {
|
|
227
|
+
geometry: i.geometry,
|
|
228
|
+
color: i.color,
|
|
229
|
+
kind: i.kind,
|
|
230
|
+
textures: i.textures,
|
|
231
|
+
name: i.name
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
for (let e of u.buffers) {
|
|
235
|
+
if (!e.uri || e.uri.startsWith("data:")) throw TypeError("libraryMesh reads a .gltf with external buffers; export the glTF with separate .bin buffers");
|
|
236
|
+
let t = await s(d + e.uri, c);
|
|
237
|
+
if (!t.ok) throw TypeError(`libraryMesh: ${d + e.uri} answered ${t.status}; check that the buffer file sits beside the .gltf`);
|
|
238
|
+
f.push(await t.arrayBuffer());
|
|
239
|
+
}
|
|
240
|
+
let p = (e, t, n) => {
|
|
241
|
+
let r = u.accessors[e], i = r ? u.bufferViews[r.bufferView ?? -1] : void 0, o = r ? a[r.componentType] : void 0;
|
|
242
|
+
if (!r || !i) throw TypeError("libraryMesh: an accessor without a buffer view; export the glTF without sparse or empty accessors");
|
|
243
|
+
if (!o || n === (r.componentType === 5126)) throw TypeError(`libraryMesh: unsupported accessor component type ${r.componentType}; use float positions and normals and integer indices`);
|
|
244
|
+
let [s, c] = o, l = i.byteStride ?? s * t, d = new DataView(f[i.buffer], (i.byteOffset ?? 0) + (r.byteOffset ?? 0)), p = n ? new Uint32Array(r.count * t) : new Float32Array(r.count * t);
|
|
245
|
+
for (let e = 0; e < r.count; e++) for (let n = 0; n < t; n++) p[e * t + n] = c(d, e * l + n * s);
|
|
246
|
+
return p;
|
|
247
|
+
}, m = [], h = [], g = [], _ = [], v = (e, t) => {
|
|
248
|
+
let n = u.nodes[e], a = i(t, r(n));
|
|
249
|
+
if (n.mesh !== void 0) for (let e of u.meshes[n.mesh].primitives) {
|
|
250
|
+
if ((e.mode ?? 4) !== 4 || e.attributes.POSITION === void 0 || e.attributes.NORMAL === void 0) continue;
|
|
251
|
+
let t = p(e.attributes.POSITION, 3, !1), n = p(e.attributes.NORMAL, 3, !1), r = m.length / 3, i = t.length / 3;
|
|
252
|
+
for (let e = 0; e < i; e++) {
|
|
253
|
+
let r = t[e * 3], i = t[e * 3 + 1], o = t[e * 3 + 2], s = n[e * 3], c = n[e * 3 + 1], l = n[e * 3 + 2];
|
|
254
|
+
m.push(a[0] * r + a[4] * i + a[8] * o + a[12], a[1] * r + a[5] * i + a[9] * o + a[13], a[2] * r + a[6] * i + a[10] * o + a[14]);
|
|
255
|
+
let u = a[0] * s + a[4] * c + a[8] * l, d = a[1] * s + a[5] * c + a[9] * l, f = a[2] * s + a[6] * c + a[10] * l, p = Math.hypot(u, d, f) || 1;
|
|
256
|
+
h.push(u / p, d / p, f / p);
|
|
257
|
+
}
|
|
258
|
+
let o = e.indices === void 0 ? Uint32Array.from({ length: i }, (e, t) => t) : p(e.indices, 1, !0);
|
|
259
|
+
for (let e of o) g.push(r + e);
|
|
260
|
+
let s = u.materials?.[e.material ?? -1]?.pbrMetallicRoughness?.baseColorFactor;
|
|
261
|
+
s && _.push(s);
|
|
262
|
+
}
|
|
263
|
+
for (let e of n.children ?? []) v(e, a);
|
|
264
|
+
}, y = [
|
|
265
|
+
1,
|
|
266
|
+
0,
|
|
267
|
+
0,
|
|
268
|
+
0,
|
|
269
|
+
0,
|
|
270
|
+
1,
|
|
271
|
+
0,
|
|
272
|
+
0,
|
|
273
|
+
0,
|
|
274
|
+
0,
|
|
275
|
+
1,
|
|
276
|
+
0,
|
|
277
|
+
0,
|
|
278
|
+
0,
|
|
279
|
+
0,
|
|
280
|
+
1
|
|
281
|
+
], b = u.scenes?.[u.scene ?? 0]?.nodes ?? u.nodes.map((e, t) => t);
|
|
282
|
+
for (let e of b) v(e, y);
|
|
283
|
+
let x = g.length / 3, S = o.maxTriangles ?? 4e4;
|
|
284
|
+
if (!x) throw TypeError(`libraryMesh: ${t} holds no triangles with positions and normals; export triangle meshes with normals`);
|
|
285
|
+
if (x > S) throw RangeError(`libraryMesh: ${t} has ${x} triangles, over maxTriangles ${S}; export a lighter level of it`);
|
|
286
|
+
let C = Infinity, w = Infinity, T = -Infinity, E = Infinity, D = -Infinity;
|
|
287
|
+
for (let e = 0; e < m.length; e += 3) C = Math.min(C, m[e + 1]), w = Math.min(w, m[e]), T = Math.max(T, m[e]), E = Math.min(E, m[e + 2]), D = Math.max(D, m[e + 2]);
|
|
288
|
+
let O = o.scale ?? 1, k = (w + T) / 2, A = (E + D) / 2, j = new Float32Array(m.length);
|
|
289
|
+
for (let e = 0; e < m.length; e += 3) j[e] = (m[e] - k) * O, j[e + 1] = (m[e + 1] - C) * O, j[e + 2] = (m[e + 2] - A) * O;
|
|
290
|
+
let M = (e) => _.length ? _.reduce((t, n) => t + n[e], 0) / _.length : .5, N = o.color ?? [
|
|
291
|
+
M(0),
|
|
292
|
+
M(1),
|
|
293
|
+
M(2)
|
|
294
|
+
];
|
|
295
|
+
return {
|
|
296
|
+
geometry: {
|
|
297
|
+
positions: j,
|
|
298
|
+
normals: Float32Array.from(h),
|
|
299
|
+
indices: Uint32Array.from(g)
|
|
300
|
+
},
|
|
301
|
+
color: N,
|
|
302
|
+
kind: o.kind ?? "stone"
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
//#endregion
|
|
306
|
+
export { n, o as t };
|