Skip to content

Commit 6b0e7d5

Browse files
committed
Fix IfcOpenShell#2979. Batch drawling unselected and selected cut lines.
1 parent 4e5659e commit 6b0e7d5

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed

src/blenderbim/blenderbim/bim/module/drawing/decoration.py

+52-34
Original file line numberDiff line numberDiff line change
@@ -1908,11 +1908,49 @@ def uninstall(cls):
19081908
cls.installed = None
19091909

19101910
def __call__(self, context):
1911-
for obj in self.get_objects(None):
1912-
self.decorate(context, obj)
1911+
all_vertices = []
1912+
all_edges = []
1913+
selected_vertices = []
1914+
selected_edges = []
1915+
all_vertex_i_offset = 0
1916+
selected_vertex_i_offset = 0
1917+
for obj in [o for o in bpy.context.visible_objects if o.type == "MESH"]:
1918+
verts, edges = self.decorate(context, obj)
1919+
if not verts:
1920+
continue
19131921

1914-
def get_objects(self, collection):
1915-
return [o for o in bpy.context.visible_objects if o.type == "MESH"]
1922+
if obj.select_get():
1923+
selected_vertices.extend(verts)
1924+
selected_edges.extend([[vi + selected_vertex_i_offset for vi in e] for e in edges])
1925+
selected_vertex_i_offset += len(verts)
1926+
else:
1927+
all_vertices.extend(verts)
1928+
all_edges.extend([[vi + all_vertex_i_offset for vi in e] for e in edges])
1929+
all_vertex_i_offset += len(verts)
1930+
1931+
gpu.state.point_size_set(2)
1932+
gpu.state.blend_set("ALPHA")
1933+
1934+
# 3D_POLYLINE_UNIFORM_COLOR is good for smoothed lines since `bgl.enable(GL_LINE_SMOOTH)` is deprecated
1935+
self.line_shader = gpu.shader.from_builtin("3D_POLYLINE_UNIFORM_COLOR")
1936+
self.line_shader.bind()
1937+
# POLYLINE_UNIFORM_COLOR specific uniforms
1938+
self.line_shader.uniform_float("viewportSize", (context.region.width, context.region.height))
1939+
self.line_shader.uniform_float("lineWidth", 3.0)
1940+
1941+
# general shader
1942+
self.shader = gpu.shader.from_builtin("3D_UNIFORM_COLOR")
1943+
self.shader.bind()
1944+
1945+
green = (0.545, 0.863, 0, 1)
1946+
black = (0, 0, 0, 1)
1947+
1948+
if all_vertices:
1949+
self.draw_batch("LINES", all_vertices, black, all_edges)
1950+
self.draw_batch("POINTS", all_vertices, black)
1951+
if selected_vertices:
1952+
self.draw_batch("LINES", selected_vertices, green, selected_edges)
1953+
self.draw_batch("POINTS", selected_vertices, green)
19161954

19171955
def draw_batch(self, shader_type, content_pos, color, indices=None):
19181956
shader = self.line_shader if shader_type == "LINES" else self.shader
@@ -1923,46 +1961,26 @@ def draw_batch(self, shader_type, content_pos, color, indices=None):
19231961
def decorate(self, context, obj):
19241962
element = tool.Ifc.get_entity(obj)
19251963
if not element:
1926-
return
1964+
return None, None
19271965

19281966
# Currently selected objects shall not be cached as they may be being moved / edited.
19291967
# If the camera is selected, we also disable the cache as the user may be moving the camera.
19301968
if obj.select_get() or context.scene.camera.select_get():
1931-
all_vertices, all_edges = None, None
1969+
verts, edges = None, None
19321970
else:
1933-
all_vertices, all_edges = DecoratorData.cut_cache.get(element.id(), (None, None))
1971+
verts, edges = DecoratorData.cut_cache.get(element.id(), (None, None))
19341972

1935-
if all_vertices is False:
1936-
return
1973+
if verts is False:
1974+
return None, None
19371975

19381976
if not self.is_intersecting_camera(obj, context.scene.camera):
19391977
DecoratorData.cut_cache[element.id()] = (False, False)
1940-
return
1941-
1942-
if all_vertices is None:
1943-
all_vertices, all_edges = self.bisect_mesh(obj, context.scene.camera)
1944-
DecoratorData.cut_cache[element.id()] = (all_vertices, all_edges)
1945-
1946-
gpu.state.point_size_set(2)
1947-
gpu.state.blend_set("ALPHA")
1948-
1949-
### Actually drawing
1950-
# 3D_POLYLINE_UNIFORM_COLOR is good for smoothed lines since `bgl.enable(GL_LINE_SMOOTH)` is deprecated
1951-
self.line_shader = gpu.shader.from_builtin("3D_POLYLINE_UNIFORM_COLOR")
1952-
self.line_shader.bind()
1953-
# POLYLINE_UNIFORM_COLOR specific uniforms
1954-
self.line_shader.uniform_float("viewportSize", (context.region.width, context.region.height))
1955-
self.line_shader.uniform_float("lineWidth", 3.0)
1956-
1957-
# general shader
1958-
self.shader = gpu.shader.from_builtin("3D_UNIFORM_COLOR")
1959-
self.shader.bind()
1978+
return None, None
19601979

1961-
green = (0.545, 0.863, 0, 1)
1962-
white = (0, 0, 0, 1)
1963-
color = green if obj.select_get() else white
1964-
self.draw_batch("LINES", all_vertices, color, all_edges)
1965-
self.draw_batch("POINTS", all_vertices, color)
1980+
if verts is None:
1981+
verts, edges = self.bisect_mesh(obj, context.scene.camera)
1982+
DecoratorData.cut_cache[element.id()] = (verts, edges)
1983+
return verts, edges
19661984

19671985
def is_intersecting_camera(self, obj, camera):
19681986
# Based on separating axis theorem

0 commit comments

Comments
 (0)