2.5 - Animation Tweaks
authorJoshua Leung <aligorith@gmail.com>
Tue, 22 Sep 2009 11:45:30 +0000 (11:45 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 22 Sep 2009 11:45:30 +0000 (11:45 +0000)
* delta-transforms for objects should work again. These were basically extra transforms that could get added on top of the values calculated from animation values.

* Added some skeleton code for fixing paths when some data needs to be renamed.

source/blender/blenkernel/intern/anim_sys.c
source/blender/blenkernel/intern/object.c

index af4bcd8b0f73da62d81ce9baa4d2a4b7d9b261c7..ca16c62436b5a32f94042853d2129715808a24f9 100644 (file)
@@ -211,25 +211,110 @@ static void make_local_strips(ListBase *strips)
 {
        NlaStrip *strip;
 
-       for(strip=strips->first; strip; strip=strip->next) {
-               if(strip->act) make_local_action(strip->act);
-               if(strip->remap && strip->remap->target) make_local_action(strip->remap->target);
-
+       for (strip=strips->first; strip; strip=strip->next) {
+               if (strip->act) make_local_action(strip->act);
+               //if (strip->remap && strip->remap->target) make_local_action(strip->remap->target);
+               
                make_local_strips(&strip->strips);
        }
 }
 
+/* Use local copy instead of linked copy of various ID-blocks */
 void BKE_animdata_make_local(AnimData *adt)
 {
        NlaTrack *nlt;
+       
+       /* Actions - Active and Temp */
+       if (adt->action) make_local_action(adt->action);
+       if (adt->tmpact) make_local_action(adt->tmpact);
+       /* Remaps */
+       if (adt->remap && adt->remap->target) make_local_action(adt->remap->target);
+       
+       /* Drivers */
+       // TODO: need to remap the ID-targets too?
+       
+       /* NLA Data */
+       for (nlt=adt->nla_tracks.first; nlt; nlt=nlt->next) 
+               make_local_strips(&nlt->strips);
+}
 
-       if(adt->action) make_local_action(adt->action);
-       if(adt->tmpact) make_local_action(adt->tmpact);
-       if(adt->remap && adt->remap->target) make_local_action(adt->remap->target);
+/* Path Validation -------------------------------------------- */
 
-       for(nlt=adt->nla_tracks.first; nlt; nlt=nlt->next) 
-               make_local_strips(&nlt->strips);
+#if 0
+/* Check if some given RNA Path needs fixing - free the given path and set a new one as appropriate */
+static char *rna_path_rename_fix (ID *owner_id, PointerRNA *modPtr, char *newName, char *oldpath)
+{
+       return oldpath; // FIXME!!!
+}
+
+/* Check RNA-Paths for a list of F-Curves */
+static void fcurves_path_rename_fix (ID *owner_id, PointerRNA *modPtr, char *newName, ListBase *curves)
+{
+       FCurve *fcu;
+       
+       /* we need to check every curve... */
+       for (fcu= curves->first; fcu; fcu= fcu->next) {
+               /* firstly, handle the F-Curve's own path */
+               fcu->rna_path= rna_path_rename_fix(owner_id, modPtr, newName, fcu->rna_path);
+               
+               /* driver? */
+               if (fcu->driver) {
+                       ChannelDriver *driver= fcu->driver;
+                       DriverTarget *dtar;
+                       
+                       /* driver targets */
+                       for (dtar= driver->targets.first; dtar; dtar=dtar->next) {
+                               dtat->rna_path= rna_path_rename_fix(owner_id, modPtr, newName, dtar->rna_path);
+                       }
+               }
+       }
+}
+
+/* Fix all RNA-Paths for Actions linked to NLA Strips */
+static void nlastrips_path_rename_fix (ID *owner_id, PointerRNA *modPtr, char *newName, ListBase *strips)
+{
+       NlaStrip *strip;
+       
+       /* recursively check strips, fixing only actions... */
+       for (strip= strips->first; strip; strip= strip->next) {
+               /* fix strip's action */
+               if (strip->act)
+                       fcurves_path_rename_fix(owner_id, modPtr, newName, &strip->act->curves);
+               /* ignore own F-Curves, since those are local...  */
+               
+               /* check sub-strips (if metas) */
+               nlastrips_path_rename_fix(owner_id, modPtr, newName, &strip->strips);
+       }
+}
+
+/* Fix all RNA-Paths in the AnimData block used by the given ID block
+ *     - the pointer of interest must not have had its new name assigned already, otherwise
+ *       path matching for this will never work
+ */
+void BKE_animdata_fix_paths_rename (ID *owner_id, PointerRNA *modPtr, char *newName)
+{
+       AnimData *adt= BKE_animdata_from_id(owner_id);
+       NlaTrack *nlt;
+       
+       /* if no AnimData, no need to proceed */
+       if (ELEM4(NULL, owner_id, adt, modPtr, newName))
+               return;
+       
+       /* Active action and temp action */
+       if (adt->action)
+               fcurves_path_rename_fix(owner_id, modPtr, newName, &adt->action->curves);
+       if (adt->tmpact)
+               fcurves_path_rename_fix(owner_id, modPtr, newName, &adt->tmpact->curves);
+               
+       /* Drivers - Drivers are really F-Curves */
+       fcurves_path_rename_fix(owner_id, modPtr, newName, &adt->drivers);
+       
+       /* NLA Data - Animation Data for Strips */
+       for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
+               
+       }
 }
+#endif
 
 /* *********************************** */ 
 /* KeyingSet API */
index 35514e9697ebb67be28109f0378c8dc30d1b494b..c98e2d5970b8427a8529aab3b2f4a3281709abac 100644 (file)
@@ -1553,13 +1553,11 @@ float bsystem_time(struct Scene *scene, Object *ob, float cfra, float ofs)
        cfra+= bluroffs+fieldoffs;
 
        /* global time */
-       cfra*= scene->r.framelen;       
+       if (scene)
+               cfra*= scene->r.framelen;       
        
 #if 0 // XXX old animation system
        if (ob) {
-               if (no_speed_curve==0 && ob->ipo)
-                       cfra= calc_ipo_time(ob->ipo, cfra);
-               
                /* ofset frames */
                if ((ob->ipoflag & OB_OFFS_PARENT) && (ob->partype & PARSLOW)==0) 
                        cfra-= give_timeoffset(ob);
@@ -1574,29 +1572,22 @@ float bsystem_time(struct Scene *scene, Object *ob, float cfra, float ofs)
 void object_scale_to_mat3(Object *ob, float mat[][3])
 {
        float vec[3];
-       if(ob->ipo) {
-               vec[0]= ob->size[0]+ob->dsize[0];
-               vec[1]= ob->size[1]+ob->dsize[1];
-               vec[2]= ob->size[2]+ob->dsize[2];
-               SizeToMat3(vec, mat);
-       }
-       else {
-               SizeToMat3(ob->size, mat);
-       }
+       
+       vec[0]= ob->size[0]+ob->dsize[0];
+       vec[1]= ob->size[1]+ob->dsize[1];
+       vec[2]= ob->size[2]+ob->dsize[2];
+       SizeToMat3(vec, mat);
 }
 
+// TODO: this should take rotation orders into account later...
 void object_rot_to_mat3(Object *ob, float mat[][3])
 {
        float vec[3];
-       if(ob->ipo) {
-               vec[0]= ob->rot[0]+ob->drot[0];
-               vec[1]= ob->rot[1]+ob->drot[1];
-               vec[2]= ob->rot[2]+ob->drot[2];
-               EulToMat3(vec, mat);
-       }
-       else {
-               EulToMat3(ob->rot, mat);
-       }
+       
+       vec[0]= ob->rot[0]+ob->drot[0];
+       vec[1]= ob->rot[1]+ob->drot[1];
+       vec[2]= ob->rot[2]+ob->drot[2];
+       EulToMat3(vec, mat);
 }
 
 void object_to_mat3(Object *ob, float mat[][3])        /* no parent */
@@ -1611,13 +1602,8 @@ void object_to_mat3(Object *ob, float mat[][3])  /* no parent */
        /* rot */
        /* Quats arnt used yet */
        /*if(ob->transflag & OB_QUAT) {
-               if(ob->ipo) {
-                       QuatMul(q1, ob->quat, ob->dquat);
-                       QuatToMat3(q1, rmat);
-               }
-               else {
-                       QuatToMat3(ob->quat, rmat);
-               }
+               QuatMul(q1, ob->quat, ob->dquat);
+               QuatToMat3(q1, rmat);
        }
        else {*/
                object_rot_to_mat3(ob, rmat);
@@ -1633,12 +1619,9 @@ void object_to_mat4(Object *ob, float mat[][4])
        
        Mat4CpyMat3(mat, tmat);
        
-       VECCOPY(mat[3], ob->loc);
-       if(ob->ipo) {
-               mat[3][0]+= ob->dloc[0];
-               mat[3][1]+= ob->dloc[1];
-               mat[3][2]+= ob->dloc[2];
-       }
+       mat[3][0]= ob->loc[0] + ob->dloc[0];
+       mat[3][1]= ob->loc[1] + ob->dloc[1];
+       mat[3][2]= ob->loc[2] + ob->dloc[2];
 }
 
 int enable_cu_speed= 1;