[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29862] branches/soc-2010-nicolasbishop: Made mask layer's opacity adjustable.

Nicholas Bishop nicholasbishop at gmail.com
Fri Jul 2 03:29:15 CEST 2010


Revision: 29862
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29862
Author:   nicholasbishop
Date:     2010-07-02 03:29:10 +0200 (Fri, 02 Jul 2010)

Log Message:
-----------
Made mask layer's opacity adjustable.

* Added a new "strength" field to CustomDataLayer, set to 1 by default.
* Added RNA for strength; the update function is ugly, commented in the file
* Added a slider control to adjust strength

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/customdata.c
    branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c
    branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h
    branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
    branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_customdata_types.h
    branches/soc-2010-nicolasbishop/source/blender/makesrna/intern/rna_mesh.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-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py	2010-07-02 01:29:10 UTC (rev 29862)
@@ -518,7 +518,10 @@
         row.operator("paint.mask_set", text="Fill").mode = 'FILL'
         row.operator("paint.mask_set", text="Invert").mode = 'INVERT'
 
+        if row.active:
+            layout.prop(mesh.paint_mask_layers[mesh.active_paint_mask_index], "strength", slider=True)
 
+
 class VIEW3D_PT_tools_brush(PaintPanel):
     bl_label = "Brush"
 

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/BKE_paint.h	2010-07-02 01:29:10 UTC (rev 29862)
@@ -58,6 +58,8 @@
  * however hiding faces is useful */
 int paint_facesel_test(struct Object *ob);
 
+void paint_refresh_mask_display(struct Object *ob);
+
 /* Session data (mode-specific) */
 
 typedef struct SculptSession {

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/customdata.c	2010-07-02 01:29:10 UTC (rev 29862)
@@ -1247,6 +1247,7 @@
 	data->layers[index].type = type;
 	data->layers[index].flag = flag;
 	data->layers[index].data = newlayerdata;
+	data->layers[index].strength = 1;
 
 	if(name) {
 		strcpy(data->layers[index].name, name);

Modified: branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/blenkernel/intern/paint.c	2010-07-02 01:29:10 UTC (rev 29862)
@@ -34,7 +34,10 @@
 #include "BKE_brush.h"
 #include "BKE_library.h"
 #include "BKE_paint.h"
+#include "BKE_utildefines.h"
 
+#include "BLI_pbvh.h"
+
 #include <stdlib.h>
 #include <string.h>
 
@@ -192,3 +195,13 @@
 			id_us_plus((ID *)new->brushes[i]);
 	}
 }
+
+/* Update the mask without doing a full object recalc */
+void paint_refresh_mask_display(Object *ob)
+{
+	if(ob && ob->sculpt && ob->sculpt->pbvh) {
+		BLI_pbvh_search_callback(ob->sculpt->pbvh, NULL, NULL,
+					 BLI_pbvh_node_set_flags,
+					 SET_INT_IN_POINTER(PBVH_UpdateColorBuffers));
+	}
+}

Modified: branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/blenlib/intern/pbvh.c	2010-07-02 01:29:10 UTC (rev 29862)
@@ -1002,7 +1002,8 @@
 							      node->prim_indices,
 							      node->totprim,
 							      bvh->gridsize,
-							      bvh->gridkey);
+							      bvh->gridkey,
+							      bvh->vdata);
 			}
 			else {
 				GPU_update_mesh_color_buffers(node->draw_buffers,

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-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-07-02 01:29:10 UTC (rev 29862)
@@ -258,9 +258,7 @@
 {
 	Object *ob = CTX_data_active_object(C);
 
-	if(ob->sculpt->pbvh)
-		BLI_pbvh_search_callback(ob->sculpt->pbvh, NULL, NULL,
-					 BLI_pbvh_node_set_flags, SET_INT_IN_POINTER(PBVH_UpdateColorBuffers));
+	paint_refresh_mask_display(ob);
 
 	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);	
 }

Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/gpu_buffers.h	2010-07-02 01:29:10 UTC (rev 29862)
@@ -148,7 +148,8 @@
 void GPU_update_grid_color_buffers(GPU_Buffers *buffers,
 				   struct DMGridData **grids,
 				   int *grid_indices, int totgrid,
-				   int gridsize, struct GridKey *gridkey);
+				   int gridsize, struct GridKey *gridkey,
+				   struct CustomData *vdata);
 void GPU_draw_buffers(void *buffers);
 void GPU_free_buffers(void *buffers);
 

