# Wrong position of bounding box

**URL:** <https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828>\
**Category:** Bugs\
**Created:** [July 5, 2024, 12:04pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828 "2024-07-05T12:04:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 5, 2024, 12:04pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/1 "2024-07-05T12:04:52Z")

</div>

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 */ } `

> **[Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%2315)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [July 5, 2024, 1:33pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/2 "2024-07-05T13:33:17Z")

</div>

Hello 🙂

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

➡[Fixed Playground](https://playground.babylonjs.com/#6QTQLT#3)

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 6, 2024, 5:37am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/3 "2024-07-06T05:37:54Z")

</div>

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](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:

> **[Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%236)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 6, 2024, 10:50am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/4 "2024-07-06T10:50:15Z")

</div>

The picking part can be fixed like this:

> **[Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%239)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 6, 2024, 12:53pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/5 "2024-07-06T12:53:24Z")

</div>

With the bounding-box-all-selected:

> **[Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%2310)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 6, 2024, 1:28pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/6 "2024-07-06T13:28:04Z")

</div>

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.

> **[Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%2312)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 6, 2024, 1:39pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/7 "2024-07-06T13:39:30Z")

</div>

See the second PG I posted

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 6, 2024, 1:41pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/8 "2024-07-06T13:41:52Z")

</div>

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:

> **[Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%2313)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 6, 2024, 1:48pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/9 "2024-07-06T13:48:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 6, 2024, 2:13pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/10 "2024-07-06T14:13:09Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 6, 2024, 2:56pm UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/11 "2024-07-06T14:56:28Z")

</div>

> [@yedpodtrzitko](#):
>
> That would work in this minimal example with specific set of meshes,

Sry dude that’s what you asked for 😃

However:

> **[Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%2314)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

> [@yedpodtrzitko](#):
>
> (Also the tree parts have a parent already - the ` __root__ ` mesh. How come it doesnt work with that?)

> [@Incorrect Bounding Info](https://forum.babylonjs.com/t/incorrect-bounding-info/44336/):
>
> Hello again! I have an application that requires bounding information of meshes, regardless of their transformations (except scaling). Which means, I would like to read correctBoundingInfo.boundingBox.extendSize to output the same value regardless how it’s translated or rotated, and surely the multiplied value when scaled. (Not sure if extendSize or extendSizeWorld+transformation, but you get the point, I need to get the same width-height-depth values of the box) The bounding related methods w…

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 7, 2024, 3:16am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/12 "2024-07-07T03:16:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 7, 2024, 4:47am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/13 "2024-07-07T04:47:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 7, 2024, 4:51am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/14 "2024-07-07T04:51:00Z")

</div>

> [@yedpodtrzitko](#):
>
> when clicking the violin attached to bone, it should show bounding box of the violin, but the BB is misplaced.

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

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/8/78e4b363f55a827584411c8313a06747890aac3d.jpeg)

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

> [@roland](#):
>
> Sry dude that’s what you asked for 😃
> 
> However:
> 
> [Babylon.js Playground](https://playground.babylonjs.com/#6QTQLT%2314)

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/f/1/f176fc4a3a620badcb87d838ab149eb64316ecda.jpeg)

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 7, 2024, 5:31am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/15 "2024-07-07T05:31:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 7, 2024, 5:35am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/16 "2024-07-07T05:35:42Z")

</div>

> [@yedpodtrzitko](#):
>
> 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.

> [@yedpodtrzitko](#):
>
> I mentioned that I am spawning the meshes dynamically, so I cant just hardcode the logic as `if (tree) else girl`.

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

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 8, 2024, 12:23am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/17 "2024-07-08T00:23:30Z")

</div>

> [@roland](#):
>
> Not to mention you added this edit after my previous response. Dude dude you killing me… 😃

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

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 8, 2024, 12:31am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/18 "2024-07-08T00:31:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yedpodtrzitko](https://avatars.discourse-cdn.com/v4/letter/y/a9a28c/32.png) [@yedpodtrzitko](https://forum.babylonjs.com/u/yedpodtrzitko)\
**Post date:** [July 8, 2024, 1:32am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/19 "2024-07-08T01:32:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 8, 2024, 2:31am UTC](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828/20 "2024-07-08T02:31:13Z")

</div>

> [@yedpodtrzitko](#):
>
> So thanks for nothing I guess and bye.

LOL Insolent and smug 😃

Comment out line 74, vole!

[Next page](https://forum.babylonjs.com/t/wrong-position-of-bounding-box/51828.md?page=2)
