@adatechnology/game-terrain-three 0.1.1 → 0.2.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/dist/index.d.ts +5 -1
- package/dist/index.global.js +264 -42
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +224 -42
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -87,18 +87,33 @@ function vertexLook(terrain, column, row, base, shade) {
|
|
|
87
87
|
shade[1] = terrain.scorch[index];
|
|
88
88
|
return patternIndex(broken ? "soil" : material.pattern);
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function chunkVertexCount(terrain, chunk, step) {
|
|
91
|
+
const lastColumn = Math.min(terrain.columns, chunk.column + chunk.cells);
|
|
92
|
+
const lastRow = Math.min(terrain.rows, chunk.row + chunk.cells);
|
|
93
|
+
return (Math.ceil((lastColumn - chunk.column) / step) + 1) * (Math.ceil((lastRow - chunk.row) / step) + 1);
|
|
94
|
+
}
|
|
95
|
+
function attributeArray(geometry, name) {
|
|
96
|
+
return geometry.getAttribute(name).array;
|
|
97
|
+
}
|
|
98
|
+
function refreshAttributes(geometry, names) {
|
|
99
|
+
for (const name of names) geometry.getAttribute(name).needsUpdate = true;
|
|
100
|
+
geometry.boundingSphere = null;
|
|
101
|
+
geometry.boundingBox = null;
|
|
102
|
+
}
|
|
103
|
+
var LOOK_ATTRIBUTES = ["position", "normal", "aBase", "aShade", "aPattern"];
|
|
104
|
+
function buildChunkGeometry(THREE, terrain, chunk, step, reuse) {
|
|
91
105
|
const [x0, z0] = terrain.bounds;
|
|
92
106
|
const { cellSize, columns, rows } = terrain;
|
|
93
107
|
const lastColumn = Math.min(columns, chunk.column + chunk.cells);
|
|
94
108
|
const lastRow = Math.min(rows, chunk.row + chunk.cells);
|
|
95
109
|
const across = Math.ceil((lastColumn - chunk.column) / step) + 1;
|
|
96
110
|
const down = Math.ceil((lastRow - chunk.row) / step) + 1;
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
111
|
+
const target = reuse && reuse.getAttribute("position").count === across * down ? reuse : void 0;
|
|
112
|
+
const positions = target ? attributeArray(target, "position") : new Float32Array(across * down * 3);
|
|
113
|
+
const normals = target ? attributeArray(target, "normal") : new Float32Array(across * down * 3);
|
|
114
|
+
const bases = target ? attributeArray(target, "aBase") : new Float32Array(across * down * 3);
|
|
115
|
+
const shades = target ? attributeArray(target, "aShade") : new Float32Array(across * down * 2);
|
|
116
|
+
const patterns = target ? attributeArray(target, "aPattern") : new Float32Array(across * down);
|
|
102
117
|
const base = [0, 0, 0];
|
|
103
118
|
const shade = [1, 0];
|
|
104
119
|
let at = 0;
|
|
@@ -127,6 +142,10 @@ function buildChunkGeometry(THREE, terrain, chunk, step) {
|
|
|
127
142
|
at++;
|
|
128
143
|
}
|
|
129
144
|
}
|
|
145
|
+
if (target) {
|
|
146
|
+
refreshAttributes(target, LOOK_ATTRIBUTES);
|
|
147
|
+
return target;
|
|
148
|
+
}
|
|
130
149
|
const indices = new Uint32Array((across - 1) * (down - 1) * 6);
|
|
131
150
|
let cursor = 0;
|
|
132
151
|
for (let j = 0; j < down - 1; j++) {
|
|
@@ -152,17 +171,19 @@ function buildChunkGeometry(THREE, terrain, chunk, step) {
|
|
|
152
171
|
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
|
153
172
|
return geometry;
|
|
154
173
|
}
|
|
155
|
-
function buildPristineGeometry(THREE, terrain, chunks, skirt) {
|
|
174
|
+
function buildPristineGeometry(THREE, terrain, chunks, skirt, reuse) {
|
|
156
175
|
const [x0, z0] = terrain.bounds;
|
|
157
176
|
const { cellSize, columns, rows } = terrain;
|
|
158
177
|
const [, , x1, z1] = terrain.bounds;
|
|
159
178
|
const quads = chunks.length + SKIRT_QUADS;
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
179
|
+
const capacity = terrain.chunksX * terrain.chunksZ + SKIRT_QUADS;
|
|
180
|
+
const target = reuse && reuse.getAttribute("position").count === capacity * 4 ? reuse : void 0;
|
|
181
|
+
const positions = target ? attributeArray(target, "position") : new Float32Array(capacity * 12);
|
|
182
|
+
const normals = target ? attributeArray(target, "normal") : new Float32Array(capacity * 12);
|
|
183
|
+
const bases = target ? attributeArray(target, "aBase") : new Float32Array(capacity * 12);
|
|
184
|
+
const shades = target ? attributeArray(target, "aShade") : new Float32Array(capacity * 8);
|
|
185
|
+
const patterns = target ? attributeArray(target, "aPattern") : new Float32Array(capacity * 4);
|
|
186
|
+
const indices = target ? target.getIndex().array : new Uint32Array(capacity * 6);
|
|
166
187
|
const base = [0, 0, 0];
|
|
167
188
|
const shade = [1, 0];
|
|
168
189
|
chunks.forEach((chunk, n) => {
|
|
@@ -196,6 +217,7 @@ function buildPristineGeometry(THREE, terrain, chunks, skirt) {
|
|
|
196
217
|
corners.forEach(([x, z], corner) => {
|
|
197
218
|
const at = n * 4 + corner;
|
|
198
219
|
positions[at * 3] = x;
|
|
220
|
+
positions[at * 3 + 1] = 0;
|
|
199
221
|
positions[at * 3 + 2] = z;
|
|
200
222
|
normals[at * 3 + 1] = 1;
|
|
201
223
|
bases.set(surface.color, at * 3);
|
|
@@ -205,17 +227,24 @@ function buildPristineGeometry(THREE, terrain, chunks, skirt) {
|
|
|
205
227
|
const first = n * 4;
|
|
206
228
|
indices.set([first, first + 2, first + 1, first + 2, first + 3, first + 1], n * 6);
|
|
207
229
|
});
|
|
208
|
-
const geometry = new THREE.BufferGeometry();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
230
|
+
const geometry = target ?? new THREE.BufferGeometry();
|
|
231
|
+
if (target) {
|
|
232
|
+
refreshAttributes(target, LOOK_ATTRIBUTES);
|
|
233
|
+
target.getIndex().needsUpdate = true;
|
|
234
|
+
} else {
|
|
235
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
|
236
|
+
geometry.setAttribute("normal", new THREE.BufferAttribute(normals, 3));
|
|
237
|
+
geometry.setAttribute("aBase", new THREE.BufferAttribute(bases, 3));
|
|
238
|
+
geometry.setAttribute("aShade", new THREE.BufferAttribute(shades, 2));
|
|
239
|
+
geometry.setAttribute("aPattern", new THREE.BufferAttribute(patterns, 1));
|
|
240
|
+
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
|
241
|
+
}
|
|
242
|
+
geometry.setDrawRange(0, quads * 6);
|
|
215
243
|
return geometry;
|
|
216
244
|
}
|
|
217
245
|
|
|
218
246
|
// src/layers.ts
|
|
247
|
+
import { crackLines } from "@adatechnology/game-terrain";
|
|
219
248
|
var MARK_LIFT = 6e-3;
|
|
220
249
|
var MARK_REACH = 1.5;
|
|
221
250
|
var MARK_TEXTURE_SIZE = 64;
|
|
@@ -254,6 +283,7 @@ function createMarkLayer(THREE, terrain, drawDistance) {
|
|
|
254
283
|
mesh.frustumCulled = false;
|
|
255
284
|
mesh.receiveShadow = true;
|
|
256
285
|
mesh.renderOrder = 1;
|
|
286
|
+
mesh.setColorAt(0, new THREE.Color(1, 1, 1));
|
|
257
287
|
const matrix = new THREE.Matrix4();
|
|
258
288
|
const rotation = new THREE.Matrix4();
|
|
259
289
|
const scale = new THREE.Matrix4();
|
|
@@ -306,6 +336,7 @@ function createDebrisLayer(THREE, terrain) {
|
|
|
306
336
|
mesh.count = 0;
|
|
307
337
|
mesh.castShadow = true;
|
|
308
338
|
mesh.frustumCulled = false;
|
|
339
|
+
mesh.setColorAt(0, new THREE.Color(1, 1, 1));
|
|
309
340
|
const matrix = new THREE.Matrix4();
|
|
310
341
|
const position = new THREE.Vector3();
|
|
311
342
|
const scale = new THREE.Vector3();
|
|
@@ -341,12 +372,104 @@ function createDebrisLayer(THREE, terrain) {
|
|
|
341
372
|
}
|
|
342
373
|
};
|
|
343
374
|
}
|
|
375
|
+
var CRACK_LIFT = 4e-3;
|
|
376
|
+
var MAX_CRACK_QUADS = 8192;
|
|
377
|
+
var CRACK_SHADE = 0.22;
|
|
378
|
+
var DARK_SURFACE = 0.1;
|
|
379
|
+
var DUST_LIFT = 2;
|
|
380
|
+
var DUST_GREY = 0.12;
|
|
381
|
+
function createCrackLayer(THREE, terrain) {
|
|
382
|
+
const positions = new Float32Array(MAX_CRACK_QUADS * 4 * 3);
|
|
383
|
+
const colours = new Float32Array(MAX_CRACK_QUADS * 4 * 3);
|
|
384
|
+
const indices = new Uint32Array(MAX_CRACK_QUADS * 6);
|
|
385
|
+
for (let quad = 0; quad < MAX_CRACK_QUADS; quad++) {
|
|
386
|
+
const first = quad * 4;
|
|
387
|
+
indices.set([first, first + 2, first + 1, first + 1, first + 2, first + 3], quad * 6);
|
|
388
|
+
}
|
|
389
|
+
const geometry = new THREE.BufferGeometry();
|
|
390
|
+
const position = new THREE.BufferAttribute(positions, 3);
|
|
391
|
+
const colour = new THREE.BufferAttribute(colours, 3);
|
|
392
|
+
position.setUsage(THREE.DynamicDrawUsage);
|
|
393
|
+
colour.setUsage(THREE.DynamicDrawUsage);
|
|
394
|
+
geometry.setAttribute("position", position);
|
|
395
|
+
geometry.setAttribute("color", colour);
|
|
396
|
+
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
|
397
|
+
geometry.setDrawRange(0, 0);
|
|
398
|
+
const material = new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.9, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -3, polygonOffsetUnits: -3 });
|
|
399
|
+
const mesh = new THREE.Mesh(geometry, material);
|
|
400
|
+
mesh.name = "terrain-cracks";
|
|
401
|
+
mesh.frustumCulled = false;
|
|
402
|
+
mesh.renderOrder = 2;
|
|
403
|
+
let seen = -1;
|
|
404
|
+
let groundMoved = false;
|
|
405
|
+
const stopListening = terrain.onDeform(() => {
|
|
406
|
+
groundMoved = true;
|
|
407
|
+
});
|
|
408
|
+
const lift = (x, z) => terrain.heightAt(x, z) + CRACK_LIFT;
|
|
409
|
+
return {
|
|
410
|
+
mesh,
|
|
411
|
+
sync() {
|
|
412
|
+
const cracks = terrain.cracks();
|
|
413
|
+
if (seen === terrain.cracksVersion && !(groundMoved && cracks.length > 0)) return;
|
|
414
|
+
seen = terrain.cracksVersion;
|
|
415
|
+
groundMoved = false;
|
|
416
|
+
let quad = 0;
|
|
417
|
+
for (let n = cracks.length - 1; n >= 0 && quad < MAX_CRACK_QUADS; n--) {
|
|
418
|
+
const crack = cracks[n];
|
|
419
|
+
const tone = terrain.material(crack.material).color;
|
|
420
|
+
const dark = tone[0] * 0.3 + tone[1] * 0.59 + tone[2] * 0.11 < DARK_SURFACE;
|
|
421
|
+
const k = dark ? DUST_LIFT : CRACK_SHADE;
|
|
422
|
+
const r = dark ? Math.min(1, tone[0] * k + DUST_GREY) : tone[0] * k;
|
|
423
|
+
const g = dark ? Math.min(1, tone[1] * k + DUST_GREY) : tone[1] * k;
|
|
424
|
+
const b = dark ? Math.min(1, tone[2] * k + DUST_GREY) : tone[2] * k;
|
|
425
|
+
for (const s of crackLines(crack)) {
|
|
426
|
+
if (quad >= MAX_CRACK_QUADS) break;
|
|
427
|
+
if (!terrain.contains(s.x0, s.z0) || !terrain.contains(s.x1, s.z1)) continue;
|
|
428
|
+
const length = Math.hypot(s.x1 - s.x0, s.z1 - s.z0);
|
|
429
|
+
if (length < 1e-5) continue;
|
|
430
|
+
const ax = -(s.z1 - s.z0) / length;
|
|
431
|
+
const az = (s.x1 - s.x0) / length;
|
|
432
|
+
const corners = [
|
|
433
|
+
[s.x0 + ax * s.w0 * 0.5, s.z0 + az * s.w0 * 0.5],
|
|
434
|
+
[s.x0 - ax * s.w0 * 0.5, s.z0 - az * s.w0 * 0.5],
|
|
435
|
+
[s.x1 + ax * s.w1 * 0.5, s.z1 + az * s.w1 * 0.5],
|
|
436
|
+
[s.x1 - ax * s.w1 * 0.5, s.z1 - az * s.w1 * 0.5]
|
|
437
|
+
];
|
|
438
|
+
corners.forEach(([x, z], corner) => {
|
|
439
|
+
const at = (quad * 4 + corner) * 3;
|
|
440
|
+
positions[at] = x;
|
|
441
|
+
positions[at + 1] = lift(x, z);
|
|
442
|
+
positions[at + 2] = z;
|
|
443
|
+
colours[at] = r;
|
|
444
|
+
colours[at + 1] = g;
|
|
445
|
+
colours[at + 2] = b;
|
|
446
|
+
});
|
|
447
|
+
quad++;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
position.needsUpdate = true;
|
|
451
|
+
colour.needsUpdate = true;
|
|
452
|
+
geometry.setDrawRange(0, quad * 6);
|
|
453
|
+
},
|
|
454
|
+
dispose() {
|
|
455
|
+
stopListening();
|
|
456
|
+
geometry.dispose();
|
|
457
|
+
material.dispose();
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
}
|
|
344
461
|
|
|
345
462
|
// src/rebar.ts
|
|
346
463
|
var BAR_RADIUS = 6e-3;
|
|
347
464
|
var EXPOSED_MARGIN = 2e-3;
|
|
348
465
|
var MAX_SAG = 0.07;
|
|
349
|
-
|
|
466
|
+
var MIN_BAR_CAPACITY = 32;
|
|
467
|
+
function barCapacity(count) {
|
|
468
|
+
let capacity = MIN_BAR_CAPACITY;
|
|
469
|
+
while (capacity < count) capacity *= 2;
|
|
470
|
+
return capacity;
|
|
471
|
+
}
|
|
472
|
+
function buildRebarGeometry(THREE, terrain, chunk, reuse) {
|
|
350
473
|
const [x0, z0] = terrain.bounds;
|
|
351
474
|
const { cellSize, columns, rows, stride } = terrain;
|
|
352
475
|
const lastColumn = Math.min(columns, chunk.column + chunk.cells);
|
|
@@ -383,9 +506,11 @@ function buildRebarGeometry(THREE, terrain, chunk) {
|
|
|
383
506
|
}
|
|
384
507
|
if (boxes.length === 0) return null;
|
|
385
508
|
const count = boxes.length / 6;
|
|
386
|
-
const
|
|
387
|
-
const
|
|
388
|
-
const
|
|
509
|
+
const target = reuse && reuse.getAttribute("position").count >= count * 24 ? reuse : void 0;
|
|
510
|
+
const capacity = target ? target.getAttribute("position").count / 24 : barCapacity(count);
|
|
511
|
+
const positions = target ? target.getAttribute("position").array : new Float32Array(capacity * 24 * 3);
|
|
512
|
+
const normals = target ? target.getAttribute("normal").array : new Float32Array(capacity * 24 * 3);
|
|
513
|
+
const indices = target ? target.getIndex().array : new Uint32Array(capacity * 36);
|
|
389
514
|
const FACES = [
|
|
390
515
|
[[0, 4, 2, 0, 4, 5, 3, 4, 5, 3, 4, 2], [0, 1, 0]],
|
|
391
516
|
[[0, 1, 5, 0, 1, 2, 3, 1, 2, 3, 1, 5], [0, -1, 0]],
|
|
@@ -411,10 +536,20 @@ function buildRebarGeometry(THREE, terrain, chunk) {
|
|
|
411
536
|
cursor += 6;
|
|
412
537
|
}
|
|
413
538
|
}
|
|
539
|
+
if (target) {
|
|
540
|
+
target.getAttribute("position").needsUpdate = true;
|
|
541
|
+
target.getAttribute("normal").needsUpdate = true;
|
|
542
|
+
target.getIndex().needsUpdate = true;
|
|
543
|
+
target.boundingSphere = null;
|
|
544
|
+
target.boundingBox = null;
|
|
545
|
+
target.setDrawRange(0, count * 36);
|
|
546
|
+
return target;
|
|
547
|
+
}
|
|
414
548
|
const geometry = new THREE.BufferGeometry();
|
|
415
549
|
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
|
416
550
|
geometry.setAttribute("normal", new THREE.BufferAttribute(normals, 3));
|
|
417
551
|
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
|
552
|
+
geometry.setDrawRange(0, count * 36);
|
|
418
553
|
return geometry;
|
|
419
554
|
}
|
|
420
555
|
|
|
@@ -424,6 +559,7 @@ var DEFAULT_MARK_DISTANCE = 45;
|
|
|
424
559
|
var DEFAULT_SKIRT = 300;
|
|
425
560
|
var LOD_CHECK_METRES = 4;
|
|
426
561
|
var REBAR_COLOUR = 4863272;
|
|
562
|
+
var MAX_SPARE_GEOMETRIES = 24;
|
|
427
563
|
function createTerrainRenderer(THREE, options) {
|
|
428
564
|
const { terrain } = options;
|
|
429
565
|
const lodDistance = options.lodDistance ?? DEFAULT_LOD_DISTANCE;
|
|
@@ -440,8 +576,10 @@ function createTerrainRenderer(THREE, options) {
|
|
|
440
576
|
const drawn = /* @__PURE__ */ new Map();
|
|
441
577
|
const marks = createMarkLayer(THREE, terrain, options.markDistance ?? DEFAULT_MARK_DISTANCE);
|
|
442
578
|
const debris = createDebrisLayer(THREE, terrain);
|
|
443
|
-
|
|
579
|
+
const cracks = createCrackLayer(THREE, terrain);
|
|
580
|
+
group.add(marks.mesh, cracks.mesh, debris.mesh);
|
|
444
581
|
let pristineStale = true;
|
|
582
|
+
let pristineBuilt = false;
|
|
445
583
|
let pristineCount = 0;
|
|
446
584
|
let lodX = Infinity;
|
|
447
585
|
let lodZ = Infinity;
|
|
@@ -453,31 +591,62 @@ function createTerrainRenderer(THREE, options) {
|
|
|
453
591
|
return Math.hypot(centreX - camera.x, centreZ - camera.z);
|
|
454
592
|
};
|
|
455
593
|
const stepFor = (distance) => distance > lodDistance * 2 ? 4 : distance > lodDistance ? 2 : 1;
|
|
594
|
+
const spareGeometries = [];
|
|
595
|
+
function keepSpare(geometry) {
|
|
596
|
+
if (spareGeometries.length < MAX_SPARE_GEOMETRIES) spareGeometries.push(geometry);
|
|
597
|
+
else geometry.dispose();
|
|
598
|
+
}
|
|
599
|
+
function takeSpare(chunk, step) {
|
|
600
|
+
const count = chunkVertexCount(terrain, chunk, step);
|
|
601
|
+
const found = spareGeometries.findIndex((geometry) => geometry.getAttribute("position").count === count);
|
|
602
|
+
return found < 0 ? void 0 : spareGeometries.splice(found, 1)[0];
|
|
603
|
+
}
|
|
456
604
|
function drop(index) {
|
|
457
605
|
const entry = drawn.get(index);
|
|
458
606
|
if (!entry) return;
|
|
459
607
|
group.remove(entry.mesh);
|
|
460
|
-
entry.mesh.geometry
|
|
608
|
+
keepSpare(entry.mesh.geometry);
|
|
461
609
|
if (entry.rebar) {
|
|
462
610
|
group.remove(entry.rebar);
|
|
463
611
|
entry.rebar.geometry.dispose();
|
|
464
612
|
}
|
|
465
613
|
drawn.delete(index);
|
|
466
614
|
}
|
|
615
|
+
function drawRebar(chunk, entry) {
|
|
616
|
+
const bars = buildRebarGeometry(THREE, terrain, chunk, entry.rebar?.geometry);
|
|
617
|
+
if (!bars) {
|
|
618
|
+
if (entry.rebar) entry.rebar.visible = false;
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
if (entry.rebar && entry.rebar.geometry === bars) {
|
|
622
|
+
entry.rebar.visible = true;
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (entry.rebar) {
|
|
626
|
+
group.remove(entry.rebar);
|
|
627
|
+
entry.rebar.geometry.dispose();
|
|
628
|
+
}
|
|
629
|
+
entry.rebar = new THREE.Mesh(bars, rebarMaterial);
|
|
630
|
+
entry.rebar.castShadow = true;
|
|
631
|
+
group.add(entry.rebar);
|
|
632
|
+
}
|
|
467
633
|
function draw(chunk, camera) {
|
|
468
|
-
drop(chunk.index);
|
|
469
634
|
const step = stepFor(distanceTo(chunk, camera));
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
635
|
+
let entry = drawn.get(chunk.index);
|
|
636
|
+
if (!entry) {
|
|
637
|
+
const mesh = new THREE.Mesh(buildChunkGeometry(THREE, terrain, chunk, step, takeSpare(chunk, step)), surface);
|
|
638
|
+
mesh.receiveShadow = true;
|
|
639
|
+
group.add(mesh);
|
|
640
|
+
entry = { mesh, rebar: null, step };
|
|
641
|
+
drawn.set(chunk.index, entry);
|
|
642
|
+
} else {
|
|
643
|
+
const previous = entry.mesh.geometry;
|
|
644
|
+
const sameDetail = previous.getAttribute("position").count === chunkVertexCount(terrain, chunk, step);
|
|
645
|
+
entry.mesh.geometry = buildChunkGeometry(THREE, terrain, chunk, step, sameDetail ? previous : takeSpare(chunk, step));
|
|
646
|
+
if (entry.mesh.geometry !== previous) keepSpare(previous);
|
|
647
|
+
entry.step = step;
|
|
479
648
|
}
|
|
480
|
-
|
|
649
|
+
drawRebar(chunk, entry);
|
|
481
650
|
}
|
|
482
651
|
function rebuildPristine() {
|
|
483
652
|
const chunks = [];
|
|
@@ -485,15 +654,17 @@ function createTerrainRenderer(THREE, options) {
|
|
|
485
654
|
const chunk = terrain.chunk(index);
|
|
486
655
|
if (chunk.pristine) chunks.push(chunk);
|
|
487
656
|
}
|
|
488
|
-
pristineMesh.geometry.dispose();
|
|
489
|
-
pristineMesh.geometry = buildPristineGeometry(THREE, terrain, chunks, skirt);
|
|
657
|
+
if (!pristineBuilt) pristineMesh.geometry.dispose();
|
|
658
|
+
pristineMesh.geometry = buildPristineGeometry(THREE, terrain, chunks, skirt, pristineBuilt ? pristineMesh.geometry : void 0);
|
|
659
|
+
pristineBuilt = true;
|
|
490
660
|
pristineCount = chunks.length;
|
|
491
661
|
pristineStale = false;
|
|
492
662
|
}
|
|
493
663
|
return {
|
|
494
664
|
group,
|
|
495
665
|
sync(camera) {
|
|
496
|
-
const
|
|
666
|
+
const laidAnew = terrain.dirtyChunkCount >= terrain.chunksX * terrain.chunksZ;
|
|
667
|
+
const limit = firstSync || laidAnew ? Infinity : void 0;
|
|
497
668
|
firstSync = false;
|
|
498
669
|
for (const chunk of terrain.drainDirtyChunks(limit)) {
|
|
499
670
|
if (chunk.pristine) {
|
|
@@ -514,15 +685,18 @@ function createTerrainRenderer(THREE, options) {
|
|
|
514
685
|
}
|
|
515
686
|
}
|
|
516
687
|
marks.sync(camera);
|
|
688
|
+
cracks.sync();
|
|
517
689
|
debris.sync();
|
|
518
690
|
},
|
|
519
|
-
stats: () => ({ chunkMeshes: drawn.size, pristineChunks: pristineCount, marksDrawn: marks.mesh.count, debrisDrawn: debris.mesh.count }),
|
|
691
|
+
stats: () => ({ chunkMeshes: drawn.size, pristineChunks: pristineCount, marksDrawn: marks.mesh.count, debrisDrawn: debris.mesh.count, crackQuads: cracks.mesh.geometry.drawRange.count / 6 }),
|
|
520
692
|
dispose() {
|
|
521
693
|
for (const index of [...drawn.keys()]) drop(index);
|
|
694
|
+
for (const geometry of spareGeometries) geometry.dispose();
|
|
522
695
|
pristineMesh.geometry.dispose();
|
|
523
696
|
surface.dispose();
|
|
524
697
|
rebarMaterial.dispose();
|
|
525
698
|
marks.dispose();
|
|
699
|
+
cracks.dispose();
|
|
526
700
|
debris.dispose();
|
|
527
701
|
group.removeFromParent();
|
|
528
702
|
}
|
|
@@ -533,6 +707,13 @@ function createTerrainRenderer(THREE, options) {
|
|
|
533
707
|
import { markKitOrigin as markKitOrigin2 } from "@adatechnology/game-contracts";
|
|
534
708
|
|
|
535
709
|
// src/locale.ts
|
|
710
|
+
var PROFILE_NAMES = {
|
|
711
|
+
en: { lawn: "Lawn", dirt: "Dirt", sand: "Sand", road: "Asphalt road", concrete_slab: "Concrete slab", suspended_slab: "Slab over a void", tile_floor: "Tile floor", wood_floor: "Wood floor", stone_paving: "Stone paving" },
|
|
712
|
+
"pt-BR": { lawn: "Grama", dirt: "Terra", sand: "Areia", road: "Asfalto", concrete_slab: "Laje de concreto", suspended_slab: "Laje sobre v\xE3o", tile_floor: "Piso cer\xE2mico", wood_floor: "Assoalho", stone_paving: "Cal\xE7amento de pedra" }
|
|
713
|
+
};
|
|
714
|
+
function terrainProfileName(profileId, localeId) {
|
|
715
|
+
return (PROFILE_NAMES[localeId] ?? PROFILE_NAMES.en)[profileId] ?? profileId;
|
|
716
|
+
}
|
|
536
717
|
var LOCALES = {
|
|
537
718
|
en: {
|
|
538
719
|
name: "Terrain",
|
|
@@ -647,6 +828,7 @@ export {
|
|
|
647
828
|
TERRAIN_STRIPS,
|
|
648
829
|
createSurfaceMaterial,
|
|
649
830
|
createTerrainRenderer,
|
|
650
|
-
createTerrainTestModule
|
|
831
|
+
createTerrainTestModule,
|
|
832
|
+
terrainProfileName
|
|
651
833
|
};
|
|
652
834
|
//# sourceMappingURL=index.js.map
|