add the option to add the parents time offset value.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 19 Jan 2008 16:32:29 +0000 (16:32 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 19 Jan 2008 16:32:29 +0000 (16:32 +0000)
12 files changed:
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/group.c
source/blender/blenkernel/intern/object.c
source/blender/makesdna/DNA_object_types.h
source/blender/python/api2_2x/Effect.c
source/blender/src/buttons_object.c
source/blender/src/drawaction.c
source/blender/src/drawipo.c
source/blender/src/drawobject.c
source/blender/src/editipo.c
source/blender/src/editobject.c

index 6e363515f4195b140f985e6d17752f2f7c5dedca..b9f31d5590b34bed86722a3c858bb0dbe481883f 100644 (file)
@@ -110,6 +110,8 @@ void solve_tracking (struct Object *ob, float targetmat[][4]);
 
 void object_handle_update(struct Object *ob);
 
+float give_timeoffset(struct Object *ob);
+
 #ifdef __cplusplus
 }
 #endif
index e09f6207642796af9b7ecbba451981742af6466f..6e33805fbebfa354e372fe8f8fe663ca1cb6df72 100644 (file)
@@ -1559,7 +1559,7 @@ static pMatrixCache *cache_object_matrices(Object *ob, int start, int end)
        framelenold= G.scene->r.framelen;
        G.scene->r.framelen= 1.0f;
        cfrao= G.scene->r.cfra;
-       sfo= ob->sf;
+       sfo= ob->sf; /* warning, dont use sfo, value should be from give_timeoffset if used for anything */
        ob->sf= 0.0f;
 
        /* clear storage, copy recalc tag (bad loop) */
index 3a64f8c8c347ff110a16869ff775d008a3ec6407..b29cf63ab0b72492297eba34ccb2029d1507b0dd 100644 (file)
@@ -241,12 +241,12 @@ void group_handle_recalc_and_update(Object *parent, Group *group)
        GroupObject *go;
        
        /* if animated group... */
