@@ -1908,11 +1908,49 @@ def uninstall(cls):
1908
1908
cls .installed = None
1909
1909
1910
1910
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
1913
1921
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 )
1916
1954
1917
1955
def draw_batch (self , shader_type , content_pos , color , indices = None ):
1918
1956
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):
1923
1961
def decorate (self , context , obj ):
1924
1962
element = tool .Ifc .get_entity (obj )
1925
1963
if not element :
1926
- return
1964
+ return None , None
1927
1965
1928
1966
# Currently selected objects shall not be cached as they may be being moved / edited.
1929
1967
# If the camera is selected, we also disable the cache as the user may be moving the camera.
1930
1968
if obj .select_get () or context .scene .camera .select_get ():
1931
- all_vertices , all_edges = None , None
1969
+ verts , edges = None , None
1932
1970
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 ))
1934
1972
1935
- if all_vertices is False :
1936
- return
1973
+ if verts is False :
1974
+ return None , None
1937
1975
1938
1976
if not self .is_intersecting_camera (obj , context .scene .camera ):
1939
1977
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
1960
1979
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
1966
1984
1967
1985
def is_intersecting_camera (self , obj , camera ):
1968
1986
# Based on separating axis theorem
0 commit comments