s6.app.sim.render_animation¶
- s6.app.sim.render_animation.blender_camera_to_opencv_extrinsics(cam_obj=None)
Returns OpenCV-style extrinsics (R, t) from a Blender camera object.
- OpenCV convention:
X_cam = R @ X_world + t
- Camera axes:
+X right, +Y down, +Z forward
- Parameters:
cam_obj – bpy.types.Object (must be a camera object). If None, uses scene camera.
- Returns:
(3, 3) numpy array t: (3,) numpy array T: (4, 4) numpy array full world->camera transform in OpenCV coords
- Return type:
R
- s6.app.sim.render_animation.matrix_to_list(m)
- s6.app.sim.render_animation.compute_intrinsic_matrix(cam_data, res_x, res_y)
Compute pinhole intrinsics (K) from Blender camera + render settings, assuming horizontal sensor fit and using fx for both fx and fy.
Accounts for render scale. Pixel aspect and vertical fit are ignored per instruction to treat all sensor fits as horizontal. Returns 3x3 matrix with fx=fy in pixels and principal point at image center.
- s6.app.sim.render_animation.compute_extrinsic_matrix(obj)
Compute OpenCV-style world→camera extrinsic using blender_camera_to_opencv_extrinsics().
Returns 4x4 transform with bottom row [0,0,0,1]. Falls back to Blender world→camera if OpenCV conversion is unavailable.
- s6.app.sim.render_animation.write_calibration_file(out_root: str, camera_names: List[str], identity_name: str) None
Write a calibration.config.json under <out_root>/configs/ using Blender scene cameras.
identity_name extrinsic is set to identity.
Other cameras’ extrinsics are expressed relative to identity (T_c = T_cB @ inv(T_idB)).
Intrinsics and resolution are taken from the active scene settings.
Distortion is zeros.
Missing cameras among {“L”,”R”,”B”,”RGBL”,”RGBR”} are filled from identity.
- s6.app.sim.render_animation.render_result_to_bgr(scene) ndarray
Read Blender’s render result into a NumPy BGR uint8 array.
Requires NumPy to be available inside Blender’s Python. The buffer is RGBA floats in [0,1] with shape (H*W*4); we reshape to (H, W, 4), drop A, convert to uint8, and swap channels to BGR for downstream OpenCV usage.
- s6.app.sim.render_animation.build_calibration_record(frame_number: int, cameras: List[bpy.types.Object]) Dict
Build the per-frame calibration dictionary (no images).
Returns a mapping: {“frame”: N, “cameras”: {name: {resolution, intrinsic, extrinsic}}}
- s6.app.sim.render_animation.ensure_directory(path)
- s6.app.sim.render_animation.render_from_camera(camera_obj, scene, frame_number: int, tmp_dir: str | None = None) ndarray
Render the active scene from a specific camera and return a BGR uint8 array.
Always renders to a temporary PNG on disk and loads it (robust across Blender builds where the in-memory Render Result buffer may be empty).
- s6.app.sim.render_animation.parse_args(argv)
- s6.app.sim.render_animation.main(argv=None)