35static float I3[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
45 for (link =
cloth->springs; link; link = link->
next) {
47 switch (spring->
type) {
72 for (
uint j = 0; j < 3; j++) {
76 if (r_weights[j] == 0.0f) {
86 const float gradient_vector[3],
87 float *r_vertex_pressure)
94 for (
uint i = 0; i < mvert_num; i++) {
96 r_vertex_pressure[i] =
dot_v3v3(pt, gradient_vector);
104 const int3 *vert_tris =
cloth->vert_tris;
106 float weights[3] = {1.0f, 1.0f, 1.0f};
114 for (
uint i = 0; i <
cloth->primitive_num; i++) {
115 const int3 tri = vert_tris[i];
132 const int3 *vert_tris =
cloth->vert_tris;
134 float weights[3] = {1.0f, 1.0f, 1.0f};
142 for (
uint i = 0; i <
cloth->primitive_num; i++) {
143 const int3 tri = vert_tris[i];
147 v[tri[0]].xrest,
v[tri[1]].xrest,
v[tri[2]].xrest);
160 const int3 *vert_tris =
cloth->vert_tris;
162 float weights[3] = {1.0f, 1.0f, 1.0f};
163 float total_force = 0;
164 float total_area = 0;
166 for (
uint i = 0; i <
cloth->primitive_num; i++) {
167 const int3 tri = vert_tris[i];
172 total_force += (vertex_pressure[tri[0]] + vertex_pressure[tri[1]] +
173 vertex_pressure[tri[2]]) *
179 return total_force / total_area;
186 const float ZERO[3] = {0.0f, 0.0f, 0.0f};
193 for (i = 0; i <
cloth->mvert_num; i++) {
197 for (i = 0; i <
cloth->mvert_num; i++) {
213 if (
cloth->implicit) {
215 cloth->implicit =
nullptr;
227 for (i = 0; i < mvert_num; i++) {
228 if (cloth_hairdata) {
256 int mvert_num =
cloth->mvert_num;
259 const float ZERO[3] = {0.0f, 0.0f, 0.0f};
263 for (
v = 0;
v < mvert_num;
v++) {
283 "cos cloth_calc_helper_forces");
291 for (i = 0; i <
cloth->mvert_num; i++, cv++) {
298 masses[i] = cv->
mass;
303 for (i = 0; i < steps; i++) {
307 float len, c,
l, vec[3];
328 l = c / ((1.0f / masses[v1]) + (1.0f / masses[
v2]));
342 for (i = 0; i <
cloth->mvert_num; i++, cv++) {
371#ifdef CLOTH_FORCE_SPRING_BEND
378 k = scaling * s->
restlen * 0.1f;
389#ifdef CLOTH_FORCE_SPRING_STRUCTURAL
390 float k_tension, scaling_tension;
394 scaling_tension = parms->
tension +
415 float k_compression, scaling_compression;
448 if (k_tension == 0.0f) {
450 k_tension_damp = 0.0f;
453 if (k_compression == 0.0f) {
455 k_compression_damp = 0.0f;
473#ifdef CLOTH_FORCE_SPRING_SHEAR
495#ifdef CLOTH_FORCE_SPRING_BEND
496 float kb, cb, scaling;
510#ifdef CLOTH_FORCE_SPRING_BEND
511 float kb, cb, scaling;
531 float x_kl[3], x_mn[3],
v[3], d[3];
538 clmd->debug_data, x_kl, x_mn, 0.8, 0.8, 0.8,
"target", 7981, s->
kl);
542 clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2,
"target", 7982, s->
kl);
560 for (i = 0; i < mvert_num; i++) {
570 ListBaseT<EffectorCache> *effectors,
579 float gravity[3] = {0.0f, 0.0f, 0.0f};
580 const int3 *vert_tris =
cloth->vert_tris;
584#ifdef CLOTH_FORCE_GRAVITY
594 for (i = 0; i <
cloth->mvert_num; i++, vert++) {
599 float goal_x[3], goal_v[3];
617#ifdef CLOTH_FORCE_DRAG
623 float pressure_difference = 0.0f;
624 float volume_factor = 1.0f;
631 init_vol =
cloth->initial_mesh_volume;
635 if (init_vol > 1E-6f) {
640 volume_factor = init_vol / vol;
641 pressure_difference = volume_factor - 1;
655 float *hydrostatic_pressure =
nullptr;
657 if (
fabs(fluid_density) > 1e-6f) {
658 float hydrostatic_vector[3];
664 if (fluid_density > 0) {
668 fluid_density *= volume_factor;
671 mul_v3_fl(hydrostatic_vector, fluid_density);
675 "hydrostatic pressure gradient");
683 if (hydrostatic_pressure ||
fabs(pressure_difference) > 1E-6f) {
684 float weights[3] = {1.0f, 1.0f, 1.0f};
686 for (i = 0; i <
cloth->primitive_num; i++) {
687 const int3 tri = vert_tris[i];
691 data, tri[0], tri[1], tri[2], pressure_difference, hydrostatic_pressure, weights);
696 if (hydrostatic_pressure) {
697 MEM_delete(hydrostatic_pressure);
703 bool is_not_hair = (clmd->
hairdata ==
nullptr) && (
cloth->primitive_num > 0);
704 bool has_wind =
false, has_force =
false;
708 float (*forcevec)[3] = is_not_hair ? winvec + mvert_num : winvec;
710 for (i = 0; i <
cloth->mvert_num; i++) {
724 has_wind = has_wind || !
is_zero_v3(winvec[i]);
725 has_force = has_force || !
is_zero_v3(forcevec[i]);
730 for (i = 0; i <
cloth->primitive_num; i++) {
731 const int3 tri = vert_tris[i];
745 for (
LinkNode *link =
cloth->springs; link; link = link->next) {
749 hair_ij = &hairdata[spring->
ij];
750 hair_kl = &hairdata[spring->
kl];
763 for (i = 0; i <
cloth->mvert_num; i++, vert++) {
779 for (
LinkNode *link =
cloth->springs; link; link = link->next) {
791 const float cell_offset[3],
825 const float cell_scale,
826 const float cell_offset[3],
831 LinkNode *next_spring_link =
nullptr;
835 float x1[3], v1[3], x2[3],
v2[3], x3[3], v3[3], x4[3], v4[3];
836 float dir1[3], dir2[3], dir3[3];
856 while (spring_link) {
874 next_spring_link = spring_link->
next;
901 spring1 ? dir1 :
nullptr,
903 spring3 ? dir3 :
nullptr);
906 return next_spring_link;
913 int mvert_num =
cloth->mvert_num;
917 for (i = 0, vert =
cloth->verts; i < mvert_num; i++, vert++) {
920 cloth_get_vertex_motion_state(
data, vert,
x,
v);
925 float cellsize, gmin[3], cell_scale, cell_offset[3];
931 cell_scale = cellsize > 0.0f ? 1.0f / cellsize : 0.0f;
935 link =
cloth->springs;
954 int mvert_num =
cloth->mvert_num;
956 const float fluid_factor = 0.95f;
975 if (smoothfac > 0.0f || density_strength > 0.0f) {
984 for (i = 0; i < mvert_num; i++) {
985 float x[3],
v[3], nv[3];
1008 const int size = 64;
1010 float offset[3], a[3],
b[3];
1012 const float shift = 0.0f;
1025 for (j = 0; j < size; j++) {
1026 for (i = 0; i < size; i++) {
1027 float x[3],
v[3], gvel[3], gvel_smooth[3], gdensity;
1034 grid,
x, &gdensity, gvel, gvel_smooth,
nullptr,
nullptr);
1038 clmd->debug_data,
x, gdensity, 0.7, 0.3, 1,
"grid density", i, j, 3111);
1045 clmd->debug_data,
x, gvel, 0.4, 0, 1,
"grid velocity", i, j, 3112);
1047 clmd->debug_data,
x, gvel_smooth, 0.6, 1, 1,
"grid velocity", i, j, 3113);
1050 clmd->debug_data,
x, dvel, 0.4, 1, 0.7,
"grid velocity", i, j, 3114);
1052 if (gdensity > 0.0f) {
1053 float col0[3] = {0.0, 0.0, 0.0};
1054 float col1[3] = {0.0, 1.0, 0.0};
1073 clmd->debug_data,
x, col[0], col[1], col[2],
"grid velocity", i, j, 3115);
1076 clmd->debug_data,
x, 0.01f, col[0], col[1], col[2],
"grid velocity", i, j, 3115);
1090static void cloth_calc_volume_force(ClothModifierData *clmd)
1092 ClothSimSettings *parms = clmd->sim_parms;
1093 Cloth *cloth = clmd->clothObject;
1094 Implicit_Data *
data = cloth->implicit;
1095 int mvert_num = cloth->mvert_num;
1099 float smoothfac = 2.0f * parms->velocity_smooth;
1100 float collfac = 2.0f * parms->collider_friction;
1101 float pressfac = parms->pressure;
1102 float minpress = parms->pressure_threshold;
1103 float gmin[3], gmax[3];
1109 if (smoothfac > 0.0f || pressfac > 0.0f) {
1111 clmd->sim_parms->voxel_res, gmin, gmax);
1113 vert = cloth->verts;
1114 for (i = 0; i < mvert_num; i++, vert++) {
1117 if (vert->solver_index < 0) {
1129 for (i = 0; i < mvert_num; i++,
vert++) {
1130 float x[3],
v[3], f[3], dfdx[3][3], dfdv[3][3];
1132 if (
vert->solver_index < 0) {
1139 vertex_grid,
x,
v, smoothfac, pressfac, minpress, f, dfdx, dfdv);
1153 int i, mvert_num =
cloth->mvert_num;
1154 float total[3] = {0.0f, 0.0f, 0.0f};
1156 for (i = 0; i < mvert_num; i++) {
1166 mul_v3_fl(total, 1.0f / dt / mvert_num);
1179 int mvert_num =
cloth->mvert_num;
1196 for (i = 0; i < mvert_num; i++) {
1199 sub_v3_v3v3(verts[i].tv, verts[i].tx, verts[i].txold);
1206 for (i = 0; i < mvert_num; i++) {
1212 madd_v3_v3fl(verts[i].tv, verts[i].dcvel, time_multiplier);
1262 ListBaseT<EffectorCache> *effectors)
1269 const bool is_hair = (clmd->
hairdata !=
nullptr);
1291 for (i = 0; i < mvert_num; i++) {
1304 if (!use_acceleration) {
1331 if (use_acceleration) {
1339 for (i = 0; i < mvert_num; i++) {
1358 for (i = 0; i < mvert_num; i++) {
#define BKE_sim_debug_data_add_dot(p, r, g, b, category,...)
#define BKE_sim_debug_data_add_vector(p, d, r, g, b, category,...)
#define BKE_sim_debug_data_add_line(p1, p2, r, g, b, category,...)
#define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category,...)
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define UNUSED_FUNCTION(x)
#define INIT_MINMAX(min, max)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
ccl_device_inline void copy_v3_v3(ccl_private float *r, const float3 val)
void min_max(const T &value, T &min, T &max)
MINLINE float min_ff(float a, float b)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
static void cloth_solve_collisions(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void SIM_mass_spring_get_velocity(struct Implicit_Data *data, int index, float v[3])
void SIM_mass_spring_clear_forces(struct Implicit_Data *data)
static float cloth_calc_average_pressure(ClothModifierData *clmd, const float *vertex_pressure)
static void cloth_calc_average_acceleration(ClothModifierData *clmd, float dt)
bool SIM_mass_spring_force_spring_goal(struct Implicit_Data *data, int i, const float goal_x[3], const float goal_v[3], float stiffness, float damping)
int SIM_cloth_solve(Depsgraph *depsgraph, Object *ob, float frame, ClothModifierData *clmd, ListBaseT< EffectorCache > *effectors)
static void cloth_setup_constraints(ClothModifierData *clmd)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void SIM_mass_spring_force_edge_wind(struct Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float(*winvec)[3])
void SIM_mass_spring_force_pressure(struct Implicit_Data *data, int v1, int v2, int v3, float common_pressure, const float *vertex_pressure, const float weights[3])
static float cloth_calc_volume(ClothModifierData *clmd)
static float cloth_calc_rest_volume(ClothModifierData *clmd)
void SIM_mass_spring_set_implicit_vertex_mass(Implicit_Data *data, int index, float mass)
void SIM_mass_spring_add_constraint_ndof0(struct Implicit_Data *data, int index, const float dV[3])
ATTR_WARN_UNUSED_RESULT const BMLoop * l
Implicit_Data * SIM_mass_spring_solver_create(int numverts, int numsprings)
float SIM_tri_area(struct Implicit_Data *data, int v1, int v2, int v3)
void SIM_hair_volume_normalize_vertex_grid(HairGrid *grid)
void SIM_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float(*winvec)[3])
void SIM_hair_volume_free_vertex_grid(HairGrid *grid)
void BKE_effectors_apply(ListBaseT< EffectorCache > *effectors, ListBaseT< ColliderCache > *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
void SIM_mass_spring_set_rest_transform(struct Implicit_Data *data, int index, float tfm[3][3])
BLI_INLINE LinkNode * hair_spring_next(LinkNode *spring_link)
static int cloth_count_nondiag_blocks(Cloth *cloth)
MINLINE int max_ii(int a, int b)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static bool cloth_get_pressure_weights(ClothModifierData *clmd, const int3 &vert_tri, float *r_weights)
void SIM_hair_volume_grid_interpolate(HairGrid *grid, const float x[3], float *density, float velocity[3], float velocity_smooth[3], float density_gradient[3], float velocity_gradient[3][3])
void SIM_mass_spring_force_gravity(struct Implicit_Data *data, int index, float mass, const float g[3])
void SIM_mass_spring_clear_constraints(struct Implicit_Data *data)
bool SIM_mass_spring_force_spring_bending_hair(struct Implicit_Data *data, int i, int j, int k, const float target[3], float stiffness, float damping)
void SIM_mass_spring_set_new_velocity(struct Implicit_Data *data, int index, const float v[3])
MINLINE void mul_v3_fl(float r[3], float f)
@ CLOTH_SPRING_TYPE_BENDING
@ CLOTH_SPRING_TYPE_STRUCTURAL
@ CLOTH_SPRING_TYPE_SHEAR
@ CLOTH_SPRING_TYPE_SEWING
@ CLOTH_SPRING_TYPE_INTERNAL
@ CLOTH_SPRING_TYPE_BENDING_HAIR
MINLINE void sub_v3_v3(float r[3], const float a[3])
void SIM_mass_spring_set_vertex_mass(struct Implicit_Data *data, int index, float mass)
void SIM_cloth_solver_set_volume(ClothModifierData *clmd)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void SIM_hair_volume_vertex_grid_forces(HairGrid *grid, const float x[3], const float v[3], float smoothfac, float pressurefac, float minpressure, float f[3], float dfdx[3][3], float dfdv[3][3])
static void cloth_clear_result(ClothModifierData *clmd)
VecBase< int32_t, 3 > int3
void SIM_mass_spring_force_extern(struct Implicit_Data *data, int i, const float f[3], float dfdx[3][3], float dfdv[3][3])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BMesh const char void * data
bool SIM_mass_spring_solve_velocities(struct Implicit_Data *data, float dt, struct ImplicitSolverResult *result)
void SIM_mass_spring_get_new_velocity(struct Implicit_Data *data, int index, float v[3])
static void cloth_continuum_fill_grid(HairGrid *grid, Cloth *cloth)
MINLINE void negate_v3(float r[3])
void SIM_hair_volume_grid_velocity(HairGrid *grid, const float x[3], const float v[3], float fluid_factor, float r_v[3])
void SIM_cloth_solver_free(ClothModifierData *clmd)
void SIM_mass_spring_apply_result(struct Implicit_Data *data)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void SIM_mass_spring_force_drag(struct Implicit_Data *data, float drag)
MINLINE void zero_v3(float r[3])
void SIM_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[3])
bool SIM_mass_spring_force_spring_angular(struct Implicit_Data *data, int i, int j, int *i_a, int *i_b, int len_a, int len_b, float restang, float stiffness, float damping)
float SIM_tri_tetra_volume_signed_6x(struct Implicit_Data *data, int v1, int v2, int v3)
void SIM_mass_spring_get_motion_state(struct Implicit_Data *data, int index, float x[3], float v[3])
int cloth_bvh_collision(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt)
static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *result, float dt)
bool SIM_mass_spring_force_spring_bending(struct Implicit_Data *data, int i, int j, float restlen, float kb, float cb)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
static void cloth_calc_force(Scene *scene, ClothModifierData *clmd, float, ListBaseT< EffectorCache > *effectors, float time)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
void SIM_hair_volume_add_segment(HairGrid *grid, const float[3], const float[3], const float x2[3], const float v2[3], const float x3[3], const float v3[3], const float[3], const float[3], const float[3], const float[3], const float[3])
@ CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL
@ CLOTH_SIMSETTINGS_FLAG_RESIST_SPRING_COMPRESS
@ CLOTH_SIMSETTINGS_FLAG_PRESSURE
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void pd_point_from_loc(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
HairGrid * SIM_hair_volume_create_vertex_grid(float cellsize, const float gmin[3], const float gmax[3])
void SIM_mass_spring_set_velocity(struct Implicit_Data *data, int index, const float v[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
MINLINE float max_ff(float a, float b)
void SIM_mass_spring_solver_free(Implicit_Data *id)
static LinkNode * cloth_continuum_add_hair_segments(HairGrid *grid, const float cell_scale, const float cell_offset[3], Cloth *cloth, LinkNode *spring_link)
BLI_INLINE void cloth_get_grid_location(Implicit_Data *data, float cell_scale, const float cell_offset[3], int index, float x[3], float v[3])
BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s)
void SIM_cloth_solver_set_positions(ClothModifierData *clmd)
@ CLOTH_SPRING_FLAG_DEACTIVATE
@ CLOTH_SPRING_FLAG_NEEDED
static void cloth_continuum_step(ClothModifierData *clmd, float dt)
static int UNUSED_FUNCTION cloth_calc_helper_forces(Object *, ClothModifierData *clmd, float(*initial_cos)[3], float, float dt)
int SIM_cloth_solver_init(Object *, ClothModifierData *clmd)
void SIM_mass_spring_set_position(struct Implicit_Data *data, int index, const float x[3])
bool SIM_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int j, float restlen, float stiffness_tension, float damping_tension, float stiffness_compression, float damping_compression, bool resist_compress, bool new_compress, float clamp_force)
bool SIM_hair_volume_solve_divergence(HairGrid *grid, float, float target_density, float target_strength)
VecBase< float, 3 > float3
void SIM_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3])
void BKE_sim_debug_data_clear_category(const char *category)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float volume_tri_tetrahedron_signed_v3_6x(const float v1[3], const float v2[3], const float v3[3])
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
@ CLOTH_COLLSETTINGS_FLAG_ENABLED
@ CLOTH_COLLSETTINGS_FLAG_SELF
MINLINE int min_ii(int a, int b)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3_int(int r[3])
void SIM_hair_volume_grid_geometry(HairGrid *grid, float *cellsize, int res[3], float gmin[3], float gmax[3])
static void hair_get_boundbox(ClothModifierData *clmd, float3 &gmin, float3 &gmax)
void SIM_mass_spring_get_position(struct Implicit_Data *data, int index, float x[3])
void SIM_mass_spring_force_face_extern(struct Implicit_Data *data, int v1, int v2, int v3, const float(*forcevec)[3])
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
void SIM_mass_spring_get_new_position(struct Implicit_Data *data, int index, float x[3])
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void SIM_mass_spring_set_motion_state(struct Implicit_Data *data, int index, const float x[3], const float v[3])
bool SIM_mass_spring_solve_positions(struct Implicit_Data *data, float dt)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void cloth_calc_pressure_gradient(ClothModifierData *clmd, const float gradient_vector[3], float *r_vertex_pressure)
void vert(const int vert_id, float4 &position)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
CLOTH_COLLISIONSETTINGS_FLAGS flags
struct Cloth * clothObject
struct ClothSolverResult * solver_result
struct ClothHairData * hairdata
struct ClothSimSettings * sim_parms
struct ClothCollSettings * coll_parms
float uniform_pressure_force
struct EffectorWeights * effector_weights
float max_internal_tension
CLOTH_SIMSETTINGS_FLAGS flags
CLOTH_BENDING_MODEL bending_model
float max_internal_compression
float internal_compression
unsigned int impulse_count
struct PhysicsSettings physics_settings