sable Posted September 20, 2017 Share Posted September 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 21, 2017 Share Posted September 21, 2017 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 Quote Link to comment Share on other sites More sharing options...
sable Posted September 21, 2017 Author Share Posted September 21, 2017 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 22, 2017 Share Posted September 22, 2017 I get it..you can still use the scene.pick with fastCheck = true (http://doc.babylonjs.com/classes/3.0/scene#pick-x-y-predicate-fastcheck-camera-rarr-pickinginfo-classes-3-0-pickinginfo-) Quote Link to comment Share on other sites More sharing options...
sable Posted September 24, 2017 Author Share Posted September 24, 2017 That doesn't seem to actually test using the bounding box, but rather just returns the first positive result (despite what the documentation there says. The mesh.intersects documentation for fastcheck here seems more correct). Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 24, 2017 Share Posted September 24, 2017 Hi Sable, you can set a predicate and make sure it only picks that what you want it to pick. Does this work in your usecase? Quote Link to comment Share on other sites More sharing options...
sable Posted September 24, 2017 Author Share Posted September 24, 2017 @RaananW For my use case that doesn't work, as it's not about picking a certain mesh over other meshes, but rather that I want to be able to pick the mesh by clicking anywhere in the encompassing area, even where there are holes (such as the center of a torus http://www.babylonjs-playground.com/#T1PZSJ#5) Quote Link to comment Share on other sites More sharing options...
RaananW Posted September 25, 2017 Share Posted September 25, 2017 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. 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.