Added active drawing in editmode (may need some more work), this hilightes the last...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2007 14:36:03 +0000 (14:36 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2007 14:36:03 +0000 (14:36 +0000)
Added copy menu for editmode for copying from the active faces material, image, UV's vcols etc,
improved on the current vertex color copy by averaging the 4th color when copying color from a tri to a quad.

And added edge crease and length copy

cerrently verts dont have a copy menu but eventually copy weights would be good.

source/blender/include/BIF_editmesh.h
source/blender/src/buttons_editing.c
source/blender/src/drawobject.c
source/blender/src/editmesh_mods.c
source/blender/src/editobject.c

index 2da77df76fcf10c4fc8ff7113bd1abeeb203e6f6..1ef526cb55fb6322d84b084c0d0f0b11aa12fb37 100644 (file)
@@ -219,6 +219,7 @@ extern void edge_flip(void);
 extern void fill_mesh(void);
 extern void bevel_menu();
 extern void mesh_set_smooth_faces(short event);
+void mesh_copy_menu(void);
 void edge_rotate_selected(int dir);
 int EdgeSlide(short immediate, float imperc);
 int EdgeLoopDelete(void);
index ab4a8499f5cfb72271e9bc2439b47faf08d9c8af..8d60f73858c53973273670bfa43f6792f98569d2 100644 (file)
@@ -5484,7 +5484,6 @@ void editing_panels()
                } else {
                        if(FACESEL_PAINT_TEST) {
                                editing_panel_mesh_texface();
-                               editing_panel_mesh_uvautocalculation(); /* draw hidden edge option from this needs to be elsewhere */
                        }
                        if(G.f & (G_VERTEXPAINT | G_TEXTUREPAINT | G_WEIGHTPAINT) ) {
                                editing_panel_mesh_paint();
index ded36ed5a0275f8292e5c7f64179bb3323186f04..27aee3133186dd2056e4bcb8fdd5715e3d1026d4 100644 (file)
@@ -2037,6 +2037,129 @@ static void draw_em_fancy(Object *ob, EditMesh *em, DerivedMesh *cageDM, Derived
                if(em->vnode && (G.f & G_DRAW_VERSE_DEBUG))
                        draw_verse_debug(ob, em);
 #endif
+               
+               /* Draw active editmode vertex edge of face (if any)*/
+               if (em->selected.last) {
+                       EditSelection *ese = em->selected.last;
+               
+                       if(ese->type == EDITVERT) {
+                               EditVert *ev = (EditVert*)ese->data;
+                               float size = BIF_GetThemeValuef(TH_VERTEX_SIZE)*4;
+                               
+                               glEnable(GL_BLEND);
+                               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+                               glDepthMask(0);
+                               glColor4ub(255,255,255,64);
+                               glPointSize(size);
+                               
+                               glBegin(GL_POINTS);
+                               glVertex3fv(ev->co);
+                               glEnd();
+                               
+                               glPointSize(1.0);
+                               
+                               glDisable(GL_BLEND);
+                               glDepthMask(1);
+                               
+                       } else if(ese->type == EDITEDGE) {
+                               EditEdge *eed = (EditEdge*)ese->data;
+                               glEnable(GL_BLEND);
+                               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+                               glDepthMask(0);
+                               glColor4ub(255,255,255,128);
+                               
+                               glLineWidth(2.0);
+                               
+                               glBegin(GL_LINES);
+                               glVertex3fv(eed->v1->co);
+                               glVertex3fv(eed->v2->co);
+                               glEnd();
+                               
+                               glLineWidth(1.0);
+
+                               glDisable(GL_BLEND);
+                               glDepthMask(1);
+                               
+                               
+                       } else if(ese->type == EDITFACE) {
+                               EditFace *efa = (EditEdge*)ese->data;
+                               
+                               /*  repeate this pattern
+                                  X000X000 
+                                  00000000 
+                                  00X000X0 
+                                  00000000 */
+                               
+                               GLubyte stipplepattern[32*32/8] = {
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
+                                       136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0
+                               };
+                               
+                               glEnable(GL_BLEND);
+                               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+                               glDepthMask(0);
+                               glColor4ub(255,255,255,64);
+                               
+                               glEnable(GL_POLYGON_STIPPLE);
+                               glPolygonStipple(stipplepattern);
+                               
+                               glDisable(GL_LIGHTING);
+                               if (((EditFace*)ese->data)->v4) {
+                                       glBegin(GL_QUADS);
+                                       glVertex3fv(efa->v1->co);
+                                       glVertex3fv(efa->v2->co);
+                                       glVertex3fv(efa->v3->co);
+                                       glVertex3fv(efa->v4->co);
+                                       glEnd();
+                               } else {
+                                       glBegin(GL_TRIANGLES);
+                                       glVertex3fv(efa->v1->co);
+                                       glVertex3fv(efa->v2->co);
+                                       glVertex3fv(efa->v3->co);
+                                       glEnd();
+                               }
+                               glDisable(GL_POLYGON_STIPPLE);
+                               
+                               glLineWidth(1.0);
+                               glBegin(GL_LINES);
+                               
+                               glColor4ub(0,   255,0,  128);
+                               glVertex3fv(efa->v1->co);
+                               glVertex3fv(efa->v2->co);
+                               
+                               
+                               glColor4ub(0,   0,      255,128);
+                               glVertex3fv(efa->v2->co);
+                               glVertex3fv(efa->v3->co);
+                               
+                               
+                               glColor4ub(255, 255,0,  128);
+                               if (efa->v4) {
+                                       glVertex3fv(efa->v3->co);
+                                       glVertex3fv(efa->v4->co);
+                                       
+                                       
+                                       glColor4ub(255, 0,      0,      128);
+                                       glVertex3fv(efa->v4->co);
+                                       glVertex3fv(efa->v1->co);
+                               } else {
+                                       glVertex3fv(efa->v3->co);
+                                       glVertex3fv(efa->v1->co);
+                               }
+                               glEnd();
+                               glLineWidth(1.0);
+                               
+                               glDisable(GL_BLEND);                                    
+                               glDepthMask(1);
+                       }
+               }
+               
        }
 
        if(dt>OB_WIRE) {
index 77f53df011b584452695fe6819ba3fd71a72bd29..c2b44b42ee318c9ed74c4af960ec56ecd184f73a 100644 (file)
@@ -1345,6 +1345,211 @@ void select_mesh_group_menu()
        }
 }
 
+/* ctrl+c in mesh editmode */
+void mesh_copy_menu(void)
+{
+       EditMesh *em = G.editMesh;
+       EditSelection *ese;
+       short ret, change=0;
+       
+       if (!em) return;
+       
+       ese = em->selected.last;
+       
+       if (!ese) return;
+       
+       if(ese->type == EDITVERT) {
+               EditVert *ev, *ev_act = (EditVert*)ese->data;
+               /*ret= pupmenu("");*/
+       } else if(ese->type == EDITEDGE) {
+               EditEdge *eed, *eed_act = (EditEdge*)ese->data;
+               float vec[3], vec_mid[3], eed_len, eed_len_act;
+               
+               ret= pupmenu("Copy Active Edge to Selected%t|Crease%x1|Length%x2");
+               if (ret<1) return;
+               
+               eed_len_act = VecLenf(eed_act->v1->co, eed_act->v2->co);
+               
+               switch (ret) {
+               case 1: /* copy crease */
+                       for(eed=em->edges.first; eed; eed=eed->next) {
+                               if (eed->f & SELECT && eed != eed_act && eed->crease != eed_act->crease) {
+                                       eed->crease = eed_act->crease;
+                                       change = 1;
+                               }
+                       }
+                       break;
+                       
+               case 2: /* 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;
+                               }
+                       }
+                       break;
+               }
+               
+       } else if(ese->type == EDITFACE) {
+               EditFace *efa, *efa_act = (EditFace*)ese->data;
+               MTFace *tf, *tf_act;
+               MCol *mcol, *mcol_act;
+               
+               ret= pupmenu("Copy Active Face to Selected%t|Material%x1|Image%x2|UV Coords%x3|Mode%x4|Transp%x5|Vertex Colors%x6");
+               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);
+               
+               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");
+                       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 teh 4th color if needs be */
+                               char r,g,b;
+                               float val =- 1;
+                               
+                               if (!efa_act->v4) {
+                                       /* guess the othe vale, we may need to use it */
+                                       val = ((float)(mcol_act->r +  (mcol_act+1)->r + (mcol_act+2)->r)) / 3; CLAMP(val, 0, 255);
+                                       r = (char)val;
+                                       
+                                       val = ((float)(mcol_act->g +  (mcol_act+1)->g + (mcol_act+2)->g)) / 3; CLAMP(val, 0, 255);
+                                       g = (char)val;
+                                       
+                                       val = ((float)(mcol_act->b +  (mcol_act+1)->b + (mcol_act+2)->b)) / 3; CLAMP(val, 0, 255);
+                                       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);
+                                               
+                                               if (!efa_act->v4 && efa->v4) {
+                                                       /* guess the 4th color */
+                                                       (mcol+3)->r = r;
+                                                       (mcol+3)->g = g;
+                                                       (mcol+3)->b = b;
+                                               }
+                                               
+                                               change = 1;
+                                       }
+                               }
+                       }
+                       
+                       break;
+               }
+       }
+       
+       if (change) {
+               allqueue(REDRAWVIEW3D, 0);
+               allqueue(REDRAWBUTSEDIT, 0);
+               
+               if(ese->type == EDITVERT)               BIF_undo_push("Copy Vert Attribute");
+               else if (ese->type == EDITEDGE) BIF_undo_push("Copy Edge Attribute");
+               else if (ese->type == EDITFACE) BIF_undo_push("Copy Face Attribute");
+       }
+       
+}
+
 
 /* ****************  LOOP SELECTS *************** */
 
