Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

June 21, 2013

Data Visualization in Blender

Partly prompted by a post on blender.stackexchange about what options are available to visualize data, with the emphasis on scientific visualization. The next few posts will be about data visualization in Blender. Examining what methods are available and what needs to be written.

It made sense to start a repository of visualization scripts, here is BlenderSciViz


sample topic.

2d Overlays onto rendered geometry

This gets 2d pixel position of 3d coordinates seen by a camera and corresponding distance to lens.
import bpy
from bpy_extras.object_utils import world_to_camera_view
scene = bpy.context.scene
# needed to rescale 2d coordinates
render = scene.render
res_x = render.resolution_x
res_y = render.resolution_y
obj = bpy.data.objects['Cube']
cam = bpy.data.objects['Camera']
verts = (vert.co for vert in obj.data.vertices)
coords_2d = [world_to_camera_view(scene, cam, coord) for coord in verts]
# find min max distance, between eye and coordinate.
rnd = lambda i: round(i)
rnd3 = lambda i: round(i, 3)
limit_finder = lambda f: f(coords_2d, key=lambda i: i[2])[2]
limits = limit_finder(min), limit_finder(max)
limits = [rnd3(d) for d in limits]
print('min, max\n{},{}'.format(*limits))
# x, y, d=distance_to_lens
print('x,y,d')
for x, y, d in coords_2d:
print("{},{},{}".format(rnd(res_x*x), rnd(res_y*y), rnd3(d)))
view raw spastica.py hosted with ❤ by GitHub

Here a live version for chrome, using d3.js and svg
Made a first few overlays in this post: