[Bf-blender-cvs] [e0db647] master: Fix region_2d_to_origin_3d not working with ortho view

Dalai Felinto noreply at git.blender.org
Tue Jun 14 23:03:17 CEST 2016


Commit: e0db647d35cd10675f8ab529f0f5f8e26680973b
Author: Dalai Felinto
Date:   Tue Jun 14 17:59:25 2016 -0300
Branches: master
https://developer.blender.org/rBe0db647d35cd10675f8ab529f0f5f8e26680973b

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()
```

===================================================================

M	release/scripts/modules/bpy_extras/view3d_utils.py

===================================================================

diff --git a/release/scripts/modules/bpy_extras/view3d_utils.py b/release/scripts/modules/bpy_extras/view3d_utils.py
index 4aa0626..5f83cdc 100644
--- a/release/scripts/modules/bpy_extras/view3d_utils.py
+++ b/release/scripts/modules/bpy_extras/view3d_utils.py
@@ -101,7 +101,7 @@ def region_2d_to_origin_3d(region, rv3d, coord, clamp=None):
         persinv = persmat.inverted()
         origin_start = ((persinv.col[0].xyz * dx) +
                         (persinv.col[1].xyz * dy) +
-                        viewinv.translation)
+                        persinv.translation)
 
         if clamp != 0.0:
             if rv3d.view_perspective != 'CAMERA':




More information about the Bf-blender-cvs mailing list