Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/object/object_constraint.c')
-rw-r--r--source/blender/editors/object/object_constraint.c216
1 files changed, 144 insertions, 72 deletions
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index 7a1cf44c0aa..8ae736d42c0 100644
--- a/source/blender/editors/object/object_constraint.c
+++ b/source/blender/editors/object/object_constraint.c
@@ -79,18 +79,21 @@
/* if object in posemode, active bone constraints, else object constraints */
ListBase *get_active_constraints(Object *ob)
{
- if (ob == NULL)
+ if (ob == NULL) {
return NULL;
+ }
if (ob->mode & OB_MODE_POSE) {
bPoseChannel *pchan;
pchan = BKE_pose_channel_active(ob);
- if (pchan)
+ if (pchan) {
return &pchan->constraints;
+ }
}
- else
+ else {
return &ob->constraints;
+ }
return NULL;
}
@@ -99,11 +102,13 @@ ListBase *get_active_constraints(Object *ob)
* and/or also get the posechannel this is from (if applicable) */
ListBase *get_constraint_lb(Object *ob, bConstraint *con, bPoseChannel **r_pchan)
{
- if (r_pchan)
+ if (r_pchan) {
*r_pchan = NULL;
+ }
- if (ELEM(NULL, ob, con))
+ if (ELEM(NULL, ob, con)) {
return NULL;
+ }
/* try object constraints first */
if ((BLI_findindex(&ob->constraints, con) != -1)) {
@@ -120,8 +125,9 @@ ListBase *get_constraint_lb(Object *ob, bConstraint *con, bPoseChannel **r_pchan
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
if ((BLI_findindex(&pchan->constraints, con) != -1)) {
- if (r_pchan)
+ if (r_pchan) {
*r_pchan = pchan;
+ }
return &pchan->constraints;
}
@@ -153,8 +159,9 @@ static void validate_pyconstraint_cb(Main *bmain, void *arg1, void *arg2)
/* exception for no script */
if (index) {
/* innovative use of a for...loop to search */
- for (text = bmain->texts.first, i = 1; text && index != i; i++, text = text->id.next)
+ for (text = bmain->texts.first, i = 1; text && index != i; i++, text = text->id.next) {
;
+ }
}
data->text = text;
}
@@ -173,14 +180,16 @@ static char *buildmenu_pyconstraints(Main *bmain, Text *con_text, int *pyconinde
BLI_dynstr_append(pupds, buf);
/* init active-index first */
- if (con_text == NULL)
+ if (con_text == NULL) {
*pyconindex = 0;
+ }
/* loop through markers, adding them */
for (text = bmain->texts.first, i = 1; text; i++, text = text->id.next) {
/* this is important to ensure that right script is shown as active */
- if (text == con_text)
+ if (text == con_text) {
*pyconindex = i;
+ }
/* only include valid pyconstraint scripts */
if (BPY_is_pyconstraint(text)) {
@@ -189,8 +198,9 @@ static char *buildmenu_pyconstraints(Main *bmain, Text *con_text, int *pyconinde
sprintf(buf, "%%x%d", i);
BLI_dynstr_append(pupds, buf);
- if (text->id.next)
+ if (text->id.next) {
BLI_dynstr_append(pupds, "|");
+ }
}
}
@@ -234,10 +244,12 @@ static void set_constraint_nth_target(bConstraint *con,
num_targets = BLI_listbase_count(&targets);
if (index < 0) {
- if (abs(index) < num_targets)
+ if (abs(index) < num_targets) {
index = num_targets - abs(index);
- else
+ }
+ else {
index = num_targets - 1;
+ }
}
else if (index >= num_targets) {
index = num_targets - 1;
@@ -251,8 +263,9 @@ static void set_constraint_nth_target(bConstraint *con,
}
}
- if (cti->flush_constraint_targets)
+ if (cti->flush_constraint_targets) {
cti->flush_constraint_targets(con, &targets, 0);
+ }
}
}
@@ -338,27 +351,33 @@ static void test_constraint(
bFollowPathConstraint *data = con->data;
/* don't allow track/up axes to be the same */
- if (data->upflag == data->trackflag)
+ if (data->upflag == data->trackflag) {
con->flag |= CONSTRAINT_DISABLE;
- if (data->upflag + 3 == data->trackflag)
+ }
+ if (data->upflag + 3 == data->trackflag) {
con->flag |= CONSTRAINT_DISABLE;
+ }
}
else if (con->type == CONSTRAINT_TYPE_TRACKTO) {
bTrackToConstraint *data = con->data;
/* don't allow track/up axes to be the same */
- if (data->reserved2 == data->reserved1)
+ if (data->reserved2 == data->reserved1) {
con->flag |= CONSTRAINT_DISABLE;
- if (data->reserved2 + 3 == data->reserved1)
+ }
+ if (data->reserved2 + 3 == data->reserved1) {
con->flag |= CONSTRAINT_DISABLE;
+ }
}
else if (con->type == CONSTRAINT_TYPE_LOCKTRACK) {
bLockTrackConstraint *data = con->data;
- if (data->lockflag == data->trackflag)
+ if (data->lockflag == data->trackflag) {
con->flag |= CONSTRAINT_DISABLE;
- if (data->lockflag + 3 == data->trackflag)
+ }
+ if (data->lockflag + 3 == data->trackflag) {
con->flag |= CONSTRAINT_DISABLE;
+ }
}
else if (con->type == CONSTRAINT_TYPE_SPLINEIK) {
bSplineIKConstraint *data = con->data;
@@ -385,17 +404,20 @@ static void test_constraint(
MovieTracking *tracking = &data->clip->tracking;
MovieTrackingObject *tracking_object;
- if (data->object[0])
+ if (data->object[0]) {
tracking_object = BKE_tracking_object_get_named(tracking, data->object);
- else
+ }
+ else {
tracking_object = BKE_tracking_object_get_camera(tracking);
+ }
if (!tracking_object) {
con->flag |= CONSTRAINT_DISABLE;
}
else {
- if (!BKE_tracking_track_get_named(tracking, tracking_object, data->track))
+ if (!BKE_tracking_track_get_named(tracking, tracking_object, data->track)) {
con->flag |= CONSTRAINT_DISABLE;
+ }
}
}
else {
@@ -406,14 +428,16 @@ static void test_constraint(
else if (con->type == CONSTRAINT_TYPE_CAMERASOLVER) {
bCameraSolverConstraint *data = con->data;
- if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL))
+ if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) {
con->flag |= CONSTRAINT_DISABLE;
+ }
}
else if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
bObjectSolverConstraint *data = con->data;
- if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL))
+ if ((data->flag & CAMERASOLVER_ACTIVECLIP) == 0 && (data->clip == NULL)) {
con->flag |= CONSTRAINT_DISABLE;
+ }
}
else if (con->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
bTransformCacheConstraint *data = con->data;
@@ -494,8 +518,9 @@ static void test_constraint(
}
/* free any temporary targets */
- if (cti->flush_constraint_targets)
+ if (cti->flush_constraint_targets) {
cti->flush_constraint_targets(con, &targets, 0);
+ }
}
}
@@ -513,8 +538,9 @@ static int constraint_type_get(Object *owner, bPoseChannel *pchan)
break;
}
}
- else
+ else {
type = CONSTRAINT_OBTYPE_OBJECT;
+ }
return type;
}
@@ -527,8 +553,9 @@ static void test_constraints(Main *bmain, Object *owner, bPoseChannel *pchan)
ListBase *conlist = NULL;
int type;
- if (owner == NULL)
+ if (owner == NULL) {
return;
+ }
type = constraint_type_get(owner, pchan);
@@ -552,15 +579,17 @@ static void test_constraints(Main *bmain, Object *owner, bPoseChannel *pchan)
void object_test_constraints(Main *bmain, Object *owner)
{
- if (owner->constraints.first)
+ if (owner->constraints.first) {
test_constraints(bmain, owner, NULL);
+ }
if (owner->type == OB_ARMATURE && owner->pose) {
bPoseChannel *pchan;
for (pchan = owner->pose->chanbase.first; pchan; pchan = pchan->next) {
- if (pchan->constraints.first)
+ if (pchan->constraints.first) {
test_constraints(bmain, owner, pchan);
+ }
}
}
}
@@ -653,8 +682,9 @@ static int edit_constraint_invoke_properties(bContext *C, wmOperator *op)
ListBase *list;
if (RNA_struct_property_is_set(op->ptr, "constraint") &&
- RNA_struct_property_is_set(op->ptr, "owner"))
+ RNA_struct_property_is_set(op->ptr, "owner")) {
return 1;
+ }
if (ptr.data) {
con = ptr.data;
@@ -662,10 +692,12 @@ static int edit_constraint_invoke_properties(bContext *C, wmOperator *op)
list = get_constraint_lb(ob, con, NULL);
- if (&ob->constraints == list)
+ if (&ob->constraints == list) {
RNA_enum_set(op->ptr, "owner", EDIT_CONSTRAINT_OWNER_OBJECT);
- else
+ }
+ else {
RNA_enum_set(op->ptr, "owner", EDIT_CONSTRAINT_OWNER_BONE);
+ }
return 1;
}
@@ -687,8 +719,9 @@ static bConstraint *edit_constraint_property_get(wmOperator *op, Object *ob, int
}
else if (owner == EDIT_CONSTRAINT_OWNER_BONE) {
bPoseChannel *pchan = BKE_pose_channel_active(ob);
- if (pchan)
+ if (pchan) {
list = &pchan->constraints;
+ }
else {
#if 0
if (G.debug & G_DEBUG) {
@@ -715,8 +748,9 @@ static bConstraint *edit_constraint_property_get(wmOperator *op, Object *ob, int
}
#endif
- if (con && (type != 0) && (con->type != type))
+ if (con && (type != 0) && (con->type != type)) {
con = NULL;
+ }
return con;
}
@@ -734,8 +768,9 @@ static int stretchto_reset_exec(bContext *C, wmOperator *op)
bStretchToConstraint *data = (con) ? (bStretchToConstraint *)con->data : NULL;
/* despite 3 layers of checks, we may still not be able to find a constraint */
- if (data == NULL)
+ if (data == NULL) {
return OPERATOR_CANCELLED;
+ }
/* just set original length to 0.0, which will cause a reset on next recalc */
data->orglength = 0.0f;
@@ -747,10 +782,12 @@ static int stretchto_reset_exec(bContext *C, wmOperator *op)
static int stretchto_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return stretchto_reset_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_stretchto_reset(wmOperatorType *ot)
@@ -780,8 +817,9 @@ static int limitdistance_reset_exec(bContext *C, wmOperator *op)
bDistLimitConstraint *data = (con) ? (bDistLimitConstraint *)con->data : NULL;
/* despite 3 layers of checks, we may still not be able to find a constraint */
- if (data == NULL)
+ if (data == NULL) {
return OPERATOR_CANCELLED;
+ }
/* just set original length to 0.0, which will cause a reset on next recalc */
data->dist = 0.0f;
@@ -793,10 +831,12 @@ static int limitdistance_reset_exec(bContext *C, wmOperator *op)
static int limitdistance_reset_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return limitdistance_reset_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot)
@@ -938,10 +978,12 @@ static int childof_set_inverse_exec(bContext *C, wmOperator *op)
static int childof_set_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return childof_set_inverse_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_childof_set_inverse(wmOperatorType *ot)
@@ -987,10 +1029,12 @@ static int childof_clear_inverse_exec(bContext *C, wmOperator *op)
static int childof_clear_inverse_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return childof_clear_inverse_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_childof_clear_inverse(wmOperatorType *ot)
@@ -1075,8 +1119,9 @@ static int followpath_path_animate_exec(bContext *C, wmOperator *op)
data->followflag |= FOLLOWPATH_STATIC;
/* path needs to be freed */
- if (path)
+ if (path) {
MEM_freeN(path);
+ }
}
/* setup dummy 'generator' modifier here to get 1-1 correspondence still working
@@ -1181,10 +1226,12 @@ static int objectsolver_set_inverse_invoke(bContext *C,
wmOperator *op,
const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return objectsolver_set_inverse_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_objectsolver_set_inverse(wmOperatorType *ot)
@@ -1229,10 +1276,12 @@ static int objectsolver_clear_inverse_invoke(bContext *C,
wmOperator *op,
const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return objectsolver_clear_inverse_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_objectsolver_clear_inverse(wmOperatorType *ot)
@@ -1262,23 +1311,27 @@ void ED_object_constraint_set_active(Object *ob, bConstraint *con)
/* lets be nice and escape if its active already */
/* NOTE: this assumes that the stack doesn't have other active ones set... */
- if ((lb && con) && (con->flag & CONSTRAINT_ACTIVE))
+ if ((lb && con) && (con->flag & CONSTRAINT_ACTIVE)) {
return;
+ }
BKE_constraints_active_set(lb, con);
}
void ED_object_constraint_update(Main *bmain, Object *ob)
{
- if (ob->pose)
+ if (ob->pose) {
BKE_pose_update_constraint_flags(ob->pose);
+ }
object_test_constraints(bmain, ob);
- if (ob->type == OB_ARMATURE)
+ if (ob->type == OB_ARMATURE) {
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM);
- else
+ }
+ else {
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
+ }
}
static void object_pose_tag_update(Main *bmain, Object *ob)
@@ -1315,10 +1368,12 @@ void ED_object_constraint_tag_update(Main *bmain, Object *ob, bConstraint *con)
object_test_constraint(bmain, ob, con);
}
- if (ob->type == OB_ARMATURE)
+ if (ob->type == OB_ARMATURE) {
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM);
- else
+ }
+ else {
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
+ }
/* Do Copy-on-Write tag here too, otherwise constraint
* influence/mute buttons in UI have no effect
@@ -1409,10 +1464,12 @@ static int constraint_move_down_exec(bContext *C, wmOperator *op)
static int constraint_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return constraint_move_down_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_move_down(wmOperatorType *ot)
@@ -1457,10 +1514,12 @@ static int constraint_move_up_exec(bContext *C, wmOperator *op)
static int constraint_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- if (edit_constraint_invoke_properties(C, op))
+ if (edit_constraint_invoke_properties(C, op)) {
return constraint_move_up_exec(C, op);
- else
+ }
+ else {
return OPERATOR_CANCELLED;
+ }
}
void CONSTRAINT_OT_move_up(wmOperatorType *ot)
@@ -1772,10 +1831,12 @@ static bool get_new_constraint_target(
/* since by default, IK targets the tip of the last bone, use the tip of the active PoseChannel
* if adding a target for an IK Constraint
*/
- if (con_type == CONSTRAINT_TYPE_KINEMATIC)
+ if (con_type == CONSTRAINT_TYPE_KINEMATIC) {
mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_tail);
- else
+ }
+ else {
mul_v3_m4v3(obt->loc, obact->obmat, pchanact->pose_head);
+ }
}
else {
copy_v3_v3(obt->loc, obact->obmat[3]);
@@ -1829,10 +1890,12 @@ static int constraint_add_exec(
/* Create a new constraint of the type required,
* and add it to the active/given constraints list. */
- if (pchan)
+ if (pchan) {
con = BKE_constraint_add_for_pose(ob, pchan, NULL, type);
- else
+ }
+ else {
con = BKE_constraint_add_for_object(ob, NULL, type);
+ }
/* get the first selected object/bone, and make that the target
* - apart from the buttons-window add buttons, we shouldn't add in this way
@@ -1846,10 +1909,12 @@ static int constraint_add_exec(
/* Method of setting target depends on the type of target we've got - by default,
* just set the first target (distinction here is only for multiple-targeted constraints).
*/
- if (tar_pchan)
+ if (tar_pchan) {
set_constraint_nth_target(con, tar_ob, tar_pchan->name, 0);
- else
+ }
+ else {
set_constraint_nth_target(con, tar_ob, "", 0);
+ }
}
}
@@ -1884,8 +1949,9 @@ static int constraint_add_exec(
/* make sure all settings are valid - similar to above checks, but sometimes can be wrong */
object_test_constraints(bmain, ob);
- if (pchan)
+ if (pchan) {
BKE_pose_update_constraint_flags(ob->pose);
+ }
/* force depsgraph to get recalculated since new relationships added */
DEG_relations_tag_update(bmain);
@@ -1900,8 +1966,9 @@ static int constraint_add_exec(
}
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM);
}
- else
+ else {
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
+ }
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_ADDED, ob);
@@ -1926,8 +1993,9 @@ static int object_constraint_add_exec(bContext *C, wmOperator *op)
/* hack: set constraint targets from selected objects in context is allowed when
* operator name included 'with_targets', since the menu doesn't allow multiple properties
*/
- if (strstr(op->idname, "with_targets"))
+ if (strstr(op->idname, "with_targets")) {
with_targets = 1;
+ }
return constraint_add_exec(C, op, ob, &ob->constraints, type, with_targets);
}
@@ -1947,8 +2015,9 @@ static int pose_constraint_add_exec(bContext *C, wmOperator *op)
/* hack: set constraint targets from selected objects in context is allowed when
* operator name included 'with_targets', since the menu doesn't allow multiple properties
*/
- if (strstr(op->idname, "with_targets"))
+ if (strstr(op->idname, "with_targets")) {
with_targets = 1;
+ }
return constraint_add_exec(C, op, ob, get_active_constraints(ob), type, with_targets);
}
@@ -2059,8 +2128,9 @@ static int pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED
/* bone must not have any constraints already */
for (con = pchan->constraints.first; con; con = con->next) {
- if (con->type == CONSTRAINT_TYPE_KINEMATIC)
+ if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
break;
+ }
}
if (con) {
BKE_report(op->reports, RPT_ERROR, "Bone already has an IK constraint");
@@ -2076,12 +2146,14 @@ static int pose_ik_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED
/* bone target, or object target?
* - the only thing that matters is that we want a target...
*/
- if (tar_pchan)
+ if (tar_pchan) {
uiItemBooleanO(
layout, IFACE_("To Active Bone"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 1);
- else
+ }
+ else {
uiItemBooleanO(
layout, IFACE_("To Active Object"), ICON_NONE, "POSE_OT_ik_add", "with_targets", 1);
+ }
}
else {
/* we have a choice of adding to a new empty, or not setting any target (targetless IK) */