blendify package¶
Subpackages¶
- blendify.cameras package
- blendify.colors package
- blendify.internal package
- blendify.lights package
- blendify.materials package
- blendify.renderables package
- Submodules
- blendify.renderables.base module
- blendify.renderables.collection module
RenderablesCollection
RenderablesCollection.add_circle_mesh()
RenderablesCollection.add_cube_mesh()
RenderablesCollection.add_curve_nurbs()
RenderablesCollection.add_cylinder_mesh()
RenderablesCollection.add_ellipsoid_nurbs()
RenderablesCollection.add_mesh()
RenderablesCollection.add_plane_mesh()
RenderablesCollection.add_pointcloud()
RenderablesCollection.add_sphere_nurbs()
RenderablesCollection.items()
RenderablesCollection.keys()
RenderablesCollection.remove()
RenderablesCollection.values()
- blendify.renderables.mesh module
- blendify.renderables.pointcloud module
- blendify.renderables.primitives module
- Module contents
- blendify.utils package
- Submodules
- blendify.utils.camera_trajectory module
- blendify.utils.image module
- blendify.utils.pointcloud module
- blendify.utils.shadow_catcher module
- blendify.utils.smpl_wrapper module
- Module contents
Submodules¶
blendify.scene module¶
- class blendify.scene.Scene(*args, **kwargs)[source]¶
Bases:
object
- attach_blend(path: str | Path, with_camera: bool = False)[source]¶
Append objects and materials from the existing .blend file to the scene. The only two modalities that can be added to blendify Scene are lights and optionally camera, others (renderable objects, materials, etc.) are only appended. The appended modalities will only be present in the internal Blender structures, but will not be added to the blendify Scene class structure. However, they will appear on rendering and in the exported .blend files
- Parameters:
path – path to the .blend file to append the contents from
with_camera – parse camera parameters from the .blend file or keep existing camera
- static check_any_exists(fileprefix: str, filesuffixes: Sequence[str]) bool [source]¶
Check if any of the combinations of <fileprefix>+<any filesuffix> exist in the filesystem
- Parameters:
fileprefix (str) – single file prefix, can the full path or local name
filesuffixes (Sequence[str]) – a sequence of file suffixes to choose from
- Returns:
True is any of the combinations exists in the filesystem, False otherwise
- Return type:
bool
- static export(path: str | Path, include_file_textures: bool = True, verbose: bool = False)[source]¶
Export the current scene to the .blend file
- Parameters:
path (Union[str, Path]) – path to the target .blend file
include_file_textures (bool) – whether to write textures loaded from external files inside .blend file
verbose (bool) – whether to allow blender to log its status to stdout during exporting
- preview(filepath: str | Path | None = None, save_depth: bool = False, save_albedo: bool = False, verbose: bool = False, fast: bool = False)[source]¶
Renders a scene using Blender’s OpenGL renderer. Linux and MacOS Only.
- Parameters:
filepath (Union[str, Path]) – path to the image (PNG) to render to, returns the image as numpy array if None
use_gpu (bool) – whether to render on GPU or not
samples (bool) – number of raytracing samples per pixel
save_depth (bool) – whether to save the depth in the separate file. If yes, the numpy array <filepath>.depth.npy will be created if filepath is set, otherwise appends the array to the output.
save_albedo (bool) – whether to save albedo (raw color information) in the separate file. If yes, the PNG image <filepath>.albedo.png with color information will be created if filepath is set, otherwise appends the array to the output.
verbose (bool) – whether to allow blender to log its status to stdout during rendering
use_denoiser (bool) – use openimage denoiser to denoise the result
fast (bool) – whether to use fast and colorless preview mode (workbench engine)
- static read_exr_distmap(path: str, dist_thresh: float = 10000.0) ndarray [source]¶
Reads the distance map stored in EXR format, filters out all the values after a certain distance threshold. Requires OpenEXR to be installed in the system
- Parameters:
path (str) – path to the .exr file
dist_thresh (float) – distance clip threshold
- Returns:
distance map in numpy array format
- Return type:
np.ndarray
- static read_image(path: str) ndarray [source]¶
Reads the image stored in PNG or JPG format
- Parameters:
path (str) – path to the image file
- Returns:
image in numpy array format
- Return type:
np.ndarray
- render(filepath: str | Path | None = None, use_gpu: bool = True, samples: int = 128, save_depth: bool = False, save_albedo: bool = False, verbose: bool = False, use_denoiser: bool = False, aa_filter_width: float = 1.5)[source]¶
Start the Blender rendering process
Automatically detects if shadow catcher objects are present in the scene by checking is_shadow_catcher property of Blender objects. For rendering with shadow catchers background is made white, because since Blender 3.0 shadow catcher rendering pass is made to be multiplied with the background.
- Parameters:
filepath (Union[str, Path]) – path to the image (PNG) to render to, returns the image as numpy array if None
use_gpu (bool) – whether to render on GPU or not
samples (bool) – number of raytracing samples per pixel
save_depth (bool) – whether to save the depth in the separate file. If yes, the numpy array <filepath>.depth.npy will be created if filepath is set, otherwise appends the array to the output.
save_albedo (bool) – whether to save albedo (raw color information) in the separate file. If yes, the PNG image <filepath>.albedo.png with color information will be created if filepath is set, otherwise appends the array to the output.
verbose (bool) – whether to allow blender to log its status to stdout during rendering
use_denoiser (bool) – use openimage denoiser to denoise the result
aa_filter_width (float) – width of the anti-aliasing filter, set 0 to turn off
- set_orthographic_camera(resolution: ndarray | Tuple[int, int], ortho_scale: float = 1.0, near: float = 0.1, far: float = 100.0, tag: str = 'camera', rotation_mode: str = 'quaternionWXYZ', rotation: ndarray | Tuple[float, float, float, float] | Tuple[float, float, float] | Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] | Positionable | Tuple[ndarray | Tuple[float, float, float], float] | Tuple[Positionable, float] = None, translation: ndarray | Tuple[float, float, float] = (0, 0, 0), resolution_percentage: int = 100) OrthographicCamera [source]¶
Set orthographic camera in the scene. Replaces the previous scene camera, if it exists
- Parameters:
resolution (Vector2di) – (w, h), the resolution of the resulting image
ortho_scale (float, optional) – Orthographic Camera scale (similar to zoom) (default: 1.0)
near (float, optional) – Camera near clipping distance (default: 0.1)
far (float, optional) – Camera far clipping distance (default: 100)
tag (str) – name of the created object in Blender
rotation_mode (str) – type of rotation representation. Can be one of the following: - “quaternionWXYZ” - WXYZ quaternion - “quaternionXYZW” - XYZW quaternion - “rotvec” - axis-angle representation of rotation - “rotmat” - 3x3 rotation matrix - “euler<mode>” - Euler angles with the specified order of rotation, e.g. XYZ, xyz, ZXZ, etc. Refer to scipy.spatial.transform.Rotation.from_euler for details. - “look_at” - look at rotation, the rotation is defined by the point to look at and, optional, the rotation around the forward direction vector (a single float value in tuple or list)
rotation (RotationParams) – rotation parameters according to the rotation_mode - for “quaternionWXYZ” and “quaternionXYZW” - Vec4d - for “rotvec” - Vec3d - for “rotmat” - Mat3x3 - for “euler<mode>” - Vec3d - for “look_at” - Vec3d, Positionable or Tuple[Vec3d/Positionable, float], where float is the rotation around the forward direction vector in degrees
translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))
resolution_percentage (int, optional)
- Returns:
created camera
- Return type:
- set_perspective_camera(resolution: ndarray | Tuple[int, int], focal_dist: float = None, fov_x: float = None, fov_y: float = None, center: ndarray | Tuple[float, float] = None, near: float = 0.1, far: float = 100.0, tag: str = 'camera', rotation_mode: str = 'quaternionWXYZ', rotation: ndarray | Tuple[float, float, float, float] | Tuple[float, float, float] | Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] | Positionable | Tuple[ndarray | Tuple[float, float, float], float] | Tuple[Positionable, float] = None, translation: ndarray | Tuple[float, float, float] = (0, 0, 0), resolution_percentage: int = 100) PerspectiveCamera [source]¶
Set perspective camera in the scene. Replaces the previous scene camera, if it exists. One of focal_dist, fov_x or fov_y is required to set the camera parameters
- Parameters:
resolution (Vector2di) – (w, h), the resolution of the resulting image
focal_dist (float, optional) – Perspective Camera focal distance in millimeters (default: None)
fov_x (float, optional) – Camera lens horizontal field of view (default: None)
fov_y (float, optional) – Camera lens vertical field of view (default: None)
center (Vector2d, optional) – (x, y), horizontal and vertical shifts of the Camera (default: None)
near (float, optional) – Camera near clipping distance (default: 0.1)
far (float, optional) – Camera far clipping distance (default: 100)
tag (str) – name of the created object in Blender
rotation_mode (str) – type of rotation representation. Can be one of the following: - “quaternionWXYZ” - WXYZ quaternion - “quaternionXYZW” - XYZW quaternion - “rotvec” - axis-angle representation of rotation - “rotmat” - 3x3 rotation matrix - “euler<mode>” - Euler angles with the specified order of rotation, e.g. XYZ, xyz, ZXZ, etc. Refer to scipy.spatial.transform.Rotation.from_euler for details. - “look_at” - look at rotation, the rotation is defined by the point to look at and, optional, the rotation around the forward direction vector (a single float value in tuple or list)
rotation (RotationParams) – rotation parameters according to the rotation_mode - for “quaternionWXYZ” and “quaternionXYZW” - Vec4d - for “rotvec” - Vec3d - for “rotmat” - Mat3x3 - for “euler<mode>” - Vec3d - for “look_at” - Vec3d, Positionable or Tuple[Vec3d/Positionable, float], where float is the rotation around the forward direction vector in degrees
translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))
resolution_percentage (int, optional)
- Returns:
created camera
- Return type: