diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-09-19 20:28:52 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-09-19 20:28:52 +0400 |
commit | 28ae78a745bab375ee227be8846479a4afc02ffd (patch) | |
tree | b69d30c61a66b1a8e430c78f149154d96d1967f0 /source/blender/src | |
parent | 1c603b63c712a539056e122f3facbfdfcc3dd912 (diff) |
reworked how tile functions, seperated image and tile setting functions/events and made tile work with image pinning.
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"
Diffstat (limited to 'source/blender/src')
-rw-r--r-- | source/blender/src/drawimage.c | 38 | ||||
-rw-r--r-- | source/blender/src/editmesh_mods.c | 8 | ||||
-rw-r--r-- | source/blender/src/editmesh_tools.c | 51 | ||||
-rw-r--r-- | source/blender/src/editsima.c | 62 | ||||
-rw-r--r-- | source/blender/src/header_image.c | 20 | ||||
-rw-r--r-- | source/blender/src/space.c | 24 |
6 files changed, 104 insertions, 99 deletions
diff --git a/source/blender/src/drawimage.c b/source/blender/src/drawimage.c index 01e4b41db8a..05cd04946ba 100644 --- a/source/blender/src/drawimage.c +++ b/source/blender/src/drawimage.c @@ -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); diff --git a/source/blender/src/editmesh_mods.c b/source/blender/src/editmesh_mods.c index a0e632e9883..037c0118325 100644 --- a/source/blender/src/editmesh_mods.c +++ b/source/blender/src/editmesh_mods.c @@ -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: diff --git a/source/blender/src/editmesh_tools.c b/source/blender/src/editmesh_tools.c index 27584d569cf..88d1cb172c3 100644 --- a/source/blender/src/editmesh_tools.c +++ b/source/blender/src/editmesh_tools.c @@ -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; diff --git a/source/blender/src/editsima.c b/source/blender/src/editsima.c index f8e69600a94..8d17599dd86 100644 --- a/source/blender/src/editsima.c +++ b/source/blender/src/editsima.c @@ -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? */ diff --git a/source/blender/src/header_image.c b/source/blender/src/header_image.c index 3bcdd1aa45b..a01fa72abc8 100644 --- a/source/blender/src/header_image.c +++ b/source/blender/src/header_image.c @@ -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) diff --git a/source/blender/src/space.c b/source/blender/src/space.c index e2fbf14e344..d2595ad5f4e 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -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; } } |