How to create curved trenches in terrain?

can somebody to show me to create curved trenches I don’t want to be direct as in this pictures


here is my code

function curvetrenches(){
const vertices = [];
const b=Math.floor(document.getElementById('Nopints-y').value);
const c=document.getElementsByTagName('table')[3].getElementsByTagName('td').length-1;
const d=4*b;
const a=(parseFloat(c)-parseFloat(d)-1)/d;
document.getElementById('Nopints-x').value=Math.round(a).toFixed(2);
for ( let i = 0; i < a; i ++ ) {
for ( let j = 0; j < b; j ++){
var x=document.getElementsByTagName('table')[3].getElementsByTagName('td')[Math.floor(4*j+1+d*i)].innerHTML;
var z=document.getElementsByTagName('table')[3].getElementsByTagName('td')[Math.floor(4*j+2+d*i)].innerHTML;
var y=document.getElementsByTagName('table')[3].getElementsByTagName('td')[Math.floor(4*j+3+d*i)].innerHTML;
	vertices.push( new THREE.Vector3(x,y,z) );
}} 
for ( let j = 100; j < 300; j ++){
document.getElementsByTagName('table')[3].getElementsByTagName('td')[4*j+3].innerHTML=-1.5;
}
const customgeometry=new THREE.BufferGeometry().setFromPoints(vertices);
const cutomMaterial=new THREE.PointsMaterial( { color:'red',size:0.2 } );
const points = new THREE.Points( customgeometry, cutomMaterial );
scene.add( points );
// triangulate x, z
var indexDelaunay = Delaunator.from(
  vertices.map(v => {
    return [v.x, v.z];
  })
);

var meshIndex = []; // delaunay index => three.js index
for (let i = 0; i < indexDelaunay.triangles.length; i++){
  meshIndex.push(indexDelaunay.triangles[i]);
}

customgeometry.setIndex(meshIndex); // add three.js index to the existing geometry
customgeometry.computeVertexNormals();

for(let x=2;x<scene.children.length-1;x++){
scene.children[x].material.visible=false;
}
var mesh = new THREE.Mesh(
  customgeometry, // re-use the existing geometry
  new THREE.MeshNormalMaterial({wireframe:true,side: THREE.DoubleSide})
);
scene.add(mesh)
}```

Straight from the twilight zone of my mind at 2:30am :crazy_face:

  1. Get points of the trench curve
  2. Create an array of Line3 objects from (1)
  3. Find the shortest distance between a point of the terrain geometry and lines in (2)
  4. Do the stuff to make the point lower
  5. Iterate through all the points in the terrain geometry with (3) and (4)

Before:

After:

Demo: https://codepen.io/prisoner849/full/MWPeWEZ

PS This is just an example, not the ultimate solution.

5 Likes

really really cool work @prisoner849 :ok_hand:

1 Like

good job thank you :+1: