11#ifdef IMPLICIT_SOLVER_BLENDER
25# pragma GCC diagnostic ignored "-Wtype-limits"
28# define CLOTH_PARALLEL_LIMIT 1024
36static float I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
37static float ZERO[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
42# defineDO_INLINE inline
44# defineDO_INLINE static
70 to[0] = from[0] * scalar;
71 to[1] = from[1] * scalar;
72 to[2] = from[2] * scalar;
95static void print_fvector(
float m3[3])
97 printf(
"%f\n%f\n%f\n\n", m3[0], m3[1], m3[2]);
108 print_fvector(fLongVector[
i]);
123 if (fLongVector !=
nullptr) {
177 for (
const int i : range) {
178 temp +=
dot_v3v3(fLongVectorA[
i], fLongVectorB[
i]);
186 temp +=
dot_v3v3(fLongVectorA[
i], fLongVectorB[
i]);
193 float (*fLongVectorA)[3],
194 float (*fLongVectorB)[3],
205 float (*to)[3],
float (*fLongVectorA)[3],
float (*fLongVectorB)[3],
float bS,
uint verts)
210 VECADDS(to[
i], fLongVectorA[
i], fLongVectorB[
i], bS);
215 float (*fLongVectorA)[3],
217 float (*fLongVectorB)[3],
224 VECADDSS(to[
i], fLongVectorA[
i], aS, fLongVectorB[
i], bS);
229 float (*to)[3],
float (*fLongVectorA)[3],
float (*fLongVectorB)[3],
float bS,
uint verts)
233 VECSUBS(to[
i], fLongVectorA[
i], fLongVectorB[
i], bS);
238 float (*fLongVectorA)[3],
239 float (*fLongVectorB)[3],
253static void print_fmatrix(
float m3[3][3])
255 printf(
"%f\t%f\t%f\n", m3[0][0], m3[0][1], m3[0][2]);
256 printf(
"%f\t%f\t%f\n", m3[1][0], m3[1][1], m3[1][2]);
257 printf(
"%f\t%f\t%f\n\n", m3[2][0], m3[2][1], m3[2][2]);
266 print_fmatrix(m[
i].m);
276 for (
i = 0;
i < numverts;
i++) {
293 float *t = MEM_calloc_array<float>
N(
size *
size,
"bfmatrix");
296 for (q = 0; q < tot; q++) {
300 for (j = 0; j < 3; j++) {
301 for (
i = 0;
i < 3;
i++) {
303 if (t[k +
i + (
l + j) *
size] != 0.0f) {
304 printf(
"warning: overwriting value at %d, %d\n", m[q].r, m[q].c);
308 t[k +
i + (k + j) *
size] += m[q].m[
i][j];
311 t[k +
i + (
l + j) *
size] += m[q].m[
i][j];
312 t[
l + j + (k +
i) *
size] += m[q].m[j][
i];
318 for (j = 0; j <
size; j++) {
319 if (j > 0 && j % 3 == 0) {
324 if (
i > 0 &&
i % 3 == 0) {
358DO_INLINE float det_fmatrix(
float m[3][3])
360 return m[0][0] * m[1][1] * m[2][2] + m[1][0] * m[2][1] * m[0][2] + m[0][1] * m[1][2] * m[2][0] -
361 m[0][0] * m[1][2] * m[2][1] - m[0][1] * m[1][0] * m[2][2] - m[2][0] * m[1][1] * m[0][2];
364DO_INLINE void inverse_fmatrix(
float to[3][3],
float from[3][3])
369 if ((d = det_fmatrix(from)) == 0) {
372 for (
i = 0;
i < 3;
i++) {
373 for (j = 0; j < 3; j++) {
374 int i1 = (
i + 1) % 3;
375 int i2 = (
i + 2) % 3;
376 int j1 = (j + 1) % 3;
377 int j2 = (j + 2) % 3;
379 to[j][
i] = (from[i1][j1] * from[i2][j2] - from[i1][j2] * from[i2][j1]) / d;
408 to[0] = matrix[0][0] * from[0] + matrix[1][0] * from[1] + matrix[2][0] * from[2];
409 to[1] = matrix[0][1] * from[0] + matrix[1][1] * from[1] + matrix[2][1] * from[2];
410 to[2] = matrix[0][2] * from[0] + matrix[1][2] * from[1] + matrix[2][2] * from[2];
423 const float matrixA[3][3],
424 const float matrixB[3][3])
432 float to[3][3],
const float matrixA[3][3],
float aS,
const float matrixB[3][3],
float bS)
434 VECSUBADDSS(to[0], matrixA[0], aS, matrixB[0], bS);
435 VECSUBADDSS(to[1], matrixA[1], aS, matrixB[1], bS);
436 VECSUBADDSS(to[2], matrixA[2], aS, matrixB[2], bS);
440 const float matrixA[3][3],
441 const float matrixB[3][3])
461 to[0] += matrix[0][0] * from[0] + matrix[1][0] * from[1] + matrix[2][0] * from[2];
462 to[1] += matrix[0][1] * from[0] + matrix[1][1] * from[1] + matrix[2][1] * from[2];
463 to[2] += matrix[0][2] * from[0] + matrix[1][2] * from[1] + matrix[2][2] * from[2];
495 r[0][0] += m[0][0] * f;
496 r[0][1] += m[0][1] * f;
497 r[0][2] += m[0][2] * f;
498 r[1][0] += m[1][0] * f;
499 r[1][1] += m[1][1] * f;
500 r[1][2] += m[1][2] * f;
501 r[2][0] += m[2][0] * f;
502 r[2][1] += m[2][1] * f;
503 r[2][2] += m[2][2] * f;
518 print_fmatrix(m3[
i].m);
549 if (matrix !=
nullptr) {
558 memcpy(to, from,
sizeof(
fmatrix3x3) * (from[0].vcount + from[0].scount));
577 float tmatrix[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
582 for (j = matrix[0].vcount; j < matrix[0].
vcount + matrix[0].
scount; j++) {
747 for (
i = 0;
i < S[0].vcount;
i++) {
758 uint conjgrad_loopcount = 0, conjgrad_looplimit = 100;
759 float conjgrad_epsilon = 0.0001f ;
761 float s, starget, a, s_prev;
783 starget = s *
sqrtf(conjgrad_epsilon);
785 while (s > starget && conjgrad_loopcount < conjgrad_looplimit) {
807 conjgrad_loopcount++;
818 return conjgrad_loopcount < conjgrad_looplimit;
830 uint conjgrad_loopcount = 0, conjgrad_looplimit = 100;
831 float conjgrad_epsilon = 0.01f;
840 float bnorm2, delta_new, delta_old, delta_target, alpha;
848 delta_target = conjgrad_epsilon * conjgrad_epsilon * bnorm2;
862# ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
873 while (delta_new > delta_target && conjgrad_loopcount < conjgrad_looplimit) {
885 delta_old = delta_new;
891 conjgrad_loopcount++;
894# ifdef IMPLICIT_PRINT_SOLVER_INPUT_OUTPUT
910 result->iterations = conjgrad_loopcount;
911 result->error = bnorm2 > 0.0f ?
sqrtf(delta_new / bnorm2) : 0.0f;
914 return conjgrad_loopcount < conjgrad_looplimit;
928 inverse_fmatrix(Pinv[
i].m,
P[
i].m);
935static int cg_filtered_pre(
lfVector *dv,
943 uint numverts = lA[0].
vcount, iterations = 0, conjgrad_looplimit = 100;
944 float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0;
945 float conjgrad_epsilon = 0.0001;
951 BuildPPinv(lA,
P, Pinv);
960 mul_prevfmatrix_lfvector(p, Pinv, r);
965 delta0 = deltaNew *
sqrt(conjgrad_epsilon);
971 while ((deltaNew > delta0) && (iterations < conjgrad_looplimit)) {
983 mul_prevfmatrix_lfvector(h, Pinv, r);
997 printf(
"cg_filtered_pre time: %f\n",
float(end - start));
1005 printf(
"iterations: %d\n", iterations);
1007 return iterations < conjgrad_looplimit;
1012static int cg_filtered_pre(
lfVector *dv,
1021 uint numverts = lA[0].
vcount, iterations = 0, conjgrad_looplimit = 100;
1022 float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0, tol = 0;
1030 BuildPPinv(lA,
P, Pinv);
1033 sub_bfmatrix_Smatrix(bigI, bigI, S);
1050 mul_prevfmatrix_lfvector(p, Pinv, r);
1054 mul_prevfmatrix_lfvector(btemp, Pinv, bhat);
1068 mul_prevfmatrix_lfvector(p, Pinv, r);
1073 delta0 = deltaNew *
sqrt(conjgrad_epsilon);
1082 while ((deltaNew > delta0 * tol * tol) && (iterations < conjgrad_looplimit)) {
1094 mul_prevfmatrix_lfvector(h, Pinv, r);
1097 deltaOld = deltaNew;
1108 printf(
"cg_filtered_pre time: %f\n",
float(end - start));
1120 return iterations < conjgrad_looplimit;
1126 uint numverts =
data->dFdV[0].vcount;
1150 printf(
"cg_filtered calc time: %f\n",
float(end - start));
1163 int numverts =
data->M[0].vcount;
1173 int numverts =
data->M[0].vcount;
1186# ifdef CLOTH_ROOT_FRAME
1257 int s =
data->M[0].vcount +
data->num_blocks;
1275 int i, numverts =
data->S[0].vcount;
1276 for (
i = 0;
i < numverts;
i++) {
1290 Implicit_Data *
data,
int index,
const float c1[3],
const float c2[3],
const float dV[3])
1292 float m[3][3], p[3], q[3], u[3], cmat[3][3];
1315 float m[3][3], p[3], u[3], cmat[3][3];
1330 int numverts =
data->M[0].vcount;
1335 data->num_blocks = 0;
1340 const float acceleration[3],
1341 const float omega[3],
1342 const float domega_dt[3],
1345# ifdef CLOTH_ROOT_FRAME
1346 float acc[3],
w[3], dwdt[3];
1347 float f[3], dfdx[3][3], dfdv[3][3];
1348 float euler[3], coriolis[3], centrifugal[3], rotvel[3];
1349 float deuler[3][3], dcoriolis[3][3], dcentrifugal[3][3], drotvel[3][3];
1405 int i, numverts =
data->M[0].vcount;
1406 for (
i = 0;
i < numverts;
i++) {
1421 float tf[3], tdfdx[3][3], tdfdv[3][3];
1451 const float effector_scale = 0.02f;
1452 const int vs[3] = {v1,
v2, v3};
1453 float win[3],
nor[3], area;
1454 float factor, base_force;
1460 factor = effector_scale * area / 3.0f;
1463 for (
int i = 0;
i < 3;
i++) {
1480 base_force = force[0] + force[1] + force[2];
1491 const float effector_scale = 0.02f;
1492 const int vs[3] = {v1,
v2, v3};
1494 float factor, base_force[3];
1500 factor = effector_scale * area / 3.0f;
1505 for (
int i = 0;
i < 3;
i++) {
1513 for (
int i = 0;
i < 3;
i++) {
1536 float common_pressure,
1537 const float *vertex_pressure,
1538 const float weights[3])
1541 float factor, base_force;
1547 factor = area / 3.0f;
1548 base_force = common_pressure * factor;
1559 if (vertex_pressure) {
1560 copy_v3_fl3(force, vertex_pressure[v1], vertex_pressure[
v2], vertex_pressure[v3]);
1563 base_force += force[0] + force[1] + force[2];
1578 const float wind[3],
1583 const float density = 0.01f;
1584 float cos_alpha, sin_alpha, cross_section;
1585 float windlen =
len_v3(wind);
1587 if (windlen == 0.0f) {
1593 cos_alpha =
dot_v3v3(wind, dir) / windlen;
1594 sin_alpha =
sqrtf(1.0f - cos_alpha * cos_alpha);
1595 cross_section = radius * (
float(
M_PI) * radius * sin_alpha +
length * cos_alpha);
1601 Implicit_Data *
data,
int v1,
int v2,
float radius1,
float radius2,
const float (*winvec)[3])
1603 float win[3], dir[3],
length;
1604 float f[3], dfdx[3][3], dfdv[3][3];
1621 const float (*winvec)[3])
1623 const float density = 0.01f;
1674 float xxxx = xxx *
x;
1675 return (-11.541f * xxxx + 34.193f * xxx - 39.083f * xx + 23.116f *
x - 9.713f);
1683 return (-46.164f * xxx + 102.579f * xx - 78.166f *
x + 23.116f);
1689 float fbstar_fl = cb * (
length -
L);
1691 if (tempfb_fl < fbstar_fl) {
1702 float fbstar_fl = cb * (
length -
L);
1704 if (tempfb_fl < fbstar_fl) {
1722 *r_length =
len_v3(r_extent);
1727 if ((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) &&
1728 (((
length -
L) * 100.0f /
L) > clmd->sim_parms->maxspringlen))
1731 s->flags |= CSPRING_FLAG_DEACTIVATE;
1749 const float dfdx[3][3],
1750 const float dfdv[3][3])
1770 float stiffness_tension,
1771 float damping_tension,
1772 float stiffness_compression,
1773 float damping_compression,
1774 bool resist_compress,
1778 float extent[3],
length, dir[3], vel[3];
1779 float f[3], dfdx[3][3], dfdv[3][3];
1788 if ((
length >= restlen &&
length > 0) || resist_compress) {
1789 float stretch_force;
1791 damping = damping_tension;
1793 stretch_force = stiffness_tension * (
length - restlen);
1794 if (clamp_force > 0.0f && stretch_force > clamp_force) {
1795 stretch_force = clamp_force;
1801 else if (new_compress) {
1804 float kb = stiffness_compression;
1807 damping = damping_compression;
1831 float extent[3],
length, dir[3], vel[3];
1837 float f[3], dfdx[3][3], dfdv[3][3];
1861 for (
int i = 0;
i <
len;
i++) {
1877 r_avg[0] = (
data[
i][0] +
data[j][0]) * 0.5f;
1878 r_avg[1] = (
data[
i][1] +
data[j][1]) * 0.5f;
1879 r_avg[2] = (
data[
i][2] +
data[j][2]) * 0.5f;
1914 float dir_e[3], vel_e[3];
1921 *r_angle =
bend_angle(r_dir_a, r_dir_b, dir_e);
1943 float angle, dir_a[3], dir_b[3], vel_a[3], vel_b[3];
1944 float f_a[3], f_b[3], f_e[3];
1948 spring_angle(
data,
i, j, i_a, i_b, len_a, len_b, dir_a, dir_b, &
angle, vel_a, vel_b);
1951 force = stiffness * (
angle - restang);
1959 for (
x = 0;
x < len_a;
x++) {
1963 for (
x = 0;
x < len_b;
x++) {
1985 Implicit_Data *
data,
int i,
int j,
float edge[3],
float dir[3],
float grad_dir[3][3])
2006 const float goal[3],
2014 float edge_ij[3], dir_ij[3];
2015 float edge_jk[3], dir_jk[3];
2016 float vel_ij[3], vel_jk[3], vel_ortho[3];
2017 float f_bend[3], f_damp[3];
2077 const float goal[3],
2083 const float delta = 0.00001f;
2084 float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3];
2096 for (a = 0; a < 3; a++) {
2098 data,
i, j, k, goal, stiffness, damping, q, dvec_pos[a], dvec_null[a], f);
2102 data,
i, j, k, goal, stiffness, damping, q, dvec_neg[a], dvec_null[a], f);
2105 for (
b = 0;
b < 3;
b++) {
2106 dfdx[a][
b] /= delta;
2116 const float goal[3],
2122 const float delta = 0.00001f;
2123 float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3];
2135 for (a = 0; a < 3; a++) {
2137 data,
i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_pos[a], f);
2141 data,
i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_neg[a], f);
2144 for (
b = 0;
b < 3;
b++) {
2145 dfdv[a][
b] /= delta;
2154 const float target[3],
2163 float dfj_dxi[3][3], dfj_dxj[3][3], dfk_dxi[3][3], dfk_dxj[3][3], dfk_dxk[3][3];
2164 float dfj_dvi[3][3], dfj_dvj[3][3], dfk_dvi[3][3], dfk_dvj[3][3], dfk_dvk[3][3];
2166 const float vecnull[3] = {0.0f, 0.0f, 0.0f};
2174 spring_hairbend_forces(
data,
i, j, k, goal, stiffness, damping, k, vecnull, vecnull, fk);
2217 float edge_ij[3], dir_ij[3], grad_dir_ij[3][3];
2218 float edge_jk[3], dir_jk[3], grad_dir_jk[3][3];
2219 float dist[3], vel_jk[3], vel_jk_ortho[3], projvel[3];
2222 float fi[3], fj[3], fk[3];
2223 float dfi_dxi[3][3], dfj_dxi[3][3], dfj_dxj[3][3], dfk_dxi[3][3], dfk_dxj[3][3], dfk_dxk[3][3];
2265 madd_m3_m3fl(dfk_dxi, grad_dir_ij, stiffness * restlen);
2267 madd_m3_m3fl(dfk_dxj, grad_dir_ij, -stiffness * restlen);
2304 const float goal_x[3],
2305 const float goal_v[3],
2309 float root_goal_x[3], root_goal_v[3], extent[3],
length, dir[3], vel[3];
2310 float f[3], dfdx[3][3], dfdv[3][3];
#define VECADDS(v1, v2, v3, bS)
#define VECSUBS(v1, v2, v3, bS)
#define VECADDSS(v1, v2, aS, v3, bS)
#define VECSUBADDSS(v1, v2, aS, v3, bS)
#define VECSUBMUL(v1, v2, aS)
float volume_tri_tetrahedron_signed_v3_6x(const float v1[3], const float v2[3], const float v3[3])
float normal_tri_v3(float n[3], const float v1[3], const float v2[3], const float v3[3])
void sub_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void negate_m3(float R[3][3])
void mul_m3_v3(const float M[3][3], float r[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void unit_m3(float m[3][3])
void mul_m3_fl(float R[3][3], float f)
void add_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void zero_m3(float m[3][3])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void transpose_m3(float R[3][3])
void mul_transposed_m3_v3(const float M[3][3], float r[3])
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
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 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 void negate_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
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])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
Platform independent time functions.
double BLI_time_now_seconds(void)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Read Guarded memory(de)allocation.
@ SIM_SOLVER_NO_CONVERGENCE
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 * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
BLI_INLINE void print_lvector(const lVector3f &v)
float length(VecOp< float, D >) RET
BLI_INLINE void implicit_print_matrix_elem(float v)
void SIM_mass_spring_force_gravity(Implicit_Data *data, int index, float mass, const float g[3])
float SIM_tri_area(Implicit_Data *data, int v1, int v2, int v3)
void SIM_mass_spring_set_vertex_mass(Implicit_Data *data, int index, float mass)
void SIM_mass_spring_clear_forces(Implicit_Data *data)
DO_INLINE void add_lfvector_lfvector(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], uint verts)
BLI_INLINE void apply_spring(Implicit_Data *data, int i, int j, const float f[3], const float dfdx[3][3], const float dfdv[3][3])
void SIM_mass_spring_clear_constraints(Implicit_Data *data)
void SIM_mass_spring_get_velocity(Implicit_Data *data, int index, float v[3])
BLI_INLINE float fbstar_jacobi(float length, float L, float kb, float cb)
void SIM_mass_spring_force_pressure(Implicit_Data *data, int v1, int v2, int v3, float common_pressure, const float *vertex_pressure, const float weights[3])
DO_INLINE void submul_lfvectorS(float(*to)[3], float(*fLongVector)[3], float scalar, uint verts)
DO_INLINE lfVector * create_lfvector(uint verts)
Implicit_Data * SIM_mass_spring_solver_create(int numverts, int numsprings)
DO_INLINE void add_fmatrix_fmatrix(float to[3][3], const float matrixA[3][3], const float matrixB[3][3])
void SIM_mass_spring_add_constraint_ndof0(Implicit_Data *data, int index, const float dV[3])
DO_INLINE void mul_fvectorT_fvector(float to[3][3], const float vectorA[3], const float vectorB[3])
void SIM_mass_spring_force_extern(Implicit_Data *data, int i, const float f[3], float dfdx[3][3], float dfdv[3][3])
DO_INLINE void del_lfvector(float(*fLongVector)[3])
BLI_INLINE void cross_m3_v3m3(float r[3][3], const float v[3], const float m[3][3])
bool SIM_mass_spring_force_spring_bending_hair(Implicit_Data *data, int i, int j, int k, const float target[3], float stiffness, float damping)
BLI_INLINE float fb(float length, float L)
void SIM_mass_spring_set_velocity(Implicit_Data *data, int index, const float v[3])
DO_INLINE void mul_fvectorT_fvectorS(float to[3][3], float vectorA[3], float vectorB[3], float aS)
DO_INLINE void mul_fmatrix_S(float matrix[3][3], float scalar)
bool SIM_mass_spring_solve_positions(Implicit_Data *data, float dt)
DO_INLINE void initdiag_fmatrixS(float to[3][3], float aS)
BLI_INLINE float fbderiv(float length, float L)
BLI_INLINE void madd_m3_m3fl(float r[3][3], const float m[3][3], float f)
DO_INLINE void muladd_fmatrix_fvector(float to[3], const float matrix[3][3], const float from[3])
DO_INLINE void mul_bfmatrix_lfvector(float(*to)[3], fmatrix3x3 *from, lfVector *fLongVector)
BLI_INLINE void spring_hairbend_forces(Implicit_Data *data, int i, int j, int k, const float goal[3], float stiffness, float damping, int q, const float dx[3], const float dv[3], float r_f[3])
void SIM_mass_spring_force_vertex_wind(Implicit_Data *data, int v, float, const float(*winvec)[3])
bool SIM_mass_spring_force_spring_goal(Implicit_Data *data, int i, const float goal_x[3], const float goal_v[3], float stiffness, float damping)
void SIM_mass_spring_force_face_extern(Implicit_Data *data, int v1, int v2, int v3, const float(*forcevec)[3])
DO_INLINE void muladd_fmatrixT_fvector(float to[3], const float matrix[3][3], const float from[3])
bool SIM_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSolverResult *result)
DO_INLINE void mul_fvector_fmatrix(float *to, const float *from, const float matrix[3][3])
BLI_INLINE void init_fmatrix(fmatrix3x3 *matrix, int r, int c)
void SIM_mass_spring_add_constraint_ndof2(Implicit_Data *data, int index, const float c1[3], const float dV[3])
BLI_INLINE bool spring_length(Implicit_Data *data, int i, int j, float r_extent[3], float r_dir[3], float *r_length, float r_vel[3])
static int SIM_mass_spring_add_block(Implicit_Data *data, int v1, int v2)
BLI_INLINE void edge_avg(lfVector *data, int i, int j, float r_avg[3])
void SIM_mass_spring_force_drag(Implicit_Data *data, float drag)
DO_INLINE void subadd_fmatrixS_fmatrixS(float to[3][3], const float matrixA[3][3], float aS, const float matrixB[3][3], float bS)
DO_INLINE void zero_lfvector(float(*to)[3], uint verts)
BLI_INLINE void root_to_world_m3(Implicit_Data *data, int index, float r[3][3], const float m[3][3])
void SIM_mass_spring_solver_free(Implicit_Data *id)
BLI_INLINE void cross_v3_identity(float r[3][3], const float v[3])
DO_INLINE void mul_fmatrix_fvector(float *to, const float matrix[3][3], const float from[3])
bool SIM_mass_spring_force_spring_linear(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)
BLI_INLINE void outerproduct(float r[3][3], const float a[3], const float b[3])
bool SIM_mass_spring_force_spring_bending(Implicit_Data *data, int i, int j, float restlen, float kb, float cb)
DO_INLINE void mul_fvector_S(float to[3], const float from[3], float scalar)
DO_INLINE void init_lfvector(float(*fLongVector)[3], const float vector[3], uint verts)
void SIM_mass_spring_set_motion_state(Implicit_Data *data, int index, const float x[3], const float v[3])
void SIM_mass_spring_set_position(Implicit_Data *data, int index, const float x[3])
DO_INLINE void mul_lfvectorS(float(*to)[3], float(*fLongVector)[3], float scalar, uint verts)
void SIM_mass_spring_get_motion_state(Implicit_Data *data, int index, float x[3], float v[3])
DO_INLINE void sub_fmatrix_fmatrix(float to[3][3], const float matrixA[3][3], const float matrixB[3][3])
BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, float L, float k)
DO_INLINE void add_lfvector_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], float bS, uint verts)
void SIM_mass_spring_get_position(Implicit_Data *data, int index, float x[3])
void SIM_mass_spring_set_rest_transform(Implicit_Data *data, int index, float tfm[3][3])
DO_INLINE void cp_lfvector(float(*to)[3], float(*from)[3], uint verts)
static int cg_filtered(lfVector *ldV, fmatrix3x3 *lA, lfVector *lB, lfVector *z, fmatrix3x3 *S, ImplicitSolverResult *result)
DO_INLINE void sub_lfvector_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], float bS, uint verts)
DO_INLINE void cp_fmatrix(float to[3][3], const float from[3][3])
BLI_INLINE void poly_norm(lfVector *data, int i, int j, int *inds, int len, float r_dir[3])
DO_INLINE void initdiag_bfmatrix(fmatrix3x3 *matrix, float m3[3][3])
void SIM_mass_spring_force_edge_wind(Implicit_Data *data, int v1, int v2, float radius1, float radius2, const float(*winvec)[3])
DO_INLINE void cp_bfmatrix(fmatrix3x3 *to, fmatrix3x3 *from)
BLI_INLINE void spring_grad_dir(Implicit_Data *data, int i, int j, float edge[3], float dir[3], float grad_dir[3][3])
void SIM_mass_spring_force_face_wind(Implicit_Data *data, int v1, int v2, int v3, const float(*winvec)[3])
static float calc_nor_area_tri(float nor[3], const float v1[3], const float v2[3], const float v3[3])
DO_INLINE fmatrix3x3 * create_bfmatrix(uint verts, uint springs)
BLI_INLINE void root_to_world_v3(Implicit_Data *data, int index, float r[3], const float v[3])
BLI_INLINE void poly_avg(lfVector *data, const int *inds, int len, float r_avg[3])
DO_INLINE void subadd_bfmatrixS_bfmatrixS(fmatrix3x3 *to, fmatrix3x3 *from, float aS, fmatrix3x3 *matrix, float bS)
void SIM_mass_spring_add_constraint_ndof1(Implicit_Data *data, int index, const float c1[3], const float c2[3], const float dV[3])
BLI_INLINE void world_to_root_m3(Implicit_Data *data, int index, float r[3][3], const float m[3][3])
BLI_INLINE void edge_norm(lfVector *data, int i, int j, float r_dir[3])
void SIM_mass_spring_set_new_velocity(Implicit_Data *data, int index, const float v[3])
BLI_INLINE void spring_hairbend_estimate_dfdv(Implicit_Data *data, int i, int j, int k, const float goal[3], float stiffness, float damping, int q, float dfdv[3][3])
DO_INLINE void sub_lfvector_lfvector(float(*to)[3], float(*fLongVectorA)[3], float(*fLongVectorB)[3], uint verts)
BLI_INLINE float fbstar(float length, float L, float kb, float cb)
void SIM_mass_spring_get_new_velocity(Implicit_Data *data, int index, float v[3])
DO_INLINE void del_bfmatrix(fmatrix3x3 *matrix)
void SIM_mass_spring_force_reference_frame(Implicit_Data *data, int index, const float acceleration[3], const float omega[3], const float domega_dt[3], float mass)
float SIM_tri_tetra_volume_signed_6x(Implicit_Data *data, int v1, int v2, int v3)
bool SIM_mass_spring_force_spring_angular(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_set_new_position(Implicit_Data *data, int index, const float x[3])
BLI_INLINE void spring_hairbend_estimate_dfdx(Implicit_Data *data, int i, int j, int k, const float goal[3], float stiffness, float damping, int q, float dfdx[3][3])
BLI_INLINE void world_to_root_v3(Implicit_Data *data, int index, float r[3], const float v[3])
BLI_INLINE void dfdv_damp(float to[3][3], const float dir[3], float damping)
void SIM_mass_spring_get_new_position(Implicit_Data *data, int index, float x[3])
void SIM_mass_spring_apply_result(Implicit_Data *data)
BLI_INLINE float bend_angle(const float dir_a[3], const float dir_b[3], const float dir_e[3])
DO_INLINE void add_lfvectorS_lfvectorS(float(*to)[3], float(*fLongVectorA)[3], float aS, float(*fLongVectorB)[3], float bS, uint verts)
BLI_INLINE void spring_angle(Implicit_Data *data, int i, int j, int *i_a, int *i_b, int len_a, int len_b, float r_dir_a[3], float r_dir_b[3], float *r_angle, float r_vel_a[3], float r_vel_b[3])
DO_INLINE void init_bfmatrix(fmatrix3x3 *matrix, float m3[3][3])
#define CLOTH_PARALLEL_LIMIT
static void edge_wind_vertex(const float dir[3], float length, float radius, const float wind[3], float f[3], float[3][3], float[3][3])
DO_INLINE float dot_lfvector(float(*fLongVectorA)[3], float(*fLongVectorB)[3], uint verts)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
void parallel_invoke(Functions &&...functions)
Value parallel_deterministic_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
CCL_NAMESPACE_BEGIN struct Window V