[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25817] trunk/blender: Animation Visualisation Cleanups - Part 2:

Joshua Leung aligorith at gmail.com
Thu Jan 7 23:54:05 CET 2010


Revision: 25817
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25817
Author:   aligorith
Date:     2010-01-07 23:54:05 +0100 (Thu, 07 Jan 2010)

Log Message:
-----------
Animation Visualisation Cleanups - Part 2:

* Finished baking code for motion paths, generalising it so that it works for both Objects and Bones. 
It is based on the old code for baking bones, although I have modified the updating code to use a more 'correct' method of updating dependencies. However, this may turn out to be too slow, and another API method should be added for that...

* Moved some of the old version-patching code for animviz settings out of the drawing functions, instead doing this on the version patching proper.

* Added RNA support for the new AnimViz types, and included RNA access via their users too. The old settings have still been left in for now, since there are still some things not ready to use yet.

----

* F-Curve's with sample points (i.e. sounds to F-Curves) now perform linear interpolation between sample points instead of using constant interpolation.

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/properties_data_bone.py
    trunk/blender/source/blender/blenkernel/BKE_anim.h
    trunk/blender/source/blender/blenkernel/intern/anim.c
    trunk/blender/source/blender/blenkernel/intern/fcurve.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesdna/DNA_action_types.h
    trunk/blender/source/blender/makesdna/DNA_armature_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/makesrna.c
    trunk/blender/source/blender/makesrna/intern/rna_internal.h
    trunk/blender/source/blender/makesrna/intern/rna_object.c
    trunk/blender/source/blender/makesrna/intern/rna_pose.c
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Added Paths:
-----------
    trunk/blender/source/blender/makesrna/intern/rna_animviz.c

Modified: trunk/blender/release/scripts/ui/properties_data_bone.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_data_bone.py	2010-01-07 22:51:17 UTC (rev 25816)
+++ trunk/blender/release/scripts/ui/properties_data_bone.py	2010-01-07 22:54:05 UTC (rev 25817)
@@ -227,7 +227,7 @@
             col.label(text="Custom Shape:")
             col.prop(pchan, "custom_shape", text="")
             if pchan.custom_shape:
-                col.prop_object(pchan, "custom_shape_transform", ob.pose, "bones", text="")
+                col.prop_object(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
 
 
 class BONE_PT_inverse_kinematics(BoneButtonsPanel):

Modified: trunk/blender/source/blender/blenkernel/BKE_anim.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_anim.h	2010-01-07 22:51:17 UTC (rev 25816)
+++ trunk/blender/source/blender/blenkernel/BKE_anim.h	2010-01-07 22:54:05 UTC (rev 25817)
@@ -40,6 +40,7 @@
 struct ListBase;
 struct bAnimVizSettings;
 struct bMotionPath;
+struct bPoseChannel;
 
 #include "DNA_object_types.h"
 
@@ -51,6 +52,9 @@
 void animviz_free_motionpath_cache(struct bMotionPath *mpath);
 void animviz_free_motionpath(struct bMotionPath *mpath);
 
+struct bMotionPath *animviz_verify_motionpaths(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan);
+void animviz_calc_motionpaths(struct Scene *scene, struct Object *ob);
+
 /* ---------------------------------------------------- */
 /* Curve Paths */
 

Modified: trunk/blender/source/blender/blenkernel/intern/anim.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim.c	2010-01-07 22:51:17 UTC (rev 25816)
+++ trunk/blender/source/blender/blenkernel/intern/anim.c	2010-01-07 22:54:05 UTC (rev 25817)
@@ -44,6 +44,7 @@
 
 #include "DNA_anim_types.h"
 #include "DNA_action_types.h"
+#include "DNA_armature_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_effect_types.h"
 #include "DNA_group_types.h"
@@ -72,6 +73,7 @@
 #include "BKE_mesh.h"
 #include "BKE_object.h"
 #include "BKE_particle.h"
+#include "BKE_scene.h"
 #include "BKE_utildefines.h"
 
 #ifdef HAVE_CONFIG_H
@@ -178,14 +180,21 @@
 		dst= &ob->mpath;
 	}
 	
