Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <eiseljulian@gmail.com>2018-01-30 00:53:32 +0300
committerJulian Eisel <eiseljulian@gmail.com>2018-01-30 01:24:11 +0300
commit3f0871dfcfbb1dda15c176dba92d36639305385a (patch)
treede7ffeeef7a99fc6103d413ebfa564596811087d /source/blender/modifiers
parent53d94dafc474380651fc529f9c03f84ce7142b13 (diff)
parent1fe2b4bf608b22ae4513051e01cf45e5012c2409 (diff)
Merge branch 'blender2.8' into topbar
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r--source/blender/modifiers/intern/MOD_array.c26
-rw-r--r--source/blender/modifiers/intern/MOD_boolean.c2
-rw-r--r--source/blender/modifiers/intern/MOD_build.c6
-rw-r--r--source/blender/modifiers/intern/MOD_collision.c2
-rw-r--r--source/blender/modifiers/intern/MOD_correctivesmooth.c20
-rw-r--r--source/blender/modifiers/intern/MOD_decimate.c2
-rw-r--r--source/blender/modifiers/intern/MOD_displace.c17
-rw-r--r--source/blender/modifiers/intern/MOD_explode.c10
-rw-r--r--source/blender/modifiers/intern/MOD_fluidsim_util.c4
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciandeform.c28
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciansmooth.c16
-rw-r--r--source/blender/modifiers/intern/MOD_mask.c4
-rw-r--r--source/blender/modifiers/intern/MOD_meshcache.c6
-rw-r--r--source/blender/modifiers/intern/MOD_meshdeform.c21
-rw-r--r--source/blender/modifiers/intern/MOD_mirror.c2
-rw-r--r--source/blender/modifiers/intern/MOD_normal_edit.c12
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c25
-rw-r--r--source/blender/modifiers/intern/MOD_particleinstance.c2
-rw-r--r--source/blender/modifiers/intern/MOD_screw.c8
-rw-r--r--source/blender/modifiers/intern/MOD_simpledeform.c169
-rw-r--r--source/blender/modifiers/intern/MOD_skin.c12
-rw-r--r--source/blender/modifiers/intern/MOD_smooth.c4
-rw-r--r--source/blender/modifiers/intern/MOD_solidify.c26
-rw-r--r--source/blender/modifiers/intern/MOD_surface.c4
-rw-r--r--source/blender/modifiers/intern/MOD_surfacedeform.c66
-rw-r--r--source/blender/modifiers/intern/MOD_util.c2
-rw-r--r--source/blender/modifiers/intern/MOD_uvproject.c2
-rw-r--r--source/blender/modifiers/intern/MOD_uvwarp.c13
-rw-r--r--source/blender/modifiers/intern/MOD_warp.c2
-rw-r--r--source/blender/modifiers/intern/MOD_wave.c2
-rw-r--r--source/blender/modifiers/intern/MOD_weightvg_util.c4
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgedit.c6
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgmix.c16
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c44
-rw-r--r--source/blender/modifiers/intern/MOD_wireframe.c9
35 files changed, 381 insertions, 213 deletions
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index 81ace75f2b1..91501e539c0 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -177,8 +177,8 @@ static void dm_mvert_map_doubles(
source_end = source_start + source_num_verts;
/* build array of MVerts to be tested for merging */
- sorted_verts_target = MEM_mallocN(sizeof(SortVertsElem) * target_num_verts, __func__);
- sorted_verts_source = MEM_mallocN(sizeof(SortVertsElem) * source_num_verts, __func__);
+ sorted_verts_target = MEM_malloc_arrayN(target_num_verts, sizeof(SortVertsElem), __func__);
+ sorted_verts_source = MEM_malloc_arrayN(source_num_verts, sizeof(SortVertsElem), __func__);
/* Copy target vertices index and cos into SortVertsElem array */
svert_from_mvert(sorted_verts_target, mverts + target_start, target_start, target_end);
@@ -491,7 +491,7 @@ static DerivedMesh *arrayModifier_doArray(
if (use_merge) {
/* Will need full_doubles_map for handling merge */
- full_doubles_map = MEM_mallocN(sizeof(int) * result_nverts, "mod array doubles map");
+ full_doubles_map = MEM_malloc_arrayN(result_nverts, sizeof(int), "mod array doubles map");
copy_vn_i(full_doubles_map, result_nverts, -1);
}
@@ -608,6 +608,26 @@ static DerivedMesh *arrayModifier_doArray(
}
}
+ /* handle UVs */
+ if (chunk_nloops > 0 && is_zero_v2(amd->uv_offset) == false) {
+ const int totuv = CustomData_number_of_layers(&result->loopData, CD_MLOOPUV);
+ for (i = 0; i < totuv; i++) {
+ MLoopUV *dmloopuv = CustomData_get_layer_n(&result->loopData, CD_MLOOPUV, i);
+ dmloopuv += chunk_nloops;
+ for (c = 1; c < count; c++) {
+ const float uv_offset[2] = {
+ amd->uv_offset[0] * (float)c,
+ amd->uv_offset[1] * (float)c,
+ };
+ int l_index = chunk_nloops;
+ for (; l_index-- != 0; dmloopuv++) {
+ dmloopuv->uv[0] += uv_offset[0];
+ dmloopuv->uv[1] += uv_offset[1];
+ }
+ }
+ }
+ }
+
last_chunk_start = (count - 1) * chunk_nverts;
last_chunk_nverts = chunk_nverts;
diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c
index 5811017f745..0554fbb0317 100644
--- a/source/blender/modifiers/intern/MOD_boolean.c
+++ b/source/blender/modifiers/intern/MOD_boolean.c
@@ -239,7 +239,7 @@ static DerivedMesh *applyModifier_bmesh(
int tottri;
BMLoop *(*looptris)[3];
- looptris = MEM_mallocN(sizeof(*looptris) * looptris_tot, __func__);
+ looptris = MEM_malloc_arrayN(looptris_tot, sizeof(*looptris), __func__);
BM_mesh_calc_tessellation_beauty(bm, looptris, &tottri);
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index 0a0ad11fe16..7a52ede8838 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -104,9 +104,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
MVert *mvert_src = dm->getVertArray(dm);
- vertMap = MEM_mallocN(sizeof(*vertMap) * numVert_src, "build modifier vertMap");
- edgeMap = MEM_mallocN(sizeof(*edgeMap) * numEdge_src, "build modifier edgeMap");
- faceMap = MEM_mallocN(sizeof(*faceMap) * numPoly_src, "build modifier faceMap");
+ vertMap = MEM_malloc_arrayN(numVert_src, sizeof(*vertMap), "build modifier vertMap");
+ edgeMap = MEM_malloc_arrayN(numEdge_src, sizeof(*edgeMap), "build modifier edgeMap");
+ faceMap = MEM_malloc_arrayN(numPoly_src, sizeof(*faceMap), "build modifier faceMap");
range_vn_i(vertMap, numVert_src, 0);
range_vn_i(edgeMap, numEdge_src, 0);
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index b9a2310366a..d2ecbaeaafe 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -158,7 +158,7 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED
{
const MLoop *mloop = dm->getLoopArray(dm);
const MLoopTri *looptri = dm->getLoopTriArray(dm);
- MVertTri *tri = MEM_mallocN(sizeof(*tri) * collmd->tri_num, __func__);
+ MVertTri *tri = MEM_malloc_arrayN(collmd->tri_num, sizeof(*tri), __func__);
DM_verttri_from_looptri(tri, mloop, looptri, collmd->tri_num);
collmd->tri = tri;
}
diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index 716b918d0f0..d95f0ae9286 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -156,7 +156,7 @@ static void dm_get_boundaries(DerivedMesh *dm, float *smooth_weights)
mpoly_num = (unsigned int)dm->getNumPolys(dm);
medge_num = (unsigned int)dm->getNumEdges(dm);
- boundaries = MEM_callocN(medge_num * sizeof(*boundaries), __func__);
+ boundaries = MEM_calloc_arrayN(medge_num, sizeof(*boundaries), __func__);
/* count the number of adjacent faces */
for (i = 0; i < mpoly_num; i++) {
@@ -199,9 +199,9 @@ static void smooth_iter__simple(
struct SmoothingData_Simple {
float delta[3];
- } *smooth_data = MEM_callocN((size_t)numVerts * sizeof(*smooth_data), __func__);
+ } *smooth_data = MEM_calloc_arrayN(numVerts, sizeof(*smooth_data), __func__);
- vertex_edge_count_div = MEM_callocN((size_t)numVerts * sizeof(float), __func__);
+ vertex_edge_count_div = MEM_calloc_arrayN(numVerts, sizeof(float), __func__);
/* calculate as floats to avoid int->float conversion in #smooth_iter */
for (i = 0; i < numEdges; i++) {
@@ -277,11 +277,11 @@ static void smooth_iter__length_weight(
struct SmoothingData_Weighted {
float delta[3];
float edge_length_sum;
- } *smooth_data = MEM_callocN((size_t)numVerts * sizeof(*smooth_data), __func__);
+ } *smooth_data = MEM_calloc_arrayN(numVerts, sizeof(*smooth_data), __func__);
/* calculate as floats to avoid int->float conversion in #smooth_iter */
- vertex_edge_count = MEM_callocN((size_t)numVerts * sizeof(float), __func__);
+ vertex_edge_count = MEM_calloc_arrayN(numVerts, sizeof(float), __func__);
for (i = 0; i < numEdges; i++) {
vertex_edge_count[edges[i].v1] += 1.0f;
vertex_edge_count[edges[i].v2] += 1.0f;
@@ -382,7 +382,7 @@ static void smooth_verts(
if (dvert || (csmd->flag & MOD_CORRECTIVESMOOTH_PIN_BOUNDARY)) {
- smooth_weights = MEM_mallocN(numVerts * sizeof(float), __func__);
+ smooth_weights = MEM_malloc_arrayN(numVerts, sizeof(float), __func__);
if (dvert) {
dm_get_weights(
@@ -530,7 +530,7 @@ static void calc_deltas(
float (*tangent_spaces)[3][3];
unsigned int i;
- tangent_spaces = MEM_callocN((size_t)(numVerts) * sizeof(float[3][3]), __func__);
+ tangent_spaces = MEM_calloc_arrayN(numVerts, sizeof(float[3][3]), __func__);
if (csmd->delta_cache_num != numVerts) {
MEM_SAFE_FREE(csmd->delta_cache);
@@ -539,7 +539,7 @@ static void calc_deltas(
/* allocate deltas if they have not yet been allocated, otheriwse we will just write over them */
if (!csmd->delta_cache) {
csmd->delta_cache_num = numVerts;
- csmd->delta_cache = MEM_mallocN((size_t)numVerts * sizeof(float[3]), __func__);
+ csmd->delta_cache = MEM_malloc_arrayN(numVerts, sizeof(float[3]), __func__);
}
smooth_verts(csmd, dm, dvert, defgrp_index, smooth_vertex_coords, numVerts);
@@ -575,7 +575,7 @@ static void correctivesmooth_modifier_do(
const bool force_delta_cache_update =
/* XXX, take care! if mesh data its self changes we need to forcefully recalculate deltas */
((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_ORCO) &&
- (((ID *)ob->data)->tag & LIB_TAG_ID_RECALC));
+ (((ID *)ob->data)->recalc & ID_RECALC));
bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0;
MDeformVert *dvert = NULL;
@@ -680,7 +680,7 @@ static void correctivesmooth_modifier_do(
float (*tangent_spaces)[3][3];
/* calloc, since values are accumulated */
- tangent_spaces = MEM_callocN((size_t)numVerts * sizeof(float[3][3]), __func__);
+ tangent_spaces = MEM_calloc_arrayN(numVerts, sizeof(float[3][3]), __func__);
calc_tangent_spaces(dm, vertexCos, tangent_spaces);
diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c
index 078a3085fc7..83dcd7b9b89 100644
--- a/source/blender/modifiers/intern/MOD_decimate.c
+++ b/source/blender/modifiers/intern/MOD_decimate.c
@@ -142,7 +142,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
const unsigned int vert_tot = dm->getNumVerts(dm);
unsigned int i;
- vweights = MEM_mallocN(vert_tot * sizeof(float), __func__);
+ vweights = MEM_malloc_arrayN(vert_tot, sizeof(float), __func__);
if (dmd->flag & MOD_DECIM_FLAG_INVERT_VGROUP) {
for (i = 0; i < vert_tot; i++) {
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index c9ccdc3b8c2..53a77b6fe38 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -187,7 +187,10 @@ typedef struct DisplaceUserdata {
float (*vert_clnors)[3];
} DisplaceUserdata;
-static void displaceModifier_do_task(void *userdata, const int iter)
+static void displaceModifier_do_task(
+ void *__restrict userdata,
+ const int iter,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
DisplaceUserdata *data = (DisplaceUserdata *)userdata;
DisplaceModifierData *dmd = data->dmd;
@@ -305,7 +308,7 @@ static void displaceModifier_do(
modifier_get_vgroup(ob, dm, dmd->defgrp_name, &dvert, &defgrp_index);
if (dmd->texture) {
- tex_co = MEM_callocN(sizeof(*tex_co) * numVerts,
+ tex_co = MEM_calloc_arrayN((size_t)numVerts, sizeof(*tex_co),
"displaceModifier_do tex_co");
get_texture_coords((MappingInfoModifierData *)dmd, ob, dm, vertexCos, tex_co, numVerts);
@@ -326,7 +329,7 @@ static void displaceModifier_do(
}
clnors = CustomData_get_layer(ldata, CD_NORMAL);
- vert_clnors = MEM_mallocN(sizeof(*vert_clnors) * (size_t)numVerts, __func__);
+ vert_clnors = MEM_malloc_arrayN(numVerts, sizeof(*vert_clnors), __func__);
BKE_mesh_normals_loop_to_vertex(numVerts, dm->getLoopArray(dm), dm->getNumLoops(dm),
(const float (*)[3])clnors, vert_clnors);
}
@@ -356,7 +359,13 @@ static void displaceModifier_do(
data.pool = BKE_image_pool_new();
BKE_texture_fetch_images_for_pool(dmd->texture, data.pool);
}
- BLI_task_parallel_range(0, numVerts, &data, displaceModifier_do_task, numVerts > 512);
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = (numVerts > 512);
+ BLI_task_parallel_range(0, numVerts,
+ &data,
+ displaceModifier_do_task,
+ &settings);
if (data.pool != NULL) {
BKE_image_pool_free(data.pool);
diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c
index 38785abbc19..8483da60576 100644
--- a/source/blender/modifiers/intern/MOD_explode.c
+++ b/source/blender/modifiers/intern/MOD_explode.c
@@ -119,9 +119,9 @@ static void createFacepa(ExplodeModifierData *emd,
if (emd->facepa)
MEM_freeN(emd->facepa);
- facepa = emd->facepa = MEM_callocN(sizeof(int) * totface, "explode_facepa");
+ facepa = emd->facepa = MEM_calloc_arrayN(totface, sizeof(int), "explode_facepa");
- vertpa = MEM_callocN(sizeof(int) * totvert, "explode_vertpa");
+ vertpa = MEM_calloc_arrayN(totvert, sizeof(int), "explode_vertpa");
/* initialize all faces & verts to no particle */
for (i = 0; i < totface; i++)
@@ -557,8 +557,8 @@ static DerivedMesh *cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
int totvert = dm->getNumVerts(dm);
int totface = dm->getNumTessFaces(dm);
- int *facesplit = MEM_callocN(sizeof(int) * totface, "explode_facesplit");
- int *vertpa = MEM_callocN(sizeof(int) * totvert, "explode_vertpa2");
+ int *facesplit = MEM_calloc_arrayN(totface, sizeof(int), "explode_facesplit");
+ int *vertpa = MEM_calloc_arrayN(totvert, sizeof(int), "explode_vertpa2");
int *facepa = emd->facepa;
int *fs, totesplit = 0, totfsplit = 0, curdupface = 0;
int i, v1, v2, v3, v4, esplit,
@@ -656,7 +656,7 @@ static DerivedMesh *cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
* later interpreted as tri's, for this to work right I think we probably
* have to stop using tessface - campbell */
- facepa = MEM_callocN(sizeof(int) * (totface + (totfsplit * 2)), "explode_facepa");
+ facepa = MEM_calloc_arrayN((totface + (totfsplit * 2)), sizeof(int), "explode_facepa");
//memcpy(facepa, emd->facepa, totface*sizeof(int));
emd->facepa = facepa;
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c
index 3684e947fe0..c9f475ad228 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim_util.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c
@@ -239,7 +239,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
return NULL;
}
- normals = MEM_callocN(sizeof(short) * numverts * 3, "fluid_tmp_normals");
+ normals = MEM_calloc_arrayN(numverts, 3 * sizeof(short), "fluid_tmp_normals");
if (!normals) {
if (dm)
dm->release(dm);
@@ -384,7 +384,7 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *
if (fss->domainNovecgen > 0) return;
- fss->meshVelocities = MEM_callocN(sizeof(FluidVertexVelocity) * dm->getNumVerts(dm), "Fluidsim_velocities");
+ fss->meshVelocities = MEM_calloc_arrayN(dm->getNumVerts(dm), sizeof(FluidVertexVelocity), "Fluidsim_velocities");
fss->totvert = totvert;
velarray = fss->meshVelocities;
diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c
index d322b8631d2..72db3f1c132 100644
--- a/source/blender/modifiers/intern/MOD_laplaciandeform.c
+++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c
@@ -108,12 +108,12 @@ static LaplacianSystem *initLaplacianSystem(
sys->total_anchors = totalAnchors;
sys->repeat = iterations;
BLI_strncpy(sys->anchor_grp_name, defgrpName, sizeof(sys->anchor_grp_name));
- sys->co = MEM_mallocN(sizeof(float[3]) * totalVerts, "DeformCoordinates");
- sys->no = MEM_callocN(sizeof(float[3]) * totalVerts, "DeformNormals");
- sys->delta = MEM_callocN(sizeof(float[3]) * totalVerts, "DeformDeltas");
- sys->tris = MEM_mallocN(sizeof(int[3]) * totalTris, "DeformFaces");
- sys->index_anchors = MEM_mallocN(sizeof(int) * (totalAnchors), "DeformAnchors");
- sys->unit_verts = MEM_callocN(sizeof(int) * totalVerts, "DeformUnitVerts");
+ sys->co = MEM_malloc_arrayN(totalVerts, sizeof(float[3]), "DeformCoordinates");
+ sys->no = MEM_calloc_arrayN(totalVerts, sizeof(float[3]), "DeformNormals");
+ sys->delta = MEM_calloc_arrayN(totalVerts, sizeof(float[3]), "DeformDeltas");
+ sys->tris = MEM_malloc_arrayN(totalTris, sizeof(int[3]), "DeformFaces");
+ sys->index_anchors = MEM_malloc_arrayN((totalAnchors), sizeof(int), "DeformAnchors");
+ sys->unit_verts = MEM_calloc_arrayN(totalVerts, sizeof(int), "DeformUnitVerts");
return sys;
}
@@ -142,7 +142,7 @@ static void createFaceRingMap(
{
int i, j, totalr = 0;
int *indices, *index_iter;
- MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * mvert_tot, "DeformRingMap");
+ MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformRingMap");
const MLoopTri *mlt;
for (i = 0, mlt = mlooptri; i < mtri_tot; i++, mlt++) {
@@ -153,7 +153,7 @@ static void createFaceRingMap(
totalr++;
}
}
- indices = MEM_callocN(sizeof(int) * totalr, "DeformRingIndex");
+ indices = MEM_calloc_arrayN(totalr, sizeof(int), "DeformRingIndex");
index_iter = indices;
for (i = 0; i < mvert_tot; i++) {
map[i].indices = index_iter;
@@ -175,7 +175,7 @@ static void createVertRingMap(
const int mvert_tot, const MEdge *medge, const int medge_tot,
MeshElemMap **r_map, int **r_indices)
{
- MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * mvert_tot, "DeformNeighborsMap");
+ MeshElemMap *map = MEM_calloc_arrayN(mvert_tot, sizeof(MeshElemMap), "DeformNeighborsMap");
int i, vid[2], totalr = 0;
int *indices, *index_iter;
const MEdge *me;
@@ -187,7 +187,7 @@ static void createVertRingMap(
map[vid[1]].count++;
totalr += 2;
}
- indices = MEM_callocN(sizeof(int) * totalr, "DeformNeighborsIndex");
+ indices = MEM_calloc_arrayN(totalr, sizeof(int), "DeformNeighborsIndex");
index_iter = indices;
for (i = 0; i < mvert_tot; i++) {
map[i].indices = index_iter;
@@ -521,7 +521,7 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh
LaplacianSystem *sys;
if (isValidVertexGroup(lmd, ob, dm)) {
- int *index_anchors = MEM_mallocN(sizeof(int) * numVerts, __func__); /* over-alloc */
+ int *index_anchors = MEM_malloc_arrayN(numVerts, sizeof(int), __func__); /* over-alloc */
const MLoopTri *mlooptri;
const MLoop *mloop;
@@ -547,7 +547,7 @@ static void initSystem(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh
memcpy(sys->index_anchors, index_anchors, sizeof(int) * total_anchors);
memcpy(sys->co, vertexCos, sizeof(float[3]) * numVerts);
MEM_freeN(index_anchors);
- lmd->vertexco = MEM_mallocN(sizeof(float[3]) * numVerts, "ModDeformCoordinates");
+ lmd->vertexco = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "ModDeformCoordinates");
memcpy(lmd->vertexco, vertexCos, sizeof(float[3]) * numVerts);
lmd->total_verts = numVerts;
@@ -631,7 +631,7 @@ static void LaplacianDeformModifier_do(
sys = lmd->cache_system;
if (sysdif) {
if (sysdif == LAPDEFORM_SYSTEM_ONLY_CHANGE_ANCHORS || sysdif == LAPDEFORM_SYSTEM_ONLY_CHANGE_GROUP) {
- filevertexCos = MEM_mallocN(sizeof(float[3]) * numVerts, "TempModDeformCoordinates");
+ filevertexCos = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "TempModDeformCoordinates");
memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * numVerts);
MEM_SAFE_FREE(lmd->vertexco);
lmd->total_verts = 0;
@@ -667,7 +667,7 @@ static void LaplacianDeformModifier_do(
lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND;
}
else if (lmd->total_verts > 0 && lmd->total_verts == numVerts) {
- filevertexCos = MEM_mallocN(sizeof(float[3]) * numVerts, "TempDeformCoordinates");
+ filevertexCos = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "TempDeformCoordinates");
memcpy(filevertexCos, lmd->vertexco, sizeof(float[3]) * numVerts);
MEM_SAFE_FREE(lmd->vertexco);
lmd->total_verts = 0;
diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
index d7bc7b6c427..977b8b41cc3 100644
--- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c
+++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
@@ -132,14 +132,14 @@ static LaplacianSystem *init_laplacian_system(int a_numEdges, int a_numPolys, in
sys->numLoops = a_numLoops;
sys->numVerts = a_numVerts;
- sys->eweights = MEM_callocN(sizeof(float) * sys->numEdges, __func__);
- sys->fweights = MEM_callocN(sizeof(float[3]) * sys->numLoops, __func__);
- sys->numNeEd = MEM_callocN(sizeof(short) * sys->numVerts, __func__);
- sys->numNeFa = MEM_callocN(sizeof(short) * sys->numVerts, __func__);
- sys->ring_areas = MEM_callocN(sizeof(float) * sys->numVerts, __func__);
- sys->vlengths = MEM_callocN(sizeof(float) * sys->numVerts, __func__);
- sys->vweights = MEM_callocN(sizeof(float) * sys->numVerts, __func__);
- sys->zerola = MEM_callocN(sizeof(short) * sys->numVerts, __func__);
+ sys->eweights = MEM_calloc_arrayN(sys->numEdges, sizeof(float), __func__);
+ sys->fweights = MEM_calloc_arrayN(sys->numLoops, sizeof(float[3]), __func__);
+ sys->numNeEd = MEM_calloc_arrayN(sys->numVerts, sizeof(short), __func__);
+ sys->numNeFa = MEM_calloc_arrayN(sys->numVerts, sizeof(short), __func__);
+ sys->ring_areas = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__);
+ sys->vlengths = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__);
+ sys->vweights = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__);
+ sys->zerola = MEM_calloc_arrayN(sys->numVerts, sizeof(short), __func__);
return sys;
}
diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c
index d942b23b216..bcebbc40adb 100644
--- a/source/blender/modifiers/intern/MOD_mask.c
+++ b/source/blender/modifiers/intern/MOD_mask.c
@@ -162,7 +162,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
* - each cell is a boolean saying whether bone corresponding to the ith group is selected
* - groups that don't match a bone are treated as not existing (along with the corresponding ungrouped verts)
*/
- bone_select_array = MEM_mallocN((size_t)defbase_tot * sizeof(char), "mask array");
+ bone_select_array = MEM_malloc_arrayN((size_t)defbase_tot, sizeof(char), "mask array");
for (i = 0, def = ob->defbase.first; def; def = def->next, i++) {
pchan = BKE_pose_channel_find_name(oba->pose, def->name);
@@ -246,7 +246,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
mloop_src = dm->getLoopArray(dm);
/* overalloc, assume all polys are seen */
- loop_mapping = MEM_mallocN(sizeof(int) * (size_t)maxPolys, "mask loopmap");
+ loop_mapping = MEM_malloc_arrayN((size_t)maxPolys, sizeof(int), "mask loopmap");
/* loop over edges and faces, and do the same thing to
* ensure that they only reference existing verts
diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c
index c990951c578..5dfa1d874b2 100644
--- a/source/blender/modifiers/intern/MOD_meshcache.c
+++ b/source/blender/modifiers/intern/MOD_meshcache.c
@@ -94,7 +94,7 @@ static void meshcache_do(
{
const bool use_factor = mcmd->factor < 1.0f;
float (*vertexCos_Store)[3] = (use_factor || (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ?
- MEM_mallocN(sizeof(*vertexCos_Store) * numVerts, __func__) : NULL;
+ MEM_malloc_arrayN(numVerts, sizeof(*vertexCos_Store), __func__) : NULL;
float (*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real;
Scene *scene = mcmd->modifier.scene;
@@ -197,8 +197,8 @@ static void meshcache_do(
/* the moons align! */
int i;
- float (*vertexCos_Source)[3] = MEM_mallocN(sizeof(*vertexCos_Source) * numVerts, __func__);
- float (*vertexCos_New)[3] = MEM_mallocN(sizeof(*vertexCos_New) * numVerts, __func__);
+ float (*vertexCos_Source)[3] = MEM_malloc_arrayN(numVerts, sizeof(*vertexCos_Source), __func__);
+ float (*vertexCos_New)[3] = MEM_malloc_arrayN(numVerts, sizeof(*vertexCos_New), __func__);
MVert *mv = me->mvert;
for (i = 0; i < numVerts; i++, mv++) {
diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c
index ab43204365d..da233a18d0a 100644
--- a/source/blender/modifiers/intern/MOD_meshdeform.c
+++ b/source/blender/modifiers/intern/MOD_meshdeform.c
@@ -215,7 +215,10 @@ typedef struct MeshdeformUserdata {
float (*icagemat)[3];
} MeshdeformUserdata;
-static void meshdeform_vert_task(void *userdata, const int iter)
+static void meshdeform_vert_task(
+ void *__restrict userdata,
+ const int iter,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
MeshdeformUserdata *data = userdata;
/*const*/ MeshDeformModifierData *mmd = data->mmd;
@@ -358,7 +361,7 @@ static void meshdeformModifier_do(
return;
}
- cagecos = MEM_mallocN(sizeof(*cagecos) * totcagevert, "meshdeformModifier vertCos");
+ cagecos = MEM_malloc_arrayN(totcagevert, sizeof(*cagecos), "meshdeformModifier vertCos");
/* setup deformation data */
cagedm->getVertCos(cagedm, cagecos);
@@ -367,7 +370,7 @@ static void meshdeformModifier_do(
/* We allocate 1 element extra to make it possible to
* load the values to SSE registers, which are float4.
*/
- dco = MEM_callocN(sizeof(*dco) * (totcagevert + 1), "MDefDco");
+ dco = MEM_calloc_arrayN((totcagevert + 1), sizeof(*dco), "MDefDco");
zero_v3(dco[totcagevert]);
for (a = 0; a < totcagevert; a++) {
/* get cage vertex in world space with binding transform */
@@ -394,7 +397,13 @@ static void meshdeformModifier_do(
data.icagemat = icagemat;
/* Do deformation. */
- BLI_task_parallel_range(0, totvert, &data, meshdeform_vert_task, totvert > 1000);
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.min_iter_per_thread = 16;
+ BLI_task_parallel_range(0, totvert,
+ &data,
+ meshdeform_vert_task,
+ &settings);
/* release cage derivedmesh */
MEM_freeN(dco);
@@ -458,8 +467,8 @@ void modifier_mdef_compact_influences(ModifierData *md)
}
/* allocate bind influences */
- mmd->bindinfluences = MEM_callocN(sizeof(MDefInfluence) * mmd->totinfluence, "MDefBindInfluence");
- mmd->bindoffsets = MEM_callocN(sizeof(int) * (totvert + 1), "MDefBindOffset");
+ mmd->bindinfluences = MEM_calloc_arrayN(mmd->totinfluence, sizeof(MDefInfluence), "MDefBindInfluence");
+ mmd->bindoffsets = MEM_calloc_arrayN((totvert + 1), sizeof(int), "MDefBindOffset");
/* write influences */
totinfluence = 0;
diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c
index db06dc43b8e..1b725e335a4 100644
--- a/source/blender/modifiers/intern/MOD_mirror.c
+++ b/source/blender/modifiers/intern/MOD_mirror.c
@@ -167,7 +167,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
if (do_vtargetmap) {
/* second half is filled with -1 */
- vtargetmap = MEM_mallocN(sizeof(int) * maxVerts * 2, "MOD_mirror tarmap");
+ vtargetmap = MEM_malloc_arrayN(maxVerts, 2 * sizeof(int), "MOD_mirror tarmap");
vtmap_a = vtargetmap;
vtmap_b = vtargetmap + maxVerts;
diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c
index 1c7c640b971..61a5b9bb03e 100644
--- a/source/blender/modifiers/intern/MOD_normal_edit.c
+++ b/source/blender/modifiers/intern/MOD_normal_edit.c
@@ -117,7 +117,7 @@ static void mix_normals(
int i;
if (dvert) {
- facs = MEM_mallocN(sizeof(*facs) * (size_t)num_loops, __func__);
+ facs = MEM_malloc_arrayN((size_t)num_loops, sizeof(*facs), __func__);
BKE_defvert_extract_vgroup_to_loopweights(
dvert, defgrp_index, num_verts, mloop, num_loops, facs, use_invert_vgroup);
}
@@ -195,8 +195,8 @@ static void normalEditModifier_do_radial(
{
int i;
- float (*cos)[3] = MEM_mallocN(sizeof(*cos) * num_verts, __func__);
- float (*nos)[3] = MEM_mallocN(sizeof(*nos) * num_loops, __func__);
+ float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__);
+ float (*nos)[3] = MEM_malloc_arrayN((size_t)num_loops, sizeof(*nos), __func__);
float size[3];
BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)num_verts, __func__);
@@ -294,8 +294,8 @@ static void normalEditModifier_do_directional(
{
const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0;
- float (*cos)[3] = MEM_mallocN(sizeof(*cos) * num_verts, __func__);
- float (*nos)[3] = MEM_mallocN(sizeof(*nos) * num_loops, __func__);
+ float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__);
+ float (*nos)[3] = MEM_malloc_arrayN((size_t)num_loops, sizeof(*nos), __func__);
float target_co[3];
int i;
@@ -434,7 +434,7 @@ static DerivedMesh *normalEditModifier_do(NormalEditModifierData *enmd, Object *
polynors = dm->getPolyDataArray(dm, CD_NORMAL);
if (!polynors) {
- polynors = MEM_mallocN(sizeof(*polynors) * num_polys, __func__);
+ polynors = MEM_malloc_arrayN((size_t)num_polys, sizeof(*polynors), __func__);
BKE_mesh_calc_normals_poly(mvert, NULL, num_verts, mloop, mpoly, num_loops, num_polys, polynors, false);
free_polynors = true;
}
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index 189cfb8553e..b3a7ecaa138 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -261,7 +261,10 @@ typedef struct GenerateOceanGeometryData {
float ix, iy;
} GenerateOceanGeometryData;
-static void generate_ocean_geometry_vertices(void *userdata, const int y)
+static void generate_ocean_geometry_vertices(
+ void *__restrict userdata,
+ const int y,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
GenerateOceanGeometryData *gogd = userdata;
int x;
@@ -275,7 +278,10 @@ static void generate_ocean_geometry_vertices(void *userdata, const int y)
}
}
-static void generate_ocean_geometry_polygons(void *userdata, const int y)
+static void generate_ocean_geometry_polygons(
+ void *__restrict userdata,
+ const int y,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
GenerateOceanGeometryData *gogd = userdata;
int x;
@@ -305,7 +311,10 @@ static void generate_ocean_geometry_polygons(void *userdata, const int y)
}
}
-static void generate_ocean_geometry_uvs(void *userdata, const int y)
+static void generate_ocean_geometry_uvs(
+ void *__restrict userdata,
+ const int y,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
GenerateOceanGeometryData *gogd = userdata;
int x;
@@ -367,11 +376,15 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
gogd.origindex = CustomData_get_layer(&result->polyData, CD_ORIGINDEX);
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = use_threading;
+
/* create vertices */
- BLI_task_parallel_range(0, gogd.res_y + 1, &gogd, generate_ocean_geometry_vertices, use_threading);
+ BLI_task_parallel_range(0, gogd.res_y + 1, &gogd, generate_ocean_geometry_vertices, &settings);
/* create faces */
- BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_polygons, use_threading);
+ BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_polygons, &settings);
CDDM_calc_edges(result);
@@ -383,7 +396,7 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
gogd.ix = 1.0 / gogd.rx;
gogd.iy = 1.0 / gogd.ry;
- BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_uvs, use_threading);
+ BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_uvs, &settings);
}
}
diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c
index de59635f335..09966da13a2 100644
--- a/source/blender/modifiers/intern/MOD_particleinstance.c
+++ b/source/blender/modifiers/intern/MOD_particleinstance.c
@@ -220,7 +220,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
if (pimd->flag & eParticleInstanceFlag_UseSize) {
float *si;
- si = size = MEM_callocN(totpart * sizeof(float), "particle size array");
+ si = size = MEM_calloc_arrayN(totpart, sizeof(float), "particle size array");
if (pimd->flag & eParticleInstanceFlag_Parents) {
for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++, si++)
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index 010bf8bf092..979dc339e4e 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -139,7 +139,7 @@ static DerivedMesh *dm_remove_doubles_on_axis(
if (tot_doubles != 0) {
uint tot = totvert * step_tot;
- int *full_doubles_map = MEM_mallocN(sizeof(int) * tot, __func__);
+ int *full_doubles_map = MEM_malloc_arrayN(tot, sizeof(int), __func__);
copy_vn_i(full_doubles_map, (int)tot, -1);
uint tot_doubles_left = tot_doubles;
@@ -448,10 +448,10 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
mpoly_orig = dm->getPolyArray(dm);
mloop_orig = dm->getLoopArray(dm);
- edge_poly_map = MEM_mallocN(sizeof(*edge_poly_map) * totedge, __func__);
+ edge_poly_map = MEM_malloc_arrayN(totedge, sizeof(*edge_poly_map), __func__);
memset(edge_poly_map, 0xff, sizeof(*edge_poly_map) * totedge);
- vert_loop_map = MEM_mallocN(sizeof(*vert_loop_map) * totvert, __func__);
+ vert_loop_map = MEM_malloc_arrayN(totvert, sizeof(*vert_loop_map), __func__);
memset(vert_loop_map, 0xff, sizeof(*vert_loop_map) * totvert);
for (i = 0, mp_orig = mpoly_orig; i < totpoly; i++, mp_orig++) {
@@ -497,7 +497,7 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
* This makes the modifier faster with one less alloc.
*/
- vert_connect = MEM_mallocN(sizeof(ScrewVertConnect) * totvert, "ScrewVertConnect");
+ vert_connect = MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), "ScrewVertConnect");
//vert_connect = (ScrewVertConnect *) &medge_new[totvert]; /* skip the first slice of verts */
vc = vert_connect;
diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c
index 146e882a6b6..6116e49d07d 100644
--- a/source/blender/modifiers/intern/MOD_simpledeform.c
+++ b/source/blender/modifiers/intern/MOD_simpledeform.c
@@ -32,7 +32,6 @@
* \ingroup modifiers
*/
-
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
@@ -48,9 +47,33 @@
#define BEND_EPS 0.000001f
+/* Re-maps the indicies for X Y Z by shifting them up and wrapping, such that
+ * X = Y, Y = Z, Z = X (for X axis), and X = Z, Y = X, Z = Y (for Y axis). This
+ * exists because the deformations (excluding bend) are based on the Z axis.
+ * Having this helps avoid long, drawn out switches. */
+static const uint axis_map_table[3][3] = {
+ {1, 2, 0},
+ {2, 0, 1},
+ {0, 1, 2},
+};
+
+BLI_INLINE void copy_v3_v3_map(float a[3], const float b[3], const uint map[3])
+{
+ a[0] = b[map[0]];
+ a[1] = b[map[1]];
+ a[2] = b[map[2]];
+}
+
+BLI_INLINE void copy_v3_v3_unmap(float a[3], const float b[3], const uint map[3])
+{
+ a[map[0]] = b[0];
+ a[map[1]] = b[1];
+ a[map[2]] = b[2];
+}
+
/* Clamps/Limits the given coordinate to: limits[0] <= co[axis] <= limits[1]
* The amount of clamp is saved on dcut */
-static void axis_limit(int axis, const float limits[2], float co[3], float dcut[3])
+static void axis_limit(const int axis, const float limits[2], float co[3], float dcut[3])
{
float val = co[axis];
if (limits[0] > val) val = limits[0];
@@ -60,7 +83,7 @@ static void axis_limit(int axis, const float limits[2], float co[3], float dcut[
co[axis] = val;
}
-static void simpleDeform_taper(const float factor, const float dcut[3], float r_co[3])
+static void simpleDeform_taper(const float factor, const int UNUSED(axis), const float dcut[3], float r_co[3])
{
float x = r_co[0], y = r_co[1], z = r_co[2];
float scale = z * factor;
@@ -69,14 +92,10 @@ static void simpleDeform_taper(const float factor, const float dcut[3], float r_
r_co[1] = y + y * scale;
r_co[2] = z;
- {
- r_co[0] += dcut[0];
- r_co[1] += dcut[1];
- r_co[2] += dcut[2];
- }
+ add_v3_v3(r_co, dcut);
}
-static void simpleDeform_stretch(const float factor, const float dcut[3], float r_co[3])
+static void simpleDeform_stretch(const float factor, const int UNUSED(axis), const float dcut[3], float r_co[3])
{
float x = r_co[0], y = r_co[1], z = r_co[2];
float scale;
@@ -87,14 +106,10 @@ static void simpleDeform_stretch(const float factor, const float dcut[3], float
r_co[1] = y * scale;
r_co[2] = z * (1.0f + factor);
- {
- r_co[0] += dcut[0];
- r_co[1] += dcut[1];
- r_co[2] += dcut[2];
- }
+ add_v3_v3(r_co, dcut);
}
-static void simpleDeform_twist(const float factor, const float *dcut, float r_co[3])
+static void simpleDeform_twist(const float factor, const int UNUSED(axis), const float *dcut, float r_co[3])
{
float x = r_co[0], y = r_co[1], z = r_co[2];
float theta, sint, cost;
@@ -107,32 +122,58 @@ static void simpleDeform_twist(const float factor, const float *dcut, float r_co
r_co[1] = x * sint + y * cost;
r_co[2] = z;
- {
- r_co[0] += dcut[0];
- r_co[1] += dcut[1];
- r_co[2] += dcut[2];
- }
+ add_v3_v3(r_co, dcut);
}
-static void simpleDeform_bend(const float factor, const float dcut[3], float r_co[3])
+static void simpleDeform_bend(const float factor, const int axis, const float dcut[3], float r_co[3])
{
float x = r_co[0], y = r_co[1], z = r_co[2];
float theta, sint, cost;
BLI_assert(!(fabsf(factor) < BEND_EPS));
- theta = x * factor;
+ switch (axis) {
+ case 0:
+ ATTR_FALLTHROUGH;
+ case 1:
+ theta = z * factor;
+ break;
+ default:
+ theta = x * factor;
+ }
sint = sinf(theta);
cost = cosf(theta);
- r_co[0] = -(y - 1.0f / factor) * sint;
- r_co[1] = (y - 1.0f / factor) * cost + 1.0f / factor;
- r_co[2] = z;
-
- {
- r_co[0] += cost * dcut[0];
- r_co[1] += sint * dcut[0];
- r_co[2] += dcut[2];
+ switch (axis) {
+ case 0:
+ r_co[0] = x;
+ r_co[1] = (y - 1.0f / factor) * cost + 1.0f / factor;
+ r_co[2] = -(y - 1.0f / factor) * sint;
+ {
+ r_co[0] += dcut[0];
+ r_co[1] += sint * dcut[2];
+ r_co[2] += cost * dcut[2];
+ }
+ break;
+ case 1:
+ r_co[0] = (x - 1.0f / factor) * cost + 1.0f / factor;
+ r_co[1] = y;
+ r_co[2] = -(x - 1.0f / factor) * sint;
+ {
+ r_co[0] += sint * dcut[2];
+ r_co[1] += dcut[1];
+ r_co[2] += cost * dcut[2];
+ }
+ break;
+ default:
+ r_co[0] = -(y - 1.0f / factor) * sint;
+ r_co[1] = (y - 1.0f / factor) * cost + 1.0f / factor;
+ r_co[2] = z;
+ {
+ r_co[0] += cost * dcut[0];
+ r_co[1] += sint * dcut[0];
+ r_co[2] += dcut[2];
+ }
}
}
@@ -142,16 +183,36 @@ static void simpleDeform_bend(const float factor, const float dcut[3], float r_c
static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
- static const float lock_axis[2] = {0.0f, 0.0f};
+ const float base_limit[2] = {0.0f, 0.0f};
int i;
- int limit_axis = 0;
float smd_limit[2], smd_factor;
SpaceTransform *transf = NULL, tmp_transf;
- void (*simpleDeform_callback)(const float factor, const float dcut[3], float co[3]) = NULL; /* Mode callback */
+ void (*simpleDeform_callback)(const float factor, const int axis, const float dcut[3], float co[3]) = NULL; /* Mode callback */
int vgroup;
MDeformVert *dvert;
+ /* This is historically the lock axis, _not_ the deform axis as the name would imply */
+ const int deform_axis = smd->deform_axis;
+ int lock_axis = smd->axis;
+ if (smd->mode == MOD_SIMPLEDEFORM_MODE_BEND) { /* Bend mode shouln't have any lock axis */
+ lock_axis = 0;
+ }
+ else {
+ /* Don't lock axis if it is the chosen deform axis, as this flattens
+ * the geometry */
+ if (deform_axis == 0) {
+ lock_axis &= ~MOD_SIMPLEDEFORM_LOCK_AXIS_X;
+ }
+ if (deform_axis == 1) {
+ lock_axis &= ~MOD_SIMPLEDEFORM_LOCK_AXIS_Y;
+ }
+ if (deform_axis == 2) {
+ lock_axis &= ~MOD_SIMPLEDEFORM_LOCK_AXIS_Z;
+ }
+ }
+
+
/* Safe-check */
if (smd->origin == ob) smd->origin = NULL; /* No self references */
@@ -166,11 +227,21 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object
BLI_SPACE_TRANSFORM_SETUP(transf, ob, smd->origin);
}
- /* Setup vars,
- * Bend limits on X.. all other modes limit on Z */
- limit_axis = (smd->mode == MOD_SIMPLEDEFORM_MODE_BEND) ? 0 : 2;
-
/* Update limits if needed */
+ int limit_axis = deform_axis;
+ if (smd->mode == MOD_SIMPLEDEFORM_MODE_BEND) {
+ /* Bend is a special case. */
+ switch (deform_axis) {
+ case 0:
+ ATTR_FALLTHROUGH;
+ case 1:
+ limit_axis = 2;
+ break;
+ default:
+ limit_axis = 0;
+ }
+ }
+
{
float lower = FLT_MAX;
float upper = -FLT_MAX;
@@ -212,6 +283,7 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object
modifier_get_vgroup(ob, dm, smd->vgroup_name, &dvert, &vgroup);
const bool invert_vgroup = (smd->flag & MOD_SIMPLEDEFORM_FLAG_INVERT_VGROUP) != 0;
+ const uint *axis_map = axis_map_table[(smd->mode != MOD_SIMPLEDEFORM_MODE_BEND) ? deform_axis : 2];
for (i = 0; i < numVerts; i++) {
float weight = defvert_array_find_weight_safe(dvert, i, vgroup);
@@ -229,14 +301,26 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object
copy_v3_v3(co, vertexCos[i]);
- /* Apply axis limits */
- if (smd->mode != MOD_SIMPLEDEFORM_MODE_BEND) { /* Bend mode shoulnt have any lock axis */
- if (smd->axis & MOD_SIMPLEDEFORM_LOCK_AXIS_X) axis_limit(0, lock_axis, co, dcut);
- if (smd->axis & MOD_SIMPLEDEFORM_LOCK_AXIS_Y) axis_limit(1, lock_axis, co, dcut);
+ /* Apply axis limits, and axis mappings */
+ if (lock_axis & MOD_SIMPLEDEFORM_LOCK_AXIS_X) {
+ axis_limit(0, base_limit, co, dcut);
+ }
+ if (lock_axis & MOD_SIMPLEDEFORM_LOCK_AXIS_Y) {
+ axis_limit(1, base_limit, co, dcut);
+ }
+ if (lock_axis & MOD_SIMPLEDEFORM_LOCK_AXIS_Z) {
+ axis_limit(2, base_limit, co, dcut);
}
axis_limit(limit_axis, smd_limit, co, dcut);
- simpleDeform_callback(smd_factor, dcut, co); /* apply deform */
+ /* apply the deform to a mapped copy of the vertex, and then re-map it back. */
+ float co_remap[3];
+ float dcut_remap[3];
+ copy_v3_v3_map(co_remap, co, axis_map);
+ copy_v3_v3_map(dcut_remap, dcut, axis_map);
+ simpleDeform_callback(smd_factor, deform_axis, dcut_remap, co_remap); /* apply deform */
+ copy_v3_v3_unmap(co, co_remap, axis_map);
+
interp_v3_v3v3(vertexCos[i], vertexCos[i], co, weight); /* Use vertex weight has coef of linear interpolation */
if (transf) {
@@ -254,6 +338,7 @@ static void initData(ModifierData *md)
smd->mode = MOD_SIMPLEDEFORM_MODE_TWIST;
smd->axis = 0;
+ smd->deform_axis = 0;
smd->origin = NULL;
smd->factor = DEG2RADF(45.0f);
diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c
index 9d1c6913c1c..97afe6d5e87 100644
--- a/source/blender/modifiers/intern/MOD_skin.c
+++ b/source/blender/modifiers/intern/MOD_skin.c
@@ -419,7 +419,7 @@ static Frame **collect_hull_frames(int v, SkinNode *frames,
int nbr, i;
(*tothullframe) = emap[v].count;
- hull_frames = MEM_callocN(sizeof(Frame *) * (*tothullframe),
+ hull_frames = MEM_calloc_arrayN((*tothullframe), sizeof(Frame *),
"hull_from_frames.hull_frames");
i = 0;
for (nbr = 0; nbr < emap[v].count; nbr++) {
@@ -600,7 +600,7 @@ static SkinNode *build_frames(const MVert *mvert, int totvert,
SkinNode *skin_nodes;
int v;
- skin_nodes = MEM_callocN(sizeof(SkinNode) * totvert, "build_frames.skin_nodes");
+ skin_nodes = MEM_calloc_arrayN(totvert, sizeof(SkinNode), "build_frames.skin_nodes");
for (v = 0; v < totvert; v++) {
if (emap[v].count <= 1)
@@ -722,7 +722,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(totedge, "build_edge_mats.visited_e");
- emat = MEM_callocN(sizeof(EMat) * totedge, "build_edge_mats.emat");
+ emat = MEM_calloc_arrayN(totedge, sizeof(EMat), "build_edge_mats.emat");
/* Edge matrices are built from the root nodes, add all roots with
* children to the stack */
@@ -836,14 +836,14 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig)
totorigedge = orig->getNumEdges(orig);
/* Get degree of all vertices */
- degree = MEM_callocN(sizeof(int) * totorigvert, "degree");
+ degree = MEM_calloc_arrayN(totorigvert, sizeof(int), "degree");
for (i = 0; i < totorigedge; i++) {
degree[origedge[i].v1]++;
degree[origedge[i].v2]++;
}
/* Per edge, store how many subdivisions are needed */
- edge_subd = MEM_callocN(sizeof(int) * totorigedge, "edge_subd");
+ edge_subd = MEM_calloc_arrayN(totorigedge, sizeof(int), "edge_subd");
for (i = 0, totsubd = 0; i < totorigedge; i++) {
edge_subd[i] += calc_edge_subdivisions(origvert, orignode,
&origedge[i], degree);
@@ -882,7 +882,7 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig)
if (origdvert) {
const MDeformVert *dv1 = &origdvert[e->v1];
const MDeformVert *dv2 = &origdvert[e->v2];
- vgroups = MEM_callocN(sizeof(*vgroups) * dv1->totweight, "vgroup");
+ vgroups = MEM_calloc_arrayN(dv1->totweight, sizeof(*vgroups), "vgroup");
/* Only want vertex groups used by both vertices */
for (j = 0; j < dv1->totweight; j++) {
diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c
index be55030e18a..91c724cd1c9 100644
--- a/source/blender/modifiers/intern/MOD_smooth.c
+++ b/source/blender/modifiers/intern/MOD_smooth.c
@@ -102,10 +102,10 @@ static void smoothModifier_do(
unsigned char *uctmp;
float *ftmp, fac, facm;
- ftmp = (float *)MEM_callocN(3 * sizeof(float) * numVerts,
+ ftmp = (float *)MEM_calloc_arrayN(numVerts, 3 * sizeof(float),
"smoothmodifier_f");
if (!ftmp) return;
- uctmp = (unsigned char *)MEM_callocN(sizeof(unsigned char) * numVerts,
+ uctmp = (unsigned char *)MEM_calloc_arrayN(numVerts, sizeof(unsigned char),
"smoothmodifier_uc");
if (!uctmp) {
if (ftmp) MEM_freeN(ftmp);
diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c
index 14b29855728..5635d37f100 100644
--- a/source/blender/modifiers/intern/MOD_solidify.c
+++ b/source/blender/modifiers/intern/MOD_solidify.c
@@ -101,7 +101,7 @@ static void dm_calc_normal(DerivedMesh *dm, float (*face_nors)[3], float (*r_ver
mp = mpoly;
{
- EdgeFaceRef *edge_ref_array = MEM_callocN(sizeof(EdgeFaceRef) * (size_t)numEdges, "Edge Connectivity");
+ EdgeFaceRef *edge_ref_array = MEM_calloc_arrayN((size_t)numEdges, sizeof(EdgeFaceRef), "Edge Connectivity");
EdgeFaceRef *edge_ref;
float edge_normal[3];
@@ -235,7 +235,7 @@ static DerivedMesh *applyModifier(
unsigned int *new_edge_arr = NULL;
STACK_DECLARE(new_edge_arr);
- unsigned int *old_vert_arr = MEM_callocN(sizeof(*old_vert_arr) * (size_t)numVerts, "old_vert_arr in solidify");
+ unsigned int *old_vert_arr = MEM_calloc_arrayN(numVerts, sizeof(*old_vert_arr), "old_vert_arr in solidify");
unsigned int *edge_users = NULL;
char *edge_order = NULL;
@@ -270,7 +270,7 @@ static DerivedMesh *applyModifier(
if (need_face_normals) {
/* calculate only face normals */
- face_nors = MEM_mallocN(sizeof(*face_nors) * (size_t)numFaces, __func__);
+ face_nors = MEM_malloc_arrayN(numFaces, sizeof(*face_nors), __func__);
BKE_mesh_calc_normals_poly(
orig_mvert, NULL, (int)numVerts,
orig_mloop, orig_mpoly,
@@ -289,11 +289,11 @@ static DerivedMesh *applyModifier(
#define INVALID_UNUSED ((unsigned int)-1)
#define INVALID_PAIR ((unsigned int)-2)
- new_vert_arr = MEM_mallocN(sizeof(*new_vert_arr) * (size_t)(numVerts * 2), __func__);
- new_edge_arr = MEM_mallocN(sizeof(*new_edge_arr) * (size_t)((numEdges * 2) + numVerts), __func__);
+ new_vert_arr = MEM_malloc_arrayN(numVerts, 2 * sizeof(*new_vert_arr), __func__);
+ new_edge_arr = MEM_malloc_arrayN(((numEdges * 2) + numVerts), sizeof(*new_edge_arr), __func__);
- edge_users = MEM_mallocN(sizeof(*edge_users) * (size_t)numEdges, "solid_mod edges");
- edge_order = MEM_mallocN(sizeof(*edge_order) * (size_t)numEdges, "solid_mod eorder");
+ edge_users = MEM_malloc_arrayN(numEdges, sizeof(*edge_users), "solid_mod edges");
+ edge_order = MEM_malloc_arrayN(numEdges, sizeof(*edge_order), "solid_mod eorder");
/* save doing 2 loops here... */
@@ -366,7 +366,7 @@ static DerivedMesh *applyModifier(
}
if (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) {
- vert_nors = MEM_callocN(sizeof(float) * (size_t)numVerts * 3, "mod_solid_vno_hq");
+ vert_nors = MEM_calloc_arrayN(numVerts, 3 * sizeof(float), "mod_solid_vno_hq");
dm_calc_normal(dm, face_nors, vert_nors);
}
@@ -517,7 +517,7 @@ static DerivedMesh *applyModifier(
if (do_clamp) {
unsigned int i;
- vert_lens = MEM_mallocN(sizeof(float) * numVerts, "vert_lens");
+ vert_lens = MEM_malloc_arrayN(numVerts, sizeof(float), "vert_lens");
copy_vn_fl(vert_lens, (int)numVerts, FLT_MAX);
for (i = 0; i < numEdges; i++) {
const float ed_len_sq = len_squared_v3v3(mvert[medge[i].v1].co, mvert[medge[i].v2].co);
@@ -596,13 +596,13 @@ static DerivedMesh *applyModifier(
const bool check_non_manifold = (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) != 0;
#endif
/* same as EM_solidify() in editmesh_lib.c */
- float *vert_angles = MEM_callocN(sizeof(float) * numVerts * 2, "mod_solid_pair"); /* 2 in 1 */
+ float *vert_angles = MEM_calloc_arrayN(numVerts, 2 * sizeof(float), "mod_solid_pair"); /* 2 in 1 */
float *vert_accum = vert_angles + numVerts;
unsigned int vidx;
unsigned int i;
if (vert_nors == NULL) {
- vert_nors = MEM_mallocN(sizeof(float) * numVerts * 3, "mod_solid_vno");
+ vert_nors = MEM_malloc_arrayN(numVerts, 3 * sizeof(float), "mod_solid_vno");
for (i = 0, mv = mvert; i < numVerts; i++, mv++) {
normal_short_to_float_v3(vert_nors[i], mv->no);
}
@@ -682,7 +682,7 @@ static DerivedMesh *applyModifier(
}
if (do_clamp) {
- float *vert_lens_sq = MEM_mallocN(sizeof(float) * numVerts, "vert_lens");
+ float *vert_lens_sq = MEM_malloc_arrayN(numVerts, sizeof(float), "vert_lens");
const float offset = fabsf(smd->offset) * smd->offset_clamp;
const float offset_sq = offset * offset;
copy_vn_fl(vert_lens_sq, (int)numVerts, FLT_MAX);
@@ -765,7 +765,7 @@ static DerivedMesh *applyModifier(
#ifdef SOLIDIFY_SIDE_NORMALS
const bool do_side_normals = !(result->dirty & DM_DIRTY_NORMALS);
/* annoying to allocate these since we only need the edge verts, */
- float (*edge_vert_nos)[3] = do_side_normals ? MEM_callocN(sizeof(float) * numVerts * 3, __func__) : NULL;
+ float (*edge_vert_nos)[3] = do_side_normals ? MEM_calloc_arrayN(numVerts, 3 * sizeof(float), __func__) : NULL;
float nor[3];
#endif
const unsigned char crease_rim = smd->crease_rim * 255.0f;
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c
index c408b4fbd63..bef35ccf1fe 100644
--- a/source/blender/modifiers/intern/MOD_surface.c
+++ b/source/blender/modifiers/intern/MOD_surface.c
@@ -130,8 +130,8 @@ static void deformVerts(ModifierData *md, const struct EvaluationContext *UNUSED
surmd->v = NULL;
}
- surmd->x = MEM_callocN(numverts * sizeof(MVert), "MVert");
- surmd->v = MEM_callocN(numverts * sizeof(MVert), "MVert");
+ surmd->x = MEM_calloc_arrayN(numverts, sizeof(MVert), "MVert");
+ surmd->v = MEM_calloc_arrayN(numverts, sizeof(MVert), "MVert");
surmd->numverts = numverts;
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c
index b623293ed5c..046a0ab27bf 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -314,11 +314,13 @@ BLI_INLINE int isPolyValid(const float coords[][2], const unsigned int nr)
copy_v2_v2(prev_co, coords[nr - 1]);
sub_v2_v2v2(prev_vec, prev_co, coords[nr - 2]);
+ normalize_v2(prev_vec);
for (int i = 0; i < nr; i++) {
sub_v2_v2v2(curr_vec, coords[i], prev_co);
- if (len_squared_v2(curr_vec) < FLT_EPSILON) {
+ const float curr_len = normalize_v2(curr_vec);
+ if (curr_len < FLT_EPSILON) {
return MOD_SDEF_BIND_RESULT_OVERLAP_ERR;
}
@@ -386,7 +388,7 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData * const data,
bwdata->numpoly = data->vert_edges[nearest].num / 2;
- bpoly = MEM_callocN(sizeof(*bpoly) * bwdata->numpoly, "SDefBindPoly");
+ bpoly = MEM_calloc_arrayN(bwdata->numpoly, sizeof(*bpoly), "SDefBindPoly");
if (bpoly == NULL) {
freeBindData(bwdata);
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
@@ -429,14 +431,14 @@ BLI_INLINE SDefBindWeightData *computeBindWeights(SDefBindCalcData * const data,
bpoly->numverts = poly->totloop;
bpoly->loopstart = poly->loopstart;
- bpoly->coords = MEM_mallocN(sizeof(*bpoly->coords) * poly->totloop, "SDefBindPolyCoords");
+ bpoly->coords = MEM_malloc_arrayN(poly->totloop, sizeof(*bpoly->coords), "SDefBindPolyCoords");
if (bpoly->coords == NULL) {
freeBindData(bwdata);
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return NULL;
}
- bpoly->coords_v2 = MEM_mallocN(sizeof(*bpoly->coords_v2) * poly->totloop, "SDefBindPolyCoords_v2");
+ bpoly->coords_v2 = MEM_malloc_arrayN(poly->totloop, sizeof(*bpoly->coords_v2), "SDefBindPolyCoords_v2");
if (bpoly->coords_v2 == NULL) {
freeBindData(bwdata);
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
@@ -734,7 +736,10 @@ BLI_INLINE float computeNormalDisplacement(const float point_co[3], const float
return normal_dist;
}
-static void bindVert(void *userdata, void *UNUSED(userdata_chunk), const int index, const int UNUSED(threadid))
+static void bindVert(
+ void *__restrict userdata,
+ const int index,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
SDefBindCalcData * const data = (SDefBindCalcData *)userdata;
float point_co[3];
@@ -760,7 +765,7 @@ static void bindVert(void *userdata, void *UNUSED(userdata_chunk), const int ind
return;
}
- sdvert->binds = MEM_callocN(sizeof(*sdvert->binds) * bwdata->numbinds, "SDefVertBindData");
+ sdvert->binds = MEM_calloc_arrayN(bwdata->numbinds, sizeof(*sdvert->binds), "SDefVertBindData");
if (sdvert->binds == NULL) {
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
sdvert->numbinds = 0;
@@ -782,13 +787,13 @@ static void bindVert(void *userdata, void *UNUSED(userdata_chunk), const int ind
sdbind->numverts = bpoly->numverts;
sdbind->mode = MOD_SDEF_MODE_NGON;
- sdbind->vert_weights = MEM_mallocN(sizeof(*sdbind->vert_weights) * bpoly->numverts, "SDefNgonVertWeights");
+ sdbind->vert_weights = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_weights), "SDefNgonVertWeights");
if (sdbind->vert_weights == NULL) {
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return;
}
- sdbind->vert_inds = MEM_mallocN(sizeof(*sdbind->vert_inds) * bpoly->numverts, "SDefNgonVertInds");
+ sdbind->vert_inds = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_inds), "SDefNgonVertInds");
if (sdbind->vert_inds == NULL) {
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return;
@@ -818,13 +823,13 @@ static void bindVert(void *userdata, void *UNUSED(userdata_chunk), const int ind
sdbind->numverts = bpoly->numverts;
sdbind->mode = MOD_SDEF_MODE_CENTROID;
- sdbind->vert_weights = MEM_mallocN(sizeof(*sdbind->vert_weights) * 3, "SDefCentVertWeights");
+ sdbind->vert_weights = MEM_malloc_arrayN(3, sizeof(*sdbind->vert_weights), "SDefCentVertWeights");
if (sdbind->vert_weights == NULL) {
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return;
}
- sdbind->vert_inds = MEM_mallocN(sizeof(*sdbind->vert_inds) * bpoly->numverts, "SDefCentVertInds");
+ sdbind->vert_inds = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_inds), "SDefCentVertInds");
if (sdbind->vert_inds == NULL) {
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return;
@@ -861,13 +866,13 @@ static void bindVert(void *userdata, void *UNUSED(userdata_chunk), const int ind
sdbind->numverts = bpoly->numverts;
sdbind->mode = MOD_SDEF_MODE_LOOPTRI;
- sdbind->vert_weights = MEM_mallocN(sizeof(*sdbind->vert_weights) * 3, "SDefTriVertWeights");
+ sdbind->vert_weights = MEM_malloc_arrayN(3, sizeof(*sdbind->vert_weights), "SDefTriVertWeights");
if (sdbind->vert_weights == NULL) {
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return;
}
- sdbind->vert_inds = MEM_mallocN(sizeof(*sdbind->vert_inds) * bpoly->numverts, "SDefTriVertInds");
+ sdbind->vert_inds = MEM_malloc_arrayN(bpoly->numverts, sizeof(*sdbind->vert_inds), "SDefTriVertInds");
if (sdbind->vert_inds == NULL) {
data->success = MOD_SDEF_BIND_RESULT_MEM_ERR;
return;
@@ -918,20 +923,20 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos)
SDefAdjacency *adj_array;
SDefEdgePolys *edge_polys;
- vert_edges = MEM_callocN(sizeof(*vert_edges) * tnumverts, "SDefVertEdgeMap");
+ vert_edges = MEM_calloc_arrayN(tnumverts, sizeof(*vert_edges), "SDefVertEdgeMap");
if (vert_edges == NULL) {
modifier_setError((ModifierData *)smd, "Out of memory");
return false;
}
- adj_array = MEM_mallocN(sizeof(*adj_array) * tnumedges * 2, "SDefVertEdge");
+ adj_array = MEM_malloc_arrayN(tnumedges, 2 * sizeof(*adj_array), "SDefVertEdge");
if (adj_array == NULL) {
modifier_setError((ModifierData *)smd, "Out of memory");
MEM_freeN(vert_edges);
return false;
}
- edge_polys = MEM_callocN(sizeof(*edge_polys) * tnumedges, "SDefEdgeFaceMap");
+ edge_polys = MEM_calloc_arrayN(tnumedges, sizeof(*edge_polys), "SDefEdgeFaceMap");
if (edge_polys == NULL) {
modifier_setError((ModifierData *)smd, "Out of memory");
MEM_freeN(vert_edges);
@@ -939,7 +944,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos)
return false;
}
- smd->verts = MEM_mallocN(sizeof(*smd->verts) * numverts, "SDefBindVerts");
+ smd->verts = MEM_malloc_arrayN(numverts, sizeof(*smd->verts), "SDefBindVerts");
if (smd->verts == NULL) {
modifier_setError((ModifierData *)smd, "Out of memory");
freeAdjacencyMap(vert_edges, adj_array, edge_polys);
@@ -976,7 +981,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos)
.medge = medge,
.mloop = mloop,
.looptri = tdm->getLoopTriArray(tdm),
- .targetCos = MEM_mallocN(sizeof(float[3]) * tnumverts, "SDefTargetBindVertArray"),
+ .targetCos = MEM_malloc_arrayN(tnumverts, sizeof(float[3]), "SDefTargetBindVertArray"),
.bind_verts = smd->verts,
.vertexCos = vertexCos,
.falloff = smd->falloff,
@@ -994,8 +999,13 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos)
mul_v3_m4v3(data.targetCos[i], smd->mat, mvert[i].co);
}
- BLI_task_parallel_range_ex(0, numverts, &data, NULL, 0, bindVert,
- numverts > 10000, false);
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = (numverts > 10000);
+ BLI_task_parallel_range(0, numverts,
+ &data,
+ bindVert,
+ &settings);
MEM_freeN(data.targetCos);
@@ -1030,7 +1040,10 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, float (*vertexCos)
return data.success == 1;
}
-static void deformVert(void *userdata, void *UNUSED(userdata_chunk), const int index, const int UNUSED(threadid))
+static void deformVert(
+ void *__restrict userdata,
+ const int index,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
const SDefDeformData * const data = (SDefDeformData *)userdata;
const SDefBind *sdbind = data->bind_verts[index].binds;
@@ -1041,7 +1054,7 @@ static void deformVert(void *userdata, void *UNUSED(userdata_chunk), const int i
for (int j = 0; j < data->bind_verts[index].numbinds; j++, sdbind++) {
/* Mode-generic operations (allocate poly coordinates) */
- float (*coords)[3] = MEM_mallocN(sizeof(*coords) * sdbind->numverts, "SDefDoPolyCoords");
+ float (*coords)[3] = MEM_malloc_arrayN(sdbind->numverts, sizeof(*coords), "SDefDoPolyCoords");
for (int k = 0; k < sdbind->numverts; k++) {
copy_v3_v3(coords[k], data->targetCos[sdbind->vert_inds[k]]);
@@ -1139,7 +1152,7 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
/* Actual vertex location update starts here */
SDefDeformData data = {
.bind_verts = smd->verts,
- .targetCos = MEM_mallocN(sizeof(float[3]) * tnumverts, "SDefTargetVertArray"),
+ .targetCos = MEM_malloc_arrayN(tnumverts, sizeof(float[3]), "SDefTargetVertArray"),
.vertexCos = vertexCos,
};
@@ -1151,8 +1164,13 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
mul_v3_m4v3(data.targetCos[i], smd->mat, mvert[i].co);
}
- BLI_task_parallel_range_ex(0, numverts, &data, NULL, 0, deformVert,
- numverts > 10000, false);
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = (numverts > 10000);
+ BLI_task_parallel_range(0, numverts,
+ &data,
+ deformVert,
+ &settings);
if (tdm_vert_alloc) {
MEM_freeN((void *)mvert);
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index ded1f0b77e6..5b19bcf4817 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -87,7 +87,7 @@ void get_texture_coords(MappingInfoModifierData *dmd, Object *ob,
MPoly *mpoly = dm->getPolyArray(dm);
MPoly *mp;
MLoop *mloop = dm->getLoopArray(dm);
- char *done = MEM_callocN(sizeof(*done) * numVerts,
+ char *done = MEM_calloc_arrayN(numVerts, sizeof(*done),
"get_texture_coords done");
int numPolys = dm->getNumPolys(dm);
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c
index c9a842621b6..498dd2486f4 100644
--- a/source/blender/modifiers/intern/MOD_uvproject.c
+++ b/source/blender/modifiers/intern/MOD_uvproject.c
@@ -226,7 +226,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
numVerts = dm->getNumVerts(dm);
- coords = MEM_mallocN(sizeof(*coords) * numVerts,
+ coords = MEM_malloc_arrayN(numVerts, sizeof(*coords),
"uvprojectModifier_do coords");
dm->getVertCos(dm, coords);
diff --git a/source/blender/modifiers/intern/MOD_uvwarp.c b/source/blender/modifiers/intern/MOD_uvwarp.c
index 3773eed26dc..32974d68d9d 100644
--- a/source/blender/modifiers/intern/MOD_uvwarp.c
+++ b/source/blender/modifiers/intern/MOD_uvwarp.c
@@ -110,7 +110,10 @@ typedef struct UVWarpData {
int axis_v;
} UVWarpData;
-static void uv_warp_compute(void *userdata, const int i)
+static void uv_warp_compute(
+ void *__restrict userdata,
+ const int i,
+ const ParallelRangeTLS *__restrict UNUSED(tls))
{
const UVWarpData *data = userdata;
@@ -208,7 +211,13 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
UVWarpData data = {.mpoly = mpoly, .mloop = mloop, .mloopuv = mloopuv,
.dvert = dvert, .defgrp_index = defgrp_index,
.warp_mat = warp_mat, .axis_u = axis_u, .axis_v = axis_v};
- BLI_task_parallel_range(0, numPolys, &data, uv_warp_compute, numPolys > 1000);
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = (numPolys > 1000);
+ BLI_task_parallel_range(0, numPolys,
+ &data,
+ uv_warp_compute,
+ &settings);
dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c
index 566ee5b2d24..be0be2671b9 100644
--- a/source/blender/modifiers/intern/MOD_warp.c
+++ b/source/blender/modifiers/intern/MOD_warp.c
@@ -214,7 +214,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
weight = strength;
if (wmd->texture) {
- tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts, "warpModifier_do tex_co");
+ tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co), "warpModifier_do tex_co");
get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts);
modifier_init_texture(wmd->modifier.scene, wmd->texture);
diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c
index c408f244afd..1271cccd719 100644
--- a/source/blender/modifiers/intern/MOD_wave.c
+++ b/source/blender/modifiers/intern/MOD_wave.c
@@ -206,7 +206,7 @@ static void waveModifier_do(WaveModifierData *md,
}
if (wmd->texture) {
- tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts,
+ tex_co = MEM_malloc_arrayN(numVerts, sizeof(*tex_co),
"waveModifier_do tex_co");
get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts);
diff --git a/source/blender/modifiers/intern/MOD_weightvg_util.c b/source/blender/modifiers/intern/MOD_weightvg_util.c
index da7230ed5af..416f2964d6e 100644
--- a/source/blender/modifiers/intern/MOD_weightvg_util.c
+++ b/source/blender/modifiers/intern/MOD_weightvg_util.c
@@ -143,9 +143,9 @@ void weightvg_do_mask(int num, const int *indices, float *org_w, const float *ne
t_map.map_object = tex_map_object;
BLI_strncpy(t_map.uvlayer_name, tex_uvlayer_name, sizeof(t_map.uvlayer_name));
t_map.texmapping = tex_mapping;
- v_co = MEM_mallocN(sizeof(*v_co) * numVerts, "WeightVG Modifier, TEX mode, v_co");
+ v_co = MEM_malloc_arrayN(numVerts, sizeof(*v_co), "WeightVG Modifier, TEX mode, v_co");
dm->getVertCos(dm, v_co);
- tex_co = MEM_callocN(sizeof(*tex_co) * numVerts, "WeightVG Modifier, TEX mode, tex_co");
+ tex_co = MEM_calloc_arrayN(numVerts, sizeof(*tex_co), "WeightVG Modifier, TEX mode, tex_co");
get_texture_coords(&t_map, ob, dm, v_co, tex_co, num);
MEM_freeN(v_co);
diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c
index dbdaafaa5a7..9aa4bad1707 100644
--- a/source/blender/modifiers/intern/MOD_weightvgedit.c
+++ b/source/blender/modifiers/intern/MOD_weightvgedit.c
@@ -213,9 +213,9 @@ static DerivedMesh *applyModifier(ModifierData *md,
}
/* Get org weights, assuming 0.0 for vertices not in given vgroup. */
- org_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, org_w");
- new_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, new_w");
- dw = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGEdit Modifier, dw");
+ org_w = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGEdit Modifier, org_w");
+ new_w = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGEdit Modifier, new_w");
+ dw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGEdit Modifier, dw");
for (i = 0; i < numVerts; i++) {
dw[i] = defvert_find_index(&dvert[i], defgrp_index);
if (dw[i]) {
diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c
index 5f30d4ca72a..ab1264cc9a0 100644
--- a/source/blender/modifiers/intern/MOD_weightvgmix.c
+++ b/source/blender/modifiers/intern/MOD_weightvgmix.c
@@ -265,9 +265,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
return dm;
}
/* Find out which vertices to work on. */
- tidx = MEM_mallocN(sizeof(int) * numVerts, "WeightVGMix Modifier, tidx");
- tdw1 = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGMix Modifier, tdw1");
- tdw2 = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGMix Modifier, tdw2");
+ tidx = MEM_malloc_arrayN(numVerts, sizeof(int), "WeightVGMix Modifier, tidx");
+ tdw1 = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGMix Modifier, tdw1");
+ tdw2 = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGMix Modifier, tdw2");
switch (wmd->mix_set) {
case MOD_WVG_SET_A:
/* All vertices in first vgroup. */
@@ -333,12 +333,12 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
return dm;
}
if (numIdx != -1) {
- indices = MEM_mallocN(sizeof(int) * numIdx, "WeightVGMix Modifier, indices");
+ indices = MEM_malloc_arrayN(numIdx, sizeof(int), "WeightVGMix Modifier, indices");
memcpy(indices, tidx, sizeof(int) * numIdx);
- dw1 = MEM_mallocN(sizeof(MDeformWeight *) * numIdx, "WeightVGMix Modifier, dw1");
+ dw1 = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGMix Modifier, dw1");
memcpy(dw1, tdw1, sizeof(MDeformWeight *) * numIdx);
MEM_freeN(tdw1);
- dw2 = MEM_mallocN(sizeof(MDeformWeight *) * numIdx, "WeightVGMix Modifier, dw2");
+ dw2 = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGMix Modifier, dw2");
memcpy(dw2, tdw2, sizeof(MDeformWeight *) * numIdx);
MEM_freeN(tdw2);
}
@@ -351,8 +351,8 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
}
MEM_freeN(tidx);
- org_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGMix Modifier, org_w");
- new_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGMix Modifier, new_w");
+ org_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGMix Modifier, org_w");
+ new_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGMix Modifier, new_w");
/* Mix weights. */
for (i = 0; i < numIdx; i++) {
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index c8bbbfe44b2..8a5d0f833a8 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -90,10 +90,13 @@ typedef struct Vert2GeomDataChunk {
/**
* Callback used by BLI_task 'for loop' helper.
*/
-static void vert2geom_task_cb_ex(void *userdata, void *userdata_chunk, const int iter, const int UNUSED(thread_id))
+static void vert2geom_task_cb_ex(
+ void *__restrict userdata,
+ const int iter,
+ const ParallelRangeTLS *__restrict tls)
{
Vert2GeomData *data = userdata;
- Vert2GeomDataChunk *data_chunk = userdata_chunk;
+ Vert2GeomDataChunk *data_chunk = tls->userdata_chunk;
float tmp_co[3];
int i;
@@ -177,9 +180,16 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3],
data.dist[1] = dist_e;
data.dist[2] = dist_f;
- BLI_task_parallel_range_ex(
- 0, numVerts, &data, &data_chunk, sizeof(data_chunk), vert2geom_task_cb_ex,
- numVerts > 10000, false);
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.use_threading = (numVerts > 10000);
+ settings.userdata_chunk = &data_chunk;
+ settings.userdata_chunk_size = sizeof(data_chunk);
+ BLI_task_parallel_range(
+ 0, numVerts,
+ &data,
+ vert2geom_task_cb_ex,
+ &settings);
if (dist_v)
free_bvhtree_from_mesh(&treeData_v);
@@ -423,9 +433,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
/* Find out which vertices to work on (all vertices in vgroup), and get their relevant weight.
*/
- tidx = MEM_mallocN(sizeof(int) * numVerts, "WeightVGProximity Modifier, tidx");
- tw = MEM_mallocN(sizeof(float) * numVerts, "WeightVGProximity Modifier, tw");
- tdw = MEM_mallocN(sizeof(MDeformWeight *) * numVerts, "WeightVGProximity Modifier, tdw");
+ tidx = MEM_malloc_arrayN(numVerts, sizeof(int), "WeightVGProximity Modifier, tidx");
+ tw = MEM_malloc_arrayN(numVerts, sizeof(float), "WeightVGProximity Modifier, tw");
+ tdw = MEM_malloc_arrayN(numVerts, sizeof(MDeformWeight *), "WeightVGProximity Modifier, tdw");
for (i = 0; i < numVerts; i++) {
MDeformWeight *_dw = defvert_find_index(&dvert[i], defgrp_index);
if (_dw) {
@@ -442,11 +452,11 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
return dm;
}
if (numIdx != numVerts) {
- indices = MEM_mallocN(sizeof(int) * numIdx, "WeightVGProximity Modifier, indices");
+ indices = MEM_malloc_arrayN(numIdx, sizeof(int), "WeightVGProximity Modifier, indices");
memcpy(indices, tidx, sizeof(int) * numIdx);
- org_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGProximity Modifier, org_w");
+ org_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGProximity Modifier, org_w");
memcpy(org_w, tw, sizeof(float) * numIdx);
- dw = MEM_mallocN(sizeof(MDeformWeight *) * numIdx, "WeightVGProximity Modifier, dw");
+ dw = MEM_malloc_arrayN(numIdx, sizeof(MDeformWeight *), "WeightVGProximity Modifier, dw");
memcpy(dw, tdw, sizeof(MDeformWeight *) * numIdx);
MEM_freeN(tw);
MEM_freeN(tdw);
@@ -455,16 +465,16 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
org_w = tw;
dw = tdw;
}
- new_w = MEM_mallocN(sizeof(float) * numIdx, "WeightVGProximity Modifier, new_w");
+ new_w = MEM_malloc_arrayN(numIdx, sizeof(float), "WeightVGProximity Modifier, new_w");
MEM_freeN(tidx);
/* Get our vertex coordinates. */
- v_cos = MEM_mallocN(sizeof(float[3]) * numIdx, "WeightVGProximity Modifier, v_cos");
+ v_cos = MEM_malloc_arrayN(numIdx, sizeof(float[3]), "WeightVGProximity Modifier, v_cos");
if (numIdx != numVerts) {
/* XXX In some situations, this code can be up to about 50 times more performant
* than simply using getVertCo for each affected vertex...
*/
- float (*tv_cos)[3] = MEM_mallocN(sizeof(float[3]) * numVerts, "WeightVGProximity Modifier, tv_cos");
+ float (*tv_cos)[3] = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "WeightVGProximity Modifier, tv_cos");
dm->getVertCos(dm, tv_cos);
for (i = 0; i < numIdx; i++)
copy_v3_v3(v_cos[i], tv_cos[indices[i]]);
@@ -503,9 +513,9 @@ static DerivedMesh *applyModifier(ModifierData *md, const struct EvaluationConte
/* We must check that we do have a valid target_dm! */
if (target_dm) {
SpaceTransform loc2trgt;
- float *dists_v = use_trgt_verts ? MEM_mallocN(sizeof(float) * numIdx, "dists_v") : NULL;
- float *dists_e = use_trgt_edges ? MEM_mallocN(sizeof(float) * numIdx, "dists_e") : NULL;
- float *dists_f = use_trgt_faces ? MEM_mallocN(sizeof(float) * numIdx, "dists_f") : NULL;
+ float *dists_v = use_trgt_verts ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_v") : NULL;
+ float *dists_e = use_trgt_edges ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_e") : NULL;
+ float *dists_f = use_trgt_faces ? MEM_malloc_arrayN(numIdx, sizeof(float), "dists_f") : NULL;
BLI_SPACE_TRANSFORM_SETUP(&loc2trgt, ob, obr);
get_vert2geom_distance(numIdx, v_cos, dists_v, dists_e, dists_f,
diff --git a/source/blender/modifiers/intern/MOD_wireframe.c b/source/blender/modifiers/intern/MOD_wireframe.c
index 6fc1907ba0a..3cb35286114 100644
--- a/source/blender/modifiers/intern/MOD_wireframe.c
+++ b/source/blender/modifiers/intern/MOD_wireframe.c
@@ -52,11 +52,6 @@ static void copyData(ModifierData *md, ModifierData *target)
modifier_copyData_generic(md, target);
}
-static bool isDisabled(ModifierData *UNUSED(md), int UNUSED(useRenderParams))
-{
- return false;
-}
-
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
{
WireframeModifierData *wmd = (WireframeModifierData *)md;
@@ -132,8 +127,8 @@ ModifierTypeInfo modifierType_Wireframe = {
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
- /* isDisabled */ isDisabled,
- /* updateDepsgraph */ NULL,
+ /* isDisabled */ NULL,
+ /* updateDepgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
/* foreachObjectLink */ NULL,