Fix T92318: adding layers (UVs, ...) doesn't notify about limit
When adding certain customdata layers (namely UVs, vertex colors and sculpt vertex colors), the user does not get notified the specific limit has been hit (blender just silently does nothing). Now inform the user [decided to not do this in poll() since it could get messy once operators are extended to operate on all selected objects, so left this as a visible error in execute() -- or from python]. Maniphest Tasks: T92318 Differential Revision: https://developer.blender.org/D13147
This commit is contained in:
parent
486d1e8510
commit
04b4ec7889
Notes:
blender-bot
2023-02-14 18:28:11 +01:00
Referenced by issue #98731, Vertex Paint mode can edit only 8 color attributes Referenced by issue #92318, Add Vertex Color doesn't notify user when limit has been hit Referenced by issue blender/blender-addons#93541, Blender 3.0 cannot import FBX (containing more than 8 UV layers)
|
@ -422,7 +422,8 @@ void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name);
|
|||
int ED_mesh_uv_texture_add(struct Mesh *me,
|
||||
const char *name,
|
||||
const bool active_set,
|
||||
const bool do_init);
|
||||
const bool do_init,
|
||||
struct ReportList *reports);
|
||||
bool ED_mesh_uv_texture_remove_index(struct Mesh *me, const int n);
|
||||
bool ED_mesh_uv_texture_remove_active(struct Mesh *me);
|
||||
bool ED_mesh_uv_texture_remove_named(struct Mesh *me, const char *name);
|
||||
|
@ -432,7 +433,8 @@ bool ED_mesh_color_ensure(struct Mesh *me, const char *name);
|
|||
int ED_mesh_color_add(struct Mesh *me,
|
||||
const char *name,
|
||||
const bool active_set,
|
||||
const bool do_init);
|
||||
const bool do_init,
|
||||
struct ReportList *reports);
|
||||
bool ED_mesh_color_remove_index(struct Mesh *me, const int n);
|
||||
bool ED_mesh_color_remove_active(struct Mesh *me);
|
||||
bool ED_mesh_color_remove_named(struct Mesh *me, const char *name);
|
||||
|
@ -441,7 +443,8 @@ bool ED_mesh_sculpt_color_ensure(struct Mesh *me, const char *name);
|
|||
int ED_mesh_sculpt_color_add(struct Mesh *me,
|
||||
const char *name,
|
||||
const bool active_set,
|
||||
const bool do_init);
|
||||
const bool do_init,
|
||||
struct ReportList *reports);
|
||||
bool ED_mesh_sculpt_color_remove_index(struct Mesh *me, const int n);
|
||||
bool ED_mesh_sculpt_color_remove_active(struct Mesh *me);
|
||||
bool ED_mesh_sculpt_color_remove_named(struct Mesh *me, const char *name);
|
||||
|
|
|
@ -254,7 +254,8 @@ void ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
|
|||
}
|
||||
|
||||
/* NOTE: keep in sync with #ED_mesh_color_add. */
|
||||
int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set, const bool do_init)
|
||||
int ED_mesh_uv_texture_add(
|
||||
Mesh *me, const char *name, const bool active_set, const bool do_init, ReportList *reports)
|
||||
{
|
||||
BMEditMesh *em;
|
||||
int layernum_dst;
|
||||
|
@ -266,6 +267,7 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set, co
|
|||
|
||||
layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV);
|
||||
if (layernum_dst >= MAX_MTFACE) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Cannot add more than %i UV maps", MAX_MTFACE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -285,6 +287,7 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set, co
|
|||
else {
|
||||
layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
|
||||
if (layernum_dst >= MAX_MTFACE) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Cannot add more than %i UV maps", MAX_MTFACE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -325,13 +328,13 @@ void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name)
|
|||
|
||||
layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV);
|
||||
if (layernum_dst == 0) {
|
||||
ED_mesh_uv_texture_add(me, name, true, true);
|
||||
ED_mesh_uv_texture_add(me, name, true, true, NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
|
||||
if (layernum_dst == 0) {
|
||||
ED_mesh_uv_texture_add(me, name, true, true);
|
||||
ED_mesh_uv_texture_add(me, name, true, true, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +382,8 @@ bool ED_mesh_uv_texture_remove_named(Mesh *me, const char *name)
|
|||
}
|
||||
|
||||
/* NOTE: keep in sync with #ED_mesh_uv_texture_add. */
|
||||
int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set, const bool do_init)
|
||||
int ED_mesh_color_add(
|
||||
Mesh *me, const char *name, const bool active_set, const bool do_init, ReportList *reports)
|
||||
{
|
||||
BMEditMesh *em;
|
||||
int layernum;
|
||||
|
@ -389,6 +393,7 @@ int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set, const b
|
|||
|
||||
layernum = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPCOL);
|
||||
if (layernum >= MAX_MCOL) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Cannot add more than %i vertex color layers", MAX_MCOL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -406,6 +411,7 @@ int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set, const b
|
|||
else {
|
||||
layernum = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
|
||||
if (layernum >= MAX_MCOL) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Cannot add more than %i vertex color layers", MAX_MCOL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -511,7 +517,8 @@ static bool sculpt_vertex_color_remove_poll(bContext *C)
|
|||
}
|
||||
|
||||
/* NOTE: keep in sync with #ED_mesh_uv_texture_add. */
|
||||
int ED_mesh_sculpt_color_add(Mesh *me, const char *name, const bool active_set, const bool do_init)
|
||||
int ED_mesh_sculpt_color_add(
|
||||
Mesh *me, const char *name, const bool active_set, const bool do_init, ReportList *reports)
|
||||
{
|
||||
BMEditMesh *em;
|
||||
int layernum;
|
||||
|
@ -521,6 +528,8 @@ int ED_mesh_sculpt_color_add(Mesh *me, const char *name, const bool active_set,
|
|||
|
||||
layernum = CustomData_number_of_layers(&em->bm->vdata, CD_PROP_COLOR);
|
||||
if (layernum >= MAX_MCOL) {
|
||||
BKE_reportf(
|
||||
reports, RPT_ERROR, "Cannot add more than %i sculpt vertex color layers", MAX_MCOL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -538,6 +547,8 @@ int ED_mesh_sculpt_color_add(Mesh *me, const char *name, const bool active_set,
|
|||
else {
|
||||
layernum = CustomData_number_of_layers(&me->vdata, CD_PROP_COLOR);
|
||||
if (layernum >= MAX_MCOL) {
|
||||
BKE_reportf(
|
||||
reports, RPT_ERROR, "Cannot add more than %i sculpt vertex color layers", MAX_MCOL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -634,12 +645,12 @@ static bool uv_texture_remove_poll(bContext *C)
|
|||
return false;
|
||||
}
|
||||
|
||||
static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
static int mesh_uv_texture_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob = ED_object_context(C);
|
||||
Mesh *me = ob->data;
|
||||
|
||||
if (ED_mesh_uv_texture_add(me, NULL, true, true) == -1) {
|
||||
if (ED_mesh_uv_texture_add(me, NULL, true, true, op->reports) == -1) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
|
@ -719,12 +730,12 @@ static bool vertex_color_remove_poll(bContext *C)
|
|||
return false;
|
||||
}
|
||||
|
||||
static int mesh_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
static int mesh_vertex_color_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob = ED_object_context(C);
|
||||
Mesh *me = ob->data;
|
||||
|
||||
if (ED_mesh_color_add(me, NULL, true, true) == -1) {
|
||||
if (ED_mesh_color_add(me, NULL, true, true, op->reports) == -1) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
|
@ -775,12 +786,12 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot)
|
|||
|
||||
/*********************** Sculpt Vertex Color Operators ************************/
|
||||
|
||||
static int mesh_sculpt_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
static int mesh_sculpt_vertex_color_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Object *ob = ED_object_context(C);
|
||||
Mesh *me = ob->data;
|
||||
|
||||
if (ED_mesh_sculpt_color_add(me, NULL, true, true) == -1) {
|
||||
if (ED_mesh_sculpt_color_add(me, NULL, true, true, op->reports) == -1) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
|
|
|
@ -246,7 +246,7 @@ static int output_toggle_exec(bContext *C, wmOperator *op)
|
|||
/* Vertex Color Layer */
|
||||
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
||||
if (!exists) {
|
||||
ED_mesh_color_add(ob->data, name, true, true);
|
||||
ED_mesh_color_add(ob->data, name, true, true, op->reports);
|
||||
}
|
||||
else {
|
||||
ED_mesh_color_remove_named(ob->data, name);
|
||||
|
|
|
@ -118,7 +118,7 @@ static bool ED_uvedit_ensure_uvs(Object *obedit)
|
|||
int cd_loop_uv_offset;
|
||||
|
||||
if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV)) {
|
||||
ED_mesh_uv_texture_add(obedit->data, NULL, true, true);
|
||||
ED_mesh_uv_texture_add(obedit->data, NULL, true, true, NULL);
|
||||
}
|
||||
|
||||
/* Happens when there are no faces. */
|
||||
|
|
|
@ -1507,12 +1507,15 @@ static int rna_Mesh_tot_face_get(PointerRNA *ptr)
|
|||
return me->edit_mesh ? me->edit_mesh->bm->totfacesel : 0;
|
||||
}
|
||||
|
||||
static PointerRNA rna_Mesh_vertex_color_new(struct Mesh *me, const char *name, const bool do_init)
|
||||
static PointerRNA rna_Mesh_vertex_color_new(struct Mesh *me,
|
||||
ReportList *reports,
|
||||
const char *name,
|
||||
const bool do_init)
|
||||
{
|
||||
PointerRNA ptr;
|
||||
CustomData *ldata;
|
||||
CustomDataLayer *cdl = NULL;
|
||||
int index = ED_mesh_color_add(me, name, false, do_init);
|
||||
int index = ED_mesh_color_add(me, name, false, do_init, reports);
|
||||
|
||||
if (index != -1) {
|
||||
ldata = rna_mesh_ldata_helper(me);
|
||||
|
@ -1533,13 +1536,14 @@ static void rna_Mesh_vertex_color_remove(struct Mesh *me,
|
|||
}
|
||||
|
||||
static PointerRNA rna_Mesh_sculpt_vertex_color_new(struct Mesh *me,
|
||||
ReportList *reports,
|
||||
const char *name,
|
||||
const bool do_init)
|
||||
{
|
||||
PointerRNA ptr;
|
||||
CustomData *vdata;
|
||||
CustomDataLayer *cdl = NULL;
|
||||
int index = ED_mesh_sculpt_color_add(me, name, false, do_init);
|
||||
int index = ED_mesh_sculpt_color_add(me, name, false, do_init, reports);
|
||||
|
||||
if (index != -1) {
|
||||
vdata = rna_mesh_vdata_helper(me);
|
||||
|
@ -1591,12 +1595,15 @@ DEFINE_CUSTOMDATA_PROPERTY_API(
|
|||
polygon, string, CD_PROP_STRING, pdata, totpoly, MeshPolygonStringPropertyLayer)
|
||||
# undef DEFINE_CUSTOMDATA_PROPERTY_API
|
||||
|
||||
static PointerRNA rna_Mesh_uv_layers_new(struct Mesh *me, const char *name, const bool do_init)
|
||||
static PointerRNA rna_Mesh_uv_layers_new(struct Mesh *me,
|
||||
ReportList *reports,
|
||||
const char *name,
|
||||
const bool do_init)
|
||||
{
|
||||
PointerRNA ptr;
|
||||
CustomData *ldata;
|
||||
CustomDataLayer *cdl = NULL;
|
||||
int index = ED_mesh_uv_texture_add(me, name, false, do_init);
|
||||
int index = ED_mesh_uv_texture_add(me, name, false, do_init, reports);
|
||||
|
||||
if (index != -1) {
|
||||
ldata = rna_mesh_ldata_helper(me);
|
||||
|
@ -2520,6 +2527,7 @@ static void rna_def_loop_colors(BlenderRNA *brna, PropertyRNA *cprop)
|
|||
|
||||
func = RNA_def_function(srna, "new", "rna_Mesh_vertex_color_new");
|
||||
RNA_def_function_ui_description(func, "Add a vertex color layer to Mesh");
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
RNA_def_string(func, "name", "Col", 0, "", "Vertex color name");
|
||||
RNA_def_boolean(func,
|
||||
"do_init",
|
||||
|
@ -2569,6 +2577,7 @@ static void rna_def_vert_colors(BlenderRNA *brna, PropertyRNA *cprop)
|
|||
|
||||
func = RNA_def_function(srna, "new", "rna_Mesh_sculpt_vertex_color_new");
|
||||
RNA_def_function_ui_description(func, "Add a sculpt vertex color layer to Mesh");
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
RNA_def_string(func, "name", "Col", 0, "", "Sculpt Vertex color name");
|
||||
RNA_def_boolean(func,
|
||||
"do_init",
|
||||
|
@ -2622,6 +2631,7 @@ static void rna_def_uv_layers(BlenderRNA *brna, PropertyRNA *cprop)
|
|||
RNA_def_struct_ui_text(srna, "UV Loop Layers", "Collection of uv loop layers");
|
||||
|
||||
func = RNA_def_function(srna, "new", "rna_Mesh_uv_layers_new");
|
||||
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||
RNA_def_function_ui_description(func, "Add a UV map layer to Mesh");
|
||||
RNA_def_string(func, "name", "UVMap", 0, "", "UV map name");
|
||||
RNA_def_boolean(func,
|
||||
|
|
Loading…
Reference in New Issue