Camera
You can directly get and set camera attributes by using member functions on a viewer object:
import panopti
viewer = panopti.connect(...)
# get current camera state as dict
camera_data = viewer.camera()
# set camera attributes manually
viewer.set_camera(
position=(0.0, 5.0, 0.0),
target=(0.0, 0.0, 0.0),
projection_mode='orthographic'
)
# standard look_at function:
viewer.look_at(
position=(-2.0, 1.0, 3.0),
target=(0.0, -2.0, 0.0),
)
# this function is triggered when the viewer camera is manipulated
@viewer.events.camera()
def my_camera_event(viewer, camera_info):
print('Camera was moved to ', camera_info.position)
viewer.hold()
ViewerClient.camera
camera
Return the current camera parameters as a dictionary containing:
key | meaning | type |
---|---|---|
position | camera world coords | ndarray |
rotation | camera XYZ euler rotation | ndarray |
quaternion | camera rotation as quaternion | ndarray |
up | camera up-vector | ndarray |
target | point the camera is looking at | ndarray |
fov | vertical field-of-view (degrees) | float |
near | near-plane distance | float |
far | far-plane distance | float |
aspect | viewport aspect ratio (w / h) | float |
projection_mode | 'perspective' or 'orthographic' | str |
ViewerClient.set_camera
set_camera
ViewerClient.look_at
look_at
Camera Event Decorator @viewer.events.camera()
event decorator
The camera
event is triggered when the user manipulates the viewer
camera (e.g. orbit, pan, zoom). This event provides a CameraInfo
object
containing information about the camera's current state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
throttle
|
int
|
Throttle interval in milliseconds. If provided, the callback will only be called at most once per throttle interval. |
None
|
Example usage:
@viewer.events.camera()
def camera_event(viewer, camera_info):
print('Camera was updated!')
# swivel scene mesh to always face the camera (in Y-axis):
mesh = viewer.get('myMesh')
mx, my, mz = mesh.position
cx, cy, cz = camera_info.position # dot-access notation
yaw = math.atan2(cx - mx, cz - mz)
mesh.rotation = [0, yaw, 0]
mesh.update(rotation=[0, yaw, 0])
# Or with throttling (100ms interval)
@viewer.events.camera(throttle=100)
def throttled_camera_event(viewer, camera_info):
print('Throttled camera update!')
camera_info
is a CameraInfo
object with the following attributes:
attribute | meaning | type |
---|---|---|
position | camera world coords | ndarray |
rotation | camera XYZ euler rotation | ndarray |
quaternion | camera rotation as quaternion | ndarray |
up | camera up-vector | ndarray |
target | point the camera is looking at | ndarray |
fov | vertical field-of-view (degrees) | float |
near | near-plane distance | float |
far | far-plane distance | float |
aspect | viewport aspect ratio (w / h) | float |
projection_mode | 'perspective' or 'orthographic' | str |