[Bf-blender-cvs] [edfeb71] soc-2013-paint: Reusable curves for the paint systems:

Antony Riakiotakis noreply at git.blender.org
Wed Mar 19 20:17:32 CET 2014


Commit: edfeb712eb93ba2479145b34c0e4cdb730b5f3bf
Author: Antony Riakiotakis
Date:   Mon Mar 17 03:28:30 2014 +0200
https://developer.blender.org/rBedfeb712eb93ba2479145b34c0e4cdb730b5f3bf

Reusable curves for the paint systems:

This commit includes the following:

* Per brush curve setting that allows setting a different curve per brush.
Those curves stay in memory and can be edited and reused accordingly.
To make sure that a curve is saved in a file users need to add a fake user,
similar to other datablocks.

* Interface while using curves is now non blocking. Users can pan, rotate,
and zoom the view while able to select and edit curve points as previously
in the GSOC branch.
Code internally uses the transform system. This needs some tweaking still
but it should be similar to the previous GSOC system. This may change
in the future to be more compatible with other curve systems
(ie enable choosing handle type etc.)

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

M	release/scripts/startup/bl_ui/space_image.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_main.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/idcode.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_sculpt.h
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/sculpt_paint/paint_cursor.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_ops.c
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/space_api/spacetypes.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_constraints.c
M	source/blender/editors/transform/transform_conversions.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_input.c
M	source/blender/editors/transform/transform_snap.c
M	source/blender/makesdna/DNA_ID.h
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_ID.c
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_image.py b/release/scripts/startup/bl_ui/space_image.py
index c21b737..e9cf48f 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -914,6 +914,10 @@ class IMAGE_PT_paint_stroke(BrushButtonsPanel, Panel):
             row = col.row(align=True)
             row.prop(brush, "spacing", text="Spacing")
 
+        if brush.use_curve:
+            col.separator()
+            col.template_ID(brush, "paint_curve", new="paintcurve.new")
+
         col = layout.column()
         col.separator()
 
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 83411c9..1111177 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1225,6 +1225,10 @@ class VIEW3D_PT_tools_brush_stroke(Panel, View3DPaintPanel):
             row = col.row(align=True)
             row.prop(brush, "spacing", text="Spacing")
 
