[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37187] branches/soc-2011-onion: Revision: 29862

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jun 4 19:47:14 CEST 2011


Revision: 37187
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37187
Author:   jwilkins
Date:     2011-06-04 17:47:14 +0000 (Sat, 04 Jun 2011)
Log Message:
-----------
Revision: 29862
Author: nicholasbishop
Date: 8:29:10 PM, Thursday, July 01, 2010
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

** jwilkins:
** tweaked UI some, only shows 'add' button when no layers.  seems more consistent than showing all controls except strength when no mask (not to mention that "inactive" controls like the clear/fill/invert actually work since they are not technically disabled).

Modified Paths:
--------------
    branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h
    branches/soc-2011-onion/source/blender/blenkernel/intern/customdata.c
    branches/soc-2011-onion/source/blender/blenkernel/intern/paint.c
    branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2011-onion/source/blender/gpu/GPU_buffers.h
    branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c
    branches/soc-2011-onion/source/blender/makesdna/DNA_customdata_types.h
    branches/soc-2011-onion/source/blender/makesrna/intern/rna_mesh.c

Property Changed:
----------------
    branches/soc-2011-onion/


Property changes on: branches/soc-2011-onion
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29796,29832,29860
/trunk/blender:36833-37054
   + /branches/soc-2010-jwilkins:28499-37009
/branches/soc-2010-nicolasbishop:28448-29796,29832,29860,29862
/trunk/blender:36833-37054

Modified: branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-06-04 17:47:14 UTC (rev 37187)
@@ -725,15 +725,17 @@
 
         col = row.column(align=True)
         col.operator("paint.mask_layer_add", icon='ZOOMIN', text="")
-        col.operator("paint.mask_layer_remove", icon='ZOOMOUT', text="")
+        if mesh.active_paint_mask_index != -1:
+            col.operator("paint.mask_layer_remove", icon='ZOOMOUT', text="")
 
-        row = layout.row(align=True)
-        row.active = mesh.active_paint_mask_index != -1
-        row.operator("paint.mask_set", text="Clear").mode = 'CLEAR'
-        row.operator("paint.mask_set", text="Fill").mode = 'FILL'
-        row.operator("paint.mask_set", text="Invert").mode = 'INVERT'
-        #row.operator("paint.mask_set", text="Random").mode = 'RANDOM'
+            row = layout.row(align=True)
+            row.operator("paint.mask_set", text="Clear").mode = 'CLEAR'
+            row.operator("paint.mask_set", text="Fill").mode = 'FILL'
+            row.operator("paint.mask_set", text="Invert").mode = 'INVERT'
+            #row.operator("paint.mask_set", text="Random").mode = 'RANDOM'
 
+            layout.prop(mesh.paint_mask_layers[mesh.active_paint_mask_index], "strength", slider=True)
+
         if context.sculpt_object:
             layout.separator()
             col = layout.column(align=True)

Modified: branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/blenkernel/BKE_paint.h	2011-06-04 17:47:14 UTC (rev 37187)
@@ -60,6 +60,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-2011-onion/source/blender/blenkernel/intern/customdata.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/customdata.c	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/customdata.c	2011-06-04 17:47:14 UTC (rev 37187)
@@ -1298,6 +1298,8 @@
 	data->layers[index].type = type;
 	data->layers[index].flag = flag;
 	data->layers[index].data = newlayerdata;
+	data->layers[index].strength = 1;
+
 	if(name || (name=typeInfo->defaultname)) {
 		BLI_strncpy(data->layers[index].name, name, 32);
 		CustomData_set_layer_unique_name(data, index);

Modified: branches/soc-2011-onion/source/blender/blenkernel/intern/paint.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenkernel/intern/paint.c	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/blenkernel/intern/paint.c	2011-06-04 17:47:14 UTC (rev 37187)
@@ -44,7 +44,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>
 
@@ -119,3 +122,13 @@
 {
 	tar->brush= src->brush;
 }
+
+/* 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-2011-onion/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/blenlib/intern/pbvh.c	2011-06-04 17:47:14 UTC (rev 37187)
@@ -1153,7 +1153,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-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c	2011-06-04 17:47:14 UTC (rev 37187)
@@ -259,9 +259,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-2011-onion/source/blender/gpu/GPU_buffers.h
===================================================================
--- branches/soc-2011-onion/source/blender/gpu/GPU_buffers.h	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/gpu/GPU_buffers.h	2011-06-04 17:47:14 UTC (rev 37187)
@@ -159,7 +159,9 @@
 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-2011-onion/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/gpu/intern/gpu_buffers.c	2011-06-04 17:47:14 UTC (rev 37187)
@@ -490,8 +490,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);
 			
@@ -616,7 +618,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;
@@ -625,6 +627,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) {
@@ -632,8 +635,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-2011-onion/source/blender/makesdna/DNA_customdata_types.h
===================================================================
--- branches/soc-2011-onion/source/blender/makesdna/DNA_customdata_types.h	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/makesdna/DNA_customdata_types.h	2011-06-04 17:47:14 UTC (rev 37187)
@@ -47,7 +47,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-2011-onion/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- branches/soc-2011-onion/source/blender/makesrna/intern/rna_mesh.c	2011-06-04 17:10:05 UTC (rev 37186)
+++ branches/soc-2011-onion/source/blender/makesrna/intern/rna_mesh.c	2011-06-04 17:47:14 UTC (rev 37187)
@@ -51,6 +51,8 @@
 #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 */
@@ -807,6 +809,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;
@@ -1690,6 +1703,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