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_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);
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);
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);

View File

@ -778,11 +778,6 @@ const char *BKE_id_attributes_default_color_name(const ID *id)
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)
{
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)
{
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)
{
if (!name) {
return nullptr;
if (CustomDataLayer *layer = BKE_id_attribute_find(id, name, CD_PROP_COLOR, ATTR_DOMAIN_POINT)) {
return layer;
}
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 (CustomDataLayer *layer = BKE_id_attribute_find(
id, name, CD_PROP_COLOR, ATTR_DOMAIN_CORNER)) {
return layer;
}
if (layer == nullptr) {
layer = BKE_id_attribute_find(id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_POINT);
if (CustomDataLayer *layer = BKE_id_attribute_find(
id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_POINT)) {
return layer;
}
if (layer == nullptr) {
layer = BKE_id_attribute_find(id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_CORNER);
if (CustomDataLayer *layer = BKE_id_attribute_find(
id, name, CD_PROP_BYTE_COLOR, ATTR_DOMAIN_CORNER)) {
return layer;
}
return layer;
return nullptr;
}
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) {
return false;
}
CustomDataLayer *layer = BKE_id_attributes_active_color_get(id);
if (layer == nullptr) {
const Mesh *mesh = static_cast<const Mesh *>(ob->data);
const char *name = mesh->active_color_attribute;
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;
}
@ -603,10 +609,10 @@ static bool geometry_color_attribute_convert_poll(bContext *C)
static int geometry_color_attribute_convert_exec(bContext *C, wmOperator *op)
{
Object *ob = ED_object_context(C);
ID *ob_data = static_cast<ID *>(ob->data);
CustomDataLayer *layer = BKE_id_attributes_active_color_get(ob_data);
ED_geometry_attribute_convert(static_cast<Mesh *>(ob->data),
layer->name,
Mesh *mesh = static_cast<Mesh *>(ob->data);
const char *name = mesh->active_color_attribute;
ED_geometry_attribute_convert(mesh,
name,
eCustomDataType(RNA_enum_get(op->ptr, "data_type")),
eAttrDomain(RNA_enum_get(op->ptr, "domain")),
op->reports);
@ -619,9 +625,8 @@ static int geometry_color_attribute_convert_invoke(bContext *C,
{
Object *ob = ED_object_context(C);
Mesh *mesh = static_cast<Mesh *>(ob->data);
const bke::AttributeMetaData meta_data = *mesh->attributes().lookup_meta_data(
BKE_id_attributes_active_color_get(&mesh->id)->name);
const char *name = mesh->active_color_attribute;
const bke::AttributeMetaData meta_data = *mesh->attributes().lookup_meta_data(name);
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "domain");
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;
const Mesh *me = BKE_object_get_original_mesh(ob);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
if (!layer || BKE_id_attribute_domain(&me->id, layer) != ATTR_DOMAIN_CORNER) {
Mesh *me = BKE_object_get_original_mesh(ob);
const CustomDataLayer *layer = BKE_id_attribute_search(
&me->id, me->active_color_attribute, CD_MASK_COLOR_ALL, ATTR_DOMAIN_MASK_CORNER);
if (!layer) {
continue;
}
@ -3177,10 +3177,10 @@ static int edbm_reverse_colors_exec(bContext *C, wmOperator *op)
continue;
}
const Mesh *me = BKE_object_get_original_mesh(obedit);
const CustomDataLayer *layer = BKE_id_attributes_active_color_get(&me->id);
if (!layer || BKE_id_attribute_domain(&me->id, layer) != ATTR_DOMAIN_CORNER) {
Mesh *me = BKE_object_get_original_mesh(obedit);
const CustomDataLayer *layer = BKE_id_attribute_search(
&me->id, me->active_color_attribute, CD_MASK_COLOR_ALL, ATTR_DOMAIN_MASK_CORNER);
if (!layer) {
continue;
}

View File

@ -6529,7 +6529,10 @@ static Image *proj_paint_image_create(wmOperator *op, Main *bmain, bool is_data)
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] = "";
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");
}
ID *id = (ID *)ob->data;
CustomDataLayer *layer = BKE_id_attribute_new(id, name, type, domain, op->reports);
Mesh *mesh = static_cast<Mesh *>(ob->data);
const CustomDataLayer *layer = BKE_id_attribute_new(&mesh->id, name, type, domain, op->reports);
if (!layer) {
return nullptr;
}
BKE_id_attributes_active_color_set(id, layer->name);
if (!BKE_id_attributes_default_color_get(id)) {
BKE_id_attributes_default_color_set(id, layer->name);
BKE_id_attributes_active_color_set(&mesh->id, layer->name);
if (!mesh->default_color_attribute) {
BKE_id_attributes_default_color_set(&mesh->id, layer->name);
}
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: {
new_node = nodeAddStaticNode(C, ntree, SH_NODE_ATTRIBUTE);
if ((layer = proj_paint_color_attribute_create(op, ob))) {
BLI_strncpy_utf8(
((NodeShaderAttribute *)new_node->storage)->name, layer->name, MAX_NAME);
if (const char *name = proj_paint_color_attribute_create(op, ob)) {
BLI_strncpy_utf8(((NodeShaderAttribute *)new_node->storage)->name, name, MAX_NAME);
}
break;
}

View File

@ -47,7 +47,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "BKE_attribute.h"
#include "BKE_attribute.hh"
#include "BKE_ccg.h"
#include "BKE_context.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)
{
Mesh *me = BKE_object_get_original_mesh(ob);
const CustomDataLayer *layer;
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->name[0] = 0;
}
using namespace blender;
Mesh *mesh = BKE_object_get_original_mesh(ob);
attr->was_set = true;
attr->domain = NO_ACTIVE_LAYER;
attr->name[0] = 0;
if (!mesh) {
return;
}
const char *name = mesh->active_color_attribute;
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)

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)
{
Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id);
if (!layer || layer->type != CD_PROP_BYTE_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_CORNER) {
return PointerRNA_NULL;
}
CustomDataLayer *layer = BKE_id_attribute_search(
&mesh->id, mesh->active_color_attribute, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_CORNER);
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)
{
Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id);
if (!layer || layer->type != CD_PROP_BYTE_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_CORNER) {
CustomDataLayer *layer = BKE_id_attribute_search(
&mesh->id, mesh->active_color_attribute, CD_MASK_PROP_BYTE_COLOR, ATTR_DOMAIN_MASK_CORNER);
if (!layer) {
return 0;
}
CustomData *ldata = rna_mesh_ldata(ptr);
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)
{
Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id);
if (!layer || layer->type != CD_PROP_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_POINT) {
return PointerRNA_NULL;
}
CustomDataLayer *layer = BKE_id_attribute_search(
&mesh->id, mesh->active_color_attribute, CD_MASK_PROP_COLOR, ATTR_DOMAIN_POINT);
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)
{
Mesh *mesh = (Mesh *)ptr->data;
CustomDataLayer *layer = BKE_id_attributes_active_color_get(&mesh->id);
CustomData *vdata = rna_mesh_vdata(ptr);
if (!layer || layer->type != CD_PROP_COLOR ||
BKE_id_attribute_domain(&mesh->id, layer) != ATTR_DOMAIN_POINT) {
CustomDataLayer *layer = BKE_id_attribute_search(
&mesh->id, mesh->active_color_attribute, CD_MASK_PROP_COLOR, ATTR_DOMAIN_POINT);
if (!layer) {
return 0;
}
CustomData *vdata = rna_mesh_vdata(ptr);
return layer - vdata->layers + CustomData_get_layer_index(vdata, CD_PROP_COLOR);
}