def project_cursor(self, event):
coord = mathutils.Vector((event.mouse_region_x, event.mouse_region_y))
transform = bpy_extras.view3d_utils.region_2d_to_location_3d
region = bpy.context.region
rv3d = bpy.context.space_data.region_3d
#### cursor used for the depth location of the mouse
depth_location = bpy.context.scene.cursor_location
#depth_location = bpy.context.active_object.location
### creating 3d vector from the cursor
end = transform(region, rv3d, coord, depth_location)
#end = transform(region, rv3d, coord, bpy.context.space_data.region_3d.view_location)
### Viewport origin
start = bpy_extras.view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)
### Cast ray from view to mouselocation
if b_version_bigger_than((2,76,0)):
ray = bpy.context.scene.ray_cast(start, (start+(end-start)*2000)-start )
else:
ray = bpy.context.scene.ray_cast(start, start+(end-start)*2000)
### ray_cast return values have changed after blender 2.67.0
if b_version_bigger_than((2,76,0)):
ray = [ray[0],ray[4],ray[5],ray[1],ray[2]]
return start, end, ray
评论列表
文章目录