Fix regression in point cloud loading in refactoring the new item mode.

This commit is contained in:
Dion Moult
2025-03-23 21:55:57 +11:00
parent 51eef295c8
commit f1138d1aac
3 changed files with 57 additions and 13 deletions
+2 -5
View File
@@ -761,12 +761,9 @@ class IfcImporter:
def create_pointclouds(self, products: set[ifcopenshell.entity_instance]) -> set[ifcopenshell.entity_instance]:
result = set()
for product in products:
representation = self.get_pointcloud_representation(product)
if representation is not None:
pointcloud = self.create_pointcloud(product, representation)
if pointcloud is not None:
if representation := self.get_pointcloud_representation(product):
if pointcloud := self.create_pointcloud(product, representation):
result.add(pointcloud)
return result
def create_pointcloud(
+7 -8
View File
@@ -766,16 +766,15 @@ class Loader(bonsai.core.tool.Loader):
coords = None
if item.is_a("IfcCartesianPointList3D"): # PointCloud.c
coords = np.array(item.CoordList)
vertex_list.extend(Vector(list(coordinates)) * unit_scale for coordinates in item.CoordList)
# Is it ever used? In IFC4+ PointCloud is requiring 3D list, before IFC4 there were no coord lists at all.
elif item.is_a("IfcCartesianPointList2D"):
vertex_list.extend(Vector(list(coordinates)).to_3d() * unit_scale for coordinates in item.CoordList)
elif item.is_a("IfcPoint"): # Point
if item.is_a("IfcCartesianPoint"):
vertex_list.append(Vector(list(item.Coordinates)) * unit_scale)
else:
# TODO: implement non cartesian point vertices.
continue
coords = np.array(item.CoordList)
coords = np.column_stack((coords, np.zeros(coords.shape[0])))
elif item.is_a("IfcCartesianPoint"): # Point
coord = np.array(item.Coordinates)
if len(coord) == 2:
coord = np.append(coord, (0.0,))
coords = np.array((coord,))
else:
assert False
assert coords is not None
+48
View File
@@ -549,3 +549,51 @@ class TestSetupActiveBsddClassification(NewFile):
def test_set_load_and_set_active_bsdd_ifc4x3(self):
self.run_test("IFC4X3")
class TestCreatePointCloudMesh(NewFile):
def test_cartesian_point_list_3d(self):
bpy.ops.bim.create_project()
ifc_file = tool.Ifc.get()
coords = ((1., 2., 3.), (4., 5., 6.))
item = ifc_file.createIfcCartesianPointList3D(coords)
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
mesh = subject.create_point_cloud_mesh(rep)
assert len(mesh.vertices) == 2
verts = np.array([v.co for v in mesh.vertices])
assert np.allclose(verts, np.array([np.array(c) for c in coords]))
def test_cartesian_point_list_2d(self):
bpy.ops.bim.create_project()
ifc_file = tool.Ifc.get()
coords = ((1., 2.), (4., 5.))
coords3d = ((1., 2., 0.), (4., 5., 0.))
item = ifc_file.createIfcCartesianPointList2D(coords)
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
mesh = subject.create_point_cloud_mesh(rep)
assert len(mesh.vertices) == 2
verts = np.array([v.co for v in mesh.vertices])
assert np.allclose(verts, np.array([np.array(c) for c in coords3d]))
def test_point_3d(self):
bpy.ops.bim.create_project()
ifc_file = tool.Ifc.get()
coords = ((1., 2., 0.),)
item = ifc_file.createIfcCartesianPoint(Coordinates=coords[0])
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
mesh = subject.create_point_cloud_mesh(rep)
assert len(mesh.vertices) == 1
verts = np.array([v.co for v in mesh.vertices])
assert np.allclose(verts, np.array([np.array(c) for c in coords]))
def test_point_2d(self):
bpy.ops.bim.create_project()
ifc_file = tool.Ifc.get()
coords = ((1., 2.),)
coords3d = ((1., 2., 0.),)
item = ifc_file.createIfcCartesianPoint(Coordinates=coords[0])
rep = ifc_file.createIfcShapeRepresentation(Items=[item])
mesh = subject.create_point_cloud_mesh(rep)
assert len(mesh.vertices) == 1
verts = np.array([v.co for v in mesh.vertices])
assert np.allclose(verts, np.array([np.array(c) for c in coords3d]))