@margoengine/terrain 0.1.0 → 1.0.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 -201
- package/NOTICE +4 -4
- package/README.md +2367 -1808
- package/dist/bed-mesh.d.ts +40 -0
- package/dist/bed-mesh.js +95 -0
- package/dist/blend.js +4 -4
- package/dist/colors.d.ts +6 -0
- package/dist/deform.d.ts +41 -10
- package/dist/deform.js +169 -87
- package/dist/displace.js +4 -4
- package/dist/elevation.d.ts +182 -0
- package/dist/elevation.js +155 -0
- package/dist/far.d.ts +66 -0
- package/dist/far.js +191 -0
- package/dist/furrows.d.ts +74 -0
- package/dist/furrows.js +157 -0
- package/dist/grid.d.ts +6 -3
- package/dist/ground-change.d.ts +1 -1
- package/dist/ground-change.js +232 -111
- package/dist/ground-contact-settings.d.ts +27 -0
- package/dist/ground-contact-settings.js +22 -0
- package/dist/ground-contact.d.ts +91 -0
- package/dist/ground-contact.js +241 -0
- package/dist/ground-model.d.ts +83 -1
- package/dist/imagery.js +4 -4
- package/dist/index.d.ts +120 -9
- package/dist/index.js +1 -1
- package/dist/layers-pbr.js +9 -9
- package/dist/overlays.js +4 -4
- package/dist/planet-complex.d.ts +31 -0
- package/dist/planet-craters.d.ts +28 -3
- package/dist/planet-rays.d.ts +37 -0
- package/dist/planet-recipes.d.ts +10 -1
- package/dist/planet-recipes.js +341 -115
- package/dist/planet.d.ts +5 -0
- package/dist/planet.js +112 -104
- package/dist/relief-lighting.d.ts +7 -0
- package/dist/relief-lighting.js +36 -23
- package/dist/rock-surface.d.ts +3 -0
- package/dist/rock-surface.js +28 -16
- package/dist/rvt.js +5 -5
- package/dist/scour.d.ts +90 -0
- package/dist/scour.js +153 -0
- package/dist/sculpt.js +4 -4
- package/dist/shader.d.ts +120 -5
- package/dist/shared/settings.d.ts +89 -89
- package/dist/{src-C6dtSaAb.js → src-Cr7Gm4n0.js} +359 -148
- package/dist/stream-window.d.ts +123 -0
- package/dist/stream.d.ts +95 -26
- package/dist/stream.js +440 -248
- package/dist/wet-ground.js +4 -4
- package/package.json +175 -148
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Geometry } from '@margoengine/core';
|
|
2
|
+
import type { Bed } from '@margoengine/math/fields';
|
|
3
|
+
/** What a {@link BedMesh} update rewrote. */
|
|
4
|
+
export interface BedPatch {
|
|
5
|
+
/** Vertices whose elevation changed. */
|
|
6
|
+
readonly changed: number;
|
|
7
|
+
/** Vertices whose position or normal was rewritten (the changed ones and their neighbours). */
|
|
8
|
+
readonly rewritten: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A mesh of a terrain bed. Build it once from the bed, then call {@link BedMesh.update} after the world steps and set
|
|
12
|
+
* the returned geometry on the mesh when it changed.
|
|
13
|
+
* ```ts
|
|
14
|
+
* const bedMesh = new BedMesh(terrain.bed);
|
|
15
|
+
* const mesh = engine.createMesh().setGeometry(bedMesh.geometry()).setMaterial(mud);
|
|
16
|
+
* // each frame, after world.step():
|
|
17
|
+
* if (bedMesh.update(terrain.bed).changed) mesh.setGeometry(bedMesh.geometry());
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class BedMesh {
|
|
21
|
+
/** Vertex positions, xyz m, in the bed's layout (element r + (rows + 1) c). */
|
|
22
|
+
readonly positions: Float32Array;
|
|
23
|
+
/** Unit vertex normals. */
|
|
24
|
+
readonly normals: Float32Array;
|
|
25
|
+
/** Triangles, the kernel's split along (r + 1, c) to (r, c + 1), counter-clockwise seen from above. */
|
|
26
|
+
readonly indices: Uint32Array;
|
|
27
|
+
/** The elevations the mesh holds, f64. */
|
|
28
|
+
readonly elevations: Float64Array;
|
|
29
|
+
private readonly shape;
|
|
30
|
+
private cached?;
|
|
31
|
+
constructor(bed: Bed);
|
|
32
|
+
/** The current geometry (a new Geometry after an update that changed something). */
|
|
33
|
+
geometry(): Geometry;
|
|
34
|
+
/**
|
|
35
|
+
* Takes the bed's current elevations and rewrites the vertices that changed and the normals around them.
|
|
36
|
+
* @throws RangeError when the bed's grid is not the one this mesh was built from.
|
|
37
|
+
*/
|
|
38
|
+
update(bed: Bed): BedPatch;
|
|
39
|
+
private normalAt;
|
|
40
|
+
}
|
package/dist/bed-mesh.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Geometry as e } from "@margoengine/core";
|
|
2
|
+
//#region src/bed-mesh.ts
|
|
3
|
+
var t = (e) => {
|
|
4
|
+
let { columns: t, rows: n, width: r, depth: i, centre: a } = e;
|
|
5
|
+
if (!Number.isInteger(t) || !Number.isInteger(n) || t < 1 || n < 1) throw RangeError("A bed mesh needs whole numbers of columns and rows from 1 up");
|
|
6
|
+
if (!(r > 0 && i > 0 && Number.isFinite(r) && Number.isFinite(i))) throw RangeError("A bed mesh needs a finite width and depth above zero, m");
|
|
7
|
+
if (!a || a.length !== 2 || !a.every(Number.isFinite)) throw RangeError("A bed mesh centre is [x, z], two finite metres");
|
|
8
|
+
let o = (t + 1) * (n + 1);
|
|
9
|
+
if (o > 11184810) throw RangeError("A bed mesh has at most 11,184,810 vertices; use fewer cells or tiles");
|
|
10
|
+
return o;
|
|
11
|
+
}, n = class {
|
|
12
|
+
constructor(e) {
|
|
13
|
+
let n = t(e);
|
|
14
|
+
if (e.elevations.length !== n) throw RangeError(`A bed of ${e.columns} by ${e.rows} cells has ${n} elevations, got ${e.elevations.length}`);
|
|
15
|
+
this.shape = {
|
|
16
|
+
columns: e.columns,
|
|
17
|
+
rows: e.rows,
|
|
18
|
+
width: e.width,
|
|
19
|
+
depth: e.depth,
|
|
20
|
+
centre: [...e.centre]
|
|
21
|
+
};
|
|
22
|
+
let { columns: r, rows: i, width: a, depth: o, centre: s } = this.shape;
|
|
23
|
+
this.positions = new Float32Array(n * 3), this.normals = new Float32Array(n * 3), this.elevations = new Float64Array(n);
|
|
24
|
+
for (let t = 0; t <= r; t++) for (let n = 0; n <= i; n++) {
|
|
25
|
+
let c = n + (i + 1) * t, l = e.elevations[c];
|
|
26
|
+
if (!Number.isFinite(l)) throw RangeError("A bed mesh needs finite elevations");
|
|
27
|
+
this.elevations[c] = l, this.positions[3 * c] = s[0] - a / 2 + a * t / r, this.positions[3 * c + 1] = l, this.positions[3 * c + 2] = s[1] - o / 2 + o * n / i;
|
|
28
|
+
}
|
|
29
|
+
this.indices = new Uint32Array(r * i * 6);
|
|
30
|
+
let c = 0;
|
|
31
|
+
for (let e = 0; e < r; e++) for (let t = 0; t < i; t++) {
|
|
32
|
+
let n = (e, t) => e + (i + 1) * t;
|
|
33
|
+
this.indices.set([
|
|
34
|
+
n(t, e),
|
|
35
|
+
n(t + 1, e),
|
|
36
|
+
n(t, e + 1),
|
|
37
|
+
n(t + 1, e + 1),
|
|
38
|
+
n(t, e + 1),
|
|
39
|
+
n(t + 1, e)
|
|
40
|
+
], c), c += 6;
|
|
41
|
+
}
|
|
42
|
+
for (let e = 0; e < n; e++) this.normalAt(e);
|
|
43
|
+
}
|
|
44
|
+
geometry() {
|
|
45
|
+
return this.cached ??= new e(this.positions, this.normals, this.indices);
|
|
46
|
+
}
|
|
47
|
+
update(e) {
|
|
48
|
+
let t = this.shape;
|
|
49
|
+
if (e.columns !== t.columns || e.rows !== t.rows || e.width !== t.width || e.depth !== t.depth || e.centre[0] !== t.centre[0] || e.centre[1] !== t.centre[1]) throw RangeError("BedMesh.update needs the bed it was built from; build a new BedMesh for another grid");
|
|
50
|
+
let n = t.rows + 1, r = e.elevations, i = /* @__PURE__ */ new Set(), a = 0;
|
|
51
|
+
for (let e = 0; e < this.elevations.length; e++) {
|
|
52
|
+
let o = r[e];
|
|
53
|
+
if (o === this.elevations[e]) continue;
|
|
54
|
+
if (!Number.isFinite(o)) throw RangeError("A bed mesh needs finite elevations");
|
|
55
|
+
this.elevations[e] = o, this.positions[3 * e + 1] = o, a++;
|
|
56
|
+
let s = e % n, c = (e - s) / n;
|
|
57
|
+
for (let e = -1; e <= 1; e++) for (let r = -1; r <= 1; r++) {
|
|
58
|
+
let a = s + r, o = c + e;
|
|
59
|
+
a >= 0 && a < n && o >= 0 && o <= t.columns && i.add(a + n * o);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (let e of i) this.normalAt(e);
|
|
63
|
+
return a && (this.cached = void 0), {
|
|
64
|
+
changed: a,
|
|
65
|
+
rewritten: i.size
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
normalAt(e) {
|
|
69
|
+
let { columns: t, rows: n } = this.shape, r = n + 1, i = e % r, a = (e - i) / r, o = this.positions, s = (e, t) => e + r * t, c = [
|
|
70
|
+
0,
|
|
71
|
+
0,
|
|
72
|
+
0
|
|
73
|
+
], l = (e, t, n) => {
|
|
74
|
+
let r = o[3 * t] - o[3 * e], i = o[3 * t + 1] - o[3 * e + 1], a = o[3 * t + 2] - o[3 * e + 2], s = o[3 * n] - o[3 * e], l = o[3 * n + 1] - o[3 * e + 1], u = o[3 * n + 2] - o[3 * e + 2];
|
|
75
|
+
c[0] += i * u - a * l, c[1] += a * s - r * u, c[2] += r * l - i * s;
|
|
76
|
+
};
|
|
77
|
+
for (let r = a - 1; r <= a; r++) for (let a = i - 1; a <= i; a++) {
|
|
78
|
+
if (r < 0 || a < 0 || r >= t || a >= n) continue;
|
|
79
|
+
let i = [
|
|
80
|
+
s(a, r),
|
|
81
|
+
s(a + 1, r),
|
|
82
|
+
s(a, r + 1)
|
|
83
|
+
], o = [
|
|
84
|
+
s(a + 1, r + 1),
|
|
85
|
+
s(a, r + 1),
|
|
86
|
+
s(a + 1, r)
|
|
87
|
+
];
|
|
88
|
+
i.includes(e) && l(i[0], i[1], i[2]), o.includes(e) && l(o[0], o[1], o[2]);
|
|
89
|
+
}
|
|
90
|
+
let u = Math.hypot(c[0], c[1], c[2]) || 1, d = c[1] < 0 ? -1 : 1;
|
|
91
|
+
this.normals[3 * e] = d * c[0] / u, this.normals[3 * e + 1] = d * c[1] / u, this.normals[3 * e + 2] = d * c[2] / u;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
export { n as BedMesh };
|
package/dist/blend.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// @margo/core-built
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
2
|
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
-
const n=(engine,version="
|
|
3
|
+
const n=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
4
|
import { n as e, t } from "./mesh-patch-BThCHCeS.js";
|
|
5
5
|
import { engineRuntime as __margoRuntime, meshRuntime as r } from "@margoengine/core/extension";
|
|
6
6
|
import { MargoError as i } from "@margoengine/math/errors";
|
|
@@ -23,12 +23,12 @@ function c(e, t) {
|
|
|
23
23
|
normal: i
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
var l = class l {coreRequirement=__margoCoreRequirement("
|
|
26
|
+
var l = class l {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
27
27
|
constructor(e, t, n = {}) {
|
|
28
28
|
if (this.terrain = e, this.virtualTexture = t, this.name = "terrain:blend:" + ++o, this.disposed = !1, this.rows = /* @__PURE__ */ new Map(), this.dirty = !0, this.capacity = 0, this.source = "", this.shader = "", this.binding = 40, this.entries = [], !e || typeof e.options != "object" || !t || typeof t.entries != "function") throw TypeError("TerrainBlend needs a Terrain and its TerrainVirtualTexture");
|
|
29
29
|
this.defaults = c(n, a);
|
|
30
30
|
}
|
|
31
|
-
static attach(e, t, r, i = {}) {__margoAssertCore(e,__margoCoreRequirement("
|
|
31
|
+
static attach(e, t, r, i = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
32
32
|
let a = new l(t, r, i);
|
|
33
33
|
return n(e).use(a), a;
|
|
34
34
|
}
|
package/dist/colors.d.ts
CHANGED
|
@@ -83,6 +83,12 @@ export interface SandSurface {
|
|
|
83
83
|
*/
|
|
84
84
|
broad?: number;
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Dry sand albedo, linear RGB: [0.5, 0.42, 0.29], luminance 0.43, inside the measured 0.35 to 0.45 of dry sand (T. R.
|
|
88
|
+
* Oke, "Boundary Layer Climates", 2nd ed., 1987, table 1.1). The {@link TerrainColorOptions.sand} default; a scene of
|
|
89
|
+
* dry sand takes it rather than a brighter guess (KB-SKY-AGXSAND1).
|
|
90
|
+
*/
|
|
91
|
+
export declare const DRY_SAND: Readonly<Vec3>;
|
|
86
92
|
/** The look fields {@link TerrainColors.setLook} changes while the scene runs, with no shader rebuild. */
|
|
87
93
|
export type TerrainLook = Pick<TerrainColorOptions, 'sand' | 'meadow' | 'stone' | 'shore' | 'meadowHeight' | 'stoneHeight' | 'stoneNormal' | 'wetHeight' | 'wetDarkening' | 'wetDryTime' | 'wetGlossTime'> & {
|
|
88
94
|
sandSurface?: SandSurface;
|
package/dist/deform.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
-
import type { EngineKernel } from '@margoengine/core';
|
|
2
|
+
import type { EngineKernel, Mesh } from '@margoengine/core';
|
|
3
3
|
import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
4
4
|
import type { Terrain, TerrainLighting } from './index.js';
|
|
5
5
|
/** Settings of {@link TerrainDeformation.attach}, fixed at attachment. Invalid values throw RangeError. */
|
|
@@ -29,6 +29,31 @@ export interface TerrainDeformationOptions {
|
|
|
29
29
|
* `floatingOrigin`. Default the camera's position.
|
|
30
30
|
*/
|
|
31
31
|
follow?: () => readonly [number, number];
|
|
32
|
+
/**
|
|
33
|
+
* Keeps every print for good: one the window leaves is pressed again when the window comes back to it, so prints
|
|
34
|
+
* laid once stay under a moving camera. Needs `fade` 0 (its default with `persist`). At most 16,384 prints and track
|
|
35
|
+
* pieces. Default false.
|
|
36
|
+
*/
|
|
37
|
+
persist?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Settings of {@link TerrainDeformation.walk}. Lengths are world units. */
|
|
40
|
+
export interface TerrainWalk {
|
|
41
|
+
/** Distance along the path from one footfall to the next, above 0. Default 0.75. */
|
|
42
|
+
step?: number;
|
|
43
|
+
/** Distance between the left and the right feet's lines, 0 or more. Default 0.08. */
|
|
44
|
+
straddle?: number;
|
|
45
|
+
/** How far each foot turns outward, radians, -1.5 to 1.5. Default 0.12 (7 degrees). */
|
|
46
|
+
toeOut?: number;
|
|
47
|
+
/** Length of a foot, above 0. Default 0.28. */
|
|
48
|
+
length?: number;
|
|
49
|
+
/** Width of a foot, above 0. Default 0.11. */
|
|
50
|
+
width?: number;
|
|
51
|
+
/** Depth, 0 to the deformation's `depth`. Default the deformation's `depth`. */
|
|
52
|
+
depth?: number;
|
|
53
|
+
/** How unevenly the walker steps (spacing, line, heading and depth), 0 to 1. Default 0.5. */
|
|
54
|
+
jitter?: number;
|
|
55
|
+
/** Seed of the unevenness, an integer. Default 1. */
|
|
56
|
+
seed?: number;
|
|
32
57
|
}
|
|
33
58
|
/** A footprint: an ellipse pressed at a point. */
|
|
34
59
|
export interface TerrainFootprint {
|
|
@@ -49,17 +74,17 @@ export interface TerrainTrack {
|
|
|
49
74
|
depth?: number;
|
|
50
75
|
}
|
|
51
76
|
/**
|
|
52
|
-
* Deformable ground: footprints, tyre tracks and trails pressed into a terrain
|
|
53
|
-
* the camera and filling back in over `fade` seconds. Prints are
|
|
54
|
-
* print's slope as normal, darkening);
|
|
55
|
-
* `TerrainDeformation.attach(engine,
|
|
77
|
+
* Deformable ground: footprints, walking trails, tyre tracks and trails pressed into a terrain or a ground mesh, kept
|
|
78
|
+
* in a deformation map that follows the camera and filling back in over `fade` seconds (or kept, `persist`). Prints are
|
|
79
|
+
* shown by the ground's lit shader (parallax, the print's slope as normal, darkening); its geometry, shadow and SSR
|
|
80
|
+
* capture are unchanged. `TerrainDeformation.attach(engine, ground, options)`, after the ground's other effects; on a
|
|
81
|
+
* mesh drawn by core's standard shader (as `TerrainColors` draws one) the prints go over its colours. WebGPU only.
|
|
56
82
|
* @throws RangeError from the constructor when an option is out of range, and from a print with a bad size.
|
|
57
83
|
* @throws MargoError `'unsupported'` on a WebGL engine or a map larger than the device allows, `'disposed'` after
|
|
58
84
|
* `dispose()`.
|
|
59
85
|
*/
|
|
60
86
|
export declare class TerrainDeformation implements EnginePlugin, TerrainLighting {
|
|
61
87
|
#private;
|
|
62
|
-
private readonly terrain;
|
|
63
88
|
readonly options: TerrainDeformationOptions;
|
|
64
89
|
readonly name: string;
|
|
65
90
|
disposed: boolean;
|
|
@@ -70,16 +95,22 @@ export declare class TerrainDeformation implements EnginePlugin, TerrainLighting
|
|
|
70
95
|
readonly texel: number;
|
|
71
96
|
/** Deepest a print goes. */
|
|
72
97
|
readonly depth: number;
|
|
73
|
-
constructor(
|
|
74
|
-
/** Attaches deformation to
|
|
75
|
-
static attach(engine: EngineKernel,
|
|
98
|
+
constructor(ground: Terrain | Mesh, options?: TerrainDeformationOptions);
|
|
99
|
+
/** Attaches deformation to a terrain or a ground mesh, after its other effects. `dispose()` removes it. */
|
|
100
|
+
static attach(engine: EngineKernel, ground: Terrain | Mesh, options?: TerrainDeformationOptions): TerrainDeformation;
|
|
76
101
|
/** Presses a footprint centred at world (x, z). Returns this. */
|
|
77
102
|
footprint(x: number, z: number, print?: TerrainFootprint): this;
|
|
78
103
|
/** Presses a track of `width` from world (x, z) `from` to `to` (rounded ends). Returns this. */
|
|
79
104
|
track(from: readonly [number, number], to: readonly [number, number], track?: TerrainTrack): this;
|
|
80
105
|
/** Presses a track through each world (x, z) point in turn (a trail). Returns this. */
|
|
81
106
|
trail(points: readonly (readonly [number, number])[], track?: TerrainTrack): this;
|
|
82
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Footprints of someone walking through each world (x, z) point in turn: left and right feet in turn, a heel and a
|
|
109
|
+
* forefoot each, toes turned out, unevenly spaced. Returns this.
|
|
110
|
+
* @throws RangeError for fewer than two points or a setting out of range.
|
|
111
|
+
*/
|
|
112
|
+
walk(points: readonly (readonly [number, number])[], walk?: TerrainWalk): this;
|
|
113
|
+
/** Smooths every print away at the next frame, kept ones too. Returns this. */
|
|
83
114
|
clear(): this;
|
|
84
115
|
/**
|
|
85
116
|
* The relief the terrain's shader reads, while attached: an `rgba16float` texture of `size` texels a side holding
|