Не подтверждена Коммит 7c702746 создал по автору Sergey's avatar Sergey Зафиксировано автором GitHub
Просмотр файлов

Add custom indexes for edges and faces (Viewer Index node) (#4595)

* add custom indexes for edges and faces

* fix problem not displaying custom text when node.draw_bface property was disabled

* update documentation

* fix list doc element
владелец 3360ae8b
......@@ -10,19 +10,46 @@ This node's primary purpose is for display the index information of geometry and
- Edge indices are drawn on midpoint of the Edge
- Face indices are drawn at the average location of the Vertices associated with the face.
Additionally
Additionally
- the input geometry can be transformed using the Matrix socket.
- the Node can draw arbitrary (non renderable) text into the 3dview at the location of incoming verts. There must be a one-to-one supply of vertices and text to draw, else the node will decide where to draw the excess text elements.
- the Node can draw arbitrary (non renderable) text into the 3dview at the
location of incoming verts, edges and faces. If incoming data is shorter than
number of elements the last element will be displayed on rest elements.
.. image:: https://user-images.githubusercontent.com/619340/127735798-4c3a4222-28ce-418a-b3f0-13c8149a590c.png
Because it can be difficult to read indices when there are many geometric elements visible there is an option to draw a small background under the text element.
- (available from N Panel) the Node can display the Object index associated with the element ( the first object, first index will be drawn as ``0: 0`` )
Parameters
----------
Because it can be difficult to read indices when there are many geometric elements visible there is an option to draw a small background under the text element.
Activate
Enabling the node.
Draw background
Hide background around text.
Draw bface
(using the Ghost icon in the Node UI) if you attach verts + faces, you can
also hide backfacing indices from being displayed. Adding the faces
information gives the node enough information to detect what can be seen
directly by the viewport "eye" location.
- (using the Ghost icon in the Node UI) if you attach verts + faces, you can also hide backfacing indices from being displayed. Adding the faces information gives the node enough information to detect what can be seen directly by the viewport "eye" location.
Draw object index
(available from N Panel) the Node can display the Object index associated
with the element ( the first object, first index will be drawn as ``0: 0`` )
Examples
--------
Hide text behind geometry
.. image:: https://user-images.githubusercontent.com/619340/127735702-7db6c27a-9f59-4ad4-83f8-44fe96fcbd0c.png
:width: 800px
Show custom text
.. image:: https://user-images.githubusercontent.com/619340/127735798-4c3a4222-28ce-418a-b3f0-13c8149a590c.png
:width: 800px
......
......@@ -203,8 +203,33 @@ class SvIDXViewer28(bpy.types.Node, SverchCustomTreeNode):
setattr(geom, socket, input_stream)
prefix_if_needed = lambda obj_index, chars: (f'{obj_index}: {chars}') if self.draw_obj_idx else chars
fixed_text = []
if geom.text:
for obj_index, final_verts in enumerate(geom.verts):
text_size = max(len(final_verts),
len(geom.edges[obj_index]),
len(geom.faces[obj_index]))
text_items = self.get_text_of_correct_length(obj_index, geom, text_size)
for text_item in text_items:
# yikes, don't feed this function nonsense :)
if isinstance(text_item, float):
chars = prefix_if_needed(obj_index, text_item)
elif isinstance(text_item, list) and len(text_item) == 1:
chars = prefix_if_needed(obj_index, text_item[0])
else:
# in case it receives [0, 0, 0] or (0, 0, 0).. etc
chars = prefix_if_needed(obj_index, text_item)
fixed_text.append(chars)
if not self.draw_bface:
geom.face_medians, geom.face_normals = self.get_face_extras(geom)
geom.text_data = fixed_text
return geom
else:
......@@ -213,15 +238,11 @@ class SvIDXViewer28(bpy.types.Node, SverchCustomTreeNode):
display_topology.vert_data = []
display_topology.edge_data = []
display_topology.face_data = []
display_topology.text_data = []
display_topology.text_data = fixed_text
concat_vert = display_topology.vert_data.append
concat_edge = display_topology.edge_data.append
concat_face = display_topology.face_data.append
concat_text = display_topology.text_data.append
prefix_if_needed = lambda obj_index, chars: (f'{obj_index}: {chars}') if self.draw_obj_idx else chars
for obj_index, final_verts in enumerate(geom.verts):
......@@ -231,23 +252,6 @@ class SvIDXViewer28(bpy.types.Node, SverchCustomTreeNode):
chars = prefix_if_needed(obj_index, idx)
concat_vert((chars, vpos))
if geom.text:
text_items = self.get_text_of_correct_length(obj_index, geom, len(final_verts))
for text_item, vpos in zip(text_items, final_verts):
# yikes, don't feed this function nonsense :)
if isinstance(text_item, float):
chars = prefix_if_needed(obj_index, text_item)
elif isinstance(text_item, list) and len(text_item) == 1:
chars = prefix_if_needed(obj_index, text_item[0])
else:
# in case it receives [0, 0, 0] or (0, 0, 0).. etc
chars = prefix_if_needed(obj_index, text_item)
concat_text((chars))
if self.display_edge_index and obj_index < len(geom.edges):
for edge_index, (idx1, idx2) in enumerate(geom.edges[obj_index]):
loc = final_verts[idx1].lerp(final_verts[idx2], 0.5)
......
......@@ -120,12 +120,20 @@ def draw_indices_2D(context, args):
draw_index(*vidx)
blf.color(font_id, *edge_idx_color)
for eidx in geom.edge_data:
draw_index(*eidx)
if geom.text_data:
for text_item, (_, location) in zip(geom.text_data, geom.edge_data):
draw_index(text_item, location)
else:
for eidx in geom.edge_data:
draw_index(*eidx)
blf.color(font_id, *face_idx_color)
for fidx in geom.face_data:
draw_index(*fidx)
if geom.text_data:
for text_item, (_, location) in zip(geom.text_data, geom.face_data):
draw_index(text_item, location)
else:
for fidx in geom.face_data:
draw_index(*fidx)
# if drawing all geometry, we end early.
return
......@@ -169,7 +177,8 @@ def draw_indices_2D(context, args):
if hit:
if hit[2] == idx:
if display_face_index:
draw_index(idx, world_coordinate)
text = geom.text_data[idx] if geom.text_data else idx
draw_index(text, world_coordinate)
if display_vert_index:
for j in polygon:
......@@ -183,7 +192,8 @@ def draw_indices_2D(context, args):
blf.color(font_id, *vert_idx_color)
for idx in cache_vert_indices:
draw_index(idx, vertices[idx])
text = geom.text_data[idx] if geom.text_data else idx
draw_index(text, vertices[idx])
blf.color(font_id, *edge_idx_color)
for idx, edge in enumerate(edges):
......@@ -191,7 +201,8 @@ def draw_indices_2D(context, args):
if sorted_edge in cache_edge_indices:
idx1, idx2 = sorted_edge
loc = vertices[idx1].lerp(vertices[idx2], 0.5)
draw_index(idx, loc)
text = geom.text_data[idx] if geom.text_data else idx
draw_index(text, loc)
cache_edge_indices.remove(sorted_edge)
except Exception as err:
......@@ -308,12 +319,20 @@ def draw_indices_2D_wbg(context, args):
gather_index(vidx[0], vidx[1], 'verts')
# blf.color(font_id, *edge_idx_color)
for eidx in geom.edge_data:
gather_index(eidx[0], eidx[1], 'edges')
if geom.text_data:
for text_item, eidx in zip(geom.text_data, geom.edge_data):
gather_index(text_item, eidx[1], 'edges')
else:
for eidx in geom.edge_data:
gather_index(eidx[0], eidx[1], 'edges')
# blf.color(font_id, *face_idx_color)
for fidx in geom.face_data:
gather_index(fidx[0], fidx[1], 'faces')
if geom.text_data:
for text_item, fidx in zip(geom.text_data, geom.face_data):
gather_index(text_item, fidx[1], 'faces')
else:
for fidx in geom.face_data:
gather_index(fidx[0], fidx[1], 'faces')
draw_all_text_at_once(final_draw_data)
# if drawing all geometry, we end early.
......@@ -360,7 +379,8 @@ def draw_indices_2D_wbg(context, args):
if hit:
if hit[2] == idx:
if display_face_index:
gather_index(idx, world_coordinate, 'faces')
text = geom.text_data[idx] if geom.text_data else idx
gather_index(text, world_coordinate, 'faces')
if display_vert_index:
for j in polygon:
......@@ -374,7 +394,8 @@ def draw_indices_2D_wbg(context, args):
# blf.color(font_id, *vert_idx_color)
for idx in cache_vert_indices:
gather_index(idx, vertices[idx], 'verts')
text = geom.text_data[idx] if geom.text_data else idx
gather_index(text, vertices[idx], 'verts')
# blf.color(font_id, *edge_idx_color)
for idx, edge in enumerate(edges):
......@@ -382,7 +403,8 @@ def draw_indices_2D_wbg(context, args):
if sorted_edge in cache_edge_indices:
idx1, idx2 = sorted_edge
loc = vertices[idx1].lerp(vertices[idx2], 0.5)
gather_index(idx, loc, 'edges')
text = geom.text_data[idx] if geom.text_data else idx
gather_index(text, loc, 'edges')
cache_edge_indices.remove(sorted_edge)
draw_all_text_at_once(final_draw_data)
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать