133#define MID_PRESERVE 1
135#define SOFTGOALSNAP 0.999f
139#define HEUNWARNLIMIT 1
141#define BSF_INTERSECT 1
145#define SBF_OUTOFCOLLISION 2
147#define BFF_INTERSECT 1
148#define BFF_CLOSEVERT 2
220 if (bp->
goal < 0.0f) {
309 for (i = 0; i < pccd_M->
mvert_num; i++) {
327 "ccd_Mesh_Faces_mima");
330 for (i = 0, mima = pccd_M->
mima; i < pccd_M->tri_num; i++, mima++) {
400 for (i = 0; i < pccd_M->
mvert_num; i++) {
425 for (i = 0, mima = pccd_M->
mima; i < pccd_M->tri_num; i++, mima++) {
492 MEM_delete(ccdm->
mima);
521 for (
int i = 0; i < numobjects; i++) {
550 if ((!
hash) || (!vertexowner)) {
558 for (
int i = 0; i < numobjects; i++) {
576 if (faces[i].size() == 4) {
604 for (
int a = 0; a <
mesh->faces_num; a++) {
605 const int poly_size = faces[a].
size();
606 if (poly_size == 4) {
607 bs->
v1 = corner_verts[faces[a].start() + 0];
608 bs->
v2 = corner_verts[faces[a].start() + 2];
611 bs->
v1 = corner_verts[faces[a].start() + 1];
612 bs->
v2 = corner_verts[faces[a].start() + 3];
630 int a,
b, c, notthis = 0, v0;
663 if ((bs2->
v1 != notthis) && (bs2->
v1 > v0)) {
672 if ((bs2->
v2 != notthis) && (bs2->
v2 > v0)) {
692 stiffness *= stiffness;
768 int a,
b, akku_count;
792 if (akku_count > 0) {
821 if (ob->
soft ==
nullptr) {
840 for (i = 0; i < totpoint; i++) {
872 for (k = 0; k < sb->
totkey; k++) {
873 key = *(sb->
keys + k);
878 MEM_SAFE_DELETE(sb->
keys);
972 return (numobjects != 0);
980 float aabbmin[3], aabbmax[3];
986 if ((sb ==
nullptr) || (sb->
scratch ==
nullptr)) {
999 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1000 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1001 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1025 const float face_v2[3],
1026 const float face_v3[3],
1032 float nv1[3], edge1[3], edge2[3], d_nvect[3], aabbmin[3], aabbmax[3];
1033 float facedist, outerfacethickness, tune = 10.0f;
1034 int a, deflected = 0;
1036 aabbmin[0] = std::min({face_v1[0], face_v2[0], face_v3[0]});
1037 aabbmin[1] = std::min({face_v1[1], face_v2[1], face_v3[1]});
1038 aabbmin[2] = std::min({face_v1[2], face_v2[2], face_v3[2]});
1039 aabbmax[0] = std::max({face_v1[0], face_v2[0], face_v3[0]});
1040 aabbmax[1] = std::max({face_v1[1], face_v2[1], face_v3[1]});
1041 aabbmax[2] = std::max({face_v1[2], face_v2[2], face_v3[2]});
1055 const float (*vert_positions)[3] =
nullptr;
1056 const float (*vert_positions_prev)[3] =
nullptr;
1062 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1063 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1064 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1077 if (vert_positions) {
1080 if (vert_positions_prev) {
1082 madd_v3_v3fl(nv1, vert_positions_prev[a - 1], 1.0f - time);
1087 if (
fabsf(facedist) < outerfacethickness) {
1091 df = (outerfacethickness - facedist) / outerfacethickness;
1094 df = (outerfacethickness + facedist) / outerfacethickness;
1099 df = 0.01f *
expf(-100.0f * df);
1114 const float face_v2[3],
1115 const float face_v3[3],
1121 float nv1[3], nv2[3], nv3[3], edge1[3], edge2[3], d_nvect[3], aabbmin[3], aabbmax[3];
1122 float t, tune = 10.0f;
1123 int a, deflected = 0;
1125 aabbmin[0] = std::min({face_v1[0], face_v2[0], face_v3[0]});
1126 aabbmin[1] = std::min({face_v1[1], face_v2[1], face_v3[1]});
1127 aabbmin[2] = std::min({face_v1[2], face_v2[2], face_v3[2]});
1128 aabbmax[0] = std::max({face_v1[0], face_v2[0], face_v3[0]});
1129 aabbmax[1] = std::max({face_v1[1], face_v2[1], face_v3[1]});
1130 aabbmax[2] = std::max({face_v1[2], face_v2[2], face_v3[2]});
1138 const float (*vert_positions)[3] =
nullptr;
1139 const float (*vert_positions_prev)[3] =
nullptr;
1140 const int3 *vt =
nullptr;
1150 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1151 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1152 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1166 if ((aabbmax[0] < mima->
minx) || (aabbmin[0] > mima->
maxx) ||
1167 (aabbmax[1] < mima->
miny) || (aabbmin[1] > mima->
maxy) ||
1168 (aabbmax[2] < mima->
minz) || (aabbmin[2] > mima->
maxz))
1175 if (vert_positions) {
1181 if (vert_positions_prev) {
1183 madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time);
1186 madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time);
1189 madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time);
1220 float damp = 0.0f, choke = 1.0f;
1221 float tune = -10.0f;
1288 const float edge_v2[3],
1294 float nv1[3], nv2[3], nv3[3], edge1[3], edge2[3], d_nvect[3], aabbmin[3], aabbmax[3];
1296 int a, deflected = 0;
1309 const float (*vert_positions)[3] =
nullptr;
1310 const float (*vert_positions_prev)[3] =
nullptr;
1311 const int3 *vt =
nullptr;
1321 if ((aabbmax[0] < ccdm->
bbmin[0]) || (aabbmax[1] < ccdm->
bbmin[1]) ||
1322 (aabbmax[2] < ccdm->
bbmin[2]) || (aabbmin[0] > ccdm->
bbmax[0]) ||
1323 (aabbmin[1] > ccdm->
bbmax[1]) || (aabbmin[2] > ccdm->
bbmax[2]))
1337 if ((aabbmax[0] < mima->
minx) || (aabbmin[0] > mima->
maxx) ||
1338 (aabbmax[1] < mima->
miny) || (aabbmin[1] > mima->
maxy) ||
1339 (aabbmax[2] < mima->
minz) || (aabbmin[2] > mima->
maxz))
1346 if (vert_positions) {
1352 if (vert_positions_prev) {
1354 madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time);
1357 madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time);
1360 madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time);
1372 float intrusiondepth, i1, i2;
1377 intrusiondepth = -
min_ff(i1, i2) / el;
1397 ListBaseT<EffectorCache> *effectors)
1405 for (a = ifirst; a < ilast; a++) {
1408 feedback[0] = feedback[1] = feedback[2] = 0.0f;
1428 float vel[3], sp[3], pr[3], force[3];
1429 float f, windfactor = 0.25f;
1433 float speed[3] = {0.0f, 0.0f, 0.0f};
1449 f = -0.0001f * f * f * sb->
aeroedge;
1484 int *ptr_to_break_func(
void))
1487 ListBaseT<ThreadSlot> threads;
1489 int i, totthread, left, dec;
1493 int lowsprings = 100;
1501 while ((totsprings / totthread < lowsprings) && (totthread > 1)) {
1507 dec = totsprings / totthread + 1;
1508 for (i = 0; i < totthread; i++) {
1509 sb_threads[i].
scene = scene;
1510 sb_threads[i].
ob = ob;
1512 sb_threads[i].
timenow = timenow;
1513 sb_threads[i].
ilast = left;
1516 sb_threads[i].
ifirst = left;
1519 sb_threads[i].
ifirst = 0;
1525 sb_threads[i].
nr = i;
1526 sb_threads[i].
tot = totthread;
1528 if (totthread > 1) {
1531 for (i = 0; i < totthread; i++) {
1541 MEM_delete(sb_threads);
1549 float *
w,
float *pos,
float *a,
float *
b,
float *c,
float *ca,
float *cb,
float *cc)
1580 float facenormal[3],
1588 float nv1[3], nv2[3], nv3[3], edge1[3], edge2[3], d_nvect[3], dv1[3], ve[3],
1589 avel[3] = {0.0, 0.0, 0.0}, vv1[3], vv2[3], vv3[3], coledge[3] = {0.0f, 0.0f, 0.0f},
1590 mindistedge = 1000.0f, outerforceaccu[3], innerforceaccu[3], facedist,
1591 force_mag_norm, minx, miny, minz, maxx, maxy, maxz,
1592 innerfacethickness = -0.5f, outerfacethickness = 0.2f, ee = 5.0f, ff = 0.1f, fa = 1;
1593 int a, deflected = 0, cavel = 0, ci = 0;
1596 outerforceaccu[0] = outerforceaccu[1] = outerforceaccu[2] = 0.0f;
1597 innerforceaccu[0] = innerforceaccu[1] = innerforceaccu[2] = 0.0f;
1606 const float (*vert_positions)[3] =
nullptr;
1607 const float (*vert_positions_prev)[3] =
nullptr;
1608 const int3 *vt =
nullptr;
1618 minx = ccdm->
bbmin[0];
1619 miny = ccdm->
bbmin[1];
1620 minz = ccdm->
bbmin[2];
1622 maxx = ccdm->
bbmax[0];
1623 maxy = ccdm->
bbmax[1];
1624 maxz = ccdm->
bbmax[2];
1626 if ((opco[0] < minx) || (opco[1] < miny) || (opco[2] < minz) || (opco[0] > maxx) ||
1627 (opco[1] > maxy) || (opco[2] > maxz))
1643 fa = (ff * outerfacethickness - outerfacethickness);
1646 avel[0] = avel[1] = avel[2] = 0.0f;
1649 if ((opco[0] < mima->
minx) || (opco[0] > mima->
maxx) || (opco[1] < mima->
miny) ||
1650 (opco[1] > mima->
maxy) || (opco[2] < mima->
minz) || (opco[2] > mima->
maxz))
1657 if (vert_positions) {
1663 if (vert_positions_prev) {
1669 sub_v3_v3v3(vv1, nv1, vert_positions_prev[(*vt)[0]]);
1670 sub_v3_v3v3(vv2, nv2, vert_positions_prev[(*vt)[1]]);
1671 sub_v3_v3v3(vv3, nv3, vert_positions_prev[(*vt)[2]]);
1674 madd_v3_v3fl(nv1, vert_positions_prev[(*vt)[0]], 1.0f - time);
1677 madd_v3_v3fl(nv2, vert_positions_prev[(*vt)[1]], 1.0f - time);
1680 madd_v3_v3fl(nv3, vert_positions_prev[(*vt)[2]], 1.0f - time);
1695 if ((facedist > innerfacethickness) && (facedist < outerfacethickness)) {
1697 force_mag_norm =
float(
exp(
double(-ee * facedist)));
1698 if (facedist > outerfacethickness * ff) {
1699 force_mag_norm = force_mag_norm * fa * (facedist - outerfacethickness) *
1700 (facedist - outerfacethickness);
1703 if (facedist > 0.0f) {
1704 *damp *= (1.0f - facedist / outerfacethickness);
1710 deflected = std::max(deflected, 2);
1712 if ((vert_positions_prev) && (*damp > 0.0f)) {
1717 *intrusion += facedist;
1729 if (deflected == 1) {
1730 force_mag_norm =
float(
exp(
double() - ee * mindistedge));
1731 if (mindistedge > outerfacethickness * ff) {
1732 force_mag_norm = force_mag_norm * fa * (mindistedge - outerfacethickness) *
1733 (mindistedge - outerfacethickness);
1737 if (mindistedge > 0.0f) {
1738 *damp *= (1.0f - mindistedge / outerfacethickness);
1741 if (deflected == 2) {
1744 if (deflected == 3) {
1775 s_actpos, facenormal, cf, force, ob, time, vel, intrusion);
1777 deflected = sb_detect_vertex_collisionCachedEx(
1778 s_actpos, facenormal, cf, force, ob, time, vel, intrusion);
1785static void dfdx_spring(
int ia,
int ic,
int op,
float dir[3],
float L,
float len,
float factor)
1790 for (i = 0; i < 3; i++) {
1791 for (j = 0; j < 3; j++) {
1792 delta_ij = (i == j ? (1.0f) : (0.0f));
1793 m = factor * (dir[i] * dir[j] + (1 -
L /
len) * (delta_ij - dir[i] * dir[j]));
1799 for (i = 0; i < 3; i++) {
1800 for (j = 0; j < 3; j++) {
1801 m = factor * dir[i] * dir[j];
1808static void dfdx_goal(
int ia,
int ic,
int op,
float factor)
1811 for (i = 0; i < 3; i++) {
1816static void dfdv_goal(
int ia,
int ic,
float factor)
1819 for (i = 0; i < 3; i++) {
1830 float dir[3], dvel[3];
1831 float distance, forcefactor, kd, absvel, projvel, kw;
1836 if (bpi == bs->
v1) {
1844 else if (bpi == bs->
v2) {
1854 CLOG_WARN(&
LOG,
"bodypoint <bpi> is not attached to spring <*bs>");
1862 iks = 1.0f / (1.0f - sb->
inspring) - 1.0f;
1865 iks = 1.0f / (1.0f - sb->
inpush) - 1.0f;
1868 if (bs->
len > 0.0f) {
1869 forcefactor = iks / bs->
len;
1899 kd *= absvel * projvel;
1912 int *ptr_to_break_func(
void),
1913 ListBaseT<EffectorCache> *effectors,
1920 int bb, do_selfcollision, do_springcollision, do_aero;
1921 int number_of_points_here = ilast - ifirst;
1948 bp = &sb->
bpoint[ifirst];
1949 for (bb = number_of_points_here; bb > 0; bb--, bp++) {
1954 if (do_selfcollision) {
1959 float velcenter[3], dvel[3], def[3];
1971 if ((
fabsf(def[0]) > compare) || (
fabsf(def[1]) > compare) || (
fabsf(def[2]) > compare)) {
1980 if (
ELEM(ilast - bb, bs->
v2, bs->
v1)) {
1987 2.0f * bstune / compare;
2011 bp->
force[0] += -ks * (auxvect[0]);
2012 bp->
force[1] += -ks * (auxvect[1]);
2013 bp->
force[2] += -ks * (auxvect[2]);
2021 if (forcetime > 0.0f) {
2022 bp->
force[0] -= kd * (auxvect[0]);
2023 bp->
force[1] -= kd * (auxvect[1]);
2024 bp->
force[2] -= kd * (auxvect[2]);
2027 bp->
force[0] -= kd * (velgoal[0] - bp->
vec[0]);
2028 bp->
force[1] -= kd * (velgoal[1] - bp->
vec[1]);
2029 bp->
force[2] -= kd * (velgoal[2] - bp->
vec[2]);
2051 float force[3] = {0.0f, 0.0f, 0.0f};
2052 float speed[3] = {0.0f, 0.0f, 0.0f};
2062 mul_v3_fl(force, fieldfactor * eval_sb_fric_force_scale);
2066 kd = sb->
mediafrict * eval_sb_fric_force_scale;
2067 bp->
force[0] -= kd * (bp->
vec[0] + windfactor * speed[0] / eval_sb_fric_force_scale);
2068 bp->
force[1] -= kd * (bp->
vec[1] + windfactor * speed[1] / eval_sb_fric_force_scale);
2069 bp->
force[2] -= kd * (bp->
vec[2] + windfactor * speed[2] / eval_sb_fric_force_scale);
2086 float cfforce[3], defforce[3] = {0.0f, 0.0f, 0.0f}, vel[3] = {0.0f, 0.0f, 0.0f},
2087 facenormal[3], cf = 1.0f, intrusion;
2090 if (
sb_deflect_face(ob, bp->
pos, facenormal, defforce, &cf, timenow, vel, &intrusion)) {
2091 if (intrusion < 0.0f) {
2106 iks = 1.0f / (1.0f - sb->
inspring) - 1.0f;
2113 if (do_springcollision || do_aero) {
2152 int *ptr_to_break_func(
void),
2153 ListBaseT<EffectorCache> *effectors,
2159 ListBaseT<ThreadSlot> threads;
2161 int i, totthread, left, dec;
2165 int lowpoints = 100;
2170 while ((totpoint / totthread < lowpoints) && (totthread > 1)) {
2178 dec = totpoint / totthread + 1;
2179 for (i = 0; i < totthread; i++) {
2180 sb_threads[i].
scene = scene;
2181 sb_threads[i].
ob = ob;
2183 sb_threads[i].
timenow = timenow;
2184 sb_threads[i].
ilast = left;
2187 sb_threads[i].
ifirst = left;
2190 sb_threads[i].
ifirst = 0;
2196 sb_threads[i].
nr = i;
2197 sb_threads[i].
tot = totthread;
2200 if (totthread > 1) {
2203 for (i = 0; i < totthread; i++) {
2213 MEM_delete(sb_threads);
2217 Depsgraph *depsgraph,
Scene *scene,
Object *ob,
float forcetime,
float timenow)
2226 float fieldfactor = -1.0f, windfactor = 0.25;
2227 int do_deflector , do_springcollision, do_aero;
2244 if (do_springcollision || do_aero) {
2284 float dx[3] = {0}, dv[3], aabbmin[3], aabbmax[3], cm[3] = {0.0f, 0.0f, 0.0f};
2285 float timeovermass ;
2286 float maxerrpos = 0.0f, maxerrvel = 0.0f;
2291 aabbmin[0] = aabbmin[1] = aabbmin[2] = 1e20f;
2292 aabbmax[0] = aabbmax[1] = aabbmax[2] = -1e20f;
2298 timeovermass = forcetime / sb->
nodemass;
2301 timeovermass = forcetime / 0.009999f;
2312 timeovermass = forcetime / 0.009999f;
2399 if (bp->
choke > 0.0f) {
2424 *err =
max_ff(maxerrpos, maxerrvel);
2450static void softbody_store_step(
Object *ob)
2452 SoftBody *sb = ob->soft;
2456 for (a = sb->totpoint, bp = sb->bpoint; a > 0; a--, bp++) {
2463static void softbody_store_state(
Object *ob,
float *ppos,
float *pvel)
2468 float *pp = ppos, *pv = pvel;
2470 for (a = sb->totpoint, bp = sb->bpoint; a > 0; a--, bp++) {
2481static void softbody_retrieve_state(
Object *ob,
float *ppos,
float *pvel)
2486 float *pp = ppos, *pv = pvel;
2488 for (a = sb->totpoint, bp = sb->bpoint; a > 0; a--, bp++) {
2499static void softbody_swap_state(
Object *ob,
float *ppos,
float *pvel)
2504 float *pp = ppos, *pv = pvel;
2507 for (a = sb->totpoint, bp = sb->bpoint; a > 0; a--, bp++) {
2559 if ((r > 1.05f) || (r < 0.95f)) {
2560 bs->
len = ((100.0f -
b) * bs->
len +
b *
l) / 100.0f;
2611 if (
mesh->verts_num) {
2613 for (a = 0; a <
mesh->verts_num; a++, bp++) {
2638 int defgroup_index, defgroup_index_mass, defgroup_index_spring;
2641 totedge =
mesh->edges_num;
2656 defgroup_index = dvert ? (sb->
vertgroup - 1) : -1;
2660 for (a = 0; a <
mesh->verts_num; a++, bp++) {
2678 if (defgroup_index_mass != -1) {
2682 if (defgroup_index_spring != -1) {
2730 mesh->vert_positions(),
mesh->faces(),
mesh->corner_verts(), corner_tris);
2736 bodyface->
v1 = corner_verts[corner_tris[a][0]];
2737 bodyface->
v2 = corner_verts[corner_tris[a][1]];
2738 bodyface->
v3 = corner_verts[corner_tris[a][2]];
2749 float accu_pos[3] = {0.0f, 0.0f, 0.0f};
2750 float accu_mass = 0.0f;
2757 for (a = 0; a < sb->
totpoint; a++, rp++, bp++) {
2775 mul_m4_v3(ob->object_to_world().ptr(), p1);
2777 mul_m4_v3(ob->object_to_world().ptr(), p2);
2784 int u,
v,
w, dv, dw, bpc = 0, bpuc;
2787 dw = dv * lt->
pntsv;
2793 for (u = 0, bpuc = 0, bpu =
nullptr; u < lt->
pntsu; u++, bp++, bpc++) {
2822 bs->
v2 = bpc - dw - dv - 1;
2824 bs->
len =
globallen((bp - dw - dv - 1)->vec, bp->vec, ob);
2827 if ((
v < lt->pntsv - 1) && (u != 0)) {
2829 bs->
v2 = bpc - dw + dv - 1;
2831 bs->
len =
globallen((bp - dw + dv - 1)->vec, bp->vec, ob);
2839 bs->
v2 = bpc + dw - dv - 1;
2841 bs->
len =
globallen((bp + dw - dv - 1)->vec, bp->vec, ob);
2844 if ((
v < lt->pntsv - 1) && (u != 0)) {
2846 bs->
v2 = bpc + dw + dv - 1;
2848 bs->
len =
globallen((bp + dw + dv - 1)->vec, bp->vec, ob);
2865 int totvert, totspring = 0, a;
2868 int defgroup_index, defgroup_index_mass, defgroup_index_spring;
2891 for (a = 0; a < totvert; a++, bp++, bpnt++) {
2904 if (defgroup_index_mass != -1) {
2908 if (defgroup_index_spring != -1) {
2932 int a, curindex = 0;
2933 int totvert, totspring = 0, setgoal = 0;
2939 totspring = totvert - cu->
nurb.count();
2969 for (bezt = nu.
bezt, a = 0; a < nu.
pntsu; a++, bezt++, bp += 3, curindex += 3) {
2974 (bp + 1)->goal = bp->
goal;
2975 (bp + 2)->goal = bp->
goal;
2983 bs->
v1 = curindex - 3;
2990 bs->
v2 = curindex + 1;
2995 bs->
v1 = curindex + 1;
2996 bs->
v2 = curindex + 2;
3004 for (bpnt = nu.
bp, a = 0; a < nu.
pntsu * nu.
pntsv; a++, bpnt++, bp++, curindex++) {
3008 if (totspring && a > 0) {
3009 bs->
v1 = curindex - 1;
3040 for (a = 0; a < numVerts; a++, bp++) {
3044 mul_m4_v3(ob->world_to_object().ptr(), vertexCos[a]);
3072 sb = MEM_new<SoftBody>(
"softbody");
3108 sb->
shared = MEM_new<SoftBody_Shared>(
"SoftBody_Shared");
3123 if (sb ==
nullptr) {
3164 for (i = 0; i < sbn->
totpoint; i++) {
3176 sbn->
keys =
nullptr;
3209 return (id_cast<Mesh *>(ob->
data))->edges_num;
3225 float (*vertexCos)[3],
3231 if (!sb || !sb->
bpoint) {
3235 for (a = 0, bp = sb->
bpoint; a < numVerts; a++, bp++) {
3255 float com[3], rcom[3];
3258 if (!ob || !ob->
soft) {
3262 if (!sb || !sb->
bpoint) {
3274 sb->
totpoint, opos,
nullptr, rpos,
nullptr, com, rcom, lrot, lscale);
3296 for (a = 0, bp = sb->
bpoint; a < numVerts; a++, bp++) {
3302 bp->
vec[0] = bp->
vec[1] = bp->
vec[2] = 0.0f;
3365 if (dtime < 0 || dtime > 10.5f) {
3381 float forcetimemax = 1.0f;
3383 float forcetimemin = 0.01f;
3385 float timedone = 0.0;
3392 forcetimemax = dtime / sb->
minloops;
3395 forcetimemin = dtime / sb->
maxloops;
3402 forcetime = forcetimemax;
3403 while ((
fabsf(timedone) <
fabsf(dtime)) && (loops < 2000)) {
3421 if (forcetime > forcetimemin) {
3422 forcetime =
max_ff(forcetime / 2.0f, forcetimemin);
3427 timedone += forcetime;
3431 float newtime = forcetime * 1.1f;
3436 newtime = forcetime;
3441 newtime = forcetime;
3444 timedone += forcetime;
3445 newtime =
min_ff(forcetimemax,
max_ff(newtime, forcetimemin));
3447 if (forcetime > 0.0f) {
3448 forcetime =
min_ff(dtime - timedone, newtime);
3451 forcetime =
max_ff(dtime - timedone, newtime);
3457 if (sct - sst > 0.5) {
3458 printf(
"%3.0f%% \r", 100.0f * timedone / dtime);
3473 printf(
"\r needed %d steps/frame", loops);
3498 if ((sct - sst > 0.5) || (
G.debug &
G_DEBUG)) {
3499 printf(
" solver time %f sec %s\n", sct - sst, ob->
id.
name);
3510 object->soft->last_frame = framenr;
3518 float (*vertexCos)[3],
3524 float dtime, timescale;
3525 int framedelta, framenr, startframe, endframe;
3529 framenr = int(cfra);
3530 framedelta = framenr - cache->
simframe;
3543 if (framenr < startframe) {
3547 framenr = std::min(framenr, endframe);
3550 if (sb->
bpoint ==
nullptr ||
3578 if (framenr == startframe) {
3626 if (can_write_cache) {
3632 if (!can_simulate) {
3645 dtime = framedelta * timescale;
CustomData interface, see also DNA_customdata_types.h.
#define PTCACHE_READ_INTERPOLATED
#define PTCACHE_RESET_OUTDATED
#define PTCACHE_READ_EXACT
Platform independent time functions.
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define MEM_realloc_zeroed(vmemh, len)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
ValueIterator values() const &
ItemIterator items() const &
constexpr IndexRange index_range() const
constexpr bool is_empty() const
IndexRange index_range() const
float distance(float, float) RET
float3x3 scale(float3x3 mat, float2 scale)
void EIG_linear_solver_matrix_add(LinearSolver *solver, int row, int col, double value)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline void copy_v3_v3(ccl_private float *r, const float3 val)
void corner_tris_calc(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< int3 > corner_tris)
MINLINE float min_ff(float a, float b)
static void calculate_collision_balls(Object *ob)
static float sb_grav_force_scale(Object *)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
static void curve_surf_to_softbody(Object *ob)
static void softbody_restore_prev_step(Object *ob)
static void ccd_update_deflector_hash_single(ColliderMeshMap *hash, Object *ob)
static float _final_goal(Object *ob, BodyPoint *bp)
int BKE_scene_num_threads(const Scene *scene)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static const int CCD_SAFETY
static void reference_to_scratch(Object *ob)
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
bool DEG_is_active(const Depsgraph *depsgraph)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void sbFreeSimulation(struct SoftBody *sb)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
static void mesh_to_softbody(Object *ob)
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)
BLI_INLINE void dfdx_spring(float to[3][3], const float dir[3], float length, float L, float k)
int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *pid, int mode)
static void add_mesh_quad_diag_springs(Object *ob)
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 float sb_fric_force_scale(Object *)
static int(*) SB_localInterruptCallBack()
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void BLI_threadpool_insert(ListBaseT< ThreadSlot > *threadbase, void *callerdata)
@ eModifierType_Collision
static void ccd_build_deflector_hash(Depsgraph *depsgraph, Collection *collection, Object *vertexowner, ColliderMeshMap *hash)
static void interpolate_exciter(Object *ob, int timescale, int time)
void BLI_threadpool_end(ListBaseT< ThreadSlot > *threadbase)
static void softbody_update_positions(Object *ob, SoftBody *sb, float(*vertexCos)[3], int numVerts)
static ccd_Mesh * ccd_mesh_make(Object *ob)
void BKE_effectors_apply(ListBaseT< EffectorCache > *effectors, ListBaseT< ColliderCache > *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
static void sb_cf_threads_run(Scene *scene, Object *ob, float forcetime, float timenow, int totpoint, int *ptr_to_break_func(void), ListBaseT< EffectorCache > *effectors, int do_deflector, float fieldfactor, float windfactor)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static int count_mesh_quads(Mesh *mesh)
static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff, 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 softbody_to_object(Object *ob, float(*vertexCos)[3], int numVerts, int local)
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])
void sbObjectStep(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float cfra, float(*vertexCos)[3], int numVerts)
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
MINLINE void mul_v3_fl(float r[3], float f)
static void sb_new_scratch(SoftBody *sb)
int BKE_id_defgroup_name_index(const ID *id, StringRef name)
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)
struct SoftBody * sbNew()
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
static int choose_winner(float *w, float *pos, float *a, float *b, float *c, float *ca, float *cb, float *cc)
void mul_m4_v3(const float M[4][4], float r[3])
static void add_2nd_order_roller(Object *ob, float, int *counter, int addsprings)
SoftBody * sbCopy(struct SoftBody *sb, int flag)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
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])
float BKE_defvert_find_weight(const MDeformVert *dvert, int defgroup)
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 apply_spring_memory(Object *ob)
VecBase< int32_t, 3 > int3
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void softbody_apply_forces(Object *ob, float forcetime, int mode, float *err, int mid_flags)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra)
BMesh const char void * data
static void ccd_mesh_free(ccd_Mesh *ccdm)
void SB_estimate_transform(Object *ob, float lloc[3], float lrot[3][3], float lscale[3][3])
static void ccd_build_deflector_hash_single(ColliderMeshMap *hash, Object *ob)
static void free_softbody_baked(SoftBody *sb)
static void mesh_faces_to_scratch(Object *ob)
static void _scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow, int ifirst, int ilast, ListBaseT< EffectorCache > *effectors)
static void sb_spring_force(Object *ob, int bpi, BodySpring *bs, float iks, float)
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
static void scan_for_ext_face_forces(Object *ob, float timenow)
void sbSetInterruptCallBack(int(*f)())
static void softbody_reset(Object *ob, SoftBody *sb, float(*vertexCos)[3], int numVerts)
static void add_2nd_order_springs(Object *ob, float stiffness)
static void add_bp_springlist(BodyPoint *bp, int springID)
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
MINLINE void zero_v3(float r[3])
static void * exec_scan_for_ext_spring_forces(void *data)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void BKE_ptcache_validate(struct PointCache *cache, int framenr)
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), ListBaseT< EffectorCache > *effectors, int do_deflector, float fieldfactor, float windfactor)
MINLINE float normalize_v3(float n[3])
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
MINLINE void add_v3_v3(float r[3], const float a[3])
static void springs_from_mesh(Object *ob)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
static int sb_deflect_face(Object *ob, float *actpos, float *facenormal, float *force, float *cf, float time, float *vel, float *intrusion)
T * DEG_get_original(T *id)
void BKE_ptcache_free_list(ListBaseT< PointCache > *ptcaches)
void unit_m3(float m[3][3])
static float sb_time_scale(Object *ob)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
struct Object ** BKE_collision_objects_create(struct Depsgraph *depsgraph, struct Object *self, struct Collection *collection, unsigned int *numcollobj, unsigned int modifier_type)
static int query_external_colliders(Depsgraph *depsgraph, Collection *collection)
MINLINE float max_ff(float a, float b)
static void * exec_softbody_calc_forces(void *data)
ListBaseT< EffectorCache > * BKE_effectors_create(struct Depsgraph *depsgraph, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool use_rotation)
static void softbody_calc_forces(Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow)
void sbFree(struct Object *ob)
struct PointCache * BKE_ptcache_add(ListBaseT< PointCache > *ptcaches)
void pd_point_from_soft(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
struct PointCache * BKE_ptcache_copy_list(ListBaseT< PointCache > *ptcaches_new, const ListBaseT< PointCache > *ptcaches_old, int flag)
double BLI_time_now_seconds()
void sbObjectToSoftbody(struct Object *ob)
Map< Object *, struct ccd_Mesh * > ColliderMeshMap
static float _final_mass(Object *ob, BodyPoint *bp)
bool isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3])
static void renew_softbody(Object *ob, int totpoint, int totspring)
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb)
static void sbStoreLastFrame(Depsgraph *depsgraph, Object *object, float framenr)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void ccd_update_deflector_hash(Depsgraph *depsgraph, Collection *collection, Object *vertexowner, ColliderMeshMap *hash)
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void BKE_ptcache_invalidate(struct PointCache *cache)
static int sb_detect_aabb_collisionCached(float[3], Object *vertexowner, float)
void BLI_threadpool_init(ListBaseT< ThreadSlot > *threadbase, void *(*do_thread)(void *), int tot)
static void free_scratch(SoftBody *sb)
void BKE_collision_objects_free(struct Object **objects)
static void build_bps_springlist(Object *ob)
static void softbody_apply_goalsnap(Object *ob)
static bool object_has_edges(const Object *ob)
int BKE_nurbList_verts_count(const ListBaseT< Nurb > *nurb)
static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M)
static float globallen(float *v1, float *v2, Object *ob)
void BKE_effectors_free(ListBaseT< EffectorCache > *lb)
static void free_softbody_intern(SoftBody *sb)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void lattice_to_softbody(Object *ob)
static void softbody_step(Depsgraph *depsgraph, Scene *scene, Object *ob, SoftBody *sb, float dtime)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define SBF_OUTOFCOLLISION
struct MDeformVert * dvert
const c_style_mat & ptr() const
bke::ObjectRuntime * runtime
ColliderMeshMap * colliderhash
short needstobuildcollider
ListBaseT< EffectorCache > * effectors
struct PhysicsSettings physics_settings
ListBaseT< PointCache > ptcaches
struct PointCache * pointcache
struct EffectorWeights * effector_weights
eSoftBody_SolverFlag solverflags
struct SoftBody_Shared * shared
struct Collection * collision_group
struct SBScratch * scratch
struct BodyPoint * bpoint
char namedVG_Spring_K[64]
struct BodySpring * bspring
const float(* vert_positions)[3]
const float(* vert_positions_prev)[3]