@margoengine/terrain 0.0.0-stage → 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 -0
- package/NOTICE +4 -0
- package/README.md +2366 -2
- package/dist/bed-mesh.d.ts +40 -0
- package/dist/bed-mesh.js +95 -0
- package/dist/blend.d.ts +70 -0
- package/dist/blend.js +159 -0
- package/dist/colors.d.ts +170 -0
- package/dist/deform.d.ts +134 -0
- package/dist/deform.js +404 -0
- package/dist/displace.d.ts +60 -0
- package/dist/displace.js +254 -0
- package/dist/dunes.d.ts +86 -0
- package/dist/dunes.js +88 -0
- package/dist/elevation.d.ts +182 -0
- package/dist/elevation.js +155 -0
- package/dist/errors-fc4i1pSL.js +7 -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 +14 -0
- package/dist/ground-change-settings.d.ts +29 -0
- package/dist/ground-change-settings.js +69 -0
- package/dist/ground-change.d.ts +227 -0
- package/dist/ground-change.js +1412 -0
- 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 +372 -0
- package/dist/hdr-format-DRhzGS7G.js +30 -0
- package/dist/height-grid.d.ts +65 -0
- package/dist/height-grid.js +74 -0
- package/dist/heightfield.d.ts +38 -0
- package/dist/holes.d.ts +37 -0
- package/dist/holes.js +97 -0
- package/dist/imagery.d.ts +109 -0
- package/dist/imagery.js +472 -0
- package/dist/index.d.ts +408 -0
- package/dist/index.js +1 -0
- package/dist/layers-pbr.d.ts +78 -0
- package/dist/layers-pbr.js +128 -0
- package/dist/lighting-layout-CaDtDa5G.js +34 -0
- package/dist/lighting-layout.d.ts +5 -0
- package/dist/mesh-patch-BThCHCeS.js +21 -0
- package/dist/mesh-patch.d.ts +14 -0
- package/dist/noise3-sQdnbz4B.js +11 -0
- package/dist/noise3.d.ts +3 -0
- package/dist/overlays.d.ts +74 -0
- package/dist/overlays.js +297 -0
- package/dist/planet-complex.d.ts +31 -0
- package/dist/planet-craters.d.ts +80 -0
- package/dist/planet-rays.d.ts +37 -0
- package/dist/planet-recipes.d.ts +84 -0
- package/dist/planet-recipes.js +442 -0
- package/dist/planet.d.ts +144 -0
- package/dist/planet.js +610 -0
- package/dist/query.d.ts +150 -0
- package/dist/query.js +243 -0
- package/dist/relief-lighting.d.ts +53 -0
- package/dist/relief-lighting.js +221 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/rock-settings.d.ts +39 -0
- package/dist/rock-settings.js +84 -0
- package/dist/rock-surface.d.ts +114 -0
- package/dist/rock-surface.js +380 -0
- package/dist/rocks.d.ts +258 -0
- package/dist/rocks.js +488 -0
- package/dist/rvt.d.ts +136 -0
- package/dist/rvt.js +518 -0
- package/dist/scour.d.ts +90 -0
- package/dist/scour.js +153 -0
- package/dist/sculpt.d.ts +103 -0
- package/dist/sculpt.js +361 -0
- package/dist/settings-B9BSdnhD.js +72 -0
- package/dist/settings.d.ts +81 -0
- package/dist/settings.js +152 -0
- package/dist/shader.d.ts +176 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/src-Cr7Gm4n0.js +1366 -0
- package/dist/stream-window.d.ts +123 -0
- package/dist/stream.d.ts +169 -0
- package/dist/stream.js +531 -0
- package/dist/surface-height.d.ts +16 -0
- package/dist/wet-ground.d.ts +82 -0
- package/dist/wet-ground.js +147 -0
- package/package.json +173 -4
package/dist/rocks.js
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { n as e, t } from "./noise3-sQdnbz4B.js";
|
|
2
|
+
import { Geometry as n } from "@margoengine/core";
|
|
3
|
+
import { marchingCubes as r } from "@margoengine/procedural/marching-cubes";
|
|
4
|
+
//#region src/rocks.ts
|
|
5
|
+
var i = (e) => {
|
|
6
|
+
throw RangeError(`Invalid rock ${e}; see the @margoengine/terrain README, "Cliffs, overhangs and sea rocks"`);
|
|
7
|
+
}, a = (e, t, n, r, a = !1) => typeof e == "number" && (a ? e > t : e >= t) && e <= n && Number.isFinite(e) ? e : i(r), o = (e, t, n, r) => Number.isInteger(e) && e >= t && e <= n ? e : i(r), s = (e) => o(e ?? 1, 0, 4294967295, "seed") | 0, c = (e, t) => (e !== void 0 && (typeof e != "object" || !e) && i(t), e ?? {}), l = (e, t, n) => e < t ? t : e > n ? n : e, u = (e, t, n) => {
|
|
8
|
+
let r = l((n - e) / (t - e), 0, 1);
|
|
9
|
+
return r * r * (3 - 2 * r);
|
|
10
|
+
}, d = (e, n, r, i) => t(e, n, r, i) * .5 + .5;
|
|
11
|
+
function f(t, n, r, i, a) {
|
|
12
|
+
let o = 0, s = .5, c = 1;
|
|
13
|
+
for (let l = 0; l < a; l++, s *= .5, c *= 2.03) o += s * e(t * c, n * c, r * c, i + l);
|
|
14
|
+
return o;
|
|
15
|
+
}
|
|
16
|
+
var p = (e, t, n) => {
|
|
17
|
+
if (n <= 0) return Math.max(e, t);
|
|
18
|
+
let r = l(.5 + .5 * (e - t) / n, 0, 1);
|
|
19
|
+
return t + (e - t) * r + n * r * (1 - r);
|
|
20
|
+
};
|
|
21
|
+
function m(e) {
|
|
22
|
+
(!e || typeof e != "object") && i("ground: pass {heights, resolution, size}");
|
|
23
|
+
let [t, n] = e.resolution ?? [], [r, s] = e.size ?? [], [c, u] = e.origin ?? [0, 0], d = e.heights;
|
|
24
|
+
o(t, 3, 8193, "ground resolution"), o(n, 3, 8193, "ground resolution"), a(r, 0, 1e7, "ground size", !0), a(s, 0, 1e7, "ground size", !0), a(c, -1e9, 1e9, "ground origin"), a(u, -1e9, 1e9, "ground origin"), (!d || typeof d.length != "number" || d.length !== t * n) && i(`ground heights: pass ${t * n} heights`);
|
|
25
|
+
for (let e = 0; e < d.length; e++) Number.isFinite(d[e]) || i("ground heights: every height must be finite");
|
|
26
|
+
let f = r / (t - 1), p = s / (n - 1), m = (e, r) => d[l(r, 0, n - 1) * t + l(e, 0, t - 1)];
|
|
27
|
+
return {
|
|
28
|
+
nx: t,
|
|
29
|
+
nz: n,
|
|
30
|
+
ox: c,
|
|
31
|
+
oz: u,
|
|
32
|
+
dx: f,
|
|
33
|
+
dz: p,
|
|
34
|
+
at: m,
|
|
35
|
+
height(e, r) {
|
|
36
|
+
let i = l((e - c) / f, 0, t - 1), a = l((r - u) / p, 0, n - 1), o = Math.min(Math.floor(i), t - 2), s = Math.min(Math.floor(a), n - 2), d = i - o, h = a - s;
|
|
37
|
+
return (m(o, s) * (1 - d) + m(o + 1, s) * d) * (1 - h) + (m(o, s + 1) * (1 - d) + m(o + 1, s + 1) * d) * h;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function h(e, t, n, r) {
|
|
42
|
+
let i = e.length, a = 2 * t + 1, o = i + 2 * t, s = new Float32Array(o), c = new Float32Array(o), u = new Float32Array(o);
|
|
43
|
+
for (let n = 0; n < o; n++) s[n] = e[l(n - t, 0, i - 1)];
|
|
44
|
+
for (let e = 0; e < o; e++) c[e] = e % a === 0 ? s[e] : n ? Math.max(c[e - 1], s[e]) : Math.min(c[e - 1], s[e]);
|
|
45
|
+
for (let e = o - 1; e >= 0; e--) u[e] = e % a === a - 1 || e === o - 1 ? s[e] : n ? Math.max(u[e + 1], s[e]) : Math.min(u[e + 1], s[e]);
|
|
46
|
+
for (let e = 0; e < i; e++) r[e] = n ? Math.max(u[e], c[e + 2 * t]) : Math.min(u[e], c[e + 2 * t]);
|
|
47
|
+
}
|
|
48
|
+
function g(e, t, n) {
|
|
49
|
+
let r = m(e), { nx: i, nz: a } = r;
|
|
50
|
+
o(t, 0, 1 << 20, "relief radius"), o(n, 0, 1 << 20, "relief radius");
|
|
51
|
+
let s = new Float32Array(i * a), c = new Float32Array(i * a), l = new Float32Array(i), u = new Float32Array(i), d = new Float32Array(i);
|
|
52
|
+
for (let e = 0; e < a; e++) {
|
|
53
|
+
for (let t = 0; t < i; t++) l[t] = r.at(t, e);
|
|
54
|
+
h(l, t, !0, u), h(l, t, !1, d), s.set(u, e * i), c.set(d, e * i);
|
|
55
|
+
}
|
|
56
|
+
let f = new Float32Array(a), p = new Float32Array(a), g = new Float32Array(i * a);
|
|
57
|
+
for (let e = 0; e < i; e++) {
|
|
58
|
+
for (let t = 0; t < a; t++) f[t] = s[t * i + e];
|
|
59
|
+
h(f, n, !0, p);
|
|
60
|
+
for (let t = 0; t < a; t++) g[t * i + e] = p[t];
|
|
61
|
+
for (let t = 0; t < a; t++) f[t] = c[t * i + e];
|
|
62
|
+
h(f, n, !1, p);
|
|
63
|
+
for (let t = 0; t < a; t++) g[t * i + e] -= p[t];
|
|
64
|
+
}
|
|
65
|
+
return g;
|
|
66
|
+
}
|
|
67
|
+
function _(e, t, n, r, i, a) {
|
|
68
|
+
let o = /* @__PURE__ */ new Map(), s = [];
|
|
69
|
+
for (let c = 0; c < t && s.length < r; c++) {
|
|
70
|
+
let t = e[c], [r, l] = i(t), u = Math.floor(r / n), d = Math.floor(l / n), f = !1;
|
|
71
|
+
for (let e = -1; e <= 1 && !f; e++) for (let t = -1; t <= 1 && !f; t++) for (let [i, a] of o.get(u + e + "," + (d + t)) ?? []) if ((i - r) ** 2 + (a - l) ** 2 < n * n) {
|
|
72
|
+
f = !0;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (f || !a(t)) continue;
|
|
76
|
+
let p = u + "," + d;
|
|
77
|
+
(o.get(p) ?? o.set(p, []).get(p)).push([r, l]), s.push(t);
|
|
78
|
+
}
|
|
79
|
+
return s;
|
|
80
|
+
}
|
|
81
|
+
function v(e, t) {
|
|
82
|
+
let n = [];
|
|
83
|
+
for (let r = 0; r < e.length; r++) t(r) && n.push(r);
|
|
84
|
+
return n.sort((t, n) => e[n] - e[t] || t - n), [Int32Array.from(n), n.length];
|
|
85
|
+
}
|
|
86
|
+
function y(e, t = {}) {
|
|
87
|
+
let n = c(t, "site options"), r = m(e), u = s(n.seed), f = a(n.seaLevel ?? 0, -1e6, 1e6, "seaLevel"), p = a(n.cliffSlope ?? 50, 20, 85, "cliffSlope"), h = a(n.cliffRelief ?? 8, .5, 5e3, "cliffRelief"), y = a(n.reliefRadius ?? 16, 0, 1e5, "reliefRadius", !0), b = a(n.cliffWidth ?? 24, 2, 500, "cliffWidth"), x = o(n.maxCliffs ?? 64, 0, 4096, "maxCliffs"), S = o(n.seaRocks ?? 32, 0, 4096, "seaRocks"), C = n.seaRockDepth ?? [1, 15], w = a(n.shoreDistance ?? 80, 0, 1e6, "shoreDistance", !0), T = a(n.seaRockSpacing ?? 14, 0, 1e5, "seaRockSpacing", !0), E = o(n.boulders ?? 3, 0, 64, "boulders");
|
|
88
|
+
(!Array.isArray(C) || C.length !== 2) && i("seaRockDepth: pass [shallowest, deepest]");
|
|
89
|
+
let [D, O] = [a(C[0], 0, 1e3, "seaRockDepth"), a(C[1], 0, 1e3, "seaRockDepth")];
|
|
90
|
+
D > O && i("seaRockDepth: shallowest above deepest");
|
|
91
|
+
let { nx: k, nz: A, dx: j, dz: M, ox: N, oz: P } = r, F = k * A, I = new Float32Array(F), L = new Float32Array(F), R = new Float32Array(F);
|
|
92
|
+
for (let e = 0; e < A; e++) for (let t = 0; t < k; t++) {
|
|
93
|
+
let n = r.at(t - 1, e - 1), i = r.at(t, e - 1), a = r.at(t + 1, e - 1), o = r.at(t - 1, e), s = r.at(t + 1, e), c = r.at(t - 1, e + 1), l = r.at(t, e + 1), u = r.at(t + 1, e + 1), d = e * k + t, f = (t === 0 || t === k - 1 ? 2 : 1) * (a + 2 * s + u - (n + 2 * o + c)), p = (e === 0 || e === A - 1 ? 2 : 1) * (c + 2 * l + u - (n + 2 * i + a));
|
|
94
|
+
L[d] = f / (8 * j), R[d] = p / (8 * M), I[d] = Math.atan(Math.hypot(L[d], R[d])) * 180 / Math.PI;
|
|
95
|
+
}
|
|
96
|
+
let z = g(e, Math.max(1, Math.round(y / j)), Math.max(1, Math.round(y / M))), B = (e, t, n) => {
|
|
97
|
+
let r = l((t - N) / j, 0, k - 1), i = l((n - P) / M, 0, A - 1), a = Math.min(Math.floor(r), k - 2), o = Math.min(Math.floor(i), A - 2), s = r - a, c = i - o, u = o * k + a;
|
|
98
|
+
return (e[u] * (1 - s) + e[u + 1] * s) * (1 - c) + (e[u + k] * (1 - s) + e[u + k + 1] * s) * c;
|
|
99
|
+
}, V = (e, t) => e >= N && t >= P && e <= N + j * (k - 1) && t <= P + M * (A - 1), H = (e) => [N + e % k * j, P + Math.floor(e / k) * M], U = new Float32Array(F);
|
|
100
|
+
for (let e = 0; e < F; e++) U[e] = z[e] * Math.sin(I[e] * Math.PI / 180);
|
|
101
|
+
let [ee, te] = v(U, (e) => {
|
|
102
|
+
let t = e % k, n = Math.floor(e / k), i = Math.ceil(b / 2 / j), a = Math.ceil(b / 2 / M);
|
|
103
|
+
return t >= i && n >= a && t < k - i && n < A - a && I[e] >= p && z[e] >= h && r.at(t, n) >= f - O;
|
|
104
|
+
}), W = [], G = Math.min(j, M) / 2, ne = 4 * y + 4 * Math.max(j, M), K = (e, t, n, r, i) => {
|
|
105
|
+
let a = e, o = t;
|
|
106
|
+
for (let e = 0; e < ne; e += G) {
|
|
107
|
+
let e = a + i * n * G, t = o + i * r * G;
|
|
108
|
+
if (!V(e, t) || B(I, e, t) < p * .5) break;
|
|
109
|
+
a = e, o = t;
|
|
110
|
+
}
|
|
111
|
+
return [a, o];
|
|
112
|
+
};
|
|
113
|
+
_(ee, te, b * .75, x, H, (e) => {
|
|
114
|
+
let [t, n] = H(e), i = Math.hypot(L[e], R[e]), a = -L[e] / i, o = -R[e] / i, s = K(t, n, a, o, 1), c = K(t, n, a, o, -1), l = r.height(s[0], s[1]), u = r.height(c[0], c[1]);
|
|
115
|
+
if (u - l < h * .5) return !1;
|
|
116
|
+
let d = 0, f = 1, p = (l + u) / 2;
|
|
117
|
+
for (let e = 0; e < 30; e++) {
|
|
118
|
+
let e = (d + f) / 2;
|
|
119
|
+
r.height(c[0] + (s[0] - c[0]) * e, c[1] + (s[1] - c[1]) * e) > p ? d = e : f = e;
|
|
120
|
+
}
|
|
121
|
+
let m = (d + f) / 2, g = c[0] + (s[0] - c[0]) * m, _ = c[1] + (s[1] - c[1]) * m;
|
|
122
|
+
return !W.some((e) => Math.hypot(e.position[0] - g, e.position[2] - _) < b * .75) && (W.push({
|
|
123
|
+
kind: "cliff",
|
|
124
|
+
position: [
|
|
125
|
+
g,
|
|
126
|
+
p,
|
|
127
|
+
_
|
|
128
|
+
],
|
|
129
|
+
facing: [a, o],
|
|
130
|
+
foot: s,
|
|
131
|
+
crest: c,
|
|
132
|
+
base: l,
|
|
133
|
+
top: u,
|
|
134
|
+
width: b,
|
|
135
|
+
slope: I[e],
|
|
136
|
+
relief: z[e]
|
|
137
|
+
}), !0);
|
|
138
|
+
});
|
|
139
|
+
let q = new Float32Array(F), J = Math.hypot(j, M);
|
|
140
|
+
for (let e = 0; e < F; e++) q[e] = r.at(e % k, Math.floor(e / k)) >= f ? 0 : 1e30;
|
|
141
|
+
for (let e = 0; e < A; e++) for (let t = 0; t < k; t++) {
|
|
142
|
+
let n = e * k + t, r = q[n];
|
|
143
|
+
t > 0 && (r = Math.min(r, q[n - 1] + j)), e > 0 && (r = Math.min(r, q[n - k] + M), t > 0 && (r = Math.min(r, q[n - k - 1] + J)), t < k - 1 && (r = Math.min(r, q[n - k + 1] + J))), q[n] = r;
|
|
144
|
+
}
|
|
145
|
+
for (let e = A - 1; e >= 0; e--) for (let t = k - 1; t >= 0; t--) {
|
|
146
|
+
let n = e * k + t, r = q[n];
|
|
147
|
+
t < k - 1 && (r = Math.min(r, q[n + 1] + j)), e < A - 1 && (r = Math.min(r, q[n + k] + M), t < k - 1 && (r = Math.min(r, q[n + k + 1] + J)), t > 0 && (r = Math.min(r, q[n + k - 1] + J))), q[n] = r;
|
|
148
|
+
}
|
|
149
|
+
let Y = (e, t) => {
|
|
150
|
+
let n = Infinity, r = -1;
|
|
151
|
+
for (let i = 0; i < W.length; i++) {
|
|
152
|
+
let a = Math.hypot(W[i].position[0] - e, W[i].position[2] - t);
|
|
153
|
+
a < n && ([n, r] = [a, i]);
|
|
154
|
+
}
|
|
155
|
+
return [n, r];
|
|
156
|
+
}, X = new Float32Array(F), Z = (e) => {
|
|
157
|
+
let t = f - r.at(e % k, Math.floor(e / k));
|
|
158
|
+
return t >= D && t <= O && t > 0 && q[e] <= w;
|
|
159
|
+
};
|
|
160
|
+
for (let e = 0; e < F; e++) if (Z(e)) {
|
|
161
|
+
let [t, n] = H(e), [r] = Y(t, n), i = q[e] / w;
|
|
162
|
+
X[e] = (.25 + 3 * i * (1 - i)) * (.4 + Math.min(1, I[e] / 30)) * (1 + 2 * Math.exp(-r / (2 * b))) * (.6 + .4 * d(e % k, Math.floor(e / k), 11, u));
|
|
163
|
+
}
|
|
164
|
+
let [re, ie] = v(X, Z), Q = [];
|
|
165
|
+
_(re, ie, T, S, H, (e) => {
|
|
166
|
+
let [t, n] = H(e), i = r.at(e % k, Math.floor(e / k)), [a, o] = Y(t, n), s = d(e, 1, 0, u), c = d(e, 2, 0, u), l = o >= 0 ? W[o].top : f, p = o >= 0 && a < 3 * b && l - f > 4 && s < .7;
|
|
167
|
+
return Q.push(p ? {
|
|
168
|
+
kind: "stack",
|
|
169
|
+
position: [
|
|
170
|
+
t,
|
|
171
|
+
i,
|
|
172
|
+
n
|
|
173
|
+
],
|
|
174
|
+
radius: T * (.18 + .17 * c),
|
|
175
|
+
top: f + Math.max(2.5, (.35 + .5 * s) * (l - f)),
|
|
176
|
+
seaLevel: f
|
|
177
|
+
} : {
|
|
178
|
+
kind: "skerry",
|
|
179
|
+
position: [
|
|
180
|
+
t,
|
|
181
|
+
i,
|
|
182
|
+
n
|
|
183
|
+
],
|
|
184
|
+
radius: T * (.22 + .25 * c),
|
|
185
|
+
top: f + .4 + 2.1 * s,
|
|
186
|
+
seaLevel: f
|
|
187
|
+
}), !0;
|
|
188
|
+
});
|
|
189
|
+
let $ = [];
|
|
190
|
+
return W.forEach((e, t) => {
|
|
191
|
+
let n = e.top - e.base, [i, a] = e.facing;
|
|
192
|
+
for (let o = 0; o < E; o++) {
|
|
193
|
+
let s = d(t, o, 21, u), c = d(t, o, 22, u) ** .7, f = (s - .5) * e.width, p = n * (.05 + .45 * c), m = e.foot[0] + i * p + a * f, h = e.foot[1] + a * p - i * f;
|
|
194
|
+
V(m, h) && $.push({
|
|
195
|
+
kind: "boulder",
|
|
196
|
+
position: [
|
|
197
|
+
m,
|
|
198
|
+
r.height(m, h),
|
|
199
|
+
h
|
|
200
|
+
],
|
|
201
|
+
radius: l(n * (.025 + .06 * c) * (.7 + .6 * d(t, o, 23, u)), .3, 6),
|
|
202
|
+
cliff: t
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}), {
|
|
206
|
+
cliffs: W,
|
|
207
|
+
seaRocks: Q,
|
|
208
|
+
boulders: $,
|
|
209
|
+
slope: I,
|
|
210
|
+
relief: z
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function b(e) {
|
|
214
|
+
let t = [
|
|
215
|
+
0,
|
|
216
|
+
1,
|
|
217
|
+
2
|
|
218
|
+
].map((t) => Math.max(3, Math.ceil((e.hi[t] - e.lo[t]) / e.cell) + 1)), a = [
|
|
219
|
+
0,
|
|
220
|
+
1,
|
|
221
|
+
2
|
|
222
|
+
].map((n) => (e.hi[n] - e.lo[n]) / (t[n] - 1)), o = (t, n) => e.lo[t] + a[t] * n, s = a.map((e) => e * 1.01), c = (t, n, r) => {
|
|
223
|
+
let i = Math.max(e.lo[0] + s[0] - t, t - e.hi[0] + s[0], e.lo[1] + s[1] - n, n - e.hi[1] + s[1], e.lo[2] + s[2] - r, r - e.hi[2] + s[2]);
|
|
224
|
+
return Math.max(e.sd(t, n, r), i);
|
|
225
|
+
};
|
|
226
|
+
t[0] * t[1] * t[2] > 64e6 && i("cell: the piece needs over 64 million samples; use a larger cell");
|
|
227
|
+
let l = t.map((e) => {
|
|
228
|
+
let t = [];
|
|
229
|
+
for (let n = 0; n < e - 1; n += 127) t.push([n, Math.min(e - 1, n + 127)]);
|
|
230
|
+
return t;
|
|
231
|
+
}), u = [], d = [], f = /* @__PURE__ */ new Map(), p = Math.min(...a) * 1e-4;
|
|
232
|
+
for (let [e, t] of l[0]) for (let [n, i] of l[1]) for (let [a, s] of l[2]) {
|
|
233
|
+
let l = [
|
|
234
|
+
t - e + 1,
|
|
235
|
+
i - n + 1,
|
|
236
|
+
s - a + 1
|
|
237
|
+
], m = new Float64Array(l[0] * l[1] * l[2]), h = !1, g = !1;
|
|
238
|
+
for (let t = 0, r = 0; t < l[2]; t++) for (let i = 0; i < l[1]; i++) for (let s = 0; s < l[0]; s++, r++) {
|
|
239
|
+
let l = c(o(0, e + s), o(1, n + i), o(2, a + t));
|
|
240
|
+
m[r] = l, l < 0 ? g = !0 : h = !0;
|
|
241
|
+
}
|
|
242
|
+
if (!g || !h) continue;
|
|
243
|
+
let _ = r(m, {
|
|
244
|
+
resolution: l,
|
|
245
|
+
bounds: [[
|
|
246
|
+
o(0, e),
|
|
247
|
+
o(1, n),
|
|
248
|
+
o(2, a)
|
|
249
|
+
], [
|
|
250
|
+
o(0, t),
|
|
251
|
+
o(1, i),
|
|
252
|
+
o(2, s)
|
|
253
|
+
]]
|
|
254
|
+
});
|
|
255
|
+
if (!_) continue;
|
|
256
|
+
let v = _.vertices, y = new Int32Array(v.length / 6);
|
|
257
|
+
for (let e = 0; e < y.length; e++) {
|
|
258
|
+
let t = v[e * 6], n = v[e * 6 + 1], r = v[e * 6 + 2], i = Math.round(t / p) + "," + Math.round(n / p) + "," + Math.round(r / p), a = f.get(i);
|
|
259
|
+
a === void 0 && (a = u.length / 3, f.set(i, a), u.push(t, n, r)), y[e] = a;
|
|
260
|
+
}
|
|
261
|
+
for (let e = 0; e < _.indices.length; e += 3) {
|
|
262
|
+
let t = y[_.indices[e]], n = y[_.indices[e + 1]], r = y[_.indices[e + 2]];
|
|
263
|
+
t !== n && n !== r && t !== r && d.push(t, n, r);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
d.length || i("shape: the field holds no rock; check the site and options");
|
|
267
|
+
let [m, h, g, _, v] = e.frame, y = new Float32Array(u.length), b = new Float32Array(u.length), x = Math.min(...a) * .5;
|
|
268
|
+
for (let e = 0; e < u.length; e += 3) {
|
|
269
|
+
let t = u[e], n = u[e + 1], r = u[e + 2], i = c(t + x, n, r) - c(t - x, n, r), a = c(t, n + x, r) - c(t, n - x, r), o = c(t, n, r + x) - c(t, n, r - x), s = Math.hypot(i, a, o) || 1;
|
|
270
|
+
y[e] = t * m + r * g, y[e + 1] = n - v, y[e + 2] = t * h + r * _, b[e] = (i * m + o * g) / s, b[e + 1] = a / s, b[e + 2] = (i * h + o * _) / s;
|
|
271
|
+
}
|
|
272
|
+
return new n(y, b, d);
|
|
273
|
+
}
|
|
274
|
+
function x(e) {
|
|
275
|
+
let t = c(e, "cliff options");
|
|
276
|
+
return {
|
|
277
|
+
cell: a(t.cell ?? .5, .05, 20, "cell"),
|
|
278
|
+
overhang: a(t.overhang ?? 2.5, 0, 100, "overhang"),
|
|
279
|
+
proud: a(t.proud ?? .6, 0, 20, "proud"),
|
|
280
|
+
thickness: a(t.thickness ?? 6, .5, 200, "thickness"),
|
|
281
|
+
strata: a(t.strata ?? 1.4, 0, 100, "strata"),
|
|
282
|
+
ledges: a(t.ledges ?? .5, 0, 20, "ledges"),
|
|
283
|
+
dip: a(t.dip ?? 0, -60, 60, "dip"),
|
|
284
|
+
joints: a(t.joints ?? 3, 0, 200, "joints"),
|
|
285
|
+
crackDepth: a(t.crackDepth ?? .35, 0, 20, "crackDepth"),
|
|
286
|
+
roughness: a(t.roughness ?? .35, 0, 20, "roughness"),
|
|
287
|
+
embed: a(t.embed ?? 1.5, 0, 50, "embed"),
|
|
288
|
+
seed: s(t.seed)
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
var S = (e, n) => {
|
|
292
|
+
let r = Math.floor(e), i = e - r;
|
|
293
|
+
return t(r, 7, 3, n) * u(0, .2, i) * u(1, .8, i);
|
|
294
|
+
};
|
|
295
|
+
function C(n, r, a) {
|
|
296
|
+
let o = x(a), s = m(r);
|
|
297
|
+
(!n || n.kind !== "cliff") && i("cliff site: pass one of findRockSites(...).cliffs");
|
|
298
|
+
let [c, , d] = n.position, [h, g] = n.facing, _ = g, v = -h, y = Math.max(n.top - n.base, o.cell * 4), b = n.width / 2, C = y * 1.5 + n.width + 4 * o.cell, w = n.top + .6 * o.roughness, T = [n.base - o.embed, w], E = Math.min(s.dx, s.dz) / 2, D = (e, t) => {
|
|
299
|
+
let n = (t) => s.height(c + _ * e + h * t, d + v * e + g * t), r = -C;
|
|
300
|
+
if (n(r) < t) return -C;
|
|
301
|
+
for (let e = -C + E; e <= C; e += E) {
|
|
302
|
+
if (n(e) < t) {
|
|
303
|
+
let i = r, a = e;
|
|
304
|
+
for (let e = 0; e < 12; e++) {
|
|
305
|
+
let e = (i + a) / 2;
|
|
306
|
+
n(e) >= t ? i = e : a = e;
|
|
307
|
+
}
|
|
308
|
+
return (i + a) / 2;
|
|
309
|
+
}
|
|
310
|
+
r = e;
|
|
311
|
+
}
|
|
312
|
+
return C;
|
|
313
|
+
}, O = Math.max(2, Math.ceil(2 * b / o.cell)) + 1, k = Math.max(2, Math.ceil((T[1] - T[0]) / o.cell)) + 1, A = new Float32Array(O * k), j = new Float32Array(O);
|
|
314
|
+
for (let e = 0; e < O; e++) j[e] = D(-b + 2 * b * e / (O - 1), n.base);
|
|
315
|
+
let M = Infinity, N = -Infinity;
|
|
316
|
+
for (let e = 0; e < k; e++) for (let t = 0; t < O; t++) {
|
|
317
|
+
let n = T[0] + (T[1] - T[0]) * e / (k - 1), r = Math.min(D(-b + 2 * b * t / (O - 1), n), j[t] + o.embed + o.cell);
|
|
318
|
+
A[e * O + t] = r, M = Math.min(M, r), N = Math.max(N, r);
|
|
319
|
+
}
|
|
320
|
+
let P = (e, t) => {
|
|
321
|
+
let n = l((e + b) / (2 * b) * (O - 1), 0, O - 1), r = l((t - T[0]) / (T[1] - T[0]) * (k - 1), 0, k - 1), i = Math.min(Math.floor(n), O - 2), a = Math.min(Math.floor(r), k - 2), o = n - i, s = r - a, c = a * O + i;
|
|
322
|
+
return (A[c] * (1 - o) + A[c + 1] * o) * (1 - s) + (A[c + O] * (1 - o) + A[c + O + 1] * o) * s;
|
|
323
|
+
}, F = Math.tan(o.dip * Math.PI / 180), I = o.proud + o.overhang + o.ledges + o.crackDepth + 3 * o.roughness + o.cell;
|
|
324
|
+
return {
|
|
325
|
+
sd: (r, i, a) => {
|
|
326
|
+
let s = P(r, i), m = l((i - n.base) / y, 0, 1), x = c + _ * r + h * a, C = d + v * r + g * a, w = s + o.proud + o.crackDepth + o.roughness + o.overhang * u(.58, .9, m), T = 0;
|
|
327
|
+
if (o.strata > 0 && (T = (i + r * F) / o.strata + .35 * e(x / (6 * o.strata), .5, C / (6 * o.strata), o.seed), w += o.ledges * (S(T, o.seed) + 1) * .5), o.joints > 0 && o.crackDepth > 0) {
|
|
328
|
+
let n = (r + t(Math.floor(T), 5, 1, o.seed) * o.joints + .25 * o.joints * e(x * .2, i * .1, C * .2, o.seed + 9)) / o.joints, a = Math.abs(n - Math.round(n)) * o.joints;
|
|
329
|
+
w -= o.crackDepth * (1 - u(0, Math.max(o.cell, .08 * o.joints), a));
|
|
330
|
+
}
|
|
331
|
+
w -= u(.55, 1, Math.abs(r) / b) * I;
|
|
332
|
+
let E = a - w + o.roughness * f(x / 3, i / 3, C / 3, o.seed + 17, 3) * 2;
|
|
333
|
+
return E = Math.max(E, s - o.thickness - a), E = p(E, i - (n.top - .25 + .5 * o.roughness * e(x * .15, 3.5, C * .15, o.seed + 3)), .3 * o.cell), E = Math.max(E, n.base - o.embed - i, Math.abs(r) - b), E;
|
|
334
|
+
},
|
|
335
|
+
lo: [
|
|
336
|
+
-b - o.cell,
|
|
337
|
+
T[0] - o.cell,
|
|
338
|
+
M - o.thickness - o.cell * 2
|
|
339
|
+
],
|
|
340
|
+
hi: [
|
|
341
|
+
b + o.cell,
|
|
342
|
+
T[1] + o.cell,
|
|
343
|
+
N + I + o.cell * 2
|
|
344
|
+
],
|
|
345
|
+
cell: o.cell,
|
|
346
|
+
frame: [
|
|
347
|
+
_,
|
|
348
|
+
v,
|
|
349
|
+
h,
|
|
350
|
+
g,
|
|
351
|
+
n.position[1]
|
|
352
|
+
]
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function w(e, t, n) {
|
|
356
|
+
return {
|
|
357
|
+
geometry: b(C(e, t, n)),
|
|
358
|
+
position: [...e.position],
|
|
359
|
+
site: e
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function T(e, t) {
|
|
363
|
+
let n = c(e, "sea rock options"), r = t.kind === "skerry";
|
|
364
|
+
return {
|
|
365
|
+
cell: a(n.cell ?? Math.max(.1, t.radius / 12), .05, 20, "cell"),
|
|
366
|
+
notchDepth: a(n.notchDepth ?? .6, 0, 20, "notchDepth"),
|
|
367
|
+
notchHeight: a(n.notchHeight ?? 1.2, .1, 20, "notchHeight"),
|
|
368
|
+
taper: a(n.taper ?? (r ? .5 : .25), 0, .9, "taper"),
|
|
369
|
+
strata: a(n.strata ?? .9, 0, 100, "strata"),
|
|
370
|
+
ledges: a(n.ledges ?? .25, 0, 20, "ledges"),
|
|
371
|
+
joints: o(n.joints ?? 7, 0, 64, "joints"),
|
|
372
|
+
crackDepth: a(n.crackDepth ?? .25, 0, 20, "crackDepth"),
|
|
373
|
+
lobes: a(n.lobes ?? .22, 0, 1, "lobes"),
|
|
374
|
+
roughness: a(n.roughness ?? .25, 0, 20, "roughness"),
|
|
375
|
+
embed: a(n.embed ?? 1, 0, 50, "embed"),
|
|
376
|
+
seed: s(n.seed)
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function E(n, r) {
|
|
380
|
+
(!n || n.kind !== "stack" && n.kind !== "skerry") && i("sea rock site: pass one of findRockSites(...).seaRocks");
|
|
381
|
+
let a = T(r, n), [o, s, c] = n.position, d = n.radius, m = Math.max(n.top - s, a.cell * 4), h = n.seaLevel + .1 * a.notchHeight, g = Math.min(a.notchDepth, .45 * d), _ = s - a.embed, v = n.top, y = (n, r, i) => {
|
|
382
|
+
let y = Math.hypot(n, i), b = y > 1e-9 ? n / y : 1, x = y > 1e-9 ? i / y : 0, C = l((r - s) / m, 0, 1), w = d * (1 - a.taper * C) * (1 + a.lobes * e(b * 1.6, r / (d * 1.5), x * 1.6, a.seed));
|
|
383
|
+
w -= g * Math.exp(-(((r - h) / (.5 * a.notchHeight)) ** 2));
|
|
384
|
+
let T = 0;
|
|
385
|
+
if (a.strata > 0 && (T = r / a.strata + .3 * e(b, .5, x, a.seed + 1), w += a.ledges * S(T, a.seed)), a.joints > 0 && a.crackDepth > 0) {
|
|
386
|
+
let e = (Math.atan2(i, n) / (2 * Math.PI) * a.joints + t(Math.floor(T), 4, 2, a.seed) * .5) % 1, r = Math.abs(e - Math.round(e)) * (2 * Math.PI * Math.max(y, .001) / a.joints);
|
|
387
|
+
w -= a.crackDepth * (1 - u(0, Math.max(a.cell, .06 * d), r));
|
|
388
|
+
}
|
|
389
|
+
let E = y - Math.max(w, .05 * d) + a.roughness * f((o + n) / 2, r / 2, (c + i) / 2, a.seed + 5, 3) * 2;
|
|
390
|
+
return E = p(E, r - (v + .3 * a.roughness * e(n * .4, 1.5, i * .4, a.seed + 2)), Math.min(d, m) * .25), Math.max(E, _ - r);
|
|
391
|
+
}, b = d * (1 + a.lobes) + a.ledges + 2 * a.roughness + 2 * a.cell;
|
|
392
|
+
return {
|
|
393
|
+
sd: y,
|
|
394
|
+
lo: [
|
|
395
|
+
-b,
|
|
396
|
+
_ - a.cell,
|
|
397
|
+
-b
|
|
398
|
+
],
|
|
399
|
+
hi: [
|
|
400
|
+
b,
|
|
401
|
+
v + a.roughness + 2 * a.cell,
|
|
402
|
+
b
|
|
403
|
+
],
|
|
404
|
+
cell: a.cell,
|
|
405
|
+
frame: [
|
|
406
|
+
1,
|
|
407
|
+
0,
|
|
408
|
+
0,
|
|
409
|
+
1,
|
|
410
|
+
s
|
|
411
|
+
]
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function D(e, t) {
|
|
415
|
+
return {
|
|
416
|
+
geometry: b(E(e, t)),
|
|
417
|
+
position: [...e.position],
|
|
418
|
+
site: e
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
function O(e, t) {
|
|
422
|
+
let n = c(e, "boulder options");
|
|
423
|
+
return {
|
|
424
|
+
cell: a(n.cell ?? Math.max(.04, t.radius / 10), .02, 10, "cell"),
|
|
425
|
+
facets: o(n.facets ?? 9, 4, 32, "facets"),
|
|
426
|
+
rounding: a(n.rounding ?? .18, 0, 1, "rounding"),
|
|
427
|
+
roughness: a(n.roughness ?? .06, 0, .5, "roughness"),
|
|
428
|
+
embed: a(n.embed ?? .3, 0, .9, "embed"),
|
|
429
|
+
seed: s(n.seed)
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
function k(e, n) {
|
|
433
|
+
(!e || e.kind !== "boulder") && i("boulder site: pass one of findRockSites(...).boulders");
|
|
434
|
+
let r = O(n, e), o = a(e.radius, 0, 1e4, "boulder radius", !0), s = [], c = Math.round(e.position[0] * 7) ^ Math.round(e.position[2] * 13) ^ r.seed, l = 2 * Math.PI * d(0, 1, c, 3), u = Math.cos(l), m = Math.sin(l), h = .92 + .25 * d(1, 1, c, 3), g = .63 + .35 * d(2, 1, c, 3), _ = .12 + .73 * d(3, 1, c, 3), v = .71 + .23 * d(4, 1, c, 3);
|
|
435
|
+
s.push(0, -1, 0, .84 * o, _, 1, .12 * t(3, 2, c, 3), v * o);
|
|
436
|
+
for (let e = 2; e < r.facets; e++) {
|
|
437
|
+
let n = e < 6, r = (e - 2) * (n ? Math.PI / 2 : 2.399963) + .24 * t(e, 2, c, 3), i = n ? .32 * t(e, 4, c, 3) : .39 + .5 * t(e, 4, c, 3), a = o * (.73 + .25 * d(e, 3, c, 3));
|
|
438
|
+
s.push(Math.cos(r) / h, i, Math.sin(r) / g, a);
|
|
439
|
+
}
|
|
440
|
+
let y = r.rounding * o * .25, b = (e, t, n) => {
|
|
441
|
+
let i = e * u + n * m, a = n * u - e * m, l = Math.hypot(i / h, t * .89, a / g) - o * 1.105;
|
|
442
|
+
for (let e = 0; e < s.length; e += 4) l = p(l, i * s[e] + t * s[e + 1] + a * s[e + 2] - s[e + 3], y);
|
|
443
|
+
return l + r.roughness * o * f(i / (.45 * o), t / (.34 * o), a / (.45 * o), r.seed + c, 3) * 2;
|
|
444
|
+
}, x = o * (1.105 + 1.75 * r.roughness), S = x * Math.hypot(u * h, m * g) + 2 * r.cell, C = x * Math.hypot(m * h, u * g) + 2 * r.cell, w = Math.min(x / .89, o * (.84 + 1.75 * r.roughness)) + 2 * r.cell;
|
|
445
|
+
return {
|
|
446
|
+
sd: b,
|
|
447
|
+
lo: [
|
|
448
|
+
-S,
|
|
449
|
+
-w,
|
|
450
|
+
-C
|
|
451
|
+
],
|
|
452
|
+
hi: [
|
|
453
|
+
S,
|
|
454
|
+
x / .89 + 2 * r.cell,
|
|
455
|
+
C
|
|
456
|
+
],
|
|
457
|
+
cell: r.cell,
|
|
458
|
+
frame: [
|
|
459
|
+
1,
|
|
460
|
+
0,
|
|
461
|
+
0,
|
|
462
|
+
1,
|
|
463
|
+
0
|
|
464
|
+
]
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function A(e, t) {
|
|
468
|
+
let n = O(t, e), [r, i, a] = e.position;
|
|
469
|
+
return {
|
|
470
|
+
geometry: b(k(e, t)),
|
|
471
|
+
position: [
|
|
472
|
+
r,
|
|
473
|
+
i + e.radius * (1 - n.embed) * .87,
|
|
474
|
+
a
|
|
475
|
+
],
|
|
476
|
+
site: e
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function j(e, t, n = {}) {
|
|
480
|
+
let r = c(n, "build options");
|
|
481
|
+
return (!e || !Array.isArray(e.cliffs)) && i("sites: pass the result of findRockSites"), [
|
|
482
|
+
...e.cliffs.map((e) => w(e, t, r.cliff)),
|
|
483
|
+
...e.seaRocks.map((e) => D(e, r.seaRock)),
|
|
484
|
+
...e.boulders.map((e) => A(e, r.boulder))
|
|
485
|
+
];
|
|
486
|
+
}
|
|
487
|
+
//#endregion
|
|
488
|
+
export { k as boulderField, A as buildBoulder, w as buildCliff, j as buildRocks, D as buildSeaRock, C as cliffField, y as findRockSites, g as localRelief, m as rockGround, E as seaRockField };
|
package/dist/rvt.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type EnginePlugin, type FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
import type { Terrain, TerrainLighting } from './index.js';
|
|
5
|
+
/** Settings of {@link TerrainVirtualTexture.attach}, fixed at attachment. Invalid values throw RangeError. */
|
|
6
|
+
export interface TerrainVirtualTextureOptions {
|
|
7
|
+
/** World width of a texel of the finest level, above 0. Default 0.05 (5 cm). */
|
|
8
|
+
texel?: number;
|
|
9
|
+
/** Texels along each level's side: 256, 512, 1024, 2048 or 4096. Default 1024. */
|
|
10
|
+
size?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Levels, 1 to 12. Level k's texels are 2^k texels of level 0 wide. The coarsest level reaches `(size / 2 - 2) *
|
|
13
|
+
* texel * 2^(levels - 1)` from the camera (along X or Z, about `size * texel * 2^(levels - 2)`); over the outer 29% of
|
|
14
|
+
* that reach the cache fades into the terrain's own shader, which draws all ground past it. Default 6.
|
|
15
|
+
*/
|
|
16
|
+
levels?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Slope (1 - normal.y, 0 to 1) from which ground draws with the terrain's own shader instead of the cache, which is
|
|
19
|
+
* baked top down and so stretches on steep faces (blended over the 0.1 below it). 1: never. Default 0.5.
|
|
20
|
+
*/
|
|
21
|
+
steep?: number;
|
|
22
|
+
/** The cache's format. `rgba16float` keeps layer colours above 1. Default `rgba8unorm-srgb` (4 bytes a texel). */
|
|
23
|
+
format?: 'rgba8unorm-srgb' | 'rgba16float';
|
|
24
|
+
/**
|
|
25
|
+
* Creates the decal pictures, at attachment and again after device restoration: one `rgba8unorm` or
|
|
26
|
+
* `rgba8unorm-srgb` 2D array texture, a layer per picture, alpha its coverage (give it a full mip chain for far
|
|
27
|
+
* decals). The virtual texture owns and destroys it. Default: none (no decals).
|
|
28
|
+
*/
|
|
29
|
+
decals?: (device: GPUDevice) => GPUTexture;
|
|
30
|
+
}
|
|
31
|
+
/** A decal: a picture laid on the ground, baked into the cache over what the terrain's layers draw there. */
|
|
32
|
+
export interface TerrainDecal {
|
|
33
|
+
/** World XZ of its centre. */
|
|
34
|
+
center: readonly [number, number];
|
|
35
|
+
/** World width (along `angle`) and depth, each above 0. */
|
|
36
|
+
size: readonly [number, number];
|
|
37
|
+
/** Turn about +Y in radians, from +X toward +Z. Default 0. */
|
|
38
|
+
angle?: number;
|
|
39
|
+
/** The decals texture layer it shows, a whole number. Default 0. */
|
|
40
|
+
layer?: number;
|
|
41
|
+
/** 0 to 1, times the picture's alpha. Default 1. */
|
|
42
|
+
opacity?: number;
|
|
43
|
+
/** How many times the picture repeats along its width (a road's length over its width), above 0. Default 1. */
|
|
44
|
+
repeat?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Splits the terrain's `terrainColor` into a wrapper that takes the position's screen derivatives and
|
|
48
|
+
* `terrainColorAt`, which reads them from `terrainDx` and `terrainDy`: so the full colour can run where control flow
|
|
49
|
+
* is not uniform (past the cache, on steep ground) and in the bake, whose derivatives are the texel's own.
|
|
50
|
+
*/
|
|
51
|
+
export declare function splitTerrainColor(code: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* The texel rectangles a level of `n` texels must bake when its window's origin moves from `from` to `to` (texel
|
|
54
|
+
* coordinates; no `from`: the whole window), plus `dirty` (world-texel rectangles [x0, z0, x1, z1)), each clipped to
|
|
55
|
+
* the new window, as scissor rectangles [x, y, width, height] of its toroidal target. Exported for the tests.
|
|
56
|
+
*/
|
|
57
|
+
export declare function bakeRects(from: readonly [number, number] | undefined, to: readonly [number, number], n: number, dirty?: readonly (readonly [number, number, number, number])[]): [number, number, number, number][];
|
|
58
|
+
/**
|
|
59
|
+
* The window origins of a cache's levels in world texels, [x0, z0, x1, z1, ...]: level k's texel is `texel * 2^k`
|
|
60
|
+
* wide and its window of `size` texels starts at the eye's float64 world texel less half the size. With a floating
|
|
61
|
+
* origin, `base` gets four numbers a level, [ax, az, bx, bz]: the world texel `a` at or below the shift and its corner
|
|
62
|
+
* as a local point, `b = a * texel - shift` (float64, under one texel). The bake places world texel w at
|
|
63
|
+
* `b + (w - a + 0.5) * texel`, so a texel's point depends on the shift alone, never on where the window stood when it
|
|
64
|
+
* baked (with the window corner in place of `a` a flight rounded each page by its own corner). The function returns
|
|
65
|
+
* the wrap of the reader, `shift` modulo the coarsest level's period. Exported for the tests.
|
|
66
|
+
*/
|
|
67
|
+
export declare function planWindows(eye: ArrayLike<number>, shift: ArrayLike<number>, texel: number, size: number, levels: number, out?: Float64Array<ArrayBuffer>, base?: Float64Array): [number, number];
|
|
68
|
+
/**
|
|
69
|
+
* A runtime virtual texture for a `Terrain`: its blended ground colour, decals and roads baked into camera-centred
|
|
70
|
+
* clipmap levels, and the terrain's lit shader reads the cache instead of its layers.
|
|
71
|
+
* `TerrainVirtualTexture.attach(engine, terrain, options)`; WebGPU only. Call `invalidate(area)` after changing what
|
|
72
|
+
* the terrain draws (sculpt, paint, streamed heights) so that area bakes again.
|
|
73
|
+
* Not with `TerrainMaterials` (`@margoengine/terrain/layers-pbr`), whose normals and roughness come from the layer
|
|
74
|
+
* loop the cache replaces. `bump` relief shows only where the terrain's own shader draws (steep or far ground).
|
|
75
|
+
* @throws RangeError when an option is out of range.
|
|
76
|
+
* @throws MargoError `'unsupported'` when the terrain's shader lacks its colour function or has layer materials,
|
|
77
|
+
* `'disposed'` after dispose.
|
|
78
|
+
*/
|
|
79
|
+
export declare class TerrainVirtualTexture implements EnginePlugin, TerrainLighting {
|
|
80
|
+
#private;
|
|
81
|
+
/** The terrain whose ground the cache holds. */
|
|
82
|
+
readonly terrain: Terrain;
|
|
83
|
+
readonly options: TerrainVirtualTextureOptions;
|
|
84
|
+
readonly name: string;
|
|
85
|
+
disposed: boolean;
|
|
86
|
+
owner?: Engine;
|
|
87
|
+
/** Texels baked in the last frame (a level's whole window is `size` squared). */
|
|
88
|
+
baked: number;
|
|
89
|
+
readonly texel: number;
|
|
90
|
+
readonly size: number;
|
|
91
|
+
readonly levels: number;
|
|
92
|
+
/**
|
|
93
|
+
* Adds an ordered cache surface provider. Its shader decorates the bake's color and the reader's steep/far fallback;
|
|
94
|
+
* bindings use group 2 in the bake, group 1 in the reader. Remove it with the returned function.
|
|
95
|
+
*/
|
|
96
|
+
addSurface(effect: TerrainLighting): () => void;
|
|
97
|
+
/** Rebuilds provider shader/layout state and the cache after a provider's declarations or binding set changes. */
|
|
98
|
+
refreshSurfaces(): void;
|
|
99
|
+
private constructor();
|
|
100
|
+
/** Attaches a virtual texture to `terrain`, which must already be attached to `engine`. `dispose()` removes it. */
|
|
101
|
+
static attach(engine: EngineKernel, terrain: Terrain, options?: TerrainVirtualTextureOptions): TerrainVirtualTexture;
|
|
102
|
+
setup(engine: Engine): void;
|
|
103
|
+
registerPasses(graph: FrameGraph): void;
|
|
104
|
+
/** The group-1 entries the patched terrain shader reads. */
|
|
105
|
+
bindings(): GPUBindGroupEntry[];
|
|
106
|
+
/** The terrain's lit shader reading its ground colour from the cache (bindings in `group`). */
|
|
107
|
+
shader(source: string, group: number): string;
|
|
108
|
+
/**
|
|
109
|
+
* WGSL for another material to read the ground under it (to blend into the terrain): its three bindings at `group`
|
|
110
|
+
* from `binding`, and `fn terrainVirtualColor(position: vec3f, footprint: f32) -> vec4f`, the baked colour (linear)
|
|
111
|
+
* at world `position` in rgb and in a its coverage (0 past the cache), for a pixel `footprint` world units wide.
|
|
112
|
+
*/
|
|
113
|
+
declarations(group: number, binding: number): string;
|
|
114
|
+
/** The bind group entries `declarations(group, binding)` reads, while attached (else an empty list). */
|
|
115
|
+
entries(binding: number): GPUBindGroupEntry[];
|
|
116
|
+
/** The cache, one array layer per level, while attached (else undefined). */
|
|
117
|
+
get texture(): GPUTexture | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Bakes again the world XZ rectangle from (x0, z0) to (x1, z1) on every level, on the next frame: call it after
|
|
120
|
+
* changing the terrain's heights, weights or tint there. Without arguments, the whole cache.
|
|
121
|
+
*/
|
|
122
|
+
invalidate(x0?: number, z0?: number, x1?: number, z1?: number): void;
|
|
123
|
+
/** Adds a decal; returns its id for `removeDecal`. Decals added later draw over earlier ones. */
|
|
124
|
+
addDecal(decal: TerrainDecal): number;
|
|
125
|
+
/** Removes a decal by its id; returns whether it was there. */
|
|
126
|
+
removeDecal(id: number): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Lays a road along world XZ `points` (2 or more): a decal per segment, `width` wide, its picture repeating once per
|
|
129
|
+
* `width` of length. Returns the decals' ids. Sharp bends leave a gap on their outer side; give a curve as short
|
|
130
|
+
* segments.
|
|
131
|
+
*/
|
|
132
|
+
road(points: readonly (readonly [number, number])[], width: number, decal?: Pick<TerrainDecal, 'layer' | 'opacity'>): number[];
|
|
133
|
+
onDeviceRestored(engine: Engine): void;
|
|
134
|
+
dispose(): void;
|
|
135
|
+
[Symbol.dispose]: () => void;
|
|
136
|
+
}
|