Blender V5.0
BKE_collision.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
9
11
12struct BVHTree;
13struct Collection;
15struct Depsgraph;
16struct Object;
17
18/* -------------------------------------------------------------------- */
23
24/* COLLISION FLAGS */
25typedef enum {
27#ifdef WITH_ELTOPO
28 COLLISION_USE_COLLFACE = (1 << 2),
29 COLLISION_IS_EDGES = (1 << 3),
30#endif
33
34typedef struct CollPair {
35 unsigned int face1; /* cloth face */
36 unsigned int face2; /* object face */
37 float distance;
38 float normal[3];
39 float vector[3]; /* unnormalized collision vector: p2-p1 */
40 float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
41 int flag;
42 float time; /* collision time, from 0 up to 1 */
43
44 /* mesh-mesh collision */
45#ifdef WITH_ELTOPO /* Either ap* or bp* can be set, but not both. */
46 float bary[3];
47 int ap1, ap2, ap3, collp, bp1, bp2, bp3;
48 int collface;
49#else
50 int ap1, ap2, ap3, bp1, bp2, bp3;
51#endif
52 /* Barycentric weights of the collision point. */
53 float aw1, aw2, aw3, bw1, bw2, bw3;
54 int pointsb[4];
56
57typedef struct EdgeCollPair {
58 unsigned int p11, p12, p21, p22;
59 float normal[3];
60 float vector[3];
61 float time;
63 float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
65
66typedef struct FaceCollPair {
67 unsigned int p11, p12, p13, p21;
68 float normal[3];
69 float vector[3];
70 float time;
72 float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
74
76
77/* Forward declarations. */
78
79/* -------------------------------------------------------------------- */
84struct BVHTree *bvhtree_build_from_mvert(const float (*positions)[3],
85 const blender::int3 *vert_tris,
86 int tri_num,
87 float epsilon);
88void bvhtree_update_from_mvert(struct BVHTree *bvhtree,
89 const float (*positions)[3],
90 const float (*positions_moving)[3],
91 const blender::int3 *vert_tris,
92 int tri_num,
93 bool moving);
95
96/* -------------------------------------------------------------------- */
99
106 float step,
107 float prevstep,
108 bool moving_bvh);
109
110void collision_get_collider_velocity(float vel_old[3],
111 float vel_new[3],
112 struct CollisionModifierData *collmd,
113 struct CollPair *collpair);
114
116
117/* -------------------------------------------------------------------- */
122
127
133struct ListBase *BKE_collision_relations_create(struct Depsgraph *depsgraph,
134 struct Collection *collection,
135 unsigned int modifier_type);
136void BKE_collision_relations_free(struct ListBase *relations);
137
138/* Collision object lists for physics simulation evaluation. */
139
144struct Object **BKE_collision_objects_create(struct Depsgraph *depsgraph,
145 struct Object *self,
146 struct Collection *collection,
147 unsigned int *numcollobj,
148 unsigned int modifier_type);
149void BKE_collision_objects_free(struct Object **objects);
150
152
153/* -------------------------------------------------------------------- */
156
162
167struct ListBase *BKE_collider_cache_create(struct Depsgraph *depsgraph,
168 struct Object *self,
169 struct Collection *collection);
170void BKE_collider_cache_free(struct ListBase **colliders);
171
struct ListBase * BKE_collision_relations_create(struct Depsgraph *depsgraph, struct Collection *collection, unsigned int modifier_type)
COLLISION_FLAGS
@ COLLISION_INACTIVE
@ COLLISION_IN_FUTURE
void BKE_collider_cache_free(struct ListBase **colliders)
void BKE_collision_relations_free(struct ListBase *relations)
void collision_get_collider_velocity(float vel_old[3], float vel_new[3], struct CollisionModifierData *collmd, struct CollPair *collpair)
void BKE_collision_objects_free(struct Object **objects)
struct ListBase * BKE_collider_cache_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection)
struct BVHTree * bvhtree_build_from_mvert(const float(*positions)[3], const blender::int3 *vert_tris, int tri_num, float epsilon)
Definition collision.cc:89
void bvhtree_update_from_mvert(struct BVHTree *bvhtree, const float(*positions)[3], const float(*positions_moving)[3], const blender::int3 *vert_tris, int tri_num, bool moving)
Definition collision.cc:113
void collision_move_object(struct CollisionModifierData *collmd, float step, float prevstep, bool moving_bvh)
Definition collision.cc:59
struct Object ** BKE_collision_objects_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
PyObject * self
BPy_StructRNA * depsgraph
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
VecBase< int32_t, 3 > int3
float epsilon
float distance
float pa[3]
unsigned int face1
float pb[3]
float normal[3]
unsigned int face2
int pointsb[4]
float vector[3]
struct ColliderCache * prev
struct Object * ob
struct CollisionModifierData * collmd
struct ColliderCache * next
struct CollisionRelation * next
struct CollisionRelation * prev
struct Object * ob
unsigned int p22
unsigned int p11
unsigned int p12
float vector[3]
float normal[3]
unsigned int p21
float normal[3]
float vector[3]
unsigned int p13
unsigned int p12
unsigned int p21
unsigned int p11