diff options
-rw-r--r-- | source/blender/blenkernel/BKE_idprop.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 43 |
3 files changed, 72 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index ec52a317ea0..9634b872e91 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -82,6 +82,9 @@ void IDP_UnlinkID(struct IDProperty *prop); /*-------- Group Functions -------*/ +/* Sync values from one group to another, only where they match */ +void IDP_SyncGroupValues(struct IDProperty *dest, struct IDProperty *src); + /* replaces all properties with the same name in a destination group from a source group. */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 4355d7a0b10..b568991742e 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -1529,9 +1529,15 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected pchanw.path= NULL; /* this is freed so copy a copy, else undo crashes */ - if(pchanw.prop) + if(pchanw.prop) { pchanw.prop= IDP_CopyProperty(pchanw.prop); + /* use the values from the the existing props */ + if(pchan->prop) { + IDP_SyncGroupValues(pchanw.prop, pchan->prop); + } + } + /* constraints - proxy constraints are flushed... local ones are added after * 1. extract constraints not from proxy (CONSTRAINT_PROXY_LOCAL) from pchan's constraints * 2. copy proxy-pchan's constraints on-to new @@ -1570,6 +1576,25 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected /* always copy custom shape */ pchan->custom= pchanp->custom; pchan->custom_tx= pchanp->custom_tx; + + /* ID-Property Syncing */ + { + IDProperty *prop_orig= pchan->prop; + if(pchanp->prop) { + pchan->prop= IDP_CopyProperty(pchanp->prop); + if(prop_orig) { + /* copy existing values across when types match */ + IDP_SyncGroupValues(pchan->prop, prop_orig); + } + } + else { + pchan->prop= NULL; + } + if (prop_orig) { + IDP_FreeProperty(prop_orig); + MEM_freeN(prop_orig); + } + } } } } diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 07a717cc419..37aee8fb4aa 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -385,6 +385,49 @@ IDProperty *IDP_CopyGroup(IDProperty *prop) return newp; } +/* use for syncing proxies. + * When values name and types match, copy the values, else ignore */ +void IDP_SyncGroupValues(IDProperty *dest, IDProperty *src) +{ + IDProperty *loop, *prop; + for (prop=src->data.group.first; prop; prop=prop->next) { + for (loop=dest->data.group.first; loop; loop=loop->next) { + if (BSTR_EQ(loop->name, prop->name)) { + int copy_done= 0; + + if(prop->type==loop->type) { + + switch (prop->type) { + case IDP_INT: + case IDP_FLOAT: + case IDP_DOUBLE: + loop->data= prop->data; + copy_done= 1; + break; + case IDP_GROUP: + IDP_SyncGroupValues(loop, prop); + copy_done= 1; + break; + default: + { + IDProperty *tmp= loop; + IDProperty *copy= IDP_CopyProperty(prop); + + BLI_insertlinkafter(&dest->data.group, loop, copy); + BLI_remlink(&dest->data.group, tmp); + loop = copy; + + IDP_FreeProperty(tmp); + MEM_freeN(tmp); + } + } + } + break; + } + } + } +} + /* replaces all properties with the same name in a destination group from a source group. */ |