[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24381] branches/sculpt25: Sculpt: WIP brush behavior changes

Brecht Van Lommel brecht at blender.org
Fri Nov 6 17:46:37 CET 2009


Revision: 24381
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24381
Author:   blendix
Date:     2009-11-06 17:46:35 +0100 (Fri, 06 Nov 2009)

Log Message:
-----------
Sculpt: WIP brush behavior changes

* Draw/Inflate/Layer now keep working on the original mesh coordinates and
  normals from when the stroke started. This helps avoid the mesh blowing
  up, but can still be better. The old behavior is still available as
  "Accumulate" in the UI.
* This requires some more memory usage for the BVH, would like to find a
  way to avoid that.
* Smooth falloff is now the default.
* Spacing is now enabled by default, with a value of 7.5.
* Anchored now stores normals per node to save some memory.

Modified Paths:
--------------
    branches/sculpt25/release/scripts/ui/space_view3d_toolbar.py
    branches/sculpt25/source/blender/blenkernel/intern/brush.c
    branches/sculpt25/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/sculpt25/source/blender/blenlib/BLI_pbvh.h
    branches/sculpt25/source/blender/blenlib/intern/pbvh.c
    branches/sculpt25/source/blender/editors/sculpt_paint/paint_undo.c
    branches/sculpt25/source/blender/editors/sculpt_paint/sculpt.c
    branches/sculpt25/source/blender/makesdna/DNA_brush_types.h
    branches/sculpt25/source/blender/makesrna/intern/rna_brush.c

Modified: branches/sculpt25/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/sculpt25/release/scripts/ui/space_view3d_toolbar.py	2009-11-06 14:46:07 UTC (rev 24380)
+++ branches/sculpt25/release/scripts/ui/space_view3d_toolbar.py	2009-11-06 16:46:35 UTC (rev 24381)
@@ -523,6 +523,9 @@
                 if brush.sculpt_tool in ('DRAW', 'PINCH', 'INFLATE', 'LAYER', 'CLAY'):
                     col.row().itemR(brush, "direction", expand=True)
 
+                if brush.sculpt_tool in ('DRAW', 'INFLATE', 'LAYER'):
+                    col.itemR(brush, "use_accumulate")
+
                 if brush.sculpt_tool == 'LAYER':
                     col.itemR(brush, "use_persistent")
                     col.itemO("sculpt.set_persistent_base")

Modified: branches/sculpt25/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/sculpt25/source/blender/blenkernel/intern/brush.c	2009-11-06 14:46:07 UTC (rev 24380)
+++ branches/sculpt25/source/blender/blenkernel/intern/brush.c	2009-11-06 16:46:35 UTC (rev 24381)
@@ -75,13 +75,14 @@
 	brush->rgb[2]= 1.0f;
 	brush->alpha= 0.2f;
 	brush->size= 25;
-	brush->spacing= 10.0f;
+	brush->spacing= 7.5f;
 	brush->smooth_stroke_radius= 75;
 	brush->smooth_stroke_factor= 0.9;
 	brush->rate= 0.1f;
 	brush->jitter= 0.0f;
 	brush->clone.alpha= 0.5;
 	brush->sculpt_tool = SCULPT_TOOL_DRAW;
+	brush->flag |= BRUSH_SPACE;
 
 	brush_curve_preset(brush, BRUSH_PRESET_SMOOTH);
 

Modified: branches/sculpt25/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/sculpt25/source/blender/blenkernel/intern/cdderivedmesh.c	2009-11-06 14:46:07 UTC (rev 24380)
+++ branches/sculpt25/source/blender/blenkernel/intern/cdderivedmesh.c	2009-11-06 16:46:35 UTC (rev 24381)
@@ -420,12 +420,14 @@
    Returns true if the AABB is at least partially within the frustum
    (ok, not a real frustum), false otherwise.
 */
