[Bf-blender-cvs] [169f831] master: Make sure we invalidate the node ID layer each time the PBVH is reset.

Antony Riakiotakis noreply at git.blender.org
Thu Apr 17 19:53:53 CEST 2014


Commit: 169f8313940e826587fc50b3c4e3b082d15b51e5
Author: Antony Riakiotakis
Date:   Thu Apr 17 20:53:20 2014 +0300
https://developer.blender.org/rB169f8313940e826587fc50b3c4e3b082d15b51e5

Make sure we invalidate the node ID layer each time the PBVH is reset.

It makes code more tidy (avoids having to call invalidation on a myriad
places). Also makes sure other invalidation cases (some mesh change,
e.g.) work as expected.

===================================================================

M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_undo.c

===================================================================

diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index d316cbb..e2e4592 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1143,6 +1143,26 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode)
 
 /***************************** Public API *****************************/
 
+static void pbvh_bmesh_node_layers_reset(PBVH *bvh)
+{
+	BMFace *f;
+	BMVert *v;
+	BMIter iter;
+	BMesh *bm = bvh->bm;
+	int cd_vert_node_offset = bvh->cd_vert_node_offset;
+	int cd_face_node_offset = bvh->cd_face_node_offset;
+
+	/* clear the elements of the node information */
+	BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
+		BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, DYNTOPO_NODE_NONE);
+	}
+
+	BM_ITER_MESH(f, &iter, bm, BM_FACES_OF_MESH) {
+		BM_ELEM_CD_SET_INT(f, cd_face_node_offset, DYNTOPO_NODE_NONE);
+	}
+}
+
+
 /* Build a PBVH from a BMesh */
 void BKE_pbvh_build_bmesh(PBVH *bvh, BMesh *bm, bool smooth_shading, BMLog *log,
                           const int cd_vert_node_offset, const int cd_face_node_offset)
@@ -1167,6 +1187,8 @@ void BKE_pbvh_build_bmesh(PBVH *bvh, BMesh *bm, bool smooth_shading, BMLog *log,
 	if (smooth_shading)
 		bvh->flags |= PBVH_DYNTOPO_SMOOTH_SHADING;
 
+	pbvh_bmesh_node_layers_reset(bvh);
+
 	/* Start with all faces in the root node */
 	n = bvh->nodes = MEM_callocN(sizeof(PBVHNode), "PBVHNode");
 	bvh->totnode = 1;
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index f5bdbfa..16c0f9b 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -4793,25 +4793,6 @@ void sculpt_pbvh_clear(Object *ob)
 	BKE_object_free_derived_caches(ob);
 }
 
-void sculpt_dyntopo_node_layers_reset(SculptSession *ss)
-{
-	BMFace *f;
-	BMVert *v;
-	BMIter iter;
-	BMesh *bm = ss->bm;
-	int cd_vert_node_offset = ss->cd_vert_node_offset;
-	int cd_face_node_offset = ss->cd_face_node_offset;
-
-	/* clear the elements of the node information */
-	BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
-		BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, DYNTOPO_NODE_NONE);
-	}
-
-	BM_ITER_MESH(f, &iter, bm, BM_FACES_OF_MESH) {
-		BM_ELEM_CD_SET_INT(f, cd_face_node_offset, DYNTOPO_NODE_NONE);
-	}
-}
-
 void sculpt_dyntopo_node_layers_add(SculptSession *ss)
 {
 	int cd_node_layer_index;
@@ -4874,7 +4855,6 @@ void sculpt_dynamic_topology_enable(bContext *C)
 	BM_data_layer_add(ss->bm, &ss->bm->vdata, CD_PAINT_MASK);
 	sculpt_dyntopo_node_layers_add(ss);
 	/* make sure the data for existing faces are initialized */
-	sculpt_dyntopo_node_layers_reset(ss);
 	BM_mesh_normals_update(ss->bm);
 
 	/* Enable dynamic topology */
@@ -5013,7 +4993,6 @@ static int sculpt_optimize_exec(bContext *C, wmOperator *UNUSED(op))
 	Object *ob = CTX_data_active_object(C);
 
 	sculpt_pbvh_clear(ob);
-	sculpt_dyntopo_node_layers_reset(ob->sculpt);
 	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 
 	return OPERATOR_FINISHED;
@@ -5072,7 +5051,6 @@ static int sculpt_symmetrize_exec(bContext *C, wmOperator *UNUSED(op))
 
 	/* Redraw */
 	sculpt_pbvh_clear(ob);
-	sculpt_dyntopo_node_layers_reset(ss);
 	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 
 	return OPERATOR_FINISHED;
@@ -5333,7 +5311,6 @@ static int sculpt_detail_flood_fill_exec(bContext *C, wmOperator *UNUSED(op))
 
 	/* force rebuild of pbvh for better BB placement */
 	sculpt_pbvh_clear(ob);
-	sculpt_dyntopo_node_layers_reset(ss);
 	/* Redraw */
 	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 8cf5bf8..a4d2f0d 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -48,7 +48,6 @@ struct MultiresModifierData;
 struct Object;
 struct Scene;
 struct Sculpt;
-struct SculptSession;
 struct SculptStroke;
 struct SculptUndoNode;
 
@@ -68,7 +67,6 @@ bool sculpt_stroke_get_location(bContext *C, float out[3], const float mouse[2])
 
 /* Dynamic topology */
 void sculpt_pbvh_clear(Object *ob);
-void sculpt_dyntopo_node_layers_reset(struct SculptSession *ss);
 void sculpt_dyntopo_node_layers_add(struct SculptSession *ss);
 void sculpt_update_after_dynamic_topology_toggle(bContext *C);
 void sculpt_dynamic_topology_enable(struct bContext *C);
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index 39df15b..6ac65e4 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -301,7 +301,6 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C,
 			MEM_freeN(nodes);
 	}
 	else {
-		sculpt_dyntopo_node_layers_reset(ss);
 		sculpt_pbvh_clear(ob);
 	}
 }
@@ -341,9 +340,6 @@ static void sculpt_undo_bmesh_restore_begin(bContext *C,
 		/* Restore the mesh from the first log entry */
 		BM_log_redo(ss->bm, ss->bm_log);
 
-		/* reset layers for all bmesh data */
-		sculpt_dyntopo_node_layers_reset(ss);
-
 		unode->applied = true;
 	}
 }
@@ -359,9 +355,6 @@ static void sculpt_undo_bmesh_restore_end(bContext *C,
 		/* Restore the mesh from the last log entry */
 		BM_log_undo(ss->bm, ss->bm_log);
 
-		/* reset layers for all bmesh data */
-		sculpt_dyntopo_node_layers_reset(ss);
-
 		unode->applied = false;
 	}
 	else {




More information about the Bf-blender-cvs mailing list