diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-06 05:17:28 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-06 05:17:28 +0300 |
commit | cfe35802aaa22b6aaf78b840c8b7410e8bef0376 (patch) | |
tree | 49bbea7d7d173784aa80dc4297af976a5f248bb6 /source/blender/modifiers/intern | |
parent | 250f174ce3de776faa9940a1e68542199d26378a (diff) | |
parent | 1fcc673230bf585b2b0239d4476b94523bd0ec21 (diff) |
Merge branch 'master' into refactor-mesh-uv-map-generic
Diffstat (limited to 'source/blender/modifiers/intern')
45 files changed, 720 insertions, 687 deletions
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index 7f3c89fe13f..36988f07ef4 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -279,13 +279,17 @@ static void mesh_merge_transform(Mesh *result, MEdge *me; MLoop *ml; MPoly *mp; + MVert *result_verts = BKE_mesh_vertices_for_write(result); + MEdge *result_edges = BKE_mesh_edges_for_write(result); + MPoly *result_polys = BKE_mesh_polygons_for_write(result); + MLoop *result_loops = BKE_mesh_loops_for_write(result); CustomData_copy_data(&cap_mesh->vdata, &result->vdata, 0, cap_verts_index, cap_nverts); CustomData_copy_data(&cap_mesh->edata, &result->edata, 0, cap_edges_index, cap_nedges); CustomData_copy_data(&cap_mesh->ldata, &result->ldata, 0, cap_loops_index, cap_nloops); CustomData_copy_data(&cap_mesh->pdata, &result->pdata, 0, cap_polys_index, cap_npolys); - mv = result->mvert + cap_verts_index; + mv = result_verts + cap_verts_index; for (i = 0; i < cap_nverts; i++, mv++) { mul_m4_v3(cap_offset, mv->co); @@ -303,26 +307,26 @@ static void mesh_merge_transform(Mesh *result, } /* remap the vertex groups if necessary */ - if (result->dvert != NULL) { - BKE_object_defgroup_index_map_apply( - &result->dvert[cap_verts_index], cap_nverts, remap, remap_len); + if (BKE_mesh_deform_verts(result) != NULL) { + MDeformVert *dvert = BKE_mesh_deform_verts_for_write(result); + BKE_object_defgroup_index_map_apply(&dvert[cap_verts_index], cap_nverts, remap, remap_len); } /* adjust cap edge vertex indices */ - me = result->medge + cap_edges_index; + me = result_edges + cap_edges_index; for (i = 0; i < cap_nedges; i++, me++) { me->v1 += cap_verts_index; me->v2 += cap_verts_index; } /* adjust cap poly loopstart indices */ - mp = result->mpoly + cap_polys_index; + mp = result_polys + cap_polys_index; for (i = 0; i < cap_npolys; i++, mp++) { mp->loopstart += cap_loops_index; } /* adjust cap loop vertex and edge indices */ - ml = result->mloop + cap_loops_index; + ml = result_loops + cap_loops_index; for (i = 0; i < cap_nloops; i++, ml++) { ml->v += cap_verts_index; ml->e += cap_edges_index; @@ -352,11 +356,8 @@ static void mesh_merge_transform(Mesh *result, static Mesh *arrayModifier_doArray(ArrayModifierData *amd, const ModifierEvalContext *ctx, - Mesh *mesh) + const Mesh *mesh) { - const MVert *src_mvert; - MVert *result_dm_verts; - MEdge *me; MLoop *ml; MPoly *mp; @@ -429,7 +430,10 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, /* Build up offset array, accumulating all settings options. */ unit_m4(offset); - src_mvert = mesh->mvert; + const MVert *src_verts = BKE_mesh_vertices(mesh); + const MEdge *src_edges = BKE_mesh_edges(mesh); + const MPoly *src_polys = BKE_mesh_polygons(mesh); + const MLoop *src_loops = BKE_mesh_loops(mesh); if (amd->offset_type & MOD_ARR_OFF_CONST) { add_v3_v3(offset[3], amd->offset); @@ -440,7 +444,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, const MVert *src_mv; INIT_MINMAX(min, max); - for (src_mv = src_mvert, j = chunk_nverts; j--; src_mv++) { + for (src_mv = src_verts, j = chunk_nverts; j--; src_mv++) { minmax_v3v3_v3(min, max, src_mv->co); } @@ -539,7 +543,10 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, /* Initialize a result dm */ result = BKE_mesh_new_nomain_from_template( mesh, result_nverts, result_nedges, 0, result_nloops, result_npolys); - result_dm_verts = result->mvert; + MVert *result_verts = BKE_mesh_vertices_for_write(result); + MEdge *result_edges = BKE_mesh_edges_for_write(result); + MPoly *result_polys = BKE_mesh_polygons_for_write(result); + MLoop *result_loops = BKE_mesh_loops_for_write(result); if (use_merge) { /* Will need full_doubles_map for handling merge */ @@ -556,14 +563,14 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, /* Subsurf for eg won't have mesh data in the custom data arrays. * now add mvert/medge/mpoly layers. */ if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) { - memcpy(result->mvert, mesh->mvert, sizeof(*result->mvert) * mesh->totvert); + memcpy(result_verts, src_verts, sizeof(MVert) * mesh->totvert); } if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) { - memcpy(result->medge, mesh->medge, sizeof(*result->medge) * mesh->totedge); + memcpy(result_edges, src_edges, sizeof(MEdge) * mesh->totedge); } if (!CustomData_has_layer(&mesh->pdata, CD_MPOLY)) { - memcpy(result->mloop, mesh->mloop, sizeof(*result->mloop) * mesh->totloop); - memcpy(result->mpoly, mesh->mpoly, sizeof(*result->mpoly) * mesh->totpoly); + memcpy(result_loops, src_loops, sizeof(MLoop) * mesh->totloop); + memcpy(result_polys, src_polys, sizeof(MPoly) * mesh->totpoly); } /* Remember first chunk, in case of cap merge */ @@ -594,7 +601,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, /* apply offset to all new verts */ for (i = 0; i < chunk_nverts; i++) { const int i_dst = vert_offset + i; - mul_m4_v3(current_offset, result_dm_verts[i_dst].co); + mul_m4_v3(current_offset, result_verts[i_dst].co); /* We have to correct normals too, if we do not tag them as dirty! */ if (!use_recalc_normals) { @@ -605,19 +612,19 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, } /* adjust edge vertex indices */ - me = result->medge + c * chunk_nedges; + me = result_edges + c * chunk_nedges; for (i = 0; i < chunk_nedges; i++, me++) { me->v1 += c * chunk_nverts; me->v2 += c * chunk_nverts; } - mp = result->mpoly + c * chunk_npolys; + mp = result_polys + c * chunk_npolys; for (i = 0; i < chunk_npolys; i++, mp++) { mp->loopstart += c * chunk_nloops; } /* adjust loop vertex and edge indices */ - ml = result->mloop + c * chunk_nloops; + ml = result_loops + c * chunk_nloops; for (i = 0; i < chunk_nloops; i++, ml++) { ml->v += c * chunk_nverts; ml->e += c * chunk_nedges; @@ -638,8 +645,8 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, while (target != -1 && !ELEM(full_doubles_map[target], -1, target)) { /* If target is already mapped, we only follow that mapping if final target remains * close enough from current vert (otherwise no mapping at all). */ - if (compare_len_v3v3(result_dm_verts[this_chunk_index].co, - result_dm_verts[full_doubles_map[target]].co, + if (compare_len_v3v3(result_verts[this_chunk_index].co, + result_verts[full_doubles_map[target]].co, amd->merge_dist)) { target = full_doubles_map[target]; } @@ -653,7 +660,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, } else { dm_mvert_map_doubles(full_doubles_map, - result_dm_verts, + result_verts, (c - 1) * chunk_nverts, chunk_nverts, c * chunk_nverts, @@ -691,7 +698,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, if (use_merge && (amd->flags & MOD_ARR_MERGEFINAL) && (count > 1)) { /* Merge first and last copies */ dm_mvert_map_doubles(full_doubles_map, - result_dm_verts, + result_verts, last_chunk_start, last_chunk_nverts, first_chunk_start, @@ -721,7 +728,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, /* Identify doubles with first chunk */ if (use_merge) { dm_mvert_map_doubles(full_doubles_map, - result_dm_verts, + result_verts, first_chunk_start, first_chunk_nverts, start_cap_start, @@ -751,7 +758,7 @@ static Mesh *arrayModifier_doArray(ArrayModifierData *amd, /* Identify doubles with last chunk */ if (use_merge) { dm_mvert_map_doubles(full_doubles_map, - result_dm_verts, + result_verts, last_chunk_start, last_chunk_nverts, end_cap_start, diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 94f2090e081..ee9a2856ab0 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -88,7 +88,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * BMVert *v; float weight, weight2; int vgroup = -1; - MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; BevelModifierData *bmd = (BevelModifierData *)md; const float threshold = cosf(bmd->bevel_angle + 0.000000175f); const bool do_clamp = !(bmd->flags & MOD_BEVEL_OVERLAP_OK); diff --git a/source/blender/modifiers/intern/MOD_boolean.cc b/source/blender/modifiers/intern/MOD_boolean.cc index 685338cf351..39667a3f1d5 100644 --- a/source/blender/modifiers/intern/MOD_boolean.cc +++ b/source/blender/modifiers/intern/MOD_boolean.cc @@ -144,11 +144,9 @@ static Mesh *get_quick_mesh( invert_m4_m4(imat, ob_self->obmat); mul_m4_m4m4(omat, imat, ob_operand_ob->obmat); - const int mverts_len = result->totvert; - MVert *mv = result->mvert; - - for (int i = 0; i < mverts_len; i++, mv++) { - mul_m4_v3(omat, mv->co); + MutableSpan<MVert> verts = result->vertices_for_write(); + for (const int i : verts.index_range()) { + mul_m4_v3(omat, verts[i].co); } BKE_mesh_tag_coords_changed(result); diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c index a9b6af967be..02d56560fc5 100644 --- a/source/blender/modifiers/intern/MOD_build.c +++ b/source/blender/modifiers/intern/MOD_build.c @@ -62,7 +62,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct int *vertMap, *edgeMap, *faceMap; float frac; MPoly *mpoly_dst; - MLoop *ml_dst, *ml_src /*, *mloop_dst */; + MLoop *ml_dst; + const MLoop *ml_src; GHashIterator gh_iter; /* maps vert indices in old mesh to indices in new mesh */ GHash *vertHash = BLI_ghash_int_new("build ve apply gh"); @@ -74,10 +75,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct const int vert_src_num = mesh->totvert; const int edge_src_num = mesh->totedge; const int poly_src_num = mesh->totpoly; - MPoly *mpoly_src = mesh->mpoly; - MLoop *mloop_src = mesh->mloop; - MEdge *medge_src = mesh->medge; - MVert *mvert_src = mesh->mvert; + const MVert *mvert_src = BKE_mesh_vertices(mesh); + const MEdge *medge_src = BKE_mesh_edges(mesh); + const MPoly *mpoly_src = BKE_mesh_polygons(mesh); + const MLoop *mloop_src = BKE_mesh_loops(mesh); vertMap = MEM_malloc_arrayN(vert_src_num, sizeof(*vertMap), "build modifier vertMap"); edgeMap = MEM_malloc_arrayN(edge_src_num, sizeof(*edgeMap), "build modifier edgeMap"); @@ -99,8 +100,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct /* if there's at least one face, build based on faces */ if (faces_dst_num) { - MPoly *mpoly, *mp; - MLoop *ml, *mloop; + const MPoly *mpoly, *mp; + const MLoop *ml, *mloop; uintptr_t hash_num, hash_num_alt; if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) { @@ -135,7 +136,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct hash_num = 0; hash_num_alt = 0; for (i = 0; i < edge_src_num; i++, hash_num_alt++) { - MEdge *me = medge_src + i; + const MEdge *me = medge_src + i; if (BLI_ghash_haskey(vertHash, POINTER_FROM_INT(me->v1)) && BLI_ghash_haskey(vertHash, POINTER_FROM_INT(me->v2))) { @@ -147,7 +148,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct BLI_assert(hash_num == BLI_ghash_len(edgeHash)); } else if (edges_dst_num) { - MEdge *medge, *me; + const MEdge *medge, *me; uintptr_t hash_num; if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) { @@ -201,6 +202,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct /* now we know the number of verts, edges and faces, we can create the mesh. */ result = BKE_mesh_new_nomain_from_template( mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash), 0, loops_dst_num, faces_dst_num); + MVert *result_verts = BKE_mesh_vertices_for_write(result); + MEdge *result_edges = BKE_mesh_edges_for_write(result); + MPoly *result_polys = BKE_mesh_polygons_for_write(result); + MLoop *result_loops = BKE_mesh_loops_for_write(result); /* copy the vertices across */ GHASH_ITER (gh_iter, vertHash) { @@ -210,7 +215,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct int newIndex = POINTER_AS_INT(BLI_ghashIterator_getValue(&gh_iter)); source = mvert_src[oldIndex]; - dest = &result->mvert[newIndex]; + dest = &result_verts[newIndex]; CustomData_copy_data(&mesh->vdata, &result->vdata, oldIndex, newIndex, 1); *dest = source; @@ -223,7 +228,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct int oldIndex = POINTER_AS_INT(BLI_ghash_lookup(edgeHash, POINTER_FROM_INT(i))); source = medge_src[oldIndex]; - dest = &result->medge[i]; + dest = &result_edges[i]; source.v1 = POINTER_AS_INT(BLI_ghash_lookup(vertHash, POINTER_FROM_INT(source.v1))); source.v2 = POINTER_AS_INT(BLI_ghash_lookup(vertHash, POINTER_FROM_INT(source.v2))); @@ -232,13 +237,13 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, struct *dest = source; } - mpoly_dst = result->mpoly; - ml_dst = result->mloop; + mpoly_dst = result_polys; + ml_dst = result_loops; /* copy the faces across, remapping indices */ k = 0; for (i = 0; i < faces_dst_num; i++) { - MPoly *source; + const MPoly *source; MPoly *dest; source = mpoly_src + faceMap[i]; diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c index e17a612376d..3f0c212999f 100644 --- a/source/blender/modifiers/intern/MOD_cast.c +++ b/source/blender/modifiers/intern/MOD_cast.c @@ -98,7 +98,7 @@ static void sphere_do(CastModifierData *cmd, float (*vertexCos)[3], int verts_num) { - MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; const bool invert_vgroup = (cmd->flag & MOD_CAST_INVERT_VGROUP) != 0; Object *ctrl_ob = NULL; @@ -239,7 +239,7 @@ static void cuboid_do(CastModifierData *cmd, float (*vertexCos)[3], int verts_num) { - MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; int defgrp_index; const bool invert_vgroup = (cmd->flag & MOD_CAST_INVERT_VGROUP) != 0; diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index 42a8ba804ed..3ae83cb2244 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -145,7 +145,7 @@ static void deformVerts(ModifierData *md, if (collmd->time_xnew == -1000) { /* first time */ - collmd->x = MEM_dupallocN(mesh_src->mvert); /* frame start position */ + collmd->x = MEM_dupallocN(BKE_mesh_vertices(mesh_src)); /* frame start position */ for (uint i = 0; i < mvert_num; i++) { /* we save global positions */ @@ -160,7 +160,7 @@ static void deformVerts(ModifierData *md, collmd->mvert_num = mvert_num; { - const MLoop *mloop = mesh_src->mloop; + const MLoop *mloop = BKE_mesh_loops(mesh_src); const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh_src); collmd->tri_num = BKE_mesh_runtime_looptri_len(mesh_src); MVertTri *tri = MEM_mallocN(sizeof(*tri) * collmd->tri_num, __func__); @@ -182,7 +182,7 @@ static void deformVerts(ModifierData *md, collmd->xnew = tempVert; collmd->time_x = collmd->time_xnew; - memcpy(collmd->xnew, mesh_src->mvert, mvert_num * sizeof(MVert)); + memcpy(collmd->xnew, BKE_mesh_vertices(mesh_src), mvert_num * sizeof(MVert)); bool is_static = true; diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index 4df0479372f..30afb993cc7 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -109,7 +109,7 @@ static void requiredDataMask(Object *UNUSED(ob), } /* check individual weights for changes and cache values */ -static void mesh_get_weights(MDeformVert *dvert, +static void mesh_get_weights(const MDeformVert *dvert, const int defgrp_index, const uint verts_num, const bool use_invert_vgroup, @@ -131,9 +131,9 @@ static void mesh_get_weights(MDeformVert *dvert, static void mesh_get_boundaries(Mesh *mesh, float *smooth_weights) { - const MPoly *mpoly = mesh->mpoly; - const MLoop *mloop = mesh->mloop; - const MEdge *medge = mesh->medge; + const MEdge *medge = BKE_mesh_edges(mesh); + const MPoly *mpoly = BKE_mesh_polygons(mesh); + const MLoop *mloop = BKE_mesh_loops(mesh); uint mpoly_num, medge_num, i; ushort *boundaries; @@ -178,7 +178,7 @@ static void smooth_iter__simple(CorrectiveSmoothModifierData *csmd, uint i; const uint edges_num = (uint)mesh->totedge; - const MEdge *edges = mesh->medge; + const MEdge *edges = BKE_mesh_edges(mesh); float *vertex_edge_count_div; struct SmoothingData_Simple { @@ -255,7 +255,7 @@ static void smooth_iter__length_weight(CorrectiveSmoothModifierData *csmd, /* NOTE: the way this smoothing method works, its approx half as strong as the simple-smooth, * and 2.0 rarely spikes, double the value for consistent behavior. */ const float lambda = csmd->lambda * 2.0f; - const MEdge *edges = mesh->medge; + const MEdge *edges = BKE_mesh_edges(mesh); float *vertex_edge_count; uint i; @@ -358,7 +358,7 @@ static void smooth_iter(CorrectiveSmoothModifierData *csmd, static void smooth_verts(CorrectiveSmoothModifierData *csmd, Mesh *mesh, - MDeformVert *dvert, + const MDeformVert *dvert, const int defgrp_index, float (*vertexCos)[3], uint verts_num) @@ -452,8 +452,8 @@ static void calc_tangent_spaces(Mesh *mesh, float (*vertexCos)[3], float (*r_tan #ifndef USE_TANGENT_CALC_INLINE const uint mvert_num = (uint)dm->getNumVerts(dm); #endif - const MPoly *mpoly = mesh->mpoly; - const MLoop *mloop = mesh->mloop; + const MPoly *mpoly = BKE_mesh_polygons(mesh); + const MLoop *mloop = BKE_mesh_loops(mesh); uint i; for (i = 0; i < mpoly_num; i++) { @@ -519,7 +519,7 @@ static bool cache_settings_equal(CorrectiveSmoothModifierData *csmd) */ static void calc_deltas(CorrectiveSmoothModifierData *csmd, Mesh *mesh, - MDeformVert *dvert, + const MDeformVert *dvert, const int defgrp_index, const float (*rest_coords)[3], uint verts_num) @@ -579,7 +579,7 @@ static void correctivesmooth_modifier_do(ModifierData *md, (((ID *)ob->data)->recalc & ID_RECALC_ALL)); bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0; - MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; int defgrp_index; MOD_get_vgroup(ob, mesh, csmd->defgrp_name, &dvert, &defgrp_index); diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index af639915bd8..2043c1096c1 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -114,7 +114,7 @@ static void deformVerts(ModifierData *md, mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false); } - struct MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; int defgrp_index = -1; MOD_get_vgroup(ctx->object, mesh_src, cmd->name, &dvert, &defgrp_index); diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c index 7590318c52b..729a912b079 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.c +++ b/source/blender/modifiers/intern/MOD_datatransfer.c @@ -22,6 +22,7 @@ #include "BKE_data_transfer.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" +#include "BKE_mesh.h" #include "BKE_mesh_mapping.h" #include "BKE_mesh_remap.h" #include "BKE_modifier.h" @@ -178,7 +179,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, ob_source); } - if (((result == me) || (me->mvert == result->mvert) || (me->medge == result->medge)) && + const MVert *me_verts = BKE_mesh_vertices(me); + const MEdge *me_edges = BKE_mesh_edges(me); + const MVert *result_verts = BKE_mesh_vertices(result); + const MEdge *result_edges = BKE_mesh_edges(result); + + if (((result == me) || (me_verts == result_verts) || (me_edges == result_edges)) && (dtmd->data_types & DT_TYPES_AFFECT_MESH)) { /* We need to duplicate data here, otherwise setting custom normals, edges' sharpness, etc., * could modify org mesh, see T43671. */ diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 55d9d148d10..1615fb28007 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -135,7 +135,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * if (dmd->mode == MOD_DECIM_MODE_COLLAPSE) { if (dmd->defgrp_name[0] && (dmd->defgrp_factor > 0.0f)) { - MDeformVert *dvert; + const MDeformVert *dvert; int defgrp_index; MOD_get_vgroup(ctx->object, mesh, dmd->defgrp_name, &dvert, &defgrp_index); @@ -203,7 +203,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* make sure we never alloc'd these */ BLI_assert(bm->vtoolflagpool == NULL && bm->etoolflagpool == NULL && bm->ftoolflagpool == NULL); - BLI_assert(bm->vtable == NULL && bm->etable == NULL && bm->ftable == NULL); result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, mesh); diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index 367809953b6..00a6cb5878f 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -150,7 +150,7 @@ typedef struct DisplaceUserdata { /*const*/ DisplaceModifierData *dmd; struct Scene *scene; struct ImagePool *pool; - MDeformVert *dvert; + const MDeformVert *dvert; float weight; int defgrp_index; int direction; @@ -170,7 +170,7 @@ static void displaceModifier_do_task(void *__restrict userdata, { DisplaceUserdata *data = (DisplaceUserdata *)userdata; DisplaceModifierData *dmd = data->dmd; - MDeformVert *dvert = data->dvert; + const MDeformVert *dvert = data->dvert; const bool invert_vgroup = (dmd->flag & MOD_DISP_INVERT_VGROUP) != 0; float weight = data->weight; int defgrp_index = data->defgrp_index; @@ -270,7 +270,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd, { Object *ob = ctx->object; MVert *mvert; - MDeformVert *dvert; + const MDeformVert *dvert; int direction = dmd->direction; int defgrp_index; float(*tex_co)[3]; @@ -286,7 +286,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd, return; } - mvert = mesh->mvert; + mvert = BKE_mesh_vertices_for_write(mesh); MOD_get_vgroup(ob, mesh, dmd->defgrp_name, &dvert, &defgrp_index); if (defgrp_index >= 0 && dvert == NULL) { @@ -316,7 +316,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd, float(*clnors)[3] = CustomData_get_layer(ldata, CD_NORMAL); vert_clnors = MEM_malloc_arrayN(verts_num, sizeof(*vert_clnors), __func__); BKE_mesh_normals_loop_to_vertex( - verts_num, mesh->mloop, mesh->totloop, (const float(*)[3])clnors, vert_clnors); + verts_num, BKE_mesh_loops(mesh), mesh->totloop, (const float(*)[3])clnors, vert_clnors); } else { direction = MOD_DISP_DIR_NOR; diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index e243c32173d..e5579819cf0 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -100,8 +100,8 @@ static void createFacepa(ExplodeModifierData *emd, ParticleSystemModifierData *p int i, p, v1, v2, v3, v4 = 0; const bool invert_vgroup = (emd->flag & eExplodeFlag_INVERT_VGROUP) != 0; - mvert = mesh->mvert; - mface = mesh->mface; + mvert = BKE_mesh_vertices_for_write(mesh); + mface = (MFace *)CustomData_get_layer(&mesh->fdata, CD_MFACE); totvert = mesh->totvert; totface = mesh->totface; totpart = psmd->psys->totpart; @@ -216,7 +216,8 @@ static const short add_faces[24] = { static MFace *get_dface(Mesh *mesh, Mesh *split, int cur, int i, MFace *mf) { - MFace *df = &split->mface[cur]; + MFace *mfaces = CustomData_get_layer(&split->fdata, CD_MFACE); + MFace *df = &mfaces[cur]; CustomData_copy_data(&mesh->fdata, &split->fdata, i, cur, 1); *df = *mf; return df; @@ -639,7 +640,7 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh) { Mesh *split_m; MFace *mf = NULL, *df1 = NULL; - MFace *mface = mesh->mface; + MFace *mface = CustomData_get_layer(&mesh->fdata, CD_MFACE); MVert *dupve, *mv; EdgeHash *edgehash; EdgeHashIterator *ehi; @@ -729,12 +730,15 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh) layers_num = CustomData_number_of_layers(&split_m->fdata, CD_MTFACE); + const MVert *mesh_verts = BKE_mesh_vertices(mesh); + MVert *split_m_verts = BKE_mesh_vertices_for_write(split_m); + /* copy new faces & verts (is it really this painful with custom data??) */ for (i = 0; i < totvert; i++) { MVert source; MVert *dest; - source = mesh->mvert[i]; - dest = &split_m->mvert[i]; + source = mesh_verts[i]; + dest = &split_m_verts[i]; CustomData_copy_data(&mesh->vdata, &split_m->vdata, i, i, 1); *dest = source; @@ -755,14 +759,14 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh) for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) { BLI_edgehashIterator_getKey(ehi, &ed_v1, &ed_v2); esplit = POINTER_AS_INT(BLI_edgehashIterator_getValue(ehi)); - mv = &split_m->mvert[ed_v2]; - dupve = &split_m->mvert[esplit]; + mv = &split_m_verts[ed_v2]; + dupve = &split_m_verts[esplit]; CustomData_copy_data(&split_m->vdata, &split_m->vdata, ed_v2, esplit, 1); *dupve = *mv; - mv = &split_m->mvert[ed_v1]; + mv = &split_m_verts[ed_v1]; mid_v3_v3v3(dupve->co, dupve->co, mv->co); } @@ -772,7 +776,7 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh) curdupface = 0; //=totface; // curdupin=totesplit; for (i = 0, fs = facesplit; i < totface; i++, fs++) { - mf = &mesh->mface[i]; + mf = &mface[i]; switch (*fs) { case 3: @@ -876,8 +880,9 @@ static Mesh *cutEdges(ExplodeModifierData *emd, Mesh *mesh) curdupface += add_faces[*fs] + 1; } + MFace *split_mface = CustomData_get_layer(&split_m->fdata, CD_MFACE); for (i = 0; i < curdupface; i++) { - mf = &split_m->mface[i]; + mf = &split_mface[i]; BKE_mesh_mface_index_validate(mf, &split_m->fdata, i, ((mf->flag & ME_FACE_SEL) ? 4 : 3)); } @@ -915,7 +920,7 @@ static Mesh *explodeMesh(ExplodeModifierData *emd, totface = mesh->totface; totvert = mesh->totvert; - mface = mesh->mface; + mface = CustomData_get_layer(&mesh->fdata, CD_MFACE); totpart = psmd->psys->totpart; sim.depsgraph = ctx->depsgraph; @@ -984,6 +989,9 @@ static Mesh *explodeMesh(ExplodeModifierData *emd, psmd->psys->lattice_deform_data = psys_create_lattice_deform_data(&sim); + const MVert *mesh_verts = BKE_mesh_vertices(mesh); + MVert *explode_verts = BKE_mesh_vertices_for_write(explode); + /* duplicate & displace vertices */ ehi = BLI_edgehashIterator_new(vertpahash); for (; !BLI_edgehashIterator_isDone(ehi); BLI_edgehashIterator_step(ehi)) { @@ -995,8 +1003,8 @@ static Mesh *explodeMesh(ExplodeModifierData *emd, ed_v2 -= totvert; v = POINTER_AS_INT(BLI_edgehashIterator_getValue(ehi)); - source = mesh->mvert[ed_v1]; - dest = &explode->mvert[v]; + source = mesh_verts[ed_v1]; + dest = &explode_verts[v]; CustomData_copy_data(&mesh->vdata, &explode->vdata, ed_v1, v, 1); @@ -1011,7 +1019,7 @@ static Mesh *explodeMesh(ExplodeModifierData *emd, state.time = ctime; psys_get_particle_state(&sim, ed_v2, &state, 1); - vertco = explode->mvert[v].co; + vertco = explode_verts[v].co; mul_m4_v3(ctx->object->obmat, vertco); sub_v3_v3(vertco, birth.co); @@ -1035,6 +1043,7 @@ static Mesh *explodeMesh(ExplodeModifierData *emd, BLI_edgehashIterator_free(ehi); /* Map new vertices to faces. */ + MFace *explode_mface = CustomData_get_layer(&explode->fdata, CD_MFACE); for (i = 0, u = 0; i < totface; i++) { MFace source; int orig_v4; @@ -1056,8 +1065,8 @@ static Mesh *explodeMesh(ExplodeModifierData *emd, pa = NULL; } - source = mesh->mface[i]; - mf = &explode->mface[u]; + source = mface[i]; + mf = &explode_mface[u]; orig_v4 = source.v4; diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c index 979a08483e1..1336b896cae 100644 --- a/source/blender/modifiers/intern/MOD_hook.c +++ b/source/blender/modifiers/intern/MOD_hook.c @@ -281,7 +281,7 @@ static void deformVerts_do(HookModifierData *hmd, bPoseChannel *pchan = BKE_pose_channel_find_name(ob_target->pose, hmd->subtarget); float dmat[4][4]; int i, *index_pt; - MDeformVert *dvert; + const MDeformVert *dvert; struct HookData_cb hd; const bool invert_vgroup = (hmd->flag & MOD_HOOK_INVERT_VGROUP) != 0; diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index 6333eb699b3..479ea25b09e 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -512,7 +512,7 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3]) static bool isValidVertexGroup(LaplacianDeformModifierData *lmd, Object *ob, Mesh *mesh) { int defgrp_index; - MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; MOD_get_vgroup(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index); @@ -526,8 +526,8 @@ static void initSystem( int defgrp_index; int anchors_num; float wpaint; - MDeformVert *dvert = NULL; - MDeformVert *dv = NULL; + const MDeformVert *dvert = NULL; + const MDeformVert *dv = NULL; LaplacianSystem *sys; const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0; @@ -570,14 +570,14 @@ static void initSystem( createFaceRingMap(mesh->totvert, BKE_mesh_runtime_looptri_ensure(mesh), BKE_mesh_runtime_looptri_len(mesh), - mesh->mloop, + BKE_mesh_loops(mesh), &sys->ringf_map, &sys->ringf_indices); createVertRingMap( - mesh->totvert, mesh->medge, mesh->totedge, &sys->ringv_map, &sys->ringv_indices); + mesh->totvert, BKE_mesh_edges(mesh), mesh->totedge, &sys->ringv_map, &sys->ringv_indices); mlooptri = BKE_mesh_runtime_looptri_ensure(mesh); - mloop = mesh->mloop; + mloop = BKE_mesh_loops(mesh); for (i = 0; i < sys->tris_num; i++) { sys->tris[i][0] = mloop[mlooptri[i].tri[0]].v; @@ -596,8 +596,8 @@ static int isSystemDifferent(LaplacianDeformModifierData *lmd, int defgrp_index; int anchors_num = 0; float wpaint; - MDeformVert *dvert = NULL; - MDeformVert *dv = NULL; + const MDeformVert *dvert = NULL; + const MDeformVert *dv = NULL; LaplacianSystem *sys = (LaplacianSystem *)lmd->cache_system; const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0; diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c index c42f7b33919..d74c1e7ac2d 100644 --- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c +++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c @@ -376,8 +376,8 @@ static void laplaciansmoothModifier_do( LaplacianSmoothModifierData *smd, Object *ob, Mesh *mesh, float (*vertexCos)[3], int verts_num) { LaplacianSystem *sys; - MDeformVert *dvert = NULL; - MDeformVert *dv = NULL; + const MDeformVert *dvert = NULL; + const MDeformVert *dv = NULL; float w, wpaint; int i, iter; int defgrp_index; @@ -388,9 +388,9 @@ static void laplaciansmoothModifier_do( return; } - sys->mpoly = mesh->mpoly; - sys->mloop = mesh->mloop; - sys->medges = mesh->medge; + sys->mpoly = BKE_mesh_polygons(mesh); + sys->mloop = BKE_mesh_loops(mesh); + sys->medges = BKE_mesh_edges(mesh); sys->vertexCos = vertexCos; sys->min_area = 0.00001f; MOD_get_vgroup(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index); diff --git a/source/blender/modifiers/intern/MOD_mask.cc b/source/blender/modifiers/intern/MOD_mask.cc index e48a949baf4..cfa0299da66 100644 --- a/source/blender/modifiers/intern/MOD_mask.cc +++ b/source/blender/modifiers/intern/MOD_mask.cc @@ -169,10 +169,11 @@ static void computed_masked_edges(const Mesh *mesh, uint *r_edges_masked_num) { BLI_assert(mesh->totedge == r_edge_map.size()); + const Span<MEdge> edges = mesh->edges(); uint edges_masked_num = 0; for (int i : IndexRange(mesh->totedge)) { - const MEdge &edge = mesh->medge[i]; + const MEdge &edge = edges[i]; /* only add if both verts will be in new mesh */ if (vertex_mask[edge.v1] && vertex_mask[edge.v2]) { @@ -194,11 +195,12 @@ static void computed_masked_edges_smooth(const Mesh *mesh, uint *r_verts_add_num) { BLI_assert(mesh->totedge == r_edge_map.size()); + const Span<MEdge> edges = mesh->edges(); uint edges_masked_num = 0; uint verts_add_num = 0; for (int i : IndexRange(mesh->totedge)) { - const MEdge &edge = mesh->medge[i]; + const MEdge &edge = edges[i]; /* only add if both verts will be in new mesh */ bool v1 = vertex_mask[edge.v1]; @@ -229,16 +231,18 @@ static void computed_masked_polygons(const Mesh *mesh, uint *r_loops_masked_num) { BLI_assert(mesh->totvert == vertex_mask.size()); + const Span<MPoly> polys = mesh->polygons(); + const Span<MLoop> loops = mesh->loops(); r_masked_poly_indices.reserve(mesh->totpoly); r_loop_starts.reserve(mesh->totpoly); uint loops_masked_num = 0; for (int i : IndexRange(mesh->totpoly)) { - const MPoly &poly_src = mesh->mpoly[i]; + const MPoly &poly_src = polys[i]; bool all_verts_in_mask = true; - Span<MLoop> loops_src(&mesh->mloop[poly_src.loopstart], poly_src.totloop); + Span<MLoop> loops_src = loops.slice(poly_src.loopstart, poly_src.totloop); for (const MLoop &loop : loops_src) { if (!vertex_mask[loop.v]) { all_verts_in_mask = false; @@ -273,17 +277,19 @@ static void compute_interpolated_polygons(const Mesh *mesh, /* NOTE: this reserve can only lift the capacity if there are ngons, which get split. */ r_masked_poly_indices.reserve(r_masked_poly_indices.size() + verts_add_num); r_loop_starts.reserve(r_loop_starts.size() + verts_add_num); + const Span<MPoly> polys = mesh->polygons(); + const Span<MLoop> loops = mesh->loops(); uint edges_add_num = 0; uint polys_add_num = 0; uint loops_add_num = 0; for (int i : IndexRange(mesh->totpoly)) { - const MPoly &poly_src = mesh->mpoly[i]; + const MPoly &poly_src = polys[i]; int in_count = 0; int start = -1; int dst_totloop = -1; - Span<MLoop> loops_src(&mesh->mloop[poly_src.loopstart], poly_src.totloop); + const Span<MLoop> loops_src = loops.slice(poly_src.loopstart, poly_src.totloop); for (const int j : loops_src.index_range()) { const MLoop &loop = loops_src[j]; if (vertex_mask[loop.v]) { @@ -332,14 +338,17 @@ static void copy_masked_vertices_to_new_mesh(const Mesh &src_mesh, Span<int> vertex_map) { BLI_assert(src_mesh.totvert == vertex_map.size()); + const Span<MVert> src_verts = src_mesh.vertices(); + MutableSpan<MVert> dst_verts = dst_mesh.vertices_for_write(); + for (const int i_src : vertex_map.index_range()) { const int i_dst = vertex_map[i_src]; if (i_dst == -1) { continue; } - const MVert &v_src = src_mesh.mvert[i_src]; - MVert &v_dst = dst_mesh.mvert[i_dst]; + const MVert &v_src = src_verts[i_src]; + MVert &v_dst = dst_verts[i_dst]; v_dst = v_src; CustomData_copy_data(&src_mesh.vdata, &dst_mesh.vdata, i_src, i_dst, 1); @@ -369,6 +378,10 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh, { BLI_assert(src_mesh.totvert == vertex_mask.size()); BLI_assert(src_mesh.totedge == r_edge_map.size()); + const Span<MVert> src_verts = src_mesh.vertices(); + const Span<MEdge> src_edges = src_mesh.edges(); + MutableSpan<MVert> dst_verts = dst_mesh.vertices_for_write(); + MutableSpan<MEdge> dst_edges = dst_mesh.edges_for_write(); uint vert_index = dst_mesh.totvert - verts_add_num; uint edge_index = edges_masked_num - verts_add_num; @@ -378,8 +391,8 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh, if (i_dst == -2) { i_dst = edge_index; } - const MEdge &e_src = src_mesh.medge[i_src]; - MEdge &e_dst = dst_mesh.medge[i_dst]; + const MEdge &e_src = src_edges[i_src]; + MEdge &e_dst = dst_edges[i_dst]; CustomData_copy_data(&src_mesh.edata, &dst_mesh.edata, i_src, i_dst, 1); e_dst = e_src; @@ -389,9 +402,9 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh, if (r_edge_map[i_src] == -2) { const int i_dst = edge_index++; r_edge_map[i_src] = i_dst; - const MEdge &e_src = src_mesh.medge[i_src]; + const MEdge &e_src = src_edges[i_src]; /* Cut destination edge and make v1 the new vertex. */ - MEdge &e_dst = dst_mesh.medge[i_dst]; + MEdge &e_dst = dst_edges[i_dst]; if (!vertex_mask[e_src.v1]) { e_dst.v1 = vert_index; } @@ -407,9 +420,9 @@ static void add_interp_verts_copy_edges_to_new_mesh(const Mesh &src_mesh, float weights[2] = {1.0f - fac, fac}; CustomData_interp( &src_mesh.vdata, &dst_mesh.vdata, (int *)&e_src.v1, weights, nullptr, 2, vert_index); - MVert &v = dst_mesh.mvert[vert_index]; - MVert &v1 = src_mesh.mvert[e_src.v1]; - MVert &v2 = src_mesh.mvert[e_src.v2]; + MVert &v = dst_verts[vert_index]; + const MVert &v1 = src_verts[e_src.v1]; + const MVert &v2 = src_verts[e_src.v2]; interp_v3_v3v3(v.co, v1.co, v2.co, fac); vert_index++; @@ -424,6 +437,9 @@ static void copy_masked_edges_to_new_mesh(const Mesh &src_mesh, Span<int> vertex_map, Span<int> edge_map) { + const Span<MEdge> src_edges = src_mesh.edges(); + MutableSpan<MEdge> dst_edges = dst_mesh.edges_for_write(); + BLI_assert(src_mesh.totvert == vertex_map.size()); BLI_assert(src_mesh.totedge == edge_map.size()); for (const int i_src : IndexRange(src_mesh.totedge)) { @@ -432,8 +448,8 @@ static void copy_masked_edges_to_new_mesh(const Mesh &src_mesh, continue; } - const MEdge &e_src = src_mesh.medge[i_src]; - MEdge &e_dst = dst_mesh.medge[i_dst]; + const MEdge &e_src = src_edges[i_src]; + MEdge &e_dst = dst_edges[i_dst]; CustomData_copy_data(&src_mesh.edata, &dst_mesh.edata, i_src, i_dst, 1); e_dst = e_src; @@ -450,19 +466,24 @@ static void copy_masked_polys_to_new_mesh(const Mesh &src_mesh, Span<int> new_loop_starts, int polys_masked_num) { + const Span<MPoly> src_polys = src_mesh.polygons(); + const Span<MLoop> src_loops = src_mesh.loops(); + MutableSpan<MPoly> dst_polys = dst_mesh.polygons_for_write(); + MutableSpan<MLoop> dst_loops = dst_mesh.loops_for_write(); + for (const int i_dst : IndexRange(polys_masked_num)) { const int i_src = masked_poly_indices[i_dst]; - const MPoly &mp_src = src_mesh.mpoly[i_src]; - MPoly &mp_dst = dst_mesh.mpoly[i_dst]; + const MPoly &mp_src = src_polys[i_src]; + MPoly &mp_dst = dst_polys[i_dst]; const int i_ml_src = mp_src.loopstart; const int i_ml_dst = new_loop_starts[i_dst]; CustomData_copy_data(&src_mesh.pdata, &dst_mesh.pdata, i_src, i_dst, 1); CustomData_copy_data(&src_mesh.ldata, &dst_mesh.ldata, i_ml_src, i_ml_dst, mp_src.totloop); - const MLoop *ml_src = src_mesh.mloop + i_ml_src; - MLoop *ml_dst = dst_mesh.mloop + i_ml_dst; + const MLoop *ml_src = src_loops.data() + i_ml_src; + MLoop *ml_dst = dst_loops.data() + i_ml_dst; mp_dst = mp_src; mp_dst.loopstart = i_ml_dst; @@ -486,6 +507,12 @@ static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh, int polys_masked_num, int edges_add_num) { + const Span<MPoly> src_polys = src_mesh.polygons(); + const Span<MLoop> src_loops = src_mesh.loops(); + MutableSpan<MEdge> dst_edges = dst_mesh.edges_for_write(); + MutableSpan<MPoly> dst_polys = dst_mesh.polygons_for_write(); + MutableSpan<MLoop> dst_loops = dst_mesh.loops_for_write(); + int edge_index = dst_mesh.totedge - edges_add_num; int sub_poly_index = 0; int last_i_src = -1; @@ -500,8 +527,8 @@ static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh, last_i_src = i_src; } - const MPoly &mp_src = src_mesh.mpoly[i_src]; - MPoly &mp_dst = dst_mesh.mpoly[i_dst]; + const MPoly &mp_src = src_polys[i_src]; + MPoly &mp_dst = dst_polys[i_dst]; const int i_ml_src = mp_src.loopstart; int i_ml_dst = new_loop_starts[i_dst]; const int mp_totloop = (i_dst + 1 < new_loop_starts.size() ? new_loop_starts[i_dst + 1] : @@ -517,7 +544,7 @@ static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh, /* Ring search starting at a vertex which is not included in the mask. */ int start = -sub_poly_index - 1; bool skip = false; - Span<MLoop> loops_src(&src_mesh.mloop[i_ml_src], mp_src.totloop); + Span<MLoop> loops_src(&src_loops[i_ml_src], mp_src.totloop); for (const int j : loops_src.index_range()) { if (!vertex_mask[loops_src[j].v]) { if (start == -1) { @@ -552,13 +579,13 @@ static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh, int indices[2] = {i_ml_src + last_index, i_ml_src + index}; CustomData_interp( &src_mesh.ldata, &dst_mesh.ldata, indices, weights, nullptr, 2, i_ml_dst); - MLoop &cut_dst_loop = dst_mesh.mloop[i_ml_dst]; + MLoop &cut_dst_loop = dst_loops[i_ml_dst]; cut_dst_loop.e = edge_map[last_loop->e]; - cut_dst_loop.v = dst_mesh.medge[cut_dst_loop.e].v1; + cut_dst_loop.v = dst_edges[cut_dst_loop.e].v1; i_ml_dst++; CustomData_copy_data(&src_mesh.ldata, &dst_mesh.ldata, i_ml_src + index, i_ml_dst, 1); - MLoop &next_dst_loop = dst_mesh.mloop[i_ml_dst]; + MLoop &next_dst_loop = dst_loops[i_ml_dst]; next_dst_loop.v = vertex_map[loop.v]; next_dst_loop.e = edge_map[loop.e]; i_ml_dst++; @@ -572,14 +599,14 @@ static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh, int indices[2] = {i_ml_src + last_index, i_ml_src + index}; CustomData_interp( &src_mesh.ldata, &dst_mesh.ldata, indices, weights, nullptr, 2, i_ml_dst); - MLoop &cut_dst_loop = dst_mesh.mloop[i_ml_dst]; + MLoop &cut_dst_loop = dst_loops[i_ml_dst]; cut_dst_loop.e = edge_index; - cut_dst_loop.v = dst_mesh.medge[edge_map[last_loop->e]].v1; + cut_dst_loop.v = dst_edges[edge_map[last_loop->e]].v1; i_ml_dst++; /* Create closing edge. */ - MEdge &cut_edge = dst_mesh.medge[edge_index]; - cut_edge.v1 = dst_mesh.mloop[mp_dst.loopstart].v; + MEdge &cut_edge = dst_edges[edge_index]; + cut_edge.v1 = dst_loops[mp_dst.loopstart].v; cut_edge.v2 = cut_dst_loop.v; BLI_assert(cut_edge.v1 != cut_edge.v2); cut_edge.flag = ME_EDGEDRAW | ME_EDGERENDER; @@ -592,7 +619,7 @@ static void add_interpolated_polys_to_new_mesh(const Mesh &src_mesh, BLI_assert(i_ml_dst != mp_dst.loopstart); /* Extend active poly. */ CustomData_copy_data(&src_mesh.ldata, &dst_mesh.ldata, i_ml_src + index, i_ml_dst, 1); - MLoop &dst_loop = dst_mesh.mloop[i_ml_dst]; + MLoop &dst_loop = dst_loops[i_ml_dst]; dst_loop.v = vertex_map[loop.v]; dst_loop.e = edge_map[loop.e]; i_ml_dst++; @@ -619,9 +646,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) (mmd->flag & MOD_MASK_SMOOTH); /* Return empty or input mesh when there are no vertex groups. */ - const MDeformVert *dvert = (const MDeformVert *)CustomData_get_layer(&mesh->vdata, - CD_MDEFORMVERT); - if (dvert == nullptr) { + const Span<MDeformVert> dverts = mesh->deform_verts(); + if (dverts.is_empty()) { return invert_mask ? mesh : BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0, 0); } @@ -643,7 +669,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) } vertex_mask = Array<bool>(mesh->totvert); - compute_vertex_mask__armature_mode(dvert, mesh, armature_ob, mmd->threshold, vertex_mask); + compute_vertex_mask__armature_mode( + dverts.data(), mesh, armature_ob, mmd->threshold, vertex_mask); } else { BLI_assert(mmd->mode == MOD_MASK_MODE_VGROUP); @@ -655,7 +682,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) } vertex_mask = Array<bool>(mesh->totvert); - compute_vertex_mask__vertex_group_mode(dvert, defgrp_index, mmd->threshold, vertex_mask); + compute_vertex_mask__vertex_group_mode( + dverts.data(), defgrp_index, mmd->threshold, vertex_mask); } if (invert_mask) { @@ -716,7 +744,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) *result, vertex_mask, vertex_map, - dvert, + dverts.data(), defgrp_index, mmd->threshold, edges_masked_num, @@ -739,7 +767,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) vertex_mask, vertex_map, edge_map, - dvert, + dverts.data(), defgrp_index, mmd->threshold, masked_poly_indices, diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c index 3e81f987da3..162ff3fe4ff 100644 --- a/source/blender/modifiers/intern/MOD_meshcache.c +++ b/source/blender/modifiers/intern/MOD_meshcache.c @@ -79,7 +79,7 @@ static void meshcache_do(MeshCacheModifierData *mcmd, { const bool use_factor = mcmd->factor < 1.0f; int influence_group_index; - MDeformVert *dvert; + const MDeformVert *dvert; MOD_get_vgroup(ob, mesh, mcmd->defgrp_name, &dvert, &influence_group_index); float(*vertexCos_Store)[3] = (use_factor || influence_group_index != -1 || @@ -182,16 +182,16 @@ static void meshcache_do(MeshCacheModifierData *mcmd, float(*vertexCos_Source)[3] = MEM_malloc_arrayN( verts_num, sizeof(*vertexCos_Source), __func__); float(*vertexCos_New)[3] = MEM_malloc_arrayN(verts_num, sizeof(*vertexCos_New), __func__); - MVert *mv = me->mvert; + const MVert *mv = BKE_mesh_vertices(me); for (i = 0; i < verts_num; i++, mv++) { copy_v3_v3(vertexCos_Source[i], mv->co); } BKE_mesh_calc_relative_deform( - me->mpoly, + BKE_mesh_polygons(me), me->totpoly, - me->mloop, + BKE_mesh_loops(me), me->totvert, (const float(*)[3])vertexCos_Source, /* From the original Mesh. */ @@ -257,7 +257,7 @@ static void meshcache_do(MeshCacheModifierData *mcmd, const float global_offset = (mcmd->flag & MOD_MESHCACHE_INVERT_VERTEX_GROUP) ? mcmd->factor : 0.0f; - if (mesh->dvert != NULL) { + if (BKE_mesh_deform_verts(mesh) != NULL) { 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_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index d1df86b1010..04d17cec10d 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -330,7 +330,7 @@ static void meshdeformModifier_do(ModifierData *md, Object *ob = ctx->object; Mesh *cagemesh; - MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; float imat[4][4], cagemat[4][4], iobmat[4][4], icagemat[3][3], cmat[4][4]; float(*dco)[3] = NULL, (*bindcagecos)[3]; int a, cage_verts_num, defgrp_index; diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.cc b/source/blender/modifiers/intern/MOD_meshsequencecache.cc index 1c35160d3ef..bdaa90af5d8 100644 --- a/source/blender/modifiers/intern/MOD_meshsequencecache.cc +++ b/source/blender/modifiers/intern/MOD_meshsequencecache.cc @@ -60,6 +60,8 @@ # include "usd.h" #endif +using blender::Span; + static void initData(ModifierData *md) { MeshSeqCacheModifierData *mcmd = reinterpret_cast<MeshSeqCacheModifierData *>(md); @@ -176,13 +178,18 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } if (me != nullptr) { - MVert *mvert = mesh->mvert; - MEdge *medge = mesh->medge; - MPoly *mpoly = mesh->mpoly; + const Span<MVert> mesh_verts = mesh->vertices(); + const Span<MEdge> mesh_edges = mesh->edges(); + const Span<MPoly> mesh_polys = mesh->polygons(); + const Span<MVert> me_vertices = me->vertices(); + const Span<MEdge> me_edges = me->edges(); + const Span<MPoly> me_polygons = me->polygons(); /* TODO(sybren+bastien): possibly check relevant custom data layers (UV/color depending on - * flags) and duplicate those too. */ - if ((me->mvert == mvert) || (me->medge == medge) || (me->mpoly == mpoly)) { + * flags) and duplicate those too. + * XXX(Hans): This probably isn't true anymore with various CoW improvements, etc. */ + if ((me_vertices.data() == mesh_verts.data()) || (me_edges.data() == mesh_edges.data()) || + (me_polygons.data() == mesh_polys.data())) { /* We need to duplicate data here, otherwise we'll modify org mesh, see T51701. */ mesh = reinterpret_cast<Mesh *>( BKE_id_copy_ex(nullptr, diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index c571a4821b4..2908fbf5597 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -297,6 +297,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte case ID_IM: case ID_TE: { DEG_add_generic_id_relation(ctx->node, id, "Nodes Modifier"); + break; } default: { /* Purposefully don't add relations for materials. While there are material sockets, @@ -755,18 +756,18 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd) } static void initialize_group_input(NodesModifierData &nmd, - const OutputSocketRef &socket, + const bNodeSocket &socket, void *r_value) { - const bNodeSocketType &socket_type = *socket.typeinfo(); - const bNodeSocket &bsocket = *socket.bsocket(); + const bNodeSocketType &socket_type = *socket.typeinfo; + const bNodeSocket &bsocket = socket; const eNodeSocketDatatype socket_data_type = static_cast<eNodeSocketDatatype>(bsocket.type); if (nmd.settings.properties == nullptr) { socket_type.get_geometry_nodes_cpp_value(bsocket, r_value); return; } const IDProperty *property = IDP_GetPropertyFromGroup(nmd.settings.properties, - socket.identifier().c_str()); + socket.identifier); if (property == nullptr) { socket_type.get_geometry_nodes_cpp_value(bsocket, r_value); return; @@ -776,15 +777,15 @@ static void initialize_group_input(NodesModifierData &nmd, return; } - if (!input_has_attribute_toggle(*nmd.node_group, socket.index())) { + if (!input_has_attribute_toggle(*nmd.node_group, socket.runtime->index_in_node)) { init_socket_cpp_value_from_property(*property, socket_data_type, r_value); return; } const IDProperty *property_use_attribute = IDP_GetPropertyFromGroup( - nmd.settings.properties, (socket.identifier() + use_attribute_suffix).c_str()); + nmd.settings.properties, (socket.identifier + use_attribute_suffix).c_str()); const IDProperty *property_attribute_name = IDP_GetPropertyFromGroup( - nmd.settings.properties, (socket.identifier() + attribute_name_suffix).c_str()); + nmd.settings.properties, (socket.identifier + attribute_name_suffix).c_str()); if (property_use_attribute == nullptr || property_attribute_name == nullptr) { init_socket_cpp_value_from_property(*property, socket_data_type, r_value); return; @@ -866,11 +867,11 @@ static void find_sockets_to_preview_for_spreadsheet(SpaceSpreadsheet *sspreadshe const DTreeContext *context = &tree.root_context(); for (SpreadsheetContextNode *node_context : nested_group_contexts) { - const NodeTreeRef &tree_ref = context->tree(); - const NodeRef *found_node = nullptr; - for (const NodeRef *node_ref : tree_ref.nodes()) { - if (node_ref->name() == node_context->node_name) { - found_node = node_ref; + const bNodeTree &btree = context->btree(); + const bNode *found_node = nullptr; + for (const bNode *bnode : btree.all_nodes()) { + if (STREQ(bnode->name, node_context->node_name)) { + found_node = bnode; break; } } @@ -883,11 +884,11 @@ static void find_sockets_to_preview_for_spreadsheet(SpaceSpreadsheet *sspreadshe } } - const NodeTreeRef &tree_ref = context->tree(); - for (const NodeRef *node_ref : tree_ref.nodes_by_type("GeometryNodeViewer")) { - if (node_ref->name() == last_context->node_name) { - const DNode viewer_node{context, node_ref}; - for (const InputSocketRef *input_socket : node_ref->inputs()) { + const bNodeTree &btree = context->btree(); + for (const bNode *bnode : btree.nodes_by_type("GeometryNodeViewer")) { + if (STREQ(bnode->name, last_context->node_name)) { + const DNode viewer_node{context, bnode}; + for (const bNodeSocket *input_socket : bnode->input_sockets()) { if (input_socket->is_available() && input_socket->is_logically_linked()) { r_sockets_to_preview.add(DSocket{context, input_socket}); } @@ -936,15 +937,15 @@ struct OutputAttributeToStore { * can be evaluated together. */ static MultiValueMap<eAttrDomain, OutputAttributeInfo> find_output_attributes_to_store( - const NodesModifierData &nmd, const NodeRef &output_node, Span<GMutablePointer> output_values) + const NodesModifierData &nmd, const bNode &output_node, Span<GMutablePointer> output_values) { MultiValueMap<eAttrDomain, OutputAttributeInfo> outputs_by_domain; - for (const InputSocketRef *socket : output_node.inputs().drop_front(1).drop_back(1)) { - if (!socket_type_has_attribute_toggle(*socket->bsocket())) { + for (const bNodeSocket *socket : output_node.input_sockets().drop_front(1).drop_back(1)) { + if (!socket_type_has_attribute_toggle(*socket)) { continue; } - const std::string prop_name = socket->identifier() + attribute_name_suffix; + const std::string prop_name = socket->identifier + attribute_name_suffix; const IDProperty *prop = IDP_GetPropertyFromGroup(nmd.settings.properties, prop_name.c_str()); if (prop == nullptr) { continue; @@ -964,7 +965,7 @@ static MultiValueMap<eAttrDomain, OutputAttributeInfo> find_output_attributes_to const GField field = cpp_type->as_field(value.get()); const bNodeSocket *interface_socket = (const bNodeSocket *)BLI_findlink( - &nmd.node_group->outputs, socket->index()); + &nmd.node_group->outputs, index); const eAttrDomain domain = (eAttrDomain)interface_socket->attribute_domain; OutputAttributeInfo output_info; output_info.field = std::move(field); @@ -1063,7 +1064,7 @@ static void store_computed_output_attributes( static void store_output_attributes(GeometrySet &geometry, const NodesModifierData &nmd, - const NodeRef &output_node, + const bNode &output_node, Span<GMutablePointer> output_values) { /* All new attribute values have to be computed before the geometry is actually changed. This is @@ -1079,8 +1080,8 @@ static void store_output_attributes(GeometrySet &geometry, * Evaluate a node group to compute the output geometry. */ static GeometrySet compute_geometry(const DerivedNodeTree &tree, - Span<const NodeRef *> group_input_nodes, - const NodeRef &output_node, + Span<const bNode *> group_input_nodes, + const bNode &output_node, GeometrySet input_geometry_set, NodesModifierData *nmd, const ModifierEvalContext *ctx) @@ -1092,18 +1093,19 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree, Map<DOutputSocket, GMutablePointer> group_inputs; const DTreeContext *root_context = &tree.root_context(); - for (const NodeRef *group_input_node : group_input_nodes) { - Span<const OutputSocketRef *> group_input_sockets = group_input_node->outputs().drop_back(1); + for (const bNode *group_input_node : group_input_nodes) { + Span<const bNodeSocket *> group_input_sockets = group_input_node->output_sockets().drop_back( + 1); if (group_input_sockets.is_empty()) { continue; } - Span<const OutputSocketRef *> remaining_input_sockets = group_input_sockets; + Span<const bNodeSocket *> remaining_input_sockets = group_input_sockets; /* If the group expects a geometry as first input, use the geometry that has been passed to * modifier. */ - const OutputSocketRef *first_input_socket = group_input_sockets[0]; - if (first_input_socket->bsocket()->type == SOCK_GEOMETRY) { + const bNodeSocket *first_input_socket = group_input_sockets[0]; + if (first_input_socket->type == SOCK_GEOMETRY) { GeometrySet *geometry_set_in = allocator.construct<GeometrySet>(input_geometry_set).release(); group_inputs.add_new({root_context, first_input_socket}, geometry_set_in); @@ -1111,8 +1113,8 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree, } /* Initialize remaining group inputs. */ - for (const OutputSocketRef *socket : remaining_input_sockets) { - const CPPType &cpp_type = *socket->typeinfo()->geometry_nodes_cpp_type; + for (const bNodeSocket *socket : remaining_input_sockets) { + const CPPType &cpp_type = *socket->typeinfo->geometry_nodes_cpp_type; void *value_in = allocator.allocate(cpp_type.size(), cpp_type.alignment()); initialize_group_input(*nmd, *socket, value_in); group_inputs.add_new({root_context, socket}, {cpp_type, value_in}); @@ -1120,7 +1122,7 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree, } Vector<DInputSocket> group_outputs; - for (const InputSocketRef *socket_ref : output_node.inputs().drop_back(1)) { + for (const bNodeSocket *socket_ref : output_node.input_sockets().drop_back(1)) { group_outputs.append({root_context, socket_ref}); } @@ -1225,8 +1227,8 @@ static void modifyGeometry(ModifierData *md, check_property_socket_sync(ctx->object, md); - NodeTreeRefMap tree_refs; - DerivedNodeTree tree{*nmd->node_group, tree_refs}; + const bNodeTree &root_tree_ref = *nmd->node_group; + DerivedNodeTree tree{root_tree_ref}; if (tree.has_link_cycles()) { BKE_modifier_set_error(ctx->object, md, "Node group has cycles"); @@ -1234,25 +1236,24 @@ static void modifyGeometry(ModifierData *md, return; } - const NodeTreeRef &root_tree_ref = tree.root_context().tree(); - Span<const NodeRef *> input_nodes = root_tree_ref.nodes_by_type("NodeGroupInput"); - Span<const NodeRef *> output_nodes = root_tree_ref.nodes_by_type("NodeGroupOutput"); + Span<const bNode *> input_nodes = root_tree_ref.nodes_by_type("NodeGroupInput"); + Span<const bNode *> output_nodes = root_tree_ref.nodes_by_type("NodeGroupOutput"); if (output_nodes.size() != 1) { BKE_modifier_set_error(ctx->object, md, "Node group must have a single output node"); geometry_set.clear(); return; } - const NodeRef &output_node = *output_nodes[0]; - Span<const InputSocketRef *> group_outputs = output_node.inputs().drop_back(1); + const bNode &output_node = *output_nodes[0]; + Span<const bNodeSocket *> group_outputs = output_node.input_sockets().drop_back(1); if (group_outputs.is_empty()) { BKE_modifier_set_error(ctx->object, md, "Node group must have an output socket"); geometry_set.clear(); return; } - const InputSocketRef *first_output_socket = group_outputs[0]; - if (first_output_socket->idname() != "NodeSocketGeometry") { + const bNodeSocket *first_output_socket = group_outputs[0]; + if (!STREQ(first_output_socket->idname, "NodeSocketGeometry")) { BKE_modifier_set_error(ctx->object, md, "Node group's first output must be a geometry"); geometry_set.clear(); return; diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc index 5cf4e21ea68..dd7c87ca499 100644 --- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc +++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc @@ -2,6 +2,7 @@ #include "MOD_nodes_evaluator.hh" +#include "BKE_node.h" #include "BKE_type_conversions.hh" #include "NOD_geometry_exec.hh" @@ -319,9 +320,9 @@ class LockedNode : NonCopyable, NonMovable { } }; -static const CPPType *get_socket_cpp_type(const SocketRef &socket) +static const CPPType *get_socket_cpp_type(const bNodeSocket &socket) { - const bNodeSocketType *typeinfo = socket.typeinfo(); + const bNodeSocketType *typeinfo = socket.typeinfo; if (typeinfo->geometry_nodes_cpp_type == nullptr) { return nullptr; } @@ -338,24 +339,24 @@ static const CPPType *get_socket_cpp_type(const SocketRef &socket) static const CPPType *get_socket_cpp_type(const DSocket socket) { - return get_socket_cpp_type(*socket.socket_ref()); + return get_socket_cpp_type(*socket); } /** * \note This is not supposed to be a long term solution. Eventually we want that nodes can * specify more complex defaults (other than just single values) in their socket declarations. */ -static bool get_implicit_socket_input(const SocketRef &socket, void *r_value) +static bool get_implicit_socket_input(const bNodeSocket &socket, void *r_value) { - const NodeRef &node = socket.node(); - const nodes::NodeDeclaration *node_declaration = node.declaration(); + const bNode &node = socket.owner_node(); + const nodes::NodeDeclaration *node_declaration = node.runtime->declaration; if (node_declaration == nullptr) { return false; } const nodes::SocketDeclaration &socket_declaration = *node_declaration->inputs()[socket.index()]; if (socket_declaration.input_field_type() == nodes::InputSocketFieldType::Implicit) { - const bNode &bnode = *socket.bnode(); - if (socket.typeinfo()->type == SOCK_VECTOR) { + const bNode &bnode = socket.owner_node(); + if (socket.typeinfo->type == SOCK_VECTOR) { if (bnode.type == GEO_NODE_SET_CURVE_HANDLES) { StringRef side = ((NodeGeometrySetCurveHandlePositions *)bnode.storage)->mode == GEO_NODE_CURVE_HANDLE_LEFT ? @@ -372,7 +373,7 @@ static bool get_implicit_socket_input(const SocketRef &socket, void *r_value) new (r_value) ValueOrField<float3>(bke::AttributeFieldInput::Create<float3>("position")); return true; } - if (socket.typeinfo()->type == SOCK_INT) { + if (socket.typeinfo->type == SOCK_INT) { if (ELEM(bnode.type, FN_NODE_RANDOM_VALUE, GEO_NODE_INSTANCE_ON_POINTS)) { new (r_value) ValueOrField<int>(Field<int>(std::make_shared<bke::IDAttributeFieldInput>())); @@ -385,19 +386,19 @@ static bool get_implicit_socket_input(const SocketRef &socket, void *r_value) return false; } -static void get_socket_value(const SocketRef &socket, void *r_value) +static void get_socket_value(const bNodeSocket &socket, void *r_value) { if (get_implicit_socket_input(socket, r_value)) { return; } - const bNodeSocketType *typeinfo = socket.typeinfo(); - typeinfo->get_geometry_nodes_cpp_value(*socket.bsocket(), r_value); + const bNodeSocketType *typeinfo = socket.typeinfo; + typeinfo->get_geometry_nodes_cpp_value(socket, r_value); } static bool node_supports_laziness(const DNode node) { - return node->typeinfo()->geometry_node_execute_supports_laziness; + return node->typeinfo->geometry_node_execute_supports_laziness; } struct NodeTaskRunState { @@ -516,9 +517,9 @@ class GeometryNodesEvaluator { node_states_.add_new({node, &node_state}); /* Push all linked origins on the stack. */ - for (const InputSocketRef *input_ref : node->inputs()) { - const DInputSocket input{node.context(), input_ref}; - input.foreach_origin_socket( + for (const bNodeSocket *input : node->input_sockets()) { + const DInputSocket dinput{node.context(), input}; + dinput.foreach_origin_socket( [&](const DSocket origin) { nodes_to_check.push(origin.node()); }); } } @@ -546,11 +547,11 @@ class GeometryNodesEvaluator { void initialize_node_state(const DNode node, NodeState &node_state, LinearAllocator<> &allocator) { /* Construct arrays of the correct size. */ - node_state.inputs = allocator.construct_array<InputState>(node->inputs().size()); - node_state.outputs = allocator.construct_array<OutputState>(node->outputs().size()); + node_state.inputs = allocator.construct_array<InputState>(node->input_sockets().size()); + node_state.outputs = allocator.construct_array<OutputState>(node->output_sockets().size()); /* Initialize input states. */ - for (const int i : node->inputs().index_range()) { + for (const int i : node->input_sockets().index_range()) { InputState &input_state = node_state.inputs[i]; const DInputSocket socket = node.input(i); if (!socket->is_available()) { @@ -567,7 +568,7 @@ class GeometryNodesEvaluator { continue; } /* Construct the correct struct that can hold the input(s). */ - if (socket->is_multi_input_socket()) { + if (socket->is_multi_input()) { input_state.value.multi = allocator.construct<MultiInputValue>().release(); MultiInputValue &multi_value = *input_state.value.multi; /* Count how many values should be added until the socket is complete. */ @@ -583,7 +584,7 @@ class GeometryNodesEvaluator { } } /* Initialize output states. */ - for (const int i : node->outputs().index_range()) { + for (const int i : node->output_sockets().index_range()) { OutputState &output_state = node_state.outputs[i]; const DOutputSocket socket = node.output(i); if (!socket->is_available()) { @@ -629,13 +630,13 @@ class GeometryNodesEvaluator { void destruct_node_state(const DNode node, NodeState &node_state) { /* Need to destruct stuff manually, because it's allocated by a custom allocator. */ - for (const int i : node->inputs().index_range()) { + for (const int i : node->input_sockets().index_range()) { InputState &input_state = node_state.inputs[i]; if (input_state.type == nullptr) { continue; } - const InputSocketRef &socket_ref = node->input(i); - if (socket_ref.is_multi_input_socket()) { + const bNodeSocket &bsocket = node->input_socket(i); + if (bsocket.is_multi_input()) { MultiInputValue &multi_value = *input_state.value.multi; for (void *value : multi_value.values) { if (value != nullptr) { @@ -756,7 +757,7 @@ class GeometryNodesEvaluator { { /* These nodes are sometimes scheduled. We could also check for them in other places, but * it's the easiest to do it here. */ - if (node->is_group_input_node() || node->is_group_output_node()) { + if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { return; } @@ -837,7 +838,7 @@ class GeometryNodesEvaluator { /* If there are no remaining outputs, all the inputs can be destructed and/or can become * unused. This can also trigger a chain reaction where nodes to the left become finished * too. */ - for (const int i : locked_node.node->inputs().index_range()) { + for (const int i : locked_node.node->input_sockets().index_range()) { const DInputSocket socket = locked_node.node.input(i); InputState &input_state = locked_node.node_state.inputs[i]; if (input_state.usage == ValueUsage::Maybe) { @@ -883,7 +884,7 @@ class GeometryNodesEvaluator { return; } /* Nodes that don't support laziness require all inputs. */ - for (const int i : locked_node.node->inputs().index_range()) { + for (const int i : locked_node.node->input_sockets().index_range()) { InputState &input_state = locked_node.node_state.inputs[i]; if (input_state.type == nullptr) { /* Ignore unavailable/non-data sockets. */ @@ -915,7 +916,7 @@ class GeometryNodesEvaluator { continue; } - if (socket->is_multi_input_socket()) { + if (socket->is_multi_input()) { MultiInputValue &multi_value = *input_state.value.multi; /* Checks if all the linked sockets have been provided already. */ if (multi_value.all_values_available()) { @@ -949,7 +950,7 @@ class GeometryNodesEvaluator { */ void execute_node(const DNode node, NodeState &node_state, NodeTaskRunState *run_state) { - const bNode &bnode = *node->bnode(); + const bNode &bnode = *node; if (node_state.has_been_executed) { if (!node_supports_laziness(node)) { @@ -978,7 +979,7 @@ class GeometryNodesEvaluator { void execute_geometry_node(const DNode node, NodeState &node_state, NodeTaskRunState *run_state) { using Clock = std::chrono::steady_clock; - const bNode &bnode = *node->bnode(); + const bNode &bnode = *node; NodeParamsProvider params_provider{*this, node, node_state, run_state}; GeoNodeExecParams params{params_provider}; @@ -1002,12 +1003,12 @@ class GeometryNodesEvaluator { bool any_input_is_field = false; Vector<const void *, 16> input_values; Vector<const ValueOrFieldCPPType *, 16> input_types; - for (const int i : node->inputs().index_range()) { - const InputSocketRef &socket_ref = node->input(i); - if (!socket_ref.is_available()) { + for (const int i : node->input_sockets().index_range()) { + const bNodeSocket &bsocket = node->input_socket(i); + if (!bsocket.is_available()) { continue; } - BLI_assert(!socket_ref.is_multi_input_socket()); + BLI_assert(!bsocket.is_multi_input()); InputState &input_state = node_state.inputs[i]; BLI_assert(input_state.was_ready_for_execution); SingleInputValue &single_value = *input_state.value.single; @@ -1055,15 +1056,15 @@ class GeometryNodesEvaluator { } int output_index = 0; - for (const int i : node->outputs().index_range()) { - const OutputSocketRef &socket_ref = node->output(i); - if (!socket_ref.is_available()) { + for (const int i : node->output_sockets().index_range()) { + const bNodeSocket &bsocket = node->output_socket(i); + if (!bsocket.is_available()) { continue; } OutputState &output_state = node_state.outputs[i]; - const DOutputSocket socket{node.context(), &socket_ref}; + const DOutputSocket socket{node.context(), &bsocket}; const ValueOrFieldCPPType *cpp_type = static_cast<const ValueOrFieldCPPType *>( - get_socket_cpp_type(socket_ref)); + get_socket_cpp_type(bsocket)); GField new_field{operation, output_index}; void *buffer = allocator.allocate(cpp_type->size(), cpp_type->alignment()); cpp_type->construct_from_field(buffer, std::move(new_field)); @@ -1091,7 +1092,7 @@ class GeometryNodesEvaluator { } Vector<GMutablePointer, 16> output_buffers; - for (const int i : node->outputs().index_range()) { + for (const int i : node->output_sockets().index_range()) { const DOutputSocket socket = node.output(i); if (!socket->is_available()) { output_buffers.append({}); @@ -1128,7 +1129,7 @@ class GeometryNodesEvaluator { void execute_unknown_node(const DNode node, NodeState &node_state, NodeTaskRunState *run_state) { LinearAllocator<> &allocator = local_allocators_.local(); - for (const OutputSocketRef *socket : node->outputs()) { + for (const bNodeSocket *socket : node->output_sockets()) { if (!socket->is_available()) { continue; } @@ -1182,8 +1183,8 @@ class GeometryNodesEvaluator { const bool supports_laziness = node_supports_laziness(locked_node.node); /* Iterating over sockets instead of the states directly, because that makes it easier to * figure out which socket is missing when one of the asserts is hit. */ - for (const OutputSocketRef *socket_ref : locked_node.node->outputs()) { - OutputState &output_state = locked_node.node_state.outputs[socket_ref->index()]; + for (const bNodeSocket *bsocket : locked_node.node->output_sockets()) { + OutputState &output_state = locked_node.node_state.outputs[bsocket->index()]; if (supports_laziness) { /* Expected that at least all required sockets have been computed. If more outputs become * required later, the node will be executed again. */ @@ -1208,7 +1209,7 @@ class GeometryNodesEvaluator { { for (const DInputSocket &socket : params_.output_sockets) { BLI_assert(socket->is_available()); - BLI_assert(!socket->is_multi_input_socket()); + BLI_assert(!socket->is_multi_input()); const DNode node = socket.node(); NodeState &node_state = this->get_node_state(node); @@ -1255,7 +1256,7 @@ class GeometryNodesEvaluator { /* Count how many values still have to be added to this input until it is "complete". */ int missing_values = 0; - if (input_socket->is_multi_input_socket()) { + if (input_socket->is_multi_input()) { MultiInputValue &multi_value = *input_state.value.multi; missing_values = multi_value.missing_values(); } @@ -1402,52 +1403,51 @@ class GeometryNodesEvaluator { Vector<DInputSocket> forward_original_value_sockets; log_original_value_sockets.append(from_socket); - from_socket.foreach_target_socket( - [&](const DInputSocket to_socket, const DOutputSocket::TargetSocketPathInfo &path_info) { - if (!this->should_forward_to_socket(to_socket)) { - return; - } - BLI_assert(to_socket == path_info.sockets.last()); - GMutablePointer current_value = value_to_forward; - for (const DSocket &next_socket : path_info.sockets) { - const DNode next_node = next_socket.node(); - const bool is_last_socket = to_socket == next_socket; - const bool do_conversion_if_necessary = is_last_socket || - next_node->is_group_output_node() || - (next_node->is_group_node() && - !next_node->is_muted()); - if (do_conversion_if_necessary) { - const CPPType &next_type = *get_socket_cpp_type(next_socket); - if (*current_value.type() != next_type) { - void *buffer = allocator.allocate(next_type.size(), next_type.alignment()); - this->convert_value(*current_value.type(), next_type, current_value.get(), buffer); - if (current_value.get() != value_to_forward.get()) { - current_value.destruct(); - } - current_value = {next_type, buffer}; - } - } - if (current_value.get() == value_to_forward.get()) { - /* Log the original value at the current socket. */ - log_original_value_sockets.append(next_socket); - } - else { - /* Multi-input sockets are logged when all values are available. */ - if (!(next_socket->is_input() && next_socket->as_input().is_multi_input_socket())) { - /* Log the converted value at the socket. */ - this->log_socket_value({next_socket}, current_value); - } + from_socket.foreach_target_socket([&](const DInputSocket to_socket, + const DOutputSocket::TargetSocketPathInfo &path_info) { + if (!this->should_forward_to_socket(to_socket)) { + return; + } + BLI_assert(to_socket == path_info.sockets.last()); + GMutablePointer current_value = value_to_forward; + for (const DSocket &next_socket : path_info.sockets) { + const DNode next_node = next_socket.node(); + const bool is_last_socket = to_socket == next_socket; + const bool do_conversion_if_necessary = is_last_socket || + next_node->type == NODE_GROUP_OUTPUT || + (next_node->is_group() && !next_node->is_muted()); + if (do_conversion_if_necessary) { + const CPPType &next_type = *get_socket_cpp_type(next_socket); + if (*current_value.type() != next_type) { + void *buffer = allocator.allocate(next_type.size(), next_type.alignment()); + this->convert_value(*current_value.type(), next_type, current_value.get(), buffer); + if (current_value.get() != value_to_forward.get()) { + current_value.destruct(); } + current_value = {next_type, buffer}; } - if (current_value.get() == value_to_forward.get()) { - /* The value has not been converted, so forward the original value. */ - forward_original_value_sockets.append(to_socket); - } - else { - /* The value has been converted. */ - this->add_value_to_input_socket(to_socket, from_socket, current_value, run_state); + } + if (current_value.get() == value_to_forward.get()) { + /* Log the original value at the current socket. */ + log_original_value_sockets.append(next_socket); + } + else { + /* Multi-input sockets are logged when all values are available. */ + if (!(next_socket->is_input() && next_socket->is_multi_input())) { + /* Log the converted value at the socket. */ + this->log_socket_value({next_socket}, current_value); } - }); + } + } + if (current_value.get() == value_to_forward.get()) { + /* The value has not been converted, so forward the original value. */ + forward_original_value_sockets.append(to_socket); + } + else { + /* The value has been converted. */ + this->add_value_to_input_socket(to_socket, from_socket, current_value, run_state); + } + }); this->log_socket_value(log_original_value_sockets, value_to_forward); this->forward_to_sockets_with_same_type( allocator, forward_original_value_sockets, value_to_forward, from_socket, run_state); @@ -1512,7 +1512,7 @@ class GeometryNodesEvaluator { InputState &input_state = node_state.inputs[socket->index()]; this->with_locked_node(node, node_state, run_state, [&](LockedNode &locked_node) { - if (socket->is_multi_input_socket()) { + if (socket->is_multi_input()) { /* Add a new value to the multi-input. */ MultiInputValue &multi_value = *input_state.value.multi; multi_value.add_value(origin, value.get()); @@ -1555,7 +1555,7 @@ class GeometryNodesEvaluator { UNUSED_VARS(locked_node); GMutablePointer value = this->get_value_from_socket(origin_socket, *input_state.type); - if (input_socket->is_multi_input_socket()) { + if (input_socket->is_multi_input()) { MultiInputValue &multi_value = *input_state.value.multi; multi_value.add_value(origin_socket, value.get()); if (multi_value.all_values_available()) { @@ -1580,7 +1580,7 @@ class GeometryNodesEvaluator { void destruct_input_value_if_exists(LockedNode &locked_node, const DInputSocket socket) { InputState &input_state = locked_node.node_state.inputs[socket->index()]; - if (socket->is_multi_input_socket()) { + if (socket->is_multi_input()) { MultiInputValue &multi_value = *input_state.value.multi; for (void *&value : multi_value.values) { if (value != nullptr) { @@ -1605,7 +1605,7 @@ class GeometryNodesEvaluator { const CPPType &type = *get_socket_cpp_type(socket); void *buffer = allocator.allocate(type.size(), type.alignment()); - get_socket_value(*socket.socket_ref(), buffer); + get_socket_value(*socket.bsocket(), buffer); if (type == required_type) { return {type, buffer}; @@ -1762,7 +1762,7 @@ bool NodeParamsProvider::can_get_input(StringRef identifier) const return false; } - if (socket->is_multi_input_socket()) { + if (socket->is_multi_input()) { MultiInputValue &multi_value = *input_state.value.multi; return multi_value.all_values_available(); } @@ -1783,7 +1783,7 @@ GMutablePointer NodeParamsProvider::extract_input(StringRef identifier) { const DInputSocket socket = this->dnode.input_by_identifier(identifier); BLI_assert(socket); - BLI_assert(!socket->is_multi_input_socket()); + BLI_assert(!socket->is_multi_input()); BLI_assert(this->can_get_input(identifier)); InputState &input_state = node_state_.inputs[socket->index()]; @@ -1797,7 +1797,7 @@ Vector<GMutablePointer> NodeParamsProvider::extract_multi_input(StringRef identi { const DInputSocket socket = this->dnode.input_by_identifier(identifier); BLI_assert(socket); - BLI_assert(socket->is_multi_input_socket()); + BLI_assert(socket->is_multi_input()); BLI_assert(this->can_get_input(identifier)); InputState &input_state = node_state_.inputs[socket->index()]; @@ -1816,7 +1816,7 @@ GPointer NodeParamsProvider::get_input(StringRef identifier) const { const DInputSocket socket = this->dnode.input_by_identifier(identifier); BLI_assert(socket); - BLI_assert(!socket->is_multi_input_socket()); + BLI_assert(!socket->is_multi_input()); BLI_assert(this->can_get_input(identifier)); InputState &input_state = node_state_.inputs[socket->index()]; @@ -1901,7 +1901,7 @@ void NodeParamsProvider::set_default_remaining_outputs() { LinearAllocator<> &allocator = evaluator_.local_allocators_.local(); - for (const int i : this->dnode->outputs().index_range()) { + for (const int i : this->dnode->output_sockets().index_range()) { OutputState &output_state = node_state_.outputs[i]; if (output_state.has_been_computed) { continue; diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c index 9e3e06fb4dc..41d6e339999 100644 --- a/source/blender/modifiers/intern/MOD_normal_edit.c +++ b/source/blender/modifiers/intern/MOD_normal_edit.c @@ -53,7 +53,7 @@ static void generate_vert_coordinates(Mesh *mesh, INIT_MINMAX(min_co, max_co); - MVert *mv = mesh->mvert; + const MVert *mv = BKE_mesh_vertices(mesh); for (int i = 0; i < mesh->totvert; i++, mv++) { copy_v3_v3(r_cos[i], mv->co); if (r_size != NULL && ob_center == NULL) { @@ -117,13 +117,13 @@ static void generate_vert_coordinates(Mesh *mesh, /* Note this modifies nos_new in-place. */ static void mix_normals(const float mix_factor, - MDeformVert *dvert, + const MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup, const float mix_limit, const short mix_mode, const int verts_num, - MLoop *mloop, + const MLoop *mloop, float (*nos_old)[3], float (*nos_new)[3], const int loops_num) @@ -175,11 +175,11 @@ static void mix_normals(const float mix_factor, static bool polygons_check_flip(MLoop *mloop, float (*nos)[3], CustomData *ldata, - MPoly *mpoly, + const MPoly *mpoly, float (*polynors)[3], const int polys_num) { - MPoly *mp; + const MPoly *mp; MDisps *mdisp = CustomData_get_layer(ldata, CD_MDISPS); int i; bool flipped = false; @@ -218,16 +218,16 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd, const short mix_mode, const float mix_factor, const float mix_limit, - MDeformVert *dvert, + const MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup, - MVert *mvert, + const MVert *mvert, const int verts_num, MEdge *medge, const int edges_num, MLoop *mloop, const int loops_num, - MPoly *mpoly, + const MPoly *mpoly, const int polys_num) { Object *ob_target = enmd->target; @@ -279,7 +279,7 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd, const float m2 = (b * b) / (a * a); const float n2 = (c * c) / (a * a); - MLoop *ml; + const MLoop *ml; float(*no)[3]; /* We reuse cos to now store the ellipsoid-normal of the verts! */ @@ -355,16 +355,16 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, const short mix_mode, const float mix_factor, const float mix_limit, - MDeformVert *dvert, + const MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup, - MVert *mvert, + const MVert *mvert, const int verts_num, MEdge *medge, const int edges_num, MLoop *mloop, const int loops_num, - MPoly *mpoly, + const MPoly *mpoly, const int polys_num) { Object *ob_target = enmd->target; @@ -399,7 +399,7 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd, generate_vert_coordinates(mesh, ob, ob_target, NULL, verts_num, cos, NULL); BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)verts_num, __func__); - MLoop *ml; + const MLoop *ml; float(*no)[3]; /* We reuse cos to now store the 'to target' normal of the verts! */ @@ -509,7 +509,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, } Mesh *result; - if (mesh->medge == ((Mesh *)ob->data)->medge) { + if (BKE_mesh_edges(mesh) == BKE_mesh_edges(((Mesh *)ob->data))) { /* We need to duplicate data here, otherwise setting custom normals * (which may also affect sharp edges) could * modify original mesh, see T43671. */ @@ -523,13 +523,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, const int edges_num = result->totedge; const int loops_num = result->totloop; const int polys_num = result->totpoly; - MVert *mvert = result->mvert; - MEdge *medge = result->medge; - MLoop *mloop = result->mloop; - MPoly *mpoly = result->mpoly; + const MVert *verts = BKE_mesh_vertices(result); + MEdge *edges = BKE_mesh_edges_for_write(result); + const MPoly *polys = BKE_mesh_polygons(result); + MLoop *loops = BKE_mesh_loops_for_write(result); int defgrp_index; - MDeformVert *dvert; + const MDeformVert *dvert; float(*loopnors)[3] = NULL; @@ -543,15 +543,15 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, clnors = CustomData_duplicate_referenced_layer(ldata, CD_CUSTOMLOOPNORMAL, loops_num); loopnors = MEM_malloc_arrayN((size_t)loops_num, sizeof(*loopnors), __func__); - BKE_mesh_normals_loop_split(mvert, + BKE_mesh_normals_loop_split(verts, vert_normals, verts_num, - medge, + edges, edges_num, - mloop, + loops, loopnors, loops_num, - mpoly, + polys, poly_normals, polys_num, true, @@ -581,13 +581,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, dvert, defgrp_index, use_invert_vgroup, - mvert, + verts, verts_num, - medge, + edges, edges_num, - mloop, + loops, loops_num, - mpoly, + polys, polys_num); } else if (enmd->mode == MOD_NORMALEDIT_MODE_DIRECTIONAL) { @@ -604,13 +604,13 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, dvert, defgrp_index, use_invert_vgroup, - mvert, + verts, verts_num, - medge, + edges, edges_num, - mloop, + loops, loops_num, - mpoly, + polys, polys_num); } diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index ce2832782f5..5f4cf23d20b 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -273,9 +273,9 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, co result = BKE_mesh_new_nomain(verts_num, 0, 0, polys_num * 4, polys_num); BKE_mesh_copy_parameters_for_eval(result, mesh_orig); - gogd.mverts = result->mvert; - gogd.mpolys = result->mpoly; - gogd.mloops = result->mloop; + gogd.mverts = BKE_mesh_vertices_for_write(result); + gogd.mpolys = BKE_mesh_polygons_for_write(result); + gogd.mloops = BKE_mesh_loops_for_write(result); TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -322,8 +322,6 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes const int resolution = (ctx->flag & MOD_APPLY_RENDER) ? omd->resolution : omd->viewport_resolution; - MVert *mverts; - int cfra_for_cache; int i, j; @@ -368,77 +366,75 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes CLAMP(cfra_for_cache, omd->bakestart, omd->bakeend); cfra_for_cache -= omd->bakestart; /* shift to 0 based */ - mverts = result->mvert; + MVert *verts = BKE_mesh_vertices_for_write(result); + MPoly *polys = BKE_mesh_polygons_for_write(result); /* add vcols before displacement - allows lookup based on position */ if (omd->flag & MOD_OCEAN_GENERATE_FOAM) { - if (CustomData_number_of_layers(&result->ldata, CD_PROP_BYTE_COLOR) < MAX_MCOL) { - const int polys_num = result->totpoly; - const int loops_num = result->totloop; - MLoop *mloops = result->mloop; - MLoopCol *mloopcols = CustomData_add_layer_named( - &result->ldata, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, NULL, loops_num, omd->foamlayername); - - MLoopCol *mloopcols_spray = NULL; - if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) { - mloopcols_spray = CustomData_add_layer_named(&result->ldata, - CD_PROP_BYTE_COLOR, - CD_SET_DEFAULT, - NULL, - loops_num, - omd->spraylayername); - } + const int polys_num = result->totpoly; + const int loops_num = result->totloop; + MLoop *mloops = BKE_mesh_loops_for_write(result); + MLoopCol *mloopcols = CustomData_add_layer_named( + &result->ldata, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, NULL, loops_num, omd->foamlayername); + + MLoopCol *mloopcols_spray = NULL; + if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) { + mloopcols_spray = CustomData_add_layer_named(&result->ldata, + CD_PROP_BYTE_COLOR, + CD_SET_DEFAULT, + NULL, + loops_num, + omd->spraylayername); + } - if (mloopcols) { /* unlikely to fail */ - MPoly *mpolys = result->mpoly; - MPoly *mp; + if (mloopcols) { /* unlikely to fail */ + MPoly *mp; - for (i = 0, mp = mpolys; i < polys_num; i++, mp++) { - MLoop *ml = &mloops[mp->loopstart]; - MLoopCol *mlcol = &mloopcols[mp->loopstart]; + for (i = 0, mp = polys; i < polys_num; i++, mp++) { + MLoop *ml = &mloops[mp->loopstart]; + MLoopCol *mlcol = &mloopcols[mp->loopstart]; - MLoopCol *mlcolspray = NULL; - if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) { - mlcolspray = &mloopcols_spray[mp->loopstart]; + MLoopCol *mlcolspray = NULL; + if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) { + mlcolspray = &mloopcols_spray[mp->loopstart]; + } + + for (j = mp->totloop; j--; ml++, mlcol++) { + const float *vco = verts[ml->v].co; + const float u = OCEAN_CO(size_co_inv, vco[0]); + const float v = OCEAN_CO(size_co_inv, vco[1]); + float foam; + + if (omd->oceancache && omd->cached == true) { + BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v); + foam = ocr.foam; + CLAMP(foam, 0.0f, 1.0f); + } + else { + BKE_ocean_eval_uv(omd->ocean, &ocr, u, v); + foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage); } - for (j = mp->totloop; j--; ml++, mlcol++) { - const float *vco = mverts[ml->v].co; - const float u = OCEAN_CO(size_co_inv, vco[0]); - const float v = OCEAN_CO(size_co_inv, vco[1]); - float foam; + mlcol->r = mlcol->g = mlcol->b = (char)(foam * 255); + /* This needs to be set (render engine uses) */ + mlcol->a = 255; - if (omd->oceancache && omd->cached == true) { - BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v); - foam = ocr.foam; - CLAMP(foam, 0.0f, 1.0f); + if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) { + if (omd->flag & MOD_OCEAN_INVERT_SPRAY) { + mlcolspray->r = ocr.Eminus[0] * 255; } else { - BKE_ocean_eval_uv(omd->ocean, &ocr, u, v); - foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage); + mlcolspray->r = ocr.Eplus[0] * 255; } - - mlcol->r = mlcol->g = mlcol->b = (char)(foam * 255); - /* This needs to be set (render engine uses) */ - mlcol->a = 255; - - if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) { - if (omd->flag & MOD_OCEAN_INVERT_SPRAY) { - mlcolspray->r = ocr.Eminus[0] * 255; - } - else { - mlcolspray->r = ocr.Eplus[0] * 255; - } - mlcolspray->g = 0; - if (omd->flag & MOD_OCEAN_INVERT_SPRAY) { - mlcolspray->b = ocr.Eminus[2] * 255; - } - else { - mlcolspray->b = ocr.Eplus[2] * 255; - } - mlcolspray->a = 255; + mlcolspray->g = 0; + if (omd->flag & MOD_OCEAN_INVERT_SPRAY) { + mlcolspray->b = ocr.Eminus[2] * 255; + } + else { + mlcolspray->b = ocr.Eplus[2] * 255; } + mlcolspray->a = 255; } } } @@ -453,7 +449,7 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes const int verts_num = result->totvert; for (i = 0; i < verts_num; i++) { - float *vco = mverts[i].co; + float *vco = verts[i].co; const float u = OCEAN_CO(size_co_inv, vco[0]); const float v = OCEAN_CO(size_co_inv, vco[1]); diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c index d6435c55211..599c056f27c 100644 --- a/source/blender/modifiers/intern/MOD_particleinstance.c +++ b/source/blender/modifiers/intern/MOD_particleinstance.c @@ -200,9 +200,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * ParticleSimulationData sim; ParticleSystem *psys = NULL; ParticleData *pa = NULL; - MPoly *mpoly, *orig_mpoly; - MLoop *mloop, *orig_mloop; - MVert *mvert, *orig_mvert; int totvert, totpoly, totloop, totedge; int maxvert, maxpoly, maxloop, maxedge, part_end = 0, part_start; int k, p, p_skip; @@ -320,12 +317,13 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * result = BKE_mesh_new_nomain_from_template(mesh, maxvert, maxedge, 0, maxloop, maxpoly); - mvert = result->mvert; - orig_mvert = mesh->mvert; - mpoly = result->mpoly; - orig_mpoly = mesh->mpoly; - mloop = result->mloop; - orig_mloop = mesh->mloop; + const MVert *orig_mvert = BKE_mesh_vertices(mesh); + const MPoly *orig_mpoly = BKE_mesh_polygons(mesh); + const MLoop *orig_mloop = BKE_mesh_loops(mesh); + MVert *mvert = BKE_mesh_vertices_for_write(result); + MEdge *edges = BKE_mesh_edges_for_write(result); + MPoly *mpoly = BKE_mesh_polygons_for_write(result); + MLoop *mloop = BKE_mesh_loops_for_write(result); MLoopCol *mloopcols_index = CustomData_get_layer_named( &result->ldata, CD_PROP_BYTE_COLOR, pimd->index_layer_name); @@ -353,7 +351,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* set vertices coordinates */ for (k = 0; k < totvert; k++) { ParticleKey state; - MVert *inMV; + const MVert *inMV; int vindex = p_skip * totvert + k; MVert *mv = mvert + vindex; @@ -477,7 +475,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* Create edges and adjust edge vertex indices. */ CustomData_copy_data(&mesh->edata, &result->edata, 0, p_skip * totedge, totedge); - MEdge *me = &result->medge[p_skip * totedge]; + MEdge *me = &edges[p_skip * totedge]; for (k = 0; k < totedge; k++, me++) { me->v1 += p_skip * totvert; me->v2 += p_skip * totvert; @@ -486,7 +484,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* create polys and loops */ for (k = 0; k < totpoly; k++) { - MPoly *inMP = orig_mpoly + k; + const MPoly *inMP = orig_mpoly + k; MPoly *mp = mpoly + p_skip * totpoly + k; CustomData_copy_data(&mesh->pdata, &result->pdata, k, p_skip * totpoly + k, 1); @@ -494,7 +492,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * mp->loopstart += p_skip * totloop; { - MLoop *inML = orig_mloop + inMP->loopstart; + const MLoop *inML = orig_mloop + inMP->loopstart; MLoop *ml = mloop + mp->loopstart; int j = mp->totloop; diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c index f21d536fadf..37d711a4bfa 100644 --- a/source/blender/modifiers/intern/MOD_remesh.c +++ b/source/blender/modifiers/intern/MOD_remesh.c @@ -60,11 +60,11 @@ static void init_dualcon_mesh(DualConInput *input, Mesh *mesh) { memset(input, 0, sizeof(DualConInput)); - input->co = (void *)mesh->mvert; + input->co = (void *)BKE_mesh_vertices(mesh); input->co_stride = sizeof(MVert); input->totco = mesh->totvert; - input->mloop = (void *)mesh->mloop; + input->mloop = (void *)BKE_mesh_loops(mesh); input->loop_stride = sizeof(MLoop); BKE_mesh_runtime_looptri_ensure(mesh); @@ -80,6 +80,9 @@ static void init_dualcon_mesh(DualConInput *input, Mesh *mesh) * keep track of the current elements */ typedef struct { Mesh *mesh; + MVert *verts; + MPoly *polys; + MLoop *loops; int curvert, curface; } DualConOutput; @@ -93,17 +96,20 @@ static void *dualcon_alloc_output(int totvert, int totquad) } output->mesh = BKE_mesh_new_nomain(totvert, 0, 0, 4 * totquad, totquad); + output->verts = BKE_mesh_vertices_for_write(output->mesh); + output->polys = BKE_mesh_polygons_for_write(output->mesh); + output->loops = BKE_mesh_loops_for_write(output->mesh); + return output; } static void dualcon_add_vert(void *output_v, const float co[3]) { DualConOutput *output = output_v; - Mesh *mesh = output->mesh; - BLI_assert(output->curvert < mesh->totvert); + BLI_assert(output->curvert < output->mesh->totvert); - copy_v3_v3(mesh->mvert[output->curvert].co, co); + copy_v3_v3(output->verts[output->curvert].co, co); output->curvert++; } @@ -111,14 +117,13 @@ static void dualcon_add_quad(void *output_v, const int vert_indices[4]) { DualConOutput *output = output_v; Mesh *mesh = output->mesh; - MLoop *mloop; - MPoly *cur_poly; int i; BLI_assert(output->curface < mesh->totpoly); + UNUSED_VARS_NDEBUG(mesh); - mloop = mesh->mloop; - cur_poly = &mesh->mpoly[output->curface]; + MLoop *mloop = output->loops; + MPoly *cur_poly = &output->polys[output->curface]; cur_poly->loopstart = output->curface * 4; cur_poly->totloop = 4; @@ -195,7 +200,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx) } if (rmd->flag & MOD_REMESH_SMOOTH_SHADING) { - MPoly *mpoly = result->mpoly; + MPoly *mpoly = BKE_mesh_polygons_for_write(result); int i, totpoly = result->totpoly; /* Apply smooth shading to output faces */ diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index e438c43d4dc..7cdeaeade9f 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -182,7 +182,7 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result, static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *meshData) { - Mesh *mesh = meshData; + const Mesh *mesh = meshData; Mesh *result; ScrewModifierData *ltmd = (ScrewModifierData *)md; const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER) != 0; @@ -241,11 +241,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * uint edge_offset; - MPoly *mpoly_orig, *mpoly_new, *mp_new; - MLoop *mloop_orig, *mloop_new, *ml_new; - MEdge *medge_orig, *med_orig, *med_new, *med_new_firstloop, *medge_new; - MVert *mvert_new, *mvert_orig, *mv_orig, *mv_new, *mv_new_base; - + MPoly *mp_new; + MLoop *ml_new; + MEdge *med_new, *med_new_firstloop; + MVert *mv_new, *mv_new_base; + const MVert *mv_orig; Object *ob_axis = ltmd->ob_axis; ScrewVertConnect *vc, *vc_tmp, *vert_connect = NULL; @@ -388,14 +388,15 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * result = BKE_mesh_new_nomain_from_template( mesh, (int)maxVerts, (int)maxEdges, 0, (int)maxPolys * 4, (int)maxPolys); - /* copy verts from mesh */ - mvert_orig = mesh->mvert; - medge_orig = mesh->medge; + const MVert *mvert_orig = BKE_mesh_vertices(mesh); + const MEdge *medge_orig = BKE_mesh_edges(mesh); + const MPoly *mpoly_orig = BKE_mesh_polygons(mesh); + const MLoop *mloop_orig = BKE_mesh_loops(mesh); - mvert_new = result->mvert; - mpoly_new = result->mpoly; - mloop_new = result->mloop; - medge_new = result->medge; + MVert *mvert_new = BKE_mesh_vertices_for_write(result); + MEdge *medge_new = BKE_mesh_edges_for_write(result); + MPoly *mpoly_new = BKE_mesh_polygons_for_write(result); + MLoop *mloop_new = BKE_mesh_loops_for_write(result); if (!CustomData_has_layer(&result->pdata, CD_ORIGINDEX)) { CustomData_add_layer(&result->pdata, CD_ORIGINDEX, CD_SET_DEFAULT, NULL, (int)maxPolys); @@ -438,7 +439,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * BLI_bitmap *vert_tag = BLI_BITMAP_NEW(totvert, __func__); /* Copy the first set of edges */ - med_orig = medge_orig; + const MEdge *med_orig = medge_orig; med_new = medge_new; for (i = 0; i < totedge; i++, med_orig++, med_new++) { med_new->v1 = med_orig->v1; @@ -453,10 +454,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* build polygon -> edge map */ if (totpoly) { - MPoly *mp_orig; + const MPoly *mp_orig; - mpoly_orig = mesh->mpoly; - mloop_orig = mesh->mloop; edge_poly_map = MEM_malloc_arrayN(totedge, sizeof(*edge_poly_map), __func__); memset(edge_poly_map, 0xff, sizeof(*edge_poly_map) * totedge); @@ -467,7 +466,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * uint loopstart = (uint)mp_orig->loopstart; uint loopend = loopstart + (uint)mp_orig->totloop; - MLoop *ml_orig = &mloop_orig[loopstart]; + const MLoop *ml_orig = &mloop_orig[loopstart]; uint k; for (k = loopstart; k < loopend; k++, ml_orig++) { edge_poly_map[ml_orig->e] = i; @@ -947,6 +946,9 @@ static Mesh *modifyMesh(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); + for (i = 0; i < totedge; i++, med_new_firstloop++) { const uint step_last = step_tot - (close ? 1 : 2); const uint mpoly_index_orig = totpoly ? edge_poly_map[i] : UINT_MAX; @@ -959,14 +961,14 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * }; const bool has_mloop_orig = mloop_index_orig[0] != UINT_MAX; - short mat_nr; + int mat_nr; /* for each edge, make a cylinder of quads */ i1 = med_new_firstloop->v1; i2 = med_new_firstloop->v2; if (has_mpoly_orig) { - mat_nr = mpoly_orig[mpoly_index_orig].mat_nr; + mat_nr = src_material_index == NULL ? 0 : src_material_index[mpoly_index_orig]; } else { mat_nr = 0; @@ -992,8 +994,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } else { origindex[mpoly_index] = ORIGINDEX_NONE; + dst_material_index[mpoly_index] = mat_nr; mp_new->flag = mpoly_flag; - mp_new->mat_nr = mat_nr; } mp_new->loopstart = mpoly_index * 4; mp_new->totloop = 4; diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index 4a927d92956..cd36d82e746 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -111,7 +111,7 @@ static void deformVerts(ModifierData *md, mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false); } - struct MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; int defgrp_index = -1; MOD_get_vgroup(ctx->object, mesh_src, swmd->vgroup_name, &dvert, &defgrp_index); @@ -143,7 +143,7 @@ static void deformVertsEM(ModifierData *md, BKE_mesh_wrapper_ensure_mdata(mesh_src); } - struct MDeformVert *dvert = NULL; + const MDeformVert *dvert = NULL; int defgrp_index = -1; if (swmd->vgroup_name[0] != '\0') { MOD_get_vgroup(ctx->object, mesh_src, swmd->vgroup_name, &dvert, &defgrp_index); diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c index 1fc4f11bc66..b49e47fa589 100644 --- a/source/blender/modifiers/intern/MOD_simpledeform.c +++ b/source/blender/modifiers/intern/MOD_simpledeform.c @@ -294,7 +294,7 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, float smd_limit[2], smd_factor; SpaceTransform *transf = NULL, tmp_transf; int vgroup; - MDeformVert *dvert; + const MDeformVert *dvert; /* This is historically the lock axis, _not_ the deform axis as the name would imply */ const int deform_axis = smd->deform_axis; diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index 982f5802df6..5b9b496b0d3 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -889,9 +889,9 @@ static Mesh *subdivide_base(const Mesh *orig) float radrat; const MVertSkin *orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN); - const MVert *origvert = orig->mvert; - const MEdge *origedge = orig->medge; - const MDeformVert *origdvert = orig->dvert; + const MVert *origvert = BKE_mesh_vertices(orig); + const MEdge *origedge = BKE_mesh_edges(orig); + const MDeformVert *origdvert = BKE_mesh_deform_verts(orig); int orig_vert_num = orig->totvert; int orig_edge_num = orig->totedge; @@ -916,10 +916,13 @@ static Mesh *subdivide_base(const Mesh *orig) Mesh *result = BKE_mesh_new_nomain_from_template( orig, orig_vert_num + subd_num, orig_edge_num + subd_num, 0, 0, 0); - MVert *outvert = result->mvert; - MEdge *outedge = result->medge; + MVert *outvert = BKE_mesh_vertices_for_write(result); + MEdge *outedge = BKE_mesh_edges_for_write(result); MVertSkin *outnode = CustomData_get_layer(&result->vdata, CD_MVERT_SKIN); - MDeformVert *outdvert = result->dvert; + MDeformVert *outdvert = NULL; + if (origdvert) { + outdvert = BKE_mesh_deform_verts_for_write(result); + } /* Copy original vertex data */ CustomData_copy_data(&orig->vdata, &result->vdata, 0, 0, orig_vert_num); @@ -1907,17 +1910,17 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_ SkinNode *skin_nodes; MeshElemMap *emap; int *emapmem; - MVert *mvert; - MEdge *medge; - MDeformVert *dvert; + const MVert *mvert; + const MEdge *medge; + const MDeformVert *dvert; int verts_num, edges_num; bool has_valid_root = false; nodes = CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN); - mvert = origmesh->mvert; - dvert = origmesh->dvert; - medge = origmesh->medge; + mvert = BKE_mesh_vertices(origmesh); + dvert = BKE_mesh_deform_verts(origmesh); + medge = BKE_mesh_edges(origmesh); verts_num = origmesh->totvert; edges_num = origmesh->totedge; diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c index 6dd3d491283..76332c61e1e 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.c @@ -99,10 +99,10 @@ static void smoothModifier_do( const float fac_orig = 1.0f - fac_new; const bool invert_vgroup = (smd->flag & MOD_SMOOTH_INVERT_VGROUP) != 0; - MEdge *medges = mesh->medge; + const MEdge *medges = BKE_mesh_edges(mesh); const int edges_num = mesh->totedge; - MDeformVert *dvert; + const MDeformVert *dvert; int defgrp_index; MOD_get_vgroup(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index); @@ -128,7 +128,7 @@ static void smoothModifier_do( const short flag = smd->flag; if (dvert) { - MDeformVert *dv = dvert; + const MDeformVert *dv = dvert; for (int i = 0; i < verts_num; i++, dv++) { float *vco_orig = vertexCos[i]; if (accumulated_vecs_count[i] > 0) { diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c index 15e8bd25997..d7b2db87a60 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.c +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c @@ -61,27 +61,16 @@ static void mesh_calc_hq_normal(Mesh *mesh, #endif ) { - int i, verts_num, edges_num, polys_num; - MPoly *mpoly, *mp; - MLoop *mloop, *ml; - MEdge *medge, *ed; + int i; - verts_num = mesh->totvert; - edges_num = mesh->totedge; - polys_num = mesh->totpoly; - mpoly = mesh->mpoly; - medge = mesh->medge; - mloop = mesh->mloop; + const int verts_num = mesh->totvert; + const int edges_num = mesh->totedge; + const int polys_num = mesh->totpoly; + const MPoly *mpoly = BKE_mesh_polygons(mesh); + const MLoop *mloop = BKE_mesh_loops(mesh); + const MEdge *medge = BKE_mesh_edges(mesh); - /* we don't want to overwrite any referenced layers */ - - /* Doesn't work here! */ -#if 0 - mv = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT, verts_num); - cddm->mvert = mv; -#endif - - mp = mpoly; + const MPoly *mp = mpoly; { EdgeFaceRef *edge_ref_array = MEM_calloc_arrayN( @@ -93,7 +82,7 @@ static void mesh_calc_hq_normal(Mesh *mesh, for (i = 0; i < polys_num; i++, mp++) { int j; - ml = mloop + mp->loopstart; + const MLoop *ml = mloop + mp->loopstart; for (j = 0; j < mp->totloop; j++, ml++) { /* --- add edge ref to face --- */ @@ -116,6 +105,7 @@ static void mesh_calc_hq_normal(Mesh *mesh, } } + const MEdge *ed; for (i = 0, ed = medge, edge_ref = edge_ref_array; i < edges_num; i++, ed++, edge_ref++) { /* Get the edge vert indices, and edge value (the face indices that use it) */ @@ -166,10 +156,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex Mesh *result; const SolidifyModifierData *smd = (SolidifyModifierData *)md; - MVert *mv, *mvert, *orig_mvert; - MEdge *ed, *medge, *orig_medge; - MLoop *ml, *mloop, *orig_mloop; - MPoly *mp, *mpoly, *orig_mpoly; const uint verts_num = (uint)mesh->totvert; const uint edges_num = (uint)mesh->totedge; const uint polys_num = (uint)mesh->totpoly; @@ -216,7 +202,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex const bool do_shell = !(do_rim && (smd->flag & MOD_SOLIDIFY_NOSHELL) != 0); /* weights */ - MDeformVert *dvert; + const MDeformVert *dvert; const bool defgrp_invert = (smd->flag & MOD_SOLIDIFY_VGROUP_INV) != 0; int defgrp_index; const int shell_defgrp_index = BKE_id_defgroup_name_index(&mesh->id, smd->shell_defgrp_name); @@ -229,10 +215,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex MOD_get_vgroup(ctx->object, mesh, smd->defgrp_name, &dvert, &defgrp_index); - orig_mvert = mesh->mvert; - orig_medge = mesh->medge; - orig_mloop = mesh->mloop; - orig_mpoly = mesh->mpoly; + const MVert *orig_mvert = BKE_mesh_vertices(mesh); + const MEdge *orig_medge = BKE_mesh_edges(mesh); + const MPoly *orig_mpoly = BKE_mesh_polygons(mesh); + const MLoop *orig_mloop = BKE_mesh_loops(mesh); if (need_poly_normals) { /* calculate only face normals */ @@ -262,16 +248,17 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex copy_vn_i(edge_users, edges_num, INVALID_UNUSED); #endif + const MEdge *ed; for (eidx = 0, ed = orig_medge; eidx < edges_num; eidx++, ed++) { edge_users[eidx] = INVALID_UNUSED; } + const MPoly *mp; for (i = 0, mp = orig_mpoly; i < polys_num; i++, mp++) { - MLoop *ml_prev; int j; - ml = orig_mloop + mp->loopstart; - ml_prev = ml + (mp->totloop - 1); + const MLoop *ml = orig_mloop + mp->loopstart; + const MLoop *ml_prev = ml + (mp->totloop - 1); for (j = 0; j < mp->totloop; j++, ml++) { /* add edge user */ @@ -348,10 +335,10 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex (int)((loops_num * stride) + newLoops), (int)((polys_num * stride) + newPolys)); - mpoly = result->mpoly; - mloop = result->mloop; - medge = result->medge; - mvert = result->mvert; + MVert *mvert = BKE_mesh_vertices_for_write(result); + MEdge *medge = BKE_mesh_edges_for_write(result); + MPoly *mpoly = BKE_mesh_polygons_for_write(result); + MLoop *mloop = BKE_mesh_loops_for_write(result); if (do_bevel_convex) { /* Make sure bweight is enabled. */ @@ -425,12 +412,14 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } \ (void)0 + int *dst_material_index = BKE_mesh_material_indices_for_write(result); + /* flip normals */ if (do_shell) { uint i; - mp = mpoly + polys_num; + MPoly *mp = mpoly + polys_num; for (i = 0; i < mesh->totpoly; i++, mp++) { const int loop_end = mp->totloop - 1; MLoop *ml2; @@ -462,8 +451,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex #endif if (mat_ofs) { - mp->mat_nr += mat_ofs; - CLAMP(mp->mat_nr, 0, mat_nr_max); + dst_material_index[mp - mpoly] += mat_ofs; + CLAMP(dst_material_index[mp - mpoly], 0, mat_nr_max); } e = ml2[0].e; @@ -480,6 +469,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } } + MEdge *ed; for (i = 0, ed = medge + edges_num; i < edges_num; i++, ed++) { ed->v1 += verts_num; ed->v2 += verts_num; @@ -528,15 +518,15 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex edge_user_pairs[eidx][0] = INVALID_UNUSED; edge_user_pairs[eidx][1] = INVALID_UNUSED; } - mp = orig_mpoly; + const MPoly *mp = orig_mpoly; for (uint i = 0; i < polys_num; i++, mp++) { - ml = orig_mloop + mp->loopstart; - MLoop *ml_prev = ml + (mp->totloop - 1); + const MLoop *ml = orig_mloop + mp->loopstart; + const MLoop *ml_prev = ml + (mp->totloop - 1); for (uint j = 0; j < mp->totloop; j++, ml++) { /* add edge user */ eidx = ml_prev->e; - ed = orig_medge + eidx; + const MEdge *ed = orig_medge + eidx; BLI_assert(ELEM(ml_prev->v, ed->v1, ed->v2) && ELEM(ml->v, ed->v1, ed->v2)); char flip = (char)((ml_prev->v > ml->v) == (ed->v1 < ed->v2)); if (edge_user_pairs[eidx][flip] == INVALID_UNUSED) { @@ -549,7 +539,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex ml_prev = ml; } } - ed = orig_medge; + const MEdge *ed = orig_medge; float e[3]; for (uint i = 0; i < edges_num; i++, ed++) { if (!ELEM(edge_user_pairs[i][0], INVALID_UNUSED, INVALID_PAIR) && @@ -580,12 +570,13 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex ofs_new_vgroup = ofs_new; + MVert *mv; INIT_VERT_ARRAY_OFFSETS(false); for (i_orig = 0; i_orig < i_end; i_orig++, mv++) { const uint i = do_shell_align ? i_orig : new_vert_arr[i_orig]; if (dvert) { - MDeformVert *dv = &dvert[i]; + const MDeformVert *dv = &dvert[i]; if (defgrp_invert) { ofs_new_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index); } @@ -631,12 +622,13 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex ofs_new_vgroup = ofs_orig; /* as above but swapped */ + MVert *mv; INIT_VERT_ARRAY_OFFSETS(true); for (i_orig = 0; i_orig < i_end; i_orig++, mv++) { const uint i = do_shell_align ? i_orig : new_vert_arr[i_orig]; if (dvert) { - MDeformVert *dv = &dvert[i]; + const MDeformVert *dv = &dvert[i]; if (defgrp_invert) { ofs_new_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index); } @@ -722,11 +714,13 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex if (vert_nors == NULL) { vert_nors = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "mod_solid_vno"); + const MVert *mv; for (i = 0, mv = mvert; i < verts_num; i++, mv++) { copy_v3_v3(vert_nors[i], mesh_vert_normals[i]); } } + const MPoly *mp; for (i = 0, mp = mpoly; i < polys_num; i++, mp++) { /* #BKE_mesh_calc_poly_angles logic is inlined here */ float nor_prev[3]; @@ -735,7 +729,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex int i_curr = mp->totloop - 1; int i_next = 0; - ml = &mloop[mp->loopstart]; + const MLoop *ml = &mloop[mp->loopstart]; sub_v3_v3v3(nor_prev, mvert[ml[i_curr - 1].v].co, mvert[ml[i_curr].v].co); normalize_v3(nor_prev); @@ -779,7 +773,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* vertex group support */ if (dvert) { - MDeformVert *dv = dvert; + const MDeformVert *dv = dvert; float scalar; if (defgrp_invert) { @@ -822,13 +816,13 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex edge_user_pairs[eidx][1] = INVALID_UNUSED; } for (i = 0, mp = orig_mpoly; i < polys_num; i++, mp++) { - ml = orig_mloop + mp->loopstart; - MLoop *ml_prev = ml + (mp->totloop - 1); + const MLoop *ml = orig_mloop + mp->loopstart; + const MLoop *ml_prev = ml + (mp->totloop - 1); for (int j = 0; j < mp->totloop; j++, ml++) { /* add edge user */ eidx = ml_prev->e; - ed = orig_medge + eidx; + const MEdge *ed = orig_medge + eidx; BLI_assert(ELEM(ml_prev->v, ed->v1, ed->v2) && ELEM(ml->v, ed->v1, ed->v2)); char flip = (char)((ml_prev->v > ml->v) == (ed->v1 < ed->v2)); if (edge_user_pairs[eidx][flip] == INVALID_UNUSED) { @@ -841,7 +835,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex ml_prev = ml; } } - ed = orig_medge; + const MEdge *ed = orig_medge; float e[3]; for (i = 0; i < edges_num; i++, ed++) { if (!ELEM(edge_user_pairs[i][0], INVALID_UNUSED, INVALID_PAIR) && @@ -936,6 +930,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex uint i_orig, i_end; bool do_shell_align; + MVert *mv; INIT_VERT_ARRAY_OFFSETS(false); for (i_orig = 0; i_orig < i_end; i_orig++, mv++) { @@ -952,6 +947,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex bool do_shell_align; /* same as above but swapped, intentional use of 'ofs_new' */ + MVert *mv; INIT_VERT_ARRAY_OFFSETS(true); for (i_orig = 0; i_orig < i_end; i_orig++, mv++) { @@ -981,7 +977,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex else if (do_shell) { uint i; /* flip vertex normals for copied verts */ - mv = mvert + verts_num; for (i = 0; i < verts_num; i++) { negate_v3((float *)mesh_vert_normals[i]); } @@ -989,22 +984,15 @@ 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) { - dvert = CustomData_duplicate_referenced_layer(&result->vdata, CD_MDEFORMVERT, result->totvert); - /* If no vertices were ever added to an object's vgroup, dvert might be NULL. */ - if (dvert == NULL) { - /* Add a valid data layer! */ - dvert = CustomData_add_layer( - &result->vdata, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, result->totvert); - } + MDeformVert *dst_dvert = BKE_mesh_deform_verts_for_write(result); + /* Ultimate security check. */ - if (dvert != NULL) { - result->dvert = dvert; + if (dst_dvert != NULL) { if (rim_defgrp_index != -1) { for (uint i = 0; i < rimVerts; i++) { - BKE_defvert_ensure_index(&result->dvert[new_vert_arr[i]], rim_defgrp_index)->weight = - 1.0f; - BKE_defvert_ensure_index(&result->dvert[(do_shell ? new_vert_arr[i] : i) + verts_num], + BKE_defvert_ensure_index(&dst_dvert[new_vert_arr[i]], rim_defgrp_index)->weight = 1.0f; + BKE_defvert_ensure_index(&dst_dvert[(do_shell ? new_vert_arr[i] : i) + verts_num], rim_defgrp_index) ->weight = 1.0f; } @@ -1012,7 +1000,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex if (shell_defgrp_index != -1) { for (uint i = verts_num; i < result->totvert; i++) { - BKE_defvert_ensure_index(&result->dvert[i], shell_defgrp_index)->weight = 1.0f; + BKE_defvert_ensure_index(&dst_dvert[i], shell_defgrp_index)->weight = 1.0f; } } } @@ -1055,7 +1043,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* add faces & edges */ origindex_edge = CustomData_get_layer(&result->edata, CD_ORIGINDEX); orig_ed = (origindex_edge) ? &origindex_edge[(edges_num * stride) + newEdges] : NULL; - ed = &medge[(edges_num * stride) + newEdges]; /* start after copied edges */ + MEdge *ed = &medge[(edges_num * stride) + newEdges]; /* start after copied edges */ for (i = 0; i < rimVerts; i++, ed++) { ed->v1 = new_vert_arr[i]; ed->v2 = (do_shell ? new_vert_arr[i] : i) + verts_num; @@ -1072,8 +1060,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } /* faces */ - mp = mpoly + (polys_num * stride); - ml = mloop + (loops_num * stride); + MPoly *mp = mpoly + (polys_num * stride); + MLoop *ml = mloop + (loops_num * stride); j = 0; for (i = 0; i < newPolys; i++, mp++) { uint eidx = new_edge_arr[i]; @@ -1151,8 +1139,8 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex /* use the next material index if option enabled */ if (mat_ofs_rim) { - mp->mat_nr += mat_ofs_rim; - CLAMP(mp->mat_nr, 0, mat_nr_max); + dst_material_index[mp - mpoly] += mat_ofs_rim; + CLAMP(dst_material_index[mp - mpoly], 0, mat_nr_max); } if (crease_outer) { /* crease += crease_outer; without wrapping */ diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c index 9205083e836..0bce954a67a 100644 --- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c +++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c @@ -76,7 +76,7 @@ static float clamp_nonzero(const float value, const float epsilon) /* Data structures for manifold solidify. */ typedef struct NewFaceRef { - MPoly *face; + const MPoly *face; uint index; bool reversed; struct NewEdgeRef **link_edges; @@ -137,10 +137,6 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, Mesh *result; const SolidifyModifierData *smd = (SolidifyModifierData *)md; - MVert *mv, *mvert, *orig_mvert; - MEdge *ed, *medge, *orig_medge; - MLoop *ml, *mloop, *orig_mloop; - MPoly *mp, *mpoly, *orig_mpoly; const uint verts_num = (uint)mesh->totvert; const uint edges_num = (uint)mesh->totedge; const uint polys_num = (uint)mesh->totpoly; @@ -178,7 +174,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const float bevel_convex = smd->bevel_convex; - MDeformVert *dvert; + const MDeformVert *dvert; const bool defgrp_invert = (smd->flag & MOD_SOLIDIFY_VGROUP_INV) != 0; int defgrp_index; const int shell_defgrp_index = BKE_id_defgroup_name_index(&mesh->id, smd->shell_defgrp_name); @@ -188,10 +184,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, const bool do_flat_faces = dvert && (smd->flag & MOD_SOLIDIFY_NONMANIFOLD_FLAT_FACES); - orig_mvert = mesh->mvert; - orig_medge = mesh->medge; - orig_mloop = mesh->mloop; - orig_mpoly = mesh->mpoly; + const MVert *orig_mvert = BKE_mesh_vertices(mesh); + const MEdge *orig_medge = BKE_mesh_edges(mesh); + const MPoly *orig_mpoly = BKE_mesh_polygons(mesh); + const MLoop *orig_mloop = BKE_mesh_loops(mesh); uint new_verts_num = 0; uint new_edges_num = 0; @@ -213,11 +209,11 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint largest_ngon = 3; /* Calculate face to #NewFaceRef map. */ { - mp = orig_mpoly; + const MPoly *mp = orig_mpoly; for (uint i = 0; i < polys_num; i++, mp++) { /* Make normals for faces without area (should really be avoided though). */ if (len_squared_v3(poly_nors[i]) < 0.5f) { - MEdge *e = orig_medge + orig_mloop[mp->loopstart].e; + const MEdge *e = orig_medge + orig_mloop[mp->loopstart].e; float edgedir[3]; sub_v3_v3v3(edgedir, orig_mvert[e->v2].co, orig_mvert[e->v1].co); if (fabsf(edgedir[2]) < fabsf(edgedir[1])) { @@ -254,9 +250,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, edges_num, sizeof(*edge_adj_faces_len), "edge_adj_faces_len in solidify"); /* Count for each edge how many faces it has adjacent. */ { - mp = orig_mpoly; + const MPoly *mp = orig_mpoly; for (uint i = 0; i < polys_num; i++, mp++) { - ml = orig_mloop + mp->loopstart; + const MLoop *ml = orig_mloop + mp->loopstart; for (uint j = 0; j < mp->totloop; j++, ml++) { edge_adj_faces_len[ml->e]++; } @@ -304,9 +300,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Create link_faces for edges. */ { - mp = orig_mpoly; + const MPoly *mp = orig_mpoly; for (uint i = 0; i < polys_num; i++, mp++) { - ml = orig_mloop + mp->loopstart; + const MLoop *ml = orig_mloop + mp->loopstart; for (uint j = 0; j < mp->totloop; j++, ml++) { const uint edge = ml->e; const bool reversed = orig_medge[edge].v2 != ml->v; @@ -353,7 +349,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint *combined_verts = MEM_calloc_arrayN( verts_num, sizeof(*combined_verts), "combined_verts in solidify"); - ed = orig_medge; + const MEdge *ed = orig_medge; for (uint i = 0; i < edges_num; i++, ed++) { if (edge_adj_faces_len[i] > 0) { uint v1 = vm[ed->v1]; @@ -377,7 +373,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (k != i && edge_adj_faces_len[k] > 0 && (ELEM(vm[orig_medge[k].v1], v1, v2) != ELEM(vm[orig_medge[k].v2], v1, v2))) { for (uint j = 0; j < edge_adj_faces[k]->faces_len && can_merge; j++) { - mp = orig_mpoly + edge_adj_faces[k]->faces[j]; + const MPoly *mp = orig_mpoly + edge_adj_faces[k]->faces[j]; uint changes = 0; int cur = mp->totloop - 1; for (int next = 0; next < mp->totloop && changes <= 2; next++) { @@ -473,7 +469,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Create vert_adj_edges for verts. */ { - ed = orig_medge; + const MEdge *ed = orig_medge; for (uint i = 0; i < edges_num; i++, ed++) { if (edge_adj_faces_len[i] > 0) { const uint vs[2] = {vm[ed->v1], vm[ed->v2]}; @@ -592,7 +588,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Filter duplicate polys. */ { - ed = orig_medge; + const MEdge *ed = orig_medge; /* Iterate over edges and only check the faces around an edge for duplicates * (performance optimization). */ for (uint i = 0; i < edges_num; i++, ed++) { @@ -615,7 +611,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Find first face first loop vert in second face loops. */ const int k_loopstart = orig_mpoly[adj_faces->faces[k]].loopstart; int l; - ml = orig_mloop + k_loopstart; + const MLoop *ml = orig_mloop + k_loopstart; for (l = 0; l < totloop && vm[ml->v] != j_first_v; l++, ml++) { /* Pass. */ } @@ -703,7 +699,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Create #NewEdgeRef array. */ { - ed = orig_medge; + const MEdge *ed = orig_medge; for (uint i = 0; i < edges_num; i++, ed++) { const uint v1 = vm[ed->v1]; const uint v2 = vm[ed->v2]; @@ -848,7 +844,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, new_edges[j] = edge_data; for (uint k = 0; k < 2; k++) { if (faces[k] != NULL) { - ml = orig_mloop + faces[k]->face->loopstart; + const MLoop *ml = orig_mloop + faces[k]->face->loopstart; for (int l = 0; l < faces[k]->face->totloop; l++, ml++) { if (edge_adj_faces[ml->e] == edge_adj_faces[i]) { if (ml->e != i && orig_edge_data_arr[ml->e] == NULL) { @@ -1377,13 +1373,13 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (do_flat_faces) { face_weight = MEM_malloc_arrayN(polys_num, sizeof(*face_weight), "face_weight in solidify"); - mp = orig_mpoly; + const MPoly *mp = orig_mpoly; for (uint i = 0; i < polys_num; i++, mp++) { float scalar_vgroup = 1.0f; int loopend = mp->loopstart + mp->totloop; - ml = orig_mloop + mp->loopstart; + const MLoop *ml = orig_mloop + mp->loopstart; for (int j = mp->loopstart; j < loopend; j++, ml++) { - MDeformVert *dv = &dvert[ml->v]; + const MDeformVert *dv = &dvert[ml->v]; if (defgrp_invert) { scalar_vgroup = min_ff(1.0f - BKE_defvert_find_weight(dv, defgrp_index), scalar_vgroup); @@ -1397,7 +1393,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } } - mv = orig_mvert; + const MVert *mv = orig_mvert; gs_ptr = orig_vert_groups_arr; for (uint i = 0; i < verts_num; i++, mv++, gs_ptr++) { if (*gs_ptr) { @@ -1655,9 +1651,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (smd->nonmanifold_offset_mode == MOD_SOLIDIFY_NONMANIFOLD_OFFSET_MODE_EVEN) { - MLoop *ml_next = orig_mloop + face->face->loopstart; - ml = ml_next + (face->face->totloop - 1); - MLoop *ml_prev = ml - 1; + const MLoop *ml_next = orig_mloop + face->face->loopstart; + const MLoop *ml = ml_next + (face->face->totloop - 1); + const MLoop *ml_prev = ml - 1; for (int m = 0; m < face->face->totloop && vm[ml->v] != i; m++, ml_next++) { ml_prev = ml; @@ -1766,7 +1762,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, float tmp[3]; int k; for (k = 1; k + 1 < g->edges_len; k++, edge_ptr++) { - MEdge *e = orig_medge + (*edge_ptr)->old_edge; + const MEdge *e = orig_medge + (*edge_ptr)->old_edge; sub_v3_v3v3(tmp, orig_mvert_co[vm[e->v1] == i ? e->v2 : e->v1], orig_mvert_co[i]); add_v3_v3(move_nor, tmp); } @@ -1781,8 +1777,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!disable_boundary_fix) { /* Constraint normal, nor * constr_nor == 0 after this fix. */ float constr_nor[3]; - MEdge *e0_edge = orig_medge + g->edges[0]->old_edge; - MEdge *e1_edge = orig_medge + g->edges[g->edges_len - 1]->old_edge; + const MEdge *e0_edge = orig_medge + g->edges[0]->old_edge; + const MEdge *e1_edge = orig_medge + g->edges[g->edges_len - 1]->old_edge; float e0[3]; float e1[3]; sub_v3_v3v3(e0, @@ -1831,7 +1827,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, float scalar_vgroup = 1; /* Use vertex group. */ if (dvert && !do_flat_faces) { - MDeformVert *dv = &dvert[i]; + const MDeformVert *dv = &dvert[i]; if (defgrp_invert) { scalar_vgroup = 1.0f - BKE_defvert_find_weight(dv, defgrp_index); } @@ -1961,10 +1957,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, (int)(new_loops_num), (int)(new_polys_num)); - mpoly = result->mpoly; - mloop = result->mloop; - medge = result->medge; - mvert = result->mvert; + MVert *mvert = BKE_mesh_vertices_for_write(result); + MEdge *medge = BKE_mesh_edges_for_write(result); + MPoly *mpoly = BKE_mesh_polygons_for_write(result); + MLoop *mloop = BKE_mesh_loops_for_write(result); int *origindex_edge = CustomData_get_layer(&result->edata, CD_ORIGINDEX); int *origindex_poly = CustomData_get_layer(&result->pdata, CD_ORIGINDEX); @@ -1975,15 +1971,9 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } /* Checks that result has dvert data. */ + MDeformVert *dst_dvert = NULL; if (shell_defgrp_index != -1 || rim_defgrp_index != -1) { - dvert = CustomData_duplicate_referenced_layer(&result->vdata, CD_MDEFORMVERT, result->totvert); - /* If no vertices were ever added to an object's vgroup, dvert might be NULL. */ - if (dvert == NULL) { - /* Add a valid data layer! */ - dvert = CustomData_add_layer( - &result->vdata, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, result->totvert); - } - result->dvert = dvert; + dst_dvert = BKE_mesh_deform_verts_for_write(result); } /* Get vertex crease layer and ensure edge creases are active if vertex creases are found, since @@ -2108,10 +2098,13 @@ 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); + /* Make boundary edges/faces. */ { gs_ptr = orig_vert_groups_arr; - mv = orig_mvert; + const MVert *mv = orig_mvert; for (uint i = 0; i < verts_num; i++, gs_ptr++, mv++) { EdgeGroup *gs = *gs_ptr; if (gs) { @@ -2144,7 +2137,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } else { for (uint k = 1; k < g->edges_len - 1; k++) { - ed = orig_medge + g->edges[k]->old_edge; + const MEdge *ed = orig_medge + g->edges[k]->old_edge; if (ed->crease > max_crease) { max_crease = ed->crease; } @@ -2224,7 +2217,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Loop data. */ int *loops = MEM_malloc_arrayN(j, sizeof(*loops), "loops in solidify"); - /* The #mat_nr is from consensus. */ + /* The result material index is from consensus. */ short most_mat_nr = 0; uint most_mat_nr_face = 0; uint most_mat_nr_count = 0; @@ -2235,16 +2228,20 @@ 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 (g3->edges[0]->faces[0]->face->mat_nr == l) { + if ((src_material_index ? 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] && le->faces[1]->face->mat_nr == l) { + if (le->faces[1] && + (src_material_index ? src_material_index[le->faces[1]->index] : 0) == l) { face = le->faces[1]->index; count++; } - else if (!le->faces[1] && le->faces[0]->face->mat_nr == l) { + else if (!le->faces[1] && + (src_material_index ? src_material_index[le->faces[0]->index] : 0) == + l) { face = le->faces[0]->index; count++; } @@ -2264,16 +2261,16 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } mpoly[poly_index].loopstart = (int)loop_index; mpoly[poly_index].totloop = (int)j; - mpoly[poly_index].mat_nr = most_mat_nr + - (g->is_orig_closed || !do_rim ? 0 : mat_ofs_rim); - CLAMP(mpoly[poly_index].mat_nr, 0, mat_nr_max); + dst_material_index[poly_index] = most_mat_nr + + (g->is_orig_closed || !do_rim ? 0 : mat_ofs_rim); + CLAMP(dst_material_index[poly_index], 0, mat_nr_max); mpoly[poly_index].flag = orig_mpoly[most_mat_nr_face].flag; poly_index++; for (uint k = 0; g2->valid && k < j; g2++) { if ((do_rim && !g2->is_orig_closed) || (do_shell && g2->split)) { - MPoly *face = g2->edges[0]->faces[0]->face; - ml = orig_mloop + face->loopstart; + const MPoly *face = g2->edges[0]->faces[0]->face; + const MLoop *ml = orig_mloop + face->loopstart; for (int l = 0; l < face->totloop; l++, ml++) { if (vm[ml->v] == i) { loops[k] = face->loopstart + l; @@ -2334,19 +2331,21 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, continue; } - MPoly *face = (*new_edges)->faces[0]->face; + const uint orig_face_index = (*new_edges)->faces[0]->index; + const MPoly *face = (*new_edges)->faces[0]->face; CustomData_copy_data( &mesh->pdata, &result->pdata, (int)(*new_edges)->faces[0]->index, (int)poly_index, 1); mpoly[poly_index].loopstart = (int)loop_index; mpoly[poly_index].totloop = 4 - (int)(v1_singularity || v2_singularity); - mpoly[poly_index].mat_nr = face->mat_nr + mat_ofs_rim; - CLAMP(mpoly[poly_index].mat_nr, 0, mat_nr_max); + dst_material_index[poly_index] = + (src_material_index ? src_material_index[orig_face_index] : 0) + mat_ofs_rim; + CLAMP(dst_material_index[poly_index], 0, mat_nr_max); mpoly[poly_index].flag = face->flag; poly_index++; int loop1 = -1; int loop2 = -1; - ml = orig_mloop + face->loopstart; + const MLoop *ml = orig_mloop + face->loopstart; const uint old_v1 = vm[orig_medge[edge1->old_edge].v1]; const uint old_v2 = vm[orig_medge[edge1->old_edge].v2]; for (uint j = 0; j < face->totloop; j++, ml++) { @@ -2362,7 +2361,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, uint open_face_edge_index; if (!do_flip) { if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge1->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, (int)loop_index, 1); @@ -2372,7 +2371,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!v2_singularity) { open_face_edge_index = edge1->link_edge_groups[1]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge1->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, (int)loop_index, 1); @@ -2387,7 +2386,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge2->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, (int)loop_index, 1); @@ -2397,7 +2396,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!v1_singularity) { open_face_edge_index = edge2->link_edge_groups[0]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge2->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, (int)loop_index, 1); @@ -2415,7 +2414,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!v1_singularity) { open_face_edge_index = edge1->link_edge_groups[0]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge1->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, (int)loop_index, 1); @@ -2430,7 +2429,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge2->new_edge].v1], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v1], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop1, (int)loop_index, 1); @@ -2440,7 +2439,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, if (!v2_singularity) { open_face_edge_index = edge2->link_edge_groups[1]->open_face_edge; if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge2->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge2->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, (int)loop_index, 1); @@ -2455,7 +2454,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, } if (rim_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[medge[edge1->new_edge].v2], rim_defgrp_index) + BKE_defvert_ensure_index(&dst_dvert[medge[edge1->new_edge].v2], rim_defgrp_index) ->weight = 1.0f; } CustomData_copy_data(&mesh->ldata, &result->ldata, loop2, (int)loop_index, 1); @@ -2530,14 +2529,16 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, CustomData_copy_data(&mesh->pdata, &result->pdata, (int)(i / 2), (int)poly_index, 1); mpoly[poly_index].loopstart = (int)loop_index; mpoly[poly_index].totloop = (int)k; - mpoly[poly_index].mat_nr = fr->face->mat_nr + (fr->reversed != do_flip ? mat_ofs : 0); - CLAMP(mpoly[poly_index].mat_nr, 0, mat_nr_max); + dst_material_index[poly_index] = (src_material_index ? src_material_index[fr->index] : + 0) + + (fr->reversed != do_flip ? mat_ofs : 0); + CLAMP(dst_material_index[poly_index], 0, mat_nr_max); mpoly[poly_index].flag = fr->face->flag; if (fr->reversed != do_flip) { for (int l = (int)k - 1; l >= 0; l--) { if (shell_defgrp_index != -1) { - BKE_defvert_ensure_index(&result->dvert[face_verts[l]], shell_defgrp_index) - ->weight = 1.0f; + BKE_defvert_ensure_index(&dst_dvert[face_verts[l]], shell_defgrp_index)->weight = + 1.0f; } CustomData_copy_data( &mesh->ldata, &result->ldata, (int)face_loops[l], (int)loop_index, 1); diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index 3e5a577a806..93da7969a09 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -125,7 +125,6 @@ static void deformVerts(ModifierData *md, if (surmd->mesh) { uint mesh_verts_num = 0, i = 0; int init = 0; - float *vec; MVert *x, *v; BKE_mesh_vert_coords_apply(surmd->mesh, vertexCos); @@ -152,8 +151,9 @@ static void deformVerts(ModifierData *md, } /* convert to global coordinates and calculate velocity */ + MVert *verts = BKE_mesh_vertices_for_write(surmd->mesh); for (i = 0, x = surmd->x, v = surmd->v; i < mesh_verts_num; i++, x++, v++) { - vec = surmd->mesh->mvert[i].co; + float *vec = verts[i].co; mul_m4_v3(ctx->object->obmat, vec); if (init) { diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index 96e761e86b6..50071cad1b9 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -1171,10 +1171,10 @@ static bool surfacedeformBind(Object *ob, Mesh *mesh) { BVHTreeFromMesh treeData = {NULL}; - const MVert *mvert = target->mvert; - const MPoly *mpoly = target->mpoly; - const MEdge *medge = target->medge; - const MLoop *mloop = target->mloop; + const MVert *mvert = BKE_mesh_vertices(target); + const MPoly *mpoly = BKE_mesh_polygons(target); + const MEdge *medge = BKE_mesh_edges(target); + const MLoop *mloop = BKE_mesh_loops(target); uint tedges_num = target->totedge; int adj_result; SDefAdjacencyArray *vert_edges; @@ -1236,7 +1236,7 @@ static bool surfacedeformBind(Object *ob, smd_orig->target_polys_num = target_polys_num; int defgrp_index; - MDeformVert *dvert; + const MDeformVert *dvert; MOD_get_vgroup(ob, mesh, smd_orig->defgrp_name, &dvert, &defgrp_index); const bool invert_vgroup = (smd_orig->flags & MOD_SDEF_INVERT_VGROUP) != 0; const bool sparse_bind = (smd_orig->flags & MOD_SDEF_SPARSE_BIND) != 0; @@ -1538,7 +1538,7 @@ static void surfacedeformModifier_do(ModifierData *md, } int defgrp_index; - MDeformVert *dvert; + const MDeformVert *dvert; MOD_get_vgroup(ob, mesh, smd->defgrp_name, &dvert, &defgrp_index); const bool invert_vgroup = (smd->flags & MOD_SDEF_INVERT_VGROUP) != 0; diff --git a/source/blender/modifiers/intern/MOD_triangulate.c b/source/blender/modifiers/intern/MOD_triangulate.c index d4faf682cdc..e8280bc9c97 100644 --- a/source/blender/modifiers/intern/MOD_triangulate.c +++ b/source/blender/modifiers/intern/MOD_triangulate.c @@ -82,7 +82,7 @@ static Mesh *triangulate_mesh(Mesh *mesh, } edges_num = result->totedge; - me = result->medge; + me = BKE_mesh_edges_for_write(result); /* force drawing of all edges (seems to be omitted in CDDM_from_bmesh) */ for (i = 0; i < edges_num; i++, me++) { diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index afbce748bab..e1907c7fce1 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -94,9 +94,9 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd, /* UVs need special handling, since they come from faces */ if (texmapping == MOD_DISP_MAP_UV) { if (CustomData_has_layer(&mesh->ldata, CD_PROP_FLOAT2)) { - MPoly *mpoly = mesh->mpoly; - MPoly *mp; - MLoop *mloop = mesh->mloop; + const MPoly *mpoly = BKE_mesh_polygons(mesh); + const MPoly *mp; + const MLoop *mloop = BKE_mesh_loops(mesh); BLI_bitmap *done = BLI_BITMAP_NEW(verts_num, __func__); const int polys_num = mesh->totpoly; char uvname[MAX_CUSTOMDATA_LAYER_NAME]; @@ -129,7 +129,7 @@ void MOD_get_texture_coords(MappingInfoModifierData *dmd, texmapping = MOD_DISP_MAP_LOCAL; } - MVert *mv = mesh->mvert; + const MVert *mv = BKE_mesh_vertices(mesh); for (i = 0; i < verts_num; i++, mv++, r_texco++) { switch (texmapping) { case MOD_DISP_MAP_LOCAL: @@ -223,12 +223,12 @@ Mesh *MOD_deform_mesh_eval_get(Object *ob, } void MOD_get_vgroup( - Object *ob, struct Mesh *mesh, const char *name, MDeformVert **dvert, int *defgrp_index) + Object *ob, struct Mesh *mesh, const char *name, const MDeformVert **dvert, int *defgrp_index) { if (mesh) { *defgrp_index = BKE_id_defgroup_name_index(&mesh->id, name); if (*defgrp_index != -1) { - *dvert = mesh->dvert; + *dvert = BKE_mesh_deform_verts(mesh); } else { *dvert = NULL; diff --git a/source/blender/modifiers/intern/MOD_util.h b/source/blender/modifiers/intern/MOD_util.h index b675c11b370..5f9bd97744b 100644 --- a/source/blender/modifiers/intern/MOD_util.h +++ b/source/blender/modifiers/intern/MOD_util.h @@ -47,7 +47,7 @@ struct Mesh *MOD_deform_mesh_eval_get(struct Object *ob, void MOD_get_vgroup(struct Object *ob, struct Mesh *mesh, const char *name, - struct MDeformVert **dvert, + const struct MDeformVert **dvert, int *defgrp_index); void MOD_depsgraph_update_object_bone_relation(struct DepsNodeHandle *node, diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index 61c5cd32cd7..d4834584952 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -97,10 +97,8 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, Mesh *mesh) { float(*coords)[3], (*co)[3]; - float(*mloop_uv)[2]; int i, verts_num, polys_num, loops_num; - MPoly *mpoly, *mp; - MLoop *mloop; + const MPoly *mp; Projector projectors[MOD_UVPROJECT_MAXPROJECTORS]; int projectors_num = 0; char uvname[MAX_CUSTOMDATA_LAYER_NAME]; @@ -188,7 +186,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, loops_num = mesh->totloop; /* make sure we are not modifying the original UV map */ - mloop_uv = CustomData_duplicate_referenced_layer_named( + float(*mloop_uv)[2] = CustomData_duplicate_referenced_layer_named( &mesh->ldata, CD_PROP_FLOAT2, uvname, loops_num); coords = BKE_mesh_vert_coords_alloc(mesh, &verts_num); @@ -205,17 +203,17 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, } } - mpoly = mesh->mpoly; - mloop = mesh->mloop; + const MPoly *polys = BKE_mesh_polygons(mesh); + const MLoop *loops = BKE_mesh_loops(mesh); /* apply coords as UVs */ - for (i = 0, mp = mpoly; i < polys_num; i++, mp++) { + for (i = 0, mp = polys; i < polys_num; i++, mp++) { if (projectors_num == 1) { if (projectors[0].uci) { uint fidx = mp->totloop - 1; do { uint lidx = mp->loopstart + fidx; - uint vidx = mloop[lidx].v; + uint vidx = loops[lidx].v; BLI_uvproject_from_camera(mloop_uv[lidx], coords[vidx], projectors[0].uci); } while (fidx--); } @@ -224,7 +222,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, uint fidx = mp->totloop - 1; do { uint lidx = mp->loopstart + fidx; - uint vidx = mloop[lidx].v; + uint vidx = loops[lidx].v; copy_v2_v2(mloop_uv[lidx], coords[vidx]); } while (fidx--); } @@ -238,7 +236,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, /* get the untransformed face normal */ BKE_mesh_calc_poly_normal_coords( - mp, mloop + mp->loopstart, (const float(*)[3])coords, face_no); + mp, loops + mp->loopstart, (const float(*)[3])coords, face_no); /* find the projector which the face points at most directly * (projector normal with largest dot product is best) @@ -258,7 +256,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, uint fidx = mp->totloop - 1; do { uint lidx = mp->loopstart + fidx; - uint vidx = mloop[lidx].v; + uint vidx = loops[lidx].v; BLI_uvproject_from_camera(mloop_uv[lidx], coords[vidx], best_projector->uci); } while (fidx--); } @@ -266,7 +264,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd, uint fidx = mp->totloop - 1; do { uint lidx = mp->loopstart + fidx; - uint vidx = mloop[lidx].v; + uint vidx = loops[lidx].v; mul_v2_project_m4_v3(mloop_uv[lidx], best_projector->projmat, coords[vidx]); } while (fidx--); } diff --git a/source/blender/modifiers/intern/MOD_uvwarp.c b/source/blender/modifiers/intern/MOD_uvwarp.c index 9f3c6e10828..0bfd53cf898 100644 --- a/source/blender/modifiers/intern/MOD_uvwarp.c +++ b/source/blender/modifiers/intern/MOD_uvwarp.c @@ -23,6 +23,7 @@ #include "BKE_context.h" #include "BKE_deform.h" #include "BKE_lib_query.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_screen.h" @@ -81,11 +82,11 @@ static void matrix_from_obj_pchan(float mat[4][4], Object *ob, const char *bonen } typedef struct UVWarpData { - MPoly *mpoly; - MLoop *mloop; + const MPoly *mpoly; + const MLoop *mloop; float (*mloopuv)[2]; - MDeformVert *dvert; + const MDeformVert *dvert; int defgrp_index; float (*warp_mat)[4]; @@ -131,10 +132,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * { UVWarpModifierData *umd = (UVWarpModifierData *)md; int polys_num, loops_num; - MPoly *mpoly; - MLoop *mloop; float(*mloopuv)[2]; - MDeformVert *dvert; + const MDeformVert *dvert; int defgrp_index; char uvname[MAX_CUSTOMDATA_LAYER_NAME]; float warp_mat[4][4]; @@ -196,19 +195,19 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * /* make sure we're using an existing layer */ CustomData_validate_layer_name(&mesh->ldata, CD_PROP_FLOAT2, umd->uvlayer_name, uvname); + const MPoly *polys = BKE_mesh_polygons(mesh); + const MLoop *loops = BKE_mesh_loops(mesh); polys_num = mesh->totpoly; loops_num = mesh->totloop; - mpoly = mesh->mpoly; - mloop = mesh->mloop; /* make sure we are not modifying the original UV map */ mloopuv = CustomData_duplicate_referenced_layer_named( &mesh->ldata, CD_PROP_FLOAT2, uvname, loops_num); MOD_get_vgroup(ctx->object, mesh, umd->vgroup_name, &dvert, &defgrp_index); UVWarpData data = { - .mpoly = mpoly, - .mloop = mloop, + .mpoly = polys, + .mloop = loops, .mloopuv = mloopuv, .dvert = dvert, .defgrp_index = defgrp_index, diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c index 0968d0646a5..ab6b2941d2f 100644 --- a/source/blender/modifiers/intern/MOD_warp.c +++ b/source/blender/modifiers/intern/MOD_warp.c @@ -196,7 +196,7 @@ static void warpModifier_do(WarpModifierData *wmd, float fac = 1.0f, weight; int i; int defgrp_index; - MDeformVert *dvert, *dv = NULL; + const MDeformVert *dvert, *dv = NULL; const bool invert_vgroup = (wmd->flag & MOD_WARP_INVERT_VGROUP) != 0; float(*tex_co)[3] = NULL; diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index 9647f47c6e0..a6b274909c0 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -134,8 +134,7 @@ static void waveModifier_do(WaveModifierData *md, int verts_num) { WaveModifierData *wmd = (WaveModifierData *)md; - MVert *mvert = NULL; - MDeformVert *dvert; + const MDeformVert *dvert; int defgrp_index; float ctime = DEG_get_ctime(ctx->depsgraph); float minfac = (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow)); @@ -148,7 +147,6 @@ static void waveModifier_do(WaveModifierData *md, const float(*vert_normals)[3] = NULL; if ((wmd->flag & MOD_WAVE_NORM) && (mesh != NULL)) { - mvert = mesh->mvert; vert_normals = BKE_mesh_vertex_normals_ensure(mesh); } @@ -269,7 +267,7 @@ static void waveModifier_do(WaveModifierData *md, /* Apply weight & falloff. */ amplit *= def_weight * falloff_fac; - if (mvert) { + if (vert_normals) { /* move along normals */ if (wmd->flag & MOD_WAVE_NORM_X) { co[0] += (lifefac * amplit) * vert_normals[i][0]; diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.c b/source/blender/modifiers/intern/MOD_weighted_normal.c index 5b5d464a710..c6c0ce58463 100644 --- a/source/blender/modifiers/intern/MOD_weighted_normal.c +++ b/source/blender/modifiers/intern/MOD_weighted_normal.c @@ -71,20 +71,20 @@ typedef struct WeightedNormalData { const int loops_num; const int polys_num; - MVert *mvert; + const MVert *mvert; const float (*vert_normals)[3]; MEdge *medge; - MLoop *mloop; + const MLoop *mloop; short (*clnors)[2]; const bool has_clnors; /* True if clnors already existed, false if we had to create them. */ const float split_angle; - MPoly *mpoly; + const MPoly *mpoly; const float (*polynors)[3]; const int *poly_strength; - MDeformVert *dvert; + const MDeformVert *dvert; const int defgrp_index; const bool use_invert_vgroup; @@ -133,7 +133,7 @@ static void aggregate_item_normal(WeightedNormalModifierData *wnmd, { const float(*polynors)[3] = wn_data->polynors; - MDeformVert *dvert = wn_data->dvert; + const MDeformVert *dvert = wn_data->dvert; const int defgrp_index = wn_data->defgrp_index; const bool use_invert_vgroup = wn_data->use_invert_vgroup; @@ -186,18 +186,18 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, const int loops_num = wn_data->loops_num; const int polys_num = wn_data->polys_num; - MVert *mvert = wn_data->mvert; + const MVert *mvert = wn_data->mvert; MEdge *medge = wn_data->medge; - MLoop *mloop = wn_data->mloop; + const MLoop *mloop = wn_data->mloop; short(*clnors)[2] = wn_data->clnors; int *loop_to_poly = wn_data->loop_to_poly; - MPoly *mpoly = wn_data->mpoly; + const MPoly *mpoly = wn_data->mpoly; const float(*polynors)[3] = wn_data->polynors; const int *poly_strength = wn_data->poly_strength; - MDeformVert *dvert = wn_data->dvert; + const MDeformVert *dvert = wn_data->dvert; const short mode = wn_data->mode; ModePair *mode_pair = wn_data->mode_pair; @@ -243,7 +243,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd, /* In this first loop, we assign each WeightedNormalDataAggregateItem * to its smooth fan of loops (aka lnor space). */ - MPoly *mp; + const MPoly *mp; int mp_index; int item_index; for (mp = mpoly, mp_index = 0, item_index = 0; mp_index < polys_num; mp++, mp_index++) { @@ -446,11 +446,11 @@ static void wn_face_area(WeightedNormalModifierData *wnmd, WeightedNormalData *w { const int polys_num = wn_data->polys_num; - MVert *mvert = wn_data->mvert; - MLoop *mloop = wn_data->mloop; - MPoly *mpoly = wn_data->mpoly; + const MVert *mvert = wn_data->mvert; + const MLoop *mloop = wn_data->mloop; + const MPoly *mpoly = wn_data->mpoly; - MPoly *mp; + const MPoly *mp; int mp_index; ModePair *face_area = MEM_malloc_arrayN((size_t)polys_num, sizeof(*face_area), __func__); @@ -472,11 +472,11 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData const int loops_num = wn_data->loops_num; const int polys_num = wn_data->polys_num; - MVert *mvert = wn_data->mvert; - MLoop *mloop = wn_data->mloop; - MPoly *mpoly = wn_data->mpoly; + const MVert *mvert = wn_data->mvert; + const MLoop *mloop = wn_data->mloop; + const MPoly *mpoly = wn_data->mpoly; - MPoly *mp; + const MPoly *mp; int mp_index; int *loop_to_poly = MEM_malloc_arrayN((size_t)loops_num, sizeof(*loop_to_poly), __func__); @@ -484,7 +484,7 @@ static void wn_corner_angle(WeightedNormalModifierData *wnmd, WeightedNormalData ModePair *corner_angle = MEM_malloc_arrayN((size_t)loops_num, sizeof(*corner_angle), __func__); for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++) { - MLoop *ml_start = &mloop[mp->loopstart]; + const MLoop *ml_start = &mloop[mp->loopstart]; float *index_angle = MEM_malloc_arrayN((size_t)mp->totloop, sizeof(*index_angle), __func__); BKE_mesh_calc_poly_angles(mp, ml_start, mvert, index_angle); @@ -513,11 +513,11 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD const int loops_num = wn_data->loops_num; const int polys_num = wn_data->polys_num; - MVert *mvert = wn_data->mvert; - MLoop *mloop = wn_data->mloop; - MPoly *mpoly = wn_data->mpoly; + const MVert *mvert = wn_data->mvert; + const MLoop *mloop = wn_data->mloop; + const MPoly *mpoly = wn_data->mpoly; - MPoly *mp; + const MPoly *mp; int mp_index; int *loop_to_poly = MEM_malloc_arrayN((size_t)loops_num, sizeof(*loop_to_poly), __func__); @@ -525,7 +525,7 @@ static void wn_face_with_angle(WeightedNormalModifierData *wnmd, WeightedNormalD ModePair *combined = MEM_malloc_arrayN((size_t)loops_num, sizeof(*combined), __func__); for (mp_index = 0, mp = mpoly; mp_index < polys_num; mp_index++, mp++) { - MLoop *ml_start = &mloop[mp->loopstart]; + const MLoop *ml_start = &mloop[mp->loopstart]; float face_area = BKE_mesh_calc_poly_area(mp, ml_start, mvert); float *index_angle = MEM_malloc_arrayN((size_t)mp->totloop, sizeof(*index_angle), __func__); @@ -579,11 +579,10 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * const int edges_num = result->totedge; const int loops_num = result->totloop; const int polys_num = result->totpoly; - - MEdge *medge = result->medge; - MPoly *mpoly = result->mpoly; - MVert *mvert = result->mvert; - MLoop *mloop = result->mloop; + const MVert *mvert = BKE_mesh_vertices(result); + MEdge *medge = BKE_mesh_edges_for_write(result); + const MPoly *mpoly = BKE_mesh_polygons(result); + const MLoop *mloop = BKE_mesh_loops(result); /* Right now: * If weight = 50 then all faces are given equal weight. @@ -613,7 +612,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * &result->ldata, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, NULL, loops_num); } - MDeformVert *dvert; + const MDeformVert *dvert; int defgrp_index; MOD_get_vgroup(ctx->object, mesh, wnmd->defgrp_name, &dvert, &defgrp_index); diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index d71813c7dd5..4002718d06c 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -27,6 +27,7 @@ #include "BKE_context.h" #include "BKE_deform.h" #include "BKE_lib_query.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_screen.h" #include "BKE_texture.h" /* Texture masking. */ @@ -158,7 +159,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md; - MDeformVert *dvert = NULL; MDeformWeight **dw = NULL; float *org_w; /* Array original weights. */ float *new_w; /* Array new weights. */ @@ -198,18 +198,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } } - if (has_mdef) { - dvert = CustomData_duplicate_referenced_layer(&mesh->vdata, CD_MDEFORMVERT, verts_num); - } - else { - /* Add a valid data layer! */ - dvert = CustomData_add_layer(&mesh->vdata, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, verts_num); - } + MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + /* Ultimate security check. */ if (!dvert) { return mesh; } - mesh->dvert = dvert; /* Get org weights, assuming 0.0 for vertices not in given vgroup. */ org_w = MEM_malloc_arrayN(verts_num, sizeof(float), "WeightVGEdit Modifier, org_w"); diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 1d38333f15b..1481ffad82c 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -23,6 +23,7 @@ #include "BKE_customdata.h" #include "BKE_deform.h" #include "BKE_lib_query.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_screen.h" #include "BKE_texture.h" /* Texture masking. */ @@ -206,7 +207,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * WeightVGMixModifierData *wmd = (WeightVGMixModifierData *)md; - MDeformVert *dvert = NULL; MDeformWeight **dw1, **tdw1, **dw2, **tdw2; float *org_w; float *new_w; @@ -263,18 +263,12 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } } - if (has_mdef) { - dvert = CustomData_duplicate_referenced_layer(&mesh->vdata, CD_MDEFORMVERT, verts_num); - } - else { - /* Add a valid data layer! */ - dvert = CustomData_add_layer(&mesh->vdata, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, verts_num); - } + MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); + /* Ultimate security check. */ if (!dvert) { return mesh; } - mesh->dvert = dvert; /* Find out which vertices to work on. */ tidx = MEM_malloc_arrayN(verts_num, sizeof(int), "WeightVGMix Modifier, tidx"); diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index df2b494199e..80c49745003 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -423,7 +423,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * BLI_assert(mesh != NULL); WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *)md; - MDeformVert *dvert = NULL; MDeformWeight **dw, **tdw; float(*v_cos)[3] = NULL; /* The vertices coordinates. */ Object *ob = ctx->object; @@ -475,12 +474,11 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * return mesh; } - dvert = CustomData_duplicate_referenced_layer(&mesh->vdata, CD_MDEFORMVERT, verts_num); + MDeformVert *dvert = BKE_mesh_deform_verts_for_write(mesh); /* Ultimate security check. */ if (!dvert) { return mesh; } - mesh->dvert = dvert; /* Find out which vertices to work on (all vertices in vgroup), and get their relevant weight. */ tidx = MEM_malloc_arrayN(verts_num, sizeof(int), "WeightVGProximity Modifier, tidx"); |