Commit: 2b840dfb2de99a34c16facc70a6fbfa25fe8329e
Author: mattoverby
Date:   Wed Aug 19 13:11:28 2020 -0500
Branches: soc-2020-soft-body
https://developer.blender.org/rB2b840dfb2de99a34c16facc70a6fbfa25fe8329e

added loglevel for mesh creation

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

M       extern/softbody/src/admmpd_collision.cpp
M       extern/softbody/src/admmpd_mesh.cpp
M       extern/softbody/src/admmpd_mesh.h
M       extern/softbody/src/admmpd_types.h
M       intern/softbody/admmpd_api.cpp

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

diff --git a/extern/softbody/src/admmpd_collision.cpp 
b/extern/softbody/src/admmpd_collision.cpp
index 78889b810b8..54d3e402e2f 100644
--- a/extern/softbody/src/admmpd_collision.cpp
+++ b/extern/softbody/src/admmpd_collision.cpp
@@ -581,7 +581,7 @@ void EmbeddedMeshCollision::linearize(
        //int nx = x->rows();
        d->reserve((int)d->size() + np);
        trips->reserve((int)trips->size() + np*3*4);
-       double eta = std::max(0.0,options->collision_thickness);
+       double eta = 0;//std::max(0.0,options->collision_thickness);
 
        for (int i=0; i<np; ++i)
        {
diff --git a/extern/softbody/src/admmpd_mesh.cpp 
b/extern/softbody/src/admmpd_mesh.cpp
index 4afa2f5c228..8b9f6158cf6 100644
--- a/extern/softbody/src/admmpd_mesh.cpp
+++ b/extern/softbody/src/admmpd_mesh.cpp
@@ -62,6 +62,7 @@ static void gather_octree_tets(
 } // end gather octree tets
 
 bool EmbeddedMesh::create(
+       const Options *options,
        const float *verts, // size nv*3
        int nv,
        const unsigned int *faces, // size nf*3
@@ -69,6 +70,7 @@ bool EmbeddedMesh::create(
        const unsigned int *tets, // ignored
        int nt)
 {
+       (void)(options);
        P_updated = true;
        if (nv<=0 || verts == nullptr)
                return false;
@@ -153,8 +155,12 @@ bool EmbeddedMesh::create(
        compute_sdf(&emb_V0, &emb_F, &emb_sdf);
        emb_rest_facet_tree.init(emb_leaves);
 
-       compute_lattice();
-       compute_embedding();
+       if (!compute_lattice(options)) {
+               throw_err("create","Failed lattice generation");
+       }
+       if (!compute_embedding(options)) {
+               throw_err("create","Failed embedding calculation");
+       }
 
        // Verify embedding is correct
        for (int i=0; i<nv; ++i)
@@ -212,7 +218,7 @@ void EmbeddedMesh::compute_sdf(
        sdf->addFunction(func, &thread_map, false);
 }
 
-bool EmbeddedMesh::compute_lattice()
+bool EmbeddedMesh::compute_lattice(const admmpd::Options *options)
 {
        // Create subset of faces
 //     if (emb_faces.size()==0) { return false; }
@@ -228,7 +234,7 @@ bool EmbeddedMesh::compute_lattice()
 
        // Create an octree to generate the tets from
        Octree<double,3> octree;
-       octree.init(&emb_V0,&F,options.max_subdiv_levels);
+       octree.init(&emb_V0,&F,options->lattice_subdiv);
 
        std::vector<Vector3d> lat_verts;
        std::vector<RowVector4i> lat_tets;
@@ -258,9 +264,10 @@ bool EmbeddedMesh::compute_lattice()
        return nlt>0;
 }
 
-bool EmbeddedMesh::compute_embedding()
+bool EmbeddedMesh::compute_embedding(const admmpd::Options *options)
 {
        struct FindTetThreadData {
+               const Options *opt;
                AABBTree<double,3> *tree;
                EmbeddedMesh *emb_mesh; // thread sets vtx_to_tet and barys
                MatrixXd *lat_V0;
@@ -269,6 +276,10 @@ bool EmbeddedMesh::compute_embedding()
                VectorXi *emb_v_to_tet;
        };
 
+       if (options->log_level >= LOGLEVEL_DEBUG) {
+               printf("Computing embedding for %d verts\n", 
(int)emb_V0.rows());
+       }
+
        auto parallel_point_in_tet = [](
                void *__restrict userdata,
                const int i,
@@ -278,6 +289,11 @@ bool EmbeddedMesh::compute_embedding()
                FindTetThreadData *td = (FindTetThreadData*)userdata;
                const MatrixXd *emb_x0 = td->emb_mesh->rest_facet_verts();
                Vector3d pt = emb_x0->row(i);
+
+               if (td->opt->log_level >= LOGLEVEL_DEBUG) {
+                       printf("\tTesting vertex %d\n", i);
+               }
+
                PointInTetMeshTraverse<double> traverser(
                                pt,
                                td->lat_V0,
@@ -309,14 +325,15 @@ bool EmbeddedMesh::compute_embedding()
        emb_barys.resize(nv,4);
        emb_barys.setZero();
        emb_v_to_tet.resize(nv);
-       emb_v_to_tet.array() = -1;
+       emb_v_to_tet.setOnes();
+       emb_v_to_tet *= -1;
        int nt = lat_T.rows();
 
        // BVH tree for finding point-in-tet and computing
        // barycoords for each embedded vertex
        std::vector<AlignedBox<double,3> > tet_aabbs;
        tet_aabbs.resize(nt);
-       Vector3d veta = Vector3d::Ones()*1e-12;
+       Vector3d veta = Vector3d::Ones()*1e-4;
        for (int i=0; i<nt; ++i)
        {
                tet_aabbs[i].setEmpty();
@@ -332,6 +349,7 @@ bool EmbeddedMesh::compute_embedding()
        tree.init(tet_aabbs);
 
        FindTetThreadData thread_data = {
+               options,
                &tree,
                this,
                &lat_V0,
@@ -341,6 +359,9 @@ bool EmbeddedMesh::compute_embedding()
        };
        TaskParallelSettings settings;
        BLI_parallel_range_settings_defaults(&settings);
+       if (options->log_level >= LOGLEVEL_DEBUG) {
+               settings.use_threading = false;
+       }
        BLI_task_parallel_range(0, nv, &thread_data, parallel_point_in_tet, 
&settings);
 
        // Double check we set (valid) barycoords for every embedded vertex
@@ -497,6 +518,7 @@ bool EmbeddedMesh::linearize_pins(
 }
 
 bool TetMesh::create(
+       const Options *options,
        const float *verts, // size nv*3
        int nv,
        const unsigned int *faces, // size nf*3 (surface faces)
@@ -664,6 +686,7 @@ bool TetMesh::linearize_pins(
 }
 
 bool TriangleMesh::create(
+       const Options *options,
        const float *verts,
        int nv,
        const unsigned int *faces,
@@ -671,6 +694,7 @@ bool TriangleMesh::create(
        const unsigned int *tets,
        int nt)
 {
+       (void)(options);
        P_updated = true;
        (void)(tets); (void)(nt);
        if (nv<=0 || verts == nullptr)
diff --git a/extern/softbody/src/admmpd_mesh.h 
b/extern/softbody/src/admmpd_mesh.h
index 364355a8a06..d3d948f62ae 100644
--- a/extern/softbody/src/admmpd_mesh.h
+++ b/extern/softbody/src/admmpd_mesh.h
@@ -18,6 +18,7 @@ public:
     // Copy buffers to internal data, 
     // calculates BVH/SDF, etc...
     virtual bool create(
+        const Options *options,
         const float *verts, // size nv*3
         int nv,
         const unsigned int *faces, // size nf*3
@@ -88,10 +89,10 @@ protected:
     SDFType emb_sdf;
     mutable bool P_updated; // set to false on linearize_pins
 
-    bool compute_embedding();
+    bool compute_embedding(const admmpd::Options *options);
 
     // Computes the tet mesh on a subset of faces
-    bool compute_lattice();
+    bool compute_lattice(const admmpd::Options *options);
 
     void compute_sdf(
         const Eigen::MatrixXd *emb_v,
@@ -102,15 +103,8 @@ public:
 
     int type() const { return MESHTYPE_EMBEDDED; }
 
-    struct Options
-    {
-        int max_subdiv_levels;
-        Options() :
-            max_subdiv_levels(3)
-            {}
-    } options;
-
     bool create(
+        const Options *options,
         const float *verts, // size nv*3
         int nv,
         const unsigned int *faces, // size nf*3
@@ -177,6 +171,7 @@ public:
     int type() const { return MESHTYPE_TET; }
 
     bool create(
+        const Options *options,
         const float *verts, // size nv*3
         int nv,
         const unsigned int *faces, // size nf*3 (surface faces)
@@ -237,6 +232,7 @@ public:
     int type() const { return MESHTYPE_TRIANGLE; }
 
     bool create(
+        const Options *options,
         const float *verts, // size nv*3
         int nv,
         const unsigned int *faces, // size nf*3
diff --git a/extern/softbody/src/admmpd_types.h 
b/extern/softbody/src/admmpd_types.h
index 85dbc1f77b3..48640268a99 100644
--- a/extern/softbody/src/admmpd_types.h
+++ b/extern/softbody/src/admmpd_types.h
@@ -57,6 +57,7 @@ typedef Discregrid::CubicLagrangeDiscreteGrid SDFType;
 
 struct Options {
     double timestep_s;
+    int lattice_subdiv; // max subdiv levels for lattice gen
     int log_level;
     int linsolver;
     int max_admm_iters;
@@ -74,12 +75,13 @@ struct Options {
     double poisson; // Poisson ratio // TODO variable per-tet
     double density_kgm3; // density of mesh
     double floor; // floor location
-    double collision_thickness;
+    //double collision_thickness;
     bool self_collision; // process self collisions
     Eigen::Vector2d strain_limit; // min=[-inf,1], max=[1,inf]
     Eigen::Vector3d grav;
     Options() :
         timestep_s(1.0/24.0),
+        lattice_subdiv(3),
         log_level(LOGLEVEL_NONE),
         linsolver(LINSOLVER_PCG),
         max_admm_iters(20),
@@ -97,7 +99,7 @@ struct Options {
         poisson(0.399),
         density_kgm3(1522),
         floor(-std::numeric_limits<double>::max()),
-        collision_thickness(1e-6),
+        //collision_thickness(1e-6),
         self_collision(false),
         strain_limit(0,100),
         grav(0,0,-9.8)
diff --git a/intern/softbody/admmpd_api.cpp b/intern/softbody/admmpd_api.cpp
index 5bc4d1c857f..bfeb0657cc6 100644
--- a/intern/softbody/admmpd_api.cpp
+++ b/intern/softbody/admmpd_api.cpp
@@ -104,6 +104,7 @@ static inline void options_from_object(
   op->linsolver = std::max(0, std::min(LINSOLVER_NUM-1, sb->admmpd_linsolver));
   op->strain_limit[0] = std::min(1.f, sb->admmpd_strainlimit_min);
   op->strain_limit[1] = std::max(1.f, sb->admmpd_strainlimit_max);
+  op->lattice_subdiv = std::max(1,sb->admmpd_embed_res);
 
   if (!skip_require_reset)
   {
@@ -186,10 +187,8 @@ static inline int 
admmpd_init_with_lattice(ADMMPDInterfaceData *iface, Object *o
   std::vector<unsigned int> f;
   vecs_from_object(ob,vertexCos,v,f);
   iface->idata->mesh = std::make_shared<admmpd::EmbeddedMesh>();
-
-  admmpd::EmbeddedMesh* emb_msh = 
static_cast<admmpd::EmbeddedMesh*>(iface->idata->mesh.get());
-  emb_msh->options.max_subdiv_levels = ob->soft->admmpd_embed_res;
   bool success = iface->idata->mesh->create(
+    iface->idata->options.get(),
     v.data(),
     v.size()/3,
     f.data(),
@@ -197,7 +196,7 @@ static inline int 
admmpd_init_with_lattice(ADMMPDInterfaceData *iface, Object *o
     nullptr,
     0);
 
-  if (!success) {
+  if (!success) { // soft unknown fail
     strcpy_error(iface, "EmbeddedMesh failed on creation");
     return 0;
   }
@@ -214,6 +213,7 @@ static inline int admmpd_init_as_cloth(ADMMPDInterfaceData 
*iface, Object *ob, f
 
   iface->idata->mesh = std::make_shared<admmpd::TriangleMesh>();
   bool success = iface->idata->mesh->create(
+    iface->idata->options.get(),
     v.data(),
     v.size()/3,
     f.data(),
@@ -239,8 +239,10 @@ void admmpd_compute_lattice(
 {
 
   admmpd::EmbeddedMesh emesh;
-  emesh.options.max_subdiv_levels = subdiv;
+  admmpd::Options opt;
+  opt.lattice_subdiv = subdiv;
   bool success = emesh.create(
+    &opt,
     in_verts, in_nv,
     in_faces, in_nf,
     nullptr,
@@ -303,9 +305,15 @@ int admmpd_update_mesh(ADMMPDInterfaceData *iface, Object 
*ob, float (*vertexCos
   if (!ob) { return 0; }
   if (!ob->soft) { return 0; }
 
-  if (!iface->idata)
+  if (!iface->idata) {
     iface->idata = 
(ADMMPDInternalData*)MEM_callocN(sizeof(ADMMPDInternalData), "ADMMPD_idata");
+  }
 
+  i

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to