diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-06-13 18:07:36 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-06-13 18:07:36 +0400 |
commit | 93ba74c20a8a50c872b3d4492bf0f5ea9499165b (patch) | |
tree | e1eb9703413f668cb44d9ac0689144df756c1b7a /release | |
parent | f9b06060c2bd05d8246bc327f0720baf29358bf2 (diff) |
minor edits to world_to_camera() utility function, include Z so you can tell if the points in font of the camera and avoid divide by zero.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bpy_extras/object_utils.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/release/scripts/modules/bpy_extras/object_utils.py b/release/scripts/modules/bpy_extras/object_utils.py index 7d7654d01af..7412d34940f 100644 --- a/release/scripts/modules/bpy_extras/object_utils.py +++ b/release/scripts/modules/bpy_extras/object_utils.py @@ -287,13 +287,18 @@ def world_to_camera(scene, obj, coord): :return: normalized 2d vector. :rtype: :class:`mathutils.Vector` """ + from mathutils import Vector co_local = obj.matrix_world.normalized().inverted() * coord + z = -co_local.z camera = obj.data frame = [-v for v in camera.view_frame(scene=scene)[:3]] if camera.type != 'ORTHO': - frame = [(v / -v.z) * co_local.z for v in frame] + if z == 0.0: + return Vector((0.5, 0.5, 0.0)) + else: + frame = [(v / (v.z / z)) for v in frame] min_x, max_x = frame[1].x, frame[2].x min_y, max_y = frame[0].y, frame[1].y @@ -301,5 +306,4 @@ def world_to_camera(scene, obj, coord): x = (co_local.x - min_x) / (max_x - min_x) y = (co_local.y - min_y) / (max_y - min_y) - from mathutils import Vector - return Vector((x, y)) + return Vector((x, y, z)) |