Fix T53002: Batch-Generate Previews generate empty or none image for large objects.
authorBastien Montagne <montagne29@wanadoo.fr>
Thu, 5 Oct 2017 16:12:10 +0000 (18:12 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Thu, 5 Oct 2017 16:13:30 +0000 (18:13 +0200)
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.

release/scripts/modules/bl_previews_utils/bl_previews_render.py

index b4f0b8dd3b8d4ba4f468e52f114470557fa9f71a..71208ef3485bb1c1566b7d2878a06289d2ee9cde 100644 (file)
@@ -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