diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index d26a96bea21..fead48b0ff3 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -97,7 +97,7 @@ typedef struct ClothVertex { float tv[3]; /* temporary "velocity", mostly used as tv = tx-txold */ float mass; /* mass / weight of the vertex */ float goal; /* goal, from SB */ - float impulse[3]; /* used in collision.c */ + float impulse[3]; /* used in collision.cc */ float xrest[3]; /* rest position of the vertex */ float dcvel[3]; /* delta velocities to be applied by collision response */ unsigned int impulse_count; /* same as above */ @@ -196,7 +196,7 @@ typedef enum { } CLOTH_SPRINGS_FLAGS; /* -------------------------------------------------------------------- */ -/* collision.c */ +/* collision.cc */ struct CollPair; @@ -232,7 +232,7 @@ void clothModifier_do(struct ClothModifierData *clmd, int cloth_uses_vgroup(struct ClothModifierData *clmd); -/* Needed for collision.c */ +/* Needed for collision.cc */ void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving, bool self); /* Needed for button_object.c */ diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h index 8e566f08b5d..868a4760e2a 100644 --- a/source/blender/blenkernel/BKE_collision.h +++ b/source/blender/blenkernel/BKE_collision.h @@ -18,7 +18,7 @@ struct MVertTri; struct Object; //////////////////////////////////////// -// used for collisions in collision.c +// used for collisions in collision.cc //////////////////////////////////////// /* COLLISION FLAGS */ @@ -32,9 +32,9 @@ typedef enum { } COLLISION_FLAGS; //////////////////////////////////////// -// used for collisions in collision.c +// used for collisions in collision.cc //////////////////////////////////////// -/* used for collisions in collision.c */ +/* used for collisions in collision.cc */ typedef struct CollPair { unsigned int face1; /* cloth face */ unsigned int face2; /* object face */ @@ -58,7 +58,7 @@ typedef struct CollPair { int pointsb[4]; } CollPair; -/* used for collisions in collision.c */ +/* used for collisions in collision.cc */ typedef struct EdgeCollPair { unsigned int p11, p12, p21, p22; float normal[3]; @@ -68,7 +68,7 @@ typedef struct EdgeCollPair { float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */ } EdgeCollPair; -/* used for collisions in collision.c */ +/* used for collisions in collision.cc */ typedef struct FaceCollPair { unsigned int p11, p12, p13, p21; float normal[3]; @@ -85,7 +85,7 @@ typedef struct FaceCollPair { ///////////////////////////////////////////////// ///////////////////////////////////////////////// -// used in modifier.cc from collision.c +// used in modifier.cc from collision.cc ///////////////////////////////////////////////// struct BVHTree *bvhtree_build_from_mvert(const float (*positions)[3], diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index bad71c19afa..3017f90a951 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -92,7 +92,7 @@ set(SRC intern/cdderivedmesh.cc intern/cloth.cc intern/collection.c - intern/collision.c + intern/collision.cc intern/colorband.c intern/colortools.c intern/compute_contexts.cc diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.cc similarity index 94% rename from source/blender/blenkernel/intern/collision.c rename to source/blender/blenkernel/intern/collision.cc index 9ff9ec08816..09b863990e5 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.cc @@ -41,7 +41,7 @@ # include "eltopo-capi.h" #endif -typedef struct ColDetectData { +struct ColDetectData { ClothModifierData *clmd; CollisionModifierData *collmd; BVHTreeOverlap *overlap; @@ -49,14 +49,14 @@ typedef struct ColDetectData { bool culling; bool use_normal; bool collided; -} ColDetectData; +}; -typedef struct SelfColDetectData { +struct SelfColDetectData { ClothModifierData *clmd; BVHTreeOverlap *overlap; CollPair *collisions; bool collided; -} SelfColDetectData; +}; /*********************************** * Collision modifier code start @@ -93,7 +93,7 @@ void collision_move_object(CollisionModifierData *collmd, } BVHTree *bvhtree_build_from_mvert(const float (*positions)[3], - const struct MVertTri *tri, + const MVertTri *tri, int tri_num, float epsilon) { @@ -126,11 +126,11 @@ void bvhtree_update_from_mvert(BVHTree *bvhtree, bool moving) { - if ((bvhtree == NULL) || (positions == NULL)) { + if ((bvhtree == nullptr) || (positions == nullptr)) { return; } - if (positions_moving == NULL) { + if (positions_moving == nullptr) { moving = false; } @@ -155,7 +155,7 @@ void bvhtree_update_from_mvert(BVHTree *bvhtree, ret = BLI_bvhtree_update_node(bvhtree, i, &co[0][0], &co_moving[0][0], 3); } else { - ret = BLI_bvhtree_update_node(bvhtree, i, &co[0][0], NULL, 3); + ret = BLI_bvhtree_update_node(bvhtree, i, &co[0][0], nullptr, 3); } /* check if tree is already full */ @@ -254,7 +254,7 @@ static float compute_collision_point_tri_tri(const float a1[3], /* Point projections. */ for (int i = 0; i < 3; i++) { - if (isect_ray_tri_v3(a[i], normal, b[0], b[1], b[2], &tmp, NULL)) { + if (isect_ray_tri_v3(a[i], normal, b[0], b[1], b[2], &tmp, nullptr)) { if (tmp > maxdist) { maxdist = tmp; copy_v3_v3(r_a, a[i]); @@ -267,7 +267,7 @@ static float compute_collision_point_tri_tri(const float a1[3], negate_v3(normal); for (int i = 0; i < 3; i++) { - if (isect_ray_tri_v3(b[i], normal, a[0], a[1], a[2], &tmp, NULL)) { + if (isect_ray_tri_v3(b[i], normal, a[0], a[1], a[2], &tmp, nullptr)) { if (tmp > maxdist) { maxdist = tmp; madd_v3_v3v3fl(r_a, b[i], normal, tmp); @@ -418,7 +418,7 @@ static float compute_collision_point_edge_tri(const float a1[3], normal_tri_v3(normal, b[0], b[1], b[2]); /* Find intersection. */ - if (isect_line_segment_tri_v3(a[0], a[1], b[0], b[1], b[2], &tmp, NULL)) { + if (isect_line_segment_tri_v3(a[0], a[1], b[0], b[1], b[2], &tmp, nullptr)) { interp_v3_v3v3(isect_a, a[0], a[1], tmp); isect = true; } @@ -457,7 +457,7 @@ static float compute_collision_point_edge_tri(const float a1[3], /* Point projections. */ for (int i = 0; i < 2; i++) { - if (isect_ray_tri_v3(a[i], normal, b[0], b[1], b[2], &tmp, NULL)) { + if (isect_ray_tri_v3(a[i], normal, b[0], b[1], b[2], &tmp, nullptr)) { if (tmp > maxdist) { maxdist = tmp; copy_v3_v3(r_a, a[i]); @@ -592,13 +592,13 @@ static void collision_compute_barycentric(const float pv[3], return; } - w1[0] = (float)((e * c - b * f) / d); + w1[0] = float((e * c - b * f) / d); if (w1[0] < 0) { w1[0] = 0; } - w2[0] = (float)((f - b * (double)w1[0]) / c); + w2[0] = float((f - b * (double)w1[0]) / c); if (w2[0] < 0) { w2[0] = 0; @@ -630,7 +630,7 @@ DO_INLINE void collision_interpolateOnTriangle(float to[3], static void cloth_collision_impulse_vert(const float clamp_sq, const float impulse[3], - struct ClothVertex *vert) + ClothVertex *vert) { float impulse_len_sq = len_squared_v3(impulse); @@ -667,7 +667,7 @@ static int cloth_collision_response_static(ClothModifierData *clmd, const float epsilon2 = BLI_bvhtree_get_epsilon(collmd->bvhtree); const float min_distance = (clmd->coll_parms->epsilon + epsilon2) * (8.0f / 9.0f); - const bool is_hair = (clmd->hairdata != NULL); + const bool is_hair = (clmd->hairdata != nullptr); for (int i = 0; i < collision_count; i++, collpair++) { float i1[3], i2[3], i3[3]; float v1[3], v2[3], relativeVelocity[3]; @@ -952,7 +952,7 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, # pragma GCC diagnostic pop #endif -static bool cloth_bvh_collision_is_active(const ClothModifierData *UNUSED(clmd), +static bool cloth_bvh_collision_is_active(const ClothModifierData * /*clmd*/, const Cloth *cloth, const MVertTri *tri_a) { @@ -971,7 +971,7 @@ static bool cloth_bvh_collision_is_active(const ClothModifierData *UNUSED(clmd), static void cloth_collision(void *__restrict userdata, const int index, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { ColDetectData *data = (ColDetectData *)userdata; @@ -1087,7 +1087,7 @@ static bool cloth_bvh_selfcollision_is_active(const ClothModifierData *clmd, static void cloth_selfcollision(void *__restrict userdata, const int index, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { SelfColDetectData *data = (SelfColDetectData *)userdata; @@ -1168,7 +1168,7 @@ static void cloth_selfcollision(void *__restrict userdata, static void hair_collision(void *__restrict userdata, const int index, - const TaskParallelTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict /*tls*/) { ColDetectData *data = (ColDetectData *)userdata; @@ -1238,13 +1238,16 @@ static void hair_collision(void *__restrict userdata, } } -static void add_collision_object(ListBase *relations, Object *ob, int level, uint modifier_type) +static void add_collision_object(ListBase *relations, + Object *ob, + int level, + const ModifierType modifier_type) { /* only get objects with collision modifier */ ModifierData *cmd = BKE_modifiers_findby_type(ob, modifier_type); if (cmd) { - CollisionRelation *relation = MEM_callocN(sizeof(CollisionRelation), "CollisionRelation"); + CollisionRelation *relation = MEM_cnew(__func__); relation->ob = ob; BLI_addtail(relations, relation); } @@ -1273,11 +1276,11 @@ ListBase *BKE_collision_relations_create(Depsgraph *depsgraph, const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); const int base_flag = (for_render) ? BASE_ENABLED_RENDER : BASE_ENABLED_VIEWPORT; - ListBase *relations = MEM_callocN(sizeof(ListBase), "CollisionRelation list"); + ListBase *relations = MEM_cnew(__func__); for (; base; base = base->next) { if (base->flag & base_flag) { - add_collision_object(relations, base->object, 0, modifier_type); + add_collision_object(relations, base->object, 0, ModifierType(modifier_type)); } } @@ -1302,12 +1305,12 @@ Object **BKE_collision_objects_create(Depsgraph *depsgraph, if (!relations) { *numcollobj = 0; - return NULL; + return nullptr; } int maxnum = BLI_listbase_count(relations); int num = 0; - Object **objects = MEM_callocN(sizeof(Object *) * maxnum, __func__); + Object **objects = MEM_cnew_array(maxnum, __func__); LISTBASE_FOREACH (CollisionRelation *, relation, relations) { /* Get evaluated object. */ @@ -1325,7 +1328,7 @@ Object **BKE_collision_objects_create(Depsgraph *depsgraph, if (num == 0) { MEM_freeN(objects); - objects = NULL; + objects = nullptr; } *numcollobj = num; @@ -1343,10 +1346,10 @@ ListBase *BKE_collider_cache_create(Depsgraph *depsgraph, Object *self, Collecti { ListBase *relations = DEG_get_collision_relations( depsgraph, collection, eModifierType_Collision); - ListBase *cache = NULL; + ListBase *cache = nullptr; if (!relations) { - return NULL; + return nullptr; } LISTBASE_FOREACH (CollisionRelation *, relation, relations) { @@ -1360,11 +1363,11 @@ ListBase *BKE_collider_cache_create(Depsgraph *depsgraph, Object *self, Collecti CollisionModifierData *cmd = (CollisionModifierData *)BKE_modifiers_findby_type( ob, eModifierType_Collision); if (cmd && cmd->bvhtree) { - if (cache == NULL) { - cache = MEM_callocN(sizeof(ListBase), "ColliderCache array"); + if (cache == nullptr) { + cache = MEM_cnew(__func__); } - ColliderCache *col = MEM_callocN(sizeof(ColliderCache), "ColliderCache"); + ColliderCache *col = MEM_cnew(__func__); col->ob = ob; col->collmd = cmd; /* make sure collider is properly set up */ @@ -1381,7 +1384,7 @@ void BKE_collider_cache_free(ListBase **colliders) if (*colliders) { BLI_freelistN(*colliders); MEM_freeN(*colliders); - *colliders = NULL; + *colliders = nullptr; } } @@ -1393,18 +1396,17 @@ static bool cloth_bvh_objcollisions_nearcheck(ClothModifierData *clmd, bool culling, bool use_normal) { - const bool is_hair = (clmd->hairdata != NULL); + const bool is_hair = (clmd->hairdata != nullptr); *collisions = (CollPair *)MEM_mallocN(sizeof(CollPair) * numresult, "collision array"); - ColDetectData data = { - .clmd = clmd, - .collmd = collmd, - .overlap = overlap, - .collisions = *collisions, - .culling = culling, - .use_normal = use_normal, - .collided = false, - }; + ColDetectData data{}; + data.clmd = clmd; + data.collmd = collmd; + data.overlap = overlap; + data.collisions = *collisions; + data.culling = culling; + data.use_normal = use_normal; + data.collided = false; TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -1420,12 +1422,11 @@ static bool cloth_bvh_selfcollisions_nearcheck(ClothModifierData *clmd, int numresult, BVHTreeOverlap *overlap) { - SelfColDetectData data = { - .clmd = clmd, - .overlap = overlap, - .collisions = collisions, - .collided = false, - }; + SelfColDetectData data{}; + data.clmd = clmd; + data.overlap = overlap; + data.collisions = collisions; + data.collided = false; TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); @@ -1444,7 +1445,7 @@ static int cloth_bvh_objcollisions_resolve(ClothModifierData *clmd, { Cloth *cloth = clmd->clothObject; int i = 0, j = 0, mvert_num = 0; - ClothVertex *verts = NULL; + ClothVertex *verts = nullptr; int ret = 0; int result = 0; @@ -1495,7 +1496,7 @@ static int cloth_bvh_selfcollisions_resolve(ClothModifierData *clmd, { Cloth *cloth = clmd->clothObject; int i = 0, j = 0, mvert_num = 0; - ClothVertex *verts = NULL; + ClothVertex *verts = nullptr; int ret = 0; int result = 0; @@ -1529,25 +1530,22 @@ static int cloth_bvh_selfcollisions_resolve(ClothModifierData *clmd, return ret; } -static bool cloth_bvh_obj_overlap_cb(void *userdata, - int index_a, - int UNUSED(index_b), - int UNUSED(thread)) +static bool cloth_bvh_obj_overlap_cb(void *userdata, int index_a, int /*index_b*/, int /*thread*/) { ClothModifierData *clmd = (ClothModifierData *)userdata; - struct Cloth *clothObject = clmd->clothObject; + Cloth *clothObject = clmd->clothObject; const MVertTri *tri_a = &clothObject->tri[index_a]; return cloth_bvh_collision_is_active(clmd, clothObject, tri_a); } -static bool cloth_bvh_self_overlap_cb(void *userdata, int index_a, int index_b, int UNUSED(thread)) +static bool cloth_bvh_self_overlap_cb(void *userdata, int index_a, int index_b, int /*thread*/) { /* This shouldn't happen, but just in case. Note that equal combinations * (eg. (0,1) & (1,0)) would be filtered out by BLI_bvhtree_overlap_self. */ if (index_a != index_b) { ClothModifierData *clmd = (ClothModifierData *)userdata; - struct Cloth *clothObject = clmd->clothObject; + Cloth *clothObject = clmd->clothObject; const MVertTri *tri_a, *tri_b; tri_a = &clothObject->tri[index_a]; tri_b = &clothObject->tri[index_b]; @@ -1566,17 +1564,17 @@ int cloth_bvh_collision( BVHTree *cloth_bvh = cloth->bvhtree; uint i = 0, mvert_num = 0; int rounds = 0; - ClothVertex *verts = NULL; + ClothVertex *verts = nullptr; int ret = 0, ret2 = 0; - Object **collobjs = NULL; + Object **collobjs = nullptr; uint numcollobj = 0; - uint *coll_counts_obj = NULL; - BVHTreeOverlap **overlap_obj = NULL; + uint *coll_counts_obj = nullptr; + BVHTreeOverlap **overlap_obj = nullptr; uint coll_count_self = 0; - BVHTreeOverlap *overlap_self = NULL; + BVHTreeOverlap *overlap_self = nullptr; bool bvh_updated = false; - if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ) || cloth_bvh == NULL) { + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ) || cloth_bvh == nullptr) { return 0; } @@ -1588,17 +1586,17 @@ int cloth_bvh_collision( bvh_updated = true; /* Enable self collision if this is a hair sim */ - const bool is_hair = (clmd->hairdata != NULL); + const bool is_hair = (clmd->hairdata != nullptr); collobjs = BKE_collision_objects_create(depsgraph, - is_hair ? NULL : ob, + is_hair ? nullptr : ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision); if (collobjs) { - coll_counts_obj = MEM_callocN(sizeof(uint) * numcollobj, "CollCounts"); - overlap_obj = MEM_callocN(sizeof(*overlap_obj) * numcollobj, "BVHOverlap"); + coll_counts_obj = MEM_cnew_array(numcollobj, "CollCounts"); + overlap_obj = MEM_cnew_array(numcollobj, "BVHOverlap"); for (i = 0; i < numcollobj; i++) { Object *collob = collobjs[i]; @@ -1615,7 +1613,7 @@ int cloth_bvh_collision( overlap_obj[i] = BLI_bvhtree_overlap(cloth_bvh, collmd->bvhtree, &coll_counts_obj[i], - is_hair ? NULL : cloth_bvh_obj_overlap_cb, + is_hair ? nullptr : cloth_bvh_obj_overlap_cb, clmd); } } @@ -1638,7 +1636,7 @@ int cloth_bvh_collision( CollPair **collisions; bool collided = false; - collisions = MEM_callocN(sizeof(CollPair *) * numcollobj, "CollPair"); + collisions = MEM_cnew_array(numcollobj, "CollPair"); for (i = 0; i < numcollobj; i++) { Object *collob = collobjs[i]; @@ -1677,7 +1675,7 @@ int cloth_bvh_collision( /* Self collisions. */ if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF) { - CollPair *collisions = NULL; + CollPair *collisions = nullptr; verts = cloth->verts; mvert_num = cloth->mvert_num; diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 545a080d7be..b14a969a712 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -54,7 +54,7 @@ set(SRC editmesh_undo.cc editmesh_utils.c mesh_data.cc - mesh_mirror.c + mesh_mirror.cc mesh_ops.c meshtools.cc diff --git a/source/blender/editors/mesh/mesh_mirror.c b/source/blender/editors/mesh/mesh_mirror.cc similarity index 90% rename from source/blender/editors/mesh/mesh_mirror.c rename to source/blender/editors/mesh/mesh_mirror.cc index 4ef2dae4389..1804ef82077 100644 --- a/source/blender/editors/mesh/mesh_mirror.c +++ b/source/blender/editors/mesh/mesh_mirror.cc @@ -27,12 +27,12 @@ #define KD_THRESH 0.00002f static struct { - void *tree; -} MirrKdStore = {NULL}; + KDTree_3d *tree; +} MirrKdStore = {nullptr}; void ED_mesh_mirror_spatial_table_begin(Object *ob, BMEditMesh *em, Mesh *me_eval) { - Mesh *me = ob->data; + Mesh *me = static_cast(ob->data); const bool use_em = (!me_eval && em && me->edit_mesh == em); const int totvert = use_em ? em->bm->totvert : me_eval ? me_eval->totvert : me->totvert; @@ -69,7 +69,7 @@ int ED_mesh_mirror_spatial_table_lookup(Object *ob, Mesh *me_eval, const float co[3]) { - if (MirrKdStore.tree == NULL) { + if (MirrKdStore.tree == nullptr) { ED_mesh_mirror_spatial_table_begin(ob, em, me_eval); } @@ -86,12 +86,12 @@ int ED_mesh_mirror_spatial_table_lookup(Object *ob, return -1; } -void ED_mesh_mirror_spatial_table_end(Object *UNUSED(ob)) +void ED_mesh_mirror_spatial_table_end(Object * /*ob*/) { /* TODO: store this in object/object-data (keep unused argument for now). */ if (MirrKdStore.tree) { BLI_kdtree_3d_free(MirrKdStore.tree); - MirrKdStore.tree = NULL; + MirrKdStore.tree = nullptr; } } @@ -101,12 +101,12 @@ void ED_mesh_mirror_spatial_table_end(Object *UNUSED(ob)) /** \name Mesh Topology Mirror API * \{ */ -typedef uint MirrTopoHash_t; +using MirrTopoHash_t = uint; -typedef struct MirrTopoVert_t { +struct MirrTopoVert_t { MirrTopoHash_t hash; int v_index; -} MirrTopoVert_t; +}; static int mirrtopo_hash_sort(const void *l1, const void *l2) { @@ -132,7 +132,7 @@ static int mirrtopo_vert_sort(const void *v1, const void *v2) bool ED_mesh_mirrtopo_recalc_check(BMEditMesh *em, Mesh *me, MirrTopoStore_t *mesh_topo_store) { - const bool is_editmode = em != NULL; + const bool is_editmode = em != nullptr; int totvert; int totedge; @@ -145,7 +145,7 @@ bool ED_mesh_mirrtopo_recalc_check(BMEditMesh *em, Mesh *me, MirrTopoStore_t *me totedge = me->totedge; } - if ((mesh_topo_store->index_lookup == NULL) || + if ((mesh_topo_store->index_lookup == nullptr) || (mesh_topo_store->prev_is_editmode != is_editmode) || (totvert != mesh_topo_store->prev_vert_tot) || (totedge != mesh_topo_store->prev_edge_tot)) { return true; @@ -159,10 +159,10 @@ void ED_mesh_mirrtopo_init(BMEditMesh *em, const bool skip_em_vert_array_init) { if (em) { - BLI_assert(me == NULL); + BLI_assert(me == nullptr); } - const bool is_editmode = (em != NULL); - const MEdge *medge = NULL, *med; + const bool is_editmode = (em != nullptr); + const MEdge *medge = nullptr, *med; /* Edit-mode variables. */ BMEdge *eed; @@ -173,13 +173,8 @@ void ED_mesh_mirrtopo_init(BMEditMesh *em, int tot_unique = -1, tot_unique_prev = -1; int tot_unique_edges = 0, tot_unique_edges_prev; - MirrTopoHash_t *topo_hash = NULL; - MirrTopoHash_t *topo_hash_prev = NULL; - MirrTopoVert_t *topo_pairs; MirrTopoHash_t topo_pass = 1; - intptr_t *index_lookup; /* direct access to mesh_topo_store->index_lookup */ - /* reallocate if needed */ ED_mesh_mirrtopo_free(mesh_topo_store); @@ -194,7 +189,8 @@ void ED_mesh_mirrtopo_init(BMEditMesh *em, totvert = me->totvert; } - topo_hash = MEM_callocN(totvert * sizeof(MirrTopoHash_t), "TopoMirr"); + MirrTopoHash_t *topo_hash = static_cast( + MEM_callocN(totvert * sizeof(MirrTopoHash_t), __func__)); /* Initialize the vert-edge-user counts used to detect unique topology */ if (em) { @@ -216,7 +212,7 @@ void ED_mesh_mirrtopo_init(BMEditMesh *em, } } - topo_hash_prev = MEM_dupallocN(topo_hash); + MirrTopoHash_t *topo_hash_prev = static_cast(MEM_dupallocN(topo_hash)); tot_unique_prev = -1; tot_unique_edges_prev = -1; @@ -268,10 +264,12 @@ void ED_mesh_mirrtopo_init(BMEditMesh *em, } /* Hash/Index pairs are needed for sorting to find index pairs */ - topo_pairs = MEM_callocN(sizeof(MirrTopoVert_t) * totvert, "MirrTopoPairs"); + MirrTopoVert_t *topo_pairs = static_cast( + MEM_callocN(sizeof(MirrTopoVert_t) * totvert, "MirrTopoPairs")); /* since we are looping through verts, initialize these values here too */ - index_lookup = MEM_mallocN(totvert * sizeof(*index_lookup), "mesh_topo_lookup"); + intptr_t *index_lookup = static_cast( + MEM_mallocN(totvert * sizeof(*index_lookup), "mesh_topo_lookup")); if (em) { if (skip_em_vert_array_init == false) { @@ -336,7 +334,7 @@ void ED_mesh_mirrtopo_init(BMEditMesh *em, } MEM_freeN(topo_pairs); - topo_pairs = NULL; + topo_pairs = nullptr; MEM_freeN(topo_hash); MEM_freeN(topo_hash_prev); diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index a0cf583153b..2130a6128ae 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -51,7 +51,7 @@ set(SRC intern/MOD_explode.cc intern/MOD_fluid.c intern/MOD_hook.c - intern/MOD_laplaciandeform.c + intern/MOD_laplaciandeform.cc intern/MOD_laplaciansmooth.cc intern/MOD_lattice.c intern/MOD_mask.cc @@ -75,8 +75,8 @@ set(SRC intern/MOD_shapekey.c intern/MOD_shrinkwrap.c intern/MOD_simpledeform.c - intern/MOD_skin.c - intern/MOD_smooth.c + intern/MOD_skin.cc + intern/MOD_smooth.cc intern/MOD_softbody.c intern/MOD_solidify.cc intern/MOD_solidify_extrude.cc diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.cc similarity index 89% rename from source/blender/modifiers/intern/MOD_laplaciandeform.c rename to source/blender/modifiers/intern/MOD_laplaciandeform.cc index c01ffd2e4fe..6e17049bb29 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.cc @@ -55,7 +55,7 @@ enum { LAPDEFORM_SYSTEM_CHANGE_NOT_VALID_GROUP, }; -typedef struct LaplacianSystem { +struct LaplacianSystem { bool is_matrix_computed; bool has_solution; int verts_num; @@ -75,12 +75,11 @@ typedef struct LaplacianSystem { LinearSolver *context; /* System for solve general implicit rotations */ MeshElemMap *ringf_map; /* Map of faces per vertex */ MeshElemMap *ringv_map; /* Map of vertex per vertex */ -} LaplacianSystem; +}; static LaplacianSystem *newLaplacianSystem(void) { - LaplacianSystem *sys; - sys = MEM_callocN(sizeof(LaplacianSystem), "DeformCache"); + LaplacianSystem *sys = MEM_cnew(__func__); sys->is_matrix_computed = false; sys->has_solution = false; @@ -111,12 +110,12 @@ static LaplacianSystem *initLaplacianSystem(int verts_num, sys->anchors_num = anchors_num; sys->repeat = iterations; BLI_strncpy(sys->anchor_grp_name, defgrpName, sizeof(sys->anchor_grp_name)); - sys->co = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "DeformCoordinates"); - sys->no = MEM_calloc_arrayN(verts_num, sizeof(float[3]), "DeformNormals"); - sys->delta = MEM_calloc_arrayN(verts_num, sizeof(float[3]), "DeformDeltas"); - sys->tris = MEM_malloc_arrayN(tris_num, sizeof(int[3]), "DeformFaces"); - sys->index_anchors = MEM_malloc_arrayN((anchors_num), sizeof(int), "DeformAnchors"); - sys->unit_verts = MEM_calloc_arrayN(verts_num, sizeof(int), "DeformUnitVerts"); + sys->co = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__)); + sys->no = static_cast(MEM_calloc_arrayN(verts_num, sizeof(float[3]), __func__)); + sys->delta = static_cast(MEM_calloc_arrayN(verts_num, sizeof(float[3]), __func__)); + sys->tris = static_cast(MEM_malloc_arrayN(tris_num, sizeof(int[3]), __func__)); + sys->index_anchors = static_cast(MEM_malloc_arrayN((anchors_num), sizeof(int), __func__)); + sys->unit_verts = static_cast(MEM_calloc_arrayN(verts_num, sizeof(int), __func__)); return sys; } @@ -148,7 +147,7 @@ static void createFaceRingMap(const int mvert_tot, { int i, j, indices_num = 0; int *indices, *index_iter; - MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformRingMap"); + MeshElemMap *map = MEM_cnew_array(mvert_tot, __func__); const MLoopTri *mlt; for (i = 0, mlt = mlooptri; i < mtri_tot; i++, mlt++) { @@ -159,7 +158,7 @@ static void createFaceRingMap(const int mvert_tot, indices_num++; } } - indices = MEM_calloc_arrayN(indices_num, sizeof(int), "DeformRingIndex"); + indices = MEM_cnew_array(indices_num, __func__); index_iter = indices; for (i = 0; i < mvert_tot; i++) { map[i].indices = index_iter; @@ -183,7 +182,7 @@ static void createVertRingMap(const int mvert_tot, MeshElemMap **r_map, int **r_indices) { - MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformNeighborsMap"); + MeshElemMap *map = MEM_cnew_array(mvert_tot, __func__); int i, vid[2], indices_num = 0; int *indices, *index_iter; const MEdge *me; @@ -195,7 +194,7 @@ static void createVertRingMap(const int mvert_tot, map[vid[1]].count++; indices_num += 2; } - indices = MEM_calloc_arrayN(indices_num, sizeof(int), "DeformNeighborsIndex"); + indices = MEM_cnew_array(indices_num, __func__); index_iter = indices; for (i = 0; i < mvert_tot; i++) { map[i].indices = index_iter; @@ -301,7 +300,7 @@ static void initLaplacianMatrix(LaplacianSystem *sys) static void computeImplictRotations(LaplacianSystem *sys) { - int vid, *vidn = NULL; + int vid, *vidn = nullptr; float minj, mjt, qj[3], vj[3]; int i, j, ln; @@ -512,11 +511,11 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3]) static bool isValidVertexGroup(LaplacianDeformModifierData *lmd, Object *ob, Mesh *mesh) { int defgrp_index; - const MDeformVert *dvert = NULL; + const MDeformVert *dvert = nullptr; MOD_get_vgroup(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index); - return (dvert != NULL); + return (dvert != nullptr); } static void initSystem( @@ -526,13 +525,14 @@ static void initSystem( int defgrp_index; int anchors_num; float wpaint; - const MDeformVert *dvert = NULL; - const MDeformVert *dv = NULL; + const MDeformVert *dvert = nullptr; + const MDeformVert *dv = nullptr; LaplacianSystem *sys; const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0; if (isValidVertexGroup(lmd, ob, mesh)) { - int *index_anchors = MEM_malloc_arrayN(verts_num, sizeof(int), __func__); /* over-alloc */ + int *index_anchors = static_cast( + MEM_malloc_arrayN(verts_num, sizeof(int), __func__)); /* over-alloc */ const MLoopTri *mlooptri; const MLoop *mloop; @@ -541,7 +541,7 @@ static void initSystem( STACK_INIT(index_anchors, verts_num); MOD_get_vgroup(ob, mesh, lmd->anchor_grp_name, &dvert, &defgrp_index); - BLI_assert(dvert != NULL); + BLI_assert(dvert != nullptr); dv = dvert; for (i = 0; i < verts_num; i++) { wpaint = invert_vgroup ? 1.0f - BKE_defvert_find_weight(dv, defgrp_index) : @@ -563,7 +563,7 @@ static void initSystem( memcpy(sys->index_anchors, index_anchors, sizeof(int) * anchors_num); memcpy(sys->co, vertexCos, sizeof(float[3]) * verts_num); MEM_freeN(index_anchors); - lmd->vertexco = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "ModDeformCoordinates"); + lmd->vertexco = static_cast(MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__)); memcpy(lmd->vertexco, vertexCos, sizeof(float[3]) * verts_num); lmd->verts_num = verts_num; @@ -596,8 +596,8 @@ static int isSystemDifferent(LaplacianDeformModifierData *lmd, int defgrp_index; int anchors_num = 0; float wpaint; - const MDeformVert *dvert = NULL; - const MDeformVert *dv = NULL; + const MDeformVert *dvert = nullptr; + const MDeformVert *dv = nullptr; LaplacianSystem *sys = (LaplacianSystem *)lmd->cache_system; const bool invert_vgroup = (lmd->flag & MOD_LAPLACIANDEFORM_INVERT_VGROUP) != 0; @@ -635,13 +635,13 @@ static void LaplacianDeformModifier_do( { float(*filevertexCos)[3]; int sysdif; - LaplacianSystem *sys = NULL; - filevertexCos = NULL; + LaplacianSystem *sys = nullptr; + filevertexCos = nullptr; if (!(lmd->flag & MOD_LAPLACIANDEFORM_BIND)) { if (lmd->cache_system) { - sys = lmd->cache_system; + sys = static_cast(lmd->cache_system); deleteLaplacianSystem(sys); - lmd->cache_system = NULL; + lmd->cache_system = nullptr; } lmd->verts_num = 0; MEM_SAFE_FREE(lmd->vertexco); @@ -649,17 +649,18 @@ static void LaplacianDeformModifier_do( } if (lmd->cache_system) { sysdif = isSystemDifferent(lmd, ob, mesh, verts_num); - sys = lmd->cache_system; + sys = static_cast(lmd->cache_system); if (sysdif) { if (ELEM(sysdif, LAPDEFORM_SYSTEM_ONLY_CHANGE_ANCHORS, LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP)) { - filevertexCos = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "TempModDeformCoordinates"); + filevertexCos = static_cast( + MEM_malloc_arrayN(verts_num, sizeof(float[3]), __func__)); memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * verts_num); MEM_SAFE_FREE(lmd->vertexco); lmd->verts_num = 0; deleteLaplacianSystem(sys); - lmd->cache_system = NULL; + lmd->cache_system = nullptr; initSystem(lmd, ob, mesh, filevertexCos, verts_num); - sys = lmd->cache_system; /* may have been reallocated */ + sys = static_cast(lmd->cache_system); /* may have been reallocated */ MEM_SAFE_FREE(filevertexCos); if (sys) { laplacianDeformPreview(sys, vertexCos); @@ -696,18 +697,19 @@ static void LaplacianDeformModifier_do( lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND; } else if (lmd->verts_num > 0 && lmd->verts_num == verts_num) { - filevertexCos = MEM_malloc_arrayN(verts_num, sizeof(float[3]), "TempDeformCoordinates"); + filevertexCos = static_cast( + MEM_malloc_arrayN(verts_num, sizeof(float[3]), "TempDeformCoordinates")); memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * verts_num); MEM_SAFE_FREE(lmd->vertexco); lmd->verts_num = 0; initSystem(lmd, ob, mesh, filevertexCos, verts_num); - sys = lmd->cache_system; + sys = static_cast(lmd->cache_system); MEM_SAFE_FREE(filevertexCos); laplacianDeformPreview(sys, vertexCos); } else { initSystem(lmd, ob, mesh, vertexCos, verts_num); - sys = lmd->cache_system; + sys = static_cast(lmd->cache_system); laplacianDeformPreview(sys, vertexCos); } } @@ -732,13 +734,11 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla BKE_modifier_copydata_generic(md, target, flag); - tlmd->vertexco = MEM_dupallocN(lmd->vertexco); - tlmd->cache_system = NULL; + tlmd->vertexco = static_cast(MEM_dupallocN(lmd->vertexco)); + tlmd->cache_system = nullptr; } -static bool isDisabled(const struct Scene *UNUSED(scene), - ModifierData *md, - bool UNUSED(useRenderParams)) +static bool isDisabled(const Scene * /*scene*/, ModifierData *md, bool /*useRenderParams*/) { LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; if (lmd->anchor_grp_name[0]) { @@ -762,35 +762,36 @@ static void deformVerts(ModifierData *md, float (*vertexCos)[3], int verts_num) { - Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false); + Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, nullptr, mesh, nullptr, verts_num, false); LaplacianDeformModifier_do( (LaplacianDeformModifierData *)md, ctx->object, mesh_src, vertexCos, verts_num); - if (!ELEM(mesh_src, NULL, mesh)) { - BKE_id_free(NULL, mesh_src); + if (!ELEM(mesh_src, nullptr, mesh)) { + BKE_id_free(nullptr, mesh_src); } } static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, - struct BMEditMesh *editData, + BMEditMesh *editData, Mesh *mesh, float (*vertexCos)[3], int verts_num) { - Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, verts_num, false); + Mesh *mesh_src = MOD_deform_mesh_eval_get( + ctx->object, editData, mesh, nullptr, verts_num, false); /* TODO(@ideasman42): use edit-mode data only (remove this line). */ - if (mesh_src != NULL) { + if (mesh_src != nullptr) { BKE_mesh_wrapper_ensure_mdata(mesh_src); } LaplacianDeformModifier_do( (LaplacianDeformModifierData *)md, ctx->object, mesh_src, vertexCos, verts_num); - if (!ELEM(mesh_src, NULL, mesh)) { - BKE_id_free(NULL, mesh_src); + if (!ELEM(mesh_src, nullptr, mesh)) { + BKE_id_free(nullptr, mesh_src); } } @@ -805,7 +806,7 @@ static void freeData(ModifierData *md) lmd->verts_num = 0; } -static void panel_draw(const bContext *UNUSED(C), Panel *panel) +static void panel_draw(const bContext * /*C*/, Panel *panel) { uiLayout *row; uiLayout *layout = panel->layout; @@ -818,9 +819,9 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel) uiLayoutSetPropSep(layout, true); - uiItemR(layout, ptr, "iterations", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "iterations", 0, nullptr, ICON_NONE); - modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", NULL); + modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr); uiItemS(layout); @@ -851,13 +852,13 @@ static void blendWrite(BlendWriter *writer, const ID *id_owner, const ModifierDa /* Modifier coming from linked data cannot be bound from an override, so we can remove all * binding data, can save a significant amount of memory. */ lmd.verts_num = 0; - lmd.vertexco = NULL; + lmd.vertexco = nullptr; } } BLO_write_struct_at_address(writer, LaplacianDeformModifierData, md, &lmd); - if (lmd.vertexco != NULL) { + if (lmd.vertexco != nullptr) { BLO_write_float3_array(writer, lmd.verts_num, lmd.vertexco); } } @@ -867,7 +868,7 @@ static void blendRead(BlendDataReader *reader, ModifierData *md) LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; BLO_read_float3_array(reader, lmd->verts_num, &lmd->vertexco); - lmd->cache_system = NULL; + lmd->cache_system = nullptr; } ModifierTypeInfo modifierType_LaplacianDeform = { @@ -881,22 +882,22 @@ ModifierTypeInfo modifierType_LaplacianDeform = { /*copyData*/ copyData, /*deformVerts*/ deformVerts, - /*deformMatrices*/ NULL, + /*deformMatrices*/ nullptr, /*deformVertsEM*/ deformVertsEM, - /*deformMatricesEM*/ NULL, - /*modifyMesh*/ NULL, - /*modifyGeometrySet*/ NULL, + /*deformMatricesEM*/ nullptr, + /*modifyMesh*/ nullptr, + /*modifyGeometrySet*/ nullptr, /*initData*/ initData, /*requiredDataMask*/ requiredDataMask, /*freeData*/ freeData, /*isDisabled*/ isDisabled, - /*updateDepsgraph*/ NULL, - /*dependsOnTime*/ NULL, - /*dependsOnNormals*/ NULL, - /*foreachIDLink*/ NULL, - /*foreachTexLink*/ NULL, - /*freeRuntimeData*/ NULL, + /*updateDepsgraph*/ nullptr, + /*dependsOnTime*/ nullptr, + /*dependsOnNormals*/ nullptr, + /*foreachIDLink*/ nullptr, + /*foreachTexLink*/ nullptr, + /*freeRuntimeData*/ nullptr, /*panelRegister*/ panelRegister, /*blendWrite*/ blendWrite, /*blendRead*/ blendRead, diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.cc similarity index 92% rename from source/blender/modifiers/intern/MOD_skin.c rename to source/blender/modifiers/intern/MOD_skin.cc index 32c3c4a27af..3e953f6e996 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.cc @@ -40,12 +40,12 @@ #include "BLI_utildefines.h" -#include "BLI_array.h" #include "BLI_bitmap.h" #include "BLI_heap_simple.h" #include "BLI_math.h" #include "BLI_math_geom.h" #include "BLI_stack.h" +#include "BLI_vector.hh" #include "BLT_translation.h" @@ -117,21 +117,22 @@ static void vert_array_face_normal_update(BMVert **verts, int verts_len) /** \} */ -typedef struct { +struct EMat { float mat[3][3]; /* Vert that edge is pointing away from, no relation to * MEdge.v1 */ int origin; -} EMat; +}; -typedef enum { +enum SkinNodeFlag { CAP_START = 1, CAP_END = 2, SEAM_FRAME = 4, FLIP_NORMAL = 8, -} SkinNodeFlag; +}; +ENUM_OPERATORS(SkinNodeFlag, FLIP_NORMAL); -typedef struct Frame { +struct Frame { /* Index in the vertex array */ BMVert *verts[4]; /* Location of each corner */ @@ -140,7 +141,7 @@ typedef struct Frame { * frame's corner (so they share a vertex index) */ struct { /* Merge to target frame/corner (no merge if frame is null) */ - struct Frame *frame; + Frame *frame; int corner; /* checked to avoid chaining. * (merging when we're already been referenced), see #39775 */ @@ -151,10 +152,10 @@ typedef struct Frame { bool inside_hull[4]; /* Whether any part of the frame (corner or edge) is detached */ bool detached; -} Frame; +}; #define MAX_SKIN_NODE_FRAMES 2 -typedef struct { +struct SkinNode { Frame frames[MAX_SKIN_NODE_FRAMES]; int totframe; @@ -162,13 +163,13 @@ typedef struct { /* Used for hulling a loop seam */ int seam_edges[2]; -} SkinNode; +}; -typedef struct { +struct SkinOutput { BMesh *bm; SkinModifierData *smd; int mat_nr; -} SkinOutput; +}; static void add_poly(SkinOutput *so, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4); @@ -453,8 +454,7 @@ static Frame **collect_hull_frames( int hull_frames_num, i; (*tothullframe) = emap[v].count; - hull_frames = MEM_calloc_arrayN( - (*tothullframe), sizeof(Frame *), "hull_from_frames.hull_frames"); + hull_frames = MEM_cnew_array(*tothullframe, __func__); hull_frames_num = 0; for (i = 0; i < emap[v].count; i++) { const MEdge *e = &medge[emap[v].indices[i]]; @@ -480,7 +480,7 @@ static void node_frames_init(SkinNode *nf, int totframe) nf->totframe = totframe; memset(nf->frames, 0, sizeof(nf->frames)); - nf->flag = 0; + nf->flag = SkinNodeFlag(0); for (i = 0; i < 2; i++) { nf->seam_edges[i] = -1; } @@ -654,10 +654,9 @@ static SkinNode *build_frames(const float (*vert_positions)[3], const MeshElemMap *emap, EMat *emat) { - SkinNode *skin_nodes; int v; - skin_nodes = MEM_calloc_arrayN(verts_num, sizeof(SkinNode), "build_frames.skin_nodes"); + SkinNode *skin_nodes = MEM_cnew_array(verts_num, __func__); for (v = 0; v < verts_num; v++) { if (emap[v].count <= 1) { @@ -705,11 +704,11 @@ static void calc_edge_mat(float mat[3][3], const float a[3], const float b[3]) } } -typedef struct { +struct EdgeStackElem { float mat[3][3]; int parent_v; int e; -} EdgeStackElem; +}; static void build_emats_stack(BLI_Stack *stack, BLI_bitmap *visited_e, @@ -784,7 +783,7 @@ static EMat *build_edge_mats(const MVertSkin *vs, stack = BLI_stack_new(sizeof(stack_elem), "build_edge_mats.stack"); visited_e = BLI_BITMAP_NEW(edges_num, "build_edge_mats.visited_e"); - emat = MEM_calloc_arrayN(edges_num, sizeof(EMat), "build_edge_mats.emat"); + emat = MEM_cnew_array(edges_num, __func__); /* Edge matrices are built from the root nodes, add all roots with * children to the stack */ @@ -862,7 +861,7 @@ static int calc_edge_subdivisions(const float (*vert_positions)[3], const float edge_len = len_v3v3(vert_positions[e->v1], vert_positions[e->v2]); subdivisions_num_fl = (edge_len / avg_radius); if (subdivisions_num_fl < NUM_SUBDIVISIONS_MAX) { - subdivisions_num = (int)subdivisions_num_fl; + subdivisions_num = int(subdivisions_num_fl); } else { subdivisions_num = NUM_SUBDIVISIONS_MAX; @@ -892,7 +891,8 @@ static Mesh *subdivide_base(const Mesh *orig) int i, j, k, u, v; float radrat; - const MVertSkin *orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN); + const MVertSkin *orignode = static_cast( + CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN)); const float(*orig_vert_positions)[3] = BKE_mesh_vert_positions(orig); const MEdge *origedge = BKE_mesh_edges(orig); const MDeformVert *origdvert = BKE_mesh_deform_verts(orig); @@ -900,14 +900,14 @@ static Mesh *subdivide_base(const Mesh *orig) int orig_edge_num = orig->totedge; /* Get degree of all vertices */ - int *degree = MEM_calloc_arrayN(orig_vert_num, sizeof(int), "degree"); + int *degree = MEM_cnew_array(orig_vert_num, __func__); for (i = 0; i < orig_edge_num; i++) { degree[origedge[i].v1]++; degree[origedge[i].v2]++; } /* Per edge, store how many subdivisions are needed */ - int *edge_subd = MEM_calloc_arrayN((uint)orig_edge_num, sizeof(int), "edge_subd"); + int *edge_subd = MEM_cnew_array(orig_edge_num, __func__); for (i = 0, subd_num = 0; i < orig_edge_num; i++) { edge_subd[i] += calc_edge_subdivisions(orig_vert_positions, orignode, &origedge[i], degree); BLI_assert(edge_subd[i] >= 0); @@ -922,9 +922,9 @@ static Mesh *subdivide_base(const Mesh *orig) float(*out_vert_positions)[3] = BKE_mesh_vert_positions_for_write(result); MEdge *outedge = BKE_mesh_edges_for_write(result); - MVertSkin *outnode = CustomData_get_layer_for_write( - &result->vdata, CD_MVERT_SKIN, result->totvert); - MDeformVert *outdvert = NULL; + MVertSkin *outnode = static_cast( + CustomData_get_layer_for_write(&result->vdata, CD_MVERT_SKIN, result->totvert)); + MDeformVert *outdvert = nullptr; if (origdvert) { outdvert = BKE_mesh_deform_verts_for_write(result); } @@ -934,11 +934,12 @@ static Mesh *subdivide_base(const Mesh *orig) /* Subdivide edges */ for (i = 0, v = orig_vert_num; i < orig_edge_num; i++) { - struct { + struct VGroupData { /* Vertex group number */ int def_nr; float w1, w2; - } *vgroups = NULL, *vg; + }; + VGroupData *vgroups = nullptr, *vg; int vgroups_num = 0; e = &origedge[i]; @@ -946,11 +947,11 @@ static Mesh *subdivide_base(const Mesh *orig) if (origdvert) { const MDeformVert *dv1 = &origdvert[e->v1]; const MDeformVert *dv2 = &origdvert[e->v2]; - vgroups = MEM_calloc_arrayN(dv1->totweight, sizeof(*vgroups), "vgroup"); + vgroups = MEM_cnew_array(dv1->totweight, __func__); /* Only want vertex groups used by both vertices */ for (j = 0; j < dv1->totweight; j++) { - vg = NULL; + vg = nullptr; for (k = 0; k < dv2->totweight; k++) { if (dv1->dw[j].def_nr == dv2->dw[k].def_nr) { vg = &vgroups[vgroups_num]; @@ -979,7 +980,7 @@ static Mesh *subdivide_base(const Mesh *orig) /* Add vertices and edge segments */ for (j = 0; j < edge_subd[i]; j++, v++, outedge++) { - float r = (j + 1) / (float)(edge_subd[i] + 1); + float r = (j + 1) / float(edge_subd[i] + 1); float t = powf(r, radrat); /* Interpolate vertex coord */ @@ -1034,7 +1035,7 @@ static void add_poly(SkinOutput *so, BMVert *v1, BMVert *v2, BMVert *v3, BMVert BLI_assert(v3 != v4); BLI_assert(v1 && v2 && v3); - f = BM_face_create_verts(so->bm, verts, v4 ? 4 : 3, NULL, BM_CREATE_NO_DOUBLE, true); + f = BM_face_create_verts(so->bm, verts, v4 ? 4 : 3, nullptr, BM_CREATE_NO_DOUBLE, true); BM_face_normal_update(f); if (so->smd->flag & MOD_SKIN_SMOOTH_SHADING) { BM_elem_flag_enable(f, BM_ELEM_SMOOTH); @@ -1105,11 +1106,11 @@ static void output_frames(BMesh *bm, SkinNode *sn, const MDeformVert *input_dver f = &sn->frames[i]; for (j = 0; j < 4; j++) { if (!f->merge[j].frame) { - BMVert *v = f->verts[j] = BM_vert_create(bm, f->co[j], NULL, BM_CREATE_NOP); + BMVert *v = f->verts[j] = BM_vert_create(bm, f->co[j], nullptr, BM_CREATE_NOP); if (input_dvert) { - MDeformVert *dv; - dv = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_MDEFORMVERT); + MDeformVert *dv = static_cast( + CustomData_bmesh_get(&bm->vdata, v->head.data, CD_MDEFORMVERT)); BLI_assert(dv->totweight == 0); BKE_defvert_copy(dv, input_dvert); @@ -1136,7 +1137,7 @@ static int isect_ray_poly(const float ray_start[3], BMFace *f, float *r_lambda) { - BMVert *v, *v_first = NULL, *v_prev = NULL; + BMVert *v, *v_first = nullptr, *v_prev = nullptr; BMIter iter; float best_dist = FLT_MAX; bool hit = false; @@ -1149,7 +1150,8 @@ static int isect_ray_poly(const float ray_start[3], float dist; bool curhit; - curhit = isect_ray_tri_v3(ray_start, ray_dir, v_first->co, v_prev->co, v->co, &dist, NULL); + curhit = isect_ray_tri_v3( + ray_start, ray_dir, v_first->co, v_prev->co, v->co, &dist, nullptr); if (curhit && dist < best_dist) { hit = true; best_dist = dist; @@ -1204,13 +1206,13 @@ static BMFace *collapse_face_corners(BMesh *bm, BMFace *f, int n, BMVert **orig_ BMO_op_finish(bm, &op); /* Find the new face */ - f = NULL; + f = nullptr; BM_ITER_ELEM (vf, &iter, v_safe, BM_FACES_OF_VERT) { bool wrong_face = false; for (i = 0; i < orig_len; i++) { if (orig_verts[i] == v_merge) { - orig_verts[i] = NULL; + orig_verts[i] = nullptr; } else if (orig_verts[i] && !BM_vert_in_face(orig_verts[i], vf)) { wrong_face = true; @@ -1250,7 +1252,7 @@ static BMFace *skin_hole_target_face(BMesh *bm, Frame *frame) /* Use a line intersection test and nearest center test against * all faces */ - isect_target_face = center_target_face = NULL; + isect_target_face = center_target_face = nullptr; BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { float dist, poly_center[3]; int hit; @@ -1322,8 +1324,6 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f { BMFace *f; BMVert *verts[4]; - BMVert **vert_buf = NULL; - BLI_array_declare(vert_buf); BMOIter oiter; BMOperator op; int i, best_order[4]; @@ -1343,7 +1343,7 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f /* Update split face (should only be one new face created * during extrusion) */ - split_face = NULL; + split_face = nullptr; BMO_ITER (f, &oiter, op.slots_out, "faces.out", BM_FACE) { BLI_assert(!split_face); split_face = f; @@ -1351,6 +1351,8 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f BMO_op_finish(bm, &op); + blender::Vector vert_buf; + if (split_face->len == 3) { BMEdge *longest_edge; @@ -1371,16 +1373,14 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f else if (split_face->len > 4) { /* Maintain a dynamic vert array containing the split_face's * vertices, avoids frequent allocations in #collapse_face_corners(). */ - if (BLI_array_len(vert_buf) < split_face->len) { - BLI_array_grow_items(vert_buf, (split_face->len - BLI_array_len(vert_buf))); - } + vert_buf.reinitialize(split_face->len); /* Get split face's verts */ - BM_iter_as_array(bm, BM_VERTS_OF_FACE, split_face, (void **)vert_buf, split_face->len); + BM_iter_as_array(bm, BM_VERTS_OF_FACE, split_face, (void **)vert_buf.data(), split_face->len); /* Earlier edge split operations may have turned some quads * into higher-degree faces */ - split_face = collapse_face_corners(bm, split_face, 4, vert_buf); + split_face = collapse_face_corners(bm, split_face, 4, vert_buf.data()); } /* `split_face` should now be a quad. */ @@ -1389,19 +1389,13 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f /* Account for the highly unlikely case that it's not a quad. */ if (split_face->len != 4) { /* Reuse `vert_buf` for updating normals. */ - BLI_array_clear(vert_buf); - BLI_array_grow_items(vert_buf, split_face->len); + vert_buf.reinitialize(split_face->len); + BM_iter_as_array(bm, BM_FACES_OF_VERT, split_face, (void **)vert_buf.data(), split_face->len); - BM_iter_as_array(bm, BM_FACES_OF_VERT, split_face, (void **)vert_buf, split_face->len); - - vert_array_face_normal_update(vert_buf, split_face->len); - BLI_array_free(vert_buf); + vert_array_face_normal_update(vert_buf.data(), split_face->len); return; } - /* Done with dynamic array. */ - BLI_array_free(vert_buf); - /* Get split face's verts */ // BM_iter_as_array(bm, BM_VERTS_OF_FACE, split_face, (void **)verts, 4); BM_face_as_array_vert_quad(split_face, verts); @@ -1444,7 +1438,7 @@ static void skin_hole_detach_partially_attached_frame(BMesh *bm, Frame *frame) static void quad_from_tris(BMEdge *e, BMFace *adj[2], BMVert *ndx[4]) { BMVert *tri[2][3]; - BMVert *opp = NULL; + BMVert *opp = nullptr; int i, j; BLI_assert(adj[0]->len == 3 && adj[1]->len == 3); @@ -1544,7 +1538,7 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd) while (!BLI_heapsimple_is_empty(heap)) { BMFace *adj[2]; - e = BLI_heapsimple_pop_min(heap); + e = static_cast(BLI_heapsimple_pop_min(heap)); if (BM_edge_face_pair(e, &adj[0], &adj[1])) { /* If both triangles still free, and if they don't already @@ -1559,7 +1553,7 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd) } } - BLI_heapsimple_free(heap, NULL); + BLI_heapsimple_free(heap, nullptr); BM_mesh_delete_hflag_tagged(so->bm, BM_ELEM_TAG, BM_EDGE | BM_FACE); } @@ -1744,7 +1738,9 @@ static void skin_smooth_hulls(BMesh *bm, BM_data_layer_add(bm, &bm->vdata, CD_SHAPEKEY); skey = CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY) - 1; BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { - copy_v3_v3(CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, skey), v->co); + copy_v3_v3( + static_cast(CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, skey)), + v->co); } /* Smooth vertices, weight unmarked vertices more strongly (helps @@ -1764,12 +1760,14 @@ static void skin_smooth_hulls(BMesh *bm, BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { BMVert *other = BM_edge_other_vert(e, v); - add_v3_v3(avg, CustomData_bmesh_get_n(&bm->vdata, other->head.data, CD_SHAPEKEY, skey)); + add_v3_v3(avg, + static_cast( + CustomData_bmesh_get_n(&bm->vdata, other->head.data, CD_SHAPEKEY, skey))); totv++; } if (totv > 1) { - mul_v3_fl(avg, 1.0f / (float)totv); + mul_v3_fl(avg, 1.0f / float(totv)); interp_v3_v3v3(v->co, v->co, avg, weight); } } @@ -1813,10 +1811,11 @@ static bool skin_output_branch_hulls(SkinOutput *so, return result; } -typedef enum eSkinErrorFlag { +enum eSkinErrorFlag { SKIN_ERROR_NO_VALID_ROOT = (1 << 0), SKIN_ERROR_HULL = (1 << 1), -} eSkinErrorFlag; +}; +ENUM_OPERATORS(eSkinErrorFlag, SKIN_ERROR_HULL); static BMesh *build_skin(SkinNode *skin_nodes, int verts_num, @@ -1831,16 +1830,15 @@ static BMesh *build_skin(SkinNode *skin_nodes, int v; so.smd = smd; - so.bm = BM_mesh_create(&bm_mesh_allocsize_default, - &((struct BMeshCreateParams){ - .use_toolflags = true, - })); + BMeshCreateParams create_params{}; + create_params.use_toolflags = true; + so.bm = BM_mesh_create(&bm_mesh_allocsize_default, &create_params); so.mat_nr = 0; /* BMESH_TODO: bumping up the stack level (see MOD_array.cc) */ BM_mesh_elem_toolflags_ensure(so.bm); - BMO_push(so.bm, NULL); - bmesh_edit_begin(so.bm, 0); + BMO_push(so.bm, nullptr); + bmesh_edit_begin(so.bm, BMOpTypeFlag(0)); if (input_dvert) { BM_data_layer_add(so.bm, &so.bm->vdata, CD_MDEFORMVERT); @@ -1853,7 +1851,7 @@ static BMesh *build_skin(SkinNode *skin_nodes, /* Write out all frame vertices to the mesh */ for (v = 0; v < verts_num; v++) { if (skin_nodes[v].totframe) { - output_frames(so.bm, &skin_nodes[v], input_dvert ? &input_dvert[v] : NULL); + output_frames(so.bm, &skin_nodes[v], input_dvert ? &input_dvert[v] : nullptr); } } @@ -1886,7 +1884,7 @@ static BMesh *build_skin(SkinNode *skin_nodes, skin_output_connections(&so, skin_nodes, medge, edges_num); hull_merge_triangles(&so, smd); - bmesh_edit_end(so.bm, 0); + bmesh_edit_end(so.bm, BMOpTypeFlag(0)); BMO_pop(so.bm); return so.bm; @@ -1894,11 +1892,9 @@ static BMesh *build_skin(SkinNode *skin_nodes, static void skin_set_orig_indices(Mesh *mesh) { - int *orig, totpoly; - - totpoly = mesh->totpoly; - orig = CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CONSTRUCT, NULL, totpoly); - copy_vn_i(orig, totpoly, ORIGINDEX_NONE); + int *orig = static_cast( + CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CONSTRUCT, nullptr, mesh->totpoly)); + copy_vn_i(orig, mesh->totpoly, ORIGINDEX_NONE); } /* @@ -1910,7 +1906,6 @@ static void skin_set_orig_indices(Mesh *mesh) static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_error) { Mesh *result; - const MVertSkin *nodes; BMesh *bm; EMat *emat; SkinNode *skin_nodes; @@ -1921,7 +1916,8 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_ int verts_num, edges_num; bool has_valid_root = false; - nodes = CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN); + const MVertSkin *nodes = static_cast( + CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN)); const float(*vert_positions)[3] = BKE_mesh_vert_positions(origmesh); dvert = BKE_mesh_deform_verts(origmesh); @@ -1935,7 +1931,7 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_ nodes, vert_positions, verts_num, medge, emap, edges_num, &has_valid_root); skin_nodes = build_frames(vert_positions, verts_num, nodes, emap, emat); MEM_freeN(emat); - emat = NULL; + emat = nullptr; bm = build_skin(skin_nodes, verts_num, emap, medge, edges_num, dvert, smd, r_error); @@ -1948,10 +1944,10 @@ static Mesh *base_skin(Mesh *origmesh, SkinModifierData *smd, eSkinErrorFlag *r_ } if (!bm) { - return NULL; + return nullptr; } - result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, origmesh); + result = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, origmesh); BM_mesh_free(bm); skin_set_orig_indices(result); @@ -1971,7 +1967,7 @@ static Mesh *final_skin(SkinModifierData *smd, Mesh *mesh, eSkinErrorFlag *r_err mesh = subdivide_base(mesh); result = base_skin(mesh, smd, r_error); - BKE_id_free(NULL, mesh); + BKE_id_free(nullptr, mesh); return result; } @@ -1991,7 +1987,7 @@ static void initData(ModifierData *md) static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) { - eSkinErrorFlag error = 0; + eSkinErrorFlag error = eSkinErrorFlag(0); Mesh *result = final_skin((SkinModifierData *)md, mesh, &error); if (error & SKIN_ERROR_NO_VALID_ROOT) { @@ -2007,18 +2003,18 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * } BLI_assert(error == 0); - if (result == NULL) { + if (result == nullptr) { return mesh; } return result; } -static void requiredDataMask(ModifierData *UNUSED(md), CustomData_MeshMasks *r_cddata_masks) +static void requiredDataMask(ModifierData * /*md*/, CustomData_MeshMasks *r_cddata_masks) { r_cddata_masks->vmask |= CD_MASK_MVERT_SKIN | CD_MASK_MDEFORMVERT; } -static void panel_draw(const bContext *UNUSED(C), Panel *panel) +static void panel_draw(const bContext * /*C*/, Panel *panel) { uiLayout *row; uiLayout *layout = panel->layout; @@ -2031,25 +2027,25 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel) uiLayoutSetPropSep(layout, true); - uiItemR(layout, ptr, "branch_smoothing", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "branch_smoothing", 0, nullptr, ICON_NONE); row = uiLayoutRowWithHeading(layout, true, IFACE_("Symmetry")); - uiItemR(row, ptr, "use_x_symmetry", toggles_flag, NULL, ICON_NONE); - uiItemR(row, ptr, "use_y_symmetry", toggles_flag, NULL, ICON_NONE); - uiItemR(row, ptr, "use_z_symmetry", toggles_flag, NULL, ICON_NONE); + uiItemR(row, ptr, "use_x_symmetry", toggles_flag, nullptr, ICON_NONE); + uiItemR(row, ptr, "use_y_symmetry", toggles_flag, nullptr, ICON_NONE); + uiItemR(row, ptr, "use_z_symmetry", toggles_flag, nullptr, ICON_NONE); - uiItemR(layout, ptr, "use_smooth_shade", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "use_smooth_shade", 0, nullptr, ICON_NONE); row = uiLayoutRow(layout, false); uiItemO(row, IFACE_("Create Armature"), ICON_NONE, "OBJECT_OT_skin_armature_create"); - uiItemO(row, NULL, ICON_NONE, "MESH_OT_customdata_skin_add"); + uiItemO(row, nullptr, ICON_NONE, "MESH_OT_customdata_skin_add"); row = uiLayoutRow(layout, false); uiItemFullO(row, "OBJECT_OT_skin_loose_mark_clear", IFACE_("Mark Loose"), ICON_NONE, - NULL, + nullptr, WM_OP_EXEC_DEFAULT, 0, &op_ptr); @@ -2058,7 +2054,7 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel) "OBJECT_OT_skin_loose_mark_clear", IFACE_("Clear Loose"), ICON_NONE, - NULL, + nullptr, WM_OP_EXEC_DEFAULT, 0, &op_ptr); @@ -2086,24 +2082,24 @@ ModifierTypeInfo modifierType_Skin = { /*copyData*/ BKE_modifier_copydata_generic, - /*deformVerts*/ NULL, - /*deformMatrices*/ NULL, - /*deformVertsEM*/ NULL, - /*deformMatricesEM*/ NULL, + /*deformVerts*/ nullptr, + /*deformMatrices*/ nullptr, + /*deformVertsEM*/ nullptr, + /*deformMatricesEM*/ nullptr, /*modifyMesh*/ modifyMesh, - /*modifyGeometrySet*/ NULL, + /*modifyGeometrySet*/ nullptr, /*initData*/ initData, /*requiredDataMask*/ requiredDataMask, - /*freeData*/ NULL, - /*isDisabled*/ NULL, - /*updateDepsgraph*/ NULL, - /*dependsOnTime*/ NULL, - /*dependsOnNormals*/ NULL, - /*foreachIDLink*/ NULL, - /*foreachTexLink*/ NULL, - /*freeRuntimeData*/ NULL, + /*freeData*/ nullptr, + /*isDisabled*/ nullptr, + /*updateDepsgraph*/ nullptr, + /*dependsOnTime*/ nullptr, + /*dependsOnNormals*/ nullptr, + /*foreachIDLink*/ nullptr, + /*foreachTexLink*/ nullptr, + /*freeRuntimeData*/ nullptr, /*panelRegister*/ panelRegister, - /*blendWrite*/ NULL, - /*blendRead*/ NULL, + /*blendWrite*/ nullptr, + /*blendRead*/ nullptr, }; diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.cc similarity index 79% rename from source/blender/modifiers/intern/MOD_smooth.c rename to source/blender/modifiers/intern/MOD_smooth.cc index a2a42b176dd..1fd7084526f 100644 --- a/source/blender/modifiers/intern/MOD_smooth.c +++ b/source/blender/modifiers/intern/MOD_smooth.cc @@ -47,9 +47,7 @@ static void initData(ModifierData *md) MEMCPY_STRUCT_AFTER(smd, DNA_struct_default_get(SmoothModifierData), modifier); } -static bool isDisabled(const struct Scene *UNUSED(scene), - ModifierData *md, - bool UNUSED(useRenderParams)) +static bool isDisabled(const Scene * /*scene*/, ModifierData *md, bool /*useRenderParams*/) { SmoothModifierData *smd = (SmoothModifierData *)md; @@ -76,18 +74,18 @@ static void requiredDataMask(ModifierData *md, CustomData_MeshMasks *r_cddata_ma static void smoothModifier_do( SmoothModifierData *smd, Object *ob, Mesh *mesh, float (*vertexCos)[3], int verts_num) { - if (mesh == NULL) { + if (mesh == nullptr) { return; } - float(*accumulated_vecs)[3] = MEM_calloc_arrayN( - (size_t)verts_num, sizeof(*accumulated_vecs), __func__); + float(*accumulated_vecs)[3] = static_cast( + MEM_calloc_arrayN((size_t)verts_num, sizeof(*accumulated_vecs), __func__)); if (!accumulated_vecs) { return; } - uint *accumulated_vecs_count = MEM_calloc_arrayN( - (size_t)verts_num, sizeof(*accumulated_vecs_count), __func__); + uint *accumulated_vecs_count = static_cast( + MEM_calloc_arrayN((size_t)verts_num, sizeof(*accumulated_vecs_count), __func__)); if (!accumulated_vecs_count) { MEM_freeN(accumulated_vecs); return; @@ -130,7 +128,7 @@ static void smoothModifier_do( for (int i = 0; i < verts_num; i++, dv++) { float *vco_orig = vertexCos[i]; if (accumulated_vecs_count[i] > 0) { - mul_v3_fl(accumulated_vecs[i], 1.0f / (float)accumulated_vecs_count[i]); + mul_v3_fl(accumulated_vecs[i], 1.0f / float(accumulated_vecs_count[i])); } float *vco_new = accumulated_vecs[i]; @@ -157,7 +155,7 @@ static void smoothModifier_do( for (int i = 0; i < verts_num; i++) { float *vco_orig = vertexCos[i]; if (accumulated_vecs_count[i] > 0) { - mul_v3_fl(accumulated_vecs[i], 1.0f / (float)accumulated_vecs_count[i]); + mul_v3_fl(accumulated_vecs[i], 1.0f / float(accumulated_vecs_count[i])); } float *vco_new = accumulated_vecs[i]; @@ -185,42 +183,42 @@ static void deformVerts(ModifierData *md, int verts_num) { SmoothModifierData *smd = (SmoothModifierData *)md; - Mesh *mesh_src = NULL; + Mesh *mesh_src = nullptr; /* mesh_src is needed for vgroups, and taking edges into account. */ - mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, verts_num, false); + mesh_src = MOD_deform_mesh_eval_get(ctx->object, nullptr, mesh, nullptr, verts_num, false); smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, verts_num); - if (!ELEM(mesh_src, NULL, mesh)) { - BKE_id_free(NULL, mesh_src); + if (!ELEM(mesh_src, nullptr, mesh)) { + BKE_id_free(nullptr, mesh_src); } } static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, - struct BMEditMesh *editData, + BMEditMesh *editData, Mesh *mesh, float (*vertexCos)[3], int verts_num) { SmoothModifierData *smd = (SmoothModifierData *)md; - Mesh *mesh_src = NULL; + Mesh *mesh_src = nullptr; /* mesh_src is needed for vgroups, and taking edges into account. */ - mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, verts_num, false); + mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, nullptr, verts_num, false); /* TODO(@ideasman42): use edit-mode data only (remove this line). */ BKE_mesh_wrapper_ensure_mdata(mesh_src); smoothModifier_do(smd, ctx->object, mesh_src, vertexCos, verts_num); - if (!ELEM(mesh_src, NULL, mesh)) { - BKE_id_free(NULL, mesh_src); + if (!ELEM(mesh_src, nullptr, mesh)) { + BKE_id_free(nullptr, mesh_src); } } -static void panel_draw(const bContext *UNUSED(C), Panel *panel) +static void panel_draw(const bContext * /*C*/, Panel *panel) { uiLayout *row, *col; uiLayout *layout = panel->layout; @@ -232,15 +230,15 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel) uiLayoutSetPropSep(layout, true); row = uiLayoutRowWithHeading(layout, true, IFACE_("Axis")); - uiItemR(row, ptr, "use_x", toggles_flag, NULL, ICON_NONE); - uiItemR(row, ptr, "use_y", toggles_flag, NULL, ICON_NONE); - uiItemR(row, ptr, "use_z", toggles_flag, NULL, ICON_NONE); + uiItemR(row, ptr, "use_x", toggles_flag, nullptr, ICON_NONE); + uiItemR(row, ptr, "use_y", toggles_flag, nullptr, ICON_NONE); + uiItemR(row, ptr, "use_z", toggles_flag, nullptr, ICON_NONE); col = uiLayoutColumn(layout, false); - uiItemR(col, ptr, "factor", 0, NULL, ICON_NONE); - uiItemR(col, ptr, "iterations", 0, NULL, ICON_NONE); + uiItemR(col, ptr, "factor", 0, nullptr, ICON_NONE); + uiItemR(col, ptr, "iterations", 0, nullptr, ICON_NONE); - modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", NULL); + modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr); modifier_panel_end(layout, ptr); } @@ -263,23 +261,23 @@ ModifierTypeInfo modifierType_Smooth = { /*copyData*/ BKE_modifier_copydata_generic, /*deformVerts*/ deformVerts, - /*deformMatrices*/ NULL, + /*deformMatrices*/ nullptr, /*deformVertsEM*/ deformVertsEM, - /*deformMatricesEM*/ NULL, - /*modifyMesh*/ NULL, - /*modifyGeometrySet*/ NULL, + /*deformMatricesEM*/ nullptr, + /*modifyMesh*/ nullptr, + /*modifyGeometrySet*/ nullptr, /*initData*/ initData, /*requiredDataMask*/ requiredDataMask, - /*freeData*/ NULL, + /*freeData*/ nullptr, /*isDisabled*/ isDisabled, - /*updateDepsgraph*/ NULL, - /*dependsOnTime*/ NULL, - /*dependsOnNormals*/ NULL, - /*foreachIDLink*/ NULL, - /*foreachTexLink*/ NULL, - /*freeRuntimeData*/ NULL, + /*updateDepsgraph*/ nullptr, + /*dependsOnTime*/ nullptr, + /*dependsOnNormals*/ nullptr, + /*foreachIDLink*/ nullptr, + /*foreachTexLink*/ nullptr, + /*freeRuntimeData*/ nullptr, /*panelRegister*/ panelRegister, - /*blendWrite*/ NULL, - /*blendRead*/ NULL, + /*blendWrite*/ nullptr, + /*blendRead*/ nullptr, };