-> Stored Selections in Mesh DNA

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.
This commit is contained in:
2006-04-03 19:02:22 +00:00
parent e9a9caee4c
commit cc8051eead
5 changed files with 68 additions and 13 deletions

View File

@@ -2209,6 +2209,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
mesh->bb= NULL; mesh->bb= NULL;
mesh->oc= 0; mesh->oc= 0;
mesh->dface= NULL; mesh->dface= NULL;
mesh->mselect= NULL;
if (mesh->tface) { if (mesh->tface) {
TFace *tfaces= mesh->tface; TFace *tfaces= mesh->tface;

View File

@@ -79,11 +79,12 @@ typedef struct Mesh {
struct MCol *mcol; struct MCol *mcol;
struct MSticky *msticky; struct MSticky *msticky;
struct Mesh *texcomesh; struct Mesh *texcomesh;
struct MSelect *mselect;
struct OcInfo *oc; /* not written in file */ struct OcInfo *oc; /* not written in file */
void *sumohandle; void *sumohandle;
int totvert, totedge, totface; int totvert, totedge, totface, totselect, pad2;
int texflag; int texflag;
float loc[3]; float loc[3];

View File

@@ -71,6 +71,10 @@ typedef struct MSticky {
float co[2]; float co[2];
} MSticky; } MSticky;
typedef struct MSelect {
int index;
int type;
} MSelect;
/* mvert->flag (1=SELECT) */ /* mvert->flag (1=SELECT) */
#define ME_SPHERETEST 2 #define ME_SPHERETEST 2
#define ME_SPHERETEMP 4 #define ME_SPHERETEMP 4
@@ -111,3 +115,7 @@ typedef struct MSticky {
#define ME_FACE_STEPINDEX (1<<7) #define ME_FACE_STEPINDEX (1<<7)
#endif #endif
/* mselect->type */
#define ME_VSEl 0
#define ME_ESEl 1
#define ME_FSEL 2

View File

@@ -719,16 +719,20 @@ void make_editMesh()
MFace *mface; MFace *mface;
TFace *tface; TFace *tface;
MVert *mvert; MVert *mvert;
MSelect *mselect;
KeyBlock *actkey; KeyBlock *actkey;
EditVert *eve, **evlist, *eve1, *eve2, *eve3, *eve4; EditVert *eve, **evlist, *eve1, *eve2, *eve3, *eve4;
EditFace *efa; EditFace *efa;
EditEdge *eed; EditEdge *eed;
EditSelection *ese;
int tot, a; int tot, a;
/* because of reload */ /* because of reload */
free_editMesh(G.editMesh); free_editMesh(G.editMesh);
G.totvert= tot= me->totvert; G.totvert= tot= me->totvert;
G.totedge= me->totedge;
G.totface= me->totface;
if(tot==0) { if(tot==0) {
countall(); countall();
@@ -848,6 +852,20 @@ void make_editMesh()
end_editmesh_fastmalloc(); // resets global function pointers 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 */ /* this creates coherent selections. also needed for older files */
EM_selectmode_set(); EM_selectmode_set();
/* paranoia check to enforce hide rules */ /* paranoia check to enforce hide rules */
@@ -869,9 +887,11 @@ void load_editMesh(void)
MEdge *medge; MEdge *medge;
MFace *mface; MFace *mface;
MSticky *ms; MSticky *ms;
MSelect *mselect;
EditVert *eve; EditVert *eve;
EditFace *efa; EditFace *efa;
EditEdge *eed; EditEdge *eed;
EditSelection *ese;
float *fp, *newkey, *oldkey, nor[3]; float *fp, *newkey, *oldkey, nor[3];
int i, a, ototvert, totedge=0; int i, a, ototvert, totedge=0;
MDeformVert *dvert; MDeformVert *dvert;
@@ -966,6 +986,7 @@ void load_editMesh(void)
} }
/* the edges */ /* the edges */
a= 0;
eed= em->edges.first; eed= em->edges.first;
while(eed) { while(eed) {
medge->v1= (unsigned int) eed->v1->tmp.l; medge->v1= (unsigned int) eed->v1->tmp.l;
@@ -980,11 +1001,14 @@ void load_editMesh(void)
medge->crease= (char)(255.0*eed->crease); medge->crease= (char)(255.0*eed->crease);
eed->tmp.l = a++;
medge++; medge++;
eed= eed->next; eed= eed->next;
} }
/* the faces */ /* the faces */
a = 0;
efa= em->faces.first; efa= em->faces.first;
i = 0; i = 0;
while(efa) { while(efa) {
@@ -1036,6 +1060,7 @@ void load_editMesh(void)
/* no index '0' at location 3 or 4 */ /* no index '0' at location 3 or 4 */
test_index_face(mface, NULL, &efa->tf, efa->v4?4:3); test_index_face(mface, NULL, &efa->tf, efa->v4?4:3);
efa->tmp.l = a++;
i++; i++;
efa= efa->next; efa= efa->next;
} }
@@ -1184,6 +1209,23 @@ void load_editMesh(void)
if(oldverts) MEM_freeN(oldverts); 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 */ /* to be sure: clear ->tmp.l pointers */
eve= em->verts.first; eve= em->verts.first;
while(eve) { while(eve) {
@@ -1191,6 +1233,18 @@ void load_editMesh(void)
eve= eve->next; 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 */ /* remake softbody of all users */
if(me->id.us>1) { if(me->id.us>1) {
Base *base; Base *base;
@@ -1214,8 +1268,6 @@ void load_editMesh(void)
} }
mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL); 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); waitcursor(0);
} }

View File

@@ -66,13 +66,6 @@ editmesh_lib: generic (no UI, no menus) operations/evaluators for editmesh data
#include "editmesh.h" #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 ************ */ /* ********* Selection ************ */
static int EM_check_selection(void *data) static int EM_check_selection(void *data)
{ {