Skip to content

Conversation

@georginahalpern
Copy link
Contributor

This is a refactor of the PR proposed here: #17292

  • Adds new optional param 'mode' to the framingBehavior zoomOnBoundingInfo. If specified, calls into the camera's new _calculateLowerRadiusFromModelBoundingInfo function which respects the passed in mode and adds orthographic framing

  • If no mode is sent, default to old behavior (using cameras _calculateLowerRadiusFromModelBoundingSphere fn, and not adding orthographic framing)

This maintains backwards compatibility of old behavior while still offering option to use new behavior

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 21, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 21, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 21, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 21, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 21, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Oct 21, 2025

@PietroFurlan
Copy link

I work a lot with BabylonJS and I love getting my hands dirty with the code.
Unfortunately, I can’t share my main projects, but if you’re interested, I have some other integrations like this one that I can share.

For example, I’ve made a “light” version of the OBJExporter that can shrink mesh size by up to 60%, by skipping details like normals, materials, etc.

Let me know if you’re interested!

const depth = (maximumWorld.z - minimumWorld.z) * 0.5;
const aspectRatio = this.getScene().getEngine().getAspectRatio(this);

if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PietroFurlan in your PR the logic here is slightly different - can you confirm which math is correct? do we want the same ortho formula regardless of sphere/box, or should they diffeR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PietroFurlan closign PR for now as it has been open a while, lets discuss the correct approach via these comments and once aligned i can re-open the PR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly: with an orthographic camera there’s no concept of radius or FOV or else, so the sphere/box mode shouldn’t affect the frustum math. Behavior should be identical in ortho mode. In your PR the ortho option existed only for the box mode; by changing the math only there, I introduced the inconsistency—my bad.

In ortho mode, the math is the same for box and sphere, and should be:

this.orthoTop = height * radiusScale;
this.orthoBottom = -this.orthoTop;
this.orthoRight = this.orthoTop * aspectRatio;
this.orthoLeft = -this.orthoRight;

Comment on lines +1607 to +1610
this.orthoRight = height * aspectRatio * radiusScale;
this.orthoLeft = -this.orthoRight * radiusScale;
this.orthoTop = height;
this.orthoBottom = -this.orthoTop;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an error on this formula when passing a radiusScale != 1.
In my last commit you find the correct one:

Suggested change
this.orthoRight = height * aspectRatio * radiusScale;
this.orthoLeft = -this.orthoRight * radiusScale;
this.orthoTop = height;
this.orthoBottom = -this.orthoTop;
this.orthoTop = height * radiusScale;
this.orthoBottom = -this.orthoTop;
this.orthoRight = this.orthoTop * aspectRatio;
this.orthoLeft = -this.orthoRight;

const depth = (maximumWorld.z - minimumWorld.z) * 0.5;
const aspectRatio = this.getScene().getEngine().getAspectRatio(this);

if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly: with an orthographic camera there’s no concept of radius or FOV or else, so the sphere/box mode shouldn’t affect the frustum math. Behavior should be identical in ortho mode. In your PR the ortho option existed only for the box mode; by changing the math only there, I introduced the inconsistency—my bad.

In ortho mode, the math is the same for box and sphere, and should be:

this.orthoTop = height * radiusScale;
this.orthoBottom = -this.orthoTop;
this.orthoRight = this.orthoTop * aspectRatio;
this.orthoLeft = -this.orthoRight;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants