From 7cef9ffe0e50f8490c0da469887cccbfc2a35f38 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 12 Sep 2023 13:16:17 +0500 Subject: [PATCH] Bends - replace faceset with simple extrusion --- .../geometry/add_railing_representation.py | 2 +- .../ifcopenshell/util/shape_builder.py | 51 ++++++++++++------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py index 33ea7b7b20..b597633678 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/geometry/add_railing_representation.py @@ -111,7 +111,7 @@ class Usecase: support_disk_circle = builder.circle(radius=support_disk_radius) angle = V(0, 1).angle_signed(ortho_dir.xy) - y_extrusion_kwargs = builder.rotate_extrusion_kwargs_by_z(builder.extrude_by_y_kwargs(), angle) + y_extrusion_kwargs = builder.rotate_extrusion_kwargs_by_z(builder.extrude_kwargs("Y"), angle) support_disk = builder.extrude( support_disk_circle, support_disk_depth, position=support_points[-1], **y_extrusion_kwargs ) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py index a3e811dc1e..f825b92db4 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape_builder.py @@ -624,17 +624,36 @@ class ShapeBuilder: return ifcopenshell.util.element.copy_deep(self.file, element) # UTILITIES - def extrude_by_y_kwargs(self): - """Shortcut to get kwargs for `ShapeBuilder.extrude` to extrude by Y axis. + def extrude_kwargs(self, axis): + """Shortcut to get kwargs for `ShapeBuilder.extrude` to extrude by some axis. - It assumes you have 2D profile in XZ plane and trying to extrude it by Y axis. + It assumes you have 2D profile in: + XZ plane for Y axis extrusion, \n + YZ plane for X axis extrusion, \n + XY plane for Z axis extrusion, \n - Extruding by Y using other kwargs might break ValidExtrusionDirection.""" - return { - "position_x_axis": Vector((1, 0, 0)), - "position_z_axis": Vector((0, -1, 0)), - "extrusion_vector": Vector((0, 0, -1)), - } + Extruding by X/Y using other kwargs might break ValidExtrusionDirection.""" + + axis = axis.upper() + + if axis == "Y": + return { + "position_x_axis": Vector((1, 0, 0)), + "position_z_axis": Vector((0, -1, 0)), + "extrusion_vector": Vector((0, 0, -1)), + } + elif axis == "X": + return { + "position_x_axis": Vector((0, 1, 0)), + "position_z_axis": Vector((1, 0, 0)), + "extrusion_vector": Vector((0, 0, 1)), + } + elif axis == "Z": + return { + "position_x_axis": Vector((1, 0, 0)), + "position_z_axis": Vector((0, 0, 1)), + "extrusion_vector": Vector((0, 0, 1)), + } def rotate_extrusion_kwargs_by_z(self, kwargs, angle, counter_clockwise=False): """shortcut to rotate extrusion kwargs by z axis @@ -1370,20 +1389,18 @@ class ShapeBuilder: points = inner_points + outer_points[::-1] points = [p + O for p in points] - offset = V(0, 0, 0) if is_circular_profile: bend_path = self.polyline(points, closed=False, arc_points=[1]) bend = self.create_swept_disk_solid(bend_path, profile_dim[lateral_axis]) else: + main_axes = lambda v: getattr(v, "xy"[lateral_axis] + "z") + offset = V(0, 0, 0) offset[non_lateral_axis] = -profile_dim[non_lateral_axis] - extrusion_vector = V(0, 0, 0) - extrusion_vector[non_lateral_axis] = 1 - bend = self.extrude_face_set( - points, - magnitude=profile_dim[non_lateral_axis] * 2, - offset=offset, - extrusion_vector=extrusion_vector, + extrusion_kwargs = self.extrude_kwargs("XY"[non_lateral_axis]) + profile_curve = self.polyline([main_axes(p) for p in points], closed=True) + bend = self.extrude( + self.profile(profile_curve), profile_dim[non_lateral_axis] * 2, position=offset, **extrusion_kwargs ) return bend