[Bf-blender-cvs] [ea2406f2496] soc-2021-simulation-display: Physics: Added visualisation for the slider constraint.

soumya pochiraju noreply at git.blender.org
Sun Aug 1 16:05:12 CEST 2021


Commit: ea2406f249635ac88b41b3972f4170cd159899c2
Author: soumya pochiraju
Date:   Mon Jul 26 17:27:20 2021 +0530
Branches: soc-2021-simulation-display
https://developer.blender.org/rBea2406f249635ac88b41b3972f4170cd159899c2

Physics: Added visualisation for the slider constraint.

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

M	release/scripts/startup/bl_ui/properties_physics_rigidbody.py
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/draw/engines/overlay/overlay_extra.c
M	source/blender/draw/engines/overlay/overlay_private.h

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
index 99b71657bea..ad0b6d38523 100644
--- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
+++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py
@@ -319,12 +319,13 @@ class PHYSICS_PT_rigid_body_display_options(PHYSICS_PT_rigidbody_panel, Panel):
             rigid_body_warning(layout, "Object does not have a Rigid Body")
             return
 
-        col = layout.column()
-        col.prop(rbo, "display_data_text")
-        col.prop(rbo, "display_acceleration")
-        col.prop(rbo, "display_velocity")
-        col.prop(rbo, "display_collisions")
-        col.prop(rbo, "display_state")
+        if rbo.type == ACTIVE
+          col = layout.column()
+          col.prop(rbo, "display_data_text")
+          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"
@@ -351,7 +352,6 @@ class PHYSICS_PT_rigid_body_display_force_types(PHYSICS_PT_rigidbody_panel, Pane
 
         ob = context.object
         rbo = ob.rigid_body
-
         col = layout.column()
         col.active = rbo.display_forces
         col.prop(rbo, "show_gravity")
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 23911f63b4b..dcc9f9b2f1d 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -781,7 +781,6 @@ static int ptcache_rigidbody_write(int index, void *rb_v, void **data, int UNUSE
 #ifdef WITH_BULLET
       RB_body_get_position(rbo->shared->physics_object, rbo->pos);
       RB_body_get_orientation(rbo->shared->physics_object, rbo->orn);
-      RB_body_get_linear_velocity(rbo->shared->physics_object, rbo->vel);
 #endif
       PTCACHE_DATA_FROM(data, BPHYS_DATA_LOCATION, rbo->pos);
       PTCACHE_DATA_FROM(data, BPHYS_DATA_ROTATION, rbo->orn);
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 5ef22ae659a..fe3230f3d23 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -2437,6 +2437,9 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime
         Object *ob = rbw->objects[j];
         if (ob->rigidbody_object != NULL) {
           rbRigidBody *rbo = (rbRigidBody *)(ob->rigidbody_object->shared->physics_object);
+          /* Get velocity. */
+          RB_body_get_linear_velocity(rbo, ob->rigidbody_object->vel);
+
           bool norm_flag = (ob->rigidbody_object->display_force_types & RB_SIM_NORMAL) ||
                           (ob->rigidbody_object->display_force_types & RB_SIM_NET_FORCE) ||
                           (ob->rigidbody_object->sim_display_options & RB_SIM_COLLISIONS);
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index 31e2631b927..0ee0726899a 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -240,12 +240,6 @@ void OVERLAY_extra_cache_init(OVERLAY_Data *vedata)
       DRW_shgroup_uniform_vec4_copy(grp_sub, "color", G_draw.block.colorLibrary);
       cb->center_deselected_lib = BUF_POINT(grp_sub, format);
     }
-    {
-        sh = OVERLAY_shader_uniform_color();
-        cb->collision_shape = grp = DRW_shgroup_create(sh, extra_ps);
-        DRW_shgroup_uniform_vec4_copy(grp, "color", G_draw.block.colorLibrary);
-
-    }
   }
 }
 
@@ -427,6 +421,7 @@ static void OVERLAY_bounds(OVERLAY_ExtraCallBuffers *cb,
               mat4_to_size(parent_size, ob->parent->obmat);
               float transformed_obmat[4][4];
               copy_m4_m4(transformed_obmat, ob->parent->obmat);
+              /* Remove arent scale factor and add object's scale. */
               for(int i=0; i<3; i++){
                   for(int j=0; j<3; j++){
                       transformed_obmat[i][j] = transformed_obmat[i][j] * (ob_size[j]/parent_size[j]);
@@ -1777,12 +1772,15 @@ static void OVERLAY_velocity_extra(OVERLAY_Data *data, RigidBodyOb *rbo)
 
   int text_flag = rbo->sim_display_options & RB_SIM_TEXT;
 
-  rbRigidBody *rb = (rbRigidBody *)rbo->shared->physics_object;
+ // rbRigidBody *rb = (rbRigidBody *)rbo->shared->physics_object;
   float vel[3] = {0.0f};
-  if (rb != NULL && is_zero_v3(rbo->vel))
-    RB_body_get_linear_velocity(rbo->shared->physics_object, vel);
-  else
+ // if (rb != NULL && is_zero_v3(rbo->vel)) {
+   // RB_body_get_linear_velocity(rbo->shared->physics_object, rbo->vel);
+  //}
+  //else {
     copy_v3_v3(vel, rbo->vel);
+    printf("vel: %f %f %f\n", vel[0], vel[1], vel[2]);
+  //}
   OVERLAY_vector_extra(data, vel, rbo->pos, scale, min_clamp, color, text_flag);
 }
 
@@ -2015,7 +2013,7 @@ static void OVERLAY_indicate_collision(OVERLAY_Data *data, Object *ob)
   copy_v3_v3(dir, ob->rigidbody_object->norm_forces[0].vector);
   normalize_v3(dir);
   if (!is_zero_v3(ob->rigidbody_object->norm_forces[0].vector)) {
-    float color[4] = {0.5, 0.7, 0.1, 1.0};
+    float color[4] = {0.5f, 0.7f, 0.1f, 1.0f};
     switch (ob->rigidbody_object->shape) {
       case RB_SHAPE_BOX:
         OVERLAY_bounds(cb, ob, color, OB_BOUND_BOX, true, mat);
@@ -2046,6 +2044,291 @@ static void OVERLAY_indicate_collision(OVERLAY_Data *data, Object *ob)
   }
 }
 
+static void OVERLAY_linear_limits_single_object_rod(RigidBodyCon *rbc,
+                                             Object *rb_ob,
+                                             Object *constraint_ob,
+                                             int axis,
+                                             OVERLAY_ExtraCallBuffers *cb) {
+    float translation_range;
+    float x_dir_color[4] = {1.0f, 0.0f, 0.0f, 1.0f};
+    float line_start[3] = {0};
+    float line_end[3] = {0};
+
+    switch(axis){
+       case 0:
+        translation_range = (rbc->limit_lin_x_upper - rbc->limit_lin_x_lower);
+        line_start[axis] += rbc->limit_lin_x_lower;
+        line_end[axis] += rbc->limit_lin_x_upper;
+        break;
+       case 1:
+        translation_range = (rbc->limit_lin_y_upper - rbc->limit_lin_y_lower);
+        line_start[axis] += rbc->limit_lin_y_lower;
+        line_end[axis] += rbc->limit_lin_y_upper;
+        break;
+       case 2:
+        translation_range = (rbc->limit_lin_z_upper - rbc->limit_lin_z_lower);
+        line_start[axis] += rbc->limit_lin_z_lower;
+        line_end[axis] += rbc->limit_lin_z_upper;
+        break;
+    }
+    if(fabsf(translation_range)>0.0f){
+        float mat[3][3];
+        mat4_to_rot(mat, constraint_ob->obmat);
+        mul_m3_v3(mat,  line_start);
+        mul_m3_v3(mat, line_end);
+        add_v3_v3(line_start, rb_ob->loc);
+        add_v3_v3(line_end, rb_ob->loc);
+        OVERLAY_extra_line_dashed(cb, line_start, line_end, x_dir_color);
+    }
+}
+
+/* Draw walls for ob1 if it lies close to the walls. */
+static void OVERLAY_linear_limits_walls(RigidBodyCon *rbc,
+                                             Object *ob1,
+                                             Object *ob2,
+                                             Object *constraint_ob,
+                                             int axis,
+                                             OVERLAY_Data *data) {
+    float translation_range;
+    float color[4];
+    copy_v4_v4(color, G_draw.block.colorLibrary);
+    float limit_start[3] = {0.0f};
+    float limit_end[3] = {0.0f};
+    float initial_offset[3];
+    float current_offset[3];
+    float distance_from_first_wall[3];
+    float distance_from_second_wall[3];
+    float *wall_pos;
+
+    sub_v3_v3v3(initial_offset, ob1->loc, ob2->loc);
+    sub_v3_v3v3(current_offset, ob1->rigidbody_object->pos, ob2->rigidbody_object->pos);
+
+    printf("woop");
+
+    /* rotate wall to correct initial orientation */
+    float rot1[3][3] = {{0}};
+    /* Constraint object rotation. */
+    float rot2[3][3] = {{0}};
+    /* Constrained object(ob2) rotation. */
+    float rot3[3][3] = {{0}};
+    /* Constrained object(ob2) initial rotation inverse. */
+    float rot4[3][3] = {{0}};
+
+    /* Get rotation from object matrices. */
+    float size[3];
+    float loc[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, rot4, rot3);
+
+    float ax[3] = {0.0f};
+
+    switch(axis){
+       case 0:
+        translation_range = (rbc->limit_lin_x_upper - rbc->limit_lin_x_lower);
+        limit_start[0] += rbc->limit_lin_x_lower;
+        limit_end[0] += rbc->limit_lin_x_upper;
+        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);
+        limit_start[1] += rbc->limit_lin_y_lower;
+        limit_end[1] += rbc->limit_lin_y_upper;
+        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);
+        limit_start[2] += rbc->limit_lin_z_lower;
+        limit_end[2] += rbc->limit_lin_z_upper;
+        /* Artbitrary axis so that the matrix(rot1) doesn't remain empty. */
+        ax[0] = 1.0f;
+        axis_angle_to_mat3(rot1, ax, 0.0f);
+        break;
+    }
+
+    /* Scale the walls based on the size of ob1. */
+    mat4_to_size(size, ob1->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_m3_v3(rot2, limit_start);
+    mul_m3_v3(rot2, limit_end);
+
+    add_v3_v3(limit_start, initial_offset);
+    add_v3_v3(limit_end, initial_offset);
+    mul_m3_v3

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list