[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29103] branches/soc-2010-jwilkins: * restored calc_area_normals use of original normals

Jason Wilkins Jason.A.Wilkins at gmail.com
Mon May 31 11:47:54 CEST 2010


Revision: 29103
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29103
Author:   jwilkins
Date:     2010-05-31 11:47:54 +0200 (Mon, 31 May 2010)

Log Message:
-----------
* restored calc_area_normals use of original normals
* cleaned up the formatting of several functions I molested (will do this as a seperate commit next time)
* rewrote sculpt_brush_test* to use math library functions
* if anchored is enabled then attenuation due to spacing is ignored
* integrated Tom's (LetterRip) patch for keeping the original normal

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    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-05-31 09:03:54 UTC (rev 29102)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-05-31 09:47:54 UTC (rev 29103)
@@ -726,7 +726,11 @@
             if brush.sculpt_tool != 'LAYER':
                 layout.prop(brush, "use_anchor")
             layout.prop(brush, "use_rake")
-
+            if brush.sculpt_tool in ('DRAW', 'LAYER', 'FLATTEN', 'CLAY', 'FILL', 'SCRAPE', 'CONTRAST'):
+                layout.prop(brush, "use_original_normal")
+                col = layout.column()
+                col.label(text="Direction:")
+                col.prop(brush, "sculpt_direction", text="")
         layout.prop(brush, "use_airbrush")
         col = layout.column()
         col.active = brush.use_airbrush

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-05-31 09:03:54 UTC (rev 29102)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-05-31 09:47:54 UTC (rev 29103)
@@ -124,6 +124,7 @@
 	float mouse[2];
 	float bstrength;
 	float tex_mouse[2];
+	int sculpt_direction;
 
 	/* The rest is temporary storage that isn't saved as a property */
 
@@ -141,8 +142,13 @@
 	float grab_active_location[8][3];
 	float grab_delta[3], grab_delta_symmetry[3];
 	float old_grab_location[3], orig_grab_location[3];
-	int symmetry; /* Symmetry index between 0 and 7 */
+	int symmetry; /* Symmetry index between 0 and 7 bit combo 0 is Brush only;
+		1 is X mirror; 2 is Y mirror; 3 is XY; 4 is Z; 5 is XZ; 6 is YZ; 7 is XYZ */
+	int symmetry_pass; /* the symmetry pass we are currently on between 0 and 7*/
 	float view_normal[3], view_normal_symmetry[3];
+	float last_area_normal[3];
+	float last_view_normal_symmetry[3];
+	float last_center[3];
 	int last_rake[2]; /* Last location of updating rake rotation */
 	int original;
 } StrokeCache;
@@ -406,75 +412,75 @@
 
 static SculptUndoNode *sculpt_undo_push_node(SculptSession *ss, PBVHNode *node)
 {
-    ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
-    Object *ob= ss->ob;
-    SculptUndoNode *unode;
-    int totvert, allvert, totgrid, maxgrid, gridsize, *grids;
+	ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
+	Object *ob= ss->ob;
+	SculptUndoNode *unode;
+	int totvert, allvert, totgrid, maxgrid, gridsize, *grids;
 
-    /* list is manipulated by multiple threads, so we lock */
-    BLI_lock_thread(LOCK_CUSTOM1);
+	/* list is manipulated by multiple threads, so we lock */
+	BLI_lock_thread(LOCK_CUSTOM1);
 
-    if((unode= sculpt_undo_get_node(ss, node))) {
-        BLI_unlock_thread(LOCK_CUSTOM1);
-        return unode;
-    }
+	if((unode= sculpt_undo_get_node(ss, node))) {
+		BLI_unlock_thread(LOCK_CUSTOM1);
+		return unode;
+	}
 
-    unode= MEM_mallocN(sizeof(SculptUndoNode), "SculptUndoNode");
-    strcpy(unode->idname, ob->id.name);
-    unode->node= node;
+	unode= MEM_mallocN(sizeof(SculptUndoNode), "SculptUndoNode");
+	strcpy(unode->idname, ob->id.name);
+	unode->node= node;
 
-    BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
-    BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
-        &maxgrid, &gridsize, NULL, NULL);
+	BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
+	BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
+		&maxgrid, &gridsize, NULL, NULL);
 
