[Bf-blender-cvs] [98d06e4] soc-2013-paint: Stencil:

Antony Riakiotakis noreply at git.blender.org
Fri Apr 25 20:14:22 CEST 2014


Commit: 98d06e4ab01ae9b4f0bf7010dc9a5bd6da85c492
Author: Antony Riakiotakis
Date:   Fri Apr 25 21:14:09 2014 +0300
https://developer.blender.org/rB98d06e4ab01ae9b4f0bf7010dc9a5bd6da85c492

Stencil:

Rework projective paint stencil to use an additional image field. This
again ommits the need to go and assign an image to the UV layer in the
image editor.

Also added an extra paint mask tool. This is not yet hooked up to do
anything, but will eventually paint exclusively on the stencil image
only.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 1eb7fe8..1f1d030 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1662,11 +1662,13 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel, Panel):
 
         split.prop(ipaint, "use_stencil_layer", text="Stencil")
 
-        row = split.row()
-        row.active = (ipaint.use_stencil_layer)
+        col = split.column()
+        col.active = (ipaint.use_stencil_layer)
+        row = col.row()
         stencil_text = mesh.uv_texture_stencil.name if mesh.uv_texture_stencil else ""
         row.menu("VIEW3D_MT_tools_projectpaint_stencil", text=stencil_text, translate=False)
         row.prop(ipaint, "invert_stencil", text="", icon='IMAGE_ALPHA')
+        col.template_ID(ipaint, "stencil_image", new="image.new")
 
         col = layout.column()
         col.active = (settings.brush.image_tool == 'CLONE')
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 5b991e6..205e1af 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -1348,6 +1348,8 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob)
 	Mesh *me;
 	int layernum;
 	bool add_material = false;
+	ImagePaintSettings *imapaint = &(CTX_data_tool_settings(C)->imapaint);
+	Brush *br = BKE_paint_brush(&imapaint->paint);
 
 	/* no material, add one */
 	if (ob->totcol == 0) {
@@ -1385,6 +1387,24 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob)
 	if (layernum == 0) {
 		ED_mesh_uv_texture_add(me, "UVMap", true);
 	}
