fix not working bim.generate_space because of the units mismatch

Not sure when this occurred but get_bmesh_from_polygon was expecting Polygon in project units but it was SI. Since it's probably better to move everything to SI, added an option to specify whether polygon is in SI or not.
This commit is contained in:
Andrej730
2024-10-22 16:15:09 +05:00
parent abd7c93c35
commit 54b104b822
3 changed files with 8 additions and 4 deletions
+1 -1
View File
@@ -178,7 +178,7 @@ def generate_space(ifc: tool.Ifc, model: tool.Model, root: tool.Root, spatial: t
if not space_polygon:
return
bm = spatial.get_bmesh_from_polygon(space_polygon, h=h)
bm = spatial.get_bmesh_from_polygon(space_polygon, h=h, polygon_is_si=True)
mesh = spatial.get_named_mesh_from_bmesh(name="Space", bmesh=bm)
+1 -1
View File
@@ -930,7 +930,7 @@ class Spatial:
def get_purged_inner_holes_poly(cls, union_geom, min_area): pass
def get_poly_valid_interior_list(cls, poly, min_area, interiors_list): pass
def get_buffered_poly_from_linear_ring(cls, linear_ring): pass
def get_bmesh_from_polygon(cls, poly, h): pass
def get_bmesh_from_polygon(cls, poly, h, polygon_is_si=False): pass
def get_named_obj_from_bmesh(cls, name, bmesh): pass
def get_named_obj_from_mesh(cls, name, mesh): pass
def get_named_mesh_from_bmesh(cls, name, bmesh): pass
+6 -2
View File
@@ -893,14 +893,18 @@ class Spatial(bonsai.core.tool.Spatial):
return poly
@classmethod
def get_bmesh_from_polygon(cls, poly: Polygon, h: float) -> bmesh.types.BMesh:
def get_bmesh_from_polygon(cls, poly: Polygon, h: float, polygon_is_si: bool = False) -> bmesh.types.BMesh:
"""
:param h: Height, in meters.
:param polygon_is_si: Should be True if `poly` is defined in meters.
"""
mat = Matrix()
bm = bmesh.new()
bm.verts.index_update()
bm.edges.index_update()
mat_invert = mat.inverted()
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
si_conversion = 1.0 if polygon_is_si else ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
new_verts = [
bm.verts.new(mat_invert @ (Vector([v[0], v[1], 0]) * si_conversion)) for v in poly.exterior.coords[0:-1]
]