ArcRotate camera zoomOn not working as expected


All started here:

Here is a repro:


Expected result (smthg like this):


Would you please check this guys?

Thank you!


If you insert scene.render() it works:


it works. But I don’t know if this is the correct way ,

Hmm, I could be wrong but I believe since it’s the arcRotateCamera, you should set the target first. Else, there’s no target.

Edit: Just checked back and you can also use
I believe both work, as long as the camera has intially a target (or setTarget).
However, I also believe that (line 8 in your PG) also demonstrates that if setTarget is a vector, it doesn’t seem to accept to zoomOn a mesh??!! Weirdo, isn’t it? Or I might have missed something? :thinking:

Making a last check, it could be related to the absence of boundingBox info when initially setting the target to a Vector3. It could be that zoomOn would just not be accounting this information when switching from vector to a mesh. But that’s only a guess. Worth checking it out may be (or may be not :wink:)

1 Like

Hey @mawa!

Thank you! :wink:

It was never a requirement to set a target to use zoomOn. The second thing here, zoomOn accepts multiple meshes and should change the camera’s values to have all of these meshes visible.

This made me think a bit and the result is:

If you put the zoomOn code in the onReadyObservable callback it works as expected even with multiple meshes.

However this was never the case. Maybe this is due some optimalizations of the scene, maybe the bounding box is not calculated just right after the mesh is added…

Have a look here and check the Agressive mode:

On the other hand the scene should be in backward compatible mode by default but maybe there are issues in the code. Just guessing :slight_smile:

1 Like

Unfortunatelly I don’t have time now to play with this :frowning: so I’ll humbly wait for the team’s response :slight_smile:

To be honest, I never used it but I believe you when you say it wasn’t.

Yes, makes sense from the pseudo-fix above calling scene.render().

Can’t agree more.

Yes, same for me. Hope it won’t take too long since you are using it. Meanwhile, have a great day :sunglasses:

1 Like

You too buddy! you need the sphere world matrix to be ready I believe

@PolygonalSun can confirm it is the correct approach ?

1 Like

This all sound good, but I have also a prolbem with zoomOn when the camera looks not from the front but from a different angle.

It does not zoom out so that I see the whole box, what can I do here?

THX :wink:

1 Like

I guess what @roland was saying is that the function was doing all that…until it didn’t anymore.
I can’t say because I haven’t used it before but I guess he can confirm. Can you?

1 Like

@mawa @sebavan Yes, I can confirm, everything was cool until something was broken/changed somewhere in a minor version of BabylonJS 5.

However I’m now using @sebavan 's ‘hack’, I have a presentation this week so I need get it working somehow :smiley:

Thanks @sebavan… I’ve tried to force compute the boundingBox, didn’t think about the world matrix though.

EDIT: I am curious, why is the world matrix not computed just right after the mesh is added to the scene (anymore?).

A great question for @PolygonalSun if he can have a look ?

Hey, @roland,
I can take a look and see what’s going on. I think that I might have an idea what’s going on.


Yeah, that matches up with what I’m seeing. Basically, in the example PG, there is a position change against just the x coordinate. While this will move the sphere and make it appear in the right spot, the world matrix hasn’t been updated with this information at the time of the zoomOn call. When zoomOn calls Mesh.MinMax, the boundingInfo is pulled and the world matrix used is whatever is in cache at the time. I’m not sure what caused the change in behavior but my proposed fix would be to force a computeWorldMatrix for all meshes used in the zoomOn meshes argument. Lemme verify it doesn’t have any unintended consequences and if we’re clear, I’ll create a PR with the change.

1 Like


@PolygonalSun @sebavan @mawa

I am bit confused now :slight_smile: I am on BJS 5.46 now and the things seems to be fixed, at least for me, my code works again the same.

EDIT: on 5.47 just right now and it works too

Well, I can only guess the fix must have somehow gone through ‘under the radar’.
I just opened my latest PG and restored your original setTarget to a vector3 and it now zoomOn properly on sphere. So I believe this one is now ‘gone with the wind’ :wind_face: :smiley:
Although, there seems to be still some sort of delay. If I zoomOn instantly (on scene building/render), it doesn’t work. If I do a timeout (or a new render) it works :thinking:

1 Like

@PolygonalSun just to double check, was the issue solved?

AFAIK, it’s working as intended. If I’m incorrect about this, feel free to ping me and let me know what is being seen.

Last time I tried it was working just fine. @roland Can you confirm?

@mawa @PolygonalSun @carolhmj

As far as we expect to calculate the world matrix of the mesh before using zoomOn with that mesh than it’s OK.