def center_obs_for_thumbnail(obs): s = bpy.context.scene # obs = bpy.context.selected_objects parent = obs[0] while parent.parent != None: parent = parent.parent # reset parent rotation, so we see how it really snaps. parent.rotation_euler = (0, 0, 0) bpy.context.view_layer.update() minx, miny, minz, maxx, maxy, maxz = utils.get_bounds_worldspace(obs) cx = (maxx - minx) / 2 + minx cy = (maxy - miny) / 2 + miny for ob in s.collection.objects: ob.select_set(False) bpy.context.view_layer.objects.active = parent parent.location += mathutils.Vector((-cx, -cy, -minz)) camZ = s.camera.parent.parent camZ.location.z = (maxz - minz) / 2 dx = (maxx - minx) dy = (maxy - miny) dz = (maxz - minz) r = math.sqrt(dx * dx + dy * dy + dz * dz) scaler = bpy.context.view_layer.objects['scaler'] scaler.scale = (r, r, r) coef = .7 r *= coef camZ.scale = (r, r, r) s.update()
def center_obs_for_thumbnail(obs): s = bpy.context.scene # obs = bpy.context.selected_objects parent = obs[0] while parent.parent != None: parent = parent.parent # reset parent rotation, so we see how it really snaps. parent.rotation_euler = (0, 0, 0) bpy.context.scene.update() minx, miny, minz, maxx, maxy, maxz = utils.get_bounds_worldspace(obs) cx = (maxx - minx) / 2 + minx cy = (maxy - miny) / 2 + miny for ob in s.collection.objects: ob.select_set(False) bpy.context.view_layer.objects.active = parent parent.location += mathutils.Vector((-cx, -cy, -minz)) camZ = s.camera.parent.parent camZ.location.z = (maxz - minz) / 2 dx = (maxx - minx) dy = (maxy - miny) dz = (maxz - minz) r = math.sqrt(dx * dx + dy * dy + dz * dz) scaler = bpy.context.view_layer.objects['scaler'] scaler.scale = (r, r, r) coef = .7 r *= coef camZ.scale = (r, r, r) s.update()