fcl icon indicating copy to clipboard operation
fcl copied to clipboard

Question: mesh and box collision check?

Open Randa-Almadhoun opened this issue 10 years ago • 2 comments

Hi, I'm trying to check if there is a collision between a mesh model and a Box of volume 1 located at specific point,
The problem I'm facing is that when the Box is located inside the mesh, the collision function returns false (no collision). How can I use fcl to check if there is a collision inside the mesh??

Here is the code used for the collision check: //loading the mesh.obj std::vector<Vec3f> p1; std::vector<Triangle> t1; loadOBJFile("mesh.obj", p1, t1); BVHModel<OBBRSS>* m1 = new BVHModel<OBBRSS>();

m1->beginModel(); m1->addSubModel(p1, t1); m1->endModel();

Transform3f tf1; tf1.setIdentity(); tf1.setTranslation(Vec3f(0,0,0)); CollisionObject* obj = new CollisionObject(boost::shared_ptr<CollisionGeometry>(m1), tf1);

//creating the Box centered at specific point boost::shared_ptr<Box> Sample(new Box(1)); tf0.setIdentity(); tf0.setTranslation(Vec3f(0 , 0 , -5)); CollisionObject co0(Sample, tf0); static const int num_max_contacts = std::numeric_limits::max(); static const bool enable_contact = true ; fcl::CollisionResult result; fcl::CollisionRequest request(num_max_contacts, enable_contact); fcl::collide(&co0, obj, request, result); AABB a = co0.getAABB() ; Vec3f vec2 = a.center() ; if (result.isCollision() == true ) { marker = drawCUBE(vec2,1,2,1) ;//red std::cout<<"Collision"<<std::endl; } else { marker = drawCUBE(vec2, 1, 1,1) ;//blue std::cout<<"No Collision"<<std::endl; }

The model used is as shown below 1

The following is a snap shot of Box and mesh collision ( the mesh is represented as points just for visualization but the model used is as shown in the previous snap shot) 2

Randa-Almadhoun avatar Sep 09 '15 11:09 Randa-Almadhoun

I have the same problem, did you find a solution?

michaelaeriksen avatar Mar 17 '16 16:03 michaelaeriksen

@Randa-Almadhoun @michaelaeriksen Hello, I mentioned a question in this kind of type, I am using BVHModel, how do I get so triangle mesh, it currently results just a boundary. https://github.com/coal-library/coal/issues/706#issue-3072792041 Looking forward to your reply!

hazidh avatar May 24 '25 03:05 hazidh