コード例 #1
0
static int rigidbody_world_add_exec(bContext *C, wmOperator *UNUSED(op))
{
	Scene *scene = CTX_data_scene(C);
	RigidBodyWorld *rbw;

	rbw = BKE_rigidbody_create_world(scene);
//	BKE_rigidbody_validate_sim_world(scene, rbw, false);
	scene->rigidbody_world = rbw;

	return OPERATOR_FINISHED;
}
コード例 #2
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;
}