Proxy ID property syncing

This means pose bones on proxy poses can have their own values as long as the name and type matches that of the library pose bone.
without this the only way to add new values on a pose bone proxy is to protect in the lib, reload the proxy blend and save.
This commit is contained in:
Campbell Barton
2010-02-15 18:43:54 +00:00
parent 50cd69d8d9
commit c5bcbad779
3 changed files with 72 additions and 1 deletions

View File

@@ -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.
*/

View File

@@ -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);
}
}
}
}
}

View File

@@ -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.
*/