5 hours ago
I have a function that alters skin constraints on a procedurally generated cloth mesh at runtime. The code currently applies the same constraints to the entire cloth, but I’ve realised I need to be able to separate them. Some parts need to be quite tight to prevent creases and crinkles, but tightening everything up prevents other parts of the cloth from moving freely, so it barely looks simulated at all.
I’m looking at the code in ObiSkinnedClothBlueprint for creating constraints, and it’s my understanding that the number of active constraints lines up with the number of clusters in the cloth mesh topology. So I would use each cluster’s vertices to calculate data about the surrounding mesh, and use that to calculate the mesh values.
Is this correct? My code isn’t giving the results I want, but before I redo my own functions to try and fix it, I want to make sure I’m actually applying the values in a way that’s intended. The Obi Cloth code is complicated stuff, and my solution feels suspiciously easy.
Thanks!
I’m looking at the code in ObiSkinnedClothBlueprint for creating constraints, and it’s my understanding that the number of active constraints lines up with the number of clusters in the cloth mesh topology. So I would use each cluster’s vertices to calculate data about the surrounding mesh, and use that to calculate the mesh values.
Is this correct? My code isn’t giving the results I want, but before I redo my own functions to try and fix it, I want to make sure I’m actually applying the values in a way that’s intended. The Obi Cloth code is complicated stuff, and my solution feels suspiciously easy.
Thanks!
Code:
public delegate float CalculateClusterData(ObiMesh.Cluster cluster);
public void ApplySkinConstraints(ObiSkinnedClothBlueprint blueprint, CalculateClusterData getSkinRadiusMultiplier = null, CalculateClusterData getBackStopSphereRadiusMultiplier = null, CalculateClusterData getBackstopSphereDistanceMultiplier = null)
{
ObiSkinConstraintsBatch clothSkinConstraintsBatch = blueprint.skinConstraintsData.batches[0];
for (int i = 0; i < clothSkinConstraintsBatch.activeConstraintCount; i++)
{
float skinRadius = this.skinRadius;
float backstopSphereRadius = this.backstopSphereRadius;
float backstopSphereDistance = this.backstopSphereDistance;
ObiMesh.Cluster cluster = blueprint.topology.clusters[i];
if (getSkinRadiusMultiplier != null) skinRadius *= getSkinRadiusMultiplier.Invoke(cluster);
if (getBackStopSphereRadiusMultiplier != null) backstopSphereRadius *= getBackStopSphereRadiusMultiplier.Invoke(cluster);
if (getBackstopSphereDistanceMultiplier != null) backstopSphereDistance *= getBackstopSphereDistanceMultiplier.Invoke(cluster);
clothSkinConstraintsBatch.skinRadiiBackstop[i * 3] = skinRadius;
clothSkinConstraintsBatch.skinRadiiBackstop[i * 3 + 1] = backstopSphereRadius;
clothSkinConstraintsBatch.skinRadiiBackstop[i * 3 + 2] = backstopSphereDistance;
}
}
