def calculate_view_axis(context): if context.area.type != 'VIEW_3D': return None, None region = context.region rv3d = context.region_data if rv3d is None: return None, None # Get the view ray from center of screen coord = Vector((int(region.width / 2), int(region.height / 2))) view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord) # Get the up vector. The default scene view camera is pointed # downward, with up on Y axis. Apply view rotation to get current up view_up_vector = rv3d.view_rotation * Vector((0.0, 1.0, 0.0)) plane_normal = sprytile_utils.snap_vector_to_axis(view_vector, mirrored=True) up_vector = sprytile_utils.snap_vector_to_axis(view_up_vector) # calculated vectors are not perpendicular, don't set data if plane_normal.dot(up_vector) != 0.0: return None, None return plane_normal, up_vector
def find_view_axis(context): if context.area.type != 'VIEW_3D': return scene = context.scene if scene.sprytile_data.lock_normal is True: return region = context.region rv3d = context.region_data if rv3d is None: return # Get the view ray from center of screen coord = Vector((int(region.width / 2), int(region.height / 2))) view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord) # Get the up vector. The default scene view camera is pointed # downward, with up on Y axis. Apply view rotation to get current up view_up_vector = rv3d.view_rotation * Vector((0.0, 1.0, 0.0)) plane_normal = sprytile_utils.snap_vector_to_axis(view_vector, mirrored=True) up_vector = sprytile_utils.snap_vector_to_axis(view_up_vector) # calculated vectors are not perpendicular, don't set data if plane_normal.dot(up_vector) != 0.0: return scene.sprytile_data.paint_normal_vector = plane_normal scene.sprytile_data.paint_up_vector = up_vector if abs(plane_normal.x) > 0: new_mode = 'X' elif abs(plane_normal.y) > 0: new_mode = 'Y' else: new_mode = 'Z' return new_mode