If a convex has called 'initializePolyhedralFeatures', use those features also to create debug visualizer mesh, to avoid showing penetration.
Avoid crash in InvertedPendulumPDControl, due to recent change in m_jointFeedbackInWorldSpace
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "btBulletCollisionCommon.h"
|
#include "btBulletCollisionCommon.h"
|
||||||
#include "BulletCollision/CollisionShapes/btShapeHull.h" //to create a tesselation of a generic btConvexShape
|
#include "BulletCollision/CollisionShapes/btShapeHull.h" //to create a tesselation of a generic btConvexShape
|
||||||
|
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
|
||||||
|
|
||||||
void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTransform& parentTransform, btAlignedObjectArray<btVector3>& vertexPositions, btAlignedObjectArray<btVector3>& vertexNormals, btAlignedObjectArray<int>& indicesOut)
|
void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTransform& parentTransform, btAlignedObjectArray<btVector3>& vertexPositions, btAlignedObjectArray<btVector3>& vertexNormals, btAlignedObjectArray<int>& indicesOut)
|
||||||
|
|
||||||
@@ -131,38 +132,71 @@ void CollisionShape2TriangleMesh(btCollisionShape* collisionShape, const btTrans
|
|||||||
{
|
{
|
||||||
btConvexShape* convex = (btConvexShape*)collisionShape;
|
btConvexShape* convex = (btConvexShape*)collisionShape;
|
||||||
{
|
{
|
||||||
btShapeHull* hull = new btShapeHull(convex);
|
|
||||||
hull->buildHull(0.0, 1);
|
const btConvexPolyhedron* pol = 0;
|
||||||
|
if (convex->isPolyhedral())
|
||||||
{
|
{
|
||||||
//int strideInBytes = 9*sizeof(float);
|
btPolyhedralConvexShape* poly = (btPolyhedralConvexShape*)convex;
|
||||||
//int numVertices = hull->numVertices();
|
pol = poly->getConvexPolyhedron();
|
||||||
//int numIndices =hull->numIndices();
|
}
|
||||||
|
|
||||||
for (int t = 0; t < hull->numTriangles(); t++)
|
if (pol)
|
||||||
|
{
|
||||||
|
for (int v = 0; v < pol->m_vertices.size(); v++)
|
||||||
|
{
|
||||||
|
vertexPositions.push_back(pol->m_vertices[v]);
|
||||||
|
btVector3 norm = pol->m_vertices[v];
|
||||||
|
norm.safeNormalize();
|
||||||
|
vertexNormals.push_back(norm);
|
||||||
|
}
|
||||||
|
for (int f = 0; f < pol->m_faces.size(); f++)
|
||||||
{
|
{
|
||||||
btVector3 triNormal;
|
|
||||||
|
|
||||||
int index0 = hull->getIndexPointer()[t * 3 + 0];
|
for (int ii = 2; ii < pol->m_faces[f].m_indices.size(); ii++)
|
||||||
int index1 = hull->getIndexPointer()[t * 3 + 1];
|
|
||||||
int index2 = hull->getIndexPointer()[t * 3 + 2];
|
|
||||||
btVector3 pos0 = parentTransform * hull->getVertexPointer()[index0];
|
|
||||||
btVector3 pos1 = parentTransform * hull->getVertexPointer()[index1];
|
|
||||||
btVector3 pos2 = parentTransform * hull->getVertexPointer()[index2];
|
|
||||||
triNormal = (pos1 - pos0).cross(pos2 - pos0);
|
|
||||||
triNormal.safeNormalize();
|
|
||||||
|
|
||||||
for (int v = 0; v < 3; v++)
|
|
||||||
{
|
{
|
||||||
int index = hull->getIndexPointer()[t * 3 + v];
|
indicesOut.push_back(pol->m_faces[f].m_indices[0]);
|
||||||
btVector3 pos = parentTransform * hull->getVertexPointer()[index];
|
indicesOut.push_back(pol->m_faces[f].m_indices[ii-1]);
|
||||||
indicesOut.push_back(vertexPositions.size());
|
indicesOut.push_back(pol->m_faces[f].m_indices[ii]);
|
||||||
vertexPositions.push_back(pos);
|
|
||||||
vertexNormals.push_back(triNormal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
btShapeHull* hull = new btShapeHull(convex);
|
||||||
|
hull->buildHull(0.0, 1);
|
||||||
|
|
||||||
|
{
|
||||||
|
//int strideInBytes = 9*sizeof(float);
|
||||||
|
//int numVertices = hull->numVertices();
|
||||||
|
//int numIndices =hull->numIndices();
|
||||||
|
|
||||||
|
for (int t = 0; t < hull->numTriangles(); t++)
|
||||||
|
{
|
||||||
|
btVector3 triNormal;
|
||||||
|
|
||||||
|
int index0 = hull->getIndexPointer()[t * 3 + 0];
|
||||||
|
int index1 = hull->getIndexPointer()[t * 3 + 1];
|
||||||
|
int index2 = hull->getIndexPointer()[t * 3 + 2];
|
||||||
|
btVector3 pos0 = parentTransform * hull->getVertexPointer()[index0];
|
||||||
|
btVector3 pos1 = parentTransform * hull->getVertexPointer()[index1];
|
||||||
|
btVector3 pos2 = parentTransform * hull->getVertexPointer()[index2];
|
||||||
|
triNormal = (pos1 - pos0).cross(pos2 - pos0);
|
||||||
|
triNormal.safeNormalize();
|
||||||
|
|
||||||
|
for (int v = 0; v < 3; v++)
|
||||||
|
{
|
||||||
|
int index = hull->getIndexPointer()[t * 3 + v];
|
||||||
|
btVector3 pos = parentTransform * hull->getVertexPointer()[index];
|
||||||
|
indicesOut.push_back(vertexPositions.size());
|
||||||
|
vertexPositions.push_back(pos);
|
||||||
|
vertexNormals.push_back(triNormal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete hull;
|
||||||
}
|
}
|
||||||
delete hull;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -313,13 +313,15 @@ void InvertedPendulumPDControl::initPhysics()
|
|||||||
|
|
||||||
int upAxis = 1;
|
int upAxis = 1;
|
||||||
|
|
||||||
m_dynamicsWorld->getSolverInfo().m_jointFeedbackInWorldSpace = true;
|
|
||||||
m_dynamicsWorld->getSolverInfo().m_jointFeedbackInJointFrame = true;
|
|
||||||
|
|
||||||
|
|
||||||
m_guiHelper->setUpAxis(upAxis);
|
m_guiHelper->setUpAxis(upAxis);
|
||||||
|
|
||||||
this->createEmptyDynamicsWorld();
|
this->createEmptyDynamicsWorld();
|
||||||
|
|
||||||
|
m_dynamicsWorld->getSolverInfo().m_jointFeedbackInWorldSpace = true;
|
||||||
|
m_dynamicsWorld->getSolverInfo().m_jointFeedbackInJointFrame = true;
|
||||||
|
|
||||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||||
m_dynamicsWorld->getDebugDrawer()->setDebugMode(
|
m_dynamicsWorld->getDebugDrawer()->setDebugMode(
|
||||||
//btIDebugDraw::DBG_DrawConstraints
|
//btIDebugDraw::DBG_DrawConstraints
|
||||||
|
|||||||
Reference in New Issue
Block a user