[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25647] trunk/blender/source/blender: Cleanup of MotionPaths+Ghosts (AnimViz) - Part 1

Joshua Leung aligorith at gmail.com
Fri Jan 1 13:24:16 CET 2010


Revision: 25647
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25647
Author:   aligorith
Date:     2010-01-01 13:24:16 +0100 (Fri, 01 Jan 2010)

Log Message:
-----------
Cleanup of MotionPaths+Ghosts (AnimViz) - Part 1

This commit sets up some of the groundwork necessary to extend the animation visualisation capabilities, previously only available for bones in PoseMode, to Objects as well. Also, some of the other goals of this refactor is to make future visualisation goodies (i.e. editable paths) more feasible...
(There's really nothing to see here yet. The following log notes are really just for my own reference to keep track of things.)

Currently, the following things have been done:
* New datastructures + settings have been tidied up, ready for usage
* Added these new types into the Object and PoseBone code as necessary, with freeing/adding/copying accounted for
* File IO code for the new data, including version patching to convert the old system to the new one.
* Set up the drawing system for motionpaths based on the old armature path drawing code. Armatures still draw using the old system, since the two systems use different storage systems.
* Started setting up the motionpath 'baking' code, but the core of this still needs to be coded...

Next Steps (after some semi-urgent Durian Driver changes):
* Port the ghosting/onionskinning code over too
* Finish motionpath baking code
* RNA wrapping for the new types
* Hooking up all the new code into the operators, etc.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_anim.h
    trunk/blender/source/blender/blenkernel/intern/action.c
    trunk/blender/source/blender/blenkernel/intern/anim.c
    trunk/blender/source/blender/blenkernel/intern/object.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/editors/armature/poseobject.c
    trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
    trunk/blender/source/blender/editors/space_view3d/view3d_select.c
    trunk/blender/source/blender/makesdna/DNA_action_types.h
    trunk/blender/source/blender/makesdna/DNA_armature_types.h
    trunk/blender/source/blender/makesdna/DNA_object_types.h

Added Paths:
-----------
    trunk/blender/source/blender/editors/space_view3d/drawanimviz.c

Modified: trunk/blender/source/blender/blenkernel/BKE_anim.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_anim.h	2010-01-01 11:55:56 UTC (rev 25646)
+++ trunk/blender/source/blender/blenkernel/BKE_anim.h	2010-01-01 12:24:16 UTC (rev 25647)
@@ -38,14 +38,30 @@
 struct PartEff;
 struct Scene;
 struct ListBase;
+struct bAnimVizSettings;
+struct bMotionPath;
 
 #include "DNA_object_types.h"
 
+/* ---------------------------------------------------- */
+/* Animation Visualisation */
+
+void animviz_settings_init(struct bAnimVizSettings *avs);
+
+void animviz_free_motionpath_cache(struct bMotionPath *mpath);
+void animviz_free_motionpath(struct bMotionPath *mpath);
+
+/* ---------------------------------------------------- */
+/* Curve Paths */
+
 void free_path(struct Path *path);
 void calc_curvepath(struct Object *ob);
 int interval_test(int min, int max, int p1, int cycl);
 int where_on_path(struct Object *ob, float ctime, float *vec, float *dir, float *quat, float *radius);
 
+/* ---------------------------------------------------- */
+/* Dupli-Geometry */
+
 struct ListBase *object_duplilist(struct Scene *sce, struct Object *ob);
 void free_object_duplilist(struct ListBase *lb);
 int count_duplilist(struct Object *ob);

Modified: trunk/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/action.c	2010-01-01 11:55:56 UTC (rev 25646)
+++ trunk/blender/source/blender/blenkernel/intern/action.c	2010-01-01 12:24:16 UTC (rev 25647)
@@ -382,12 +382,12 @@
 	if (ELEM(NULL, pose, name) || (name[0] == 0))
 		return NULL;
 	
-	return BLI_findstring(&pose->chanbase, name, offsetof(bPoseChannel, name));
+	return BLI_findstring(&((bPose *)pose)->chanbase, name, offsetof(bPoseChannel, name));
 }
 
 /* Use with care, not on Armature poses but for temporal ones */
 /* (currently used for action constraints and in rebuild_pose) */
