Skip to content

Commit

Permalink
UPBGE: Implement bending constraint distance UI option.
Browse files Browse the repository at this point in the history
Previously the bending distance was fixed to 2, now the user is able
to change its value in the UI.
  • Loading branch information
panzergame committed Sep 28, 2017
1 parent 6c7862b commit 5fde4ed
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions release/scripts/startup/bl_ui/properties_game.py
Expand Up @@ -149,6 +149,9 @@ def draw(self, context):
col.prop(soft, "dynamic_friction", slider=True)
col.prop(soft, "collision_margin", slider=True)
col.prop(soft, "use_bending_constraints", text="Bending Constraints")
sub = col.column()
sub.active = soft.use_bending_constraints
sub.prop(soft, "bending_distance")

col = split.column()
col.prop(soft, "use_shape_match")
Expand Down
1 change: 1 addition & 0 deletions source/blender/blenkernel/intern/bullet.c
Expand Up @@ -84,6 +84,7 @@ BulletSoftBody *bsbNew(void)
bsb->collisionflags = 0;
//bsb->collisionflags = OB_BSB_COL_CL_RS + OB_BSB_COL_CL_SS;
bsb->numclusteriterations = 64;
bsb->bending_dist = 2;
bsb->welding = 0.f;

return bsb;
Expand Down
11 changes: 11 additions & 0 deletions source/blender/blenloader/intern/versioning_upbge.c
Expand Up @@ -35,6 +35,7 @@

#include "DNA_genfile.h"
#include "DNA_material_types.h"
#include "DNA_object_force.h"
#include "DNA_object_types.h"
#include "DNA_camera_types.h"
#include "DNA_sdna_types.h"
Expand Down Expand Up @@ -242,4 +243,14 @@ void blo_do_versions_upbge(FileData *fd, Library *lib, Main *main)
}
}
}

if (!MAIN_VERSION_UPBGE_ATLEAST(main, 2, 1)) {
if (!DNA_struct_elem_find(fd->filesdna, "BulletSoftBody", "int", "bending_dist")) {
for (Object *ob = main->object.first; ob; ob = ob->id.next) {
if (ob->bsoft) {
ob->bsoft->bending_dist = 2;
}
}
}
}
}
1 change: 1 addition & 0 deletions source/blender/makesdna/DNA_object_force.h
Expand Up @@ -247,6 +247,7 @@ typedef struct BulletSoftBody {
float kAHR; /* Anchors hardness [0,1] */
int collisionflags; /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
int numclusteriterations; /* number of iterations to refine collision clusters*/
int bending_dist; /* Bending constraint distance */
float welding; /* welding limit to remove duplicate/nearby vertices, 0.0..0.01 */
float margin; /* margin specific to softbody */
} BulletSoftBody;
Expand Down
7 changes: 6 additions & 1 deletion source/blender/makesrna/intern/rna_object_force.c
Expand Up @@ -1540,7 +1540,12 @@ static void rna_def_game_softbody(BlenderRNA *brna)
RNA_def_property_int_sdna(prop, NULL, "numclusteriterations");
RNA_def_property_range(prop, 1, 1000);
RNA_def_property_ui_text(prop, "Cluster Iterations", "Number of cluster iterations");


prop = RNA_def_property(srna, "bending_distance", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "bending_dist");
RNA_def_property_range(prop, 1, 1000);
RNA_def_property_ui_text(prop, "Bending Distance", "Bending Constraint Distance");

/* Booleans */

prop = RNA_def_property(srna, "use_shape_match", PROP_BOOLEAN, PROP_NONE);
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
Expand Up @@ -441,7 +441,7 @@ bool CcdPhysicsController::CreateSoftbody()
psb->m_cfg.kAHR = m_cci.m_soft_kAHR; // Anchors hardness [0,1]

if (m_cci.m_gamesoftFlag & CCD_BSB_BENDING_CONSTRAINTS) {
psb->generateBendingConstraints(2, pm);
psb->generateBendingConstraints(m_cci.m_softBendingDistance, pm);
}

psb->m_cfg.piterations = m_cci.m_soft_piterations;
Expand Down
2 changes: 2 additions & 0 deletions source/gameengine/Physics/Bullet/CcdPhysicsController.h
Expand Up @@ -236,6 +236,7 @@ struct CcdConstructionInfo {
m_angularDamping(0.1f),
m_margin(0.06f),
m_gamesoftFlag(0),
m_softBendingDistance(2),
m_soft_linStiff(1.0f),
m_soft_angStiff(1.0f),
m_soft_volume(1.0f),
Expand Down Expand Up @@ -312,6 +313,7 @@ struct CcdConstructionInfo {
unsigned char m_maxJumps;

int m_gamesoftFlag;
unsigned short m_softBendingDistance;
/// linear stiffness 0..1
float m_soft_linStiff;
/// angular stiffness 0..1
Expand Down
4 changes: 4 additions & 0 deletions source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
Expand Up @@ -2741,6 +2741,8 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K
ci.m_margin = blenderobject->bsoft->margin;
ci.m_gamesoftFlag = blenderobject->bsoft->flag;

ci.m_softBendingDistance = blenderobject->bsoft->bending_dist;

ci.m_soft_linStiff = blenderobject->bsoft->linStiff;
ci.m_soft_angStiff = blenderobject->bsoft->angStiff; // angular stiffness 0..1
ci.m_soft_volume = blenderobject->bsoft->volume; // volume preservation 0..1
Expand Down Expand Up @@ -2780,6 +2782,8 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K
ci.m_margin = 0.0f;
ci.m_gamesoftFlag = OB_BSB_BENDING_CONSTRAINTS | OB_BSB_SHAPE_MATCHING | OB_BSB_AERO_VPOINT;

ci.m_softBendingDistance = 2;

ci.m_soft_linStiff = 0.5f;
ci.m_soft_angStiff = 1.0f; // angular stiffness 0..1
ci.m_soft_volume = 1.0f; // volume preservation 0..1
Expand Down

0 comments on commit 5fde4ed

Please sign in to comment.