more code for compound hull collisions

This commit is contained in:
Seth Alves 2015-03-21 16:11:47 -07:00
parent 86d09a1607
commit bfc5cf99d6
3 changed files with 49 additions and 4 deletions

View file

@ -297,9 +297,34 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
_points.clear();
unsigned int i = 0;
foreach (const FBXMesh& mesh, fbxGeometry.meshes) {
QVector<glm::vec3> newMeshPoints;
_points << newMeshPoints;
_points[i++] << mesh.vertices;
foreach (const FBXMeshPart &meshPart, mesh.parts) {
QVector<glm::vec3> pointsInPart;
unsigned int triangleCount = meshPart.triangleIndices.size() / 3;
for (unsigned int i = 0; i < triangleCount; i++) {
unsigned int p0Index = meshPart.triangleIndices[i*3];
unsigned int p1Index = meshPart.triangleIndices[i*3+1];
unsigned int p2Index = meshPart.triangleIndices[i*3+2];
glm::vec3 p0 = mesh.vertices[p0Index];
glm::vec3 p1 = mesh.vertices[p1Index];
glm::vec3 p2 = mesh.vertices[p2Index];
if (!pointsInPart.contains(p0)) {
pointsInPart << p0;
}
if (!pointsInPart.contains(p1)) {
pointsInPart << p1;
}
if (!pointsInPart.contains(p2)) {
pointsInPart << p2;
}
}
QVector<glm::vec3> newMeshPoints;
_points << newMeshPoints;
_points[i++] << pointsInPart;
}
}
info.setParams(getShapeType(), 0.5f * getDimensions(), _collisionModelURL);

View file

@ -116,6 +116,9 @@ void ShapeInfoUtil::collectInfoFromShape(const btCollisionShape* shape, ShapeInf
btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
btCollisionShape* shape = NULL;
qDebug() << "\n\nHERE" << info.getType();
switch(info.getType()) {
case SHAPE_TYPE_BOX: {
shape = new btBoxShape(glmToBullet(info.getHalfExtents()));
@ -145,8 +148,14 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
case SHAPE_TYPE_COMPOUND: {
shape = new btCompoundShape();
const QVector<QVector<glm::vec3>>& points = info.getPoints();
qDebug() << "\n\nSHAPE_TYPE_COMPOUND" << info.getPoints().size() << "hulls.";
foreach (QVector<glm::vec3> hullPoints, info.getPoints()) {
auto hull = new btConvexHullShape();
qDebug() << " SHAPE_TYPE_COMPOUND" << hullPoints.size() << "points in hull.";
foreach (glm::vec3 point, hullPoints) {
btVector3 btPoint(point[0], point[1], point[2]);
hull->addPoint(btPoint);
@ -155,6 +164,9 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) {
static_cast<btCompoundShape*>(shape)->addChildShape (trans, hull);
}
}
qDebug() << "DONE, getNumChildShapes =" << static_cast<btCompoundShape*>(shape)->getNumChildShapes();
break;
}
return shape;

View file

@ -40,6 +40,10 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString
_url = QUrl(url);
_halfExtents = halfExtents;
break;
case SHAPE_TYPE_COMPOUND:
_url = QUrl(url);
_halfExtents = halfExtents;
break;
default:
_halfExtents = halfExtents;
break;
@ -65,7 +69,11 @@ void ShapeInfo::setEllipsoid(const glm::vec3& halfExtents) {
}
void ShapeInfo::setConvexHulls(const QVector<QVector<glm::vec3>>& points) {
_type = SHAPE_TYPE_CONVEX_HULL;
if (points.size() == 1) {
_type = SHAPE_TYPE_CONVEX_HULL;
} else {
_type = SHAPE_TYPE_COMPOUND;
}
_points = points;
}