oschakravarthi Posted November 19, 2018 Share Posted November 19, 2018 Hi, I am trying to build navigation mesh programatically for my flat (apartment) model The logic I could think of, 1. I know all the floor meshes of my model. I keep them in an array. 2. I create a empty CSG and add (union) of CSG of all floor meshes. 3. For each non-floor mesh, I check if it is intersects with any of the floor mesh. If yes, then substract that part from my unioned CSG. (It makes a hole) 4. Build a new mesh from the unioned CSG. The below is a rough implementation of this idea. Can you please suggest a better approach? Thanks in advance. var buildNavMesh = function (scene, floorMeshes) { var navigationCSG = new BABYLON.CSG(); floorMeshes.forEach(floorMesh => { var floorMeshCSG = BABYLON.CSG.FromMesh(floorMesh); navigationCSG.unionInPlace(floorMeshCSG); }); var nonFloorMeshes = []; scene.meshes.forEach(mesh => { if (floorMeshes.indexOf(mesh) < 0) { nonFloorMeshes.push(mesh); mesh.position.y -= 0.2; } }); scene.render(); for (var i = 0; i < floorMeshes.length; i++) { var floorMesh = floorMeshes; nonFloorMeshes.forEach(nonFloorMesh => { if (nonFloorMesh.intersectsMesh(floorMesh)) { var nonFloorMeshCSG = BABYLON.CSG.FromMesh(nonFloorMesh); navigationCSG.subtractInPlace(nonFloorMeshCSG); } }); } nonFloorMeshes.forEach(mesh => { mesh.position.y += 0.2; }); var navMesh = navigationCSG.toMesh("csg4", null, scene, true); scene.removeMesh(navMesh); return navMesh; }; Quote Link to comment Share on other sites More sharing options...
oschakravarthi Posted November 20, 2018 Author Share Posted November 20, 2018 @trevordev, Can you please help me? Quote Link to comment Share on other sites More sharing options...
trevordev Posted November 20, 2018 Share Posted November 20, 2018 @oschakravarthi That sounds like an ok approach (however I havn't used nav meshes before) I would also use the objects bounding box instead of the raw object for csg. 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.