Jump to content

RayCasting


Richard C
 Share

Recommended Posts

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...