main sync #3

Merged
Patrick Busch merged 318 commits from blender/blender:main into main 2023-03-17 15:52:21 +01:00
7 changed files with 80 additions and 97 deletions
Showing only changes of commit 90076b543b - Show all commits

View File

@ -123,11 +123,9 @@ void BKE_id_attribute_copy_domains_temp(short id_type,
const char *BKE_id_attributes_active_color_name(const struct ID *id); const char *BKE_id_attributes_active_color_name(const struct ID *id);
const char *BKE_id_attributes_default_color_name(const struct ID *id); const char *BKE_id_attributes_default_color_name(const struct ID *id);
struct CustomDataLayer *BKE_id_attributes_active_color_get(const struct ID *id);
void BKE_id_attributes_active_color_set(struct ID *id, const char *name); void BKE_id_attributes_active_color_set(struct ID *id, const char *name);
struct CustomDataLayer *BKE_id_attributes_default_color_get(const struct ID *id);
void BKE_id_attributes_default_color_set(struct ID *id, const char *name); void BKE_id_attributes_default_color_set(struct ID *id, const char *name);
struct CustomDataLayer *BKE_id_attributes_color_find(const struct ID *id, const char *name); struct CustomDataLayer *BKE_id_attributes_color_find(const struct ID *id, const char *name);
bool BKE_id_attribute_calc_unique_name(struct ID *id, const char *name, char *outname); bool BKE_id_attribute_calc_unique_name(struct ID *id, const char *name, char *outname);

View File

@ -778,11 +778,6 @@ const char *BKE_id_attributes_default_color_name(const ID *id)
return nullptr; return nullptr;
} }
CustomDataLayer *BKE_id_attributes_active_color_get(const ID *id)
{
return BKE_id_attributes_color_find(id, BKE_id_attributes_active_color_name(id));
}
void BKE_id_attributes_active_color_set(ID *id, const char *name) void BKE_id_attributes_active_color_set(ID *id, const char *name)
{ {
switch (GS(id->name)) { switch (GS(id->name)) {
@ -799,11 +794,6 @@ void BKE_id_attributes_active_color_set(ID *id, const char *name)
} }
} }
CustomDataLayer *BKE_id_attributes_default_color_get(const ID *id)
{
return BKE_id_attributes_color_find(id, BKE_id_attributes_default_color_name(id));
}
void BKE_id_attributes_default_color_set(ID *id, const char *name) void BKE_id_attributes_default_color_set(ID *id, const char *name)
{ {
switch (GS(id->name)) { switch (GS(id->name)) {
@ -822,21 +812,22 @@ void BKE_id_attributes_default_color_set(ID *id, const char *name)
CustomDataLayer *BKE_id_attributes_color_find(const ID *id, const char *name) CustomDataLayer *BKE_id_attributes_color_find(const ID *id, const char *name)
{ {
if (!name) { if (CustomDataLayer *layer = BKE_id_attribute_find(id, name, CD_PROP_COLOR, ATTR_DOMAIN_POINT)) {
return nullptr;
}
CustomDataLayer *layer = BKE_id_attribute_find(id, name, CD_PROP_COLOR, ATTR_DOMAIN_POINT);
if (layer == nullptr) {
layer = BKE_id_attribute_find(id, name, CD_PROP_COLOR, ATTR_DOMAIN_CORNER);
}
if (layer == nullptr) {
layer = BKE_id_attribute_find(id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_POINT);
}
if (layer == nullptr) {
layer = BKE_id_attribute_find(id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_CORNER);
}
return layer; return layer;
}
if (CustomDataLayer *layer = BKE_id_attribute_find(
id, name, CD_PROP_COLOR, ATTR_DOMAIN_CORNER)) {
return layer;
}
if (CustomDataLayer *layer = BKE_id_attribute_find(
id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_POINT)) {
return layer;
}
if (CustomDataLayer *layer = BKE_id_attribute_find(
id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_CORNER)) {
return layer;
}
return nullptr;
} }
void BKE_id_attribute_copy_domains_temp(short id_type, void BKE_id_attribute_copy_domains_temp(short id_type,

View File

@ -591,9 +591,15 @@ static bool geometry_color_attribute_convert_poll(bContext *C)
if (GS(id->name) != ID_ME) { if (GS(id->name) != ID_ME) {
return false; return false;
} }
const Mesh *mesh = static_cast<const Mesh *>(ob->data);
CustomDataLayer *layer = BKE_id_attributes_active_color_get(id); const char *name = mesh->active_color_attribute;
if (layer == nullptr) { const bke::AttributeAccessor attributes = mesh->attributes();
const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(name);
if (!meta_data) {
return false;
}
if (!(ATTR_DOMAIN_AS_MASK(meta_data->domain) & ATTR_DOMAIN_MASK_COLOR) ||
!(CD_TYPE_AS_MASK(meta_data->data_type) & CD_MASK_COLOR_ALL)) {
return false; return false;
} }
@ -603,10 +609,10 @@ static bool geometry_color_attribute_convert_poll(bContext *C)
static int geometry_color_attribute_convert_exec(bContext *C, wmOperator *op) static int geometry_color_attribute_convert_exec(bContext *C, wmOperator *op)
{ {
Object *ob = ED_object_context(C); Object *ob = ED_object_context(C);
ID *ob_data = static_cast<ID *>(ob->data); Mesh *mesh = static_cast<Mesh *>(ob->data);
CustomDataLayer *layer = BKE_id_attributes_active_color_get(ob_data); const char *name = mesh->active_color_attribute;
ED_geometry_attribute_convert(static_cast<Mesh *>(ob->data), ED_geometry_attribute_convert(mesh,
layer->name, name,
eCustomDataType(RNA_enum_get(op->ptr, "data_type")), eCustomDataType(RNA_enum_get(op->ptr, "data_type")),
eAttrDomain(RNA_enum_get(op->ptr, "domain")), eAttrDomain(RNA_enum_get(op->ptr, "domain")),
op->reports); op->reports);
@ -619,9 +625,8 @@ static int geometry_color_attribute_convert_invoke(bContext *C,
{ {
Object *ob = ED_object_context(C); Object *ob = ED_object_context(C);
Mesh *mesh = static_cast<Mesh *>(ob->data); Mesh *mesh = static_cast<Mesh *>(ob->data);
const char *name = mesh->active_color_attribute;
const bke::AttributeMetaData meta_data = *mesh->attributes().lookup_meta_data( const bke::AttributeMetaData meta_data = *mesh->attributes().lookup_meta_data(name);
BKE_id_attributes_active_color_get(&mesh->id)->name);
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "domain"); PropertyRNA *prop = RNA_struct_find_property(op->ptr, "domain");
if (!RNA_property_is_set(op->ptr, prop)) { if (!RNA_property_is_set(op->ptr, prop)) {

View File

@ -3125,10 +3125,10 @@ static int edbm_rotate_colors_exec(bContext *C, wmOperator *op)
BMOperator bmop; BMOperator bmop;
const Mesh *me = BKE_object_get_original_mesh(ob); Mesh *me = BKE_object_get_original_mesh(ob);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id); const CustomDataLayer *layer = BKE_id_attribute_search(
&me->id, me->active_color_attribute, CD_MASK_COLOR_ALL, ATTR_DOMAIN_MASK_CORNER);
if (!layer || BKE_id_attribute_domain(&me->id, layer) != ATTR_DOMAIN_CORNER) { if (!layer) {
continue; continue;
} }
@ -3177,10 +3177,10 @@ static int edbm_reverse_colors_exec(bContext *C, wmOperator *op)
continue; continue;
} }
const Mesh *me = BKE_object_get_original_mesh(obedit); Mesh *me = BKE_object_get_original_mesh(obedit);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id); const CustomDataLayer *layer = BKE_id_attribute_search(
&me->id, me->active_color_attribute, CD_MASK_COLOR_ALL, ATTR_DOMAIN_MASK_CORNER);
if (!layer || BKE_id_attribute_domain(&me->id, layer) != ATTR_DOMAIN_CORNER) { if (!layer) {
continue; continue;
} }

View File

@ -6529,7 +6529,10 @@ static Image *proj_paint_image_create(wmOperator *op, Main *bmain, bool is_data)
return ima; return ima;
} }
static CustomDataLayer *proj_paint_color_attribute_create(wmOperator *op, Object *ob) /**
* \return The name of the new attribute.
*/
static const char *proj_paint_color_attribute_create(wmOperator *op, Object *ob)
{ {
char name[MAX_NAME] = ""; char name[MAX_NAME] = "";
float color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; float color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
@ -6543,22 +6546,20 @@ static CustomDataLayer *proj_paint_color_attribute_create(wmOperator *op, Object
type = (eCustomDataType)RNA_enum_get(op->ptr, "data_type"); type = (eCustomDataType)RNA_enum_get(op->ptr, "data_type");
} }
ID *id = (ID *)ob->data; Mesh *mesh = static_cast<Mesh *>(ob->data);
CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, op->reports); const CustomDataLayer *layer = BKE_id_attribute_new(&mesh->id, name, type, domain, op->reports);
if (!layer) { if (!layer) {
return nullptr; return nullptr;
} }
BKE_id_attributes_active_color_set(id, layer->name); BKE_id_attributes_active_color_set(&mesh->id, layer->name);
if (!mesh->default_color_attribute) {
if (!BKE_id_attributes_default_color_get(id)) { BKE_id_attributes_default_color_set(&mesh->id, layer->name);
BKE_id_attributes_default_color_set(id, layer->name);
} }
BKE_object_attributes_active_color_fill(ob, color, false); BKE_object_attributes_active_color_fill(ob, color, false);
return layer; return layer->name;
} }
/** /**
@ -6668,9 +6669,8 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
} }
case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE: { case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE: {
new_node = nodeAddStaticNode(C, ntree, SH_NODE_ATTRIBUTE); new_node = nodeAddStaticNode(C, ntree, SH_NODE_ATTRIBUTE);
if ((layer = proj_paint_color_attribute_create(op, ob))) { if (const char *name = proj_paint_color_attribute_create(op, ob)) {
BLI_strncpy_utf8( BLI_strncpy_utf8(((NodeShaderAttribute *)new_node->storage)->name, name, MAX_NAME);
((NodeShaderAttribute *)new_node->storage)->name, layer->name, MAX_NAME);
} }
break; break;
} }

View File

@ -47,7 +47,7 @@
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "BKE_attribute.h" #include "BKE_attribute.hh"
#include "BKE_ccg.h" #include "BKE_ccg.h"
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_customdata.h" #include "BKE_customdata.h"
@ -1731,20 +1731,27 @@ static bool sculpt_attribute_ref_equals(SculptAttrRef *a, SculptAttrRef *b)
static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr) static void sculpt_save_active_attribute(Object *ob, SculptAttrRef *attr)
{ {
Mesh *me = BKE_object_get_original_mesh(ob); using namespace blender;
const CustomDataLayer *layer; Mesh *mesh = BKE_object_get_original_mesh(ob);
attr->was_set = true;
if (ob && me && (layer = BKE_id_attributes_active_color_get((ID *)me))) {
attr->domain = BKE_id_attribute_domain((ID *)me, layer);
BLI_strncpy(attr->name, layer->name, sizeof(attr->name));
attr->type = layer->type;
}
else {
attr->domain = NO_ACTIVE_LAYER; attr->domain = NO_ACTIVE_LAYER;
attr->name[0] = 0; attr->name[0] = 0;
if (!mesh) {
return;
} }
const char *name = mesh->active_color_attribute;
attr->was_set = true; const bke::AttributeAccessor attributes = mesh->attributes();
const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(name);
if (!meta_data) {
return;
}
if (!(ATTR_DOMAIN_AS_MASK(meta_data->domain) & ATTR_DOMAIN_MASK_COLOR) ||
!(CD_TYPE_AS_MASK(meta_data->data_type) & CD_MASK_COLOR_ALL)) {
return;
}
attr->domain = meta_data->domain;
BLI_strncpy(attr->name, name, sizeof(attr->name));
attr->type = meta_data->data_type;
} }
void SCULPT_undo_push_begin(Object *ob, const wmOperator *op) void SCULPT_undo_push_begin(Object *ob, const wmOperator *op)

View File

@ -1175,14 +1175,8 @@ DEFINE_CUSTOMDATA_LAYER_COLLECTION(vertex_color, ldata, CD_PROP_BYTE_COLOR)
static PointerRNA rna_Mesh_vertex_color_active_get(PointerRNA *ptr) static PointerRNA rna_Mesh_vertex_color_active_get(PointerRNA *ptr)
{ {
Mesh *mesh = (Mesh *)ptr->data; Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attribute_search(
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id); &mesh->id, mesh->active_color_attribute, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_CORNER);
if (!layer || layer->type != CD_PROP_BYTE_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_CORNER) {
return PointerRNA_NULL;
}
return rna_pointer_inherit_refine(ptr, &RNA_MeshLoopColorLayer, layer); return rna_pointer_inherit_refine(ptr, &RNA_MeshLoopColorLayer, layer);
} }
@ -1203,14 +1197,11 @@ static void rna_Mesh_vertex_color_active_set(PointerRNA *ptr,
static int rna_Mesh_vertex_color_active_index_get(PointerRNA *ptr) static int rna_Mesh_vertex_color_active_index_get(PointerRNA *ptr)
{ {
Mesh *mesh = (Mesh *)ptr->data; Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attribute_search(
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id); &mesh->id, mesh->active_color_attribute, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_CORNER);
if (!layer) {
if (!layer || layer->type != CD_PROP_BYTE_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_CORNER) {
return 0; return 0;
} }
CustomData *ldata = rna_mesh_ldata(ptr); CustomData *ldata = rna_mesh_ldata(ptr);
return layer - ldata->layers + CustomData_get_layer_index(ldata, CD_PROP_BYTE_COLOR); return layer - ldata->layers + CustomData_get_layer_index(ldata, CD_PROP_BYTE_COLOR);
} }
@ -1287,14 +1278,8 @@ DEFINE_CUSTOMDATA_LAYER_COLLECTION(sculpt_vertex_color, vdata, CD_PROP_COLOR)
static PointerRNA rna_Mesh_sculpt_vertex_color_active_get(PointerRNA *ptr) static PointerRNA rna_Mesh_sculpt_vertex_color_active_get(PointerRNA *ptr)
{ {
Mesh *mesh = (Mesh *)ptr->data; Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attribute_search(
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id); &mesh->id, mesh->active_color_attribute, CD_MASK_PROP_COLOR, ATTR_DOMAIN_POINT);
if (!layer || layer->type != CD_PROP_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_POINT) {
return PointerRNA_NULL;
}
return rna_pointer_inherit_refine(ptr, &RNA_MeshVertColorLayer, layer); return rna_pointer_inherit_refine(ptr, &RNA_MeshVertColorLayer, layer);
} }
@ -1315,15 +1300,12 @@ static void rna_Mesh_sculpt_vertex_color_active_set(PointerRNA *ptr,
static int rna_Mesh_sculpt_vertex_color_active_index_get(PointerRNA *ptr) static int rna_Mesh_sculpt_vertex_color_active_index_get(PointerRNA *ptr)
{ {
Mesh *mesh = (Mesh *)ptr->data; Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attribute_search(
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id); &mesh->id, mesh->active_color_attribute, CD_MASK_PROP_COLOR, ATTR_DOMAIN_POINT);
CustomData *vdata = rna_mesh_vdata(ptr); if (!layer) {
if (!layer || layer->type != CD_PROP_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_POINT) {
return 0; return 0;
} }
CustomData *vdata = rna_mesh_vdata(ptr);
return layer - vdata->layers + CustomData_get_layer_index(vdata, CD_PROP_COLOR); return layer - vdata->layers + CustomData_get_layer_index(vdata, CD_PROP_COLOR);
} }