index 762a3a1d4a9d00c3ab6c7289bf401f83e5eba447..8a8f31e027d78b1e5294c5e77ef51c097248e8d8 100644 (file)
@@ -3361,101 +3361,59 @@ void copy_attr(short event)
        BIF_undo_push("Copy Attributes");
 }
 
-void copy_attr_tface(short event)
-{
-       /* Face Select Mode */
-       Object *ob= OBACT;
-       Mesh *me= get_mesh(ob);
-       MTFace *tface;
-       MFace *mface;
-       MCol *activemcol;
-       MTFace *activetf= get_active_tface(NULL, &activemcol);
-       int a;
-       
-       if(activetf==NULL) return;
-       
-       tface= me->mtface;
-       mface= me->mface;
-       for(a=0; a<me->totface; a++, tface++, mface++) {
-               if(mface->flag & ME_FACE_SEL) {
-                       switch(event) {
-                       case 1:
-                               tface->tpage = activetf->tpage;
-                               tface->tile= activetf->tile;
-                               tface->mode |= TF_TEX;
-                               break;
-                       case 2:
-                               memcpy(tface->uv, activetf->uv, sizeof(tface->uv)); break;
-                       case 3:
-                               if(activemcol)
-                                       memcpy(&me->mcol[a*4], activemcol, sizeof(MCol)*4); break;
-                       case 4:
-                               tface->mode = activetf->mode; break;
-                       case 5:
-                               tface->transp= activetf->transp; break;
-                       }
-               }
-       }
-       DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
-       allqueue(REDRAWVIEW3D, 0);
-       allqueue(REDRAWBUTSEDIT, 0);
-       BIF_undo_push("Copy texture face");
-}
-
 void copy_attr_menu()
 {
        Object *ob;
        short event;
+       char str[512];
        
        if(!(ob=OBACT)) return;
        
-       if ((G.obedit)) return; /* no editmode copy yet */
+       if (G.obedit && ob->type == OB_MESH) {
+               mesh_copy_menu();
+               return;
+       } else {
+               return;
+       }
        
-       if(FACESEL_PAINT_TEST) {
-               event= pupmenu("Copy Active Texface%t|Image%x1|UV Coords%x2|Color%x3|Mode%x4|Transp%x5");
-               copy_attr_tface(event);
+       /* Object Mode */
        
-       } else { /* Object Mode */
-               
-               /* If you change this menu, don't forget to update the menu in header_view3d.c
-                * view3d_edit_object_copyattrmenu() and in toolbox.c
-                */
-               
-               char str[512];
-               
-               strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Drawtype%x4|Time Offset%x5|Dupli%x6|%l|Mass%x7|Damping%x8|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l");
-               
-               strcat (str, "|Object Constraints%x22");
-               strcat (str, "|NLA Strips%x26");
-               
-               if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
-                       strcat(str, "|Texture Space%x17");
-               }       
-               
-               if(ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
-               if(ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19|UV Orco%x28");
-               
-               if((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
-                               strcat(str, "|Curve Resolution%x25");
-               }
-
-               if(ob->type==OB_MESH){
-                       strcat(str, "|Subsurf Settings%x21|AutoSmooth%x27");
-               }
+       /* If you change this menu, don't forget to update the menu in header_view3d.c
+        * view3d_edit_object_copyattrmenu() and in toolbox.c
+        */
+       
+       strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Drawtype%x4|Time Offset%x5|Dupli%x6|%l|Mass%x7|Damping%x8|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l");
+       
+       strcat (str, "|Object Constraints%x22");
+       strcat (str, "|NLA Strips%x26");
+       
+       if ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) {
+               strcat(str, "|Texture Space%x17");
+       }       
+       
+       if(ob->type == OB_FONT) strcat(str, "|Font Settings%x18|Bevel Settings%x19");
+       if(ob->type == OB_CURVE) strcat(str, "|Bevel Settings%x19|UV Orco%x28");
+       
+       if((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
+                       strcat(str, "|Curve Resolution%x25");
+       }
 
-               if( give_parteff(ob) ) strcat(str, "|Particle Settings%x20");
+       if(ob->type==OB_MESH){
+               strcat(str, "|Subsurf Settings%x21|AutoSmooth%x27");
+       }
 
-               if(ob->soft) strcat(str, "|Soft Body Settings%x23");
-               
-               if(ob->type==OB_MESH || ob->type==OB_CURVE || ob->type==OB_LATTICE || ob->type==OB_SURF){
-                       strcat(str, "|Modifiers ...%x24");
-               }
+       if( give_parteff(ob) ) strcat(str, "|Particle Settings%x20");
 
-               event= pupmenu(str);
-               if(event<= 0) return;
-               
-               copy_attr(event);
+       if(ob->soft) strcat(str, "|Soft Body Settings%x23");
+       
+       if(ob->type==OB_MESH || ob->type==OB_CURVE || ob->type==OB_LATTICE || ob->type==OB_SURF){
+               strcat(str, "|Modifiers ...%x24");
        }
+
+       event= pupmenu(str);
+       if(event<= 0) return;
+       
+       copy_attr(event);
 }