From d0cf5f9d0c4014193b4a65b4f92b9e9e77fec65e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 10 Jan 2023 15:06:46 +0500 Subject: [PATCH] Fixed ShapeBuilder bug for mirroring IfcExtrudedAreaSolid Also fixed typo in shape_builder_examples --- .../scripts/shape_builder_examples.py | 2 +- .../ifcopenshell/util/shape_builder.py | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/blenderbim/scripts/shape_builder_examples.py b/src/blenderbim/scripts/shape_builder_examples.py index 48ec820687..d68fc19699 100644 --- a/src/blenderbim/scripts/shape_builder_examples.py +++ b/src/blenderbim/scripts/shape_builder_examples.py @@ -1,5 +1,5 @@ import ifcopenshell -from ifcopenshell.util.representation import ShapeBuilder +from ifcopenshell.util.shape_builder import ShapeBuilder from mathutils import Vector V = lambda *x: Vector([float(i) for i in x]) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py index 6509895ad0..47859bbaa0 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py @@ -286,7 +286,7 @@ class ShapeBuilder: mirror_axes: Vector = Vector((1.0, 1.0)).freeze(), mirror_point: Vector = Vector((0.0, 0.0)).freeze(), ): - """mirror axes - along which axes mirror will be applied""" + """mirror_axes - along which axes mirror will be applied""" base = point_2d # prevent mutating the argument mirror_axes = Vector( [-1 if i > 0 else 1 for i in mirror_axes] ) relative_point = base - mirror_point @@ -321,6 +321,10 @@ class ShapeBuilder: create_copy=False, placement_matrix=None, ): + """mirror_axes - along which axes mirror will be applied + + For example, mirroring A(1,0) by axis (1,0) will result in A'(-1,0) + """ # > curve_or_item - could be a list of curves or items # > mirror_axes - could be a list of mirrors to apply to curve_or_item # multiple mirror_axes will result in multiple resulting curves @@ -349,7 +353,7 @@ class ShapeBuilder: co_base = placement_matrix @ co_base.to_3d() co = self.mirror_2d_point(co_base.to_2d(), mirror_axes, mirror_point).to_3d() co.z = co_base.z - co = inverted_placement_matrix @ co + co = (inverted_placement_matrix @ co).to_2d() else: co = self.mirror_2d_point(co_base, mirror_axes, mirror_point) @@ -371,18 +375,24 @@ class ShapeBuilder: new_position.z = base_position.z c.Position.Location.Coordinates = new_position + # TODO: add support for Z-axis too + self.translate(c.SweptArea.OuterCurve, base_position.to_2d()) self.mirror(c.SweptArea.OuterCurve, mirror_axes, mirror_point, placement_matrix=placement_matrix) + self.translate(c.SweptArea.OuterCurve, -new_position.to_2d()) if hasattr(c.SweptArea, "InnerCurves"): for inner_curve in c.SweptArea.InnerCurves: + self.translate(inner_curve, base_position) self.mirror(inner_curve, mirror_axes, mirror_point, placement_matrix=placement_matrix) + self.translate(inner_curve, -new_position) # extrusion converted to world space base_extruded_direction = Vector(c.ExtrudedDirection.DirectionRatios) extruded_direction = placement_matrix @ base_extruded_direction # TODO: add support for Z-axis too - new_direction = self.mirror_2d_point(extruded_direction.to_2d(), mirror_axes, mirror_point) + # mirror point is ignored for extrusion direction + new_direction = self.mirror_2d_point(extruded_direction.to_2d(), mirror_axes, mirror_point=V(0,0)) new_direction = new_direction.to_3d() new_direction.z = extruded_direction.z @@ -464,4 +474,7 @@ class ShapeBuilder: RepresentationType="SweptSolid" if items[0].is_a("IfcExtrudedAreaSolid") else "Curve2D", Items=items, ) - return representation \ No newline at end of file + return representation + + def deep_copy(self, element): + return ifcopenshell.util.element.copy_deep(self.ifc, element) \ No newline at end of file