BGE soft body: change welding option to disable welding check by default: speeds...
authorBenoit Bolsee <benoit.bolsee@online.be>
Mon, 27 Apr 2009 22:21:42 +0000 (22:21 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Mon, 27 Apr 2009 22:21:42 +0000 (22:21 +0000)
source/blender/blenkernel/intern/bullet.c
source/blender/makesdna/DNA_object_force.h
source/blender/src/buttons_logic.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h

index 657507ee048a99caa2fcebda07eefa27d0155cbf..44e8ed1f08c6bb29cb365cd86c83eeb618c47877 100644 (file)
@@ -82,7 +82,7 @@ BulletSoftBody *bsbNew(void)
        bsb->collisionflags = 0;
        //bsb->collisionflags = OB_BSB_COL_CL_RS + OB_BSB_COL_CL_SS;
        bsb->numclusteriterations = 64;
-       bsb->welding = -4.f;
+       bsb->welding = 0.f;
 
        return bsb;
 }
index 73dd8b28d15d6f67694870d3eab61fc3580cfdf3..e8e865a533cecf9daeb8724291f2acedf77e71eb 100644 (file)
@@ -119,7 +119,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*/
-       float   welding;                /* welding limit to remove duplicate/nearby vertices, 0.0000001..0.01 */
+       float   welding;                /* welding limit to remove duplicate/nearby vertices, 0.0..0.01 */
 } BulletSoftBody;
 
 /* BulletSoftBody.flag */
index 8b6cc4579949d8e6e09a0b904e9841390511f33c..eb65dcc678591c8196a232811265db8d7f1bdc9b 100644 (file)
@@ -3104,12 +3104,9 @@ static uiBlock *advanced_bullet_menu(void *arg_ob)
                        uiBlockEndAlign(block);
                        yco -= 20;
                        xco = 0;
-                       if (ob->bsoft->welding == 0.f)
-                               ob->bsoft->welding = -4.f;
-
-                       uiDefButF(block, NUMSLI, 0, "Welding(10^) ", 
-                               xco, yco, 360, 19, &ob->bsoft->welding, -7.f, -2.f, 10, 2, 
-                               "Threshold to remove duplicate/nearby vertices. Displayed in logarithmic scale for readability: linear values from 0.0000001 to 0.01");
+                       uiDefButF(block, NUMSLI, 0, "Welding ", 
+                               xco, yco, 360, 19, &ob->bsoft->welding, 0.f, 0.01f, 10, 4, 
+                               "Welding threshold: distance between nearby vertices to be considered equal => set to 0.0 to disable welding test and speed up scene loading (ok if the mesh has no duplicates)");
 
                        /*
                        //too complex tweaking, disable for now
index b330515c0d36985e892c26810128e7a6e571c5d3..ef3efbcec870f322ceca9935f082b114ae204dd5 100644 (file)
@@ -1418,10 +1418,7 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
                        objprop.m_soft_kAHR= blenderobject->bsoft->kAHR;                        /* Anchors hardness [0,1] */
                        objprop.m_soft_collisionflags= blenderobject->bsoft->collisionflags;    /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
                        objprop.m_soft_numclusteriterations= blenderobject->bsoft->numclusteriterations;        /* number of iterations to refine collision clusters*/
-                       if (blenderobject->bsoft->welding == 0.f)
-                               objprop.m_soft_welding = 0.0001f;               /* welding */
-                       else
-                               objprop.m_soft_welding = pow(10.f,blenderobject->bsoft->welding);               /* welding */
+                       objprop.m_soft_welding = blenderobject->bsoft->welding;         /* welding */
                
                } else
                {
@@ -1461,7 +1458,7 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
                        objprop.m_soft_kAHR= 0.7f;
                        objprop.m_soft_collisionflags= OB_BSB_COL_SDF_RS + OB_BSB_COL_VF_SS;
                        objprop.m_soft_numclusteriterations= 16;
-                       objprop.m_soft_welding = 0.0001f;
+                       objprop.m_soft_welding = 0.f;
                }
        }
 
index b944ae085bad7770ab18123acbef7034061fdd13..b171fbb3c3494be84f0581c5421e45b407579306 100644 (file)
@@ -1368,9 +1368,9 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                        }
                }
 
-               m_vertexArray.resize(tot_bt_verts);
+               m_vertexArray.resize(tot_bt_verts*3);
 
-               btVector3 *bt= &m_vertexArray[0];
+               btScalar *bt= &m_vertexArray[0];
 
                for (int p2=0; p2<numpolys; p2++)
                {
@@ -1388,8 +1388,9 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                                                const float* vtx = v->getXYZ();
                                                vert_tag_array[orig_index]= false;
 
-                                               bt->setX(vtx[0]);  bt->setY(vtx[1]);  bt->setZ(vtx[2]);
-                                               bt++;
+                                               *bt++ = vtx[0];
+                                               *bt++ = vtx[1];
+                                               *bt++ = vtx[2];
                                        }
                                }
                        }
@@ -1421,11 +1422,11 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                        }
                }
 
-               m_vertexArray.resize(tot_bt_verts);
+               m_vertexArray.resize(tot_bt_verts*3);
                m_polygonIndexArray.resize(tot_bt_tris);
                m_triFaceArray.resize(tot_bt_tris*3);
 
-               btVector3 *bt= &m_vertexArray[0];
+               btScalar *bt= &m_vertexArray[0];
                int *poly_index_pt= &m_polygonIndexArray[0];
                int *tri_pt= &m_triFaceArray[0];
 
