score:0

ok, as @prisoner849 commented, buffergeometryies index property was the answer.

i redid the triangulation of the mesh by looping over the "squares" of my mesh, getting their corners and then changing the indexes for each squares triangles to one of a pre calculated set, based on which corner had a unique height. it also seems that you want the indexes to go in a specific order to control which side is "up", it seems to be that counter clockwise or so.

const size = 10;
const vertmap = [0, 3, 1, 3, 2, 1];
const trisets = [
  [0, 3, 2, 0, 2, 1],
  [1, 3, 2, 1, 0, 3],
  [0, 3, 2, 0, 2, 1],
  [1, 3, 2, 1, 0, 3],
];

const getsquareverts = (x, y) => {
  const i = (y * size) + x + y;
  return [i, i + 1, i + (size + 2), i + (size + 1)];
}

const getuniqueheightpoint = (verts) => {
  let unique = -1;
  const set = verts.reduce((p, n) => {
    const c = p[n.tostring()] || 0;
    p[n.tostring()] = c + 1;
    return p;
  }, {});
  const keys = object.keys(set);
  if (keys.length == 2 && (set[keys[0]] == 1 || set[keys[0]] == 3)) {
    for (const key of keys) {
      if (set[key] == 1) {
        unique = verts.findindex((v) => v == parsefloat(key));
        break;
      }
    }
  }
  return unique;
}

const reworktris = (plane) => {
  let indexoffset = 0;
  const planeidx = plane.geometry.index;
  for (let y = 0; y < this.size; y++) {
    for (let x = 0; x < this.size; x++) {
      const verts = this.getsquareverts(x, y);
      const heights = verts.map((v) => this.planepos.getz(v));
      const uniqueheight = this.getuniqueheightpoint(heights);
      let tris = vertmap.map((i) => verts[i]);
      if (uniqueheight >= 0) {
        tris = trisets[uniqueheight].map((i) => verts[i]);
      }
      planeidx.set(tris, indexoffset);
      indexoffset += 6;
    }
  }
  planeidx.needsupdate = true;
}

const plane = new three.mesh(new three.planebuffergeometry());
reqorktris(plane);

Related Query

More Query from same tag