Python: "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" does not work correctly in Ortho #43206

Closed
opened 2015-01-11 13:59:05 +01:00 by paul geraskin · 17 comments
Member

Blender Version
2.73RC

Short description of error
Hi. I asked a question about Viewport position and direction here http://blender.stackexchange.com/questions/22963/viewport-position-and-direction .
I was recommended to use "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" to get position of the viewport.
But "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" does not work correctly in Ortho.
In OrthoView it shows the same values of "RegionView3D.view_location" (view target of viewport).

Here is my videotest: http://youtu.be/Ia7wjCMafqA
And here how it works in Perspective: http://youtu.be/tL9IXVDs7Cg

Is it possible to get Viewport position in Ortho view correctly?
This is very important for scripts developers. We need to get Viewport position in Ortho correctly.

If you need any other test examples just usk.

Thanks.

**Blender Version** 2.73RC **Short description of error** Hi. I asked a question about Viewport position and direction here http://blender.stackexchange.com/questions/22963/viewport-position-and-direction . I was recommended to use "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" to get position of the viewport. But "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" does not work correctly in Ortho. In OrthoView it shows the same values of "RegionView3D.view_location" (view target of viewport). Here is my videotest: http://youtu.be/Ia7wjCMafqA And here how it works in Perspective: http://youtu.be/tL9IXVDs7Cg Is it possible to get Viewport position in Ortho view correctly? This is very important for scripts developers. We need to get Viewport position in Ortho correctly. If you need any other test examples just usk. Thanks.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @PaulGeraskin

Added subscriber: @PaulGeraskin

Added subscriber: @ideasman42

Added subscriber: @ideasman42

This is not a bug, view matrices in ortho & perspective behave different.

For functions which work with both ortho & perspective views, see:
http://www.blender.org/api/blender_python_api_2_73_release/bpy_extras.view3d_utils.html#module-bpy_extras.view3d_utils

This is not a bug, view matrices in ortho & perspective behave different. For functions which work with both ortho & perspective views, see: http://www.blender.org/api/blender_python_api_2_73_release/bpy_extras.view3d_utils.html#module-bpy_extras.view3d_utils

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Campbell Barton self-assigned this 2015-01-11 14:19:08 +01:00
paul geraskin changed title from Python: "rv3d.view_matrix.inverted().translation" does not work correctly in Ortho to Python: "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" does not work correctly in Ortho 2015-01-11 14:30:04 +01:00

Added subscriber: @pink.vertex

Added subscriber: @pink.vertex

The code of region_2d_to_origin_3d is located here .

In case one is using the coordinates of the center of the window region,

region.width / 2.0 and
region.height / 2.0

dx and dy are both zero and the function returns a copy of view_matrix.inverted().translation as well.

By the way "zooming" in and out should only change the scaling factor not the view origin.

The view origin is relevant for clipping / visibility test.