@@ -1459,20 +1460,23 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                                if (vert_tag_array[i1]==true) { /* *** v1 *** */
                                        vert_tag_array[i1]= false;
                                        vtx = v1->getXYZ();
-                                       bt->setX(vtx[0]);       bt->setY( vtx[1]);      bt->setZ(vtx[2]);
-                                       bt++;
+                                       *bt++ = vtx[0];
+                                       *bt++ = vtx[1];
+                                       *bt++ = vtx[2];
                                }
                                if (vert_tag_array[i2]==true) { /* *** v2 *** */
                                        vert_tag_array[i2]= false;
                                        vtx = v2->getXYZ();
-                                       bt->setX(vtx[0]);       bt->setY(vtx[1]);       bt->setZ(vtx[2]);
-                                       bt++;
+                                       *bt++ = vtx[0];
+                                       *bt++ = vtx[1];
+                                       *bt++ = vtx[2];
                                }
                                if (vert_tag_array[i3]==true) { /* *** v3 *** */
                                        vert_tag_array[i3]= false;
                                        vtx = v3->getXYZ();
-                                       bt->setX(vtx[0]);       bt->setY(vtx[1]);       bt->setZ(vtx[2]);
-                                       bt++;
+                                       *bt++ = vtx[0]; 
+                                       *bt++ = vtx[1];
+                                       *bt++ = vtx[2];
                                }
 
                                if (poly->VertexCount()==4)
@@ -1493,8 +1497,9 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                                        if (vert_tag_array[i4]==true) { /* *** v4 *** */
                                                vert_tag_array[i4]= false;
                                                vtx = v4->getXYZ();
-                                               bt->setX(vtx[0]);       bt->setY(vtx[1]);       bt->setZ(vtx[2]);
-                                               bt++;
+                                               *bt++ = vtx[0];
+                                               *bt++ = vtx[1]; 
+                                               *bt++ = vtx[2];
                                        }
                                }
                        }
@@ -1577,7 +1582,7 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                break;
 
        case PHY_SHAPE_POLYTOPE:
-               collisionShape = new btConvexHullShape(&m_vertexArray[0].getX(), m_vertexArray.size());
+               collisionShape = new btConvexHullShape(&m_vertexArray[0], m_vertexArray.size()/3, 3*sizeof(btScalar));
                break;
 
        case PHY_SHAPE_MESH:
@@ -1594,9 +1599,9 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                                                m_polygonIndexArray.size(),
                                                &m_triFaceArray[0],
                                                3*sizeof(int),
-                                               m_vertexArray.size(),
-                                               (btScalar*) &m_vertexArray[0].x(),
-                                               sizeof(btVector3)
+                                               m_vertexArray.size()/3,
+                                               &m_vertexArray[0],
+                                               3*sizeof(btScalar)
                                );
                                
                                btGImpactMeshShape* gimpactShape =  new btGImpactMeshShape(indexVertexArrays);
@@ -1619,12 +1624,13 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                                        bool removeDuplicateVertices=true;
                                        // m_vertexArray not in multiple of 3 anymore, use m_triFaceArray
                                        for(int i=0; i<m_triFaceArray.size(); i+=3) {
-                                               collisionMeshData->addTriangle(
-                                                               m_vertexArray[m_triFaceArray[i]],
-                                                               m_vertexArray[m_triFaceArray[i+1]],
-                                                               m_vertexArray[m_triFaceArray[i+2]],
-                                                               removeDuplicateVertices
-                                               );
+                                               btScalar *bt = &m_vertexArray[3*m_triFaceArray[i]];
+                                               btVector3 v1(bt[0], bt[1], bt[2]);
+                                               bt = &m_vertexArray[3*m_triFaceArray[i+1]];
+                                               btVector3 v2(bt[0], bt[1], bt[2]);
+                                               bt = &m_vertexArray[3*m_triFaceArray[i+2]];
+                                               btVector3 v3(bt[0], bt[1], bt[2]);
+                                               collisionMeshData->addTriangle(v1, v2, v3, removeDuplicateVertices);
                                        }
                                        indexVertexArrays = collisionMeshData;
 
@@ -1634,9 +1640,9 @@ btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape()
                                                        m_polygonIndexArray.size(),
                                                        &m_triFaceArray[0],
                                                        3*sizeof(int),
-                                                       m_vertexArray.size(),
-                                                       (btScalar*) &m_vertexArray[0].x(),
-                                                       sizeof(btVector3));
+                                                       m_vertexArray.size()/3,
+                                                       &m_vertexArray[0],
+                                                       3*sizeof(btScalar));
                                }
                                
                                // this shape will be shared and not deleted until shapeInfo is deleted
index 4510bbddf65917a82644e5a01e7f6b4e88bb6429..4ab478b210646910846fe947a65e7bfbba90a238 100644 (file)
@@ -161,8 +161,8 @@ public:
        btTransform                             m_childTrans;
        btVector3                               m_childScale;
        void*                                   m_userData;     
-       btAlignedObjectArray<btVector3> m_vertexArray;  // Contains both vertex array for polytope shape and
-                                                                                       // triangle array for concave mesh shape.
+       btAlignedObjectArray<btScalar>  m_vertexArray;  // Contains both vertex array for polytope shape and
+                                                                                       // triangle array for concave mesh shape. Each vertex is 3 consecutive values
                                                                                        // In this case a triangle is made of 3 consecutive points
        std::vector<int>                m_polygonIndexArray;    // Contains the array of polygon index in the 
                                                                                                        // original mesh that correspond to shape triangles.
@@ -173,11 +173,7 @@ public:
 
        void    setVertexWeldingThreshold1(float threshold)
        {
-               m_weldingThreshold1  = threshold;
-       }
-       float   getVertexWeldingThreshold1() const
-       {
-               return m_weldingThreshold1;
+               m_weldingThreshold1  = threshold*threshold;
        }
 protected:
        static std::map<RAS_MeshObject*, CcdShapeConstructionInfo*> m_meshShapeMap;