2.5 - Restored Set/Clear Inverse Buttons for ChildOf Constraint

I've tagged these operators with CONSTRAINT_OT_* not OBJECT_OT_constraint_* since constraints can operate on Bones too (and do so more often)
This commit is contained in:
2009-07-11 11:52:20 +00:00
parent 8a1caaed32
commit 10d14e7259
5 changed files with 53 additions and 68 deletions

View File

@@ -111,8 +111,8 @@ class ConstraintButtonsPanel(bpy.types.Panel):
# Missing
row = layout.row()
row.itemL(text="SET OFFSET")
row.itemL(text="CLEAR OFFSET")
row.itemO("CONSTRAINT_OT_childof_set_inverse")
row.itemO("CONSTRAINT_OT_childof_clear_inverse")
def track_to(self, layout, con):
self.target_template(layout, con)

View File

@@ -35,7 +35,6 @@ struct bContext;
struct Base;
struct View3D;
struct bConstraint;
struct bConstraintChannel;
struct KeyBlock;
struct Lattice;
struct Mesh;
@@ -78,7 +77,6 @@ void add_constraint_to_object(struct bConstraint *con, struct Object *ob);
struct ListBase *get_active_constraints(struct Object *ob);
struct bConstraint *get_active_constraint(struct Object *ob);
struct bConstraintChannel *get_active_constraint_channel(struct Scene *scene, struct Object *ob);
void object_test_constraints(struct Object *ob);

View File

@@ -117,63 +117,6 @@ bConstraint *get_active_constraint (Object *ob)
return NULL;
}
/* single channel, for ipo */
bConstraintChannel *get_active_constraint_channel (Scene *scene, Object *ob)
{
bConstraint *con;
if (ob->flag & OB_POSEMODE) {
//if (ob->action) { // XXX old animation system
bPoseChannel *pchan;
pchan = get_active_posechannel(ob);
if (pchan) {
for (con= pchan->constraints.first; con; con= con->next) {
if (con->flag & CONSTRAINT_ACTIVE)
break;
}
if (con) {
#if 0 // XXX old animation system
bActionChannel *achan = get_action_channel(ob->action, pchan->name);
if (achan) {
for (chan= achan->constraintChannels.first; chan; chan= chan->next) {
if (!strcmp(chan->name, con->name))
break;
}
return chan;
}
#endif // XXX old animation system
}
}
//} // xxx old animation system
}
else {
for (con= ob->constraints.first; con; con= con->next) {
if (con->flag & CONSTRAINT_ACTIVE)
break;
}
if (con) {
#if 0 // XXX old animation system
ListBase *lb= get_active_constraint_channels(scene, ob, 0);
if (lb) {
for (chan= lb->first; chan; chan= chan->next) {
if (!strcmp(chan->name, con->name))
break;
}
return chan;
}
#endif // XXX old animation system
}
}
return NULL;
}
/* -------------- Constraint Management (Add New, Remove, Rename) -------------------- */
/* ------------- PyConstraints ------------------ */
@@ -790,15 +733,17 @@ void object_test_constraints (Object *owner)
/* ------------- Child-Of Constraint ------------------ */
/* ChildOf Constraint - set inverse callback */
void childof_const_setinv (void *conv, void *scenev)
static int childof_set_inverse_exec (bContext *C, wmOperator *op)
{
bConstraint *con= (bConstraint *)conv;
Scene *scene= (Scene *)scenev;
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_ChildOfConstraint);
Scene *scene= CTX_data_scene(C);
Object *ob= ptr.id.data;
bConstraint *con= ptr.data;
bChildOfConstraint *data= (bChildOfConstraint *)con->data;
Object *ob= OBACT;
bPoseChannel *pchan= NULL;
/* try to find a pose channel */
// TODO: get from context instead?
if (ob && ob->pose)
pchan= get_active_posechannel(ob);
@@ -839,16 +784,53 @@ void childof_const_setinv (void *conv, void *scenev)
}
else
Mat4One(data->invmat);
WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
return OPERATOR_FINISHED;
}
/* ChildOf Constraint - clear inverse callback */
void childof_const_clearinv (void *conv, void *unused)
void CONSTRAINT_OT_childof_set_inverse (wmOperatorType *ot)
{
bConstraint *con= (bConstraint *)conv;
/* identifiers */
ot->name= "Set Inverse";
ot->idname= "CONSTRAINT_OT_childof_set_inverse";
ot->description= "Set inverse correction for ChildOf constraint.";
ot->exec= childof_set_inverse_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* ChildOf Constraint - clear inverse callback */
static int childof_clear_inverse_exec (bContext *C, wmOperator *op)
{
PointerRNA ptr= CTX_data_pointer_get_type(C, "constraint", &RNA_ChildOfConstraint);
Object *ob= ptr.id.data;
bConstraint *con= ptr.data;
bChildOfConstraint *data= (bChildOfConstraint *)con->data;
/* simply clear the matrix */
Mat4One(data->invmat);
WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
return OPERATOR_FINISHED;
}
void CONSTRAINT_OT_childof_clear_inverse (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Clear Inverse";
ot->idname= "CONSTRAINT_OT_childof_clear_inverse";
ot->description= "Clear inverse correction for ChildOf constraint.";
ot->exec= childof_clear_inverse_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/***************************** BUTTONS ****************************/

View File

@@ -102,6 +102,9 @@ void OBJECT_OT_modifier_mdef_bind(struct wmOperatorType *ot);
/* editconstraint.c */
void OBJECT_OT_constraint_add(struct wmOperatorType *ot);
void CONSTRAINT_OT_childof_set_inverse(struct wmOperatorType *ot);
void CONSTRAINT_OT_childof_clear_inverse(struct wmOperatorType *ot);
/* object_vgroup.c */
void OBJECT_OT_vertex_group_add(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_remove(struct wmOperatorType *ot);

View File

@@ -111,6 +111,8 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_modifier_mdef_bind);
WM_operatortype_append(OBJECT_OT_constraint_add);
WM_operatortype_append(CONSTRAINT_OT_childof_set_inverse);
WM_operatortype_append(CONSTRAINT_OT_childof_clear_inverse);
WM_operatortype_append(OBJECT_OT_vertex_group_add);
WM_operatortype_append(OBJECT_OT_vertex_group_remove);