BGE patch: create new BulletSoftBody data block to store bullet soft body specific parameters.

Previously we tried to share the parameters with the
blender render soft body but there were too many differences.

MSVC project files updated.
This commit is contained in:
Benoit Bolsee 2008-09-27 21:52:20 +00:00
parent 5f7359a4ad
commit c723b91446
12 changed files with 176 additions and 38 deletions

View File

@ -365,6 +365,9 @@
<File
RelativePath="..\..\..\source\blender\blenkernel\intern\brush.c">
</File>
<File
RelativePath="..\..\..\source\blender\blenkernel\intern\bullet.c">
</File>
<File
RelativePath="..\..\..\source\blender\blenkernel\intern\bvhutils.c">
</File>
@ -591,6 +594,9 @@
<File
RelativePath="..\..\..\source\blender\blenkernel\BKE_brush.h">
</File>
<File
RelativePath="..\..\..\source\blender\blenkernel\BKE_bullet.h">
</File>
<File
RelativePath="..\..\..\source\blender\blenkernel\BKE_bvhutils.h">
</File>

View File

@ -0,0 +1,43 @@
/**
*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef BKE_BULLET_H
#define BKE_BULLET_H
struct BulletSoftBody;
/* allocates and initializes general main data */
extern struct BulletSoftBody *bsbNew(void);
/* frees internal data and softbody itself */
extern void bsbFree(struct BulletSoftBody *sb);
#endif

View File

@ -41,6 +41,7 @@ struct Camera;
struct BoundBox;
struct View3D;
struct SoftBody;
struct BulletSoftBody;
struct Group;
struct bAction;
@ -48,10 +49,12 @@ void clear_workob(void);
void copy_baseflags(void);
void copy_objectflags(void);
struct SoftBody *copy_softbody(struct SoftBody *sb);
struct BulletSoftBody *copy_bulletsoftbody(struct BulletSoftBody *sb);
void copy_object_particlesystems(struct Object *obn, struct Object *ob);
void copy_object_softbody(struct Object *obn, struct Object *ob);
void object_free_particlesystems(struct Object *ob);
void object_free_softbody(struct Object *ob);
void object_free_bulletsoftbody(struct Object *ob);
void update_base_layer(struct Object *ob);
void free_object(struct Object *ob);

View File

@ -0,0 +1,62 @@
/*
*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) Blender Foundation
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
#include "MEM_guardedalloc.h"
/* types */
#include "DNA_object_force.h" /* here is the softbody struct */
#include "BKE_bullet.h"
/* ************ Object level, exported functions *************** */
/* allocates and initializes general main data */
BulletSoftBody *bsbNew(void)
{
BulletSoftBody *bsb;
bsb= MEM_callocN(sizeof(BulletSoftBody), "bulletsoftbody");
bsb->flag = OB_BSB_SHAPE_MATCHING;
bsb->linStiff = 0.5f;
bsb->angStiff = 1.0f;
bsb->volume = 1.0f;
return bsb;
}
/* frees all */
void bsbFree(BulletSoftBody *bsb)
{
/* no internal data yet */
MEM_freeN(bsb);
}

View File

@ -179,6 +179,14 @@ void object_free_softbody(Object *ob)
}
}
void object_free_bulletsoftbody(Object *ob)
{
if(ob->bsoft) {
sbFree(ob->bsoft);
ob->bsoft= NULL;
}
}
void object_free_modifiers(Object *ob)
{
while (ob->modifiers.first) {
@ -269,6 +277,7 @@ void free_object(Object *ob)
MEM_freeN(ob->pd);
}
if(ob->soft) sbFree(ob->soft);
if(ob->bsoft) bsbFree(ob->bsoft);
if(ob->gpulamp.first) GPU_lamp_free(ob);
}
@ -1047,6 +1056,17 @@ SoftBody *copy_softbody(SoftBody *sb)
return sbn;
}
BulletSoftBody *copy_bulletsoftbody(BulletSoftBody *bsb)
{
BulletSoftBody *bsbn;
if (bsb == NULL)
return NULL;
bsbn = MEM_dupallocN(bsb);
/* no pointer in this structure yet */
return bsbn;
}
ParticleSystem *copy_particlesystem(ParticleSystem *psys)
{
ParticleSystem *psysn;
@ -1217,6 +1237,7 @@ Object *copy_object(Object *ob)
id_us_plus(&(obn->pd->tex->id));
}
obn->soft= copy_softbody(ob->soft);
obn->bsoft = copy_bulletsoftbody(ob->bsoft);
copy_object_particlesystems(obn, ob);

