[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37897] branches/cycles/source/blender/ editors: Cycles: uv editor and texture paint now also use active texture node.

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Jun 28 14:18:18 CEST 2011


Revision: 37897
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37897
Author:   blendix
Date:     2011-06-28 12:18:17 +0000 (Tue, 28 Jun 2011)
Log Message:
-----------
Cycles: uv editor and texture paint now also use active texture node.

Modified Paths:
--------------
    branches/cycles/source/blender/editors/include/ED_uvedit.h
    branches/cycles/source/blender/editors/mesh/mesh_data.c
    branches/cycles/source/blender/editors/sculpt_paint/paint_image.c
    branches/cycles/source/blender/editors/space_image/space_image.c
    branches/cycles/source/blender/editors/space_view3d/drawmesh.c
    branches/cycles/source/blender/editors/uvedit/uvedit_ops.c
    branches/cycles/source/blender/editors/uvedit/uvedit_unwrap_ops.c

Modified: branches/cycles/source/blender/editors/include/ED_uvedit.h
===================================================================
--- branches/cycles/source/blender/editors/include/ED_uvedit.h	2011-06-28 11:21:12 UTC (rev 37896)
+++ branches/cycles/source/blender/editors/include/ED_uvedit.h	2011-06-28 12:18:17 UTC (rev 37897)
@@ -35,6 +35,7 @@
 struct ARegionType;
 struct EditFace;
 struct Image;
+struct ImageUser;
 struct MTFace;
 struct Object;
 struct Scene;
@@ -45,9 +46,12 @@
 void ED_operatortypes_uvedit(void);
 void ED_keymap_uvedit(struct wmKeyConfig *keyconf);
 
-void ED_uvedit_assign_image(struct Scene *scene, struct Object *obedit, struct Image *ima, struct Image *previma);
+void ED_uvedit_assign_image(struct Main *bmain, struct Scene *scene, struct Object *obedit, struct Image *ima, struct Image *previma);
 int ED_uvedit_minmax(struct Scene *scene, struct Image *ima, struct Object *obedit, float *min, float *max);
 
+int ED_object_get_active_image(struct Object *ob, int mat_nr, struct Image **ima, struct ImageUser **iuser);
+void ED_object_assign_active_image(struct Main *bmain, struct Object *ob, int mat_nr, struct Image *ima);
+
 int ED_uvedit_test_silent(struct Object *obedit);
 int ED_uvedit_test(struct Object *obedit);
 

Modified: branches/cycles/source/blender/editors/mesh/mesh_data.c
===================================================================
--- branches/cycles/source/blender/editors/mesh/mesh_data.c	2011-06-28 11:21:12 UTC (rev 37896)
+++ branches/cycles/source/blender/editors/mesh/mesh_data.c	2011-06-28 12:18:17 UTC (rev 37897)
@@ -53,6 +53,7 @@
 #include "BKE_displist.h"
 #include "BKE_image.h"
 #include "BKE_library.h"
+#include "BKE_main.h"
 #include "BKE_material.h"
 #include "BKE_mesh.h"
 #include "BKE_report.h"
@@ -336,6 +337,7 @@
 
 static int drop_named_image_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+	Main *bmain= CTX_data_main(C);
 	Scene *scene= CTX_data_scene(C);
 	View3D *v3d= CTX_wm_view3d(C);
 	Base *base= ED_view3d_give_base_under_cursor(C, event->mval);
@@ -380,7 +382,7 @@
 	if(me->edit_mesh==NULL)
 		return OPERATOR_CANCELLED;
 	
-	ED_uvedit_assign_image(scene, obedit, ima, NULL);
+	ED_uvedit_assign_image(bmain, scene, obedit, ima, NULL);
 
 	if(exitmode) {
 		load_editMesh(scene, obedit);

Modified: branches/cycles/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/cycles/source/blender/editors/sculpt_paint/paint_image.c	2011-06-28 11:21:12 UTC (rev 37896)
+++ branches/cycles/source/blender/editors/sculpt_paint/paint_image.c	2011-06-28 12:18:17 UTC (rev 37897)
@@ -77,6 +77,7 @@
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
+#include "BKE_scene.h"
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
@@ -86,6 +87,7 @@
 #include "ED_image.h"
 #include "ED_screen.h"
 #include "ED_sculpt.h"
+#include "ED_uvedit.h"
 #include "ED_view3d.h"
 
 #include "WM_api.h"
@@ -456,6 +458,40 @@
 		MEM_freeN(tile->rect);
 }
 