+
+	/* Make sure we have a stencil to paint on! */
+	if ((br->imagepaint_tool == PAINT_TOOL_MASK) && (imapaint->stencil == NULL)) {
+		int width;
+		int height;
+		Main *bmain = CTX_data_main(C);
+		float color[4] = {0.0, 0.0, 0.0, 1.0};
+
+		/* should not be allowed, but just in case */
+		if (imapaint->new_slot_xresolution == 0)
+			imapaint->new_slot_xresolution = 1024;
+		if (imapaint->new_slot_yresolution == 0)
+			imapaint->new_slot_yresolution = 1024;
+
+		width = imapaint->new_slot_xresolution;
+		height = imapaint->new_slot_yresolution;
+		imapaint->stencil = BKE_image_add_generated(bmain, width, height, "Stencil", 32, false, IMA_GENTYPE_BLANK, color);
+	}
 }
 
 static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index c02e556..7eff47a 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -223,6 +223,8 @@ typedef struct ProjPaintState {
 	MTFace         **dm_mtface_clone;    /* other UV map, use for cloning between layers */
 	MTFace         *dm_mtface_stencil;
 
+	Image *stencil_ima;
+
 	/* projection painting only */
 	MemArena *arena_mt[BLENDER_MAX_THREADS]; /* for multithreading, the first item is sometimes used for non threaded cases too */
 	LinkNode **bucketRect;              /* screen sized 2D array, each pixel has a linked list of ProjPixel's */
@@ -363,22 +365,6 @@ static TexPaintSlot *project_paint_face_clone_slot(const ProjPaintState *ps, int
 	return &ma->texpaintslot[ma->paint_clone_slot];
 }
 
-
-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])
 {
@@ -1238,7 +1224,7 @@ static float project_paint_uvpixel_mask(
 	if (ps->do_layer_stencil) {
 		/* another UV maps image is masking this one's */
 		ImBuf *ibuf_other;
-		Image *other_tpage = project_paint_mtface_image(ps, ps->dm_mtface_stencil, face_index);
+		Image *other_tpage = ps->stencil_ima;
 		const MTFace *tf_other = ps->dm_mtface_stencil + face_index;
 
 		if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, NULL, NULL))) {
@@ -3333,8 +3319,6 @@ static void project_paint_begin(ProjPaintState *ps)
 
 		/* tfbase here should be non-null! */
 		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_paint_slot(ps, face_index)->ima))) {
 			float *v1coSS, *v2coSS, *v3coSS, *v4coSS = NULL;
@@ -4438,6 +4422,7 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
 	ps->scene = scene;
 	ps->ob = ob; /* allow override of active object */
 
+	ps->stencil_ima = settings->imapaint.stencil;
 	/* setup projection painting data */
 	ps->do_backfacecull = (settings->imapaint.flag & IMAGEPAINT_PROJECT_BACKFACE) ? 0 : 1;
 	ps->do_occlude = (settings->imapaint.flag & IMAGEPAINT_PROJECT_XRAY) ? 0 : 1;
@@ -4564,6 +4549,8 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
 	IDProperty *idgroup;
 	IDProperty *view_data = NULL;
 
+	paint_proj_mesh_data_ensure(C, OBACT);
+
 	project_state_init(C, OBACT, &ps, BRUSH_STROKE_NORMAL);
 
 	if (ps.ob == NULL || ps.ob->type != OB_MESH) {
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 74ccf28..ef27eef 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1890,6 +1890,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
 	SpaceImage *sima;
 	Scene *scene;
 	Object *obedit;
+	Object *ob;
 	Image *ima;
 	Main *bmain;
 	PointerRNA ptr, idptr;
@@ -1904,6 +1905,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
 	scene = CTX_data_scene(C);
 	obedit = CTX_data_edit_object(C);
 	bmain = CTX_data_main(C);
+	ob = OBACT;
 
 	prop = RNA_struct_find_property(op->ptr, "name");
 	RNA_property_string_get(op->ptr, prop, name);
@@ -1949,6 +1951,13 @@ static int image_new_exec(bContext *C, wmOperator *op)
 			tex->ima = ima;
 			ED_area_tag_redraw(CTX_wm_area(C));
 		}
+		else if (ob->mode == OB_MODE_TEXTURE_PAINT) {
+			ImagePaintSettings *imapaint = &(CTX_data_tool_settings(C)->imapaint);
+
+			if (imapaint->stencil)
+				id_us_min(&imapaint->stencil->id);
+			imapaint->stencil = ima;
+		}
 	}
 
 	BKE_image_signal(ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_USER_NEW_IMAGE);
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index da0b3cd..03f9c3d 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -265,7 +265,8 @@ typedef enum BrushImagePaintTool {
 	PAINT_TOOL_SOFTEN = 1,
 	PAINT_TOOL_SMEAR = 2,
 	PAINT_TOOL_CLONE = 3,
-	PAINT_TOOL_FILL = 4
+	PAINT_TOOL_FILL = 4,
+	PAINT_TOOL_MASK = 5
 } BrushImagePaintTool;
 
 /* direction that the brush displaces along */
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index fa6cdc6..960a73f 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -804,6 +804,7 @@ typedef struct ImagePaintSettings {
 	int pad1;
 
 	void *paintcursor;			/* wm handle */
+	struct Image *stencil;      /* workaround until we support true layer masks */
 } ImagePaintSettings;
 
 /* ------------------------------------------- */
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 315d511..ce2f03e 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -102,6 +102,7 @@ EnumPropertyItem brush_image_tool_items[] = {
 	{PAINT_TOOL_SMEAR, "SMEAR", ICON_BRUSH_SMEAR, "Smear", ""},
 	{PAINT_TOOL_CLONE, "CLONE", ICON_BRUSH_CLONE, "Clone", ""},
 	{PAINT_TOOL_FILL, "FILL", ICON_BRUSH_CLONE, "Fill", ""},
+    {PAINT_TOOL_MASK, "MASK", ICON_BRUSH_CLONE, "Mask", ""},
 	{0, NULL, 0, NULL, NULL}
 };
 
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 3e793ab..8ddca76 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -592,7 +592,13 @@ static void rna_def_image_paint(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_STENCIL_INV);
 	RNA_def_property_ui_text(prop, "Invert", "Invert the stencil layer");
 	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
-	
+
+	prop = RNA_def_property(srna, "stencil_image", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "stencil");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Stencil Image", "Image used as stencil");
+	RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
+
 	prop = RNA_def_property(srna, "use_clone_layer", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_CLONE);
 	RNA_def_property_ui_text(prop, "Clone Map",




More information about the Bf-blender-cvs mailing list