re-use some Blender soft body settings for Bullet game soft bodies

This commit is contained in:
Erwin Coumans 2008-09-25 16:48:25 +00:00
parent c9c9b2e833
commit bc28feb997
7 changed files with 66 additions and 53 deletions

@ -964,11 +964,7 @@ Object *add_only_object(int type, char *name)
ob->anisotropicFriction[2] = 1.0f;
ob->gameflag= OB_PROP|OB_COLLISION;
ob->margin = 0.0;
ob->linearStiffness = 1.0f;
ob->angularStiffness = 1.0f;
ob->volumePreservation = 1.0f;
ob->gamesoftFlag = OB_SOFT_SHAPE_MATCHING;
/* NT fluid sim defaults */
ob->fluidsimFlag = 0;
ob->fluidsimSettings = NULL;

@ -7850,10 +7850,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
if (!(ob->gameflag & OB_ACTOR))
ob->gameflag &= ~(OB_GHOST|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_COLLISION_RESPONSE);
/* suitable default for older files */
ob->linearStiffness = 1.0f;
ob->angularStiffness = 1.0f;
ob->volumePreservation = 1.0f;
ob->softflag = OB_SOFT_SHAPE_MATCHING;
}
}

@ -157,15 +157,8 @@ typedef struct Object {
float formfactor;
float rdamping, sizefac;
float margin;
/* for game engine soft body */
float linearStiffness;
float angularStiffness;
float volumePreservation;
int gamesoftFlag;
int pad3;
char dt, dtx;
char totcol; /* copy of mesh or curve or meta */
char actcol; /* currently selected material in the user interface */
@ -418,8 +411,6 @@ extern Object workob;
#define OB_RECALC_TIME 4
#define OB_RECALC 7
/* ob->gamesoftFlag */
#define OB_SOFT_SHAPE_MATCHING 1
/* ob->gameflag */
#define OB_DYNAMIC 1

@ -49,6 +49,7 @@
#include "DNA_controller_types.h"
#include "DNA_property_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_scene_types.h"
@ -2926,9 +2927,9 @@ void buttons_ketsji(uiBlock *block, Object *ob)
uiBlockBeginAlign(block);
uiDefButBitI(block, TOG, OB_BOUNDS, B_REDR, "Bounds", 10, 105, 75, 19,
&ob->gameflag, 0, 0,0, 0,
"Specify a bounds object for physics");
"Specify a collision shape bounds type");
if (ob->gameflag & OB_BOUNDS) {
uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull%x5|Static TriangleMesh %x4",
uiDefButS(block, MENU, REDRAWVIEW3D, "Collision Type%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull%x5|Concave TriangleMesh %x4",
85, 105, 160, 19, &ob->boundtype, 0, 0, 0, 0, "Selects the collision type");
uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 250,105,100,19,
&ob->gameflag, 0, 0, 0, 0,
@ -3009,22 +3010,30 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
"Collision margin");
}
if (ob->gameflag & OB_SOFT_BODY) {
uiDefButBitI(block, TOG, OB_SOFT_SHAPE_MATCHING, 0, "Shape matching",
xco+=120, yco, 118, 19, &ob->gamesoftFlag, 0, 0, 0, 0,
"Enable soft body shape matching");
yco -= 25;
xco = 0;
uiDefButF(block, NUMSLI, 0, "LinStiff ", xco, yco, 238, 19,
&ob->linearStiffness, 0.0, 1.0, 1, 0,
"Linear stiffness of the soft body vertex spring");
yco -= 25;
uiDefButF(block, NUMSLI, 0, "AngStiff ", xco, yco, 238, 19,
&ob->angularStiffness, 0.0, 1.0, 1, 0,
"Angular stiffness of the soft body vertex spring");
yco -= 25;
uiDefButF(block, NUMSLI, 0, "Volume ", xco, yco, 238, 19,
&ob->volumePreservation, 0.0, 1.0, 1, 0,
"Factor of soft body volume preservation");
if (ob->soft)
{
uiDefButBitI(block, TOG, OB_SB_GOAL, 0, "Shape matching",
xco+=120, yco, 118, 19, &ob->softflag, 0, 0, 0, 0,
"Enable soft body shape matching goal");
yco -= 25;
xco = 0;
uiDefButF(block, NUMSLI, 0, "LinStiff ", xco, yco, 238, 19,
&ob->soft->inspring, 0.0, 1.0, 1, 0,
"Linear stiffness of the soft body vertex spring");
/*
yco -= 25;
uiDefButF(block, NUMSLI, 0, "AngStiff ", xco, yco, 238, 19,
&ob->angularStiffness, 0.0, 1.0, 1, 0,
"Angular stiffness of the soft body vertex spring");
yco -= 25;
uiDefButF(block, NUMSLI, 0, "Volume ", xco, yco, 238, 19,
&ob->volumePreservation, 0.0, 1.0, 1, 0,
"Factor of soft body volume preservation");
*/
}
}
@ -3049,10 +3058,21 @@ void buttons_bullet(uiBlock *block, Object *ob)
else
ob->body_type = OB_BODY_TYPE_SOFT;
but = uiDefButS(block, MENU, REDRAWVIEW3D,
"Object type%t|No collision%x0|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4",
10, 205, 120, 19, &ob->body_type, 0, 0, 0, 0, "Selects the type of physical representation");
uiButSetFunc(but, check_body_type, but, ob);
//only enable game soft body if Blender Soft Body exists
if (ob->soft)
{
but = uiDefButS(block, MENU, REDRAWVIEW3D,
"Object type%t|No collision%x0|Static%x1|Dynamic%x2|Rigid body%x3|Soft body%x4",
10, 205, 120, 19, &ob->body_type, 0, 0, 0, 0, "Selects the type of physical representation");
uiButSetFunc(but, check_body_type, but, ob);
} else
{
but = uiDefButS(block, MENU, REDRAWVIEW3D,
"Object type%t|No collision%x0|Static%x1|Dynamic%x2|Rigid body%x3",
10, 205, 120, 19, &ob->body_type, 0, 0, 0, 0, "Selects the type of physical representation");
uiButSetFunc(but, check_body_type, but, ob);
}
if (ob->gameflag & OB_COLLISION) {
@ -3088,9 +3108,9 @@ void buttons_bullet(uiBlock *block, Object *ob)
uiBlockBeginAlign(block);
uiDefButBitI(block, TOG, OB_BOUNDS, B_REDR, "Bounds", 10, 105, 80, 19,
&ob->gameflag, 0, 0, 0, 0,
"Specify a bounds object for physics");
"Specify a collision bounds type");
if (ob->gameflag & OB_BOUNDS) {
uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull%x5|Static Mesh%x4",
uiDefButS(block, MENU, REDRAWVIEW3D, "Collision Bounds%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull%x5|Triangle Mesh%x4",
//almost ready to enable this one: uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Convex Hull Polytope%x5|Static TriangleMesh %x4|Dynamic Mesh %x5|",
90, 105, 150, 19, &ob->boundtype, 0, 0, 0, 0, "Selects the collision type");
uiDefButBitI(block, TOG, OB_CHILD, B_REDR, "Compound", 240,105,110,19,

@ -3529,10 +3529,10 @@ void copy_attr(short event)
base->object->boundtype = ob->boundtype;
}
base->object->margin= ob->margin;
base->object->linearStiffness= ob->linearStiffness;
base->object->angularStiffness= ob->angularStiffness;
base->object->volumePreservation= ob->volumePreservation;
base->object->gamesoftFlag= ob->gamesoftFlag;
//base->object->linearStiffness= ob->linearStiffness;
//base->object->angularStiffness= ob->angularStiffness;
//base->object->volumePreservation= ob->volumePreservation;
//base->object->gamesoftFlag= ob->gamesoftFlag;
}
else if(event==17) { /* tex space */
copy_texture_space(base->object, ob);

@ -129,6 +129,7 @@
#include "DNA_sound_types.h"
#include "DNA_key_types.h"
#include "DNA_armature_types.h"
#include "DNA_object_force.h"
#include "MEM_guardedalloc.h"
#include "BKE_utildefines.h"
@ -1323,10 +1324,20 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
///for game soft bodies
objprop.m_linearStiffness = blenderobject->linearStiffness;
objprop.m_angularStiffness = blenderobject->angularStiffness;
objprop.m_volumePreservation = blenderobject->volumePreservation;
objprop.m_gamesoftFlag = blenderobject->gamesoftFlag;
if (blenderobject->soft)
{
objprop.m_linearStiffness = blenderobject->soft->inspring;
objprop.m_angularStiffness = 1.f;//blenderobject->angularStiffness;
objprop.m_volumePreservation = 1.f;//blenderobject->volumePreservation;
objprop.m_gamesoftFlag = blenderobject->softflag;//blenderobject->gamesoftFlag;
} else
{
objprop.m_linearStiffness = 0.5;//blenderobject->linearStiffness;
objprop.m_angularStiffness = 1.f;//blenderobject->angularStiffness;
objprop.m_volumePreservation = 1.f;//blenderobject->volumePreservation;
objprop.m_gamesoftFlag = 1;//blenderobject->gamesoftFlag;
}
objprop.m_ghost = (blenderobject->gameflag & OB_GHOST) != 0;
objprop.m_disableSleeping = (blenderobject->gameflag & OB_COLLISION_RESPONSE) != 0;//abuse the OB_COLLISION_RESPONSE flag

@ -346,7 +346,6 @@ void CcdPhysicsController::CreateRigidbody()
//pm->m_kAST = 0.01f;
//pm->m_kVST = 0.001f;
psb->generateBendingConstraints(2,pm);
@ -354,7 +353,7 @@ void CcdPhysicsController::CreateRigidbody()
//psb->m_cfg.viterations = 4;
//psb->m_cfg.diterations = 4;
//psb->m_cfg.citerations = 4;
if (m_cci.m_gamesoftFlag & 1)///OB_SOFT_SHAPE_MATCHING)
if (m_cci.m_gamesoftFlag & 2)//OB_SB_GOAL)
{
psb->setPose(false,true);//
} else
@ -390,7 +389,7 @@ void CcdPhysicsController::CreateRigidbody()
//psb->m_materials[0]->m_kLST = 0.1+(i/(btScalar)(n-1))*0.9;
psb->setTotalMass(m_cci.m_mass);
//psb->generateClusters(8);//(64);
psb->generateClusters(8);//(64);
psb->setCollisionFlags(0);
// m_object->setCollisionShape(rbci.m_collisionShape);
btTransform startTrans;