BGE #30734: add support for physics linear and angular thresholds and deactivation...
authorBenoit Bolsee <benoit.bolsee@online.be>
Tue, 29 May 2012 20:30:33 +0000 (20:30 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Tue, 29 May 2012 20:30:33 +0000 (20:30 +0000)
========================
The linear and angular thresholds set the speed limit (in m/s) and rotation limit (in rad/s)
under which a rigid body will go to sleep (stop moving) if it stays below the limits for a
time equal or longer than the deactivation time (sleeping is disabled is deactivation time is
set to 0).
These settings help reducing the processing spent on Physics during the game.

Previously they were only accessible from python but not working because of a bug.
Now the python functions are working and the settings are available in the Physics panel
of the World settings when using the Blender Game render engine.

Python API:
  import PhysicsConstraints
  PhysicsConstraints.setDeactivationLinearTreshold(float)
  PhysicsConstraints.setDeactivationAngularTreshold(float)

release/scripts/startup/bl_ui/properties_game.py
source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/intern/scene.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_object_types.h
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp

index 857afbd9f0981689ceab14c94fa9f94f821a1b0f..549e2181a2be0c69ae6a6e8ebcd54dae24fb8d04 100644 (file)
@@ -621,6 +621,14 @@ class WORLD_PT_game_physics(WorldButtonsPanel, Panel):
             col.label(text="Logic Steps:")
             col.prop(gs, "logic_step_max", text="Max")
 
+            col = layout.column()
+            col.label(text="Physics Deactivation:")
+            sub = col.row(align=True)
+            sub.prop(gs, "deactivation_linear_threshold", text="Linear Threshold")
+            sub.prop(gs, "deactivation_angular_threshold", text="Angular Threshold")
+            sub = col.row()
+            sub.prop(gs, "deactivation_time", text="Time")
+
             col = layout.column()
             col.prop(gs, "use_occlusion_culling", text="Occlusion Culling")
             sub = col.column()
index e2bca1bb93ec7fdb6a118f7387d996d493cb0463..24386730ddb22706ffe2740882778379984c4974 100644 (file)
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         263
-#define BLENDER_SUBVERSION      7
+#define BLENDER_SUBVERSION      8
 
 #define BLENDER_MINVERSION      250
 #define BLENDER_MINSUBVERSION   0
index 63efd194932ad83b6b9b7015e0855c99ef97a352..62d5459336bd67efa8976a8641045746f567dda1 100644 (file)
@@ -516,6 +516,9 @@ Scene *BKE_scene_add(const char *name)
        sce->gm.maxlogicstep = 5;
        sce->gm.physubstep = 1;
        sce->gm.maxphystep = 5;
+       sce->gm.lineardeactthreshold = 0.8f;
+       sce->gm.angulardeactthreshold = 1.0f;
+       sce->gm.deactivationtime = 0.0f;
 
        sce->gm.flag = GAME_DISPLAY_LISTS;
        sce->gm.matmode = GAME_MAT_MULTITEX;
index a0513cf55b1140d3ed4a9e093474c0128355a830..081264d62df11258de6d0969e5d5f816591bbc2a 100644 (file)
@@ -7230,9 +7230,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
        if (main->versionfile < 263) {
                /* set fluidsim rate. the version patch for this in 2.62 was wrong, so
-                * try to correct it, if rate is 0.0 that's likely not intentional */
+               try to correct it, if rate is 0.0 that's likely not intentional */
                Object *ob;
-               
+
                for (ob = main->object.first; ob; ob = ob->id.next) {
                        ModifierData *md;
                        for (md = ob->modifiers.first; md; md = md->next) {
@@ -7502,6 +7502,19 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        
+       if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 8))
+       {
+               /* set new deactivation values for game settings */
+               Scene *sce;
+
+               for (sce = main->scene.first; sce; sce = sce->id.next) {
+                       /* Game Settings */
+                       sce->gm.lineardeactthreshold = 0.8f;
+                       sce->gm.angulardeactthreshold = 1.0f;
+                       sce->gm.deactivationtime = 2.0f;
+               }
+       }
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
        {
index 11ca1f1fa8ecc55068b07459448a93dd4a1c28cf..44d7ec660f2c69ac405ca5bdd3ef2c78f291752e 100644 (file)
@@ -201,7 +201,7 @@ typedef struct Object {
        float rdamping, sizefac;
        float margin;
        float max_vel; /* clamp the maximum velocity 0.0 is disabled */
-       float min_vel; /* clamp the maximum velocity 0.0 is disabled */
+       float min_vel; /* clamp the minimum velocity 0.0 is disabled */
        float m_contactProcessingThreshold;
        float obstacleRad;
        
index 673156e3d7da680d804143228dd0883e7c60bae5..198b6a9bf8093bae8ec63bdcbdb8d897e1cebd32 100644 (file)
@@ -625,6 +625,7 @@ typedef struct GameData {
        short ticrate, maxlogicstep, physubstep, maxphystep;
        short obstacleSimulation, pad1;
        float levelHeight;
+       float deactivationtime, lineardeactthreshold, angulardeactthreshold,pad2;
 } GameData;
 
 #define STEREO_NOSTEREO                1
index 5b355e569116f8424d5124de11acbe7004b2b88f..17efc25c13278ea59fe67a3a7b2d81e89c6cae06 100644 (file)
@@ -2577,6 +2577,31 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
                                 "higher value give better physics precision");
        RNA_def_property_update(prop, NC_SCENE, NULL);
 
+       prop = RNA_def_property(srna, "deactivation_linear_threshold", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "lineardeactthreshold");
+       RNA_def_property_ui_range(prop, 0.001, 10000.0, 2, 3);
+       RNA_def_property_range(prop, 0.001, 10000.0);
+       RNA_def_property_ui_text(prop, "Deactivation Linear Threshold",
+                                "Linear velocity that an object must be below before the deactivation timer can start");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop = RNA_def_property(srna, "deactivation_angular_threshold", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "angulardeactthreshold");
+       RNA_def_property_ui_range(prop, 0.001, 10000.0, 2, 3);
+       RNA_def_property_range(prop, 0.001, 10000.0);
+       RNA_def_property_ui_text(prop, "Deactivation Angular Threshold",
+                                "Angular velocity that an object must be below before the deactivation timer can start");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
+       prop = RNA_def_property(srna, "deactivation_time", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "deactivationtime");
+       RNA_def_property_ui_range(prop, 0.0, 60.0, 1, 1);
+       RNA_def_property_range(prop, 0.0, 60.0);
+       RNA_def_property_ui_text(prop, "Deactivation Time",
+                                "Amount of time (in seconds) after objects with a velocity less than than a certain "
+                                "threshold will deactivate. Time 0.0 means deactivation inactive");
+       RNA_def_property_update(prop, NC_SCENE, NULL);
+
        /* mode */
        prop = RNA_def_property(srna, "use_occlusion_culling", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "mode", (1 << 5)); /*XXX mode hardcoded  *//* WO_DBVT_CULLING */
index b62e667c2118ab3485309f4f227c9961065d94b6..0613b137fe88ba53637da6ad221b47f7af4fac32 100644 (file)
@@ -324,8 +324,9 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
                        {
                                CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment(useDbvtCulling);
                                ccdPhysEnv->setDebugDrawer(new BlenderDebugDraw());
-                               ccdPhysEnv->setDeactivationLinearTreshold(0.8f); // default, can be overridden by Python
-                               ccdPhysEnv->setDeactivationAngularTreshold(1.0f); // default, can be overridden by Python
+                               ccdPhysEnv->setDeactivationLinearTreshold(blenderscene->gm.lineardeactthreshold);
+                               ccdPhysEnv->setDeactivationAngularTreshold(blenderscene->gm.angulardeactthreshold);
+                               ccdPhysEnv->setDeactivationTime(blenderscene->gm.deactivationtime);
 
                                SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
                                int visualizePhysics = SYS_GetCommandLineInt(syshandle,"show_physics",0);
index 92a9b405b7c8a1d22d1383820ffe0cc0587827e7..21158a9461def86226095761f118530e7a886e66 100644 (file)
@@ -60,8 +60,8 @@ extern float gDeactivationTime;
 extern bool gDisableDeactivation;
 
 
-float gLinearSleepingTreshold = 0.8f;
-float gAngularSleepingTreshold = 1.0f;
+float gLinearSleepingTreshold;
+float gAngularSleepingTreshold;
 
 
 btVector3 startVel(0,0,0);//-10000);
@@ -519,6 +519,7 @@ void CcdPhysicsController::CreateRigidbody()
                        body->setAngularFactor(0.f);
                }
                body->setContactProcessingThreshold(m_cci.m_contactProcessingThreshold);
+               body->setSleepingThresholds(gLinearSleepingTreshold, gAngularSleepingTreshold);
 
        }
        if (m_object && m_cci.m_do_anisotropic)