fix [#26607] blender won't duplicate or assign new drivers on duplication
authorCampbell Barton <ideasman42@gmail.com>
Fri, 25 Mar 2011 07:34:44 +0000 (07:34 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 25 Mar 2011 07:34:44 +0000 (07:34 +0000)
source/blender/blenkernel/BKE_animsys.h
source/blender/blenkernel/intern/anim_sys.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_relations.c
source/blender/makesdna/DNA_anim_types.h

index a469d05ee265bd932f9cc9a06595d5f20f6275f5..348b967f9c423150033846bbda8a92df45c17f22 100644 (file)
@@ -72,6 +72,9 @@ void BKE_copy_animdata_id_action(struct ID *id);
 /* Make Local */
 void BKE_animdata_make_local(struct AnimData *adt);
 
+/* Re-Assign ID's */
+void BKE_relink_animdata(struct AnimData *adt);
+
 /* ************************************* */
 /* KeyingSets API */
 
index 16269c3f66f79389ebca74bf73bb49c0d5fd9e17..b4adaa0ab07839c1c2b254a0c8bf4f97c73a7379 100644 (file)
@@ -282,6 +282,32 @@ void BKE_animdata_make_local(AnimData *adt)
                make_local_strips(&nlt->strips);
 }
 
+void BKE_relink_animdata(struct AnimData *adt)
+{
+       /* drivers */
+       if (adt->drivers.first) {
+               FCurve *fcu;
+
+               /* check each driver against all the base paths to see if any should go */
+               for (fcu= adt->drivers.first; fcu; fcu=fcu->next) {
+                       ChannelDriver *driver= fcu->driver;
+                       DriverVar *dvar;
+
+                       /* driver variables */
+                       for (dvar= driver->variables.first; dvar; dvar=dvar->next) {
+                               /* only change the used targets, since the others will need fixing manually anyway */
+                               DRIVER_TARGETS_USED_LOOPER(dvar)
+                               {
+                                       if(dtar->id->newid) {
+                                               dtar->id= dtar->id->newid;
+                                       }
+                               }
+                               DRIVER_TARGETS_LOOPER_END
+                       }
+               }
+       }
+}
+
 /* Sub-ID Regrouping ------------------------------------------- */
 
 /* helper heuristic for determining if a path is compatible with the basepath 
index 2463e17d49f1a41d56126a450a8875d35b04f97b..289a66a1484db77a9ba996694fe2980ebe1c419d 100644 (file)
@@ -868,6 +868,10 @@ static void copy_object_set_idnew(bContext *C, int dupflag)
                        }
                }
                modifiers_foreachIDLink(ob, copy_object__forwardModifierLinks, NULL);
+
+               if(ob->adt)
+                       BKE_relink_animdata(ob->adt);
+
                ID_NEW(ob->parent);
                ID_NEW(ob->proxy);
                ID_NEW(ob->proxy_group);
index 7938096c2a623f068b4baddb5e54b1afbe2cff1b..eccc826f01f82a54e5812b1980ddbb2b5ae3e38c 100644 (file)
@@ -1412,7 +1412,10 @@ static void single_object_users(Scene *scene, View3D *v3d, int flag)
                                }
                        }
                        modifiers_foreachObjectLink(base->object, single_object_users__forwardModifierLinks, NULL);
-                       
+
+                       if(ob->adt)
+                               BKE_relink_animdata(ob->adt);
+
                        ID_NEW(ob->parent);
                }
        }
index 31e02ff1877e46ab65bca6481c88f7a6a9812328..4b649031f97eea39471ed69bc6b8b71801c4f80d 100644 (file)
@@ -261,7 +261,7 @@ typedef enum eFMod_Stepped_Flags {
  * Defines how to access a dependency needed for a driver variable.
  */
 typedef struct DriverTarget {
-       ID      *id;                            /* ID-block which owns the target */
+       ID      *id;                            /* ID-block which owns the target, no user count */
        
        char *rna_path;                 /* RNA path defining the setting to use (for DVAR_TYPE_SINGLE_PROP) */