Wrong position of bounding box

I’ve edited the PG example to take into consideration some other scenarios

current (expected) behaviour:

  • when clicking tree, it should show bounding box of the whole tree, not just trunk or crown. This works fine now due to traversing upward in the hierarchy

  • when clicking dude, it should show bounding box of the whole character. this also works fine

  • when clicking sphere attached to bone, it should show bounding box of the sphere. this also works fine now, thanks to @Tricotou

what doesnt work:

  • when clicking the violin attached to bone, it should show bounding box of the violin, but the BB is misplaced.

one more edit: I am spawning the meshes ad-hoc, so I cant hardcode the logic as if (tree) { /* tree scenario */ } else { /* girl scenario */ }

Hello :slight_smile:

Having a look at your setup I fund a few issues :

  • skeleton.scaling = new BABYLON.Vector3(0.02, 0.02, 0.02); → you should do dude.scaling = new BABYLON.Vector3(0.02, 0.02, 0.02); in this context, as well as you used dude for rotation.
  • In your hierarchycal bounding box compute, you do not check either mesh (last node traversed) and clickedMesh are the same. If they are the same (which is the case for the sphere), then there is no need to rebuild any bounding box

:arrow_right: Fixed Playground

1 Like

Thanks for your response. Some of the issues are actually from existing PG which I was using as a reference when learning how to attach mesh to bone ( https://playground.babylonjs.com/#11BH6Z#18 ). I was working with the sphere in the provided instead of attaching a compound mesh, as it looked like it’s (mis)behaving the same way.

Unfortunately the fix for the sphere is not working with the compound mesh, see this updated PG:

The picking part can be fixed like this:

With the bounding-box-all-selected:

Thanks, this one would be perfect, but it the traversing is needed to make it work with meshes like this tree - right now it select only the trunk or crown instead of the whole tree.

See the second PG I posted

I tried to add the tree into that example as well, but that still doesnt work as expected - only the trunk or crown is selected:

Create a parent for the tree parts as I did for the girl and the violin

That would work in this minimal example with specific set of meshes, however in the real project I am dynamically adding meshes into the scene and any of them can be selected with the bounding box displayed, so having just one parent variable wont work unless there will be some ad-hoc (un)parenting, which feels brittle. (Also the tree parts have a parent already - the __root__ mesh. How come it doesnt work with that?)

The other approach would be to traverse upward in the hierarchy to reach the parent dynamically, but that’s where I started and where I have issue with the bounding box position, so…

Sry dude that’s what you asked for :smiley:


I dont believe I asked for that specifically, but I agree the MVP didnt properly reflect all the expectations and edge cases.

I updated the original post to be explicit about the expected behaviour and all different cases.

Thanks for the provided link. I read through the whole thread there, and tried to apply each approach, but none of that still work as expected for each scenario (either the tree or violin is misbehaving).

If you edit a post which has answers already, don’t remove the original question. Add an EDIT: mark and type your edit below.

1 Like

I’ve provided 3 PG’s where the violin picking works:

You replaced the picking code everytime you posted your PG with the old one which doesn’t work! (hey @Tricotou wassup! :smiley: )

ok I’ll do the edit better next time.

The example you provided is ignoring the constraint I mentioned that I am spawning the meshes dynamically, so I cant just hardcode the logic as if (tree) else girl.

Code your own logic to select the right parent according to the picked mesh.

Not to mention you added this edit after my previous response. Dude dude you killing me… :smiley:

1 Like

this was already mentioned in another message I posted in this thread earlier.

1 Like

Sorry I’m dropping the :microphone: …and you already have a solution

None of the solutions you provided works as expected. Eg. when I click the tree trunk, it shows the tree bounding box (expected), but also the bounding box of the trunk, which is not desired. Same with violin/sphere - I need only the bounding box of that particular item, not the whole character. So thanks for nothing I guess and bye.

LOL Insolent and smug :smiley:

Comment out line 74, vole!

1 Like