Richard C Posted August 11, 2017 Share Posted August 11, 2017 My project is ocean based. I want to measure the water depth as a vessel travels the water surface. The seabed is undulating, so I would expect the point at which the ray intersects the 'seabed' mesh to change as the vessel moves through the water. I understand the ray interacts with the bounding box of the mesh it is intersecting. My problem appears to be that the bounding box of the seabed is effectively a rectangle and currently as the vessel moves the water depth is remaining constant. My code (pinched from examples in the PG) is : var ray = new BABYLON.Ray(new BABYLON.Vector3(0, nSeaBed.getBoundingInfo().boundingBox.maximumWorld.y, 0), new BABYLON.Vector3(0, -1, 0)); var worldInverse = new BABYLON.Matrix(); nSeaBed.getWorldMatrix().invertToRef(worldInverse); ray = BABYLON.Ray.Transform(ray, worldInverse); var pickInfoW = nSeaBed.intersects(ray); waterDepth = (pickInfoW.pickedPoint.y); 1. It seems to me that the ray should be intersecting with the actual mesh rather than the bounding box. Is this possible? 2. Also. I have to admit I don't understand the code - would someone be kind enough to comment each line to briefly explain what the code is doing, particularly 'invertToRef'. Thanks Richard C Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 11, 2017 Share Posted August 11, 2017 Hello I would recommend relying on scene.pick: scene.pick(0, 0, function(mesh) { return mesh.name === "myseabed"; }) It will return a pickingInfo: http://doc.babylonjs.com/classes/3.0/pickinginfo You should have everything there (including pickedPoint where you could use the y coordinate :)) Quote Link to comment Share on other sites More sharing options...
Richard C Posted August 11, 2017 Author Share Posted August 11, 2017 @Deltakosh I'm not sure how this will work. I assume scene.pick is for mouse use. I assumed I should be using a ray, fired on each frame from the vector.y of the water's surface where the vessel is to the seabed. How can scene.pick work in that senario please? Thanks Richard C Quote Link to comment Share on other sites More sharing options...
adam Posted August 11, 2017 Share Posted August 11, 2017 Here is an example using a Ray and RayHelper: https://www.babylonjs-playground.com/#1UZIZC#33 JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 11, 2017 Share Posted August 11, 2017 Hiya RC, good to see you again. Hope things are going good. Why not test in a playground? Here's a nice starter... with an undulating sea-bed about 150 units below the camera. Perhaps paste-in all your new pickin' toys, and see if you can get some numbers streaming to console.log. FUN! Would Jerome's umm... getDistanceAboveHeightMap() work? No, that's not the correct name. What the heck was that straight-down-to-heightMap distance checker thing... that Jerome coded? umm. I'll think of it... eventually. PS: I stole this animated ground playground from somebody... its COOL! Quote Link to comment Share on other sites More sharing options...
Richard C Posted August 14, 2017 Author Share Posted August 14, 2017 @adam @Wingnut Thanks Adam and Wingnut (hope things are good with you too). I am continuing to play but could I ask you or anyone else the answer to the my original question ............ 1. It seems to me that the ray should be intersecting with the actual mesh rather than the bounding box. Is this possible? I vaguely remember reading somewhere of there being a .getboundingMesh - does it exist or is it just wishful. Wingnut - I'm not sure using a heightmap for the seabed will be a workaround - I have modelled quite a few 3d coral reef objects that will of course build off the sea bed. I am thinking the seabed could be split into sections each according to height. I can then raycast from the bounding boxes from each of there together with the same for each coral reef. It would still be good to know if there is something like a bounding mesh. Adam, I assume you are suggesting I try making the 'seabed' a ribbon, albeit a static one. If a seabed were to move as much as the sine wave makes the ribbon in that PG I think we would have a Tsunami Cheers Ricard Quote Link to comment Share on other sites More sharing options...
jerome Posted August 14, 2017 Share Posted August 14, 2017 If you use a BJS provided GroundMesh object to depict the seabed, you'll get immediatley the method getHeightAtCoordinates(x, z) http://doc.babylonjs.com/classes/3.0/groundmesh#getheightatcoordinates-x-z-rarr-number Wingnut and JackFalcon 2 Quote Link to comment Share on other sites More sharing options...
SvenFrankson Posted August 14, 2017 Share Posted August 14, 2017 I think scene.pick and scene.pickWithRay does intersect with the Mesh, not only its boundingBox. Here an example with scene.pick (click to add small spheres in the scene) : https://www.babylonjs-playground.com/#TUSYHN If it were using boundingBoxes, the small spheres would not be placed correctly on the large sphere. JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
adam Posted August 14, 2017 Share Posted August 14, 2017 2 hours ago, Richard C said: Adam, I assume you are suggesting I try making the 'seabed' a ribbon, albeit a static one. Nope https://www.babylonjs-playground.com/#WJPB9#39 That example uses Pick (click on the ground) and Ray with a ground mesh. edit: and an example that uses a model: https://playground.babylonjs.com/#YEHNDI#2 Wingnut and JackFalcon 2 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 14, 2017 Share Posted August 14, 2017 Tons of cool toys! Excellent! @Richard C yeah, bottom of sea is MORE THAN simply ground. Other stuff, too. Those other things affect depth-sounding values. Yep, good point. You need more than depth-to-ground. You need depth to whatever is below, be it ground, modeled reef, sunken ship, whale. Quote Link to comment Share on other sites More sharing options...
Richard C Posted August 15, 2017 Author Share Posted August 15, 2017 @jerome @SvenFrankson @adam @Wingnut Thanks all. adam - your suggestion works for my project, so problem solved. I now have a working depth sounder. Right, on to the next challenge ! Cheers Wingnut 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.