[Bf-blender-cvs] [1149157] soc-2013-paint: Change the clone tool to use the new slot system.

Antony Riakiotakis noreply at git.blender.org
Fri Apr 25 01:49:12 CEST 2014


Commit: 11491572cb5cbc229a62940ae8eaf3318e109a98
Author: Antony Riakiotakis
Date:   Fri Apr 25 02:49:01 2014 +0300
https://developer.blender.org/rB11491572cb5cbc229a62940ae8eaf3318e109a98

Change the clone tool to use the new slot system.

When clone from layer is active, a layer selection will be available in
the the layer panel and the tool will sample from the selected clone
layer.

This is not ideal UI wise, the user has to change between tabs and
panels to set the option - Maybe a good reason to rethink about setting
the layer panel to the right.

This makes the mtface_clone_layer functions and data obsolete for
texture painting.

===================================================================

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/material.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_material.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index cbb6e18..1eb7fe8 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1100,6 +1100,7 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
         layout = self.layout
 
         settings = context.tool_settings.image_paint
+        brush = settings.brush
 
         ob = context.active_object
         col = layout.column()
@@ -1110,7 +1111,6 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
         if mat:
             col.label("Available Paint Slots")
             col.template_list("TEXTURE_UL_texpaintslots", "", mat, "texture_paint_slots", mat, "paint_active_slot", rows=2)
-            #col.label("Only slots with UV mapping and image textures are available")
             
             if not mat.use_nodes:
                 col.operator_menu_enum("paint.add_texture_paint_slot", "type")
@@ -1118,6 +1118,11 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
                 row = col.row(align=True)
                 row.prop(settings, "new_slot_xresolution")
                 row.prop(settings, "new_slot_yresolution")
+                
+            if brush.image_tool == 'CLONE' and settings.use_clone_layer:
+                col.label("Clone Slot")
+                col.template_list("TEXTURE_UL_texpaintslots", "", mat, "texture_paint_slots", mat, "paint_clone_slot", rows=2)
+            
 
 
 class VIEW3D_PT_tools_brush_overlay(Panel, View3DPaintPanel):
@@ -1665,9 +1670,9 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel, Panel):
 
         col = layout.column()
         col.active = (settings.brush.image_tool == 'CLONE')
-        col.prop(ipaint, "use_clone_layer", text="Clone from UV map")
-        clone_text = mesh.uv_texture_clone.name if mesh.uv_texture_clone else ""
-        col.menu("VIEW3D_MT_tools_projectpaint_clone", text=clone_text, translate=False)
+        col.prop(ipaint, "use_clone_layer", text="Clone from paint slot")
+        #clone_text = mesh.uv_texture_clone.name if mesh.uv_texture_clone else ""
+        #col.menu("VIEW3D_MT_tools_projectpaint_clone", text=clone_text, translate=False)
 
         layout.prop(ipaint, "seam_bleed")
 
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 2b5acd7..61956e6 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1386,6 +1386,10 @@ void refresh_texpaint_image_cache(Material *ma, bool use_nodes)
 		ma->paint_active_slot = count - 1;
 	}
 
