Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2009-05-14 17:47:08 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2009-05-14 17:47:08 +0400
commitd95a10999052ad308599cb0fbbe7ed4f59870c9c (patch)
treec8ab32463f7e774319e35ab23855743dd0dea341 /source/gameengine/Physics
parent003534513645576215092b79f1aa46e85c89e3bd (diff)
BGE modifier: generate correct physic shape, share static derived mesh, share display list.
This commit completes the support for modifiers in the BGE. - The physic shape is generated according to the derived mesh. This is true for all types of shapes and all types of objects except soft body. - Optimization for static derived mesh (mesh with modifiers but no armature and no shape keys). Replicas will share the derived mesh and the display list: less memory and faster rendering. With this optimization, the static derived mesh will render as fast as if the modifiers were applied. Known Limits: - Sharing of mesh and display list is only possible between in-game replicas or dupligroup. If you want to instantiate multiple objects with modifiers, use dupligroup to ensure best memory and GPU utilization. - rayCast() will interact with the derived mesh as follow: Hit position and hit normal are the real values according to the derived mesh but the KX_PolyProxy object refers to the original mesh. You should use it only to retrieve the material. - Dynamic derived mesh have very poor performance: They use direct openGL calls for rendering (no support for display list and vertex array) and they dont't share the derived mesh memory. Always apply modifiers on dynamic mesh for best performance. - Time dependent modifiers are not supported. - Modifiers are not supported for Bullet soft body.
Diffstat (limited to 'source/gameengine/Physics')
-rw-r--r--source/gameengine/Physics/Bullet/CMakeLists.txt3
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp200
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h5
-rw-r--r--source/gameengine/Physics/Bullet/Makefile2
-rw-r--r--source/gameengine/Physics/Bullet/SConscript3
5 files changed, 124 insertions, 89 deletions
diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt
index ec2cdede683..02f2aa635af 100644
--- a/source/gameengine/Physics/Bullet/CMakeLists.txt
+++ b/source/gameengine/Physics/Bullet/CMakeLists.txt
@@ -32,6 +32,7 @@ SET(INC
../../../../extern/bullet2/src
../../../../extern/glew/include
../../../../intern/moto/include
+ ../../../../intern/guardedalloc
../../../kernel/gen_system
../../../../intern/string
../../../../intern/SoundSystem
@@ -41,6 +42,8 @@ SET(INC
../../GameLogic
../../SceneGraph
../../../../source/blender/makesdna
+ ../../../../source/blender/blenlib
+ ../../../../source/blender/blenkernel
${PYTHON_INC}
)
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index 961e9096442..01e8aa2560f 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -35,6 +35,10 @@ subject to the following restrictions:
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+extern "C"{
+#include "BKE_cdderivedmesh.h"
+}
+
class BP_Proxy;
///todo: fill all the empty CcdPhysicsController methods, hook them up to the btRigidBody class
@@ -1312,9 +1316,9 @@ void DefaultMotionState::calculateWorldTransformations()
// Shape constructor
std::map<RAS_MeshObject*, CcdShapeConstructionInfo*> CcdShapeConstructionInfo::m_meshShapeMap;
-CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mesh, bool polytope)
+CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope, bool gimpact)
{
- if (polytope)
+ if (polytope || dm || gimpact)
// not yet supported
return NULL;
@@ -1324,9 +1328,9 @@ CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mes
return NULL;
}
-bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bool useGimpact)
+bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, bool polytope,bool useGimpact)
{
- int numpolys;
+ int numpolys, numverts;
m_useGimpact = useGimpact;
@@ -1335,6 +1339,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
assert(IsUnused());
m_shapeType = PHY_SHAPE_NONE;
m_meshObject = NULL;
+ bool free_dm = false;
// No mesh object or mesh has no polys
if (!meshobj || meshobj->HasColliderPolygon()==false) {
@@ -1344,12 +1349,21 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
return false;
}
- numpolys = meshobj->NumPolygons();
+ if (!dm) {
+ free_dm = true;
+ dm = CDDM_from_mesh(meshobj->GetMesh(), NULL);
+ }
+
+ MVert *mvert = dm->getVertArray(dm);
+ MFace *mface = dm->getFaceArray(dm);
+ numpolys = dm->getNumFaces(dm);
+ numverts = dm->getNumVerts(dm);
+ int* index = (int*)dm->getFaceDataArray(dm, CD_ORIGINDEX);
m_shapeType = (polytope) ? PHY_SHAPE_POLYTOPE : PHY_SHAPE_MESH;
/* Convert blender geometry into bullet mesh, need these vars for mapping */
- vector<bool> vert_tag_array(meshobj->GetMesh()->totvert, false);
+ vector<bool> vert_tag_array(numverts, false);
unsigned int tot_bt_verts= 0;
unsigned int orig_index;
int i;
@@ -1359,19 +1373,16 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
// Tag verts we're using
for (int p2=0; p2<numpolys; p2++)
{
- RAS_Polygon* poly= meshobj->GetPolygon(p2);
+ MFace* mf = &mface[p2];
+ RAS_Polygon* poly = meshobj->GetPolygon(index[p2]);
// only add polygons that have the collision flag set
if (poly->IsCollider())
{
- for(i=0; i<poly->VertexCount(); i++) {
- orig_index= poly->GetVertex(i)->getOrigIndex();
- if (vert_tag_array[orig_index]==false)
- {
- vert_tag_array[orig_index]= true;
- tot_bt_verts++;
- }
- }
+ if (vert_tag_array[mf->v1]==false) {vert_tag_array[mf->v1]= true;tot_bt_verts++;}
+ if (vert_tag_array[mf->v2]==false) {vert_tag_array[mf->v2]= true;tot_bt_verts++;}
+ if (vert_tag_array[mf->v3]==false) {vert_tag_array[mf->v3]= true;tot_bt_verts++;}
+ if (mf->v4 && vert_tag_array[mf->v4]==false) {vert_tag_array[mf->v4]= true;tot_bt_verts++;}
}
}
@@ -1381,51 +1392,69 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
for (int p2=0; p2<numpolys; p2++)
{
- RAS_Polygon* poly= meshobj->GetPolygon(p2);
+ MFace* mf = &mface[p2];
+ RAS_Polygon* poly= meshobj->GetPolygon(index[p2]);
// only add polygons that have the collisionflag set
if (poly->IsCollider())
{
- for(i=0; i<poly->VertexCount(); i++) {
- RAS_TexVert *v= poly->GetVertex(i);
- orig_index= v->getOrigIndex();
-
- if (vert_tag_array[orig_index]==true)
- {
- const float* vtx = v->getXYZ();
- vert_tag_array[orig_index]= false;
-
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
- }
+ if (vert_tag_array[mf->v1]==true)
+ {
+ const float* vtx = mvert[mf->v1].co;
+ vert_tag_array[mf->v1]= false;
+ *bt++ = vtx[0];
+ *bt++ = vtx[1];
+ *bt++ = vtx[2];
+ }
+ if (vert_tag_array[mf->v2]==true)
+ {
+ const float* vtx = mvert[mf->v2].co;
+ vert_tag_array[mf->v2]= false;
+ *bt++ = vtx[0];
+ *bt++ = vtx[1];
+ *bt++ = vtx[2];
+ }
+ if (vert_tag_array[mf->v3]==true)
+ {
+ const float* vtx = mvert[mf->v3].co;
+ vert_tag_array[mf->v3]= false;
+ *bt++ = vtx[0];
+ *bt++ = vtx[1];
+ *bt++ = vtx[2];
+ }
+ if (mf->v4 && vert_tag_array[mf->v4]==true)
+ {
+ const float* vtx = mvert[mf->v4].co;
+ vert_tag_array[mf->v4]= false;
+ *bt++ = vtx[0];
+ *bt++ = vtx[1];
+ *bt++ = vtx[2];
}
}
}
}
else {
unsigned int tot_bt_tris= 0;
- vector<int> vert_remap_array(meshobj->GetMesh()->totvert, 0);
+ vector<int> vert_remap_array(numverts, 0);
// Tag verts we're using
for (int p2=0; p2<numpolys; p2++)
{
- RAS_Polygon* poly= meshobj->GetPolygon(p2);
+ MFace* mf = &mface[p2];
+ RAS_Polygon* poly= meshobj->GetPolygon(index[p2]);
// only add polygons that have the collision flag set
if (poly->IsCollider())
{
- for(i=0; i<poly->VertexCount(); i++) {
- orig_index= poly->GetVertex(i)->getOrigIndex();
- if (vert_tag_array[orig_index]==false)
- {
- vert_tag_array[orig_index]= true;
- vert_remap_array[orig_index]= tot_bt_verts;
- tot_bt_verts++;
- }
- }
-
- tot_bt_tris += (i==4 ? 2:1); /* a quad or a tri */
+ if (vert_tag_array[mf->v1]==false)
+ {vert_tag_array[mf->v1]= true;vert_remap_array[mf->v1]= tot_bt_verts;tot_bt_verts++;}
+ if (vert_tag_array[mf->v2]==false)
+ {vert_tag_array[mf->v2]= true;vert_remap_array[mf->v2]= tot_bt_verts;tot_bt_verts++;}
+ if (vert_tag_array[mf->v3]==false)
+ {vert_tag_array[mf->v3]= true;vert_remap_array[mf->v3]= tot_bt_verts;tot_bt_verts++;}
+ if (mf->v4 && vert_tag_array[mf->v4]==false)
+ {vert_tag_array[mf->v4]= true;vert_remap_array[mf->v4]= tot_bt_verts;tot_bt_verts++;}
+ tot_bt_tris += (mf->v4 ? 2:1); /* a quad or a tri */
}
}
@@ -1437,76 +1466,67 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
int *poly_index_pt= &m_polygonIndexArray[0];
int *tri_pt= &m_triFaceArray[0];
-
for (int p2=0; p2<numpolys; p2++)
{
- RAS_Polygon* poly= meshobj->GetPolygon(p2);
+ MFace* mf = &mface[p2];
+ RAS_Polygon* poly= meshobj->GetPolygon(index[p2]);
// only add polygons that have the collisionflag set
if (poly->IsCollider())
{
- RAS_TexVert *v1= poly->GetVertex(0);
- RAS_TexVert *v2= poly->GetVertex(1);
- RAS_TexVert *v3= poly->GetVertex(2);
- int i1= v1->getOrigIndex();
- int i2= v2->getOrigIndex();
- int i3= v3->getOrigIndex();
- const float* vtx;
+ MVert *v1= &mvert[mf->v1];
+ MVert *v2= &mvert[mf->v2];
+ MVert *v3= &mvert[mf->v3];
// the face indicies
- tri_pt[0]= vert_remap_array[i1];
- tri_pt[1]= vert_remap_array[i2];
- tri_pt[2]= vert_remap_array[i3];
+ tri_pt[0]= vert_remap_array[mf->v1];
+ tri_pt[1]= vert_remap_array[mf->v2];
+ tri_pt[2]= vert_remap_array[mf->v3];
tri_pt= tri_pt+3;
// m_polygonIndexArray
- *poly_index_pt= p2;
+ *poly_index_pt= index[p2];
poly_index_pt++;
// the vertex location
- if (vert_tag_array[i1]==true) { /* *** v1 *** */
- vert_tag_array[i1]= false;
- vtx = v1->getXYZ();
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
+ if (vert_tag_array[mf->v1]==true) { /* *** v1 *** */
+ vert_tag_array[mf->v1]= false;
+ *bt++ = v1->co[0];
+ *bt++ = v1->co[1];
+ *bt++ = v1->co[2];
}
- if (vert_tag_array[i2]==true) { /* *** v2 *** */
- vert_tag_array[i2]= false;
- vtx = v2->getXYZ();
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
+ if (vert_tag_array[mf->v2]==true) { /* *** v2 *** */
+ vert_tag_array[mf->v2]= false;
+ *bt++ = v2->co[0];
+ *bt++ = v2->co[1];
+ *bt++ = v2->co[2];
}
- if (vert_tag_array[i3]==true) { /* *** v3 *** */
- vert_tag_array[i3]= false;
- vtx = v3->getXYZ();
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
+ if (vert_tag_array[mf->v3]==true) { /* *** v3 *** */
+ vert_tag_array[mf->v3]= false;
+ *bt++ = v3->co[0];
+ *bt++ = v3->co[1];
+ *bt++ = v3->co[2];
}
- if (poly->VertexCount()==4)
+ if (mf->v4)
{
- RAS_TexVert *v4= poly->GetVertex(3);
- int i4= v4->getOrigIndex();
+ MVert *v4= &mvert[mf->v4];
- tri_pt[0]= vert_remap_array[i1];
- tri_pt[1]= vert_remap_array[i3];
- tri_pt[2]= vert_remap_array[i4];
+ tri_pt[0]= vert_remap_array[mf->v1];
+ tri_pt[1]= vert_remap_array[mf->v3];
+ tri_pt[2]= vert_remap_array[mf->v4];
tri_pt= tri_pt+3;
// m_polygonIndexArray
- *poly_index_pt= p2;
+ *poly_index_pt= index[p2];
poly_index_pt++;
// the vertex location
- if (vert_tag_array[i4]==true) { /* *** v4 *** */
- vert_tag_array[i4]= false;
- vtx = v4->getXYZ();
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
+ if (vert_tag_array[mf->v4]==true) { /* *** v4 *** */
+ vert_tag_array[mf->v4]= false;
+ *bt++ = v4->co[0];
+ *bt++ = v4->co[1];
+ *bt++ = v4->co[2];
}
}
}
@@ -1538,7 +1558,13 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
#endif
m_meshObject = meshobj;
- if (!polytope)
+ if (free_dm) {
+ dm->release(dm);
+ dm = NULL;
+ }
+
+ // sharing only on static mesh at present, if you change that, you must also change in FindMesh
+ if (!polytope && !dm && !useGimpact)
{
// triangle shape can be shared, store the mesh object in the map
m_meshShapeMap.insert(std::pair<RAS_MeshObject*,CcdShapeConstructionInfo*>(meshobj,this));
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index 4ab478b2106..315e2bdf429 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -36,6 +36,7 @@ extern bool gDisableDeactivation;
class CcdPhysicsEnvironment;
class btMotionState;
class RAS_MeshObject;
+struct DerivedMesh;
class btCollisionShape;
@@ -59,7 +60,7 @@ class CcdShapeConstructionInfo
public:
- static CcdShapeConstructionInfo* FindMesh(RAS_MeshObject* mesh, bool polytope);
+ static CcdShapeConstructionInfo* FindMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope, bool gimpact);
CcdShapeConstructionInfo() :
m_shapeType(PHY_SHAPE_NONE),
@@ -139,7 +140,7 @@ public:
return true;
}
- bool SetMesh(RAS_MeshObject* mesh, bool polytope,bool useGimpact);
+ bool SetMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope,bool useGimpact);
RAS_MeshObject* GetMesh(void)
{
return m_meshObject;
diff --git a/source/gameengine/Physics/Bullet/Makefile b/source/gameengine/Physics/Bullet/Makefile
index 48e537bb6a3..19b17de275a 100644
--- a/source/gameengine/Physics/Bullet/Makefile
+++ b/source/gameengine/Physics/Bullet/Makefile
@@ -51,4 +51,6 @@ CPPFLAGS += -I../../Expressions
CPPFLAGS += -I../../GameLogic
CPPFLAGS += -I../../SceneGraph
CPPFLAGS += -I../../../../source/blender/makesdna
+CPPFLAGS += -I../../../../source/blender/blenkernel
+CPPFLAGS += -I../../../../source/blender/blenlib
diff --git a/source/gameengine/Physics/Bullet/SConscript b/source/gameengine/Physics/Bullet/SConscript
index 115ab8bf730..c517d8b5d9d 100644
--- a/source/gameengine/Physics/Bullet/SConscript
+++ b/source/gameengine/Physics/Bullet/SConscript
@@ -14,7 +14,10 @@ incs += ' #source/gameengine/Expressions'
incs += ' #source/gameengine/GameLogic'
incs += ' #source/gameengine/SceneGraph'
incs += ' #source/blender/makesdna'
+incs += ' #source/blender/blenkernel'
+incs += ' #source/blender/blenlib'
incs += ' #intern/SoundSystem'
+incs += ' #intern/guardedalloc'
incs += ' ' + env['BF_BULLET_INC']
incs += ' ' + env['BF_PYTHON_INC']