Dad72 Posted April 15, 2015 Share Posted April 15, 2015 HI, Does anyone have an idea of how we create Holes in the ground by removing faces? This can be used to create of enter underground cave, tunnel, gallery ... Thanks Quote Link to comment Share on other sites More sharing options...
Temechon Posted April 16, 2015 Share Posted April 16, 2015 Did you try CSG ? http://www.babylonjs.com/?CSGMaybe with a big box and a tube it can work... jahow and Jaskar 2 Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 16, 2015 Share Posted April 16, 2015 CSG is a feature I always forget exists. But it is an amazing feature :-) Thanks for reminding it is there! Jaskar 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted April 16, 2015 Share Posted April 16, 2015 GSG or poly2tri with the first one, you create fist a mesh, then you remove parts with another meshwith the second one, you create a 2D complex polygon, which can have holes, then it creates the relative plane (with holes) Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 16, 2015 Author Share Posted April 16, 2015 I'll try with CSG can be a good solution. Thanks Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 16, 2015 Author Share Posted April 16, 2015 Its not working as I would like. What I want is to create a hole by removing the face of the field. Then I place a 3d model to the hole. exemple: Quote Link to comment Share on other sites More sharing options...
jerome Posted April 16, 2015 Share Posted April 16, 2015 What happens if you use CSG with a cylinder to dig a hole in your terrain ? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 16, 2015 Author Share Posted April 16, 2015 CSG is not suitable. I would just by clicking on the faces of the terrain that removes polygons to form a hole. The irregularity of the hole is not imortante, a model 3d will hide it. Quote Link to comment Share on other sites More sharing options...
jahow Posted April 16, 2015 Share Posted April 16, 2015 The pick() function of a scene gives you the id of the face picked. You are then able to use this to remove the three corresponding indices in the indice array of the meshes. This way you effectively remove the picked face (but not its vertices). Example here (based on the decals PG): http://www.babylonjs-playground.com/#1BAPRM#19 Is that what you're looking for? qqdarren, jerome and Dad72 3 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 16, 2015 Author Share Posted April 16, 2015 yes, that's exactly what I was looking for. thank you Jahow Quote Link to comment Share on other sites More sharing options...
jahow Posted April 16, 2015 Share Posted April 16, 2015 good luck on your editor! Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 16, 2015 Author Share Posted April 16, 2015 Thank you Jahow. I have one last question. if I want to add a radius to remove more faces, what are the best ways to do it ? thanks. Quote Link to comment Share on other sites More sharing options...
jahow Posted April 16, 2015 Share Posted April 16, 2015 That's a bit more complex. I think I would check all vertices close to the picked point, and remove those that are under a certain distance (= hole radius). For each vertex removed, I would have to delete the associated faces in the indices array. Not sure if that would work, I'll try to do it in the PG... Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 16, 2015 Author Share Posted April 16, 2015 thank you Jahow for your help. Quote Link to comment Share on other sites More sharing options...
jahow Posted April 17, 2015 Share Posted April 17, 2015 I managed to get it working: http://www.babylonjs-playground.com/#8OMYN#4 But:1/ I do not remove the vertices, only the faces. So after a while the mes might need to be cleaned (ie remove vertices that are not used)2/ There should be some possible optimization by looking only into submeshes vertices, instead of all the vertices of the mesh (since pickInfo gives you a submeshID) Good luck jerome, Dad72 and Jaskar 3 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 17, 2015 Author Share Posted April 17, 2015 Cool, is perfect. thank you very much Jahow for help Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 20, 2015 Author Share Posted April 20, 2015 Hi, Still thank you for helping me Jahow for this function. I would go the other way to close the holes. is it possible ? I have this function to create the holes. I would like to create a function: addFaces () that recreate the missing faces. var removeFaces = function (pickInfo, radius) { var mesh = pickInfo.pickedMesh, faceID = pickInfo.faceId, indices_array = mesh.getIndices(), positions_array = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), vertices_toremove = [], pickpoint = pickInfo.pickedPoint, current_v = new BABYLON.Vector3.Zero(), worldmatrix = mesh.getWorldMatrix(), index, safety = 1000; for(var i=0; i<positions_array.length/3; 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(var i = 0; i < vertices_toremove.length; i++) { index = indices_array.indexOf(vertices_toremove[i]); while(index != -1) { indices_array.splice(index - index%3, 3); break; } } mesh.setIndices(indices_array); }; var addFaces = function (pickInfo, radius) { ???? }; Thank you for the help. Quote Link to comment Share on other sites More sharing options...
jahow Posted April 22, 2015 Share Posted April 22, 2015 Hey dad72, sorry for not responding earlier. Adding the faces back is not trivial, unless we save the indices of the faces we've removed earlier. In this case it's just a matter of putting back those faces in the mesh. But it may not be suitable for every use, since the "removed faces" info can become quite big if you remove a lot of stuff, and must be saved with the mesh otherwise it won't be possible to add its faces back. Herre is an example: http://www.babylonjs-playground.com/#8OMYN#5The first time you click, faces will be removed. If you click back somewhere on the mesh, the faces around the click will be restored. It still has one problem: since we removed the faces from the mesh, nothing happens if we click in the hole... Here are a few suggestions for you:- Maybe setting vertices alpha (transparency) to zero would be easier than remove them, because we wouldn't have to actually modify the mesh and clicks in 'holes' would still be detected ; the big drawback is that the mesh would then be classified as "transparent", which may pose other problems- If you plan to use this exclusively for a heightmap, a simpler & more efficient method can probably be found because all your vertices and faces are on a grid and it is easier to know what to remove/add- Another method: for each mesh than can have hole in it, create an "inverse mesh" which will hold all the vertices & faces that have been removed from the main mesh. This mesh can be invisible but will still detects when we click on it. Dad72 1 Quote Link to comment Share on other sites More sharing options...
jahow Posted April 22, 2015 Share Posted April 22, 2015 Another try: http://www.babylonjs-playground.com/#8OMYN#9 This time I'm switching the face direction, meaning that the faces will become invisible if backface culling is activated. They can easily be switched back afterwards Also the geometry is not changed at all. You have "l'embarras du choix"! jerome and Dad72 2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 22, 2015 Author Share Posted April 22, 2015 I like the latter. Thank you Jahow, but the question I ask myself is: Is that if I hide the faces, a character can pass through the holes. The collision is still activate in the holes or no? I wish that a character can pass through this mesh where the holes are. Thank you again Jahow. Quote Link to comment Share on other sites More sharing options...
jahow Posted April 22, 2015 Share Posted April 22, 2015 Well, I know almost nothing about collisions in BJS so I can't really say for sure... But I guess you'd have to actually remove faces like I did in the first example I gave you. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 22, 2015 Author Share Posted April 22, 2015 I just think of a solution. From the editor last solution to hide the faces and record them in a .dat. And when one is in game I take all the faces hidden this .dat file and I delete as your first solution. I think it will work like this. I think this time everything is ok. Big thanks Jahow Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 22, 2015 Author Share Posted April 22, 2015 Arf, my solution does not work in case the user want to close the hole in the future. it is necessary that I remove the collision on the faces hidden only. So I think Deltakosh is able to answer that :Can we disable collisions on some faces of a mesh. If so, how? Thank you very much Quote Link to comment Share on other sites More sharing options...
joshcamas Posted April 22, 2015 Share Posted April 22, 2015 Do I spy a hobbit hole? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted April 23, 2015 Author Share Posted April 23, 2015 What do you mean by: "hobbit hole" ? 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.