def limit_cursor_by_bounds(self,context,location):
obj = context.active_object
bounds = self.bounds#get_bounds_and_center(obj)[1]
if len(bounds) > 0:
e1 = [bounds[0],bounds[2]] ### top edge
e2 = [bounds[2],bounds[3]] ### right edge
e3 = [bounds[3],bounds[1]] ### bottom edge
e4 = [bounds[1],bounds[0]] ### left edge
p1 = self.get_projected_point(e1,custom_pos=None,disable_edge_threshold=True) + Vector((0,0,-.1))
p2 = self.get_projected_point(e2,custom_pos=None,disable_edge_threshold=True) + Vector((-.1,0,0))
p3 = self.get_projected_point(e3,custom_pos=None,disable_edge_threshold=True) + Vector((0,0,.1))
p4 = self.get_projected_point(e4,custom_pos=None,disable_edge_threshold=True) + Vector((.1,0,0))
edges = [e1,e2,e3,e4]
points_on_edge = [p1,p2,p3,p4]
mouse_vec = [self.mesh_center,location]
for j,edge in enumerate(edges):
#mouse_vec = [points_on_edge[j] , location]
i = geometry.intersect_line_line_2d(edge[0].xz,edge[1].xz,mouse_vec[0].xz,mouse_vec[1].xz)
if i != None:
location = Vector((i[0],location[1],i[1]))
return location
评论列表
文章目录