Zooming to 100% model surface

I am still struggling a bit with how to be able to zoom to a models surface but not have the camera go “through” an object. ( clipping ).
I I just limit the zoom to the bounding box

var framingBehavior = scene.activeCamera.getBehaviorByName("Framing");
framingBehavior.framingTime = 0;
framingBehavior.elevationReturnTime = -1;
if (scene.meshes.length) {
    var worldExtends = scene.getWorldExtends();
    scene.activeCamera.lowerRadiusLimit = null;
    framingBehavior.zoomOnBoundingInfo(worldExtends.min, worldExtends.max);
scene.activeCamera.radius = scene.activeCamera.lowerRadiusLimit * 2.5;
scene.activeCamera.pinchPrecision = 200 / scene.activeCamera.radius;
scene.activeCamera.upperRadiusLimit = 5 * scene.activeCamera.radius;
scene.activeCamera.lowerRadiusLimit = 0;

I have the problem that depending on the model shape some areas can be zoomed to the surface, while others remain far away even at highest zoom.
Maybe the ArcRotateCamera is not the right tool for that?


camera minZ!

it by default is 1, so if you zoom in closer then that things will get clipped.

set it to like 0.1 but be aware that z fighting will happen at longer distances if you have a low minZ

Thanks, but i already have it at 0.0001
That does not help.

Can you give us a playground to help us troubleshoot with you?

What I would like to achive is to be able to fly / zoom into the pot if accessed from the open top side and watch the bottom up close but not be able to clip through the sides.

So it sounds like you’re planning on changing the radius of the arcRotate camera based on some type of user interaction, but then you want to avoid colliding through the walls of the “pot.”

There’s a bunch of different ways you could go about something like this, but off the top of my head, I’d probably dig into raycasting and using the distance property of pickingInfo to set the radius of the arcRotate camera.

Basically cast a ray every frame that grabs the distance from the camera to an object, and then make sure it stays above a certain value.


1 Like