@adatechnology/game-terrain-three 0.6.12 → 0.6.14

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.
@@ -736,9 +736,12 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
736
736
  const quaternion = new THREE.Quaternion();
737
737
  const euler = new THREE.Euler();
738
738
  const colour = new THREE.Color();
739
+ let seenVersion = -1;
739
740
  return {
740
741
  mesh,
741
742
  sync() {
743
+ if (terrain.debrisVersion === seenVersion) return;
744
+ seenVersion = terrain.debrisVersion;
742
745
  const pieces = terrain.debris();
743
746
  let count = 0;
744
747
  for (const piece of pieces) {
@@ -977,24 +980,43 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
977
980
  while (capacity < count) capacity *= 2;
978
981
  return capacity;
979
982
  }
983
+ var FACES = [
984
+ [[0, 4, 2, 0, 4, 5, 3, 4, 5, 3, 4, 2], [0, 1, 0]],
985
+ [[0, 1, 5, 0, 1, 2, 3, 1, 2, 3, 1, 5], [0, -1, 0]],
986
+ [[0, 1, 5, 3, 1, 5, 3, 4, 5, 0, 4, 5], [0, 0, 1]],
987
+ [[3, 1, 2, 0, 1, 2, 0, 4, 2, 3, 4, 2], [0, 0, -1]],
988
+ [[3, 1, 5, 3, 1, 2, 3, 4, 2, 3, 4, 5], [1, 0, 0]],
989
+ [[0, 1, 2, 0, 1, 5, 0, 4, 5, 0, 4, 2], [-1, 0, 0]]
990
+ ];
991
+ var BOX = 6;
992
+ var barsByProfile = /* @__PURE__ */ new WeakMap();
993
+ var barsOf = (profile) => {
994
+ const known = barsByProfile.get(profile);
995
+ if (known) return known;
996
+ let top = 0;
997
+ let depth = Number.NaN;
998
+ let spacing = Number.NaN;
999
+ for (const stratum of profile.strata) {
1000
+ if (stratum.reinforcement && Number.isNaN(depth)) {
1001
+ depth = top + stratum.reinforcement.cover;
1002
+ spacing = stratum.reinforcement.spacing;
1003
+ }
1004
+ top += stratum.thickness;
1005
+ }
1006
+ const bars = { depth, spacing, limit: top };
1007
+ barsByProfile.set(profile, bars);
1008
+ return bars;
1009
+ };
1010
+ var boxes = [];
980
1011
  function buildRebarGeometry(THREE, terrain, chunk, reuse) {
981
1012
  const [x0, z0] = terrain.bounds;
982
1013
  const { cellSize, columns, rows, stride } = terrain;
983
1014
  const lastColumn = Math.min(columns, chunk.column + chunk.cells);
984
1015
  const lastRow = Math.min(rows, chunk.row + chunk.cells);
985
- const boxes = [];
986
- const coverOf = (index) => {
987
- let top = 0;
988
- for (const stratum of terrain.profileList[terrain.profileIndex[index]].strata) {
989
- if (stratum.reinforcement) return { depth: top + stratum.reinforcement.cover, spacing: stratum.reinforcement.spacing };
990
- top += stratum.thickness;
991
- }
992
- return null;
993
- };
1016
+ boxes.length = 0;
994
1017
  const showing = (index, depth) => {
995
- const profile = terrain.profileList[terrain.profileIndex[index]];
996
- const limit = profile.strata.reduce((sum, stratum) => sum + stratum.thickness, 0);
997
- return terrain.dug[index] > depth + EXPOSED_MARGIN && terrain.dug[index] <= limit + EXPOSED_MARGIN;
1018
+ const dug = terrain.dug[index];
1019
+ return dug > depth + EXPOSED_MARGIN && dug <= barsOf(terrain.profileList[terrain.profileIndex[index]]).limit + EXPOSED_MARGIN;
998
1020
  };
999
1021
  const onBar = (coordinate, spacing) => Math.floor(coordinate / spacing) !== Math.floor((coordinate + cellSize) / spacing);
1000
1022
  const addBox = (ax, az, bx, bz, y) => {
@@ -1003,44 +1025,43 @@ ${SURFACE_GLSL}`).replace("#include <color_fragment>", "#include <color_fragment
1003
1025
  for (let row = chunk.row; row <= lastRow; row++) {
1004
1026
  for (let column = chunk.column; column <= lastColumn; column++) {
1005
1027
  const index = row * stride + column;
1006
- const cover = coverOf(index);
1007
- if (!cover || !showing(index, cover.depth)) continue;
1028
+ const { depth, spacing } = barsOf(terrain.profileList[terrain.profileIndex[index]]);
1029
+ if (Number.isNaN(depth) || !showing(index, depth)) continue;
1008
1030
  const x = x0 + column * cellSize;
1009
1031
  const z = z0 + row * cellSize;
1010
- const y = -cover.depth - BAR_RADIUS - Math.min(1, terrain.barBend[index]) * MAX_SAG;
1011
- if (onBar(z, cover.spacing) && column < lastColumn && showing(index + 1, cover.depth)) addBox(x, z, x + cellSize, z, y);
1012
- if (onBar(x, cover.spacing) && row < lastRow && showing(index + stride, cover.depth)) addBox(x, z, x, z + cellSize, y);
1032
+ const y = -depth - BAR_RADIUS - Math.min(1, terrain.barBend[index]) * MAX_SAG;
1033
+ if (onBar(z, spacing) && column < lastColumn && showing(index + 1, depth)) addBox(x, z, x + cellSize, z, y);
1034
+ if (onBar(x, spacing) && row < lastRow && showing(index + stride, depth)) addBox(x, z, x, z + cellSize, y);
1013
1035
  }
1014
1036
  }
1015
1037
  if (boxes.length === 0) return null;
1016
- const count = boxes.length / 6;
1038
+ const count = boxes.length / BOX;
1017
1039
  const target = reuse && reuse.getAttribute("position").count >= count * 24 ? reuse : void 0;
1018
1040
  const capacity = target ? target.getAttribute("position").count / 24 : barCapacity(count);
1019
1041
  const positions = target ? target.getAttribute("position").array : new Float32Array(capacity * 24 * 3);
1020
1042
  const normals = target ? target.getAttribute("normal").array : new Float32Array(capacity * 24 * 3);
1021
1043
  const indices = target ? target.getIndex().array : new Uint32Array(capacity * 36);
1022
- const FACES = [
1023
- [[0, 4, 2, 0, 4, 5, 3, 4, 5, 3, 4, 2], [0, 1, 0]],
1024
- [[0, 1, 5, 0, 1, 2, 3, 1, 2, 3, 1, 5], [0, -1, 0]],
1025
- [[0, 1, 5, 3, 1, 5, 3, 4, 5, 0, 4, 5], [0, 0, 1]],
1026
- [[3, 1, 2, 0, 1, 2, 0, 4, 2, 3, 4, 2], [0, 0, -1]],
1027
- [[3, 1, 5, 3, 1, 2, 3, 4, 2, 3, 4, 5], [1, 0, 0]],
1028
- [[0, 1, 2, 0, 1, 5, 0, 4, 5, 0, 4, 2], [-1, 0, 0]]
1029
- ];
1030
1044
  let vertex = 0;
1031
1045
  let cursor = 0;
1032
1046
  for (let n = 0; n < count; n++) {
1033
- const box = boxes.slice(n * 6, n * 6 + 6);
1047
+ const at = n * BOX;
1034
1048
  for (const [corners, normal] of FACES) {
1035
1049
  const first = vertex;
1036
1050
  for (let c = 0; c < 4; c++) {
1037
- positions[vertex * 3] = box[corners[c * 3]];
1038
- positions[vertex * 3 + 1] = box[corners[c * 3 + 1]];
1039
- positions[vertex * 3 + 2] = box[corners[c * 3 + 2]];
1040
- normals.set(normal, vertex * 3);
1051
+ positions[vertex * 3] = boxes[at + corners[c * 3]];
1052
+ positions[vertex * 3 + 1] = boxes[at + corners[c * 3 + 1]];
1053
+ positions[vertex * 3 + 2] = boxes[at + corners[c * 3 + 2]];
1054
+ normals[vertex * 3] = normal[0];
1055
+ normals[vertex * 3 + 1] = normal[1];
1056
+ normals[vertex * 3 + 2] = normal[2];
1041
1057
  vertex++;
1042
1058
  }
1043
- indices.set([first, first + 1, first + 2, first, first + 2, first + 3], cursor);
1059
+ indices[cursor] = first;
1060
+ indices[cursor + 1] = first + 1;
1061
+ indices[cursor + 2] = first + 2;
1062
+ indices[cursor + 3] = first;
1063
+ indices[cursor + 4] = first + 2;
1064
+ indices[cursor + 5] = first + 3;
1044
1065
  cursor += 6;
1045
1066
  }
1046
1067
  }