[Bf-blender-cvs] [ea208f067fe] soc-2021-simulation-display: Cleanup: Constraint linear limits visualisation

soumya pochiraju noreply at git.blender.org
Sun Aug 15 13:34:11 CEST 2021


Commit: ea208f067feb124fa1197b931ba1aa58439d5a09
Author: soumya pochiraju
Date:   Sun Aug 15 00:06:02 2021 +0530
Branches: soc-2021-simulation-display
https://developer.blender.org/rBea208f067feb124fa1197b931ba1aa58439d5a09

Cleanup: Constraint linear limits visualisation

-created option to enable/disable fading of walls
-simplified variable names and transform matrices

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

M	release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py
M	source/blender/draw/engines/overlay/overlay_extra.c
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_rigidbody.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py
index cfce8da6543..c48b7d7280d 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody_constraint.py
@@ -499,6 +499,10 @@ class PHYSICS_PT_rigid_body_constraint_debug_draw(PHYSICS_PT_rigidbody_constrain
         col = flow.column()
         col.prop(rbc, "debug_draw_limits", text="Debug draw")
 
+        if rbc.type in {'PISTON', 'SLIDER'}:
+            col = flow.column()
+            col.prop(rbc, "debug_draw_fade_walls", text="Fade walls")
+
 classes = (
     PHYSICS_PT_rigid_body_constraint,
     PHYSICS_PT_rigid_body_constraint_settings,
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index a6aba422013..92ff7609c06 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -2089,91 +2089,70 @@ static void OVERLAY_linear_limits_single_object_rod(RigidBodyCon *rbc,
 }
 
 /* Draw walls for ob1 if it lies close to the walls. */
-static void OVERLAY_linear_limits_walls (RigidBodyCon *rbc,
-                                         Object *ob1,
-                                         Object *ob2,
-                                        float upper_wall_pos[3],
-                                        float lower_wall_pos[3],
-                                        Object *constraint_ob,
-                                        int axis,
-                                        OVERLAY_Data *data) {
-    float translation_range;
+static void OVERLAY_linear_limits_walls(Object *ob,
+                                         const float transform_mat[3][3],
+                                         const float corr_rot[3][3],
+                                         float upper_wall_pos[3],
+                                         float lower_wall_pos[3],
+                                         const float translation_range,
+                                         OVERLAY_Data *data,
+                                         bool fade_walls) {
+
     float color[4];
     copy_v4_v4(color, G_draw.block.colorLibrary);
 
     float distance_from_first_wall[3];
     float distance_from_second_wall[3];
     float *wall_pos;
-
-    /* Rotate wall to correct initial orientation */
-    float rot1[3][3] = {{0}};
-    /* Constraint object transform. */
-    float rot2[3][3] = {{0}};
-    /* Constrained object(ob2) transform. */
-    float rot3[3][3] = {{0}};
-    /* Constrained object(ob2) initial transform inverse. */
-    float rot4[3][3] = {{0}};
-
-    /* Get rotation from object matrices. */
     float size[3];
 
-    BKE_object_rot_to_mat3(constraint_ob, rot2, false);
-    mat4_to_rot(rot3, ob2->obmat);
-    /* Rigid body transforms are not stored in ob->rot.
-     * So this is the rotation at the start of the simulation. */
-    BKE_object_rot_to_mat3(ob2, rot4, false);
-    invert_m3(rot4);
-    /* Remove initial rotation of ob2. */
-    mul_m3_m3m3(rot3, rot3, rot4);
+    sub_v3_v3v3(distance_from_first_wall, ob->rigidbody_object->pos, upper_wall_pos);
+    sub_v3_v3v3(distance_from_second_wall, ob->rigidbody_object->pos, lower_wall_pos);
 
-    float ax[3] = {0.0f};
+    float d1 = fabsf(len_v3(distance_from_first_wall));
+    float d2 = fabsf(len_v3(distance_from_second_wall));
 
-    switch(axis){
-       case 0:
-        translation_range = (rbc->limit_lin_x_upper - rbc->limit_lin_x_lower);
-        ax[1] = 1.0f;
-        axis_angle_to_mat3(rot1, ax, M_PI_2);
-        break;
-       case 1:
-        translation_range = (rbc->limit_lin_y_upper - rbc->limit_lin_y_lower);
-        ax[0] = 1.0f;
-        axis_angle_to_mat3(rot1, ax, M_PI_2);
-        break;
-       case 2:
-        translation_range = (rbc->limit_lin_z_upper - rbc->limit_lin_z_lower);
-        /* Artbitrary axis so that the matrix(rot1) doesn't remain empty. */
-        ax[0] = 1.0f;
-        axis_angle_to_mat3(rot1, ax, 0.0f);
-        break;
-    }
+    float draw_range = translation_range < 12.0f ? (translation_range/2.0f)*0.5f : 3.0f;
+
+    bool draw_upper_wall = (d1 <= draw_range) || !fade_walls;
+    bool draw_lower_wall = (d2 <= draw_range) || !fade_walls;
 
+    float final_mat[4][4] = {{0.0f}};
+    copy_m4_m3(final_mat, transform_mat);
+    mul_m4_m4m3(final_mat, final_mat, corr_rot);
     /* Scale the walls based on the size of ob1. */
-    mat4_to_size(size, ob1->obmat);
+    mat4_to_size(size, ob->obmat);
     mul_v3_fl(size, 1.5f);
-    mul_v3_fl(rot1[0], size[0]);
-    mul_v3_fl(rot1[1], size[1]);
-    mul_v3_fl(rot1[2], size[2]);
+    mul_v3_fl(final_mat[0], size[0]);
+    mul_v3_fl(final_mat[1], size[1]);
+    mul_v3_fl(final_mat[2], size[2]);
 
-    sub_v3_v3v3(distance_from_first_wall, ob1->rigidbody_object->pos, upper_wall_pos);
-    sub_v3_v3v3(distance_from_second_wall, ob1->rigidbody_object->pos, lower_wall_pos);
-
-    float d1 = fabsf(len_v3(distance_from_first_wall));
-    float d2 = fabsf(len_v3(distance_from_second_wall));
+     if(fabsf(translation_range)>0.0f && draw_upper_wall) {
+         wall_pos = upper_wall_pos ;
+         float distance = d1;
+         if(fade_walls) {
+             mul_v4_fl(color, (draw_range - distance)/draw_range);
+         }
 
-    float draw_range = translation_range < 12.0f ? (translation_range/2.0f)*0.5f : 3.0f;
+         GPUBatch *geom = DRW_cache_quad_get();
 
-    bool draw_wall = (d1 <= draw_range) || (d2 <= draw_range);
+         copy_v3_v3(final_mat[3], wall_pos);
+         final_mat[3][3] = 1.0f;
 
-     if(fabsf(translation_range)>0.0f && draw_wall) {
-         wall_pos = (d1 <= draw_range) ? upper_wall_pos : lower_wall_pos;
-         float distance = (d1 <= draw_range) ? d1 : d2;
-         mul_v4_fl(color, (draw_range - distance)/draw_range);
+         GPUShader *sh = OVERLAY_shader_uniform_color();
+         DRWShadingGroup *grp = DRW_shgroup_create(sh, data->psl->extra_ps[0]);
+         DRW_shgroup_uniform_vec4_copy(grp, "color", color);
+         DRW_shgroup_call_obmat(grp, geom, final_mat);
+     }
+     if(fabsf(translation_range)>0.0f && draw_lower_wall) {
+         wall_pos = lower_wall_pos ;
+         float distance = d2;
+         if(fade_walls) {
+             mul_v4_fl(color, (draw_range - distance)/draw_range);
+         }
 
          GPUBatch *geom = DRW_cache_quad_get();
-         float final_mat[4][4] = {{0.0f}};
-         copy_m4_m3(final_mat, rot1);
-         mul_m4_m3m4(final_mat, rot2, final_mat);
-         mul_m4_m3m4(final_mat, rot3, final_mat);
+
          copy_v3_v3(final_mat[3], wall_pos);
          final_mat[3][3] = 1.0f;
 
@@ -2184,7 +2163,7 @@ static void OVERLAY_linear_limits_walls (RigidBodyCon *rbc,
      }
 }
 
-static void OVERLAY_linear_limits_rod(RigidBodyCon *rbc,
+static void OVERLAY_linear_limits(RigidBodyCon *rbc,
                                              Object *ob1,
                                              Object *ob2,
                                              Object *constraint_ob,
@@ -2199,93 +2178,148 @@ static void OVERLAY_linear_limits_rod(RigidBodyCon *rbc,
     float initial_distance_vec[3];
     float line_start[3] = {0.0f};
     float line_end[3] = {0.0f};
+    float ob1_upper_limit[3] = {0.0f};
+    float ob2_upper_limit[3] = {0.0f};
     float ob1_lower_limit_mark[3] = {0.0f};
     float ob2_lower_limit_mark[3] = {0.0f};
     float ob1_projection[3] = {0.0f};
     float ob2_projection[3] = {0.0f};
+
     sub_v3_v3v3(initial_distance_vec, ob1->loc, ob2->loc);
     sub_v3_v3v3(distance_vec, ob1->rigidbody_object->pos, ob2->rigidbody_object->pos);
     float constrained_axis[3] = {0.0f};
     constrained_axis[axis] = 1.0f;
+
+    /* Correct initial orientation of walls. */
+    float corr_rot[3][3];
     /* Constraint ob rotation. */
-    float rot1[3][3] = {{0.0f}};
+    float constraint_ob_rot[3][3] = {{0.0f}};
     /* Ob1 rotation. */
-    float rot2[3][3] = {{0.0f}};
+    float ob1_rot[3][3] = {{0.0f}};
     /* Ob1 initial rotation inverse. */
-    float rot3[3][3] = {{0.0f}};
-    BKE_object_rot_to_mat3(constraint_ob, rot1, false);
-    mat4_to_rot(rot2, ob1->obmat);
-    BKE_object_rot_to_mat3(ob1, rot3, false);
-    invert_m3(rot3);
-    mul_m3_m3m3(rot2, rot2, rot3);
+    float ob1_rot_initial_inv[3][3] = {{0.0f}};
+    /* Ob1 final transform matrix. */
+    float transform_mat1[3][3] = {{0.0f}};
+    /* Ob2 rotation. */
+    float ob2_rot[3][3] = {{0.0f}};
+    /* Ob2 initial rotation inverse. */
+    float ob2_rot_initial_inv[3][3] = {{0.0f}};
+    /* Ob2 final transform matrix. */
+    float transform_mat2[3][3] = {{0.0f}};
+
+    BKE_object_rot_to_mat3(constraint_ob, constraint_ob_rot, false);
+
+    mat4_to_rot(ob1_rot, ob1->obmat);
+    BKE_object_rot_to_mat3(ob1, ob1_rot_initial_inv, false);
+    invert_m3(ob1_rot_initial_inv);
+    mul_m3_m3m3(transform_mat1, ob1_rot, ob1_rot_initial_inv);
+    mul_m3_m3m3(transform_mat1, transform_mat1, constraint_ob_rot);
+
+    mat4_to_rot(ob2_rot, ob2->obmat);
+    BKE_object_rot_to_mat3(ob2, ob2_rot_initial_inv, false);
+    invert_m3(ob2_rot_initial_inv);
+    mul_m3_m3m3(transform_mat2, ob2_rot, ob2_rot_initial_inv);
+    mul_m3_m3m3(transform_mat2, transform_mat2, constraint_ob_rot);
 
     float cross_product[3];
     cross_v3_v3v3(cross_product, distance_vec, constrained_axis);
-    mul_m3_v3(rot1, constrained_axis);
+    mul_m3_v3(constraint_ob_rot, constrained_axis);
     normalize_v3(constrained_axis);
 
     bool draw_rod = rbc->type == RBC_TYPE_SLIDER;
 
+    float translation_range;
+    /* Axis that lies along the plane perpendicular to constrained axis. */
+    float ax[3] = {0.0f};
 
+    switch(axis){
+       case 0:
+        translation_range = (rbc->limit_lin_x_upper - rbc->limit_lin_x_lower);
+        ob2_upper_limit[0] += (rbc->limit_lin_x_upper*0.5f);
+        ob2_lower_limit_mark[0] += (rbc->limit_lin_x_lower*0.5f);
+        ob1_upper_limit[0] -= (rbc->limit_lin_x_upper*0.5f);
+        ob1_lower_limit_mark[0] -= (rbc->limit_lin_x_lower*0.5f);
+        ax[1] = 1.0f;
+        axis_ang

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list