diff options
Diffstat (limited to 'source/blender/editors/mesh/mesh_data.c')
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 153 |
1 files changed, 91 insertions, 62 deletions
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 68e93fa22f7..20633aa0c87 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -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 */ @@ -344,12 +340,12 @@ int 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(bContext *C, Mesh *me, const char *name, int active_set) +int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set) { BMEditMesh *em; int layernum_dst; - short is_init = FALSE; + bool is_init = false; if (me->edit_btmesh) { em = me->edit_btmesh; @@ -376,7 +372,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s const int layernum_src = CustomData_get_active_layer(&em->bm->ldata, CD_MLOOPUV); BM_data_layer_copy(em->bm, &em->bm->ldata, CD_MLOOPUV, layernum_src, layernum_dst); - is_init = TRUE; + is_init = true; } if (active_set || layernum_dst == 0) { CustomData_set_layer_active(&em->bm->ldata, CD_MLOOPUV, layernum_dst); @@ -391,7 +387,7 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DUPLICATE, me->mtpoly, me->totpoly, name); CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DUPLICATE, me->mloopuv, me->totloop, name); CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface, name); - is_init = TRUE; + is_init = true; } else { CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, name); @@ -410,42 +406,73 @@ int ED_mesh_uv_texture_add(bContext *C, Mesh *me, const char *name, int active_s } /* don't overwrite our copied coords */ - if (is_init == FALSE) { + if (is_init == false) { ED_mesh_uv_loop_reset_ex(me, layernum_dst); } 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 layernum_dst; } -int ED_mesh_uv_texture_remove(bContext *C, Object *ob, Mesh *me) +bool ED_mesh_uv_texture_remove_index(Mesh *me, const int n) { CustomData *pdata = GET_CD_DATA(me, pdata), *ldata = GET_CD_DATA(me, ldata); CustomDataLayer *cdlp, *cdlu; int index; - index = CustomData_get_active_layer_index(pdata, CD_MTEXPOLY); + index = CustomData_get_layer_index_n(pdata, CD_MTEXPOLY, n); cdlp = (index == -1) ? NULL : &pdata->layers[index]; - index = CustomData_get_active_layer_index(ldata, CD_MLOOPUV); + index = CustomData_get_layer_index_n(ldata, CD_MLOOPUV, n); cdlu = (index == -1) ? NULL : &ldata->layers[index]; - + if (!cdlp || !cdlu) - return 0; + return false; + + delete_customdata_layer(me, cdlp); + delete_customdata_layer(me, cdlu); - delete_customdata_layer(C, ob, cdlp); - delete_customdata_layer(C, ob, cdlu); - 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_uv_texture_remove_active(Mesh *me) +{ + /* texpoly/uv are assumed to be in sync */ + CustomData *pdata = GET_CD_DATA(me, pdata); + const int n = CustomData_get_active_layer(pdata, CD_MTEXPOLY); + + /* double check active layers align! */ +#ifdef DEBUG + CustomData *ldata = GET_CD_DATA(me, ldata); + BLI_assert(CustomData_get_active_layer(ldata, CD_MLOOPUV) == n); +#endif + + if (n != -1) { + return ED_mesh_uv_texture_remove_index(me, n); + } + else { + return false; + } +} +bool ED_mesh_uv_texture_remove_named(Mesh *me, const char *name) +{ + /* texpoly/uv are assumed to be in sync */ + CustomData *pdata = GET_CD_DATA(me, pdata); + const int n = CustomData_get_named_layer(pdata, CD_MTEXPOLY, name); + if (n != -1) { + return ED_mesh_uv_texture_remove_index(me, n); + } + else { + return false; + } } /* note: keep in sync with ED_mesh_uv_texture_add */ -int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mesh *me, const char *name, int active_set) +int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set) { BMEditMesh *em; int layernum; @@ -493,47 +520,50 @@ int ED_mesh_color_add(bContext *C, Scene *UNUSED(scene), Object *UNUSED(ob), Mes } 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 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; } - -int ED_mesh_color_remove_named(bContext *C, Object *ob, Mesh *me, const char *name) +bool ED_mesh_color_remove_active(Mesh *me) { 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_active_layer(ldata, CD_MLOOPCOL); + if (n != -1) { + return ED_mesh_color_remove_index(me, n); + } + else { + return false; + } +} +bool ED_mesh_color_remove_named(Mesh *me, const char *name) +{ + CustomData *ldata = GET_CD_DATA(me, ldata); + 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 ************************/ @@ -550,7 +580,7 @@ static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Mesh *me = ob->data; - if (ED_mesh_uv_texture_add(C, me, NULL, TRUE) == -1) + if (ED_mesh_uv_texture_add(me, NULL, true) == -1) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; @@ -670,7 +700,7 @@ static int mesh_uv_texture_remove_exec(bContext *C, wmOperator *UNUSED(op)) Object *ob = ED_object_context(C); Mesh *me = ob->data; - if (!ED_mesh_uv_texture_remove(C, ob, me)) + if (!ED_mesh_uv_texture_remove_active(me)) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; @@ -695,11 +725,10 @@ void MESH_OT_uv_texture_remove(wmOperatorType *ot) static int mesh_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op)) { - Scene *scene = CTX_data_scene(C); Object *ob = ED_object_context(C); Mesh *me = ob->data; - if (ED_mesh_color_add(C, scene, ob, me, NULL, TRUE) == -1) + if (ED_mesh_color_add(me, NULL, true) == -1) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; @@ -725,7 +754,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; @@ -757,7 +786,7 @@ static int mesh_customdata_clear_exec__internal(bContext *C, int tot; CustomData *data = mesh_customdata_get_type(me, htype, &tot); - BLI_assert(CustomData_layertype_is_singleton(type) == TRUE); + BLI_assert(CustomData_layertype_is_singleton(type) == true); if (CustomData_has_layer(data, type)) { if (me->edit_btmesh) { @@ -786,21 +815,21 @@ static int mesh_customdata_clear_mask_poll(bContext *C) /* special case - can't run this if we're in sculpt mode */ if (ob->mode & OB_MODE_SCULPT) { - return FALSE; + return false; } if (me->id.lib == NULL) { CustomData *data = GET_CD_DATA(me, vdata); if (CustomData_has_layer(data, CD_PAINT_MASK)) { - return TRUE; + return true; } data = GET_CD_DATA(me, ldata); if (CustomData_has_layer(data, CD_GRID_PAINT_MASK)) { - return TRUE; + return true; } } } - return FALSE; + return false; } static int mesh_customdata_clear_mask_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -843,11 +872,11 @@ static int mesh_customdata_clear_skin_poll(bContext *C) if (me->id.lib == NULL) { CustomData *data = GET_CD_DATA(me, vdata); if (CustomData_has_layer(data, CD_MVERT_SKIN)) { - return TRUE; + return true; } } } - return FALSE; + return false; } static int mesh_customdata_clear_skin_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -875,20 +904,20 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface) { int *polyindex = NULL; float (*face_nors)[3]; - int tessface_input = FALSE; + bool tessface_input = false; if (mesh->totface > 0 && mesh->totpoly == 0) { BKE_mesh_convert_mfaces_to_mpolys(mesh); /* would only be converting back again, don't bother */ - tessface_input = TRUE; + tessface_input = true; } if (calc_edges || ((mesh->totpoly || mesh->totface) && mesh->totedge == 0)) BKE_mesh_calc_edges(mesh, calc_edges, true); if (calc_tessface) { - if (tessface_input == FALSE) { + if (tessface_input == false) { BKE_mesh_tessface_calc(mesh); } } @@ -911,7 +940,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface) mesh->totloop, mesh->totpoly, NULL /* polyNors_r */, mesh->mface, mesh->totface, - polyindex, face_nors, FALSE); + polyindex, face_nors, false); #else BKE_mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, @@ -1239,7 +1268,7 @@ void ED_mesh_calc_normals(Mesh *mesh) #ifdef USE_BMESH_MPOLY_NORMALS BKE_mesh_calc_normals_mapping_ex(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, - NULL, NULL, 0, NULL, NULL, FALSE); + NULL, NULL, 0, NULL, NULL, false); #else BKE_mesh_calc_normals(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, |