blendersynth.blender.compositor.compositor

blendersynth.blender.compositor.compositor.AVAILABLE_FORMATS = ['BMP', 'IRIS', 'PNG', 'JPEG', 'JPEG2000', 'TARGA', 'TARGA_RAW', 'CINEON', 'DPX', 'OPEN_EXR_MULTILAYER', 'OPEN_EXR', 'HDR', 'TIFF']

List of available output file formats

class blendersynth.blender.compositor.compositor.Compositor(view_layer='ViewLayer', background_color=None, rgb_color_space=None)[source]

Compositor output - for handling file outputs, and managing Compositor node tree

__init__(view_layer='ViewLayer', background_color=None, rgb_color_space=None)[source]
Parameters:
  • view_layer – Name of View Layer to render

  • background_color (tuple) – If given, RGB[A] tuple in range [0-1], will overwrite World background with solid color (while retaining lighting effects).

  • rgb_color_space (str) – Color transform for RGB only. Defaults to AgX Base sRGB for Blender 4+, and Filmic sRGB for older versions.

define_output(input_data, directory='.', file_name=None, file_format='PNG', color_mode='RGBA', jpeg_quality=90, png_compression=15, color_depth='8', EXR_color_depth='32', name=None)[source]

Add a connection between a valid render output, and a file output node.

This should only be called once per output (NOT inside a loop). Inside the loop, only call update_filename, update_all_filenames update_directory

All outputs will be defined in raw color space (no color correction), except for the RGB output, and any overlays on this output (e.g. Bounding Box Visualization)

Parameters:
  • input_data (Union[str, CompositorNodeGroup, AOV]) – If str, will get the input_data from that key in the render_layers_node. If CompositorNodeGroup, use that node as input. If AOV, use that AOV as input (storing AOV).

  • directory (str) – Directory to save output to

  • file_name (str) – Name of file to save output to. If None, will use name (or input_data if name is None)

  • file_format (str) – File format to save output as. Must be in AVAILABLE_FORMATS

  • color_mode (str) – Color mode to save output as.

  • jpeg_quality (int) – Quality of JPEG output.

  • png_compression (int) – Compression of PNG output.

  • color_depth (str) – Color depth of output.

  • EXR_color_depth (str) – Color depth of EXR output.

  • name (str) – Name of output. If not given, will take the str representation of input_data

Return type:

str

Returns:

Name of output, which can be used to update filename or directory

get_axes_visual(size=1, thickness=2)[source]

Return an axes visual overlay.

Parameters:
  • size (int) – Size of axes. Default 100

  • thickness (int) – Thickness of axes. Default 2

Return type:

AxesOverlay

get_bounding_box_visual(col=(0.0, 0.0, 255.0, 255.0), thickness=5)[source]

Return a bounding box visual overlay.

Parameters:
  • col – (3,) or (N, 3) Color(s) of bounding box(es) [in BGR]

  • thickness (int) – (,) or (N,) Thickness(es) of bounding box(es)

Return type:

BoundingBoxOverlay

get_depth_visual(max_depth=1, col=(255, 255, 255))[source]

Get depth visual, which normalizes depth values so max_depth = col, and any values below that are depth/max_depth * col.

Parameters:
  • max_depth – Maximum depth value to normalize to

  • col (tuple) – Color of maximum depth value. 0-255 RGB or RGBA.

Return type:

CompositorNodeGroup

get_keypoints_visual(marker='x', color=(0, 0, 255), size=5, thickness=2)[source]

Return a keypoints visual overlay.

Parameters:
  • marker (str) – Marker type, either [c/circle], [s/square], [t/triangle] or [x]. Default ‘x’

  • size (int) – Size of marker. Default 5

  • color (tuple) – Color of marker, RGB or RGBA, default (0, 0, 255) (red)

  • thickness (int) – Thickness of marker. Default 2

Return type:

KeypointsOverlay

get_mask(index, input_rgb, anti_aliasing=False)[source]

Get mask node from pass index. If not found, create new mask node

Return type:

CompositorNodeGroup

render(camera=None, scene=None, annotations=None, animation=False, frame_start=0, frame_end=250)[source]

Render the scene.

Parameters:
  • camera (Union[Camera, List[Camera]]) – Camera(s) to render from. If None, will use scene.camera. If multiple, will render each camera separately, appending the camera’s names as the output file names.

  • scene (Scene) – Scene to render. If None, will use bpy.context.scene.

  • annotations (AnnotationHandler) – Object containing annotation information for each camera view to be used for overlays

  • animation (bool) – If True, will render an animation, using frame_start and frame_end as the start and end frames.

  • frame_start (int) – Start frame for animation.

  • frame_end (int) – End frame for animation.

stack_visuals(*visuals)[source]

Given a series of image overlays, stack them and return to be used as a single output node.

Parameters:

*visuals

Stack of overlays to add.

Return type:

AlphaImageOverlay

update_all_filenames(fname)[source]

Reassign all filenames (not directories) for all file output nodes.

Parameters:

fname (str) – new filename, without extension

update_directory(key, directory)[source]

Reassign the directory for a given file output node

Parameters:
  • key (str) – key of output, as given in define_output

  • directory (str) – new directory

update_filename(key, fname)[source]

Reassign the filename (not directory) for a given file output node.

Parameters:
  • key (str) – key of output, as given in define_output

  • fname (str) – new filename, without extension