-    unode->totvert= totvert;
-    /* we will use this while sculpting, is mapalloc slow to access then? */
-    unode->co= MEM_mapallocN(sizeof(float)*3*allvert, "SculptUndoNode.co");
-    unode->no= MEM_mapallocN(sizeof(short)*3*allvert, "SculptUndoNode.no");
-    undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float)*3 + sizeof(short)*3 + sizeof(int))*allvert);
-    BLI_addtail(lb, unode);
+	unode->totvert= totvert;
+	/* we will use this while sculpting, is mapalloc slow to access then? */
+	unode->co= MEM_mapallocN(sizeof(float)*3*allvert, "SculptUndoNode.co");
+	unode->no= MEM_mapallocN(sizeof(short)*3*allvert, "SculptUndoNode.no");
+	undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float)*3 + sizeof(short)*3 + sizeof(int))*allvert);
+	BLI_addtail(lb, unode);
 
-    if(maxgrid) {
-        /* multires */
-        unode->maxgrid= maxgrid;
-        unode->totgrid= totgrid;
-        unode->gridsize= gridsize;
-        unode->grids= MEM_mapallocN(sizeof(int)*totgrid, "SculptUndoNode.grids");
+	if(maxgrid) {
+		/* multires */
+		unode->maxgrid= maxgrid;
+		unode->totgrid= totgrid;
+		unode->gridsize= gridsize;
+		unode->grids= MEM_mapallocN(sizeof(int)*totgrid, "SculptUndoNode.grids");
 
-        unode->maxvert = 0;
-        unode->index   = 0;
-    }
-    else {
-        /* regular mesh */
-        unode->maxvert= ss->totvert;
-        unode->index= MEM_mapallocN(sizeof(int)*allvert, "SculptUndoNode.index");
+		unode->maxvert = 0;
+		unode->index   = 0;
+	}
+	else {
+		/* regular mesh */
+		unode->maxvert= ss->totvert;
+		unode->index= MEM_mapallocN(sizeof(int)*allvert, "SculptUndoNode.index");
 
-        unode->maxgrid=  0;
-        unode->totgrid=  0;
-        unode->gridsize= 0;
-        unode->grids=    0;
-    }
+		unode->maxgrid=  0;
+		unode->totgrid=  0;
+		unode->gridsize= 0;
+		unode->grids=    0;
+	}
 
-    BLI_unlock_thread(LOCK_CUSTOM1);
+	BLI_unlock_thread(LOCK_CUSTOM1);
 
-    /* copy threaded, hopefully this is the performance critical part */
-    {
-        PBVHVertexIter vd;
+	/* copy threaded, hopefully this is the performance critical part */
+	{
+		PBVHVertexIter vd;
 
-        BLI_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_ALL) {
-            copy_v3_v3(unode->co[vd.i], vd.co);
-            if(vd.no) VECCOPY(unode->no[vd.i], vd.no)
-            else normal_float_to_short_v3(unode->no[vd.i], vd.fno);
-            if(vd.vert_indices) unode->index[vd.i]= vd.vert_indices[vd.i];
-        }
-        BLI_pbvh_vertex_iter_end;
-    }
+		BLI_pbvh_vertex_iter_begin(ss->pbvh, node, vd, PBVH_ITER_ALL) {
+			copy_v3_v3(unode->co[vd.i], vd.co);
+			if(vd.no) VECCOPY(unode->no[vd.i], vd.no)
+			else normal_float_to_short_v3(unode->no[vd.i], vd.fno);
+			if(vd.vert_indices) unode->index[vd.i]= vd.vert_indices[vd.i];
+		}
+		BLI_pbvh_vertex_iter_end;
+	}
 
-    if(unode->grids) memcpy(unode->grids, grids, sizeof(int)*totgrid);
+	if(unode->grids) memcpy(unode->grids, grids, sizeof(int)*totgrid);
 
-    unode->layer_disp= 0;
+	unode->layer_disp= 0;
 
-    return unode;
+	return unode;
 }
 
 static void sculpt_undo_push_begin(SculptSession *ss, char *name)
