def set_active_axes_to_view(manip=0, axis_mode=0): manip = { 0: MoveManip, 1: RotateManip, 2: ScaleManip, }[manip]() offset = get_vector_offset(manip) camera = Camera(mvp.Viewport.active().camera) main_vector = camera.get_view_direction() vector_map = get_axis_vector_map(main_vector, offset, mode=axis_mode) closest_match = max(vector_map, key=vector_map.get) manip.set_active_handle(closest_match)
def walk_fit_camera_history(prev=False): """ Walk saved camera positions. """ if prev: fit_view_history.jump_back() else: fit_view_history.jump_forward() # Restore attributes current = fit_view_history.current_element camera = Camera(current.name) camera.transform.attr['translate'] = current.translate camera.transform.attr['rotate'] = current.rotate camera.attr['centerOfInterest'] = current.centerOfInterest
def viewport_snap(): """ Smooth camera transition between perspective and orthographic. """ view = mvp.Viewport.active() camera = Camera(view.camera) view_vector = camera.get_view_direction() axis = get_active_axis_from_view_vector(view_vector) negative = True if len(axis) > 1: negative = False axis = axis[-1] print 'negative', negative if camera.is_ortho(): camera.attr['orthographic'] = False translate_axis = 'translate{}'.format(axis.upper()) # Match values for smooth transition. trans = camera.transform.attr[translate_axis] value = camera.attr['orthographicWidth'] center_of_interrest = camera.attr['centerOfInterest'] if value > center_of_interrest: change = value - camera.attr['centerOfInterest'] camera_move = (trans-change) if negative else (trans+change) else: change = center_of_interrest - value camera_move = (trans+change) if negative else (trans-change) camera.transform.attr[translate_axis] = camera_move camera.attr['centerOfInterest'] = abs(value) else: camera_center = -camera.attr['centerOfInterest'] center_of_interest_approx = view_vector * camera_center # Find matching axis from world axes # Get necessary transforms cam_translate = camera.transform.get_translation() cam_rotate = camera.transform.get_rotate() view_vector = cam_translate - center_of_interest_approx # Modify non matching world vectors. for i in 'xyz'.replace(axis, ''): setattr(cam_translate, i, getattr(view_vector, i)) camera.attr['orthographic'] = True camera.attr['orthographicWidth'] = abs(camera_center) camera.transform.attr['translate'] = list(cam_translate) camera.transform.attr['rotateX'] = int(90 * round(float(cam_rotate.x)/90)) camera.transform.attr['rotateY'] = int(90 * round(float(cam_rotate.y)/90))