Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_constraint.c
| Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | |||||
| * \{ */ | * \{ */ | ||||
| /* helper function for add_constriant - sets the last target for the active constraint */ | /* helper function for add_constriant - sets the last target for the active constraint */ | ||||
| static void set_constraint_nth_target(bConstraint *con, | static void set_constraint_nth_target(bConstraint *con, | ||||
| Object *target, | Object *target, | ||||
| const char subtarget[], | const char subtarget[], | ||||
| int index) | int index) | ||||
| { | { | ||||
| const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); | |||||
| ListBase targets = {NULL, NULL}; | ListBase targets = {NULL, NULL}; | ||||
| bConstraintTarget *ct; | bConstraintTarget *ct; | ||||
| int num_targets, i; | int num_targets, i; | ||||
| if (cti && cti->get_constraint_targets) { | if (BKE_constraint_targets_get(con, &targets)) { | ||||
| cti->get_constraint_targets(con, &targets); | |||||
| num_targets = BLI_listbase_count(&targets); | num_targets = BLI_listbase_count(&targets); | ||||
| if (index < 0) { | if (index < 0) { | ||||
| if (abs(index) < num_targets) { | if (abs(index) < num_targets) { | ||||
| index = num_targets - abs(index); | index = num_targets - abs(index); | ||||
| } | } | ||||
| else { | else { | ||||
| index = num_targets - 1; | index = num_targets - 1; | ||||
| } | } | ||||
| } | } | ||||
| else if (index >= num_targets) { | else if (index >= num_targets) { | ||||
| index = num_targets - 1; | index = num_targets - 1; | ||||
| } | } | ||||
| for (ct = targets.first, i = 0; ct; ct = ct->next, i++) { | for (ct = targets.first, i = 0; ct; ct = ct->next, i++) { | ||||
| if (i == index) { | if (i == index) { | ||||
| ct->tar = target; | ct->tar = target; | ||||
| BLI_strncpy(ct->subtarget, subtarget, sizeof(ct->subtarget)); | BLI_strncpy(ct->subtarget, subtarget, sizeof(ct->subtarget)); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (cti->flush_constraint_targets) { | BKE_constraint_targets_flush(con, &targets, 0); | ||||
| cti->flush_constraint_targets(con, &targets, 0); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* ------------------------------------------------------------------- */ | /* ------------------------------------------------------------------- */ | ||||
| /** \name Constraint Sanity Testing | /** \name Constraint Sanity Testing | ||||
| * \{ */ | * \{ */ | ||||
| static void test_constraint( | static void test_constraint( | ||||
| Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type) | Main *bmain, Object *owner, bPoseChannel *pchan, bConstraint *con, int type) | ||||
| { | { | ||||
| const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); | |||||
| ListBase targets = {NULL, NULL}; | ListBase targets = {NULL, NULL}; | ||||
| bConstraintTarget *ct; | bConstraintTarget *ct; | ||||
| bool check_targets = true; | bool check_targets = true; | ||||
| /* clear disabled-flag first */ | /* clear disabled-flag first */ | ||||
| con->flag &= ~CONSTRAINT_DISABLE; | con->flag &= ~CONSTRAINT_DISABLE; | ||||
| if (con->type == CONSTRAINT_TYPE_KINEMATIC) { | if (con->type == CONSTRAINT_TYPE_KINEMATIC) { | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | else if (con->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) { | ||||
| bTransformCacheConstraint *data = con->data; | bTransformCacheConstraint *data = con->data; | ||||
| if ((data->cache_file == NULL) || (data->object_path[0] == '\0')) { | if ((data->cache_file == NULL) || (data->object_path[0] == '\0')) { | ||||
| con->flag |= CONSTRAINT_DISABLE; | con->flag |= CONSTRAINT_DISABLE; | ||||
| } | } | ||||
| } | } | ||||
| /* Check targets for constraints */ | /* Check targets for constraints */ | ||||
| if (check_targets && cti && cti->get_constraint_targets) { | if (check_targets && BKE_constraint_targets_get(con, &targets)) { | ||||
| cti->get_constraint_targets(con, &targets); | |||||
| /* constraints with empty target list that actually require targets */ | |||||
| if (!targets.first && ELEM(con->type, CONSTRAINT_TYPE_ARMATURE)) { | |||||
| con->flag |= CONSTRAINT_DISABLE; | |||||
| } | |||||
| /* disable and clear constraints targets that are incorrect */ | /* disable and clear constraints targets that are incorrect */ | ||||
| for (ct = targets.first; ct; ct = ct->next) { | for (ct = targets.first; ct; ct = ct->next) { | ||||
| /* general validity checks (for those constraints that need this) */ | /* general validity checks (for those constraints that need this) */ | ||||
| if (BKE_object_exists_check(bmain, ct->tar) == 0) { | if (BKE_object_exists_check(bmain, ct->tar) == 0) { | ||||
| /* object doesn't exist, but constraint requires target */ | /* object doesn't exist, but constraint requires target */ | ||||
| ct->tar = NULL; | ct->tar = NULL; | ||||
| con->flag |= CONSTRAINT_DISABLE; | con->flag |= CONSTRAINT_DISABLE; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | for (ct = targets.first; ct; ct = ct->next) { | ||||
| /* bone must exist in armature... */ | /* bone must exist in armature... */ | ||||
| con->flag |= CONSTRAINT_DISABLE; | con->flag |= CONSTRAINT_DISABLE; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* free any temporary targets */ | /* free any temporary targets */ | ||||
| if (cti->flush_constraint_targets) { | BKE_constraint_targets_flush(con, &targets, 0); | ||||
| cti->flush_constraint_targets(con, &targets, 0); | } | ||||
| else if (check_targets) { | |||||
| /* constraints with empty target list that actually require targets */ | |||||
| if (ELEM(con->type, CONSTRAINT_TYPE_ARMATURE)) { | |||||
| con->flag |= CONSTRAINT_DISABLE; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static int constraint_type_get(Object *owner, bPoseChannel *pchan) | static int constraint_type_get(Object *owner, bPoseChannel *pchan) | ||||
| { | { | ||||
| int type; | int type; | ||||
| /* Check parents */ | /* Check parents */ | ||||
| ▲ Show 20 Lines • Show All 2,216 Lines • Show Last 20 Lines | |||||