80
void ED_rigidbody_con_add(wmOperator *op, Scene *scene, Object *ob, int type)
80
bool ED_rigidbody_constraint_add(Scene *scene, Object *ob, int type, ReportList *reports)
82
82
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
84
84
/* check that object doesn't already have a constraint */
85
85
if (ob->rigidbody_constraint) {
86
BKE_reportf(op->reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2);
86
BKE_reportf(reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2);
89
89
/* create constraint group if it doesn't already exits */
90
90
if (rbw->constraints == NULL) {
91
rbw->constraints = add_group(G.main, "RigidBodyConstraints");
91
rbw->constraints = BKE_group_add(G.main, "RigidBodyConstraints");
93
93
/* make rigidbody constraint settings */
94
94
ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type);
95
95
ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE;
97
97
/* add constraint to rigid body constraint group */
98
add_to_group(rbw->constraints, ob, scene, NULL);
98
BKE_group_object_add(rbw->constraints, ob, scene, NULL);
100
DAG_id_tag_update(&ob->id, OB_RECALC_OB);
101
void ED_rigidbody_con_remove(Scene *scene, Object *ob)
104
void ED_rigidbody_constraint_remove(Scene *scene, Object *ob)
103
106
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
105
108
BKE_rigidbody_remove_constraint(scene, ob);
107
rem_from_group(rbw->constraints, ob, scene, NULL);
110
BKE_group_object_unlink(rbw->constraints, ob, scene, NULL);
109
112
DAG_id_tag_update(&ob->id, OB_RECALC_OB);
120
123
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
121
124
Object *ob = (scene) ? OBACT : NULL;
122
125
int type = RNA_enum_get(op->ptr, "type");
124
128
/* sanity checks */
125
129
if (ELEM(NULL, scene, rbw)) {
127
131
return OPERATOR_CANCELLED;
129
133
/* apply to active object */
130
ED_rigidbody_con_add(op, scene, ob, type);
133
DAG_ids_flush_update(CTX_data_main(C), 0);
135
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
138
return OPERATOR_FINISHED;
134
change = ED_rigidbody_constraint_add(scene, ob, type, op->reports);
138
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
141
return OPERATOR_FINISHED;
144
return OPERATOR_CANCELLED;
141
148
void RIGIDBODY_OT_constraint_add(wmOperatorType *ot)
153
160
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
156
ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_con_type_items, RBC_TYPE_FIXED, "Rigid Body Constraint Type", "");
163
ot->prop = RNA_def_enum(ot->srna, "type", rigidbody_constraint_type_items, RBC_TYPE_FIXED, "Rigid Body Constraint Type", "");
159
166
/* ************ Remove Rigid Body Constraint ************** */
173
180
return OPERATOR_CANCELLED;
176
ED_rigidbody_con_remove(scene, ob);
183
ED_rigidbody_constraint_remove(scene, ob);
179
186
/* send updates */
180
DAG_ids_flush_update(CTX_data_main(C), 0);
182
187
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);