-       if(parent->sf != 0.0f || parent->nlastrips.first) {
+       if(give_timeoffset(parent) != 0.0f || parent->nlastrips.first) {
                int cfrao;
                
                /* switch to local time */
                cfrao= G.scene->r.cfra;
-               G.scene->r.cfra -= (int)parent->sf;
+               G.scene->r.cfra -= (int)give_timeoffset(parent);
                
                /* we need a DAG per group... */
                for(go= group->gobject.first; go; go= go->next) {
index 3ac4a572b960657484bf2e5eca2865dcbfe02c41..70be6d2c79bf74a8830d2224657b3b8102b0b874 100644 (file)
@@ -1367,7 +1367,7 @@ float bsystem_time(Object *ob, float cfra, float ofs)
                
                /* ofset frames */
                if ((ob->ipoflag & OB_OFFS_PARENT) && (ob->partype & PARSLOW)==0) 
-                       cfra-= ob->sf;
+                       cfra-= give_timeoffset(ob);
        }
        
        cfra-= ofs;
@@ -1438,7 +1438,7 @@ static void ob_parcurve(Object *ob, Object *par, float mat[][4])
 {
        Curve *cu;
        float q[4], vec[4], dir[3], *quat, x1, ctime;
-       float timeoffs= 0.0;
+       float timeoffs, sf_orig = 0.0;
        
        Mat4One(mat);
        
@@ -1449,7 +1449,8 @@ static void ob_parcurve(Object *ob, Object *par, float mat[][4])
        
        /* exception, timeoffset is regarded as distance offset */
        if(cu->flag & CU_OFFS_PATHDIST) {
-               SWAP(float, timeoffs, ob->sf);
+               timeoffs = give_timeoffset(ob);
+               SWAP(float, sf_orig, ob->sf);
        }
        
        /* catch exceptions: feature for nla stride editing */
@@ -1466,7 +1467,7 @@ static void ob_parcurve(Object *ob, Object *par, float mat[][4])
                }
        }
        else {
-               ctime= G.scene->r.cfra - ob->sf;
+               ctime= G.scene->r.cfra - give_timeoffset(ob);
                ctime /= cu->pathlen;
                
                CLAMP(ctime, 0.0, 1.0);
@@ -1477,7 +1478,7 @@ static void ob_parcurve(Object *ob, Object *par, float mat[][4])
                ctime += timeoffs/cu->path->totdist;
 
                /* restore */
-               SWAP(float, timeoffs, ob->sf);
+               SWAP(float, sf_orig, ob->sf);
        }
        
        
@@ -1735,7 +1736,7 @@ void where_is_object_time(Object *ob, float ctime)
        if(ob->parent) {
                Object *par= ob->parent;
                
-               if(ob->ipoflag & OB_OFFS_PARENT) ctime-= ob->sf;
+               if(ob->ipoflag & OB_OFFS_PARENT) ctime-= give_timeoffset(ob);
                
                /* hurms, code below conflicts with depgraph... (ton) */
                /* and even worse, it gives bad effects for NLA stride too (try ctime != par->ctime, with MBlur) */
@@ -1759,7 +1760,7 @@ void where_is_object_time(Object *ob, float ctime)
                if(ob->partype & PARSLOW) {
                        // include framerate
 
-                       fac1= (1.0f/(1.0f+ fabs(ob->sf)));
+                       fac1= (1.0f/(1.0f+ fabs(give_timeoffset(ob))));
                        if(fac1>=1.0) return;
                        fac2= 1.0f-fac1;
                        
@@ -1942,7 +1943,7 @@ for a lamp that is the child of another object */
 
                if(ob->partype & PARSLOW) {
 
-                       fac1= (float)(1.0/(1.0+ fabs(ob->sf)));
+                       fac1= (float)(1.0/(1.0+ fabs(give_timeoffset(ob))));
                        fac2= 1.0f-fac1;
                        fp1= ob->obmat[0];
                        fp2= slowmat[0];
@@ -2247,3 +2248,11 @@ void object_handle_update(Object *ob)
                // printf("set proxy pointer for later group stuff %s\n", ob->id.name);
        }
 }
+
+float give_timeoffset(Object *ob) {
+       if ((ob->ipoflag & OB_OFFS_PARENTADD) && ob->parent) {
+               return ob->sf + give_timeoffset(ob->parent);
+       } else {
+               return ob->sf;
+       }
+}
\ No newline at end of file
index 565b2cfd67891d70551998112bc51edda34f150c..f3a0dfdfdc754ad76d95be4a2c91b5c6ad5f04d4 100644 (file)
@@ -297,6 +297,9 @@ extern Object workob;
        /* for stride edit */
 #define OB_DISABLE_PATH                1024
 
+#define OB_OFFS_PARENTADD      2048
+
+
 /* (short) trackflag / upflag */
 #define OB_POSX                        0
 #define OB_POSY                        1
index 1dcc2279ee24bdee4400dc9b838a5252848eec48..43c86ebe6340e560709a6cd90abb65fce2232f76 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: Effect.c 11485 2007-08-05 09:21:29Z aligorith $
+ * $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
@@ -1330,7 +1330,7 @@ static PyObject *Effect_getParticlesLoc( BPy_Effect * self )
 
        /* if object is in motion */
        if( ob->ipoflag & OB_OFFS_PARTICLE )
-               p_time= ob->sf;
+               p_time= give_timeoffset(ob);
        else
                p_time= 0.0;
 
index 0ff1e3dd40d98c62754f37d0849d677e11a32a9e..f659611c2bee3ecf414ce244262b54153b79746a 100644 (file)
@@ -2494,21 +2494,25 @@ static void object_panel_anim(Object *ob)
        uiDefButI(block, NUM, REDRAWVIEW3D, "DupOn:",           170,85,146,19, &ob->dupon, 1.0, 1500.0, 0, 0, "Specify the number of frames to use between DupOff frames");
        uiDefButI(block, NUM, REDRAWVIEW3D, "DupEnd",           24,65,140,19, &ob->dupend, 1.0, 32767, 0, 0, "Specify endframe for Dupliframes");
        uiDefButI(block, NUM, REDRAWVIEW3D, "DupOff",           171,65,145,19, &ob->dupoff, 0.0, 1500.0, 0, 0, "Specify recurring frames to exclude from the Dupliframes");
+       uiBlockEndAlign(block);
+       
        uiBlockBeginAlign(block);
-       uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "Offs Ob",                      24,35,56,20, &ob->ipoflag, 0, 0, 0, 0, "Not functional at the moment!");
-       uiDefButBitS(block, TOG, OB_OFFS_PARENT, REDRAWALL, "Offs Par",                 82,35,56,20 , &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the parent");
-       uiDefButBitS(block, TOG, OB_OFFS_PARTICLE, REDRAWALL, "Offs Particle",          140,35,103,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the particle effect");
+       uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,35,115,20, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Animation offset in frames for ipo's and dupligroup instances");
+       uiDefBut(block, BUT, B_AUTOTIMEOFS, "Auto",     139,35,34,20, 0, 0, 0, 0, 0, "Assign selected objects a timeoffset within a range, starting from the active object");
+       uiDefBut(block, BUT, B_OFSTIMEOFS, "Ofs",       173,35,34,20, 0, 0, 0, 0, 0, "Offset selected objects timeoffset");
+       uiDefBut(block, BUT, B_RANDTIMEOFS, "Rand",     207,35,34,20, 0, 0, 0, 0, 0, "Randomize selected objects timeoffset");
+       uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      250,35,65,20, 0, 0, 0, 0, 0, "Print objectspeed");
+       uiBlockEndAlign(block);
        
        uiBlockBeginAlign(block);
-       uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,10,115,20, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Animation offset in frames for ipo's and dupligroup instances");
-       uiDefBut(block, BUT, B_AUTOTIMEOFS, "Auto",     139,10,34,20, 0, 0, 0, 0, 0, "Assign selected objects a timeoffset within a range, starting from the active object");
-       uiDefBut(block, BUT, B_OFSTIMEOFS, "Ofs",       173,10,34,20, 0, 0, 0, 0, 0, "Offset selected objects timeoffset");
-       uiDefBut(block, BUT, B_RANDTIMEOFS, "Rand",     207,10,34,20, 0, 0, 0, 0, 0, "Randomize selected objects timeoffset");
-       uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      250,10,65,20, 0, 0, 0, 0, 0, "Print objectspeed");
+       uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "OfsEdit",                      24,10,56,20, &ob->ipoflag, 0, 0, 0, 0, "Use timeoffset when inserting keys and display timeoffset for ipo and action views");
+       uiDefButBitS(block, TOG, OB_OFFS_PARENT, REDRAWALL, "OfsParent",                        82,10,56,20 , &ob->ipoflag, 0, 0, 0, 0, "Apply the timeoffset to this objects parent relationship");
+       uiDefButBitS(block, TOG, OB_OFFS_PARTICLE, REDRAWALL, "OfsParticle",            140,10,56,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the particle effect");
+       uiDefButBitS(block, TOG, OB_OFFS_PARENTADD, REDRAWALL, "AddParent",             196,10,56,20, &ob->ipoflag, 0, 0, 0, 0, "Add the parents timeoffset value");
        uiBlockEndAlign(block);
        
        sprintf(str, "%.4f", prspeed);
-       uiDefBut(block, LABEL, 0, str,                                                  247,35,63,31, NULL, 1.0, 0, 0, 0, "");
+       uiDefBut(block, LABEL, 0, str,                                                  260,10,63,31, NULL, 1.0, 0, 0, 0, "");
        
 }
 
