[Bf-blender-cvs] [9ac618a] master: Sculpt: smooth brush, exclude self from average

Campbell Barton noreply at git.blender.org
Sun Apr 19 08:06:16 CEST 2015


Commit: 9ac618a90eddf90071a1d94fa2ae076ce239c785
Author: Campbell Barton
Date:   Sun Apr 19 14:21:23 2015 +1000
Branches: master
https://developer.blender.org/rB9ac618a90eddf90071a1d94fa2ae076ce239c785

Sculpt: smooth brush, exclude self from average

Was including the vertices own location when accumulating.

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

M	source/blender/blenkernel/BKE_mesh.h
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 05c2041..c0d8902 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -69,12 +69,13 @@ extern "C" {
 
 struct BMesh *BKE_mesh_to_bmesh(struct Mesh *me, struct Object *ob);
 
-int poly_find_loop_from_vert(const struct MPoly *poly,
-                             const struct MLoop *loopstart,
-                             unsigned vert);
-
-int poly_get_adj_loops_from_vert(unsigned r_adj[3], const struct MPoly *poly,
-                                 const struct MLoop *mloop, unsigned vert);
+int poly_find_loop_from_vert(
+        const struct MPoly *poly,
+        const struct MLoop *loopstart,
+        unsigned vert);
+int poly_get_adj_loops_from_vert(
+        unsigned r_adj[2], const struct MPoly *poly,
+        const struct MLoop *mloop, unsigned vert);
 
 int BKE_mesh_edge_other_vert(const struct MEdge *e, int v);
 
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 840ef47..eec2b10 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1821,8 +1821,9 @@ float (*BKE_mesh_vertexCos_get(const Mesh *me, int *r_numVerts))[3]
  * Find the index of the loop in 'poly' which references vertex,
  * returns -1 if not found
  */
-int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart,
-                             unsigned vert)
+int poly_find_loop_from_vert(
+        const MPoly *poly, const MLoop *loopstart,
+        unsigned vert)
 {
 	int j;
 	for (j = 0; j < poly->totloop; j++, loopstart++) {
@@ -1838,20 +1839,22 @@ int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart,
  * vertex. Returns the index of the loop matching vertex, or -1 if the
  * vertex is not in \a poly
  */
-int poly_get_adj_loops_from_vert(unsigned r_adj[3], const MPoly *poly,
-                                 const MLoop *mloop, unsigned vert)
+int poly_get_adj_loops_from_vert(
+        unsigned r_adj[2], const MPoly *poly,
+        const MLoop *mloop, unsigned vert)
 {
 	int corner = poly_find_loop_from_vert(poly,
 	                                      &mloop[poly->loopstart],
 	                                      vert);
 		
 	if (corner != -1) {
+#if 0	/* unused - this loop */
 		const MLoop *ml = &mloop[poly->loopstart + corner];
+#endif
 
 		/* vertex was found */
 		r_adj[0] = ME_POLY_LOOP_PREV(mloop, poly, corner)->v;
-		r_adj[1] = ml->v;
-		r_adj[2] = ME_POLY_LOOP_NEXT(mloop, poly, corner)->v;
+		r_adj[1] = ME_POLY_LOOP_NEXT(mloop, poly, corner)->v;
 	}
 
 	return corner;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 95eddbf..73a9abe 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -1177,12 +1177,11 @@ static void neighbor_average(SculptSession *ss, float avg[3], unsigned vert)
 
 		for (i = 0; i < vert_map->count; i++) {
 			const MPoly *p = &ss->mpoly[vert_map->indices[i]];
-			unsigned f_adj_v[3];
+			unsigned f_adj_v[2];
 
 			if (poly_get_adj_loops_from_vert(f_adj_v, p, ss->mloop, vert) != -1) {
 				int j;
-			
-				for (j = 0; j < 3; j++) {
+				for (j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) {
 					if (vert_map->count != 2 || ss->pmap[f_adj_v[j]].count <= 2) {
 						add_v3_v3(avg, deform_co ? deform_co[f_adj_v[j]] :
 						          mvert[f_adj_v[j]].co);
@@ -1213,12 +1212,11 @@ static float neighbor_average_mask(SculptSession *ss, unsigned vert)
 
 	for (i = 0; i < ss->pmap[vert].count; i++) {
 		const MPoly *p = &ss->mpoly[ss->pmap[vert].indices[i]];
-		unsigned f_adj_v[3];
+		unsigned f_adj_v[2];
 
 		if (poly_get_adj_loops_from_vert(f_adj_v, p, ss->mloop, vert) != -1) {
 			int j;
-			
-			for (j = 0; j < 3; j++) {
+			for (j = 0; j < ARRAY_SIZE(f_adj_v); j += 1) {
 				avg += vmask[f_adj_v[j]];
 				total++;
 			}
@@ -1245,9 +1243,9 @@ static void bmesh_neighbor_average(float avg[3], BMVert *v)
 		int i, total = 0;
 
 		BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
-			BMVert *adj_v[3] = {l->prev->v, v, l->next->v};
+			BMVert *adj_v[2] = {l->prev->v, l->next->v};
 
-			for (i = 0; i < 3; i++) {
+			for (i = 0; i < ARRAY_SIZE(adj_v); i++) {
 				if (vfcount != 2 || BM_vert_face_count(adj_v[i]) <= 2) {
 					add_v3_v3(avg, adj_v[i]->co);
 					total++;
@@ -1273,9 +1271,10 @@ static float bmesh_neighbor_average_mask(BMesh *bm, BMVert *v)
 	int i, total = 0;
 
 	BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
-		BMVert *adj_v[3] = {l->prev->v, v, l->next->v};
+		/* skip this vertex */
+		BMVert *adj_v[2] = {l->prev->v, l->next->v};
 
-		for (i = 0; i < 3; i++) {
+		for (i = 0; i < ARRAY_SIZE(adj_v); i++) {
 			BMVert *v2 = adj_v[i];
 			float *vmask = CustomData_bmesh_get(&bm->vdata,
 			                                    v2->head.data,




More information about the Bf-blender-cvs mailing list