From 01b63d87d0d9219afd4b8f63b1c3ca730b3d41eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Fri, 7 Mar 2025 15:42:09 -0300 Subject: [PATCH] Fix issue with updating slab offset with negative direction sense. --- src/bonsai/bonsai/bim/module/model/slab.py | 7 ++----- src/bonsai/bonsai/bim/module/model/wall.py | 5 +---- src/bonsai/bonsai/tool/model.py | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/slab.py b/src/bonsai/bonsai/bim/module/model/slab.py index 2c4357e308..54f8f57fa8 100644 --- a/src/bonsai/bonsai/bim/module/model/slab.py +++ b/src/bonsai/bonsai/bim/module/model/slab.py @@ -300,8 +300,9 @@ class DumbSlabPlaner: existing_x_angle = tool.Model.get_existing_x_angle(extrusion) existing_x_angle = 0 if tool.Cad.is_x(existing_x_angle, 0, tolerance=0.001) else existing_x_angle existing_x_angle = 0 if tool.Cad.is_x(existing_x_angle, pi, tolerance=0.001) else existing_x_angle + existing_x_angle = 0 if tool.Cad.is_x(existing_x_angle, 2*pi, tolerance=0.001) else existing_x_angle direction_ratios = Vector(extrusion.ExtrudedDirection.DirectionRatios) - offset_direction = direction_ratios.copy() + offset_direction = Vector((abs(direction_ratios.x), abs(direction_ratios.y), abs(direction_ratios.z))) # The offset direction doesn't change with direction sense perpendicular_depth = thickness * abs(1 / cos(existing_x_angle)) perpendicular_offset = layer_params["offset"] * abs(1 / cos(existing_x_angle)) / self.unit_scale @@ -311,19 +312,15 @@ class DumbSlabPlaner: ): # The extrusion direction is positive. If the layer_parameter is set to negative, # then the we change the extrusion direction. - # The offset direction must always be positive, so we keep it. if layer_params["direction_sense"] == "NEGATIVE": direction_ratios *= -1 - # offset_direction *= -1 elif (abs(existing_x_angle) > (pi / 2) and direction_ratios.z > 0) or ( abs(existing_x_angle) < (pi / 2) and direction_ratios.z < 0 ): # The extrusion direction is negative. If the layer_parameter is set to positive, # then the we change the extrusion direction. - # The offset direction must always be positive, so we change it too. if layer_params["direction_sense"] == "POSITIVE": direction_ratios *= -1 - offset_direction *= -1 extrusion.ExtrudedDirection.DirectionRatios = tuple(direction_ratios) extrusion.Depth = perpendicular_depth diff --git a/src/bonsai/bonsai/bim/module/model/wall.py b/src/bonsai/bonsai/bim/module/model/wall.py index adf8ee9725..484937b136 100644 --- a/src/bonsai/bonsai/bim/module/model/wall.py +++ b/src/bonsai/bonsai/bim/module/model/wall.py @@ -264,7 +264,7 @@ class ChangeExtrusionXAngle(bpy.types.Operator, tool.Ifc.Operator): layer_params = tool.Model.get_material_layer_parameters(element) perpendicular_depth = layer_params["thickness"] * abs(1 / cos(x_angle)) / unit_scale perpendicular_offset = layer_params["offset"] * abs(1 / cos(x_angle)) / unit_scale - offset_direction = direction_ratios.copy() + offset_direction = Vector((abs(direction_ratios.x), abs(direction_ratios.y), abs(direction_ratios.z))) # The offset direction doesn't change with direction sense # Check angle and z direction to determine whether the extrusion direction is positive or negative if (abs(x_angle) < (pi / 2) and direction_ratios.z > 0) or ( @@ -272,7 +272,6 @@ class ChangeExtrusionXAngle(bpy.types.Operator, tool.Ifc.Operator): ): # The extrusion direction is positive. If the layer_parameter is set to negative, # then the we change the extrusion direction. - # The offset direction must always be positive, so we keep it. if layer_params["direction_sense"] == "NEGATIVE": direction_ratios *= -1 elif ((x_angle) > (pi / 2) and direction_ratios.z > 0) or ( @@ -280,10 +279,8 @@ class ChangeExtrusionXAngle(bpy.types.Operator, tool.Ifc.Operator): ): # The extrusion direction is negative. If the layer_parameter is set to positive, # then the we change the extrusion direction. - # The offset direction must always be positive, so we change it too. if layer_params["direction_sense"] == "POSITIVE": direction_ratios *= -1 - offset_direction *= -1 extrusion.ExtrudedDirection.DirectionRatios = tuple(direction_ratios) extrusion.Depth = perpendicular_depth diff --git a/src/bonsai/bonsai/tool/model.py b/src/bonsai/bonsai/tool/model.py index d304645d4c..ecccf21fe2 100644 --- a/src/bonsai/bonsai/tool/model.py +++ b/src/bonsai/bonsai/tool/model.py @@ -39,7 +39,7 @@ import bonsai.core.geometry import bonsai.core.tool import bonsai.tool as tool import bonsai.core.geometry as geometry -from math import atan, cos, degrees, radians +from math import atan, cos, degrees, radians, pi from mathutils import Matrix, Vector from copy import deepcopy from functools import partial @@ -2084,7 +2084,7 @@ class Model(bonsai.core.tool.Model): x, y, z = extrusion.ExtrudedDirection.DirectionRatios vector = Vector((0, 1)) x_angle = vector.angle_signed(Vector((y, z))) - return x_angle + return x_angle if z > 0 else (x_angle + pi) @classmethod def create_axis_curve(cls, obj: bpy.types.Object, grid_axis: ifcopenshell.entity_instance) -> None: