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
This commit is contained in:
Joshua Leung
2011-01-03 11:58:19 +00:00
parent e7ed8a3be0
commit f7857ec81b
2 changed files with 58 additions and 1 deletions

View File

@@ -2456,7 +2456,7 @@ static void direct_link_key(FileData *fd, Key *key)
while(kb) {
kb->data= newdataadr(fd, kb->data);
if(fd->flags & FD_FLAGS_SWITCH_ENDIAN)
switch_endian_keyblock(key, kb);
@@ -11226,6 +11226,20 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
/* 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! */

View File

@@ -97,6 +97,47 @@ static void rna_ShapeKey_value_range(PointerRNA *ptr, float *min, float *max)
*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 @@ static void rna_def_keyblock(BlenderRNA *brna)
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);