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.
Here a live version for chrome, using d3.js and svg
Made a first few overlays in this post:
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
Here a live version for chrome, using d3.js and svg
Made a first few overlays in this post: