[Bf-blender-cvs] [b9903c78c1b] soc-2021-simulation-display: Physics: Added visualisation for rigid body states and a small fix for forces

soumya pochiraju noreply at git.blender.org
Sun Jun 27 16:59:29 CEST 2021


Commit: b9903c78c1bcab424f7faf98737d32888abe97d0
Author: soumya pochiraju
Date:   Sun Jun 27 20:12:46 2021 +0530
Branches: soc-2021-simulation-display
https://developer.blender.org/rBb9903c78c1bcab424f7faf98737d32888abe97d0

Physics: Added visualisation for rigid body states and a small fix for forces

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

M	intern/rigidbody/rb_bullet_api.cpp
M	release/scripts/startup/bl_ui/properties_physics_rigidbody.py
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/draw/engines/overlay/overlay_extra.c
M	source/blender/draw/engines/workbench/workbench_materials.c
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_rigidbody.c

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

diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index d46b18416d3..cf079653678 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -225,10 +225,10 @@ void RB_dworld_get_impulse(rbDynamicsWorld *world,
     const void *obB = contactManifold->getBody1();
     if (num_norm_forces > 2)
       break;
-    if (obA != rbo->body && obB != rbo->body) {
-      continue;
-    }
-    else {
+        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;
@@ -238,13 +238,15 @@ void RB_dworld_get_impulse(rbDynamicsWorld *world,
       for (int j = 0; j < numContacts; j++) {
         /* Find points where impulse was appplied. */
         btManifoldPoint &pt = contactManifold->getContactPoint(j);
-        if (pt.getAppliedImpulse() > 0.f)
+        if (pt.getAppliedImpulse() > 0.f || -pt.getAppliedImpulse() > 0.f) {
           num_impulse_points++;
+          printf("getApplied:%f\n",pt.getAppliedImpulse());
+        }
       }
 
       for (int j = 0; j < numContacts; j++) {
         btManifoldPoint &pt = contactManifold->getContactPoint(j);
-        if (pt.getAppliedImpulse() > 0.f) {
+        if (pt.getAppliedImpulse() > 0.f || -pt.getAppliedImpulse() > 0.f) {
           const btVector3 &loc = pt.getPositionWorldOnB();
           const btVector3 imp = (rbo->body == obB) ?
                                     -pt.m_normalWorldOnB * pt.getAppliedImpulse() / timeSubStep :
diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
index 058fbc5c295..99b71657bea 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
@@ -324,6 +324,7 @@ class PHYSICS_PT_rigid_body_display_options(PHYSICS_PT_rigidbody_panel, Panel):
         col.prop(rbo, "display_acceleration")
         col.prop(rbo, "display_velocity")
         col.prop(rbo, "display_collisions")
+        col.prop(rbo, "display_state")
 
 class PHYSICS_PT_rigid_body_display_force_types(PHYSICS_PT_rigidbody_panel, Panel):
     bl_label = "Forces"
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 80a66de6ddc..0be8137ef2d 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2260,6 +2260,14 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
     const float interp_step = 1.0f / rbw->substeps_per_frame;
     float cur_interp_val = interp_step;
 
+    /* Set all Objects normal forces to zero. */
+    for (int i = 0; i < rbw->numbodies; i++) {
+        Object *ob = rbw->objects[i];
+        zero_v3(ob->rigidbody_object->norm_forces[0].vector);
+        zero_v3(ob->rigidbody_object->norm_forces[1].vector);
+        zero_v3(ob->rigidbody_object->norm_forces[2].vector);
+    }
+
     for (int i = 0; i < rbw->substeps_per_frame; i++) {
       rigidbody_update_kinematic_obj_substep(&substep_targets, cur_interp_val);
       RB_dworld_step_simulation(rbw->shared->physics_world, substep, 0, substep);
@@ -2286,18 +2294,16 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
                                   vec_locations,
                                   norm_flag,
                                   fric_flag);
-            copy_v3_v3(ob->rigidbody_object->vec_locations[0].vector, vec_locations[0]);
-            copy_v3_v3(ob->rigidbody_object->vec_locations[1].vector, vec_locations[1]);
-            copy_v3_v3(ob->rigidbody_object->vec_locations[2].vector, vec_locations[2]);
-            if (norm_flag) {
-              copy_v3_v3(ob->rigidbody_object->norm_forces[0].vector, norm_forces[0]);
-              copy_v3_v3(ob->rigidbody_object->norm_forces[1].vector, norm_forces[1]);
-              copy_v3_v3(ob->rigidbody_object->norm_forces[2].vector, norm_forces[2]);
-            }
-            if (fric_flag) {
-              copy_v3_v3(ob->rigidbody_object->fric_forces[0].vector, fric_forces[0]);
-              copy_v3_v3(ob->rigidbody_object->fric_forces[1].vector, fric_forces[1]);
-              copy_v3_v3(ob->rigidbody_object->fric_forces[2].vector, fric_forces[2]);
+            for(int k=0; k<3; k++){
+              if(len_v3(norm_forces[k])>len_v3(ob->rigidbody_object->norm_forces[k].vector)){
+                copy_v3_v3(ob->rigidbody_object->vec_locations[k].vector, vec_locations[k]);
+                if (norm_flag) {
+                  copy_v3_v3(ob->rigidbody_object->norm_forces[k].vector, norm_forces[k]);
+                }
+                if (fric_flag) {
+                  copy_v3_v3(ob->rigidbody_object->fric_forces[k].vector, fric_forces[k]);
+                }
+              }
             }
           }
         }
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index 4c552a94977..c69118a85c1 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -1819,11 +1819,13 @@ static void OVERLAY_colliding_face_on_box(OVERLAY_Data *data,
                0.00001f)) /* impulse direction must not be parallel to face. */
       {
         face = i;
-        if (fabsf(dot_v3v3(norm, dir)) < 0.0001f) {
+        /*if (fabsf(dot_v3v3(norm, dir)) < 0.0001f) {
           printf("n%f %f %f\n", norm[0], norm[1], norm[2]);
           printf("d%f %f %f\n", dir[0], dir[1], dir[2]);
           printf("%f\n", fabsf(dot_v3v3(norm, dir)));
         }
+        printf("impulse:%f %f %f\n", point[0], point[1],point[2]);
+        printf("intersect:%f %f %f\n", isect_co[0], isect_co[1], isect_co[2]); */
         GPUShader *sh = OVERLAY_shader_collision_box();
         DRWShadingGroup *grp = DRW_shgroup_create(sh, data->psl->extra_ps[1]);
         DRW_shgroup_uniform_vec3_copy(grp, "vert1", box_shape[box_shape_tris[2 * face][0]]);
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
index 800d1085505..e4ceb157405 100644
--- a/source/blender/draw/engines/workbench/workbench_materials.c
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -32,6 +32,7 @@
 
 #include "DNA_mesh_types.h"
 #include "DNA_node_types.h"
+#include "DNA_rigidbody_types.h"
 
 #include "GPU_uniform_buffer.h"
 
@@ -49,7 +50,6 @@ void workbench_material_ubo_data(WORKBENCH_PrivateData *wpd,
   float metallic = 0.0f;
   float roughness = 0.632455532f; /* sqrtf(0.4f); */
   float alpha = wpd->shading.xray_alpha;
-
   switch (color_type) {
     case V3D_SHADING_SINGLE_COLOR:
       copy_v3_v3(data->base_color, wpd->shading.single_color);
@@ -74,7 +74,36 @@ void workbench_material_ubo_data(WORKBENCH_PrivateData *wpd,
     default:
       if (mat) {
         alpha *= mat->a;
-        copy_v3_v3(data->base_color, &mat->r);
+        if(ob && ob->rigidbody_object) {
+            if(ob->rigidbody_object->sim_display_options & RB_SIM_STATE) {
+                float rbo_color_active[4] = {0.8f, 0.8f, 0.8f, 1.0f};
+                float rbo_color_passive[4] = {0.3f, 0.3f, 0.3f, 1.0f};
+                float *rbo_color;
+                if(ob->rigidbody_object->type == RBO_TYPE_ACTIVE){
+                  rbo_color = rbo_color_active;
+                  if(ob->rigidbody_object->flag & RBO_FLAG_KINEMATIC) {
+                      rbo_color[2] += 0.2f;
+                      rbo_color[0] -= 0.1f;
+                      rbo_color[1] -= 0.1f;
+                  }
+                }
+                else if(ob->rigidbody_object->type == RBO_TYPE_PASSIVE){
+                  rbo_color = rbo_color_passive;
+                  if(ob->rigidbody_object->flag & RBO_FLAG_KINEMATIC) {
+                      rbo_color[2] += 0.2f;
+                  }
+                }
+
+                copy_v3_v3(data->base_color, rbo_color);
+
+            }
+            else {
+              copy_v3_v3(data->base_color, &mat->r);
+            }
+        }
+        else {
+          copy_v3_v3(data->base_color, &mat->r);
+        }
         metallic = mat->metallic;
         roughness = sqrtf(mat->roughness); /* Remap to Disney roughness. */
       }
@@ -177,7 +206,6 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd,
       color_type = V3D_SHADING_MATERIAL_COLOR;
     }
   }
-
   switch (color_type) {
     case V3D_SHADING_TEXTURE_COLOR: {
       return workbench_image_setup_ex(wpd, ob, mat_nr, ima, iuser, sampler, datatype);
@@ -200,7 +228,14 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd,
       DRWShadingGroup **grp_mat = NULL;
       /* A hashmap stores material shgroups to pack all similar drawcalls together. */
       if (BLI_ghash_ensure_p(prepass->material_hash, ma, (void ***)&grp_mat)) {
-        return *grp_mat;
+        if(ob){
+            if(!ob->rigidbody_object){
+                return *grp_mat;
+            }
+        }
+        if(!ob){
+          return *grp_mat;
+        }
       }
 
       uint32_t mat_id, id = wpd->material_index++;
@@ -209,12 +244,14 @@ DRWShadingGroup *workbench_material_setup_ex(WORKBENCH_PrivateData *wpd,
       workbench_material_ubo_data(wpd, ob, ma, &wpd->material_ubo_data_curr[mat_id], color_type);
 
       DRWShadingGroup *grp = prepass->common_shgrp;
+
       *grp_mat = grp = DRW_shgroup_create_sub(grp);
       DRW_shgroup_uniform_block(grp, "material_block", wpd->material_ubo_curr);
       DRW_shgroup_uniform_int_copy(grp, "materialIndex", mat_id);
       return grp;
     }
     case V3D_SHADING_VERTEX_COLOR: {
+      printf("b\n");
       const bool transp = wpd->shading.xray_alpha < 1.0f;
       DRWShadingGroup *grp = wpd->prepass[transp][infront][datatype].vcol_shgrp;
       return grp;
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index 0a86a379e5a..da1515fa59b 100644
--- a/source/blender/makesdna/DNA_rigidbod

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list