View File

@ -141,6 +141,7 @@
#include "BKE_sca.h" // for init_actuator
#include "BKE_scene.h"
#include "BKE_softbody.h" // sbNew()
#include "BKE_bullet.h" // bsbNew()
#include "BKE_sculpt.h"
#include "BKE_texture.h" // for open_plugin_tex
#include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
@ -3334,6 +3335,7 @@ static void direct_link_object(FileData *fd, Object *ob)
if(sb->pointcache)
direct_link_pointcache(fd, sb->pointcache);
}
ob->bsoft= newdataadr(fd, ob->bsoft);
ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */
link_list(fd, &ob->particlesystem);

View File

@ -922,6 +922,7 @@ static void write_objects(WriteData *wd, ListBase *idbase)
writestruct(wd, DATA, "PartDeflect", 1, ob->pd);
writestruct(wd, DATA, "SoftBody", 1, ob->soft);
if(ob->soft) writestruct(wd, DATA, "PointCache", 1, ob->soft->pointcache);
writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft);
write_particlesystems(wd, &ob->particlesystem);
write_modifiers(wd, &ob->modifiers);

View File

@ -84,6 +84,16 @@ typedef struct SBVertex {
float vec[4];
} SBVertex;
typedef struct BulletSoftBody {
int flag; /* various boolean options */
float linStiff; /* linear stiffness 0..1 */
float angStiff; /* angular stiffness 0..1 */
float volume; /* volume preservation 0..1 */
} BulletSoftBody;
/* BulletSoftBody.flag */
#define OB_BSB_SHAPE_MATCHING 2
typedef struct SoftBody {
struct ParticleSystem *particles; /* particlesystem softbody */

View File

@ -193,7 +193,9 @@ typedef struct Object {
* bit 15: Always ignore activity culling
*/
int gameflag2;
short softflag; /* softboday settings */
struct BulletSoftBody *bsoft; /* settings for game engine bullet soft body */
short softflag; /* softbody settings */
short recalc; /* dependency flag */
float anisotropicFriction[3];

View File

@ -67,6 +67,7 @@
#include "BKE_property.h"
#include "BKE_property.h"
#include "BKE_utildefines.h"
#include "BKE_bullet.h"
#include "BIF_gl.h"
#include "BIF_resources.h"
@ -3007,28 +3008,27 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
"Collision margin");
}
if (ob->gameflag & OB_SOFT_BODY) {
if (ob->soft)
/* create a BulletSoftBody structure if not already existing */
if (!ob->bsoft)
ob->bsoft = bsbNew();
if (ob->bsoft)
{
uiDefButBitS(block, TOG, OB_SB_GOAL, 0, "Shape matching",
xco+=120, yco, 118, 19, &ob->softflag, 0, 0, 0, 0,
uiDefButBitI(block, TOG, OB_BSB_SHAPE_MATCHING, 0, "Shape matching",
xco+=120, yco, 118, 19, &ob->bsoft->flag, 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,
&ob->bsoft->linStiff, 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,
&ob->bsoft->angStiff, 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,
&ob->bsoft->volume, 0.0, 1.0, 1, 0,
"Factor of soft body volume preservation");
*/
}
}
@ -3056,20 +3056,10 @@ void buttons_bullet(uiBlock *block, Object *ob)
ob->body_type = OB_BODY_TYPE_SOFT;
//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);
}
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);
if (ob->gameflag & OB_COLLISION) {

View File

@ -3529,10 +3529,8 @@ 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->bsoft= copy_bulletsoftbody(ob->bsoft);
}
else if(event==17) { /* tex space */
copy_texture_space(base->object, ob);

View File

@ -1324,19 +1324,19 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
objprop.m_angular_rigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
///for game soft bodies
if (blenderobject->soft)
if (blenderobject->bsoft)
{
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;
objprop.m_linearStiffness = blenderobject->bsoft->linStiff;
objprop.m_angularStiffness = blenderobject->bsoft->angStiff;
objprop.m_volumePreservation = blenderobject->bsoft->volume;
objprop.m_gamesoftFlag = blenderobject->bsoft->flag;
} 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_linearStiffness = 0.5;//blenderobject->bsoft->linStiff;
objprop.m_angularStiffness = 1.f;//blenderobject->bsoft->angStiff;
objprop.m_volumePreservation = 1.f;//blenderobject->bsoft->volume;
objprop.m_gamesoftFlag = 1;//blenderobject->bsoft->flag;
}
objprop.m_ghost = (blenderobject->gameflag & OB_GHOST) != 0;