diff options
-rw-r--r-- | source/blender/blenkernel/BKE_constraint.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 33 | ||||
-rw-r--r-- | source/blender/editors/armature/armature_add.c | 6 |
3 files changed, 24 insertions, 25 deletions
diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h index 737b05fee0c..2be299f5b0c 100644 --- a/source/blender/blenkernel/BKE_constraint.h +++ b/source/blender/blenkernel/BKE_constraint.h @@ -334,7 +334,15 @@ void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, struct bConstraintOb *ob, struct ListBase *targets, float ctime); -void BKE_constraint_custom_object_space_get(float r_mat[4][4], struct bConstraint *con); + +/** + * Initializes the custom coordinate space data if required by the constraint. + * + * \param cob Constraint evaluation context (contains the matrix to be initialized). + * \param con Constraint that is about to be evaluated. + */ +void BKE_constraint_custom_object_space_init(struct bConstraintOb *cob, struct bConstraint *con); + /** * This function is called whenever constraints need to be evaluated. Currently, all * constraints that can be evaluated are every time this gets run. diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index aa09541c043..cee32dc557b 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -6323,33 +6323,24 @@ void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, } } -void BKE_constraint_custom_object_space_get(float r_mat[4][4], bConstraint *con) +/** Initialize the Custom Space matrix inside cob. */ +void BKE_constraint_custom_object_space_init(bConstraintOb *cob, bConstraint *con) { - if (!con || - (con->ownspace != CONSTRAINT_SPACE_CUSTOM && con->tarspace != CONSTRAINT_SPACE_CUSTOM)) { - return; - } - bConstraintTarget *ct; - ListBase target = {NULL, NULL}; - SINGLETARGET_GET_TARS(con, con->space_object, con->space_subtarget, ct, &target); - - /* Basically default_get_tarmat but without the unused parameters. */ - if (VALID_CONS_TARGET(ct)) { - constraint_target_to_mat4(ct->tar, - ct->subtarget, + if (con && con->space_object && is_custom_space_needed(con)) { + /* Basically default_get_tarmat but without the unused parameters. */ + constraint_target_to_mat4(con->space_object, + con->space_subtarget, NULL, - ct->matrix, + cob->space_obj_world_matrix, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_WORLD, 0, 0); - copy_m4_m4(r_mat, ct->matrix); - } - else { - unit_m4(r_mat); + + return; } - SINGLETARGET_FLUSH_TARS(con, con->space_object, con->space_subtarget, ct, &target, true); + unit_m4(cob->space_obj_world_matrix); } /* ---------- Evaluation ----------- */ @@ -6394,8 +6385,8 @@ void BKE_constraints_solve(struct Depsgraph *depsgraph, */ enf = con->enforce; - /* Get custom space matrix. */ - BKE_constraint_custom_object_space_get(cob->space_obj_world_matrix, con); + /* Initialize the custom space for use in calculating the matrices. */ + BKE_constraint_custom_object_space_init(cob, con); /* make copy of world-space matrix pre-constraint for use with blending later */ copy_m4_m4(oldmat, cob->matrix); diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index dd43e3e6613..2071f056f9e 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -422,7 +422,7 @@ static void updateDuplicateActionConstraintSettings( float mat[4][4]; bConstraintOb cob = {.depsgraph = NULL, .scene = NULL, .ob = ob, .pchan = pchan}; - BKE_constraint_custom_object_space_get(cob.space_obj_world_matrix, curcon); + BKE_constraint_custom_object_space_init(&cob, curcon); unit_m4(mat); bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, act_con->subtarget); @@ -576,7 +576,7 @@ static void updateDuplicateLocRotConstraintSettings(Object *ob, unit_m4(local_mat); bConstraintOb cob = {.depsgraph = NULL, .scene = NULL, .ob = ob, .pchan = pchan}; - BKE_constraint_custom_object_space_get(cob.space_obj_world_matrix, curcon); + BKE_constraint_custom_object_space_init(&cob, curcon); BKE_constraint_mat_convertspace( ob, pchan, &cob, local_mat, curcon->ownspace, CONSTRAINT_SPACE_LOCAL, false); @@ -631,7 +631,7 @@ static void updateDuplicateTransformConstraintSettings(Object *ob, float target_mat[4][4], own_mat[4][4], imat[4][4]; bConstraintOb cob = {.depsgraph = NULL, .scene = NULL, .ob = ob, .pchan = pchan}; - BKE_constraint_custom_object_space_get(cob.space_obj_world_matrix, curcon); + BKE_constraint_custom_object_space_init(&cob, curcon); unit_m4(own_mat); BKE_constraint_mat_convertspace( |