blendertools

class pyvale.blendertools.BlenderTools[source]

Bases: object

Namespace for tools used within the pyvale Blender module.

static add_image_texture(mat_data: BlenderMaterialData, image_path: Path | None = None, image_array: ndarray | None = None) None[source]

A method to add an image texture to a Blender object, this will primarily be used for applying a speckle pattern to a sample object.

Parameters:
  • mat_data (BlenderMaterialData) -- A dataclass containing the material parameters, including roughness

  • image_path (Path | None, optional) -- The filepath for the speckle image file. If provided, that image will be used, by default None

  • image_array (np.ndarray | None, optional) -- An 2D array of a speckle image. If provided, this image will be used, by default None

Raises:

BlenderError -- "Image texture filepath does not exist". This error is thrown when neither a filepath nor an image array have been provided

check_for_GPU() bool[source]

A method to check whether the machine has a GPU or not.

Returns:

bool -- Returns True if a GPU is present, returns False if only a CPU is present.

static clear_material_nodes(part: <bpy_collection[3], BlendDataObjects>) None[source]

A method to clear any existing material nodes from the specified Blender object.

Parameters:

part (bpy.data.objects) -- The Blender part object to which a material will be applied.

static deform_single_timestep(part: <bpy_collection[3], BlendDataObjects>, deformed_nodes: ~numpy.ndarray) <bpy_collection[3], BlendDataObjects>[source]

A method to deform the part for a single timestep, given the node positions the nodes will move to.

Parameters:
  • part (bpy.data.objects) -- The Blender part object to be deformed, normally the sample object.

  • deformed_nodes (np.ndarray) -- An array of the deformed positions of each node in the surface mesh.

Returns:

bpy.data.objects -- The deformed Blender part object.

static move_blender_obj(pos_world: ~numpy.ndarray, part: <bpy_collection[3], BlendDataObjects>) None[source]

A method to move an object within Blender.

Parameters:
  • pos_world (np.ndarray) -- A array describing the vector position to which the part should be moved to.

  • part (bpy.data.objects) -- The Blender part object to be moved.

static number_calibration_images(calibration_data: CalibrationData) int[source]

A function to calculate the number of calibration images that will be rendered, given the calibration target's movement limits.

Parameters:

calibration_data (CalibrationData) -- A dataclass detailing the movement the calibration target will have throughout the calibration

Returns:

int -- The number of calibration images that will be rendered with the given settings

render_calibration_images(calibration_data: ~pyvale.blendercalibrationdata.CalibrationData, part: <bpy_collection[3], BlendDataObjects>) int[source]

A method to render a set of calibration images, which can be used to calculate the intrinsic and extrinsic parameters.

Parameters:
  • render_data (RenderData) -- A dataclass containing the parameters needed to render the images

  • calibration_data (CalibrationData) -- A dataclass containing the parameters by which to move the calibration target. These inclcude the plungle depth and rotation angle. It also inlcludes optional x and y limits for the movement of the calibration target (if None they will be initialised from the FOV).

  • part (bpy.data.objects) -- The Blender part object, in this instance the calibration target.

Returns:

int -- The number of calibration images that will be rendered. This is dependant on the values set within the CalibrationData dataclass.

static rotate_blender_obj(rot_world: ~scipy.spatial.transform._rotation.Rotation, part: <bpy_collection[3], BlendDataObjects>) None[source]

A method to rotate an object within Blender.

Parameters:
  • rot_world (Rotation) -- The rotation that is to be applied to the part object.

  • part (bpy.data.objects) -- The Blender part object to be rotated.

static save_blender_file(base_dir: Path | None = PosixPath('/home/runner'), override: bool = False) None[source]

A method to save the current Blender scene to a Blender .blend filepath

Parameters:
  • base_dir (Path) -- The base directory to which the Blender file will be saved to. The file will be saved in a subfolder of this directory named blenderfiles.

  • override (bool, optional) -- A flag which can be set to True or False. If set to True, if the specified filepath already exists, this file will be automatically overwritten. If set to False and the specified filepath already exists an error will be thrown. If the specified filepath does not exist, the file will be saved normally, by default False

Raises:
  • BlenderError -- "The specified save directory does not exist".

  • BlenderError -- "A file already exists with this filepath". This error is thrown when override is set to False, and the specified filepath already exists.

static save_render_as_array(filepath: Path) ndarray[source]

Method to save a rendered image as an array. This method write the image to the disk and then extracts it

Parameters:

filepath (Path) -- The filepath to which the image is saved

Returns:

np.ndarray -- The rendered image as an array with the following dimensions: shape=(pixels_num_y, pixels_num_x)

static set_new_frame(part: <bpy_collection[3], BlendDataObjects>) None[source]

A method to set a new frame within Blender (needed to differenciate the timesteps).

Parameters:

part (bpy.data.objects) -- The Blender part object, normally the sample object. This is passed in to ensure it is the active object within the scene.

static uv_unwrap_part(part: <bpy_collection[3], BlendDataObjects>, resolution: float, cal: bool = False) None[source]

A method to UV unwrap the Blender object, in order to apply a speckle image texture.

Parameters:
  • part (bpy.data.objects) -- The Blender part object to be unwrapped, normally the sample object.

  • resolution (float) -- The mm/px resolution of the rendered image, used to size the UV unwrapping.

  • cal (bool, optional) -- A flag that can be set when UV unwrapping a calibration target as the sizing differs, by default False