reworked how tile functions, seperated image and tile setting functions/events and...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 19 Sep 2007 16:28:52 +0000 (16:28 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 19 Sep 2007 16:28:52 +0000 (16:28 +0000)
changed how image replace works,
it used to load a new image and then assign that image to all faces in meshes active UV layer.
without replacing images in textures or images on inactive UV layers

now it simply changes the filename of the existing image and reloads the contense.

This is different in some other subtle ways,
1) replace used to use an existing image if it was available,
this could be confusing because when I replaced with an image I didnt like, but had alredy applied to objects in some other scene, replacing again would alter the images from models unintentionally.
2) since replace used to load a new image, it would load with a new name. at the moment the name is left unchanged,
This is better when dealing with linked libraries. because when replacing a images, anything linking to that texture gets broken. since imaged can get automatically named strings longer then its possible to enter into the user interface, you could wind up with some really annoying cases where it wasnt possible to type in the original name again.

Since this replace effects everything usiung the image, we may want to have 2 replace functions, "Replace Globaly" and "Replace in Mesh"

source/blender/include/BIF_editmesh.h
source/blender/include/blendef.h
source/blender/makesdna/DNA_space_types.h
source/blender/src/drawimage.c
source/blender/src/editmesh_mods.c
source/blender/src/editmesh_tools.c
source/blender/src/editsima.c
source/blender/src/header_image.c
source/blender/src/space.c

index 2a6f3e4b559dce07c5ae2936a6caf056e8c54a2a..6539fe00b80f0fd80359b6ddec634ad613bb93c6 100644 (file)
@@ -223,6 +223,7 @@ extern void join_triangles(void);
 extern void edge_flip(void);
 extern void fill_mesh(void);
 extern void bevel_menu();
+void mesh_set_face_flags(short mode);
 extern void mesh_set_smooth_faces(short event);
 extern void mesh_rotate_uvs(void);
 extern void mesh_mirror_uvs(void);
index 490d5532ce5ce96e20a535a42d9065d74119b93f..5db45b6571ff0001c437af30707963c8f2bb63f5 100644 (file)
 #define B_SIMAGEHOME           351
 #define B_SIMABROWSE           352
 #define B_SIMAGELOAD           353
-#define B_SIMAGETILE1          354
-#define B_SIMAGETILE2          355
+#define B_SIMA_REDR_IMA_3D     354
+#define B_SIMAGETILE           355
 #define B_BE_SQUARE                    356
 #define B_TWINANIM                     357
 #define B_SIMAGEREPLACE                358