index 2b280864f1cdd633c69b24ce3c4410d28628b09d..42b0b0bda3b46503b9160574bdd8de26f32acc1a 100644 (file)
@@ -374,8 +374,8 @@ void draw_cfra_action (void)
        
        /* Draw dark green line if slow-parenting/time-offset is enabled */
        ob= (G.scene->basact) ? (G.scene->basact->object) : 0;
-       if ((ob) && (ob->sf!=0.0) && (ob->ipoflag & OB_OFFS_OB)) {
-               vec[0]-= ob->sf;
+       if ((ob) && (ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0)) {
+               vec[0]-= give_timeoffset(ob); /* could avoid calling twice */
                
                BIF_ThemeColorShade(TH_CFRAME, -30);
                
index 07442a541a5ba907ad67cc3927c00238722678c7..d5040bf0a5186dbd55f4632d42a2b9bdea85796c 100644 (file)
@@ -1571,8 +1571,8 @@ static void draw_cfra(SpaceIpo *sipo)
        
        if(sipo->blocktype==ID_OB) {
                ob= (G.scene->basact) ? (G.scene->basact->object) : 0;
-               if (ob && (ob->sf!=0.0) && (ob->ipoflag & OB_OFFS_OB) ) {
-                       vec[0]-= ob->sf;
+               if (ob && (ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0)) { 
+                       vec[0]-= give_timeoffset(ob);
                        
                        BIF_ThemeColorShade(TH_HILITE, -30);
                        
index 3e154298517daf3184a572f99bf8e902761e7257..1d30815f29ad6c86db6a25ec4cf4029e0c84cfd6 100644 (file)
@@ -2857,7 +2857,7 @@ static void draw_particle_system(Base *base, PartEff *paf)
                mymultmatrix(mat);
        }
        
-       if(ob->ipoflag & OB_OFFS_PARTICLE) ptime= ob->sf;
+       if(ob->ipoflag & OB_OFFS_PARTICLE) ptime= give_timeoffset(ob);
        else ptime= 0.0;
        ctime= bsystem_time(ob, (float)(G.scene->r.cfra), ptime);
 
@@ -5248,7 +5248,7 @@ void draw_object(Base *base, int flag)
                                        for (ct= targets.first; ct; ct= ct->next) {
                                                /* calculate target's matrix */
                                                if (cti->get_target_matrix) 
-                                                       cti->get_target_matrix(curcon, cob, ct, bsystem_time(ob, (float)(G.scene->r.cfra), ob->sf));
+                                                       cti->get_target_matrix(curcon, cob, ct, bsystem_time(ob, (float)(G.scene->r.cfra), give_timeoffset(ob)));
                                                else
                                                        Mat4One(ct->matrix);
                                                
index f6ef0eaadb2cde528f22c3694fed0f469f373372..22eea8190770fac2042edd31e9b098b8d54ce91b 100644 (file)
@@ -2335,9 +2335,9 @@ static void insertkey_nonrecurs(ID *id, int blocktype, char *actname, char *cons
                                
                                if( GS(id->name)==ID_OB ) {
                                        ob= (Object *)id;
-                                       if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
+                                       if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
                                                /* actually frametofloat calc again! */
-                                               cfra-= ob->sf*G.scene->r.framelen;
+                                               cfra-= give_timeoffset(ob)*G.scene->r.framelen;
                                        }
                                }
                                
@@ -2556,9 +2556,9 @@ void insertkey(ID *id, int blocktype, char *actname, char *constname, int adrcod
                                
                                if( GS(id->name)==ID_OB ) {
                                        ob= (Object *)id;
-                                       if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
+                                       if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
                                                /* actually frametofloat calc again! */
-                                               cfra-= ob->sf*G.scene->r.framelen;
+                                               cfra-= give_timeoffset(ob)*G.scene->r.framelen;
                                        }
                                }
                                
@@ -2598,9 +2598,9 @@ void insertkey_smarter(ID *id, int blocktype, char *actname, char *constname, in
                        
                        if( GS(id->name)==ID_OB ) {
                                ob= (Object *)id;
-                               if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
+                               if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
                                        /* actually frametofloat calc again! */
-                                       cfra-= ob->sf*G.scene->r.framelen;
+                                       cfra-= give_timeoffset(ob)*G.scene->r.framelen;
                                }
                        }
                        
@@ -2649,9 +2649,9 @@ void insertfloatkey(ID *id, int blocktype, char *actname, char *constname, int a
                        
                        if( GS(id->name)==ID_OB ) {
                                ob= (Object *)id;
-                               if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
+                               if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
                                        /* actually frametofloat calc again! */
-                                       cfra-= ob->sf*G.scene->r.framelen;
+                                       cfra-= give_timeoffset(ob)*G.scene->r.framelen;
                                }
                        }
                        
@@ -2731,8 +2731,8 @@ void insertkey_editipo(void)
                                                id= G.sipo->from;       
                                                if(id && GS(id->name)==ID_OB ) {
                                                        Object *ob= (Object *)id;
-                                                       if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
-                                                               cfra-= ob->sf*G.scene->r.framelen;
+                                                       if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
+                                                               cfra-= give_timeoffset(ob)*G.scene->r.framelen;
                                                        }
                                                }
                                                else if(id && GS(id->name)==ID_SEQ) {
@@ -5769,8 +5769,8 @@ void move_to_frame(void)
                                                        id= G.sipo->from;
                                                        if(id && GS(id->name)==ID_OB ) {
                                                                Object *ob= (Object *)id;
-                                                               if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
-                                                                       cfra+= ob->sf/G.scene->r.framelen;
+                                                               if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
+                                                                       cfra+= give_timeoffset(ob)/G.scene->r.framelen;
                                                                }
                                                        }
                                                        CFRA= (int)floor(cfra+0.5);
index bbdcfc428ddf04645e4ef004ae3309c5a9e8ae32..90b0e8c048eb89a74475e091f1b64bb850ea5fed 100644 (file)
@@ -1430,7 +1430,7 @@ void make_parent(void)
                                                
                                                add_constraint_to_object(con, base->object);
                                                
-                                               get_constraint_target_matrix(con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, G.scene->r.cfra - base->object->sf);
+                                               get_constraint_target_matrix(con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, G.scene->r.cfra - give_timeoffset(base->object));
                                                VecSubf(vec, base->object->obmat[3], cmat[3]);
                                                
                                                base->object->loc[0] = vec[0];