Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Stitcher 's problem
#9
(10-08-2020, 11:21 AM)jackdos Wrote: HI,this is my demo project with the CursorStitch Component.CursorStitchDemo
steps:
1. press Play;
2. press the left mouse button, to select the sewing area between the two patches;
3. press R key, to flip the points on the second patch;
4. press S key, to sewing the two patches.

Hi there,

In your OnDrawGizmos method, you're constantly doing the equivalent to this:

Code:
for (int i = 0; i < count; i++)
meshFilter.mesh.vertices[i]

This is extremely slow, creates a lot of garbage (as you're requesting a copy of all mesh vertices every iteration of the for loop, that the GC has to collect) and will also result in incorrect behavior as you're creating a new instance of the cloth mesh by calling meshFilter.mesh instead of meshFilter.sharedMesh. This is clearly stated in Unity's documentation:

https://docs.unity3d.com/ScriptReference...-mesh.html
Quote:If a mesh is assigned to the mesh filter already, then first query of mesh property will create a duplicate of it, and this copy will be returned. Further queries of mesh property will return this duplicated mesh instance. Once mesh property is queried, link to the original shared mesh is lost and MeshFilter.sharedMesh property becomes an alias to mesh. If you want to avoid this automatic mesh duplication, use MeshFilter.sharedMesh instead.

Calling meshFilter.mesh completely ditches the deformed mesh created by Obi and replaces it with a copy of the original, undeformed mesh. That's why you don't see the mesh moving at all.

Instead, you want something that looks like this:

Code:
// grab the original mesh (not a copy of it) and request a copy of its vertices, only once.
Vector3[] vertices = meshA.sharedMesh.vertices;

// reuse our copy of the vertices for all iterations:
for (int i = 0; i < gatherA.Count; i++)
{
      Vector3 p1 = meshA.transform.TransformPoint(vertices[gatherA[i].v1]);
      Vector3 p2 = meshA.transform.TransformPoint(vertices[gatherA[i].v2]);
      Gizmos.DrawLine(p1, p2);
}

Same for meshB.
Reply


Messages In This Thread
Obi Stitcher 's problem - by jackdos - 06-08-2020, 12:24 PM
RE: Obi Stitcher 's problem - by josemendez - 06-08-2020, 12:31 PM
RE: Obi Stitcher 's problem - by jackdos - 06-08-2020, 12:32 PM
RE: Obi Stitcher 's problem - by jackdos - 07-08-2020, 01:17 PM
RE: Obi Stitcher 's problem - by josemendez - 07-08-2020, 01:20 PM
RE: Obi Stitcher 's problem - by jackdos - 07-08-2020, 01:32 PM
RE: Obi Stitcher 's problem - by josemendez - 07-08-2020, 02:36 PM
RE: Obi Stitcher 's problem - by jackdos - 10-08-2020, 11:21 AM
RE: Obi Stitcher 's problem - by josemendez - 10-08-2020, 12:18 PM
RE: Obi Stitcher 's problem - by jackdos - 10-08-2020, 12:38 PM
RE: Obi Stitcher 's problem - by josemendez - 10-08-2020, 12:40 PM