added back copy buttons to "Texture Face" panel.

This commit is contained in:
Campbell Barton 2008-08-07 01:02:06 +00:00
parent ba12aa0962
commit 5d62ad194d
4 changed files with 410 additions and 385 deletions

@ -132,7 +132,7 @@ extern int EM_check_backbuf(unsigned int index);
extern void EM_free_backbuf(void); extern void EM_free_backbuf(void);
extern void EM_selectmode_menu(void); extern void EM_selectmode_menu(void);
extern void EM_mesh_copy_face(short type);
extern void vertexnoise(void); extern void vertexnoise(void);
extern void vertexsmooth(void); extern void vertexsmooth(void);

@ -593,7 +593,7 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
#define B_VPCOLSLI 2801 #define B_VPCOLSLI 2801
#define B_VPGAMMA 2802 #define B_VPGAMMA 2802
#define B_COPY_TF_TRANSP 2803
#define B_COPY_TF_MODE 2804 #define B_COPY_TF_MODE 2804
#define B_COPY_TF_UV 2805 #define B_COPY_TF_UV 2805
#define B_COPY_TF_COL 2806 #define B_COPY_TF_COL 2806

@ -5671,13 +5671,9 @@ void sculptmode_draw_interface_textures(uiBlock *block, unsigned short cx, unsig
void do_fpaintbuts(unsigned short event) void do_fpaintbuts(unsigned short event)
{ {
Mesh *me;
Object *ob; Object *ob;
bDeformGroup *defGroup; bDeformGroup *defGroup;
MTFace *activetf, *tf; MTFace *activetf;
MFace *mf;
MCol *activemcol;
int a;
SculptData *sd= &G.scene->sculptdata; SculptData *sd= &G.scene->sculptdata;
ID *id, *idtest; ID *id, *idtest;
extern VPaint Gwp; /* from vpaint */ extern VPaint Gwp; /* from vpaint */
@ -5695,45 +5691,19 @@ void do_fpaintbuts(unsigned short event)
vpaint_dogamma(); vpaint_dogamma();
break; break;
case B_COPY_TF_MODE: case B_COPY_TF_MODE:
EM_mesh_copy_face(4); /* todo, get rid of magic numbers */
break;
case B_COPY_TF_TRANSP:
EM_mesh_copy_face(5);
break;
case B_COPY_TF_UV: case B_COPY_TF_UV:
EM_mesh_copy_face(3);
break;
case B_COPY_TF_COL: case B_COPY_TF_COL:
EM_mesh_copy_face(6);
break;
case B_COPY_TF_TEX: case B_COPY_TF_TEX:
me= get_mesh(OBACT); EM_mesh_copy_face(2);
activetf= get_active_mtface(NULL, &activemcol, 0);
if(me && activetf) {
for (a=0, tf=me->mtface, mf=me->mface; a < me->totface; a++, tf++, mf++) {
if(tf!=activetf && (mf->flag & ME_FACE_SEL)) {
if(event==B_COPY_TF_MODE) {
tf->mode= activetf->mode;
tf->transp= activetf->transp;
}
else if(event==B_COPY_TF_UV) {
memcpy(tf->uv, activetf->uv, sizeof(tf->uv));
tf->tpage= activetf->tpage;
tf->tile= activetf->tile;
if(activetf->mode & TF_TILES) tf->mode |= TF_TILES;
else tf->mode &= ~TF_TILES;
}
else if(event==B_COPY_TF_TEX) {
tf->tpage= activetf->tpage;
tf->tile= activetf->tile;
if(activetf->mode & TF_TILES) tf->mode |= TF_TILES;
else tf->mode &= ~TF_TILES;
}
else if(event==B_COPY_TF_COL && activemcol)
memcpy(&me->mcol[a*4], activemcol, sizeof(MCol)*4);
}
}
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
do_shared_vertexcol(me);
allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWIMAGE, 0);
}
break; break;
case B_SET_VCOL: case B_SET_VCOL:
if(FACESEL_PAINT_TEST) if(FACESEL_PAINT_TEST)
@ -6170,8 +6140,20 @@ static void editing_panel_mesh_texface(void)
if(uiNewPanel(curarea, block, "Texture Face", "Editing", 960, 0, 318, 204)==0) return; if(uiNewPanel(curarea, block, "Texture Face", "Editing", 960, 0, 318, 204)==0) return;
tf = get_active_mtface(NULL, NULL, 0); tf = get_active_mtface(NULL, NULL, 0);
if(tf) { if(tf) {
uiDefBut(block, LABEL, B_NOP, "Active Face Mode", 600,185,300,19, NULL, 0.0, 0.0, 0, 0, "Face mode its used for TexFace display and the game engine ");
uiDefBut(block, BUT,B_COPY_TF_MODE, "Copy", 850,185,50,19, 0, 0, 0, 0, 0, "Copy active faces mode to other selected (View3D Ctrl+C)");
/* Other copy buttons, layout isnt that nice */
uiBlockBeginAlign(block); uiBlockBeginAlign(block);
uiDefBut(block, BUT,B_COPY_TF_UV, "CopyUV", 600,15,100,19, 0, 0, 0, 0, 0, "Copy active faces UVs to other selected (View3D Ctrl+C)");
uiDefBut(block, BUT,B_COPY_TF_TEX, "CopyTex", 700,15,100,19, 0, 0, 0, 0, 0, "Copy active faces Texture to other selected (View3D Ctrl+C)");
uiDefBut(block, BUT,B_COPY_TF_COL, "CopyColor", 800,15,100,19, 0, 0, 0, 0, 0, "Copy active faces Color to other selected (View3D Ctrl+C)");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, TF_TEX, B_REDR_3D_IMA, "Tex", 600,160,60,19, &tf->mode, 0, 0, 0, 0, "Render face with texture"); uiDefButBitS(block, TOG, TF_TEX, B_REDR_3D_IMA, "Tex", 600,160,60,19, &tf->mode, 0, 0, 0, 0, "Render face with texture");
uiDefButBitS(block, TOG, TF_TILES, B_REDR_3D_IMA, "Tiles", 660,160,60,19, &tf->mode, 0, 0, 0, 0, "Use tilemode for face"); uiDefButBitS(block, TOG, TF_TILES, B_REDR_3D_IMA, "Tiles", 660,160,60,19, &tf->mode, 0, 0, 0, 0, "Use tilemode for face");
uiDefButBitS(block, TOG, TF_LIGHT, REDRAWVIEW3D, "Light", 720,160,60,19, &tf->mode, 0, 0, 0, 0, "Use light for face"); uiDefButBitS(block, TOG, TF_LIGHT, REDRAWVIEW3D, "Light", 720,160,60,19, &tf->mode, 0, 0, 0, 0, "Use light for face");
@ -6182,24 +6164,30 @@ static void editing_panel_mesh_texface(void)
uiDefButBitS(block, TOG, TF_SHAREDCOL, REDRAWVIEW3D, "Shared", 600,135,60,19, &tf->mode, 0, 0, 0, 0, "Blend vertex colors across face when vertices are shared"); uiDefButBitS(block, TOG, TF_SHAREDCOL, REDRAWVIEW3D, "Shared", 600,135,60,19, &tf->mode, 0, 0, 0, 0, "Blend vertex colors across face when vertices are shared");
uiDefButBitS(block, TOG, TF_TWOSIDE, REDRAWVIEW3D, "Twoside",660,135,60,19, &tf->mode, 0, 0, 0, 0, "Render face twosided"); uiDefButBitS(block, TOG, TF_TWOSIDE, REDRAWVIEW3D, "Twoside",660,135,60,19, &tf->mode, 0, 0, 0, 0, "Render face twosided");
uiDefButBitS(block, TOG, TF_OBCOL, REDRAWVIEW3D, "ObColor",720,135,60,19, &tf->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colors"); uiDefButBitS(block, TOG, TF_OBCOL, REDRAWVIEW3D, "ObColor",720,135,60,19, &tf->mode, 0, 0, 0, 0, "Use ObColor instead of vertex colors");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
uiBlockBeginAlign(block);
uiDefButBitS(block, TOG, TF_BILLBOARD, B_TFACE_HALO, "Halo", 600,110,60,19, &tf->mode, 0, 0, 0, 0, "Screen aligned billboard"); uiDefButBitS(block, TOG, TF_BILLBOARD, B_TFACE_HALO, "Halo", 600,110,60,19, &tf->mode, 0, 0, 0, 0, "Screen aligned billboard");
uiDefButBitS(block, TOG, TF_BILLBOARD2, B_TFACE_BILLB, "Billboard",660,110,60,19, &tf->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint"); uiDefButBitS(block, TOG, TF_BILLBOARD2, B_TFACE_BILLB, "Billboard",660,110,60,19, &tf->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint");
uiDefButBitS(block, TOG, TF_SHADOW, REDRAWVIEW3D, "Shadow", 720,110,60,19, &tf->mode, 0, 0, 0, 0, "Face is used for shadow"); uiDefButBitS(block, TOG, TF_SHADOW, REDRAWVIEW3D, "Shadow", 720,110,60,19, &tf->mode, 0, 0, 0, 0, "Face is used for shadow");
uiDefButBitS(block, TOG, TF_BMFONT, REDRAWVIEW3D, "Text", 780,110,60,19, &tf->mode, 0, 0, 0, 0, "Enable bitmap text on face"); uiDefButBitS(block, TOG, TF_BMFONT, REDRAWVIEW3D, "Text", 780,110,60,19, &tf->mode, 0, 0, 0, 0, "Enable bitmap text on face");
uiDefButBitS(block, TOG, TF_ALPHASORT, REDRAWVIEW3D, "Sort", 840,110,60,19, &tf->mode, 0, 0, 0, 0, "Enable sorting of faces for correct alpha drawing (slow, use Clip Alpha instead when possible)"); uiDefButBitS(block, TOG, TF_ALPHASORT, REDRAWVIEW3D, "Sort", 840,110,60,19, &tf->mode, 0, 0, 0, 0, "Enable sorting of faces for correct alpha drawing (slow, use Clip Alpha instead when possible)");
uiBlockEndAlign(block);
uiDefBut(block, LABEL, B_NOP, "Active Face Alpha Blending (Transp)", 600,75,300,19, NULL, 0.0, 0.0, 0, 0, "Face mode its used for TexFace display and the game engine");
uiDefBut(block, BUT,B_COPY_TF_TRANSP, "Copy", 850,75,50,19, 0, 0, 0, 0, 0, "Copy active faces transp to other selected (View3D Ctrl+C)");
uiBlockBeginAlign(block); uiBlockBeginAlign(block);
uiBlockSetCol(block, TH_BUT_SETTING1); uiBlockSetCol(block, TH_BUT_SETTING1);
uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque", 600,80,60,19, &tf->transp, 2.0, (float)TF_SOLID,0, 0, "Render color of textured face as color"); uiDefButC(block, ROW, REDRAWVIEW3D, "Opaque", 600,50,60,19, &tf->transp, 2.0, (float)TF_SOLID,0, 0, "Render color of textured face as color");
uiDefButC(block, ROW, REDRAWVIEW3D, "Add", 660,80,60,19, &tf->transp, 2.0, (float)TF_ADD, 0, 0, "Render face transparent and add color of face"); uiDefButC(block, ROW, REDRAWVIEW3D, "Add", 660,50,60,19, &tf->transp, 2.0, (float)TF_ADD, 0, 0, "Render face transparent and add color of face");
uiDefButC(block, ROW, REDRAWVIEW3D, "Alpha", 720,80,60,19, &tf->transp, 2.0, (float)TF_ALPHA,0, 0, "Render polygon transparent, depending on alpha channel of the texture"); uiDefButC(block, ROW, REDRAWVIEW3D, "Alpha", 720,50,60,19, &tf->transp, 2.0, (float)TF_ALPHA,0, 0, "Render polygon transparent, depending on alpha channel of the texture");
uiDefButC(block, ROW, REDRAWVIEW3D, "Clip Alpha", 780,80,80,19, &tf->transp, 2.0, (float)TF_CLIP,0, 0, "Use the images alpha values clipped with no blending (binary alpha)"); uiDefButC(block, ROW, REDRAWVIEW3D, "Clip Alpha", 780,50,80,19, &tf->transp, 2.0, (float)TF_CLIP,0, 0, "Use the images alpha values clipped with no blending (binary alpha)");
} uiBlockEndAlign(block);
else
} else {
uiDefBut(block,LABEL,B_NOP, "(No Active Face)", 10,200,150,19,0,0,0,0,0,""); uiDefBut(block,LABEL,B_NOP, "(No Active Face)", 10,200,150,19,0,0,0,0,0,"");
}
} }

