[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29423] branches/soc-2010-jwilkins: == Autosmooth & Snake Hook Tool ==

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jun 12 13:57:23 CEST 2010


Revision: 29423
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29423
Author:   jwilkins
Date:     2010-06-12 13:57:22 +0200 (Sat, 12 Jun 2010)

Log Message:
-----------
== Autosmooth & Snake Hook Tool ==
* Autosmooth - automatically apply smoothing after a stroke.  this is important to keep snake hooks from deforming badly
* The autosmooth factor is soft limited from 0-1 and hard limited from 0-4
* Known Bug: grab does not currently play nice with symmetry, You can use snake hook for now to get the same effect but you have to be more careful
* some formatting changes in pbvh.c
* made it so that what you grab be pulled out to where the mouse cursor is if you have the normal_weight slider set to 0

* BUG FIX: fixed a bug present in this branch and the trunk where the 
bounding boxes of the original data was always used instead of the 
newly calculated bounding boxes of edited data.  This is what was
causing the mesh to rip apart under certain circumstances.

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

Modified: branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-06-12 01:04:30 UTC (rev 29422)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-06-12 11:57:22 UTC (rev 29423)
@@ -568,6 +568,10 @@
                 #row.prop(brush, "jitter", slider=True)
                 #row.prop(brush, "use_jitter_pressure", toggle=True, text="")
 
+            if brush.sculpt_tool not in ('SMOOTH'):
+                row = col.row(align=True)
+                row.prop(brush, "autosmooth_factor", slider=True)
+
             if brush.sculpt_tool in ('GRAB'):
                 row = col.row(align=True)
                 row.prop(brush, "normal_weight", slider=True)

Modified: branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c	2010-06-12 01:04:30 UTC (rev 29422)
+++ branches/soc-2010-jwilkins/source/blender/blenkernel/intern/brush.c	2010-06-12 11:57:22 UTC (rev 29423)
@@ -95,6 +95,7 @@
 	brush->texture_scale_y = 1;
 	brush->texture_offset = 0;
 	brush->overlay_texture = 0;
+	brush->autosmooth_factor = 0;
 
 	brush->add_col[0] = 1.00;
 	brush->add_col[1] = 0.39;

Modified: branches/soc-2010-jwilkins/source/blender/blenlib/intern/pbvh.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/blenlib/intern/pbvh.c	2010-06-12 01:04:30 UTC (rev 29422)
+++ branches/soc-2010-jwilkins/source/blender/blenlib/intern/pbvh.c	2010-06-12 11:57:22 UTC (rev 29423)
@@ -91,7 +91,7 @@
 
 	char flag;
 
-        float tmin;
+	float tmin; // used for raycasting, is how close bb is to the ray point
 };
 
 struct PBVH {
@@ -812,37 +812,37 @@
 	BLI_pbvh_SearchCallback scb, void *search_data,
 	BLI_pbvh_HitOccludedCallback hcb, void *hit_data)
 {
-    PBVHIter iter;
-    PBVHNode *node;
-    node_tree *tree = 0;
-    float tmin = FLT_MAX;
+	PBVHIter iter;
+	PBVHNode *node;
+	node_tree *tree = 0;
 
-    pbvh_iter_begin(&iter, bvh, scb, search_data);
+	pbvh_iter_begin(&iter, bvh, scb, search_data);
 
-    while((node=pbvh_iter_next_occluded(&iter))) {
-        if(node->flag & PBVH_Leaf) {
-            node_tree* new_node = malloc(sizeof(node_tree));
+	while((node=pbvh_iter_next_occluded(&iter))) {
+		if(node->flag & PBVH_Leaf) {
+			node_tree* new_node = malloc(sizeof(node_tree));
 
-            new_node->data = node;
+			new_node->data = node;
 
-            new_node->left  = NULL;
-            new_node->right = NULL;
+			new_node->left  = NULL;
+			new_node->right = NULL;
 
-            if (tree) {
-                node_tree_insert(tree, new_node);
-            }
-            else {
-                tree = new_node;
-            }
-        }
-    }
+			if (tree) {
+				node_tree_insert(tree, new_node);
+			}
+			else {
+				tree = new_node;
+			}
+		}
+	}
 
-    pbvh_iter_end(&iter);
+	pbvh_iter_end(&iter);
 
-    if (tree) {
-        traverse_tree(tree, hcb, hit_data, &tmin);
-        free_tree(tree);
-    }
+	if (tree) {
+		float tmin = FLT_MAX;
+		traverse_tree(tree, hcb, hit_data, &tmin);
+		free_tree(tree);
+	}
 }
 
 static int update_search_cb(PBVHNode *node, void *data_v)
