allow to use compression on btTriangleMesh

This commit is contained in:
ejcoumans
2007-03-12 23:19:02 +00:00
parent b2351c84f3
commit 0a5b19864e
2 changed files with 23 additions and 31 deletions

View File

@@ -16,7 +16,6 @@ subject to the following restrictions:
#include "btTriangleMesh.h" #include "btTriangleMesh.h"
#include <assert.h> #include <assert.h>
static int myindices[3] = {0,1,2};
btTriangleMesh::btTriangleMesh () btTriangleMesh::btTriangleMesh ()
{ {
@@ -25,31 +24,29 @@ btTriangleMesh::btTriangleMesh ()
void btTriangleMesh::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) void btTriangleMesh::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart)
{ {
numverts = 3; numverts = m_vertices.size();
*vertexbase = (unsigned char*)&m_triangles[subpart]; *vertexbase = (unsigned char*)&m_vertices[0];
type = PHY_FLOAT; type = PHY_FLOAT;
stride = sizeof(btVector3); stride = sizeof(btVector3);
numfaces = m_indices.size()/3;
numfaces = 1; *indexbase = (unsigned char*) &m_indices[0];
*indexbase = (unsigned char*) &myindices[0];
indicestype = PHY_INTEGER; indicestype = PHY_INTEGER;
indexstride = sizeof(int); indexstride = 3*sizeof(int);
} }
void btTriangleMesh::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const void btTriangleMesh::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const
{ {
numverts = 3; numverts = m_vertices.size();
*vertexbase = (unsigned char*)&m_triangles[subpart]; *vertexbase = (unsigned char*)&m_vertices[0];
type = PHY_FLOAT; type = PHY_FLOAT;
stride = sizeof(btVector3); stride = sizeof(btVector3);
numfaces = m_indices.size()/3;
numfaces = 1; *indexbase = (unsigned char*) &m_indices[0];
*indexbase = (unsigned char*) &myindices[0];
indicestype = PHY_INTEGER; indicestype = PHY_INTEGER;
indexstride = sizeof(int); indexstride = 3*sizeof(int);
} }
@@ -57,5 +54,5 @@ void btTriangleMesh::getLockedReadOnlyVertexIndexBase(const unsigned char **vert
int btTriangleMesh::getNumSubParts() const int btTriangleMesh::getNumSubParts() const
{ {
return m_triangles.size(); return 1;
} }

View File

@@ -20,39 +20,34 @@ subject to the following restrictions:
#include "btStridingMeshInterface.h" #include "btStridingMeshInterface.h"
#include "../../LinearMath/btVector3.h" #include "../../LinearMath/btVector3.h"
#include "../../LinearMath/btAlignedObjectArray.h" #include "../../LinearMath/btAlignedObjectArray.h"
struct btMyTriangle
{
btVector3 m_vert0;
btVector3 m_vert1;
btVector3 m_vert2;
};
///TriangleMesh provides storage for a concave triangle mesh. It can be used as data for the btTriangleMeshShape. ///TriangleMesh provides storage for a concave triangle mesh. It can be used as data for the btTriangleMeshShape.
class btTriangleMesh : public btStridingMeshInterface class btTriangleMesh : public btStridingMeshInterface
{ {
btAlignedObjectArray<btMyTriangle> m_triangles; btAlignedObjectArray<btVector3> m_vertices;
btAlignedObjectArray<int> m_indices;
public: public:
btTriangleMesh (); btTriangleMesh ();
void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2) void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2)
{ {
btMyTriangle tri; int curIndex = m_indices.size();
tri.m_vert0 = vertex0; m_vertices.push_back(vertex0);
tri.m_vert1 = vertex1; m_vertices.push_back(vertex1);
tri.m_vert2 = vertex2; m_vertices.push_back(vertex2);
m_triangles.push_back(tri);
m_indices.push_back(curIndex++);
m_indices.push_back(curIndex++);
m_indices.push_back(curIndex++);
} }
int getNumTriangles() const int getNumTriangles() const
{ {
return m_triangles.size(); return m_indices.size() / 3;
} }
const btMyTriangle& getTriangle(int index) const
{
return m_triangles[index];
}
//StridingMeshInterface interface implementation //StridingMeshInterface interface implementation