1 # -*- coding: utf-8 -*-
2 # ##### BEGIN GPL LICENSE BLOCK #####
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # ##### END GPL LICENSE BLOCK #####
23 Miscellaneous helper methods.
28 from cursor_utils
import *
29 from mathutils
import Vector
, Matrix
36 if bpy
.context
.mode
== 'EDIT_MESH':
37 bpy
.ops
.object.mode_set(mode
='OBJECT')
38 bpy
.ops
.object.mode_set(mode
='EDIT')
42 CursorAccess
.setCursor(CursorAccess
.getCursor())
45 # Converts 3D coordinates in a 3DRegion
46 # into 2D screen coordinates for that region.
47 # Borrowed from Buerbaum Martin (Pontiac)
48 def region3d_get_2d_coordinates(context
, loc_3d
):
49 # Get screen information
50 mid_x
= context
.region
.width
/ 2.0
51 mid_y
= context
.region
.height
/ 2.0
52 width
= context
.region
.width
53 height
= context
.region
.height
56 view_mat
= context
.space_data
.region_3d
.perspective_matrix
60 vec
= total_mat
* Vector((loc_3d
[0], loc_3d
[1], loc_3d
[2], 1.0))
68 x
= int(mid_x
+ vec
[0] * width
/ 2.0)
69 y
= int(mid_y
+ vec
[1] * height
/ 2.0)
72 return Vector((x
, y
, z
))