index c587a406388ca20765424860170a759e4947fb30..af6bb24e284aaa5b55a2d527ea57ca80ae188794 100644 (file)
@@ -232,7 +232,8 @@ typedef struct SpaceImage {
        
        struct CurveMapping *cumap;
        short mode, menunr;
-       short imanr, curtile;
+       short imanr;
+       short curtile; /* the currently active tile of the image when tile is enabled, is kept in sync with the active faces tile */
        int flag;
        short imtypenr, lock;
        short showspare, pin;
index 01e4b41db8a8e686643579685759c3b6dbb07c65..05cd04946baa462fb33c26d4b96883235b143d03 100644 (file)
@@ -244,8 +244,7 @@ void what_image(SpaceImage *sima)
 {
        MTFace *activetf;
                
-       if(             (sima->pin != 0) ||
-                       (sima->mode!=SI_TEXTURE) ||
+       if(             (sima->mode!=SI_TEXTURE) ||
                        (sima->image && sima->image->source==IMA_SRC_VIEWER) ||
                        (G.obedit != OBACT)
        ) {
@@ -253,11 +252,14 @@ void what_image(SpaceImage *sima)
        }
        
        /* viewer overrides faceselect */
-       sima->image= NULL;
+       if (!sima->pin)
+               sima->image= NULL;
+       
        activetf = get_active_mtface(NULL, NULL, 1); /* partially selected face is ok */
        
        if(activetf && activetf->mode & TF_TEX) {
-               sima->image= activetf->tpage;
+               if (!sima->pin)
+                       sima->image= activetf->tpage;
                
                if(sima->flag & SI_EDITTILE);
                else sima->curtile= activetf->tile;
@@ -327,14 +329,17 @@ void image_changed(SpaceImage *sima, Image *image)
        object_uvs_changed(OBACT);
        allqueue(REDRAWBUTSEDIT, 0);
 }
-
+/*
+ * dotile -    1, set the tile flag (from the space image)
+ *                     2, set the tile index for the faces. 
+ * */
 void image_set_tile(SpaceImage *sima, int dotile)
 {
        MTFace *tface;
        EditMesh *em = G.editMesh;
        EditFace *efa;
        
-       if(sima->mode!=SI_TEXTURE || !EM_texFaceCheck())
+       if(!sima->image || sima->mode!=SI_TEXTURE || !EM_texFaceCheck())
                return;
        
        /* skip assigning these procedural images... */
@@ -343,15 +348,20 @@ void image_set_tile(SpaceImage *sima, int dotile)
        
        for (efa= em->faces.first; efa; efa= efa->next) {
                tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
-               if (SIMA_FACEDRAW_CHECK(efa, tface)) {
-                       if(dotile==2) {
-                               tface->mode &= ~TF_TILES;
-                       } else if (dotile) {
+               if (efa->h==0 && efa->f & SELECT) {
+                       if (dotile==1) {
+                               /* set tile flag */
+                               if (sima->image->tpageflag & IMA_TILES) {
+                                       tface->mode |= TF_TILES;
+                               } else {
+                                       tface->mode &= ~TF_TILES;
+                               }
+                       } else if (dotile==2) {
+                               /* set tile index */
                                tface->tile= sima->curtile;
                        }
                }
        }
-       
        object_uvs_changed(OBACT);
        allqueue(REDRAWBUTSEDIT, 0);
 }
@@ -1016,9 +1026,9 @@ static void image_panel_game_properties(short cntrl)      // IMAGE_HANDLER_GAME_PROPE
                uiBlockEndAlign(block);
 
                uiBlockBeginAlign(block);
-               uiDefButBitS(block, TOG, IMA_TILES, B_SIMAGETILE2, "Tiles",     160,150,140,19, &G.sima->image->tpageflag, 0, 0, 0, 0, "Toggles use of tilemode for faces (Shift LMB to pick the tile for selected faces)");
-               uiDefButS(block, NUM, B_SIMAGETILE1, "X:",              160,130,70,19, &G.sima->image->xrep, 1.0, 16.0, 0, 0, "Sets the degree of repetition in the X direction");
-               uiDefButS(block, NUM, B_SIMAGETILE1, "Y:",              230,130,70,19, &G.sima->image->yrep, 1.0, 16.0, 0, 0, "Sets the degree of repetition in the Y direction");
+               uiDefButBitS(block, TOG, IMA_TILES, B_SIMAGETILE, "Tiles",      160,150,140,19, &G.sima->image->tpageflag, 0, 0, 0, 0, "Toggles use of tilemode for faces (Shift LMB to pick the tile for selected faces)");
+               uiDefButS(block, NUM, B_SIMA_REDR_IMA_3D, "X:",         160,130,70,19, &G.sima->image->xrep, 1.0, 16.0, 0, 0, "Sets the degree of repetition in the X direction");
+               uiDefButS(block, NUM, B_SIMA_REDR_IMA_3D, "Y:",         230,130,70,19, &G.sima->image->yrep, 1.0, 16.0, 0, 0, "Sets the degree of repetition in the Y direction");
                uiBlockBeginAlign(block);
 
                uiBlockBeginAlign(block);
index a0e632e9883291ddf8496e1b902eb8ffa48130d1..037c01183253e9397b5dbb65b7527d8e8713d47d 100644 (file)
@@ -3408,6 +3408,7 @@ void Face_Menu() {
        ret= pupmenu(
                "Face Specials%t|Flip Normals%x1|Bevel%x2|Shade Smooth%x3|Shade Flat%x4|"
                "Triangulate (Ctrl T)%x5|Quads from Triangles (Alt J)%x6|Flip Triangle Edges (Ctrl Shift F)%x7|%l|"
+               "Face Mode Set%x8|Face Mode Clear%x9|%l|"
                "UV Rotate (Shift - CCW)%x10|UV Mirror (Shift - Switch Axis)%x11|"
                "Color Rotate (Shift - CCW)%x12|Color Mirror (Shift - Switch Axis)%x13");
 
@@ -3439,7 +3440,12 @@ void Face_Menu() {
                case 7: /* Flip triangle edges */
                        edge_flip();
                        break;
-                       
+               case 8:
+                       mesh_set_face_flags(1);
+                       break;
+               case 9:
+                       mesh_set_face_flags(0);
+                       break;
                        
                /* uv texface options */
                case 10:
index 27584d569cf538fabdb97abdf10cc0f0379fcf03..88d1cb172c3c7f302452fd518df3bcd4777a8ed1 100644 (file)
@@ -5103,6 +5103,57 @@ int EdgeSlide(short immediate, float imperc)
 
 /* -------------------- More tools ------------------ */
 
+void mesh_set_face_flags(short mode)
+{
+       EditMesh *em = G.editMesh;
+       EditFace *efa;
+       MTFace *tface;
+       short m_tex=0, m_tiles=0, m_shared=0, m_light=0, m_invis=0, m_collision=0, m_twoside=0, m_obcolor=0; 
+       short flag = 0, change = 0;
+       
+       if(G.obedit==0) return;
+       
+       if(G.obedit->type != OB_MESH) return;
+       
+       add_numbut(0, TOG|SHO, "Texture", 0, 0, &m_tex, NULL);
+       add_numbut(1, TOG|SHO, "Tiles", 0, 0, &m_tiles, NULL);
+       add_numbut(2, TOG|SHO, "Shared", 0, 0, &m_shared, NULL);
+       add_numbut(3, TOG|SHO, "Light", 0, 0, &m_light, NULL);
+       add_numbut(4, TOG|SHO, "Invisible", 0, 0, &m_invis, NULL);
+       add_numbut(5, TOG|SHO, "Collision", 0, 0, &m_collision, NULL);
+       add_numbut(6, TOG|SHO, "Twoside", 0, 0, &m_twoside, NULL);
+       add_numbut(7, TOG|SHO, "ObColor", 0, 0, &m_obcolor, NULL);
+       
+       if (!do_clever_numbuts((mode ? "Set Flags" : "Clear Flags"), 8, REDRAW))
+               return;
+       
+       if (m_tex)                      flag |= TF_TEX;
+       if (m_tiles)            flag |= TF_TILES;
+       if (m_shared)           flag |= TF_SHAREDCOL;
+       if (m_light)            flag |= TF_LIGHT;
+       if (m_invis)            flag |= TF_INVISIBLE;
+       if (m_collision)        flag |= TF_DYNAMIC;
+       if (m_twoside)          flag |= TF_TWOSIDE;
+       if (m_obcolor)          flag |= TF_OBCOL;
+       
+       efa= em->faces.first;
+       while(efa) {
+               if(efa->f & SELECT) {
+                       tface= CustomData_em_get(&em->fdata, efa->data, CD_MTFACE);
+                       if (mode)       tface->mode |= flag;
+                       else            tface->mode &= ~flag;
+               }
+               efa= efa->next;
+       }
+       
+       if (change) {
+               BIF_undo_push((mode ? "Set Flags" : "Clear Flags"));
+
+               allqueue(REDRAWIMAGE, 0);
+               allqueue(REDRAWVIEW3D, 0);
+       }
+}
+
 void mesh_set_smooth_faces(short event)
 {
        EditMesh *em = G.editMesh;
index f8e69600a948e2e5b2dccda2b9ef42f20c8a49fc..8d17599dd8640b0c53f3e41184987b3dad25cbdb 100644 (file)
@@ -1038,7 +1038,7 @@ void mouseco_to_curtile(void)
                
                G.sima->flag &= ~SI_EDITTILE;
 
-               image_set_tile(G.sima, 1);
+               image_set_tile(G.sima, 2);
 
                allqueue(REDRAWVIEW3D, 0);
                scrarea_queue_winredraw(curarea);
@@ -1622,65 +1622,16 @@ static void load_image_filesel(char *str)       /* called from fileselect */
        allqueue(REDRAWIMAGE, 0);
 }
 
-static void image_replace(Image *old, Image *new)
-{
-       MTFace *tface;
-       Mesh *me;
-       int a, rep=0;
-
-       new->tpageflag= old->tpageflag;
-       new->twsta= old->twsta;
-       new->twend= old->twend;
-       new->xrep= old->xrep;
-       new->yrep= old->yrep;
-       /* TODO - This is incorrect!! -
-        * replace should take all layers into account,
-        * should also work with editmode */
-       me= G.main->mesh.first;
-       while(me) {
-
-               if(me->id.lib==NULL && me->mtface) {
-                       tface= me->mtface;
-                       a= me->totface;
-                       while(a--) {
-                               if(tface->tpage==old) {
-                                       tface->tpage= new;
-                                       rep++;
-                               }
-                               tface++;
-                       }
-               }
-               me= me->id.next;
-       }
-       if(rep) {
-               if(new->id.us==0) id_us_plus(&new->id);
-               else id_lib_extern(&new->id);
-               
-       }
-       else error("Nothing replaced");
-}
-
 static void replace_image_filesel(char *str)           /* called from fileselect */
 {
-       Image *ima=0;
+       if (!G.sima->image)
+               return;
        
-       ima= BKE_add_image_file(str);
-       if(ima) {
-               if(G.sima->image && G.sima->image != ima) {
-                       image_replace(G.sima->image, ima);
-               }
-
-               BKE_image_signal(ima, &G.sima->iuser, IMA_SIGNAL_RELOAD);
-
-               /* replace also assigns: */
-               image_changed(G.sima, ima);
-
-       }
+       strncpy(G.sima->image->name, str, sizeof(G.sima->image->name)-1); /* we cant do much if the str is longer then 240 :/ */
+       BKE_image_signal(G.sima->image, &G.sima->iuser, IMA_SIGNAL_RELOAD);
        BIF_undo_push("Replace image UV");
        allqueue(REDRAWIMAGE, 0);
+       allqueue(REDRAWVIEW3D, 0);
 }
 
 
@@ -1918,7 +1869,6 @@ void save_image_sequence_sima(void)
 
 void reload_image_sima(void)
 {
-
        if (G.sima ) {
                BKE_image_signal(G.sima->image, &G.sima->iuser, IMA_SIGNAL_RELOAD);
                /* image_changed(G.sima, 0); - do we really need this? */
index 3bcdd1aa45b410e1df006771c738d8311d36103a..a01fa72abc8396ef7252d252017c9505dbb54c92 100644 (file)
@@ -142,27 +142,17 @@ void do_image_buttons(unsigned short event)
                BIF_undo_push("Assign image UV");
 
                break;
-               
-       case B_SIMAGETILE1:
-               if (EM_texFaceCheck()) {
-                       make_repbind(G.sima->image);
-                       image_set_tile(G.sima, 1);
-               }
-               /* XXX might be another event needed for this? */
-               if(G.sima->image)
-                       if(ELEM(G.sima->image->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
-                               if(G.sima->iuser.flag & IMA_ANIM_ALWAYS)
-                                       BKE_image_user_calc_imanr(&G.sima->iuser, G.scene->r.cfra, 0);
+       case B_SIMAGETILE:
+               image_set_tile(G.sima, 1);              /* 1: only tileflag */
                allqueue(REDRAWVIEW3D, 0);
                allqueue(REDRAWIMAGE, 0);
                break;
-       case B_SIMAGETILE2:
-               image_set_tile(G.sima, 2);              /* 2: only tileflag */
+       case B_SIMA3DVIEWDRAW:
                allqueue(REDRAWVIEW3D, 0);
-               allqueue(REDRAWIMAGE, 0);
                break;
-       case B_SIMA3DVIEWDRAW:
+       case B_SIMA_REDR_IMA_3D:
                allqueue(REDRAWVIEW3D, 0);
+               allqueue(REDRAWIMAGE, 0);
                break;
        case B_SIMAGEPAINTTOOL:
                if(G.sima->flag & SI_DRAWTOOL)
index e2fbf14e3446ba5857341f6dd09c8d59861c5787..d2595ad5f4edf5ac1983389d6fdf13fc3f67536d 100644 (file)
@@ -4795,8 +4795,13 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                if (EM_texFaceCheck() && (G.sima->image==0 || (G.sima->image->type != IMA_TYPE_R_RESULT && G.sima->image->type != IMA_TYPE_COMPOSITE))) {
                        switch(event) {
                        case LEFTMOUSE:
-                               if (!gesture())
+                               if(G.qual == LR_SHIFTKEY) {
+                                       if(G.sima->image && G.sima->image->tpageflag & IMA_TILES) {
+                                               mouseco_to_curtile();
+                                       }
+                               } else if (!gesture()) {
                                        mouseco_to_cursor_sima();
+                               }
                                break;
                        case RIGHTMOUSE:
                                mouse_select_sima();
@@ -4921,6 +4926,10 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                scrarea_queue_headredraw(curarea);
                                scrarea_queue_winredraw(curarea);
                                break;
+                       case PADPERIOD:
+                               if(G.qual==0)
+                                       image_viewcenter();
+                               break;
                        case OKEY:
                                if(G.qual==0) {
                                        G.scene->proportional= !G.scene->proportional;
@@ -4942,14 +4951,7 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                /* Draw and editmode are inactive */
                switch(event) {
                case LEFTMOUSE:
-                       if(G.qual & LR_SHIFTKEY) {
-                               if(G.sima->image && G.sima->image->tpageflag & IMA_TILES)
-                                       mouseco_to_curtile();
-                               else
-                                       sima_sample_color();
-                       } else { 
-                               sima_sample_color();
-                       }
+                       sima_sample_color();
                        break;
                case RIGHTMOUSE:
                        if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT))
@@ -4965,10 +4967,6 @@ static void winqreadimagespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                scrarea_queue_winredraw(sa);
                        }
                        break;
-               case PADPERIOD:
-                       if(G.qual==0)
-                               image_viewcenter();
-                       break;
                }
        }