python api: add functionality to remove vertex color layers.

note: that this intentionally removes check to exit vpaint mode when a vertex color layer is removed,
	  since being in vertex-paint mode without a vertex color layer is supported.

also minor change to drawing camera limits while picking from previous commit.
This commit is contained in:
2013-03-21 20:15:39 +00:00
parent 21c55d5304
commit fa1cd9ce9b
8 changed files with 59 additions and 43 deletions

View File

@@ -259,6 +259,7 @@ int CustomData_get_active_layer_index(const struct CustomData *data, int type);
int CustomData_get_render_layer_index(const struct CustomData *data, int type);
int CustomData_get_clone_layer_index(const struct CustomData *data, int type);
int CustomData_get_stencil_layer_index(const struct CustomData *data, int type);
int CustomData_get_named_layer(const struct CustomData *data, int type, const char *name);
int CustomData_get_active_layer(const struct CustomData *data, int type);
int CustomData_get_render_layer(const struct CustomData *data, int type);
int CustomData_get_clone_layer(const struct CustomData *data, int type);

View File

@@ -1458,6 +1458,14 @@ int CustomData_get_stencil_layer_index(const CustomData *data, int type)
/* -------------------------------------------------------------------- */
/* index values per layer type */
int CustomData_get_named_layer(const struct CustomData *data, int type, const char *name)
{
const int named_index = CustomData_get_named_layer_index(data, type, name);
const int layer_index = data->typemap[type];
BLI_assert(customdata_typemap_is_valid(data));
return (named_index != -1) ? named_index - layer_index : -1;
}
int CustomData_get_active_layer(const CustomData *data, int type)
{
const int layer_index = data->typemap[type];

View File

@@ -259,8 +259,9 @@ int ED_mesh_uv_texture_remove(struct bContext *C, struct Object *ob, struct Mesh
int ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me);
int ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum);
int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob, struct Mesh *me, const char *name, int active_set);
int ED_mesh_color_remove(struct bContext *C, struct Object *ob, struct Mesh *me);
int ED_mesh_color_remove_named(struct bContext *C, struct Object *ob, struct Mesh *me, const char *name);
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);
/* mesh backup */
typedef struct BMBackup {

View File

@@ -123,9 +123,8 @@ static CustomData *mesh_customdata_get_type(Mesh *me, const char htype, int *r_t
}
#define GET_CD_DATA(me, data) (me->edit_btmesh ? &me->edit_btmesh->bm->data : &me->data)
static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *layer)
static void delete_customdata_layer(Mesh *me, CustomDataLayer *layer)
{
Mesh *me = ob->data;
CustomData *data;
void *actlayerdata, *rndlayerdata, *clonelayerdata, *stencillayerdata, *layerdata = layer->data;
int type = layer->type;
@@ -162,9 +161,6 @@ static void delete_customdata_layer(bContext *C, Object *ob, CustomDataLayer *la
BKE_mesh_update_customdata_pointers(me, true);
}
if (!CustomData_has_layer(data, type) && (type == CD_MLOOPCOL && (ob->mode & OB_MODE_VERTEX_PAINT)))
ED_object_toggle_modes(C, OB_MODE_VERTEX_PAINT);
/* reconstruct active layer */
if (actlayerdata != layerdata) {
/* find index */
@@ -435,8 +431,8 @@ int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me)
if (!cdlp || !cdlu)
return 0;
delete_customdata_layer(C, ob, cdlp);
delete_customdata_layer(C, ob, cdlu);
delete_customdata_layer(ob->data, cdlp);
delete_customdata_layer(ob->data, cdlu);
DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
@@ -498,42 +494,46 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes
return layernum;
}
int ED_mesh_color_remove(bContext *C, Object *ob, Mesh *me)
bool ED_mesh_color_remove_index(Mesh *me, const int n)
{
CustomData *ldata = GET_CD_DATA(me, ldata);
CustomDataLayer *cdl;
int index;
index = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL);
index = CustomData_get_layer_index_n(ldata, CD_MLOOPCOL, n);
cdl = (index == -1) ? NULL : &ldata->layers[index];
if (!cdl)
return 0;
return false;
delete_customdata_layer(C, ob, cdl);
delete_customdata_layer(me, cdl);
DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
WM_main_add_notifier(NC_GEOM | ND_DATA, me);
return 1;
return true;
}
bool ED_mesh_color_remove_active(Mesh *me)
{
CustomData *ldata = GET_CD_DATA(me, ldata);
const int n = CustomData_get_active_layer(ldata, CD_MLOOPCOL);
if (n != -1) {
return ED_mesh_color_remove_index(me, n);
}
else {
return false;
}
}
int ED_mesh_color_remove_named(bContext *C, Object *ob, Mesh *me, const char *name)
bool ED_mesh_color_remove_named(Mesh *me, const char *name)
{
CustomData *ldata = GET_CD_DATA(me, ldata);
CustomDataLayer *cdl;
int index;
index = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, name);
cdl = (index == -1) ? NULL : &ldata->layers[index];
if (!cdl)
return 0;
delete_customdata_layer(C, ob, cdl);
DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return 1;
const int n = CustomData_get_named_layer(ldata, CD_MLOOPCOL, name);
if (n != -1) {
return ED_mesh_color_remove_index(me, n);
}
else {
return false;
}
}
/*********************** UV texture operators ************************/
@@ -725,7 +725,7 @@ static int mesh_vertex_color_remove_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = ED_object_context(C);
Mesh *me = ob->data;
if (!ED_mesh_color_remove(C, ob, me))
if (!ED_mesh_color_remove_active(me))
return OPERATOR_CANCELLED;
return OPERATOR_FINISHED;

