Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/armature/armature_relations.c
| Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | static void joined_armature_fix_links_constraints(Main *bmain, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| EditBone *curbone, | EditBone *curbone, | ||||
| ListBase *lb) | ListBase *lb) | ||||
| { | { | ||||
| bConstraint *con; | bConstraint *con; | ||||
| bool changed = false; | bool changed = false; | ||||
| for (con = lb->first; con; con = con->next) { | for (con = lb->first; con; con = con->next) { | ||||
| const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); | |||||
| ListBase targets = {NULL, NULL}; | ListBase targets = {NULL, NULL}; | ||||
| bConstraintTarget *ct; | bConstraintTarget *ct; | ||||
| /* constraint targets */ | /* constraint targets */ | ||||
| if (cti && cti->get_constraint_targets) { | if (BKE_constraint_targets_get(con, &targets)) { | ||||
| cti->get_constraint_targets(con, &targets); | |||||
| for (ct = targets.first; ct; ct = ct->next) { | for (ct = targets.first; ct; ct = ct->next) { | ||||
| if (ct->tar == srcArm) { | if (ct->tar == srcArm) { | ||||
| if (ct->subtarget[0] == '\0') { | if (ct->subtarget[0] == '\0') { | ||||
| ct->tar = tarArm; | ct->tar = tarArm; | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| else if (STREQ(ct->subtarget, pchan->name)) { | else if (STREQ(ct->subtarget, pchan->name)) { | ||||
| ct->tar = tarArm; | ct->tar = tarArm; | ||||
| BLI_strncpy(ct->subtarget, curbone->name, sizeof(ct->subtarget)); | BLI_strncpy(ct->subtarget, curbone->name, sizeof(ct->subtarget)); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (cti->flush_constraint_targets) { | BKE_constraint_targets_flush(con, &targets, 0); | ||||
| cti->flush_constraint_targets(con, &targets, 0); | |||||
| } | |||||
| } | } | ||||
| /* action constraint? (pose constraints only) */ | /* action constraint? (pose constraints only) */ | ||||
| if (con->type == CONSTRAINT_TYPE_ACTION) { | if (con->type == CONSTRAINT_TYPE_ACTION) { | ||||
| bActionConstraint *data = con->data; | bActionConstraint *data = con->data; | ||||
| if (data->act) { | if (data->act) { | ||||
| BKE_action_fix_paths_rename( | BKE_action_fix_paths_rename( | ||||
| ▲ Show 20 Lines • Show All 341 Lines • ▼ Show 20 Lines | static void separated_armature_fix_links(Main *bmain, Object *origArm, Object *newArm) | ||||
| npchans = &newArm->pose->chanbase; | npchans = &newArm->pose->chanbase; | ||||
| /* let's go through all objects in database */ | /* let's go through all objects in database */ | ||||
| for (ob = bmain->objects.first; ob; ob = ob->id.next) { | for (ob = bmain->objects.first; ob; ob = ob->id.next) { | ||||
| /* do some object-type specific things */ | /* do some object-type specific things */ | ||||
| if (ob->type == OB_ARMATURE) { | if (ob->type == OB_ARMATURE) { | ||||
| for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { | for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { | ||||
| for (con = pchan->constraints.first; con; con = con->next) { | for (con = pchan->constraints.first; con; con = con->next) { | ||||
| const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); | |||||
| ListBase targets = {NULL, NULL}; | ListBase targets = {NULL, NULL}; | ||||
| bConstraintTarget *ct; | bConstraintTarget *ct; | ||||
| /* constraint targets */ | /* constraint targets */ | ||||
| if (cti && cti->get_constraint_targets) { | if (BKE_constraint_targets_get(con, &targets)) { | ||||
| cti->get_constraint_targets(con, &targets); | |||||
| for (ct = targets.first; ct; ct = ct->next) { | for (ct = targets.first; ct; ct = ct->next) { | ||||
| /* Any targets which point to original armature | /* Any targets which point to original armature | ||||
| * are redirected to the new one only if: | * are redirected to the new one only if: | ||||
| * - The target isn't origArm/newArm itself. | * - The target isn't origArm/newArm itself. | ||||
| * - The target is one that can be found in newArm/origArm. | * - The target is one that can be found in newArm/origArm. | ||||
| */ | */ | ||||
| if (ct->subtarget[0] != 0) { | if (ct->subtarget[0] != 0) { | ||||
| if (ct->tar == origArm) { | if (ct->tar == origArm) { | ||||
| if (BLI_findstring(npchans, ct->subtarget, offsetof(bPoseChannel, name))) { | if (BLI_findstring(npchans, ct->subtarget, offsetof(bPoseChannel, name))) { | ||||
| ct->tar = newArm; | ct->tar = newArm; | ||||
| } | } | ||||
| } | } | ||||
| else if (ct->tar == newArm) { | else if (ct->tar == newArm) { | ||||
| if (BLI_findstring(opchans, ct->subtarget, offsetof(bPoseChannel, name))) { | if (BLI_findstring(opchans, ct->subtarget, offsetof(bPoseChannel, name))) { | ||||
| ct->tar = origArm; | ct->tar = origArm; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (cti->flush_constraint_targets) { | BKE_constraint_targets_flush(con, &targets, 0); | ||||
| cti->flush_constraint_targets(con, &targets, 0); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* fix object-level constraints */ | /* fix object-level constraints */ | ||||
| if (ob != origArm) { | if (ob != origArm) { | ||||
| for (con = ob->constraints.first; con; con = con->next) { | for (con = ob->constraints.first; con; con = con->next) { | ||||
| const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); | |||||
| ListBase targets = {NULL, NULL}; | ListBase targets = {NULL, NULL}; | ||||
| bConstraintTarget *ct; | bConstraintTarget *ct; | ||||
| /* constraint targets */ | /* constraint targets */ | ||||
| if (cti && cti->get_constraint_targets) { | if (BKE_constraint_targets_get(con, &targets)) { | ||||
| cti->get_constraint_targets(con, &targets); | |||||
| for (ct = targets.first; ct; ct = ct->next) { | for (ct = targets.first; ct; ct = ct->next) { | ||||
| /* any targets which point to original armature are redirected to the new one only if: | /* any targets which point to original armature are redirected to the new one only if: | ||||
| * - the target isn't origArm/newArm itself | * - the target isn't origArm/newArm itself | ||||
| * - the target is one that can be found in newArm/origArm | * - the target is one that can be found in newArm/origArm | ||||
| */ | */ | ||||
| if (ct->subtarget[0] != '\0') { | if (ct->subtarget[0] != '\0') { | ||||
| if (ct->tar == origArm) { | if (ct->tar == origArm) { | ||||
| if (BLI_findstring(npchans, ct->subtarget, offsetof(bPoseChannel, name))) { | if (BLI_findstring(npchans, ct->subtarget, offsetof(bPoseChannel, name))) { | ||||
| ct->tar = newArm; | ct->tar = newArm; | ||||
| } | } | ||||
| } | } | ||||
| else if (ct->tar == newArm) { | else if (ct->tar == newArm) { | ||||
| if (BLI_findstring(opchans, ct->subtarget, offsetof(bPoseChannel, name))) { | if (BLI_findstring(opchans, ct->subtarget, offsetof(bPoseChannel, name))) { | ||||
| ct->tar = origArm; | ct->tar = origArm; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (cti->flush_constraint_targets) { | BKE_constraint_targets_flush(con, &targets, 0); | ||||
| cti->flush_constraint_targets(con, &targets, 0); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* See if an object is parented to this armature */ | /* See if an object is parented to this armature */ | ||||
| if (ob->parent && (ob->parent == origArm)) { | if (ob->parent && (ob->parent == origArm)) { | ||||
| /* Is object parented to a bone of this src armature? */ | /* Is object parented to a bone of this src armature? */ | ||||
| if ((ob->partype == PARBONE) && (ob->parsubstr[0] != '\0')) { | if ((ob->partype == PARBONE) && (ob->parsubstr[0] != '\0')) { | ||||
| ▲ Show 20 Lines • Show All 555 Lines • Show Last 20 Lines | |||||