-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add option to use boundingBox (instead of boundingSphere) when calculating arcRotateCam lowerRadius. Add orthographic framing #17329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
georginahalpern
wants to merge
1
commit into
BabylonJS:master
from
georginahalpern:framingBoundingBox
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,9 @@ Node.AddNodeConstructor("ArcRotateCamera", (name, scene) => { | |||||||||||||||||||
| return () => new ArcRotateCamera(name, 0, 0, 1.0, Vector3.Zero(), scene); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Used to indicate boundingInfo for the calculateLowerRadius methods | ||||||||||||||||||||
| export type BoundingInfoMode = "sphere" | "box"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Computes the alpha angle based on the source position and the target position. | ||||||||||||||||||||
| * @param offset The directional offset between the source position and the target position | ||||||||||||||||||||
|
|
@@ -1581,6 +1584,45 @@ export class ArcRotateCamera extends TargetCamera { | |||||||||||||||||||
| return Math.max(distanceForHorizontalFrustum, distanceForVerticalFrustum); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * @internal | ||||||||||||||||||||
| * This expands functionality beyond what _calculateLowerRadiusFromModelBoundingSphere does by | ||||||||||||||||||||
| * 1. Offering boundingBox mode which calculates distance according to the bounding box | ||||||||||||||||||||
| * 2. Setting orthographic extents on the class | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| public _calculateLowerRadiusFromModelBoundingInfo(minimumWorld: Vector3, maximumWorld: Vector3, mode: BoundingInfoMode = "sphere", radiusScale: number = 1): number { | ||||||||||||||||||||
| // Setting orthographic extents -- this is done regardless of mode | ||||||||||||||||||||
| const height = (maximumWorld.y - minimumWorld.y) * 0.5; | ||||||||||||||||||||
| const width = (maximumWorld.x - minimumWorld.x) * 0.5; | ||||||||||||||||||||
| const depth = (maximumWorld.z - minimumWorld.z) * 0.5; | ||||||||||||||||||||
| const aspectRatio = this.getScene().getEngine().getAspectRatio(this); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (this.mode === Camera.ORTHOGRAPHIC_CAMERA) { | ||||||||||||||||||||
| if (aspectRatio < width / height) { | ||||||||||||||||||||
| this.orthoRight = width * radiusScale; | ||||||||||||||||||||
| this.orthoLeft = -this.orthoRight; | ||||||||||||||||||||
| this.orthoTop = this.orthoRight / aspectRatio; | ||||||||||||||||||||
| this.orthoBottom = this.orthoLeft / aspectRatio; | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| this.orthoRight = height * aspectRatio * radiusScale; | ||||||||||||||||||||
| this.orthoLeft = -this.orthoRight * radiusScale; | ||||||||||||||||||||
| this.orthoTop = height; | ||||||||||||||||||||
| this.orthoBottom = -this.orthoTop; | ||||||||||||||||||||
|
Comment on lines
+1607
to
+1610
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is an error on this formula when passing a radiusScale != 1.
Suggested change
|
||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (mode === "box") { | ||||||||||||||||||||
| // Formula for setting distance according to the bounding box (centring the first face of the bounding box) | ||||||||||||||||||||
| const frustumSlopeY = Math.tan(this.fov / 2); | ||||||||||||||||||||
| const frustumSlopeX = frustumSlopeY * aspectRatio; | ||||||||||||||||||||
| const distanceForHorizontalFrustum = (radiusScale * width) / frustumSlopeX + depth; | ||||||||||||||||||||
| const distanceForVerticalFrustum = (radiusScale * height) / frustumSlopeY + depth; | ||||||||||||||||||||
| return Math.max(distanceForHorizontalFrustum, distanceForVerticalFrustum); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| return this._calculateLowerRadiusFromModelBoundingSphere(minimumWorld, maximumWorld, radiusScale); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Destroy the camera and release the current resources hold by it. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
|
|
||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: