mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
use common method to generate mesh name
This commit is contained in:
@@ -661,7 +661,7 @@ class IfcImporter:
|
||||
def create_generic_sqlite_elements(self, elements: set[ifcopenshell.entity_instance]) -> None:
|
||||
self.geometry_cache = self.file.get_geometry([e.id() for e in elements])
|
||||
for geometry_id, geometry in self.geometry_cache["geometry"].items():
|
||||
mesh_name = tool.Loader.get_mesh_name(type("Geometry", (), {"id": geometry_id}))
|
||||
mesh_name = tool.Loader.get_mesh_name_from_shape(type("Geometry", (), {"id": geometry_id}))
|
||||
mesh = bpy.data.meshes.new(mesh_name)
|
||||
|
||||
verts = geometry["verts"]
|
||||
@@ -701,7 +701,7 @@ class IfcImporter:
|
||||
mesh = None
|
||||
geometry_id = self.geometry_cache["shapes"][element.id()]["geometry"]
|
||||
if geometry_id:
|
||||
mesh_name = tool.Loader.get_mesh_name(type("Geometry", (), {"id": geometry_id}))
|
||||
mesh_name = tool.Loader.get_mesh_name_from_shape(type("Geometry", (), {"id": geometry_id}))
|
||||
mesh = self.meshes.get(mesh_name)
|
||||
self.create_product(element, mesh=mesh)
|
||||
|
||||
@@ -776,7 +776,7 @@ class IfcImporter:
|
||||
if not vertex or not context or not representation:
|
||||
continue # TODO implement non cartesian point vertexes
|
||||
|
||||
mesh_name = f"{context.id()}/{representation.id()}"
|
||||
mesh_name = tool.Geometry.get_representation_name(representation)
|
||||
mesh = bpy.data.meshes.new(mesh_name)
|
||||
mesh.from_pydata([mathutils.Vector(vertex) * self.unit_scale], [], [])
|
||||
|
||||
@@ -841,7 +841,7 @@ class IfcImporter:
|
||||
if len(vertex_list) == 0:
|
||||
return None
|
||||
|
||||
mesh_name = f"{representation.ContextOfItems.id()}/{representation.id()}"
|
||||
mesh_name = tool.Geometry.get_representation_name(representation)
|
||||
mesh = bpy.data.meshes.new(mesh_name)
|
||||
mesh.from_pydata(vertex_list, [], [])
|
||||
tool.Ifc.link(representation, mesh)
|
||||
@@ -873,7 +873,7 @@ class IfcImporter:
|
||||
mesh = self.create_curve(element, shape)
|
||||
tool.Loader.link_mesh(shape, mesh)
|
||||
elif shape:
|
||||
mesh_name = tool.Loader.get_mesh_name(shape.geometry)
|
||||
mesh_name = tool.Loader.get_mesh_name_from_shape(shape.geometry)
|
||||
mesh = self.meshes.get(mesh_name)
|
||||
if mesh is None:
|
||||
mesh = self.create_mesh(element, shape)
|
||||
@@ -1323,7 +1323,7 @@ class IfcImporter:
|
||||
else:
|
||||
geometry = shape
|
||||
|
||||
curve = bpy.data.curves.new(tool.Loader.get_mesh_name(geometry), type="CURVE")
|
||||
curve = bpy.data.curves.new(tool.Loader.get_mesh_name_from_shape(geometry), type="CURVE")
|
||||
curve.dimensions = "3D"
|
||||
curve.resolution_u = 2
|
||||
|
||||
@@ -1354,7 +1354,7 @@ class IfcImporter:
|
||||
else:
|
||||
geometry = shape
|
||||
|
||||
mesh = bpy.data.meshes.new(tool.Loader.get_mesh_name(geometry))
|
||||
mesh = bpy.data.meshes.new(tool.Loader.get_mesh_name_from_shape(geometry))
|
||||
|
||||
if geometry.verts and tool.Loader.is_point_far_away(
|
||||
(geometry.verts[0], geometry.verts[1], geometry.verts[2]), is_meters=True
|
||||
|
||||
@@ -662,7 +662,7 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
height = max(y) - min(y)
|
||||
depth = max(z) - min(z)
|
||||
|
||||
camera = bpy.data.cameras.new(tool.Loader.get_mesh_name(geometry))
|
||||
camera = bpy.data.cameras.new(tool.Loader.get_mesh_name_from_shape(geometry))
|
||||
camera.type = camera_type
|
||||
camera.show_limits = True
|
||||
|
||||
|
||||
@@ -468,7 +468,7 @@ class Geometry(blenderbim.core.tool.Geometry):
|
||||
|
||||
@classmethod
|
||||
def get_representation_name(cls, representation: ifcopenshell.entity_instance) -> str:
|
||||
return f"{representation.ContextOfItems.id()}/{representation.id()}"
|
||||
return tool.Loader.get_mesh_name(representation.ContextOfItems.id(), representation.id())
|
||||
|
||||
@classmethod
|
||||
def get_styles(
|
||||
|
||||
@@ -71,7 +71,7 @@ class Loader(blenderbim.core.tool.Loader):
|
||||
return collection
|
||||
|
||||
@classmethod
|
||||
def get_mesh_name(cls, geometry: ifcopenshell.geom.ShapeType) -> str:
|
||||
def get_mesh_name_from_shape(cls, geometry: ifcopenshell.geom.ShapeType) -> str:
|
||||
representation_id = geometry.id
|
||||
if "-" in representation_id:
|
||||
# Example: 2432-openings-2468, where
|
||||
@@ -82,6 +82,10 @@ class Loader(blenderbim.core.tool.Loader):
|
||||
representation_id = int(re.sub(r"\D", "", representation_id))
|
||||
representation = tool.Ifc.get().by_id(representation_id)
|
||||
context_id = representation.ContextOfItems.id() if hasattr(representation, "ContextOfItems") else 0
|
||||
return cls.get_mesh_name(context_id, representation_id)
|
||||
|
||||
@classmethod
|
||||
def get_mesh_name(cls, context_id: int, representation_id: int) -> str:
|
||||
return "{}/{}".format(context_id, representation_id)
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user