@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.
Files changed (88) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +2366 -2
  4. package/dist/bed-mesh.d.ts +40 -0
  5. package/dist/bed-mesh.js +95 -0
  6. package/dist/blend.d.ts +70 -0
  7. package/dist/blend.js +159 -0
  8. package/dist/colors.d.ts +170 -0
  9. package/dist/deform.d.ts +134 -0
  10. package/dist/deform.js +404 -0
  11. package/dist/displace.d.ts +60 -0
  12. package/dist/displace.js +254 -0
  13. package/dist/dunes.d.ts +86 -0
  14. package/dist/dunes.js +88 -0
  15. package/dist/elevation.d.ts +182 -0
  16. package/dist/elevation.js +155 -0
  17. package/dist/errors-fc4i1pSL.js +7 -0
  18. package/dist/far.d.ts +66 -0
  19. package/dist/far.js +191 -0
  20. package/dist/furrows.d.ts +74 -0
  21. package/dist/furrows.js +157 -0
  22. package/dist/grid.d.ts +14 -0
  23. package/dist/ground-change-settings.d.ts +29 -0
  24. package/dist/ground-change-settings.js +69 -0
  25. package/dist/ground-change.d.ts +227 -0
  26. package/dist/ground-change.js +1412 -0
  27. package/dist/ground-contact-settings.d.ts +27 -0
  28. package/dist/ground-contact-settings.js +22 -0
  29. package/dist/ground-contact.d.ts +91 -0
  30. package/dist/ground-contact.js +241 -0
  31. package/dist/ground-model.d.ts +372 -0
  32. package/dist/hdr-format-DRhzGS7G.js +30 -0
  33. package/dist/height-grid.d.ts +65 -0
  34. package/dist/height-grid.js +74 -0
  35. package/dist/heightfield.d.ts +38 -0
  36. package/dist/holes.d.ts +37 -0
  37. package/dist/holes.js +97 -0
  38. package/dist/imagery.d.ts +109 -0
  39. package/dist/imagery.js +472 -0
  40. package/dist/index.d.ts +408 -0
  41. package/dist/index.js +1 -0
  42. package/dist/layers-pbr.d.ts +78 -0
  43. package/dist/layers-pbr.js +128 -0
  44. package/dist/lighting-layout-CaDtDa5G.js +34 -0
  45. package/dist/lighting-layout.d.ts +5 -0
  46. package/dist/mesh-patch-BThCHCeS.js +21 -0
  47. package/dist/mesh-patch.d.ts +14 -0
  48. package/dist/noise3-sQdnbz4B.js +11 -0
  49. package/dist/noise3.d.ts +3 -0
  50. package/dist/overlays.d.ts +74 -0
  51. package/dist/overlays.js +297 -0
  52. package/dist/planet-complex.d.ts +31 -0
  53. package/dist/planet-craters.d.ts +80 -0
  54. package/dist/planet-rays.d.ts +37 -0
  55. package/dist/planet-recipes.d.ts +84 -0
  56. package/dist/planet-recipes.js +442 -0
  57. package/dist/planet.d.ts +144 -0
  58. package/dist/planet.js +610 -0
  59. package/dist/query.d.ts +150 -0
  60. package/dist/query.js +243 -0
  61. package/dist/relief-lighting.d.ts +53 -0
  62. package/dist/relief-lighting.js +221 -0
  63. package/dist/require-webgpu--tUXPsmA.js +7 -0
  64. package/dist/rock-settings.d.ts +39 -0
  65. package/dist/rock-settings.js +84 -0
  66. package/dist/rock-surface.d.ts +114 -0
  67. package/dist/rock-surface.js +380 -0
  68. package/dist/rocks.d.ts +258 -0
  69. package/dist/rocks.js +488 -0
  70. package/dist/rvt.d.ts +136 -0
  71. package/dist/rvt.js +518 -0
  72. package/dist/scour.d.ts +90 -0
  73. package/dist/scour.js +153 -0
  74. package/dist/sculpt.d.ts +103 -0
  75. package/dist/sculpt.js +361 -0
  76. package/dist/settings-B9BSdnhD.js +72 -0
  77. package/dist/settings.d.ts +81 -0
  78. package/dist/settings.js +152 -0
  79. package/dist/shader.d.ts +176 -0
  80. package/dist/shared/settings.d.ts +89 -0
  81. package/dist/src-Cr7Gm4n0.js +1366 -0
  82. package/dist/stream-window.d.ts +123 -0
  83. package/dist/stream.d.ts +169 -0
  84. package/dist/stream.js +531 -0
  85. package/dist/surface-height.d.ts +16 -0
  86. package/dist/wet-ground.d.ts +82 -0
  87. package/dist/wet-ground.js +147 -0
  88. package/package.json +173 -4
@@ -0,0 +1,155 @@
1
+ import { gridHeightField as e } from "./height-grid.js";
2
+ //#region src/elevation.ts
3
+ var t = (e) => /* @__PURE__ */ RangeError(`Invalid elevation; ${e}.`), n = {
4
+ metre: 1,
5
+ foot: .3048,
6
+ "us-foot": 1200 / 3937
7
+ };
8
+ function r(e, r, i = {}) {
9
+ let { width: a, height: o, samples: s } = e, c = e.samplesPerPixel ?? 1, l = i.band ?? 0, u = r.transform;
10
+ if (!u) throw t("the raster has no georeference (ModelPixelScale and ModelTiepoint, or ModelTransformation)");
11
+ if (r.crs.model !== "geographic") throw t(`the raster is ${r.crs.model}; pass a geographic (latitude and longitude) raster`);
12
+ let [d, f, p, m, h, g] = u;
13
+ if (f !== 0 || m !== 0 || !(d > 0) || !(h < 0)) throw t("the raster must be north-up and not rotated");
14
+ if (!Number.isInteger(l) || l < 0 || l >= c) throw t(`band ${l} is not in 0 to ${c - 1}`);
15
+ if (s.length !== a * o * c) throw t(`${a * o * c} samples are needed`);
16
+ let _ = r.verticalUnits, v = i.scale ?? (_ ? n[_] : 1);
17
+ if (!Number.isFinite(v) || v === 0) throw t("scale must be a finite number other than 0");
18
+ let y = r.raster === "area" ? .5 : 0, b = (e) => d * (e + y) + p, x = (e) => h * (e + y) + g, S = 0, C = a - 1, w = 0, T = o - 1, E = i.window;
19
+ if (E) {
20
+ if (![
21
+ E.south,
22
+ E.west,
23
+ E.north,
24
+ E.east
25
+ ].every(Number.isFinite) || !(E.north > E.south) || !(E.east > E.west)) throw t("the window needs finite south < north and west < east, degrees");
26
+ if (S = Math.max(0, Math.floor((E.west - p) / d - y)), C = Math.min(a - 1, Math.ceil((E.east - p) / d - y)), w = Math.max(0, Math.floor((E.north - g) / h - y)), T = Math.min(o - 1, Math.ceil((E.south - g) / h - y)), C - S < 1 || T - w < 1) throw t("the window holds fewer than 2 by 2 samples of the raster");
27
+ }
28
+ let D = C - S + 1, O = T - w + 1, k = new Float32Array(D * O), A = r.noData === null ? NaN : Math.fround(r.noData), j = 0, M = Infinity, N = -Infinity;
29
+ for (let e = 0; e < O; e++) for (let t = 0; t < D; t++) {
30
+ let n = Number(s[((e + w) * a + t + S) * c + l]);
31
+ if (!Number.isFinite(n) || Math.fround(n) === A) {
32
+ k[e * D + t] = NaN, j++;
33
+ continue;
34
+ }
35
+ let r = n * v;
36
+ k[e * D + t] = r, r < M && (M = r), r > N && (N = r);
37
+ }
38
+ let P = b(S), F = x(w);
39
+ return {
40
+ width: D,
41
+ height: O,
42
+ heights: k,
43
+ west: P,
44
+ north: F,
45
+ step: [d, -h],
46
+ east: b(C),
47
+ south: x(T),
48
+ datum: i.datum ?? "unknown",
49
+ crs: {
50
+ epsg: r.crs.epsg,
51
+ citation: r.crs.citation
52
+ },
53
+ missing: j,
54
+ min: M,
55
+ max: N,
56
+ at: (e, t) => {
57
+ let n = (t - P) / d, r = (e - F) / h;
58
+ if (!(n >= 0 && r >= 0 && n <= D - 1 && r <= O - 1)) return NaN;
59
+ let i = Math.min(Math.floor(n), D - 2), a = Math.min(Math.floor(r), O - 2), o = n - i, s = r - a, c = a * D + i;
60
+ return (k[c] + (k[c + 1] - k[c]) * o) * (1 - s) + (k[c + D] + (k[c + D + 1] - k[c + D]) * o) * s;
61
+ }
62
+ };
63
+ }
64
+ var i = Object.freeze({
65
+ a: 6378137,
66
+ f: 1 / 298.257222101
67
+ }), a = Object.freeze({
68
+ a: 6378137,
69
+ f: 1 / 298.257223563
70
+ }), o = Math.PI / 180;
71
+ function s(e, n = i) {
72
+ let { a: r, f: a } = n, s = e.lat, c = e.lon, l = e.height ?? 0;
73
+ if (!(r > 0) || !(a >= 0 && a < 1)) throw t("the ellipsoid needs a > 0 and 0 <= f < 1");
74
+ if (!(Math.abs(s) <= 90) || !Number.isFinite(c) || !Number.isFinite(l)) throw t("the site needs a latitude from -90 to 90, a finite longitude and a finite height");
75
+ let u = a * (2 - a), d = r * (1 - a), f = u / (1 - u), p = (e, t, n) => {
76
+ let i = e * o, a = t * o, s = Math.sin(i), c = r / Math.sqrt(1 - u * s * s), l = (c + n) * Math.cos(i);
77
+ return [
78
+ l * Math.cos(a),
79
+ l * Math.sin(a),
80
+ (c * (1 - u) + n) * s
81
+ ];
82
+ }, m = Math.sin(s * o), h = Math.cos(s * o), g = Math.sin(c * o), _ = Math.cos(c * o), [v, y, b] = p(s, c, l);
83
+ return {
84
+ site: {
85
+ lat: s,
86
+ lon: c,
87
+ height: l
88
+ },
89
+ ellipsoid: n,
90
+ toLocal(e, t, n = 0) {
91
+ let [r, i, a] = p(e, t, n), o = r - v, s = i - y, c = a - b, l = -g * o + _ * s, u = -m * _ * o - m * g * s + h * c;
92
+ return [
93
+ l,
94
+ h * _ * o + h * g * s + m * c,
95
+ -u
96
+ ];
97
+ },
98
+ toGeographic(e, t, n = 0) {
99
+ let i = e, s = -t, c = n, l = v - g * i - m * _ * s + h * _ * c, p = y + _ * i - m * g * s + h * g * c, x = b + h * s + m * c, S = Math.hypot(l, p), C = Math.atan2(x, (1 - a) * S), w = 0;
100
+ for (let e = 0; e < 3; e++) {
101
+ let e = Math.sin(C), t = Math.cos(C);
102
+ w = Math.atan2(x + f * d * e * e * e, S - u * r * t * t * t), C = Math.atan2((1 - a) * Math.sin(w), Math.cos(w));
103
+ }
104
+ let T = Math.sin(w), E = S * Math.cos(w) + x * T - r * Math.sqrt(1 - u * T * T);
105
+ return [
106
+ w / o,
107
+ Math.atan2(p, l) / o,
108
+ E
109
+ ];
110
+ }
111
+ };
112
+ }
113
+ var c = 2 ** 26;
114
+ function l(n, r) {
115
+ let i = "toLocal" in r.site ? r.site : s(r.site), { lat: a, lon: o } = i.site, [l] = i.toLocal(a, o + n.step[0]), [, , u] = i.toLocal(a - n.step[1], o), d = [Math.abs(l), Math.abs(u)], f = r.spacing ?? d[1];
116
+ if (!(f > 0) || !Number.isFinite(f)) throw t("spacing must be a positive number of metres");
117
+ let p = r.size;
118
+ if (!p) {
119
+ let e = [
120
+ i.toLocal(n.north, n.west),
121
+ i.toLocal(n.north, n.east),
122
+ i.toLocal(n.south, n.west),
123
+ i.toLocal(n.south, n.east)
124
+ ], r = Math.min(-Math.min(e[0][0], e[2][0]), Math.min(e[1][0], e[3][0])), a = Math.min(-Math.min(e[0][2], e[1][2]), Math.min(e[2][2], e[3][2])), o = Math.floor(r / f), s = Math.floor(a / f);
125
+ if (!(o >= 1 && s >= 1)) throw t("the site is outside the elevation (or within a spacing of its edge); pass size and origin");
126
+ p = [2 * o * f, 2 * s * f];
127
+ }
128
+ let m = r.origin ?? [-p[0] / 2, -p[1] / 2], h = Math.max(2, Math.round(p[0] / f) + 1), g = Math.max(2, Math.round(p[1] / f) + 1);
129
+ if (h * g > c) throw t(`${h} by ${g} texels is over ${c}; raise spacing`);
130
+ let _ = r.curvature ?? !1, v = r.detail, y = new Float32Array(h * g);
131
+ for (let e = 0; e < g; e++) {
132
+ let t = m[1] + p[1] * e / (g - 1);
133
+ for (let r = 0; r < h; r++) {
134
+ let a = m[0] + p[0] * r / (h - 1), [o, s] = i.toGeographic(a, t), c = n.at(o, s);
135
+ _ && !Number.isNaN(c) && (c = i.toLocal(o, s, c)[1]), v && !Number.isNaN(c) && (c += v(a, t)), y[e * h + r] = c;
136
+ }
137
+ }
138
+ let b = e({
139
+ width: h,
140
+ height: g,
141
+ heights: y,
142
+ size: p,
143
+ origin: m,
144
+ fill: r.fill ?? "nearest"
145
+ });
146
+ return Object.assign(b, {
147
+ frame: i,
148
+ datum: _ ? "tangent plane" : n.datum,
149
+ surveyed: d,
150
+ spacing: f,
151
+ detailed: !!v
152
+ });
153
+ }
154
+ //#endregion
155
+ export { i as GRS80, a as WGS84, l as elevationField, s as localFrame, r as readElevation };
@@ -0,0 +1,7 @@
1
+ //#region ../shared/errors.js
2
+ var e = (e, t) => Object.assign(Error(t), {
3
+ name: "MargoError",
4
+ code: e
5
+ });
6
+ //#endregion
7
+ export { e as t };
package/dist/far.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ import type { TerrainStreamFar, TerrainStreamWindow } from './stream.js';
2
+ import type { TerrainStreamLoad } from './stream-window.js';
3
+ /** {@link terrainFar} options. */
4
+ export interface TerrainFarOptions {
5
+ /**
6
+ * Loads far tile (x, z): like the stream's `load`, but a far tile is `scale` times as wide and starts at the stream's
7
+ * `origin + [x, z] * scale * tileSize`. Give the same weights, normals and tint a near tile would, `tileTexels` square.
8
+ */
9
+ readonly load: TerrainStreamLoad;
10
+ /** Far tile width in near tiles, an integer from 2 to 64. Default 4. */
11
+ readonly scale?: number;
12
+ /** Samples per far tile side, an integer from 4 to 1,024. Default: the stream's `tileTexels`. */
13
+ readonly tileTexels?: number;
14
+ /** Far tiles per window side, an even integer from 2 to 16. Default: the stream's `window`. */
15
+ readonly window?: number;
16
+ /**
17
+ * World distance over which the fine heights blend into the far ones, above 0. It ends where the near window is sure
18
+ * to reach, `(window / 2 - 0.75) * tileSize - 2 * tileSize / tileTexels` from the camera on each axis. Default: half
19
+ * a tile, or half that distance when it is smaller.
20
+ */
21
+ readonly blend?: number;
22
+ /** Seconds a near tile takes to fade in over the far ground once uploaded, 0 or more. Default 0.5. */
23
+ readonly fade?: number;
24
+ }
25
+ /**
26
+ * The far ring of one streamed terrain: pass it as `TerrainStreamOptions.far`. Make it with {@link terrainFar}; it
27
+ * serves one stream at a time.
28
+ */
29
+ export declare class TerrainFar implements TerrainStreamFar {
30
+ #private;
31
+ /** The options given, as given. */
32
+ readonly options: TerrainFarOptions;
33
+ constructor(options: TerrainFarOptions);
34
+ get load(): TerrainStreamLoad;
35
+ /** While a stream draws it: the far window's tiles (CPU copies, tile indices on the far lattice, changes). */
36
+ get tiles(): TerrainStreamWindow | undefined;
37
+ /** While attached: how far from the camera on each axis ground is drawn, in world units. */
38
+ get reach(): number | undefined;
39
+ /** While attached: how far from the camera on each axis loaded ground is drawn from the fine heights alone. */
40
+ get detail(): number | undefined;
41
+ /**
42
+ * The world height the terrain draws at world (x, z) this frame: the fine heights near the camera, the far ones past
43
+ * the blend, mixed between. Undefined past `reach` and while no stream draws the ring. The mesh joins such heights
44
+ * with flat triangles, so ground between vertices differs by what a triangle cuts off.
45
+ */
46
+ heightAt(x: number, z: number): number | undefined;
47
+ plan(near: {
48
+ tileSize: number;
49
+ tileTexels: number;
50
+ window: number;
51
+ }): {
52
+ tileSize: number;
53
+ tileTexels: number;
54
+ window: number;
55
+ reach: number;
56
+ };
57
+ bind(near: TerrainStreamWindow, far: TerrainStreamWindow, terrain: {
58
+ heightScale?: number;
59
+ heightOffset?: number;
60
+ }): ReturnType<TerrainStreamFar['bind']>;
61
+ }
62
+ /**
63
+ * A coarser ring of ground past a streamed terrain's window, for `TerrainStreamOptions.far`.
64
+ * @throws TypeError without `load`; RangeError for options out of range.
65
+ */
66
+ export declare function terrainFar(options: TerrainFarOptions): TerrainFar;
package/dist/far.js ADDED
@@ -0,0 +1,191 @@
1
+ import { MargoError as e } from "@margoengine/math/errors";
2
+ //#region src/far.ts
3
+ var t = (e, t, n) => Number.isInteger(e) && e >= t && e <= n, n = (e) => Math.min(1, Math.max(0, e)), r = (e, t, r, i) => {
4
+ let a = n(r) * (t - 1), o = n(i) * (t - 1), s = Math.floor(a), c = Math.floor(o), l = Math.min(s + 1, t - 1), u = Math.min(c + 1, t - 1), d = e[c * t + s] + (e[c * t + l] - e[c * t + s]) * (a - s);
5
+ return d + (e[u * t + s] + (e[u * t + l] - e[u * t + s]) * (a - s) - d) * (o - c);
6
+ }, i = (t, n, r) => {
7
+ if (!t.includes(n)) throw new e("unsupported", "Terrain far ring found no \"" + n + "\" in the terrain shader; use matching versions of @margoengine/terrain");
8
+ return t.replace(n, r);
9
+ }, a = "if(any(i.position.xz<frame.map.xy)||any(i.position.xz>frame.map.xy+frame.map.zw)){discard;}";
10
+ function o(e, t, n, r, o) {
11
+ e = e.split(a).join("if(any(abs(i.position.xz-frame.map.xy-terrainFarData.blend.xy)>vec2f(terrainFarData.tiles.x))){discard;}");
12
+ let s = "fn height(position:vec2f)->f32 {";
13
+ if (!e.includes(s)) return e;
14
+ let c = t, l = (e) => `@group(0) @binding(${c++}) ${e};\n`, u = "struct TerrainFar {map:vec4f,blend:vec4f,tiles:vec4f}\n" + l("var<uniform> terrainFarData:TerrainFar") + l("var terrainResidency:texture_2d<f32>") + l("var terrainFarHeight:texture_2d<f32>");
15
+ return r && (u += l("var terrainFarNormal:texture_2d<f32>")), n && (u += l("var terrainFarWeights:texture_2d_array<f32>")), o && (u += l("var terrainFarTint:texture_2d<f32>")), u += "fn terrainFarBlend(xz:vec2f)->f32 {\n let p=xz-frame.map.xy;let d=abs(p-terrainFarData.blend.xy);\n var a=clamp((max(d.x,d.y)-terrainFarData.blend.z)*terrainFarData.blend.w,0.0,1.0);\n if(a>=1.0){return 1.0;}\n let tile=terrainFarData.tiles.y;let n=i32(textureDimensions(terrainResidency).x);\n let u=p/tile;let c=vec2i(floor(u));let s=select(vec2i(-1),vec2i(1),fract(u)>=vec2f(0.5));\n for(var k=0;k<4;k++){\n let q=c+vec2i(s.x*(k%2),s.y*(k/2));\n if(any(q<vec2i(0))||any(q>=vec2i(n))){continue;}\n let low=vec2f(q)*tile-vec2f(terrainFarData.tiles.z);let high=vec2f(q)*tile+vec2f(tile);\n let g=max(max(low-p,p-high),vec2f(0));\n a=max(a,(1.0-textureLoad(terrainResidency,q,0).r)*clamp(1.0-max(g.x,g.y)*terrainFarData.tiles.w,0.0,1.0));\n }\n return a;\n}\nfn terrainFarUV(xz:vec2f)->vec2f {return clamp((xz-frame.map.xy-terrainFarData.map.xy)/terrainFarData.map.zw,vec2f(0),vec2f(1));}\nfn height(position:vec2f)->f32 {\n let a=terrainFarBlend(position);\n if(a<=0.0){return terrainNearHeight(position);}\n let d=vec2i(textureDimensions(terrainFarHeight));let pixel=terrainFarUV(position)*vec2f(d-vec2i(1));let lo=vec2i(floor(pixel));let hi=min(lo+vec2i(1),d-vec2i(1));let t=fract(pixel);\n let low=mix(textureLoad(terrainFarHeight,lo,0).r,textureLoad(terrainFarHeight,vec2i(hi.x,lo.y),0).r,t.x);let high=mix(textureLoad(terrainFarHeight,vec2i(lo.x,hi.y),0).r,textureLoad(terrainFarHeight,hi,0).r,t.x);\n let far=mix(low,high,t.y)*frame.heights.x+frame.heights.y;\n if(a>=1.0){return far;}\n return mix(terrainNearHeight(position),far,a);\n}\n", r && (u += "fn terrainFarNormalAt(xz:vec2f,near:vec3f)->vec3f {\n let a=terrainFarBlend(xz);if(a<=0.0){return near;}\n let d=vec2i(textureDimensions(terrainFarNormal));\n return mix(near,textureLoad(terrainFarNormal,min(vec2i(terrainFarUV(xz)*vec2f(d)),d-vec2i(1)),0).xyz*2-1,a);\n}\n"), e = i(e, s, "fn terrainNearHeight(position:vec2f)->f32 {"), e = i(e, "let step=frame.map.zw/max(vec2f(textureDimensions(heightMap))-1,vec2f(1));", "let step=mix(frame.map.zw/max(vec2f(textureDimensions(heightMap))-1,vec2f(1)),terrainFarData.map.zw/max(vec2f(textureDimensions(terrainFarHeight))-1,vec2f(1)),terrainFarBlend(xz));"), r && (e = i(e, "textureLoad(normalMap,min(vec2i(uv*vec2f(dimensions)),dimensions-vec2i(1)),0).xyz*2-1", "terrainFarNormalAt(xz,textureLoad(normalMap,min(vec2i(uv*vec2f(dimensions)),dimensions-vec2i(1)),0).xyz*2-1)")), n && e.includes("var packed=") && (e = i(e, "var color=vec3f(0);var total=0.0;", `let farBlend=terrainFarBlend(position.xz);if(farBlend>0.0){${((e) => `let d=vec2f(textureDimensions(${e}));let uv=clamp(terrainFarUV(position.xz),vec2f(0.5)/d,vec2f(1)-vec2f(0.5)/d);`)("terrainFarWeights")}for(var k=0;k<${n};k++){packed[k]=mix(packed[k],textureSampleLevel(terrainFarWeights,terrainSampler,uv,k,0.0),farBlend);}${o ? "terrainTintTexel=mix(terrainTintTexel,textureSampleLevel(terrainFarTint,terrainSampler,uv,0.0),farBlend);" : ""}}
16
+ var color=vec3f(0);var total=0.0;`)), u + e;
17
+ }
18
+ var s = class {
19
+ #e;
20
+ #t;
21
+ #n;
22
+ #r;
23
+ constructor(e) {
24
+ let n = e;
25
+ if (!n || typeof n.load != "function") throw TypeError("Invalid terrain far ring; pass load(x, z, signal).");
26
+ if (!t(n.scale ?? 4, 2, 64) || n.tileTexels !== void 0 && !t(n.tileTexels, 4, 1024) || n.window !== void 0 && (!t(n.window, 2, 16) || n.window % 2 != 0) || n.blend !== void 0 && !(n.blend > 0 && Number.isFinite(n.blend)) || !((n.fade ?? .5) >= 0 && Number.isFinite(n.fade ?? .5))) throw RangeError("Invalid terrain far ring options; give a scale 2..64, tileTexels 4..1024, an even window 2..16, a blend above 0 and a fade of 0 s or more.");
27
+ this.options = n;
28
+ }
29
+ get load() {
30
+ return this.options.load;
31
+ }
32
+ get tiles() {
33
+ return this.#e;
34
+ }
35
+ get reach() {
36
+ return this.#r?.reach;
37
+ }
38
+ get detail() {
39
+ return this.#r?.near;
40
+ }
41
+ heightAt(e, t) {
42
+ return this.#t?.(e, t);
43
+ }
44
+ plan(e) {
45
+ let t = this.options, n = e.tileSize * (t.scale ?? 4), r = t.tileTexels ?? e.tileTexels, i = t.window ?? e.window, a = e.tileSize / e.tileTexels, o = (e.window / 2 - .75) * e.tileSize - 2 * a, s = (i / 2 - .75) * n - n / r * 2, c = t.blend ?? Math.min(e.tileSize / 2, o / 2);
46
+ if (!(o > 0)) throw RangeError("Terrain far ring: the near window is too small to blend in; raise its window to 4 or its tileTexels above 8.");
47
+ if (r < 4 || e.tileTexels < 4) throw RangeError("Terrain far ring: both windows need tileTexels of 4 or more.");
48
+ if (!(c <= o)) throw RangeError(`Terrain far ring blend must be at most ${o}, the reach of the near window.`);
49
+ if (!(s > o)) throw RangeError(`Terrain far ring reaches ${s}, inside the near window's ${o}; raise far.scale or far.window.`);
50
+ return this.#n = {
51
+ count: e.window,
52
+ tile: e.tileSize,
53
+ spacing: a,
54
+ farSpacing: n / r,
55
+ near: o - c,
56
+ width: c,
57
+ hole: Math.min(c, e.tileSize / 2 - a),
58
+ reach: s
59
+ }, {
60
+ tileSize: n,
61
+ tileTexels: r,
62
+ window: i,
63
+ reach: s
64
+ };
65
+ }
66
+ bind(t, i, a) {
67
+ if (this.#e) throw new e("attached", "This terrain far ring draws another stream; make one terrainFar per stream");
68
+ let s = this.#n, c = this.options.fade ?? .5, l = s.count, u = s.farSpacing, d = t.weights.length, f = !!t.normals, p = !!t.tint, m = new Float32Array(l * l), h = new Float32Array(l * l), g = [t.tile[0], t.tile[1]], _ = /* @__PURE__ */ new Float32Array(12), v = /* @__PURE__ */ new Float32Array(12), y = [NaN, NaN], b, x, S, C = !0, w = () => {
69
+ b.queue.writeBuffer(x, 0, _), b.queue.writeTexture({ texture: S }, m, { bytesPerRow: l * 4 }, [l, l]);
70
+ }, T = () => {
71
+ x?.destroy(), S?.destroy(), x = S = void 0;
72
+ }, E = (e) => {
73
+ let n = t.tile[0] - g[0], r = t.tile[1] - g[1], i = !1;
74
+ if (n || r) {
75
+ h.set(m);
76
+ for (let e = 0; e < l; e++) for (let t = 0; t < l; t++) {
77
+ let i = t + n >= 0 && t + n < l && e + r >= 0 && e + r < l;
78
+ m[e * l + t] = i ? h[(e + r) * l + t + n] : 0;
79
+ }
80
+ g[0] = t.tile[0], g[1] = t.tile[1], i = !0;
81
+ }
82
+ let a = c > 0 ? e > 0 ? e / c : 0 : 1;
83
+ for (let e = 0; e < l; e++) for (let n = 0; n < l; n++) {
84
+ let r = e * l + n, o = m[r], s = t.holds(t.tile[0] + n, t.tile[1] + e) ? Math.min(1, o + a) : 0;
85
+ Math.fround(s) !== o && (m[r] = s, i = !0);
86
+ }
87
+ return i;
88
+ };
89
+ return this.#e = i, this.#r = s, this.#t = (e, o) => {
90
+ let [c, d] = y, f = e - t.origin[0], p = o - t.origin[1], h = Math.max(Math.abs(e - c), Math.abs(o - d));
91
+ if (!(h <= s.reach)) return;
92
+ let g = n((h - s.near) / s.width), _ = f / s.tile, v = p / s.tile, b = Math.floor(_), x = Math.floor(v), S = _ - b >= .5 ? 1 : -1, C = v - x >= .5 ? 1 : -1;
93
+ for (let e = 0; e < 4; e++) {
94
+ let t = b + e % 2 * S, r = x + C * (e >> 1);
95
+ if (t < 0 || r < 0 || t >= l || r >= l) continue;
96
+ let i = Math.max(t * s.tile - s.spacing - f, f - (t + 1) * s.tile, 0), a = Math.max(r * s.tile - s.spacing - p, p - (r + 1) * s.tile, 0);
97
+ g = Math.max(g, (1 - m[r * l + t]) * n(1 - Math.max(i, a) / s.hole));
98
+ }
99
+ let w = (e, t) => (e.columns - 1) * t, T = r(t.heights, t.columns, f / w(t, s.spacing), p / w(t, s.spacing));
100
+ return (T + (r(i.heights, i.columns, (e - i.origin[0]) / w(i, u), (o - i.origin[1]) / w(i, u)) - T) * g) * (a.heightScale ?? 100) + (a.heightOffset ?? 0);
101
+ }, {
102
+ source: (e) => (T(), b = e, x = e.createBuffer({
103
+ size: 48,
104
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
105
+ }), S = e.createTexture({
106
+ size: [l, l],
107
+ format: "r32float",
108
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
109
+ }), C = !0, {
110
+ entries: (e) => {
111
+ let t = GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT, n = GPUShaderStage.FRAGMENT, r = { sampleType: "unfilterable-float" };
112
+ return [
113
+ {
114
+ visibility: t,
115
+ buffer: { type: "uniform" }
116
+ },
117
+ {
118
+ visibility: t,
119
+ texture: r
120
+ },
121
+ {
122
+ visibility: t,
123
+ texture: r
124
+ },
125
+ ...f ? [{
126
+ visibility: t,
127
+ texture: r
128
+ }] : [],
129
+ ...d ? [{
130
+ visibility: n,
131
+ texture: { viewDimension: "2d-array" }
132
+ }] : [],
133
+ ...p ? [{
134
+ visibility: n,
135
+ texture: {}
136
+ }] : []
137
+ ].map((t, n) => ({
138
+ ...t,
139
+ binding: e + n
140
+ }));
141
+ },
142
+ resources: () => {
143
+ let e = i.textures;
144
+ return [
145
+ { buffer: x },
146
+ S.createView(),
147
+ e.height.createView(),
148
+ ...f ? [e.normals.createView()] : [],
149
+ ...d ? [e.weights[0].createView({ dimension: "2d-array" })] : [],
150
+ ...p ? [e.tint.createView()] : []
151
+ ];
152
+ },
153
+ shader: (e, t) => o(e, t, d, f, p)
154
+ }),
155
+ update: (e, n, r) => {
156
+ if (!b) return !1;
157
+ let a = s.width / 256, o = E(e);
158
+ if (Number.isFinite(n) && Number.isFinite(r)) {
159
+ let e = Math.round(n / a) * a, t = Math.round(r / a) * a;
160
+ o ||= e !== y[0] || t !== y[1], y[0] = e, y[1] = t;
161
+ }
162
+ let c = (i.columns - 1) * u;
163
+ _.set([
164
+ i.origin[0] - t.origin[0],
165
+ i.origin[1] - t.origin[1],
166
+ c,
167
+ c,
168
+ (y[0] || 0) - t.origin[0],
169
+ (y[1] || 0) - t.origin[1],
170
+ s.near,
171
+ 1 / s.width,
172
+ s.reach,
173
+ s.tile,
174
+ s.spacing,
175
+ 1 / s.hole
176
+ ]);
177
+ let l = C || o;
178
+ for (let e = 0; e < 12; e++) _[e] !== v[e] && (l = !0);
179
+ return l && (w(), v.set(_), C = !1), o;
180
+ },
181
+ dispose: () => {
182
+ T(), b = void 0, this.#e = this.#t = this.#r = void 0;
183
+ }
184
+ };
185
+ }
186
+ };
187
+ function c(e) {
188
+ return new s(e);
189
+ }
190
+ //#endregion
191
+ export { s as TerrainFar, c as terrainFar };
@@ -0,0 +1,74 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
4
+ import type { Terrain, TerrainLighting } from './index.js';
5
+ type Pair = readonly [number, number];
6
+ /** One field's furrows. */
7
+ export interface FurrowField {
8
+ /** The field's outline, 3 or more [x, z] world points. */
9
+ readonly outline: readonly Pair[];
10
+ /** The furrows' direction, radians from +x toward +z (farmland's `Field.furrow`). */
11
+ readonly furrow: number;
12
+ /** Metres from one furrow to the next, 0.05 to 4. Default 0.35 (a plough's turned slice). */
13
+ readonly spacing?: number;
14
+ /** Contrast of the stripes, 0 (none) to 1: the colour swings by this share either way. Default 0.25. */
15
+ readonly depth?: number;
16
+ }
17
+ /** Options of {@link FieldFurrows.attach}. */
18
+ export interface FieldFurrowsOptions {
19
+ readonly fields: readonly FurrowField[];
20
+ /** World [x, z] of the texture's minimum corner. Default the fields' extent's. */
21
+ readonly origin?: Pair;
22
+ /** World [width, depth] it covers. Default the fields' extent. */
23
+ readonly size?: Pair;
24
+ /** Metres a texel, 0.5 to 64. Default 4. */
25
+ readonly texel?: number;
26
+ /** The first of the two lighting-group bindings the effect declares. Default 118. */
27
+ readonly binding?: number;
28
+ }
29
+ /**
30
+ * Furrowed fields on a `Terrain`: stripes of each field's direction, spacing and contrast over the terrain's colour.
31
+ * @example
32
+ * const furrows = FieldFurrows.attach(engine, terrain, {
33
+ * fields: farm.fields.filter((f) => f.use === 'plough').map((f) => ({ outline: f.outline, furrow: f.furrow })),
34
+ * });
35
+ */
36
+ export declare class FieldFurrows implements EnginePlugin, TerrainLighting, Disposable {
37
+ #private;
38
+ readonly name: string;
39
+ readonly origin: Pair;
40
+ readonly size: Pair;
41
+ /** Texels a side of the furrow texture. */
42
+ readonly texels: Pair;
43
+ readonly binding: number;
44
+ disposed: boolean;
45
+ constructor(terrain: Terrain, options: FieldFurrowsOptions);
46
+ /** Attaches the furrows to `terrain` on `engine`. */
47
+ static attach(engine: EngineKernel, terrain: Terrain, options: FieldFurrowsOptions): FieldFurrows;
48
+ /**
49
+ * The furrows' texel at world (x, z): its direction [cos, sin] (from +x toward +z), contrast and spacing, m; null where
50
+ * no field lies.
51
+ */
52
+ at(x: number, z: number): {
53
+ direction: Pair;
54
+ depth: number;
55
+ spacing: number;
56
+ } | null;
57
+ get owner(): Engine | undefined;
58
+ setup(engine: Engine): void;
59
+ onDeviceRestored(engine: Engine): void;
60
+ /** The lighting group entries: the furrow texture and the look (extent and the screen's pixel angle). */
61
+ bindings(): GPUBindGroupEntry[];
62
+ /** The terrain's lit shader with `terrainColor` striped by the furrows under each point. */
63
+ shader(source: string, group: number): string;
64
+ /** Detaches from the terrain (its shader returns to what it was) and frees the texture and uniform. */
65
+ dispose(): void;
66
+ [Symbol.dispose]: () => void;
67
+ }
68
+ /**
69
+ * The fields into `texels` RGBA8 texels over `origin` and `size`: each texel whose centre lies in a field (even-odd,
70
+ * scanline) holds the field's direction as cos, sin in [0, 1], its contrast and its spacing over MAX_SPACING; a later
71
+ * field wins where outlines overlap.
72
+ */
73
+ export declare function rasterise(fields: readonly FurrowField[], origin: Pair, size: Pair, texels: Pair): Uint8Array;
74
+ export {};
@@ -0,0 +1,157 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const t=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { t as e } from "./require-webgpu--tUXPsmA.js";
5
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
+ import { MargoError as n } from "@margoengine/math/errors";
7
+ //#region src/furrows.ts
8
+ var r = "@fragment fn fragment(i:Output)->@location(0) vec4f {", i = "fn terrainColor(position:vec3f,normal:vec3f)->vec3f {", a = 4, o = 40, s = 0, c = class c {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
9
+ #e;
10
+ #t;
11
+ #n;
12
+ #r;
13
+ #i;
14
+ #a;
15
+ #o;
16
+ #s;
17
+ #c;
18
+ constructor(e, t) {
19
+ if (this.name = `field-furrows:${s++}`, this.disposed = !1, this.#s = /* @__PURE__ */ new Float32Array(8), this.#c = /* @__PURE__ */ new Map(), !e || typeof e.addLighting != "function") throw TypeError("FieldFurrows needs a clipmap Terrain (@margoengine/terrain); pass the terrain to attach");
20
+ let n = t?.fields;
21
+ if (!Array.isArray(n)) throw TypeError("FieldFurrows needs fields: an array of {outline, furrow}");
22
+ let r = Infinity, i = Infinity, o = -Infinity, c = -Infinity;
23
+ for (let [e, t] of n.entries()) {
24
+ if (!t || !Array.isArray(t.outline) || t.outline.length < 3) throw RangeError(`FieldFurrows fields[${e}] needs an outline of 3 or more [x, z] points`);
25
+ for (let n of t.outline) {
26
+ if (!Array.isArray(n) || !Number.isFinite(n[0]) || !Number.isFinite(n[1])) throw RangeError(`FieldFurrows fields[${e}].outline holds a point that is not a finite [x, z]`);
27
+ r = Math.min(r, n[0]), i = Math.min(i, n[1]), o = Math.max(o, n[0]), c = Math.max(c, n[1]);
28
+ }
29
+ if (!Number.isFinite(t.furrow)) throw RangeError(`FieldFurrows fields[${e}].furrow must be a finite angle`);
30
+ let n = t.spacing ?? .35, s = t.depth ?? .25;
31
+ if (!(n >= .05 && n <= a)) throw RangeError(`FieldFurrows fields[${e}].spacing must be 0.05 to ${a} m`);
32
+ if (!(s >= 0 && s <= 1)) throw RangeError(`FieldFurrows fields[${e}].depth must be 0 to 1`);
33
+ }
34
+ let u = t.texel ?? 4;
35
+ if (!(u >= .5 && u <= 64)) throw RangeError("FieldFurrows texel must be 0.5 to 64 m");
36
+ let d = t.binding ?? 118;
37
+ if (!Number.isInteger(d) || d < 0 || d > 998) throw RangeError("FieldFurrows binding must be an integer 0 to 998");
38
+ if (this.origin = t.origin ?? (n.length ? [r, i] : [0, 0]), this.size = t.size ?? (n.length ? [Math.max(o - r, u), Math.max(c - i, u)] : [u, u]), ![...this.origin, ...this.size].every(Number.isFinite) || !(this.size[0] > 0 && this.size[1] > 0)) throw RangeError("FieldFurrows needs a finite origin and a positive size");
39
+ if (this.texels = [Math.max(1, Math.ceil(this.size[0] / u)), Math.max(1, Math.ceil(this.size[1] / u))], this.texels[0] > 8192 || this.texels[1] > 8192) throw RangeError("FieldFurrows covers more than 8,192 texels a side; raise texel");
40
+ this.binding = d, this.#e = e, this.#o = l(n, this.origin, this.size, this.texels);
41
+ }
42
+ static attach(e, n, r) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
43
+ let i = new c(n, r);
44
+ return t(e).use(i), i;
45
+ }
46
+ at(e, t) {
47
+ let [n, r] = this.texels, i = Math.floor((e - this.origin[0]) / this.size[0] * n), o = Math.floor((t - this.origin[1]) / this.size[1] * r);
48
+ if (i < 0 || o < 0 || i >= n || o >= r) return null;
49
+ let s = (o * n + i) * 4, c = this.#o;
50
+ return c[s + 2] ? {
51
+ direction: [c[s] / 255 * 2 - 1, c[s + 1] / 255 * 2 - 1],
52
+ depth: c[s + 2] / 255,
53
+ spacing: c[s + 3] / 255 * a
54
+ } : null;
55
+ }
56
+ get owner() {
57
+ return this.#t;
58
+ }
59
+ setup(t) {
60
+ if (e(t, "FieldFurrows"), this.disposed) throw new n("disposed", "These FieldFurrows were disposed; attach new ones");
61
+ this.#t = t, this.#l(t.gpu), this.#n ??= this.#e.addLighting(this);
62
+ }
63
+ onDeviceRestored(e) {
64
+ this.#l(e.gpu);
65
+ }
66
+ #l(e) {
67
+ let [t, n] = this.texels;
68
+ this.#r = e.createBuffer({
69
+ size: 32,
70
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
71
+ }), this.#i = e.createTexture({
72
+ size: [t, n],
73
+ format: "rgba8unorm",
74
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
75
+ }), e.queue.writeTexture({ texture: this.#i }, this.#o, { bytesPerRow: t * 4 }, [t, n]), this.#a = this.#i.createView();
76
+ }
77
+ bindings() {
78
+ let e = this.#t, t = e?.gpu;
79
+ if (!t || !this.#r || !this.#a) return [];
80
+ let n = e, r = (n.camera?.fov ?? 45) * Math.PI / 180, i = n.canvas?.height || 1080, a = this.#e?.options?.origin ?? [0, 0];
81
+ return this.#s.set([
82
+ this.origin[0] - a[0],
83
+ this.origin[1] - a[1],
84
+ this.size[0],
85
+ this.size[1],
86
+ 2 * Math.tan(r / 2) / i,
87
+ a[0],
88
+ a[1],
89
+ 0
90
+ ]), t.queue.writeBuffer(this.#r, 0, this.#s), [{
91
+ binding: this.binding,
92
+ resource: this.#a
93
+ }, {
94
+ binding: this.binding + 1,
95
+ resource: { buffer: this.#r }
96
+ }];
97
+ }
98
+ shader(e, t) {
99
+ let s = t + e, c = this.#c.get(s);
100
+ if (c) return c;
101
+ if (e.split(r).length !== 2 || e.split(i).length !== 2) throw new n("unsupported", "FieldFurrows needs the terrain's lit fragment shader and its terrainColor; attach it before effects that replace them");
102
+ let l = "_f" + this.name.slice(this.name.indexOf(":") + 1), u = this.binding, d = `
103
+ @group(${t}) @binding(${u}) var furrowField${l}:texture_2d<f32>;
104
+ @group(${t}) @binding(${u + 1}) var<uniform> furrowLook${l}:array<vec4f,2>;
105
+ fn furrowAt${l}(p:vec3f)->f32 {
106
+ let L=furrowLook${l};let local=p.xz-frame.map.xy;let uv=(local-L[0].xy)/L[0].zw;
107
+ if(any(uv<vec2f(0))||any(uv>=vec2f(1))){return 1.0;}
108
+ let n=vec2i(textureDimensions(furrowField${l}));let t=textureLoad(furrowField${l},min(vec2i(uv*vec2f(n)),n-1),0);
109
+ if(t.b<=0.0){return 1.0;}
110
+ let dir=t.rg*2.0-1.0;let across=vec2f(-dir.y,dir.x);let spacing=max(t.a*${a.toFixed(1)},0.05);
111
+ let foot=distance(frame.eye.xyz,p)*L[1].x;let seen=smoothstep(1.5,4.0,spacing/max(foot,1e-6));
112
+ let w=dot(local+L[1].yz,across);let land=spacing*${o.toFixed(1)};
113
+ let wide=smoothstep(1.5,4.0,land/max(foot,1e-6));
114
+ return 1.0+t.b*(seen*cos(6.2831853*w/spacing)+0.5*wide*cos(6.2831853*w/land));
115
+ }
116
+ ` + e.replace(i, `fn terrainColorPlain${l}(position:vec3f,normal:vec3f)->vec3f {`) + `\n${i}return terrainColorPlain${l}(position,normal)*furrowAt${l}(position);}`;
117
+ return this.#c.size >= 16 && this.#c.clear(), this.#c.set(s, d), d;
118
+ }
119
+ dispose() {
120
+ if (this.disposed) return;
121
+ this.disposed = !0, this.#n?.(), this.#n = void 0, this.#r?.destroy(), this.#i?.destroy(), this.#r = this.#i = void 0, this.#a = void 0, this.#c.clear();
122
+ let e = this.#t;
123
+ this.#t = void 0, this.#e = void 0, e?.sceneOf(this)?.removePlugin(this.name);
124
+ }
125
+ [Symbol.dispose ?? Symbol()]() {
126
+ this.dispose();
127
+ }
128
+ };
129
+ function l(e, t, n, r) {
130
+ let [i, o] = r, s = new Uint8Array(i * o * 4), c = n[0] / i, l = n[1] / o, u = (e) => Math.max(0, Math.min(255, Math.round(e * 255)));
131
+ for (let n of e) {
132
+ let e = n.outline, r = u(Math.cos(n.furrow) * .5 + .5), d = u(Math.sin(n.furrow) * .5 + .5), f = u(n.depth ?? .25), p = u((n.spacing ?? .35) / a);
133
+ if (!f) continue;
134
+ let m = Infinity, h = -Infinity;
135
+ for (let t of e) m = Math.min(m, t[1]), h = Math.max(h, t[1]);
136
+ let g = Math.max(0, Math.floor((m - t[1]) / l)), _ = Math.min(o - 1, Math.ceil((h - t[1]) / l)), v = [];
137
+ for (let n = g; n <= _; n++) {
138
+ let a = t[1] + (n + .5) * l;
139
+ v.length = 0;
140
+ for (let t = 0; t < e.length; t++) {
141
+ let n = e[t], r = e[(t + 1) % e.length];
142
+ n[1] <= a != r[1] <= a && v.push(n[0] + (a - n[1]) / (r[1] - n[1]) * (r[0] - n[0]));
143
+ }
144
+ v.sort((e, t) => e - t);
145
+ for (let e = 0; e + 1 < v.length; e += 2) {
146
+ let a = Math.max(0, Math.ceil((v[e] - t[0]) / c - .5)), o = Math.min(i - 1, Math.floor((v[e + 1] - t[0]) / c - .5));
147
+ for (let e = a; e <= o; e++) {
148
+ let t = (n * i + e) * 4;
149
+ s[t] = r, s[t + 1] = d, s[t + 2] = f, s[t + 3] = p;
150
+ }
151
+ }
152
+ }
153
+ }
154
+ return s;
155
+ }
156
+ //#endregion
157
+ export { c as FieldFurrows, l as rasterise };
package/dist/grid.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The fixed clipmap grid `Terrain` draws: `(resolution + 1)²` XZ corner vertices centred on the origin (one unit apart),
3
+ * then one vertex at the centre of every cell (`resolution²` more, at half-unit offsets), and two triangle index lists:
4
+ * `center`, every cell (the finest level), and `ring`, the cells outside the middle half-by-half block (three quarters
5
+ * of the grid, drawn by every coarser level). Each cell is a fan of four triangles around its centre vertex, counter-
6
+ * clockwise seen from above like the cell's two triangles were; the vertex shader puts the centre on the midpoint of the
7
+ * diagonal that follows the ground (`terrainVertex`), so the four draw the cell split along that diagonal.
8
+ * @throws RangeError unless `resolution` is a multiple of 4 from 8 to 256.
9
+ */
10
+ export declare function clipmapGrid(resolution: number): {
11
+ vertices: Float32Array;
12
+ center: Uint32Array;
13
+ ring: Uint32Array;
14
+ };