svn merge -r40000:40179 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / editors / mesh / editmesh.c
index 9bf863f..1634b46 100644 (file)
@@ -1958,3 +1958,96 @@ void em_setup_viewcontext(bContext *C, ViewContext *vc)
                vc->em= me->edit_mesh;
        }
 }
+
+
+/* Jason (similar to void paintface_flush_flags(Object *ob))
+ * copy the vertex flags, most importantly selection from the mesh to the final derived mesh,
+ * use in object mode when selecting vertices (while painting) */
+void paintvert_flush_flags(Object *ob)
+{
+       Mesh *me= get_mesh(ob);
+       DerivedMesh *dm= ob->derivedFinal;
+       MVert *verts, *mv, *mv_orig;
+       int *index_array = NULL;
+       int totvert;
+       int i;
+       
+       if(me==NULL || dm==NULL)
+               return;
+
+       index_array = dm->getVertDataArray(dm, CD_ORIGINDEX);
+       
+       verts = dm->getVertArray(dm);
+       totvert = dm->getNumVerts(dm);
+       
+       mv= verts;
+       
+       for (i= 0; i<totvert; i++, mv++) { /* loop over derived mesh faces */
+               if(index_array) {
+                       mv_orig= me->mvert + index_array[i];
+                       mv->flag= mv_orig->flag;
+               } else {
+                       mv_orig= me->mvert + i;
+                       mv->flag= mv_orig->flag;
+               }
+       }
+}
+/* Jason note: caller needs to run paintvert_flush_flags(ob) after this */
+void paintvert_deselect_all_visible(Object *ob, int action, short flush_flags)
+{
+       Mesh *me;
+       MVert *mvert;
+       int a;
+
+       me= get_mesh(ob);
+       if(me==NULL) return;
+       
+       if(action == SEL_INVERT) {
+               mvert= me->mvert;
+               a= me->totvert;
+               while(a--) {
+                       if((mvert->flag & ME_HIDE) == 0) {
+                               mvert->flag ^= SELECT;
+                       }
+                       mvert++;
+               }
+       }
+       else {
+               if (action == SEL_TOGGLE) {
+                       action = SEL_SELECT;
+
+                       mvert= me->mvert;
+                       a= me->totvert;
+                       while(a--) {
+                               if((mvert->flag & ME_HIDE) == 0 && mvert->flag & SELECT) {
+                                       action = SEL_DESELECT;
+                                       break;
+                               }
+                               mvert++;
+                       }
+               }
+
+               mvert= me->mvert;
+               a= me->totvert;
+               while(a--) {
+                       if((mvert->flag & ME_HIDE) == 0) {
+                               switch (action) {
+                               case SEL_SELECT:
+                                       mvert->flag |= SELECT;
+                                       break;
+                               case SEL_DESELECT:
+                                       mvert->flag &= ~SELECT;
+                                       break;
+                               case SEL_INVERT:
+                                       mvert->flag ^= SELECT;
+                                       break;
+                               }
+                       }
+                       mvert++;
+               }
+       }
+
+       if(flush_flags) {
+               paintvert_flush_flags(ob);
+       }
+}
\ No newline at end of file