The code of region_2d_to_origin_3d is located [here ](https://git.blender.org/gitweb/gitweb.cgi/blender.git/blob/HEAD:/release/scripts/modules/bpy_extras/view3d_utils.py#l66). In case one is using the coordinates of the center of the window region, region.width / 2.0 and region.height / 2.0 dx and dy are both zero and the function returns a copy of view_matrix.inverted().translation as well. By the way "zooming" in and out should only change the scaling factor not the view origin. The view origin is relevant for clipping / visibility test.

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'

There is an issue where ortho views dont have any good way to choose how far back their point of origin is.

There is an issue where ortho views dont have any good way to choose how far back their point of origin is.
Member

Added subscriber: @JulianEisel

Added subscriber: @JulianEisel
Author
Member

@pink.vertex
I changed "rv3d.view_matrix.inverted().translation" method to a different one. As it makes position a bit not correct. The position becomes behind the camera (in Perspective mode). Possibly, because of cameraClipping. But it's a bit behind.

I changed this issue to "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" as it's documented and it makes the position correctly (in Perspective mode). Also, this method always make the same position even if coordinates are different (in Perspective mode). But sure, you are right. It's better to use "region.width / 2.0" and "region.height / 2.0".

Corrected: view3d_utils.region_2d_to_origin_3d(region, rv3d, (region.width/2.0, region.height/2.0))

@ideasman42
I also noticed one thing about OrthoDirection. Direction is always the same in this method (in Ortho mode):
"view_vector_mouse = view3d_utils.region_2d_to_vector_3d(region, rv3d, (coord.x, coord.y))"
if there will be any coords - the direction will be always the same. But in Perspective mode the direction is always different depending on coords of a mouse. Is it ok for Orthographic mode?
I mean, if you will add the corrected OrthoPosition then should we also add corrected OrthoDirection?

@pink.vertex I changed "rv3d.view_matrix.inverted().translation" method to a different one. As it makes position a bit not correct. The position becomes behind the camera (in Perspective mode). Possibly, because of cameraClipping. But it's a bit behind. I changed this issue to "view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))" as it's documented and it makes the position correctly (in Perspective mode). Also, this method always make the same position even if coordinates are different (in Perspective mode). But sure, you are right. It's better to use "region.width / 2.0" and "region.height / 2.0". Corrected: view3d_utils.region_2d_to_origin_3d(region, rv3d, (region.width/2.0, region.height/2.0)) @ideasman42 I also noticed one thing about OrthoDirection. Direction is always the same in this method (in Ortho mode): "view_vector_mouse = view3d_utils.region_2d_to_vector_3d(region, rv3d, (coord.x, coord.y))" if there will be any coords - the direction will be always the same. But in Perspective mode the direction is always different depending on coords of a mouse. Is it ok for Orthographic mode? I mean, if you will add the corrected OrthoPosition then should we also add corrected OrthoDirection?
Author
Member

Just for notification and not to forget:
CGCookie team has fixed the issue with Ortho. it was discussed here:
http://blenderartists.org/forum/showthread.php?355154-Addon-Retopo-MT&p=2793598&viewfull=1#post2793598

And here is the code they did:
087bc8a40a/common_utilities.py (L343)

@ideasman42 said in IRC that he would make it a bit in a different way. This code is reference only.

Just for notification and not to forget: CGCookie team has fixed the issue with Ortho. it was discussed here: http://blenderartists.org/forum/showthread.php?355154-Addon-Retopo-MT&p=2793598&viewfull=1#post2793598 And here is the code they did: https://github.com/CGCookie/retopology-lib/blob/087bc8a40a872943c7b1d9af9a9a4a0a2055c70a/common_utilities.py#L343 @ideasman42 said in IRC that he would make it a bit in a different way. This code is reference only.

Re:

  view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0))

This is not documented anywhere in Blender.

Docs infact say:

    :arg coord: 2d coordinates relative to the region;
       (event.mouse_region_x, event.mouse_region_y) for example.

The only issue is that the point isn't projected backwards to the limit of the far clipping plane.
This is because the value is often very large (far clip of 5000+ is common),

So a way to optionally allow using the far clip would be useful. (or % of it)

Re: ``` view3d_utils.region_2d_to_origin_3d(region, rv3d, (0,0)) ``` This is not documented anywhere in Blender. Docs infact say: ``` :arg coord: 2d coordinates relative to the region; (event.mouse_region_x, event.mouse_region_y) for example. ``` The only issue is that the point isn't projected backwards to the limit of the far clipping plane. This is because the value is often very large (far clip of 5000+ is common), So a way to optionally allow using the far clip would be useful. (or % of it)

This issue was referenced by a4366497db

This issue was referenced by a4366497db5d30d12f9bbdc6644e5a282383af37

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit a4366497db.

Closed by commit a4366497db.
Author
Member

Thank you a lot! THanks thanks thanks!!!!!
Super cool!!! Yahoo!

i have just tested it and Ortho works great! http://youtu.be/2y2Qz8O2oyg
Origin is great now!

Thanks again. Now we (users) can make our tools with cool picking.

Thank you a lot! THanks thanks thanks!!!!! Super cool!!! Yahoo! i have just tested it and Ortho works great! http://youtu.be/2y2Qz8O2oyg Origin is great now! Thanks again. Now we (users) can make our tools with cool picking.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#43206
No description provided.