Jump to content

How to pick a Mesh which acts as container of other meshes?


leota
 Share

Recommended Posts

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

Link to comment
Share on other sites

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!

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