@@ -1203,41 +1203,46 @@
 /* Adapted from here: http://www.gamedev.net/community/forums/topic.asp?topic_id=459973 */
 static int ray_aabb_intersect(PBVHNode *node, void *data_v)
 {
-    RaycastData *ray = data_v;
-    float bbox[2][3];
-    float tmin, tmax, tymin, tymax, tzmin, tzmax;
+	RaycastData *ray = data_v;
+	float bbox[2][3];
+	float tmin, tmax, tymin, tymax, tzmin, tzmax;
 
-    if(ray->original)
-        BLI_pbvh_node_get_original_BB(node, bbox[0], bbox[1]);
-    else
-        BLI_pbvh_node_get_BB(node, bbox[0], bbox[1]);
+	if(ray->original)
+		BLI_pbvh_node_get_original_BB(node, bbox[0], bbox[1]);
+	else
+		BLI_pbvh_node_get_BB(node, bbox[0], bbox[1]);
 
-    tmin = (bbox[ray->sign[0]][0] - ray->start[0]) * ray->inv_dir[0];
-    tmax = (bbox[1-ray->sign[0]][0] - ray->start[0]) * ray->inv_dir[0];
+	tmin = (bbox[ray->sign[0]][0] - ray->start[0]) * ray->inv_dir[0];
+	tmax = (bbox[1-ray->sign[0]][0] - ray->start[0]) * ray->inv_dir[0];
 
-    tymin = (bbox[ray->sign[1]][1] - ray->start[1]) * ray->inv_dir[1];
-    tymax = (bbox[1-ray->sign[1]][1] - ray->start[1]) * ray->inv_dir[1];
+	tymin = (bbox[ray->sign[1]][1] - ray->start[1]) * ray->inv_dir[1];
+	tymax = (bbox[1-ray->sign[1]][1] - ray->start[1]) * ray->inv_dir[1];
 
-    if((tmin > tymax) || (tymin > tmax)) return 0;
+	if((tmin > tymax) || (tymin > tmax))
+		return 0;
 
-    if(tymin > tmin) tmin = tymin;
+	if(tymin > tmin)
+		tmin = tymin;
 
-    if(tymax < tmax) tmax = tymax;
+	if(tymax < tmax)
+		tmax = tymax;
 
-    tzmin = (bbox[ray->sign[2]][2] - ray->start[2]) * ray->inv_dir[2];
-    tzmax = (bbox[1-ray->sign[2]][2] - ray->start[2]) * ray->inv_dir[2];
+	tzmin = (bbox[ray->sign[2]][2] - ray->start[2]) * ray->inv_dir[2];
+	tzmax = (bbox[1-ray->sign[2]][2] - ray->start[2]) * ray->inv_dir[2];
 
-    if((tmin > tzmax) || (tzmin > tmax)) return 0;
+	if((tmin > tzmax) || (tzmin > tmax))
+		return 0;
 
-    if(tzmin > tmin) tmin = tzmin;
+	if(tzmin > tmin)
+		tmin = tzmin;
 
-	// jwilkins: tmax does not need to be updated since we don't use it
+	// XXX jwilkins: tmax does not need to be updated since we don't use it
 	// keeping this here for future reference
-    //if(tzmax < tmax) tmax = tzmax; 
+	//if(tzmax < tmax) tmax = tzmax; 
 
-    node->tmin = tmin;
+	node->tmin = tmin;
 
-    return 1;
+	return 1;
 }
 
 void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback cb, void *data,

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-06-12 01:04:30 UTC (rev 29422)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-06-12 11:57:22 UTC (rev 29423)
@@ -148,7 +148,6 @@
 	float (*face_norms)[3]; /* Copy of the mesh faces' normals */
 	float special_rotation; /* Texture rotation (radians) for anchored and rake modes */
 	int pixel_radius, previous_pixel_radius;
-	float grab_active_location[8][3];
 	float grab_delta[3], grab_delta_symmetry[3];
 	float old_grab_location[3], orig_grab_location[3];
 
@@ -694,7 +693,7 @@
 
 			create_EditMesh_sculpt(ss);
 			obedit= ob;
-			me= obedit->data;			
+			me= obedit->data;
 			detail = ss->cache->detail * ss->cache->radius;
 			smoothness = ss->cache->smoothness;
 			 
