[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19365] trunk/blender/source/gameengine/ Physics/Bullet: Speedup for bullet creating convex hull meshes
Campbell Barton
ideasman42 at gmail.com
Sun Mar 22 22:04:28 CET 2009
Revision: 19365
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19365
Author: campbellbarton
Date: 2009-03-22 22:04:28 +0100 (Sun, 22 Mar 2009)
Log Message:
-----------
Speedup for bullet creating convex hull meshes
In a simple test with ~12000 verts, overall BGE startup time went from ~4.5 sec to a bit under a second.
- before adding each vert it did a check for a duplicates.
- Using RAS_Polygon verts can give a lot of duplicates because the verts also store UV's and normals.
- Was increasing the array one item at a time, now resize the array once.
- Use the blender mesh mvert array rather then RAS_TexVert's, so needed to include some DNA headers.
Modified Paths:
--------------
trunk/blender/source/gameengine/Physics/Bullet/CMakeLists.txt
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
trunk/blender/source/gameengine/Physics/Bullet/Makefile
trunk/blender/source/gameengine/Physics/Bullet/SConscript
Modified: trunk/blender/source/gameengine/Physics/Bullet/CMakeLists.txt
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CMakeLists.txt 2009-03-22 20:59:32 UTC (rev 19364)
+++ trunk/blender/source/gameengine/Physics/Bullet/CMakeLists.txt 2009-03-22 21:04:28 UTC (rev 19365)
@@ -34,6 +34,7 @@
../../../kernel/gen_system
../../../../intern/string
../../Rasterizer
+ ../../../../source/blender/makesdna
)
BLENDERLIB(bf_bullet "${SRC}" "${INC}")
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2009-03-22 20:59:32 UTC (rev 19364)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp 2009-03-22 21:04:28 UTC (rev 19365)
@@ -24,10 +24,14 @@
#include "BulletSoftBody/btSoftBodyHelpers.h"
#include "LinearMath/btConvexHull.h"
#include "BulletCollision/Gimpact/btGImpactShape.h"
+#include "BulletCollision/Gimpact/btGImpactShape.h"
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
class BP_Proxy;
///todo: fill all the empty CcdPhysicsController methods, hook them up to the btRigidBody class
@@ -1315,37 +1319,64 @@
numvalidpolys = 0;
- for (int p2=0; p2<numpolys; p2++)
+ if (polytope)
{
- RAS_Polygon* poly = meshobj->GetPolygon(p2);
-
- // only add polygons that have the collisionflag set
- if (poly->IsCollider())
- {
- //Bullet can raycast any shape, so
- if (polytope)
+ Mesh *blen_mesh= meshobj->GetMesh();
+ vector<bool> vuser_array(blen_mesh->totvert, false);
+
+ unsigned int tot_bt_verts= 0;
+ unsigned int orig_index;
+ int i;
+
+ // Tag verts we're using
+ for (int p2=0; p2<numpolys; p2++)
+ {
+ RAS_Polygon* poly= meshobj->GetPolygon(p2);
+
+ // only add polygons that have the collisionflag set
+ if (poly->IsCollider())
{
- for (int i=0;i<poly->VertexCount();i++)
+ for (i=0;i<poly->VertexCount();i++)
{
- const float* vtx = poly->GetVertex(i)->getXYZ();
- btVector3 point(vtx[0],vtx[1],vtx[2]);
- //avoid duplicates (could better directly use vertex offsets, rather than a vertex compare)
- bool found = false;
- for (int j=0;j<m_vertexArray.size();j++)
+ orig_index= poly->GetVertex(i)->getOrigIndex();
+
+ if (vuser_array[orig_index]==false)
{
- if (m_vertexArray[j]==point)
- {
- found = true;
- break;
- }
+ vuser_array[orig_index]= true;
+ tot_bt_verts++;
}
- if (!found)
- m_vertexArray.push_back(point);
-
- numvalidpolys++;
}
- } else
+ }
+ }
+
+ m_vertexArray.resize(tot_bt_verts);
+
+ // Copy used verts directly from the meshes vert location to the bullet vector array
+ MVert *mv= blen_mesh->mvert;
+ btVector3 *bt= &m_vertexArray[0];
+
+ for (i=0;i<vuser_array.size();i++, mv++)
+ {
+ if (vuser_array[i]==true)
{
+ bt->setX( mv->co[0] );
+ bt->setY( mv->co[1] );
+ bt->setZ( mv->co[2] );
+ bt++;
+ }
+ }
+ numvalidpolys++;
+ }
+ else {
+ for (int p2=0; p2<numpolys; p2++)
+ {
+ RAS_Polygon* poly = meshobj->GetPolygon(p2);
+
+ // only add polygons that have the collisionflag set
+ if (poly->IsCollider())
+ {
+ //Bullet can raycast any shape, so
+
{
const float* vtx = poly->GetVertex(2)->getXYZ();
btVector3 vertex0(vtx[0],vtx[1],vtx[2]);
@@ -1379,7 +1410,7 @@
m_polygonIndexArray.push_back(p2);
numvalidpolys++;
}
- }
+ }
}
}
Modified: trunk/blender/source/gameengine/Physics/Bullet/Makefile
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/Makefile 2009-03-22 20:59:32 UTC (rev 19364)
+++ trunk/blender/source/gameengine/Physics/Bullet/Makefile 2009-03-22 21:04:28 UTC (rev 19365)
@@ -43,4 +43,5 @@
CPPFLAGS += -I../../Physics/common
CPPFLAGS += -I../../Physics/Dummy
CPPFLAGS += -I../../Rasterizer
+CPPFLAGS += -I../../../../source/blender/makesdna
Modified: trunk/blender/source/gameengine/Physics/Bullet/SConscript
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/SConscript 2009-03-22 20:59:32 UTC (rev 19364)
+++ trunk/blender/source/gameengine/Physics/Bullet/SConscript 2009-03-22 21:04:28 UTC (rev 19365)
@@ -3,7 +3,7 @@
sources = 'CcdPhysicsEnvironment.cpp CcdPhysicsController.cpp'
-incs = '. ../common #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer'
+incs = '. ../common #source/kernel/gen_system #intern/string #intern/moto/include #source/gameengine/Rasterizer #source/blender/makesdna'
incs += ' ' + env['BF_BULLET_INC']
More information about the Bf-blender-cvs
mailing list