add support for 16bit indices and 3-float vertices (instead of btVector3 which is 4float) in
in btTriangleMesh container and ColladaConverter. compile issue with PlatformDefinitions in GDC demo.
This commit is contained in:
@@ -18,6 +18,8 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
btTriangleMesh::btTriangleMesh ()
|
||||
:m_use32bitIndices(true),
|
||||
m_use4componentVertices(true)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -25,31 +27,68 @@ 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)subpart;
|
||||
numverts = m_vertices.size();
|
||||
*vertexbase = (unsigned char*)&m_vertices[0];
|
||||
type = PHY_FLOAT;
|
||||
stride = sizeof(btVector3);
|
||||
if (m_use4componentVertices)
|
||||
{
|
||||
numverts = m_4componentVertices.size();
|
||||
*vertexbase = (unsigned char*)&m_4componentVertices[0];
|
||||
type = PHY_FLOAT;
|
||||
stride = sizeof(btVector3);
|
||||
} else
|
||||
{
|
||||
numverts = m_3componentVertices.size();
|
||||
*vertexbase = (unsigned char*)&m_3componentVertices[0];
|
||||
type = PHY_FLOAT;
|
||||
stride = 3*sizeof(btScalar);
|
||||
}
|
||||
|
||||
numfaces = m_indices.size()/3;
|
||||
*indexbase = (unsigned char*) &m_indices[0];
|
||||
indicestype = PHY_INTEGER;
|
||||
indexstride = 3*sizeof(int);
|
||||
if (m_use32bitIndices)
|
||||
{
|
||||
numfaces = m_32bitIndices.size()/3;
|
||||
*indexbase = (unsigned char*) &m_32bitIndices[0];
|
||||
indicestype = PHY_INTEGER;
|
||||
indexstride = 3*sizeof(int);
|
||||
} else
|
||||
{
|
||||
numfaces = m_16bitIndices.size()/3;
|
||||
*indexbase = (unsigned char*) &m_16bitIndices[0];
|
||||
indicestype = PHY_SHORT;
|
||||
indexstride = 3*sizeof(short 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)subpart;
|
||||
numverts = m_vertices.size();
|
||||
*vertexbase = (unsigned char*)&m_vertices[0];
|
||||
type = PHY_FLOAT;
|
||||
stride = sizeof(btVector3);
|
||||
|
||||
numfaces = m_indices.size()/3;
|
||||
*indexbase = (unsigned char*) &m_indices[0];
|
||||
indicestype = PHY_INTEGER;
|
||||
indexstride = 3*sizeof(int);
|
||||
if (m_use4componentVertices)
|
||||
{
|
||||
numverts = m_4componentVertices.size();
|
||||
*vertexbase = (unsigned char*)&m_4componentVertices[0];
|
||||
type = PHY_FLOAT;
|
||||
stride = sizeof(btVector3);
|
||||
} else
|
||||
{
|
||||
numverts = m_3componentVertices.size();
|
||||
*vertexbase = (unsigned char*)&m_3componentVertices[0];
|
||||
type = PHY_FLOAT;
|
||||
stride = 3*sizeof(btScalar);
|
||||
}
|
||||
|
||||
|
||||
if (m_use32bitIndices)
|
||||
{
|
||||
numfaces = m_32bitIndices.size()/3;
|
||||
*indexbase = (unsigned char*) &m_32bitIndices[0];
|
||||
indicestype = PHY_INTEGER;
|
||||
indexstride = 3*sizeof(int);
|
||||
} else
|
||||
{
|
||||
numfaces = m_16bitIndices.size()/3;
|
||||
*indexbase = (unsigned char*) &m_16bitIndices[0];
|
||||
indicestype = PHY_SHORT;
|
||||
indexstride = 3*sizeof(short int);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,27 +24,80 @@ subject to the following restrictions:
|
||||
///TriangleMesh provides storage for a concave triangle mesh. It can be used as data for the btTriangleMeshShape.
|
||||
class btTriangleMesh : public btStridingMeshInterface
|
||||
{
|
||||
btAlignedObjectArray<btVector3> m_vertices;
|
||||
btAlignedObjectArray<int> m_indices;
|
||||
btAlignedObjectArray<btVector3> m_4componentVertices;
|
||||
btAlignedObjectArray<float> m_3componentVertices;
|
||||
|
||||
btAlignedObjectArray<int> m_32bitIndices;
|
||||
btAlignedObjectArray<short int> m_16bitIndices;
|
||||
bool m_use32bitIndices;
|
||||
bool m_use4componentVertices;
|
||||
|
||||
|
||||
public:
|
||||
btTriangleMesh ();
|
||||
|
||||
void setUse32bitIndices(bool use32bitIndices)
|
||||
{
|
||||
m_use32bitIndices = use32bitIndices;
|
||||
}
|
||||
bool getUse32bitIndices() const
|
||||
{
|
||||
return m_use32bitIndices;
|
||||
}
|
||||
|
||||
void setUse4componentVertices(bool use4componentVertices)
|
||||
{
|
||||
m_use4componentVertices = use4componentVertices;
|
||||
}
|
||||
bool getUse4componentVertices() const
|
||||
{
|
||||
return m_use4componentVertices;
|
||||
}
|
||||
|
||||
void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2)
|
||||
{
|
||||
int curIndex = m_indices.size();
|
||||
m_vertices.push_back(vertex0);
|
||||
m_vertices.push_back(vertex1);
|
||||
m_vertices.push_back(vertex2);
|
||||
if (m_use4componentVertices)
|
||||
{
|
||||
m_4componentVertices.push_back(vertex0);
|
||||
m_4componentVertices.push_back(vertex1);
|
||||
m_4componentVertices.push_back(vertex2);
|
||||
} else
|
||||
{
|
||||
m_3componentVertices.push_back(vertex0.getX());
|
||||
m_3componentVertices.push_back(vertex0.getY());
|
||||
m_3componentVertices.push_back(vertex0.getZ());
|
||||
|
||||
m_indices.push_back(curIndex++);
|
||||
m_indices.push_back(curIndex++);
|
||||
m_indices.push_back(curIndex++);
|
||||
m_3componentVertices.push_back(vertex1.getX());
|
||||
m_3componentVertices.push_back(vertex1.getY());
|
||||
m_3componentVertices.push_back(vertex1.getZ());
|
||||
|
||||
m_3componentVertices.push_back(vertex2.getX());
|
||||
m_3componentVertices.push_back(vertex2.getY());
|
||||
m_3componentVertices.push_back(vertex2.getZ());
|
||||
}
|
||||
|
||||
if (m_use32bitIndices)
|
||||
{
|
||||
int curIndex = m_32bitIndices.size();
|
||||
m_32bitIndices.push_back(curIndex++);
|
||||
m_32bitIndices.push_back(curIndex++);
|
||||
m_32bitIndices.push_back(curIndex++);
|
||||
} else
|
||||
{
|
||||
int curIndex = m_16bitIndices.size();
|
||||
m_16bitIndices.push_back(curIndex++);
|
||||
m_16bitIndices.push_back(curIndex++);
|
||||
m_16bitIndices.push_back(curIndex++);
|
||||
}
|
||||
}
|
||||
|
||||
int getNumTriangles() const
|
||||
{
|
||||
return m_indices.size() / 3;
|
||||
if (m_use32bitIndices)
|
||||
{
|
||||
return m_32bitIndices.size() / 3;
|
||||
}
|
||||
return m_16bitIndices.size() / 3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user