-bPoseChannel *verify_pose_channel(bPose* pose, const char* name)
+bPoseChannel *verify_pose_channel(bPose *pose, const char *name)
 {
 	bPoseChannel *chan;
 	
@@ -455,10 +455,10 @@
 void copy_pose (bPose **dst, bPose *src, int copycon)
 {
 	bPose *outPose;
-	bPoseChannel	*pchan;
+	bPoseChannel *pchan;
 	ListBase listb;
 	
-	if (!src){
+	if (!src) {
 		*dst=NULL;
 		return;
 	}
@@ -482,7 +482,8 @@
 		if (copycon) {
 			copy_constraints(&listb, &pchan->constraints);  // copy_constraints NULLs listb
 			pchan->constraints= listb;
-			pchan->path= NULL;
+			pchan->path= NULL; // XXX remove this line when the new motionpaths are ready... (depreceated code)
+			pchan->mpath= NULL; /* motion paths should not get copied yet... */
 		}
 		
 		if(pchan->prop) {
@@ -491,7 +492,7 @@
 	}
 
 	/* for now, duplicate Bone Groups too when doing this */
-	if(copycon)
+	if (copycon)
 		BLI_duplicatelist(&outPose->agroups, &src->agroups);
 	
 	*dst=outPose;
@@ -532,12 +533,20 @@
 
 void free_pose_channel(bPoseChannel *pchan)
 {
-	if (pchan->path)
+	// XXX this case here will need to be removed when the new motionpaths are ready
+	if (pchan->path) {
 		MEM_freeN(pchan->path);
-
+		pchan->path= NULL;
+	}
+	
+	if (pchan->mpath) {
+		animviz_free_motionpath(pchan->mpath);
+		pchan->mpath= NULL;
+	}
+	
 	free_constraints(&pchan->constraints);
-
-	if(pchan->prop) {
+	
+	if (pchan->prop) {
 		IDP_FreeProperty(pchan->prop);
 		MEM_freeN(pchan->prop);
 	}
@@ -550,7 +559,7 @@
 	if (pose->chanbase.first) {
 		for (pchan = pose->chanbase.first; pchan; pchan=pchan->next)
 			free_pose_channel(pchan);
-
+		
 		BLI_freelistN(&pose->chanbase);
 	}
 }
@@ -564,14 +573,14 @@
 		/* free pose-groups */
 		if (pose->agroups.first)
 			BLI_freelistN(&pose->agroups);
-
+		
 		/* free IK solver state */
 		BIK_clear_data(pose);
-
+		
 		/* free IK solver param */
 		if (pose->ikparam)
 			MEM_freeN(pose->ikparam);
-
+		
 		/* free pose */
 		MEM_freeN(pose);
 	}

Modified: trunk/blender/source/blender/blenkernel/intern/anim.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/anim.c	2010-01-01 11:55:56 UTC (rev 25646)
+++ trunk/blender/source/blender/blenkernel/intern/anim.c	2010-01-01 12:24:16 UTC (rev 25647)
@@ -29,16 +29,21 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <stdio.h>
 #include <math.h>
 #include <string.h>
 
 #include "MEM_guardedalloc.h"
+
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
+
 #include "DNA_listBase.h"
 
+#include "DNA_anim_types.h"
+#include "DNA_action_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_effect_types.h"
 #include "DNA_group_types.h"
@@ -53,6 +58,7 @@
 #include "DNA_vfont_types.h"
 
 #include "BKE_anim.h"
+#include "BKE_animsys.h"
 #include "BKE_curve.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_displist.h"
@@ -60,7 +66,6 @@
 #include "BKE_font.h"
 #include "BKE_group.h"
 #include "BKE_global.h"
-#include "BKE_ipo.h"
 #include "BKE_key.h"
 #include "BKE_lattice.h"
 #include "BKE_main.h"
@@ -73,17 +78,157 @@
 #include <config.h>
 #endif
 
+// XXX bad level call...
 #include "ED_mesh.h"
 
+/* --------------------- */
+/* forward declarations */
+
 static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int level, int animated);
 
+/* ******************************************************************** */
+/* Animation Visualisation */
+
+/* Initialise the default settings for animation visualisation */
+void animviz_settings_init(bAnimVizSettings *avs)
+{
+	/* sanity check */
+	if (avs == NULL)
+		return;
+		
+	/* ghosting settings */
+	avs->ghost_bc= avs->ghost_ac= 10;
+	
+	avs->ghost_sf= 1; // xxx - take from scene instead?
+	avs->ghost_ef= 250; // xxx - take from scene instead?
+	
+	avs->ghost_step= 1;
+	
+	
+	/* path settings */
+	avs->path_bc= avs->path_ac= 10;
+	
+	avs->path_sf= 1; // xxx - take from scene instead?
+	avs->path_ef= 250; // xxx - take from scene instead?
+	
+	avs->path_viewflag= (MOTIONPATH_VIEW_KFRAS|MOTIONPATH_VIEW_KFNOS);
+	
+	avs->path_step= 1;
+}
+
+/* ------------------- */
+
+/* Free the given motion path's cache */
+void animviz_free_motionpath_cache(bMotionPath *mpath) 
+{
+	/* sanity check */
+	if (mpath == NULL) 
+		return;
+		
+	/* free the path if necessary */
+	if (mpath->points)
+		MEM_freeN(mpath->points);
+	
+	/* reset the relevant parameters */
+	mpath->points= NULL;
+	mpath->length= 0;
+}
+
+/* Free the given motion path instance and its data 
+ * NOTE: this frees the motion path given!
+ */
+void animviz_free_motionpath(bMotionPath *mpath)
+{
+	/* sanity check */
+	if (mpath == NULL)
+		return;
+	
+	/* free the cache first */
+	animviz_free_motionpath_cache(mpath);
+	
+	/* now the instance itself */
+	MEM_freeN(mpath);
+}
+
+/* ------------------- */
+
+/* Setup motion paths for the given data 
+ *	- scene: current scene (for frame ranges, etc.)
+ *	- ob: object to add paths for (must be provided)
+ *	- pchan: posechannel to add paths for (optional; if not provided, object-paths are assumed)
+ */
+bMotionPath *animviz_verify_motionpaths(Scene *scene, Object *ob, bPoseChannel *pchan)
+{
+	bAnimVizSettings *avs;
+	bMotionPath *mpath, **dst;
+	
+	/* sanity checks */
+	if (ELEM(NULL, scene, ob))
+		return NULL;
+		
+	/* get destination data */
+	if (pchan) {
+		/* paths for posechannel - assume that posechannel belongs to the object */
+		avs= &ob->pose->avs;
+		dst= &pchan->mpath;
+	}
+	else {
+		/* paths for object */
+		avs= &ob->avs;
+		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;
+		
+	/* 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;
+	mpath->end_frame= avs->path_ef;
+	
+	mpath->length= mpath->end_frame - mpath->start_frame;
+	
+	if (avs->path_bakeflag & MOTIONPATH_BAKE_HEADS)
+		mpath->flag |= MOTIONPATH_FLAG_BHEAD;
+	
+	/* allocate a cache */
+	mpath->points= MEM_callocN(sizeof(bMotionPathVert)*mpath->length, "bMotionPathVerts");
+	
+	/* return it */
+	return mpath;
+}
+
+
+/* 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 
+ */
+void animviz_calc_motionpaths(Scene *scene, Object *ob)
+{
+
+}
+
+/* ******************************************************************** */
+/* Curve Paths - for curve deforms and/or curve following */
+
+/* free curve path data 
+ * NOTE: frees the path itself!
+ */
 void free_path(Path *path)
 {
 	if(path->data) MEM_freeN(path->data);
 	MEM_freeN(path);
 }
 
-
+/* calculate a curve-deform path for a curve 
+ * 	- only called from displist.c -> makeDispListCurveTypes
+ */
 void calc_curvepath(Object *ob)
 {
 	BevList *bl;
@@ -96,7 +241,6 @@
 	float fac, d=0, fac1, fac2;
 	int a, tot, cycl=0;
 	
-
 	/* in a path vertices are with equal differences: path->len = number of verts */
 	/* NOW WITH BEVELCURVE!!! */
 	
@@ -143,7 +287,7 @@
 	}
 	
 	path->totdist= *fp;
-
+	
 		/* the path verts  in path->data */
 		/* now also with TILT value */
 	pp= path->data = (PathPoint *)MEM_callocN(sizeof(PathPoint)*4*path->len, "pathdata"); // XXX - why *4? - in 2.4x each element was 4 and the size was 16, so better leave for now - Campbell
@@ -155,7 +299,7 @@
 	maxdist= dist+tot;
 	fac= 1.0f/((float)path->len-1.0f);
         fac = fac * path->totdist;
-
+	
 	for(a=0; a<path->len; a++) {
 		
 		d= ((float)a)*fac;
@@ -175,7 +319,7 @@
 		fac2= *(fp)-d;
 		fac1= fac2/fac1;
 		fac2= 1.0f-fac1;
-
+		
 		interp_v3_v3v3(pp->vec, bevp->vec, bevpn->vec, fac2);
 		pp->vec[3]= fac1*bevp->alfa + fac2*bevpn->alfa;
 		pp->radius= fac1*bevp->radius + fac2*bevpn->radius;
@@ -188,11 +332,12 @@
 	MEM_freeN(dist);
 }
 
+
+/* is this only used internally?*/
 int interval_test(int min, int max, int p1, int cycl)
 {
-	
 	if(cycl) {
-		if( p1 < min) 
+		if(p1 < min) 
 			p1=  ((p1 -min) % (max-min+1)) + max+1;
 		else if(p1 > max)
 			p1=  ((p1 -min) % (max-min+1)) + min;
@@ -204,8 +349,11 @@
 	return p1;
 }
 
-/* warning, *vec needs FOUR items! */
-/* ctime is normalized range <0-1> */
+
+/* calculate the deformation implied by the curve path at a given parametric position, and returns whether this operation succeeded 
+ * 	- *vec needs FOUR items!

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list