View File

@@ -225,7 +225,7 @@ static int output_toggle_exec(bContext *C, wmOperator *op)
if (!exists)
ED_mesh_color_add(C, scene, ob, ob->data, name, 1);
else
ED_mesh_color_remove_named(C, ob, ob->data, name);
ED_mesh_color_remove_named(ob->data, name);
}
/* Vertex Weight Layer */
else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {

View File

@@ -1416,15 +1416,15 @@ static void draw_limit_line(float sta, float end, const short dflag, unsigned in
glVertex3f(0.0, 0.0, -end);
glEnd();
glPointSize(3.0);
glBegin(GL_POINTS);
if (!(dflag & (DRAW_PICKING | DRAW_CONSTCOLOR | DRAW_SCENESET))) {
if (!(dflag & DRAW_PICKING)) {
glPointSize(3.0);
glBegin(GL_POINTS);
cpack(col);
glVertex3f(0.0, 0.0, -sta);
glVertex3f(0.0, 0.0, -end);
glEnd();
glPointSize(1.0);
}
glVertex3f(0.0, 0.0, -sta);
glVertex3f(0.0, 0.0, -end);
glEnd();
glPointSize(1.0);
}

View File

@@ -1284,6 +1284,13 @@ static PointerRNA rna_Mesh_vertex_color_new(struct Mesh *me, struct bContext *C,
return ptr;
}
static void rna_Mesh_vertex_color_remove(struct Mesh *me, ReportList *reports, CustomDataLayer *layer)
{
if (ED_mesh_color_remove_named(me, layer->name) == false) {
BKE_reportf(reports, RPT_ERROR, "vertex color '%s' not found", layer->name);
}
}
static PointerRNA rna_Mesh_tessface_vertex_color_new(struct Mesh *me, struct bContext *C, ReportList *reports,
const char *name)
{
@@ -2408,14 +2415,12 @@ static void rna_def_loop_colors(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_flag(parm, PROP_RNAPTR);
RNA_def_function_return(func, parm);
#if 0
func = RNA_def_function(srna, "remove", "rna_Mesh_vertex_color_remove");
RNA_def_function_ui_description(func, "Remove a vertex color layer");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
parm = RNA_def_pointer(func, "layer", "Layer", "", "The layer to remove");
RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
parm = RNA_def_pointer(func, "layer", "MeshLoopColorLayer", "", "The layer to remove");
RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
#endif
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "MeshLoopColorLayer");

View File

@@ -372,6 +372,7 @@ void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int cou
void ED_mesh_material_link(struct Mesh *mesh, struct Material *ma) {}
int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob, struct Mesh *me) {return 0;}
int ED_mesh_uv_texture_add(struct bContext *C, struct Mesh *me) {return 0;}
bool ED_mesh_color_remove_named(struct Mesh *me, const char *name) { return false; }
void ED_object_constraint_dependency_update(struct Scene *scene, struct Object *ob) {}
void ED_object_constraint_update(struct Object *ob) {}
struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, char *name) {return (struct bDeformGroup *) NULL;}