@ -1432,348 +1432,78 @@ int mesh_layers_menu(CustomData *data, int type) {
return ret; return ret;
} }
/* ctrl+c in mesh editmode */ void EM_mesh_copy_edge(short type)
void mesh_copy_menu(void)
{ {
EditMesh *em = G.editMesh; EditMesh *em = G.editMesh;
EditSelection *ese; EditSelection *ese;
short ret, change=0; short change=0;
EditEdge *eed, *eed_act;
float vec[3], vec_mid[3], eed_len, eed_len_act;
if (!em) return; if (!em) return;
ese = em->selected.last; ese = em->selected.last;
if (!ese) return;
/* Faces can have a NULL ese, so dont return on a NULL ese here */ eed_act = (EditEdge*)ese->data;
if(ese && ese->type == EDITVERT) { switch (type) {
case 1: /* copy crease */
if (!ese) return; for(eed=em->edges.first; eed; eed=eed->next) {
/*EditVert *ev, *ev_act = (EditVert*)ese->data; if (eed->f & SELECT && eed != eed_act && eed->crease != eed_act->crease) {
ret= pupmenu("");*/ eed->crease = eed_act->crease;
} else if(ese && ese->type == EDITEDGE) { change = 1;
EditEdge *eed, *eed_act; }
float vec[3], vec_mid[3], eed_len, eed_len_act; }
break;
if (!ese) return; case 2: /* copy bevel weight */
for(eed=em->edges.first; eed; eed=eed->next) {
eed_act = (EditEdge*)ese->data; if (eed->f & SELECT && eed != eed_act && eed->bweight != eed_act->bweight) {
eed->bweight = eed_act->bweight;
ret= pupmenu("Copy Active Edge to Selected%t|Crease%x1|Bevel Weight%x2|Length%x3"); change = 1;
if (ret<1) return; }
}
break;
case 3: /* copy length */
eed_len_act = VecLenf(eed_act->v1->co, eed_act->v2->co); eed_len_act = VecLenf(eed_act->v1->co, eed_act->v2->co);
for(eed=em->edges.first; eed; eed=eed->next) {
switch (ret) { if (eed->f & SELECT && eed != eed_act) {
case 1: /* copy crease */
for(eed=em->edges.first; eed; eed=eed->next) { eed_len = VecLenf(eed->v1->co, eed->v2->co);
if (eed->f & SELECT && eed != eed_act && eed->crease != eed_act->crease) {
eed->crease = eed_act->crease; if (eed_len == eed_len_act) continue;
change = 1; /* if this edge is zero length we cont do anything with it*/
if (eed_len == 0.0f) continue;
if (eed_len_act == 0.0f) {
VecAddf(vec_mid, eed->v1->co, eed->v2->co);
VecMulf(vec_mid, 0.5);
VECCOPY(eed->v1->co, vec_mid);
VECCOPY(eed->v2->co, vec_mid);
} else {
/* copy the edge length */
VecAddf(vec_mid, eed->v1->co, eed->v2->co);
VecMulf(vec_mid, 0.5);
/* SCALE 1 */
VecSubf(vec, eed->v1->co, vec_mid);
VecMulf(vec, eed_len_act/eed_len);
VecAddf(eed->v1->co, vec, vec_mid);
/* SCALE 2 */
VecSubf(vec, eed->v2->co, vec_mid);
VecMulf(vec, eed_len_act/eed_len);
VecAddf(eed->v2->co, vec, vec_mid);
} }
change = 1;
} }
break;
case 2: /* copy bevel weight */
for(eed=em->edges.first; eed; eed=eed->next) {
if (eed->f & SELECT && eed != eed_act && eed->bweight != eed_act->bweight) {
eed->bweight = eed_act->bweight;
change = 1;
}
}
break;
case 3: /* copy length */
for(eed=em->edges.first; eed; eed=eed->next) {
if (eed->f & SELECT && eed != eed_act) {
eed_len = VecLenf(eed->v1->co, eed->v2->co);
if (eed_len == eed_len_act) continue;
/* if this edge is zero length we cont do anything with it*/
if (eed_len == 0.0f) continue;
if (eed_len_act == 0.0f) {
VecAddf(vec_mid, eed->v1->co, eed->v2->co);
VecMulf(vec_mid, 0.5);
VECCOPY(eed->v1->co, vec_mid);
VECCOPY(eed->v2->co, vec_mid);
} else {
/* copy the edge length */
VecAddf(vec_mid, eed->v1->co, eed->v2->co);
VecMulf(vec_mid, 0.5);
/* SCALE 1 */
VecSubf(vec, eed->v1->co, vec_mid);
VecMulf(vec, eed_len_act/eed_len);
VecAddf(eed->v1->co, vec, vec_mid);
/* SCALE 2 */
VecSubf(vec, eed->v2->co, vec_mid);
VecMulf(vec, eed_len_act/eed_len);
VecAddf(eed->v2->co, vec, vec_mid);
}
change = 1;
}
}
if (change)
recalc_editnormals();
break;
} }
} else if(ese==NULL || ese->type == EDITFACE) { if (change)
EditFace *efa, *efa_act; recalc_editnormals();
MTFace *tf, *tf_act = NULL;
MCol *mcol, *mcol_act = NULL; break;
efa_act = EM_get_actFace(0);
if (efa_act) {
ret= pupmenu(
"Copy Face Selected%t|"
"Active Material%x1|Active Image%x2|Active UV Coords%x3|"
"Active Mode%x4|Active Transp%x5|Active Vertex Colors%x6|%l|"
"TexFace UVs from layer%x7|"
"TexFace Images from layer%x8|"
"TexFace All from layer%x9|"
"Vertex Colors from layer%x10");
if (ret<1) return;
tf_act = CustomData_em_get(&em->fdata, efa_act->data, CD_MTFACE);
mcol_act = CustomData_em_get(&em->fdata, efa_act->data, CD_MCOL);
} else {
ret= pupmenu(
"Copy Face Selected%t|"
/* Make sure these are always the same as above */
"TexFace UVs from layer%x7|"
"TexFace Images from layer%x8|"
"TexFace All from layer%x9|"
"Vertex Colors from layer%x10");
if (ret<1) return;
}
switch (ret) {
case 1: /* copy material */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa->mat_nr != efa_act->mat_nr) {
efa->mat_nr = efa_act->mat_nr;
change = 1;
}
}
break;
case 2: /* copy image */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (tf_act->tpage) {
tf->tpage = tf_act->tpage;
tf->mode |= TF_TEX;
} else {
tf->tpage = NULL;
tf->mode &= ~TF_TEX;
}
tf->tile= tf_act->tile;
change = 1;
}
}
break;
case 3: /* copy UV's */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
memcpy(tf->uv, tf_act->uv, sizeof(tf->uv));
change = 1;
}
}
break;
case 4: /* mode's */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
tf->mode= tf_act->mode;
change = 1;
}
}
break;
case 5: /* copy transp's */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
tf->transp= tf_act->transp;
change = 1;
}
}
break;
case 6: /* copy vcols's */
if (!mcol_act) {
error("mesh has no color layers");
return;
} else {
/* guess the 4th color if needs be */
float val =- 1;
if (!efa_act->v4) {
/* guess the othe vale, we may need to use it
*
* Modifying the 4th value of the mcol is ok here since its not seen
* on a triangle
* */
val = ((float)(mcol_act->r + (mcol_act+1)->r + (mcol_act+2)->r)) / 3; CLAMP(val, 0, 255);
(mcol_act+3)->r = (char)val;
val = ((float)(mcol_act->g + (mcol_act+1)->g + (mcol_act+2)->g)) / 3; CLAMP(val, 0, 255);
(mcol_act+3)->g = (char)val;
val = ((float)(mcol_act->b + (mcol_act+1)->b + (mcol_act+2)->b)) / 3; CLAMP(val, 0, 255);
(mcol_act+3)->b = (char)val;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
/* TODO - make copy from tri to quad guess the 4th vert */
mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
memcpy(mcol, mcol_act, sizeof(MCol)*4);
change = 1;
}
}
}
break;
/* Copy from layer - Warning! tf_act and mcol_act will be NULL here */
case 7:
case 8:
case 9:
if (CustomData_number_of_layers(&em->fdata, CD_MTFACE)<2) {
error("mesh does not have multiple uv/image layers");
return;
} else {
int layer_orig_idx, layer_idx;
layer_idx = mesh_layers_menu(&em->fdata, CD_MTFACE);
if (layer_idx<0) return;
/* warning, have not updated mesh pointers however this is not needed since we swicth back */
layer_orig_idx = CustomData_get_active_layer(&em->fdata, CD_MTFACE);
if (layer_idx==layer_orig_idx)
return;
/* get the tfaces */
CustomData_set_layer_active(&em->fdata, CD_MTFACE, (int)layer_idx);
/* store the tfaces in our temp */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
efa->tmp.p = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
}
}
CustomData_set_layer_active(&em->fdata, CD_MTFACE, layer_orig_idx);
}
break;
case 10: /* select vcol layers - make sure this stays in sync with above code */
if (CustomData_number_of_layers(&em->fdata, CD_MCOL)<2) {
error("mesh does not have multiple color layers");
return;
} else {
int layer_orig_idx, layer_idx;
layer_idx = mesh_layers_menu(&em->fdata, CD_MCOL);
if (layer_idx<0) return;
/* warning, have not updated mesh pointers however this is not needed since we swicth back */
layer_orig_idx = CustomData_get_active_layer(&em->fdata, CD_MCOL);
if (layer_idx==layer_orig_idx)
return;
/* get the tfaces */
CustomData_set_layer_active(&em->fdata, CD_MCOL, (int)layer_idx);
/* store the tfaces in our temp */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
efa->tmp.p = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
}
}
CustomData_set_layer_active(&em->fdata, CD_MCOL, layer_orig_idx);
}
break;
}
/* layer copy only - sanity checks done above */
switch (ret) {
case 7: /* copy UV's only */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
tf_act = (MTFace *)efa->tmp.p; /* not active but easier to use this way */
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
memcpy(tf->uv, tf_act->uv, sizeof(tf->uv));
change = 1;
}
}
break;
case 8: /* copy image settings only */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
tf_act = (MTFace *)efa->tmp.p; /* not active but easier to use this way */
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (tf_act->tpage) {
tf->tpage = tf_act->tpage;
tf->mode |= TF_TEX;
} else {
tf->tpage = NULL;
tf->mode &= ~TF_TEX;
}
tf->tile= tf_act->tile;
change = 1;
}
}
break;
case 9: /* copy all tface info */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
tf_act = (MTFace *)efa->tmp.p; /* not active but easier to use this way */
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
memcpy(tf->uv, ((MTFace *)efa->tmp.p)->uv, sizeof(tf->uv));
tf->tpage = tf_act->tpage;
tf->mode = tf_act->mode;
tf->transp = tf_act->transp;
change = 1;
}
}
break;
case 10:
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
mcol_act = (MCol *)efa->tmp.p;
mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
memcpy(mcol, mcol_act, sizeof(MCol)*4);
change = 1;
}
}
break;
}
} }
if (change) { if (change) {
@ -1781,12 +1511,319 @@ void mesh_copy_menu(void)
allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWBUTSEDIT, 0); allqueue(REDRAWBUTSEDIT, 0);
if (ese==NULL || ese->type == EDITFACE) BIF_undo_push("Copy Face Attribute"); BIF_undo_push("Copy Edge Attribute");
else if ( ese->type == EDITEDGE) BIF_undo_push("Copy Edge Attribute"); }
else if ( ese->type == EDITVERT) BIF_undo_push("Copy Vert Attribute"); }
void EM_mesh_copy_face(short type)
{
EditMesh *em = G.editMesh;
short change=0;
EditFace *efa, *efa_act;
MTFace *tf, *tf_act = NULL;
MCol *mcol, *mcol_act = NULL;
if (!em) return;
efa_act = EM_get_actFace(0);
if (!efa_act) return;
tf_act = CustomData_em_get(&em->fdata, efa_act->data, CD_MTFACE);
mcol_act = CustomData_em_get(&em->fdata, efa_act->data, CD_MCOL);
switch (type) {
case 1: /* copy material */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa->mat_nr != efa_act->mat_nr) {
efa->mat_nr = efa_act->mat_nr;
change = 1;
}
}
break;
case 2: /* copy image */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (tf_act->tpage) {
tf->tpage = tf_act->tpage;
tf->mode |= TF_TEX;
} else {
tf->tpage = NULL;
tf->mode &= ~TF_TEX;
}
tf->tile= tf_act->tile;
change = 1;
}
}
break;
case 3: /* copy UV's */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
memcpy(tf->uv, tf_act->uv, sizeof(tf->uv));
change = 1;
}
}
break;
case 4: /* mode's */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
tf->mode= tf_act->mode;
change = 1;
}
}
break;
case 5: /* copy transp's */
if (!tf_act) {
error("mesh has no uv/image layers");
return;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
tf->transp= tf_act->transp;
change = 1;
}
}
break;
case 6: /* copy vcols's */
if (!mcol_act) {
error("mesh has no color layers");
return;
} else {
/* guess the 4th color if needs be */
float val =- 1;
if (!efa_act->v4) {
/* guess the othe vale, we may need to use it
*
* Modifying the 4th value of the mcol is ok here since its not seen
* on a triangle
* */
val = ((float)(mcol_act->r + (mcol_act+1)->r + (mcol_act+2)->r)) / 3; CLAMP(val, 0, 255);
(mcol_act+3)->r = (char)val;
val = ((float)(mcol_act->g + (mcol_act+1)->g + (mcol_act+2)->g)) / 3; CLAMP(val, 0, 255);
(mcol_act+3)->g = (char)val;
val = ((float)(mcol_act->b + (mcol_act+1)->b + (mcol_act+2)->b)) / 3; CLAMP(val, 0, 255);
(mcol_act+3)->b = (char)val;
}
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT && efa != efa_act) {
/* TODO - make copy from tri to quad guess the 4th vert */
mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
memcpy(mcol, mcol_act, sizeof(MCol)*4);
change = 1;
}
}
}
break;
} }
if (change) {
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWBUTSEDIT, 0);
if (type==3) {
allqueue(REDRAWIMAGE, 0);
}
BIF_undo_push("Copy Face Attribute");
}
}
void EM_mesh_copy_face_layer(short type)
{
EditMesh *em = G.editMesh;
short change=0;
EditFace *efa;
MTFace *tf, *tf_from;
MCol *mcol, *mcol_from;
if (!em) return;
switch(type) {
case 7:
case 8:
case 9:
if (CustomData_number_of_layers(&em->fdata, CD_MTFACE)<2) {
error("mesh does not have multiple uv/image layers");
return;
} else {
int layer_orig_idx, layer_idx;
layer_idx = mesh_layers_menu(&em->fdata, CD_MTFACE);
if (layer_idx<0) return;
/* warning, have not updated mesh pointers however this is not needed since we swicth back */
layer_orig_idx = CustomData_get_active_layer(&em->fdata, CD_MTFACE);
if (layer_idx==layer_orig_idx)
return;
/* get the tfaces */
CustomData_set_layer_active(&em->fdata, CD_MTFACE, (int)layer_idx);
/* store the tfaces in our temp */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
efa->tmp.p = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
}
}
CustomData_set_layer_active(&em->fdata, CD_MTFACE, layer_orig_idx);
}
break;
case 10: /* select vcol layers - make sure this stays in sync with above code */
if (CustomData_number_of_layers(&em->fdata, CD_MCOL)<2) {
error("mesh does not have multiple color layers");
return;
} else {
int layer_orig_idx, layer_idx;
layer_idx = mesh_layers_menu(&em->fdata, CD_MCOL);
if (layer_idx<0) return;
/* warning, have not updated mesh pointers however this is not needed since we swicth back */
layer_orig_idx = CustomData_get_active_layer(&em->fdata, CD_MCOL);
if (layer_idx==layer_orig_idx)
return;
/* get the tfaces */
CustomData_set_layer_active(&em->fdata, CD_MCOL, (int)layer_idx);
/* store the tfaces in our temp */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
efa->tmp.p = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
}
}
CustomData_set_layer_active(&em->fdata, CD_MCOL, layer_orig_idx);
}
break;
}
/* layer copy only - sanity checks done above */
switch (type) {
case 7: /* copy UV's only */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
tf_from = (MTFace *)efa->tmp.p; /* not active but easier to use this way */
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
memcpy(tf->uv, tf_from->uv, sizeof(tf->uv));
change = 1;
}
}
break;
case 8: /* copy image settings only */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
tf_from = (MTFace *)efa->tmp.p; /* not active but easier to use this way */
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
if (tf_from->tpage) {
tf->tpage = tf_from->tpage;
tf->mode |= TF_TEX;
} else {
tf->tpage = NULL;
tf->mode &= ~TF_TEX;
}
tf->tile= tf_from->tile;
change = 1;
}
}
break;
case 9: /* copy all tface info */
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
tf_from = (MTFace *)efa->tmp.p; /* not active but easier to use this way */
tf = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
memcpy(tf->uv, ((MTFace *)efa->tmp.p)->uv, sizeof(tf->uv));
tf->tpage = tf_from->tpage;
tf->mode = tf_from->mode;
tf->transp = tf_from->transp;
change = 1;
}
}
break;
case 10:
for(efa=em->faces.first; efa; efa=efa->next) {
if (efa->f & SELECT) {
mcol_from = (MCol *)efa->tmp.p;
mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL);
memcpy(mcol, mcol_from, sizeof(MCol)*4);
change = 1;
}
}
break;
}
if (change) {
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA);
allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWBUTSEDIT, 0);
BIF_undo_push("Copy Face Layer");
}
}
/* ctrl+c in mesh editmode */
void mesh_copy_menu(void)
{
EditMesh *em = G.editMesh;
EditSelection *ese;
int ret;
if (!em) return;
ese = em->selected.last;
/* Faces can have a NULL ese, so dont return on a NULL ese here */
if(ese && ese->type == EDITVERT) {
/* EditVert *ev, *ev_act = (EditVert*)ese->data;
ret= pupmenu(""); */
} else if(ese && ese->type == EDITEDGE) {
ret= pupmenu("Copy Active Edge to Selected%t|Crease%x1|Bevel Weight%x2|Length%x3");
if (ret<1) return;
EM_mesh_copy_edge(ret);
} else if(ese==NULL || ese->type == EDITFACE) {
ret= pupmenu(
"Copy Face Selected%t|"
"Active Material%x1|Active Image%x2|Active UV Coords%x3|"
"Active Mode%x4|Active Transp%x5|Active Vertex Colors%x6|%l|"
"TexFace UVs from layer%x7|"
"TexFace Images from layer%x8|"
"TexFace All from layer%x9|"
"Vertex Colors from layer%x10");
if (ret<1) return;
if (ret<=6) {
EM_mesh_copy_face(ret);
} else {
EM_mesh_copy_face_layer(ret);
}
}
} }