diff options
Diffstat (limited to 'source/blender/blenkernel/intern/DerivedMesh.cc')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.cc | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc index bfdfc447baf..2730873c7e8 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.cc +++ b/source/blender/blenkernel/intern/DerivedMesh.cc @@ -92,18 +92,19 @@ static void editbmesh_calc_modifier_final_normals_or_defer( /* -------------------------------------------------------------------- */ -static MVert *dm_getVertArray(DerivedMesh *dm) +static float *dm_getVertArray(DerivedMesh *dm) { - MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT); + float(*positions)[3] = (float(*)[3])CustomData_get_layer_named( + &dm->vertData, CD_PROP_FLOAT3, "position"); - if (!mvert) { - mvert = (MVert *)CustomData_add_layer( - &dm->vertData, CD_MVERT, CD_SET_DEFAULT, nullptr, dm->getNumVerts(dm)); - CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY); - dm->copyVertArray(dm, mvert); + if (!positions) { + positions = (float(*)[3])CustomData_add_layer_named( + &dm->vertData, CD_PROP_FLOAT3, CD_SET_DEFAULT, nullptr, dm->getNumVerts(dm), "position"); + CustomData_set_layer_flag(&dm->vertData, CD_PROP_FLOAT3, CD_FLAG_TEMPORARY); + dm->copyVertArray(dm, positions); } - return mvert; + return (float *)positions; } static MEdge *dm_getEdgeArray(DerivedMesh *dm) @@ -350,10 +351,6 @@ static void mesh_set_only_copy(Mesh *mesh, const CustomData_MeshMasks *mask) void *DM_get_vert_data_layer(DerivedMesh *dm, int type) { - if (type == CD_MVERT) { - return dm->getVertArray(dm); - } - return CustomData_get_layer(&dm->vertData, type); } @@ -673,10 +670,8 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph, BLI_assert((mesh_input->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0); - /* Deformed vertex locations array. Deform only modifier need this type of - * float array rather than MVert*. Tracked along with mesh_final as an - * optimization to avoid copying coordinates back and forth if there are - * multiple sequential deform only modifiers. */ + /* TODO: Remove use of "deformed_verts" in mesh modifier stack since mesh positions are now in a + * contiguous array. */ float(*deformed_verts)[3] = nullptr; int num_deformed_verts = mesh_input->totvert; bool isPrevDeform = false; @@ -1931,9 +1926,9 @@ void mesh_get_mapped_verts_coords(Mesh *me_eval, float (*r_cos)[3], const int to MEM_freeN(userData.vertex_visit); } else { - const Span<MVert> verts = me_eval->verts(); + const Span<float3> positions = me_eval->positions(); for (int i = 0; i < totcos; i++) { - copy_v3_v3(r_cos[i], verts[i].co); + copy_v3_v3(r_cos[i], positions[i]); } } } @@ -1946,7 +1941,7 @@ static void mesh_init_origspace(Mesh *mesh) CD_ORIGSPACE_MLOOP); const int numpoly = mesh->totpoly; // const int numloop = mesh->totloop; - const Span<MVert> verts = mesh->verts(); + const Span<float3> positions = mesh->positions(); const Span<MPoly> polys = mesh->polys(); const Span<MLoop> loops = mesh->loops(); @@ -1971,12 +1966,13 @@ static void mesh_init_origspace(Mesh *mesh) float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX}; float translate[2], scale[2]; - BKE_mesh_calc_poly_normal(mp, l, verts.data(), p_nor); + BKE_mesh_calc_poly_normal( + mp, l, reinterpret_cast<const float(*)[3]>(positions.data()), p_nor); axis_dominant_v3_to_m3(mat, p_nor); vcos_2d.resize(mp->totloop); for (j = 0; j < mp->totloop; j++, l++) { - mul_v3_m3v3(co, mat, verts[l->v].co); + mul_v3_m3v3(co, mat, positions[l->v]); copy_v2_v2(vcos_2d[j], co); for (k = 0; k < 2; k++) { |