[Bf-blender-cvs] [3c4b9a4bfb4] temp-sculpt-colors: temp-sculpt-colors: Vertex color list now has active reference
Joseph Eagar
noreply at git.blender.org
Wed Nov 17 11:36:49 CET 2021
Commit: 3c4b9a4bfb4edc8c4c948786e4edb189e0af8ad2
Author: Joseph Eagar
Date: Wed Nov 17 01:28:21 2021 -0800
Branches: temp-sculpt-colors
https://developer.blender.org/rB3c4b9a4bfb4edc8c4c948786e4edb189e0af8ad2
temp-sculpt-colors: Vertex color list now has active reference
===================================================================
M release/scripts/startup/bl_ui/properties_data_mesh.py
M source/blender/blenkernel/BKE_attribute.h
M source/blender/blenkernel/intern/attribute.c
M source/blender/blenkernel/intern/fluid.c
M source/blender/blenkernel/intern/mesh.cc
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenloader/intern/versioning_300.c
M source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc
M source/blender/editors/geometry/geometry_attributes.c
M source/blender/editors/geometry/geometry_intern.h
M source/blender/editors/geometry/geometry_ops.c
M source/blender/io/alembic/intern/abc_reader_mesh.cc
M source/blender/makesdna/DNA_mesh_types.h
M source/blender/makesrna/intern/rna_attribute.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index fbff93dadd4..8a9f79b795d 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -433,6 +433,48 @@ 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="")
+class MESH_UL_color_attributes(UIList):
+ display_domain_names = {
+ 'POINT': "Vertex",
+ 'EDGE': "Edge",
+ 'FACE': "Face",
+ 'CORNER': "Face Corner",
+ }
+
+ def filter_items(self, context, data, property):
+ attrs = getattr(data, property)
+ ret = []
+ idxs = []
+ idx = 0
+
+ for item in attrs:
+ bad = item.domain not in ["POINT", "CORNER"]
+ bad = bad or item.data_type not in ["FLOAT_COLOR", "BYTE_COLOR"]
+ bad = bad or item.temporary
+
+ ret.append(self.bitflag_filter_item if not bad else 0)
+ idxs.append(idx)
+
+ # note this is index in full attribute list, not color list
+ idx += 1
+
+ return ret, idxs
+
+ def draw_item(self, _context, layout, _data, attribute, _icon, _active_data, _active_propname, _index):
+ data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type]
+
+ domain_name = self.display_domain_names.get(attribute.domain, "")
+
+ split = layout.split(factor=0.50)
+ split.emboss = 'NONE'
+ split.prop(attribute, "name", text="")
+
+ split.prop(attribute, "active_render", text="", icon = 'RESTRICT_RENDER_OFF' if attribute.active_render else 'RESTRICT_RENDER_ON')
+
+ sub = split.row()
+ sub.alignment = 'RIGHT'
+ sub.active = False
+ sub.label(text="%s ▶ %s" % (domain_name, data_type.name))
class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
bl_label = "Vertex Colors"
@@ -440,18 +482,60 @@ class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
def draw(self, context):
- layout = self.layout
-
- me = context.mesh
+ mesh = context.mesh
+ layout = self.layout
row = layout.row()
- col = row.column()
- col.template_list("MESH_UL_vcols", "vcols", me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
+ col = row.column()
+ col.template_list("MESH_UL_color_attributes",
+ "attributes",
+ mesh,
+ "attributes",
+ mesh.attributes,
+ "active_color_index",
+ rows=3,)
col = row.column(align=True)
- col.operator("mesh.vertex_color_add", icon='ADD', text="")
- col.operator("mesh.vertex_color_remove", icon='REMOVE', text="")
+ col.operator("geometry.color_attribute_add", icon='ADD', text="")
+ col.operator("geometry.color_attribute_remove", icon='REMOVE', text="")
+
+ active = mesh.attributes.active
+
+ if active and (active.domain == "POINT" and active.data_type == "FLOAT_COLOR"):
+ layout.operator("sculpt.vertex_to_loop_colors", text="Save To Corners")
+ layout.operator("sculpt.loop_to_vertex_colors", text="Load From Corners")
+
+ self.draw_attribute_warnings(context, layout)
+
+ def draw_attribute_warnings(self, context, layout):
+ attributes_by_name = defaultdict(list)
+
+ ob = context.object
+ mesh = ob.data
+
+ builtin_attribute = object()
+
+ def add_builtin(name):
+ attributes_by_name[name].append(builtin_attribute)
+
+ def add_attributes(layers):
+ for layer in layers:
+ attributes_by_name[layer.name].append(layer)
+
+ add_builtin("position")
+ add_builtin("material_index")
+ add_builtin("shade_smooth")
+ add_builtin("normal")
+ add_builtin("crease")
+
+ add_attributes(mesh.attributes)
+
+ colliding_names = [name for name, layers in attributes_by_name.items() if len(layers) >= 2]
+ if len(colliding_names) == 0:
+ return
+
+ layout.label(text="Name collisions: {}".format(", ".join(colliding_names)), icon='ERROR')
class DATA_PT_remesh(MeshButtonsPanel, Panel):
bl_label = "Remesh"
@@ -527,6 +611,20 @@ class MESH_UL_attributes(UIList):
'CORNER': "Face Corner",
}
+ def filter_items(self, context, data, property):
+ attrs = getattr(data, property)
+ ret = []
+ idxs = []
+ idx = 0
+
+ for item in attrs:
+ ret.append(self.bitflag_filter_item if not item.temporary else 0)
+ idxs.append(idx)
+
+ idx += 1
+
+ return ret, idxs
+
def draw_item(self, _context, layout, _data, attribute, _icon, _active_data, _active_propname, _index):
data_type = attribute.bl_rna.properties['data_type'].enum_items[attribute.data_type]
@@ -624,7 +722,8 @@ classes = (MESH_MT_vertex_group_context_menu,
DATA_PT_texture_space,
DATA_PT_remesh,
DATA_PT_customdata,
- DATA_PT_custom_props_mesh,)
+ DATA_PT_custom_props_mesh,
+ MESH_UL_color_attributes,)
if __name__ == "__main__": # only for live edit.
from bpy.utils import register_class
diff --git a/source/blender/blenkernel/BKE_attribute.h b/source/blender/blenkernel/BKE_attribute.h
index 7476474258b..f3614e31313 100644
--- a/source/blender/blenkernel/BKE_attribute.h
+++ b/source/blender/blenkernel/BKE_attribute.h
@@ -53,14 +53,26 @@ typedef enum AttributeDomain {
ATTR_DOMAIN_NUM
} AttributeDomain;
+typedef enum {
+ ATTR_DOMAIN_MASK_POINT = (1 << 0),
+ ATTR_DOMAIN_MASK_EDGE = (1 << 1),
+ ATTR_DOMAIN_MASK_FACE = (1 << 2),
+ ATTR_DOMAIN_MASK_CORNER = (1 << 3),
+ ATTR_DOMAIN_MASK_CURVE = (1 << 4),
+ ATTR_DOMAIN_MASK_ALL = (1 << 5) - 1
+} AttributeDomainMask;
+
/* Attributes */
bool BKE_id_attributes_supported(struct ID *id);
+/* list_mask restricts unique name check to certain customdata types,
+ if in doubt just pass CD_MASK_PROP_ALL */
struct CustomDataLayer *BKE_id_attribute_new(struct ID *id,
const char *name,
const int type,
const AttributeDomain domain,
+ const CustomDataMask list_mask,
struct ReportList *reports);
bool BKE_id_attribute_remove(struct ID *id,
struct CustomDataLayer *layer,
@@ -79,13 +91,42 @@ bool BKE_id_attribute_rename(struct ID *id,
const char *new_name,
struct ReportList *reports);
-int BKE_id_attributes_length(struct ID *id, const CustomDataMask mask);
+int BKE_id_attributes_length(const struct ID *id,
+ const AttributeDomainMask domain_mask,
+ const CustomDataMask mask);
struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id);
void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer);
int *BKE_id_attributes_active_index_p(struct ID *id);
CustomData *BKE_id_attributes_iterator_next_domain(struct ID *id, struct CustomDataLayer *layers);
+CustomDataLayer *BKE_id_attribute_from_index(const struct ID *id,
+ int lookup_index,
+ const AttributeDomainMask domain_mask);
+
+struct AttributeRef *BKE_id_attributes_active_color_ref_p(struct ID *id);
+void BKE_id_attributes_active_color_set(struct ID *id, struct CustomDataLayer *active_layer);
+struct CustomDataLayer *BKE_id_attributes_active_color_get(struct ID *id);
+
+struct AttributeRef *BKE_id_attributes_render_color_ref_p(struct ID *id);
+void BKE_id_attributes_render_color_set(struct ID *id, struct CustomDataLayer *active_layer);
+CustomDataLayer *BKE_id_attributes_render_color_get(struct ID *id);
+
+bool BKE_id_attribute_find_unique_name(struct ID *id,
+ const char *name,
+ char *outname,
+ CustomDataMask mask);
+
+int BKE_id_attribute_index_from_ref(struct ID *id,
+ struct AttributeRef *ref,
+ AttributeDomainMask domain_mask,
+ CustomDataMask type_filter);
+
+bool BKE_id_attribute_ref_from_index(struct ID *id,
+ int attr_index,
+ AttributeDomainMask domain_mask,
+ CustomDataMask type_filter,
+ struct AttributeRef *r_ref);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index ee8ef5e97f7..e4b4728a747 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -36,6 +36,7 @@
#include "DNA_pointcloud_types.h"
#include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
#include "BKE_attribute.h"
#include "BKE_customdata.h"
@@ -149,8 +150,55 @@ bool BKE_id_attribute_rename(ID *id,
return true;
}
-CustomDataLayer *BKE_id_attribute_new(
- ID *id, const char *name, const int type, const AttributeDomain domain, ReportList *reports)
+
+typedef struct AttrUniqueData {
+ ID *id;
+ CustomDataMask mask;
+} AttrUniqueData;
+
+static bool unique_name_cb(void *arg, const char *name)
+{
+ AttrUniqueData *data = (AttrUniqueData *)arg;
+
+ DomainInfo info[ATTR_DOMAIN_NUM];
+ get_domains(data->id, info);
+
+ for (AttributeDomain domain = ATTR_DOMAIN_POINT; domain < ATTR_DOMAIN_NUM; domain++) {
+ if (!info[domain].customdata) {
+ continue;
+ }
+
+ CustomData *cdata = info[domain].customdata;
+ for (int i = 0; i < cdata->totlayer; i++) {
+ CustomDataLayer *layer = cdata->laye
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list