Just look at the picture:
The colliders are dynamically generated once based on the bone transforms. And are subdevided using a BVH method. But, when I set up the ClothSphereColliderPair[ ], the right legs colliders always fails.
Here is the code how I setup and pass the ClothSphereColliderPair[ ] to the Cloth component:
First, I already have SphereColliders[ ] colliders generated;
private void CreateColliderPairs()
{
List pair = new List();
for (int i = 0; i < refBonesCount; i++)
{
if (skinnedBVHs != null)
{
int parentId = skinnedBVHs*.bvh.id;*
BVHNode.Traverse(skinnedBVHs*.bvh, (BVHNode node) =>*
{
if (node.id != parentId)
{
if (parentId == thighRIndex)
{
Debug.Log("skinnedBVH is thighR");
}
pair.Add(new ClothSphereColliderPair(colliders[node.id], colliders[parentId]));
}
});
}
}
// If I only add the right legs’ colliders in the hard coded way, it would work.
//pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[pelvisIndex].bvh.id], colliders[skinnedBVHs[thighRIndex].bvh.id]));
//pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[pelvisIndex].bvh.id], colliders[skinnedBVHs[thighLIndex].bvh.id]));
//pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[thighLIndex].bvh.id], colliders[skinnedBVHs[calfLIndex].bvh.id]));
//pair.Add(new ClothSphereColliderPair(colliders[skinnedBVHs[thighRIndex].bvh.id], colliders[skinnedBVHs[calfRIndex].bvh.id]));
colliderPairs = new ClothSphereColliderPair[pair.Count];
pair.CopyTo(colliderPairs);
}
As you can see, the ClothSphereColliderPair is created into a List<>, and then copied to the colliderPairs, which is an array.
And for the case to setup the collider pair to the cloth, simply do Cloth.sphereColliders = colliderPairs;
I thought the Cloth component has a limit of 30 for the sphere collider pairs. Anyway my colliderPairs is definitely less than that.