Blender  V2.93
BKE_collision.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) Blender Foundation.
17  * All rights reserved.
18  */
19 #pragma once
20 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct BVHTree;
30 struct Collection;
32 struct Depsgraph;
33 struct MVert;
34 struct MVertTri;
35 struct Object;
36 
38 // used for collisions in collision.c
40 
41 /* COLLISION FLAGS */
42 typedef enum {
43  COLLISION_IN_FUTURE = (1 << 1),
44 #ifdef WITH_ELTOPO
45  COLLISION_USE_COLLFACE = (1 << 2),
46  COLLISION_IS_EDGES = (1 << 3),
47 #endif
48  COLLISION_INACTIVE = (1 << 4),
50 
52 // used for collisions in collision.c
54 /* used for collisions in collision.c */
55 typedef struct CollPair {
56  unsigned int face1; /* cloth face */
57  unsigned int face2; /* object face */
58  float distance;
59  float normal[3];
60  float vector[3]; /* unnormalized collision vector: p2-p1 */
61  float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
62  int flag;
63  float time; /* collision time, from 0 up to 1 */
64 
65  /* mesh-mesh collision */
66 #ifdef WITH_ELTOPO /*either ap* or bp* can be set, but not both*/
67  float bary[3];
68  int ap1, ap2, ap3, collp, bp1, bp2, bp3;
69  int collface;
70 #else
71  int ap1, ap2, ap3, bp1, bp2, bp3;
72 #endif
73  int pointsb[4];
75 
76 /* used for collisions in collision.c */
77 typedef struct EdgeCollPair {
78  unsigned int p11, p12, p21, p22;
79  float normal[3];
80  float vector[3];
81  float time;
82  int lastsign;
83  float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
85 
86 /* used for collisions in collision.c */
87 typedef struct FaceCollPair {
88  unsigned int p11, p12, p13, p21;
89  float normal[3];
90  float vector[3];
91  float time;
92  int lastsign;
93  float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
95 
97 
99 // forward declarations
101 
103 // used in modifier.c from collision.c
105 
106 struct BVHTree *bvhtree_build_from_mvert(const struct MVert *mvert,
107  const struct MVertTri *tri,
108  int tri_num,
109  float epsilon);
110 void bvhtree_update_from_mvert(struct BVHTree *bvhtree,
111  const struct MVert *mvert,
112  const struct MVert *mvert_moving,
113  const struct MVertTri *tri,
114  int tri_num,
115  bool moving);
116 
118 
119 /* move Collision modifier object inter-frame with step = [0,1]
120  * defined in collisions.c */
121 void collision_move_object(struct CollisionModifierData *collmd,
122  const float step,
123  const float prevstep,
124  const bool moving_bvh);
125 
126 void collision_get_collider_velocity(float vel_old[3],
127  float vel_new[3],
128  struct CollisionModifierData *collmd,
129  struct CollPair *collpair);
130 
131 /* Collision relations for dependency graph build. */
132 
133 typedef struct CollisionRelation {
135  struct Object *ob;
137 
139  struct Collection *collection,
140  unsigned int modifier_type);
141 void BKE_collision_relations_free(struct ListBase *relations);
142 
143 /* Collision object lists for physics simulation evaluation. */
144 
146  struct Object *self,
147  struct Collection *collection,
148  unsigned int *numcollobj,
149  unsigned int modifier_type);
150 void BKE_collision_objects_free(struct Object **objects);
151 
152 typedef struct ColliderCache {
154  struct Object *ob;
157 
159  struct Object *self,
160  struct Collection *collection);
161 void BKE_collider_cache_free(struct ListBase **colliders);
162 
164 
166 
167 #ifdef __cplusplus
168 }
169 #endif
void collision_move_object(struct CollisionModifierData *collmd, const float step, const float prevstep, const bool moving_bvh)
Definition: collision.c:82
COLLISION_FLAGS
Definition: BKE_collision.h:42
@ COLLISION_INACTIVE
Definition: BKE_collision.h:48
@ COLLISION_IN_FUTURE
Definition: BKE_collision.h:43
struct ListBase * BKE_collision_relations_create(struct Depsgraph *depsgraph, struct Collection *collection, unsigned int modifier_type)
Definition: collision.c:1267
struct EdgeCollPair EdgeCollPair
void BKE_collider_cache_free(struct ListBase **colliders)
Definition: collision.c:1383
struct Object ** BKE_collision_objects_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
Definition: collision.c:1297
struct BVHTree * bvhtree_build_from_mvert(const struct MVert *mvert, const struct MVertTri *tri, int tri_num, float epsilon)
void BKE_collision_relations_free(struct ListBase *relations)
Definition: collision.c:1287
void bvhtree_update_from_mvert(struct BVHTree *bvhtree, const struct MVert *mvert, const struct MVert *mvert_moving, const struct MVertTri *tri, int tri_num, bool moving)
struct CollisionRelation CollisionRelation
void collision_get_collider_velocity(float vel_old[3], float vel_new[3], struct CollisionModifierData *collmd, struct CollPair *collpair)
Definition: collision.c:1740
void BKE_collision_objects_free(struct Object **objects)
Definition: collision.c:1337
struct ListBase * BKE_collider_cache_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection)
Definition: collision.c:1346
struct CollPair CollPair
struct ColliderCache ColliderCache
struct FaceCollPair FaceCollPair
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
const Depsgraph * depsgraph
static double epsilon
float distance
Definition: BKE_collision.h:58
float pa[3]
Definition: BKE_collision.h:61
unsigned int face1
Definition: BKE_collision.h:56
float pb[3]
Definition: BKE_collision.h:61
float time
Definition: BKE_collision.h:63
float normal[3]
Definition: BKE_collision.h:59
unsigned int face2
Definition: BKE_collision.h:57
int pointsb[4]
Definition: BKE_collision.h:73
struct ColliderCache * prev
struct Object * ob
struct CollisionModifierData * collmd
struct ColliderCache * next
struct CollisionRelation * next
struct CollisionRelation * prev
struct Object * ob
float pb[3]
Definition: BKE_collision.h:83
float pa[3]
Definition: BKE_collision.h:83
unsigned int p22
Definition: BKE_collision.h:78
unsigned int p11
Definition: BKE_collision.h:78
unsigned int p12
Definition: BKE_collision.h:78
float normal[3]
Definition: BKE_collision.h:79
unsigned int p21
Definition: BKE_collision.h:78
float normal[3]
Definition: BKE_collision.h:89
float pa[3]
Definition: BKE_collision.h:93
unsigned int p13
Definition: BKE_collision.h:88
float pb[3]
Definition: BKE_collision.h:93
unsigned int p12
Definition: BKE_collision.h:88
unsigned int p21
Definition: BKE_collision.h:88
unsigned int p11
Definition: BKE_collision.h:88