[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12094] trunk/blender/source/blender: reworked how tile functions, seperated image and tile setting functions/ events and made tile work with image pinning.

Campbell Barton cbarton at metavr.com
Wed Sep 19 18:28:52 CEST 2007


Revision: 12094
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12094
Author:   campbellbarton
Date:     2007-09-19 18:28:52 +0200 (Wed, 19 Sep 2007)

Log Message:
-----------
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"

Modified Paths:
--------------
    trunk/blender/source/blender/include/BIF_editmesh.h
    trunk/blender/source/blender/include/blendef.h
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/src/drawimage.c
    trunk/blender/source/blender/src/editmesh_mods.c
    trunk/blender/source/blender/src/editmesh_tools.c
    trunk/blender/source/blender/src/editsima.c
    trunk/blender/source/blender/src/header_image.c
    trunk/blender/source/blender/src/space.c

Modified: trunk/blender/source/blender/include/BIF_editmesh.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editmesh.h	2007-09-19 12:13:16 UTC (rev 12093)
+++ trunk/blender/source/blender/include/BIF_editmesh.h	2007-09-19 16:28:52 UTC (rev 12094)
@@ -223,6 +223,7 @@
 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);

Modified: trunk/blender/source/blender/include/blendef.h
===================================================================
--- trunk/blender/source/blender/include/blendef.h	2007-09-19 12:13:16 UTC (rev 12093)
+++ trunk/blender/source/blender/include/blendef.h	2007-09-19 16:28:52 UTC (rev 12094)
@@ -303,8 +303,8 @@
 #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

Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h	2007-09-19 12:13:16 UTC (rev 12093)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h	2007-09-19 16:28:52 UTC (rev 12094)
@@ -232,7 +232,8 @@
 	
 	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;

Modified: trunk/blender/source/blender/src/drawimage.c
===================================================================
--- trunk/blender/source/blender/src/drawimage.c	2007-09-19 12:13:16 UTC (rev 12093)
+++ trunk/blender/source/blender/src/drawimage.c	2007-09-19 16:28:52 UTC (rev 12094)
@@ -244,8 +244,7 @@
 {
 	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 @@
 	}
 	
 	/* 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 @@
 	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 @@
 	
 	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 @@
 		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);

Modified: trunk/blender/source/blender/src/editmesh_mods.c
===================================================================
--- trunk/blender/source/blender/src/editmesh_mods.c	2007-09-19 12:13:16 UTC (rev 12093)
+++ trunk/blender/source/blender/src/editmesh_mods.c	2007-09-19 16:28:52 UTC (rev 12094)
@@ -3408,6 +3408,7 @@
 	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,8 +3440,13 @@
 		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:
 			mesh_rotate_uvs();

Modified: trunk/blender/source/blender/src/editmesh_tools.c
===================================================================
--- trunk/blender/source/blender/src/editmesh_tools.c	2007-09-19 12:13:16 UTC (rev 12093)
+++ trunk/blender/source/blender/src/editmesh_tools.c	2007-09-19 16:28:52 UTC (rev 12094)
@@ -5103,6 +5103,57 @@
 
 /* -------------------- 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;

Modified: trunk/blender/source/blender/src/editsima.c
===================================================================
--- trunk/blender/source/blender/src/editsima.c	2007-09-19 12:13:16 UTC (rev 12093)
+++ trunk/blender/source/blender/src/editsima.c	2007-09-19 16:28:52 UTC (rev 12094)
@@ -1038,7 +1038,7 @@
 		
 		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 @@
 	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 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? */

Modified: trunk/blender/source/blender/src/header_image.c
===================================================================
--- trunk/blender/source/blender/src/header_image.c	2007-09-19 12:13:16 UTC (rev 12093)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list