+/* get active image for face depending on old/new shading system */
+
+static Image *imapaint_face_image(const ImagePaintState *s, int face_index)
+{
+	Image *ima;
+
+	if(scene_use_new_shading_system(s->scene)) {
+		MFace *mf = s->me->mface+face_index;
+		ED_object_get_active_image(s->ob, mf->mat_nr, &ima, NULL);
+	}
+	else {
+		MTFace *tf = s->me->mtface+face_index;
+		ima = tf->tpage;
+	}
+
+	return ima;
+}
+
+static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
+{
+	Image *ima;
+
+	if(scene_use_new_shading_system(ps->scene)) {
+		MFace *mf = ps->dm_mface+face_index;
+		ED_object_get_active_image(ps->ob, mf->mat_nr, &ima, NULL);
+	}
+	else {
+		MTFace *tf = ps->dm_mtface+face_index;
+		ima = tf->tpage;
+	}
+
+	return ima;
+}
+
 /* fast projection bucket array lookup, use the safe version for bound checking  */
 static int project_bucket_offset(const ProjPaintState *ps, const float projCoSS[2])
 {
@@ -628,6 +664,7 @@
 	int side;
 	int face_index;
 	MTFace *tf;
+	Image *ima;
 	ImBuf *ibuf;
 	int xi, yi;
 	
@@ -645,8 +682,9 @@
 	else { /* QUAD */
 		interp_v2_v2v2v2(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
 	}
-	
-	ibuf = tf->tpage->ibufs.first; /* we must have got the imbuf before getting here */
+
+	ima = project_paint_face_image(ps, face_index);
+	ibuf = ima->ibufs.first; /* we must have got the imbuf before getting here */
 	if (!ibuf) return 0;
 	
 	if (interp) {
@@ -1011,6 +1049,9 @@
 			
 			/* Only need to check if 'i2_fidx' is valid because we know i1_fidx is the same vert on both faces */
 			if (i2_fidx != -1) {
+				Image *tpage = project_paint_face_image(ps, face_index);
+				Image *orig_tpage = project_paint_face_image(ps, orig_face);
+
 				/* This IS an adjacent face!, now lets check if the UVs are ok */
 				tf = ps->dm_mtface + face_index;
 				
@@ -1019,7 +1060,7 @@
 				*orig_fidx = (i1_fidx < i2_fidx) ? i1_fidx : i2_fidx;
 				
 				/* first test if they have the same image */
-				if (	(orig_tf->tpage == tf->tpage) &&
+				if (	(orig_tpage == tpage) &&
 						cmp_uv(orig_tf->uv[orig_i1_fidx], tf->uv[i1_fidx]) &&
 						cmp_uv(orig_tf->uv[orig_i2_fidx], tf->uv[i2_fidx]) )
 				{
@@ -1285,9 +1326,10 @@
 	if (ps->do_layer_stencil) {
 		/* another UV layers image is masking this one's */
 		ImBuf *ibuf_other;
+		Image *other_tpage = project_paint_face_image(ps, face_index);
 		const MTFace *tf_other = ps->dm_mtface_stencil + face_index;
 		
-		if (tf_other->tpage && (ibuf_other = BKE_image_get_ibuf(tf_other->tpage, NULL))) {
+		if (other_tpage && (ibuf_other = BKE_image_get_ibuf(other_tpage, NULL))) {
 			/* BKE_image_get_ibuf - TODO - this may be slow */
 			unsigned char rgba_ub[4];
 			float rgba_f[4];
@@ -1441,9 +1483,10 @@
 	if (ps->tool==PAINT_TOOL_CLONE) {
 		if (ps->dm_mtface_clone) {
 			ImBuf *ibuf_other;
+			Image *other_tpage = project_paint_face_image(ps, face_index);
 			const MTFace *tf_other = ps->dm_mtface_clone + face_index;
 			
-			if (tf_other->tpage && (ibuf_other = BKE_image_get_ibuf(tf_other->tpage, NULL))) {
+			if (other_tpage && (ibuf_other = BKE_image_get_ibuf(other_tpage, NULL))) {
 				/* BKE_image_get_ibuf - TODO - this may be slow */
 				
 				if (ibuf->rect_float) {
@@ -2649,10 +2692,8 @@
 	LinkNode *node;
 	int face_index, image_index=0;
 	ImBuf *ibuf = NULL;
-	MTFace *tf;
+	Image *tpage_last = NULL, *tpage;
 	
-	Image *tpage_last = NULL;
-	
 
 	if (ps->image_tot==1) {
 		/* Simple loop, no context switching */
@@ -2669,9 +2710,9 @@
 			face_index = GET_INT_FROM_POINTER(node->link);
 				
 			/* Image context switching */
-			tf = ps->dm_mtface+face_index;
-			if (tpage_last != tf->tpage) {
-				tpage_last = tf->tpage;
+			tpage = project_paint_face_image(ps, face_index);
+			if (tpage_last != tpage) {
+				tpage_last = tpage;
 				
 				image_index = -1; /* sanity check */
 				
@@ -2841,7 +2882,7 @@
 	LinkNode *node;
 	
 	ProjPaintImage *projIma;
-	Image *tpage_last = NULL;
+	Image *tpage_last = NULL, *tpage;
 	
 	/* Face vars */
 	MFace *mf;
@@ -3174,7 +3215,9 @@
 		}
 #endif
 		
-		if (tf->tpage && ((((Mesh *)ps->ob->data)->editflag & ME_EDIT_PAINT_MASK)==0 || mf->flag & ME_FACE_SEL)) {
+		tpage = project_paint_face_image(ps, face_index);
+
+		if (tpage && ((((Mesh *)ps->ob->data)->editflag & ME_EDIT_PAINT_MASK)==0 || mf->flag & ME_FACE_SEL)) {
 			
 			float *v1coSS, *v2coSS, *v3coSS, *v4coSS=NULL;
 			
@@ -3247,17 +3290,17 @@
 				}
 			}
 			
-			if (tpage_last != tf->tpage) {
+			if (tpage_last != tpage) {
 				
-				image_index = BLI_linklist_index(image_LinkList, tf->tpage);
+				image_index = BLI_linklist_index(image_LinkList, tpage);
 				
-				if (image_index==-1 && BKE_image_get_ibuf(tf->tpage, NULL)) { /* MemArena dosnt have an append func */
-					BLI_linklist_append(&image_LinkList, tf->tpage);
+				if (image_index==-1 && BKE_image_get_ibuf(tpage, NULL)) { /* MemArena dosnt have an append func */
+					BLI_linklist_append(&image_LinkList, tpage);
 					image_index = ps->image_tot;
 					ps->image_tot++;
 				}
 				
-				tpage_last = tf->tpage;
+				tpage_last = tpage;
 			}
 			
 			if (image_index != -1) {
@@ -4444,7 +4487,7 @@
 		) {
 			ImBuf *ibuf;
 			
-			newimage = (s->me->mtface+newfaceindex)->tpage;
+			newimage = imapaint_face_image(s, newfaceindex);
 			ibuf= BKE_image_get_ibuf(newimage, s->sima? &s->sima->iuser: NULL);
 
 			if(ibuf && ibuf->rect)

Modified: branches/cycles/source/blender/editors/space_image/space_image.c
===================================================================
--- branches/cycles/source/blender/editors/space_image/space_image.c	2011-06-28 11:21:12 UTC (rev 37896)
+++ branches/cycles/source/blender/editors/space_image/space_image.c	2011-06-28 12:18:17 UTC (rev 37897)
@@ -49,7 +49,10 @@
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_image.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
 #include "BKE_mesh.h"
+#include "BKE_scene.h"
 #include "BKE_screen.h"
 
 #include "IMB_imbuf_types.h"
@@ -83,7 +86,7 @@
 /* called to assign images to UV faces */
 void ED_space_image_set(bContext *C, SpaceImage *sima, Scene *scene, Object *obedit, Image *ima)
 {
-	ED_uvedit_assign_image(scene, obedit, ima, sima->image);
+	ED_uvedit_assign_image(G.main, scene, obedit, ima, sima->image);
 	
 	/* change the space ima after because uvedit_face_visible uses the space ima
 	 * to check if the face is displayed in UV-localview */
@@ -570,6 +573,7 @@
 
 static void image_refresh(const bContext *C, ScrArea *UNUSED(sa))
 {
+	Scene *scene = CTX_data_scene(C);
 	SpaceImage *sima= CTX_wm_space_image(C);
 	Object *obedit= CTX_data_edit_object(C);
 	Image *ima;
@@ -584,19 +588,31 @@
 	else if(obedit && obedit->type == OB_MESH) {
 		Mesh *me= (Mesh*)obedit->data;
 		EditMesh *em= BKE_mesh_get_editmesh(me);
-		MTFace *tf;
-		
-		if(em && EM_texFaceCheck(em)) {
-			sima->image= NULL;
+		int sloppy= 1; /* partially selected face is ok */
+
+		if(scene_use_new_shading_system(scene)) {
+			/* new shading system, get image from material */
+			EditFace *efa= EM_get_actFace(em, sloppy);
+
+			if(efa)
+				ED_object_get_active_image(obedit, efa->mat_nr, &sima->image, NULL);
+		}
+		else {
+			/* old shading system, we set texface */
+			MTFace *tf;
 			
-			tf = EM_get_active_mtface(em, NULL, NULL, 1); /* partially selected face is ok */
-			
-			if(tf && (tf->mode & TF_TEX)) {
-				/* don't need to check for pin here, see above */
-				sima->image= tf->tpage;
+			if(em && EM_texFaceCheck(em)) {
+				sima->image= NULL;
 				
-				if(sima->flag & SI_EDITTILE);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list