animated
Animated scene elements for viser visualization.
Each function in this module adds an animated element to a viser scene and
returns a tuple of (handle, update_callback). The update callback has
signature update_callback(frame_idx: int) -> None and updates the visual
to reflect the state at that frame index.
Collect these callbacks and pass them to add_animation_controls() to
wire up playback with GUI controls (play/pause, scrubber, speed, etc.).
Example::
_, update_trail = add_animated_trail(server, positions, colors)
_, update_marker = add_position_marker(server, positions)
_, update_thrust = add_thrust_vector(server, positions, thrust, attitude)
add_animation_controls(server, time_array, [update_trail, update_marker, update_thrust])
add_animated_trail(server: viser.ViserServer, pos: np.ndarray, colors: np.ndarray, point_size: float = 0.15) -> tuple[viser.PointCloudHandle, UpdateCallback]
¶
Add an animated trail that grows with the animation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
colors
|
ndarray
|
RGB color array of shape (N, 3) |
required |
point_size
|
float
|
Size of trail points |
0.15
|
Returns:
| Type | Description |
|---|---|
tuple[PointCloudHandle, UpdateCallback]
|
Tuple of (handle, update_callback) |
Source code in openscvx/plotting/viser/animated.py
add_animation_controls(server: viser.ViserServer, traj_time: np.ndarray, update_callbacks: list[UpdateCallback], loop: bool = True, folder_name: str = 'Animation') -> None
¶
Add animation GUI controls and start the animation loop.
Creates play/pause button, reset button, time slider, speed slider, and loop checkbox. Runs animation in a background daemon thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
traj_time
|
ndarray
|
Time array of shape (N,) with timestamps for each frame |
required |
update_callbacks
|
list[UpdateCallback]
|
List of update functions to call each frame |
required |
loop
|
bool
|
Whether to loop animation by default |
True
|
folder_name
|
str
|
Name for the GUI folder |
'Animation'
|
Source code in openscvx/plotting/viser/animated.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
add_attitude_frame(server: viser.ViserServer, pos: np.ndarray, attitude: np.ndarray | None, axes_length: float = 2.0, axes_radius: float = 0.05) -> tuple[viser.FrameHandle | None, UpdateCallback | None]
¶
Add an animated body coordinate frame showing attitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
attitude
|
ndarray | None
|
Quaternion array of shape (N, 4) in [w, x, y, z] format, or None to skip |
required |
axes_length
|
float
|
Length of the coordinate axes |
2.0
|
axes_radius
|
float
|
Radius of the axes cylinders |
0.05
|
Returns:
| Type | Description |
|---|---|
tuple[FrameHandle | None, UpdateCallback | None]
|
Tuple of (handle, update_callback), or (None, None) if attitude is None |
Source code in openscvx/plotting/viser/animated.py
add_position_marker(server: viser.ViserServer, pos: np.ndarray, radius: float = 0.5, color: tuple[int, int, int] = (100, 200, 255)) -> tuple[viser.IcosphereHandle, UpdateCallback]
¶
Add an animated position marker (sphere at current position).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
radius
|
float
|
Marker radius |
0.5
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(100, 200, 255)
|
Returns:
| Type | Description |
|---|---|
tuple[IcosphereHandle, UpdateCallback]
|
Tuple of (handle, update_callback) |
Source code in openscvx/plotting/viser/animated.py
add_target_marker(server: viser.ViserServer, target_pos: np.ndarray, name: str = 'target', radius: float = 0.8, color: tuple[int, int, int] = (255, 50, 50), show_trail: bool = True, trail_color: tuple[int, int, int] | None = None) -> tuple[viser.IcosphereHandle, UpdateCallback | None]
¶
Add a viewplanning target marker (static or moving).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
target_pos
|
ndarray
|
Target position - either shape (3,) for static or (N, 3) for moving |
required |
name
|
str
|
Unique name for this target (used in scene path) |
'target'
|
radius
|
float
|
Marker radius |
0.8
|
color
|
tuple[int, int, int]
|
RGB color tuple for marker |
(255, 50, 50)
|
show_trail
|
bool
|
If True and target is moving, show trajectory trail |
True
|
trail_color
|
tuple[int, int, int] | None
|
RGB color for trail (defaults to dimmed marker color) |
None
|
Returns:
| Type | Description |
|---|---|
tuple[IcosphereHandle, UpdateCallback | None]
|
Tuple of (handle, update_callback). update_callback is None for static targets. |
Source code in openscvx/plotting/viser/animated.py
add_target_markers(server: viser.ViserServer, target_positions: list[np.ndarray], colors: list[tuple[int, int, int]] | None = None, radius: float = 0.8, show_trails: bool = True) -> list[tuple[viser.IcosphereHandle, UpdateCallback | None]]
¶
Add multiple viewplanning target markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
target_positions
|
list[ndarray]
|
List of target positions, each either (3,) or (N, 3) |
required |
colors
|
list[tuple[int, int, int]] | None
|
List of RGB colors, one per target. Defaults to distinct colors. |
None
|
radius
|
float
|
Marker radius |
0.8
|
show_trails
|
bool
|
If True, show trails for moving targets |
True
|
Returns:
| Type | Description |
|---|---|
list[tuple[IcosphereHandle, UpdateCallback | None]]
|
List of (handle, update_callback) tuples |
Source code in openscvx/plotting/viser/animated.py
add_thrust_vector(server: viser.ViserServer, pos: np.ndarray, thrust: np.ndarray | None, attitude: np.ndarray | None = None, scale: float = 0.3, color: tuple[int, int, int] = (255, 100, 100), line_width: float = 4.0) -> tuple[viser.LineSegmentsHandle | None, UpdateCallback | None]
¶
Add an animated thrust/force vector visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
thrust
|
ndarray | None
|
Thrust/force array of shape (N, 3), or None to skip |
required |
attitude
|
ndarray | None
|
Quaternion array of shape (N, 4) in [w, x, y, z] format. If provided, thrust is assumed to be in body frame and will be rotated to world frame using the attitude. |
None
|
scale
|
float
|
Scale factor for thrust vector length |
0.3
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(255, 100, 100)
|
line_width
|
float
|
Line width |
4.0
|
Returns:
| Type | Description |
|---|---|
tuple[LineSegmentsHandle | None, UpdateCallback | None]
|
Tuple of (handle, update_callback), or (None, None) if thrust is None |
Source code in openscvx/plotting/viser/animated.py
add_viewcone(server: viser.ViserServer, pos: np.ndarray, attitude: np.ndarray | None, half_angle_x: float, half_angle_y: float | None = None, scale: float = 10.0, norm_type: float | str = 2, R_sb: np.ndarray | None = None, color: tuple[int, int, int] = (35, 138, 141), opacity: float = 0.4, wireframe: bool = False, n_segments: int = 32) -> tuple[viser.MeshHandle | None, UpdateCallback | None]
¶
Add an animated viewcone mesh that matches p-norm constraints.
The sensor is assumed to look along +Z in its own frame (boresight = [0,0,1]). The viewcone represents the constraint ||[x,y]||_p <= tan(alpha) * z.
Cross-section shapes by norm
- p=1: diamond
- p=2: circle/ellipse
- p>2: rounded square (superellipse)
- p=inf: square/rectangle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server
|
ViserServer
|
ViserServer instance |
required |
pos
|
ndarray
|
Position array of shape (N, 3) |
required |
attitude
|
ndarray | None
|
Quaternion array of shape (N, 4) in [w, x, y, z] format, or None to skip |
required |
half_angle_x
|
float
|
Half-angle of the cone in x direction (radians). For symmetric cones, this is pi/alpha_x where alpha_x is the constraint parameter. |
required |
half_angle_y
|
float | None
|
Half-angle in y direction (radians). If None, uses half_angle_x. For asymmetric constraints, this is pi/alpha_y. |
None
|
scale
|
float
|
Depth/length of the cone visualization |
10.0
|
norm_type
|
float | str
|
p-norm value (1, 2, 3, ..., or "inf" for infinity norm) |
2
|
R_sb
|
ndarray | None
|
Body-to-sensor rotation matrix (3x3). If None, sensor is aligned with body z-axis. |
None
|
color
|
tuple[int, int, int]
|
RGB color tuple |
(35, 138, 141)
|
opacity
|
float
|
Mesh opacity (0-1), ignored if wireframe=True |
0.4
|
wireframe
|
bool
|
If True, render as wireframe instead of solid |
False
|
n_segments
|
int
|
Number of segments for cone smoothness |
32
|
Returns:
| Type | Description |
|---|---|
tuple[MeshHandle | None, UpdateCallback | None]
|
Tuple of (handle, update_callback), or (None, None) if attitude is None |
Source code in openscvx/plotting/viser/animated.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |