mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 09:05:18 +00:00
project.operator - reuse ray_cast method
This commit is contained in:
@@ -2307,7 +2307,9 @@ class QueryLinkedElement(bpy.types.Operator):
|
|||||||
coord = (self.mouse_x, self.mouse_y)
|
coord = (self.mouse_x, self.mouse_y)
|
||||||
origin = region_2d_to_origin_3d(region, rv3d, coord)
|
origin = region_2d_to_origin_3d(region, rv3d, coord)
|
||||||
direction = region_2d_to_vector_3d(region, rv3d, coord)
|
direction = region_2d_to_vector_3d(region, rv3d, coord)
|
||||||
hit, location, normal, face_index, obj, instance_matrix = self.ray_cast(context, origin, direction)
|
hit, location, normal, face_index, obj, instance_matrix = tool.Blender.ray_cast_scene(
|
||||||
|
context, origin, direction
|
||||||
|
)
|
||||||
if not hit:
|
if not hit:
|
||||||
self.report({"INFO"}, "No object found.")
|
self.report({"INFO"}, "No object found.")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
@@ -2399,11 +2401,6 @@ class QueryLinkedElement(bpy.types.Operator):
|
|||||||
ProjectDecorator.install(bpy.context)
|
ProjectDecorator.install(bpy.context)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def ray_cast(self, context: bpy.types.Context, origin: Vector, direction: Vector):
|
|
||||||
depsgraph = context.evaluated_depsgraph_get()
|
|
||||||
result = context.scene.ray_cast(depsgraph, origin, direction)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def find_obj_root(self, obj: bpy.types.Object, matrix: Matrix) -> Union[bpy.types.Object, None]:
|
def find_obj_root(self, obj: bpy.types.Object, matrix: Matrix) -> Union[bpy.types.Object, None]:
|
||||||
collections = set(obj.users_collection)
|
collections = set(obj.users_collection)
|
||||||
for o in bpy.data.objects:
|
for o in bpy.data.objects:
|
||||||
@@ -2723,7 +2720,7 @@ class CreateClippingPlane(bpy.types.Operator):
|
|||||||
coord = (self.mouse_x, self.mouse_y)
|
coord = (self.mouse_x, self.mouse_y)
|
||||||
origin = region_2d_to_origin_3d(region, rv3d, coord)
|
origin = region_2d_to_origin_3d(region, rv3d, coord)
|
||||||
direction = region_2d_to_vector_3d(region, rv3d, coord)
|
direction = region_2d_to_vector_3d(region, rv3d, coord)
|
||||||
hit, location, normal, face_index, obj, matrix = self.ray_cast(context, origin, direction)
|
hit, location, normal, face_index, obj, matrix = tool.Blender.ray_cast_scene(context, origin, direction)
|
||||||
if not hit:
|
if not hit:
|
||||||
self.report({"INFO"}, "No object found.")
|
self.report({"INFO"}, "No object found.")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
@@ -2758,11 +2755,6 @@ class CreateClippingPlane(bpy.types.Operator):
|
|||||||
bpy.ops.bim.refresh_clipping_planes("INVOKE_DEFAULT")
|
bpy.ops.bim.refresh_clipping_planes("INVOKE_DEFAULT")
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def ray_cast(self, context, origin, direction):
|
|
||||||
depsgraph = context.evaluated_depsgraph_get()
|
|
||||||
result = context.scene.ray_cast(depsgraph, origin, direction)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
self.mouse_x = event.mouse_region_x
|
self.mouse_x = event.mouse_region_x
|
||||||
self.mouse_y = event.mouse_region_y
|
self.mouse_y = event.mouse_region_y
|
||||||
|
|||||||
@@ -2184,3 +2184,20 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
for f in files
|
for f in files
|
||||||
if (Path(directory) / f.name).is_file()
|
if (Path(directory) / f.name).is_file()
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def ray_cast_scene(
|
||||||
|
cls,
|
||||||
|
context: bpy.types.Context,
|
||||||
|
origin: Vector,
|
||||||
|
direction: Vector,
|
||||||
|
) -> tuple[bool, Vector, Vector, int, bpy.types.Object, Matrix]:
|
||||||
|
depsgraph = context.evaluated_depsgraph_get()
|
||||||
|
assert context.scene
|
||||||
|
# `matrix` is just `obj.matrix_world`.
|
||||||
|
result = context.scene.ray_cast(
|
||||||
|
depsgraph,
|
||||||
|
origin,
|
||||||
|
direction,
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user