-int planes_contain_AABB(PBVHNode *node, float bb_min[3], float bb_max[3], void *data)
+int planes_contain_AABB(PBVHNode *node, void *data)
 {
 	float (*planes)[4] = data;
 	int i, axis;
-	float vmin[3], vmax[3];
+	float vmin[3], vmax[3], bb_min[3], bb_max[3];
 
+	BLI_pbvh_node_get_BB(node, bb_min, bb_max);
+
 	for(i = 0; i < 4; ++i) { 
 		for(axis = 0; axis < 3; ++axis) {
 			if(planes[i][axis] > 0) { 

Modified: branches/sculpt25/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- branches/sculpt25/source/blender/blenlib/BLI_pbvh.h	2009-11-06 14:46:07 UTC (rev 24380)
+++ branches/sculpt25/source/blender/blenlib/BLI_pbvh.h	2009-11-06 16:46:35 UTC (rev 24381)
@@ -37,8 +37,7 @@
 /* Callbacks */
 
 /* returns 1 if the search should continue from this node, 0 otherwise */
-typedef int (*BLI_pbvh_SearchCallback)(PBVHNode *node,
-	float bb_min[3], float bb_max[3], void *data);
+typedef int (*BLI_pbvh_SearchCallback)(PBVHNode *node, void *data);
 
 typedef void (*BLI_pbvh_HitCallback)(PBVHNode *node, void *data);
 
@@ -69,7 +68,7 @@
    hit first */
 
 void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitCallback cb, void *data,
-		      float ray_start[3], float ray_normal[3]);
+		      float ray_start[3], float ray_normal[3], int original);
 
 /* Node Access */
 
@@ -78,20 +77,25 @@
 
 	PBVH_UpdateNormals = 2,
 	PBVH_UpdateBB = 4,
+	PBVH_UpdateOriginalBB = 4,
 	PBVH_UpdateDrawBuffers = 8,
 	PBVH_UpdateRedraw = 16
 } PBVHNodeFlags;
 
 void BLI_pbvh_node_mark_update(PBVHNode *node);
 
-void BLI_pbvh_node_get_verts(PBVHNode *node, int **vert_indices, int *totvert);
-void BLI_pbvh_node_get_faces(PBVHNode *node, int **face_indices, int *totface);
+void BLI_pbvh_node_get_verts(PBVHNode *node, int **vert_indices,
+	int *totvert, int *allverts);
+void BLI_pbvh_node_get_faces(PBVHNode *node, int **face_indices,
+	int **face_vert_indices, int *totface);
 void *BLI_pbvh_node_get_draw_buffers(PBVHNode *node);
+void BLI_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
+void BLI_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
 
 /* Update Normals/Bounding Box/Draw Buffers/Redraw and clear flags */
 
 void BLI_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
-void BLI_pbvh_redraw_bounding_box(PBVH *bvh, float bb_min[3], float bb_max[3]);
+void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
 
 #endif /* BLI_PBVH_H */
 

Modified: branches/sculpt25/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/sculpt25/source/blender/blenlib/intern/pbvh.c	2009-11-06 14:46:07 UTC (rev 24380)
+++ branches/sculpt25/source/blender/blenlib/intern/pbvh.c	2009-11-06 16:46:35 UTC (rev 24381)
@@ -82,12 +82,14 @@
 
 	/* Voxel bounds */
 	BB vb;
+	BB orig_vb;
 
 	/* For internal nodes */
 	int children_offset;
 
 	/* Pointer into bvh face_indices */
 	int *face_indices;
+	int *face_vert_indices;
 
 	unsigned short totface;
 	unsigned short uniq_verts, face_verts;
@@ -266,7 +268,7 @@
 
 /* Add a vertex to the map, with a positive value for unique vertices and
    a negative value for additional vertices */
-static void map_insert_vert(PBVH *bvh, GHash *map,
+static int map_insert_vert(PBVH *bvh, GHash *map,
 			    unsigned short *face_verts,
 			    unsigned short *uniq_verts, int vertex)
 {
@@ -284,7 +286,10 @@
 		}
 		
 		BLI_ghash_insert(map, key, value);
+		return GET_INT_FROM_POINTER(value);
 	}
+	else
+		return GET_INT_FROM_POINTER(BLI_ghash_lookup(map, key));
 }
 
 /* Find vertices used by the faces in this node and update the draw buffers */
@@ -299,13 +304,17 @@
 	node->uniq_verts = node->face_verts = 0;
 	totface= node->totface;
 
+	node->face_vert_indices = MEM_callocN(sizeof(int) *
+					 4*totface, "bvh node face vert indices");
+
 	for(i = 0; i < totface; ++i) {
 		MFace *f = bvh->faces + node->face_indices[i];
 		int sides = f->v4 ? 4 : 3;
 
 		for(j = 0; j < sides; ++j) {
-			map_insert_vert(bvh, map, &node->face_verts,
-					&node->uniq_verts, (&f->v1)[j]);
+			node->face_vert_indices[i*4 + j]= 
+				map_insert_vert(bvh, map, &node->face_verts,
+						&node->uniq_verts, (&f->v1)[j]);
 		}
 	}
 
@@ -327,6 +336,10 @@
 			GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(iter));
 	}
 
+	for(i = 0; i < totface*4; ++i)
+		if(node->face_vert_indices[i] < 0)
+			node->face_vert_indices[i]= -node->face_vert_indices[i] + node->uniq_verts - 1;
+
 	node->draw_buffers =
 		GPU_build_buffers(map, bvh->verts, bvh->faces,
 				  node->face_indices,
@@ -370,6 +383,7 @@
 		}
 		
 		build_leaf_node(bvh, bvh->nodes + node_index);
+		bvh->nodes[node_index].orig_vb= bvh->nodes[node_index].vb;
 
 		/* Done with this subtree */
 		return;
