Usage#

The package pysdic-blender provides a collection of examples demonstrating how to render synthetic images of a pysdic scene with Blender. Each example can be downloaded as a Python script or a Jupyter notebook.

Note

The examples need bpy, available only with Python 3.13 (see Installation).

A first rendering#

A rendering is built in four steps: a pysdic.Camera and a triangle_3 pysdic.Mesh are created with pysdic, converted into Blender objects (pysdic_blender.BlenderCamera, pysdic_blender.BlenderMesh), added to a pysdic_blender.BlenderExperiment with a material and a light, then rendered.

import numpy
from pysdic import Camera, PerspectiveExtrinsic, PinholeIntrinsic, compute_wave_speckle, create_3d_triangle_3_heightmap
from pysdic_blender import BlenderCamera, BlenderExperiment, BlenderMesh, BlenderSpotLight, get_matte_paint_material

camera = Camera(
    180, 240,
    extrinsic=PerspectiveExtrinsic.from_rt(rvec=[numpy.pi, 0.0, 0.0], tvec=[0.0, 0.0, 5.0]),
    intrinsic=PinholeIntrinsic.from_matrix([[300.0, 0.0, 119.5], [0.0, 300.0, 89.5], [0.0, 0.0, 1.0]]),
)
plate = create_3d_triangle_3_heightmap(x_bounds=(-2.5, 2.5), y_bounds=(-2.0, 2.0), n_x=11, n_y=9)
x, y = numpy.linspace(-2.5, 2.5, 500), numpy.linspace(2.0, -2.0, 400)
speckle = compute_wave_speckle(numpy.stack(numpy.meshgrid(x, y), axis=-1), wavelength=0.15)

experiment = BlenderExperiment(background_strength=0.1)
experiment.add_camera("camera", BlenderCamera(camera))
experiment.add_mesh("plate", BlenderMesh(plate, texture=speckle), material=get_matte_paint_material())
experiment.add_spotlight("spot", BlenderSpotLight.looking_at([3.0, 0.0, 6.0], [0.0, 0.0, 0.0], energy=2000.0))
image = experiment.render("camera", n_samples=64)  # (180, 240), scene-linear

All the examples#

Placing the cameras with frames

Placing the cameras with frames

Depth of field of an inclined camera

Depth of field of an inclined camera

Lighting a specimen with Blender

Lighting a specimen with Blender

Checking the Blender cameras against pysdic

Checking the Blender cameras against pysdic

Rendering synthetic images with Blender

Rendering synthetic images with Blender

Stereo images of a deforming specimen

Stereo images of a deforming specimen

Gallery generated by Sphinx-Gallery