From 8deefe497cca8b9fd41e29e809ec0d0ad9478169 Mon Sep 17 00:00:00 2001 From: CyrilWaechter Date: Sun, 26 Jul 2026 15:20:23 +0200 Subject: [PATCH] Fix space regen doubling Z location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing translate_obj_to_z_location from the existing-IfcSpace regeneration branch. The ShapeBuilder rewrite (d8de62308) builds geometry in local space preserving obj.matrix_world, making the translate call redundant — it adds z on top of the already-correct location.z, producing 2*z. Add test_regenerate_space_preserves_z_location to cover the regeneration path with a non-zero Z elevation. Generated with the assistance of an AI coding tool. --- src/bonsai/bonsai/core/spatial.py | 1 - src/bonsai/test/tool/test_spatial.py | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/bonsai/bonsai/core/spatial.py b/src/bonsai/bonsai/core/spatial.py index 98db273f46..8843d48f2d 100644 --- a/src/bonsai/bonsai/core/spatial.py +++ b/src/bonsai/bonsai/core/spatial.py @@ -222,7 +222,6 @@ def generate_space( if element and element.is_a("IfcSpace"): spatial.set_space_representation_from_polygon(active_obj, element, space_polygon, h, polygon_is_si=True) - spatial.translate_obj_to_z_location(active_obj, z) else: if relating_type: name = model.generate_occurrence_name(relating_type, "IfcSpace") diff --git a/src/bonsai/test/tool/test_spatial.py b/src/bonsai/test/tool/test_spatial.py index ee2991e1c3..94b480f010 100644 --- a/src/bonsai/test/tool/test_spatial.py +++ b/src/bonsai/test/tool/test_spatial.py @@ -288,3 +288,27 @@ class TestGenerateSpace(NewFile): ) ) assert np.allclose(TEST_VERTS, sorted([tuple(v.co) for v in mesh.vertices])) + + def test_regenerate_space_preserves_z_location(self): + bpy.ops.bim.create_project() + ifc = tool.Ifc.get() + scene = bpy.context.scene + product = ifcopenshell.api.root.create_entity(ifc, ifc_class="IfcWall") + bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 4)) + obj = bpy.data.objects["Cube"] + scene.collection.objects.link(obj) + tool.Ifc.link(product, obj) + scene.cursor.location = (0, 0, 0) + + bpy.ops.bim.generate_space() + space = bpy.data.objects["IfcSpace/Space"] + space.location.z = 5 + bpy.context.view_layer.update() + + bpy.context.view_layer.objects.active = space + space.select_set(True) + obj.select_set(False) + + bpy.ops.bim.generate_space() + + assert np.isclose(space.location.z, 5), f"Expected z=5, got {space.location.z}"