Blender V5.3
BKE_cloth.hh
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#include "BLI_ordered_edge.hh"
12#include "BLI_set.hh"
13
14#include <cfloat>
15
16namespace blender {
17
18struct BVHTree;
19struct ClothVertex;
22struct Depsgraph;
23struct Implicit_Data;
24struct LinkNode;
25struct Mesh;
26struct Object;
27struct Scene;
28
29#define DO_INLINE MALWAYS_INLINE
30
31/* Goal defines. */
32#define SOFTGOALSNAP 0.999f
33
34/* This is approximately the smallest number that can be
35 * represented by a float, given its precision. */
36#define ALMOST_ZERO FLT_EPSILON
37
38/* Bits to or into the #ClothVertex.flags. */
41 CLOTH_VERT_FLAG_NOSELFCOLL = (1 << 1), /* vertex NOT used for self collisions */
42 CLOTH_VERT_FLAG_NOOBJCOLL = (1 << 2), /* vertex NOT used for object collisions */
43};
44
46 float loc[3];
47 float rot[3][3];
48 float rest_target[3]; /* rest target direction for each segment */
49 float radius;
51};
52
60
70struct Cloth {
71 ClothVertex *verts; /* The vertices that represent this cloth. */
72 LinkNode *springs; /* The springs connecting the mesh. */
73 unsigned int numsprings; /* The count of springs. */
74 unsigned int mvert_num; /* The number of verts == m * n. */
75 unsigned int primitive_num; /* Number of triangles for cloth and edges for hair. */
76 unsigned char old_solver_type; /* unused, only 1 solver here */
77 unsigned char pad2;
78 short pad3;
79 BVHTree *bvhtree; /* collision tree for this cloth object */
80 BVHTree *bvhselftree; /* Collision tree for this cloth object (may be same as BVH-tree). */
82 Implicit_Data *implicit; /* our implicit solver connects to this pointer */
83 Set<OrderedEdge> edgeset; /* Used for self-collisions. */
85 float initial_mesh_volume; /* Initial volume of the mesh. Used for pressure */
86 float average_acceleration[3]; /* Moving average of overall acceleration. */
87 const int2 *edges; /* Used for hair collisions. */
88 Set<OrderedEdge> sew_edge_graph; /* Sewing edges. */
89};
90
95 int flags; /* General flags per vertex. */
96 float v[3]; /* The velocity of the point. */
97 float xconst[3]; /* constrained position */
98 float x[3]; /* The current position of this vertex. */
99 float xold[3]; /* The previous position of this vertex. */
100 float tx[3]; /* temporary position */
101 float txold[3]; /* temporary old position */
102 float tv[3]; /* temporary "velocity", mostly used as tv = tx-txold */
103 float mass; /* mass / weight of the vertex */
104 float goal; /* goal, from SB */
105 float impulse[3]; /* used in collision.cc */
106 float xrest[3]; /* rest position of the vertex */
107 float dcvel[3]; /* delta velocities to be applied by collision response */
108 unsigned int impulse_count; /* same as above */
109 float avg_spring_len; /* average length of connected springs */
113 int spring_count; /* how many springs attached? */
114 float shrink_factor; /* how much to shrink this cloth */
115 float internal_stiff; /* internal spring stiffness scaling */
116 float pressure_factor; /* how much pressure should affect this vertex */
117};
118
123 int ij; /* `Pij` from the paper, one end of the spring. */
124 int kl; /* `Pkl` from the paper, one end of the spring. */
125 int mn; /* For hair springs: third vertex index; For bending springs: edge index. */
126 int *pa; /* Array of vert indices for poly a (for bending springs). */
127 int *pb; /* Array of vert indices for poly b (for bending springs). */
128 int la; /* Length of `*pa`. */
129 int lb; /* Length of `*pb`. */
130 float restlen; /* The original length of the spring. */
131 float restang; /* The original angle of the bending springs. */
132 int type; /* Types defined in BKE_cloth.hh ("springType"). */
133 int flags; /* Defined in BKE_cloth.hh, e.g. deactivated due to tearing. */
134 float lin_stiffness; /* Linear stiffness factor from the vertex groups. */
135 float ang_stiffness; /* Angular stiffness factor from the vertex groups. */
137
138 /* angular bending spring target and derivatives */
139 float target[3];
140};
141
142/* Some macro enhancements for vector treatment. */
143#define VECSUBADDSS(v1, v2, aS, v3, bS) \
144 { \
145 *(v1) -= *(v2) * aS + *(v3) * bS; \
146 *(v1 + 1) -= *(v2 + 1) * aS + *(v3 + 1) * bS; \
147 *(v1 + 2) -= *(v2 + 2) * aS + *(v3 + 2) * bS; \
148 } \
149 ((void)0)
150#define VECADDSS(v1, v2, aS, v3, bS) \
151 { \
152 *(v1) = *(v2) * aS + *(v3) * bS; \
153 *(v1 + 1) = *(v2 + 1) * aS + *(v3 + 1) * bS; \
154 *(v1 + 2) = *(v2 + 2) * aS + *(v3 + 2) * bS; \
155 } \
156 ((void)0)
157#define VECADDS(v1, v2, v3, bS) \
158 { \
159 *(v1) = *(v2) + *(v3) * bS; \
160 *(v1 + 1) = *(v2 + 1) + *(v3 + 1) * bS; \
161 *(v1 + 2) = *(v2 + 2) + *(v3 + 2) * bS; \
162 } \
163 ((void)0)
164#define VECSUBMUL(v1, v2, aS) \
165 { \
166 *(v1) -= *(v2) * aS; \
167 *(v1 + 1) -= *(v2 + 1) * aS; \
168 *(v1 + 2) -= *(v2 + 2) * aS; \
169 } \
170 ((void)0)
171#define VECSUBS(v1, v2, v3, bS) \
172 { \
173 *(v1) = *(v2) - *(v3) * bS; \
174 *(v1 + 1) = *(v2 + 1) - *(v3 + 1) * bS; \
175 *(v1 + 2) = *(v2 + 2) - *(v3 + 2) * bS; \
176 } \
177 ((void)0)
178#define VECADDMUL(v1, v2, aS) \
179 { \
180 *(v1) += *(v2) * aS; \
181 *(v1 + 1) += *(v2 + 1) * aS; \
182 *(v1 + 2) += *(v2 + 2) * aS; \
183 } \
184 ((void)0)
185
186/* Spring types as defined in the paper. */
196
197/* SPRING FLAGS */
200 CLOTH_SPRING_FLAG_NEEDED = (1 << 2), /* Springs has values to be applied. */
201};
202
203/* -------------------------------------------------------------------- */
204/* collision.cc */
205
206struct CollPair;
207
215
216/* needed for implicit.c */
218 Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt);
219
220/* -------------------------------------------------------------------- */
221/* cloth.cc */
222
223/* Needed for modifier.cc */
229 Depsgraph *depsgraph,
230 Scene *scene,
231 Object *ob,
232 const Mesh *mesh,
233 float (*vertexCos)[3]);
234
236
237/* Needed for collision.cc */
238void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self);
239
240/* Needed for button_object.c */
241void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr);
242
243void cloth_parallel_transport_hair_frame(float mat[3][3],
244 const float dir_old[3],
245 const float dir_new[3]);
246
247} // namespace blender
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
BMesh Iterators.
int cloth_uses_vgroup(ClothModifierData *clmd)
Definition cloth.cc:599
void cloth_free_modifier(ClothModifierData *clmd)
Definition cloth.cc:445
CLOTH_SPRING_TYPES
Definition BKE_cloth.hh:187
@ CLOTH_SPRING_TYPE_BENDING
Definition BKE_cloth.hh:190
@ CLOTH_SPRING_TYPE_STRUCTURAL
Definition BKE_cloth.hh:188
@ CLOTH_SPRING_TYPE_SHEAR
Definition BKE_cloth.hh:189
@ CLOTH_SPRING_TYPE_SEWING
Definition BKE_cloth.hh:192
@ CLOTH_SPRING_TYPE_INTERNAL
Definition BKE_cloth.hh:194
@ CLOTH_SPRING_TYPE_BENDING_HAIR
Definition BKE_cloth.hh:193
@ CLOTH_SPRING_TYPE_GOAL
Definition BKE_cloth.hh:191
void clothModifier_do(ClothModifierData *clmd, Depsgraph *depsgraph, Scene *scene, Object *ob, const Mesh *mesh, float(*vertexCos)[3])
Definition cloth.cc:327
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
void cloth_parallel_transport_hair_frame(float mat[3][3], const float dir_old[3], const float dir_new[3])
Definition cloth.cc:1274
void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
Definition cloth.cc:208
int cloth_bvh_collision(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt)
void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self)
Definition cloth.cc:123
void cloth_free_modifier_extern(ClothModifierData *clmd)
Definition cloth.cc:506
eClothVertexFlag
Definition BKE_cloth.hh:39
@ CLOTH_VERT_FLAG_NOSELFCOLL
Definition BKE_cloth.hh:41
@ CLOTH_VERT_FLAG_NOOBJCOLL
Definition BKE_cloth.hh:42
@ CLOTH_VERT_FLAG_PINNED
Definition BKE_cloth.hh:40
CLOTH_SPRINGS_FLAGS
Definition BKE_cloth.hh:198
@ CLOTH_SPRING_FLAG_DEACTIVATE
Definition BKE_cloth.hh:199
@ CLOTH_SPRING_FLAG_NEEDED
Definition BKE_cloth.hh:200
unsigned int impulse_count
Definition BKE_cloth.hh:108
unsigned char old_solver_type
Definition BKE_cloth.hh:76
float average_acceleration[3]
Definition BKE_cloth.hh:86
unsigned char pad2
Definition BKE_cloth.hh:77
unsigned int numsprings
Definition BKE_cloth.hh:73
BVHTree * bvhtree
Definition BKE_cloth.hh:79
Set< OrderedEdge > sew_edge_graph
Definition BKE_cloth.hh:88
unsigned int mvert_num
Definition BKE_cloth.hh:74
const int2 * edges
Definition BKE_cloth.hh:87
Implicit_Data * implicit
Definition BKE_cloth.hh:82
Set< OrderedEdge > edgeset
Definition BKE_cloth.hh:83
unsigned int primitive_num
Definition BKE_cloth.hh:75
ClothVertex * verts
Definition BKE_cloth.hh:71
int3 * vert_tris
Definition BKE_cloth.hh:81
BVHTree * bvhselftree
Definition BKE_cloth.hh:80
LinkNode * springs
Definition BKE_cloth.hh:72
float initial_mesh_volume
Definition BKE_cloth.hh:85
CollisionModifierData * collmd
Definition BKE_cloth.hh:210