diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 76c7940a070..925e8893fa8 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -14,7 +14,6 @@ #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "BKE_customdata.hh" struct BMesh; struct BMeshCreateParams; @@ -563,46 +562,6 @@ void BKE_mesh_debug_print(const struct Mesh *mesh) ATTR_NONNULL(1); /** \name Inline Mesh Data Access * \{ */ -/** - * \return The material index for each face. May be null. - * \note In C++ code, prefer using the attribute API (#AttributeAccessor). - */ -BLI_INLINE const int *BKE_mesh_material_indices(const Mesh *mesh) -{ - return (const int *)CustomData_get_layer_named( - &mesh->face_data, CD_PROP_INT32, "material_index"); -} - -/** - * \return The material index for each face. Create the layer if it doesn't exist. - * \note In C++ code, prefer using the attribute API (#MutableAttributeAccessor). - */ -BLI_INLINE int *BKE_mesh_material_indices_for_write(Mesh *mesh) -{ - int *indices = (int *)CustomData_get_layer_named_for_write( - &mesh->face_data, CD_PROP_INT32, "material_index", mesh->faces_num); - if (indices) { - return indices; - } - return (int *)CustomData_add_layer_named( - &mesh->face_data, CD_PROP_INT32, CD_SET_DEFAULT, mesh->faces_num, "material_index"); -} - -BLI_INLINE const MDeformVert *BKE_mesh_deform_verts(const Mesh *mesh) -{ - return (const MDeformVert *)CustomData_get_layer(&mesh->vert_data, CD_MDEFORMVERT); -} -BLI_INLINE MDeformVert *BKE_mesh_deform_verts_for_write(Mesh *mesh) -{ - MDeformVert *dvert = (MDeformVert *)CustomData_get_layer_for_write( - &mesh->vert_data, CD_MDEFORMVERT, mesh->totvert); - if (dvert) { - return dvert; - } - return (MDeformVert *)CustomData_add_layer( - &mesh->vert_data, CD_MDEFORMVERT, CD_SET_DEFAULT, mesh->totvert); -} - #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_mesh.hh b/source/blender/blenkernel/BKE_mesh.hh index ea434f3c53a..1b0ec3e1910 100644 --- a/source/blender/blenkernel/BKE_mesh.hh +++ b/source/blender/blenkernel/BKE_mesh.hh @@ -10,6 +10,7 @@ #include "BLI_index_mask.hh" +#include "BKE_customdata.hh" #include "BKE_mesh.h" #include "BKE_mesh_types.hh" @@ -389,7 +390,8 @@ inline blender::MutableSpan Mesh::corner_edges_for_write() inline blender::Span Mesh::deform_verts() const { - const MDeformVert *dverts = BKE_mesh_deform_verts(this); + const MDeformVert *dverts = static_cast( + CustomData_get_layer(&this->vert_data, CD_MDEFORMVERT)); if (!dverts) { return {}; } @@ -397,7 +399,14 @@ inline blender::Span Mesh::deform_verts() const } inline blender::MutableSpan Mesh::deform_verts_for_write() { - return {BKE_mesh_deform_verts_for_write(this), this->totvert}; + MDeformVert *dvert = static_cast( + CustomData_get_layer_for_write(&this->vert_data, CD_MDEFORMVERT, this->totvert)); + if (dvert) { + return {dvert, this->totvert}; + } + return {static_cast(CustomData_add_layer( + &this->vert_data, CD_MDEFORMVERT, CD_SET_DEFAULT, this->totvert)), + this->totvert}; } /** \} */ diff --git a/source/blender/blenkernel/intern/armature_deform.cc b/source/blender/blenkernel/intern/armature_deform.cc index 5c958fbcf20..526a8195376 100644 --- a/source/blender/blenkernel/intern/armature_deform.cc +++ b/source/blender/blenkernel/intern/armature_deform.cc @@ -520,7 +520,7 @@ static void armature_deform_coords_impl(const Object *ob_arm, target_data_id = me_target == nullptr ? (const ID *)ob_target->data : &me_target->id; if (em_target == nullptr) { const Mesh *mesh = (const Mesh *)target_data_id; - dverts = BKE_mesh_deform_verts(mesh); + dverts = mesh->deform_verts().data(); if (dverts) { dverts_len = mesh->totvert; } @@ -555,7 +555,7 @@ static void armature_deform_coords_impl(const Object *ob_arm, use_dverts = (cd_dvert_offset != -1); } else if (me_target) { - use_dverts = (BKE_mesh_deform_verts(me_target) != nullptr); + use_dverts = !me_target->deform_verts().is_empty(); } else if (dverts) { use_dverts = true; diff --git a/source/blender/blenkernel/intern/fluid.cc b/source/blender/blenkernel/intern/fluid.cc index 5e50e0cb614..6c7a9b11576 100644 --- a/source/blender/blenkernel/intern/fluid.cc +++ b/source/blender/blenkernel/intern/fluid.cc @@ -2085,7 +2085,7 @@ static void emit_from_mesh( const blender::Span corner_verts = mesh->corner_verts(); const blender::Span looptris = mesh->looptris(); const int numverts = mesh->totvert; - const MDeformVert *dvert = BKE_mesh_deform_verts(mesh); + const MDeformVert *dvert = mesh->deform_verts().data(); const float(*mloopuv)[2] = static_cast( CustomData_get_layer_named(&mesh->loop_data, CD_PROP_FLOAT2, ffs->uvlayer_name)); @@ -3219,14 +3219,17 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds, Mesh *orgmesh, Object *ob) { + using namespace blender; Mesh *mesh; float min[3]; float max[3]; float size[3]; float cell_size_scaled[3]; - const int *orig_material_indices = BKE_mesh_material_indices(orgmesh); - const short mp_mat_nr = orig_material_indices ? orig_material_indices[0] : 0; + const bke::AttributeAccessor orig_attributes = orgmesh->attributes(); + const VArraySpan orig_material_indices = *orig_attributes.lookup("material_index", + ATTR_DOMAIN_FACE); + const short mp_mat_nr = orig_material_indices.is_empty() ? 0 : orig_material_indices[0]; int i; int num_verts, num_faces; @@ -3341,12 +3344,14 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds, } } - int *material_indices = BKE_mesh_material_indices_for_write(mesh); + bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); + bke::SpanAttributeWriter material_indices = attributes.lookup_or_add_for_write_span( + "material_index", ATTR_DOMAIN_FACE); /* Loop for triangles. */ for (const int i : face_offsets.index_range().drop_back(1)) { /* Initialize from existing face. */ - material_indices[i] = mp_mat_nr; + material_indices.span[i] = mp_mat_nr; face_offsets[i] = i * 3; @@ -3362,6 +3367,8 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds, # endif } + material_indices.finish(); + BKE_mesh_calc_edges(mesh, false, false); return mesh; diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index 5ea12b5ab87..babba29987e 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -1274,7 +1274,7 @@ static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cac /* gather dvert and totvert */ if (ob->type == OB_MESH) { Mesh *mesh = static_cast(ob->data); - dvert = BKE_mesh_deform_verts(mesh); + dvert = mesh->deform_verts().data(); totvert = mesh->totvert; if (mesh->edit_mesh && mesh->edit_mesh->bm->totvert == totvert) { diff --git a/source/blender/blenkernel/intern/lattice_deform.cc b/source/blender/blenkernel/intern/lattice_deform.cc index 71d87db65ed..51c55833e74 100644 --- a/source/blender/blenkernel/intern/lattice_deform.cc +++ b/source/blender/blenkernel/intern/lattice_deform.cc @@ -372,7 +372,7 @@ static void lattice_deform_coords_impl(const Object *ob_lattice, dvert = ((Lattice *)ob_target->data)->dvert; } else { - dvert = BKE_mesh_deform_verts((Mesh *)ob_target->data); + dvert = ((Mesh *)ob_target->data)->deform_verts().data(); } } } diff --git a/source/blender/blenkernel/intern/mesh_mirror.cc b/source/blender/blenkernel/intern/mesh_mirror.cc index 90354e1bc40..0df49c330cb 100644 --- a/source/blender/blenkernel/intern/mesh_mirror.cc +++ b/source/blender/blenkernel/intern/mesh_mirror.cc @@ -447,7 +447,7 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd, /* handle vgroup stuff */ if (BKE_object_supports_vertex_groups(ob)) { if ((mmd->flag & MOD_MIR_VGROUP) && CustomData_has_layer(&result->vert_data, CD_MDEFORMVERT)) { - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(result) + src_verts_num; + MDeformVert *dvert = result->deform_verts_for_write().data() + src_verts_num; int flip_map_len = 0; int *flip_map = BKE_object_defgroup_flip_map(ob, false, &flip_map_len); if (flip_map) { diff --git a/source/blender/blenkernel/intern/object_deform.cc b/source/blender/blenkernel/intern/object_deform.cc index b1a3c1e4691..0c735487517 100644 --- a/source/blender/blenkernel/intern/object_deform.cc +++ b/source/blender/blenkernel/intern/object_deform.cc @@ -112,7 +112,7 @@ bDeformGroup *BKE_object_defgroup_add(Object *ob) MDeformVert *BKE_object_defgroup_data_create(ID *id) { if (GS(id->name) == ID_ME) { - return BKE_mesh_deform_verts_for_write((Mesh *)id); + return ((Mesh *)id)->deform_verts_for_write().data(); } if (GS(id->name) == ID_LT) { Lattice *lt = (Lattice *)id; @@ -160,12 +160,12 @@ bool BKE_object_defgroup_clear(Object *ob, bDeformGroup *dg, const bool use_sele } } else { - if (BKE_mesh_deform_verts(mesh)) { + if (!mesh->deform_verts().data()) { const bool *select_vert = (const bool *)CustomData_get_layer_named( &mesh->vert_data, CD_PROP_BOOL, ".select_vert"); int i; - dv = BKE_mesh_deform_verts_for_write(mesh); + dv = mesh->deform_verts_for_write().data(); for (i = 0; i < mesh->totvert; i++, dv++) { if (dv->dw && (!use_selection || (select_vert && select_vert[i]))) { @@ -496,7 +496,7 @@ bool BKE_object_defgroup_array_get(ID *id, MDeformVert **dvert_arr, int *dvert_t switch (GS(id->name)) { case ID_ME: { Mesh *mesh = (Mesh *)id; - *dvert_arr = BKE_mesh_deform_verts_for_write(mesh); + *dvert_arr = mesh->deform_verts_for_write().data(); *dvert_tot = mesh->totvert; return true; } diff --git a/source/blender/blenkernel/intern/particle.cc b/source/blender/blenkernel/intern/particle.cc index e52b4eaf93a..1a18c80c0c4 100644 --- a/source/blender/blenkernel/intern/particle.cc +++ b/source/blender/blenkernel/intern/particle.cc @@ -2575,7 +2575,7 @@ float *psys_cache_vgroup(Mesh *mesh, ParticleSystem *psys, int vgroup) /* hair dynamics pinning vgroup */ } else if (psys->vgroup[vgroup]) { - const MDeformVert *dvert = BKE_mesh_deform_verts(mesh); + const MDeformVert *dvert = mesh->deform_verts().data(); if (dvert) { int totvert = mesh->totvert, i; vg = static_cast(MEM_callocN(sizeof(float) * totvert, "vg_cache")); diff --git a/source/blender/blenkernel/intern/particle_system.cc b/source/blender/blenkernel/intern/particle_system.cc index b658d25f736..27175174ccc 100644 --- a/source/blender/blenkernel/intern/particle_system.cc +++ b/source/blender/blenkernel/intern/particle_system.cc @@ -3352,7 +3352,7 @@ static void hair_create_input_mesh(ParticleSimulationData *sim, } blender::MutableSpan positions = mesh->vert_positions_for_write(); blender::int2 *edge = mesh->edges_for_write().data(); - dvert = BKE_mesh_deform_verts_for_write(mesh); + dvert = mesh->deform_verts_for_write().data(); if (psys->clmd->hairdata == nullptr) { psys->clmd->hairdata = static_cast( diff --git a/source/blender/blenkernel/intern/softbody.cc b/source/blender/blenkernel/intern/softbody.cc index 581249fcca5..edd90613685 100644 --- a/source/blender/blenkernel/intern/softbody.cc +++ b/source/blender/blenkernel/intern/softbody.cc @@ -2701,7 +2701,7 @@ static void mesh_to_softbody(Object *ob) sb = ob->soft; bp = sb->bpoint; - const MDeformVert *dvert = BKE_mesh_deform_verts(mesh); + const MDeformVert *dvert = mesh->deform_verts().data(); defgroup_index = dvert ? (sb->vertgroup - 1) : -1; defgroup_index_mass = dvert ? BKE_id_defgroup_name_index(&mesh->id, sb->namedVG_Mass) : -1; diff --git a/source/blender/blenloader/intern/versioning_290.cc b/source/blender/blenloader/intern/versioning_290.cc index 6469754865e..b06f87749ad 100644 --- a/source/blender/blenloader/intern/versioning_290.cc +++ b/source/blender/blenloader/intern/versioning_290.cc @@ -846,7 +846,7 @@ void blo_do_versions_290(FileData *fd, Library * /*lib*/, Main *bmain) me->totloop, me->face_offsets_for_write().data(), me->faces_num, - BKE_mesh_deform_verts_for_write(me), + me->deform_verts_for_write().data(), false, true, &changed); diff --git a/source/blender/draw/intern/draw_manager.hh b/source/blender/draw/intern/draw_manager.hh index 30e871554b8..01d6422fd7c 100644 --- a/source/blender/draw/intern/draw_manager.hh +++ b/source/blender/draw/intern/draw_manager.hh @@ -14,8 +14,9 @@ * \note It is currently work in progress and should replace the old global draw manager. */ -#include "BLI_listbase_wrapper.hh" +#include "BLI_map.hh" #include "BLI_sys_types.h" + #include "GPU_material.h" #include "draw_resource.hh" diff --git a/source/blender/draw/intern/draw_pass.hh b/source/blender/draw/intern/draw_pass.hh index 9a71da49ef5..f008d9a17ce 100644 --- a/source/blender/draw/intern/draw_pass.hh +++ b/source/blender/draw/intern/draw_pass.hh @@ -40,12 +40,16 @@ * if any of these reference becomes invalid. */ -#include "BKE_image.h" +#include "BLI_listbase_wrapper.hh" #include "BLI_vector.hh" -#include "DRW_gpu_wrapper.hh" + +#include "BKE_image.h" + #include "GPU_debug.h" #include "GPU_material.h" +#include "DRW_gpu_wrapper.hh" + #include "draw_command.hh" #include "draw_handle.hh" #include "draw_manager.hh" diff --git a/source/blender/editors/object/object_bake.cc b/source/blender/editors/object/object_bake.cc index bf231e85249..b3e9055e66d 100644 --- a/source/blender/editors/object/object_bake.cc +++ b/source/blender/editors/object/object_bake.cc @@ -23,6 +23,7 @@ #include "BLI_utildefines.h" #include "BKE_DerivedMesh.hh" +#include "BKE_attribute.hh" #include "BKE_blender.h" #include "BKE_cdderivedmesh.h" #include "BKE_context.hh" @@ -114,6 +115,7 @@ struct MultiresBakeJob { static bool multiresbake_check(bContext *C, wmOperator *op) { + using namespace blender; Scene *scene = CTX_data_scene(C); Object *ob; Mesh *mesh; @@ -163,10 +165,13 @@ static bool multiresbake_check(bContext *C, wmOperator *op) ok = false; } else { - const int *material_indices = BKE_mesh_material_indices(mesh); + const bke::AttributeAccessor attributes = mesh->attributes(); + const VArraySpan material_indices = *attributes.lookup("material_index", + ATTR_DOMAIN_FACE); a = mesh->faces_num; while (ok && a--) { - Image *ima = bake_object_image_get(ob, material_indices ? material_indices[a] : 0); + Image *ima = bake_object_image_get(ob, + material_indices.is_empty() ? 0 : material_indices[a]); if (!ima) { BKE_report( diff --git a/source/blender/editors/sculpt_paint/paint_utils.cc b/source/blender/editors/sculpt_paint/paint_utils.cc index 3b45d34d46f..5af14b5c76a 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.cc +++ b/source/blender/editors/sculpt_paint/paint_utils.cc @@ -820,8 +820,7 @@ static int vert_select_ungrouped_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); Mesh *mesh = static_cast(ob->data); - if (BLI_listbase_is_empty(&mesh->vertex_group_names) || (BKE_mesh_deform_verts(mesh) == nullptr)) - { + if (BLI_listbase_is_empty(&mesh->vertex_group_names) || mesh->deform_verts().is_empty()) { BKE_report(op->reports, RPT_ERROR, "No weights/vertex groups on object"); return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc index 339b464cdb5..c1ab61d4f91 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc @@ -175,7 +175,7 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, const wmEvent *even ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph); mesh = BKE_mesh_from_object(vc.obact); - const MDeformVert *dvert = BKE_mesh_deform_verts(mesh); + const MDeformVert *dvert = mesh->deform_verts().data(); if (mesh && dvert && vc.v3d && vc.rv3d && (mesh->vertex_group_active_index != 0)) { const bool use_vert_sel = (mesh->editflag & ME_EDIT_PAINT_VERT_SEL) != 0; @@ -320,7 +320,7 @@ static int weight_sample_group_invoke(bContext *C, wmOperator *op, const wmEvent BLI_assert(vc.v3d && vc.rv3d); /* Ensured by poll. */ Mesh *mesh = BKE_mesh_from_object(vc.obact); - const MDeformVert *dverts = BKE_mesh_deform_verts(mesh); + const MDeformVert *dverts = mesh->deform_verts().data(); if (BLI_listbase_is_empty(&mesh->vertex_group_names) || (dverts == nullptr)) { BKE_report(op->reports, RPT_WARNING, "No vertex group data"); return OPERATOR_CANCELLED; @@ -416,7 +416,7 @@ static bool weight_paint_set(Object *ob, float paintweight) const blender::OffsetIndices faces = mesh->faces(); const blender::Span corner_verts = mesh->corner_verts(); - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + MDeformVert *dvert = mesh->deform_verts_for_write().data(); if (mesh->faces_num == 0 || dvert == nullptr) { return false; @@ -722,7 +722,7 @@ static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEven if (vert_cache != nullptr) { Mesh *mesh = static_cast(ob->data); if (vert_cache->wpp.wpaint_prev) { - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + MDeformVert *dvert = mesh->deform_verts_for_write().data(); BKE_defvert_array_free_elems(dvert, mesh->totvert); BKE_defvert_array_copy(dvert, vert_cache->wpp.wpaint_prev, mesh->totvert); wpaint_prev_destroy(&vert_cache->wpp); @@ -750,7 +750,7 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Mesh *mesh = static_cast(ob->data); - MDeformVert *dverts = BKE_mesh_deform_verts_for_write(mesh); + MDeformVert *dverts = mesh->deform_verts_for_write().data(); int x_start = RNA_int_get(op->ptr, "xstart"); int y_start = RNA_int_get(op->ptr, "ystart"); int x_end = RNA_int_get(op->ptr, "xend"); diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.cc b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.cc index b75550dded6..e00ca516f1e 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.cc @@ -60,7 +60,7 @@ bool ED_wpaint_ensure_data(bContext *C, } /* If nothing was added yet, we make deform-verts and a vertex deform group. */ - if (BKE_mesh_deform_verts(mesh) == nullptr) { + if (mesh->deform_verts().is_empty()) { BKE_object_defgroup_data_create(&mesh->id); WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh); } diff --git a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc index 20475d22657..14d74b11d29 100644 --- a/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc +++ b/source/blender/gpencil_modifiers_legacy/intern/lineart/lineart_cpu.cc @@ -5357,7 +5357,7 @@ static void lineart_gpencil_generate(LineartCache *cache, if (eval_ob && eval_ob->type == OB_MESH) { int dindex = 0; Mesh *mesh = BKE_object_get_evaluated_mesh(eval_ob); - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + MDeformVert *dvert = mesh->deform_verts_for_write().data(); if (dvert) { LISTBASE_FOREACH (bDeformGroup *, db, &mesh->vertex_group_names) { if ((!source_vgname) || strstr(db->name, source_vgname) == db->name) { diff --git a/source/blender/io/collada/ArmatureExporter.cpp b/source/blender/io/collada/ArmatureExporter.cpp index efd3f0f3256..713b3ce7d26 100644 --- a/source/blender/io/collada/ArmatureExporter.cpp +++ b/source/blender/io/collada/ArmatureExporter.cpp @@ -115,7 +115,7 @@ bool ArmatureExporter::add_instance_controller(Object *ob) ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id)); Mesh *mesh = (Mesh *)ob->data; - if (BKE_mesh_deform_verts(mesh) == nullptr) { + if (mesh->deform_verts().is_empty()) { return false; } diff --git a/source/blender/io/collada/ControllerExporter.cpp b/source/blender/io/collada/ControllerExporter.cpp index 0c115cc03e0..5e5bb2582c4 100644 --- a/source/blender/io/collada/ControllerExporter.cpp +++ b/source/blender/io/collada/ControllerExporter.cpp @@ -66,7 +66,7 @@ bool ControllerExporter::add_instance_controller(Object *ob) ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id)); Mesh *mesh = (Mesh *)ob->data; - if (BKE_mesh_deform_verts(mesh) == nullptr) { + if (mesh->deform_verts().is_empty()) { return false; } @@ -162,7 +162,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) bool use_instantiation = this->export_settings.get_use_object_instantiation(); Mesh *mesh; - if (BKE_mesh_deform_verts((Mesh *)ob->data) == nullptr) { + if (((Mesh *)ob->data)->deform_verts().is_empty()) { return; } @@ -205,7 +205,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) } } - const MDeformVert *dvert = BKE_mesh_deform_verts(mesh); + const MDeformVert *dvert = mesh->deform_verts().data(); int oob_counter = 0; for (i = 0; i < mesh->totvert; i++) { const MDeformVert *vert = &dvert[i]; diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index 8f0f45816a7..84222d1de59 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -18,7 +18,7 @@ #include "MEM_guardedalloc.h" -#include "BKE_attribute.h" +#include "BKE_attribute.hh" #include "BKE_customdata.hh" #include "BKE_displist.h" #include "BKE_global.h" @@ -601,6 +601,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *mesh, blender::Vector &loop_normals) { + using namespace blender; uint i; allocate_poly_data(collada_mesh, mesh); @@ -615,7 +616,10 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, MaterialIdPrimitiveArrayMap mat_prim_map; - int *material_indices = BKE_mesh_material_indices_for_write(mesh); + bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); + bke::SpanAttributeWriter material_indices = attributes.lookup_or_add_for_write_span( + "material_index", ATTR_DOMAIN_FACE); + bool *sharp_faces = static_cast(CustomData_get_layer_named_for_write( &mesh->face_data, CD_PROP_BOOL, "sharp_face", mesh->faces_num)); if (!sharp_faces) { @@ -642,7 +646,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, /* Since we cannot set `poly->mat_nr` here, we store a portion of `mesh->mpoly` in Primitive. */ - Primitive prim = {face_index, &material_indices[face_index], 0}; + Primitive prim = {face_index, &material_indices.span[face_index], 0}; /* If MeshPrimitive is TRIANGLE_FANS we split it into triangles * The first triangle-fan vertex will be the first vertex in every triangle @@ -800,6 +804,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, } geom_uid_mat_mapping_map[collada_mesh->getUniqueId()] = mat_prim_map; + material_indices.finish(); } void MeshImporter::get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride) diff --git a/source/blender/io/usd/hydra/mesh.cc b/source/blender/io/usd/hydra/mesh.cc index 1239c12b258..89fbd626735 100644 --- a/source/blender/io/usd/hydra/mesh.cc +++ b/source/blender/io/usd/hydra/mesh.cc @@ -10,7 +10,7 @@ #include "BLI_string.h" #include "BLI_vector_set.hh" -#include "BKE_attribute.h" +#include "BKE_attribute.hh" #include "BKE_material.h" #include "BKE_mesh.hh" #include "BKE_mesh_runtime.hh" @@ -373,21 +373,20 @@ void MeshData::write_submeshes(const Mesh *mesh) const Span corner_verts = mesh->corner_verts(); const Span looptris = mesh->looptris(); const Span looptri_faces = mesh->looptri_faces(); - const std::pair> normals = get_mesh_normals(*mesh); + const bke::AttributeAccessor attributes = mesh->attributes(); + const StringRef active_uv = CustomData_get_active_layer_name(&mesh->loop_data, CD_PROP_FLOAT2); + const VArraySpan uv_map = *attributes.lookup(active_uv, ATTR_DOMAIN_CORNER); + const VArraySpan material_indices = *attributes.lookup("material_index", ATTR_DOMAIN_FACE); - const float2 *uv_map = static_cast( - CustomData_get_layer(&mesh->loop_data, CD_PROP_FLOAT2)); - - const int *material_indices = BKE_mesh_material_indices(mesh); - if (!material_indices) { + if (material_indices.is_empty()) { copy_submesh(*mesh, vert_positions, corner_verts, looptris, looptri_faces, normals, - uv_map ? Span(uv_map, mesh->totloop) : Span(), + uv_map, looptris.index_range(), submeshes_.first()); return; @@ -410,7 +409,7 @@ void MeshData::write_submeshes(const Mesh *mesh) looptris, looptri_faces, normals, - uv_map ? Span(uv_map, mesh->totloop) : Span(), + uv_map, triangles_by_material[i], submeshes_[i]); } diff --git a/source/blender/makesrna/intern/rna_mesh.cc b/source/blender/makesrna/intern/rna_mesh.cc index f09d09579bf..40b090302a6 100644 --- a/source/blender/makesrna/intern/rna_mesh.cc +++ b/source/blender/makesrna/intern/rna_mesh.cc @@ -55,6 +55,7 @@ static const EnumPropertyItem rna_enum_mesh_remesh_mode_items[] = { # include "BLI_math_vector.h" +# include "BKE_attribute.hh" # include "BKE_customdata.hh" # include "BKE_main.hh" # include "BKE_mesh.hh" @@ -628,18 +629,23 @@ static void rna_MeshPolygon_select_set(PointerRNA *ptr, bool value) static int rna_MeshPolygon_material_index_get(PointerRNA *ptr) { + using namespace blender; const Mesh *mesh = rna_mesh(ptr); - const int *material_indices = BKE_mesh_material_indices(mesh); - const int index = rna_MeshPolygon_index_get(ptr); - return material_indices == nullptr ? 0 : material_indices[index]; + const bke::AttributeAccessor attributes = mesh->attributes(); + const VArray material_index = *attributes.lookup_or_default( + "material_index", ATTR_DOMAIN_FACE, 0); + return material_index[rna_MeshPolygon_index_get(ptr)]; } static void rna_MeshPolygon_material_index_set(PointerRNA *ptr, int value) { + using namespace blender; Mesh *mesh = rna_mesh(ptr); - int *material_indices = BKE_mesh_material_indices_for_write(mesh); - const int index = rna_MeshPolygon_index_get(ptr); - material_indices[index] = max_ii(0, value); + bke::MutableAttributeAccessor attributes = mesh->attributes_for_write(); + bke::AttributeWriter material_index = attributes.lookup_or_add_for_write("material_index", + ATTR_DOMAIN_FACE); + material_index.varray.set(rna_MeshPolygon_index_get(ptr), max_ii(0, value)); + material_index.finish(); } static void rna_MeshPolygon_center_get(PointerRNA *ptr, float *values) @@ -765,7 +771,7 @@ static void rna_Mesh_texspace_location_get(PointerRNA *ptr, float values[3]) static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Mesh *mesh = rna_mesh(ptr); - MDeformVert *dverts = (MDeformVert *)BKE_mesh_deform_verts(mesh); + MDeformVert *dverts = mesh->deform_verts_for_write().data(); if (dverts) { const int index = rna_MeshVertex_index_get(ptr); MDeformVert *dvert = &dverts[index]; @@ -1384,10 +1390,12 @@ static bool rna_MeshEdge_is_loose_get(PointerRNA *ptr) static int rna_MeshLoopTriangle_material_index_get(PointerRNA *ptr) { + using namespace blender; const Mesh *mesh = rna_mesh(ptr); - const int face_i = rna_MeshLoopTriangle_polygon_index_get(ptr); - const int *material_indices = BKE_mesh_material_indices(mesh); - return material_indices == nullptr ? 0 : material_indices[face_i]; + const bke::AttributeAccessor attributes = mesh->attributes(); + const VArray material_indices = *attributes.lookup_or_default( + "material_index", ATTR_DOMAIN_FACE, 0); + return material_indices[rna_MeshLoopTriangle_polygon_index_get(ptr)]; } static bool rna_MeshLoopTriangle_use_smooth_get(PointerRNA *ptr) @@ -1405,7 +1413,7 @@ static char *rna_VertexGroupElement_path(const PointerRNA *ptr) { const Mesh *mesh = rna_mesh(ptr); /* XXX not always! */ const MDeformWeight *dw = (MDeformWeight *)ptr->data; - const MDeformVert *dvert = BKE_mesh_deform_verts(mesh); + const MDeformVert *dvert = mesh->deform_verts().data(); int a, b; for (a = 0; a < mesh->totvert; a++, dvert++) { diff --git a/source/blender/modifiers/intern/MOD_array.cc b/source/blender/modifiers/intern/MOD_array.cc index 326344a2df1..8cc77cdcd07 100644 --- a/source/blender/modifiers/intern/MOD_array.cc +++ b/source/blender/modifiers/intern/MOD_array.cc @@ -316,8 +316,8 @@ static void mesh_merge_transform(Mesh *result, } /* remap the vertex groups if necessary */ - if (BKE_mesh_deform_verts(result) != nullptr) { - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(result); + if (!result->deform_verts().is_empty()) { + MDeformVert *dvert = result->deform_verts_for_write().data(); BKE_object_defgroup_index_map_apply(&dvert[cap_verts_index], cap_nverts, remap, remap_len); } diff --git a/source/blender/modifiers/intern/MOD_explode.cc b/source/blender/modifiers/intern/MOD_explode.cc index 971221b24ba..7a5983a4bc2 100644 --- a/source/blender/modifiers/intern/MOD_explode.cc +++ b/source/blender/modifiers/intern/MOD_explode.cc @@ -128,7 +128,7 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p /* set protected verts */ if (emd->vgroup) { - const MDeformVert *dvert = BKE_mesh_deform_verts(mesh); + const MDeformVert *dvert = mesh->deform_verts().data(); if (dvert) { const int defgrp_index = emd->vgroup - 1; for (i = 0; i < totvert; i++, dvert++) { diff --git a/source/blender/modifiers/intern/MOD_meshcache.cc b/source/blender/modifiers/intern/MOD_meshcache.cc index ff81d61e477..dd0938f0a1f 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.cc +++ b/source/blender/modifiers/intern/MOD_meshcache.cc @@ -248,7 +248,7 @@ static void meshcache_do(MeshCacheModifierData *mcmd, const float global_offset = (mcmd->flag & MOD_MESHCACHE_INVERT_VERTEX_GROUP) ? mcmd->factor : 0.0f; - if (BKE_mesh_deform_verts(mesh) != nullptr) { + if (!mesh->deform_verts().is_empty()) { for (int i = 0; i < verts_num; i++) { /* For each vertex, compute its blending factor between the mesh cache (for `fac = 0`) * and the former position of the vertex (for `fac = 1`). */ diff --git a/source/blender/modifiers/intern/MOD_screw.cc b/source/blender/modifiers/intern/MOD_screw.cc index b6e82c2f99e..9c21caf8ead 100644 --- a/source/blender/modifiers/intern/MOD_screw.cc +++ b/source/blender/modifiers/intern/MOD_screw.cc @@ -836,8 +836,13 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh /* more of an offset in this case */ edge_offset = totedge + (totvert * (step_tot - (close ? 0 : 1))); - const int *src_material_index = BKE_mesh_material_indices(mesh); - int *dst_material_index = BKE_mesh_material_indices_for_write(result); + const bke::AttributeAccessor src_attributes = mesh->attributes(); + const VArraySpan src_material_index = *src_attributes.lookup("material_index", + ATTR_DOMAIN_FACE); + + bke::MutableAttributeAccessor dst_attributes = result->attributes_for_write(); + bke::SpanAttributeWriter dst_material_index = dst_attributes.lookup_or_add_for_write_span( + "material_index", ATTR_DOMAIN_FACE); for (uint i = 0; i < totedge; i++, med_new_firstloop++) { const uint step_last = step_tot - (close ? 1 : 2); @@ -858,7 +863,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh i2 = uint((*med_new_firstloop)[1]); if (has_mpoly_orig) { - mat_nr = src_material_index == nullptr ? 0 : src_material_index[face_index_orig]; + mat_nr = src_material_index.is_empty() ? 0 : src_material_index[face_index_orig]; } else { mat_nr = 0; @@ -884,7 +889,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh } else { origindex[face_index] = ORIGINDEX_NONE; - dst_material_index[face_index] = mat_nr; + dst_material_index.span[face_index] = mat_nr; sharp_faces.span[face_index] = use_flat_shading; } face_offests_new[face_index] = face_index * 4; @@ -1026,6 +1031,8 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh ltmd->merge_dist); } + dst_material_index.finish(); + return result; } diff --git a/source/blender/modifiers/intern/MOD_skin.cc b/source/blender/modifiers/intern/MOD_skin.cc index ec8624d3838..ef13280124a 100644 --- a/source/blender/modifiers/intern/MOD_skin.cc +++ b/source/blender/modifiers/intern/MOD_skin.cc @@ -906,7 +906,7 @@ static Mesh *subdivide_base(const Mesh *orig) CustomData_get_layer(&orig->vert_data, CD_MVERT_SKIN)); const blender::Span orig_vert_positions = orig->vert_positions(); const blender::Span orig_edges = orig->edges(); - const MDeformVert *origdvert = BKE_mesh_deform_verts(orig); + const MDeformVert *origdvert = orig->deform_verts().data(); int orig_vert_num = orig->totvert; int orig_edge_num = orig->totedge; @@ -932,7 +932,7 @@ static Mesh *subdivide_base(const Mesh *orig) CustomData_get_layer_for_write(&result->vert_data, CD_MVERT_SKIN, result->totvert)); MDeformVert *outdvert = nullptr; if (origdvert) { - outdvert = BKE_mesh_deform_verts_for_write(result); + outdvert = result->deform_verts_for_write().data(); } /* Copy original vertex data */ @@ -1913,7 +1913,6 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_ BMesh *bm; EMat *emat; SkinNode *skin_nodes; - const MDeformVert *dvert; bool has_valid_root = false; const MVertSkin *nodes = static_cast( @@ -1921,7 +1920,7 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_ const blender::Span vert_positions = origmesh->vert_positions(); const blender::Span edges = origmesh->edges(); - dvert = BKE_mesh_deform_verts(origmesh); + const MDeformVert *dvert = origmesh->deform_verts().data(); const int verts_num = origmesh->totvert; blender::Array vert_to_edge_offsets; diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.cc b/source/blender/modifiers/intern/MOD_solidify_extrude.cc index 147637b1d71..fc7b579c6c3 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.cc +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.cc @@ -19,6 +19,7 @@ #include "MEM_guardedalloc.h" +#include "BKE_attribute.hh" #include "BKE_deform.h" #include "BKE_mesh.hh" #include "BKE_particle.h" @@ -144,6 +145,7 @@ static void mesh_calc_hq_normal(Mesh *mesh, /* NOLINTNEXTLINE: readability-function-size */ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) { + using namespace blender; Mesh *result; const SolidifyModifierData *smd = (SolidifyModifierData *)md; @@ -415,7 +417,9 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } \ (void)0 - int *dst_material_index = BKE_mesh_material_indices_for_write(result); + bke::MutableAttributeAccessor dst_attributes = mesh->attributes_for_write(); + bke::SpanAttributeWriter dst_material_index = dst_attributes.lookup_or_add_for_write_span( + "material_index", ATTR_DOMAIN_FACE); /* flip normals */ @@ -451,8 +455,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex #endif if (mat_ofs) { - dst_material_index[faces_num + i] += mat_ofs; - CLAMP(dst_material_index[faces_num + i], 0, mat_nr_max); + dst_material_index.span[faces_num + i] += mat_ofs; + CLAMP(dst_material_index.span[faces_num + i], 0, mat_nr_max); } e = corner_edges[corner_2 + 0]; @@ -982,7 +986,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* Add vertex weights for rim and shell vgroups. */ if (shell_defgrp_index != -1 || rim_defgrp_index != -1) { - MDeformVert *dst_dvert = BKE_mesh_deform_verts_for_write(result); + MDeformVert *dst_dvert = result->deform_verts_for_write().data(); /* Ultimate security check. */ if (dst_dvert != nullptr) { @@ -1121,8 +1125,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* use the next material index if option enabled */ if (mat_ofs_rim) { - dst_material_index[new_face_index] += mat_ofs_rim; - CLAMP(dst_material_index[new_face_index], 0, mat_nr_max); + dst_material_index.span[new_face_index] += mat_ofs_rim; + CLAMP(dst_material_index.span[new_face_index], 0, mat_nr_max); } if (crease_outer) { /* crease += crease_outer; without wrapping */ @@ -1152,6 +1156,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex MEM_freeN(old_vert_arr); } + dst_material_index.finish(); + return result; } diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc index 189f5a0bb9b..ddcabe22637 100644 --- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc +++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.cc @@ -2014,7 +2014,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Checks that result has dvert data. */ MDeformVert *dst_dvert = nullptr; if (shell_defgrp_index != -1 || rim_defgrp_index != -1) { - dst_dvert = BKE_mesh_deform_verts_for_write(result); + dst_dvert = result->deform_verts_for_write().data(); } /* Get vertex crease layer and ensure edge creases are active if vertex creases are found, since @@ -2148,9 +2148,12 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } } #endif - - const int *src_material_index = BKE_mesh_material_indices(mesh); - int *dst_material_index = BKE_mesh_material_indices_for_write(result); + const bke::AttributeAccessor src_attributes = mesh->attributes(); + const VArraySpan src_material_index = *src_attributes.lookup("material_index", + ATTR_DOMAIN_FACE); + bke::MutableAttributeAccessor dst_attributes = result->attributes_for_write(); + bke::SpanAttributeWriter dst_material_index = dst_attributes.lookup_or_add_for_write_span( + "material_index", ATTR_DOMAIN_FACE); /* Make boundary edges/faces. */ { @@ -2293,20 +2296,24 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, for (EdgeGroup *g3 = g2; g3->valid && k < j; g3++) { if ((do_rim && !g3->is_orig_closed) || (do_shell && g3->split)) { /* Check both far ends in terms of faces of an edge group. */ - if ((src_material_index ? src_material_index[g3->edges[0]->faces[0]->index] : - 0) == l) { + if ((!src_material_index.is_empty() ? + src_material_index[g3->edges[0]->faces[0]->index] : + 0) == l) { face = g3->edges[0]->faces[0]->index; count++; } NewEdgeRef *le = g3->edges[g3->edges_len - 1]; if (le->faces[1] && - (src_material_index ? src_material_index[le->faces[1]->index] : 0) == l) { + (!src_material_index.is_empty() ? src_material_index[le->faces[1]->index] : + 0) == l) + { face = le->faces[1]->index; count++; } - else if (!le->faces[1] && - (src_material_index ? src_material_index[le->faces[0]->index] : 0) == - l) { + else if (!le->faces[1] && (!src_material_index.is_empty() ? + src_material_index[le->faces[0]->index] : + 0) == l) + { face = le->faces[0]->index; count++; } @@ -2325,9 +2332,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, origindex_face[face_index] = ORIGINDEX_NONE; } face_offsets[face_index] = int(loop_index); - dst_material_index[face_index] = most_mat_nr + - (g->is_orig_closed || !do_rim ? 0 : mat_ofs_rim); - CLAMP(dst_material_index[face_index], 0, mat_nr_max); + dst_material_index.span[face_index] = most_mat_nr + (g->is_orig_closed || !do_rim ? + 0 : + mat_ofs_rim); + CLAMP(dst_material_index.span[face_index], 0, mat_nr_max); face_index++; for (uint k = 0; g2->valid && k < j; g2++) { @@ -2401,9 +2409,11 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, int(face_index), 1); face_offsets[face_index] = int(loop_index); - dst_material_index[face_index] = - (src_material_index ? src_material_index[orig_face_index] : 0) + mat_ofs_rim; - CLAMP(dst_material_index[face_index], 0, mat_nr_max); + dst_material_index.span[face_index] = (!src_material_index.is_empty() ? + src_material_index[orig_face_index] : + 0) + + mat_ofs_rim; + CLAMP(dst_material_index.span[face_index], 0, mat_nr_max); face_index++; int loop1 = -1; @@ -2593,10 +2603,11 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, CustomData_copy_data( &mesh->face_data, &result->face_data, int(i / 2), int(face_index), 1); face_offsets[face_index] = int(loop_index); - dst_material_index[face_index] = (src_material_index ? src_material_index[fr->index] : - 0) + - (fr->reversed != do_flip ? mat_ofs : 0); - CLAMP(dst_material_index[face_index], 0, mat_nr_max); + dst_material_index.span[face_index] = (!src_material_index.is_empty() ? + src_material_index[fr->index] : + 0) + + (fr->reversed != do_flip ? mat_ofs : 0); + CLAMP(dst_material_index.span[face_index], 0, mat_nr_max); if (fr->reversed != do_flip) { for (int l = int(k) - 1; l >= 0; l--) { if (shell_defgrp_index != -1) { @@ -2686,6 +2697,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, #undef MOD_SOLIDIFY_EMPTY_TAG + dst_material_index.finish(); + return result; } diff --git a/source/blender/modifiers/intern/MOD_util.cc b/source/blender/modifiers/intern/MOD_util.cc index 2664656fd63..5dc444fdd5f 100644 --- a/source/blender/modifiers/intern/MOD_util.cc +++ b/source/blender/modifiers/intern/MOD_util.cc @@ -170,7 +170,7 @@ void MOD_get_vgroup(const Object *ob, if (mesh) { *defgrp_index = BKE_id_defgroup_name_index(&mesh->id, name); if (*defgrp_index != -1) { - *dvert = BKE_mesh_deform_verts(mesh); + *dvert = mesh->deform_verts().data(); } else { *dvert = nullptr; diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.cc b/source/blender/modifiers/intern/MOD_weightvgedit.cc index 88fffbe70e7..548c48c0cbc 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.cc +++ b/source/blender/modifiers/intern/MOD_weightvgedit.cc @@ -193,7 +193,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh } } - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + MDeformVert *dvert = mesh->deform_verts_for_write().data(); /* Ultimate security check. */ if (!dvert) { diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.cc b/source/blender/modifiers/intern/MOD_weightvgmix.cc index ce53ed538cb..f364f6525de 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.cc +++ b/source/blender/modifiers/intern/MOD_weightvgmix.cc @@ -257,7 +257,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh } } - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + MDeformVert *dvert = mesh->deform_verts_for_write().data(); /* Ultimate security check. */ if (!dvert) { diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.cc b/source/blender/modifiers/intern/MOD_weightvgproximity.cc index 41b14f80ef9..1ac5967c4bb 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.cc +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.cc @@ -477,7 +477,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh return mesh; } - MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + MDeformVert *dvert = mesh->deform_verts_for_write().data(); /* Ultimate security check. */ if (!dvert) { return mesh; diff --git a/source/blender/render/intern/bake.cc b/source/blender/render/intern/bake.cc index 97c36b58973..6456b0e2c48 100644 --- a/source/blender/render/intern/bake.cc +++ b/source/blender/render/intern/bake.cc @@ -720,6 +720,7 @@ void RE_bake_pixels_populate(Mesh *mesh, const BakeTargets *targets, const char *uv_layer) { + using namespace blender; const float(*mloopuv)[2]; if ((uv_layer == nullptr) || (uv_layer[0] == '\0')) { mloopuv = static_cast( @@ -756,8 +757,9 @@ void RE_bake_pixels_populate(Mesh *mesh, mesh->vert_positions(), mesh->faces(), mesh->corner_verts(), {looptri, tottri}); const blender::Span looptri_faces = mesh->looptri_faces(); + const bke::AttributeAccessor attributes = mesh->attributes(); + const VArraySpan material_indices = *attributes.lookup("material_index", ATTR_DOMAIN_FACE); - const int *material_indices = BKE_mesh_material_indices(mesh); const int materials_num = targets->materials_num; for (int i = 0; i < tottri; i++) { @@ -767,7 +769,7 @@ void RE_bake_pixels_populate(Mesh *mesh, bd.primitive_id = i; /* Find images matching this material. */ - const int material_index = (material_indices && materials_num) ? + const int material_index = (!material_indices.is_empty() && materials_num) ? clamp_i(material_indices[face_i], 0, materials_num - 1) : 0; Image *image = targets->material_to_image[material_index];