[Bf-blender-cvs] [aad804bac0b] soc-2021-simulation-display: Cleanup: fixed some issues with collision display and formatted the code No functional changes

soumya pochiraju noreply at git.blender.org
Tue Jun 22 07:47:57 CEST 2021


Commit: aad804bac0b02a164d7479a238edea43ee16c7af
Author: soumya pochiraju
Date:   Tue Jun 22 11:13:53 2021 +0530
Branches: soc-2021-simulation-display
https://developer.blender.org/rBaad804bac0b02a164d7479a238edea43ee16c7af

Cleanup: fixed some issues with collision display and formatted the code
No functional changes

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

M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp
M	source/blender/blenkernel/intern/dynamicpaint.c
M	source/blender/blenkernel/intern/effect.c
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/blenkernel/intern/softbody.c
M	source/blender/draw/engines/overlay/overlay_extra.c
M	source/blender/draw/engines/overlay/overlay_shader.c
M	source/blender/draw/engines/overlay/shaders/collision_display_box_vert.glsl
M	source/blender/draw/engines/overlay/shaders/collision_display_cylinder_vert.glsl
M	source/blender/draw/engines/overlay/shaders/vector_vert.glsl
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_rigidbody.c
M	source/blender/sequencer/intern/render.c

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

diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index cde25ec8991..59500d1a234 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -22,7 +22,6 @@
  * \brief Rigid Body API for interfacing with external Physics Engines
  */
 
-
 #ifndef __RB_API_H__
 #define __RB_API_H__
 
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 62ea7e302a2..d46b18416d3 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -205,7 +205,8 @@ void RB_dworld_set_split_impulse(rbDynamicsWorld *world, int split_impulse)
 }
 
 /* Get last applied impulse at contact points */
