Jump to content

Pointer intersects bounding box


sable
 Share

Recommended Posts

I've just been finding a way to test if the pointer intersects with a bounding box of a mesh in the scene, and have come up with http://www.babylonjs-playground.com/#T1PZSJ#3

I've a couple of questions though.

First, is there a more obvious way to do this that would tie in with the action manager?

Second, why is ray.intersectsBox() and similar methods dealing with mesh local space and not world space (i.e. it's internally using minimum and maximum as opposed to minimumWorld and maximumWorld). There's likely a good reason, but I couldn't find anything that even references that before using these methods a transform on the ray would be needed (to get it from world to mesh local space), besides in one post here.

Link to comment
Share on other sites

Hey, you can just use the onPointerDown:

    scene.onPointerDown = (e, pickResult) => {
        if (pickResult.hit) {
            // Check pickResult.mesh === myMesh
		}
    }

For your second question: I'm using local world because if you want to get the picked point you won't need to transform ALL vertices to world space. It is faster to move the ray to local space instead of moving all vertices to world :)

Link to comment
Share on other sites

Hey Delta, thanks for your reply.

I was specifically looking for a way to pick using the bounding box, as the mesh I'm wanting to pick has holes in it. I want the whole area to be pickable, and using the bounding box seemed like a good way to achieve this (while also getting a nice buffer area for the pick).

Thanks for the explanation regarding local space, that does make sense.

Link to comment
Share on other sites

IMO, you will need to intelligently use the predicate to limit the intersecting meshes and use fast check for the best performance.

I remember once suggesting a bounding-box/sphere only ray pick, but it had an (obvious) problem getting the exact point of the intersection. It shouldn't be too heard to implement thou, if this is enough for you.

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