[Bf-blender-cvs] [244fab58760] soc-2021-simulation-display: Physics: Added visualisation for rigid bodies' velocities.
soumya pochiraju
noreply at git.blender.org
Mon Jun 14 13:21:25 CEST 2021
Commit: 244fab587605c73284de084c7b0c4ec345bbe4a5
Author: soumya pochiraju
Date: Mon Jun 14 15:55:59 2021 +0530
Branches: soc-2021-simulation-display
https://developer.blender.org/rB244fab587605c73284de084c7b0c4ec345bbe4a5
Physics: Added visualisation for rigid bodies' velocities.
===================================================================
M source/blender/blenkernel/intern/effect.c
M source/blender/blenkernel/intern/pointcache.c
M source/blender/blenkernel/intern/rigidbody.c
M source/blender/draw/CMakeLists.txt
M source/blender/draw/engines/overlay/overlay_extra.c
M source/blender/makesdna/DNA_rigidbody_types.h
===================================================================
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 23b978c3b92..c8bca48ec68 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -1215,7 +1215,12 @@ void BKE_effectors_apply(ListBase *effectors,
}
if(eff_forces!=NULL){
- copy_v3_v3(eff_forces[num_eff_forces],force);
+ 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/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 8ba6958f08f..6093bebddf3 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -781,9 +781,11 @@ 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);
+ PTCACHE_DATA_FROM(data, BPHYS_DATA_VELOCITY, rbo->vel);
PTCACHE_DATA_FROM(data, BPHYS_DATA_EFF_FORCES, rbo->eff_forces);
PTCACHE_DATA_FROM(data, BPHYS_DATA_NORM_FORCES, rbo->norm_forces);
PTCACHE_DATA_FROM(data, BPHYS_DATA_FRIC_FORCES, rbo->fric_forces);
@@ -815,6 +817,7 @@ static void ptcache_rigidbody_read(
else {
PTCACHE_DATA_TO(data, BPHYS_DATA_LOCATION, 0, rbo->pos);
PTCACHE_DATA_TO(data, BPHYS_DATA_ROTATION, 0, rbo->orn);
+ PTCACHE_DATA_TO(data, BPHYS_DATA_VELOCITY, 0, rbo->vel);
PTCACHE_DATA_TO(data, BPHYS_DATA_EFF_FORCES, 0 ,rbo->eff_forces);
PTCACHE_DATA_TO(data, BPHYS_DATA_NORM_FORCES, 0 ,rbo->norm_forces);
PTCACHE_DATA_TO(data, BPHYS_DATA_FRIC_FORCES, 0 ,rbo->fric_forces);
@@ -1106,7 +1109,7 @@ void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, Object *ob, RigidBodyWorld *r
pid->write_header = ptcache_basic_header_write;
pid->read_header = ptcache_basic_header_read;
- pid->data_types = (1 << BPHYS_DATA_LOCATION) | (1 << BPHYS_DATA_ROTATION) | (1 << BPHYS_DATA_EFF_FORCES) | (1 << BPHYS_DATA_NORM_FORCES) | (1 << BPHYS_DATA_FRIC_FORCES) | (1 << BPHYS_DATA_VEC_LOCATIONS);
+ pid->data_types = (1 << BPHYS_DATA_LOCATION) | (1 << BPHYS_DATA_ROTATION) | (1 << BPHYS_DATA_VELOCITY) | (1 << BPHYS_DATA_EFF_FORCES) | (1 << BPHYS_DATA_NORM_FORCES) | (1 << BPHYS_DATA_FRIC_FORCES) | (1 << BPHYS_DATA_VEC_LOCATIONS);
pid->info_types = 0;
pid->stack_index = pid->cache->index;
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index 634df6aee35..2b02127265d 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -1299,6 +1299,8 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
zero_v3(rbo->vec_locations[1].vector);
zero_v3(rbo->vec_locations[2].vector);
+ zero_v3(rbo->vel);
+
/* use triangle meshes for passive objects
* use convex hulls for active objects since dynamic triangle meshes are very unstable
*/
@@ -1755,7 +1757,7 @@ static void rigidbody_update_sim_ob(
* which we don't have... */
float eff_forces[3][3] = {{0.0}};
BKE_effectors_apply(effectors, NULL, effector_weights, &epoint, eff_force, NULL, NULL,eff_forces);
- if(rbo->display_force_types & RB_SIM_EFFECTORS) {
+ if(rbo->sim_display_options & RB_SIM_FORCES) {
for(int i=0; i<3; i++){
copy_v3_v3(rbo->eff_forces[i].vector, eff_forces[i]);
}
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 06f650eb8f0..388613dfb80 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -483,6 +483,13 @@ if(WITH_GTESTS)
endif()
endif()
+if(WITH_BULLET)
+ list(APPEND INC
+ ../../../intern/rigidbody
+ )
+ add_definitions(-DWITH_BULLET)
+endif()
+
blender_add_lib(bf_draw "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index f170d144479..4cbfbeccd6c 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -1635,14 +1635,13 @@ static void OVERLAY_forces_extra(OVERLAY_Data *data,
int text_flag = rbo->sim_display_options & RB_SIM_TEXT;
- if(len_v3(net_force)!=0.0f)
+ if(len_v3(net_force)>0.0f)
OVERLAY_vector_extra(data, net_force, rbo->pos, scale, min_clamp, color2, text_flag);
if(rbo->display_force_types & RB_SIM_GRAVITY){
/* Draw the force of gravity. */
- /* Get magnitude of vector to be displayed. */
copy_v3_v3(vector,scene->physics_settings.gravity);
mul_v3_fl(vector, rbo->mass);
OVERLAY_vector_extra(data, vector, rbo->pos, scale, min_clamp, color1,text_flag);
@@ -1652,7 +1651,6 @@ static void OVERLAY_forces_extra(OVERLAY_Data *data,
for(int i=0; i<3; i++){
if(!is_zero_v3(rbo->eff_forces[i].vector)){
- /* Get magnitude of vector to be displayed. */
OVERLAY_vector_extra(data, rbo->eff_forces[i].vector, rbo->pos, scale, min_clamp, color1, text_flag);
}
else
@@ -1664,7 +1662,6 @@ static void OVERLAY_forces_extra(OVERLAY_Data *data,
if(rbo->display_force_types & RB_SIM_NORMAL) {
for(int i=0; i<3; i++){
if(!is_zero_v3(rbo->norm_forces[i].vector)){
- /* Get magnitude of vector to be displayed. */
OVERLAY_vector_extra(data, rbo->norm_forces[i].vector, rbo->vec_locations[i].vector , scale, min_clamp, color1, text_flag);
}
else
@@ -1674,7 +1671,6 @@ static void OVERLAY_forces_extra(OVERLAY_Data *data,
if(rbo->display_force_types & RB_SIM_FRICTION) {
for(int i=0; i<3; i++){
if(!is_zero_v3(rbo->fric_forces[i].vector)){
- /* Get magnitude of vector to be displayed. */
OVERLAY_vector_extra(data, rbo->fric_forces[i].vector, rbo->vec_locations[i].vector , scale, min_clamp, color3, text_flag);
}
}
@@ -1682,7 +1678,7 @@ static void OVERLAY_forces_extra(OVERLAY_Data *data,
}
-/*#ifdef WITH_BULLET
+#ifdef WITH_BULLET
static void OVERLAY_velocity_extra(OVERLAY_Data *data,
RigidBodyOb *rbo)
{
@@ -1694,12 +1690,13 @@ static void OVERLAY_forces_extra(OVERLAY_Data *data,
rbRigidBody *rb = (rbRigidBody*)rbo->shared->physics_object;
float vel[3] = {0.0f};
- //printf("%p\n", rb->body);
- if(rb!=NULL)RB_body_get_linear_velocity(rbo->shared->physics_object, vel);
- printf("vel:%f %f %f\n", vel[0],vel[1], vel[2]);
+ if(rb!=NULL && is_zero_v3(rbo->vel))
+ RB_body_get_linear_velocity(rbo->shared->physics_object, vel);
+ else
+ copy_v3_v3(vel, rbo->vel);
OVERLAY_vector_extra(data, vel, rbo->pos, scale, min_clamp, color, text_flag);
}
-#endif */
+
/*static void OVERLAY_acceleration_extra(OVERLAY_Data *data,
RigidBodyOb *rbo)
{
@@ -1714,6 +1711,7 @@ static void OVERLAY_forces_extra(OVERLAY_Data *data,
RB_body_get_linear_velocity(rb, acc);
OVERLAY_vector_extra(data, acc, rbo->pos, scale, min_clamp, color, text_flag);
} */
+ #endif
void OVERLAY_extra_cache_populate(OVERLAY_Data *vedata, Object *ob)
{
@@ -1781,13 +1779,14 @@ void OVERLAY_extra_cache_populate(OVERLAY_Data *vedata, Object *ob)
}
if (ob->rigidbody_object != NULL) {
OVERLAY_collision(cb, ob, color);
+#ifdef WITH_BULLET
if(ob->rigidbody_object->sim_display_options & RB_SIM_FORCES)
OVERLAY_forces_extra(vedata, scene, ob->rigidbody_object);
- //if(ob->rigidbody_object->sim_display_options & RB_SIM_VELOCITY)
- // OVERLAY_velocity_extra(vedata, ob->rigidbody_object);
+ if(ob->rigidbody_object->sim_display_options & RB_SIM_VELOCITY)
+ OVERLAY_velocity_extra(vedata, ob->rigidbody_object);
//if(ob->rigidbody_object->sim_display_options & RB_SIM_ACCELERATION)
// OVERLAY_acceleration_extra(vedata, ob->rigidbody_object);
-
+#endif
}
if (ob->dtx & OB_AXIS) {
DRW_buffer_add_entry(cb->empty_axes, color, ob->obmat);
diff --git a/source/blender/makesdna/DNA_rigidbody_types.h b/source/blender/makesdna/DNA_rigidbody_types.h
index 89c72968622..fecf3fd8369 100644
--- a/source/blender/makesdna/DNA_rigidbody_types.h
+++ b/source/blender/makesdna/DNA_rigidbody_types.h
@@ -182,7 +182,9 @@ typedef struct RigidBodyOb {
sim_data_vec fric_forces[3];
char _pad5[4];
sim_data_vec vec_locations[3];
- char _pad6[4];
+
+ /* Velocity, to display sim data */
+ float vel[3];
} RigidBodyOb;
More information about the Bf-blender-cvs
mailing list