[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34032] trunk/blender/source/blender: 2. 4x <-> 2.5 Regression Fixes: Shapekey Problems

Joshua Leung aligorith at gmail.com
Mon Jan 3 12:58:19 CET 2011


Revision: 34032
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34032
Author:   aligorith
Date:     2011-01-03 12:58:19 +0100 (Mon, 03 Jan 2011)

Log Message:
-----------
2.4x <-> 2.5 Regression Fixes: Shapekey Problems

This commit partially fixes the problems with Shapekeys from older
files, as seen from the Regression suite (relative.blend and
dolphin.blend in particular).

In older files, keyblock->slidermax was never truly set to 1.0 even
though the UI may have shown such a value (which was bizzarely being
sourced from somewhere else). Hence, after loading the files in 2.5,
the shapekeys wouldn't animate, as the value would get clamped between
0 and 0.

To fix this, I've added a version patch which corrects these
situations in old files, and I've adjusted the slider-RNA code so that
it is not possible to set up such clamping anymore.

TODO:
The fixes detailed here only make it possible for these files to work
again in 2.5. However, I haven't been able to find a way to get the
files to actually work in 2.5 without manually changing the active
shapekey (per object) after loading the files with these patches
applied. Possibly it's just some depsgraph magic needed, unless
there's still some other evil voodoo in the shapekey code

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesrna/intern/rna_key.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2011-01-03 11:50:10 UTC (rev 34031)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2011-01-03 11:58:19 UTC (rev 34032)
@@ -2456,7 +2456,7 @@
 	while(kb) {
 
 		kb->data= newdataadr(fd, kb->data);
-
+		
 		if(fd->flags & FD_FLAGS_SWITCH_ENDIAN)
 			switch_endian_keyblock(key, kb);
 
@@ -11226,6 +11226,20 @@
 
 	/* put compatibility code here until next subversion bump */
 	{
+		Key *key;
+		
+		/* old files could have been saved with slidermin = slidermax = 0.0, but the UI in
+		 * 2.4x would never reveal this to users as a dummy value always ended up getting used
+		 * instead
+		 */
+		for (key = main->key.first; key; key = key->id.next) {
+			KeyBlock *kb;
+			
+			for (kb = key->block.first; kb; kb = kb->next) {
+				if (IS_EQ(kb->slidermin, kb->slidermax) && IS_EQ(kb->slidermax, 0))
+					kb->slidermax = kb->slidermin + 1.0f;
+			}
+		}
 	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: trunk/blender/source/blender/makesrna/intern/rna_key.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_key.c	2011-01-03 11:50:10 UTC (rev 34031)
+++ trunk/blender/source/blender/makesrna/intern/rna_key.c	2011-01-03 11:58:19 UTC (rev 34032)
@@ -97,6 +97,47 @@
 	*max= data->slidermax;
 }
 
+/* epsilon for how close one end of shapekey range can get to the other */
+#define SHAPEKEY_SLIDER_TOL 0.001
+
+static void rna_ShapeKey_slider_min_range(PointerRNA *ptr, float *min, float *max)
+{
+	KeyBlock *data= (KeyBlock*)ptr->data;
+
+	*min= -10.0f;
+	*max= data->slidermax - SHAPEKEY_SLIDER_TOL;
+}
+
+static void rna_ShapeKey_slider_min_set(PointerRNA *ptr, float value)
+{
+	KeyBlock *data= (KeyBlock*)ptr->data;
+	float min, max;
+	
+	rna_ShapeKey_slider_min_range(ptr, &min, &max);
+	CLAMP(value, min, max);
+	data->slidermin = value;
+}
+
+static void rna_ShapeKey_slider_max_range(PointerRNA *ptr, float *min, float *max)
+{
+	KeyBlock *data= (KeyBlock*)ptr->data;
+
+	*min= data->slidermin + SHAPEKEY_SLIDER_TOL;
+	*max= 10.0f;
+}
+
+static void rna_ShapeKey_slider_max_set(PointerRNA *ptr, float value)
+{
+	KeyBlock *data= (KeyBlock*)ptr->data;
+	float min, max;
+	
+	rna_ShapeKey_slider_max_range(ptr, &min, &max);
+	CLAMP(value, min, max);
+	data->slidermax = value;
+}
+
+#undef SHAPEKEY_SLIDER_TOL
+
 PointerRNA rna_object_shapekey_index_get(ID *id, int value)
 {
 	Key *key= rna_ShapeKey_find_key(id);
@@ -446,12 +487,14 @@
 	prop= RNA_def_property(srna, "slider_min", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "slidermin");
 	RNA_def_property_range(prop, -10.0f, 10.0f);
+	RNA_def_property_float_funcs(prop, NULL, "rna_ShapeKey_slider_min_set", "rna_ShapeKey_slider_min_range");
 	RNA_def_property_ui_text(prop, "Slider Min", "Minimum for slider");
 
 	prop= RNA_def_property(srna, "slider_max", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "slidermax");
 	RNA_def_property_range(prop, -10.0f, 10.0f);
 	RNA_def_property_float_default(prop, 1.0f);
+	RNA_def_property_float_funcs(prop, NULL, "rna_ShapeKey_slider_max_set", "rna_ShapeKey_slider_max_range");
 	RNA_def_property_ui_text(prop, "Slider Max", "Maximum for slider");
 
 	prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);





More information about the Bf-blender-cvs mailing list