129#define MID_PRESERVE 1
131#define SOFTGOALSNAP 0.999f
135#define HEUNWARNLIMIT 1
137#define BSF_INTERSECT 1
141#define SBF_OUTOFCOLLISION 2
143#define BFF_INTERSECT 1
144#define BFF_CLOSEVERT 2
216 if (bp->
goal < 0.0f) {
304 for (i = 0; i < pccd_M->
mvert_num; i++) {
325 for (i = 0, mima = pccd_M->
mima; i < pccd_M->
tri_num; i++, mima++) {
394 for (i = 0; i < pccd_M->
mvert_num; i++) {
419 for (i = 0, mima = pccd_M->
mima; i < pccd_M->
tri_num; i++, mima++) {
519 for (
int i = 0; i < numobjects; i++) {
548 if ((!
hash) || (!vertexowner)) {
556 for (
int i = 0; i < numobjects; i++) {
573 for (
const int i : faces.index_range()) {
574 if (faces[i].
size() == 4) {
602 for (
int a = 0; a < mesh->faces_num; a++) {
603 const int poly_size = faces[a].size();
604 if (poly_size == 4) {
605 bs->
v1 = corner_verts[faces[a].start() + 0];
606 bs->
v2 = corner_verts[faces[a].start() + 2];
609 bs->
v1 = corner_verts[faces[a].start() + 1];
610 bs->
v2 = corner_verts[faces[a].start() + 3];
628 int a,
b, c, notthis = 0, v0;
661 if ((bs2->
v1 != notthis) && (bs2->
v1 > v0)) {
670 if ((bs2->
v2 != notthis) && (bs2->
v2 > v0)) {
690 stiffness *= stiffness;
766 int a,
b, akku_count;
790 if (akku_count > 0) {
819 if (ob->
soft ==
nullptr) {
839 for (i = 0; i < totpoint; i++) {
871 for (k = 0; k < sb->
totkey; k++) {
872 key = *(sb->
keys + k);
970 return (numobjects != 0);
981 float aabbmin[3], aabbmax[3];
987 if ((sb ==
nullptr) || (sb->
scratch ==
nullptr)) {
1003 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1004 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1005 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1033 const float face_v2[3],
1034 const float face_v3[3],
1043 float nv1[3], edge1[3], edge2[3], d_nvect[3], aabbmin[3], aabbmax[3];
1044 float facedist, outerfacethickness, tune = 10.0f;
1045 int a, deflected = 0;
1047 aabbmin[0] =
min_fff(face_v1[0], face_v2[0], face_v3[0]);
1048 aabbmin[1] =
min_fff(face_v1[1], face_v2[1], face_v3[1]);
1049 aabbmin[2] =
min_fff(face_v1[2], face_v2[2], face_v3[2]);
1050 aabbmax[0] =
max_fff(face_v1[0], face_v2[0], face_v3[0]);
1051 aabbmax[1] =
max_fff(face_v1[1], face_v2[1], face_v3[1]);
1052 aabbmax[2] =
max_fff(face_v1[2], face_v2[2], face_v3[2]);
1069 const float(*vert_positions)[3] =
nullptr;
1070 const float(*vert_positions_prev)[3] =
nullptr;
1076 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1077 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1078 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1093 if (vert_positions) {
1096 if (vert_positions_prev) {
1098 madd_v3_v3fl(nv1, vert_positions_prev[a - 1], 1.0f - time);
1103 if (
fabsf(facedist) < outerfacethickness) {
1107 df = (outerfacethickness - facedist) / outerfacethickness;
1110 df = (outerfacethickness + facedist) / outerfacethickness;
1115 df = 0.01f *
expf(-100.0f * df);
1132 const float face_v2[3],
1133 const float face_v3[3],
1142 float nv1[3], nv2[3], nv3[3], edge1[3], edge2[3], d_nvect[3], aabbmin[3], aabbmax[3];
1143 float t, tune = 10.0f;
1144 int a, deflected = 0;
1146 aabbmin[0] =
min_fff(face_v1[0], face_v2[0], face_v3[0]);
1147 aabbmin[1] =
min_fff(face_v1[1], face_v2[1], face_v3[1]);
1148 aabbmin[2] =
min_fff(face_v1[2], face_v2[2], face_v3[2]);
1149 aabbmax[0] =
max_fff(face_v1[0], face_v2[0], face_v3[0]);
1150 aabbmax[1] =
max_fff(face_v1[1], face_v2[1], face_v3[1]);
1151 aabbmax[2] =
max_fff(face_v1[2], face_v2[2], face_v3[2]);
1162 const float(*vert_positions)[3] =
nullptr;
1163 const float(*vert_positions_prev)[3] =
nullptr;
1174 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1175 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1176 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1192 if ((aabbmax[0] < mima->
minx) || (aabbmin[0] > mima->
maxx) ||
1193 (aabbmax[1] < mima->
miny) || (aabbmin[1] > mima->
maxy) ||
1194 (aabbmax[2] < mima->
minz) || (aabbmin[2] > mima->
maxz))
1201 if (vert_positions) {
1207 if (vert_positions_prev) {
1209 madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time);
1212 madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time);
1215 madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time);
1248 float damp = 0.0f, choke = 1.0f;
1249 float tune = -10.0f;
1258 bf->
flag &= ~BFF_INTERSECT;
1279 bf->
flag &= ~BFF_CLOSEVERT;
1316 const float edge_v2[3],
1325 float nv1[3], nv2[3], nv3[3], edge1[3], edge2[3], d_nvect[3], aabbmin[3], aabbmax[3];
1327 int a, deflected = 0;
1343 const float(*vert_positions)[3] =
nullptr;
1344 const float(*vert_positions_prev)[3] =
nullptr;
1355 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1356 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1357 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1373 if ((aabbmax[0] < mima->
minx) || (aabbmin[0] > mima->
maxx) ||
1374 (aabbmax[1] < mima->
miny) || (aabbmin[1] > mima->
maxy) ||
1375 (aabbmax[2] < mima->
minz) || (aabbmin[2] > mima->
maxz))
1382 if (vert_positions) {
1388 if (vert_positions_prev) {
1390 madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time);
1393 madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time);
1396 madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time);
1408 float intrusiondepth, i1, i2;
1413 intrusiondepth = -
min_ff(i1, i2) / el;
1439 for (a = ifirst; a < ilast; a++) {
1442 feedback[0] = feedback[1] = feedback[2] = 0.0f;
1443 bs->
flag &= ~BSF_INTERSECT;
1462 float vel[3], sp[3], pr[3], force[3];
1463 float f, windfactor = 0.25f;
1467 float speed[3] = {0.0f, 0.0f, 0.0f};
1483 f = -0.0001f * f * f * sb->
aeroedge;
1518 int *ptr_to_break_func(
void))
1523 int i, totthread,
left, dec;
1527 int lowsprings = 100;
1535 while ((totsprings / totthread < lowsprings) && (totthread > 1)) {
1542 dec = totsprings / totthread + 1;
1543 for (i = 0; i < totthread; i++) {
1545 sb_threads[i].
ob = ob;
1547 sb_threads[i].
timenow = timenow;
1554 sb_threads[i].
ifirst = 0;
1560 sb_threads[i].
nr = i;
1561 sb_threads[i].
tot = totthread;
1563 if (totthread > 1) {
1566 for (i = 0; i < totthread; i++) {
1584 float *
w,
float *
pos,
float *a,
float *
b,
float *c,
float *ca,
float *cb,
float *cc)
1615 float facenormal[3],
1626 float nv1[3], nv2[3], nv3[3], edge1[3], edge2[3], d_nvect[3], dv1[3], ve[3],
1627 avel[3] = {0.0, 0.0, 0.0}, vv1[3], vv2[3], vv3[3], coledge[3] = {0.0f, 0.0f, 0.0f},
1628 mindistedge = 1000.0f, outerforceaccu[3], innerforceaccu[3], facedist,
1629 force_mag_norm, minx, miny, minz, maxx, maxy, maxz,
1630 innerfacethickness = -0.5f, outerfacethickness = 0.2f, ee = 5.0f, ff = 0.1f, fa = 1;
1631 int a, deflected = 0, cavel = 0, ci = 0;
1636 outerforceaccu[0] = outerforceaccu[1] = outerforceaccu[2] = 0.0f;
1637 innerforceaccu[0] = innerforceaccu[1] = innerforceaccu[2] = 0.0f;
1646 const float(*vert_positions)[3] =
nullptr;
1647 const float(*vert_positions_prev)[3] =
nullptr;
1658 minx = ccdm->
bbmin[0];
1659 miny = ccdm->
bbmin[1];
1660 minz = ccdm->
bbmin[2];
1662 maxx = ccdm->
bbmax[0];
1663 maxy = ccdm->
bbmax[1];
1664 maxz = ccdm->
bbmax[2];
1666 if ((opco[0] < minx) || (opco[1] < miny) || (opco[2] < minz) || (opco[0] > maxx) ||
1667 (opco[1] > maxy) || (opco[2] > maxz))
1685 fa = (ff * outerfacethickness - outerfacethickness);
1688 avel[0] = avel[1] = avel[2] = 0.0f;
1691 if ((opco[0] < mima->
minx) || (opco[0] > mima->
maxx) || (opco[1] < mima->
miny) ||
1692 (opco[1] > mima->
maxy) || (opco[2] < mima->
minz) || (opco[2] > mima->
maxz))
1699 if (vert_positions) {
1705 if (vert_positions_prev) {
1711 sub_v3_v3v3(vv1, nv1, vert_positions_prev[(*vt)[0]]);
1712 sub_v3_v3v3(vv2, nv2, vert_positions_prev[(*vt)[1]]);
1713 sub_v3_v3v3(vv3, nv3, vert_positions_prev[(*vt)[2]]);
1716 madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time);
1719 madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time);
1722 madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time);
1737 if ((facedist > innerfacethickness) && (facedist < outerfacethickness)) {
1739 force_mag_norm =
float(
exp(
double(-ee * facedist)));
1740 if (facedist > outerfacethickness * ff) {
1741 force_mag_norm =
float(force_mag_norm) * fa * (facedist - outerfacethickness) *
1742 (facedist - outerfacethickness);
1745 if (facedist > 0.0f) {
1746 *damp *= (1.0f - facedist / outerfacethickness);
1752 if (deflected < 2) {
1756 if ((vert_positions_prev) && (*damp > 0.0f)) {
1761 *intrusion += facedist;
1774 if (deflected == 1) {
1775 force_mag_norm =
float(
exp(
double() - ee * mindistedge));
1776 if (mindistedge > outerfacethickness * ff) {
1777 force_mag_norm =
float(force_mag_norm) * fa * (mindistedge - outerfacethickness) *
1778 (mindistedge - outerfacethickness);
1782 if (mindistedge > 0.0f) {
1783 *damp *= (1.0f - mindistedge / outerfacethickness);
1786 if (deflected == 2) {
1789 if (deflected == 3) {
1821 s_actpos, facenormal, cf, force, ob, time, vel, intrusion);
1823 deflected = sb_detect_vertex_collisionCachedEx(
1824 s_actpos, facenormal, cf, force, ob, time, vel, intrusion);
1831static void dfdx_spring(
int ia,
int ic,
int op,
float dir[3],
float L,
float len,
float factor)
1836 for (i = 0; i < 3; i++) {
1837 for (j = 0; j < 3; j++) {
1838 delta_ij = (i == j ? (1.0f) : (0.0f));
1839 m = factor * (dir[i] * dir[j] + (1 -
L /
len) * (delta_ij - dir[i] * dir[j]));
1845 for (i = 0; i < 3; i++) {
1846 for (j = 0; j < 3; j++) {
1847 m = factor * dir[i] * dir[j];
1854static void dfdx_goal(
int ia,
int ic,
int op,
float factor)
1857 for (i = 0; i < 3; i++) {
1862static void dfdv_goal(
int ia,
int ic,
float factor)
1865 for (i = 0; i < 3; i++) {
1876 float dir[3], dvel[3];
1877 float distance, forcefactor, kd, absvel, projvel, kw;
1882 if (bpi == bs->
v1) {
1890 else if (bpi == bs->
v2) {
1900 CLOG_WARN(&
LOG,
"bodypoint <bpi> is not attached to spring <*bs>");
1907 if (bs->
len < distance) {
1908 iks = 1.0f / (1.0f - sb->
inspring) - 1.0f;
1911 iks = 1.0f / (1.0f - sb->
inpush) - 1.0f;
1914 if (bs->
len > 0.0f) {
1915 forcefactor = iks / bs->
len;
1945 kd *= absvel * projvel;
1958 int *ptr_to_break_func(
void),
1966 int bb, do_selfcollision, do_springcollision, do_aero;
1967 int number_of_points_here = ilast - ifirst;
1994 bp = &sb->
bpoint[ifirst];
1995 for (bb = number_of_points_here; bb > 0; bb--, bp++) {
2000 if (do_selfcollision) {
2005 float velcenter[3], dvel[3], def[3];
2017 if ((
fabsf(def[0]) > compare) || (
fabsf(def[1]) > compare) || (
fabsf(def[2]) > compare)) {
2021 if (distance < compare) {
2026 if (
ELEM(ilast - bb, bs->
v2, bs->
v1)) {
2032 float f = bstune / (
distance) + bstune / (compare * compare) * distance -
2033 2.0f * bstune / compare;
2057 bp->
force[0] += -ks * (auxvect[0]);
2058 bp->
force[1] += -ks * (auxvect[1]);
2059 bp->
force[2] += -ks * (auxvect[2]);
2067 if (forcetime > 0.0f) {
2068 bp->
force[0] -= kd * (auxvect[0]);
2069 bp->
force[1] -= kd * (auxvect[1]);
2070 bp->
force[2] -= kd * (auxvect[2]);
2073 bp->
force[0] -= kd * (velgoal[0] - bp->
vec[0]);
2074 bp->
force[1] -= kd * (velgoal[1] - bp->
vec[1]);
2075 bp->
force[2] -= kd * (velgoal[2] - bp->
vec[2]);
2083 copy_v3_v3(gravity, scene->physics_settings.gravity);
2097 float force[3] = {0.0f, 0.0f, 0.0f};
2098 float speed[3] = {0.0f, 0.0f, 0.0f};
2108 mul_v3_fl(force, fieldfactor * eval_sb_fric_force_scale);
2112 kd = sb->
mediafrict * eval_sb_fric_force_scale;
2113 bp->
force[0] -= kd * (bp->
vec[0] + windfactor * speed[0] / eval_sb_fric_force_scale);
2114 bp->
force[1] -= kd * (bp->
vec[1] + windfactor * speed[1] / eval_sb_fric_force_scale);
2115 bp->
force[2] -= kd * (bp->
vec[2] + windfactor * speed[2] / eval_sb_fric_force_scale);
2132 float cfforce[3], defforce[3] = {0.0f, 0.0f, 0.0f}, vel[3] = {0.0f, 0.0f, 0.0f},
2133 facenormal[3], cf = 1.0f, intrusion;
2136 if (
sb_deflect_face(ob, bp->
pos, facenormal, defforce, &cf, timenow, vel, &intrusion)) {
2137 if (intrusion < 0.0f) {
2152 iks = 1.0f / (1.0f - sb->
inspring) - 1.0f;
2159 if (do_springcollision || do_aero) {
2198 int *ptr_to_break_func(
void),
2207 int i, totthread,
left, dec;
2211 int lowpoints = 100;
2216 while ((totpoint / totthread < lowpoints) && (totthread > 1)) {
2225 dec = totpoint / totthread + 1;
2226 for (i = 0; i < totthread; i++) {
2228 sb_threads[i].
ob = ob;
2230 sb_threads[i].
timenow = timenow;
2237 sb_threads[i].
ifirst = 0;
2243 sb_threads[i].
nr = i;
2244 sb_threads[i].
tot = totthread;
2247 if (totthread > 1) {
2250 for (i = 0; i < totthread; i++) {
2273 float fieldfactor = -1.0f, windfactor = 0.25;
2274 int do_deflector , do_springcollision, do_aero;
2291 if (do_springcollision || do_aero) {
2330 float dx[3] = {0}, dv[3], aabbmin[3], aabbmax[3], cm[3] = {0.0f, 0.0f, 0.0f};
2331 float timeovermass ;
2332 float maxerrpos = 0.0f, maxerrvel = 0.0f;
2337 aabbmin[0] = aabbmin[1] = aabbmin[2] = 1e20f;
2338 aabbmax[0] = aabbmax[1] = aabbmax[2] = -1e20f;
2344 timeovermass = forcetime / sb->
nodemass;
2347 timeovermass = forcetime / 0.009999f;
2358 timeovermass = forcetime / 0.009999f;
2445 if (bp->
choke > 0.0f) {
2470 *err =
max_ff(maxerrpos, maxerrvel);
2496static void softbody_store_step(
Object *ob)
2509static void softbody_store_state(
Object *ob,
float *ppos,
float *pvel)
2514 float *pp = ppos, *pv = pvel;
2527static void softbody_retrieve_state(
Object *ob,
float *ppos,
float *pvel)
2532 float *pp = ppos, *pv = pvel;
2545static void softbody_swap_state(
Object *ob,
float *ppos,
float *pvel)
2550 float *pp = ppos, *pv = pvel;
2605 if ((r > 1.05f) || (r < 0.95f)) {
2606 bs->
len = ((100.0f -
b) * bs->
len +
b *
l) / 100.0f;
2657 if (mesh->verts_num) {
2659 for (a = 0; a < mesh->verts_num; a++, bp++) {
2686 int defgroup_index, defgroup_index_mass, defgroup_index_spring;
2689 totedge = mesh->edges_num;
2702 const MDeformVert *dvert = mesh->deform_verts().data();
2704 defgroup_index = dvert ? (sb->
vertgroup - 1) : -1;
2708 for (a = 0; a < mesh->verts_num; a++, bp++) {
2726 if (defgroup_index_mass != -1) {
2730 if (defgroup_index_spring != -1) {
2739 for (a = mesh->edges_num; a > 0; a--, edge++, bs++) {
2769 const Mesh *mesh =
static_cast<const Mesh *
>(ob->
data);
2779 mesh->vert_positions(), mesh->faces(), mesh->corner_verts(), corner_tris);
2785 bodyface->
v1 = corner_verts[corner_tris[a][0]];
2786 bodyface->
v2 = corner_verts[corner_tris[a][1]];
2787 bodyface->
v3 = corner_verts[corner_tris[a][2]];
2798 float accu_pos[3] = {0.0f, 0.0f, 0.0f};
2799 float accu_mass = 0.0f;
2806 for (a = 0; a < sb->
totpoint; a++, rp++, bp++) {
2824 mul_m4_v3(ob->object_to_world().ptr(), p1);
2826 mul_m4_v3(ob->object_to_world().ptr(), p2);
2833 int u,
v,
w, dv, dw, bpc = 0, bpuc;
2836 dw = dv * lt->
pntsv;
2842 for (u = 0, bpuc = 0, bpu =
nullptr; u < lt->
pntsu; u++, bp++, bpc++) {
2871 bs->
v2 = bpc - dw - dv - 1;
2873 bs->
len =
globallen((bp - dw - dv - 1)->vec, bp->vec, ob);
2876 if ((
v < lt->pntsv - 1) && (u != 0)) {
2878 bs->
v2 = bpc - dw + dv - 1;
2880 bs->
len =
globallen((bp - dw + dv - 1)->vec, bp->vec, ob);
2888 bs->
v2 = bpc + dw - dv - 1;
2890 bs->
len =
globallen((bp + dw - dv - 1)->vec, bp->vec, ob);
2893 if ((
v < lt->pntsv - 1) && (u != 0)) {
2895 bs->
v2 = bpc + dw + dv - 1;
2897 bs->
len =
globallen((bp + dw + dv - 1)->vec, bp->vec, ob);
2914 int totvert, totspring = 0, a;
2917 int defgroup_index, defgroup_index_mass, defgroup_index_spring;
2940 for (a = 0; a < totvert; a++, bp++, bpnt++) {
2953 if (defgroup_index_mass != -1) {
2957 if (defgroup_index_spring != -1) {
2981 int a, curindex = 0;
2982 int totvert, totspring = 0, setgoal = 0;
3018 for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++, bp += 3, curindex += 3) {
3020 bp->goal *= bezt->weight;
3023 (bp + 1)->goal = bp->goal;
3024 (bp + 2)->goal = bp->goal;
3032 bs->
v1 = curindex - 3;
3035 bs->
len =
globallen((bezt - 1)->vec[0], bezt->vec[0], ob);
3039 bs->
v2 = curindex + 1;
3044 bs->
v1 = curindex + 1;
3045 bs->
v2 = curindex + 2;
3053 for (bpnt = nu->bp, a = 0; a < nu->pntsu * nu->pntsv; a++, bpnt++, bp++, curindex++) {
3055 bp->goal *= bpnt->weight;
3057 if (totspring && a > 0) {
3058 bs->
v1 = curindex - 1;
3089 for (a = 0; a < numVerts; a++, bp++) {
3093 mul_m4_v3(ob->world_to_object().ptr(), vertexCos[a]);
3171 if (sb ==
nullptr) {
3208 return ((
Mesh *)ob->
data)->edges_num;
3224 float (*vertexCos)[3],
3230 if (!sb || !sb->
bpoint) {
3234 for (a = 0, bp = sb->
bpoint; a < numVerts; a++, bp++) {
3254 float com[3], rcom[3];
3257 if (!ob || !ob->
soft) {
3261 if (!sb || !sb->
bpoint) {
3273 sb->
totpoint, opos,
nullptr, rpos,
nullptr, com, rcom, lrot, lscale);
3295 for (a = 0, bp = sb->
bpoint; a < numVerts; a++, bp++) {
3301 bp->
vec[0] = bp->
vec[1] = bp->
vec[2] = 0.0f;
3364 if (dtime < 0 || dtime > 10.5f) {
3380 float forcetimemax = 1.0f;
3382 float forcetimemin = 0.01f;
3384 float timedone = 0.0;
3391 forcetimemax = dtime / sb->
minloops;
3394 forcetimemin = dtime / sb->
maxloops;
3401 forcetime = forcetimemax;
3402 while ((
fabsf(timedone) <
fabsf(dtime)) && (loops < 2000)) {
3420 if (forcetime > forcetimemin) {
3421 forcetime =
max_ff(forcetime / 2.0f, forcetimemin);
3426 timedone += forcetime;
3430 float newtime = forcetime * 1.1f;
3435 newtime = forcetime;
3440 newtime = forcetime;
3443 timedone += forcetime;
3444 newtime =
min_ff(forcetimemax,
max_ff(newtime, forcetimemin));
3446 if (forcetime > 0.0f) {
3447 forcetime =
min_ff(dtime - timedone, newtime);
3450 forcetime =
max_ff(dtime - timedone, newtime);
3456 if (sct - sst > 0.5) {
3457 printf(
"%3.0f%% \r", 100.0f * timedone / dtime);
3472 printf(
"\r needed %d steps/frame", loops);
3497 if ((sct - sst > 0.5) || (
G.debug &
G_DEBUG)) {
3498 printf(
" solver time %f sec %s\n", sct - sst, ob->
id.
name);
3509 object->soft->last_frame = framenr;
3517 float (*vertexCos)[3],
3523 float dtime, timescale;
3524 int framedelta, framenr, startframe, endframe;
3528 framenr =
int(cfra);
3529 framedelta = framenr - cache->
simframe;
3542 if (framenr < startframe) {
3546 if (framenr > endframe) {
3551 if (sb->
bpoint ==
nullptr ||
3579 if (framenr == startframe) {
3586 cache->
flag &= ~PTCACHE_REDO_NEEDED;
3598 cache_result =
BKE_ptcache_read(&pid,
float(framenr) + scene->r.subframe, can_simulate);
3627 if (can_write_cache) {
3633 if (!can_simulate) {
3646 dtime = framedelta * timescale;
void BKE_collision_objects_free(struct Object **objects)
struct Object ** BKE_collision_objects_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
int BKE_nurbList_verts_count(const ListBase *nurb)
CustomData interface, see also DNA_customdata_types.h.
const void * CustomData_get_layer_named(const CustomData *data, eCustomDataType type, blender::StringRef name)
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
void BKE_effectors_free(struct ListBase *lb)
void BKE_effectors_apply(struct ListBase *effectors, struct ListBase *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
void pd_point_from_soft(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
struct ListBase * BKE_effectors_create(struct Depsgraph *depsgraph, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool use_rotation)
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
void BKE_ptcache_validate(struct PointCache *cache, int framenr)
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb)
struct PointCache * BKE_ptcache_add(struct ListBase *ptcaches)
#define PTCACHE_READ_INTERPOLATED
int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
void BKE_ptcache_free_list(struct ListBase *ptcaches)
#define PTCACHE_RESET_OUTDATED
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode)
void BKE_ptcache_invalidate(struct PointCache *cache)
#define PTCACHE_READ_EXACT
int BKE_scene_num_threads(const Scene *scene)
BLI_INLINE void * BLI_ghashIterator_getKey(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
void BLI_ghashIterator_step(GHashIterator *ghi)
void BLI_ghashIterator_free(GHashIterator *ghi)
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
GHashIterator * BLI_ghashIterator_new(GHash *gh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void(* GHashValFreeFP)(void *val)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
bool BLI_ghash_ensure_p(GHash *gh, void *key, void ***r_val) ATTR_WARN_UNUSED_RESULT
BLI_INLINE bool BLI_ghashIterator_done(const GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
#define LISTBASE_FOREACH(type, var, list)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE float max_fff(float a, float b, float c)
MINLINE float max_ff(float a, float b)
MINLINE float min_ff(float a, float b)
MINLINE float min_fff(float a, float b, float c)
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
void vcloud_estimate_transform_v3(int list_size, const float(*pos)[3], const float *weight, const float(*rpos)[3], const float *rweight, float lloc[3], float rloc[3], float lrot[3][3], float lscale[3][3])
bool isect_line_segment_tri_v3(const float p1[3], const float p2[3], const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2])
bool isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void unit_m3(float m[3][3])
void mul_m4_v3(const float M[4][4], float r[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void minmax_v3v3_v3(float min[3], float max[3], const float vec[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])
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
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])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
void BLI_threadpool_init(struct ListBase *threadbase, void *(*do_thread)(void *), int tot)
void BLI_threadpool_end(struct ListBase *threadbase)
void BLI_threadpool_insert(struct ListBase *threadbase, void *callerdata)
Platform independent time functions.
double BLI_time_now_seconds(void)
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
bool DEG_is_active(const Depsgraph *depsgraph)
Object * DEG_get_original_object(Object *object)
Object groups, one object can be in many groups at once.
@ eModifierType_Collision
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
#define MEM_recallocN(vmemh, len)
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 & w() const
Return the w value.
local_group_size(16, 16) .push_constant(Type b
pow(value.r - subtrahend, 2.0)") .do_static_compilation(true)
const Depsgraph * depsgraph
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, float L, float k)
void EIG_linear_solver_matrix_add(LinearSolver *solver, int row, int col, double value)
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_dupallocN)(const void *vmemh)
ccl_device_inline float3 exp(float3 v)
void corner_tris_calc(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< int3 > corner_tris)
float distance(float a, float b)
static void add_mesh_quad_diag_springs(Object *ob)
struct BodySpring BodySpring
static int query_external_colliders(Depsgraph *depsgraph, Collection *collection)
static ccd_Mesh * ccd_mesh_make(Object *ob)
#define SBF_OUTOFCOLLISION
static int sb_deflect_face(Object *ob, float *actpos, float *facenormal, float *force, float *cf, float time, float *vel, float *intrusion)
struct ReferenceVert ReferenceVert
static void sbStoreLastFrame(Depsgraph *depsgraph, Object *object, float framenr)
static void ccd_mesh_free(ccd_Mesh *ccdm)
static int sb_detect_face_pointCached(const float face_v1[3], const float face_v2[3], const float face_v3[3], float *damp, float force[3], Object *vertexowner, float time)
static void * exec_softbody_calc_forces(void *data)
static float _final_mass(Object *ob, BodyPoint *bp)
static void mesh_faces_to_scratch(Object *ob)
static void springs_from_mesh(Object *ob)
static float _final_goal(Object *ob, BodyPoint *bp)
void sbObjectToSoftbody(Object *ob)
static void ccd_build_deflector_hash_single(GHash *hash, Object *ob)
static void softbody_restore_prev_step(Object *ob)
static void sb_sfesf_threads_run(Depsgraph *depsgraph, Scene *scene, Object *ob, float timenow, int totsprings, int *ptr_to_break_func(void))
static void sb_cf_threads_run(Scene *scene, Object *ob, float forcetime, float timenow, int totpoint, int *ptr_to_break_func(void), ListBase *effectors, int do_deflector, float fieldfactor, float windfactor)
static int sb_detect_edge_collisionCached(const float edge_v1[3], const float edge_v2[3], float *damp, float force[3], Object *vertexowner, float time)
static void _scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow, int ifirst, int ilast, ListBase *effectors)
static void mesh_to_softbody(Object *ob)
static void sb_spring_force(Object *ob, int bpi, BodySpring *bs, float iks, float)
static int(* SB_localInterruptCallBack)(void)
struct SBScratch SBScratch
static void curve_surf_to_softbody(Object *ob)
static void softbody_apply_goalsnap(Object *ob)
static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], float *damp, float force[3], Object *vertexowner, float time, float vel[3], float *intrusion)
static void softbody_apply_forces(Object *ob, float forcetime, int mode, float *err, int mid_flags)
static void ccd_build_deflector_hash(Depsgraph *depsgraph, Collection *collection, Object *vertexowner, GHash *hash)
struct SB_thread_context SB_thread_context
static void calculate_collision_balls(Object *ob)
static void build_bps_springlist(Object *ob)
static void add_bp_springlist(BodyPoint *bp, int springID)
static const int CCD_SAFETY
static void softbody_reset(Object *ob, SoftBody *sb, float(*vertexCos)[3], int numVerts)
static void renew_softbody(Object *ob, int totpoint, int totspring)
static void softbody_step(Depsgraph *depsgraph, Scene *scene, Object *ob, SoftBody *sb, float dtime)
static float globallen(float *v1, float *v2, Object *ob)
static void softbody_to_object(Object *ob, float(*vertexCos)[3], int numVerts, int local)
static void add_2nd_order_springs(Object *ob, float stiffness)
static void ccd_update_deflector_hash_single(GHash *hash, Object *ob)
static void free_softbody_intern(SoftBody *sb)
static void softbody_calc_forces(Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow)
static int sb_detect_face_collisionCached(const float face_v1[3], const float face_v2[3], const float face_v3[3], float *damp, float force[3], Object *vertexowner, float time)
static void add_2nd_order_roller(Object *ob, float, int *counter, int addsprings)
void sbFreeSimulation(SoftBody *sb)
static int sb_detect_aabb_collisionCached(float[3], Object *vertexowner, float)
static void sb_new_scratch(SoftBody *sb)
static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, float forcetime, float timenow, int ifirst, int ilast, int *ptr_to_break_func(void), ListBase *effectors, int do_deflector, float fieldfactor, float windfactor)
static float sb_time_scale(Object *ob)
static void free_scratch(SoftBody *sb)
static void interpolate_exciter(Object *ob, int timescale, int time)
void SB_estimate_transform(Object *ob, float lloc[3], float lrot[3][3], float lscale[3][3])
void sbSetInterruptCallBack(int(*f)(void))
void sbObjectStep(Depsgraph *depsgraph, Scene *scene, Object *ob, float cfra, float(*vertexCos)[3], int numVerts)
static int choose_winner(float *w, float *pos, float *a, float *b, float *c, float *ca, float *cb, float *cc)
static float sb_fric_force_scale(Object *)
static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff, Object *ob)
static void reference_to_scratch(Object *ob)
static bool object_has_edges(const Object *ob)
static void free_softbody_baked(SoftBody *sb)
struct ReferenceState ReferenceState
struct ccdf_minmax ccdf_minmax
static void lattice_to_softbody(Object *ob)
static void * exec_scan_for_ext_spring_forces(void *data)
static void ccd_update_deflector_hash(Depsgraph *depsgraph, Collection *collection, Object *vertexowner, GHash *hash)
static void scan_for_ext_face_forces(Object *ob, float timenow)
static float sb_grav_force_scale(Object *)
static void apply_spring_memory(Object *ob)
static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
static void softbody_update_positions(Object *ob, SoftBody *sb, float(*vertexCos)[3], int numVerts)
static int count_mesh_quads(Mesh *mesh)
struct MDeformVert * dvert
ObjectRuntimeHandle * runtime
short needstobuildcollider
struct PointCache * pointcache
struct SoftBody_Shared * shared
struct Collection * collision_group
struct EffectorWeights * effector_weights
char namedVG_Spring_K[64]
struct BodySpring * bspring
struct SBScratch * scratch
struct BodyPoint * bpoint
const float(* vert_positions_prev)[3]
const blender::int3 * vert_tris
const float(* vert_positions)[3]