blendify package#

Subpackages#

Submodules#

blendify.cameras module#

blendify.scene module#

class blendify.scene.Scene(*args, **kwargs)[source]#

Bases: object

static attach_blend(path: Union[str, Path])[source]#

Append objects and materials from the existing .blend file to the scene. This includes lights, renderable objects, materials, etc. The appended modalities will only be present in the internal Blender structures, but not be present in the 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

attach_blend_with_camera(path: Union[str, Path])[source]#

Append objects and materials from the existing .blend file to the scene. This includes lights, renderable objects, materials, etc. The appended modalities will only be present in the internal Blender structures, but not be present in the 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

property camera: 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

clear()[source]#

Clears the scene

static export(path: Union[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

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: Optional[Union[str, Path]] = None, use_gpu: bool = True, samples: int = 128, save_depth: bool = False, save_albedo: bool = False, verbose: bool = False, use_denoiser: bool = False)[source]#

Start the Blender rendering process

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

set_orthographic_camera(resolution: Union[ndarray, Tuple[int, int]], ortho_scale: float = 1.0, near: float = 0.1, far: float = 100.0, tag: str = 'camera', quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[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

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • resolution_percentage (int, optional) –

Returns:

created camera

Return type:

OrthographicCamera

set_perspective_camera(resolution: Union[ndarray, Tuple[int, int]], focal_dist: Optional[float] = None, fov_x: Optional[float] = None, fov_y: Optional[float] = None, center: Optional[Union[ndarray, Tuple[float, float]]] = None, near: float = 0.1, far: float = 100.0, tag: str = 'camera', quaternion: Union[ndarray, Tuple[float, float, float, float]] = (1, 0, 0, 0), translation: Union[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

  • quaternion (Vector4d, optional) – rotation applied to the Blender object (default: (1,0,0,0))

  • translation (Vector3d, optional) – translation applied to the Blender object (default: (0,0,0))

  • resolution_percentage (int, optional) –

Returns:

created camera

Return type:

PerspectiveCamera

Module contents#