@@ -394,6 +408,8 @@
 				  (BB*)(prim_bbc + bvh->face_indices[i]));
 	}
 
+	bvh->nodes[node_index].orig_vb= bvh->nodes[node_index].vb;
+
 	end = partition_indices(bvh->face_indices, offset, offset + count - 1,
 				axis,
 				(cb->bmax[axis] + cb->bmin[axis]) * 0.5f,
@@ -480,6 +496,7 @@
 		if(bvh->nodes[i].flag & PBVH_Leaf) {
 			GPU_free_buffers(bvh->nodes[i].draw_buffers);
 			MEM_freeN(bvh->nodes[i].vert_indices);
+			MEM_freeN(bvh->nodes[i].face_vert_indices);
 		}
 	}
 
@@ -562,7 +579,7 @@
 		/* check search callback */
 		search_data= iter->search_data;
 
-		if(iter->scb && !iter->scb(node, node->vb.bmin, node->vb.bmax, search_data))
+		if(iter->scb && !iter->scb(node, search_data))
 			continue; /* don't traverse, outside of search zone */
 
 		if(node->flag & PBVH_Leaf) {
@@ -634,11 +651,12 @@
 	pbvh_iter_end(&iter);
 }
 
-static int update_search_cb(PBVHNode *node,
-	float bb_min[3], float bb_max[3], void *data_v)
+static int update_search_cb(PBVHNode *node, void *data_v)
 {
+	int flag= GET_INT_FROM_POINTER(data_v);
+
 	if(node->flag & PBVH_Leaf)
-		return (node->flag & (PBVH_UpdateNormals|PBVH_UpdateBB|PBVH_UpdateDrawBuffers|PBVH_UpdateRedraw));
+		return (node->flag & flag);
 	
 	return 1;
 }
@@ -670,7 +688,8 @@
 		if((node->flag & PBVH_UpdateNormals)) {
 			int i, j, totface, *faces;
 
-			BLI_pbvh_node_get_faces(node, &faces, &totface);
+			faces= node->face_indices;
+			totface= node->totface;
 
 			for(i = 0; i < totface; ++i) {
 				MFace *f= bvh->faces + faces[i];
@@ -713,7 +732,8 @@
 		if(node->flag & PBVH_UpdateNormals) {
 			int i, *verts, totvert;
 
-			BLI_pbvh_node_get_verts(node, &verts, &totvert);
+			verts= node->vert_indices;
+			totvert= node->uniq_verts;
 
 			for(i = 0; i < totvert; ++i) {
 				const int v = verts[i];
@@ -754,6 +774,9 @@
 			/* don't clear flag yet, leave it for flushing later */
 			update_node_vb(bvh, node);
 
+		if((flag & PBVH_UpdateOriginalBB) && (node->flag & PBVH_UpdateOriginalBB))
+			node->orig_vb= node->vb;
+
 		if((flag & PBVH_UpdateRedraw) && (node->flag & PBVH_UpdateRedraw))
 			node->flag &= ~PBVH_UpdateRedraw;
 	}
@@ -780,22 +803,32 @@
 	}
 }
 
-static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node)
+static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag)
 {
 	int update= 0;
 
 	/* difficult to multithread well, we just do single threaded recursive */
 	if(node->flag & PBVH_Leaf) {
-		update= (node->flag & PBVH_UpdateBB);
-		node->flag &= ~PBVH_UpdateBB;
+		if(flag & PBVH_UpdateBB) {
+			update |= (node->flag & PBVH_UpdateBB);
+			node->flag &= ~PBVH_UpdateBB;
+		}
+
+		if(flag & PBVH_UpdateOriginalBB) {
+			update |= (node->flag & PBVH_UpdateOriginalBB);
+			node->flag &= ~PBVH_UpdateOriginalBB;
+		}
+
 		return update;
 	}
 	else {
-		update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset);
-		update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset + 1);
+		update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset, flag);
+		update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset + 1, flag);
 
-		if(update)
+		if(update & PBVH_UpdateBB)
 			update_node_vb(bvh, node);
+		if(update & PBVH_UpdateOriginalBB)
+			node->orig_vb= node->vb;
 	}
 
 	return update;
@@ -806,24 +839,25 @@
 	PBVHNode **nodes;
 	int totnode;
 
-	BLI_pbvh_search_gather(bvh, update_search_cb, NULL, &nodes, &totnode);
+	BLI_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(flag),
+		&nodes, &totnode);
 
 	if(flag & PBVH_UpdateNormals)
 		pbvh_update_normals(bvh, nodes, totnode, face_nors);
 
-	if(flag & (PBVH_UpdateBB|PBVH_UpdateRedraw))
+	if(flag & (PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw))
 		pbvh_update_BB_redraw(bvh, nodes, totnode, flag);
 
 	if(flag & PBVH_UpdateDrawBuffers)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list