blender/release/scripts/modules/bpy_extras
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
..
__init__.py More spell checking. 2012-07-04 15:04:38 +00:00
anim_utils.py Fix T46040: Bake action cleans existing keyframes 2015-09-08 04:01:03 +10:00
image_utils.py Fix T47986: OBJ Import fails w/ imagepath encoding 2016-03-29 18:30:08 +11:00
io_utils.py Cleanup: pep8 2016-02-01 00:47:10 +11:00
keyconfig_utils.py Keymap: include 'Dopesheet Generic' 2016-06-13 23:03:00 +10:00
mesh_utils.py Correct Python exceptions 2014-08-07 00:44:55 +10:00
object_utils.py Fix T46220: Add torus has no 'layers' option 2015-09-24 01:05:55 +10:00
view3d_utils.py Fix region_2d_to_origin_3d not working with ortho view 2016-06-14 18:03:07 -03:00