Double-click mouse wheel = Zoom All

Hi all,

I’m trying to achive a behavior similar to CAD programs, when I double-click scroll to zoom all and displaing all meshes in the scene.
I tried something, but my math su…

Adding @PolygonalSun our Camera wizard :slight_smile:

So, I first want to make sure that I’m understanding what you want to do. What you’d like to do is to make it so that when you double-click the mouse wheel, the camera will zoom in/out to display all available meshes (I’m assuming that you don’t care about the ground mesh). For a feature like this, the first thought that comes to mind is to try leveraging the camera’s field of view to get your computed radius by doing something like:

// Angles of the camera's frustum, with respect to the camera's target
const frustumSlopeY = Math.tan(camera.fov / 2);
const frustumSlopeX = frustumSlopeY * engine.getAspectRatio(camera);
// Get the radii with respect to each axis and take the bigger one
const computedRadiusY = Math.abs((maxZ-minZ) / 2) / frustumSlopeY;
const computedRadiusX = Math.abs((maxX-minX) / 2) / frustumSlopeX;
const computedRadius = Math.max(computedRadiusX, computedRadiusY);

I’m a little rusty on the math myself but this may get you the desired result. You may also want to add a little bit extra of a margin to your computedRadius to account for the sizes of your meshes.

2 Likes