waverider Posted December 28, 2017 Share Posted December 28, 2017 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 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 28, 2017 Share Posted December 28, 2017 I have a function to make a hole and to close it: var vertices_toremove = []; var faces_toswitch = []; function createHole(ground, pickInfo, radius, ctrl) { 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); if(BABYLON.Vector3.Distance(pickpoint, current_v) < (radius)) { 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); } NasimiAsl, Pryme8, waverider and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 28, 2017 Share Posted December 28, 2017 I have you add an example on the playground : http://www.babylonjs-playground.com/#99GABU GameMonetize and waverider 2 Quote Link to comment Share on other sites More sharing options...
waverider Posted December 28, 2017 Author Share Posted December 28, 2017 Great awesome!! Quote Link to comment Share on other sites More sharing options...
waverider Posted December 28, 2017 Author Share Posted December 28, 2017 looks better http://www.babylonjs-playground.com/#99GABU#1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.