[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59609] branches/soc-2013-paint: Change the way projective texture painting sets up the paint layers.

Antony Riakiotakis kalast at gmail.com
Wed Aug 28 18:18:54 CEST 2013


Revision: 59609
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59609
Author:   psy-fi
Date:     2013-08-28 16:18:53 +0000 (Wed, 28 Aug 2013)
Log Message:
-----------
Change the way projective texture painting sets up the paint layers.

Projective texture painting now includes a material list in the
projection painting options in the toolbar. By selecting a material in
this menu, the user can see the avalailable texture layers that can be
used for painting (Those that are of image type and have UV mapping
currently, as expalined by a label below) in a separate texture list.

http://www.pasteall.org/pic/58315

By selecting textures in that list, the user can now immediately select
a texture slot of the material to paint on. This means that painting now
has immediate effect on the output of rendering :)

Now time to gather artist feedback.

TODO:
* Improve behaviour of projection painting so that it uses the UV layer
of the texture slot, if it exists, instead of the active UV layer.

* Find a way to cache the active paint image of the material. There are
a few places this can get invalidated. I'd like a central way to handle
this but probably a case by case solution will have to be made

* Add more user convenience functions: Operators to add material layers
for painting, automatically adding layers/materials if they do not
exist, maybe automatic UV unwrapping? With appropriate warning that for
optimal results a manual unwrap is needed.

Modified Paths:
--------------
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h
    branches/soc-2013-paint/source/blender/blenkernel/intern/material.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c
    branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c
    branches/soc-2013-paint/source/blender/makesrna/intern/rna_material.c

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-08-28 16:03:56 UTC (rev 59608)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-08-28 16:18:53 UTC (rev 59609)
@@ -1252,11 +1252,13 @@
         col = layout.column()
 
         if ob:
-            col.label("Paint layers")
+            col.label("Materials")
             col.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=2)
             mat = ob.active_material;
             if mat:
+                col.label("Available Paint layers")
                 col.template_list("TEXTURE_UL_texpaintslots", "", mat, "texture_paint_slots", mat, "active_paint_texture_index", rows=2)
+                col.label("Only slots with UV mapping and image textures are available")
 
         col.prop(ipaint, "input_samples")
 

Modified: branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h	2013-08-28 16:03:56 UTC (rev 59608)
+++ branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h	2013-08-28 16:18:53 UTC (rev 59609)
@@ -43,6 +43,8 @@
 struct Mesh;
 struct MTFace;
 struct Scene;
+struct Image;
+struct MTex;
 
 /* materials */
 
@@ -86,6 +88,9 @@
 int object_add_material_slot(struct Object *ob);
 int object_remove_material_slot(struct Object *ob);
 
+bool get_mtex_slot_valid_texpaint(struct MTex *);
+struct Image *give_current_texpaint_image(struct Material *ma);
+
 /* rna api */
 void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user);
 void BKE_material_append_id(struct ID *id, struct Material *ma);

Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/material.c	2013-08-28 16:03:56 UTC (rev 59608)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/material.c	2013-08-28 16:18:53 UTC (rev 59609)
@@ -1299,7 +1299,37 @@
 	return TRUE;
 }
 
+bool get_mtex_slot_valid_texpaint(struct MTex *mtex)
+{
+		return mtex && (mtex->texco == TEXCO_UV) &&
+		       mtex->tex && (mtex->tex->type == TEX_IMAGE) &&
+		       mtex->tex->ima;
+}
 
