[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31123] branches/soc-2010-nicolasbishop: = = Paint ==

Nicholas Bishop nicholasbishop at gmail.com
Fri Aug 6 21:51:24 CEST 2010


Revision: 31123
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31123
Author:   nicholasbishop
Date:     2010-08-06 21:51:23 +0200 (Fri, 06 Aug 2010)

Log Message:
-----------
== Paint ==

Paint overlay

* Added a new vpaint input that samples an image rather than using the
  brush color

* The image is displayed as a translucent overlay in vpaint mode
** Can be toggled on and off in the UI or with IKEY

* A color can be marked as transparent so that it will not affect the
  brush color
** There's a tolerance value to set how close colors have to be to the
   transparency color

* The image overlay can be moved with G/S/R when its enabled

* For now only enabled in vpaint mode, should be enabled for texpaint too

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/readfile.c
    branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ops.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2010-nicolasbishop/source/blender/editors/space_view3d/view3d_draw.c
    branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2010-nicolasbishop/source/blender/makesrna/intern/rna_scene.c
    branches/soc-2010-nicolasbishop/source/blender/makesrna/intern/rna_sculpt_paint.c

Added Paths:
-----------
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_overlay.c

Modified: branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py	2010-08-06 18:40:05 UTC (rev 31122)
+++ branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py	2010-08-06 19:51:23 UTC (rev 31123)
@@ -1398,6 +1398,25 @@
             sub.active = pe.fade_time
             sub.prop(pe, "fade_frames", slider=True)
 
+
+class VIEW3D_PT_paint_overlay(PaintPanel, bpy.types.Panel):
+    bl_label = "Source Image"
+    bl_default_closed = True
+
+    def poll(context):
+        #return (context.vertex_paint_object or context.texture_paint_object)
+        return (context.vertex_paint_object)
+
+    def draw(self, context):
+        layout = self.layout
+
+        overlay = context.tool_settings.paint_overlay
+
+        layout.prop(overlay, "enabled")
+        layout.template_ID(overlay, "image", open="image.open")
+        layout.prop(overlay, "transparency_color")
+        layout.prop(overlay, "transparency_tolerance")
+
 def register():
     pass
 

