[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56168] trunk/blender/source/blender: Fix #34818: Sculpting Mode only rotates around geometry origin ( bring bug back)

Sergey Sharybin sergey.vfx at gmail.com
Fri Apr 19 15:26:17 CEST 2013


Revision: 56168
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56168
Author:   nazgul
Date:     2013-04-19 13:26:17 +0000 (Fri, 19 Apr 2013)
Log Message:
-----------
Fix #34818: Sculpting Mode only rotates around geometry origin (bring bug back)

Made it so average coordinate of previous stroke is used as
a viewport rotation center when Rotate Around Selection is
enabled in user preferences.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_paint.h
    trunk/blender/source/blender/editors/include/ED_sculpt.h
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c

Modified: trunk/blender/source/blender/blenkernel/BKE_paint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-04-19 13:03:30 UTC (rev 56167)
+++ trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-04-19 13:26:17 UTC (rev 56168)
@@ -158,6 +158,9 @@
 	/* last paint/sculpt stroke location */
 	int last_stroke_valid;
 	float last_stroke[3];
+
+	float average_stroke_accum[3];
+	int average_stroke_counter;
 } SculptSession;
 
 void free_sculptsession(struct Object *ob);

Modified: trunk/blender/source/blender/editors/include/ED_sculpt.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_sculpt.h	2013-04-19 13:03:30 UTC (rev 56167)
+++ trunk/blender/source/blender/editors/include/ED_sculpt.h	2013-04-19 13:26:17 UTC (rev 56168)
@@ -44,6 +44,7 @@
                               struct RegionView3D *rv3d, struct Object *ob);
 void ED_sculpt_force_update(struct bContext *C);
 float *ED_sculpt_get_last_stroke(struct Object *ob);
+void ED_sculpt_get_average_stroke(struct Object *ob, float stroke[3]);
 int ED_sculpt_minmax(struct bContext *C, float min[3], float max[3]);
 int ED_sculpt_mask_layers_ensure(struct Object *ob,
                                   struct MultiresModifierData *mmd);

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-04-19 13:03:30 UTC (rev 56167)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2013-04-19 13:26:17 UTC (rev 56168)
@@ -118,6 +118,17 @@
 	return (ob && ob->sculpt && ob->sculpt->last_stroke_valid) ? ob->sculpt->last_stroke : NULL;
 }
 
+void ED_sculpt_get_average_stroke(Object *ob, float stroke[3])
+{
+	if (ob->sculpt->last_stroke_valid) {
+		float fac = 1.0f / ob->sculpt->average_stroke_counter;
+		mul_v3_v3fl(stroke, ob->sculpt->average_stroke_accum, fac);
+	}
+	else {
+		copy_v3_v3(stroke, ob->obmat[3]);
+	}
+}
+
 int ED_sculpt_minmax(bContext *C, float min[3], float max[3])
 {
 	Object *ob = CTX_data_active_object(C);
@@ -3015,6 +3026,8 @@
 
 	/* Only act if some verts are inside the brush area */
 	if (totnode) {
+		float location[3];
+
 		#pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP)
 		for (n = 0; n < totnode; n++) {
 			sculpt_undo_push_node(ob, nodes[n],
@@ -3099,6 +3112,13 @@
 		}
 
 		MEM_freeN(nodes);
+
+		/* update average stroke position */
+		copy_v3_v3(location, ss->cache->true_location);
+		mul_m4_v3(ob->obmat, location);
+
+		add_v3_v3(ob->sculpt->average_stroke_accum, location);
+		ob->sculpt->average_stroke_counter++;
 	}
 }
 
@@ -4143,6 +4163,9 @@
 	is_smooth = sculpt_any_smooth_mode(brush, NULL, mode);
 	sculpt_update_mesh_elements(scene, sd, ob, is_smooth, need_mask);
 
+	zero_v3(ob->sculpt->average_stroke_accum);
+	ob->sculpt->average_stroke_counter = 0;
+
 	return 1;
 }
 

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2013-04-19 13:03:30 UTC (rev 56167)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_edit.c	2013-04-19 13:26:17 UTC (rev 56168)
@@ -441,11 +441,18 @@
 		Object *ob = OBACT;
 
 		if (ob && (ob->mode & OB_MODE_ALL_PAINT) && (BKE_object_pose_armature_get(ob) == NULL)) {
-			/* transformation is disabled for painting modes, which will make it
-			 * so previous offset is used. This is annoying when you open file
-			 * saved with active object in painting mode
+			/* in case of sculpting use last average stroke position as a rotation
+			 * center, in other cases it's not clear what rotation center shall be
+			 * so just rotate around object origin
 			 */
-			copy_v3_v3(lastofs, ob->obmat[3]);
+			if (ob->mode & OB_MODE_SCULPT) {
+				float stroke[3];
+				ED_sculpt_get_average_stroke(ob, stroke);
+				copy_v3_v3(lastofs, stroke);
+			}
+			else {
+				copy_v3_v3(lastofs, ob->obmat[3]);
+			}
 		}
 		else {
 			/* If there's no selection, lastofs is unmodified and last value since static */




More information about the Bf-blender-cvs mailing list