Modified: branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/gpu/intern/gpu_buffers.c	2010-07-02 01:29:10 UTC (rev 29862)
@@ -479,8 +479,10 @@
 
 		for(i = 0; i < totvert; ++i) {
 			float v = 0;
-			for(j = 0; j < pmask_totlayer; ++j)
-				v += ((float*)vdata->layers[pmask_first_layer + j].data)[vert_indices[i]];
+			for(j = 0; j < pmask_totlayer; ++j) {
+				CustomDataLayer *cdl = &vdata->layers[pmask_first_layer + j];
+				v += ((float*)cdl->data)[vert_indices[i]] * cdl->strength;
+			}
 
 			mask_to_gpu_colors(color_data + i*3, v);
 			
@@ -605,7 +607,7 @@
 }
 
 void GPU_update_grid_color_buffers(GPU_Buffers *buffers, DMGridData **grids, int *grid_indices,
-				   int totgrid, int gridsize, GridKey *gridkey)
+				   int totgrid, int gridsize, GridKey *gridkey, CustomData *vdata)
 {
 	unsigned char *color_data;
 	int totvert;
@@ -614,6 +616,7 @@
 	color_data= map_color_buffer(buffers, gridkey->mask, totvert);
 
 	if(color_data) {
+		int pmask_first_layer = CustomData_get_layer_index(vdata, CD_PAINTMASK);
 		int i, j, k;
 
 		for(i = 0; i < totgrid; ++i) {
@@ -621,8 +624,11 @@
 
 			for(j = 0; j < gridsize*gridsize; ++j, color_data += 3) {
 				float v = 0;
-				for(k = 0; k < gridkey->mask; ++k)
-					v += GRIDELEM_MASK_AT(grid, j, gridkey)[k];
+				for(k = 0; k < gridkey->mask; ++k) {
+					CustomDataLayer *cdl = &vdata->layers[pmask_first_layer + k];
+					v += GRIDELEM_MASK_AT(grid, j, gridkey)[k] * cdl->strength;
+				}
+
 				mask_to_gpu_colors(color_data, v);
 			}
 		}

Modified: branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_customdata_types.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_customdata_types.h	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/makesdna/DNA_customdata_types.h	2010-07-02 01:29:10 UTC (rev 29862)
@@ -39,7 +39,7 @@
 	int active_rnd; /* number of the layer to render*/
 	int active_clone; /* number of the layer to render*/
 	int active_mask; /* number of the layer to render*/
-	char pad[4];
+	float strength; /* for mixing a layer, strength between 0 and 1 */
 	char name[32];  /* layer name */
 	void *data;     /* layer data */
 } CustomDataLayer;

Modified: branches/soc-2010-nicolasbishop/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/makesrna/intern/rna_mesh.c	2010-07-02 01:06:24 UTC (rev 29861)
+++ branches/soc-2010-nicolasbishop/source/blender/makesrna/intern/rna_mesh.c	2010-07-02 01:29:10 UTC (rev 29862)
@@ -46,6 +46,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
+#include "BKE_paint.h"
 #include "BKE_utildefines.h"
 
 #include "ED_mesh.h" /* XXX Bad level call */
@@ -787,6 +788,17 @@
 
 /* Paint mask layer */
 
+static void rna_MeshPaintMask_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	/* Hack: sculpt mesh is the active object, so find the active object
+	   and compare it's mesh to see if the update is on the sculpt mesh,
+	   only then pass the object to the real update function */
+	Object *ob = OBACT;
+
+	if(get_mesh(ob) == ptr->id.data)
+		paint_refresh_mask_display(ob);
+}
+
 static int rna_MeshPaintMaskLayer_data_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
 {
 	Mesh *me= (Mesh*)ptr->id.data;
@@ -1623,6 +1635,11 @@
 	RNA_def_property_float_funcs(prop, "rna_MeshPaintMaskLayer_data_get",
 				     "rna_MeshPaintMaskLayer_data_set", NULL);
 	RNA_def_struct_path_func(srna, "rna_MeshPaintMask_path");
+
+	prop= RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 0.0f, 1.0f);
+	RNA_def_property_ui_text(prop, "Strength", "Opacity of the paint mask");
+	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_MeshPaintMask_update_data");
 }
 
 static void rna_def_mproperties(BlenderRNA *brna)





More information about the Bf-blender-cvs mailing list