+        if brush.use_curve:
+            col.separator()
+            col.template_ID(brush, "paint_curve", new="paintcurve.new")
+
         if context.sculpt_object:
             if brush.sculpt_capabilities.has_jitter:
                 col.separator()
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index 565bf3e..922bd77 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -87,6 +87,7 @@ typedef struct Main {
 	ListBase brush;
 	ListBase particle;
 	ListBase palettes;
+	ListBase paintcurves;
 	ListBase wm;
 	ListBase gpencil;
 	ListBase movieclip;
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index a5ba888..d1894a3 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -45,6 +45,7 @@ struct MultireModifierData;
 struct MVert;
 struct Object;
 struct Paint;
+struct PaintCurve;
 struct PBVH;
 struct Scene;
 struct StrokeCache;
@@ -102,6 +103,10 @@ struct PaletteColor *BKE_palette_color_get_last(struct Palette *palette);
 bool BKE_palette_is_empty(const struct Palette *palette);
 void BKE_palette_remove_color (struct Palette *palette, struct PaletteColor *colour);
 
+/* paint curves */
+struct PaintCurve *BKE_paint_curve_add(struct Main *bmain, const char *name);
+void BKE_free_paint_curve(struct PaintCurve *pc);
+
 void BKE_paint_init(struct Paint *p, const char col[3]);
 void BKE_paint_free(struct Paint *p);
 void BKE_paint_copy(struct Paint *src, struct Paint *tar);
@@ -113,6 +118,7 @@ struct Brush *BKE_paint_brush(struct Paint *paint);
 void BKE_paint_brush_set(struct Paint *paint, struct Brush *br);
 struct Palette *BKE_paint_palette(struct Paint *paint);
 void BKE_paint_palette_set(struct Paint *p, struct Palette *palette);
+void BKE_paint_curve_set(struct Brush *br, struct PaintCurve *pc);
 
 /* testing face select mode
  * Texture paint could be removed since selected faces are not used
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 2d46fcc..287411b 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -166,6 +166,9 @@ Brush *BKE_brush_copy(Brush *brush)
 	if (brush->mask_mtex.tex)
 		id_us_plus((ID *)brush->mask_mtex.tex);
 
+	if (brush->paint_curve)
+		id_us_plus((ID *)brush->paint_curve);
+
 	if (brush->icon_imbuf)
 		brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf);
 
@@ -191,6 +194,9 @@ void BKE_brush_free(Brush *brush)
 	if (brush->mask_mtex.tex)
 		brush->mask_mtex.tex->id.us--;
 
+	if (brush->paint_curve)
+		brush->paint_curve->id.us--;
+
 	if (brush->icon_imbuf)
 		IMB_freeImBuf(brush->icon_imbuf);
 
@@ -207,6 +213,7 @@ static void extern_local_brush(Brush *brush)
 	id_lib_extern((ID *)brush->mtex.tex);
 	id_lib_extern((ID *)brush->mask_mtex.tex);
 	id_lib_extern((ID *)brush->clone.image);
+	id_lib_extern((ID *)brush->paint_curve);
 }
 
 void BKE_brush_make_local(Brush *brush)
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
index 61842d0..d98bd9a 100644
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -74,6 +74,7 @@ static IDType idtypes[] = {
 	{ ID_OB,     "Object",           "objects",         IDTYPE_FLAGS_ISLINKABLE },
 	{ ID_PA,     "ParticleSettings", "particles",       0                       },
 	{ ID_PAL,    "Palettes",         "palettes",        IDTYPE_FLAGS_ISLINKABLE },
+	{ ID_PC,   "PaintCurve",       "paint_curves",    IDTYPE_FLAGS_ISLINKABLE },
 	{ ID_SCE,    "Scene",            "scenes",          IDTYPE_FLAGS_ISLINKABLE },
 	{ ID_SCR,    "Screen",           "screens",         0                       },
 	{ ID_SEQ,    "Sequence",         "sequences",       0                       }, /* not actually ID data */
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index def1327..cfee8bc 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -519,6 +519,8 @@ ListBase *which_libbase(Main *mainlib, short type)
 			return &(mainlib->linestyle);
 		case ID_PAL:
 			return &(mainlib->palettes);
+		case ID_PC:
+			return &(mainlib->paintcurves);
 	}
 	return NULL;
 }
@@ -615,6 +617,7 @@ int set_listbasepointers(Main *main, ListBase **lb)
 	lb[a++] = &(main->movieclip);
 	lb[a++] = &(main->mask);
 	lb[a++] = &(main->palettes);
+	lb[a++] = &(main->paintcurves);
 	
 	lb[a] = NULL;
 
@@ -739,6 +742,9 @@ static ID *alloc_libblock_notest(short type)
 		case ID_PAL:
 			id = MEM_callocN(sizeof(Palette), "Palette");
 			break;
+		case ID_PC:
+			id = MEM_callocN(sizeof(PaintCurve), "Paint Curve");
+			break;
 	}
 	return id;
 }
@@ -991,6 +997,9 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
 		case ID_PAL:
 			BKE_free_palette((Palette *)id);
 			break;
+		case ID_PC:
+			BKE_free_paint_curve((PaintCurve *)id);
+			break;
 	}
 
 	/* avoid notifying on removed data */
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 5ad187d..35f8e55 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -267,6 +267,24 @@ void BKE_paint_brush_set(Paint *p, Brush *br)
 	}
 }
 
