Fix T53002: Batch-Generate Previews generate empty or none image for large objects.

Camera clipping was left to default values, which won't work well for
very large (or small) objects. Now recompute valid clipping start/end
based on boundingbox of rendered data, and final location of camera.
This commit is contained in:
Bastien Montagne 2017-10-05 18:12:10 +02:00
parent 4537e85584
commit 63482a5f2e

@ -278,7 +278,7 @@ def do_previews(do_objects, do_groups, do_scenes, do_data_intern):
bbox[1].z = v.z
def objects_bbox_calc(camera, objects, offset_matrix):
bbox = (Vector((1e9, 1e9, 1e9)), Vector((-1e9, -1e9, -1e9)))
bbox = (Vector((1e24, 1e24, 1e24)), Vector((-1e24, -1e24, -1e24)))
for obname, libpath in objects:
ob = bpy.data.objects[obname, libpath]
object_bbox_merge(bbox, ob, camera, offset_matrix)
@ -305,6 +305,17 @@ def do_previews(do_objects, do_groups, do_scenes, do_data_intern):
cos = objects_bbox_calc(camera, objects, offset_matrix)
loc, ortho_scale = camera.camera_fit_coords(scene, cos)
camera.location = loc
# Set camera clipping accordingly to computed bbox.
min_dist = 1e24
max_dist = -1e24
for co in zip(*(iter(cos),) * 3):
dist = (Vector(co) - loc).length
if dist < min_dist:
min_dist = dist
if dist > max_dist:
max_dist = dist
camera.data.clip_start = min_dist / 2
camera.data.clip_end = max_dist * 2
if lamp:
loc, ortho_scale = lamp.camera_fit_coords(scene, cos)
lamp.location = loc