[Bf-blender-cvs] [245f97d] master: Clear Transforms and Deltas

Joshua Leung noreply at git.blender.org
Sat Jul 9 02:00:46 CEST 2016


Commit: 245f97d7dc60f64256620383ac71c84146910300
Author: Joshua Leung
Date:   Sat Jul 9 11:52:09 2016 +1200
Branches: master
https://developer.blender.org/rB245f97d7dc60f64256620383ac71c84146910300

Clear Transforms and Deltas

* Alt-G, Alt-R, Alt-S  --> These don't clear delta transforms by default anymore,
  making it possible to use these to properly store a "rest" pose

* Alt-Shift-G, Alt-Shift-R, Alt-Shift-S  --> These WILL clear both the normal
  transform and the delta, should you need to do so.

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

M	source/blender/editors/object/object_ops.c
M	source/blender/editors/object/object_transform.c

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

diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 534e593..7e7e1ef 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -365,9 +365,21 @@ void ED_keymap_object(wmKeyConfig *keyconf)
 	WM_keymap_verify_item(keymap, "OBJECT_OT_constraint_add_with_targets", CKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
 	WM_keymap_verify_item(keymap, "OBJECT_OT_constraints_clear", CKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
 	
-	WM_keymap_verify_item(keymap, "OBJECT_OT_location_clear", GKEY, KM_PRESS, KM_ALT, 0);
-	WM_keymap_verify_item(keymap, "OBJECT_OT_rotation_clear", RKEY, KM_PRESS, KM_ALT, 0);
-	WM_keymap_verify_item(keymap, "OBJECT_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
+	
+	kmi = WM_keymap_add_item(keymap, "OBJECT_OT_location_clear", GKEY, KM_PRESS, KM_ALT, 0);
+	RNA_boolean_set(kmi->ptr, "clear_delta", false);
+	kmi = WM_keymap_add_item(keymap, "OBJECT_OT_rotation_clear", RKEY, KM_PRESS, KM_ALT, 0);
+	RNA_boolean_set(kmi->ptr, "clear_delta", false);
+	kmi = WM_keymap_add_item(keymap, "OBJECT_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
+	RNA_boolean_set(kmi->ptr, "clear_delta", false);
+	
+	kmi = WM_keymap_add_item(keymap, "OBJECT_OT_location_clear", GKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
+	RNA_boolean_set(kmi->ptr, "clear_delta", true);
+	kmi = WM_keymap_add_item(keymap, "OBJECT_OT_rotation_clear", RKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
+	RNA_boolean_set(kmi->ptr, "clear_delta", true);
+	kmi = WM_keymap_add_item(keymap, "OBJECT_OT_scale_clear", SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
+	RNA_boolean_set(kmi->ptr, "clear_delta", true);
+	
 	WM_keymap_verify_item(keymap, "OBJECT_OT_origin_clear", OKEY, KM_PRESS, KM_ALT, 0);
 	
 	WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_clear", HKEY, KM_PRESS, KM_ALT, 0);
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index 6d80c4a..c681b94 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -76,60 +76,85 @@
 /*************************** Clear Transformation ****************************/
 
 /* clear location of object */
-static void object_clear_loc(Object *ob)
+static void object_clear_loc(Object *ob, const bool clear_delta)
 {
 	/* clear location if not locked */
-	if ((ob->protectflag & OB_LOCK_LOCX) == 0)
-		ob->loc[0] = ob->dloc[0] = 0.0f;
-	if ((ob->protectflag & OB_LOCK_LOCY) == 0)
-		ob->loc[1] = ob->dloc[1] = 0.0f;
-	if ((ob->protectflag & OB_LOCK_LOCZ) == 0)
-		ob->loc[2] = ob->dloc[2] = 0.0f;
+	if ((ob->protectflag & OB_LOCK_LOCX) == 0) {
+		ob->loc[0] = 0.0f;
+		if (clear_delta) ob->dloc[0] = 0.0f;
+	}
+	if ((ob->protectflag & OB_LOCK_LOCY) == 0) {
+		ob->loc[1] = 0.0f;
+		if (clear_delta) ob->dloc[1] = 0.0f;
+	}
+	if ((ob->protectflag & OB_LOCK_LOCZ) == 0) {
+		ob->loc[2] = 0.0f;
+		if (clear_delta) ob->dloc[2] = 0.0f;
+	}
 }
 
 /* clear rotation of object */
-static void object_clear_rot(Object *ob)
+static void object_clear_rot(Object *ob, const bool clear_delta)
 {
 	/* clear rotations that aren't locked */
 	if (ob->protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) {
 		if (ob->protectflag & OB_LOCK_ROT4D) {
 			/* perform clamping on a component by component basis */
 			if (ob->rotmode == ROT_MODE_AXISANGLE) {
-				if ((ob->protectflag & OB_LOCK_ROTW) == 0)
-					ob->rotAngle = ob->drotAngle = 0.0f;
-				if ((ob->protectflag & OB_LOCK_ROTX) == 0)
-					ob->rotAxis[0] = ob->drotAxis[0] = 0.0f;
-				if ((ob->protectflag & OB_LOCK_ROTY) == 0)
-					ob->rotAxis[1] = ob->drotAxis[1] = 0.0f;
-				if ((ob->protectflag & OB_LOCK_ROTZ) == 0)
-					ob->rotAxis[2] = ob->drotAxis[2] = 0.0f;
+				if ((ob->protectflag & OB_LOCK_ROTW) == 0) {
+					ob->rotAngle = 0.0f;
+					if (clear_delta) ob->drotAngle = 0.0f;
+				}
+				if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
+					ob->rotAxis[0] = 0.0f;
+					if (clear_delta) ob->drotAxis[0] = 0.0f;
+				}
+				if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
+					ob->rotAxis[1] = 0.0f;
+					if (clear_delta) ob->drotAxis[1] = 0.0f;
+				}
+				if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
+					ob->rotAxis[2] = 0.0f;
+					if (clear_delta) ob->drotAxis[2] = 0.0f;
+				}
 					
 				/* check validity of axis - axis should never be 0,0,0 (if so, then we make it rotate about y) */
 				if (IS_EQF(ob->rotAxis[0], ob->rotAxis[1]) && IS_EQF(ob->rotAxis[1], ob->rotAxis[2]))
 					ob->rotAxis[1] = 1.0f;
-				if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2]))
+				if (IS_EQF(ob->drotAxis[0], ob->drotAxis[1]) && IS_EQF(ob->drotAxis[1], ob->drotAxis[2]) && clear_delta)
 					ob->drotAxis[1] = 1.0f;
 			}
 			else if (ob->rotmode == ROT_MODE_QUAT) {
-				if ((ob->protectflag & OB_LOCK_ROTW) == 0)
-					ob->quat[0] = ob->dquat[0] = 1.0f;
+				if ((ob->protectflag & OB_LOCK_ROTW) == 0) {
+					ob->quat[0] = 1.0f;
+					if (clear_delta) ob->dquat[0] = 1.0f;
+				}
 				if ((ob->protectflag & OB_LOCK_ROTX) == 0)
-					ob->quat[1] = ob->dquat[1] = 0.0f;
+					ob->quat[1] = 0.0f;
+					if (clear_delta) ob->dquat[1] = 0.0f;
 				if ((ob->protectflag & OB_LOCK_ROTY) == 0)
-					ob->quat[2] = ob->dquat[2] = 0.0f;
+					ob->quat[2] = 0.0f;
+					if (clear_delta) ob->dquat[2] = 0.0f;
 				if ((ob->protectflag & OB_LOCK_ROTZ) == 0)
-					ob->quat[3] = ob->dquat[3] = 0.0f;
+					ob->quat[3] = 0.0f;
+					if (clear_delta) ob->dquat[3] = 0.0f;
 					
 				/* TODO: does this quat need normalizing now? */
 			}
 			else {
 				/* the flag may have been set for the other modes, so just ignore the extra flag... */
-				if ((ob->protectflag & OB_LOCK_ROTX) == 0)
-					ob->rot[0] = ob->drot[0] = 0.0f;
-				if ((ob->protectflag & OB_LOCK_ROTY) == 0)
-					ob->rot[1] = ob->drot[1] = 0.0f;
-				if ((ob->protectflag & OB_LOCK_ROTZ) == 0)
-					ob->rot[2] = ob->drot[2] = 0.0f;
+				if ((ob->protectflag & OB_LOCK_ROTX) == 0) {
+					ob->rot[0] = 0.0f;
+					if (clear_delta) ob->drot[0] = 0.0f;
+				}
+				if ((ob->protectflag & OB_LOCK_ROTY) == 0) {
+					ob->rot[1] = 0.0f;
+					if (clear_delta) ob->drot[1] = 0.0f;
+				}
+				if ((ob->protectflag & OB_LOCK_ROTZ) == 0) {
+					ob->rot[2] = 0.0f;
+					if (clear_delta) ob->drot[2] = 0.0f;
+				}
 			}
 		}
 		else {
@@ -175,34 +200,34 @@ static void object_clear_rot(Object *ob)
 	else {
 		if (ob->rotmode == ROT_MODE_QUAT) {
 			unit_qt(ob->quat);
-			unit_qt(ob->dquat);
+			if (clear_delta) unit_qt(ob->dquat);
 		}
 		else if (ob->rotmode == ROT_MODE_AXISANGLE) {
 			unit_axis_angle(ob->rotAxis, &ob->rotAngle);
-			unit_axis_angle(ob->drotAxis, &ob->drotAngle);
+			if (clear_delta) unit_axis_angle(ob->drotAxis, &ob->drotAngle);
 		}
 		else {
 			zero_v3(ob->rot);
-			zero_v3(ob->drot);
+			if (clear_delta) zero_v3(ob->drot);
 		}
 	}
 }
 
 /* clear scale of object */
-static void object_clear_scale(Object *ob)
+static void object_clear_scale(Object *ob, const bool clear_delta)
 {
 	/* clear scale factors which are not locked */
 	if ((ob->protectflag & OB_LOCK_SCALEX) == 0) {
-		ob->dscale[0] = 1.0f;
 		ob->size[0] = 1.0f;
+		if (clear_delta) ob->dscale[0] = 1.0f;
 	}
 	if ((ob->protectflag & OB_LOCK_SCALEY) == 0) {
-		ob->dscale[1] = 1.0f;
 		ob->size[1] = 1.0f;
+		if (clear_delta) ob->dscale[1] = 1.0f;
 	}
 	if ((ob->protectflag & OB_LOCK_SCALEZ) == 0) {
-		ob->dscale[2] = 1.0f;
 		ob->size[2] = 1.0f;
+		if (clear_delta) ob->dscale[2] = 1.0f;
 	}
 }
 
@@ -210,10 +235,12 @@ static void object_clear_scale(Object *ob)
 
 /* generic exec for clear-transform operators */
 static int object_clear_transform_generic_exec(bContext *C, wmOperator *op, 
-                                               void (*clear_func)(Object *), const char default_ksName[])
+                                               void (*clear_func)(Object *, const bool),
+                                               const char default_ksName[])
 {
 	Scene *scene = CTX_data_scene(C);
 	KeyingSet *ks;
+	const bool clear_delta = RNA_boolean_get(op->ptr, "clear_delta");
 	
 	/* sanity checks */
 	if (ELEM(NULL, clear_func, default_ksName)) {
@@ -231,10 +258,10 @@ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op,
 	{
 		if (!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
 			/* run provided clearing function */
-			clear_func(ob);
-
+			clear_func(ob, clear_delta);
+			
 			ED_autokeyframe_object(C, scene, ob, ks);
-
+			
 			/* tag for updates */
 			DAG_id_tag_update(&ob->id, OB_RECALC_OB);
 		}
@@ -268,6 +295,11 @@ void OBJECT_OT_location_clear(wmOperatorType *ot)
 	
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	
+	/* properties */
+	ot->prop = RNA_def_boolean(ot->srna, "clear_delta", false, "Clear Delta",
+	                           "Clear delta location in addition to clearing the normal location transform");
 }
 
 static int object_rotation_clear_exec(bContext *C, wmOperator *op)
@@ -288,6 +320,10 @@ void OBJECT_OT_rotation_clear(wmOperatorType *ot)
 	
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	/* properties */
+	ot->prop = RNA_def_boolean(ot->srna, "clear_delta", false, "Clear Delta",
+	                           "Clear delta rotation in addition to clearing the normal rotation transform");
 }
 
 static int object_scale_clear_exec(bContext *C, wmOperator *op)
@@ -308,6 +344,10 @@ void OBJECT_OT_scale_clear(wmOperatorType *ot)
 	
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+	
+	/* properties */
+	ot->prop = RNA_def_boolean(ot->srna, "clear_delta", false, "Clear Delta",
+	                           "Clear delta scale in addition to clearing the normal scale transform");
 }
 
 /* --------------- */




More information about the Bf-blender-cvs mailing list