# Why does simple cloth to a single triangle fails to response to collision and gravity(NvCloth)?

I have a piece of cloth (made of a single triangle) that I let it fall on arbitrary triangle meshes (made of two triangles) for collision. The problem I am facing is the cloth just pass through the triangle mesh. The cloth also ignores the gravity value.

// cloth
// vertices
mVertices.emplace_back(4,4,0);
mVertices.emplace_back(8,4,0);
mVertices.emplace_back(4,8,0);
// triangles
mTriangles.emplace_back(0,1,2);

// triangles
std::vectorphysx::PxVec3 triangles;
// triangle 1
triangles.push_back({4,4,4});
triangles.push_back({8,8,4});
triangles.push_back({4,8,4});
// triangle 2
triangles.push_back({4,4,4});
triangles.push_back({8,4,4});
triangles.push_back({8,8,4});

cloth->setSelfCollisionDistance(4.0f);
cloth->setSelfCollisionStiffness(0.9f);

int triangleCount = 2;
nv::cloth::Range triangleR(&triangles[0],
&triangles[0] + triangleCount * 3);

cloth->setTriangles(triangleR, 0, cloth->getNumTriangles());
cloth->setFriction(0.5);

// Note :

physx::PxVec4 spheres[1] = {
physx::PxVec4(0.0f, 0.0f, 3.3f, 3.0f)
};
nv::cloth::Range sphereRange(spheres, spheres + 1);
cloth->setSpheres(sphereRange, 0, cloth->getNumSpheres());
//every thing works fine.

//Another odd thing I noticed was when only using setTriangles. The gravity has no effect. Even //though I place gravity to zero
physx::PxVec3 gravity(0.0f, 0.0f, 0.0f);
// or
physx::PxVec3 gravity(0.0f, 0.0f, 9.8f);
// or
physx::PxVec3 gravity(0.0f, 9.8f, 0.0f);

The cloth stills moves in positive z always ignoring the triangles. The position of cloth triangle goes from 0 to 19.23 in single step.

The problem was the triangles were not in anti-clock wise order. Now the contacts works. I would recommend writing that in the guide.

// from

triangles.push_back({4,4,4});
triangles.push_back({8,8,4});
triangles.push_back({4,8,4});

//
triangles.push_back({4,4,4});
triangles.push_back({8,4,4});
triangles.push_back({8,8,4});

// to

triangles.push_back({4,4,4});
triangles.push_back({4,8,4});
triangles.push_back({8,8,4});

//
triangles.push_back({4,4,4});
triangles.push_back({8,8,4});
triangles.push_back({8,4,4});

Thanks for your feedback, I’ll put it on my todo list to improve the triangle collision documentation.