Skip to content

BlenderPython Example Scene

Ben Heasly edited this page Nov 8, 2013 · 4 revisions

The BlenderPython scene is special in that its geometry is defined procedurally, instead of using Blender's GUI. Procedural generation of scene geometry offers several advantages:

  • Arbitrarily complex geometric patterns with specified spatial statistics can be easily generated, e.g., the table cloth in the scenes below. Such patterns would be very difficult, if at all possible, using Blender's GUI.
  • The geometric attributes of all each and every scene component can be loaded from a text file. In such a case, the mappings file, the conditions file, and this geometry file form a complete parametric description of the stimulus.
  • A family of scenes varying in one or more geometric aspect(s) can be generated automatically.
  • Use of the complicated Blender GUI can be kept at a bare minimum, or even eliminated.

The BlenderPython scene depicts a version of the checker-shadow illusion. It consists of a checkerboard, a cylinder, a table cloth, two area lights and a room enclosure. The left area light is responsible for the shadow cast by the cylinder on the checkerboard, whereas the front area light provides a more uniform illumination of the scene. There are two versions, one with a dimpled checkerboard, and one with a flat surface checkerboard. Note that in both versions, the luminance of the square at (row,col) = (3,3) from the top left corner is nearly identical to that of the square at (row,col) = (1,4). Yet, the square at (3,3) appears light and the square at (1,4) appears dark. Also note that the cloth material adds significant realism to the overall scene.

Here is what the dimpled checkerboard version looks like (Mitsuba rendering):

And here is what the non-dimpled checkerboard version looks like (Mitsuba rendering):

Geometric scene modeling (Blender-Python code)

The scene geometry is generated procedurally via a Python script, CheckerShadowScene.py, located in (path-to-RenderToolbox3)/ExampleScenes/BlenderPython/. This script calls methods of our custom BlenderPython module, SceneUtilsV1.py, located in (path-to-RenderToolbox3)/Utilities/BlenderPython/. The SceneUtilsV1.py provides a high-level interface for generating a number of scene elements. Its methods interact directly with Blender's 3D modeling engine via the bpy.py module which ships with Blender (version 2.68a).

To generate this scene, launch Blender from a terminal as described at Python-driven-Blender. Then open a TextEditor viewport, and type the following:

path = '(path-to-RenderToolbox3)/ExampleScenes/BlenderPython';
sceneName = 'CheckerShadowScene.py';
filename = '{}/{}'.format(path,sceneName);
exec(compile(open(filename).read(), filename, 'exec'));

Then hit the Run Script button.

Alternatively, you can interactively build the scene one component at a time, by running parts of the script as described at Python-driven-Blender.

Rendering (RenderToolbox3)

Excerpt from the mappings file,

% Lights
Generic {
    % Two-step workaround for RT3/Collada issue with parsing Blender's area lights.
    % Step 1: turn off the point light generated by the RT3-collada parser when it parses an area light
    leftAreaLamp-light:light:point
    leftAreaLamp-light:intensity.spectrum  = 300:0 800:0
    frontAreaLamp-light:light:point
    frontAreaLamp-light:intensity.spectrum = 300:0 800:0

    % Step 2: "bless" the meshes auto-generated by our custom SceneManager class for each 
    % of the Blender area lights into RenderToolbox3 area lights
    leftAreaLamp-mesh:light:area
    frontAreaLamp-mesh:light:area
    % Specify achromatic spectrums for the two area lights
    leftAreaLamp-mesh:intensity.spectrum = GrayRGB_scale1.00_Spectrum.spd
    frontAreaLamp-mesh:intensity.spectrum = GrayRGB_scale0.16_Spectrum.spd
}

% Materials
Generic {
    darkCheckMaterial-material:material:anisoward
    darkCheckMaterial-material:diffuseReflectance.spectrum      = GrayRGB_scale0.20_Spectrum.spd
    darkCheckMaterial-material:specularReflectance.spectrum     = GrayRGB_scale0.03_Spectrum.spd
    darkCheckMaterial-material:ensureEnergyConservation.boolean = false
    darkCheckMaterial-material:alphaU.float = 0.1
    darkCheckMaterial-material:alphaV.float = 0.1

    lightCheckMaterial-material:material:anisoward
    lightCheckMaterial-material:diffuseReflectance.spectrum      = GrayRGB_scale0.44_Spectrum.spd
    lightCheckMaterial-material:specularReflectance.spectrum     = GrayRGB_scale0.03_Spectrum.spd
    lightCheckMaterial-material:ensureEnergyConservation.boolean = false
    lightCheckMaterial-material:alphaU.float = 0.1
    lightCheckMaterial-material:alphaV.float = 0.1

    roomMaterial-material:material:anisoward
    roomMaterial-material:diffuseReflectance.spectrum      = GrayRGB_scale0.20_Spectrum.spd
    roomMaterial-material:specularReflectance.spectrum     = GrayRGB_scale0.03_Spectrum.spd
    roomMaterial-material:ensureEnergyConservation.boolean = false
    roomMaterial-material:alphaU.float = 0.51
    roomMaterial-material:alphaV.float = 0.51
}

Clone this wiki locally