How to get Viewport Position, Direction, UpVector? For Perspective and Ortho views.
Here is explanation Screenshot:
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.
Sign up to join this communityHow to get Viewport Position, Direction, UpVector? For Perspective and Ortho views.
Here is explanation Screenshot:
You can get information about the view from RegionView3D which can be accessed via space_data.region_3d.
There are utility functions available in the bpy_extras.view3d_utils module.
You may get the view direction like this
r3d.view_rotation * Vector((0.0, 0.0, -1.0))
the up direction should be
r3d.view_rotation * Vector((0.0, 1.0, 0.0))
and the view location:
r3d.view_matrix.inverted().translation
Or another way
region = context.region
rv3d = context.region_data
view3d_utils.region_2d_to_origin_3d(region, rv3d, (region.width/2.0, region.height/2.0))
Despite its name, RegionView3D.view_location
specifies the view target.
considering the answer given by pink vertex the first part is equivalent to:
r3d = bpy.context.area.spaces.active.region_3d
view_matrix = r3d.view_matrix
x,y,z = view_matrix.to_3x3()
with
view_dir = -z
up = y