Skip to content

Commit b83d857

Browse files
authored
Add support for zoomOn with ArcRotateCamera in Orthographic mode (#16737)
I am working on a project that uses the ArcRotateCamera in Orthographic mode. I want to use the `ArcRotateCamera.zoomOn` function to zoom to a set of meshes. Unfortunately, the zoomOn function updates only the radius, not the orthographic extents. This PR updates the orthographic extents along with the radius when zooming onto mesh(es) in orthographic mode. Here is a demo playground: https://playground.babylonjs.com/#545IZ4 **Before:** https://github.com/user-attachments/assets/77b8516e-4ec8-40e0-a4d5-4f9ae0d4104d **After:** https://github.com/user-attachments/assets/876c3b68-3638-48a2-9b71-c909a4ae55ef
1 parent 4e5a7f7 commit b83d857

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/dev/core/src/Cameras/arcRotateCamera.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,15 @@ export class ArcRotateCamera extends TargetCamera {
14521452
distance = Math.max(Math.min(distance, this.upperRadiusLimit || Number.MAX_VALUE), this.lowerRadiusLimit || 0);
14531453
this.radius = distance * this.zoomOnFactor;
14541454

1455+
if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {
1456+
const aspectRatio = this.getScene().getEngine().getAspectRatio(this);
1457+
const orthoExtent = (distance * this.zoomOnFactor) / 2;
1458+
this.orthoLeft = -orthoExtent * aspectRatio;
1459+
this.orthoRight = orthoExtent * aspectRatio;
1460+
this.orthoBottom = -orthoExtent;
1461+
this.orthoTop = orthoExtent;
1462+
}
1463+
14551464
this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);
14561465
}
14571466

0 commit comments

Comments
 (0)