How to update bounding info properly?

Hi there,

I’m working on an app when I’m trying to update the bounding box of several meshes that I rotated first to use it directly in the observer callback then (but everything in its own time…).

I used the playground given in the docs here:
and adapted it to show you the situation : playground of the situation

It seems that the bounding box is not updated well and is not surrounding the meshes properly (and it’s even worse in my application where there is more meshes) but I can’t find out how to make it work properly. I tried to use refreshBoundingInfo() or computeWorldMatrix() on each mesh but always without success. Do I have to use a transformNode and how ? …

Do you have any idea of how to make it work properly ? Maybe I’m doing something wrong because I’m discovering the framework.


PS: I’m french, sry for my potentlially bad english


A very clear question, no need to apologize :slight_smile:

The issue was in line 62 - Bounding Box - problem with pointerEvent sync | Babylon.js Playground ( , you need to force-compute the world matrix, otherwise it will use the cached version.

Thank you again @RaananW for the quick answer. :slight_smile:

It seems to work fine in the playground indeed but it solves only partially the problem in my application.

To explain it quickly, the “parent” in the playground is the root mesh of a loaded gltf file in the application. When the user toggles a button in the app, it enables/disable a UI which allows the user to rotate the meshes like in the playground. There are other differences like a ground set up with createDefaultEnvironment() but I didn’t think it was involved.

Thanks to your fix, it seems (I quickly tested it) to work great when I create a custom parent mesh on my own (parenting all the meshes including the root one). But with the root mesh itself, the bouding box is not updated well. Is there something different with loaded meshes structures that could create that behavior ?
Oh and by the way, is the minimum world value of the bounding info always giving the lower point of a bounding box in the scene ?

I’m afraid that it seems difficult to create a playground for it but if you have some leads, I gladly take it.

Thanks again

Would be great to have that reproduced to understand what’s happening. Will you be able to reproduce that somehow?

It’s hard to say what could be the issue…

Yes I understand…

I can try to make something close to what I expect in a playground as soon as possible and come back here with the link then (or with a solution if I found one, who knows… :sweat_smile:)

1 Like

Hi again @RaananW, I’m back with a playground but unfortunately, it behaves differently in the application.

So, to go further in my issue, the purpose here is to make a UI that allows the user to rotate the loaded model. The BoundingInfo comes here for one reason : replace the model on the top of the ground each time the model orientation is modified.

This playground is what I’ve got so far as a reproduction of what’s going on : playground.

Of course it’s a part of it because in the app, there’s no GUI like there but some React UI made in the application (it’s a React web app using Babylonjs inside it) , the camera replaces itself on the model automatically and animations or materials smooth the experience but the idea is here. (I adapted the Babylonjs code, notably zoomOnBoundingInfo for example so i think it was overkill to do it here again).

However, here are the differences between the playground and the app that I noticed as potentially relevant in that case (i will update it if I found new ones) :

  • in the app, orientationGUI3DManager, modelTransformNode and uiOn are static variables in the file that are reused in two methods: one setting the ui (which is the case !uiOn in the playground) and one exiting the ui (the else case)
  • in the app, the hierarchy of the model I’m testing for now (it could be another one but the structure tends to be the same) contains initially two TransformNodes under the “root” one in cascade (one setting rotation values and one setting scaling values), and under the last one, all the meshes are listed.
  • in the app, the ground is created with createDefaultEnvironment with a groundYBias = 0.01

To be positive, I made some improvements since the last time. As you can see, it works quite well now in the playground, except in the case when we stop rotating the model as it is “horizontally” placed. Indeed, when we close and open again the ui, the bounding box is not well placed at first, but we observe the expected behavior then (a transformNode and some updates of the bounding info were needed and i changed the order of some operations to reach that point).

However in the application, where I almost copied and paste what I made in the playground (see differences for more information), the bounding box is just not well placed and the repositioning also goes wrong…
It’s better when I use a custom parent mesh parenting the “root” one (which I use as the rootMesh in the playground). In that case, it behaves close to what expected sometimes but the bounding box shown seems broken.
I don’t know how to show you that, can a quick video of what’s happening be usefull ?

As I read myself, I see that it’s not easy to help on this basis, but if you have any question or further information needed about something, I can try to give more details.

So here I am so far, do you have any lead on how to make it work (even if it invloves a completely different solution) ?


Hello @RaananW , I allowed myself to tag you in case you didn’t see the update because I didn’t properly reply to your message but I replied to the entire subject.

Let me know if it was wrong to do that.


Hi again,

I’ve got some new information.
It seems that the behavior is different on the application because of the version of babylonjs running. It’s currently the 4.2.0 in the application whereas the playground is running on the 5.0.0. If I switch to 4.2.0 too in the playground, the behavior is similar to the application one.

So I updated the version to the 5.0.0-alpha.22 in the application.
Now, it behaves almost like in the playground but some problems are still here with the initialization of the bounding info (somehow related to what appends in the case mentionned here about the horizontal position of the model and the relaunch of the UI)

So I still need help but there’s progress :sweat_smile:

Hello again,

I’m a bit late for the update but I think I fixed the problem by using a parent mesh dedicated to the boundingInfo. You can see the previous playground fixed with this method here : playground

I don’t know why, but it seems that the ‘root’ Mesh of the gltf loaded does not behave as a new Mesh and messes up the bounding info computing in that case.

So I guess my fix is probably a workaround but at least, it seems to work :sweat_smile:

Anyway thanks again @RaananW for your help and your time ! :slightly_smiling_face:

1 Like