SBCamera#

The SBCamera class implements all mechanisms related to cameras in SAMSON. A camera provides a 3D view of visualizable objects in SAMSON’s data graph, and can be easily controlled to point to a specific location, zoom in or out, translate, rotate, etc. Basically, you may consider your screen as a camera pointing into the viewport and yourself as an operator seeing through the camera.

Cameras and their positions and properties are saved and loaded together with a document.

The currently active camera can be retrieved through the SAMSON interface:

# get the active camera of the active document
camera = SAMSON.getActiveCamera()

# make the change undoable
SAMSON.beginHolding("Change camera")

# set the front view of the camera
camera.frontView()
camera.name = "Front view camera"

# stop holding
SAMSON.endHolding()

Let’s center a camera on all structural models in the active document.

# get a node indexer with all structural models in the active document
nodeIndexer = SAMSON.getNodes('node.type sm')

# make the change undoable
SAMSON.beginHolding("Change camera")

# center the camera on the nodes in the nodeIndexer
camera.center(nodeIndexer)

# stop holding
SAMSON.endHolding()

Let’s rotate a camera around some center with a given velocity.

# get all atoms
nodeIndexer = SAMSON.getNodes('node.type atom')

# compute the centroid
center = SBStructuralModel.getCentroid(nodeIndexer)

# rotate the camera

numberOfRotations = 36 # the number of rotations
# set the rotation velocity in x-direction
velocity3 = SBRadianPerSecond3() # the zero vector
velocity3.x = SBQuantity.radPerS(3.14159 / 180.0)

# rotate several times in the loop
for i in range(numberOfRotations):
    # rotate the camera once with the given velocity around the given center
    camera.rotate(velocity3, center)
    # request SAMSON to process events
    SAMSON.processEvents()

There can be multiple cameras in a document which might be useful if you want to switch fast between different views (e.g., positions, projections, close-up views, and a full view) in the same document. To switch between cameras in the document

Change the active camera in a document#
# get all cameras in the document
cameraIndexer = document.getNodes("node.type camera")

if len(cameraIndexer):
    # make the change undoable
    SAMSON.beginHolding("Change camera")
    # change the document's active camera to the first camera in the document
    document.setActiveCamera(cameraIndexer[0])
    # stop holding
    SAMSON.endHolding()

You can also change camera view, zoom it via SAMSON actions using SAMSON.runCommand() (see Running actions). The following actions are available:

  • Change view: ‘Top view’, ‘Bottom view’, ‘Front view’, ‘Back view’, ‘Left view’, ‘Right view’

  • Zoom: ‘Zoom in’, ‘Zoom out’, ‘Zoom to fit’, ‘Zoom on selection’

  • Changing projection: ‘Projection’

Change the camera view#
# change the active camera's view using commands
SAMSON.runCommand('Top view')

Note

If you want to produce pictures, you can capture the current viewport using the SAMSON.captureViewportToFile function.

See also

SAMSON SDK: SBDDocumentCamera

class samson.SBCamera(*args, **kwargs)#

Bases: SBNode

This class describes a camera.

Overloaded function.

  1. __init__(self: samson.SBCamera) -> None

Constructs a camera.

  1. __init__(self: samson.SBCamera, name: str) -> None

Constructs a camera with the given name.

Parameters:

name (str) – A name of the camera.

Examples

Add a camera to the active document and make this operation undoable.

>>> camera = SBCamera('New camera')
>>> SAMSON.beginHolding('Add camera')
>>> SAMSON.hold(camera)
>>> camera.create()
>>> SAMSON.getActiveDocument().addChild(camera)
True
>>> SAMSON.endHolding()
alignWithAxis(self: samson.SBCamera, nodeIndexer: samson.SBNodeIndexer, reversed: bool = False) None#

Aligns the indexed nodes with the camera axis

alignWithPlane(self: samson.SBCamera, nodeIndexer: samson.SBNodeIndexer, reversed: bool = False) None#

Aligns the indexed nodes with the camera plane

backView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the back view

bottomView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the bottom view

center(*args, **kwargs)#

Overloaded function.

  1. center(self: samson.SBCamera, immediate: bool = False) -> None

Centers the camera

  1. center(self: samson.SBCamera, nodeIndexer: samson.SBNodeIndexer, immediate: bool = False) -> None

Centers the camera on the indexed nodes

defaultView(self: samson.SBCamera) None#

Sets the view to default parameters

frontView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the front view