+void BKE_free_paint_curve(PaintCurve *pc)
+{
+	if (pc->points) {
+		MEM_freeN(pc->points);
+		pc->points = NULL;
+		pc->tot_points = 0;
+	}
+}
+
+PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name)
+{
+	PaintCurve *pc;
+
+	pc = BKE_libblock_alloc(bmain, ID_PC, name);
+
+	return pc;
+}
+
 Palette *BKE_paint_palette(Paint *p)
 {
 	return p ? p->palette : NULL;
@@ -281,8 +299,17 @@ void BKE_paint_palette_set(Paint *p, Palette *palette)
 	}
 }
 
+void BKE_paint_curve_set(Brush *br, PaintCurve *pc)
+{
+	if (br) {
+		id_us_min((ID *)br->paint_curve);
+		id_us_plus((ID *)pc);
+		br->paint_curve = pc;
+	}
+}
+
 /* remove colour from palette. Must be certain colour is inside the palette! */
-void BKE_palette_remove_color (Palette *palette, PaletteColor *colour)
+void BKE_palette_remove_color(Palette *palette, PaletteColor *colour)
 {
 	BLI_remlink(&palette->colors, colour);
 	MEM_freeN(colour);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9d44d17..402690c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1838,6 +1838,7 @@ static void lib_link_brush(FileData *fd, Main *main)
 			brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex);
 			brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex);
 			brush->clone.image = newlibadr_us(fd, brush->id.lib, brush->clone.image);
+			brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve);
 		}
 	}
 }
@@ -1878,6 +1879,23 @@ static void direct_link_palette(FileData *fd, Palette *palette)
 	link_list(fd, &palette->colors);
 }
 
+static void lib_link_paint_curve(FileData *UNUSED(fd), Main *main)
+{
+	PaintCurve *pc;
+
+	/* only link ID pointers */
+	for (pc = main->paintcurves.first; pc; pc = pc->id.next) {
+		if (pc->id.flag & LIB_NEED_LINK) {
+			pc->id.flag -= LIB_NEED_LINK;
+		}
+	}
+}
+
+static void direct_link_paint_curve(FileData *fd, PaintCurve *pc)
+{
+	pc->points = newdataadr(fd, pc->points);
+}
+
 
 static void direct_link_script(FileData *UNUSED(fd), Script *script)
 {
@@ -7143,6 +7161,7 @@ static const char *dataname(short id_code)
 		case ID_BR: return "Data from BR";
 		case ID_PA: return "Data from PA";
 		case ID_PAL: return "Data from PAL";
+		case ID_PC: return "Data from PCRV";
 		case ID_GD: return "Data from GD";
 		case ID_WM: return "Data from WM";
 		case ID_MC: return "Data from MC";
@@ -7331,6 +7350,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
 		case ID_PAL:
 			direct_link_palette(fd, (Palette *)id);
 			break;
+		case ID_PC:
+			direct_link_paint_curve(fd, (PaintCurve *)id);
+			break;
 	}
 	
 	oldnewmap_free_unused(fd->datamap);
@@ -7520,6 +7542,7 @@ static void lib_link_all(FileData *fd, Main *main)
 	lib_link_nodetree(fd, main);	/* has to be done after scene/materials, this will verify group nodes */
 	lib_link_brush(fd, main);
 	lib_link_palette(fd, main);
+	lib_link_paint_curve(fd, main);
 	lib_link_particlesettings(fd, main);
 	lib_link_movieclip(fd, main);
 	lib_link_mask(fd, main);
@@ -8059,6 +8082,7 @@ static void expand_brush(FileData *fd, Main *mainvar, Brush *brush)
 	expand_doit(fd, mainvar, brush->mtex.tex);
 	expand_doit(fd, mainvar, brush->mask_mtex.tex);
 	expand_doit(fd, mainvar, brush->clone.image);
+	expand_doit(fd, mainvar, brush->paint_curve);
 }
 
 static void expand_material(FileData *fd, Main *mainvar, Material *ma)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 95a8239..52e7d37 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2926,7 +2926,7 @@ static void write_palettes(WriteData *wd, ListBase *idbase)
 {
 	Palett

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list