def fixed(options): # TODO: Let the user position the camera in the browser, use his values center, radius = align_info() bpy.ops.object.camera_add() bpy.data.objects["Camera"].data.clip_start = 0.01 bpy.data.objects["Camera"].data.clip_end = radius * 9 bpy.context.scene.camera = bpy.data.objects["Camera"] bpy.data.objects["Camera"].location = (center.x + radius * 3, center.y, center.z + radius * 1.4) # Auto fit to viewport view3d_context = get_view3d_context() for obj in bpy.data.objects: obj.select = True bpy.ops.view3d.camera_to_view_selected(view3d_context)
def import_scene(import_scene, orient_flip_horizontally, orient_flip_vertically, orient_rotate_x, orient_rotate_y, orient_rotate_z): # TODO: This imports also camera, lights, etc. ... # TODO: Conceptually this imports one object, the code is like if there # were many objects imported though, unclean, unclear. filepath = path.join("imports", import_scene, "imported.blend") with bpy.data.libraries.load(filepath) as (data_from, data_to): data_to.objects = data_from.objects for obj in data_to.objects: if obj is not None: bpy.context.scene.objects.link(obj) bpy.context.scene.objects.active = obj bpy.ops.object.mode_set(mode='EDIT') view3d_context = get_view3d_context() bpy.ops.mesh.select_all(view3d_context, action='SELECT') bpy.ops.transform.mirror(view3d_context, constraint_axis=(False, orient_flip_horizontally == "true", orient_flip_vertically == "true")) # We need to flip the normals if the mesh is mirrored # on one axis only (if mirrored on both we don't need to) if orient_flip_horizontally != orient_flip_vertically: bpy.ops.mesh.flip_normals(view3d_context) bpy.ops.transform.rotate(value=orient_rotate_z, axis=(0, 0, 1)) bpy.ops.transform.rotate(value=orient_rotate_y, axis=(0, 1, 0)) bpy.ops.transform.rotate(value=orient_rotate_x, axis=(1, 0, 0)) bpy.ops.mesh.select_all(view3d_context, action='DESELECT') bpy.ops.object.mode_set(mode='OBJECT')
def import_scene(import_scene, orient_flip_horizontally, orient_flip_vertically, orient_rotate_x, orient_rotate_y, orient_rotate_z): # TODO: This imports also camera, lights, etc. ... # TODO: Conceptually this imports one object, the code is like if there # were many objects imported though, unclean, unclear. filepath = path.join(path.dirname(path.realpath(__file__)), "imports", import_scene, "imported.blend") with bpy.data.libraries.load(filepath) as (data_from, data_to): data_to.objects = data_from.objects for obj in data_to.objects: if obj is not None: bpy.context.scene.objects.link(obj) bpy.context.scene.objects.active = obj bpy.ops.object.mode_set(mode='EDIT') view3d_context = get_view3d_context() bpy.ops.mesh.select_all(view3d_context, action='SELECT') bpy.ops.transform.mirror( view3d_context, constraint_axis=(False, orient_flip_horizontally == "true", orient_flip_vertically == "true")) # We need to flip the normals if the mesh is mirrored # on one axis only (if mirrored on both we don't need to) if orient_flip_horizontally != orient_flip_vertically: bpy.ops.mesh.flip_normals(view3d_context) bpy.ops.transform.rotate(value=orient_rotate_z, axis=(0, 0, 1)) bpy.ops.transform.rotate(value=orient_rotate_y, axis=(0, 1, 0)) bpy.ops.transform.rotate(value=orient_rotate_x, axis=(1, 0, 0)) bpy.ops.mesh.select_all(view3d_context, action='DESELECT') bpy.ops.object.mode_set(mode='OBJECT')