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:
@@ -177,7 +177,9 @@ ColladaConverter::ColladaConverter(btDynamicsWorld* dynaWorld)
|
|||||||
m_collada(0),
|
m_collada(0),
|
||||||
m_dom(0),
|
m_dom(0),
|
||||||
m_filename(0),
|
m_filename(0),
|
||||||
m_unitMeterScaling(1.f)
|
m_unitMeterScaling(1.f),
|
||||||
|
m_use32bitIndices(true),
|
||||||
|
m_use4componentVertices(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2692,6 +2694,8 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
|
|||||||
{
|
{
|
||||||
|
|
||||||
btTriangleMesh* trimesh = new btTriangleMesh();
|
btTriangleMesh* trimesh = new btTriangleMesh();
|
||||||
|
trimesh->setUse32bitIndices(m_use32bitIndices);
|
||||||
|
trimesh->setUse4componentVertices(m_use4componentVertices);
|
||||||
|
|
||||||
for (unsigned int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
|
for (unsigned int tg = 0;tg<meshRef->getTriangles_array().getCount();tg++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ protected:
|
|||||||
char* m_filename;
|
char* m_filename;
|
||||||
|
|
||||||
float m_unitMeterScaling;
|
float m_unitMeterScaling;
|
||||||
|
bool m_use32bitIndices;
|
||||||
|
bool m_use4componentVertices;
|
||||||
|
|
||||||
void PreparePhysicsObject(struct btRigidBodyInput& input, bool isDynamics, float mass,btCollisionShape* colShape, btVector3 linearVelocity, btVector3 angularVelocity);
|
void PreparePhysicsObject(struct btRigidBodyInput& input, bool isDynamics, float mass,btCollisionShape* colShape, btVector3 linearVelocity, btVector3 angularVelocity);
|
||||||
|
|
||||||
@@ -101,6 +103,26 @@ public:
|
|||||||
///if the filename is left empty, modify the filename used during loading
|
///if the filename is left empty, modify the filename used during loading
|
||||||
bool save(const char* filename = 0);
|
bool save(const char* filename = 0);
|
||||||
|
|
||||||
|
void setUse32bitIndices(bool use32bitIndices)
|
||||||
|
{
|
||||||
|
m_use32bitIndices = use32bitIndices;
|
||||||
|
}
|
||||||
|
bool setUse32bitIndices() const
|
||||||
|
{
|
||||||
|
return m_use32bitIndices;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setUse4componentVertices(bool use4componentVertices)
|
||||||
|
{
|
||||||
|
m_use4componentVertices = use4componentVertices;
|
||||||
|
}
|
||||||
|
bool getUse4componentVertices() const
|
||||||
|
{
|
||||||
|
return m_use4componentVertices;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///those virtuals are called by load and save.
|
///those virtuals are called by load and save.
|
||||||
virtual btTypedConstraint* createUniversalD6Constraint(
|
virtual btTypedConstraint* createUniversalD6Constraint(
|
||||||
class btRigidBody* body0,class btRigidBody* otherBody,
|
class btRigidBody* body0,class btRigidBody* otherBody,
|
||||||
@@ -125,6 +147,7 @@ public:
|
|||||||
virtual void setCameraInfo(const btVector3& up, int forwardAxis)
|
virtual void setCameraInfo(const btVector3& up, int forwardAxis)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //COLLADA_CONVERTER_H
|
#endif //COLLADA_CONVERTER_H
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ typedef union
|
|||||||
#endif //__MINGW32__
|
#endif //__MINGW32__
|
||||||
|
|
||||||
typedef unsigned char uint8_t;
|
typedef unsigned char uint8_t;
|
||||||
|
#ifndef __PHYSICS_COMMON_H__
|
||||||
typedef unsigned long int uint64_t;
|
typedef unsigned long int uint64_t;
|
||||||
typedef unsigned int uint32_t;
|
typedef unsigned int uint32_t;
|
||||||
|
#endif //__PHYSICS_COMMON_H__
|
||||||
typedef unsigned short uint16_t;
|
typedef unsigned short uint16_t;
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
|
|
||||||
btTriangleMesh::btTriangleMesh ()
|
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 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;
|
(void)subpart;
|
||||||
numverts = m_vertices.size();
|
if (m_use4componentVertices)
|
||||||
*vertexbase = (unsigned char*)&m_vertices[0];
|
{
|
||||||
|
numverts = m_4componentVertices.size();
|
||||||
|
*vertexbase = (unsigned char*)&m_4componentVertices[0];
|
||||||
type = PHY_FLOAT;
|
type = PHY_FLOAT;
|
||||||
stride = sizeof(btVector3);
|
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;
|
if (m_use32bitIndices)
|
||||||
*indexbase = (unsigned char*) &m_indices[0];
|
{
|
||||||
|
numfaces = m_32bitIndices.size()/3;
|
||||||
|
*indexbase = (unsigned char*) &m_32bitIndices[0];
|
||||||
indicestype = PHY_INTEGER;
|
indicestype = PHY_INTEGER;
|
||||||
indexstride = 3*sizeof(int);
|
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 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;
|
(void)subpart;
|
||||||
numverts = m_vertices.size();
|
|
||||||
*vertexbase = (unsigned char*)&m_vertices[0];
|
if (m_use4componentVertices)
|
||||||
|
{
|
||||||
|
numverts = m_4componentVertices.size();
|
||||||
|
*vertexbase = (unsigned char*)&m_4componentVertices[0];
|
||||||
type = PHY_FLOAT;
|
type = PHY_FLOAT;
|
||||||
stride = sizeof(btVector3);
|
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];
|
if (m_use32bitIndices)
|
||||||
|
{
|
||||||
|
numfaces = m_32bitIndices.size()/3;
|
||||||
|
*indexbase = (unsigned char*) &m_32bitIndices[0];
|
||||||
indicestype = PHY_INTEGER;
|
indicestype = PHY_INTEGER;
|
||||||
indexstride = 3*sizeof(int);
|
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.
|
///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<btVector3> m_vertices;
|
btAlignedObjectArray<btVector3> m_4componentVertices;
|
||||||
btAlignedObjectArray<int> m_indices;
|
btAlignedObjectArray<float> m_3componentVertices;
|
||||||
|
|
||||||
|
btAlignedObjectArray<int> m_32bitIndices;
|
||||||
|
btAlignedObjectArray<short int> m_16bitIndices;
|
||||||
|
bool m_use32bitIndices;
|
||||||
|
bool m_use4componentVertices;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
btTriangleMesh ();
|
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)
|
void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2)
|
||||||
{
|
{
|
||||||
int curIndex = m_indices.size();
|
if (m_use4componentVertices)
|
||||||
m_vertices.push_back(vertex0);
|
{
|
||||||
m_vertices.push_back(vertex1);
|
m_4componentVertices.push_back(vertex0);
|
||||||
m_vertices.push_back(vertex2);
|
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_3componentVertices.push_back(vertex1.getX());
|
||||||
m_indices.push_back(curIndex++);
|
m_3componentVertices.push_back(vertex1.getY());
|
||||||
m_indices.push_back(curIndex++);
|
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
|
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