コード例 #1
0
static int rigidbody_con_add_exec(bContext *C, wmOperator *op)
{
	Scene *scene = CTX_data_scene(C);
	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
	Object *ob = (scene) ? OBACT : NULL;
	int type = RNA_enum_get(op->ptr, "type");
	bool changed;

	/* sanity checks */
	if (ELEM(NULL, scene, rbw)) {
		BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to add Rigid Body Constraint to");
		return OPERATOR_CANCELLED;
	}
	/* apply to active object */
	changed = ED_rigidbody_constraint_add(scene, ob, type, op->reports);

	if (changed) {
		/* send updates */
		WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);

		/* done */
		return OPERATOR_FINISHED;
	}
	else {
		return OPERATOR_CANCELLED;
	}
}
コード例 #2
0
void ED_rigidbody_object_remove(Scene *scene, Object *ob)
{
	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);

	BKE_rigidbody_remove_object(scene, ob);
	if (rbw)
		BKE_group_object_unlink(rbw->group, ob, scene, NULL);

	DAG_id_tag_update(&ob->id, OB_RECALC_OB);
}
コード例 #3
0
bool ED_rigidbody_object_add(Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports)
{
	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);

	if (ob->type != OB_MESH) {
		BKE_report(reports, RPT_ERROR, "Can't add Rigid Body to non mesh object");
		return false;
	}

	/* Add rigid body world and group if they don't exist for convenience */
	if (rbw == NULL) {
		rbw = BKE_rigidbody_create_world(scene);
		if (rbw == NULL) {
			BKE_report(reports, RPT_ERROR, "Can't create Rigid Body world");
			return false;
		}
		BKE_rigidbody_validate_sim_world(scene, rbw, false);
		scene->rigidbody_world = rbw;
	}
	if (rbw->group == NULL) {
		rbw->group = BKE_group_add(bmain, "RigidBodyWorld");
	}

	/* make rigidbody object settings */
	if (ob->rigidbody_object == NULL) {
		ob->rigidbody_object = BKE_rigidbody_create_object(scene, ob, type);
	}
	ob->rigidbody_object->type = type;
	ob->rigidbody_object->flag |= RBO_FLAG_NEEDS_VALIDATE;

	/* add object to rigid body group */
	BKE_group_object_add(rbw->group, ob, scene, NULL);

	DAG_relations_tag_update(bmain);
	DAG_id_tag_update(&ob->id, OB_RECALC_OB);

	return true;
}
コード例 #4
0
bool ED_rigidbody_constraint_add(Scene *scene, Object *ob, int type, ReportList *reports)
{
	RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);

	/* check that object doesn't already have a constraint */
	if (ob->rigidbody_constraint) {
		BKE_reportf(reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2);
		return false;
	}
	/* create constraint group if it doesn't already exits */
	if (rbw->constraints == NULL) {
		rbw->constraints = BKE_group_add(G.main, "RigidBodyConstraints");
	}
	/* make rigidbody constraint settings */
	ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type);
	ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE;

	/* add constraint to rigid body constraint group */
	BKE_group_object_add(rbw->constraints, ob, scene, NULL);

	DAG_id_tag_update(&ob->id, OB_RECALC_OB);
	return true;
}