Refactor: anim, change if-elseif-else chain to switch + reduce iterations
Refactor `BKE_pose_channel_copy_data()` so that it iterates over the entire armature only once (instead of twice), and to use a `switch` instead of a chain of `if`/`else if`/`else` clauses. No functional changes.
This commit is contained in:
parent
69bf3f4e9a
commit
12fc4b6c58
|
@ -1168,67 +1168,66 @@ void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_f
|
|||
|
||||
void BKE_pose_update_constraint_flags(bPose *pose)
|
||||
{
|
||||
bPoseChannel *parchan;
|
||||
|
||||
/* clear */
|
||||
LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) {
|
||||
pchan->constflag = 0;
|
||||
}
|
||||
pose->flag &= ~POSE_CONSTRAINTS_TIMEDEPEND;
|
||||
|
||||
/* detect */
|
||||
LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) {
|
||||
pchan->constflag = 0;
|
||||
|
||||
LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) {
|
||||
if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
|
||||
bKinematicConstraint *data = (bKinematicConstraint *)con->data;
|
||||
switch (con->type) {
|
||||
case CONSTRAINT_TYPE_KINEMATIC: {
|
||||
bKinematicConstraint *data = (bKinematicConstraint *)con->data;
|
||||
|
||||
pchan->constflag |= PCHAN_HAS_IK;
|
||||
pchan->constflag |= PCHAN_HAS_IK;
|
||||
|
||||
if (data->tar == nullptr || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0)) {
|
||||
pchan->constflag |= PCHAN_HAS_TARGET;
|
||||
}
|
||||
|
||||
/* negative rootbone = recalc rootbone index. used in do_versions */
|
||||
if (data->rootbone < 0) {
|
||||
data->rootbone = 0;
|
||||
|
||||
if (data->flag & CONSTRAINT_IK_TIP) {
|
||||
parchan = pchan;
|
||||
}
|
||||
else {
|
||||
parchan = pchan->parent;
|
||||
if (data->tar == nullptr || (data->tar->type == OB_ARMATURE && data->subtarget[0] == 0))
|
||||
{
|
||||
pchan->constflag |= PCHAN_HAS_TARGET;
|
||||
}
|
||||
|
||||
while (parchan) {
|
||||
data->rootbone++;
|
||||
if ((parchan->bone->flag & BONE_CONNECTED) == 0) {
|
||||
break;
|
||||
/* negative rootbone = recalc rootbone index. used in do_versions */
|
||||
if (data->rootbone < 0) {
|
||||
data->rootbone = 0;
|
||||
|
||||
bPoseChannel *chain_tip = (data->flag & CONSTRAINT_IK_TIP) ? pchan : pchan->parent;
|
||||
bPoseChannel *parchan = chain_tip;
|
||||
while (parchan) {
|
||||
data->rootbone++;
|
||||
if ((parchan->bone->flag & BONE_CONNECTED) == 0) {
|
||||
break;
|
||||
}
|
||||
parchan = parchan->parent;
|
||||
}
|
||||
parchan = parchan->parent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) {
|
||||
bFollowPathConstraint *data = (bFollowPathConstraint *)con->data;
|
||||
|
||||
/* for drawing constraint colors when color set allows this */
|
||||
pchan->constflag |= PCHAN_HAS_CONST;
|
||||
case CONSTRAINT_TYPE_FOLLOWPATH: {
|
||||
bFollowPathConstraint *data = (bFollowPathConstraint *)con->data;
|
||||
|
||||
/* if we have a valid target, make sure that this will get updated on frame-change
|
||||
* (needed for when there is no anim-data for this pose)
|
||||
*/
|
||||
if ((data->tar) && (data->tar->type == OB_CURVES_LEGACY)) {
|
||||
pose->flag |= POSE_CONSTRAINTS_TIMEDEPEND;
|
||||
/* for drawing constraint colors when color set allows this */
|
||||
pchan->constflag |= PCHAN_HAS_CONST;
|
||||
|
||||
/* if we have a valid target, make sure that this will get updated on frame-change
|
||||
* (needed for when there is no anim-data for this pose)
|
||||
*/
|
||||
if ((data->tar) && (data->tar->type == OB_CURVES_LEGACY)) {
|
||||
pose->flag |= POSE_CONSTRAINTS_TIMEDEPEND;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (con->type == CONSTRAINT_TYPE_SPLINEIK) {
|
||||
pchan->constflag |= PCHAN_HAS_SPLINEIK;
|
||||
}
|
||||
else {
|
||||
pchan->constflag |= PCHAN_HAS_CONST;
|
||||
|
||||
case CONSTRAINT_TYPE_SPLINEIK:
|
||||
pchan->constflag |= PCHAN_HAS_SPLINEIK;
|
||||
break;
|
||||
|
||||
default:
|
||||
pchan->constflag |= PCHAN_HAS_CONST;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pose->flag &= ~POSE_CONSTRAINTS_NEED_UPDATE_FLAGS;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue