BGE patch: create new BulletSoftBody data block to store bullet soft body specific...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sat, 27 Sep 2008 21:52:20 +0000 (21:52 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sat, 27 Sep 2008 21:52:20 +0000 (21:52 +0000)
Previously we tried to share the parameters with the
blender render soft body but there were too many differences.

MSVC project files updated.

12 files changed:
projectfiles_vc7/blender/blenkernel/BKE_blenkernel.vcproj
source/blender/blenkernel/BKE_bullet.h [new file with mode: 0644]
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/bullet.c [new file with mode: 0644]
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/makesdna/DNA_object_force.h
source/blender/makesdna/DNA_object_types.h
source/blender/src/buttons_logic.c
source/blender/src/editobject.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp

index 2151f581d19ea855b5d499eed311580c3eafa834..15e3680cf8cb95ef8df56e23165ec902a3a6cd9b 100644 (file)
                        <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>
                        <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>
diff --git a/source/blender/blenkernel/BKE_bullet.h b/source/blender/blenkernel/BKE_bullet.h
new file mode 100644 (file)
index 0000000..1c3bb17
--- /dev/null
@@ -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
+
index 116a59fa97e6d33ea4b1a75659710280e48ed39e..ab76fc922eacd8ad82fa7edfc9a02db37b7893eb 100644 (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);
diff --git a/source/blender/blenkernel/intern/bullet.c b/source/blender/blenkernel/intern/bullet.c
new file mode 100644 (file)
index 0000000..8e07566
--- /dev/null
@@ -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);
+}
+
+
index 7b53d77086154af213fb4aff2450118f453eb77a..2dfa849fc43bbdedaaebcced86fe40ceb48ea0b1 100644 (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);
        
index 5692627281de98f9a52e0fffeabe9a582d78a88c..0999c8b0ce3e415afc7b9aa95af3e57cad099181 100644 (file)
 #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);
index e53c725867a6dcedd2b13750a7daba30d9ab34b2..9ca9a3d9287695d4e677e333a6793921db26375b 100644 (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);
index 5900e16d5e804f7a3e7420f8fac9b48e719bef6c..081b83c3d02b85ae71cb59463d6dc1c154104abc 100644 (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 */
 
index c12da6b0194d0fc7d62eb45171886fd04c4e5571..fad5c0207274a12d96b97bc5e180f8fa18d324f5 100644 (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];
 
index db3081070be6467e3d9e76eb0272cd9a3cb8f848..cec04910de512804b1a374521a1a2795d4c6cebd 100644 (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) {
 
index 6f926f7396ecb1a248998b470eefa4a6a859ae7b..370f116d318b91ddcbb3ec07ebea1d0d0b887778 100644 (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);
index 5b72a10cd0d04c1c6d403533f3055d9b304c4380..784a103f3e3e290e3813312c234118ddd41dc30f 100644 (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;