Blender V4.3
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
11
12struct BVHTree;
13struct Collection;
15struct Depsgraph;
16struct Object;
17
19// used for collisions in collision.cc
21
22/* COLLISION FLAGS */
23typedef enum {
25#ifdef WITH_ELTOPO
26 COLLISION_USE_COLLFACE = (1 << 2),
27 COLLISION_IS_EDGES = (1 << 3),
28#endif
31
33// used for collisions in collision.cc
35/* used for collisions in collision.cc */
36typedef struct CollPair {
37 unsigned int face1; /* cloth face */
38 unsigned int face2; /* object face */
39 float distance;
40 float normal[3];
41 float vector[3]; /* unnormalized collision vector: p2-p1 */
42 float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
43 int flag;
44 float time; /* collision time, from 0 up to 1 */
45
46 /* mesh-mesh collision */
47#ifdef WITH_ELTOPO /* Either ap* or bp* can be set, but not both. */
48 float bary[3];
49 int ap1, ap2, ap3, collp, bp1, bp2, bp3;
50 int collface;
51#else
52 int ap1, ap2, ap3, bp1, bp2, bp3;
53#endif
54 /* Barycentric weights of the collision point. */
55 float aw1, aw2, aw3, bw1, bw2, bw3;
56 int pointsb[4];
58
59/* used for collisions in collision.cc */
60typedef struct EdgeCollPair {
61 unsigned int p11, p12, p21, p22;
62 float normal[3];
63 float vector[3];
64 float time;
66 float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
68
69/* used for collisions in collision.cc */
70typedef struct FaceCollPair {
71 unsigned int p11, p12, p13, p21;
72 float normal[3];
73 float vector[3];
74 float time;
76 float pa[3], pb[3]; /* collision point p1 on face1, p2 on face2 */
78
80
82// forward declarations
84
86// used in modifier.cc from collision.cc
88
89struct BVHTree *bvhtree_build_from_mvert(const float (*positions)[3],
90 const blender::int3 *vert_tris,
91 int tri_num,
92 float epsilon);
93void bvhtree_update_from_mvert(struct BVHTree *bvhtree,
94 const float (*positions)[3],
95 const float (*positions_moving)[3],
96 const blender::int3 *vert_tris,
97 int tri_num,
98 bool moving);
99
101
108 float step,
109 float prevstep,
110 bool moving_bvh);
111
112void collision_get_collider_velocity(float vel_old[3],
113 float vel_new[3],
114 struct CollisionModifierData *collmd,
115 struct CollPair *collpair);
116
117/* Collision relations for dependency graph build. */
118
123
129struct ListBase *BKE_collision_relations_create(struct Depsgraph *depsgraph,
130 struct Collection *collection,
131 unsigned int modifier_type);
132void BKE_collision_relations_free(struct ListBase *relations);
133
134/* Collision object lists for physics simulation evaluation. */
135
140struct Object **BKE_collision_objects_create(struct Depsgraph *depsgraph,
141 struct Object *self,
142 struct Collection *collection,
143 unsigned int *numcollobj,
144 unsigned int modifier_type);
145void BKE_collision_objects_free(struct Object **objects);
146
152
157struct ListBase *BKE_collider_cache_create(struct Depsgraph *depsgraph,
158 struct Object *self,
159 struct Collection *collection);
160void BKE_collider_cache_free(struct ListBase **colliders);
161
163
struct ListBase * BKE_collision_relations_create(struct Depsgraph *depsgraph, struct Collection *collection, unsigned int modifier_type)
COLLISION_FLAGS
@ COLLISION_INACTIVE
@ COLLISION_IN_FUTURE
struct EdgeCollPair EdgeCollPair
void BKE_collider_cache_free(struct ListBase **colliders)
void BKE_collision_relations_free(struct ListBase *relations)
struct CollisionRelation CollisionRelation
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:90
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:114
void collision_move_object(struct CollisionModifierData *collmd, float step, float prevstep, bool moving_bvh)
Definition collision.cc:60
struct CollPair CollPair
struct ColliderCache ColliderCache
struct Object ** BKE_collision_objects_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
struct FaceCollPair FaceCollPair
PyObject * self
const Depsgraph * depsgraph
float epsilon
Definition BLI_kdopbvh.c:82
float distance
float pa[3]
unsigned int face1
float pb[3]
unsigned int face2
int pointsb[4]
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
unsigned int p21
unsigned int p13
unsigned int p12
unsigned int p21
unsigned int p11