[Bf-blender-cvs] [ff6b2490468] master: Simplify Array modifier 'relative offset' handling.

Bastien Montagne noreply at git.blender.org
Thu Jun 8 09:18:56 CEST 2017


Commit: ff6b2490468ed7103685d5c06d73393f361a7950
Author: Bastien Montagne
Date:   Thu Jun 8 09:17:08 2017 +0200
Branches: master
https://developer.blender.org/rBff6b2490468ed7103685d5c06d73393f361a7950

Simplify Array modifier 'relative offset' handling.

Was looping three times over the source mesh's vertices to get min/max
along all three axes... Nothing critical, but still!

===================================================================

M	source/blender/modifiers/intern/MOD_array.c

===================================================================

diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index 2b739dc0093..5731ceb4382 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -50,6 +50,7 @@
 #include "BKE_curve.h"
 #include "BKE_library_query.h"
 #include "BKE_modifier.h"
+#include "BKE_mesh.h"
 
 #include "MOD_util.h"
 
@@ -157,25 +158,6 @@ static void updateDepsgraph(ModifierData *md,
 	}
 }
 
-static float vertarray_size(const MVert *mvert, int numVerts, int axis)
-{
-	int i;
-	float min_co, max_co;
-
-	/* if there are no vertices, width is 0 */
-	if (numVerts == 0) return 0;
-
-	/* find the minimum and maximum coordinates on the desired axis */
-	min_co = max_co = mvert->co[axis];
-	mvert++;
-	for (i = 1; i < numVerts; ++i, ++mvert) {
-		if (mvert->co[axis] < min_co) min_co = mvert->co[axis];
-		if (mvert->co[axis] > max_co) max_co = mvert->co[axis];
-	}
-
-	return max_co - min_co;
-}
-
 BLI_INLINE float sum_v3(const float v[3])
 {
 	return v[0] + v[1] + v[2];
@@ -472,12 +454,22 @@ static DerivedMesh *arrayModifier_doArray(
 	unit_m4(offset);
 	src_mvert = dm->getVertArray(dm);
 
-	if (amd->offset_type & MOD_ARR_OFF_CONST)
-		add_v3_v3v3(offset[3], offset[3], amd->offset);
+	if (amd->offset_type & MOD_ARR_OFF_CONST) {
+		add_v3_v3(offset[3], amd->offset);
+	}
 
 	if (amd->offset_type & MOD_ARR_OFF_RELATIVE) {
-		for (j = 0; j < 3; j++)
-			offset[3][j] += amd->scale[j] * vertarray_size(src_mvert, chunk_nverts, j);
+		float min[3], max[3];
+		const MVert *src_mv;
+
+		INIT_MINMAX(min, max);
+		for (src_mv = src_mvert, j = chunk_nverts; j--; src_mv++) {
+			minmax_v3v3_v3(min, max, src_mv->co);
+		}
+
+		for (j = 3; j--; ) {
+			offset[3][j] += amd->scale[j] * (max[j] - min[j]);
+		}
 	}
 
 	if (use_offset_ob) {




More information about the Bf-blender-cvs mailing list