-/* TODO: this may not be the most efficient way to do it. get all forces at once and store in a lookup table. */
+/* TODO: this may not be the most efficient way to do it. get all forces at once and store in a
+ * lookup table. */
 void RB_dworld_get_impulse(rbDynamicsWorld *world,
                            rbRigidBody *rbo,
                            float timeSubStep,
@@ -215,70 +216,71 @@ void RB_dworld_get_impulse(rbDynamicsWorld *world,
                            int norm_flag,
                            int fric_flag)
 {
-    int numManifolds = world->dispatcher->getNumManifolds();
-    int num_norm_forces = 0;
-    int num_fric_forces = 0;
-    for (int i = 0; i < numManifolds; i++)
-    {
-        btPersistentManifold* contactManifold =  world->dispatcher->getManifoldByIndexInternal(i);
-        const void *obA = contactManifold->getBody0();
-        const void *obB = contactManifold->getBody1();
-        if(num_norm_forces>2)
-          break;
-        if(obA != rbo->body && obB != rbo->body)
-        {
-          continue;
-        }
-        else
-        {
-          btVector3 tot_impulse = btVector3(0.0,0.0,0.0);
-          btVector3 final_loc =  btVector3(0.0,0.0,0.0);
-          btScalar tot_impulse_magnitude=0.f;
-          btVector3 tot_lat_impulse = btVector3(0.0,0.0,0.0);
-          int numContacts = contactManifold->getNumContacts();
-          int num_impulse_points = 0;
-          for (int j = 0; j < numContacts; j++)
-          {
-              /* Find points where impulse was appplied. */
-              btManifoldPoint& pt = contactManifold->getContactPoint(j);
-              if (pt.getAppliedImpulse() > 0.f)
-                num_impulse_points++;
-          }
-
-          for (int j = 0; j < numContacts; j++)
-          {
-            btManifoldPoint& pt = contactManifold->getContactPoint(j);
-            if (pt.getAppliedImpulse() > 0.f)
-            {
-                 const btVector3& loc = pt.getPositionWorldOnB();
-                 const btVector3 imp = (rbo->body == obB)? -pt.m_normalWorldOnB * pt.getAppliedImpulse()/timeSubStep:pt.m_normalWorldOnB * pt.getAppliedImpulse()/timeSubStep;
-                 tot_impulse_magnitude += pt.getAppliedImpulse();
-                 tot_impulse += imp;
-                 final_loc += num_impulse_points>1 ? loc * pt.getAppliedImpulse() : loc;
-               if (fric_flag)
-               {
-                   const btVector3 lat_imp1 = (rbo->body == obB)? -pt.m_appliedImpulseLateral1 * pt.m_lateralFrictionDir1/timeSubStep : pt.m_appliedImpulseLateral1 * pt.m_lateralFrictionDir1/timeSubStep;
-                   const btVector3 lat_imp2 = (rbo->body == obB)? -pt.m_appliedImpulseLateral2 * pt.m_lateralFrictionDir2/timeSubStep : pt.m_appliedImpulseLateral2 * pt.m_lateralFrictionDir2/timeSubStep;
-                   tot_lat_impulse += lat_imp1 + lat_imp2;
-               }
-            }
-          }
+  int numManifolds = world->dispatcher->getNumManifolds();
+  int num_norm_forces = 0;
+  int num_fric_forces = 0;
+  for (int i = 0; i < numManifolds; i++) {
+    btPersistentManifold *contactManifold = world->dispatcher->getManifoldByIndexInternal(i);
+    const void *obA = contactManifold->getBody0();
+    const void *obB = contactManifold->getBody1();
+    if (num_norm_forces > 2)
+      break;
+    if (obA != rbo->body && obB != rbo->body) {
+      continue;
+    }
+    else {
+      btVector3 tot_impulse = btVector3(0.0, 0.0, 0.0);
+      btVector3 final_loc = btVector3(0.0, 0.0, 0.0);
+      btScalar tot_impulse_magnitude = 0.f;
+      btVector3 tot_lat_impulse = btVector3(0.0, 0.0, 0.0);
+      int numContacts = contactManifold->getNumContacts();
+      int num_impulse_points = 0;
+      for (int j = 0; j < numContacts; j++) {
+        /* Find points where impulse was appplied. */
+        btManifoldPoint &pt = contactManifold->getContactPoint(j);
+        if (pt.getAppliedImpulse() > 0.f)
+          num_impulse_points++;
+      }
 
-          if(num_impulse_points >1) final_loc = final_loc / tot_impulse_magnitude;
-          copy_v3_btvec3(vec_locations[num_norm_forces],final_loc);
-          if(norm_flag)
-          {
-            copy_v3_btvec3(norm_forces[num_norm_forces],tot_impulse);
-            num_norm_forces++;
-          }
-          if(fric_flag)
-          {
-            copy_v3_btvec3(fric_forces[num_fric_forces], tot_lat_impulse);
-            num_fric_forces++;
+      for (int j = 0; j < numContacts; j++) {
+        btManifoldPoint &pt = contactManifold->getContactPoint(j);
+        if (pt.getAppliedImpulse() > 0.f) {
+          const btVector3 &loc = pt.getPositionWorldOnB();
+          const btVector3 imp = (rbo->body == obB) ?
+                                    -pt.m_normalWorldOnB * pt.getAppliedImpulse() / timeSubStep :
+                                    pt.m_normalWorldOnB * pt.getAppliedImpulse() / timeSubStep;
+          tot_impulse_magnitude += pt.getAppliedImpulse();
+          tot_impulse += imp;
+          final_loc += num_impulse_points > 1 ? loc * pt.getAppliedImpulse() : loc;
+          if (fric_flag) {
+            const btVector3 lat_imp1 = (rbo->body == obB) ?
+                                           -pt.m_appliedImpulseLateral1 *
+                                               pt.m_lateralFrictionDir1 / timeSubStep :
+                                           pt.m_appliedImpulseLateral1 * pt.m_lateralFrictionDir1 /
+                                               timeSubStep;
+            const btVector3 lat_imp2 = (rbo->body == obB) ?
+                                           -pt.m_appliedImpulseLateral2 *
+                                               pt.m_lateralFrictionDir2 / timeSubStep :
+                                           pt.m_appliedImpulseLateral2 * pt.m_lateralFrictionDir2 /
+                                               timeSubStep;
+            tot_lat_impulse += lat_imp1 + lat_imp2;
           }
         }
+      }
 
-     }
+      if (num_impulse_points > 1)
+        final_loc = final_loc / tot_impulse_magnitude;
+      copy_v3_btvec3(vec_locations[num_norm_forces], final_loc);
+      if (norm_flag) {
+        copy_v3_btvec3(norm_forces[num_norm_forces], tot_impulse);
+        num_norm_forces++;
+      }
+      if (fric_flag) {
+        copy_v3_btvec3(fric_forces[num_fric_forces], tot_lat_impulse);
+        num_fric_forces++;
+      }
+    }
+  }
 }
 
 /* Simulation ----------------------- */
@@ -289,23 +291,6 @@ void RB_dworld_step_simulation(rbDynamicsWorld *world,
                                float timeSubStep)
 {
   world->dynamicsWorld->stepSimulation(timeStep, maxSubSteps, timeSubStep);
-  //printf("step\n");
-  int numManifolds = world->dispatcher->getNumManifolds();
-  for (int i = 0; i < numManifolds; i++)
-  {
-      btPersistentManifold* contactManifold =  world->dispatcher->getManifoldByIndexInternal(i);
-      const void *obA = contactManifold->getBody0();
-      const void *obB = contactManifold->getBody1();
-      int numContacts = contactManifold->getNumContacts();
-      for (int j = 0; j < numContacts; j++)
-      {
-        btManifoldPoint& pt = contactManifold->getContactPoint(j);
-        if (pt.getAppliedImpulse() > 0.f)
-        {
-          //printf("%d,%f %f %f\n",j,pt.getPositionWorldOnB().getX(), pt.getPositionWorldOnB().getY(), pt.getPositionWorldOnB().getZ());
-        }
-      }
-  }
 }
 
 /* Export -------------------------- */
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index b8d934bb374..e5d131afcda 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -5108,7 +5108,8 @@ static void dynamic_paint_prepare_effect_cb(void *__restrict userdata,
     EffectedPoint epoint;
     pd_point_from_loc(scene, realCoord[bData->s_pos[index]].v, vel, index, &epoint);
     epoint.vel_to_sec = 1.0f;
-    BKE_effectors_apply(effectors, NULL, surface->effector_weights, &epoint, forc, NULL, NULL,NULL);
+    BKE_effectors_apply(
+        effectors, NULL, surface->effector_weights, &epoint, forc, NULL, NULL, NULL);
   }
 
   /* if global gravity is enabled, add it too */
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index c8bca48ec68..5b69e030814 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -1214,13 +1214,13 @@ void BKE_effectors_apply(ListBase *effectors,
           add_v3_v3v3(impulse, impulse, efd.vel);
         }
 
-        if(eff_forces!=NULL){
-            if(eff->flag & PE_VELOCITY_TO_IMPULSE && impulse){
-              copy_v3_v3(eff_forces[num_eff_forces],impulse);
-            }
-            else{
-              copy_v3_v3(eff_forces[num_eff_forces],force);
-            }
+        if (eff_forces != NULL) {
+          if (eff->flag & PE_VELOCITY_TO_IMPULSE && impulse) {
+            copy_v3_v3(eff_forces[num_eff_forces], impulse);
+          }
+          else {
+            copy_v3_v3(eff_forces[num_eff_forces], force);
+          }
         }
       }
     }
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 7f0e02eb9ee..e16fa6f6c99 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -3195,7 +3195,7 @@ static void update_effectors_task_cb(void *__restrict userdata,
       /* Do effectors. */
       pd_point_from_loc(data->scene, voxel_center, vel, index, &epoint);
       BKE_effec

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list