Go to file
Dalai Felinto e0db647d35 Fix region_2d_to_origin_3d not working with ortho view
In some cases when:
* the viewport was in the camera mode
* the camera was ortho
* the view was not fitting (as oppose to use HOME)

region_2d_to_origin_3d would misbehave (and consequently region_2d_to_location_3d).

Sample addon to test it:
```
import bpy

from bpy_extras.view3d_utils import (
    region_2d_to_location_3d,
    )

from mathutils import (
    Vector,
    )

class MoveXYOperator(bpy.types.Operator):
    """Translate the view using mouse events"""
    bl_idname = "view3d.move_xy"
    bl_label = "Move XY"

    @classmethod
    def poll(cls, context):
        return context.object

    def modal(self, context, event):
        if event.type == 'MOUSEMOVE':
            self.move(context, event)

        elif event.type in {'LEFTMOUSE', 'RIGHTMOUSE', 'ESC'}:
            return {'FINISHED'}

        return {'RUNNING_MODAL'}

    def invoke(self, context, event):
        if context.space_data.type == 'VIEW_3D':
            self.ob = context.object
            context.window_manager.modal_handler_add(self)
            return {'RUNNING_MODAL'}
        else:
            self.report({'WARNING'}, "Active space must be a View3d")
            return {'CANCELLED'}

    def move(self, context, event):
        xy = region_2d_to_location_3d(
                context.region,
                context.space_data.region_3d,
                (event.mouse_region_x, event.mouse_region_y),
                Vector(),
                ).xy

        self.ob.location.xy = xy

def register():
    bpy.utils.register_class(MoveXYOperator)

def unregister():
    bpy.utils.unregister_class(MoveXYOperator)

if __name__ == "__main__":
    register()
```
2016-06-14 18:03:07 -03:00
build_files BGE: DeckLink card support for video capture and streaming. 2016-06-11 22:26:05 +02:00
doc Docs: Support out-of-source reference-API builds 2016-06-12 11:31:28 +10:00
extern Curve Fitting: add high-quality flag 2016-06-14 02:27:32 +10:00
intern Cleanup: Remove outdated comment, visibility layers in kernel have been removed. 2016-06-14 16:46:44 +02:00
release Fix region_2d_to_origin_3d not working with ortho view 2016-06-14 18:03:07 -03:00
source Text Editor: auto-complete removed entire word on undo 2016-06-15 04:28:13 +10:00
tests BLI_rand: add BLI_rng_get_char_n 2016-06-12 00:41:02 +10:00
.arcconfig Use HTTPS protocol for arc 2013-12-24 22:57:27 +06:00
.gitignore Git ignore BUILD_NOTES.txt from install_deps.sh. 2015-11-23 20:17:02 +01:00
.gitmodules Remove SCons building system 2016-01-04 14:20:48 +05:00
CMakeLists.txt Fix OS X build after Decklink changes, it is not supported yet so don't enable it. 2016-06-11 23:50:06 +02:00
COPYING == docs == 2010-10-13 14:44:22 +00:00
GNUmakefile Makefile: Use hidden FORCE target 2016-05-21 05:48:10 +10:00
make.bat Fix make.bat checking 64bit systems 2016-02-10 00:26:12 +11:00