diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-30 23:20:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-30 23:20:17 +0400 |
commit | 00acdb629254b680992f1863a1d62cd2985198af (patch) | |
tree | e29b23a247a6111dc47f508cab01e2a5d955b983 /source/gameengine/Physics | |
parent | 6bd18e357563f6b28f7cfdf6da8a032bab947172 (diff) |
remove CD_POLYINDEX customdata layer:
reported as [#29376] BMESH_TODO: remove tessface CD_ORIGINDEX layer
for a single mesh there could be 3 origindex mappings stored, one on the polygons and 2 on the tessfaces.
(CD_POLYINDEX and CD_ORIGINDEX).
as Andrew suggests, now tessfaces (which are really a cache of polygons), using origindex to point to polygons on
the same derived mesh, and polygons only store the original index values.
Diffstat (limited to 'source/gameengine/Physics')
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsController.cpp | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 568c11a0be4..ce0e0dd2c5c 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -46,9 +46,11 @@ subject to the following restrictions: #include "DNA_meshdata_types.h" extern "C"{ -#include "BKE_cdderivedmesh.h" + #include "BLI_utildefines.h" + #include "BKE_cdderivedmesh.h" } + class BP_Proxy; ///todo: fill all the empty CcdPhysicsController methods, hook them up to the btRigidBody class @@ -1500,9 +1502,15 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, MFace *mface = dm->getTessFaceArray(dm); numpolys = dm->getNumTessFaces(dm); numverts = dm->getNumVerts(dm); - int* index = (int*)dm->getTessFaceDataArray(dm, CD_ORIGINDEX); MTFace *tface = (MTFace *)dm->getTessFaceDataArray(dm, CD_MTFACE); + /* double lookup */ + const int *index_mf_to_mpoly = (const int *)dm->getTessFaceDataArray(dm, CD_ORIGINDEX); + const int *index_mp_to_orig = (const int *)dm->getPolyDataArray(dm, CD_ORIGINDEX); + if ((index_mf_to_mpoly && index_mp_to_orig) == false) { + index_mf_to_mpoly = index_mp_to_orig = NULL; + } + m_shapeType = (polytope) ? PHY_SHAPE_POLYTOPE : PHY_SHAPE_MESH; /* Convert blender geometry into bullet mesh, need these vars for mapping */ @@ -1515,7 +1523,8 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, for (int p2=0; p2<numpolys; p2++) { MFace* mf = &mface[p2]; - RAS_Polygon* poly = meshobj->GetPolygon((index)? index[p2]: p2); + const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2; + RAS_Polygon* poly = meshobj->GetPolygon(origi); // only add polygons that have the collision flag set if (poly->IsCollider()) @@ -1534,7 +1543,8 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, for (int p2=0; p2<numpolys; p2++) { MFace* mf = &mface[p2]; - RAS_Polygon* poly= meshobj->GetPolygon((index)? index[p2]: p2); + const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2; + RAS_Polygon* poly= meshobj->GetPolygon(origi); // only add polygons that have the collisionflag set if (poly->IsCollider()) @@ -1582,7 +1592,8 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, for (int p2=0; p2<numpolys; p2++) { MFace* mf = &mface[p2]; - RAS_Polygon* poly= meshobj->GetPolygon((index)? index[p2]: p2); + const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2; + RAS_Polygon* poly= meshobj->GetPolygon(origi); // only add polygons that have the collision flag set if (poly->IsCollider()) @@ -1619,7 +1630,8 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, { MFace* mf = &mface[p2]; MTFace* tf = (tface) ? &tface[p2] : NULL; - RAS_Polygon* poly= meshobj->GetPolygon((index)? index[p2]: p2); + const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2; + RAS_Polygon* poly= meshobj->GetPolygon(origi); // only add polygons that have the collisionflag set if (poly->IsCollider()) @@ -1645,7 +1657,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, } // m_polygonIndexArray - *poly_index_pt= (index)? index[p2]: p2; + *poly_index_pt = origi; poly_index_pt++; // the vertex location @@ -1688,7 +1700,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, } // m_polygonIndexArray - *poly_index_pt= (index)? index[p2]: p2; + *poly_index_pt = origi; poly_index_pt++; // the vertex location @@ -1800,7 +1812,13 @@ bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject* gameobj, class RA MFace *mface = dm->getTessFaceArray(dm); numpolys = dm->getNumTessFaces(dm); numverts = dm->getNumVerts(dm); - int* index = (int*)dm->getTessFaceDataArray(dm, CD_ORIGINDEX); + + /* double lookup */ + const int *index_mf_to_mpoly = (const int *)dm->getTessFaceDataArray(dm, CD_ORIGINDEX); + const int *index_mp_to_orig = (const int *)dm->getPolyDataArray(dm, CD_ORIGINDEX); + if ((index_mf_to_mpoly && index_mp_to_orig) == false) { + index_mf_to_mpoly = index_mp_to_orig = NULL; + } MFace *mf; MVert *mv; @@ -1856,7 +1874,7 @@ bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject* gameobj, class RA { if (tf->mode & TF_DYNAMIC) { - int origi = (index)? index[i]: i; + int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i; if (mf->v4) { fv_pt= quad_verts; @@ -1915,7 +1933,7 @@ bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject* gameobj, class RA } for (mf= mface, i=0; i < numpolys; mf++, i++) { - int origi = (index)? index[i]: i; + int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i; if (mf->v4) { fv_pt= quad_verts; |