mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
Fix slowness when rendering dense meshes with the opening decorator
It uses a custom boolean attribute on the mesh to decide whether an edge should be displayed or not. I think later on it can be used to get rid of the dictionary accessors which make the blend file size skyrocket.
This commit is contained in:
@@ -1184,12 +1184,14 @@ class DecorationsHandler:
|
|||||||
bm.from_mesh(obj.data)
|
bm.from_mesh(obj.data)
|
||||||
|
|
||||||
verts = [tuple(obj.matrix_world @ v.co) for v in bm.verts]
|
verts = [tuple(obj.matrix_world @ v.co) for v in bm.verts]
|
||||||
edges = [tuple([v.index for v in e.verts]) for e in bm.edges]
|
if ios_edges_attribute := obj.data.attributes.get("ios_edges"):
|
||||||
ios_edges = [(edge[0], edge[1]) for edge in obj.data.get("ios_edges", [])]
|
edges = [e for i, e in enumerate(bm.edges) if ios_edges_attribute.data[i].value]
|
||||||
if ios_edges:
|
else:
|
||||||
edges = [e for e in edges if (e[0], e[1]) in ios_edges or (e[1], e[0]) in ios_edges]
|
edges = bm.edges
|
||||||
|
edges_indices = [tuple([v.index for v in e.verts]) for e in edges]
|
||||||
|
|
||||||
color = selected_elements_color if obj in context.selected_objects else special_elements_color
|
color = selected_elements_color if obj in context.selected_objects else special_elements_color
|
||||||
self.draw_batch("LINES", verts, color, edges)
|
self.draw_batch("LINES", verts, color, edges_indices)
|
||||||
|
|
||||||
obj.data.calc_loop_triangles()
|
obj.data.calc_loop_triangles()
|
||||||
tris = [tuple(t.vertices) for t in obj.data.loop_triangles]
|
tris = [tuple(t.vertices) for t in obj.data.loop_triangles]
|
||||||
|
|||||||
@@ -937,7 +937,8 @@ class Loader(bonsai.core.tool.Loader):
|
|||||||
# ios_edges holds true edges that aren't triangulated.
|
# ios_edges holds true edges that aren't triangulated.
|
||||||
#
|
#
|
||||||
# we do `.tolist()` because Blender can't assign `np.int32` to it's custom attributes
|
# we do `.tolist()` because Blender can't assign `np.int32` to it's custom attributes
|
||||||
mesh["ios_edges"] = list(set(tuple(e) for e in ifcopenshell.util.shape.get_edges(geometry).tolist()))
|
ios_edges = list(set(tuple(e) for e in ifcopenshell.util.shape.get_edges(geometry).tolist()))
|
||||||
|
mesh["ios_edges"] = ios_edges
|
||||||
mesh["ios_item_ids"] = ifcopenshell.util.shape.get_faces_representation_item_ids(geometry).tolist()
|
mesh["ios_item_ids"] = ifcopenshell.util.shape.get_faces_representation_item_ids(geometry).tolist()
|
||||||
|
|
||||||
mesh.vertices.add(num_vertices)
|
mesh.vertices.add(num_vertices)
|
||||||
@@ -979,6 +980,20 @@ class Loader(bonsai.core.tool.Loader):
|
|||||||
# For now, not necessary to load maps in Item mode
|
# For now, not necessary to load maps in Item mode
|
||||||
if rep.is_a("IfcShapeRepresentation"):
|
if rep.is_a("IfcShapeRepresentation"):
|
||||||
tool.Loader.load_indexed_colour_map(rep, mesh)
|
tool.Loader.load_indexed_colour_map(rep, mesh)
|
||||||
|
|
||||||
|
ios_edges_indices = [(e[0], e[1]) for e in ios_edges]
|
||||||
|
attribute_ios_edges = mesh.attributes.get("ios_edges")
|
||||||
|
if not attribute_ios_edges:
|
||||||
|
attribute_ios_edges = mesh.attributes.new("ios_edges", domain="EDGE", type="BOOLEAN")
|
||||||
|
|
||||||
|
attribute_ios_edges.data.foreach_set(
|
||||||
|
"value",
|
||||||
|
[
|
||||||
|
(e.vertices[0], e.vertices[1]) in ios_edges_indices
|
||||||
|
or (e.vertices[1], e.vertices[0]) in ios_edges_indices
|
||||||
|
for e in mesh.edges
|
||||||
|
],
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
e = geometry.edges
|
e = geometry.edges
|
||||||
v = verts
|
v = verts
|
||||||
|
|||||||
Reference in New Issue
Block a user