SoFitCameraToBoundingBox

InventorModule

author

Florian Link

package

FMEwork/ReleaseMeVis

dll

SoFitCameraToBoundingBox

definition

SoFitCameraToBoundingBox.def

keywords

camera, fit, bounding, box, orthographic, perspective, viewAll, view, zoom, pan

Purpose

The SoFitCameraToBoundingBox fits a given perspective or orthographic camera to view the given scene bounding box so that it fits into the given viewport. It keeps the orientation and height/heightAngle of the camera and re-positions the camera so that it best views to bounding box, changing the camera’s position, near/far and focal distance.

It can also calculate the best aspect-ratio and outputs it as Ideal Aspect Ratio. Using Aspect Mode it can also adjust the width or height of the viewport to the ideal aspect ratio.

There is still a known problem with the ideal aspect ratio in perspective projection, it only works perfectly when the SoPerspectiveCamera is set to “viewportMapping = LEAVE_ALONE”, because the ADJUST_VIEWPORT option interferes with the calculation. So for SoPerspectiveCamera we recommend setting viewportMapping to LEAVE_ALONE for good automatic aspect ratio results.

This module is especially useful with OffscreenRenderer and you can connect the Viewport of this module to the viewport of an OffscreenRenderer module for automatic adjustment of the aspect ratio.

Windows

Default Panel

../../../Projects/SoFitCameraToBoundingBox/Modules/mhelp/Images/Screenshots/SoFitCameraToBoundingBox._default.png

Input Fields

inCamera

name: inCamera, type: SoNode

Scene with the camera

inScene

name: inScene, type: SoNode

The scene which is used for bounding box detection.

Parameter Fields

Field Index

Aspect Mode: Enum

Fit Mode: Enum

Ideal Aspect Ratio: Float

Slack: Float

Update: Trigger

Viewport: IntVector2

Visible Fields

Viewport

name: viewport, type: IntVector2, default: 512 512

The desired viewport

Slack

name: slack, type: Float, default: 1

Additional slack (padding) that is applied

Ideal Aspect Ratio

name: idealAspectRatio, type: Float, persistent: no

The calculated ideal aspect

Update

name: update, type: Trigger

Runs the calculation

Aspect Mode

name: aspectMode, type: Enum, default: AspectKeep

How to handle the aspect ratio

Values:

Title

Name

Description

Keep

AspectKeep

Keep the given viewport

Adjust Width

AspectAdjustWidth

Adjust the width of the viewport according to ideal aspect ratio

Adjust Height

AspectAdjustHeight

Adjust the height of the viewport according to ideal aspect ratio

Fit Mode

name: fitMode, type: Enum, default: FitProjectedBox

Selects how to fit the camera.

Values:

Title

Name

Description

Centered Box

FitCenteredBox

Use the center of the bounding box. (In perspective, this will mean that the box does not touch all sides of the viewport).

Projected Box

FitProjectedBox

Use the center of the projected bounding box. In perspective, this will mean that the fitting tries to touch all sides of the viewport.