Add "View Selected" (numpad .-key) for faceselect mode and the uv editor.

Also includes some 2d vector operations (subtract, dot, normalise).
This commit is contained in:
2005-04-22 20:16:02 +00:00
parent 43835d4d04
commit 6a00fcd90c
11 changed files with 186 additions and 0 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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.

View File

@@ -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;
}

View File

@@ -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, "");

View File

@@ -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;
}
}

View File

@@ -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) {