Fix topology mirror ignoring center verts
authorCampbell Barton <ideasman42@gmail.com>
Wed, 19 Jul 2017 17:29:08 +0000 (03:29 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 19 Jul 2017 17:52:53 +0000 (03:52 +1000)
Caused select-mirror to fail with edges & faces.

source/blender/editors/mesh/editface.c

index a478526dee00a9178b65fbf06312ec6bff503f03..6c6c106b19a78c20f6eedd4b2b716683ed43e09e 100644 (file)
@@ -797,25 +797,47 @@ void ED_mesh_mirrtopo_init(Mesh *me, DerivedMesh *dm, const int ob_mode, MirrTop
 
        qsort(topo_pairs, totvert, sizeof(MirrTopoVert_t), mirrtopo_vert_sort);
 
-       /* Since the loop starts at 2, we must define the last index where the hash's differ */
-       last = ((totvert >= 2) && (topo_pairs[0].hash == topo_pairs[1].hash)) ? 0 : 1;
+       last = 0;
 
        /* Get the pairs out of the sorted hashes, note, totvert+1 means we can use the previous 2,
         * but you cant ever access the last 'a' index of MirrTopoPairs */
-       for (a = 2; a <= totvert; a++) {
-               /* printf("I %d %ld %d\n", (a-last), MirrTopoPairs[a  ].hash, MirrTopoPairs[a  ].v_index ); */
-               if ((a == totvert) || (topo_pairs[a - 1].hash != topo_pairs[a].hash)) {
-                       if (a - last == 2) {
-                               if (em) {
-                                       index_lookup[topo_pairs[a - 1].v_index] = (intptr_t)BM_vert_at_index(em->bm, topo_pairs[a - 2].v_index);
-                                       index_lookup[topo_pairs[a - 2].v_index] = (intptr_t)BM_vert_at_index(em->bm, topo_pairs[a - 1].v_index);
+       if (em) {
+               BMVert **vtable = em->bm->vtable;
+               for (a = 1; a <= totvert; a++) {
+                       /* printf("I %d %ld %d\n", (a - last), MirrTopoPairs[a].hash, MirrTopoPairs[a].v_indexs); */
+                       if ((a == totvert) || (topo_pairs[a - 1].hash != topo_pairs[a].hash)) {
+                               const int match_count = a - last;
+                               if (match_count == 2) {
+                                       const int j = topo_pairs[a - 1].v_index, k = topo_pairs[a - 2].v_index;
+                                       index_lookup[j] = (intptr_t)vtable[k];
+                                       index_lookup[k] = (intptr_t)vtable[j];
+                               }
+                               else if (match_count == 1) {
+                                       /* Center vertex. */
+                                       const int j = topo_pairs[a - 1].v_index;
+                                       index_lookup[j] = (intptr_t)vtable[j];
+                               }
+                               last = a;
+                       }
+               }
+       }
+       else {
+               /* same as above, for mesh */
+               for (a = 1; a <= totvert; a++) {
+                       if ((a == totvert) || (topo_pairs[a - 1].hash != topo_pairs[a].hash)) {
+                               const int match_count = a - last;
+                               if (match_count == 2) {
+                                       const int j = topo_pairs[a - 1].v_index, k = topo_pairs[a - 2].v_index;
+                                       index_lookup[j] = k;
+                                       index_lookup[k] = j;
                                }
-                               else {
-                                       index_lookup[topo_pairs[a - 1].v_index] = topo_pairs[a - 2].v_index;
-                                       index_lookup[topo_pairs[a - 2].v_index] = topo_pairs[a - 1].v_index;
+                               else if (match_count == 1) {
+                                       /* Center vertex. */
+                                       const int j = topo_pairs[a - 1].v_index;
+                                       index_lookup[j] = j;
                                }
+                               last = a;
                        }
-                       last = a;
                }
        }