add some utils functions
This commit is contained in:
@@ -84,6 +84,20 @@ def get_tri_from_face(hit_location, face_index, object_hit, depsgraph):
|
||||
return tri, tri_indices
|
||||
|
||||
def ray_cast_point(point, origin, depsgraph):
|
||||
'''Return object hit by ray cast, hit location and triangle vertices coordinates and indices
|
||||
|
||||
point: point coordinate in world space
|
||||
origin: origin of the ray in world space
|
||||
depsgraph: current depsgraph (use bpy.context.evaluated_depsgraph_get())
|
||||
|
||||
return:
|
||||
object_hit (object): Object that was hit
|
||||
hit_location (Vector3, as np.array): Location Vector of the hit
|
||||
tri (list(Vector)): List of Vector3 world space coordinate of hitten triangle (tesselated from face if needed)
|
||||
tri_indices (list(int)): List of vertices index corresponding to tri coordinates
|
||||
|
||||
if nothing hit. return None, None, None, None
|
||||
'''
|
||||
ray = (point - origin)
|
||||
hit, hit_location, normal, face_index, object_hit, matrix = bpy.context.scene.ray_cast(depsgraph, origin, ray)
|
||||
|
||||
@@ -479,4 +493,25 @@ def index_list_from_bools(bool_list) -> list:
|
||||
## -- animation
|
||||
|
||||
def is_animated(obj):
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
## -- regions operations
|
||||
|
||||
def location_to_region(worldcoords) -> Vector:
|
||||
'''Get a world 3d coordinate and return 2d region coordinate
|
||||
|
||||
return: 2d vector in region space
|
||||
'''
|
||||
from bpy_extras import view3d_utils
|
||||
return view3d_utils.location_3d_to_region_2d(bpy.context.region, bpy.context.space_data.region_3d, worldcoords)
|
||||
|
||||
def region_to_location(viewcoords, depthcoords) -> Vector:
|
||||
'''Get 3d world coordinate from viewport region 2d coordianate
|
||||
viewcoords (Vector2): 2d region vector coordinate
|
||||
depthcoords (Vector3): 3d coordinate to define the depth
|
||||
|
||||
return: Vector3 of the placed location
|
||||
'''
|
||||
from bpy_extras import view3d_utils
|
||||
return view3d_utils.region_2d_to_location_3d(bpy.context.region, bpy.context.space_data.region_3d, viewcoords, depthcoords)
|
||||
Reference in New Issue
Block a user