roamwright 0.61.29 → 0.61.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Road convoy rendering and lifecycle controller paired with `createRoadTraffic`: registers convoy travellers
3
+ * into a world's crowd system, lazily raises instanced horses, oxen, carts and wagons when the viewer approaches,
4
+ * warms vehicle shaders before first draw, and updates every convoy member per frame with zero allocations.
5
+ * @module
6
+ */
7
+
8
+ import * as THREE from 'three';
9
+ import { mulberry32 } from '../math/random.js';
10
+ import { ROAD_TRAFFIC, createRoadTraffic } from '../motion/road-traffic.js';
11
+
12
+ /**
13
+ * Default ox coat colours (sRGB hex) assigned randomly to draught teams pulling carts and wagons.
14
+ */
15
+ export const DEFAULT_TRAFFIC_OXEN = Object.freeze([0x8a6a4a, 0x6a5040, 0xb0a090, 0x5a4232, 0x9a8a70]);
16
+
17
+ /**
18
+ * Number of draught oxen harnessed to each vehicle kind.
19
+ */
20
+ export const OXEN_DRAWING = Object.freeze({ cart: 1, wagon: 2 });
21
+
22
+ /**
23
+ * Builds a road-traffic convoy renderer and per-frame updater for one land or space.
24
+ *
25
+ * Each entry `[roadId, convoyKind]` places a convoy from `specs[convoyKind]` along `roads`, registers its walkers and
26
+ * riders with `addCrowd`, and lazily invokes `loadAssets()` once the camera comes within `raise` metres of any convoy.
27
+ * Vehicle groups are warmed through `warmShaders` on the first frame a cart or wagon is seen.
28
+ *
29
+ * @param {object} options
30
+ * @param {Array<[string, string]>} options.entries Pairs `[roadId, convoyKind]` to populate on the land's roads.
31
+ * @param {Record<string, { pace: number, body?: string, members: Array<[string, number, number]> }>} options.specs Convoy templates keyed by `convoyKind`.
32
+ * @param {Array<{ id: string, pts: Array<[number, number]> }>} options.roads Road polylines with ids matching `entries`.
33
+ * @param {(x: number, z: number) => number} options.ground Surface elevation sampler in metres.
34
+ * @param {THREE.Group} options.group Parent group receiving the lazily raised convoy mounts, herd and vehicles group.
35
+ * @param {THREE.Camera} options.camera Viewer camera whose position controls lazy raise and draw distance.
36
+ * @param {(people: object[], tones: number[], cx: number, cz: number, near: number, kind: string, beasts: unknown, spaceId: string) => object} options.addCrowd Crowd registration callback that converts traveller specs into live crowd figures in place.
37
+ * @param {() => Promise<{ makeHerd?: Function, makeMounts?: Function, orderBeasts?: Function, makeVehicles?: Function }> | { makeHerd?: Function, makeMounts?: Function, orderBeasts?: Function, makeVehicles?: Function }} [options.loadAssets=() => ({})] Lazy loader returning the beast and vehicle instancing builders; a vehicle or beast with no builder is not drawn.
38
+ * @param {string} [options.spaceId='world'] Space identifier forwarded to `addCrowd`.
39
+ * @param {() => number} [options.random] Repeatable PRNG stream for convoy spacing, traveller variation and coat picks.
40
+ * @param {number[]} [options.tones] Garment palette (sRGB hex) forwarded to `addCrowd`.
41
+ * @param {((crowd: object, bodyId: string) => void) | null} [options.nameBody=null] Optional nameplate binder for convoys whose spec sets `body`.
42
+ * @param {(rank: number) => boolean} [options.isTravelling] Daily schedule predicate receiving convoy `rank` in `[0, 1)`.
43
+ * @param {(x: number, y: number, z: number, radius: number, shadow: boolean, exact: boolean) => boolean} [options.inView] Frustum/visibility test for individual convoy members.
44
+ * @param {(group: THREE.Group) => Promise<void>} [options.warmShaders] Async shader warm-up hook called before vehicle meshes enter the scene.
45
+ * @param {Array<number | THREE.Color>} [options.oxCoats=DEFAULT_TRAFFIC_OXEN] Draught ox coat colours.
46
+ * @param {number} [options.drawn=ROAD_TRAFFIC.drawn] Distance in metres from `camera` within which beasts and vehicles draw.
47
+ * @param {number} [options.raise=ROAD_TRAFFIC.raise] Distance in metres from `camera` that triggers `loadAssets()`.
48
+ * @param {number} [options.minSpan=30] Minimum usable road length (after trimming both ends) in metres.
49
+ * @param {object} [options.trafficOptions] Optional parameters forwarded to `createRoadTraffic`.
50
+ * @returns {{ tick: (dt: number) => void, convoys: object[], dispose: () => void } | null}
51
+ */
52
+ export function createRoadTrafficRenderer({
53
+ entries,
54
+ specs,
55
+ roads,
56
+ ground,
57
+ group,
58
+ camera,
59
+ addCrowd,
60
+ loadAssets = () => ({}),
61
+ spaceId = 'world',
62
+ random = mulberry32(61),
63
+ tones = [0x8a6a48, 0x6a5a44, 0x7a6a4a],
64
+ nameBody = null,
65
+ isTravelling = () => true,
66
+ inView = () => true,
67
+ warmShaders = () => Promise.resolve(),
68
+ oxCoats = DEFAULT_TRAFFIC_OXEN,
69
+ drawn: drawnRange = ROAD_TRAFFIC.drawn,
70
+ raise: raiseRange = ROAD_TRAFFIC.raise,
71
+ minSpan = 30,
72
+ trafficOptions = {},
73
+ }) {
74
+ if (!entries?.length) return null;
75
+
76
+ const { road: roadOf, setOut, traveller: travellerOf, placeOn, goOn } = createRoadTraffic(trafficOptions),
77
+ trim = trafficOptions.trim ?? ROAD_TRAFFIC.trim,
78
+ team = ROAD_TRAFFIC.team,
79
+ shafts = ROAD_TRAFFIC.shafts,
80
+ drawnSq = drawnRange * drawnRange,
81
+ raiseSq = raiseRange * raiseRange,
82
+ oxen = oxCoats.map(c => (c && c.isColor ? c : new THREE.Color(c))),
83
+ byId = new Map(),
84
+ onRoad = new Map(), // convoys per road so each sets out spaced along it
85
+ convoys = [],
86
+ folk = [], // travellers of every unnamed convoy share one crowd
87
+ named = [], // each convoy with a spec `body` gets its own crowd for its nameplate
88
+ counts = { cart: 0, wagon: 0, rider: 0, walker: 0, ox: 0 };
89
+
90
+ for (let i = 0; i < entries.length; i++) {
91
+ const id = entries[i][0];
92
+ onRoad.set(id, (onRoad.get(id) ?? 0) + 1);
93
+ }
94
+ const placed = new Map();
95
+ for (let i = 0; i < entries.length; i++) {
96
+ const [id, kind] = entries[i],
97
+ r = roads.find(q => q.id === id),
98
+ k = placed.get(id) ?? 0;
99
+ placed.set(id, k + 1);
100
+ if (!r) continue;
101
+ if (!byId.has(id)) byId.set(id, roadOf(r.pts, ground));
102
+ const road = byId.get(id),
103
+ spec = specs[kind],
104
+ span = road.way.length - 2 * trim;
105
+ if (!spec || span < minSpan) continue;
106
+ const c = setOut(road, spec.pace, { order: k, count: onRoad.get(id), random });
107
+ c.spec = spec;
108
+ c.members = [];
109
+ let front = -Infinity,
110
+ back = Infinity;
111
+ for (let j = 0; j < spec.members.length; j++) {
112
+ const ahead = spec.members[j][1];
113
+ if (ahead > front) front = ahead;
114
+ if (ahead < back) back = ahead;
115
+ }
116
+ c.front = front;
117
+ c.back = back;
118
+ const people = spec.body ? [] : folk;
119
+ if (spec.body) named.push({ people, body: spec.body });
120
+ for (let j = 0; j < spec.members.length; j++) {
121
+ const [what, ahead, side] = spec.members[j],
122
+ m = { what, ahead, side, figure: null, people, at: 0, coat: (random() * 97) | 0, tint: oxen[(random() * oxen.length) | 0] };
123
+ c.members.push(m);
124
+ if (what === 'walker' || what === 'rider') {
125
+ m.at = people.length;
126
+ people.push((m.figure = travellerOf(what, spec.pace, random)));
127
+ }
128
+ counts[what] = (counts[what] ?? 0) + 1;
129
+ counts.ox += OXEN_DRAWING[what] ?? 0;
130
+ }
131
+ convoys.push(c);
132
+ }
133
+ if (!convoys.length) return null;
134
+
135
+ if (folk.length) addCrowd(folk, tones, 0, 0, Infinity, 'plain', null, spaceId);
136
+ for (let i = 0; i < named.length; i++) {
137
+ const crowd = addCrowd(named[i].people, tones, 0, 0, Infinity, 'plain', null, spaceId);
138
+ if (nameBody) nameBody(crowd, named[i].body);
139
+ }
140
+ // Each crowd replaced its traveller entries with live crowd figures: keep direct references.
141
+ for (let i = 0; i < convoys.length; i++) {
142
+ const members = convoys[i].members;
143
+ for (let j = 0; j < members.length; j++) if (members[j].figure) members[j].figure = members[j].people[members[j].at];
144
+ }
145
+ const everyone = folk.concat(...named.map(n => n.people));
146
+
147
+ let drawn = null,
148
+ asked = false,
149
+ disposed = false;
150
+
151
+ const raise = async () => {
152
+ const { makeHerd, makeMounts, orderBeasts, makeVehicles } = await loadAssets();
153
+ if (disposed) return;
154
+ const beasts = orderBeasts ? orderBeasts() : null,
155
+ convoy = new THREE.Group(),
156
+ vehicles = new THREE.Group(),
157
+ carts = counts.cart && makeVehicles ? makeVehicles(vehicles, counts.cart, 'cart', random) : null,
158
+ wagons = counts.wagon && makeVehicles ? makeVehicles(vehicles, counts.wagon, 'wagon', random) : null;
159
+ await beasts;
160
+ if (disposed) return;
161
+ let preparing;
162
+ drawn = {
163
+ convoy,
164
+ mounts: counts.rider && makeMounts ? makeMounts(convoy, counts.rider, 0) : null,
165
+ herd: counts.ox && makeHerd ? makeHerd(convoy, counts.ox) : null,
166
+ carts,
167
+ wagons,
168
+ vehiclesReady: false,
169
+ prepareVehicles() {
170
+ // A passing rider can raise the convoy while every cart is outside the view.
171
+ preparing ??= warmShaders(vehicles).then(() => {
172
+ if (disposed) return;
173
+ convoy.add(vehicles);
174
+ drawn.vehiclesReady = true;
175
+ });
176
+ },
177
+ };
178
+ group.add(convoy);
179
+ // A rider is drawn from the frame there is a horse under them (`out: -1` lets the crowd show them at once).
180
+ for (let i = 0; i < everyone.length; i++) {
181
+ const f = everyone[i];
182
+ if (f.mounted) {
183
+ f.home = undefined;
184
+ f.out = -1;
185
+ }
186
+ }
187
+ everyone.length = 0; // release the setup-only traveller list once riders are revealed
188
+ };
189
+
190
+ function drawVehicle(c, m, p) {
191
+ if (!drawn.vehiclesReady) {
192
+ drawn.prepareVehicles();
193
+ return;
194
+ }
195
+ const { x, y, z, yaw } = p;
196
+ // a builder a world left out draws nothing of its kind: the people still walk
197
+ if (m.what === 'cart') {
198
+ drawn.carts?.vehicle(x, y, z, yaw, c.travel);
199
+ const ox = placeOn(c, m.ahead + shafts, m.side);
200
+ drawn.herd?.beast(ox.x, ox.y, ox.z, ox.yaw, c.v, c.travel, m.tint, 1);
201
+ return;
202
+ }
203
+ drawn.wagons?.vehicle(x, y, z, yaw, c.travel);
204
+ for (let side = -1; side <= 1; side += 2) {
205
+ const ox = placeOn(c, m.ahead + team.ahead, m.side + team.apart * side);
206
+ drawn.herd?.beast(ox.x, ox.y, ox.z, ox.yaw, c.v, c.travel + side * 0.3, m.tint, 1);
207
+ }
208
+ }
209
+
210
+ function moveMembers(c) {
211
+ const show = drawn && c.near,
212
+ members = c.members;
213
+ for (let i = 0; i < members.length; i++) {
214
+ const m = members[i],
215
+ p = placeOn(c, m.ahead, m.side),
216
+ seen = show && inView(p.x, p.y + 1, p.z, 3.4, false, true);
217
+ if (m.figure) {
218
+ const g = m.figure;
219
+ g.ax = p.x;
220
+ g.az = p.z;
221
+ g.yaw = p.yaw;
222
+ g.speed = c.v; // walking at the convoy's pace, or standing (0)
223
+ g.travel = c.travel + g.ph;
224
+ if (m.what === 'rider' && seen) drawn.mounts?.horse(p.x, p.y, p.z, p.yaw, c.v, c.travel + g.ph, m.coat, g.s, 0);
225
+ } else if (seen) drawVehicle(c, m, p);
226
+ }
227
+ }
228
+
229
+ function tick(dt) {
230
+ if (disposed) return;
231
+ const cx = camera.position.x,
232
+ cz = camera.position.z;
233
+ if (drawn) {
234
+ drawn.mounts?.begin();
235
+ drawn.herd?.begin();
236
+ drawn.carts?.begin();
237
+ drawn.wagons?.begin();
238
+ }
239
+ for (let i = 0; i < convoys.length; i++) {
240
+ const c = convoys[i],
241
+ head = placeOn(c, 0, 0),
242
+ d2 = (head.x - cx) ** 2 + (head.z - cz) ** 2;
243
+ if (!asked && d2 < raiseSq) {
244
+ asked = true;
245
+ raise();
246
+ }
247
+ c.near = d2 < drawnSq;
248
+ goOn(c, dt, convoys, isTravelling(c.rank));
249
+ moveMembers(c);
250
+ }
251
+ if (drawn) {
252
+ drawn.mounts?.end();
253
+ drawn.herd?.end();
254
+ drawn.carts?.end();
255
+ drawn.wagons?.end();
256
+ }
257
+ }
258
+
259
+ function dispose() {
260
+ disposed = true;
261
+ if (drawn?.convoy) group.remove(drawn.convoy);
262
+ drawn = null;
263
+ everyone.length = 0;
264
+ convoys.length = 0;
265
+ }
266
+
267
+ return { tick, convoys, dispose };
268
+ }
@@ -7,6 +7,7 @@
7
7
  import * as THREE from 'three';
