Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-06-13 18:07:36 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-06-13 18:07:36 +0400
commit93ba74c20a8a50c872b3d4492bf0f5ea9499165b (patch)
treee1eb9703413f668cb44d9ac0689144df756c1b7a /release/scripts/modules/bpy_extras
parentf9b06060c2bd05d8246bc327f0720baf29358bf2 (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/scripts/modules/bpy_extras')
-rw-r--r--release/scripts/modules/bpy_extras/object_utils.py10
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))