[Bf-blender-cvs] [5f6dc2fd50e] soc-2020-soft-body: fixed bug when switching mesh types

mattoverby noreply at git.blender.org
Fri Aug 21 16:09:49 CEST 2020


Commit: 5f6dc2fd50ec1fe1abddcc4e16ba4c79e24b135c
Author: mattoverby
Date:   Fri Aug 21 09:09:43 2020 -0500
Branches: soc-2020-soft-body
https://developer.blender.org/rB5f6dc2fd50ec1fe1abddcc4e16ba4c79e24b135c

fixed bug when switching mesh types

===================================================================

M	extern/softbody/src/admmpd_collision.cpp
M	extern/softbody/src/admmpd_collision.h
M	intern/softbody/admmpd_api.cpp
M	source/blender/blenkernel/intern/softbody.c

===================================================================

diff --git a/extern/softbody/src/admmpd_collision.cpp b/extern/softbody/src/admmpd_collision.cpp
index 09af127a6c2..3aa912520ae 100644
--- a/extern/softbody/src/admmpd_collision.cpp
+++ b/extern/softbody/src/admmpd_collision.cpp
@@ -26,20 +26,6 @@ VFCollisionPair::VFCollisionPair() :
 	q_bary(0,0,0)
 	{}
 
-bool Collision::ObstacleData::has_obs() const
-{
-	// The obstacle list may include non-closed obstacles,
-	// in which an SDF cannot be computed. This function
-	// instead returns true only if an SDF can be generated.
-	int n_box = box.size();
-	for (int i=0; i<n_box; ++i) {
-		if (!box[i].isEmpty()) {
-			return true;
-		}
-	}
-	return false;
-}
-
 bool Collision::ObstacleData::compute_sdf(int idx)
 {
 	if (idx < 0 || idx >x1.size()) {
@@ -196,11 +182,13 @@ int EmbeddedMeshCollision::detect(
 	const Eigen::MatrixXd *x0,
 	const Eigen::MatrixXd *x1)
 {
-	if (!mesh)
+	if (!mesh) {
 		return 0;
+	}
 
-	if (mesh->type() != MESHTYPE_EMBEDDED)
+	if (mesh->type() != MESHTYPE_EMBEDDED) {
 		return 0;
+	}
 
 	// Compute SDFs if the mesh is intersecting
 	// the associated obstacle. The sdf generation is internally threaded,
@@ -221,10 +209,8 @@ int EmbeddedMeshCollision::detect(
 
 	// Do we even need to process collisions and launch
 	// the per-vertex threads?
-	if (!has_obs_intersection && !options->self_collision)
-	{
-		if (x1->col(2).minCoeff() > options->floor)
-		{
+	if (!has_obs_intersection && !options->self_collision) {
+		if (x1->col(2).minCoeff() > options->floor) {
 			return 0;
 		}
 	}
@@ -396,8 +382,12 @@ int EmbeddedMeshCollision::detect(
 	// Launch threads
 	std::vector<std::thread> pool;
 	per_thread_results.resize(max_threads, std::vector<Vector2i>());
-	for (int i=0; i<max_threads; ++i)
+	for (int i=0; i<max_threads; ++i) {
+		per_thread_results[i].reserve(std::max(1,nev/max_threads));
+	}
+	for (int i=0; i<max_threads; ++i) {
 		pool.emplace_back(per_thread_function,&thread_data,i);
+	}
 
 	// Combine parallel results
 	vf_pairs.clear();
diff --git a/extern/softbody/src/admmpd_collision.h b/extern/softbody/src/admmpd_collision.h
index 4869b2b7268..3c9a0a329a5 100644
--- a/extern/softbody/src/admmpd_collision.h
+++ b/extern/softbody/src/admmpd_collision.h
@@ -24,7 +24,6 @@ class Collision {
 public:
     struct ObstacleData {
         int num_obs() const { return sdf.size(); }
-        bool has_obs() const;
         bool compute_sdf(int idx);
         std::vector<SDFType> sdf;
         // Obstacle data stored in custom matrix type to interop with DiscreGrid
diff --git a/intern/softbody/admmpd_api.cpp b/intern/softbody/admmpd_api.cpp
index 3c808546e8b..671ecf44bf1 100644
--- a/intern/softbody/admmpd_api.cpp
+++ b/intern/softbody/admmpd_api.cpp
@@ -278,6 +278,7 @@ int admmpd_mesh_needs_update(ADMMPDInterfaceData *iface, Object *ob)
   // Mode or topology change?
   int mode = ob->soft->admmpd_mesh_mode;
   int mesh_type = iface->idata->mesh->type();
+
   if (mode != mesh_type) { return 1; }
   if (!iface->idata->mesh->rest_facet_verts()) { return 1; }
   int nx = iface->idata->mesh->rest_facet_verts()->rows();
@@ -461,11 +462,18 @@ void admmpd_copy_to_object(ADMMPDInterfaceData *iface, Object *ob, float (*verte
 
   if (ob && ob->soft) {
     SoftBody *sb = ob->soft;
+
     if (!sb->bpoint) {
       if (!ob->soft->bpoint) {
         sb->bpoint = (BodyPoint*)MEM_callocN(nx*sizeof(BodyPoint), "ADMMPD_bpoint");
       }
+      sb->totpoint = nx;
+      sb->totspring = 0;
+    }
 
+    if (sb->totpoint != nx && sb->totpoint>0) {
+      MEM_freeN(sb->bpoint);
+      sb->bpoint = (BodyPoint*)MEM_callocN(nx*sizeof(BodyPoint), "ADMMPD_bpoint");
       sb->totpoint = nx;
       sb->totspring = 0;
     }
@@ -497,67 +505,7 @@ void admmpd_copy_to_object(ADMMPDInterfaceData *iface, Object *ob, float (*verte
     }
   }
 }
-/*
-void admmpd_update_obstacles(
-    ADMMPDInterfaceData *iface,
-    float *in_verts_0,
-    float *in_verts_1,
-    int nv,
-    unsigned int *in_faces,
-    int nf)
-{
-  if (iface==NULL || in_verts_0==NULL || in_verts_1==NULL || in_faces==NULL) {
-    return;
-  }
-  if (!iface->idata) { return; }
-
-  if (nf==0 || nv==0) { return; }
-  int nv3 = nv*3;
-  int nf3 = nf*3;
-  iface->idata->obs.needs_sdf_recompute = false;
-
-  if (iface->idata->obs.x0.size()!=nv3) {
-    iface->idata->obs.x0.resize(nv3);
-    iface->idata->obs.needs_sdf_recompute = true;
-  }
-
-  if (iface->idata->obs.x1.size()!=nv3) {
-    iface->idata->obs.x1.resize(nv3);
-    iface->idata->obs.needs_sdf_recompute = true;
-  }
 
-  if (iface->idata->obs.F.size()!=nf3) {
-    iface->idata->obs.F.resize(nf3);
-    iface->idata->obs.needs_sdf_recompute = true;
-  }
-
-  for (int i=0; i<nv3; ++i) {
-
-    // Change in x?
-    if (!iface->idata->obs.needs_sdf_recompute) {
-      if (std::abs(iface->idata->obs.x0[i]-in_verts_0[i])>1e-8 ||
-          std::abs(iface->idata->obs.x1[i]-in_verts_1[i])>1e-8 ) {
-        iface->idata->obs.needs_sdf_recompute = true;
-      }
-    }
-
-    iface->idata->obs.x0[i] = in_verts_0[i];
-    iface->idata->obs.x1[i] = in_verts_1[i];
-  }
-  for (int i=0; i<nf3; ++i) {
-
-    // Change in f?
-    if (!iface->idata->obs.needs_sdf_recompute) {
-      if (iface->idata->obs.F[i] != in_faces[i]) {
-        iface->idata->obs.needs_sdf_recompute = true;
-      }
-    }
-
-    iface->idata->obs.F[i] = in_faces[i];
-  }
-
-}
-*/
 static inline void admmpd_update_goals(ADMMPDInterfaceData *iface, Object *ob, float (*vertexCos)[3])
 {
   if (!iface) { return; }
@@ -690,7 +638,7 @@ int admmpd_solve(ADMMPDInterfaceData *iface, Object *ob, float (*vertexCos)[3])
 
   int substeps = std::max(1,iface->idata->options->substeps);
   int n_obs = iface->idata->obs_x0.size();
-  if (substeps == 1) { // no lerp necessary
+  if (has_obstacles && substeps == 1) { // no lerp necessary
     std::string set_obs_error = "";
     if (!iface->idata->collision->set_obstacles(
         iface->idata->obs_x0, iface->idata->obs_x1, iface->idata->obs_F,
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index d73a4b08c07..678e1fd225c 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -3836,6 +3836,9 @@ void sbObjectStep(struct Depsgraph *depsgraph,
 
     if (init_mesh || init_solver) {
       BKE_ptcache_invalidate(cache);
+      //BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+      //return;
+      //admmpd_copy_from_object(admmpd, ob);
     }
   }
   else if (sb->solver_mode == SOLVER_MODE_LEGACY) {



More information about the Bf-blender-cvs mailing list