Apply camera motion animation based on motion type. Args: camera: Kubric camera object motion_type: One of ['static', 'zoom_in', 'zoom_out', 'pan_left', 'pan_right'] cam_distance: Initial camera distance from center cam_angle: Initial camera angle (radians)
(camera, motion_type, cam_distance, cam_angle, cam_height,
look_at_point, frame_start, frame_end, rng, motion_params=None)
| 56 | pass |
| 57 | |
| 58 | def apply_camera_motion(camera, motion_type, cam_distance, cam_angle, cam_height, |
| 59 | look_at_point, frame_start, frame_end, rng, motion_params=None): |
| 60 | """Apply camera motion animation based on motion type. |
| 61 | |
| 62 | Args: |
| 63 | camera: Kubric camera object |
| 64 | motion_type: One of ['static', 'zoom_in', 'zoom_out', 'pan_left', 'pan_right'] |
| 65 | cam_distance: Initial camera distance from center |
| 66 | cam_angle: Initial camera angle (radians) |
| 67 | cam_height: Camera height |
| 68 | look_at_point: Point camera looks at (tuple) |
| 69 | frame_start: First frame |
| 70 | frame_end: Last frame |
| 71 | rng: Random number generator |
| 72 | motion_params: Pre-computed motion parameters (for reproducing exact motion) |
| 73 | |
| 74 | Returns: |
| 75 | Dictionary of motion parameters used (for reusing in other passes) |
| 76 | """ |
| 77 | if motion_type == 'static': |
| 78 | # No animation, already set |
| 79 | return {} |
| 80 | |
| 81 | # Calculate initial position |
| 82 | pos_x_start = cam_distance * np.cos(cam_angle) |
| 83 | pos_y_start = -cam_distance * np.sin(cam_angle) |
| 84 | |
| 85 | # Use pre-computed parameters or generate new ones |
| 86 | if motion_params is None: |
| 87 | motion_params = {} |
| 88 | if motion_type == 'zoom_in': |
| 89 | motion_params['zoom_factor'] = rng.uniform(0.6, 0.8) |
| 90 | elif motion_type == 'zoom_out': |
| 91 | motion_params['zoom_factor'] = rng.uniform(1.3, 1.5) |
| 92 | elif motion_type in ['pan_left', 'pan_right']: |
| 93 | motion_params['angle_change'] = rng.uniform(20, 40) * np.pi / 180 |
| 94 | |
| 95 | if motion_type == 'zoom_in': |
| 96 | # Move camera closer over time (reduce distance by 20-40%) |
| 97 | cam_distance_end = cam_distance * motion_params['zoom_factor'] |
| 98 | pos_x_end = cam_distance_end * np.cos(cam_angle) |
| 99 | pos_y_end = -cam_distance_end * np.sin(cam_angle) |
| 100 | |
| 101 | elif motion_type == 'zoom_out': |
| 102 | # Move camera farther over time (increase distance by 30-50%) |
| 103 | cam_distance_end = cam_distance * motion_params['zoom_factor'] |
| 104 | pos_x_end = cam_distance_end * np.cos(cam_angle) |
| 105 | pos_y_end = -cam_distance_end * np.sin(cam_angle) |
| 106 | |
| 107 | elif motion_type == 'pan_left': |
| 108 | # Rotate camera angle to the left (increase angle by 20-40 degrees) |
| 109 | cam_angle_end = cam_angle + motion_params['angle_change'] |
| 110 | pos_x_end = cam_distance * np.cos(cam_angle_end) |
| 111 | pos_y_end = -cam_distance * np.sin(cam_angle_end) |
| 112 | |
| 113 | elif motion_type == 'pan_right': |
| 114 | # Rotate camera angle to the right (decrease angle by 20-40 degrees) |
| 115 | cam_angle_end = cam_angle - motion_params['angle_change'] |