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

Nicholas Bishop nicholasbishop at gmail.com
Tue Jul 27 21:56:16 CEST 2010


Revision: 30815
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30815
Author:   nicholasbishop
Date:     2010-07-27 21:56:16 +0200 (Tue, 27 Jul 2010)

Log Message:
-----------
== VPaint ==

Masking for vpaint

* Enabled combined display of masks and vertex colors
* Added mask painting to vpaint
* VPaint factors masks into strength
* Added functions in BKE paint to find the combined mask value for an element

TODO:
* Because vpaint doesn't have proper undo yet, and mask painting is shared between sculpt and vpaint, undoing the effects of the mask brush is disabled for now.

Modified Paths:
--------------
    branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
    branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.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/gpu/intern/gpu_buffers.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-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py	2010-07-27 19:56:16 UTC (rev 30815)
@@ -495,8 +495,7 @@
     bl_default_closed = False
 
     def poll(self, context):
-        settings = self.paint_settings(context)
-        return (settings)
+        return context.sculpt_object or context.vertex_paint_object
 
     def draw(self, context):
         layout = self.layout
@@ -766,7 +765,9 @@
                 row = col.row(align=True)
                 row.prop(brush, "direction", expand=True)
 
+            col.prop(brush, "mask")
 
+
 class VIEW3D_PT_tools_brush_texture(PaintPanel):
     bl_label = "Texture"
     bl_default_closed = True

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h	2010-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h	2010-07-27 19:56:16 UTC (rev 30815)
@@ -31,6 +31,9 @@
 #include "DNA_vec_types.h"
 
 struct Brush;
+struct CustomData;
+struct DMGridData;
+struct GridKey;
 struct MFace;
 struct MultireModifierData;
 struct MVert;
@@ -60,9 +63,14 @@
  * however hiding faces is useful */
 int paint_facesel_test(struct Object *ob);
 
-void paint_refresh_mask_display(struct Object *ob);
 int paint_has_brush(struct Paint *p, struct Brush *brush);
 
+void paint_refresh_mask_display(struct Object *ob);
+float paint_mask_from_gridelem(struct DMGridData *elem, struct GridKey *gridkey,
+			       struct CustomData *vdata);
+float paint_mask_from_vertex(struct CustomData *vdata, int vertex_index,
+			     int pmask_totlayer, int pmask_first_layer);
+
 typedef struct SculptSession {
 	/* Mesh data (not copied) can come either directly from a Mesh, or from a MultiresDM */
 	struct MultiresModifierData *multires; /* Special handling for multires meshes */

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c	2010-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c	2010-07-27 19:56:16 UTC (rev 30815)
@@ -33,6 +33,7 @@
 
 #include "BKE_brush.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_dmgrid.h"
 #include "BKE_library.h"
 #include "BKE_paint.h"
 #include "BKE_utildefines.h"
@@ -208,6 +209,51 @@
 	}
 }
 
