[Bf-blender-cvs] [48ef050] master: Transform: absolute grid snapping

Campbell Barton noreply at git.blender.org
Sat Jun 27 12:08:05 CEST 2015


Commit: 48ef0501b7cbbd10d5462c68a2559b2b64848b97
Author: Campbell Barton
Date:   Sat Jun 27 15:30:17 2015 +1000
Branches: master
https://developer.blender.org/rB48ef0501b7cbbd10d5462c68a2559b2b64848b97

Transform: absolute grid snapping

D910 by @donfabio with edits

New icon for menu is still TODO

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/transform/transform_constraints.c
M	source/blender/editors/transform/transform_snap.c
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index b608ff9..1047d12 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -86,7 +86,7 @@ class VIEW3D_HT_header(Header):
             row = layout.row(align=True)
             row.prop(toolsettings, "use_snap", text="")
             row.prop(toolsettings, "snap_element", icon_only=True)
-            if snap_element != 'INCREMENT':
+            if snap_element not in {'INCREMENT', 'GRID'}:
                 row.prop(toolsettings, "snap_target", text="")
                 if obj:
                     if mode in {'OBJECT', 'POSE'} and snap_element != 'VOLUME':
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index ae5d2c8..3063ee2 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -310,7 +310,7 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, const float in[3
 		mul_m3_v3(t->con.pmtx, out);
 
 		// With snap, a projection is alright, no need to correct for view alignment
-		if (!(t->tsnap.mode != SCE_SNAP_MODE_INCREMENT && activeSnap(t))) {
+		if (ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID) || activeSnap(t)) {
 			if (getConstraintSpaceDimension(t) == 2) {
 				if (out[0] != 0.0f || out[1] != 0.0f || out[2] != 0.0f) {
 					planeProjection(t, in, out);
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 8e100b9..1b0256b 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -454,7 +454,7 @@ void applySnapping(TransInfo *t, float *vec)
 	
 		t->tsnap.applySnap(t, vec);
 	}
-	else if ((t->tsnap.mode != SCE_SNAP_MODE_INCREMENT) && activeSnap(t)) {
+	else if (!ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID) && activeSnap(t)) {
 		double current = PIL_check_seconds_timer();
 		
 		// Time base quirky code to go around findnearest slowness
@@ -2393,8 +2393,8 @@ void snapGridIncrement(TransInfo *t, float *val)
 {
 	GearsType action;
 
-	// Only do something if using Snap to Grid
-	if (t->tsnap.mode != SCE_SNAP_MODE_INCREMENT)
+	/* only do something if using absolute or incremental grid snapping */
+	if (!ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID))
 		return;
 
 	action = activeSnap(t) ? BIG_GEARS : NO_GEARS;
@@ -2435,6 +2435,7 @@ static void applyGridIncrement(TransInfo *t, float *val, int max_index, const fl
 	const float *asp = use_aspect ? t->aspect : asp_local;
 	int i;
 
+	BLI_assert(ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID));
 	BLI_assert(max_index <= 2);
 
 	/* Early bailing out if no need to snap */
@@ -2461,7 +2462,21 @@ static void applyGridIncrement(TransInfo *t, float *val, int max_index, const fl
 		}
 	}
 
-	for (i = 0; i <= max_index; i++) {
-		val[i] = fac[action] * asp[i] * floorf(val[i] / (fac[action] * asp[i]) + 0.5f);
+	/* absolute snapping on grid based on global center */
+	if ((t->tsnap.mode == SCE_SNAP_MODE_GRID) && (t->mode == TFM_TRANSLATION)) {
+		for (i = 0; i <= max_index; i++) {
+			/* do not let unconstrained axis jump to absolute grid increments */
+			if (!(t->con.mode & CON_APPLY) || t->con.mode & (CON_AXIS0 << i)) {
+				const float iter_fac = fac[action] * asp[i];
+				val[i] = iter_fac * roundf((val[i] + t->center_global[i]) / iter_fac) - t->center_global[i];
+			}
+		}
+	}
+	else {
+		/* relative snapping in fixed increments */
+		for (i = 0; i <= max_index; i++) {
+			const float iter_fac = fac[action] * asp[i];
+			val[i] = iter_fac * roundf(val[i] / iter_fac);
+		}
 	}
 }
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 0986c50..d288da9 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -158,7 +158,8 @@ EnumPropertyItem mesh_select_mode_items[] = {
 };
 
 EnumPropertyItem snap_element_items[] = {
-	{SCE_SNAP_MODE_INCREMENT, "INCREMENT", ICON_SNAP_INCREMENT, "Increment", "Snap to increments of grid"},
+	{SCE_SNAP_MODE_INCREMENT, "INCREMENT", ICON_ALIGN, "Grid (increment)", "Snap to increments of grid"},
+	{SCE_SNAP_MODE_GRID, "GRID", ICON_SNAP_INCREMENT, "Grid (absolute)", "Snap to grid"},
 	{SCE_SNAP_MODE_VERTEX, "VERTEX", ICON_SNAP_VERTEX, "Vertex", "Snap to vertices"},
 	{SCE_SNAP_MODE_EDGE, "EDGE", ICON_SNAP_EDGE, "Edge", "Snap to edges"},
 	{SCE_SNAP_MODE_FACE, "FACE", ICON_SNAP_FACE, "Face", "Snap to faces"},




More information about the Bf-blender-cvs mailing list