Blender/bpy utilities for paper-ready visualizations of meshes, point clouds and occupancy grids.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
README.md
binvox_rw.py
blender_utils.py
import_off.py
mesh.py
obj_to_off.py
off_to_obj.py
point_cloud.py
render_binvox.py
render_off.py
render_off_txt.py
render_txt.py
screenshot.jpg
txt_to_ply.py
write_binvox.py
write_txt.py

README.md

Visualizing 3D Data with Blender in Python

This repository contains various Python scripts for visualizing 3D data, in the form of triangular meshes, point clouds or occupancy grids, using Blender's Python API.

Acknowledgement: The code is based in some parts on work by Simon Donné.

If you use this code, consider citing:

@inproceedings{Stutz2018CVPR,
    title = {Learning 3D Shape Completion from Laser Scan Data with Weak Supervision },
    author = {Stutz, David and Geiger, Andreas},
    booktitle = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
    publisher = {IEEE Computer Society},
    year = {2018}
}
@misc{Stutz2017,
    author = {David Stutz},
    title = {Learning Shape Completion from Bounding Boxes with CAD Shape Priors},
    month = {September},
    year = {2017},
    institution = {RWTH Aachen University},
    address = {Aachen, Germany},
    howpublished = {http://davidstutz.de/},
}

Example of visualizations.

Requirements

The code was tested with Blender 2.78 or higher. Python should be installed locally and should also ship Python 3.5 with a custom NumPy installation.

All remaining requirements, essentially dimatura/binvox-rw-py and alextsui05/blender-off-addon are included.

File Formats

The following file formats are assumed:

  • OFF: file format for triangular meshes.
  • BINVOX: file format for occupancy grids.
  • A custom TXT format for point clouds.

The provided OFF files can be visualized using MeshLab. Scripts for converting OBJ files to OFF files as well as writing BINVOX and TXT files are provided.

The custom TXT file format looks as follows:

n_points
p1_x p1_y p2_z
p2_x p2_y p2_z
...

Use the following Python scripts for conversion:

  • off_to_obj.py and obj_to_off.py to conversion between OFF and OBJ.
  • txt_to_ply.py to convert a TXT point cloud to PLY format.

Examples of using the included Python code for writing TXT or BINVOX files are provided in write_txt.py and write_binvox.py.

Examples

examples/ includes some examples; these should be rune out of the root folder:

./examples/render_off.sh
./examples/render_binvox.sh
./examples/render_txt.sh

All examples create examples/0.png.

Usage

The provided examples essentially use the functionality provided in blender_utils.py; the general approach is as follows:

# Import utils.
from blender_utils import *

# Initialize and set camera target.
# Check the function to adapt the light sources or camera(s).
camera_target = initialize()

# Create a material.
# First parameter is the name, second is the diffuse color in rgb,
# third argument is the alpha channel and last whether to cast/receive shadow.
off_material = make_material('BRC_Material_Mesh', (0.66, 0.45, 0.23), 0.8, True)

# Load an OFF file, alternatively, use load_binvox or load_txt.
# In any case, we need the previously defined material.
# The mesh provided in examples/0.off is scaled to [0,32]^3,
# so we scale it by 1/32 = 0.03125 and then translate it to the
# origin using (-0.5, -0.5, -0.5).
# Finally we switch y and z axes.
load_off(args.off, off_material, (-0.5, -0.5, -0.5), 0.03125, 'xzy')

# Set rotation of camera around the origin, implicitly defines the locatio
# together with the distance.
rotation = (5, 0, -55)
distance = 0.5

# Render all loaded objects using the camera_target obtained above and
# the output file.
render(camera_target, output_file, rotation, distance)

License

Also see dimatura/binvox-rw-py and alextsui05/blender-off-addon.

Example data is from ModelNet and the shape completion benchmark of the CVPR paper referenced above.

Remaining code licensed as:

Copyright (c) 2018 David Stutz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.