leota Posted July 18, 2018 Share Posted July 18, 2018 Hi there, learning Babylon.js since 2 days I've created a "container" mesh (with no geometry), and then added to it 2 children meshes, a box and a sphere. I would like to pick the container mesh on mouseClick event, but actually either box or sphere get selected. Is there a way to ignore submeshes? I know there would be many workarounds, like for example creating the container as a box with a transparent material, but I was just wondering if there was a flag/parameter a can set when doing raycasting. Here you can find the PG: https://www.babylonjs-playground.com/#BD4L6U Quote Link to comment Share on other sites More sharing options...
babbleon Posted July 18, 2018 Share Posted July 18, 2018 this? https://www.babylonjs-playground.com/#BD4L6U#1 (line 41) Quote Link to comment Share on other sites More sharing options...
leota Posted July 18, 2018 Author Share Posted July 18, 2018 5 minutes ago, babbleon said: this? https://www.babylonjs-playground.com/#BD4L6U#1 (line 41) Not really, because in a situation like this: - Mesh1 - Mesh2 - Mesh3 The ray will pick Mesh3, its parent is Mesh2, but actually I want Mesh1 to be picked. Sorry for not mentioning this earlier Quote Link to comment Share on other sites More sharing options...
babbleon Posted July 18, 2018 Share Posted July 18, 2018 How about this? https://www.babylonjs-playground.com/#BD4L6U#3 This will return the ultimate parent. Quote Link to comment Share on other sites More sharing options...
leota Posted July 18, 2018 Author Share Posted July 18, 2018 Yes this could make it definitely a better workaround. So just to make sure, there's no way to tell the Raycast to ignore submeshes, right? Quote Link to comment Share on other sites More sharing options...
babbleon Posted July 18, 2018 Share Posted July 18, 2018 I don't think there is, but others here may know otherwise. However, your container has no geometry so there's nothing to pick - I think I'm right in saying. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
leota Posted July 18, 2018 Author Share Posted July 18, 2018 6 minutes ago, babbleon said: I don't think there is, but others here may know otherwise. However, your container has no geometry so there's nothing to pick - I think I'm right in saying. Makes totally sense Quote Link to comment Share on other sites More sharing options...
brianzinn Posted July 18, 2018 Share Posted July 18, 2018 1 hour ago, leota said: So just to make sure, there's no way to tell the Raycast to ignore submeshes, right? You can put in any logic you wanted in a predicate for scene.pick/raycast - here I am ignoring clicks on any meshes named 'sphere' : https://www.babylonjs-playground.com/#BD4L6U#4 In that PG I check the mesh.name, but you can ignore anything based on child/parent hierarchy or submeshes. note: Thanks for making a playground as they really help answering questions. it's a bit nitpicky for me to say - as you probably quickly did it for a PG, but adding click handlers to 'window' has some issues when you rerun playgrounds (ie: hit run a couple of times) then they're a bit harder to edit from the errors as handlers keep being added and activeScene isnt' available after re-run Anyway, I've attached to pointerDown on Scene as one other example. cheers! Quote Link to comment Share on other sites More sharing options...
leota Posted July 18, 2018 Author Share Posted July 18, 2018 @brianzinn thanks for your updated PG . Sorry for attaching event to Window object I wasn't considering the the page never gets refreshed on re-run. brianzinn 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.