[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57904] trunk/blender/source/blender/ blenkernel/intern/anim_sys.c: Bugfix [#35856] Bones gets scaled chaotically when during NLA Strip Blend In/Out

Joshua Leung aligorith at gmail.com
Mon Jul 1 15:57:01 CEST 2013


Revision: 57904
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57904
Author:   aligorith
Date:     2013-07-01 13:57:00 +0000 (Mon, 01 Jul 2013)
Log Message:
-----------
Bugfix [#35856] Bones gets scaled chaotically when during NLA Strip Blend In/Out

This was one of the consequences of r.57333 (i.e. influence shouldn't be ignored
on the first strip that animates a channel), as scale should really default to a
base value of 1 (instead of things being blended against 0 as per all other
properties). The end result was that bones were getting scaled to zero here when
the influence of their strip fell to zero.

Now, we use the RNA default values of properties to initialise their initial
values. This may/may not work well in all cases:
1) For properties which don't have the appropriate RNA defaults set, this will
be problematic. But, most properties people are likely to animate here I think
are already set up correctly.
2) It may not always be nice to have values "snapping back" to default values.
In this case, you should still be defining a strip at the bottom of your NLA
stack which defines what the appropriate rest poses *should* be for your shot.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/anim_sys.c

Modified: trunk/blender/source/blender/blenkernel/intern/anim_sys.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2013-07-01 13:30:19 UTC (rev 57903)
+++ trunk/blender/source/blender/blenkernel/intern/anim_sys.c	2013-07-01 13:57:00 UTC (rev 57904)
@@ -1639,8 +1639,46 @@
 	return NULL;
 }
 
+/* initialise default value for NlaEvalChannel, so that it doesn't blend things wrong */
+static void nlaevalchan_value_init(NlaEvalChannel *nec)
+{
+	PointerRNA *ptr = &nec->ptr;
+	PropertyRNA *prop = nec->prop;
+	int index = nec->index;
+	
+	/* NOTE: while this doesn't work for all RNA properties as default values aren't in fact 
+	 * set properly for most of them, at least the common ones (which also happen to get used 
+	 * in NLA strips a lot, e.g. scale) are set correctly.
+	 */
+	switch (RNA_property_type(prop)) {
+		case PROP_BOOLEAN:
+			if (RNA_property_array_length(ptr, prop))
+				nec->value = (float)RNA_property_boolean_get_default_index(ptr, prop, index);
+			else
+				nec->value = (float)RNA_property_boolean_get_default(ptr, prop);
+			break;
+		case PROP_INT:
+			if (RNA_property_array_length(ptr, prop))
+				nec->value = (float)RNA_property_int_get_default_index(ptr, prop, index);
+			else
+				nec->value = (float)RNA_property_int_get_default(ptr, prop);
+			break;
+		case PROP_FLOAT:
+			if (RNA_property_array_length(ptr, prop))
+				nec->value = RNA_property_float_get_default_index(ptr, prop, index);
+			else
+				nec->value = RNA_property_float_get_default(ptr, prop);
+			break;
+		case PROP_ENUM:
+			nec->value = (float)RNA_property_enum_get_default(ptr, prop);
+			break;
+		default:
+			break;
+	}
+}
+
 /* verify that an appropriate NlaEvalChannel for this F-Curve exists */
-static NlaEvalChannel *nlaevalchan_verify(PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes, FCurve *fcu, short *newChan)
+static NlaEvalChannel *nlaevalchan_verify(PointerRNA *ptr, ListBase *channels, NlaEvalStrip *nes, FCurve *fcu)
 {
 	NlaEvalChannel *nec;
 	NlaStrip *strip = nes->strip;
@@ -1674,22 +1712,23 @@
 	/* allocate a new struct for this if none found */
 	if (nec == NULL) {
 		nec = MEM_callocN(sizeof(NlaEvalChannel), "NlaEvalChannel");
-		*newChan = 1;
 		BLI_addtail(channels, nec);
 		
+		/* store property links for writing to the property later */
 		nec->ptr = new_ptr;
 		nec->prop = prop;
 		nec->index = fcu->array_index;
+		
+		/* initialise value using default value of property [#35856] */
+		nlaevalchan_value_init(nec);
 	}
-	else
-		*newChan = 0;
 	
 	/* we can now return */
 	return nec;
 }
 
 /* accumulate (i.e. blend) the given value on to the channel it affects */
-static void nlaevalchan_accumulate(NlaEvalChannel *nec, NlaEvalStrip *nes, short UNUSED(newChan), float value)
+static void nlaevalchan_accumulate(NlaEvalChannel *nec, NlaEvalStrip *nes, float value)
 {
 	NlaStrip *strip = nes->strip;
 	short blendmode = strip->blendmode;
@@ -1756,7 +1795,7 @@
 		 * otherwise, add the current channel to the buffer for efficiency
 		 */
 		if (necd)
-			nlaevalchan_accumulate(necd, nes, 0, nec->value);
+			nlaevalchan_accumulate(necd, nes, nec->value);
 		else {
 			BLI_remlink(tmp_buffer, nec);
 			BLI_addtail(channels, nec);
@@ -1853,7 +1892,6 @@
 	for (fcu = strip->act->curves.first; fcu; fcu = fcu->next) {
 		NlaEvalChannel *nec;
 		float value = 0.0f;
-		short newChan = -1;
 		
 		/* check if this curve should be skipped */
 		if (fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED))
@@ -1875,9 +1913,9 @@
 		/* get an NLA evaluation channel to work with, and accumulate the evaluated value with the value(s)
 		 * stored in this channel if it has been used already
 		 */
-		nec = nlaevalchan_verify(ptr, channels, nes, fcu, &newChan);
+		nec = nlaevalchan_verify(ptr, channels, nes, fcu);
 		if (nec)
-			nlaevalchan_accumulate(nec, nes, newChan, value);
+			nlaevalchan_accumulate(nec, nes, value);
 	}
 	
 	/* unlink this strip's modifiers from the parent's modifiers again */




More information about the Bf-blender-cvs mailing list