Commit: 0666ece2e2f96571200d693d9d7bee1ca72d026f
Author: Luca Rood
Date:   Wed Sep 26 17:18:16 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0666ece2e2f96571200d693d9d7bee1ca72d026f

Cloth: Collision improvements

This commit includes several performance, stability, and reliability
improvements to cloth collisions.

Most notably:
* The implementation of a new self-collisions system.
* Multithreading of collision detection.
* Implementation of single sided collisions and normal overrides.
* Replacement of the `plNearestPoints` function from Bullet with a
dedicated solution.

Further, this also includes several bug fixes, and algorithmic
improvements.

Reviewed By: brecht

Differential Revision: http://developer.blender.org/D3712

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

M       release/scripts/startup/bl_ui/properties_physics_cloth.py
M       release/scripts/startup/bl_ui/properties_physics_field.py
M       source/blender/blenkernel/BKE_cloth.h
M       source/blender/blenkernel/BKE_collision.h
M       source/blender/blenkernel/intern/cloth.c
M       source/blender/blenkernel/intern/collision.c
M       source/blender/blenkernel/intern/effect.c
M       source/blender/blenlib/BLI_math_geom.h
M       source/blender/blenlib/intern/math_geom.c
M       source/blender/blenloader/intern/versioning_280.c
M       source/blender/makesdna/DNA_cloth_types.h
M       source/blender/makesdna/DNA_object_force_types.h
M       source/blender/makesrna/intern/rna_cloth.c
M       source/blender/makesrna/intern/rna_object_force.c
M       source/blender/modifiers/intern/MOD_collision.c
M       source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py 
b/release/scripts/startup/bl_ui/properties_physics_cloth.py
index 983e2910bce..ee2415b26d3 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -224,12 +224,33 @@ class PHYSICS_PT_cloth_shape(PhysicButtonsPanel, Panel):
             col.prop_search(cloth, "rest_shape_key", key, "key_blocks", 
text="Rest Shape Key")
 
 
-class PHYSICS_PT_cloth_object_collision(PhysicButtonsPanel, Panel):
-    bl_label = "Object Collision"
+class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
+    bl_label = "Collision"
     bl_parent_id = 'PHYSICS_PT_cloth'
     bl_options = {'DEFAULT_CLOSED'}
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
 
+    def draw(self, context):
+        layout = self.layout
+        layout.use_property_split = True
+
+        cloth = context.cloth.collision_settings
+        md = context.cloth
+        ob = context.object
+
+        layout.active = (cloth.use_collision or cloth.use_self_collision) and 
cloth_panel_enabled(md)
+
+        flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, 
even_rows=False, align=True)
+
+        col = flow.column()
+        col.prop(cloth, "collision_quality", text="Quality")
+
+
+class PHYSICS_PT_cloth_object_collision(PhysicButtonsPanel, Panel):
+    bl_label = "Object Collision"
+    bl_parent_id = 'PHYSICS_PT_cloth_collision'
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
+
     def draw_header(self, context):
         cloth = context.cloth.collision_settings
 
@@ -248,20 +269,18 @@ class 
PHYSICS_PT_cloth_object_collision(PhysicButtonsPanel, Panel):
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, 
even_rows=False, align=True)
 
         col = flow.column()
-        col.prop(cloth, "collision_quality", text="Quality")
         col.prop(cloth, "distance_min", slider=True, text="Distance")
-        col.prop(cloth, "repel_force", slider=True, text="Repel")
 
         col = flow.column()
-        col.prop(cloth, "distance_repel", slider=True, text="Repel Distance")
-        col.prop(cloth, "friction")
+        col.prop(cloth, "impulse_clamp")
+
+        col = flow.column()
         col.prop(cloth, "group")
 
 
 class PHYSICS_PT_cloth_self_collision(PhysicButtonsPanel, Panel):
     bl_label = "Self Collision"
-    bl_parent_id = 'PHYSICS_PT_cloth'
-    bl_options = {'DEFAULT_CLOSED'}
+    bl_parent_id = 'PHYSICS_PT_cloth_collision'
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
 
     def draw_header(self, context):
@@ -283,9 +302,14 @@ class PHYSICS_PT_cloth_self_collision(PhysicButtonsPanel, 
Panel):
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, 
even_rows=False, align=True)
 
         col = flow.column()
