diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2005-04-23 00:16:02 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2005-04-23 00:16:02 +0400 |
commit | 6a00fcd90ca8a2c4bd3a0429d37be2ce6c2ac77a (patch) | |
tree | 8dadc718838f5d6711917b73991c2fdc2d9a28d6 /source | |
parent | 43835d4d0450c15c4d8e962c0b979b34325f4c97 (diff) |
Add "View Selected" (numpad .-key) for faceselect mode and the uv editor.
Also includes some 2d vector operations (subtract, dot, normalise).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_arithb.h | 20 | ||||
-rw-r--r-- | source/blender/blenlib/intern/arithb.c | 35 | ||||
-rw-r--r-- | source/blender/include/BDR_editface.h | 1 | ||||
-rw-r--r-- | source/blender/include/BIF_drawimage.h | 1 | ||||
-rw-r--r-- | source/blender/include/BIF_editsima.h | 1 | ||||
-rw-r--r-- | source/blender/src/drawimage.c | 29 | ||||
-rw-r--r-- | source/blender/src/editface.c | 48 | ||||
-rw-r--r-- | source/blender/src/editsima.c | 39 | ||||
-rw-r--r-- | source/blender/src/header_image.c | 3 | ||||
-rw-r--r-- | source/blender/src/space.c | 4 | ||||
-rw-r--r-- | source/blender/src/view.c | 5 |
11 files changed, 186 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h index 21e5bceffff..6e05a5e2dea 100644 --- a/source/blender/blenlib/BLI_arithb.h +++ b/source/blender/blenlib/BLI_arithb.h @@ -811,6 +811,26 @@ Vec2Addf( float *v1, float *v2 ); + void +Vec2Subf( + float *v, + float *v1, + float *v2 +); + void +Vec2Copyf( + float *v1, + float *v2 +); + float +Inp2f( + float *v1, + float *v2 +); + float +Normalise2( + float *n +); void tubemap(float x, float y, float z, float *u, float *v); void spheremap(float x, float y, float z, float *u, float *v); diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index b77590ebd18..00301192179 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -2365,6 +2365,41 @@ void Vec2Addf(float *v, float *v1, float *v2) v[1]= v1[1]+ v2[1]; } +void Vec2Subf(float *v, float *v1, float *v2) +{ + v[0]= v1[0]- v2[0]; + v[1]= v1[1]- v2[1]; +} + +void Vec2Copyf(float *v1, float *v2) +{ + v1[0]= v2[0]; + v1[1]= v2[1]; +} + +float Inp2f(float *v1, float *v2) +{ + return v1[0]*v2[0]+v1[1]*v2[1]; +} + +float Normalise2(float *n) +{ + float d; + + d= n[0]*n[0]+n[1]*n[1]; + + if(d>1.0e-35F) { + d= (float)sqrt(d); + + n[0]/=d; + n[1]/=d; + } else { + n[0]=n[1]= 0.0; + d= 0.0; + } + return d; +} + void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b) { int i; diff --git a/source/blender/include/BDR_editface.h b/source/blender/include/BDR_editface.h index c3a7821c11d..2670e5246f3 100644 --- a/source/blender/include/BDR_editface.h +++ b/source/blender/include/BDR_editface.h @@ -47,6 +47,7 @@ void select_linked_tfaces(void); void deselectall_tface(void); void selectswap_tface(void); void rotate_uv_tface(void); +void minmax_tface(float *min, float *max); int face_pick(struct Mesh *me, short x, short y); void face_select(void); void face_borderselect(void); diff --git a/source/blender/include/BIF_drawimage.h b/source/blender/include/BIF_drawimage.h index cbd87fd9e6f..8df27a364a5 100644 --- a/source/blender/include/BIF_drawimage.h +++ b/source/blender/include/BIF_drawimage.h @@ -44,6 +44,7 @@ void image_changed(struct SpaceImage *sima, int dotile); void image_home(void); void image_viewmove(void); void image_viewzoom(unsigned short event); +void image_viewcentre(void); void uvco_to_areaco(float *vec, short *mval); void uvco_to_areaco_noclip(float *vec, short *mval); void what_image(struct SpaceImage *sima); diff --git a/source/blender/include/BIF_editsima.h b/source/blender/include/BIF_editsima.h index c3750bfc018..00ba13a81dc 100644 --- a/source/blender/include/BIF_editsima.h +++ b/source/blender/include/BIF_editsima.h @@ -46,4 +46,5 @@ void unlink_selection(void); void select_linked_tface_uv(void); void toggle_uv_select(int mode); void pin_tface_uv(int mode); +int minmax_tface_uv(float *min, float *max); diff --git a/source/blender/src/drawimage.c b/source/blender/src/drawimage.c index b10837a9bfd..6eda482f840 100644 --- a/source/blender/src/drawimage.c +++ b/source/blender/src/drawimage.c @@ -1020,3 +1020,32 @@ void image_home(void) scrarea_queue_winredraw(curarea); } +void image_viewcentre(void) +{ + float size, min[2], max[2], d[2], xim=256.0f, yim=256.0f; + + if( is_uv_tface_editing_allowed()==0 ) return; + + if (!minmax_tface_uv(min, max)) return; + + if(G.sima->image && G.sima->image->ibuf) { + xim= G.sima->image->ibuf->x; + yim= G.sima->image->ibuf->y; + } + + G.sima->xof= ((min[0] + max[0])*0.5f - 0.5f)*xim; + G.sima->yof= ((min[1] + max[1])*0.5f - 0.5f)*yim; + + d[0] = max[0] - min[0]; + d[1] = max[1] - min[1]; + size= 0.5*MAX2(d[0], d[1])*MAX2(xim, yim)/256.0f; + + if(size<=0.01) size= 0.01; + + G.sima->zoom= 1.0/size; + + calc_image_view(G.sima, 'p'); + + scrarea_queue_winredraw(curarea); +} + diff --git a/source/blender/src/editface.c b/source/blender/src/editface.c index f2a8dbcf316..a9864ccd303 100644 --- a/source/blender/src/editface.c +++ b/source/blender/src/editface.c @@ -844,6 +844,54 @@ void rotate_uv_tface() allqueue(REDRAWIMAGE, 0); } +void minmax_tface(float *min, float *max) +{ + Object *ob; + Mesh *me; + MFace *mf; + TFace *tf; + MVert *mv; + int a; + float vec[3], bmat[3][3]; + + ob = OBACT; + if (ob==0) return; + me= get_mesh(ob); + if(me==0 || me->tface==0) return; + + Mat3CpyMat4(bmat, ob->obmat); + + mv= me->mvert; + mf= me->mface; + tf= me->tface; + for (a=me->totface; a>0; a--, mf++, tf++) { + if (!mf->v3 || tf->flag & TF_HIDE || !(tf->flag & TF_SELECT)) + continue; + + VECCOPY(vec, (mv+mf->v1)->co); + Mat3MulVecfl(bmat, vec); + VecAddf(vec, vec, ob->obmat[3]); + DO_MINMAX(vec, min, max); + + VECCOPY(vec, (mv+mf->v2)->co); + Mat3MulVecfl(bmat, vec); + VecAddf(vec, vec, ob->obmat[3]); + DO_MINMAX(vec, min, max); + + VECCOPY(vec, (mv+mf->v3)->co); + Mat3MulVecfl(bmat, vec); + VecAddf(vec, vec, ob->obmat[3]); + DO_MINMAX(vec, min, max); + + if (mf->v4) { + VECCOPY(vec, (mv+mf->v4)->co); + Mat3MulVecfl(bmat, vec); + VecAddf(vec, vec, ob->obmat[3]); + DO_MINMAX(vec, min, max); + } + } +} + /** * Returns the face under the give position in screen coordinates. * Code extracted from face_select routine. diff --git a/source/blender/src/editsima.c b/source/blender/src/editsima.c index 25c1d82fb7f..4de8824cb6c 100644 --- a/source/blender/src/editsima.c +++ b/source/blender/src/editsima.c @@ -1739,3 +1739,42 @@ void pin_tface_uv(int mode) scrarea_queue_winredraw(curarea); } +int minmax_tface_uv(float *min, float *max) +{ + Mesh *me; + TFace *tf; + MFace *mf; + int a, sel; + + if( is_uv_tface_editing_allowed()==0 ) return 0; + me= get_mesh(OBACT); + + INIT_MINMAX2(min, max); + + sel= 0; + mf= (MFace*)me->mface; + tf= (TFace*)me->tface; + for(a=me->totface; a>0; a--, tf++, mf++) { + if(tf->flag & TF_HIDE); + else if(mf->v3 && (tf->flag & TF_SELECT)) { + + if (tf->flag & TF_SEL1) { + DO_MINMAX2(tf->uv[0], min, max); + } + if (tf->flag & TF_SEL2) { + DO_MINMAX2(tf->uv[1], min, max); + } + if (tf->flag & TF_SEL3) { + DO_MINMAX2(tf->uv[2], min, max); + } + if (mf->v4 && tf->flag & TF_SEL4) { + DO_MINMAX2(tf->uv[3], min, max); + } + + sel = 1; + } + } + + return sel; +} + diff --git a/source/blender/src/header_image.c b/source/blender/src/header_image.c index 346a59bad00..e0af6971959 100644 --- a/source/blender/src/header_image.c +++ b/source/blender/src/header_image.c @@ -411,6 +411,8 @@ static void do_image_viewmenu(void *arg, int event) case 8: /* Paint Panel... */ add_blockhandler(curarea, IMAGE_HANDLER_PAINT, UI_PNL_UNSTOW); break; + case 9: + image_viewcentre(); } allqueue(REDRAWVIEW3D, 0); } @@ -444,6 +446,7 @@ static uiBlock *image_viewmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View Selected|NumPad .", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 9, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); if(!curarea->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, ""); diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 6b3d5b2bd76..28fd15279ea 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -3835,6 +3835,10 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt) case WKEY: transform_tface_uv('w'); break; + case PADPERIOD: + if(G.qual==0) + image_viewcentre(); + break; } } diff --git a/source/blender/src/view.c b/source/blender/src/view.c index c67f6681da6..15852b64de0 100644 --- a/source/blender/src/view.c +++ b/source/blender/src/view.c @@ -75,6 +75,7 @@ #include "BSE_drawview.h" /* For inner_play_anim_loop */ #include "BDR_drawobject.h" /* For draw_object */ +#include "BDR_editface.h" /* For minmax_tface */ #include "mydevice.h" #include "blendef.h" @@ -1006,6 +1007,10 @@ void centreview() /* like a localview without local! */ ok= 1; } + else if (G.f & G_FACESELECT) { + minmax_tface(min, max); + ok= 1; + } else { base= FIRSTBASE; while(base) { |