blenderscene

class pyvale.blenderscene.BlenderScene[source]

Bases: object

Namespace for creating a scene within Blender. Methods include adding an object, camera, light and adding a speckle pattern, as well as deforming the object, and then rendering the scene.

add_cal_target(target_size: ndarray) <bpy_collection[3], BlendDataObjects>[source]

A function to add a calibration target object to a Blender scene.

Parameters:

target_size (np.ndarray) -- The dimensions of the calibration target, with the shape=(width, height, depth).

Returns:

bpy.data.objects -- A Blender part object of the calibration target.

add_camera(cam_data: CameraData) <bpy_collection[3], BlendDataObjects>[source]

Method to add a camera object within Blender.

Parameters:

cam_data (CameraData) -- A dataclass containing the necessary parameters to create the camera object in Blender.

Returns:

bpy.data.objects -- The Blender camera object that is created.

add_light(light_data: BlenderLightData) <bpy_collection[3], BlendDataObjects>[source]

A method to add a light object within Blender.

Parameters:

light_data (BlenderLightData) -- A dataclass contain the necessary parameters to create a Blender light object.

Returns:

bpy.data.objects -- The Blender light object that is created.

add_part(render_mesh: RenderMesh, sim_spat_dim: int) <bpy_collection[3], BlendDataObjects>[source]

A method to add a part mesh into Blender, given a RenderMeshData object. This is done by taking the mesh information from the RenderMeshData object and converting it into a form that is accepted by Blender. It should be noted that the object is placed at the origin and centred around its geometric centroid.

Parameters:
  • render_mesh (RenderMeshData) -- A dataclass containing the mesh information of the skinned simulation mesh.

  • sim_spat_dim (int) -- The spatial dimension of the simulation mesh.

Returns:

bpy.data.objects -- The Blender part object that is created.

add_speckle(part: <bpy_collection[3], BlendDataObjects>, speckle_path: ~pathlib.Path | None, mat_data: ~pyvale.blendermaterialdata.BlenderMaterialData | None, mm_px_resolution: float, cal: bool = False) None[source]

A method to add a speckle pattern to an existing mesh object within Blender. The speckle pattern can either be passed in as an image file that is saved to the disc, or can be generated dynamically (this is currently not an option but this method has the capaibility to link up to a speckle pattern generator)

Parameters:
  • part (bpy.data.objects) -- The Blender part object, to which the speckle is to be applied.

  • speckle_path (Path | None) -- The filepath containing the speckle pattern image. If this is None, there will be capability to generate a speckle pattern.

  • mat_data (BlenderMaterialData | None) -- A dataclass containin the material parameters. If this is None, it is initialised within the method.

  • mm_px_resolution (float) -- The mm/px resolution of the camera. This is required in order to scale the speckle image.

  • cal (bool, optional) -- A flag that can be set if a calibration target image is added to a Blender part object. When set to True, the part object is UV unwrapped differently to ensure the correct scaling, by default False

add_stereo_system(stereo_system: CameraStereo) tuple[<bpy_collection[3], BlendDataObjects>, <bpy_collection[3], BlendDataObjects>][source]

A method to add a stereo camera system within Blender, given an instance of the CameraStereo class (that describes a stereo system).

Parameters:

stereo_system (CameraStereo) -- An instance of the CameraStereo class, describing a stereo system.

Returns:

tuple[bpy.data.objects, bpy.data.objects] -- A tuple of the Blender camera objects: camera 0 and camera 1.

render_deformed_images(render_mesh: ~pyvale.rendermesh.RenderMesh, sim_spat_dim: int, render_data: ~pyvale.blenderrenderdata.RenderData, part: <bpy_collection[3], BlendDataObjects>, stage_image: bool | None = True) None | ndarray[source]

A method to deform the mesh object at all timesteps, and render image(s) at each timestep

Parameters:
  • render_mesh (RenderMeshData) -- A dataclass containing the skimmed mesh and simulation information needed to deform the sample.

  • sim_spat_dim (int) -- The spatial dimension of the simulation.

  • render_data (RenderData) -- A dataclass containing the parameters necessary to render an image.

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

  • stage_image (bool | None, optional) -- A flag that can be set to save the rendered image to disk or not, by default True. In order to output these images as an array, the image will first be saved to the disk and then bounced back as an array.

Returns:

None | np.ndarray --

Either nothing is returned if the image is saved

to disk or a stack of image arrays are returned with the following dimensions: shape=(pixels_num_y, pixels_num_x, (num_timesteps + 1) for 2D setups and shape=(pixels_num_y, pixels_num_x, (num_timesteps + 1)*2) for 3D setups. The additional image is the reference image. For 3D setups, the images in the stack alternate between camera 0 and camera 1.

render_single_image(render_data: RenderData, stage_image: bool | None = True) None | ndarray[source]

A method to render an images(s) of the current scene in Blender. Depending on the number of cameras, either one or two images will be rendered.

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

  • stage_image (bool | None, optional) -- A flag that can be set to either save the rendered to disk or not. If set to False, an array of the image or stack of images will be returned, by default True. In order to output these images as an array, the image will first be saved to the disk and then bounced back as an array.

Returns:

None | np.ndarray -- Nothing is returned if the image(s) is saved to disk (when save set to True). When save is set to False, the image array is returned. For a 2D system, an array with shape=(pixels_num_y, pixels_num_x) is returned. For a 3D system, a stack of arrays with shape=(pixels_num_y, pixels_num_x, 2) is returned.

reset_scene() None[source]

This method creates a new, empty scene. The units are then set to milimetres, and all nodes are cleared from the scene. This method will be called when the class is initialised.