How to render multiple cameras with Blender
Table of Contents
Intro

When showing the stl parts to a project it is important to give an idea, which part is which.
There might be better ways of doing this inside Blender. If you know how, please point me in the right direction. In this post I describe how I achieved this with scripting inside Blender and an additional library.
Preparation
If you are using Blender with a bundled Python, use the next section as a guide, otherwise you should be able to use pip
directily.
Locate Blenders Bundled Python
In the Blender Python Console
run
>>> import sys
>>> sys.exec_prefix
It will show you where the bundled Python is on your disk:
'/Applications/Blender.app/Contents/Resources/2.80/python'
Then go to this folder with a shell an cd
into bin
, and then run (as taken from https://pip.pypa.io/en/stable/installing/) :
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
./python3.7m get-pip.py
Which should output something like this:
Collecting pip Downloading https://files.pythonhosted.org/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB) |████████████████████████████████| 1.4MB 3.9MB/s Collecting wheel Downloading https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl Installing collected packages: pip, wheel Found existing installation: pip 10.0.1 Uninstalling pip-10.0.1: Successfully uninstalled pip-10.0.1 Successfully installed pip-19.2.3 wheel-0.33.6
Once this worked as expected, you can run the following to install Pillow
./pip install Pillow
Which should output something like this:
Collecting Pillow Using cached https://files.pythonhosted.org/packages/8f/f3/c6d351d7e582e4f2ef4343c9be1f0472cb249fb69695e68631e337f4b6e9/ Pillow-6.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl Installing collected packages: Pillow Successfully installed Pillow-6.1.0
Setting up the cameras
Add four cameras with the following names (the script is hard coded to use these, you can change this to your requirements):
front
left
right
top
The Magic
Import an STL file, move it into place and select it.
Then, paste the following script into a new file inside blenders text editor view and hit Run Script
.
It should render your object from all four cameras and save each, as well as a combined image.
import bpy
import sys
from PIL import Image
def renderAndSaveCamera ( cameraName, fileName):
bpy.context.scene.camera = bpy.data.objects[cameraName]
bpy.context.scene.render.filepath = './' + fileName + '-' + cameraName
bpy.context.scene.render.image_settings.file_format='PNG'
bpy.ops.render.render(use_viewport=False, write_still=True)
if len(bpy.context.selected_objects) == 1:
selected=bpy.context.selected_objects[0]
print('creating render for ' + selected.name)
renderAndSaveCamera("front", selected.name)
renderAndSaveCamera("left", selected.name)
renderAndSaveCamera("right", selected.name)
renderAndSaveCamera("top", selected.name)
# combine cameras and save
combinedImage = Image.new('RGB', (bpy.context.scene.render.resolution_x*2,bpy.context.scene.render.resolution_y*2))
im=Image.open('./' + selected.name + '-front.png')
combinedImage.paste(im, (0,0))
im=Image.open('./' + selected.name + '-right.png')
combinedImage.paste(im, (0,bpy.context.scene.render.resolution_y))
im=Image.open('./' + selected.name + '-left.png')
combinedImage.paste(im, (bpy.context.scene.render.resolution_x,0))
im=Image.open('./' + selected.name + '-top.png')
combinedImage.paste(im, (bpy.context.scene.render.resolution_x,bpy.context.scene.render.resolution_y))
combinedImage.save('./' + selected.name + '-render.png')
else:
print('Please select a single object')
Hint
For true isomorphic camera settings in blender, see https://www.blender3darchitect.com/architectural-visualization/create-true-isometric-camera-architecture/