Fix issue with updating slab offset with negative direction sense.

This commit is contained in:
Bruno Perdigão
2025-03-07 15:42:09 -03:00
parent 36744d391e
commit 01b63d87d0
3 changed files with 5 additions and 11 deletions
+2 -5
View File
@@ -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
+1 -4
View File
@@ -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
+2 -2
View File
@@ -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: