[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29265] branches/soc-2010-nicolasbishop/ source/blender/editors/sculpt_paint: * Updated the paint_mask_set operator so that it can set mask values using the sculpt PBVH .

Nicholas Bishop nicholasbishop at gmail.com
Sun Jun 6 09:31:52 CEST 2010


Revision: 29265
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29265
Author:   nicholasbishop
Date:     2010-06-06 09:31:52 +0200 (Sun, 06 Jun 2010)

Log Message:
-----------
* Updated the paint_mask_set operator so that it can set mask values using the sculpt PBVH. The mask-setting part is commented out until the PBVH is ready.

Modified Paths:
--------------
    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_utils.c
    branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c

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-06-06 07:07:58 UTC (rev 29264)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h	2010-06-06 07:31:52 UTC (rev 29265)
@@ -33,6 +33,7 @@
 struct Scene;
 struct Object;
 struct Mesh;
+struct Multires;
 struct PaintStroke;
 struct PointerRNA;
 struct ViewContext;
@@ -110,6 +111,8 @@
 
 int facemask_paint_poll(struct bContext *C);
 
+struct MultiresModifierData *paint_multires_active(struct Scene *scene, struct Object *ob);
+
 /* paint_undo.c */
 typedef void (*UndoRestoreCb)(struct bContext *C, struct ListBase *lb);
 typedef void (*UndoFreeCb)(struct ListBase *lb);

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-06-06 07:07:58 UTC (rev 29264)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_mask.c	2010-06-06 07:31:52 UTC (rev 29265)
@@ -1,4 +1,5 @@
 #include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 
 #include "RNA_access.h"
@@ -10,33 +11,75 @@
 #include "BKE_context.h"
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_mesh.h"
+#include "BKE_multires.h"
+#include "BKE_paint.h"
 
+#include "BLI_pbvh.h"
+
 #include "paint_intern.h"
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
+static float get_mask_value(MaskSetMode mode)
+{
+	return (mode == MASKING_CLEAR ? 1 :
+		mode == MASKING_FULL ? 0 :
+		mode == MASKING_RANDOM ? (float)rand() / RAND_MAX : 0);
+}
+
 static int paint_mask_set_exec(bContext *C, wmOperator *op)
 {
 	MaskSetMode mode = RNA_enum_get(op->ptr, "mode");
+	struct Scene *scene;
 	Object *ob;
+	DerivedMesh *dm;
 	Mesh *me;
+	PBVH *pbvh;
 
+	scene = CTX_data_scene(C);
 	ob = CTX_data_active_object(C);
+	me = get_mesh(ob);
 
-	if((me = get_mesh(ob))) {
-		printf("paint mask set %d\n", mode);
+	/* Make sure a mask layer has been allocated for the mesh */
+	if(!CustomData_get_layer(&me->vdata, CD_PAINTMASK))
+		CustomData_add_layer(&me->vdata, CD_PAINTMASK, CD_CALLOC, NULL, me->totvert);
 
-		DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+	dm = mesh_get_derived_final(scene, ob, 0);
+	pbvh = dm->getPBVH(ob, dm);
+
+	if(pbvh) {
+		PBVHNode **nodes;
+		int n, totnode;
+
+		BLI_pbvh_search_gather(pbvh, NULL, NULL, &nodes, &totnode);
+		for(n=0; n<totnode; n++) {
+			PBVHVertexIter vd;
+
+			BLI_pbvh_vertex_iter_begin(pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
+				/* *vd.mask = get_mask_value(mode) */
+			}
+			BLI_pbvh_vertex_iter_end;
+
+			BLI_pbvh_node_mark_update(nodes[n]);
+		}
+
+		BLI_pbvh_update(pbvh, PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw, NULL);
+		//WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+		//ED_region_tag_redraw(CTX_wm_region(C));
 	}
-
+	
 	return OPERATOR_FINISHED;
 }
 
 static int mask_poll(bContext *C)
 {
-	return 1; // TODO
+	Object *ob = CTX_data_active_object(C);
+
+	return ob && get_mesh(ob) && ob->sculpt;
 }
 
 /* Temporary operator to test masking; simply fills up a mask for the

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c	2010-06-06 07:07:58 UTC (rev 29264)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c	2010-06-06 07:31:52 UTC (rev 29265)
@@ -4,6 +4,7 @@
 
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 
 #include "DNA_scene_types.h"
@@ -18,6 +19,7 @@
 #include "BKE_context.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
+#include "BKE_modifier.h"
 #include "BKE_paint.h"
 
 #include "BKE_utildefines.h"
@@ -295,3 +297,28 @@
 
 	WM_operator_properties_select_all(ot);
 }
+
+/* Currently just used for sculpt mode.
+   Sculpt mode handles multires differently from regular meshes, but only if
+   it's the last modifier on the stack and it is not on the first level */
+struct MultiresModifierData *paint_multires_active(Scene *scene, Object *ob)
+{
+	ModifierData *md, *nmd;
+	
+	for(md= modifiers_getVirtualModifierList(ob); md; md= md->next) {
+		if(md->type == eModifierType_Multires) {
+			MultiresModifierData *mmd= (MultiresModifierData*)md;
+
+			/* Check if any of the modifiers after multires are active
+			 * if not it can use the multires struct */
+			for(nmd= md->next; nmd; nmd= nmd->next)
+				if(modifier_isEnabled(scene, nmd, eModifierMode_Realtime))
+					break;
+
+			if(!nmd && mmd->sculptlvl > 0)
+				return mmd;
+		}
+	}
+
+	return NULL;
+}

Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-06-06 07:07:58 UTC (rev 29264)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c	2010-06-06 07:31:52 UTC (rev 29265)
@@ -286,7 +286,7 @@
 static int sculpt_modifiers_active(Scene *scene, Object *ob)
 {
 	ModifierData *md;
-	MultiresModifierData *mmd = sculpt_multires_active(scene, ob);
+	MultiresModifierData *mmd = paint_multires_active(scene, ob);
 
 	/* check if there are any modifiers after what we are sculpting,
 	   for a multires modifier with a deform modifier in front, we
@@ -374,7 +374,7 @@
 		BLI_pbvh_search_callback(ss->pbvh, NULL, NULL, update_cb, NULL);
 		BLI_pbvh_update(ss->pbvh, PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw, NULL);
 
-		if((mmd=sculpt_multires_active(scene, ob)))
+		if((mmd=paint_multires_active(scene, ob)))
 			multires_mark_as_modified(ob);
 
 		if(sculpt_modifiers_active(scene, ob))
@@ -436,7 +436,7 @@
 
 	BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
 	BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
-		&maxgrid, &gridsize, NULL, NULL);
+				&maxgrid, &gridsize, NULL, NULL);
 
 	unode->totvert= totvert;
 	/* we will use this while sculpting, is mapalloc slow to access then? */
@@ -970,7 +970,7 @@
 	sculpt_brush_test_init(ss, &test);
 
 	BLI_pbvh_node_get_grids(ss->pbvh, node, &grid_indices, &totgrid,
-		NULL, &gridsize, &griddata, &gridadj);
+				NULL, &gridsize, &griddata, &gridadj);
 
 	//#pragma omp critical
 	tmpgrid= MEM_mallocN(sizeof(float)*3*gridsize*gridsize, "tmpgrid");
@@ -1482,30 +1482,6 @@
 	}
 }
 