@@ -529,56 +535,46 @@
 
 static int sculpt_brush_test(SculptBrushTest *test, float co[3])
 {
-	float distsq, delta[3];
+	float distsq = len_squared_v3v3(co, test->location);
 
-	sub_v3_v3v3(delta, co, test->location);
-	distsq = INPR(delta, delta);
-
 	if(distsq < test->radius_squared) {
 		test->dist = sqrt(distsq);
 		return 1;
 	}
-
-	return 0;
+	else {
+		return 0;
+	}
 }
 
 static int sculpt_brush_test_sq(SculptBrushTest *test, float co[3])
 {
-	float distsq, delta[3];
+	float distsq = len_squared_v3v3(co, test->location);
 
-	sub_v3_v3v3(delta, co, test->location);
-	distsq = INPR(delta, delta);
-
 	if(distsq < test->radius_squared) {
 		test->dist = distsq;
 		return 1;
 	}
-        else {
-        	return 0;
-        }
+	else {
+		return 0;
+	}
 }
 
 static int sculpt_brush_test_fast(SculptBrushTest *test, float co[3])
 {
-	float distsq, delta[3];
-
-	sub_v3_v3v3(delta, co, test->location);
-	distsq = INPR(delta, delta);
-
-	return distsq < test->radius_squared;
+	return len_squared_v3v3(co, test->location) < test->radius_squared;
 }
 
 /* area of overlap of two circles of radius 1 seperated by d units from their centers */
 static float circle_overlap(float d)
 {
-    return (2*acos(d/2)-(1/2)*d*sqrt(4-d*d));
+	return (2*acos(d/2)-(1/2)*d*sqrt(4-d*d));
 }
 
 /* percentage of overlap of two circles of radius 1 seperated by d units from their centers */
 /* TODO: cache one minus this value*/
 static float circle_overlap_percent(float d)
 {
-    return circle_overlap(d) / M_PI;
+	return circle_overlap(d) / M_PI;
 }
 
 /* ===== Sculpting =====
@@ -590,41 +586,41 @@
    special multiplier found experimentally to scale the strength factor. */
 static float brush_strength(Sculpt *sd, StrokeCache *cache)
 {
-    Brush *brush = paint_brush(&sd->paint);
+	Brush *brush = paint_brush(&sd->paint);
 
-    /* Primary strength input; square it to make lower values more sensitive */
-    float alpha = brush->alpha * brush->alpha;
+	/* Primary strength input; square it to make lower values more sensitive */
+	float alpha = brush->alpha * brush->alpha;
 
-    float dir      = brush->flag & BRUSH_DIR_IN ? -1 : 1;
-    float pressure = brush->flag & BRUSH_ALPHA_PRESSURE ? cache->pressure : 1;
-    float flip     = cache->flip ? -1 : 1;
-    float overlap  = (brush->flag & BRUSH_SPACE) && (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 dir      = brush->flag & BRUSH_DIR_IN ? -1 : 1;
+	float pressure = brush->flag & BRUSH_ALPHA_PRESSURE ? cache->pressure : 1;
+	float flip     = cache->flip ? -1 : 1;
+	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
 
-    switch(brush->sculpt_tool){
-        case SCULPT_TOOL_DRAW:
-        case SCULPT_TOOL_INFLATE:
-        case SCULPT_TOOL_CLAY:
-            return  alpha * dir * pressure * flip * overlap;
+	switch(brush->sculpt_tool){
+		case SCULPT_TOOL_DRAW:
+		case SCULPT_TOOL_INFLATE:
+		case SCULPT_TOOL_CLAY:
+			return  alpha * dir * pressure * flip * overlap;
 
-        case SCULPT_TOOL_FLATTEN:
-        case SCULPT_TOOL_LAYER:
-        case SCULPT_TOOL_FILL:
-        case SCULPT_TOOL_SCRAPE:
-        case SCULPT_TOOL_CONTRAST:
-            return alpha * pressure * flip;
+		case SCULPT_TOOL_FLATTEN:
+		case SCULPT_TOOL_LAYER:
+		case SCULPT_TOOL_FILL:
+		case SCULPT_TOOL_SCRAPE:
+		case SCULPT_TOOL_CONTRAST:
+			return alpha * pressure * flip;
 
-        case SCULPT_TOOL_SMOOTH:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list