-> Stored Selections in Mesh DNA
authorGeoffrey Bantle <hairbat@yahoo.com>
Mon, 3 Apr 2006 19:02:22 +0000 (19:02 +0000)
committerGeoffrey Bantle <hairbat@yahoo.com>
Mon, 3 Apr 2006 19:02:22 +0000 (19:02 +0000)
Stored selections now get saved to mesh library blocks as direct data.
The idea that stored selections are 'erased' when leaving editmode and
switching objects is pretty mysterious for the user. Note that currently
the mselect array in a mesh is not written to file.  Not sure whether
to change this or not.

source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesdna/DNA_meshdata_types.h
source/blender/src/editmesh.c
source/blender/src/editmesh_lib.c

index 2c7386ac45df8eb311925279c013384a34ff9124..aff8c07c9907690788a9bfd1b6fdbaf7bc52305b 100644 (file)
@@ -2209,6 +2209,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
        mesh->bb= NULL;
        mesh->oc= 0;
        mesh->dface= NULL;
+       mesh->mselect= NULL;
        
        if (mesh->tface) {
                TFace *tfaces= mesh->tface;
index e5496c895bc4b23cc67071737fb3a2556cbc61e7..6f477e963c67bdbe8e0e3f2f07f5fe9ee7047332 100644 (file)
@@ -79,11 +79,12 @@ typedef struct Mesh {
        struct MCol *mcol;
        struct MSticky *msticky;
        struct Mesh *texcomesh;
-
+       struct MSelect *mselect;
+       
        struct OcInfo *oc;              /* not written in file */
        void *sumohandle;
 
-       int totvert, totedge, totface;
+       int totvert, totedge, totface, totselect, pad2;
        int texflag;
        
        float loc[3];
index 834c206d8e0e19d39b503490bc06225d2c6d7199..691696f1c803c9fd655810c7acd77067809d31de 100644 (file)
@@ -71,6 +71,10 @@ typedef struct MSticky {
        float co[2];
 } MSticky;
 
+typedef struct MSelect {
+       int index;
+       int type;
+} MSelect;
 /* mvert->flag (1=SELECT) */
 #define ME_SPHERETEST  2
 #define ME_SPHERETEMP  4
@@ -111,3 +115,7 @@ typedef struct MSticky {
 #define ME_FACE_STEPINDEX      (1<<7)
 
 #endif
+/* mselect->type */
+#define ME_VSEl        0
+#define ME_ESEl 1
+#define ME_FSEL 2
index b3c89690bb12d05dea8d6f6af9ba8c0d8b64736b..f2766b9574d8c0cee26d796cbf7c440195e711d4 100644 (file)
@@ -719,16 +719,20 @@ void make_editMesh()
        MFace *mface;
        TFace *tface;
        MVert *mvert;
+       MSelect *mselect;
        KeyBlock *actkey;
        EditVert *eve, **evlist, *eve1, *eve2, *eve3, *eve4;
        EditFace *efa;
        EditEdge *eed;
+       EditSelection *ese;
        int tot, a;
 
        /* because of reload */
        free_editMesh(G.editMesh);
        
        G.totvert= tot= me->totvert;
+       G.totedge= me->totedge;
+       G.totface= me->totface;
 
        if(tot==0) {
                countall();
@@ -848,6 +852,20 @@ void make_editMesh()
 
        end_editmesh_fastmalloc();      // resets global function pointers
        
+       if(me->mselect){
+               //restore editselections
+               EM_init_index_arrays(1,1,1);
+               mselect = me->mselect;
+               for(a=0; a<me->totselect; a++, mselect++){
+                       ese = MEM_callocN(sizeof(EditSelection), "Edit Selection");
+                       ese->type = mselect->type;      
+                       if(ese->type == EDITVERT) ese->data = EM_get_vert_for_index(mselect->index); else
+                       if(ese->type == EDITEDGE) ese->data = EM_get_edge_for_index(mselect->index); else
+                       if(ese->type == EDITFACE) ese->data = EM_get_face_for_index(mselect->index);
+                       BLI_addtail(&(G.editMesh->selected),ese);
+               }
+               EM_free_index_arrays();
+       }
        /* this creates coherent selections. also needed for older files */
        EM_selectmode_set();
        /* paranoia check to enforce hide rules */
@@ -869,9 +887,11 @@ void load_editMesh(void)
        MEdge *medge;
        MFace *mface;
        MSticky *ms;
+       MSelect *mselect;
        EditVert *eve;
        EditFace *efa;
        EditEdge *eed;
+       EditSelection *ese;
        float *fp, *newkey, *oldkey, nor[3];
        int i, a, ototvert, totedge=0;
        MDeformVert *dvert;
@@ -966,6 +986,7 @@ void load_editMesh(void)
        }
 
        /* the edges */
+       a= 0;
        eed= em->edges.first;
        while(eed) {
                medge->v1= (unsigned int) eed->v1->tmp.l;
@@ -979,12 +1000,15 @@ void load_editMesh(void)
                if(eed->h & 1) medge->flag |= ME_HIDE;
                
                medge->crease= (char)(255.0*eed->crease);
-
+               
+               eed->tmp.l = a++;
+               
                medge++;
                eed= eed->next;
        }
 
        /* the faces */
+       a = 0;
        efa= em->faces.first;
        i = 0;
        while(efa) {
@@ -1035,7 +1059,8 @@ void load_editMesh(void)
 
                /* no index '0' at location 3 or 4 */
                test_index_face(mface, NULL, &efa->tf, efa->v4?4:3);
-                       
+               
+               efa->tmp.l = a++;
                i++;
                efa= efa->next;
        }
@@ -1184,6 +1209,23 @@ void load_editMesh(void)
 
        if(oldverts) MEM_freeN(oldverts);
        
+       i = 0;
+       for(ese=em->selected.first; ese; ese=ese->next) i++;
+       me->totselect = i;
+       if(i==0) mselect= NULL;
+       else mselect= MEM_callocN(i*sizeof(MSelect), "loadeditMesh selections");
+       
+       if(me->mselect) MEM_freeN(me->mselect);
+       me->mselect= mselect;
+       
+       for(ese=em->selected.first; ese; ese=ese->next){
+               mselect->type = ese->type;
+               if(ese->type == EDITVERT) mselect->index = ((EditVert*)ese->data)->tmp.l;
+               else if(ese->type == EDITEDGE) mselect->index = ((EditEdge*)ese->data)->tmp.l;
+               else if(ese->type == EDITFACE) mselect->index = ((EditFace*)ese->data)->tmp.l;
+               mselect++;
+       }
+       
        /* to be sure: clear ->tmp.l pointers */
        eve= em->verts.first;
        while(eve) {
@@ -1191,6 +1233,18 @@ void load_editMesh(void)
                eve= eve->next;
        }
        
+       eed= em->edges.first;
+       while(eed) { 
+               eed->tmp.l = 0;
+               eed= eed->next;
+       }
+       
+       efa= em->faces.first;
+       while(efa) {
+               efa->tmp.l = 0;
+               efa= efa->next;
+       }
+       
        /* remake softbody of all users */
        if(me->id.us>1) {
                Base *base;
@@ -1214,8 +1268,6 @@ void load_editMesh(void)
        }
 
        mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
-       
-       BLI_freelistN(&(em->selected)); /*come up with better solution so leaving editmode and not switching meshes will not nuke this...*/
        waitcursor(0);
 }
 
index 88852052eaac375524302c8857c05eefab8e6231..a717e0ed9b92001a0c531cff5a3d56bfd444f179 100644 (file)
@@ -66,13 +66,6 @@ editmesh_lib: generic (no UI, no menus) operations/evaluators for editmesh data
 
 #include "editmesh.h"
 
-
-//TODO
-//fix undo code. Biggest one.
-//fix issues with EM_selectmode_set()
-//get rid of 'lastvert' and 'firstvert' hacks in EditMesh struct and clean from undo code and 'load_editmesh' code and elsewhere
-//find out if storing  EditSelection(s) in Mesh DNA is 'ok', even if only for runtime(?)
-
 /* ********* Selection ************ */
 static int EM_check_selection(void *data)
 {