diff --git a/Extras/BulletColladaConverter/ColladaConverter.cpp b/Extras/BulletColladaConverter/ColladaConverter.cpp index 8efa43cbd..6780d18f0 100644 --- a/Extras/BulletColladaConverter/ColladaConverter.cpp +++ b/Extras/BulletColladaConverter/ColladaConverter.cpp @@ -177,7 +177,9 @@ ColladaConverter::ColladaConverter(btDynamicsWorld* dynaWorld) m_collada(0), m_dom(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(); + trimesh->setUse32bitIndices(m_use32bitIndices); + trimesh->setUse4componentVertices(m_use4componentVertices); for (unsigned int tg = 0;tggetTriangles_array().getCount();tg++) { diff --git a/Extras/BulletColladaConverter/ColladaConverter.h b/Extras/BulletColladaConverter/ColladaConverter.h index c9c9b12ed..54023ccdd 100644 --- a/Extras/BulletColladaConverter/ColladaConverter.h +++ b/Extras/BulletColladaConverter/ColladaConverter.h @@ -39,6 +39,8 @@ protected: char* m_filename; float m_unitMeterScaling; + bool m_use32bitIndices; + bool m_use4componentVertices; 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 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. virtual btTypedConstraint* createUniversalD6Constraint( class btRigidBody* body0,class btRigidBody* otherBody, @@ -125,6 +147,7 @@ public: virtual void setCameraInfo(const btVector3& up, int forwardAxis) { }; + }; #endif //COLLADA_CONVERTER_H diff --git a/Extras/BulletMultiThreaded/PlatformDefinitions.h b/Extras/BulletMultiThreaded/PlatformDefinitions.h index ec349b269..62ddb1412 100644 --- a/Extras/BulletMultiThreaded/PlatformDefinitions.h +++ b/Extras/BulletMultiThreaded/PlatformDefinitions.h @@ -19,8 +19,10 @@ typedef union #endif //__MINGW32__ typedef unsigned char uint8_t; +#ifndef __PHYSICS_COMMON_H__ typedef unsigned long int uint64_t; typedef unsigned int uint32_t; +#endif //__PHYSICS_COMMON_H__ typedef unsigned short uint16_t; #include diff --git a/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp b/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp index 98c54ef45..1f2e20344 100644 --- a/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp +++ b/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp @@ -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); + } } diff --git a/src/BulletCollision/CollisionShapes/btTriangleMesh.h b/src/BulletCollision/CollisionShapes/btTriangleMesh.h index 83e5a56d1..f7ee2cf91 100644 --- a/src/BulletCollision/CollisionShapes/btTriangleMesh.h +++ b/src/BulletCollision/CollisionShapes/btTriangleMesh.h @@ -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 m_vertices; - btAlignedObjectArray m_indices; + btAlignedObjectArray m_4componentVertices; + btAlignedObjectArray m_3componentVertices; + + btAlignedObjectArray m_32bitIndices; + btAlignedObjectArray 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; }