Skip to content
Snippets Groups Projects
Commit bbcb7423 authored by Fabian Paus's avatar Fabian Paus
Browse files

Support concave object collisions if the object is not dynamic

parent 0ec41fb1
No related branches found
No related tags found
No related merge requests found
......@@ -208,11 +208,11 @@ namespace SimDynamics
return result;
}
btConvexHullShape* BulletObject::createConvexHullShape(VirtualRobot::TriMeshModelPtr trimesh)
btCollisionShape* BulletObject::createConvexHullShape(VirtualRobot::TriMeshModelPtr trimesh)
{
VR_ASSERT(trimesh);
// create triangle shape
btTriangleMesh* btTrimesh = new btTriangleMesh();
btTrimesh.reset(new btTriangleMesh());
//com = trimesh->getCOM();
......@@ -247,25 +247,35 @@ namespace SimDynamics
Eigen::Matrix4f comConv = sceneObject->getGlobalPoseVisualization() * comLoc;
com = comConv.block(0,3,3,1);*/
// build convex hull
boost::shared_ptr<btConvexShape> btConvexShape(new btConvexTriangleMeshShape(btTrimesh));
btConvexShape->setMargin(btMargin);
boost::shared_ptr<btShapeHull> btHull(new btShapeHull(btConvexShape.get()));
btHull->buildHull(btMargin);
btConvexHullShape* btConvex = new btConvexHullShape();
btConvex->setLocalScaling(btVector3(1, 1, 1));
for (int i = 0; i < btHull->numVertices(); i++)
if (sceneObject->getSimulationType() == VirtualRobot::SceneObject::Physics::eKinematic)
{
btConvex->addPoint(btHull->getVertexPointer()[i]);
// Support concave objects if they are not dynamic
return new btBvhTriangleMeshShape(btTrimesh.get(), false);
}
else
{
// build convex hull
boost::shared_ptr<btConvexShape> btConvexShape(new btConvexTriangleMeshShape(btTrimesh.get()));
btConvexShape->setMargin(btMargin);
btConvex->setMargin(btMargin);
boost::shared_ptr<btShapeHull> btHull(new btShapeHull(btConvexShape.get()));
btHull->buildHull(btMargin);
btConvexHullShape* btConvex = new btConvexHullShape();
btConvex->setLocalScaling(btVector3(1, 1, 1));
// trimesh not needed any more
delete btTrimesh;
return btConvex;
for (int i = 0; i < btHull->numVertices(); i++)
{
btConvex->addPoint(btHull->getVertexPointer()[i]);
}
btConvex->setMargin(btMargin);
// Trimesh no longer needed
btTrimesh.reset();
return btConvex;
}
}
boost::shared_ptr<btRigidBody> BulletObject::getRigidBody()
......
......@@ -100,10 +100,11 @@ namespace SimDynamics
void setPoseIntern(const Eigen::Matrix4f& pose);
btCollisionShape* getShapeFromPrimitive(VirtualRobot::Primitive::PrimitivePtr primitive);
btConvexHullShape* createConvexHullShape(VirtualRobot::TriMeshModelPtr trimesh);
btCollisionShape* createConvexHullShape(VirtualRobot::TriMeshModelPtr trimesh);
boost::shared_ptr<btRigidBody> rigidBody;
boost::shared_ptr<btCollisionShape> collisionShape; // bullet collision shape
std::unique_ptr<btTriangleMesh> btTrimesh;
Eigen::Vector3f com; // com offset of trimesh
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment