BGE #30734: add support for physics linear and angular thresholds and deactivation time from python and GUI.

========================
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)
This commit is contained in:
Benoit Bolsee
2012-05-29 20:30:33 +00:00
parent 1d4ab9daf0
commit 58bc424b3c
9 changed files with 60 additions and 8 deletions

View 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()

View 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

View 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;

View 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! */
{

View 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;

View 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

View 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 */

View 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);

View 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)