8
8
  import { createUnitShapes } from '../geometry/primitives.js';
9
9
  import { buildLampStandGeometry, buildWallLanternGeometry } from '../geometry/ruins-masonry.js';
10
+ import { flatFittingGeometry, glowMesh, lightPoolMaterial } from './glow-mesh.js';
10
11
  import { falloffAt, pixelTexture } from './textures.js';
11
12
 
12
13
  /** Default parameters for additive radial ground light pools built by {@link addLightPool}. */
@@ -44,7 +45,7 @@ export function createLightPoolTexture({ size = LIGHT_POOL.size, falloff = LIGHT
44
45
 
45
46
  /**
46
47
  * Place a soft additive pool of warm light lying flat on the ground at `(x, y, z)` so unlit street
47
- * lanterns read warmly without extra dynamic point lights.
48
+ * lanterns read warmly without extra dynamic point lights. The plane and material are shared. Clone them before editing.
48
49
  *
49
50
  * @param {THREE.Object3D} group - Destination scene or group.
50
51
  * @param {number} x - World X position in metres.
@@ -69,15 +70,8 @@ export function addLightPool(group, x, y, z, radius, options = {}) {
69
70
  fogFades = false,
70
71
  } = options;
71
72
  const map = options.texture ?? (defaultPoolTexture ??= createLightPoolTexture());
72
- const material = new THREE.MeshBasicMaterial({
73
- map,
74
- color: new THREE.Color(hex).multiplyScalar(strength),
75
- blending: THREE.AdditiveBlending,
76
- depthWrite: false,
77
- transparent: true,
78
- });
79
- if (fogFades) material.defines = { FOG_FADES: '' };
80
- const pool = new THREE.Mesh(new THREE.PlaneGeometry(1, 1).rotateX(-Math.PI / 2), material);
73
+ const material = lightPoolMaterial(hex, strength, map, fogFades);
74
+ const pool = new THREE.Mesh(flatFittingGeometry('plane', 1, 1), material);
81
75
  pool.position.set(x, y + lift, z);
82
76
  pool.scale.set(radius * 2, 1, radius * 2);
83
77
  pool.renderOrder = renderOrder;
@@ -140,7 +134,7 @@ export function addStillPool(group, options = {}) {
140
134
  new THREE.MeshStandardMaterial(
141
135
  transparent ? { color, roughness, metalness, transparent: true, opacity } : { color, roughness, metalness },
142
136
  );
143
- const geo = new THREE.CircleGeometry(radius ?? 0.5, segments).rotateX(-Math.PI / 2);
137
+ const geo = flatFittingGeometry('circle', radius ?? 0.5, segments);
144
138
  const water = new THREE.Mesh(geo, mat);
145
139
  water.position.set(origin.x + x, y, origin.z + z);
146
140
  if (radius === null) water.scale.set(width, 1, depth);
@@ -197,13 +191,7 @@ export function addFlame(group, options = {}) {
197
191
  onSite = null,
198
192
  space = 'world',
199
193
  } = options;
200
- const core = makeGlowMesh
201
- ? makeGlowMesh(shapes.sph, color, boost, group)
202
- : (() => {
203
- const m = new THREE.Mesh(shapes.sph, new THREE.MeshBasicMaterial({ color: new THREE.Color(color).multiplyScalar(boost) }));
204
- if (group) group.add(m);
205
- return m;
206
- })();
194
+ const core = (makeGlowMesh ?? glowMesh)(shapes.sph, color, boost, group);
207
195
  core.position.set(origin.x + x, y, origin.z + z);
208
196
  core.scale.set(size * 0.5, size * 1.1, size * 0.5);
209
197
  const lamp = size < lampSize;
@@ -277,13 +265,7 @@ export function addWallLantern(kit, options) {
277
265
  onSite = null,
278
266
  } = options;
279
267
  const lantern = buildWallLanternGeometry(kit, { ...options, shapes });
280
- const horn = makeGlowMesh
281
- ? makeGlowMesh(shapes.cyl6, 0xffb860, 1.15, group)
282
- : (() => {
283
- const m = new THREE.Mesh(shapes.cyl6, new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffb860).multiplyScalar(1.15) }));
284
- group.add(m);
285
- return m;
286
- })();
268
+ const horn = (makeGlowMesh ?? glowMesh)(shapes.cyl6, 0xffb860, 1.15, group);
287
269
  horn.position.set(origin.x + lantern.x, lantern.y - 0.135, origin.z + lantern.z);
288
270
  horn.scale.set(0.14, 0.27, 0.14);
289
271
  onSite?.(origin.x + lantern.x, lantern.y - 0.05, origin.z + lantern.z);
@@ -1,4 +1,5 @@
1
1
  import * as THREE from 'three';
2
+ import { releaseArray } from '../geometry/builder.js';
2
3
 
3
4
  /**
4
5
  * The vertex stage of bedded rock laid over a land in tiles (`createStrataTiles`): it moves each vertex between levels of
@@ -77,6 +78,7 @@ void cliffMorph() {
77
78
  * @param {(options: { level: number, uniforms: object, vertex: string }) => { material: import('three').Material, depth: import('three').Material }} options.material -
78
79
  * The picture's material and shadow-depth material of one level, made for `level` with the shared uniforms and the vertex
79
80
  * stage (`createStrataMaterial`).
81
+ * @param {boolean} [options.releaseAfterUpload=false] - Drop box vertex and index arrays after upload when ground queries use the field alone.
80
82
  * @param {() => number} [options.lodScale=() => 1] - A quality setting that stretches or shrinks every distance.
81
83
  * @param {{ pooled: () => boolean, size: () => number, prepare: Function, run: Function, spread: Function }} [options.pool] -
82
84
  * A worker pool (`createPool`): without one, or once one fails, every box is built on the page.
@@ -109,6 +111,7 @@ export function createStrataCliffs({
109
111
  parent,
110
112
  material,
111
113
  lodScale = () => 1,
114
+ releaseAfterUpload = false,
112
115
  pool = { pooled: () => false, size: () => 0, prepare() {}, run: () => Promise.reject(), spread() {} },
113
116
  budget = {
114
117
  task:
@@ -145,6 +148,7 @@ export function createStrataCliffs({
145
148
  const asked = new Set(); // the boxes being built, by level and key ('1/3:4'), until their meshes stand
146
149
  const answers = []; // boxes the pool has built, to be meshed one a frame: [level, key, arrays]
147
150
  let coarse = null, // the promise of the coarse level's arrays, box by box, once begun
151
+ built = null, // concurrent callers share one build after the coarse arrays have been consumed
148
152
  planned = null, // the promise of the plan: where the rock stands and its tiles
149
153
  mats = null,
150
154
  job = null, // a box the page builds itself, a slice a frame: { lv, key, it }
@@ -162,6 +166,10 @@ export function createStrataCliffs({
162
166
  geo.setIndex(new THREE.BufferAttribute(index, 1));
163
167
  geo.computeBoundingSphere();
164
168
  geo.boundingSphere.radius += 8;
169
+ if (releaseAfterUpload) {
170
+ for (const attribute of Object.values(geo.attributes)) attribute.onUpload(releaseArray);
171
+ geo.index.onUpload(releaseArray);
172
+ }
165
173
  const mesh = new THREE.Mesh(geo, mats[lv].material);
166
174
  mesh.customDepthMaterial = mats[lv].depth;
167
175
  mesh.castShadow = true;
@@ -189,6 +197,7 @@ export function createStrataCliffs({
189
197
  // plan the rock and build those boxes while the page goes on with the land's other builders. The page takes the plan from
190
198
  // the worker that made it (or makes it itself where there are none).
191
199
  function begin() {
200
+ if (planned) return;
192
201
  // what a worker shapes the rock from, as the page has it now (a worker works the normals and slopes out from the heights:
193
202
  // less to copy each time this is sent)
194
203
  if (!onPage) pool.prepare(jobs.preparation, preparation(), preparationCost);
@@ -217,17 +226,31 @@ export function createStrataCliffs({
217
226
  }
218
227
  // The rock's materials and ground; the promise is kept once the coarse level stands, meshed in the order of its boxes.
219
228
  function build() {
220
- const hm = new THREE.DataTexture(heights.data, heights.side + 1, heights.side + 1, THREE.RedFormat, THREE.FloatType);
221
- hm.needsUpdate = true;
222
- const sh = new THREE.DataTexture(shown, TILES_SIDE, TILES_SIDE, THREE.RedFormat, THREE.FloatType);
223
- sh.needsUpdate = true;
224
- uniforms.uHM.value = hm;
225
- uniforms.uShown.value = sh;
226
- mats = [0, 1, 2].map(level => material({ level, uniforms, vertex }));
227
- onBuilt(ground);
228
- return coarse.then(([keys, arrays]) => {
229
- keys.forEach((key, i) => meshBox(2, key, arrays[i]));
230
- });
229
+ if (built) return built;
230
+ if (!planned) begin();
231
+ if (!mats) {
232
+ const hm = new THREE.DataTexture(heights.data, heights.side + 1, heights.side + 1, THREE.RedFormat, THREE.FloatType);
233
+ hm.needsUpdate = true;
234
+ const sh = new THREE.DataTexture(shown, TILES_SIDE, TILES_SIDE, THREE.RedFormat, THREE.FloatType);
235
+ sh.needsUpdate = true;
236
+ uniforms.uHM.value = hm;
237
+ uniforms.uShown.value = sh;
238
+ mats = [0, 1, 2].map(level => material({ level, uniforms, vertex }));
239
+ onBuilt(ground);
240
+ }
241
+ built = coarse
242
+ .then(([keys, arrays]) => {
243
+ for (let i = 0; i < keys.length; i++) {
244
+ if (!boxes[2].has(keys[i])) meshBox(2, keys[i], arrays[i]);
245
+ arrays[i] = null;
246
+ }
247
+ coarse = null;
248
+ })
249
+ .catch(error => {
250
+ planned = coarse = built = null;
251
+ throw error;
252
+ });
253
+ return built;
231
254
  }
232
255
  // The ground is the rock where a cliff stands proud of the terrain, so nobody walks inside it: find the point of the rock
233
256
  // surface (at the 1 m level) that lies over (x, z) by stepping its ground point until it lands there.
@@ -55,6 +55,8 @@ function canvasTexture(canvas, options = {}) {
55
55
  function onCardOnly(texture) {
56
56
  texture.onUpdate = () => {
57
57
  texture.image.data = null;
58
+ // A hand-built mip chain keeps its own pixel arrays, including another reference to level zero.
59
+ for (const mip of texture.mipmaps) if (ArrayBuffer.isView(mip.data)) mip.data = null;
58
60
  texture.onUpdate = null;
59
61
  };
60
62
  return texture;