@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,362 @@
1
+ import { t as e } from "./timber-valley-info-BB6GvcsL.js";
2
+ import { applyLookFamily as t } from "./look-family.js";
3
+ import { applySkySettings as n } from "@margoengine/sky/settings";
4
+ import { WEATHER_LOOKS as r, WEATHER_SETTINGS as i, applyWeatherSettings as a } from "@margoengine/weather/settings";
5
+ import { applyFireSettings as o } from "@margoengine/vfx/settings";
6
+ import { PresetScene as s, sunScene as c } from "@margoengine/sky/scenes";
7
+ import { degrees as l, sunPath as u } from "@margoengine/sky/sun";
8
+ import { Shadows as d } from "@margoengine/shadows";
9
+ import { GTAO as f } from "@margoengine/post/gtao";
10
+ import { BiomeWorld as p } from "@margoengine/biomes";
11
+ import { pathExclusions as m } from "@margoengine/biomes/splines";
12
+ import { BiomeView as h } from "@margoengine/biomes/view";
13
+ import { VolumetricClouds as g } from "@margoengine/sky/volumetric-clouds";
14
+ import { WEATHER_PRESETS as _, WeatherMachine as v } from "@margoengine/weather";
15
+ import { WeatherDrive as y } from "@margoengine/weather/drive";
16
+ import { rockiesValleyWorld as b } from "@margoengine/biomes/presets";
17
+ import { createRelief as x } from "@margoengine/biomes/relief";
18
+ import "@margoengine/biomes/valley";
19
+ import { fuelMap as S } from "@margoengine/biomes/fuel";
20
+ import { layoutSettlements as C } from "@margoengine/biomes/settlements";
21
+ import { FireFront as w } from "@margoengine/vfx/fire-front";
22
+ //#region src/timber-valley.ts
23
+ var T = e, E = 4096, D = [-2048, -2048];
24
+ function O(e) {
25
+ if (typeof e != "object" || !e) throw TypeError("timber-valley: pass settings as an object.");
26
+ let { signal: t, ...n } = e, r = {
27
+ ...Object.fromEntries(Object.entries(T.settings).map(([e, t]) => [e, t.default])),
28
+ ...n
29
+ };
30
+ for (let [e, t] of Object.entries(T.settings)) {
31
+ let n = r[e];
32
+ if (t.range && !(typeof n == "number" && n >= t.range[0] && n <= t.range[1])) throw RangeError(`timber-valley: ${e} is out of range; pass ${t.range[0]} to ${t.range[1]}.`);
33
+ if (t.options && !t.options.includes(n)) throw RangeError(`timber-valley: unknown ${e}; pass ${t.options.join(" or ")}.`);
34
+ }
35
+ if (!Number.isInteger(r.houses)) throw RangeError("timber-valley: houses is not a whole number; pass 0 to 256.");
36
+ if (!Number.isInteger(r.seed) || r.seed < 0) throw RangeError("timber-valley: seed must be a whole number 0 or more.");
37
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(r.date) || Number.isNaN(Date.parse(r.date))) throw RangeError("timber-valley: date is not a date; pass YYYY-MM-DD.");
38
+ if (r.meshes !== void 0 && (typeof r.meshes != "object" || r.meshes === null)) throw TypeError("timber-valley: meshes must be an object of mesh parts by key.");
39
+ return r;
40
+ }
41
+ function k(e) {
42
+ let t = Date.parse(e + "T12:00:00Z"), n = Date.UTC(Number(e.slice(0, 4)), 0, 1, 12);
43
+ return Math.round((t - n) / 864e5) + 1;
44
+ }
45
+ function A(e, t) {
46
+ let n = (t + 180) * Math.PI / 180, i = Math.atan2(Math.sin(n), -Math.cos(n)), a = e === "calm" ? {
47
+ wind: 2,
48
+ gust: .15,
49
+ cloud: .2,
50
+ humidity: .35,
51
+ temperature: 27
52
+ } : e === "redFlag" ? (({ storm: e, ...t }) => t)(r.redFlag) : e === "blowup" ? {
53
+ wind: 20,
54
+ gust: .8,
55
+ humidity: .12,
56
+ temperature: 30,
57
+ cloud: .15
58
+ } : {
59
+ wind: 6,
60
+ gust: .3,
61
+ smoke: .6,
62
+ cloud: .3,
63
+ humidity: .3,
64
+ temperature: 22
65
+ };
66
+ return {
67
+ ..._.clear,
68
+ ...a,
69
+ windDirection: i
70
+ };
71
+ }
72
+ function j(e, t = {}) {
73
+ let n = O(t), r = x({
74
+ seed: n.seed,
75
+ origin: D,
76
+ size: [E, E],
77
+ ...b.relief
78
+ }).mountainValley, i = (e) => {
79
+ let t = [];
80
+ if (e) for (let n = 0; n + 1 < e.length; n += 2) t.push([e[n] / 1e3, e[n + 1] / 1e3]);
81
+ return t;
82
+ }, a = i(r.axis), o = i(r.rail), s = i(r.creek), c = (e) => a[Math.min(a.length - 1, Math.round(e / 16))], l = (e) => o[Math.min(o.length - 1, Math.round(e / 16))] ?? c(e), u = (e) => {
83
+ let t = c(e), n = l(e), r = n[0] - t[0], i = n[1] - t[1], a = Math.hypot(r, i) || 1;
84
+ return [Math.round(n[0] + r / a * 40), Math.round(n[1] + i / a * 40)];
85
+ }, d = (e) => {
86
+ let t = c(e - 64), n = c(e + 64), r = Math.hypot(n[0] - t[0], n[1] - t[1]) || 1;
87
+ return [(n[0] - t[0]) / r, (n[1] - t[1]) / r];
88
+ }, f = {
89
+ points: o,
90
+ width: 10,
91
+ edge: 2
92
+ }, p = {
93
+ points: s,
94
+ width: 14,
95
+ edge: 2
96
+ }, h = n.houses > 0 ? C(e, {
97
+ seed: n.seed,
98
+ sites: [u(700), u(2600)],
99
+ villages: 2,
100
+ spacing: 400,
101
+ houses: Math.ceil(n.houses / 2),
102
+ pattern: "grid",
103
+ grid: {
104
+ toward: d(700),
105
+ block: [64, 32],
106
+ lot: 12,
107
+ street: 10
108
+ },
109
+ siteGrade: .2,
110
+ avoid: m([f, p])
111
+ }) : {
112
+ villages: [],
113
+ roads: [],
114
+ lanes: [],
115
+ paths: [],
116
+ exclusions: []
117
+ }, g = h.villages.flatMap((e) => e.houses.map((e) => ({
118
+ at: [e.centre[0], e.centre[1]],
119
+ radius: Math.max(e.size[0], e.size[1]) / 2
120
+ }))), _ = c(250), v = [{
121
+ at: [_[0] + 60, _[1] + 380],
122
+ time: 0
123
+ }];
124
+ return {
125
+ creek: s,
126
+ rail: o,
127
+ axis: a,
128
+ town: {
129
+ ...h,
130
+ exclusions: [...h.exclusions, ...m([f, p])]
131
+ },
132
+ structures: g,
133
+ ignitions: v
134
+ };
135
+ }
136
+ async function M(e = {}) {
137
+ let t = O(e);
138
+ return p.create({
139
+ seed: t.seed,
140
+ origin: D,
141
+ size: [E, E],
142
+ climate: b.climate,
143
+ height: { relief: b.relief },
144
+ biomes: b.biomes,
145
+ ...e.signal ? { signal: e.signal } : {}
146
+ });
147
+ }
148
+ async function N(e, r = {}) {
149
+ let i = O(r), p = i.quality === "film", m = [], _ = (e) => {
150
+ for (let e of m.reverse()) e();
151
+ throw e;
152
+ }, b = await M(r);
153
+ m.push(() => b.dispose());
154
+ try {
155
+ let _ = j(b, i), x = (e, t) => b.heightAt(e, t), C = u({
156
+ latitude: l(i.latitude),
157
+ dayOfYear: k(i.date),
158
+ hour: i.hour
159
+ }), O = s.attach(e, {
160
+ ...c(C.azimuth.degrees, C.elevation.degrees),
161
+ fog: 3.912 / 4e4
162
+ });
163
+ if (O.sky.options.night) {
164
+ let { moonPosition: e } = await import("@margoengine/sky/astro"), t = Date.parse(i.date + "T00:00:00Z") + (i.hour - i.longitude / 15) * 36e5, n = e(new Date(t), {
165
+ latitude: l(i.latitude),
166
+ longitude: l(i.longitude)
167
+ });
168
+ O.sky.options.night = {
169
+ moonDirection: [...n.direction],
170
+ moonPhase: Math.max(-1, Math.min(1, 2 * n.illumination - 1)),
171
+ moonLitBySun: !0
172
+ };
173
+ }
174
+ m.push(() => O.dispose());
175
+ let M = new f({
176
+ radius: 2,
177
+ slices: p ? 3 : 2,
178
+ steps: p ? 8 : 6
179
+ });
180
+ O.post.addEffect(M, 0);
181
+ let N = d.attach(e, {
182
+ resolution: p ? 4096 : 2048,
183
+ distance: 900,
184
+ lambda: .8,
185
+ lightSize: .02,
186
+ normalBias: .2,
187
+ casterMargin: 300
188
+ });
189
+ m.push(() => N.dispose());
190
+ let L = await h.attach(e, b, {
191
+ sky: O.sky,
192
+ shadows: N,
193
+ water: { rivers: "auto" },
194
+ exclusions: _.town.exclusions,
195
+ radius: p ? 2e3 : 1e3,
196
+ ...i.meshes ? { meshes: i.meshes } : {},
197
+ ...r.signal ? { signal: r.signal } : {}
198
+ });
199
+ m.push(() => L.dispose());
200
+ let R = g.attach(e, {
201
+ sky: O.sky,
202
+ type: "cumulus",
203
+ coverage: .2
204
+ });
205
+ m.push(() => R.dispose());
206
+ let z = S(b, {
207
+ step: p ? 8 : 16,
208
+ bare: _.town.exclusions
209
+ }), B = new v(A(i.weather, i.windFrom), { seed: i.seed });
210
+ m.push(() => B.dispose());
211
+ let V;
212
+ i.fire !== "none" && (V = w.attach(e, {
213
+ ground: x,
214
+ size: [E, E],
215
+ origin: D,
216
+ cell: p ? 4 : 8,
217
+ fuel: (e, t) => z.at(e, t),
218
+ structures: _.structures,
219
+ ignitions: _.ignitions,
220
+ seed: i.seed,
221
+ columns: p ? 12 : 6,
222
+ flames: p ? 24 : 12
223
+ }), m.push(() => V?.dispose()));
224
+ let H = y.attach(e, {
225
+ weather: B,
226
+ listener: e.camera,
227
+ clouds: R,
228
+ ...V ? { fires: V } : {}
229
+ });
230
+ m.push(() => H.dispose?.()), V && (P(H, V, i.fireTime), i.fire === "burnt" && await V.settle(86400, r.signal));
231
+ let U = (e) => t(e, {
232
+ sky: {
233
+ sky: O.sky,
234
+ clouds: R,
235
+ tonemap: O.tonemap
236
+ },
237
+ ...V ? {
238
+ fire: V,
239
+ smoke: V
240
+ } : {}
241
+ });
242
+ U(i.look);
243
+ let W = I(_, x), G = {};
244
+ for (let e of T.shots ?? []) {
245
+ let t = W[e.camera[0]], n = W[e.camera[e.camera.length - 1]];
246
+ G[e.name] = [{
247
+ type: "camera",
248
+ id: "camera",
249
+ path: "linear",
250
+ keys: [{
251
+ time: 0,
252
+ position: [...t.position],
253
+ target: [...t.target],
254
+ fov: 45
255
+ }, {
256
+ time: e.seconds,
257
+ position: [...n.position],
258
+ target: [...n.target],
259
+ fov: 45,
260
+ ease: "smoothstep"
261
+ }]
262
+ }];
263
+ }
264
+ return {
265
+ settings: i,
266
+ height: x,
267
+ anchors: W,
268
+ views: T.views,
269
+ view(t, n = 50) {
270
+ let r = W[t];
271
+ if (!r) throw RangeError(`timber-valley: no anchor ${t}; pass one of ${Object.keys(W).join(", ")}.`);
272
+ e.camera.position = [...r.position], e.camera.target = [...r.target], e.camera.fov = n;
273
+ },
274
+ shots: T.shots ?? [],
275
+ tracks: G,
276
+ targets: T.targets ?? {},
277
+ layout: _,
278
+ applyLook: U,
279
+ applySettings(e) {
280
+ for (let [t, r] of Object.entries(e)) if (t === "weather") a(B, {
281
+ ...F(B),
282
+ ...r
283
+ });
284
+ else if (t === "sky") n({
285
+ sky: O.sky,
286
+ clouds: R,
287
+ tonemap: O.tonemap
288
+ }, r);
289
+ else if (t === "fire") V && o(V, r);
290
+ else throw RangeError(`timber-valley: no settings target ${t}; pass weather, sky or fire.`);
291
+ },
292
+ advanceTime(e) {
293
+ H.advanceTime(e), O.sky.advanceTime?.(e), V?.advanceTime(e);
294
+ },
295
+ settle: () => L.whenIdle(),
296
+ parts: {
297
+ world: b,
298
+ view: L,
299
+ preset: O,
300
+ clouds: R,
301
+ weather: B,
302
+ drive: H,
303
+ shadows: N,
304
+ occlusion: M,
305
+ fuel: z,
306
+ fireFront: V
307
+ },
308
+ dispose() {
309
+ for (let e of m.reverse()) e();
310
+ m.length = 0;
311
+ },
312
+ [Symbol.dispose]() {
313
+ this.dispose();
314
+ }
315
+ };
316
+ } catch (e) {
317
+ return _(e);
318
+ }
319
+ }
320
+ function P(e, t, n) {
321
+ e.update(0);
322
+ for (let r = 0; r < n; r += 10) {
323
+ let i = Math.min(10, n - r);
324
+ e.advanceTime(i), t.advanceTime(i);
325
+ }
326
+ }
327
+ function F(e) {
328
+ let t = e.state, n = {};
329
+ for (let e of i) e.name in t && (n[e.name] = t[e.name]);
330
+ return n;
331
+ }
332
+ function I(e, t) {
333
+ let n = (t) => e.axis[Math.max(0, Math.min(e.axis.length - 1, Math.round(t / 16)))], r = (t) => e.rail[Math.max(0, Math.min(e.rail.length - 1, Math.round(t / 16)))] ?? n(t), i = (t) => e.creek[Math.max(0, Math.min(e.creek.length - 1, Math.round(t / 16)))], a = (e, n, r = 0, i = 0) => [
334
+ e[0] + r,
335
+ Math.max(t(e[0] + r, e[1] + i), 0) + n,
336
+ e[1] + i
337
+ ], o = e.ignitions[0].at, s = e.structures[0]?.at ?? r(700), c = (e, t, n) => ({
338
+ position: e,
339
+ target: t,
340
+ about: n
341
+ });
342
+ return {
343
+ "aerial-west": c(a(n(0), 260), a(n(1400), 60), "high over the valley mouth, looking up the valley"),
344
+ "aerial-east": c(a(n(900), 220), a(n(2400), 40), "over the town, looking up the valley"),
345
+ town: c(a(s, 1.7, -40, 0), a(s, 2, 60, 0), "eye level by the town lots, looking up the street"),
346
+ "town-up": c(a(s, 1.7, 40, 0), a(s, 30, 160, 300), "the lots, turning toward the south ridge"),
347
+ rail: c(a(r(400), 1.2), a(r(800), 1.5), "on the rail grade, looking up the line"),
348
+ "rail-far": c(a(r(600), 1.2), a(r(1e3), 1.5), "up the rail grade"),
349
+ creek: c(a(i(1200), 1, 0, 6), a(i(1500), .5), "on the creek bank"),
350
+ "creek-up": c(a(i(1300), 1, 0, 6), a(i(1600), .5), "up the creek"),
351
+ ridge: c(a(n(1200), 600, 0, -900), a(n(900), 300, 0, 900), "the north ridge, across the valley to the south wall"),
352
+ "ridge-pan": c(a(n(1300), 600, 0, -900), a(n(500), 300, 0, 600), "the north ridge, panning toward the fire"),
353
+ "fire-line": c(a(o, 80, 500, -200), a(o, 40, 0, -100), "side on to the front on the south wall"),
354
+ "fire-line-near": c(a(o, 60, 400, -100), a(o, 40, 0, -150), "closer on the front"),
355
+ blowup: c(a(s, 3, 120, -40), a(o, 200, 0, -200), "from the valley floor by the town toward the fire"),
356
+ "blowup-push": c(a(s, 3, 40, -20), a(o, 250, 0, -250), "pushing in toward the fire"),
357
+ aftermath: c(a(n(500), 40), a(n(500), 250, 0, 700), "the burned south wall from the floor"),
358
+ "aftermath-crane": c(a(n(500), 260), a(n(700), 120, 0, 700), "craned up over the burned walls")
359
+ };
360
+ }
361
+ //#endregion
362
+ export { N as attach, O as check, T as info, j as layout, P as rollFire, A as weatherState, M as world };
package/package.json CHANGED
@@ -1,6 +1,104 @@
1
- {
2
- "name": "@margoengine/scenes",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@margoengine/scenes",
3
+ "version": "0.1.0",
4
+ "description": "Ready places built from the engine's packages in one call: a catalogue of scenes, each with documented settings, presets, anchors and camera views.",
5
+ "keywords": [
6
+ "margoengine",
7
+ "webgpu",
8
+ "3d",
9
+ "scenes",
10
+ "environment",
11
+ "landscape"
12
+ ],
13
+ "homepage": "https://margoengine.com",
14
+ "bugs": {
15
+ "url": "https://github.com/scottcampbelldata/margoengine/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/scottcampbelldata/margoengine.git",
20
+ "directory": "packages/scenes"
21
+ },
22
+ "license": "Apache-2.0",
23
+ "author": "Scott Campbell",
24
+ "type": "module",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "node ../../scripts/build-optional.js scenes",
30
+ "test": "npm run build && node --test test/*.test.js",
31
+ "prepack": "npm --prefix ../.. run build:packages",
32
+ "test:gpu": "cd ../.. && node packages/scenes/test/dune-coast-still.mjs && node packages/scenes/test/timber-valley-still.mjs && node scripts/run-with-timeout.mjs 600 -- node packages/scenes/test/look-family-gpu.mjs"
33
+ },
34
+ "sideEffects": false,
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js"
39
+ },
40
+ "./look-family": {
41
+ "types": "./dist/look-family.d.ts",
42
+ "import": "./dist/look-family.js"
43
+ },
44
+ "./dune-coast": {
45
+ "types": "./dist/dune-coast.d.ts",
46
+ "import": "./dist/dune-coast.js"
47
+ },
48
+ "./fauld-countryside": {
49
+ "types": "./dist/fauld-countryside.d.ts",
50
+ "import": "./dist/fauld-countryside.js"
51
+ },
52
+ "./fauld-blast": {
53
+ "types": "./dist/fauld-blast.d.ts",
54
+ "import": "./dist/fauld-blast.js"
55
+ },
56
+ "./fauld-crater": {
57
+ "types": "./dist/fauld-crater.d.ts",
58
+ "import": "./dist/fauld-crater.js"
59
+ },
60
+ "./timber-valley": {
61
+ "types": "./dist/timber-valley.d.ts",
62
+ "import": "./dist/timber-valley.js"
63
+ },
64
+ "./fauld-tunnels": {
65
+ "types": "./dist/fauld-tunnels.d.ts",
66
+ "import": "./dist/fauld-tunnels.js"
67
+ },
68
+ "./library": {
69
+ "types": "./dist/library.d.ts",
70
+ "import": "./dist/library.js"
71
+ },
72
+ "./shot-settings": {
73
+ "types": "./dist/shot-settings.d.ts",
74
+ "import": "./dist/shot-settings.js"
75
+ }
76
+ },
77
+ "files": [
78
+ "dist",
79
+ "LICENSE",
80
+ "NOTICE"
81
+ ],
82
+ "peerDependencies": {
83
+ "@margoengine/core": "^0.1.0"
84
+ },
85
+ "dependencies": {
86
+ "@margoengine/biomes": "^0.1.0",
87
+ "@margoengine/clustered": "^0.1.0",
88
+ "@margoengine/dof": "^0.1.0",
89
+ "@margoengine/environment": "^0.1.0",
90
+ "@margoengine/geometry": "^0.1.0",
91
+ "@margoengine/gltf": "^0.1.0",
92
+ "@margoengine/materials": "^0.1.0",
93
+ "@margoengine/post": "^0.1.0",
94
+ "@margoengine/procedural": "^0.1.0",
95
+ "@margoengine/scatter": "^0.1.0",
96
+ "@margoengine/shadows": "^0.1.0",
97
+ "@margoengine/sky": "^0.1.0",
98
+ "@margoengine/terrain": "^0.1.0",
99
+ "@margoengine/tonemap": "^0.1.0",
100
+ "@margoengine/vfx": "^0.1.0",
101
+ "@margoengine/water": "^0.1.0",
102
+ "@margoengine/weather": "^0.1.0"
103
+ }
104
+ }