From cf65612a961f5ebf9c8438429ed57ba633b385ca Mon Sep 17 00:00:00 2001 From: Massimo Fabbro Date: Sun, 12 Nov 2023 07:47:15 +0100 Subject: [PATCH] Covering Tool: fixed bug if the project is defined in units different from SI units --- src/blenderbim/blenderbim/core/covering.py | 5 +++++ src/blenderbim/blenderbim/core/tool.py | 1 + src/blenderbim/blenderbim/tool/spatial.py | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/blenderbim/blenderbim/core/covering.py b/src/blenderbim/blenderbim/core/covering.py index e764dd4c78..49cf4722b4 100644 --- a/src/blenderbim/blenderbim/core/covering.py +++ b/src/blenderbim/blenderbim/core/covering.py @@ -50,6 +50,7 @@ def add_instance_flooring_covering_from_cursor(ifc, spatial, model, Type, geomet # spatial.traslate_obj_to_z_location(obj, z) spatial.link_obj_to_active_collection(obj) points = spatial.get_2d_vertices_from_obj(obj) + points = spatial.get_scaled_2d_vertices(points) spatial.assign_type_to_obj(obj) spatial.assign_swept_area_outer_curve_from_2d_vertices(obj, vertices = points) @@ -91,6 +92,7 @@ def add_instance_ceiling_covering_from_cursor(ifc, spatial, model, Type, geometr spatial.traslate_obj_to_z_location(obj, z) spatial.link_obj_to_active_collection(obj) points = spatial.get_2d_vertices_from_obj(obj) + points = spatial.get_scaled_2d_vertices(points) spatial.assign_type_to_obj(obj) spatial.assign_swept_area_outer_curve_from_2d_vertices(obj, vertices = points) @@ -119,6 +121,7 @@ def regen_selected_covering_object(ifc, spatial, model, Type, geometry): obj = spatial.get_named_obj_from_mesh(name, mesh) points = spatial.get_2d_vertices_from_obj(obj) + points = spatial.get_scaled_2d_vertices(points) spatial.assign_swept_area_outer_curve_from_2d_vertices(active_obj, vertices = points) body = spatial.get_body_representation(active_obj) @@ -140,6 +143,7 @@ def add_instance_flooring_coverings_from_walls(ifc, spatial, collector, geometry spatial.link_obj_to_active_collection(obj) points = spatial.get_2d_vertices_from_obj(obj) + points = spatial.get_scaled_2d_vertices(points) spatial.assign_type_to_obj(obj) spatial.assign_container_to_obj(obj) @@ -163,6 +167,7 @@ def add_instance_ceiling_coverings_from_walls(ifc, spatial, collector, geometry, spatial.link_obj_to_active_collection(obj) points = spatial.get_2d_vertices_from_obj(obj) + points = spatial.get_scaled_2d_vertices(points) spatial.assign_type_to_obj(obj) spatial.assign_container_to_obj(obj) diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index a373531533..6384c16c93 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -843,6 +843,7 @@ class Spatial: def traslate_obj_to_z_location(cls, obj): pass def link_obj_to_active_collection(cls, obj): pass def get_2d_vertices_from_obj(cls, obj): pass + def get_scaled_2d_vertices(cls, points): pass def assign_swept_area_outer_curve_from_2d_vertices(cls, obj, vertices): pass def get_body_representation(cls, obj): pass def assign_ifcspace_class_to_obj(cls, obj): pass diff --git a/src/blenderbim/blenderbim/tool/spatial.py b/src/blenderbim/blenderbim/tool/spatial.py index 1e74db5175..a30dfa77c5 100644 --- a/src/blenderbim/blenderbim/tool/spatial.py +++ b/src/blenderbim/blenderbim/tool/spatial.py @@ -627,6 +627,18 @@ class Spatial(blenderbim.core.tool.Spatial): points.append((vectors[0][0], vectors[0][1])) return points + @classmethod + def get_scaled_2d_vertices(cls, points): + model = tool.Ifc.get() + unit_scale = ifcopenshell.util.unit.calculate_unit_scale(model) + for i in range(len(points)): + a = list(points[i]) + a[0]/=unit_scale + a[1]/=unit_scale + points[i] = tuple(a) + + return points + @classmethod def assign_swept_area_outer_curve_from_2d_vertices(cls, obj, vertices): body = cls.get_body_representation(obj)