diff options
Diffstat (limited to 'extern/softbody/src')
-rw-r--r-- | extern/softbody/src/admmpd_collision.cpp | 6 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_collision.h | 7 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_linsolve.cpp | 10 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_solver.cpp | 9 | ||||
-rw-r--r-- | extern/softbody/src/admmpd_types.h | 10 |
5 files changed, 24 insertions, 18 deletions
diff --git a/extern/softbody/src/admmpd_collision.cpp b/extern/softbody/src/admmpd_collision.cpp index 9508b74a740..4d2444e6a52 100644 --- a/extern/softbody/src/admmpd_collision.cpp +++ b/extern/softbody/src/admmpd_collision.cpp @@ -219,6 +219,12 @@ int EmbeddedMeshCollision::detect( if (mesh==NULL) return 0; + // Do we even need to process collisions? + if (!this->settings.test_floor && + !this->settings.self_collision && + this->obsdata.F.rows()==0) + return 0; + update_bvh(x0,x1); int max_threads = std::max(1,BLI_system_thread_count()); diff --git a/extern/softbody/src/admmpd_collision.h b/extern/softbody/src/admmpd_collision.h index baf92c28754..efde21db25e 100644 --- a/extern/softbody/src/admmpd_collision.h +++ b/extern/softbody/src/admmpd_collision.h @@ -33,10 +33,11 @@ public: struct Settings { double floor_z; bool test_floor; + bool self_collision; Settings() : - floor_z(-0.5), -// floor_z(-std::numeric_limits<double>::max()), - test_floor(true) + floor_z(-std::numeric_limits<double>::max()), + test_floor(false), + self_collision(false) {} } settings; diff --git a/extern/softbody/src/admmpd_linsolve.cpp b/extern/softbody/src/admmpd_linsolve.cpp index 7d5a29eb964..b91d3041913 100644 --- a/extern/softbody/src/admmpd_linsolve.cpp +++ b/extern/softbody/src/admmpd_linsolve.cpp @@ -77,8 +77,9 @@ void ConjugateGradients::solve( make_n3(data->A, gsdata->A3); } - gsdata->CtC = data->spring_k * data->C.transpose()*data->C; - gsdata->Ctd = data->spring_k * data->C.transpose()*data->d; + double col_k = options->mult_ck * data->A_diag_max; + gsdata->CtC = col_k * data->C.transpose()*data->C; + gsdata->Ctd = col_k * data->C.transpose()*data->d; gsdata->A3_CtC_PtP = gsdata->A3 + gsdata->CtC + data->PtP; VectorXd x3(nx*3); for (int i=0; i<nx; ++i) @@ -319,8 +320,9 @@ void GaussSeidel::init_solve( // Finally, the new global matrix and rhs if (has_constraints) { - data->gsdata.CtC = data->spring_k * data->C.transpose()*data->C; - data->gsdata.Ctd.noalias() = data->spring_k * data->C.transpose()*data->d; + double col_k = options->mult_ck * data->A_diag_max; + data->gsdata.CtC = col_k * data->C.transpose()*data->C; + data->gsdata.Ctd.noalias() = col_k * data->C.transpose()*data->d; data->gsdata.A3_CtC_PtP = data->gsdata.A3 + data->gsdata.CtC; data->gsdata.b3_Ctd_Ptx.resize(nx*3); for (int i=0; i<nx; ++i) diff --git a/extern/softbody/src/admmpd_solver.cpp b/extern/softbody/src/admmpd_solver.cpp index 922f6a58612..f8847a15a9d 100644 --- a/extern/softbody/src/admmpd_solver.cpp +++ b/extern/softbody/src/admmpd_solver.cpp @@ -105,7 +105,6 @@ void Solver::init_solve( BLI_assert(options != NULL); int nx = data->x.rows(); BLI_assert(nx > 0); - BLI_assert(data->pin_sqrt_k.rows()==nx); (void)(collision); if (data->M_xbar.rows() != nx) @@ -141,7 +140,7 @@ void Solver::init_solve( else { // Scale stiffness by A diagonal max - double pin_k_scale = data->A_diag_max; + double pin_k_scale = options->mult_pk * data->A_diag_max; int np = q_coeffs.size(); RowSparseMatrix<double> P(np, nx*3); P.setFromTriplets(trips.begin(), trips.end()); @@ -241,7 +240,6 @@ bool Solver::compute_matrices( int nx = data->x.rows(); BLI_assert(nx > 0); BLI_assert(data->x.cols() == 3); - BLI_assert(data->pin_sqrt_k.rows() == nx); // Allocate per-vertex data data->x_start = data->x; @@ -293,13 +291,12 @@ bool Solver::compute_matrices( data->A_diag_max = data->A.diagonal().maxCoeff(); // Constraint data - data->spring_k = options->mult_k*data->A_diag_max; data->C.resize(1,nx*3); data->d = VectorXd::Zero(1); data->PtP.resize(nx*3,nx*3); - data->pin_sqrt_k.resize(nx); - data->pin_sqrt_k.setZero(); + data->Ptq.resize(nx*3); + data->Ptq.setZero(); // ADMM dual/lagrange data->z.resize(n_row_D,3); diff --git a/extern/softbody/src/admmpd_types.h b/extern/softbody/src/admmpd_types.h index d951687f11c..aa33380d2f7 100644 --- a/extern/softbody/src/admmpd_types.h +++ b/extern/softbody/src/admmpd_types.h @@ -21,7 +21,8 @@ struct Options { int max_cg_iters; int max_gs_iters; double gs_omega; // Gauss-Seidel relaxation - double mult_k; // stiffness multiplier for constraints + double mult_ck; // stiffness multiplier for constraints + double mult_pk; // (global) stiffness multiplier for pins double min_res; // exit tolerance for global step double youngs; // Young's modulus // TODO variable per-tet double poisson; // Poisson ratio // TODO variable per-tet @@ -32,9 +33,10 @@ struct Options { max_cg_iters(10), max_gs_iters(100), gs_omega(1), - mult_k(1), + mult_ck(1), + mult_pk(0.001), min_res(1e-8), - youngs(10000000), + youngs(1000000), poisson(0.399), grav(0,0,-9.8) {} @@ -79,10 +81,8 @@ struct SolverData { double A_diag_max; // Max coeff of diag of A RowSparseMatrix<double> C; // linearized constraints (cols = n x 3) Eigen::VectorXd d; // constraints rhs - double spring_k; // constraint stiffness RowSparseMatrix<double> PtP; // pin_k Pt P Eigen::VectorXd Ptq; // pin_k Pt q - Eigen::VectorXd pin_sqrt_k; // per-vertex pin (goal) sqrt stiffness Eigen::SimplicialLDLT<Eigen::SparseMatrix<double> > ldltA; struct GlobalStepData { // Temporaries used in global step RowSparseMatrix<double> A3; // (M + D'W^2D) n3 x n3 |