This commit is contained in:
Andrej730
2025-04-30 18:14:28 +05:00
parent 5b1da583d9
commit 07f42b9126
2 changed files with 20 additions and 9 deletions
+13 -5
View File
@@ -1531,20 +1531,23 @@ class Drawing(bonsai.core.tool.Drawing):
drawing: ifcopenshell.entity_instance, drawing: ifcopenshell.entity_instance,
reference_element: ifcopenshell.entity_instance, reference_element: ifcopenshell.entity_instance,
context: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance,
) -> ifcopenshell.entity_instance: ) -> Union[ifcopenshell.entity_instance, None]:
import bonsai.bim.module.drawing.helper as helper import bonsai.bim.module.drawing.helper as helper
target_view = tool.Drawing.get_drawing_target_view(drawing) target_view = tool.Drawing.get_drawing_target_view(drawing)
camera = tool.Ifc.get_object(drawing) camera = tool.Ifc.get_object(drawing)
assert isinstance(camera, bpy.types.Object)
assert isinstance(camera_data := camera.data, bpy.types.Camera)
is_ortho = camera.data.type == "ORTHO" is_ortho = camera_data.type == "ORTHO"
bounds = helper.ortho_view_frame(camera.data) if is_ortho else None bounds = helper.ortho_view_frame(camera_data) if is_ortho else None
clipping = is_ortho and target_view in ("PLAN_VIEW", "REFLECTED_PLAN_VIEW") clipping = is_ortho and target_view in ("PLAN_VIEW", "REFLECTED_PLAN_VIEW")
elevating = is_ortho and target_view in ("ELEVATION_VIEW", "SECTION_VIEW") elevating = is_ortho and target_view in ("ELEVATION_VIEW", "SECTION_VIEW")
def clone(src: bpy.types.Object) -> bpy.types.Object: def clone(src: bpy.types.Object) -> bpy.types.Object:
dst = src.copy() dst = src.copy()
assert isinstance(dst.data, bpy.types.Mesh)
dst.data = dst.data.copy() dst.data = dst.data.copy()
dst.name = dst.name.replace("IfcGridAxis/", "") dst.name = dst.name.replace("IfcGridAxis/", "")
tool.Blender.get_object_bim_props(dst).ifc_definition_id = 0 tool.Blender.get_object_bim_props(dst).ifc_definition_id = 0
@@ -1552,19 +1555,23 @@ class Drawing(bonsai.core.tool.Drawing):
return dst return dst
def disassemble(obj: bpy.types.Object) -> tuple[bpy.types.Object, bmesh.types.BMesh]: def disassemble(obj: bpy.types.Object) -> tuple[bpy.types.Object, bmesh.types.BMesh]:
assert isinstance(obj.data, bpy.types.Mesh)
mesh = bmesh.new() mesh = bmesh.new()
mesh.verts.ensure_lookup_table() mesh.verts.ensure_lookup_table()
mesh.from_mesh(obj.data) mesh.from_mesh(obj.data)
return obj, mesh return obj, mesh
def assemble(obj: bpy.types.Object, mesh: bmesh.types.BMesh) -> bpy.types.Object: def assemble(obj: bpy.types.Object, mesh: bmesh.types.BMesh) -> bpy.types.Object:
assert isinstance(obj.data, bpy.types.Mesh)
mesh.to_mesh(obj.data) mesh.to_mesh(obj.data)
return obj return obj
def to_camera_coords(obj: bpy.types.Object, mesh: bpy.types.Mesh) -> tuple[bpy.types.Object, bpy.types.Mesh]: def to_camera_coords(
obj: bpy.types.Object, mesh: bmesh.types.BMesh
) -> tuple[bpy.types.Object, bmesh.types.BMesh]:
mesh.transform(camera.matrix_world.inverted() @ obj.matrix_world) mesh.transform(camera.matrix_world.inverted() @ obj.matrix_world)
obj.matrix_world = camera.matrix_world obj.matrix_world = camera.matrix_world
annotation_offset = mathutils.Vector((0, 0, -camera.data.clip_start - 0.05)) annotation_offset = mathutils.Vector((0, 0, -camera_data.clip_start - 0.05))
annotation_offset = camera.matrix_world.to_quaternion() @ annotation_offset annotation_offset = camera.matrix_world.to_quaternion() @ annotation_offset
obj.matrix_world.translation += annotation_offset obj.matrix_world.translation += annotation_offset
return obj, mesh return obj, mesh
@@ -1595,6 +1602,7 @@ class Drawing(bonsai.core.tool.Drawing):
obj = tool.Ifc.get_object(reference_element) obj = tool.Ifc.get_object(reference_element)
if not obj: if not obj:
return return
assert isinstance(obj, bpy.types.Object)
obj, mesh = to_camera_coords(*disassemble(clone(obj))) obj, mesh = to_camera_coords(*disassemble(clone(obj)))
if clipping: if clipping:
+7 -4
View File
@@ -27,9 +27,11 @@ import numpy.typing as npt
import multiprocessing import multiprocessing
import ifcopenshell import ifcopenshell
import ifcopenshell.api import ifcopenshell.api
import ifcopenshell.api.boundary
import ifcopenshell.api.geometry import ifcopenshell.api.geometry
import ifcopenshell.api.grid import ifcopenshell.api.grid
import ifcopenshell.api.profile import ifcopenshell.api.profile
import ifcopenshell.api.root
import ifcopenshell.api.style import ifcopenshell.api.style
import ifcopenshell.geom import ifcopenshell.geom
import ifcopenshell.guid import ifcopenshell.guid
@@ -223,13 +225,14 @@ class Geometry(bonsai.core.tool.Geometry):
@classmethod @classmethod
def delete_ifc_object(cls, obj: bpy.types.Object) -> None: def delete_ifc_object(cls, obj: bpy.types.Object) -> None:
ifc_file = tool.Ifc.get()
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
if not element: if not element:
return return
elif element.is_a("IfcAnnotation") and element.ObjectType == "DRAWING": elif element.is_a("IfcAnnotation") and element.ObjectType == "DRAWING":
return bonsai.core.drawing.remove_drawing(tool.Ifc, tool.Drawing, drawing=element) return bonsai.core.drawing.remove_drawing(tool.Ifc, tool.Drawing, drawing=element)
elif element.is_a("IfcRelSpaceBoundary"): elif element.is_a("IfcRelSpaceBoundary"):
ifcopenshell.api.run("boundary.remove_boundary", tool.Ifc.get(), boundary=element) ifcopenshell.api.boundary.remove_boundary(ifc_file, boundary=element)
tool.Boundary.undecorate_boundary(obj) tool.Boundary.undecorate_boundary(obj)
return bpy.data.objects.remove(obj) return bpy.data.objects.remove(obj)
elif element.is_a("IfcGridAxis"): elif element.is_a("IfcGridAxis"):
@@ -241,14 +244,14 @@ class Geometry(bonsai.core.tool.Geometry):
is_last_axis = True is_last_axis = True
if is_last_axis: if is_last_axis:
return return
ifcopenshell.api.run("grid.remove_grid_axis", tool.Ifc.get(), axis=element) ifcopenshell.api.grid.remove_grid_axis(ifc_file, axis=element)
return bpy.data.objects.remove(obj) return bpy.data.objects.remove(obj)
elif element.is_a("IfcGrid"): elif element.is_a("IfcGrid"):
axes = list(element.UAxes or []) + list(element.VAxes or []) + list(element.WAxes or []) axes = list(element.UAxes or []) + list(element.VAxes or []) + list(element.WAxes or [])
for axis in axes: for axis in axes:
if axis_obj := tool.Ifc.get_object(axis): if axis_obj := tool.Ifc.get_object(axis):
bpy.data.objects.remove(axis_obj) bpy.data.objects.remove(axis_obj)
ifcopenshell.api.grid.remove_grid_axis(tool.Ifc.get(), axis=axis) ifcopenshell.api.grid.remove_grid_axis(ifc_file, axis=axis)
collection = tool.Blender.get_object_bim_props(obj).collection collection = tool.Blender.get_object_bim_props(obj).collection
if collection: if collection:
@@ -286,7 +289,7 @@ class Geometry(bonsai.core.tool.Geometry):
bpy.ops.bim.remove_opening(opening_id=rel.RelatedOpeningElement.id()) bpy.ops.bim.remove_opening(opening_id=rel.RelatedOpeningElement.id())
for port in ifcopenshell.util.system.get_ports(element): for port in ifcopenshell.util.system.get_ports(element):
bonsai.core.system.remove_port(tool.Ifc, tool.System, port=port) bonsai.core.system.remove_port(tool.Ifc, tool.System, port=port)
ifcopenshell.api.run("root.remove_product", tool.Ifc.get(), product=element) ifcopenshell.api.root.remove_product(ifc_file, product=element)
data = obj.data data = obj.data
if ( if (