[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37126] branches/soc-2011-onion/source/ blender/editors/sculpt_paint: Revision: 29265

Jason Wilkins Jason.A.Wilkins at gmail.com
Fri Jun 3 16:37:44 CEST 2011


Revision: 37126
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37126
Author:   jwilkins
Date:     2011-06-03 14:37:44 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Revision: 29265
Author: nicholasbishop
Date: 2:31:52 AM, Sunday, June 06, 2010
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-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_utils.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h	2011-06-03 14:14:32 UTC (rev 37125)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h	2011-06-03 14:37:44 UTC (rev 37126)
@@ -41,6 +41,7 @@
 struct ListBase;
 struct Mesh;
 struct Object;
+struct Multires;
 struct PaintStroke;
 struct PointerRNA;
 struct Scene;
@@ -123,6 +124,8 @@
 
 int facemask_paint_poll(struct bContext *C);
 
+struct MultiresModifierData *paint_multires_active(struct Scene *scene, struct Object *ob);
+
 /* stroke operator */
 typedef enum BrushStrokeMode {
 	BRUSH_STROKE_NORMAL,

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-03 14:14:32 UTC (rev 37125)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_mask.c	2011-06-03 14:37:44 UTC (rev 37126)
@@ -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_tag_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-2011-onion/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_utils.c	2011-06-03 14:14:32 UTC (rev 37125)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_utils.c	2011-06-03 14:37:44 UTC (rev 37126)
@@ -7,6 +7,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_brush.h"
 #include "BKE_context.h"
 #include "BKE_DerivedMesh.h"
+#include "BKE_modifier.h"
 #include "BKE_paint.h"
 
 #include "RNA_access.h"
@@ -426,3 +428,34 @@
 
 	RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects.");
 }
+
+/* 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)
+{
+	Mesh *me= (Mesh*)ob->data;
+	ModifierData *md;
+
+	if(!CustomData_get_layer(&me->fdata, CD_MDISPS)) {
+		/* multires can't work without displacement layer */
+		return NULL;
+	}
+
+	for(md= modifiers_getVirtualModifierList(ob); md; md= md->next) {
+		if(md->type == eModifierType_Multires) {
+			MultiresModifierData *mmd= (MultiresModifierData*)md;
+
+			if(!modifier_isEnabled(scene, md, eModifierMode_Realtime))
+				continue;
+
+			if (mmd->sculptlvl > 0)
+				return mmd;
+			else
+				return NULL;
+		}
+	}
+
+	return NULL;
+}
+

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c	2011-06-03 14:14:32 UTC (rev 37125)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c	2011-06-03 14:37:44 UTC (rev 37126)
@@ -130,35 +130,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)
-{
-	Mesh *me= (Mesh*)ob->data;
-	ModifierData *md;
-
-	if(!CustomData_get_layer(&me->fdata, CD_MDISPS)) {
-		/* multires can't work without displacement layer */
-		return NULL;
-	}
-
-	for(md= modifiers_getVirtualModifierList(ob); md; md= md->next) {
-		if(md->type == eModifierType_Multires) {
-			MultiresModifierData *mmd= (MultiresModifierData*)md;
-
-			if(!modifier_isEnabled(scene, md, eModifierMode_Realtime))
-				continue;
-
-			if (mmd->sculptlvl > 0)
-				return mmd;
-			else
-				return NULL;
-		}
-	}
-
-	return NULL;
-}
-
 /* Check if there are any active modifiers in stack (used for flushing updates at enter/exit sculpt mode) */
 static int sculpt_has_active_modifiers(Scene *scene, Object *ob)
 {
@@ -180,7 +151,7 @@
 {
 	ModifierData *md;
 	Mesh *me= (Mesh*)ob->data;
-	MultiresModifierData *mmd= sculpt_multires_active(scene, ob);
+	MultiresModifierData *mmd= paint_multires_active(scene, ob);
 
 	if (mmd)
 		return 0;
@@ -3240,7 +3211,7 @@
 {
 	DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
 	SculptSession *ss = ob->sculpt;
-	MultiresModifierData *mmd= sculpt_multires_active(scene, ob);
+	MultiresModifierData *mmd= paint_multires_active(scene, ob);
 
 	ss->modifiers_active= sculpt_modifiers_active(scene, sd, ob);
 
@@ -4416,7 +4387,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 */

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h	2011-06-03 14:14:32 UTC (rev 37125)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_intern.h	2011-06-03 14:37:44 UTC (rev 37126)
@@ -57,7 +57,6 @@
 void sculpt_paint_brush(char clear);
 void sculpt_stroke_draw(struct SculptStroke *);
 void sculpt_radialcontrol_start(int mode);
-struct MultiresModifierData *sculpt_multires_active(struct Scene *scene, struct Object *ob);
 
 struct Brush *sculptmode_brush(void);
 

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c	2011-06-03 14:14:32 UTC (rev 37125)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_undo.c	2011-06-03 14:37:44 UTC (rev 37126)
@@ -190,7 +190,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);
 
 		tag_update= ((Mesh*)ob->data)->id.us > 1;




More information about the Bf-blender-cvs mailing list