Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/intern/bmesh_mesh_convert.cc
| Show First 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshParams *params) | ||||
| CustomData mesh_vdata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->vdata, | CustomData mesh_vdata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->vdata, | ||||
| mask.vmask); | mask.vmask); | ||||
| CustomData mesh_edata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->edata, | CustomData mesh_edata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->edata, | ||||
| mask.emask); | mask.emask); | ||||
| CustomData mesh_pdata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->pdata, | CustomData mesh_pdata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->pdata, | ||||
| mask.pmask); | mask.pmask); | ||||
| CustomData mesh_ldata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->ldata, | CustomData mesh_ldata = CustomData_shallow_copy_remove_non_bmesh_attributes(&me->ldata, | ||||
| mask.lmask); | mask.lmask); | ||||
| blender::Vector<std::string> temporary_layers_to_delete; | |||||
| for (const int layer_index : | |||||
HooglyBoogly: This worked out better than I expect, nice one!
How about this prettier loop syntax? | |||||
Done Inline ActionsDepends on your definition of 'prettier' (/ducks) ;-) Ok, I'll change it. I'm still too used to the old C syntax, to me this syntax still looks very weird and abstract ;-) Baardaap: Depends on your definition of 'prettier' (/ducks) ;-)
Ok, I'll change it. I'm still too used… | |||||
Done Inline ActionsCould call layer_index, I find it more readable. campbellbarton: Could call `layer_index`, I find it more readable. | |||||
| IndexRange(CustomData_number_of_layers(&mesh_ldata, CD_PROP_FLOAT2))) { | |||||
| char name[MAX_CUSTOMDATA_LAYER_NAME]; | |||||
| BKE_uv_map_vert_select_name_get( | |||||
| CustomData_get_layer_name(&mesh_ldata, CD_PROP_FLOAT2, layer_index), name); | |||||
| if (CustomData_get_named_layer_index(&mesh_ldata, CD_PROP_BOOL, name) < 0) { | |||||
| CustomData_add_layer_named( | |||||
| &mesh_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, name); | |||||
| temporary_layers_to_delete.append(std::string(name)); | |||||
| } | |||||
| BKE_uv_map_edge_select_name_get( | |||||
| CustomData_get_layer_name(&mesh_ldata, CD_PROP_FLOAT2, layer_index), name); | |||||
| if (CustomData_get_named_layer_index(&mesh_ldata, CD_PROP_BOOL, name) < 0) { | |||||
| CustomData_add_layer_named( | |||||
| &mesh_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, name); | |||||
| temporary_layers_to_delete.append(std::string(name)); | |||||
| } | |||||
| BKE_uv_map_pin_name_get(CustomData_get_layer_name(&mesh_ldata, CD_PROP_FLOAT2, layer_index), | |||||
| name); | |||||
| if (CustomData_get_named_layer_index(&mesh_ldata, CD_PROP_BOOL, name) < 0) { | |||||
| CustomData_add_layer_named( | |||||
| &mesh_ldata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me->totloop, name); | |||||
| temporary_layers_to_delete.append(std::string(name)); | |||||
| } | |||||
| } | |||||
| BLI_SCOPED_DEFER([&]() { | BLI_SCOPED_DEFER([&]() { | ||||
| for (const std::string &name : temporary_layers_to_delete) { | |||||
| CustomData_free_layer_named(&mesh_ldata, name.c_str(), me->totloop); | |||||
| } | |||||
| MEM_SAFE_FREE(mesh_vdata.layers); | MEM_SAFE_FREE(mesh_vdata.layers); | ||||
| MEM_SAFE_FREE(mesh_edata.layers); | MEM_SAFE_FREE(mesh_edata.layers); | ||||
| MEM_SAFE_FREE(mesh_pdata.layers); | MEM_SAFE_FREE(mesh_pdata.layers); | ||||
| MEM_SAFE_FREE(mesh_ldata.layers); | MEM_SAFE_FREE(mesh_ldata.layers); | ||||
| }); | }); | ||||
| if (me->totvert == 0) { | if (me->totvert == 0) { | ||||
| if (is_new) { | if (is_new) { | ||||
| ▲ Show 20 Lines • Show All 790 Lines • ▼ Show 20 Lines | void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params) | ||||
| me->totedge = bm->totedge; | me->totedge = bm->totedge; | ||||
| me->totloop = bm->totloop; | me->totloop = bm->totloop; | ||||
| me->totpoly = bm->totface; | me->totpoly = bm->totface; | ||||
| /* Will be overwritten with a valid value if 'dotess' is set, otherwise we | /* Will be overwritten with a valid value if 'dotess' is set, otherwise we | ||||
| * end up with 'me->totface' and `me->mface == nullptr` which can crash T28625. */ | * end up with 'me->totface' and `me->mface == nullptr` which can crash T28625. */ | ||||
| me->totface = 0; | me->totface = 0; | ||||
| me->act_face = -1; | me->act_face = -1; | ||||
| /* Mark UV selection layers which are all false as 'nocopy'. */ | |||||
| for (const int layer_index : | |||||
| IndexRange(CustomData_number_of_layers(&bm->ldata, CD_PROP_FLOAT2))) { | |||||
| char const *layer_name = CustomData_get_layer_name(&bm->ldata, CD_PROP_FLOAT2, layer_index); | |||||
| char sub_layer_name[MAX_CUSTOMDATA_LAYER_NAME]; | |||||
| int vertsel_layer_index = CustomData_get_named_layer_index( | |||||
| &bm->ldata, CD_PROP_BOOL, BKE_uv_map_vert_select_name_get(layer_name, sub_layer_name)); | |||||
| int edgesel_layer_index = CustomData_get_named_layer_index( | |||||
| &bm->ldata, CD_PROP_BOOL, BKE_uv_map_edge_select_name_get(layer_name, sub_layer_name)); | |||||
| int pin_layer_index = CustomData_get_named_layer_index( | |||||
| &bm->ldata, CD_PROP_BOOL, BKE_uv_map_pin_name_get(layer_name, sub_layer_name)); | |||||
| int vertsel_offset = bm->ldata.layers[vertsel_layer_index].offset; | |||||
| int edgesel_offset = bm->ldata.layers[edgesel_layer_index].offset; | |||||
| int pin_offset = bm->ldata.layers[pin_layer_index].offset; | |||||
| bool need_vertsel = false; | |||||
| bool need_edgesel = false; | |||||
| bool need_pin = false; | |||||
| BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | |||||
| BMIter liter; | |||||
| BMLoop *l; | |||||
| BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | |||||
| need_vertsel |= BM_ELEM_CD_GET_BOOL(l, vertsel_offset); | |||||
| need_edgesel |= BM_ELEM_CD_GET_BOOL(l, edgesel_offset); | |||||
| need_pin |= BM_ELEM_CD_GET_BOOL(l, pin_offset); | |||||
| } | |||||
| } | |||||
| if (need_vertsel) { | |||||
| bm->ldata.layers[vertsel_layer_index].flag &= ~CD_FLAG_NOCOPY; | |||||
| } | |||||
| else { | |||||
| bm->ldata.layers[vertsel_layer_index].flag |= CD_FLAG_NOCOPY; | |||||
| } | |||||
| if (need_edgesel) { | |||||
| bm->ldata.layers[edgesel_layer_index].flag &= ~CD_FLAG_NOCOPY; | |||||
| } | |||||
| else { | |||||
| bm->ldata.layers[edgesel_layer_index].flag |= CD_FLAG_NOCOPY; | |||||
| } | |||||
| if (need_pin) { | |||||
| bm->ldata.layers[pin_layer_index].flag &= ~CD_FLAG_NOCOPY; | |||||
| } | |||||
| else { | |||||
| bm->ldata.layers[pin_layer_index].flag |= CD_FLAG_NOCOPY; | |||||
| } | |||||
| } | |||||
| { | { | ||||
| CustomData_MeshMasks mask = CD_MASK_MESH; | CustomData_MeshMasks mask = CD_MASK_MESH; | ||||
| CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra); | CustomData_MeshMasks_update(&mask, ¶ms->cd_mask_extra); | ||||
| CustomData_copy(&bm->vdata, &me->vdata, mask.vmask, CD_SET_DEFAULT, me->totvert); | CustomData_copy(&bm->vdata, &me->vdata, mask.vmask, CD_SET_DEFAULT, me->totvert); | ||||
| CustomData_copy(&bm->edata, &me->edata, mask.emask, CD_SET_DEFAULT, me->totedge); | CustomData_copy(&bm->edata, &me->edata, mask.emask, CD_SET_DEFAULT, me->totedge); | ||||
| CustomData_copy(&bm->ldata, &me->ldata, mask.lmask, CD_SET_DEFAULT, me->totloop); | CustomData_copy(&bm->ldata, &me->ldata, mask.lmask, CD_SET_DEFAULT, me->totloop); | ||||
| CustomData_copy(&bm->pdata, &me->pdata, mask.pmask, CD_SET_DEFAULT, me->totpoly); | CustomData_copy(&bm->pdata, &me->pdata, mask.pmask, CD_SET_DEFAULT, me->totpoly); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 398 Lines • Show Last 20 Lines | |||||
This worked out better than I expect, nice one!
How about this prettier loop syntax?