[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57435] trunk/blender/release/scripts/ modules/bpy_extras/object_utils.py: 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 .
Campbell Barton
ideasman42 at gmail.com
Thu Jun 13 16:07:36 CEST 2013
Revision: 57435
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57435
Author: campbellbarton
Date: 2013-06-13 14:07:36 +0000 (Thu, 13 Jun 2013)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bpy_extras/object_utils.py
Modified: trunk/blender/release/scripts/modules/bpy_extras/object_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy_extras/object_utils.py 2013-06-13 13:55:05 UTC (rev 57434)
+++ trunk/blender/release/scripts/modules/bpy_extras/object_utils.py 2013-06-13 14:07:36 UTC (rev 57435)
@@ -287,13 +287,18 @@
: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 @@
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))
More information about the Bf-blender-cvs
mailing list