Modified: branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/readfile.c	2010-08-06 18:40:05 UTC (rev 31122)
+++ branches/soc-2010-nicolasbishop/source/blender/blenloader/intern/readfile.c	2010-08-06 19:51:23 UTC (rev 31123)
@@ -4173,6 +4173,8 @@
 	sce= main->scene.first;
 	while(sce) {
 		if(sce->id.flag & LIB_NEEDLINK) {
+			ToolSettings *ts;
+
 			/*Link ID Properties -- and copy this comment EXACTLY for easy finding
 			of library blocks that implement this.*/
 			if (sce->id.properties) IDP_LibLinkProperty(sce->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
@@ -4186,10 +4188,16 @@
 			sce->ima= newlibadr_us(fd, sce->id.lib, sce->ima);
 			sce->gpd= newlibadr_us(fd, sce->id.lib, sce->gpd);
 			
-			link_paint(fd, sce, &sce->toolsettings->sculpt->paint);
-			link_paint(fd, sce, &sce->toolsettings->vpaint->paint);
-			link_paint(fd, sce, &sce->toolsettings->wpaint->paint);
-			link_paint(fd, sce, &sce->toolsettings->imapaint.paint);
+			ts = sce->toolsettings;
+			link_paint(fd, sce, &ts->sculpt->paint);
+			link_paint(fd, sce, &ts->vpaint->paint);
+			link_paint(fd, sce, &ts->wpaint->paint);
+			link_paint(fd, sce, &ts->imapaint.paint);
+			if(ts) {
+				if(ts->paint_overlay.img)
+					ts->paint_overlay.img = newlibadr_us(fd, sce->id.lib, ts->paint_overlay.img);
+				ts->paint_overlay.gltex = 0;
+			}
 
 			sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
 

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h	2010-08-06 18:40:05 UTC (rev 31122)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/include/ED_sculpt.h	2010-08-06 19:51:23 UTC (rev 31123)
@@ -64,5 +64,8 @@
 			     struct RegionView3D *rv3d, struct Object *ob);
 void ED_paint_force_update(struct bContext *C);
 
+/* paint_vertex.c */
+void ED_paint_overlay_draw(const struct bContext *C, struct ARegion *ar);
+void ED_paint_update_overlay(struct Object *ob);
 
 #endif

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h	2010-08-06 18:40:05 UTC (rev 31122)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h	2010-08-06 19:51:23 UTC (rev 31123)
@@ -39,6 +39,7 @@
 struct Multires;
 struct Object;
 struct Paint;
+struct PaintOverlay;
 struct PaintStroke;
 struct PointerRNA;
 struct ViewContext;
@@ -89,6 +90,8 @@
 float paint_stroke_radius_squared(PaintStroke *stroke);
 void paint_stroke_symmetry_location(PaintStroke *stroke, float loc[3]);
 int paint_stroke_first_dab(PaintStroke *stroke);
+void paint_stroke_project(PaintStroke *stroke, float loc[3], float out[2]);
+void paint_stroke_symmetry_unflip(PaintStroke *stroke, float out[3], float vec[3]);
 
 /* paint stroke modifiers */
 void paint_stroke_set_modifier_use_original_location(PaintStroke *stroke);
@@ -144,7 +147,6 @@
 void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_vertex_paint(struct wmOperatorType *ot);
 void PAINT_OT_vertex_colors_to_texture(struct wmOperatorType *ot);
-
 unsigned int vpaint_get_current_col(struct VPaint *vp);
 
 /* paint_image.c */
@@ -247,5 +249,16 @@
 void PTEX_OT_layer_add(struct wmOperatorType *ot);
 void PTEX_OT_open(struct wmOperatorType *ot);
 
+/* paint_overlay.c */
+int paint_sample_overlay(PaintStroke *stroke, float col[3], float co[2]);
+typedef enum {
+	PAINT_MANIP_GRAB,
+	PAINT_MANIP_SCALE,
+	PAINT_MANIP_ROTATE
+} PaintManipAction;
+void paint_overlay_transform(struct PaintOverlay *overlay, struct ARegion *ar, struct ImBuf *ibuf,
+			      int out[2], float vec[2], int scale, int rotate);
+void PAINT_OT_overlay_manipulate(struct wmOperatorType *ot);
+
 #endif /* ED_PAINT_INTERN_H */
 

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ops.c	2010-08-06 18:40:05 UTC (rev 31122)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_ops.c	2010-08-06 19:51:23 UTC (rev 31123)
@@ -217,6 +217,7 @@
 	WM_operatortype_append(PAINT_OT_vertex_paint);
 	WM_operatortype_append(PAINT_OT_vertex_color_set);
 	WM_operatortype_append(PAINT_OT_vertex_colors_to_texture);
+	WM_operatortype_append(PAINT_OT_overlay_manipulate);
 
 	/* ptex */
 	WM_operatortype_append(PTEX_OT_layer_add);
@@ -312,6 +313,19 @@
 	RNA_float_set(kmi->ptr, "scalar", 10.0/9.0); // 1.1111....
 }
 
+static void ed_keymap_paint_overlay(wmKeyMap *keymap)
+{
+	wmKeyMapItem *kmi;
+	kmi = WM_keymap_add_item(keymap, "PAINT_OT_overlay_manipulate", GKEY, KM_PRESS, 0, 0);
+	RNA_enum_set(kmi->ptr, "action", PAINT_MANIP_GRAB);
+	kmi = WM_keymap_add_item(keymap, "PAINT_OT_overlay_manipulate", SKEY, KM_PRESS, 0, 0);
+	RNA_enum_set(kmi->ptr, "action", PAINT_MANIP_SCALE);
+	kmi = WM_keymap_add_item(keymap, "PAINT_OT_overlay_manipulate", RKEY, KM_PRESS, 0, 0);
+	RNA_enum_set(kmi->ptr, "action", PAINT_MANIP_ROTATE);
+	kmi= WM_keymap_add_item(keymap, "WM_OT_context_toggle", IKEY, KM_PRESS, 0, 0);
+	RNA_string_set(kmi->ptr, "data_path", "tool_settings.paint_overlay.enabled");
+}
+
 void ED_keymap_paint(wmKeyConfig *keyconf)
 {
 	wmKeyMap *keymap;
@@ -421,6 +435,8 @@
 	kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
 	RNA_string_set(kmi->ptr, "data_path", "vertex_paint_object.data.use_paint_mask");
 
+	ed_keymap_paint_overlay(keymap);
+
 	/* Weight Paint mode */
 	keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
 	keymap->poll= weight_paint_mode_poll;
@@ -459,6 +475,8 @@
 	kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
 	RNA_string_set(kmi->ptr, "data_path", "texture_paint_object.data.use_paint_mask");
 
+	ed_keymap_paint_overlay(keymap);
+
 	/* face-mask mode */
 	keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
 	keymap->poll= facemask_paint_poll;

Added: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_overlay.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_overlay.c	                        (rev 0)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_overlay.c	2010-08-06 19:51:23 UTC (rev 31123)
@@ -0,0 +1,427 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software  Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2010 by Nicholas Bishop
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): None
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BKE_context.h"
+#include "BKE_image.h"
+#include "BKE_paint.h"
+
+#include "BLI_math.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+
+#include "ED_screen.h"
+#include "ED_space_api.h"
+#include "ED_view3d.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+#include "UI_resources.h"
+
+#include "paint_intern.h"
+
+#include <math.h>
+
+int paint_sample_overlay(PaintStroke *stroke, float col[3], float co[2])
+{
+	ViewContext *vc = paint_stroke_view_context(stroke);
+	PaintOverlay *overlay = &vc->scene->toolsettings->paint_overlay;
+
+	col[0] = col[1] = col[2] = col[3] = 0;
+
+	if(overlay->use && overlay->img) {
+		ImBuf *ibuf = BKE_image_get_ibuf(overlay->img, NULL);
+
+		if(ibuf) {
+			int x, y;
+			int offset, trans[2];
+			float uco[3], proj[2];
+
+			paint_stroke_symmetry_unflip(stroke, uco, co);
+			paint_stroke_project(stroke, uco, proj);
+
+
+			paint_overlay_transform(overlay, vc->ar, ibuf, 
+						trans, proj, 1, 1);
+			x = trans[0];
+			y = trans[1];
+				
+			if(x >= 0 && x < ibuf->x && y >= 0 && y < ibuf->y) {
+				offset = y*ibuf->x + x;
+
+				if(ibuf->rect) {
+					char *ccol = ((char*)ibuf->rect) + offset*4;
+				
+					col[0] = ccol[0] / 255.0;
+					col[1] = ccol[1] / 255.0;
+					col[2] = ccol[2] / 255.0;
+					col[3] = ccol[3] / 255.0;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list