-        col.prop(cloth, "self_collision_quality", text="Quality")
+        col.prop(cloth, "self_friction", text="Friction")
+
+        col = flow.column()
         col.prop(cloth, "self_distance_min", slider=True, text="Distance")
 
+        col = flow.column()
+        col.prop(cloth, "self_impulse_clamp")
+
         col = flow.column()
         col.prop_search(cloth, "vertex_group_self_collisions", ob, 
"vertex_groups", text="Vertex Group")
 
@@ -363,6 +387,7 @@ classes = (
     PHYSICS_PT_cloth_damping,
     PHYSICS_PT_cloth_cache,
     PHYSICS_PT_cloth_shape,
+    PHYSICS_PT_cloth_collision,
     PHYSICS_PT_cloth_object_collision,
     PHYSICS_PT_cloth_self_collision,
     PHYSICS_PT_cloth_property_weights,
diff --git a/release/scripts/startup/bl_ui/properties_physics_field.py 
b/release/scripts/startup/bl_ui/properties_physics_field.py
index ad840bbc89f..394f42190c4 100644
--- a/release/scripts/startup/bl_ui/properties_physics_field.py
+++ b/release/scripts/startup/bl_ui/properties_physics_field.py
@@ -377,7 +377,7 @@ class PHYSICS_PT_collision_particle(PhysicButtonsPanel, 
Panel):
 
 
 class PHYSICS_PT_collision_softbody(PhysicButtonsPanel, Panel):
-    bl_label = "Softbody"
+    bl_label = "Softbody And Cloth"
     bl_parent_id = "PHYSICS_PT_collision"
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_OPENGL'}
 
@@ -414,6 +414,15 @@ class PHYSICS_PT_collision_softbody(PhysicButtonsPanel, 
Panel):
         col = flow.column()
         col.prop(settings, "thickness_inner", text="Inner", slider=True)
 
+        col = flow.column()
+        col.prop(settings, "cloth_friction")
+
+        col = flow.column()
+        col.prop(settings, "use_culling")
+
+        col = flow.column()
+        col.prop(settings, "use_normal")
+
 
 classes = (
     PHYSICS_PT_field,
diff --git a/source/blender/blenkernel/BKE_cloth.h 
b/source/blender/blenkernel/BKE_cloth.h
index 423d7014918..d0a08060180 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -117,6 +117,7 @@ typedef struct ClothVertex {
        float   goal;           /* goal, from SB                        */
        float   impulse[3];     /* used in collision.c */
        float   xrest[3];   /* rest position of the vertex */
+       float   dcvel[3];       /* delta velocities to be applied by collision 
response */
        unsigned int impulse_count; /* same as above */
        float   avg_spring_len; /* average length of connected springs */
        float   struct_stiff;
@@ -222,8 +223,7 @@ typedef struct ColliderContacts {
 } ColliderContacts;
 
 // needed for implicit.c
-int cloth_bvh_objcollision (struct Depsgraph *depsgraph, struct Object *ob, 
struct ClothModifierData *clmd, float step, float dt );
-int cloth_points_objcollision(struct Depsgraph *depsgraph, struct Object *ob, 
struct ClothModifierData *clmd, float step, float dt);
+int cloth_bvh_collision(struct Depsgraph *depsgraph, struct Object *ob, struct 
ClothModifierData *clmd, float step, float dt);
 
 void cloth_find_point_contacts(struct Depsgraph *depsgraph, struct Object *ob, 
struct ClothModifierData *clmd, float step, float dt,
                                ColliderContacts **r_collider_contacts, int 
*r_totcolliders);
@@ -244,8 +244,7 @@ void clothModifier_do(struct ClothModifierData *clmd, 
struct Depsgraph *depsgrap
 int cloth_uses_vgroup(struct ClothModifierData *clmd);
 
 // needed for collision.c
-void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving);
-void bvhselftree_update_from_cloth(struct ClothModifierData *clmd, bool 
moving);
+void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving, 
bool self);
 
 // needed for button_object.c
 void cloth_clear_cache(
diff --git a/source/blender/blenkernel/BKE_collision.h 
b/source/blender/blenkernel/BKE_collision.h
index a082b5be804..9bd1f5385da 100644
--- a/source/blender/blenkernel/BKE_collision.h
+++ b/source/blender/blenkernel/BKE_collision.h
@@ -63,6 +63,7 @@ typedef enum {
        COLLISION_USE_COLLFACE =    (1 << 2),
        COLLISION_IS_EDGES =        (1 << 3),
 #endif
+       COLLISION_INACTIVE =        (1 << 4),
 } COLLISION_FLAGS;
 
 
@@ -73,7 +74,7 @@ typedef enum {
 typedef struct CollPair {
        unsigned int face1; // cloth face
        unsigned int face2; // object face
-       double distance; // magnitude of vector
+       float distance;
        float normal[3];
        float vector[3]; // unnormalized collision vector: p2-p1
        float pa[3], pb[3]; // collision point p1 on face1, p2 on face2
diff --git a/source/blender/blenkernel/intern/cloth.c 
b/source/blender/blenkernel/intern/cloth.c
index d8482bf632b..2b246804e28 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -124,8 +124,7 @@ void cloth_init(ClothModifierData *clmd )
        clmd->coll_parms->epsilon = 0.015f;
        clmd->coll_parms->flags = CLOTH_COLLSETTINGS_FLAG_ENABLED;
        clmd->coll_parms->collision_list = NULL;
-       clmd->coll_parms->self_loop_count = 1.0;
-       clmd->coll_parms->selfepsilon = 0.75;
+       clmd->coll_parms->selfepsilon = 0.015;
        clmd->coll_parms->vgroup_selfcol = 0;
 
        /* These defaults are copied from softbody.c's
@@ -153,44 +152,6 @@ void cloth_init(ClothModifierData *clmd )
                clmd->point_cache->step = 1;
 }
 
-static BVHTree *bvhselftree_build_from_cloth (ClothModifierData *clmd, float 
epsilon)
-{
-       unsigned int i;
-       BVHTree *bvhtree;
-       Cloth *cloth;
-       ClothVertex *verts;
-
-       if (!clmd)
-               return NULL;
-
-       cloth = clmd->clothObject;
-
-       if (!cloth)
-               return NULL;
-
-       verts = cloth->verts;
-
-       /* in the moment, return zero if no faces there */
-       if (!cloth->mvert_num)
-               return NULL;
-
-       /* create quadtree with k=26 */
-       bvhtree = BLI_bvhtree_new(cloth->mvert_num, epsilon, 4, 6);
-
-       /* fill tree */
-       for (i = 0; i < cloth->mvert_num; i++, verts++) {
-               const float *co;
-               co = verts->xold;
-
-               BLI_bvhtree_insert(bvhtree, i, co, 1);
-       }
-
-       /* balance tree */
-       BLI_bvhtree_balance(bvhtree);
-
-       return bvhtree;
-}
-
 static BVHTree *bvhtree_build_from_cloth (ClothModifierData *clmd, float 
epsilon)
 {
        unsigned int i;
@@ -234,14 +195,21 @@ static BVHTree *bvhtree_build_from_cloth 
(ClothModifierData *clmd, float epsilon
        return bvhtree;
 }
 
-void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving)
+void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving, bool self)
 {
        unsigned int i = 0;
        Cloth *cloth = clmd->clothObject;
-       BVHTree *bvhtree = cloth->bvhtree;
+       BVHTree *bvhtree;
        ClothVertex *verts = cloth->verts;
        const MVertTri *vt;
 
+       if (self) {
+               bvhtree = cloth->bvhselftree;
+       }
+       else {
+               bvhtree = cloth->bvhtree;
+       }
+
        if (!bvhtree)
                return;
 
@@ -253,12 +221,12 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, 
bool moving)
                        float co[3][3], co_moving[3][3];
                        bool ret;
 
-                       copy_v3_v3(co[0], verts[vt->tri[0]].txold);
-                       copy_v3_v3(co[1], verts[vt->tri[1]].txold);
-                       copy_v3_v3(co[2], verts[vt->tri[2]].txold);
-
                        /* copy new locations into array */
                        if (moving) {
+                               copy_v3_v3(co[0], verts[vt->tri[0]].txold);
+                               copy_v3_v3(co[1], verts[vt->tri[1]].txold);
+                               copy_v3_v3(co[2], verts[vt->tri[2]].txold);
+
                                /* update moving positions */
                                copy_v3_v3(co_moving[0], verts[vt->tri[0]].tx);
                                copy_v3_v3(co_moving[1], verts[vt->tri[1]].tx);
@@ -267,48 +235,11 @@ void bvhtree_update_from_cloth(ClothModifierData *clmd, 
bool moving)
                                ret = BLI_bvhtree_update

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to