# Hole in a terrain

## Recommended Posts

Hy i've been trying to create a hole in a terrain like in this video, but i don't know what approach to take, i was thinking maybe i should use shader, but the only problem with using shader is that the vertices can't be specified. i'll appreciate any demo or idea that can help me out

##### Share on other sites

I have a function to make a hole and to close it:

``````var vertices_toremove = [];
var faces_toswitch = [];

{
let indices_array = ground.getIndices();
let positions_array = ground.getVerticesData(BABYLON.VertexBuffer.PositionKind);
let index;
let face_id;
let safety = 10000;
let pickpoint = pickInfo.pickedPoint;
let current_v = BABYLON.Vector3.Zero();
let worldmatrix = ground.getWorldMatrix();

if(!ground.original_indices) {
ground.original_indices = indices_array.slice(0);
}
for(let i = 0, countPositionsArray = positions_array.length/3; i < countPositionsArray; i++) {
current_v.x = positions_array[i*3];
current_v.y = positions_array[i*3+1];
current_v.z = positions_array[i*3+2];
current_v = BABYLON.Vector3.TransformCoordinates(current_v, worldmatrix);
vertices_toremove.push(i);
}
}
for(let i = 0, countVerticeToRemove = vertices_toremove.length; i < countVerticeToRemove; i++) {
while((index = indices_array.indexOf(vertices_toremove[i], index+1)) != -1)
{
face_id = index - index%3;
faces_toswitch.push(face_id);
safety--;
if(safety <= 0) { break; }
}
if(safety <= 0) { break; }
}
let countFacesToWitch = faces_toswitch.length;
if(ctrl == false) {
for(let i = 0; i < countFacesToWitch; i++) {
indices_array[faces_toswitch[i]+2] = ground.original_indices[faces_toswitch[i]+1];
indices_array[faces_toswitch[i]+1] = ground.original_indices[faces_toswitch[i]+2];
}
} else {
for(let i = 0; i < countFacesToWitch; i++) {
indices_array[faces_toswitch[i]+1] = ground.original_indices[faces_toswitch[i]+1];
indices_array[faces_toswitch[i]+2] = ground.original_indices[faces_toswitch[i]+2];
}
}
ground.setIndices(indices_array);
}``````

##### Share on other sites

I have you add an example on the playground :

Great awesome!!

looks better

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.