From 69b5d0940fbc7a422cbf870c6ae4b613513bd04d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 9 Apr 2025 15:26:34 +0500 Subject: [PATCH] bim.assign_class - flip normals if matrix is negative #6500 object.transform_apply doesn't preserve normals (https://projects.blender.org/blender/blender/issues/102266) --- src/bonsai/bonsai/bim/module/root/operator.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index fcc9303fc4..436f712b62 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -229,12 +229,19 @@ class AssignClass(bpy.types.Operator, tool.Ifc.Operator): continue if self.should_add_representation and isinstance(obj.data, bpy.types.Mesh) and obj.data.polygons: + # Apply scale. if obj.scale != (1, 1, 1): if obj.data.users > 1: bpy.ops.object.make_single_user( object=True, obdata=True, material=False, animation=False, obdata_animation=False ) + is_negative = obj.matrix_world.is_negative bpy.ops.object.transform_apply(location=False, rotation=False, scale=True, properties=False) + # object.transform_apply is losing normals. + if is_negative: + for polygon in obj.data.polygons: + polygon.flip() + if tool.Geometry.mesh_has_loose_geometry(obj.data): self.report( {"WARNING"},