-	/* if there is already a motionpath, just return that... */
-	// TODO: maybe we should validate the settings in this case
-	if (*dst != NULL)
-		return *dst;
+	/* if there is already a motionpath, just return that,
+	 * but provided it's settings are ok 
+	 */
+	if (*dst != NULL) {
+		mpath= *dst;
 		
-	/* create a new motionpath, and assign it */
-	mpath= MEM_callocN(sizeof(bMotionPath), "bMotionPath");
-	*dst= mpath;
+		/* if range is not invalid, and/or length is set ok, just return */
+		if ((mpath->start_frame != mpath->end_frame) && (mpath->length > 0))
+			return mpath;
+	}
+	else {
+		/* create a new motionpath, and assign it */
+		mpath= MEM_callocN(sizeof(bMotionPath), "bMotionPath");
+		*dst= mpath;
+	}
 	
 	/* set settings from the viz settings */
 	mpath->start_frame= avs->path_sf;
@@ -203,15 +212,151 @@
 	return mpath;
 }
 
+/* ------------------- */
 
+/* Motion path needing to be baked (mpt) */
+typedef struct MPathTarget {
+	struct MPathTarget *next, *prev;
+	
+	bMotionPath *mpath;			/* motion path in question */
+	
+	Object *ob;					/* source object */
+	bPoseChannel *pchan;		/* source posechannel (if applicable) */
+} MPathTarget;
+
+/* ........ */
+
+/* get list of motion paths to be baked (assumes the list is ready to be used) */
+static void motionpaths_get_bake_targets(Object *ob, ListBase *targets)
+{
+	MPathTarget *mpt;
+	
+	/* object itself first */
+	if ((ob->avs.recalc & ANIMVIZ_RECALC_PATHS) && (ob->mpath)) {
+		/* new target for object */
+		mpt= MEM_callocN(sizeof(MPathTarget), "MPathTarget Ob");
+		BLI_addtail(targets, mpt);
+		
+		mpt->mpath= ob->mpath;
+		mpt->ob= ob;
+	}
+	
+	/* bones */
+	if ((ob->pose) && (ob->pose->avs.recalc & ANIMVIZ_RECALC_PATHS)) {
+		bArmature *arm= ob->data;
+		bPoseChannel *pchan;
+		
+		for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+			if ((pchan->bone) && (arm->layer & pchan->bone->layer) && (pchan->mpath)) {
+				/* new target for bone */
+				mpt= MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone");
+				BLI_addtail(targets, mpt);
+				
+				mpt->mpath= pchan->mpath;
+				mpt->ob= ob;
+				mpt->pchan= pchan;
+			}
+		}
+	}
+}
+
+/* perform baking for the targets on the current frame */
+static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
+{
+	MPathTarget *mpt;
+	
+	/* for each target, check if it can be baked on the current frame */
+	for (mpt= targets->first; mpt; mpt= mpt->next) {	
+		bMotionPath *mpath= mpt->mpath;
+		bMotionPathVert *mpv;
+		
+		/* current frame must be within the range the cache works for */
+		if (IN_RANGE(CFRA, mpath->start_frame, mpath->end_frame) == 0)
+			continue;
+		
+		/* get the relevant cache vert to write to */
+		mpv= mpath->points + (CFRA - mpath->start_frame);
+		
+		/* pose-channel or object path baking? */
+		if (mpt->pchan) {
+			/* heads or tails */
+			if (mpath->flag & MOTIONPATH_FLAG_BHEAD) {
+				VECCOPY(mpv->co, mpt->pchan->pose_head);
+			}
+			else {
+				VECCOPY(mpv->co, mpt->pchan->pose_tail);
+			}
+			
+			/* result must be in worldspace */
+			mul_m4_v3(mpt->ob->obmat, mpv->co);
+		}
+		else {
+			/* worldspace object location */
+			VECCOPY(mpv->co, mpt->ob->obmat[3]);
+		}
+	}
+}
+
+/* ........ */
+
 /* Perform baking of the given object's and/or its bones' transforms to motion paths 
  *	- scene: current scene
  *	- ob: object whose flagged motionpaths should get calculated
  *	- recalc: whether we need to 
  */