@@ -746,6 +745,9 @@
 	//float overlap  = (brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100.0f) ? 1 - circle_overlap_percent(brush->spacing/50.0f) : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
 	float overlap  = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 100) ? (float)brush->spacing/100.0f : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
 
+	// XXX not functionally cohesive to update this here
+	brush->autosmooth_overlap = overlap;
+
 	switch(brush->sculpt_tool){
 		case SCULPT_TOOL_DRAW:
 		case SCULPT_TOOL_INFLATE:
@@ -763,7 +765,7 @@
 			return alpha / 2.0f * dir * pressure * flip * overlap;
 
 		case SCULPT_TOOL_GRAB:
-			return dir*flip > 0 ? 0.5f : -0.5f;
+			return dir*flip > 0 ? 1.0f : -1.0f;
 
 		case SCULPT_TOOL_NUDGE:
 			return alpha * pressure * overlap;
@@ -967,7 +969,7 @@
 	
 	sub_v3_v3v3(t, center, nearest);
 
-	return t[0] * t[0] + t[1] * t[1] + t[2] * t[2] < data->radius_squared;
+	return dot_v3v3(t, t) < data->radius_squared;
 }
 
 static void symmetry_feather(Sculpt *sd, SculptSession* ss, float co[3], float val[3])
@@ -1123,52 +1125,6 @@
 	}
 }
 
-static void do_draw_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
-{
-	Brush *brush = paint_brush(&sd->paint);
-	float offset[3], area_normal[3];
-	float bstrength= ss->cache->bstrength;
-	int n;
-
-	calc_area_normal(sd, ss, area_normal, nodes, totnode);
-	
-	/* offset with as much as possible factored in already */
-	mul_v3_v3fl(offset, area_normal, ss->cache->radius);
-	mul_v3_v3(offset, ss->cache->scale);
-	mul_v3_fl(offset, bstrength);
-
-	/* threaded loop over nodes */
-	//#pragma omp parallel for private(n) schedule(static)
-	for(n=0; n<totnode; n++) {
-		PBVHVertexIter vd;
-		SculptBrushTest test;
-
-		sculpt_undo_push_node(ss, nodes[n]);
-		sculpt_brush_test_init(ss, &test);
-
-		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
-			if(sculpt_brush_test(&test, vd.co)) {
-				/* offset vertex */
-				float fade = tex_strength(ss, brush, vd.co, test.dist);
-				float val[3];
-
-				mul_v3_v3fl(val, offset, fade);
-				symmetry_feather(sd, ss, vd.co, val);
-				add_v3_v3(val, vd.co);
-
-				sculpt_clip(sd, ss, vd.co, val);
-				if(vd.mvert) {
-					vd.mvert->flag |= ME_VERT_PBVH_UPDATE;
-					if(brush->flag & BRUSH_SUBDIV) vd.mvert->flag = 1; 
-				}
-			}
-		}
-		BLI_pbvh_vertex_iter_end;
-
-		BLI_pbvh_node_mark_update(nodes[n]);
-	}
-}
-
 /* For the smooth brush, uses the neighboring vertices around vert to calculate
    a smoothed location for vert. Skips corner vertices (used by only one
    polygon.) */
@@ -1350,6 +1306,55 @@
 	smooth(sd, ss, nodes, totnode, ss->cache->bstrength);
 }
 
+static void do_draw_brush(Sculpt *sd, SculptSession *ss, PBVHNode **nodes, int totnode)
+{
+	Brush *brush = paint_brush(&sd->paint);
+	float offset[3], area_normal[3];
+	float bstrength= ss->cache->bstrength;
+	int n;
+
+	calc_area_normal(sd, ss, area_normal, nodes, totnode);
+	
+	/* offset with as much as possible factored in already */
+	mul_v3_v3fl(offset, area_normal, ss->cache->radius);
+	mul_v3_v3(offset, ss->cache->scale);
+	mul_v3_fl(offset, bstrength);
+
+	/* threaded loop over nodes */
+	//#pragma omp parallel for private(n) schedule(static)
+	for(n=0; n<totnode; n++) {
+		PBVHVertexIter vd;
+		SculptBrushTest test;
+
+		sculpt_undo_push_node(ss, nodes[n]);
+		sculpt_brush_test_init(ss, &test);
+
+		BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) {
+			if(sculpt_brush_test(&test, vd.co)) {
+				/* offset vertex */
+				float fade = tex_strength(ss, brush, vd.co, test.dist);
+				float val[3];
+
+				mul_v3_v3fl(val, offset, fade);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list