-/* Sculpt mode handles multires differently from regular meshes, but only if
-   it's the last modifier on the stack and it is not on the first level */
-struct MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob)
-{
-	ModifierData *md, *nmd;
-	
-	for(md= modifiers_getVirtualModifierList(ob); md; md= md->next) {
-		if(md->type == eModifierType_Multires) {
-			MultiresModifierData *mmd= (MultiresModifierData*)md;
-
-			/* Check if any of the modifiers after multires are active
-			 * if not it can use the multires struct */
-			for(nmd= md->next; nmd; nmd= nmd->next)
-				if(modifier_isEnabled(scene, nmd, eModifierMode_Realtime))
-					break;
-
-			if(!nmd && mmd->sculptlvl > 0)
-				return mmd;
-		}
-	}
-
-	return NULL;
-}
-
 void sculpt_key_to_mesh(KeyBlock *kb, Object *ob)
 {
 	Mesh *me= ob->data;
@@ -1525,7 +1501,7 @@
 {
 	DerivedMesh *dm = mesh_get_derived_final(scene, ob, 0);
 	SculptSession *ss = ob->sculpt;
-	MultiresModifierData *mmd= sculpt_multires_active(scene, ob);
+	MultiresModifierData *mmd= paint_multires_active(scene, ob);
 
 	ss->ob= ob;
 
@@ -2235,7 +2211,7 @@
 	Scene *scene = CTX_data_scene(C);
 	ToolSettings *ts = CTX_data_tool_settings(C);
 	Object *ob = CTX_data_active_object(C);
-	MultiresModifierData *mmd = sculpt_multires_active(scene, ob);
+	MultiresModifierData *mmd = paint_multires_active(scene, ob);
 	int flush_recalc= 0;
 
 	/* multires in sculpt mode could have different from object mode subdivision level */





More information about the Bf-blender-cvs mailing list