+	if (ma->paint_clone_slot >= count) {
+		ma->paint_clone_slot = count - 1;
+	}
+
 	return;
 }
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 6a2e9c1..c02e556 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -220,7 +220,7 @@ typedef struct ProjPaintState {
 	MVert          *dm_mvert;
 	MFace          *dm_mface;
 	MTFace         **dm_mtface;
-	MTFace         *dm_mtface_clone;    /* other UV map, use for cloning between layers */
+	MTFace         **dm_mtface_clone;    /* other UV map, use for cloning between layers */
 	MTFace         *dm_mtface_stencil;
 
 	/* projection painting only */
@@ -349,28 +349,18 @@ typedef struct {
 
 /* Finish projection painting structs */
 
-static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
+static TexPaintSlot *project_paint_face_paint_slot(const ProjPaintState *ps, 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 {
-		MFace *mf = ps->dm_mface + face_index;
-		Material *ma = ps->dm->mat[mf->mat_nr];
-		ima = ma->texpaintslot[ma->paint_active_slot].ima;
-	}
-
-	return ima;
+	MFace *mf = ps->dm_mface + face_index;
+	Material *ma = ps->dm->mat[mf->mat_nr];
+	return &ma->texpaintslot[ma->paint_active_slot];
 }
 
-static TexPaintSlot *project_paint_face_paint_slot(const ProjPaintState *ps, int face_index)
+static TexPaintSlot *project_paint_face_clone_slot(const ProjPaintState *ps, int face_index)
 {
 	MFace *mf = ps->dm_mface + face_index;
 	Material *ma = ps->dm->mat[mf->mat_nr];
-	return &ma->texpaintslot[ma->paint_active_slot];
+	return &ma->texpaintslot[ma->paint_clone_slot];
 }
 
 
@@ -389,7 +379,6 @@ static Image *project_paint_mtface_image(const ProjPaintState *ps, MTFace *dm_mt
 	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])
 {
@@ -565,7 +554,7 @@ static bool project_paint_PickColor(const ProjPaintState *ps, const float pt[2],
 		interp_v2_v2v2v2(uv, tf->uv[0], tf->uv[2], tf->uv[3], w);
 	}
 
-	ima = project_paint_face_image(ps, face_index);
+	ima = project_paint_face_paint_slot(ps, face_index)->ima;
 	ibuf = BKE_image_get_first_ibuf(ima); /* we must have got the imbuf before getting here */
 	if (!ibuf) return 0;
 
@@ -927,8 +916,8 @@ static bool check_seam(const ProjPaintState *ps,
 
 			/* 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);
+				Image *tpage = project_paint_face_paint_slot(ps, face_index)->ima;
+				Image *orig_tpage = project_paint_face_paint_slot(ps, orig_face)->ima;
 
 				BLI_assert(i1_fidx != -1);
 
@@ -1500,8 +1489,8 @@ static ProjPixel *project_paint_uvpixel_init(
 	if (ps->tool == PAINT_TOOL_CLONE) {
 		if (ps->dm_mtface_clone) {
 			ImBuf *ibuf_other;
-			Image *other_tpage = project_paint_mtface_image(ps, ps->dm_mtface_clone, face_index);
-			const MTFace *tf_other = ps->dm_mtface_clone + face_index;
+			Image *other_tpage = project_paint_face_clone_slot(ps, face_index)->ima;
+			const MTFace *tf_other = ps->dm_mtface_clone[face_index];
 
 			if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, NULL, NULL))) {
 				/* BKE_image_acquire_ibuf - TODO - this may be slow */
@@ -2763,7 +2752,7 @@ static void project_bucket_init(const ProjPaintState *ps, const int thread_index
 			face_index = GET_INT_FROM_POINTER(node->link);
 
 			/* Image context switching */
-			tpage = project_paint_face_image(ps, face_index);
+			tpage = project_paint_face_paint_slot(ps, face_index)->ima;
 			if (tpage_last != tpage) {
 				tpage_last = tpage;
 
@@ -2932,6 +2921,7 @@ static void project_paint_begin(ProjPaintState *ps)
 	ProjPaintImage *projIma;
 	Image *tpage_last = NULL, *tpage;
 	TexPaintSlot *slot_last = NULL, *slot;
+	TexPaintSlot *slot_last_clone = NULL, *slot_clone;
 
 	/* Face vars */
 	MPoly *mpoly_orig;
@@ -2939,6 +2929,9 @@ static void project_paint_begin(ProjPaintState *ps)
 	MTFace **tf;
 	MTFace *tf_base;
 
+	MTFace **tf_clone;
+	MTFace *tf_clone_base;
+
 	int a, i; /* generic looping vars */
 	int image_index = -1, face_index;
 
@@ -2994,13 +2987,13 @@ static void project_paint_begin(ProjPaintState *ps)
 
 	DM_update_materials(ps->dm, ps->ob);
 
-	ps->dm_mvert = ps->dm->getVertArray(ps->dm);
-	ps->dm_mface = ps->dm->getTessFaceArray(ps->dm);
-	ps->dm_mtface = MEM_mallocN(ps->dm->getNumTessFaces(ps->dm) * sizeof (MTFace *), "proj_paint_mtfaces");
-
 	ps->dm_totvert = ps->dm->getNumVerts(ps->dm);
 	ps->dm_totface = ps->dm->getNumTessFaces(ps->dm);
 
+	ps->dm_mvert = ps->dm->getVertArray(ps->dm);
+	ps->dm_mface = ps->dm->getTessFaceArray(ps->dm);
+	ps->dm_mtface = MEM_mallocN(ps->dm_totface * sizeof (MTFace *), "proj_paint_mtfaces");
+
 	if (ps->do_face_sel) {
 		index_mf_to_mpoly = ps->dm->getTessFaceDataArray(ps->dm, CD_ORIGINDEX);
 		index_mp_to_orig  = ps->dm->getPolyDataArray(ps->dm, CD_ORIGINDEX);
@@ -3016,20 +3009,8 @@ static void project_paint_begin(ProjPaintState *ps)
 	}
 
 	/* use clone mtface? */
-
-
-	/* Note, use the original mesh for getting the clone and mask layer index
-	 * this avoids re-generating the derived mesh just to get the new index */
 	if (ps->do_layer_clone) {
-		//int layer_num = CustomData_get_clone_layer(&ps->dm->faceData, CD_MTFACE);
-		int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->pdata, CD_MTEXPOLY);
-		if (layer_num != -1)
-			ps->dm_mtface_clone = CustomData_get_layer_n(&ps->dm->faceData, CD_MTFACE, layer_num);
-
-		if (ps->dm_mtface_clone == NULL) {
-			ps->do_layer_clone = false;
-			ps->dm_mtface_clone = NULL;
-		}
+		ps->dm_mtface_clone = MEM_mallocN(ps->dm_totface * sizeof (MTFace *), "proj_paint_mtfaces");
 	}
 
 	if (ps->do_layer_stencil) {
@@ -3326,19 +3307,36 @@ static void project_paint_begin(ProjPaintState *ps)
 				tf_base = CustomData_get_layer_named(&ps->dm->faceData, CD_MTFACE, slot->uvname);
 			else
 				tf_base = CustomData_get_layer(&ps->dm->faceData, CD_MTFACE);
-			*tf = tf_base + face_index;
 			slot_last = slot;
 		}
-		else {
-			*tf = tf_base + face_index;
+
+		*tf = tf_base + face_index;
+
+		if (ps->do_layer_clone) {
+			slot_clone = project_paint_face_clone_slot(ps, face_index);
+			/* all faces should have a valid slot, reassert here */
+			if (ELEM(slot_clone, NULL, slot))
+				continue;
+
+			tf_clone = ps->dm_mtface_clone + face_index;
+
+			if (slot_clone != slot_last_clone) {
+				if (slot_clone->uvname[0])
+					tf_clone_base = CustomData_get_layer_named(&ps->dm->faceData, CD_MTFACE, slot_clone->uvname);
+				else
+					tf_clone_base = CustomData_get_layer(&ps->dm->faceData, CD_MTFACE);
+				slot_last_clone = slot_clone;
+			}
+
+			*tf_clone = tf_clone_base + face_index;
 		}
 
 		/* tfbase here should be non-null! */
-		BLI_assert (tf_base!= NULL);
-		if (ps->dm_mtface_stencil == tf_base || ps->dm_mtface_clone == tf_base)
+		BLI_assert (tf_base != NULL);
+		if (ps->dm_mtface_stencil == tf_base)
 			continue;
 
-		if (is_face_sel && ((slot && (tpage = slot->ima)) || (tpage = project_paint_face_image(ps, face_index)))) {
+	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list