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 */ }
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
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:
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.
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…
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).
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.
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.