01-02-2022, 02:10 PM
(This post was last modified: 01-02-2022, 02:17 PM by josemendez.)
(01-02-2022, 12:32 PM)MoonBoop Wrote: ah okay, so then I should remove the vertices based stitching completely.
would replacing it with a system that can detect if a particle needs to be stitched based on its position be good?
I'm trying to figure out how to get the particles I need to stitch since the garment generation has seams specified where the garment must stitch
Are you generating the garment meshes programmatically? for instance, delaunay triangulation of a bezier patch. If so there's a good chance that your mesh does not have any uv/normal/color discontinuity (at least not for each individual garment piece). In that case, assuming vertex == particle is ok. This is what I did some time ago for a similar app that used ObiCloth for simulation:
Each garment piece was defined by multiple curves, and the interior area triangulated. Start/end positions in the curves define regions that should be stitched together. The vertex index of these are used as actor particle indices, since there's a 1-1 correspondence between vertex and particle when there's no discontinuities/seams in the mesh.
The stitching code for a "stitch line" (a seam specified as start/end points in two bezier curves) is this:
Code:
public void Commit()
{
stitcher.Clear();
if (!StitchSide.IsValid(sideA) || !StitchSide.IsValid(sideB))
return;
ObiCloth clothA = sideA.pattern.cloth;
ObiCloth clothB = sideB.pattern.cloth;
if (clothA != null && clothB != null)
{
stitcher.Actor1 = clothA;
stitcher.Actor2 = clothB;
int startIndexA = sideA.pattern.GetBoundaryIndexAtMu(sideA.range.x);
int endIndexA = sideA.pattern.GetBoundaryIndexAtMu(sideA.range.y);
int startIndexB = sideB.pattern.GetBoundaryIndexAtMu(sideB.range.x);
int endIndexB = sideB.pattern.GetBoundaryIndexAtMu(sideB.range.y);
int pointRangeA = endIndexA - startIndexA;
int pointRangeB = endIndexB - startIndexB;
int pointCountA = Mathf.Abs(pointRangeA);
int pointCountB = Mathf.Abs(pointRangeB);
if (pointCountA > 0 && pointCountB > 0)
{
float maxCount = Mathf.Max(pointCountA, pointCountB);
float a = 0, b = 0;
while (Mathf.Abs(a) < pointCountA || Mathf.Abs(b) < pointCountB)
{
stitcher.AddStitch(startIndexA + Mathf.RoundToInt(a), startIndexB + Mathf.RoundToInt(b));
a += pointRangeA / maxCount;
b += pointRangeB / maxCount;
}
}
}
stitcher.PushDataToSolver();
onStitchUpdated?.Invoke(this);
}
I know this code doesn't mean much without context, but suffice to say that "startIndexA" and "startIndexB" passed to AddStitch() are vertex indices. When triangulating the garment piece to generate a mesh, I create the vertices at the borders last, this way I have an easy way to identify vertices at the borders: they're always at the end of the mesh vertex list.
Since there's no uv/normal/color discontinuities in the mesh, I know particles and vertices appear in the same order in their respective arrays and there's always one particle per vertex. This allows me to use vertex indices and particle indices interchangeably.
Of course this isn't possible if you do have (or plan to have) discontinuities in your meshes, in that case you can map from vertex index to particle index using the cloth blueprint:
Code:
cloth.clothBlueprintBase.Topology.rawToWelded //<-- this array maps from vertex index to particle index.
int particleIndex = cloth.clothBlueprintBase.Topology.rawToWelded[5]; // get the particle index that corresponds to vertex #5 in the mesh.
let me know if I can be of further help,