[Bf-blender-cvs] [8714ae0] master: Fix T39563: Tiny unit-display problem in constraint panels.

Bastien Montagne noreply at git.blender.org
Mon Apr 7 12:19:03 CEST 2014


Commit: 8714ae09f89426242ecd0c65f3291de1a2b51fc4
Author: Bastien Montagne
Date:   Mon Apr 7 12:10:37 2014 +0200
https://developer.blender.org/rB8714ae09f89426242ecd0c65f3291de1a2b51fc4

Fix T39563: Tiny unit-display problem in constraint panels.

There is no good solution here, since RNA props can only have one type/unit.
Tried to find the less worse one - have different RNA props for same DNA value
(a bit like the angle/length for camera lens).

Also fixed two other issues with Transform conctraint:
* Angle were still in degrees (yes, another backward-compatibility breacking).
* Scale was absolute, unlike loc/rot.

Also cleaned up a bit the code, replaced some magic numbers by proper enums, ...

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

M	release/scripts/startup/bl_ui/properties_constraint.py
M	source/blender/blenkernel/BKE_blender.h
M	source/blender/blenkernel/intern/constraint.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/makesdna/DNA_constraint_types.h
M	source/blender/makesrna/intern/rna_constraint.c

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

diff --git a/release/scripts/startup/bl_ui/properties_constraint.py b/release/scripts/startup/bl_ui/properties_constraint.py
index 91999e1..09dfbcf 100644
--- a/release/scripts/startup/bl_ui/properties_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_constraint.py
@@ -653,21 +653,22 @@ class ConstraintButtonsPanel():
         col.row().prop(con, "map_from", expand=True)
 
         split = layout.split()
+        ext = "" if con.map_from == 'LOCATION' else "_rot" if con.map_from == 'ROTATION' else "_scale"
 
         sub = split.column(align=True)
         sub.label(text="X:")
-        sub.prop(con, "from_min_x", text="Min")
-        sub.prop(con, "from_max_x", text="Max")
+        sub.prop(con, "from_min_x" + ext, text="Min")
+        sub.prop(con, "from_max_x" + ext, text="Max")
 
         sub = split.column(align=True)
         sub.label(text="Y:")
-        sub.prop(con, "from_min_y", text="Min")
-        sub.prop(con, "from_max_y", text="Max")
+        sub.prop(con, "from_min_y" + ext, text="Min")
+        sub.prop(con, "from_max_y" + ext, text="Max")
 
         sub = split.column(align=True)
         sub.label(text="Z:")
-        sub.prop(con, "from_min_z", text="Min")
-        sub.prop(con, "from_max_z", text="Max")
+        sub.prop(con, "from_min_z" + ext, text="Min")
+        sub.prop(con, "from_max_z" + ext, text="Max")
 
         col = layout.column()
         row = col.row()
@@ -694,27 +695,28 @@ class ConstraintButtonsPanel():
         col.row().prop(con, "map_to", expand=True)
 
         split = layout.split()
+        ext = "" if con.map_to == 'LOCATION' else "_rot" if con.map_to == 'ROTATION' else "_scale"
 
         col = split.column()
         col.label(text="X:")
 
         sub = col.column(align=True)
-        sub.prop(con, "to_min_x", text="Min")
-        sub.prop(con, "to_max_x", text="Max")
+        sub.prop(con, "to_min_x" + ext, text="Min")
+        sub.prop(con, "to_max_x" + ext, text="Max")
 
         col = split.column()
         col.label(text="Y:")
 
         sub = col.column(align=True)
-        sub.prop(con, "to_min_y", text="Min")
-        sub.prop(con, "to_max_y", text="Max")
+        sub.prop(con, "to_min_y" + ext, text="Min")
+        sub.prop(con, "to_max_y" + ext, text="Max")
 
         col = split.column()
         col.label(text="Z:")
 
         sub = col.column(align=True)
-        sub.prop(con, "to_min_z", text="Min")
-        sub.prop(con, "to_max_z", text="Max")
+        sub.prop(con, "to_min_z" + ext, text="Min")
+        sub.prop(con, "to_max_z" + ext, text="Max")
 
         self.space_template(layout, con)
 
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 415a912..3eb2fab 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         270
-#define BLENDER_SUBVERSION      0
+#define BLENDER_SUBVERSION      1
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262
 #define BLENDER_MINSUBVERSION   0
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 7ec0035..2b486f6 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3206,7 +3206,7 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
 		
 		/* obtain target effect */
 		switch (data->from) {
-			case 2: /* scale */
+			case TRANS_SCALE:
 				mat4_to_size(dvec, ct->matrix);
 				
 				if (is_negative_m4(ct->matrix)) {
@@ -3218,11 +3218,11 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
 					negate_v3(dvec);
 				}
 				break;
-			case 1: /* rotation (convert to degrees first) */
+			case TRANS_ROTATION:
 				mat4_to_eulO(dvec, cob->rotOrder, ct->matrix);
-				mul_v3_fl(dvec, RAD2DEGF(1.0f)); /* rad -> deg */
 				break;
-			default: /* location */
+			case TRANS_LOCATION:
+			default:
 				copy_v3_v3(dvec, ct->matrix[3]);
 				break;
 		}
@@ -3255,32 +3255,24 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
 		
 		/* apply transforms */
 		switch (data->to) {
-			case 2: /* scaling */
-				for (i = 0; i < 3; i++)
-					size[i] = data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]));
+			case TRANS_SCALE:
+				for (i = 0; i < 3; i++) {
+					/* multiply with original scale (so that it can still be scaled) */
+					size[i] *= data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]));
+				}
 				break;
