now spaces created with spatial tool have relative zero elevation origin point

This commit is contained in:
Massimo Fabbro
2024-04-06 16:30:42 +02:00
committed by Massimo Fabbro
parent 2b926f7906
commit c05d2df116
3 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -214,7 +214,7 @@ def generate_spaces_from_walls(ifc, spatial, collector):
obj = spatial.get_named_obj_from_bmesh(name, bmesh=bm)
spatial.set_obj_origin_to_bboxcenter(obj)
spatial.set_obj_origin_to_bboxcenter_and_zero_elevation(obj)
spatial.traslate_obj_to_z_location(obj, z)
spatial.link_obj_to_active_collection(obj)
+1
View File
@@ -872,6 +872,7 @@ class Spatial:
def get_transformed_mesh_from_local_to_global(cls, mesh): pass
def edit_active_space_obj_from_mesh(cls, mesh): pass
def set_obj_origin_to_bboxcenter(cls, obj): pass
def set_obj_origin_to_bboxcenter_and_zero_elevation(cls, obj): pass
def set_obj_origin_to_cursor_position(cls, obj): pass
def get_selected_objects(cls): pass
def get_active_obj(cls): pass
+18
View File
@@ -582,6 +582,24 @@ class Spatial(blenderbim.core.tool.Spatial):
vert.co = inverted @ aux_vector
obj.location = newLoc
@classmethod
def set_obj_origin_to_bboxcenter_and_zero_elevation(cls, obj):
mat = obj.matrix_world
inverted = mat.inverted()
local_bbox_center = 0.125 * sum((Vector(b) for b in obj.bound_box), Vector())
global_bbox_center = mat @ local_bbox_center
global_obj_origin = global_bbox_center
global_obj_origin.z = 0
oldLoc = obj.location
newLoc = global_obj_origin
diff = newLoc - oldLoc
for vert in obj.data.vertices:
aux_vector = mat @ vert.co
aux_vector = aux_vector - diff
vert.co = inverted @ aux_vector
obj.location = newLoc
@classmethod
def set_obj_origin_to_cursor_position(cls, obj):
mat = obj.matrix_world