getEyeDestination(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns destination of the eye

getEyePosition(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns position of the eye

getEyeVelocity(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns velocity of the eye

getFrustumPositionFromWorldPosition(self: samson.SBCamera, worldPosition: samson.SBPhysicalVector3) samson.SBPhysicalVector3#

Returns the projection in the frustum of the given world position

getHeadPosition(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns position of the head

getNextCamera(self: samson.SBCamera) samson.SBCamera#

Returns the next camera.

getPreviousCamera(self: samson.SBCamera) samson.SBCamera#

Returns the previous camera.

getProjectionMatrix(self: samson.SBCamera) list[list[float]]#

Returns the projection matrix

getProjectionMatrixTranspose(self: samson.SBCamera) list[list[float]]#

Returns the transpose of the projection matrix

getRotationVelocity(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns rotation velocity

getTargetDestination(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns destination of the target

getTargetPosition(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns position of the target

getTargetVelocity(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns velocity of the target

getUpVector(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns up vector

getUpVectorDestination(self: samson.SBCamera) samson.SBPhysicalVector3#

Returns destination of the up vector

getViewMatrix(self: samson.SBCamera) list[list[float]]#

Returns the view matrix

getViewMatrixTranspose(self: samson.SBCamera) list[list[float]]#

Returns the transpose of the view matrix

getViewProjectionMatrix(self: samson.SBCamera) list[list[float]]#

Returns the view projection matrix

getViewProjectionMatrixTranspose(self: samson.SBCamera) list[list[float]]#

Returns the transpose of the view projection matrix

getViewProjectionMatrixTransposeInverse(self: samson.SBCamera) list[list[float]]#

Returns the inverse of the transpose of the view projection matrix

getWorldPositionFromFrustumPosition(self: samson.SBCamera, frustumPosition: samson.SBPhysicalVector3) samson.SBPhysicalVector3#

Returns the world position that corresponds to the frustum position

isMoving(self: samson.SBCamera) bool#

Returns whether the camera is currently moving

leftBackBottomView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the left back bottom view

leftBackTopView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the left back top view

leftFrontBottomView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the left front bottom view

leftFrontTopView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the left front top view

leftView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the left view

orientUpwards(self: samson.SBCamera, immediate: bool = False) None#

Turns the camera around its Z vector to the upwards direction

rightBackBottomView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the right back bottom view

rightBackTopView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the right back top view

rightFrontBottomView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the right front bottom view

rightFrontTopView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the right front top view

rightView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the right view

rotate(*args, **kwargs)#

Overloaded function.

  1. rotate(self: samson.SBCamera, axis: samson.SBPhysicalVector3, angle: samson.SBQuantity.unitsSI, immediate: bool = False) -> None

Rotates the camera

  1. rotate(self: samson.SBCamera, velocity: samson.SBPhysicalVector3, center: samson.SBPhysicalVector3) -> None

Rotates the camera

rotateClockwise(self: samson.SBCamera, immediate: bool = False) None#

Rotates the camera 45 degrees clockwise around its target

rotateCounterClockwise(self: samson.SBCamera, immediate: bool = False) None#

Rotates the camera 45 degrees counterclockwise around its target

rotateDown(self: samson.SBCamera, immediate: bool = False) None#

Rotates the camera 45 degrees down around its target

rotateLeft(self: samson.SBCamera, immediate: bool = False) None#

Rotates the camera 45 degrees left around its target

rotateRight(self: samson.SBCamera, immediate: bool = False) None#

Rotates the camera 45 degrees right around its target

rotateUp(self: samson.SBCamera, immediate: bool = False) None#

Rotates the camera 45 degrees up around its target

setEyeDestination(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets destination of the eye

setEyePosition(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets position of the eye

setEyeVelocity(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets velocity of the eye

setHeadPosition(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets position of the head

setRotationVelocity(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets rotation velocity

setTargetDestination(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets destination of the target

setTargetPosition(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets position of the target

setTargetVelocity(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets velocity of the target

setUpVector(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets up vector

setUpVectorDestination(self: samson.SBCamera, arg0: samson.SBPhysicalVector3) None#

Sets destination of the up vector

stop(self: samson.SBCamera) None#

Stops the camera

topView(self: samson.SBCamera, immediate: bool = False) None#

Goes to the top view

transform(self: samson.SBCamera, spatialTransform: samson.SBSpatialTransform, immediate: bool = False) None#

Applies a spatial transform to the camera

translate(self: samson.SBCamera, velocity: samson.SBPhysicalVector3, immediate: bool = False) None#

Translates the camera

updateState(self: samson.SBCamera) bool#

Updates the state of the camera and returns True if the camera moved

zoomIn(self: samson.SBCamera, velocity: samson.SBQuantity.unitsSI, center: samson.SBPhysicalVector3) None#

Zooms in

zoomOut(self: samson.SBCamera, velocity: samson.SBQuantity.unitsSI, center: samson.SBPhysicalVector3) None#

Zooms out

zoomTo(self: samson.SBCamera, cameraTargetDestination: samson.SBPhysicalVector3) None#

Zooms to a specific destination

property aspectRatio#

The aspect ratio

property autofocusFlag#

The autofocus flag

property basisX#

The x vector of the camera basis

property basisY#

The y vector of the camera basis

property basisZ#

The z vector of the camera basis

property clippingPlane#

The clipping plane

property depthOfFieldFlag#

The depth of field flag

property fNumber#

The f-number

property farPlane#

The far plane

property fieldOfViewAngleY#

The field of view angle

property focalDistance#

The focal distance

property getTransform#

The spatial transform

property inertiaFlag#

The inertia flag

property nearPlane#

The near plane

property orthographicProjectionFlag#

the orthographic projection flag