+// TODO: include reports pointer?
 void animviz_calc_motionpaths(Scene *scene, Object *ob)
 {
-
+	ListBase targets = {NULL, NULL};
+	MPathTarget *mpt;
+	int sfra, efra;
+	int cfra;
+	
+	/* sanity checks */
+	if (ob == NULL)
+		return;
+		
+	/* get motion paths to affect */
+	motionpaths_get_bake_targets(ob, &targets);
+	
+	if (targets.first == NULL) 
+		return;
+	
+	/* set frame values */
+	cfra = CFRA;
+	sfra = efra = cfra;
+	
+	for (mpt= targets.first; mpt; mpt= mpt->next) {
+		/* try to increase area to do (only as much as needed) */
+		sfra= MIN2(sfra, mpt->mpath->start_frame);
+		efra= MAX2(efra, mpt->mpath->end_frame);
+	}
+	if (efra <= sfra) return;
+	
+	/* calculate path over requested range */
+	for (CFRA=sfra; CFRA<=efra; CFRA++) {
+		/* do all updates 
+		 *	- if this is too slow, resort to using a more efficient way 
+		 * 	  that doesn't force complete update, but for now, this is the
+		 *	  most accurate way!
+		 */
+		scene_update_for_newframe(scene, ob->lay); // XXX is the layer flag too restrictive?
+		
+		/* perform baking for targets */
+		motionpaths_calc_bake_targets(scene, &targets);
+	}
+	
+	/* reset original environment */
+	CFRA= cfra;
+	scene_update_for_newframe(scene, ob->lay); // XXX is the layer flag too restrictive?
+	
+		// TODO: make an API call for this too?
+	ob->avs.recalc &= ~ANIMVIZ_RECALC_PATHS;
+	if (ob->pose)
+		ob->pose->avs.recalc &= ~ANIMVIZ_RECALC_PATHS;
+	
+	/* free temp data */
+	BLI_freelistN(&targets);
 }
 
 /* ******************************************************************** */

Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c	2010-01-07 22:51:17 UTC (rev 25816)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c	2010-01-07 22:54:05 UTC (rev 25817)
@@ -1734,9 +1734,16 @@
 		cvalue= lastfpt->vec[1];
 	}
 	else {
+		float t= (float)abs(evaltime - (int)evaltime);
+		
 		/* find the one on the right frame (assume that these are spaced on 1-frame intervals) */
 		fpt= prevfpt + (int)(evaltime - prevfpt->vec[0]);
-		cvalue= fpt->vec[1];
+		
+		/* if not exactly on the frame, perform linear interpolation with the next one */
+		if (t != 0.0f) 
+			cvalue= interpf(fpt->vec[1], (fpt+1)->vec[1], t);
+		else
+			cvalue= fpt->vec[1];
 	}
 	
 	/* return value */

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2010-01-07 22:51:17 UTC (rev 25816)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2010-01-07 22:54:05 UTC (rev 25817)
@@ -10339,33 +10339,37 @@
 			/* initialise object defaults */
 			animviz_settings_init(&ob->avs);
 			
-			/* if armature, copy settings for pose from armature data */
+			/* if armature, copy settings for pose from armature data 
+			 * performing initialisation where appropriate 
+			 */
 			if (ob->pose && ob->data) {
 				bArmature *arm= newlibadr(fd, lib, ob->data);
 				if(arm) { /* XXX - why does this fail in some cases? */
 					bAnimVizSettings *avs= &ob->pose->avs;
-
+					
 					/* ghosting settings ---------------- */
 						/* ranges */
 					avs->ghost_bc= avs->ghost_ac= arm->ghostep;
-
+					
 					avs->ghost_sf= arm->ghostsf;
 					avs->ghost_ef= arm->ghostef;
-
+					
 						/* type */
 					avs->ghost_type= arm->ghosttype;
-
+					
 						/* stepsize */
 					avs->ghost_step= arm->ghostsize;
-
+					if (avs->ghost_step == 0)
+						avs->ghost_step= 1;
+					
 					/* path settings --------------------- */
 						/* ranges */
 					avs->path_bc= arm->pathbc;
 					avs->path_ac= arm->pathac;
-
+					
 					avs->path_sf= arm->pathsf;
 					avs->path_ef= arm->pathef;
-
+					
 						/* flags */
 					if (arm->pathflag & ARM_PATH_FNUMS)
 						avs->path_viewflag |= MOTIONPATH_VIEW_FNUMS;
@@ -10373,17 +10377,19 @@
 						avs->path_viewflag |= MOTIONPATH_VIEW_KFRAS;
 					if (arm->pathflag & ARM_PATH_KFNOS)
 						avs->path_viewflag |= MOTIONPATH_VIEW_KFNOS;
-
+					
 						/* bake flags */
 					if (arm->pathflag & ARM_PATH_HEADS)
 						avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS;
-
+					
 						/* type */
 					if (arm->pathflag & ARM_PATH_ACFRA)
 						avs->path_type = MOTIONPATH_TYPE_ACFRA;
-
+					
 						/* stepsize */
 					avs->path_step= arm->pathsize;
+					if (avs->path_step == 0)
+						avs->path_step= 1;
 				}
 			}
 		}

Modified: trunk/blender/source/blender/makesdna/DNA_action_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_action_types.h	2010-01-07 22:51:17 UTC (rev 25816)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list