5
$\begingroup$

How to get Viewport Position, Direction, UpVector? For Perspective and Ortho views.

Here is explanation Screenshot:

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ related: blender.stackexchange.com/questions/13738/… $\endgroup$
    – p2or
    Commented Jan 9, 2015 at 22:50
  • $\begingroup$ I don't need camera. I need 3dView. Repspective/Ortho. But not camera object. $\endgroup$
    – mifth
    Commented Jan 10, 2015 at 20:30
  • $\begingroup$ Can you define the view-position much more clearly, this is quite an important distinction. (The point in the center of the view you look at, the point you look from?) $\endgroup$
    – ideasman42
    Commented Jan 11, 2015 at 13:21
  • $\begingroup$ The point i look from. $\endgroup$
    – mifth
    Commented Jan 11, 2015 at 17:58

2 Answers 2

8
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Thanks a lot! But Ortho view does not show position correctly. Here is my video test: youtu.be/Ia7wjCMafqA This line does not work in Ortho "r3d.view_matrix.inverted().translation". Do you know how to fix it? Thanks. $\endgroup$
    – mifth
    Commented Jan 11, 2015 at 12:17
  • $\begingroup$ I reported the issue with OrthoView here developer.blender.org/T43206 $\endgroup$
    – mifth
    Commented Jan 11, 2015 at 12:59
  • $\begingroup$ I added another approach according to the issue which was discussed. I hope you don't mind. $\endgroup$
    – mifth
    Commented Mar 4, 2015 at 14:19
2
$\begingroup$

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
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .