2013-01-23 06:56:22 +01:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2013 Blender Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Joshua Leung, Sergej Reich
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file BKE_rigidbody.h
|
|
|
|
* \ingroup blenkernel
|
|
|
|
* \brief API for Blender-side Rigid Body stuff
|
|
|
|
*/
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2013-01-23 06:56:22 +01:00
|
|
|
|
|
|
|
#ifndef __BKE_RIGIDBODY_H__
|
|
|
|
#define __BKE_RIGIDBODY_H__
|
|
|
|
|
|
|
|
struct RigidBodyWorld;
|
|
|
|
struct RigidBodyOb;
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph;
|
2013-01-23 06:56:22 +01:00
|
|
|
struct Scene;
|
|
|
|
struct Object;
|
|
|
|
|
|
|
|
/* -------------- */
|
|
|
|
/* Memory Management */
|
|
|
|
|
|
|
|
void BKE_rigidbody_free_world(struct RigidBodyWorld *rbw);
|
|
|
|
void BKE_rigidbody_free_object(struct Object *ob);
|
|
|
|
void BKE_rigidbody_free_constraint(struct Object *ob);
|
|
|
|
|
|
|
|
/* ...... */
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
struct RigidBodyOb *BKE_rigidbody_copy_object(const struct Object *ob, const int flag);
|
|
|
|
struct RigidBodyCon *BKE_rigidbody_copy_constraint(const struct Object *ob, const int flag);
|
2013-01-23 06:56:22 +01:00
|
|
|
|
2015-10-08 14:59:24 +02:00
|
|
|
/* Callback format for performing operations on ID-pointers for rigidbody world. */
|
2017-01-31 10:41:25 +01:00
|
|
|
typedef void (*RigidbodyWorldIDFunc)(struct RigidBodyWorld *rbw, struct ID **idpoin, void *userdata, int cb_flag);
|
2015-10-08 14:59:24 +02:00
|
|
|
|
|
|
|
void BKE_rigidbody_world_id_loop(struct RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata);
|
|
|
|
|
2013-01-23 06:56:22 +01:00
|
|
|
/* -------------- */
|
|
|
|
/* Setup */
|
|
|
|
|
2013-11-01 00:52:44 +01:00
|
|
|
/* create Blender-side settings data - physics objects not initialized yet */
|
2013-01-23 06:56:22 +01:00
|
|
|
struct RigidBodyWorld *BKE_rigidbody_create_world(struct Scene *scene);
|
|
|
|
struct RigidBodyOb *BKE_rigidbody_create_object(struct Scene *scene, struct Object *ob, short type);
|
|
|
|
struct RigidBodyCon *BKE_rigidbody_create_constraint(struct Scene *scene, struct Object *ob, short type);
|
|
|
|
|
2013-04-25 01:09:25 +02:00
|
|
|
/* copy */
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
struct RigidBodyWorld *BKE_rigidbody_world_copy(struct RigidBodyWorld *rbw, const int flag);
|
2013-04-25 01:09:25 +02:00
|
|
|
void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw);
|
|
|
|
|
2013-01-23 06:56:22 +01:00
|
|
|
/* 'validate' (i.e. make new or replace old) Physics-Engine objects */
|
2013-12-26 21:30:53 +01:00
|
|
|
void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct RigidBodyWorld *rbw, bool rebuild);
|
2013-01-23 06:56:22 +01:00
|
|
|
|
2014-07-11 12:06:13 +02:00
|
|
|
void BKE_rigidbody_calc_volume(struct Object *ob, float *r_vol);
|
2015-07-19 21:19:47 +02:00
|
|
|
void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_center[3]);
|
2014-07-11 12:06:13 +02:00
|
|
|
|
2013-01-23 06:56:22 +01:00
|
|
|
/* -------------- */
|
|
|
|
/* Utilities */
|
|
|
|
|
|
|
|
struct RigidBodyWorld *BKE_rigidbody_get_world(struct Scene *scene);
|
2018-06-19 14:57:07 +02:00
|
|
|
void BKE_rigidbody_remove_object(struct Main *bmain, struct Scene *scene, struct Object *ob);
|
2013-01-23 06:56:22 +01:00
|
|
|
void BKE_rigidbody_remove_constraint(struct Scene *scene, struct Object *ob);
|
|
|
|
|
|
|
|
/* -------------- */
|
|
|
|
/* Utility Macros */
|
|
|
|
|
|
|
|
/* get mass of Rigid Body Object to supply to RigidBody simulators */
|
|
|
|
#define RBO_GET_MASS(rbo) \
|
|
|
|
((rbo && ((rbo->type == RBO_TYPE_PASSIVE) || (rbo->flag & RBO_FLAG_KINEMATIC) || (rbo->flag & RBO_FLAG_DISABLED))) ? (0.0f) : (rbo->mass))
|
|
|
|
/* get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, convex hull always uses custom margin */
|
|
|
|
#define RBO_GET_MARGIN(rbo) \
|
|
|
|
((rbo->flag & RBO_FLAG_USE_MARGIN || rbo->shape == RB_SHAPE_CONVEXH || rbo->shape == RB_SHAPE_TRIMESH || rbo->shape == RB_SHAPE_CONE) ? (rbo->margin) : (0.04f))
|
|
|
|
|
|
|
|
/* -------------- */
|
|
|
|
/* Simulation */
|
|
|
|
|
2013-01-23 13:06:18 +01:00
|
|
|
void BKE_rigidbody_aftertrans_update(struct Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle);
|
2013-02-16 17:17:45 +01:00
|
|
|
void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime);
|
2013-04-07 16:09:29 +02:00
|
|
|
bool BKE_rigidbody_check_sim_running(struct RigidBodyWorld *rbw, float ctime);
|
2013-01-23 06:56:22 +01:00
|
|
|
void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw);
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, struct Scene *scene, float ctime);
|
|
|
|
void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, struct Scene *scene, float ctime);
|
2013-01-23 06:56:22 +01:00
|
|
|
|
2015-05-12 10:57:11 +02:00
|
|
|
/* -------------------- */
|
|
|
|
/* Depsgraph evaluation */
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph,
|
2015-05-12 10:57:11 +02:00
|
|
|
struct Scene *scene);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph,
|
2015-05-12 10:57:11 +02:00
|
|
|
struct Scene *scene);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_rigidbody_object_sync_transforms(struct Depsgraph *depsgraph,
|
2015-05-12 10:57:11 +02:00
|
|
|
struct Scene *scene,
|
|
|
|
struct Object *ob);
|
|
|
|
|
2013-01-23 06:56:22 +01:00
|
|
|
#endif /* __BKE_RIGIDBODY_H__ */
|