Fix inverted layer order for flipped slab direction

When the mesh centroid check detects a direction mismatch
and flips `no`, also reverse the layer list so layer ordering
remains consistent with the reference line convention.

Generated with the assistance of an AI coding tool.
This commit is contained in:
Ryan Schultz
2026-03-24 08:45:26 -05:00
parent cd00b9994d
commit ae1c5444c3
3 changed files with 12 additions and 6 deletions
@@ -1903,16 +1903,18 @@ class CutDecorator:
# in object local space is on the wrong side of the starting plane, flip no.
bb = [Vector(v) for v in obj.bound_box]
mesh_centroid = sum(bb, Vector((0.0, 0.0, 0.0))) / 8
layers = list(layer_set.MaterialLayers)
if (mesh_centroid - co).dot(no) < 0:
no = -no
last_i = len(layer_set.MaterialLayers) - 1
layers = list(reversed(layers))
last_i = len(layers) - 1
vert_map = {}
verts = []
edges = []
j = 0
for i, layer in enumerate(layer_set.MaterialLayers):
for i, layer in enumerate(layers):
prev_co = co.copy()
co += no * layer.LayerThickness * self.unit_scale
if i != last_i:
@@ -734,10 +734,12 @@ class CreateDrawing(bpy.types.Operator):
# in object local space is on the wrong side of the starting plane, flip no.
bb = [Vector(v) for v in obj.bound_box]
mesh_centroid = sum(bb, Vector((0.0, 0.0, 0.0))) / 8
layers = list(layer_set.MaterialLayers)
if (mesh_centroid - co).dot(no) < 0:
no = -no
last_i = len(layer_set.MaterialLayers) - 1
for i, layer in enumerate(layer_set.MaterialLayers):
layers = list(reversed(layers))
last_i = len(layers) - 1
for i, layer in enumerate(layers):
prev_co = co.copy()
co += no * layer.LayerThickness * self.unit_scale
+4 -2
View File
@@ -1093,10 +1093,12 @@ class Loader(bonsai.core.tool.Loader):
# Detect non-conformant exports (e.g. Revit) where DirectionSense=POSITIVE
# but the geometry extrudes in the negative direction. If the mesh centroid
# in object local space is on the wrong side of the starting plane, flip no.
layers = list(layer_set.MaterialLayers)
if bm.verts:
mesh_centroid = sum((v.co for v in bm.verts), Vector((0.0, 0.0, 0.0))) / len(bm.verts)
if (mesh_centroid - co).dot(no) < 0:
no = -no
layers = list(reversed(layers))
# Cache this
body = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
styles = {}
@@ -1104,8 +1106,8 @@ class Loader(bonsai.core.tool.Loader):
for i, material in enumerate(mesh.materials):
if style := tool.Ifc.get_entity(material):
styles[style] = i
last_i = len(layer_set.MaterialLayers) - 1
for i, layer in enumerate(layer_set.MaterialLayers):
last_i = len(layers) - 1
for i, layer in enumerate(layers):
if i != last_i:
prev_co = co.copy()
co += no * layer.LayerThickness * cls.unit_scale