Blender  V2.93
BKE_rigidbody.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation
17  * All rights reserved.
18  */
19 
25 #pragma once
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 struct RigidBodyOb;
32 struct RigidBodyWorld;
33 
34 struct Collection;
35 struct Depsgraph;
36 struct Main;
37 struct Object;
38 struct ReportList;
39 struct Scene;
40 
41 /* -------------- */
42 /* Memory Management */
43 
45 void BKE_rigidbody_free_object(struct Object *ob, struct RigidBodyWorld *rbw);
46 void BKE_rigidbody_free_constraint(struct Object *ob);
47 
48 /* ...... */
49 
50 void BKE_rigidbody_object_copy(struct Main *bmain,
51  struct Object *ob_dst,
52  const struct Object *ob_src,
53  const int flag);
54 
55 /* Callback format for performing operations on ID-pointers for rigidbody world. */
56 typedef void (*RigidbodyWorldIDFunc)(struct RigidBodyWorld *rbw,
57  struct ID **idpoin,
58  void *userdata,
59  int cb_flag);
60 
63  void *userdata);
64 
65 /* -------------- */
66 /* Setup */
67 
68 /* create Blender-side settings data - physics objects not initialized yet */
71  struct Object *ob,
72  short type);
74  struct Object *ob,
75  short type);
76 
77 /* Ensure newly set collections' objects all have required data. */
80  struct RigidBodyWorld *rbw);
81 
82 /* Ensure object added to collection gets RB data if that collection is a RB one. */
84  struct Collection *collection,
85  struct Object *object);
86 
87 /* copy */
88 struct RigidBodyWorld *BKE_rigidbody_world_copy(struct RigidBodyWorld *rbw, const int flag);
90 
91 /* 'validate' (i.e. make new or replace old) Physics-Engine objects */
93  struct RigidBodyWorld *rbw,
94  bool rebuild);
95 
96 void BKE_rigidbody_calc_volume(struct Object *ob, float *r_vol);
97 void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_center[3]);
98 
99 /* -------------- */
100 /* Utilities */
101 
103 bool BKE_rigidbody_add_object(struct Main *bmain,
104  struct Scene *scene,
105  struct Object *ob,
106  int type,
107  struct ReportList *reports);
108 void BKE_rigidbody_ensure_local_object(struct Main *bmain, struct Object *ob);
109 void BKE_rigidbody_remove_object(struct Main *bmain,
110  struct Scene *scene,
111  struct Object *ob,
112  const bool free_us);
113 void BKE_rigidbody_remove_constraint(struct Main *bmain,
114  struct Scene *scene,
115  struct Object *ob,
116  const bool free_us);
117 
118 /* -------------- */
119 /* Utility Macros */
120 
121 /* get mass of Rigid Body Object to supply to RigidBody simulators */
122 #define RBO_GET_MASS(rbo) \
123  (((rbo) && (((rbo)->type == RBO_TYPE_PASSIVE) || ((rbo)->flag & RBO_FLAG_KINEMATIC) || \
124  ((rbo)->flag & RBO_FLAG_DISABLED))) ? \
125  (0.0f) : \
126  ((rbo)->mass))
127 /* Get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin,
128  * convex hull always uses custom margin. */
129 #define RBO_GET_MARGIN(rbo) \
130  (((rbo)->flag & RBO_FLAG_USE_MARGIN || (rbo)->shape == RB_SHAPE_CONVEXH || \
131  (rbo)->shape == RB_SHAPE_TRIMESH || (rbo)->shape == RB_SHAPE_CONE) ? \
132  ((rbo)->margin) : \
133  (0.04f))
134 
135 /* -------------- */
136 /* Simulation */
137 
139  float loc[3],
140  float rot[3],
141  float quat[4],
142  float rotAxis[3],
143  float rotAngle);
144 void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime);
145 bool BKE_rigidbody_check_sim_running(struct RigidBodyWorld *rbw, float ctime);
147 void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw);
148 void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, struct Scene *scene, float ctime);
149 void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, struct Scene *scene, float ctime);
150 
151 /* -------------------- */
152 /* Depsgraph evaluation */
153 
155 
157 
159  struct Scene *scene,
160  struct Object *ob);
161 
162 #ifdef __cplusplus
163 }
164 #endif
bool BKE_rigidbody_is_affected_by_simulation(struct Object *ob)
Definition: rigidbody.c:232
void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, struct Scene *scene, float ctime)
Definition: rigidbody.c:2342
void BKE_rigidbody_object_copy(struct Main *bmain, struct Object *ob_dst, const struct Object *ob_src, const int flag)
void(* RigidbodyWorldIDFunc)(struct RigidBodyWorld *rbw, struct ID **idpoin, void *userdata, int cb_flag)
Definition: BKE_rigidbody.h:56
void BKE_rigidbody_free_constraint(struct Object *ob)
Definition: rigidbody.c:212
void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw)
Definition: rigidbody.c:2339
void BKE_rigidbody_remove_constraint(struct Main *bmain, struct Scene *scene, struct Object *ob, const bool free_us)
Definition: rigidbody.c:2325
void BKE_rigidbody_remove_object(struct Main *bmain, struct Scene *scene, struct Object *ob, const bool free_us)
Definition: rigidbody.c:2322
void BKE_rigidbody_aftertrans_update(struct Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle)
Definition: rigidbody.c:2331
void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_center[3])
Definition: rigidbody.c:2279
void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, struct Scene *scene, float ctime)
Definition: rigidbody.c:2345
void BKE_rigidbody_free_world(struct Scene *scene)
Definition: rigidbody.c:107
void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph, struct Scene *scene)
Definition: rigidbody.c:2377
void BKE_rigidbody_constraints_collection_validate(struct Scene *scene, struct RigidBodyWorld *rbw)
Definition: rigidbody.c:2351
struct RigidBodyWorld * BKE_rigidbody_create_world(struct Scene *scene)
Definition: rigidbody.c:2283
bool BKE_rigidbody_check_sim_running(struct RigidBodyWorld *rbw, float ctime)
Definition: rigidbody.c:2335
void BKE_rigidbody_world_id_loop(struct RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata)
Definition: rigidbody.c:2294
void BKE_rigidbody_calc_volume(struct Object *ob, float *r_vol)
Definition: rigidbody.c:2273
void BKE_rigidbody_ensure_local_object(struct Main *bmain, struct Object *ob)
Definition: rigidbody.c:2312
void BKE_rigidbody_objects_collection_validate(struct Scene *scene, struct RigidBodyWorld *rbw)
Definition: rigidbody.c:2348
struct RigidBodyWorld * BKE_rigidbody_world_copy(struct RigidBodyWorld *rbw, const int flag)
Definition: rigidbody.c:2287
void BKE_rigidbody_free_object(struct Object *ob, struct RigidBodyWorld *rbw)
Definition: rigidbody.c:164
void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph, struct Scene *scene)
Definition: rigidbody.c:2367
struct RigidBodyWorld * BKE_rigidbody_get_world(struct Scene *scene)
Definition: rigidbody.c:2307
void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw)
Definition: rigidbody.c:2291
struct RigidBodyCon * BKE_rigidbody_create_constraint(struct Scene *scene, struct Object *ob, short type)
Definition: rigidbody.c:2303
void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime)
Definition: rigidbody.c:2328
void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct RigidBodyWorld *rbw, bool rebuild)
Definition: rigidbody.c:2270
void BKE_rigidbody_object_sync_transforms(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
Definition: rigidbody.c:2389
bool BKE_rigidbody_add_object(struct Main *bmain, struct Scene *scene, struct Object *ob, int type, struct ReportList *reports)
Definition: rigidbody.c:2316
struct RigidBodyOb * BKE_rigidbody_create_object(struct Scene *scene, struct Object *ob, short type)
Definition: rigidbody.c:2299
void BKE_rigidbody_main_collection_object_add(struct Main *bmain, struct Collection *collection, struct Object *object)
Definition: rigidbody.c:2354
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Scene scene
const Depsgraph * depsgraph
#define rot(x, k)
Definition: DNA_ID.h:273
Definition: BKE_main.h:116
short flag