/** * Duplicate of BM_mesh_cd_validate() for Mesh data. */ void BKE_mesh_cd_validate(Mesh *me) { int totlayer_mtex = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY); int totlayer_uv = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); int mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY); int uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV); int i; /* XXX For now, do not delete those, just warn they are not really usable. */ if (UNLIKELY(totlayer_mtex > MAX_MTFACE)) { printf("WARNING! More UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", MAX_MTFACE, totlayer_mtex - MAX_MTFACE); } if (UNLIKELY(totlayer_uv > MAX_MTFACE)) { printf("WARNING! More UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", MAX_MTFACE, totlayer_uv - MAX_MTFACE); } if (UNLIKELY(totlayer_mcol > MAX_MCOL)) { printf("WARNING! More VCol layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n", MAX_MCOL, totlayer_mcol - MAX_MCOL); } if (LIKELY(totlayer_mtex == totlayer_uv)) { /* pass */ } else if (totlayer_mtex < totlayer_uv) { do { const char *from_name = me->ldata.layers[uv_index + totlayer_mtex].name; CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, from_name); CustomData_set_layer_unique_name(&me->pdata, totlayer_mtex); } while (totlayer_uv != ++totlayer_mtex); mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY); } else if (totlayer_uv < totlayer_mtex) { do { const char *from_name = me->pdata.layers[mtex_index + totlayer_uv].name; CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, from_name); CustomData_set_layer_unique_name(&me->ldata, totlayer_uv); } while (totlayer_mtex != ++totlayer_uv); uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV); } BLI_assert(totlayer_mtex == totlayer_uv); /* Check uv/tex names match as well!!! */ for (i = 0; i < totlayer_mtex; i++, mtex_index++, uv_index++) { const char *name_src = me->pdata.layers[mtex_index].name; const char *name_dst = me->ldata.layers[uv_index].name; if (!STREQ(name_src, name_dst)) { BKE_mesh_uv_cdlayer_rename_index(me, mtex_index, uv_index, -1, name_src, false); } } }
/** * Duplicate of BM_mesh_cd_validate() for Mesh data. */ void BKE_mesh_cd_validate(Mesh *me) { int totlayer_mtex = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY); int totlayer_uv = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); int mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY); int uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV); int i; if (LIKELY(totlayer_mtex == totlayer_uv)) { /* pass */ } else if (totlayer_mtex < totlayer_uv) { do { const char *from_name = me->ldata.layers[uv_index + totlayer_mtex].name; CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, from_name); CustomData_set_layer_unique_name(&me->pdata, totlayer_mtex); } while (totlayer_uv != ++totlayer_mtex); mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY); } else if (totlayer_uv < totlayer_mtex) { do { const char *from_name = me->pdata.layers[mtex_index + totlayer_uv].name; CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, from_name); CustomData_set_layer_unique_name(&me->ldata, totlayer_uv); } while (totlayer_mtex != ++totlayer_uv); uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV); } BLI_assert(totlayer_mtex == totlayer_uv); /* Check uv/tex names match as well!!! */ for (i = 0; i < totlayer_mtex; i++, mtex_index++, uv_index++) { const char *name_src = me->pdata.layers[mtex_index].name; const char *name_dst = me->ldata.layers[uv_index].name; if (!STREQ(name_src, name_dst)) { BKE_mesh_uv_cdlayer_rename_index(me, mtex_index, uv_index, -1, name_src, false); } } }
bool BKE_mesh_uv_cdlayer_rename(Mesh *me, const char *old_name, const char *new_name, bool do_tessface) { CustomData *pdata, *ldata, *fdata; if (me->edit_btmesh) { pdata = &me->edit_btmesh->bm->pdata; ldata = &me->edit_btmesh->bm->ldata; /* No tessellated data in BMesh! */ fdata = NULL; do_tessface = false; } else { pdata = &me->pdata; ldata = &me->ldata; fdata = &me->fdata; do_tessface = (do_tessface && fdata->totlayer); } { const int pidx_start = CustomData_get_layer_index(pdata, CD_MTEXPOLY); const int lidx_start = CustomData_get_layer_index(ldata, CD_MLOOPUV); const int fidx_start = do_tessface ? CustomData_get_layer_index(fdata, CD_MTFACE) : -1; int pidx = CustomData_get_named_layer(pdata, CD_MTEXPOLY, old_name); int lidx = CustomData_get_named_layer(ldata, CD_MLOOPUV, old_name); int fidx = do_tessface ? CustomData_get_named_layer(fdata, CD_MTFACE, old_name) : -1; /* None of those cases should happen, in theory! * Note this assume we have the same number of mtexpoly, mloopuv and mtface layers! */ if (pidx == -1) { if (lidx == -1) { if (fidx == -1) { /* No layer found with this name! */ return false; } else { lidx = fidx; } } pidx = lidx; } else { if (lidx == -1) { lidx = pidx; } if (fidx == -1 && do_tessface) { fidx = pidx; } } #if 0 /* For now, we do not consider mismatch in indices (i.e. same name leading to (relative) different indices). */ else if (pidx != lidx) { lidx = pidx; } #endif /* Go back to absolute indices! */ pidx += pidx_start; lidx += lidx_start; if (fidx != -1) fidx += fidx_start; return BKE_mesh_uv_cdlayer_rename_index(me, pidx, lidx, fidx, new_name, do_tessface); }