-			case 1: /* rotation */
+			case TRANS_ROTATION:
 				for (i = 0; i < 3; i++) {
-					float tmin, tmax;
-					float val;
-					
-					tmin = data->to_min[i];
-					tmax = data->to_max[i];
-					
-					/* all values here should be in degrees */
-					val = tmin + (sval[(int)data->map[i]] * (tmax - tmin));
-					
-					/* now convert final value back to radians, and add to original rotation (so that it can still be rotated) */
-					eul[i] += DEG2RADF(val);
+					/* add to original rotation (so that it can still be rotated) */
+					eul[i] += data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]));
 				}
 				break;
-			default: /* location */
-				/* get new location */
-				for (i = 0; i < 3; i++)
-					loc[i] = (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])));
-				
-				/* add original location back on (so that it can still be moved) */
-				add_v3_v3v3(loc, cob->matrix[3], loc);
+			case TRANS_LOCATION:
+			default:
+				for (i = 0; i < 3; i++) {
+					/* add to original location (so that it can still be moved) */
+					loc[i] += (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])));
+				}
 				break;
 		}
 		
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 8fadfa6..8f95d78 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -34,6 +34,7 @@
 /* allow readfile to use deprecated functionality */
 #define DNA_DEPRECATED_ALLOW
 
+#include "DNA_constraint_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_sdna_types.h"
 #include "DNA_space_types.h"
@@ -48,6 +49,8 @@
 #include "BKE_main.h"
 #include "BKE_node.h"
 
+#include "BLI_math.h"
+
 #include "BLO_readfile.h"
 
 #include "readfile.h"
@@ -110,4 +113,29 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 		}
 	}
+
+	if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
+		Object *ob;
+
+		/* Update Transform constraint (another deg -> rad stuff). */
+		for (ob = main->object.first; ob; ob = ob->id.next) {
+			bConstraint *con;
+			for (con = ob->constraints.first; con; con = con->next) {
+				if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
+					bTransformConstraint *data = (bTransformConstraint *)con->data;
+					const float deg_to_rad_f = DEG2RADF(1.0f);
+
+					if (data->from == TRANS_ROTATION) {
+						mul_v3_fl(data->from_min, deg_to_rad_f);
+						mul_v3_fl(data->from_max, deg_to_rad_f);
+					}
+
+					if (data->to == TRANS_ROTATION) {
+						mul_v3_fl(data->to_min, deg_to_rad_f);
+						mul_v3_fl(data->to_max, deg_to_rad_f);
+					}
+				}
+			}
+		}
+	}
 }
diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h
index 29e49a9..999c669 100644
--- a/source/blender/makesdna/DNA_constraint_types.h
+++ b/source/blender/makesdna/DNA_constraint_types.h
@@ -557,6 +557,13 @@ typedef enum eCopyScale_Flags {
 	SIZELIKE_OFFSET = (1<<3)
 } eCopyScale_Flags;
 
+/* bTransformConstraint.to/from */
+typedef enum eTransform_ToFrom {
+	TRANS_LOCATION = 0,
+	TRANS_ROTATION = 1,
+	TRANS_SCALE    = 2,
+} eTransform_ToFrom;
+
 /* bSameVolumeConstraint.flag */
 typedef enum eSameVolume_Modes {
 	SAMEVOL_X		= 0,
diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c
index c0ad4fe..6d6ea80 100644
--- a/source/blender/makesrna/intern/rna_constraint.c
+++ b/source/blender/makesrna/intern/rna_constraint.c
@@ -1581,9 +1581,9 @@ static void rna_def_constraint_transform(BlenderRNA *brna)
 	PropertyRNA *prop;
 
 	static EnumPropertyItem transform_items[] = {
-		{0, "LOCATION", 0, "Loc", ""},
-		{1, "ROTATION", 0, "Rot", ""},
-		{2, "SCALE", 0, "Scale", ""},
+		{TRANS_LOCATION, "LOCATION", 0, "Loc", ""},
+		{TRANS_ROTATION, "ROTATION", 0, "Rot", ""},
+		{TRANS_SCALE, "SCALE", 0, "Scale", ""},
 		{0, NULL, 0, NULL, NULL}
 	};
 
@@ -1644,6 +1644,7 @@ static void rna_def_constraint_transform(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Extrapolate Motion", "Extrapolate ranges");
 	RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
 
+	/* Loc */
 	prop = RNA_def_property(srna, "from_min_x", PROP_FLOAT, PROP_DISTANCE);
 	RNA_def_property_float_sdna(prop, NULL, "from_min[0]");
 	RNA_def_property_ui_range(prop, -1000.0f, 1000.0f, 10, 3);
@@ -1715,6 +1716,152 @@ static void rna_def_constraint_transform(BlenderRNA *brna)
 	RNA_def_property_ui_range(prop, -1000.0f, 1000.0f, 10, 3);
 	RNA_def_property_ui_text(prop, "To Maximum Z", "Top range of Z axis destination motion");
 	RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
+
+	/* Rot */
+	prop = RNA_def_property(srna, "from_min_x_rot", PROP_FLOAT, PROP_ANGLE);
+	RNA_def_property_float_sdna(prop, NULL, "from_min[0]");
+	RNA_def_property_ui_range(prop, DEG2RADF(-180.0f), DEG2RADF(180.0f), 10, 3);
+	RNA_def_property_ui_text(prop, "From Minimum X", "Bottom range of X axis source motion");
+	RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
+
+	prop = RNA_def_property(srna, "from_min_y_rot", PROP_FLOAT, PROP_ANGLE);
+	RNA_def_property_float_sdna(prop, NULL, "from_min[1]");
+	RNA_def_property_ui_range(prop, DEG2RADF(-180.0f), DEG2RADF(180.0f), 10, 3);
+	RNA_def_property_ui_text(prop, "From Minimum Y", "Bottom range of Y axis source motio

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list