11#ifdef IMPLICIT_SOLVER_BLENDER
32# pragma GCC diagnostic ignored "-Wtype-limits"
36# define CLOTH_OPENMP_LIMIT 512
45static float I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
46static float ZERO[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
51# defineDO_INLINE inline
53# defineDO_INLINE static
79 to[0] = from[0] * scalar;
80 to[1] = from[1] * scalar;
81 to[2] = from[2] * scalar;
104static void print_fvector(
float m3[3])
106 printf(
"%f\n%f\n%f\n\n", m3[0], m3[1], m3[2]);
116 for (i = 0; i <
verts; i++) {
117 print_fvector(fLongVector[i]);
132 if (fLongVector !=
nullptr) {
146 for (i = 0; i <
verts; i++) {
160 for (i = 0; i <
verts; i++) {
169 for (i = 0; i <
verts; i++) {
170 VECSUBMUL(to[i], fLongVector[i], scalar);
183 for (i = 0; i < long(
verts); i++) {
184 temp +=
dot_v3v3(fLongVectorA[i], fLongVectorB[i]);
190 float (*fLongVectorA)[3],
191 float (*fLongVectorB)[3],
196 for (i = 0; i <
verts; i++) {
197 add_v3_v3v3(to[i], fLongVectorA[i], fLongVectorB[i]);
202 float (*to)[3],
float (*fLongVectorA)[3],
float (*fLongVectorB)[3],
float bS,
uint verts)
206 for (i = 0; i <
verts; i++) {
207 VECADDS(to[i], fLongVectorA[i], fLongVectorB[i], bS);
212 float (*fLongVectorA)[3],
214 float (*fLongVectorB)[3],
220 for (i = 0; i <
verts; i++) {
221 VECADDSS(to[i], fLongVectorA[i], aS, fLongVectorB[i], bS);
226 float (*to)[3],
float (*fLongVectorA)[3],
float (*fLongVectorB)[3],
float bS,
uint verts)
229 for (i = 0; i <
verts; i++) {
230 VECSUBS(to[i], fLongVectorA[i], fLongVectorB[i], bS);
235 float (*fLongVectorA)[3],
236 float (*fLongVectorB)[3],
241 for (i = 0; i <
verts; i++) {
242 sub_v3_v3v3(to[i], fLongVectorA[i], fLongVectorB[i]);
250static void print_fmatrix(
float m3[3][3])
252 printf(
"%f\t%f\t%f\n", m3[0][0], m3[0][1], m3[0][2]);
253 printf(
"%f\t%f\t%f\n", m3[1][0], m3[1][1], m3[1][2]);
254 printf(
"%f\t%f\t%f\n\n", m3[2][0], m3[2][1], m3[2][2]);
263 print_fmatrix(m[i].m);
273 for (i = 0; i < numverts; i++) {
289 int size = m[0].
vcount * 3;
290 float *t =
MEM_callocN(
sizeof(
float) * size * size,
"bfmatrix");
293 for (q = 0; q < tot; q++) {
297 for (j = 0; j < 3; j++) {
298 for (i = 0; i < 3; i++) {
300 if (t[k + i + (
l + j) * size] != 0.0f) {
301 printf(
"warning: overwriting value at %d, %d\n", m[q].r, m[q].c);
305 t[k + i + (k + j) * size] += m[q].m[i][j];
308 t[k + i + (
l + j) * size] += m[q].m[i][j];
309 t[
l + j + (k + i) * size] += m[q].m[j][i];
315 for (j = 0; j <
size; j++) {
316 if (j > 0 && j % 3 == 0) {
320 for (i = 0; i <
size; i++) {
321 if (i > 0 && i % 3 == 0) {
355DO_INLINE float det_fmatrix(
float m[3][3])
357 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] -
358 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];
361DO_INLINE void inverse_fmatrix(
float to[3][3],
float from[3][3])
366 if ((d = det_fmatrix(from)) == 0) {
369 for (i = 0; i < 3; i++) {
370 for (j = 0; j < 3; j++) {
371 int i1 = (i + 1) % 3;
372 int i2 = (i + 2) % 3;
373 int j1 = (j + 1) % 3;
374 int j2 = (j + 2) % 3;
376 to[j][i] = (from[i1][j1] * from[i2][j2] - from[i1][j2] * from[i2][j1]) / d;
405 to[0] = matrix[0][0] * from[0] + matrix[1][0] * from[1] + matrix[2][0] * from[2];
406 to[1] = matrix[0][1] * from[0] + matrix[1][1] * from[1] + matrix[2][1] * from[2];
407 to[2] = matrix[0][2] * from[0] + matrix[1][2] * from[1] + matrix[2][2] * from[2];
420 const float matrixA[3][3],
421 const float matrixB[3][3])
429 float to[3][3],
const float matrixA[3][3],
float aS,
const float matrixB[3][3],
float bS)
431 VECSUBADDSS(to[0], matrixA[0], aS, matrixB[0], bS);
432 VECSUBADDSS(to[1], matrixA[1], aS, matrixB[1], bS);
433 VECSUBADDSS(to[2], matrixA[2], aS, matrixB[2], bS);
437 const float matrixA[3][3],
438 const float matrixB[3][3])
458 to[0] += matrix[0][0] * from[0] + matrix[1][0] * from[1] + matrix[2][0] * from[2];
459 to[1] += matrix[0][1] * from[0] + matrix[1][1] * from[1] + matrix[2][1] * from[2];
460 to[2] += matrix[0][2] * from[0] + matrix[1][2] * from[1] + matrix[2][2] * from[2];
492 r[0][0] += m[0][0] * f;
493 r[0][1] += m[0][1] * f;
494 r[0][2] += m[0][2] * f;
495 r[1][0] += m[1][0] * f;
496 r[1][1] += m[1][1] * f;
497 r[1][2] += m[1][2] * f;
498 r[2][0] += m[2][0] * f;
499 r[2][1] += m[2][1] * f;
500 r[2][2] += m[2][2] * f;
515 print_fmatrix(m3[i].m);
531 "cloth_implicit_alloc_matrix");
538 for (i = 0; i <
verts; i++) {
547 if (matrix !=
nullptr) {
556 memcpy(to, from,
sizeof(
fmatrix3x3) * (from[0].vcount + from[0].scount));
565 for (i = 0; i < matrix[0].vcount + matrix[0].scount; i++) {
575 float tmatrix[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
577 for (i = 0; i < matrix[0].vcount; i++) {
580 for (j = matrix[0].vcount; j < matrix[0].vcount + matrix[0].scount; j++) {
589 uint vcount = from[0].vcount;
594# pragma omp parallel sections if (vcount > CLOTH_OPENMP_LIMIT)
598 for (
uint i = from[0].vcount; i < from[0].vcount + from[0].scount; i++) {
606 for (
uint i = 0; i < from[0].vcount + from[0].scount; i++) {
625 for (i = 0; i < matrix[0].vcount + matrix[0].scount; i++) {
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;
925 for (i = 0; i < lA[0].
vcount; i++) {
928 inverse_fmatrix(Pinv[i].m,
P[i].m);
934static int cg_filtered_pre(
lfVector *dv,
942 uint numverts = lA[0].
vcount, iterations = 0, conjgrad_looplimit = 100;
943 float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0;
944 float conjgrad_epsilon = 0.0001;
950 BuildPPinv(lA,
P, Pinv);
959 mul_prevfmatrix_lfvector(p, Pinv, r);
964 delta0 = deltaNew *
sqrt(conjgrad_epsilon);
970 while ((deltaNew > delta0) && (iterations < conjgrad_looplimit)) {
982 mul_prevfmatrix_lfvector(h, Pinv, r);
996 printf(
"cg_filtered_pre time: %f\n",
float(end - start));
1004 printf(
"iterations: %d\n", iterations);
1006 return iterations < conjgrad_looplimit;
1011static int cg_filtered_pre(
lfVector *dv,
1020 uint numverts = lA[0].
vcount, iterations = 0, conjgrad_looplimit = 100;
1021 float delta0 = 0, deltaNew = 0, deltaOld = 0, alpha = 0, tol = 0;
1029 BuildPPinv(lA,
P, Pinv);
1032 sub_bfmatrix_Smatrix(bigI, bigI, S);
1049 mul_prevfmatrix_lfvector(p, Pinv, r);
1053 mul_prevfmatrix_lfvector(btemp, Pinv, bhat);
1067 mul_prevfmatrix_lfvector(p, Pinv, r);
1072 delta0 = deltaNew *
sqrt(conjgrad_epsilon);
1081 while ((deltaNew > delta0 * tol * tol) && (iterations < conjgrad_looplimit)) {
1093 mul_prevfmatrix_lfvector(h, Pinv, r);
1096 deltaOld = deltaNew;
1107 printf(
"cg_filtered_pre time: %f\n",
float(end - start));
1119 return iterations < conjgrad_looplimit;
1125 uint numverts = data->dFdV[0].vcount;
1143 cg_filtered(data->dV, data->A, data->B, data->z, data->S, result);
1149 printf(
"cg_filtered calc time: %f\n",
float(end - start));
1162 int numverts = data->M[0].vcount;
1172 int numverts = data->M[0].vcount;
1185# ifdef CLOTH_ROOT_FRAME
1256 int s = data->M[0].vcount + data->num_blocks;
1257 BLI_assert(s < data->
M[0].vcount + data->M[0].scount);
1274 int i, numverts = data->S[0].vcount;
1275 for (i = 0; i < numverts; i++) {
1289 Implicit_Data *data,
int index,
const float c1[3],
const float c2[3],
const float dV[3])
1291 float m[3][3], p[3], q[3], u[3], cmat[3][3];
1314 float m[3][3], p[3], u[3], cmat[3][3];
1329 int numverts = data->M[0].vcount;
1334 data->num_blocks = 0;
1339 const float acceleration[3],
1340 const float omega[3],
1341 const float domega_dt[3],
1344# ifdef CLOTH_ROOT_FRAME
1345 float acc[3],
w[3], dwdt[3];
1346 float f[3], dfdx[3][3], dfdv[3][3];
1347 float euler[3], coriolis[3], centrifugal[3], rotvel[3];
1348 float deuler[3][3], dcoriolis[3][3], dcentrifugal[3][3], drotvel[3][3];
1381 add_m3_m3m3(data->dFdX[index].m, data->dFdX[index].m, dfdx);
1382 add_m3_m3m3(data->dFdV[index].m, data->dFdV[index].m, dfdv);
1404 int i, numverts = data->M[0].vcount;
1405 for (i = 0; i < numverts; i++) {
1413 add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, tmp);
1418 Implicit_Data *data,
int i,
const float f[3],
float dfdx[3][3],
float dfdv[3][3])
1420 float tf[3], tdfdx[3][3], tdfdv[3][3];
1426 add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, tdfdx);
1427 add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, tdfdv);
1445 Implicit_Data *data,
int v1,
int v2,
int v3,
const float (*winvec)[3])
1450 const float effector_scale = 0.02f;
1451 const int vs[3] = {v1,
v2, v3};
1452 float win[3],
nor[3], area;
1453 float factor, base_force;
1459 factor = effector_scale * area / 3.0f;
1462 for (
int i = 0; i < 3; i++) {
1479 base_force = force[0] + force[1] + force[2];
1488 Implicit_Data *data,
int v1,
int v2,
int v3,
const float (*forcevec)[3])
1490 const float effector_scale = 0.02f;
1491 const int vs[3] = {v1,
v2, v3};
1493 float factor, base_force[3];
1499 factor = effector_scale * area / 3.0f;
1504 for (
int i = 0; i < 3; i++) {
1512 for (
int i = 0; i < 3; i++) {
1535 float common_pressure,
1536 const float *vertex_pressure,
1537 const float weights[3])
1540 float factor, base_force;
1546 factor = area / 3.0f;
1547 base_force = common_pressure * factor;
1558 if (vertex_pressure) {
1559 copy_v3_fl3(force, vertex_pressure[v1], vertex_pressure[
v2], vertex_pressure[v3]);
1562 base_force += force[0] + force[1] + force[2];
1577 const float wind[3],
1582 const float density = 0.01f;
1583 float cos_alpha, sin_alpha, cross_section;
1584 float windlen =
len_v3(wind);
1586 if (windlen == 0.0f) {
1592 cos_alpha =
dot_v3v3(wind, dir) / windlen;
1593 sin_alpha =
sqrtf(1.0f - cos_alpha * cos_alpha);
1594 cross_section = radius * (
float(
M_PI) * radius * sin_alpha + length * cos_alpha);
1600 Implicit_Data *data,
int v1,
int v2,
float radius1,
float radius2,
const float (*winvec)[3])
1602 float win[3], dir[3],
length;
1603 float f[3], dfdx[3][3], dfdv[3][3];
1620 const float (*winvec)[3])
1622 const float density = 0.01f;
1670 float x = length /
L;
1673 float xxxx = xxx *
x;
1674 return (-11.541f * xxxx + 34.193f * xxx - 39.083f * xx + 23.116f * x - 9.713f);
1679 float x = length /
L;
1682 return (-46.164f * xxx + 102.579f * xx - 78.166f * x + 23.116f);
1687 float tempfb_fl = kb *
fb(length,
L);
1688 float fbstar_fl = cb * (length -
L);
1690 if (tempfb_fl < fbstar_fl) {
1700 float tempfb_fl = kb *
fb(length,
L);
1701 float fbstar_fl = cb * (length -
L);
1703 if (tempfb_fl < fbstar_fl) {
1721 *r_length =
len_v3(r_extent);
1726 if ((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) &&
1727 (((length -
L) * 100.0f /
L) > clmd->sim_parms->maxspringlen))
1730 s->flags |= CSPRING_FLAG_DEACTIVATE;
1748 const float dfdx[3][3],
1749 const float dfdv[3][3])
1756 add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, dfdx);
1757 add_m3_m3m3(data->dFdX[j].m, data->dFdX[j].m, dfdx);
1758 sub_m3_m3m3(data->dFdX[block_ij].m, data->dFdX[block_ij].m, dfdx);
1760 add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, dfdv);
1761 add_m3_m3m3(data->dFdV[j].m, data->dFdV[j].m, dfdv);
1762 sub_m3_m3m3(data->dFdV[block_ij].m, data->dFdV[block_ij].m, dfdv);
1769 float stiffness_tension,
1770 float damping_tension,
1771 float stiffness_compression,
1772 float damping_compression,
1773 bool resist_compress,
1777 float extent[3],
length, dir[3], vel[3];
1778 float f[3], dfdx[3][3], dfdv[3][3];
1787 if ((length >= restlen && length > 0) || resist_compress) {
1788 float stretch_force;
1790 damping = damping_tension;
1792 stretch_force = stiffness_tension * (length - restlen);
1793 if (clamp_force > 0.0f && stretch_force > clamp_force) {
1794 stretch_force = clamp_force;
1798 dfdx_spring(dfdx, dir, length, restlen, stiffness_tension);
1800 else if (new_compress) {
1803 float kb = stiffness_compression;
1806 damping = damping_compression;
1826 Implicit_Data *data,
int i,
int j,
float restlen,
float kb,
float cb)
1830 float extent[3],
length, dir[3], vel[3];
1835 if (length < restlen) {
1836 float f[3], dfdx[3][3], dfdv[3][3];
1860 for (
int i = 0; i <
len; i++) {
1876 r_avg[0] = (data[i][0] + data[j][0]) * 0.5f;
1877 r_avg[1] = (data[i][1] + data[j][1]) * 0.5f;
1878 r_avg[2] = (data[i][2] + data[j][2]) * 0.5f;
1913 float dir_e[3], vel_e[3];
1915 poly_norm(data->X, j, i, i_a, len_a, r_dir_a);
1916 poly_norm(data->X, i, j, i_b, len_b, r_dir_b);
1920 *r_angle =
bend_angle(r_dir_a, r_dir_b, dir_e);
1922 poly_avg(data->V, i_a, len_a, r_vel_a);
1923 poly_avg(data->V, i_b, len_b, r_vel_b);
1942 float angle, dir_a[3], dir_b[3], vel_a[3], vel_b[3];
1943 float f_a[3], f_b[3], f_e[3];
1947 spring_angle(data, i, j, i_a, i_b, len_a, len_b, dir_a, dir_b, &angle, vel_a, vel_b);
1950 force = stiffness * (angle - restang);
1958 for (x = 0; x < len_a; x++) {
1962 for (x = 0; x < len_b; x++) {
1984 Implicit_Data *data,
int i,
int j,
float edge[3],
float dir[3],
float grad_dir[3][3])
2005 const float goal[3],
2013 float edge_ij[3], dir_ij[3];
2014 float edge_jk[3], dir_jk[3];
2015 float vel_ij[3], vel_jk[3], vel_ortho[3];
2016 float f_bend[3], f_damp[3];
2076 const float goal[3],
2082 const float delta = 0.00001f;
2083 float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3];
2095 for (a = 0; a < 3; a++) {
2097 data, i, j, k, goal, stiffness, damping, q, dvec_pos[a], dvec_null[a], f);
2101 data, i, j, k, goal, stiffness, damping, q, dvec_neg[a], dvec_null[a], f);
2104 for (
b = 0;
b < 3;
b++) {
2105 dfdx[a][
b] /= delta;
2115 const float goal[3],
2121 const float delta = 0.00001f;
2122 float dvec_null[3][3], dvec_pos[3][3], dvec_neg[3][3];
2134 for (a = 0; a < 3; a++) {
2136 data, i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_pos[a], f);
2140 data, i, j, k, goal, stiffness, damping, q, dvec_null[a], dvec_neg[a], f);
2143 for (
b = 0;
b < 3;
b++) {
2144 dfdv[a][
b] /= delta;
2153 const float target[3],
2162 float dfj_dxi[3][3], dfj_dxj[3][3], dfk_dxi[3][3], dfk_dxj[3][3], dfk_dxk[3][3];
2163 float dfj_dvi[3][3], dfj_dvj[3][3], dfk_dvi[3][3], dfk_dvj[3][3], dfk_dvk[3][3];
2165 const float vecnull[3] = {0.0f, 0.0f, 0.0f};
2173 spring_hairbend_forces(data, i, j, k, goal, stiffness, damping, k, vecnull, vecnull, fk);
2197 add_m3_m3m3(data->dFdX[j].m, data->dFdX[j].m, dfj_dxj);
2198 add_m3_m3m3(data->dFdX[k].m, data->dFdX[k].m, dfk_dxk);
2200 add_m3_m3m3(data->dFdX[block_ij].m, data->dFdX[block_ij].m, dfj_dxi);
2201 add_m3_m3m3(data->dFdX[block_jk].m, data->dFdX[block_jk].m, dfk_dxj);
2202 add_m3_m3m3(data->dFdX[block_ik].m, data->dFdX[block_ik].m, dfk_dxi);
2204 add_m3_m3m3(data->dFdV[j].m, data->dFdV[j].m, dfj_dvj);
2205 add_m3_m3m3(data->dFdV[k].m, data->dFdV[k].m, dfk_dvk);
2207 add_m3_m3m3(data->dFdV[block_ij].m, data->dFdV[block_ij].m, dfj_dvi);
2208 add_m3_m3m3(data->dFdV[block_jk].m, data->dFdV[block_jk].m, dfk_dvj);
2209 add_m3_m3m3(data->dFdV[block_ik].m, data->dFdV[block_ik].m, dfk_dvi);
2216 float edge_ij[3], dir_ij[3], grad_dir_ij[3][3];
2217 float edge_jk[3], dir_jk[3], grad_dir_jk[3][3];
2218 float dist[3], vel_jk[3], vel_jk_ortho[3], projvel[3];
2221 float fi[3], fj[3], fk[3];
2222 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];
2264 madd_m3_m3fl(dfk_dxi, grad_dir_ij, stiffness * restlen);
2266 madd_m3_m3fl(dfk_dxj, grad_dir_ij, -stiffness * restlen);
2289 add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, dfi_dxi);
2290 add_m3_m3m3(data->dFdX[j].m, data->dFdX[j].m, dfj_dxj);
2291 add_m3_m3m3(data->dFdX[k].m, data->dFdX[k].m, dfk_dxk);
2293 add_m3_m3m3(data->dFdX[block_ij].m, data->dFdX[block_ij].m, dfj_dxi);
2294 add_m3_m3m3(data->dFdX[block_jk].m, data->dFdX[block_jk].m, dfk_dxj);
2295 add_m3_m3m3(data->dFdX[block_ik].m, data->dFdX[block_ik].m, dfk_dxi);
2303 const float goal_x[3],
2304 const float goal_v[3],
2308 float root_goal_x[3], root_goal_v[3], extent[3],
length, dir[3], vel[3];
2309 float f[3], dfdx[3][3], dfdv[3][3];
2330 add_m3_m3m3(data->dFdX[i].m, data->dFdX[i].m, dfdx);
2331 add_m3_m3m3(data->dFdV[i].m, data->dFdV[i].m, dfdv);
#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)
Object is a sort of wrapper for general info.
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Read Guarded memory(de)allocation.
@ SIM_SOLVER_NO_CONVERGENCE
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.
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
BLI_INLINE void print_lvector(const lVector3f &v)
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 filter(lfVector *V, fmatrix3x3 *S)
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])
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_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
ccl_device_inline float3 cos(float3 v)
Frequency::GEOMETRY nor[]
CCL_NAMESPACE_BEGIN struct Window V