Mesh: show attribute name collision warning in more panels

So far, only the attribute panel showed a warning when there were duplicate
attribute names. This patch adds the same warning to the vertex groups,
color attributes and uv maps panel. All of these attributes are in the same
namespace from the perspective of geometry nodes. Name collisions should
be avoided to so that ambiguities when referencing attributes don't come up.

With #112889, vertex groups can have the same name as other attributes again.
While we can handle this case somewhat gracefully in general, duplicate names
likely lead to problems down the line, so it's better if they can be avoided early.

Pull Request: https://projects.blender.org/blender/blender/pulls/112891
This commit is contained in:
Jacques Lucke 2023-09-26 15:36:40 +02:00
parent 5c5a041edd
commit 425a5a3158
1 changed files with 30 additions and 25 deletions

View File

@ -292,6 +292,8 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
draw_attribute_warnings(context, layout)
class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
bl_label = "Shape Keys"
@ -416,6 +418,8 @@ class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
col.operator("mesh.uv_texture_add", icon='ADD', text="")
col.operator("mesh.uv_texture_remove", icon='REMOVE', text="")
draw_attribute_warnings(context, layout)
class DATA_PT_remesh(MeshButtonsPanel, Panel):
bl_label = "Remesh"
@ -562,34 +566,35 @@ class DATA_PT_mesh_attributes(MeshButtonsPanel, Panel):
col.menu("MESH_MT_attribute_context_menu", icon='DOWNARROW_HLT', text="")
self.draw_attribute_warnings(context, layout)
draw_attribute_warnings(context, layout)
def draw_attribute_warnings(self, context, layout):
ob = context.object
mesh = context.mesh
unique_names = set()
colliding_names = []
for collection in (
# Built-in names.
{"crease": None},
mesh.attributes,
None if ob is None else ob.vertex_groups,
):
if collection is None:
colliding_names.append("Cannot check for object vertex groups when pinning mesh")
continue
for name in collection.keys():
unique_names_len = len(unique_names)
unique_names.add(name)
if len(unique_names) == unique_names_len:
colliding_names.append(name)
def draw_attribute_warnings(context, layout):
ob = context.object
mesh = context.mesh
if not colliding_names:
return
unique_names = set()
colliding_names = []
for collection in (
# Built-in names.
{"crease": None},
mesh.attributes,
None if ob is None else ob.vertex_groups,
):
if collection is None:
colliding_names.append("Cannot check for object vertex groups when pinning mesh")
continue
for name in collection.keys():
unique_names_len = len(unique_names)
unique_names.add(name)
if len(unique_names) == unique_names_len:
colliding_names.append(name)
layout.label(text=tip_("Name collisions: ") + ", ".join(set(colliding_names)),
icon='ERROR', translate=False)
if not colliding_names:
return
layout.label(text=tip_("Name collisions: ") + ", ".join(set(colliding_names)),
icon='ERROR', translate=False)
class ColorAttributesListBase():
@ -691,7 +696,7 @@ class DATA_PT_vertex_colors(DATA_PT_mesh_attributes, Panel):
col.menu("MESH_MT_color_attribute_context_menu", icon='DOWNARROW_HLT', text="")
self.draw_attribute_warnings(context, layout)
draw_attribute_warnings(context, layout)
classes = (