Commit: 2d5c8b0a9cb02db756fb252f49229a17cbc4afb8 Author: Martijn Versteegh Date: Thu Nov 24 21:28:31 2022 +0100 Branches: refactor-mesh-uv-map-generic https://developer.blender.org/rB2d5c8b0a9cb02db756fb252f49229a17cbc4afb8
Merge branch 'master' into refactor-mesh-uv-map-generic =================================================================== =================================================================== diff --cc source/blender/blenkernel/intern/mesh.cc index 35ac5634af9,02d375bd782..d26f381cbdc --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@@ -276,12 -275,10 +276,14 @@@ static void mesh_blend_write(BlendWrite CustomData_blend_write_prepare(mesh->edata, edge_layers, names_to_skip); CustomData_blend_write_prepare(mesh->ldata, loop_layers, names_to_skip); CustomData_blend_write_prepare(mesh->pdata, poly_layers, names_to_skip); + + if (!BLO_write_is_undo(writer)) { + BKE_mesh_legacy_convert_uvs_to_struct(mesh, temp_arrays_for_legacy_format, loop_layers); + } } + mesh->runtime = nullptr; + BLO_write_id_struct(writer, Mesh, id_address, &mesh->id); BKE_id_blend_write(writer, &mesh->id); diff --cc source/blender/bmesh/intern/bmesh_interp.c index fdae1d71f04,8ceefc94d8a..ab7978d7d70 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@@ -874,58 -864,17 +866,54 @@@ void BM_data_layer_add_named(BMesh *bm } } +void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const char *name) +{ + if (CustomData_get_named_layer_index(data, type, name) == -1) { + BM_data_layer_add_named(bm, data, type, name); + } +} + +void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char *uv_map_name) +{ + char name[MAX_CUSTOMDATA_LAYER_NAME]; + BM_data_layer_ensure_named( + bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_vert_selection_name(uv_map_name, name)); + BM_data_layer_ensure_named( + bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_edge_selection_name(uv_map_name, name)); + BM_data_layer_ensure_named(bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_pin_name(uv_map_name, name)); +} + +void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char *uv_map_name) +{ + char name[MAX_CUSTOMDATA_LAYER_NAME]; + BM_data_layer_ensure_named( + bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_vert_selection_name(uv_map_name, name)); +} + +void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char *uv_map_name) +{ + char name[MAX_CUSTOMDATA_LAYER_NAME]; + BM_data_layer_ensure_named( + bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_edge_selection_name(uv_map_name, name)); +} + +void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name) +{ + char name[MAX_CUSTOMDATA_LAYER_NAME]; + BM_data_layer_ensure_named(bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_pin_name(uv_map_name, name)); +} + void BM_data_layer_free(BMesh *bm, CustomData *data, int type) { - CustomData olddata; - bool has_layer; - - olddata = *data; + CustomData olddata = *data; olddata.layers = (olddata.layers) ? MEM_dupallocN(olddata.layers) : NULL; - - /* the pool is now owned by olddata and must not be shared */ + /* The pool is now owned by `olddata` and must not be shared. */ data->pool = NULL; - has_layer = CustomData_free_layer_active(data, type, 0); + const bool had_layer = CustomData_free_layer_active(data, type, 0); /* Assert because its expensive to realloc - better not do if layer isn't present. */ - BLI_assert(has_layer != false); - UNUSED_VARS_NDEBUG(has_layer); + BLI_assert(had_layer != false); + UNUSED_VARS_NDEBUG(had_layer); update_data_blocks(bm, &olddata, data); if (olddata.layers) { diff --cc source/blender/editors/include/ED_mesh.h index 76f7e3b2c3e,bab1f7e4c5e..b717a9d4b4e --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@@ -552,13 -552,8 +552,15 @@@ void ED_mesh_geometry_clear(struct Mes void ED_mesh_update(struct Mesh *mesh, struct bContext *C, bool calc_edges, bool calc_edges_loose); +bool *ED_mesh_uv_map_ensure_vert_selection(struct Mesh *mesh, int uv_index); +bool *ED_mesh_uv_map_ensure_edge_selection(struct Mesh *mesh, int uv_index); +bool *ED_mesh_uv_map_ensure_pin(struct Mesh *mesh, int uv_index); +const bool *ED_mesh_uv_map_get_vert_selection(const struct Mesh *mesh, int uv_index); +const bool *ED_mesh_uv_map_get_edge_selection(const struct Mesh *mesh, int uv_index); +const bool *ED_mesh_uv_map_get_pin(const struct Mesh *mesh, int uv_index); + + bool ED_mesh_edge_is_loose(const struct Mesh *mesh, int index); + void ED_mesh_uv_ensure(struct Mesh *me, const char *name); int ED_mesh_uv_add( struct Mesh *me, const char *name, bool active_set, bool do_init, struct ReportList *reports); diff --cc source/blender/editors/sculpt_paint/paint_image_proj.cc index 7cb117ab6bc,107c592a10c..60728f26e79 --- a/source/blender/editors/sculpt_paint/paint_image_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc @@@ -514,10 -514,12 +514,11 @@@ BLI_INLINE const MPoly *ps_tri_index_to } #define PS_LOOPTRI_AS_VERT_INDEX_3(ps, lt) \ - ps->mloop_eval[lt->tri[0]].v, ps->mloop_eval[lt->tri[1]].v, ps->mloop_eval[lt->tri[2]].v, + int(ps->mloop_eval[lt->tri[0]].v), int(ps->mloop_eval[lt->tri[1]].v), \ + int(ps->mloop_eval[lt->tri[2]].v), #define PS_LOOPTRI_AS_UV_3(uvlayer, lt) \ - uvlayer[lt->poly][lt->tri[0]].uv, uvlayer[lt->poly][lt->tri[1]].uv, \ - uvlayer[lt->poly][lt->tri[2]].uv, + uvlayer[lt->poly][lt->tri[0]], uvlayer[lt->poly][lt->tri[1]], uvlayer[lt->poly][lt->tri[2]], #define PS_LOOPTRI_ASSIGN_UV_3(uv_tri, uvlayer, lt) \ { \ @@@ -1658,11 -1660,11 +1659,11 @@@ static float project_paint_uvpixel_mask ImBuf *ibuf_other; Image *other_tpage = ps->stencil_ima; - if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, NULL, NULL))) { + if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, nullptr, nullptr))) { const MLoopTri *lt_other = &ps->mlooptri_eval[tri_index]; - const float *lt_other_tri_uv[3] = {ps->mloopuv_stencil_eval[lt_other->tri[0]].uv, - ps->mloopuv_stencil_eval[lt_other->tri[1]].uv, - ps->mloopuv_stencil_eval[lt_other->tri[2]].uv}; + const float *lt_other_tri_uv[3] = {ps->mloopuv_stencil_eval[lt_other->tri[0]], + ps->mloopuv_stencil_eval[lt_other->tri[1]], + ps->mloopuv_stencil_eval[lt_other->tri[2]]}; /* #BKE_image_acquire_ibuf - TODO: this may be slow. */ uchar rgba_ub[4]; @@@ -4039,8 -4050,8 +4049,8 @@@ static bool proj_paint_state_mesh_eval_ } ps->me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_eval, &cddata_masks); - if (!CustomData_has_layer(&ps->me_eval->ldata, CD_MLOOPUV)) { + if (!CustomData_has_layer(&ps->me_eval->ldata, CD_PROP_FLOAT2)) { - ps->me_eval = NULL; + ps->me_eval = nullptr; return false; } @@@ -4076,7 -4088,8 +4087,7 @@@ ps->mlooptri_eval = BKE_mesh_runtime_looptri_ensure(ps->me_eval); ps->totlooptri_eval = BKE_mesh_runtime_looptri_len(ps->me_eval); - ps->poly_to_loop_uv = MEM_mallocN(ps->totpoly_eval * sizeof(float(*)[2]), "proj_paint_mtfaces"); - ps->poly_to_loop_uv = static_cast<const MLoopUV **>( - MEM_mallocN(ps->totpoly_eval * sizeof(MLoopUV *), "proj_paint_mtfaces")); ++ ps->poly_to_loop_uv = static_cast<const float (**)[2]>(MEM_mallocN(ps->totpoly_eval * sizeof(float(*)[2]), "proj_paint_mtfaces")); return true; } @@@ -4089,23 -4102,24 +4100,25 @@@ typedef struct static void proj_paint_layer_clone_init(ProjPaintState *ps, ProjPaintLayerClone *layer_clone) { - const float(*mloopuv_clone_base)[2] = NULL; - const MLoopUV *mloopuv_clone_base = nullptr; ++ const float(*mloopuv_clone_base)[2] = nullptr; /* use clone mtface? */ if (ps->do_layer_clone) { - const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV); + const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->ldata, + CD_PROP_FLOAT2); - ps->poly_to_loop_uv_clone = MEM_mallocN(ps->totpoly_eval * sizeof(float(*)[2]), - "proj_paint_mtfaces"); - ps->poly_to_loop_uv_clone = static_cast<const MLoopUV **>( - MEM_mallocN(ps->totpoly_eval * sizeof(MLoopUV *), "proj_paint_mtfaces")); ++ ps->poly_to_loop_uv_clone = static_cast<const float(**)[2]>( ++ MEM_mallocN(ps->totpoly_eval * sizeof(float (*)[2]), "proj_paint_mtfaces")); if (layer_num != -1) { - mloopuv_clone_base = CustomData_get_layer_n(&ps->me_eval->ldata, CD_PROP_FLOAT2, layer_num); - mloopuv_clone_base = static_cast<const MLoopUV *>( - CustomData_get_layer_n(&ps->me_eval->ldata, CD_MLOOPUV, layer_num)); ++ mloopuv_clone_base = static_cast<const float (*)[2]( ++ CustomData_get_layer_n(&ps->me_eval->ldata, CD_PROP_FLOAT2, layer_num)); } - if (mloopuv_clone_base == NULL) { + if (mloopuv_clone_base == nullptr) { /* get active instead */ - mloopuv_clone_base = CustomData_get_layer(&ps->me_eval->ldata, CD_PROP_FLOAT2); - mloopuv_clone_base = static_cast<const MLoopUV *>( - CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV)); ++ mloopuv_clone_base = static_cast<const float (*)[2]>( ++ CustomData_get_layer(&ps->me_eval->ldata, CD_PROP_FLOAT2)); } } @@@ -4134,9 -4148,10 +4147,10 @@@ static bool project_paint_clone_face_sk if (ps->do_material_slots) { if (lc->slot_clone != lc->slot_last_clone) { if (!lc->slot_clone->uvname || - !(lc->mloopuv_clone_base = CustomData_get_layer_named( - &ps->me_eval->ldata, CD_PROP_FLOAT2, lc->slot_clone->uvname))) { - lc->mloopuv_clone_base = CustomData_get_layer(&ps->me_eval->ldata, CD_PROP_FLOAT2); - !(lc->mloopuv_clone_base = static_cast<const MLoopUV *>(CustomData_get_layer_named( - &ps->me_eval->ldata, CD_MLOOPUV, lc->slot_clone->uvname)))) { - lc->mloopuv_clone_base = static_cast<const MLoopUV *>( - CustomData_get_layer(&ps->me_eval->ldata, CD_MLOOPUV)); ++ !(lc->mloopuv_clone_base = static_cast<const float (*)[2]>(CustomData_get_layer_named( ++ @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs