diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-09-22 21:54:13 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-09-22 21:54:13 +0400 |
commit | aee06ac0d0ebe22c6156808fcc4d87aca1fbea10 (patch) | |
tree | 444def3be57a5c2134cdff13060c47ccdc7ddb46 /source/blender | |
parent | d5b186ba6bac1e41a87aa4d9153a30a4091524f4 (diff) |
added an active face for the mesh editmode and normal mesh - this is needed because the TFace flag was not always easy to access from editmode.
using the last selected face was almost good enough however when selecting verts and edges the last selected face would become inactive and the space image would flicker about too much.
The active face is used for getting the space image at the moment and keeps scripts that use this flag working also.
This has 2 commands to get and set, so the variable is not accessed directly.
all "UV Calculate" scripts work now
last commit crashed when in solid draw mode, it seems subsurf modifier is ignoring the displayMask since MTFACE is available. just made it do a null check for now.
uvcalc_follow_active_coords.py - should be done inC and put in the snap menu.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 36 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_editVert.h | 7 | ||||
-rw-r--r-- | source/blender/include/BIF_editmesh.h | 3 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_mesh_types.h | 9 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_meshdata_types.h | 2 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 46 | ||||
-rw-r--r-- | source/blender/python/api2_2x/NMesh.c | 13 | ||||
-rw-r--r-- | source/blender/src/drawimage.c | 1 | ||||
-rw-r--r-- | source/blender/src/drawmesh.c | 6 | ||||
-rw-r--r-- | source/blender/src/editface.c | 43 | ||||
-rw-r--r-- | source/blender/src/editmesh.c | 13 | ||||
-rw-r--r-- | source/blender/src/editmesh_lib.c | 11 | ||||
-rw-r--r-- | source/blender/src/editmesh_mods.c | 2 | ||||
-rw-r--r-- | source/blender/src/editsima.c | 15 |
15 files changed, 111 insertions, 97 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 3a64c3504cb..ff84b3c08f8 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -243,6 +243,7 @@ static Image *image_alloc(const char *name, short source, short type) ima->ok= IMA_OK; ima->xrep= ima->yrep= 1; + ima->aspx= ima->aspy= 1.0; ima->gen_x= 256; ima->gen_y= 256; ima->gen_type= 1; /* no defines yet? */ diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 39674c9796f..646157991bb 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -1881,28 +1881,30 @@ static void ccgDM_drawUVEdges(DerivedMesh *dm) MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE); int i; - glBegin(GL_LINES); - for(i = 0; i < dm->numFaceData; i++, mf++, tf++) { - if(!(mf->flag&ME_HIDE)) { - glVertex2fv(tf->uv[0]); - glVertex2fv(tf->uv[1]); - - glVertex2fv(tf->uv[1]); - glVertex2fv(tf->uv[2]); - - if(!mf->v4) { - glVertex2fv(tf->uv[2]); + if (tf) { + glBegin(GL_LINES); + for(i = 0; i < dm->numFaceData; i++, mf++, tf++) { + if(!(mf->flag&ME_HIDE)) { glVertex2fv(tf->uv[0]); - } else { + glVertex2fv(tf->uv[1]); + + glVertex2fv(tf->uv[1]); glVertex2fv(tf->uv[2]); - glVertex2fv(tf->uv[3]); - - glVertex2fv(tf->uv[3]); - glVertex2fv(tf->uv[0]); + + if(!mf->v4) { + glVertex2fv(tf->uv[2]); + glVertex2fv(tf->uv[0]); + } else { + glVertex2fv(tf->uv[2]); + glVertex2fv(tf->uv[3]); + + glVertex2fv(tf->uv[3]); + glVertex2fv(tf->uv[0]); + } } } + glEnd(); } - glEnd(); } static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors) { diff --git a/source/blender/blenlib/BLI_editVert.h b/source/blender/blenlib/BLI_editVert.h index c05d33f2792..fd217e479ed 100644 --- a/source/blender/blenlib/BLI_editVert.h +++ b/source/blender/blenlib/BLI_editVert.h @@ -164,6 +164,13 @@ typedef struct EditMesh /* DerivedMesh caches... note that derived cage can be equivalent * to derived final, care should be taken on release. */ + + /* used for keeping track of the last clicked on face - so the space image + * when using the last selected face - (EditSelection) the space image flickered too much + * + * never access this directly, use EM_set_actFace and EM_get_actFace */ + EditFace *act_face; + struct DerivedMesh *derivedCage, *derivedFinal; /* the custom data layer mask that was last used to calculate * derivedCage and derivedFinal diff --git a/source/blender/include/BIF_editmesh.h b/source/blender/include/BIF_editmesh.h index 6539fe00b80..7ad3fd480a3 100644 --- a/source/blender/include/BIF_editmesh.h +++ b/source/blender/include/BIF_editmesh.h @@ -259,4 +259,7 @@ void free_uv_vert_map_EM(UvVertMap *vmap); int EM_texFaceCheck(void); /* can we edit UV's for this mesh?*/ int EM_vertColorCheck(void); /* can we edit colors for this mesh?*/ +void EM_set_actFace(struct EditFace *efa); +struct EditFace * EM_get_actFace(void); + #endif diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 953c8176962..59f3a64ba5e 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -74,7 +74,14 @@ typedef struct Mesh { struct CustomData vdata, edata, fdata; - int totvert, totedge, totface, totselect, pad2; + int totvert, totedge, totface, totselect; + + /* the last selected vertex/edge/face are used for the active face however + * this means the active face must always be selected, this is to keep track + * of the last selected face and is similar to the old active face flag where + * the face does not need to be selected, -1 is inactive */ + int act_face; + int texflag; /* texture space, copied as one block in editobject.c */ diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index 2cbe03ab4cc..68d9bb245cf 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -204,7 +204,7 @@ typedef struct PartialVisibility { /* mtface->flag */ #define TF_SELECT 1 /* use MFace hide flag (after 2.43), should be able to reuse after 2.44 */ -#define TF_ACTIVE 2 +#define TF_ACTIVE 2 /* deprecated! */ #define TF_SEL1 4 #define TF_SEL2 8 #define TF_SEL3 16 diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index d2cc1edf3c3..659ecd79d81 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -4077,7 +4077,7 @@ static int MFace_setImage( BPy_MFace *self, PyObject *value ) return 0; } -#define MFACE_FLAG_BITMASK ( TF_SELECT | TF_ACTIVE | TF_SEL1 | \ +#define MFACE_FLAG_BITMASK ( TF_SELECT | TF_SEL1 | \ TF_SEL2 | TF_SEL3 | TF_SEL4 | TF_HIDE ) /* @@ -4086,6 +4086,7 @@ static int MFace_setImage( BPy_MFace *self, PyObject *value ) static PyObject *MFace_getFlag( BPy_MFace *self ) { + int flag; if( !self->mesh->mtface ) return EXPP_ReturnPyObjError( PyExc_ValueError, "face has no texture values" ); @@ -4093,8 +4094,13 @@ static PyObject *MFace_getFlag( BPy_MFace *self ) if( !MFace_get_pointer( self ) ) return NULL; - return PyInt_FromLong( (long) ( self->mesh->mtface[self->index].flag - & MFACE_FLAG_BITMASK ) ); + flag = self->mesh->mtface[self->index].flag & MFACE_FLAG_BITMASK; + + /* so old scripts still work */ + if (self->index == self->mesh->act_face) + flag |= TF_ACTIVE; + + return PyInt_FromLong( (long)( flag ) ); } /* @@ -4128,7 +4134,7 @@ static int MFace_setFlag( BPy_MFace *self, PyObject *value ) "invalid bit(s) set in mask" ); /* merge active setting with other new params */ - param |= (self->mesh->mtface[self->index].flag & TF_ACTIVE); + param |= (self->mesh->mtface[self->index].flag); self->mesh->mtface[self->index].flag = (char)param; return 0; @@ -7869,27 +7875,19 @@ static PyObject *Mesh_getKey( BPy_Mesh * self ) static PyObject *Mesh_getActiveFace( BPy_Mesh * self ) { - MTFace *face; - int i, totface; - + /* not needed but keep incase exceptions make use of it */ if( !self->mesh->mtface ) return EXPP_ReturnPyObjError( PyExc_ValueError, "face has no texture values" ); - face = self->mesh->mtface; - totface = self->mesh->totface; - - for( i = 0; i < totface; ++face, ++i ) - if( face->flag & TF_ACTIVE ) { - return PyInt_FromLong( i ); - } - + if (self->mesh->act_face != -1 && self->mesh->act_face <= self->mesh->totface) + return PyInt_FromLong( self->mesh->act_face ); + Py_RETURN_NONE; } static int Mesh_setActiveFace( BPy_Mesh * self, PyObject * value ) { - MTFace *face; int param; /* if no texture faces, error */ @@ -7910,18 +7908,8 @@ static int Mesh_setActiveFace( BPy_Mesh * self, PyObject * value ) if( param < 0 || param > self->mesh->totface ) return EXPP_ReturnIntError( PyExc_TypeError, "face index out of range" ); - - face = self->mesh->mtface; - - /* if requested face isn't already active, then inactivate all - * faces and activate the requested one */ - - if( !( face[param].flag & TF_ACTIVE ) ) { - int i; - for( i = self->mesh->totface; i > 0; ++face, --i ) - face->flag &= ~TF_ACTIVE; - self->mesh->mtface[param].flag |= TF_ACTIVE; - } + + self->mesh->act_face = param; return 0; } @@ -8500,7 +8488,7 @@ static PyObject *M_Mesh_FaceFlagsDict( void ) PyConstant_Insert( d, "SELECT", PyInt_FromLong( TF_SELECT ) ); PyConstant_Insert( d, "HIDE", PyInt_FromLong( TF_HIDE ) ); - PyConstant_Insert( d, "ACTIVE", PyInt_FromLong( TF_ACTIVE ) ); + PyConstant_Insert( d, "ACTIVE", PyInt_FromLong( TF_ACTIVE ) ); /* deprecated */ } return FF; diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index 51d6fc1a2b6..e50c9678606 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -1978,20 +1978,11 @@ static BPy_NMVert *nmvert_from_data( MVert * vert, MSticky * st, float *co, static int get_active_faceindex( Mesh * me ) { - MTFace *tf; - int i; - if( me == NULL ) return -1; - tf = me->mtface; - if( tf == 0 ) - return -1; - - for( i = 0; i < me->totface; i++ ) - if( tf[i].flag & TF_ACTIVE ) - return i; - + if (me->act_face != -1 && me->act_face < me->totface) + return me->act_face; return -1; } diff --git a/source/blender/src/drawimage.c b/source/blender/src/drawimage.c index d69ec6d1b05..7fb6604b2fc 100644 --- a/source/blender/src/drawimage.c +++ b/source/blender/src/drawimage.c @@ -490,6 +490,7 @@ void draw_uvs_sima(void) cageDM = editmesh_get_derived_cage_and_final(&finalDM, CD_MASK_BAREMESH | CD_MASK_MTFACE); if (finalDM->drawUVEdges && + DM_get_face_data_layer(finalDM, CD_MTFACE) && /* When sync selection is enabled, all faces are drawn (except for hidden) * so if cage is the same as the final, theres no point in drawing the shadowmesh. */ !((G.sima->flag & SI_SYNC_UVSEL && cageDM==finalDM)) diff --git a/source/blender/src/drawmesh.c b/source/blender/src/drawmesh.c index f974e85293a..0c8132b3469 100644 --- a/source/blender/src/drawmesh.c +++ b/source/blender/src/drawmesh.c @@ -634,7 +634,7 @@ EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me) if (!(mf->flag&ME_HIDE)) { unsigned int flags = eEdge_Visible; if (mf->flag&ME_FACE_SEL) flags |= eEdge_Select; - if (tf && tf->flag&TF_ACTIVE) { + if (i==me->act_face) { flags |= eEdge_Active; if (mf->flag&ME_FACE_SEL) flags |= eEdge_SelectAndActive; } @@ -647,8 +647,8 @@ EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me) } else { get_marked_edge_info__orFlags(eh, mf->v3, mf->v1, flags); } - - if (tf && tf->flag&TF_ACTIVE) { + + if (i==me->act_face) { get_marked_edge_info__orFlags(eh, mf->v1, mf->v2, eEdge_ActiveFirst); get_marked_edge_info__orFlags(eh, mf->v1, mf->v4?mf->v4:mf->v3, eEdge_ActiveLast); } diff --git a/source/blender/src/editface.c b/source/blender/src/editface.c index 65e335ea6ab..516928af14e 100644 --- a/source/blender/src/editface.c +++ b/source/blender/src/editface.c @@ -569,13 +569,18 @@ MTFace *get_active_mtface(EditFace **act_efa, MCol **mcol, short partsel) if(!EM_texFaceCheck()) return NULL; - - for (ese = em->selected.last; ese; ese=ese->prev){ - if(ese->type == EDITFACE) { - efa = (EditFace *)ese->data; - - if (efa->h) efa= NULL; - else break; + + /* first check the active face */ + if (em->act_face) { + efa = em->act_face; + } else { + for (ese = em->selected.last; ese; ese=ese->prev){ + if(ese->type == EDITFACE) { + efa = (EditFace *)ese->data; + + if (efa->h) efa= NULL; + else break; + } } } @@ -1107,7 +1112,6 @@ void face_select() { Object *ob; Mesh *me; - MTFace *tface, *tsel; MFace *mface, *msel; short mval[2]; unsigned int a, index; @@ -1127,33 +1131,20 @@ void face_select() if (!facesel_face_pick(me, mval, &index, 1)) return; - tsel= (((MTFace*)me->mtface)+index); /* check me->mtface before using */ msel= (((MFace*)me->mface)+index); - if (msel->flag & ME_HIDE) return; /* clear flags */ - tface = me->mtface; mface = me->mface; a = me->totface; - while (a--) { - if (G.qual & LR_SHIFTKEY) { - if (me->mtface) { - tface->flag &= ~TF_ACTIVE; - } - } else { - if (me->mtface) { - tface->flag &= ~TF_ACTIVE; - } + if ((G.qual & LR_SHIFTKEY)==0) { + while (a--) { mface->flag &= ~ME_FACE_SEL; + mface++; } - if (me->mtface) { - tface++; - } - mface++; } - if (me->mtface) - tsel->flag |= TF_ACTIVE; + + me->act_face = (int)index; if (G.qual & LR_SHIFTKEY) { if (msel->flag & ME_FACE_SEL) diff --git a/source/blender/src/editmesh.c b/source/blender/src/editmesh.c index fcfb1a5c40f..678178e6e5b 100644 --- a/source/blender/src/editmesh.c +++ b/source/blender/src/editmesh.c @@ -333,6 +333,10 @@ void free_editface(EditFace *efa) } #endif EM_remove_selection(efa, EDITFACE); + + if (G.editMesh->act_face==efa) + EM_set_actFace(NULL); + CustomData_em_free_block(&G.editMesh->fdata, &efa->data); if(efa->fast==0) free(efa); @@ -809,10 +813,11 @@ void make_editMesh() /* because of reload */ free_editMesh(em); + em->act_face = NULL; G.totvert= tot= me->totvert; G.totedge= me->totedge; G.totface= me->totface; - + if(tot==0) { countall(); return; @@ -906,6 +911,9 @@ void make_editMesh() if((FACESEL_PAINT_TEST) && (efa->f & SELECT)) EM_select_face(efa, 1); /* flush down */ + + if (a==me->act_face) + em->act_face = efa; } } } @@ -1140,6 +1148,9 @@ void load_editMesh(void) /* no index '0' at location 3 or 4 */ test_index_face(mface, &me->fdata, i, efa->v4?4:3); + + if (a==me->act_face) + EM_set_actFace(efa); #ifdef WITH_VERSE if(efa->vface) { diff --git a/source/blender/src/editmesh_lib.c b/source/blender/src/editmesh_lib.c index d6781c8e430..c85efa609b1 100644 --- a/source/blender/src/editmesh_lib.c +++ b/source/blender/src/editmesh_lib.c @@ -72,6 +72,17 @@ editmesh_lib: generic (no UI, no menus) operations/evaluators for editmesh data #include "editmesh.h" +/* this replaces the active flag used in uv/face mode */ +void EM_set_actFace(EditFace *efa) +{ + G.editMesh->act_face = efa; +} + +EditFace * EM_get_actFace(void) +{ + return G.editMesh->act_face; +} + /* ********* Selection History ************ */ static int EM_check_selection(void *data) { diff --git a/source/blender/src/editmesh_mods.c b/source/blender/src/editmesh_mods.c index 2af77f6e2dc..2a86c674f66 100644 --- a/source/blender/src/editmesh_mods.c +++ b/source/blender/src/editmesh_mods.c @@ -2067,6 +2067,8 @@ void mouse_mesh(void) if((G.qual & LR_SHIFTKEY)==0) EM_clear_flag_all(SELECT); if(efa) { + /* set the last selected face */ + EM_set_actFace(efa); if( (efa->f & SELECT)==0 ) { EM_store_selection(efa, EDITFACE); diff --git a/source/blender/src/editsima.c b/source/blender/src/editsima.c index f809409b9f0..0daf468c253 100644 --- a/source/blender/src/editsima.c +++ b/source/blender/src/editsima.c @@ -575,8 +575,8 @@ void mouse_select_sima(void) /* TODO - SYNCSEL */ find_nearest_tface(&nearesttf, &nearestefa); if(nearesttf==NULL) return; - - nearesttf->flag |= TF_ACTIVE; + + EM_set_actFace(nearestefa); for (i=0; i<4; i++) hituv[i]= nearesttf->uv[i]; @@ -660,10 +660,7 @@ void mouse_select_sima(void) /* TODO - SYNCSEL */ for (efa= em->faces.first; efa; efa= efa->next) { tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); if (SIMA_FACEDRAW_CHECK(efa, tf)) { - if(nearesttf && tf!=nearesttf) - tf->flag &=~ TF_ACTIVE; if (!sticky) continue; - if(msel_hit(limit, hitv, efa->v1->tmp.l, hituv, tf->uv[0], sticky)) SIMA_UVSEL_SET(efa, tf, 0); if(msel_hit(limit, hitv, efa->v2->tmp.l, hituv, tf->uv[1], sticky)) @@ -675,6 +672,7 @@ void mouse_select_sima(void) /* TODO - SYNCSEL */ SIMA_UVSEL_SET(efa, tf, 3); } } + EM_set_actFace(nearestefa); flush = 1; } } @@ -685,11 +683,12 @@ void mouse_select_sima(void) /* TODO - SYNCSEL */ for (efa= em->faces.first; efa; efa= efa->next) { tf= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); SIMA_FACESEL_UNSET(efa, tf); - //if(nearesttf && tf!=nearesttf) /* TODO - deal with editmesh active face */ - // tf->flag &= ~TF_ACTIVE; } - if(nearesttf) + if(nearesttf) { SIMA_FACESEL_SET(nearestefa, nearesttf); + EM_set_actFace(nearestefa); + } + } /* deselect uvs, and select sticky uvs */ |