1
1

Constraints: rename and refactor custom space initialization.

Rename and simplify the function for initializing the custom space,
avoiding the need for the calling code to be aware of the internals
of bConstraintOb. This patch should not change any behavior.

This was split off from D9732.

Differential Revision: https://developer.blender.org/D15252
This commit is contained in:
2022-06-03 16:28:09 +03:00
parent c64d1b23df
commit 4a7e1c9209
3 changed files with 24 additions and 25 deletions

View File

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

View File

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

View File

@@ -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(