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, *, name: str = '/trail') -> 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
|
name
|
str
|
Scene path for this trail. Pass a distinct name per vehicle when more than one shares a server. |
'/trail'
|
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
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
add_attitude_frame(server: viser.ViserServer, pos: np.ndarray, attitude: np.ndarray | None, axes_length: float = 2.0, axes_radius: float = 0.05, *, name: str = '/body_frame') -> 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
|
name
|
str
|
Scene path for this frame. Pass a distinct name per vehicle when more than one shares a server. |
'/body_frame'
|
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), *, name: str = '/current_pos') -> 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)
|
name
|
str
|
Scene path for this marker. Pass a distinct name per vehicle when more than one shares a server. |
'/current_pos'
|
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_plume(server: viser.ViserServer, pos: np.ndarray, thrust: np.ndarray | None, attitude: np.ndarray | None = None, scale: float = 0.3, min_length: float = 0.05, max_length: float = 2.5, half_angle_deg: float = 12.0, color: tuple[int, int, int] = (255, 120, 40), opacity: float = 0.45, n_segments: int = 24, remap_world_to_viser: bool = False, *, name: str = '/thrust_plume') -> tuple[viser.MeshHandle | None, UpdateCallback | None]
¶
Animated exhaust plume (cone) pointing opposite to the thrust vector.
Thrust controls are assumed to be in the body frame when attitude is set.
The plume opens along -thrust in the world frame (exhaust direction).
Pass a distinct name per vehicle when more than one shares a server.
Source code in openscvx/plotting/viser/animated.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
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, remap_world_to_viser: bool = False, *, name: str = '/thrust_vector') -> 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
|
remap_world_to_viser
|
bool
|
If True, apply the PDG model (z, y, x) → Viser (x, y, z) permutation to the world-frame thrust vector (after body rotation). |
False
|
name
|
str
|
Scene path for this vector. Pass a distinct name per vehicle when more than one shares a server. |
'/thrust_vector'
|
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, ring_only: bool = False, line_width: float = 4.0, n_segments: int = 32, *, name: str = '/viewcone_sensor') -> tuple[viser.FrameHandle | 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, shape (3, 3) for a fixed sensor or (N, 3, 3) for a gimballed one whose mounting rotates per frame. If None, the sensor is aligned with the 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
|
ring_only
|
bool
|
If True, render only the base ring as a closed line loop instead of the full cone mesh. |
False
|
line_width
|
float
|
Line width for the ring (only used when |
4.0
|
n_segments
|
int
|
Number of segments for cone smoothness |
32
|
name
|
str
|
Scene path for the sensor frame; the cone geometry is parented under it. Pass a distinct name per sensor when more than one shares a server. |
'/viewcone_sensor'
|
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
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
normalize_wxyz(q: np.ndarray) -> np.ndarray
¶
Return a unit quaternion in [w, x, y, z] order.
Viser rejects non-unit quaternions, while solver output drifts off the unit sphere; use this on any attitude before handing it to a scene handle. A degenerate (near-zero) quaternion maps to identity rather than raising.
Source code in openscvx/plotting/viser/animated.py
place_body_frame(server: viser.ViserServer, path: str, position: np.ndarray, wxyz: np.ndarray, axes_length: float = 2.0, axes_radius: float = 0.05) -> viser.FrameHandle
¶
Place a static body coordinate frame at a single pose.
Source code in openscvx/plotting/viser/animated.py
place_viewcone(server: viser.ViserServer, path: str, position: np.ndarray, attitude_wxyz: np.ndarray, 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, ring_only: bool = False, line_width: float = 4.0, n_segments: int = 32) -> viser.FrameHandle
¶
Place a static viewcone rigidly attached to the sensor frame at one pose.