Commit: 63c8bf807d92f4d5f805f418a5b2999a618245d8 Author: soumya pochiraju Date: Thu Jun 10 21:43:09 2021 +0530 Branches: soc-2021-simulation-display https://developer.blender.org/rB63c8bf807d92f4d5f805f418a5b2999a618245d8
Pysics: Added visualisation for forces due to effectors, normal forces and gravity. =================================================================== M intern/rigidbody/RBI_api.h M intern/rigidbody/rb_bullet_api.cpp M release/scripts/startup/bl_ui/properties_physics_rigidbody.py M source/blender/blenkernel/BKE_effect.h M source/blender/blenkernel/BKE_pointcache.h M source/blender/blenkernel/intern/boids.c 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/particle.c M source/blender/blenkernel/intern/particle_system.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/shaders/vector_vert.glsl M source/blender/makesdna/DNA_pointcache_types.h M source/blender/makesdna/DNA_rigidbody_types.h M source/blender/makesrna/intern/rna_rigidbody.c M source/blender/simulation/intern/SIM_mass_spring.cpp =================================================================== diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h index 2e09f8952cb..81c7c442706 100644 --- a/intern/rigidbody/RBI_api.h +++ b/intern/rigidbody/RBI_api.h @@ -22,6 +22,7 @@ * \brief Rigid Body API for interfacing with external Physics Engines */ + #ifndef __RB_API_H__ #define __RB_API_H__ @@ -81,6 +82,13 @@ void RB_dworld_set_solver_iterations(rbDynamicsWorld *world, int num_solver_iter /* Split Impulse */ void RB_dworld_set_split_impulse(rbDynamicsWorld *world, int split_impulse); +/* Get latest applied impulse */ +void RB_dworld_get_impulse(rbDynamicsWorld *world, + rbRigidBody *rbo, + float timeSubStep, + float norm_forces[3][3], + float vec_locations[3][3]); + /* Simulation ----------------------- */ /* Step the simulation by the desired amount (in seconds) with extra controls on substep sizes and diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp index d932a9ca951..639c4a13c79 100644 --- a/intern/rigidbody/rb_bullet_api.cpp +++ b/intern/rigidbody/rb_bullet_api.cpp @@ -204,6 +204,65 @@ void RB_dworld_set_split_impulse(rbDynamicsWorld *world, int split_impulse) info.m_splitImpulse = 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. */ +void RB_dworld_get_impulse(rbDynamicsWorld *world, + rbRigidBody *rbo, + float timeSubStep, + float norm_forces[3][3], + float vec_locations[3][3]) +{ + int numManifolds = world->dispatcher->getNumManifolds(); + int num_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_forces>2) + break; + if(obA != rbo->body && obB != rbo->body) + { + printf("%p,%p,\n",rbo,obA); + continue; + } + else + { + btVector3 tot_impulse = btVector3(0.0,0.0,0.0); + btVector3 final_loc = 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 lat_imp1 = pt.m_appliedImpulseLateral1 * pt.m_lateralFrictionDir1; + const btVector3 lat_imp2 = pt.m_appliedImpulseLateral2 * pt.m_lateralFrictionDir2; + printf("%f,%f,%f %f,%f,%f\n",lat_imp1.getX(),lat_imp1.getY(),lat_imp1.getZ(),lat_imp2.getX(), lat_imp2.getY(),lat_imp2.getZ()); + const btVector3 imp = (rbo->body == obB)? -pt.m_normalWorldOnB * pt.getAppliedImpulse()/timeSubStep:pt.m_normalWorldOnB * pt.getAppliedImpulse()/timeSubStep; + + tot_impulse += imp; + final_loc += num_impulse_points>1 ? loc * pt.getAppliedImpulse() / numContacts : loc; + } + } + copy_v3_btvec3(norm_forces[num_forces],tot_impulse); + copy_v3_btvec3(vec_locations[num_forces],final_loc); + num_forces++; + } + + } +} + /* Simulation ----------------------- */ void RB_dworld_step_simulation(rbDynamicsWorld *world, @@ -212,31 +271,6 @@ void RB_dworld_step_simulation(rbDynamicsWorld *world, float timeSubStep) { world->dynamicsWorld->stepSimulation(timeStep, maxSubSteps, timeSubStep); - - int numManifolds = world->dispatcher->getNumManifolds(); - for (int i = 0; i < numManifolds; i++) - { - printf("manifold:%d\n",i); - btPersistentManifold* contactManifold = world->dispatcher->getManifoldByIndexInternal(i); - const btCollisionObject* obA = contactManifold->getBody0(); - const btCollisionObject* obB = contactManifold->getBody1(); - - int numContacts = contactManifold->getNumContacts(); - for (int j = 0; j < numContacts; j++) - { - btManifoldPoint& pt = contactManifold->getContactPoint(j); - if (pt.getAppliedImpulse() > 0.f) - { - const btVector3& ptA = pt.getPositionWorldOnA(); - const btVector3& ptB = pt.getPositionWorldOnB(); - const btScalar imp = pt.getAppliedImpulse() ; - if((imp/timeStep)>=9.82) printf("****impulse on point%d:%f****\n",j,imp); - printf("impulse on point%d:%f \nloc: %f %f %f\ndist:%f\n",j,imp,ptA.getX(),ptA.getY(),ptA.getZ(),pt.getDistance()); - printf("force on point%d:%f\n",j,imp/timeSubStep); - - } - } - } } /* Export -------------------------- */ diff --git a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py index 75b584617c3..827a7b777fd 100644 --- a/release/scripts/startup/bl_ui/properties_physics_rigidbody.py +++ b/release/scripts/startup/bl_ui/properties_physics_rigidbody.py @@ -320,10 +320,42 @@ class PHYSICS_PT_rigid_body_display_options(PHYSICS_PT_rigidbody_panel, Panel): return col = layout.column() - col.prop(rbo, "display_forces") + col.prop(rbo, "display_data_text") col.prop(rbo, "display_acceleration") col.prop(rbo, "display_velocity") +class PHYSICS_PT_rigid_body_display_force_types(PHYSICS_PT_rigidbody_panel, Panel): + bl_label = "Forces" + bl_parent_id = 'PHYSICS_PT_rigid_body_display_options' + bl_options = {'DEFAULT_CLOSED'} + COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'} + + @classmethod + def poll(cls, context): + obj = context.object + if obj.parent is not None and obj.parent.rigid_body is not None: + return False + return (obj and obj.rigid_body and (context.engine in cls.COMPAT_ENGINES)) + + def draw_header(self, context): + ob = context.object + rbo = ob.rigid_body + + self.layout.prop(rbo, "display_forces", text="") + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + + ob = context.object + rbo = ob.rigid_body + + col = layout.column() + col.active = rbo.display_forces + col.prop(rbo, "show_gravity") + col.prop(rbo, "show_effectors_force") + col.prop(rbo, "show_normal_force") + col.prop(rbo, "show_frictional_force") classes = ( PHYSICS_PT_rigid_body, @@ -335,6 +367,7 @@ classes = ( PHYSICS_PT_rigid_body_dynamics, PHYSICS_PT_rigid_body_dynamics_deactivation, PHYSICS_PT_rigid_body_display_options, + PHYSICS_PT_rigid_body_display_force_types, ) diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index 231a4563630..69eaa9884d3 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -129,7 +129,8 @@ void BKE_effectors_apply(struct ListBase *effectors, struct EffectedPoint *point, float *force, float *wind_force, - float *impulse); + float *impulse, + float eff_forces[3][3]); void BKE_effectors_free(struct ListBase *lb); void pd_point_from_particle(struct ParticleSimulationData *sim, diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index 170eb4ba662..bb3e5710582 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -25,6 +25,7 @@ #include "DNA_boid_types.h" /* for #BoidData */ #include "DNA_pointcache_types.h" /* for #BPHYS_TOT_DATA */ +#include "DNA_rigidbody_types.h" #include <stdio.h> /* for #FILE */ @@ -103,6 +104,8 @@ typedef struct PTCacheData { float size; float times[3]; struct BoidData boids; + struct force_vec eff_forces[3]; + struct force_vec norm_forces[3]; } PTCacheData; typedef struct PTCacheFile { diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index e69173cc1d5..c7983df2233 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -1389,6 +1389,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) &epoint, force, NULL, + NULL, NULL); if (ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing)) { diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 42af3a391ed..b8d934bb374 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -5108,7 +5108,7 @@ 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); + 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 e39749225ea..23b978c3b92 100644 --- a/source/blender/blenkernel/intern/effect. @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs