Refactor getting constraints
This is the refactoring part of D8805 (should be no functional changes). - exposes pose-related part of former 'get_constraints()' from interface_templates.c to new ED_object_pose_constraint_list - rename ED_object_constraint_list_from_context --> ED_object_constraint_active_list Also clarify comments on both of these. ref T80464 ref https://developer.blender.org/D8805
This commit is contained in:
parent
98eb89be5d
commit
9dcae4eb17
Notes:
blender-bot
2023-02-14 00:44:02 +01:00
Referenced by commit 51c7a854fe
, Fix T81057: PoseBone Constraints are displayed in Object Constraints tab
Referenced by issue #81164, Switching to pose mode occurs crashes (2.90.1, fixed in master)
Referenced by issue #80464, Deleting bone constraints when the armature layer isn't active crashes Blender
Referenced by issue #80396, Potential candidates for corrective releases
|
@ -323,7 +323,8 @@ void ED_objects_recalculate_paths(struct bContext *C,
|
|||
eObjectPathCalcRange range);
|
||||
|
||||
/* constraints */
|
||||
struct ListBase *ED_object_constraint_list_from_context(struct Object *ob);
|
||||
struct ListBase *ED_object_constraint_active_list(struct Object *ob);
|
||||
struct ListBase *ED_object_pose_constraint_list(const struct bContext *C);
|
||||
struct ListBase *ED_object_constraint_list_from_constraint(struct Object *ob,
|
||||
struct bConstraint *con,
|
||||
struct bPoseChannel **r_pchan);
|
||||
|
|
|
@ -1971,27 +1971,6 @@ static bool constraint_panel_is_bone(Panel *panel)
|
|||
(panel->panelname[2] == 'N') && (panel->panelname[3] == 'E');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the constraints for the active pose bone or the active / pinned object.
|
||||
*/
|
||||
static ListBase *get_constraints(const bContext *C, bool use_bone_constraints)
|
||||
{
|
||||
ListBase *constraints = {NULL};
|
||||
if (use_bone_constraints) {
|
||||
bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data;
|
||||
if (pose_bone != NULL) {
|
||||
constraints = &pose_bone->constraints;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object *ob = ED_object_active_context(C);
|
||||
if (ob != NULL) {
|
||||
constraints = &ob->constraints;
|
||||
}
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a constraint to the index it's moved to after a drag and drop.
|
||||
*/
|
||||
|
@ -2066,7 +2045,13 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_
|
|||
ARegion *region = CTX_wm_region(C);
|
||||
|
||||
Object *ob = ED_object_active_context(C);
|
||||
ListBase *constraints = get_constraints(C, use_bone_constraints);
|
||||
ListBase *constraints = {NULL};
|
||||
if (use_bone_constraints) {
|
||||
constraints = ED_object_pose_constraint_list(C);
|
||||
}
|
||||
else {
|
||||
constraints = ED_object_constraint_active_list(ob);
|
||||
}
|
||||
|
||||
/* Switch between the bone panel ID function and the object panel ID function. */
|
||||
uiListPanelIDFromDataFunc panel_id_func = use_bone_constraints ? bone_constraint_panel_id :
|
||||
|
|
|
@ -80,8 +80,9 @@
|
|||
/** \name Constraint Data Accessors
|
||||
* \{ */
|
||||
|
||||
/* if object in posemode, active bone constraints, else object constraints */
|
||||
ListBase *ED_object_constraint_list_from_context(Object *ob)
|
||||
/* If object is in posemode, return active bone constraints, else object constraints. No
|
||||
* constraints are returned for a bone on an inactive bonelayer. */
|
||||
ListBase *ED_object_constraint_active_list(Object *ob)
|
||||
{
|
||||
if (ob == NULL) {
|
||||
return NULL;
|
||||
|
@ -102,6 +103,18 @@ ListBase *ED_object_constraint_list_from_context(Object *ob)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Get the constraints for the active pose bone. Bone may be on an inactive bonelayer (unlike
|
||||
* ED_object_constraint_active_list, such constraints are not excluded here). */
|
||||
ListBase *ED_object_pose_constraint_list(const bContext *C)
|
||||
{
|
||||
bPoseChannel *pose_bone = CTX_data_pointer_get(C, "pose_bone").data;
|
||||
if (pose_bone == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &pose_bone->constraints;
|
||||
}
|
||||
|
||||
/* Find the list that a given constraint belongs to,
|
||||
* and/or also get the posechannel this is from (if applicable) */
|
||||
ListBase *ED_object_constraint_list_from_constraint(Object *ob,
|
||||
|
@ -147,7 +160,7 @@ ListBase *ED_object_constraint_list_from_constraint(Object *ob,
|
|||
/* single constraint */
|
||||
bConstraint *ED_object_constraint_active_get(Object *ob)
|
||||
{
|
||||
return BKE_constraints_active_get(ED_object_constraint_list_from_context(ob));
|
||||
return BKE_constraints_active_get(ED_object_constraint_active_list(ob));
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@ -813,7 +826,7 @@ static bConstraint *edit_constraint_property_get(wmOperator *op, Object *ob, int
|
|||
printf("edit_constraint_property_get: defaulting to getting list in the standard way\n");
|
||||
}
|
||||
#endif
|
||||
list = ED_object_constraint_list_from_context(ob);
|
||||
list = ED_object_constraint_active_list(ob);
|
||||
}
|
||||
|
||||
con = BKE_constraints_find_name(list, constraint_name);
|
||||
|
@ -2161,8 +2174,7 @@ static int pose_constraint_add_exec(bContext *C, wmOperator *op)
|
|||
with_targets = 1;
|
||||
}
|
||||
|
||||
return constraint_add_exec(
|
||||
C, op, ob, ED_object_constraint_list_from_context(ob), type, with_targets);
|
||||
return constraint_add_exec(C, op, ob, ED_object_constraint_active_list(ob), type, with_targets);
|
||||
}
|
||||
|
||||
/* ------------------ */
|
||||
|
@ -2363,12 +2375,8 @@ static int pose_ik_add_exec(bContext *C, wmOperator *op)
|
|||
|
||||
/* add the constraint - all necessary checks should have
|
||||
* been done by the invoke() callback already... */
|
||||
return constraint_add_exec(C,
|
||||
op,
|
||||
ob,
|
||||
ED_object_constraint_list_from_context(ob),
|
||||
CONSTRAINT_TYPE_KINEMATIC,
|
||||
with_targets);
|
||||
return constraint_add_exec(
|
||||
C, op, ob, ED_object_constraint_active_list(ob), CONSTRAINT_TYPE_KINEMATIC, with_targets);
|
||||
}
|
||||
|
||||
void POSE_OT_ik_add(wmOperatorType *ot)
|
||||
|
|
|
@ -271,7 +271,7 @@ void BCAnimationSampler::find_depending_animated(std::set<Object *> &animated_ob
|
|||
std::set<Object *>::iterator it;
|
||||
for (it = candidates.begin(); it != candidates.end(); ++it) {
|
||||
Object *cob = *it;
|
||||
ListBase *conlist = ED_object_constraint_list_from_context(cob);
|
||||
ListBase *conlist = ED_object_constraint_active_list(cob);
|
||||
if (is_animated_by_constraint(cob, conlist, animated_objects)) {
|
||||
animated_objects.insert(cob);
|
||||
candidates.erase(cob);
|
||||
|
|
Loading…
Reference in New Issue