added a sloppy option for getting the active face, which returns the last selected if none is active, made the uv calculation aspect correction use the active faces image rather then the last used image viewports.
This commit is contained in:
@@ -38,7 +38,7 @@ struct EditFace;
|
||||
struct Mesh;
|
||||
struct MCol;
|
||||
|
||||
struct MTFace *get_active_mtface(struct EditFace **efa, struct MCol **mcol, short sloppy);
|
||||
struct MTFace *get_active_mtface(struct EditFace **efa, struct MCol **mcol, int sloppy);
|
||||
void calculate_uv_map(unsigned short mapmode);
|
||||
void default_uv(float uv[][2], float size);
|
||||
void make_tfaces(struct Mesh *me);
|
||||
|
||||
@@ -262,6 +262,6 @@ 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);
|
||||
struct EditFace * EM_get_actFace(int sloppy);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -63,7 +63,9 @@ void borderselect_sima(short whichuvs);
|
||||
void mouseco_to_curtile(void);
|
||||
void mouse_select_sima(void);
|
||||
void snap_menu_sima(void);
|
||||
void aspect_sima(struct SpaceImage *sima, float *x, float *y);
|
||||
void image_pixel_aspect(struct Image *image, float *x, float *y);
|
||||
void image_final_aspect(struct Image *image, float *x, float *y);
|
||||
|
||||
|
||||
void select_invert_tface_uv(void);
|
||||
void select_swap_tface_uv(void);
|
||||
|
||||
@@ -194,7 +194,7 @@ void calc_image_view(SpaceImage *sima, char mode)
|
||||
ImBuf *ibuf= imagewindow_get_ibuf(sima);
|
||||
float xuser_asp, yuser_asp;
|
||||
|
||||
aspect_sima(sima, &xuser_asp, &yuser_asp);
|
||||
image_pixel_aspect(sima->image, &xuser_asp, &yuser_asp);
|
||||
if(ibuf) {
|
||||
xim= ibuf->x * xuser_asp;
|
||||
yim= ibuf->y * yuser_asp;
|
||||
@@ -2045,7 +2045,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
|
||||
unsigned int *rect;
|
||||
float x1, y1;
|
||||
short sx, sy, dx, dy, show_render= 0, show_viewer= 0;
|
||||
float xuser_asp, yuser_asp;
|
||||
float xuser_asp=1, yuser_asp=1;
|
||||
/* If derived data is used then make sure that object
|
||||
* is up-to-date... might not be the case because updates
|
||||
* are normally done in drawview and could get here before
|
||||
@@ -2070,9 +2070,8 @@ void drawimagespace(ScrArea *sa, void *spacedata)
|
||||
|
||||
what_image(sima);
|
||||
|
||||
aspect_sima(sima, &xuser_asp, &yuser_asp);
|
||||
|
||||
if(sima->image) {
|
||||
image_pixel_aspect(sima->image, &xuser_asp, &yuser_asp);
|
||||
|
||||
/* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */
|
||||
if(sima->image->type==IMA_TYPE_COMPOSITE) {
|
||||
|
||||
@@ -2061,7 +2061,7 @@ static int draw_em_fancy__setFaceOpts(void *userData, int index, int *drawSmooth
|
||||
static void draw_em_fancy(Object *ob, EditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, int dt)
|
||||
{
|
||||
Mesh *me = ob->data;
|
||||
EditFace *efa_act = EM_get_actFace(); /* annoying but active faces is stored differently */
|
||||
EditFace *efa_act = EM_get_actFace(0); /* annoying but active faces is stored differently */
|
||||
EditEdge *eed_act = NULL;
|
||||
EditVert *eve_act = NULL;
|
||||
|
||||
|
||||
@@ -341,14 +341,19 @@ static void uv_calc_shift_project(float *target, float *shift, float rotmat[][4]
|
||||
|
||||
void correct_uv_aspect( void )
|
||||
{
|
||||
float aspx, aspy;
|
||||
float aspx=1, aspy=1;
|
||||
EditMesh *em = G.editMesh;
|
||||
EditFace *efa = EM_get_actFace(1);
|
||||
MTFace *tface;
|
||||
|
||||
transform_aspect_ratio_tface_uv(&aspx, &aspy);
|
||||
if (efa) {
|
||||
tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
|
||||
image_final_aspect(tface->tpage, &aspx, &aspy);
|
||||
}
|
||||
|
||||
if (aspx != aspy) {
|
||||
MTFace *tface;
|
||||
|
||||
EditMesh *em = G.editMesh;
|
||||
EditFace *efa;
|
||||
float scale;
|
||||
|
||||
if (aspx > aspy) {
|
||||
@@ -569,6 +574,8 @@ void calculate_uv_map(unsigned short mapmode)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if ((G.scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT)==0)
|
||||
correct_uv_aspect();
|
||||
return;
|
||||
} /* end switch mapmode */
|
||||
|
||||
@@ -615,37 +622,15 @@ void calculate_uv_map(unsigned short mapmode)
|
||||
|
||||
/* last_sel, use em->act_face otherwise get the last selected face in the editselections
|
||||
* at the moment, last_sel is mainly useful for gaking sure the space image dosnt flicker */
|
||||
MTFace *get_active_mtface(EditFace **act_efa, MCol **mcol, short sloppy)
|
||||
MTFace *get_active_mtface(EditFace **act_efa, MCol **mcol, int sloppy)
|
||||
{
|
||||
EditMesh *em = G.editMesh;
|
||||
EditFace *efa = NULL;
|
||||
EditSelection *ese;
|
||||
|
||||
if(!EM_texFaceCheck())
|
||||
return NULL;
|
||||
|
||||
if (sloppy)
|
||||
efa = EM_get_actFace();
|
||||
|
||||
/* first check the active face */
|
||||
if ((sloppy && efa)==0) {
|
||||
ese = em->selected.last;
|
||||
for (; ese; ese=ese->prev){
|
||||
if(ese->type == EDITFACE) {
|
||||
efa = (EditFace *)ese->data;
|
||||
|
||||
if (efa->h) efa= NULL;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sloppy && !efa) {
|
||||
for (efa= em->faces.first; efa; efa= efa->next) {
|
||||
if (efa->f & SELECT)
|
||||
break;
|
||||
}
|
||||
}
|
||||
efa = EM_get_actFace(sloppy);
|
||||
|
||||
if (efa) {
|
||||
if (mcol) {
|
||||
|
||||
@@ -1023,7 +1023,7 @@ void load_editMesh(void)
|
||||
MFace *mface;
|
||||
MSelect *mselect;
|
||||
EditVert *eve;
|
||||
EditFace *efa;
|
||||
EditFace *efa, *efa_act;
|
||||
EditEdge *eed;
|
||||
EditSelection *ese;
|
||||
float *fp, *newkey, *oldkey, nor[3];
|
||||
@@ -1238,6 +1238,7 @@ void load_editMesh(void)
|
||||
/* the faces */
|
||||
a = 0;
|
||||
efa= em->faces.first;
|
||||
efa_act= EM_get_actFace(0);
|
||||
i = 0;
|
||||
me->act_face = -1;
|
||||
while(efa) {
|
||||
@@ -1295,7 +1296,7 @@ void load_editMesh(void)
|
||||
/* no index '0' at location 3 or 4 */
|
||||
test_index_face(mface, &me->fdata, i, efa->v4?4:3);
|
||||
|
||||
if (EM_get_actFace() == efa)
|
||||
if (efa_act == efa)
|
||||
me->act_face = a;
|
||||
|
||||
#ifdef WITH_VERSE
|
||||
|
||||
@@ -78,9 +78,32 @@ void EM_set_actFace(EditFace *efa)
|
||||
G.editMesh->act_face = efa;
|
||||
}
|
||||
|
||||
EditFace * EM_get_actFace(void)
|
||||
EditFace * EM_get_actFace(int sloppy)
|
||||
{
|
||||
return (G.editMesh->act_face && G.editMesh->act_face->f & SELECT) ? G.editMesh->act_face : NULL ;
|
||||
if (G.editMesh->act_face && G.editMesh->act_face->f & SELECT) {
|
||||
return G.editMesh->act_face;
|
||||
} else if (sloppy) {
|
||||
EditFace *efa= NULL;
|
||||
EditSelection *ese;
|
||||
|
||||
ese = G.editMesh->selected.last;
|
||||
for (; ese; ese=ese->prev){
|
||||
if(ese->type == EDITFACE) {
|
||||
efa = (EditFace *)ese->data;
|
||||
|
||||
if (efa->h) efa= NULL;
|
||||
else break;
|
||||
}
|
||||
}
|
||||
if (efa==NULL) {
|
||||
for (efa= G.editMesh->faces.first; efa; efa= efa->next) {
|
||||
if (efa->f & SELECT)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return efa; /* can still be null */
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ********* Selection History ************ */
|
||||
|
||||
@@ -1521,7 +1521,7 @@ void mesh_copy_menu(void)
|
||||
MTFace *tf, *tf_act = NULL;
|
||||
MCol *mcol, *mcol_act = NULL;
|
||||
|
||||
efa_act = EM_get_actFace();
|
||||
efa_act = EM_get_actFace(0);
|
||||
|
||||
if (efa_act) {
|
||||
ret= pupmenu(
|
||||
|
||||
@@ -219,8 +219,8 @@ void transform_aspect_ratio_tface_uv(float *aspx, float *aspy)
|
||||
int w, h;
|
||||
float xuser_asp, yuser_asp;
|
||||
|
||||
if(G.sima) {
|
||||
aspect_sima(G.sima, &xuser_asp, &yuser_asp);
|
||||
if(G.sima && G.sima->image) {
|
||||
image_pixel_aspect(G.sima->image, &xuser_asp, &yuser_asp);
|
||||
|
||||
transform_width_height_tface_uv(&w, &h);
|
||||
*aspx= (float)w/256.0f * xuser_asp;
|
||||
@@ -2712,23 +2712,44 @@ void image_changed(SpaceImage *sima, Image *image)
|
||||
allqueue(REDRAWBUTSEDIT, 0);
|
||||
}
|
||||
|
||||
void aspect_sima(SpaceImage *sima, float *x, float *y)
|
||||
void image_pixel_aspect(Image *image, float *x, float *y)
|
||||
{
|
||||
*x = *y = 1.0;
|
||||
|
||||
if( (sima->image == 0) ||
|
||||
(sima->image->type == IMA_TYPE_R_RESULT) ||
|
||||
(sima->image->type == IMA_TYPE_COMPOSITE) ||
|
||||
(sima->image->tpageflag & IMA_TILES) ||
|
||||
(sima->image->aspx==0.0 || sima->image->aspy==0.0)
|
||||
if( (image == NULL) ||
|
||||
(image->type == IMA_TYPE_R_RESULT) ||
|
||||
(image->type == IMA_TYPE_COMPOSITE) ||
|
||||
(image->tpageflag & IMA_TILES) ||
|
||||
(image->aspx==0.0 || image->aspy==0.0)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* x is always 1 */
|
||||
*y = sima->image->aspy / sima->image->aspx;
|
||||
*y = image->aspy / image->aspx;
|
||||
}
|
||||
|
||||
void image_final_aspect(Image *image, float *x, float *y)
|
||||
{
|
||||
*x = *y = 1.0;
|
||||
|
||||
if( (image == NULL) ||
|
||||
(image->type == IMA_TYPE_R_RESULT) ||
|
||||
(image->type == IMA_TYPE_COMPOSITE) ||
|
||||
(image->tpageflag & IMA_TILES) ||
|
||||
(image->aspx==0.0 || image->aspy==0.0)
|
||||
) {
|
||||
return;
|
||||
} else {
|
||||
ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
|
||||
if (ibuf && ibuf->x && ibuf->y) {
|
||||
*y = (image->aspy * ibuf->y) / (image->aspx * ibuf->x);
|
||||
} else {
|
||||
/* x is always 1 */
|
||||
*y = image->aspy / image->aspx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Face selection tests - Keep these together */
|
||||
|
||||
|
||||
@@ -321,12 +321,15 @@ void unwrap_lscm(short seamcut)
|
||||
|
||||
/* scale before packing */
|
||||
if ((G.scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT)==0) {
|
||||
float aspx, aspy;
|
||||
EditFace *efa = EM_get_actFace(1);
|
||||
if (efa) {
|
||||
float aspx, aspy;
|
||||
MTFace *tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
|
||||
image_final_aspect(tface->tpage, &aspx, &aspy);
|
||||
|
||||
transform_aspect_ratio_tface_uv(&aspx, &aspy);
|
||||
|
||||
if (aspx!=aspy) {
|
||||
param_scale(handle, 1.0, aspx/aspy);
|
||||
if (aspx!=aspy) {
|
||||
param_scale(handle, 1.0, aspx/aspy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user