33static float I3[3][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};
43 for (link = cloth->
springs; link; link = link->
next) {
45 switch (spring->
type) {
70 for (
uint j = 0; j < 3; j++) {
71 r_weights[j] =
verts[vert_tri[j]].pressure_factor;
74 if (r_weights[j] == 0.0f) {
84 const float gradient_vector[3],
85 float *r_vertex_pressure)
92 for (
uint i = 0;
i < mvert_num;
i++) {
94 r_vertex_pressure[
i] =
dot_v3v3(pt, gradient_vector);
104 float weights[3] = {1.0f, 1.0f, 1.0f};
132 float weights[3] = {1.0f, 1.0f, 1.0f};
145 v[tri[0]].xrest,
v[tri[1]].xrest,
v[tri[2]].xrest);
160 float weights[3] = {1.0f, 1.0f, 1.0f};
161 float total_force = 0;
162 float total_area = 0;
170 total_force += (vertex_pressure[tri[0]] + vertex_pressure[tri[1]] +
171 vertex_pressure[tri[2]]) *
177 return total_force / total_area;
184 const float ZERO[3] = {0.0f, 0.0f, 0.0f};
225 for (
i = 0;
i < mvert_num;
i++) {
226 if (cloth_hairdata) {
257 const float ZERO[3] = {0.0f, 0.0f, 0.0f};
261 for (
v = 0;
v < mvert_num;
v++) {
267 verts[
v].impulse_count = 0;
279 Cloth *cloth = clmd->clothObject;
295 masses[
i] = cv->
mass;
300 for (
i = 0;
i < steps;
i++) {
301 for (node = cloth->
springs; node; node = node->
next) {
304 float len, c,
l, vec[3];
325 l = c / ((1.0f / masses[v1]) + (1.0f / masses[
v2]));
368#ifdef CLOTH_FORCE_SPRING_BEND
375 k = scaling * s->
restlen * 0.1f;
386#ifdef CLOTH_FORCE_SPRING_STRUCTURAL
387 float k_tension, scaling_tension;
391 scaling_tension = parms->
tension +
393 k_tension = scaling_tension / (parms->
avg_spring_len + FLT_EPSILON);
412 float k_compression, scaling_compression;
415 k_compression = scaling_compression / (parms->
avg_spring_len + FLT_EPSILON);
436 k_tension = scaling_tension / (parms->
avg_spring_len + FLT_EPSILON);
440 float k_compression = scaling_compression / (parms->
avg_spring_len + FLT_EPSILON);
445 if (k_tension == 0.0f) {
447 k_tension_damp = 0.0f;
450 if (k_compression == 0.0f) {
452 k_compression_damp = 0.0f;
470#ifdef CLOTH_FORCE_SPRING_SHEAR
492#ifdef CLOTH_FORCE_SPRING_BEND
493 float kb, cb, scaling;
507#ifdef CLOTH_FORCE_SPRING_BEND
508 float kb, cb, scaling;
528 float x_kl[3], x_mn[3],
v[3], d[3];
535 clmd->debug_data, x_kl, x_mn, 0.8, 0.8, 0.8,
"target", 7981, s->
kl);
539 clmd->debug_data, x_kl, d, 0.8, 0.8, 0.2,
"target", 7982, s->
kl);
559 for (
i = 0;
i < mvert_num;
i++) {
575 float gravity[3] = {0.0f, 0.0f, 0.0f};
580#ifdef CLOTH_FORCE_GRAVITY
595 float goal_x[3], goal_v[3];
613#ifdef CLOTH_FORCE_DRAG
619 float pressure_difference = 0.0f;
620 float volume_factor = 1.0f;
631 if (init_vol > 1E-6f) {
636 volume_factor = init_vol / vol;
637 pressure_difference = volume_factor - 1;
651 float *hydrostatic_pressure =
nullptr;
653 if (
fabs(fluid_density) > 1e-6f) {
654 float hydrostatic_vector[3];
660 if (fluid_density > 0) {
664 fluid_density *= volume_factor;
667 mul_v3_fl(hydrostatic_vector, fluid_density);
678 if (hydrostatic_pressure ||
fabs(pressure_difference) > 1E-6f) {
679 float weights[3] = {1.0f, 1.0f, 1.0f};
686 data, tri[0], tri[1], tri[2], pressure_difference, hydrostatic_pressure, weights);
691 if (hydrostatic_pressure) {
699 bool has_wind =
false, has_force =
false;
703 float (*forcevec)[3] = is_not_hair ? winvec + mvert_num : winvec;
744 hair_ij = &hairdata[spring->
ij];
745 hair_kl = &hairdata[spring->
kl];
786 const float cell_offset[3],
820 const float cell_scale,
821 const float cell_offset[3],
826 LinkNode *next_spring_link =
nullptr;
830 float x1[3], v1[3], x2[3],
v2[3], x3[3], v3[3], x4[3], v4[3];
831 float dir1[3], dir2[3], dir3[3];
851 while (spring_link) {
869 next_spring_link = spring_link->
next;
896 spring1 ? dir1 :
nullptr,
898 spring3 ? dir3 :
nullptr);
901 return next_spring_link;
912 for (
i = 0, vert = cloth->
verts;
i < mvert_num;
i++, vert++) {
915 cloth_get_vertex_motion_state(
data, vert,
x,
v);
920 float cellsize, gmin[3], cell_scale, cell_offset[3];
926 cell_scale = cellsize > 0.0f ? 1.0f / cellsize : 0.0f;
952 const float fluid_factor = 0.95f;
971 if (smoothfac > 0.0f || density_strength > 0.0f) {
980 for (
i = 0, vert = cloth->
verts;
i < mvert_num;
i++, vert++) {
981 float x[3],
v[3], nv[3];
1004 const int size = 64;
1006 float offset[3], a[3],
b[3];
1008 const float shift = 0.0f;
1021 for (j = 0; j <
size; j++) {
1023 float x[3],
v[3], gvel[3], gvel_smooth[3], gdensity;
1030 grid,
x, &gdensity, gvel, gvel_smooth,
nullptr,
nullptr);
1034 clmd->debug_data,
x, gdensity, 0.7, 0.3, 1,
"grid density",
i, j, 3111);
1041 clmd->debug_data,
x, gvel, 0.4, 0, 1,
"grid velocity",
i, j, 3112);
1043 clmd->debug_data,
x, gvel_smooth, 0.6, 1, 1,
"grid velocity",
i, j, 3113);
1046 clmd->debug_data,
x, dvel, 0.4, 1, 0.7,
"grid velocity",
i, j, 3114);
1048 if (gdensity > 0.0f) {
1049 float col0[3] = {0.0, 0.0, 0.0};
1050 float col1[3] = {0.0, 1.0, 0.0};
1069 clmd->debug_data,
x,
col[0],
col[1],
col[2],
"grid velocity",
i, j, 3115);
1072 clmd->debug_data,
x, 0.01f,
col[0],
col[1],
col[2],
"grid velocity",
i, j, 3115);
1097 float pressfac = parms->pressure;
1098 float minpress = parms->pressure_threshold;
1099 float gmin[3], gmax[3];
1105 if (smoothfac > 0.0f || pressfac > 0.0f) {
1107 clmd->
sim_parms->voxel_res, gmin, gmax);
1109 vert = cloth->
verts;
1110 for (
i = 0;
i < mvert_num;
i++, vert++) {
1113 if (vert->solver_index < 0) {
1124 vert = cloth->
verts;
1125 for (
i = 0;
i < mvert_num;
i++, vert++) {
1126 float x[3],
v[3], f[3], dfdx[3][3], dfdv[3][3];
1128 if (vert->solver_index < 0) {
1135 vertex_grid,
x,
v, smoothfac, pressfac, minpress, f, dfdx, dfdv);
1150 float total[3] = {0.0f, 0.0f, 0.0f};
1152 for (
i = 0;
i < mvert_num;
i++) {
1162 mul_v3_fl(total, 1.0f / dt / mvert_num);
1192 for (
i = 0;
i < mvert_num;
i++) {
1202 for (
i = 0;
i < mvert_num;
i++) {
1262 const bool is_hair = (clmd->
hairdata !=
nullptr);
1284 for (
i = 0;
i < mvert_num;
i++) {
1297 if (!use_acceleration) {
1324 if (use_acceleration) {
1332 for (
i = 0;
i < mvert_num;
i++) {
1351 for (
i = 0;
i < mvert_num;
i++) {
@ CLOTH_SPRING_TYPE_SEWING
@ CLOTH_SPRING_TYPE_SHEAR
@ CLOTH_SPRING_TYPE_BENDING_HAIR
@ CLOTH_SPRING_TYPE_STRUCTURAL
@ CLOTH_SPRING_TYPE_BENDING
@ CLOTH_SPRING_TYPE_INTERNAL
@ CLOTH_SPRING_FLAG_DEACTIVATE
@ CLOTH_SPRING_FLAG_NEEDED
int cloth_bvh_collision(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt)
#define BKE_sim_debug_data_add_dot(p, r, g, b, category,...)
void BKE_sim_debug_data_clear_category(const char *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,...)
void BKE_effectors_apply(struct ListBase *effectors, struct ListBase *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
#define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category,...)
void pd_point_from_loc(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
MINLINE float max_ff(float a, float b)
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
float volume_tri_tetrahedron_signed_v3_6x(const float v1[3], const float v2[3], const float v3[3])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE void zero_v3_int(int r[3])
MINLINE void negate_v3(float r[3])
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
MINLINE void zero_v3(float r[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
#define UNUSED_FUNCTION(x)
#define INIT_MINMAX(min, max)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
@ CLOTH_COLLSETTINGS_FLAG_ENABLED
@ CLOTH_COLLSETTINGS_FLAG_SELF
@ CLOTH_SIMSETTINGS_FLAG_PRESSURE_VOL
@ CLOTH_SIMSETTINGS_FLAG_PRESSURE
@ CLOTH_SIMSETTINGS_FLAG_RESIST_SPRING_COMPRESS
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
void SIM_cloth_solver_free(ClothModifierData *clmd)
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])
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)
static void cloth_continuum_fill_grid(HairGrid *grid, Cloth *cloth)
static void cloth_clear_result(ClothModifierData *clmd)
static float cloth_calc_average_pressure(ClothModifierData *clmd, const float *vertex_pressure)
static float cloth_calc_rest_volume(ClothModifierData *clmd)
static void cloth_calc_pressure_gradient(ClothModifierData *clmd, const float gradient_vector[3], float *r_vertex_pressure)
static int cloth_count_nondiag_blocks(Cloth *cloth)
int SIM_cloth_solver_init(Object *, ClothModifierData *clmd)
static void hair_get_boundbox(ClothModifierData *clmd, blender::float3 &gmin, blender::float3 &gmax)
static void cloth_calc_average_acceleration(ClothModifierData *clmd, float dt)
static bool cloth_get_pressure_weights(ClothModifierData *clmd, const blender::int3 &vert_tri, float *r_weights)
static void cloth_record_result(ClothModifierData *clmd, ImplicitSolverResult *result, float dt)
BLI_INLINE LinkNode * hair_spring_next(LinkNode *spring_link)
static void cloth_calc_force(Scene *scene, ClothModifierData *clmd, float, ListBase *effectors, float time)
BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s)
void SIM_cloth_solver_set_volume(ClothModifierData *clmd)
static void cloth_setup_constraints(ClothModifierData *clmd)
static float cloth_calc_volume(ClothModifierData *clmd)
void SIM_mass_spring_set_implicit_vertex_mass(Implicit_Data *data, int index, float mass)
static void cloth_solve_collisions(Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, float step, float dt)
void SIM_cloth_solver_set_positions(ClothModifierData *clmd)
int SIM_cloth_solve(Depsgraph *depsgraph, Object *ob, float frame, ClothModifierData *clmd, ListBase *effectors)
static LinkNode * cloth_continuum_add_hair_segments(HairGrid *grid, const float cell_scale, const float cell_offset[3], Cloth *cloth, LinkNode *spring_link)
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
BPy_StructRNA * depsgraph
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
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])
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_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_hair_volume_grid_geometry(HairGrid *grid, float *cellsize, int res[3], float gmin[3], float gmax[3])
void SIM_hair_volume_free_vertex_grid(HairGrid *grid)
bool SIM_hair_volume_solve_divergence(HairGrid *grid, float, float target_density, float target_strength)
void SIM_hair_volume_add_vertex(HairGrid *grid, const float x[3], const float v[3])
HairGrid * SIM_hair_volume_create_vertex_grid(float cellsize, const float gmin[3], const float gmax[3])
void SIM_hair_volume_normalize_vertex_grid(HairGrid *grid)
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])
void SIM_mass_spring_force_vertex_wind(struct Implicit_Data *data, int v, float radius, const float(*winvec)[3])
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])
void SIM_mass_spring_add_constraint_ndof0(struct Implicit_Data *data, int index, const float dV[3])
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_set_new_velocity(struct Implicit_Data *data, int index, const float v[3])
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)
float SIM_tri_area(struct Implicit_Data *data, int v1, int v2, int v3)
void SIM_mass_spring_set_vertex_mass(struct Implicit_Data *data, int index, float mass)
void SIM_mass_spring_force_face_extern(struct Implicit_Data *data, int v1, int v2, int v3, const float(*forcevec)[3])
void SIM_mass_spring_get_velocity(struct Implicit_Data *data, int index, float v[3])
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_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)
void SIM_mass_spring_get_new_position(struct Implicit_Data *data, int index, float x[3])
bool SIM_mass_spring_force_spring_bending(struct Implicit_Data *data, int i, int j, float restlen, float kb, float cb)
void SIM_mass_spring_apply_result(struct Implicit_Data *data)
void SIM_mass_spring_set_position(struct Implicit_Data *data, int index, const float x[3])
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_force_pressure(struct Implicit_Data *data, int v1, int v2, int v3, float common_pressure, const float *vertex_pressure, const float weights[3])
void SIM_mass_spring_force_face_wind(struct Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3])
void SIM_mass_spring_get_position(struct Implicit_Data *data, int index, float x[3])
bool SIM_mass_spring_solve_velocities(struct Implicit_Data *data, float dt, struct ImplicitSolverResult *result)
void SIM_mass_spring_force_drag(struct Implicit_Data *data, float drag)
void SIM_mass_spring_clear_constraints(struct Implicit_Data *data)
bool SIM_mass_spring_solve_positions(struct Implicit_Data *data, float dt)
void SIM_mass_spring_get_new_velocity(struct Implicit_Data *data, int index, float v[3])
void SIM_mass_spring_set_velocity(struct Implicit_Data *data, int index, 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)
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 SIM_mass_spring_force_gravity(struct Implicit_Data *data, int index, float mass, const float g[3])
void SIM_mass_spring_set_rest_transform(struct Implicit_Data *data, int index, float tfm[3][3])
void SIM_mass_spring_clear_forces(struct Implicit_Data *data)
Implicit_Data * SIM_mass_spring_solver_create(int numverts, int numsprings)
void SIM_mass_spring_solver_free(Implicit_Data *id)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
ccl_device_inline float2 fabs(const float2 a)
void min_max(const T &value, T &min, T &max)
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3
struct ClothSolverResult * solver_result
struct ClothHairData * hairdata
struct Cloth * clothObject
struct ClothSimSettings * sim_parms
struct ClothCollSettings * coll_parms
struct EffectorWeights * effector_weights
float uniform_pressure_force
float max_internal_tension
float max_internal_compression
float internal_compression
float initial_mesh_volume
float average_acceleration[3]
blender::int3 * vert_tris
unsigned int primitive_num
struct PhysicsSettings physics_settings