+
+float paint_mask_from_gridelem(DMGridData *elem, GridKey *gridkey,
+			      CustomData *vdata)
+{
+	CustomDataLayer *cdl;
+	float mask = 0;
+	int i, ndx;
+
+	for(i=0; i < gridkey->mask; ++i) {
+		ndx = CustomData_get_named_layer_index(vdata,
+						       CD_PAINTMASK,
+						       gridkey->mask_names[i]);
+		cdl = &vdata->layers[ndx];
+
+		if(!(cdl->flag & CD_FLAG_ENABLED))
+			continue;
+
+		mask += GRIDELEM_MASK(elem, gridkey)[i] * cdl->strength;
+	}
+
+	CLAMP(mask, 0, 1);
+
+	return mask;
+}
+
+float paint_mask_from_vertex(CustomData *vdata, int vertex_index,
+			    int pmask_totlayer, int pmask_first_layer)
+{
+	float mask = 0;
+	int i;
+
+	for(i = 0; i < pmask_totlayer; ++i) {
+		CustomDataLayer *cdl= vdata->layers + pmask_first_layer + i;
+
+		if(!(cdl->flag & CD_FLAG_ENABLED))
+			continue;
+
+		mask +=	((float*)cdl->data)[vertex_index] * cdl->strength;
+	}
+
+	CLAMP(mask, 0, 1);
+
+	return mask;
+}
+
 void create_paintsession(Object *ob)
 {
 	if(ob->paint)

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/subsurf_ccg.c	2010-07-27 19:56:16 UTC (rev 30815)
@@ -519,7 +519,7 @@
 
 		/* copy paint mask data */
 		for(j = 0; j < gridkey->mask; ++j)
-			vertData[3 + gridkey->color*3 + j] = ((float*)dm->vertData.layers[pmask_first_layer+j].data)[i];
+			vertData[3 + gridkey->color*4 + j] = ((float*)dm->vertData.layers[pmask_first_layer+j].data)[i];
 
 		ccgSubSurf_syncVert(ss, SET_INT_IN_POINTER(i), vertData, 0, &v);
 

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h	2010-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/BLI_pbvh.h	2010-07-27 19:56:16 UTC (rev 30815)
@@ -283,14 +283,9 @@
 					vi.fno= GRIDELEM_NO(vi.grid, vi.gridkey); \
 					\
 					if(vi.gridkey->mask) { \
-						int j; \
-						vi.mask_combined= 0; \
-						for(j=0; j<vi.gridkey->mask; ++j) { \
-							CustomDataLayer *cdl= vi.vdata->layers + vi.pmask_first_layer + j; \
-							if(!(cdl->flag & CD_FLAG_ENABLED)) continue; \
-							vi.mask_combined+= GRIDELEM_MASK(vi.grid, vi.gridkey)[j] * cdl->strength; \
-						} \
-						CLAMP(vi.mask_combined, 0, 1); \
+						vi.mask_combined = \
+							paint_mask_from_gridelem(vi.grid, vi.gridkey, vi.vdata); \
+						\
 						if(vi.pmask_active_layer != -1) \
 							vi.mask_active= &GRIDELEM_MASK(vi.grid, \
 										       vi.gridkey)[vi.pmask_active_layer - \
@@ -304,15 +299,11 @@
 					vi.co= vi.mvert->co; \
 					vi.no= vi.mvert->no; \
 					if(vi.pmask_layer_count) { \
-						int j; \
-						vi.mask_combined= 0; \
-						for(j=0; j<vi.pmask_layer_count; ++j) { \
-							CustomDataLayer *cdl= vi.vdata->layers + vi.pmask_first_layer + j; \
-							if(!(cdl->flag & CD_FLAG_ENABLED)) continue; \
-							vi.mask_combined+= \
-								((float*)cdl->data)[vi.vert_indices[vi.gx]] * cdl->strength; \
-						} \
-						CLAMP(vi.mask_combined, 0, 1); \
+						vi.mask_combined = \
+							paint_mask_from_vertex(vi.vdata, vi.vert_indices[vi.gx], \
+									       vi.pmask_layer_count, \
+									       vi.pmask_first_layer); \
+						\
 						if(vi.pmask_active_layer != -1) \
 							vi.mask_active = &((float*)vi.vdata->layers[vi.pmask_active_layer].data)[vi.vert_indices[vi.gx]]; \
 					} \

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-27 19:56:16 UTC (rev 30815)
@@ -31,6 +31,7 @@
 #include "BKE_dmgrid.h"
 #include "BKE_mesh.h" /* for mesh_calc_normals */
 #include "BKE_global.h" /* for mesh_calc_normals */
+#include "BKE_paint.h"
 
 #include "GPU_buffers.h"
 

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-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h	2010-07-27 19:56:16 UTC (rev 30815)
@@ -37,6 +37,7 @@
 struct Object;
 struct Mesh;
 struct Multires;
+struct Paint;
 struct PaintStroke;
 struct PointerRNA;
 struct ViewContext;
@@ -81,6 +82,20 @@
 int paint_poll(struct bContext *C);
 void paint_cursor_start(struct bContext *C, int (*poll)(struct bContext *C));
 
+typedef struct PaintStrokeTest {
+	float radius_squared;
+	float location[3];
+	float dist;
+} PaintStrokeTest;
+void paint_stroke_test_init(PaintStrokeTest *test, float loc[3],
+			    float radius_squared);
+int paint_stroke_test(PaintStrokeTest *test, float co[3]);
+int paint_stroke_test_sq(PaintStrokeTest *test, float co[3]);
+int paint_stroke_test_fast(PaintStrokeTest *test, float co[3]);
+int paint_stroke_test_cube(PaintStrokeTest *test, float co[3],
+			   float local[4][4]);
+float paint_stroke_test_dist(PaintStrokeTest *test);
+
 /* paint_vertex.c */
 int weight_paint_poll(struct bContext *C);
 int weight_paint_mode_poll(struct bContext *C);
@@ -161,6 +176,11 @@
 void undo_paint_push_end(int type);
 
 /* paint_mask.c */
+void paintmask_brush_apply(struct Paint *paint, struct PaintStroke *stroke,
+			   struct Object *ob, struct PBVHNode **nodes,
+			   int totnode, float location[3],
+			   float bstrength, float radius3d);
+
 void PAINT_OT_mask_layer_add(struct wmOperatorType *ot);
 void PAINT_OT_mask_layer_remove(struct wmOperatorType *ot);
 

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-07-27 19:22:23 UTC (rev 30814)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-07-27 19:56:16 UTC (rev 30815)
@@ -5,10 +5,11 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_material_types.h"
 #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 "RNA_access.h"
 #include "RNA_define.h"
@@ -16,6 +17,7 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
@@ -33,6 +35,7 @@
 
 #include "ED_mesh.h"
 #include "ED_sculpt.h"
+#include "ED_view3d.h"
 #include "paint_intern.h"
 #include "sculpt_intern.h"
  
@@ -49,12 +52,12 @@
 	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);	
 }
 
-/* For now masking requires sculpt mode */
 static int mask_poll(bContext *C)
 {
 	Object *ob = CTX_data_active_object(C);
 	
-	return ob && get_mesh(ob) && ob->paint && ob->paint->sculpt;
+	return ob && get_mesh(ob) && ob->paint &&
+		(ob->mode & (OB_MODE_SCULPT|OB_MODE_VERTEX_PAINT));
 }
 
 static int mask_active_poll(bContext *C)
@@ -69,6 +72,53 @@
 	return 0;
 }
 
+void paintmask_brush_apply(Paint *paint, PaintStroke *stroke, Object *ob, PBVHNode **nodes, int totnode,
+			   float location[3], float bstrength, float radius3d)
+{
+	Brush *brush = paint_brush(paint);
+	ViewContext *vc;
+	float (*pmat)[4];

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list