Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Stitcher 's problem
#10
(10-08-2020, 12:18 PM)josemendez Wrote: Hi there,

In your OnGizmos 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 vertices of the mesh every iteration fo 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 meshA.mesh instead of meshA.sharedMesh. This is clearly stated in Unity's documentation:

https://docs.unity3d.com/ScriptReference...-mesh.html

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.
Thank you very much, you help me a lot.
In the future, I will pay attention to these programming details, and strive to write high-quality code.
Cheers.
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