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