+struct Image *give_current_texpaint_image(Material *ma)
+{
+	MTex **mtex, *validmtex = NULL;
+
+	short index = 0, i = 0;
+
+	for(mtex = ma->mtex; i < MAX_MTEX; i++, mtex++) {
+		if (get_mtex_slot_valid_texpaint(*mtex)) {
+			if (index++ == ma->texactpaint)
+				return (*mtex)->tex->ima;
+
+			validmtex = *mtex;
+		}
+	}
+
+	/* possible to not have selected anything as active texture. Just set to a valid index */
+	if (index > 0) {
+		ma->texactpaint = index;
+		return validmtex->tex->ima;
+	}
+
+	return NULL;
+}
+
 /* r_col = current value, col = new value, (fac == 0) is no change */
 void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
 {

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c	2013-08-28 16:03:56 UTC (rev 59608)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c	2013-08-28 16:18:53 UTC (rev 59609)
@@ -68,6 +68,7 @@
 #include "BKE_image.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
+#include "BKE_material.h"
 #include "BKE_mesh.h"
 #include "BKE_node.h"
 #include "BKE_object.h"
@@ -336,7 +337,7 @@
 
 /* Finish projection painting structs */
 
-static Image *project_paint_face_image(const ProjPaintState *ps, MTFace *dm_mtface, int face_index)
+static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
 {
 	Image *ima;
 
@@ -345,12 +346,30 @@
 		ED_object_get_active_image(ps->ob, mf->mat_nr + 1, &ima, NULL, NULL);
 	}
 	else {
+		MFace *mf = ps->dm_mface + face_index;
+		Material *ma = give_current_material(ps->ob, mf->mat_nr + 1);
+		ima = give_current_texpaint_image(ma);
+	}
+
+	return ima;
+}
+
+static Image *project_paint_mtface_image(const ProjPaintState *ps, MTFace *dm_mtface, int face_index)
+{
+	Image *ima;
+
+	if (ps->do_new_shading_nodes) { /* cached BKE_scene_use_new_shading_nodes result */
+		MFace *mf = ps->dm_mface + face_index;
+		ED_object_get_active_image(ps->ob, mf->mat_nr + 1, &ima, NULL, NULL);
+	}
+	else {
 		ima = dm_mtface[face_index].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])
 {
@@ -547,7 +566,7 @@
 		interp_v2_v2v2v2(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
 	}
 
-	ima = project_paint_face_image(ps, ps->dm_mtface, face_index);
+	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;
 
@@ -913,8 +932,8 @@
 
 			/* 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, ps->dm_mtface, face_index);
-				Image *orig_tpage = project_paint_face_image(ps, ps->dm_mtface, orig_face);
+				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;
@@ -1236,7 +1255,7 @@
 	if (ps->do_layer_stencil) {
 		/* another UV maps image is masking this one's */
 		ImBuf *ibuf_other;
-		Image *other_tpage = project_paint_face_image(ps, ps->dm_mtface_stencil, face_index);
+		Image *other_tpage = project_paint_mtface_image(ps, ps->dm_mtface_stencil, face_index);
 		const MTFace *tf_other = ps->dm_mtface_stencil + face_index;
 
 		if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, NULL, NULL))) {
@@ -1444,7 +1463,7 @@
 	if (ps->tool == PAINT_TOOL_CLONE) {
 		if (ps->dm_mtface_clone) {
 			ImBuf *ibuf_other;
-			Image *other_tpage = project_paint_face_image(ps, ps->dm_mtface_clone, face_index);
+			Image *other_tpage = project_paint_mtface_image(ps, ps->dm_mtface_clone, face_index);
 			const MTFace *tf_other = ps->dm_mtface_clone + face_index;
 
 			if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, NULL, NULL))) {
@@ -2809,7 +2828,7 @@
 			face_index = GET_INT_FROM_POINTER(node->link);
 
 			/* Image context switching */
-			tpage = project_paint_face_image(ps, ps->dm_mtface, face_index);
+			tpage = project_paint_face_image(ps, face_index);
 			if (tpage_last != tpage) {
 				tpage_last = tpage;
 
@@ -3358,7 +3377,7 @@
 			is_face_sel = true;
 		}
 
-		if (is_face_sel && (tpage = project_paint_face_image(ps, ps->dm_mtface, face_index))) {
+		if (is_face_sel && (tpage = project_paint_face_image(ps, face_index))) {
 			float *v1coSS, *v2coSS, *v3coSS, *v4coSS = NULL;
 
 			v1coSS = ps->screenCoords[mf->v1];

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c	2013-08-28 16:03:56 UTC (rev 59608)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c	2013-08-28 16:18:53 UTC (rev 59609)
@@ -35,6 +35,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
+#include "DNA_material_types.h"
 
 #include "DNA_scene_types.h"
 #include "DNA_brush_types.h"
@@ -50,6 +51,7 @@
 #include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_material.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
 #include "BKE_image.h"
@@ -354,15 +356,15 @@
 	Image *ima;
 
 	MFace *dm_mface = dm->getTessFaceArray(dm);
-	MTFace *dm_mtface = dm->getTessFaceDataArray(dm, CD_MTFACE);
 
 	if (BKE_scene_use_new_shading_nodes(scene)) {
 		MFace *mf = &dm_mface[face_index];
 		ED_object_get_active_image(ob, mf->mat_nr + 1, &ima, NULL, NULL);
 	}
 	else {
-		MTFace *tf = &dm_mtface[face_index];
-		ima = tf->tpage;
+		MFace *mf = dm_mface + face_index;
+		Material *ma = give_current_material(ob, mf->mat_nr + 1);
+		ima = give_current_texpaint_image(ma);
 	}
 
 	return ima;

Modified: branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c	2013-08-28 16:03:56 UTC (rev 59608)
+++ branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c	2013-08-28 16:18:53 UTC (rev 59609)
@@ -231,23 +231,25 @@
 	static int c_lit;
 	static int c_has_texface;
 
-	Object *litob = NULL;  /* to get mode to turn off mipmap in painting mode */
 	int backculled = 1;
 	int alphablend = 0;
 	int textured = 0;
 	int lit = 0;
 	int has_texface = texface != NULL;
 	bool need_set_tpage = false;
+	bool texpaint = false;
+	Image *ima = NULL;
 
 	if (clearcache) {
 		c_textured = c_lit = c_backculled = -1;
 		memset(&c_texface, 0, sizeof(MTFace));
 		c_badtex = false;
 		c_has_texface = -1;
+		c_ma = NULL;
 	}
 	else {
 		textured = gtexdraw.is_tex;
-		litob = gtexdraw.ob;
+		texpaint = ((gtexdraw.ob->mode & OB_MODE_TEXTURE_PAINT) != 0);
 	}
 
 	/* convert number of lights into boolean */
@@ -259,14 +261,16 @@
 		backculled = (ma->game.flag & GEMAT_BACKCULL) || gtexdraw.use_backface_culling;
 	}
 
-	if (texface) {
+	if (texface && !texpaint) {
 		textured = textured && (texface->tpage);
 
 		/* no material, render alpha if texture has depth=32 */
 		if (!ma && BKE_image_has_alpha(texface->tpage))
 			alphablend = GPU_BLEND_ALPHA;
 	}
-
+	else if (texpaint) {
+		ima = ma ? give_current_texpaint_image(ma) : NULL;
+	}
 	else
 		textured = 0;
 
@@ -280,11 +284,23 @@
 	/* need to re-set tpage if textured flag changed or existsment of texface changed..  */
 	need_set_tpage = textured != c_textured || has_texface != c_has_texface;
 	/* ..or if settings inside texface were changed (if texface was used) */
-	need_set_tpage |= texface && memcmp(&c_texface, texface, sizeof(c_texface));

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list