BGE patch: add advanced parameters for SoftBody. Add Rasterizer.drawLine() Python...
authorBenoit Bolsee <benoit.bolsee@online.be>
Wed, 24 Sep 2008 22:58:49 +0000 (22:58 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Wed, 24 Sep 2008 22:58:49 +0000 (22:58 +0000)
source/blender/blenkernel/intern/object.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_object_types.h
source/blender/src/buttons_logic.c
source/blender/src/editobject.c
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/PyDoc/Rasterizer.py

index 0da69ef516834fec995ff5142a91d9e72cf37f9d..54908230d88adcc5e04906a2b69424ac37eb0f5a 100644 (file)
@@ -964,6 +964,10 @@ 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 = 0;
 
        /* NT fluid sim defaults */
        ob->fluidsimFlag = 0;
index a193e89d26c4ad0f139543c73c57ad95a86e0b13..d966d691fddf6c1de3e2b64428f82f75079f1861 100644 (file)
@@ -7849,6 +7849,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        // Before it was conditioning all the other dynamic flags
                        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;
                }
        }
 
index 66bdaf2c98b8222953fa7c8ab50a28fb53a7ab9d..041e0eaebde44e25299f413077c54649291ccfb6 100644 (file)
@@ -156,7 +156,14 @@ typedef struct Object {
 
        float formfactor;
        float rdamping, sizefac;
-       float margin, pad3;
+       float margin;
+       /* for game engine soft body */
+       float linearStiffness;
+       float angularStiffness;
+       float volumePreservation;
+       int   gamesoftFlag;
+       int   pad3;
+
 
 
        char dt, dtx;
@@ -411,6 +418,9 @@ 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
 #define OB_CHILD               2
index 96949756083bff9bd307a7fb478c905a787cfcee..667f822bed56294ff6e752f835535edfd81af554 100644 (file)
@@ -2979,11 +2979,11 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
 {
        uiBlock *block;
        Object *ob = arg_ob;
-       short yco = 65, xco = 0;
+       short yco = 105, xco = 0;
 
        block= uiNewBlock(&curarea->uiblocks, "advanced_bullet_options", UI_EMBOSS, UI_HELV, curarea->win);
        /* use this for a fake extra empy space around the buttons */
-       uiDefBut(block, LABEL, 0, "", -5, -10, 255, 100, NULL, 0, 0, 0, 0, "");
+       uiDefBut(block, LABEL, 0, "", -5, -10, 255, 140, NULL, 0, 0, 0, 0, "");
 
        uiDefButBitI(block, TOG, OB_ACTOR, 0, "Sensor actor",
                                xco, yco, 118, 19, &ob->gameflag, 0, 0, 0, 0,
@@ -3008,6 +3008,25 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
                                xco, yco, 118, 19, &ob->margin, 0.0, 1.0, 1, 0, 
                                "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");
+       }
+
                        
        uiBlockSetDirection(block, UI_TOP);
 
index 6c830c7febfc80117b6f4de9b62cddc4ffd7b71e..7cc8138cb6f5ad3143d8b2d37bbc8f9dfb9fcaa3 100644 (file)
@@ -3529,6 +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;
                                }
                                else if(event==17) {    /* tex space */
                                        copy_texture_space(base->object, ob);
index 95693efe30e2d75c6900c31fda5ee02873620109..3e271be79849a2f0746540bf6f8f75e5b79379cc 100644 (file)
@@ -797,6 +797,36 @@ static PyObject* gPyGetMaterialType(PyObject*)
        return PyInt_FromLong(flag);
 }
 
+static PyObject* gPyDrawLine(PyObject*, PyObject* args)
+{
+       PyObject* ob_from;
+       PyObject* ob_to;
+       PyObject* ob_color;
+
+       if (!gp_Rasterizer) {
+               PyErr_SetString(PyExc_RuntimeError, "Rasterizer not available");
+               return NULL;
+       }
+
+       if (!PyArg_ParseTuple(args,"OOO",&ob_from,&ob_to,&ob_color))
+               return NULL;
+
+       MT_Vector3 from(0., 0., 0.);
+       MT_Vector3 to(0., 0., 0.);
+       MT_Vector3 color(0., 0., 0.);
+       if (!PyVecTo(ob_from, from))
+               return NULL;
+       if (!PyVecTo(ob_to, to))
+               return NULL;
+       if (!PyVecTo(ob_color, color))
+               return NULL;
+
+       gp_Rasterizer->DrawDebugLine(from,to,color);
+       
+       Py_RETURN_NONE;
+}
+
+
 STR_String     gPyGetWindowHeight__doc__="getWindowHeight doc";
 STR_String     gPyGetWindowWidth__doc__="getWindowWidth doc";
 STR_String     gPyEnableVisibility__doc__="enableVisibility doc";
@@ -838,6 +868,8 @@ static struct PyMethodDef rasterizer_methods[] = {
    METH_VARARGS, "set the state of a GLSL material setting"},
   {"getGLSLMaterialSetting",(PyCFunction) gPyGetGLSLMaterialSetting,
    METH_VARARGS, "get the state of a GLSL material setting"},
+  {"drawLine", (PyCFunction) gPyDrawLine,
+   METH_VARARGS, "draw a line on the screen"},
   { NULL, (PyCFunction) NULL, 0, NULL }
 };
 
index ebb5332d98dd8df6146db68f71443d81d98cad56..cdda87fcb49c3ef474b4b6797b0d58f3ba1392f2 100644 (file)
@@ -181,4 +181,15 @@ def getGLSLMaterialSetting(setting, enable):
        @type setting: string (lights, shaders, shadows, ramps, nodes, extra_textures)
        @rtype: boolean
        """
+def drawLine(from,to,color):
+       """
+       Draw a line in the 3D scene.
+       
+       @param from: the origin of the line
+       @type from: list [x, y, z]
+       @param to: the end of the line
+       @type to: list [x, y, z]
+       @param color: the color of the line
+       @type color: list [r, g, b]
+       """