private static void FixVertices(ref MeshData m)
        {
            Dictionary <Vector3, List <SharedTriangle> > triangleList = new Dictionary <Vector3, List <SharedTriangle> >();
            int counter = 0;

            // loop through all triangles and create a list of all triangles that share a vertice that has an x, y or z value of 0
            for (int i = 0; i < m.Triangles.Count;)
            {
                SharedTriangle t = new SharedTriangle {
                    Index = i, A = m.Triangles[i++], B = m.Triangles[i++], C = m.Triangles[i++]
                };
                Vector3 av = m.Vertices[t.A];
                Vector3 bv = m.Vertices[t.B];
                Vector3 cv = m.Vertices[t.C];
                AddTriangleIfNeeded(triangleList, ref av, ref t, ref t.AShared, ref counter);
                AddTriangleIfNeeded(triangleList, ref bv, ref t, ref t.BShared, ref counter);
                AddTriangleIfNeeded(triangleList, ref cv, ref t, ref t.CShared, ref counter);
            }

            foreach (KeyValuePair <Vector3, List <SharedTriangle> > kv in triangleList)
            {
                Vector3 v = kv.Key;
                FixTriangle(ref v, kv.Value, ref m);
            }
        }
 private static void AddTriangleIfNeeded(Dictionary <Vector3, List <SharedTriangle> > triangleList, ref Vector3 v, ref SharedTriangle t, ref bool shareVar, ref int counter)
 {
     if (v.x == 0.0f || v.y == 0.0f || v.z == 0.0f)
     {
         List <SharedTriangle> list;
         if (!triangleList.TryGetValue(v, out list))
         {
             list            = new List <SharedTriangle>();
             triangleList[v] = list;
         }
         shareVar = true;
         list.Add(t);
         counter++;
     }
 }