[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13515] trunk/blender/source/blender: == Sculpt ==

Nicholas Bishop nicholasbishop at gmail.com
Fri Feb 1 20:45:11 CET 2008


Revision: 13515
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13515
Author:   nicholasbishop
Date:     2008-02-01 20:45:11 +0100 (Fri, 01 Feb 2008)

Log Message:
-----------
== Sculpt ==

Added a new brush option, "Anchored". When enabled, the brush doesn't move with the mouse, but rather stays in it's initial location and grows larger or smaller to follow the mouse. Good for brushing alphas on to the mesh. (Note that this option isn't available for the grab brush, and ignores the smooth stroke option.)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/scene.c
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/src/buttons_editing.c
    trunk/blender/source/blender/src/header_view3d.c
    trunk/blender/source/blender/src/sculptmode.c
    trunk/blender/source/blender/src/space.c

Modified: trunk/blender/source/blender/blenkernel/intern/scene.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/scene.c	2008-02-01 18:27:28 UTC (rev 13514)
+++ trunk/blender/source/blender/blenkernel/intern/scene.c	2008-02-01 19:45:11 UTC (rev 13515)
@@ -604,9 +604,9 @@
 		sd->grabbrush.strength = sd->layerbrush.strength =
 		sd->flattenbrush.strength = 25;
 	sd->drawbrush.dir = sd->pinchbrush.dir = sd->inflatebrush.dir = sd->layerbrush.dir= 1;
-	sd->drawbrush.airbrush = sd->smoothbrush.airbrush =
-		sd->pinchbrush.airbrush = sd->inflatebrush.airbrush =
-		sd->layerbrush.airbrush = sd->flattenbrush.airbrush = 0;
+	sd->drawbrush.flag = sd->smoothbrush.flag =
+		sd->pinchbrush.flag = sd->inflatebrush.flag =
+		sd->layerbrush.flag = sd->flattenbrush.flag = 0;
 	sd->drawbrush.view= 0;
 	sd->brush_type= DRAW_BRUSH;
 	sd->texact= -1;

Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h	2008-02-01 18:27:28 UTC (rev 13514)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h	2008-02-01 19:45:11 UTC (rev 13515)
@@ -423,8 +423,8 @@
 {
 	short size;
 	char strength, dir; /* Not used for smooth brush */
-	char airbrush;
 	char view;
+	char flag;
 	char pad[2];
 } BrushData;
 
@@ -707,6 +707,9 @@
 #define FFMPEG_MULTIPLEX_AUDIO  1
 #define FFMPEG_AUTOSPLIT_OUTPUT 2
 
+/* Sculpt brush flags */
+#define SCULPT_BRUSH_AIRBRUSH 1
+#define SCULPT_BRUSH_ANCHORED 2
 /* SculptData.flags */
 #define SCULPT_INPUT_SMOOTH 1
 #define SCULPT_DRAW_FAST    2

Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c	2008-02-01 18:27:28 UTC (rev 13514)
+++ trunk/blender/source/blender/src/buttons_editing.c	2008-02-01 19:45:11 UTC (rev 13515)
@@ -5370,7 +5370,7 @@
 		uiDefButC(block,ROW,B_NOP,"Sub",cx+89,cy,89,19,&sculptmode_brush()->dir,15.0,2.0,0, 0,"Subtract depth from model [Shift]");
 	}
 	if(sd->brush_type!=GRAB_BRUSH)
-		uiDefButC(block,TOG,B_NOP,"Airbrush",cx+178,cy,89,19,&sculptmode_brush()->airbrush,0,0,0,0,"Brush makes changes without waiting for the mouse to move");
+		uiDefButBitC(block, TOG, SCULPT_BRUSH_AIRBRUSH, 0, "Airbrush", cx+178,cy,89,19, &sculptmode_brush()->flag,0,0,0,0, "Brush makes changes without waiting for the mouse to move");
 	cy-= 20;
 	uiDefButS(block,NUMSLI,B_NOP,"Size: ",cx,cy,268,19,&sculptmode_brush()->size,1.0,200.0,0,0,"Set brush radius in pixels");
 	cy-= 20;
@@ -5419,6 +5419,8 @@
 	cy-= 20;
 	if(sd->brush_type == DRAW_BRUSH)
 		uiDefButC(block,NUM,B_NOP, "View", cx,cy,80,19, &sculptmode_brush()->view, 0,10,20,0,"Pulls brush direction towards view");
+	cy-= 20;
+	uiDefButBitC(block, TOG, SCULPT_BRUSH_ANCHORED, 0, "Anchored", cx,cy,80,19, &sculptmode_brush()->flag, 0,0,0,0, "Keep the brush center anchored to the initial location");
 	uiBlockEndAlign(block);
 
 	/* Draw curve */

Modified: trunk/blender/source/blender/src/header_view3d.c
===================================================================
--- trunk/blender/source/blender/src/header_view3d.c	2008-02-01 18:27:28 UTC (rev 13514)
+++ trunk/blender/source/blender/src/header_view3d.c	2008-02-01 19:45:11 UTC (rev 13515)
@@ -4533,7 +4533,7 @@
 		BIF_undo_push("Brush type");
 		break;
 	case 7:
-		br->airbrush= !br->airbrush;
+		br->flag ^= SCULPT_BRUSH_AIRBRUSH;
 		BIF_undo_push("Airbrush");
 		break;
 	case 8:
@@ -4632,7 +4632,7 @@
 	
 	if(sd->brush_type!=GRAB_BRUSH) {
 		uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-		uiDefIconTextBut(block, BUTM, 1, (br->airbrush ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT), "Airbrush|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
+		uiDefIconTextBut(block, BUTM, 1, (br->flag & SCULPT_BRUSH_AIRBRUSH ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT), "Airbrush|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
 		
 		if(sd->brush_type!=SMOOTH_BRUSH && sd->brush_type!=FLATTEN_BRUSH) {
 			uiDefIconTextBut(block, BUTM, 1, (br->dir==1 ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT), "Add|V", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 18, "");

Modified: trunk/blender/source/blender/src/sculptmode.c
===================================================================
--- trunk/blender/source/blender/src/sculptmode.c	2008-02-01 18:27:28 UTC (rev 13514)
+++ trunk/blender/source/blender/src/sculptmode.c	2008-02-01 19:45:11 UTC (rev 13515)
@@ -134,7 +134,7 @@
 
 	float up[3], right[3], out[3];
 
-	// Grab brush
+	/* Grab brush */
 	float grab_delta[3];
 } BrushActionSymm;
 
@@ -143,17 +143,25 @@
 
 	char firsttime;
 
+	/* Some brushes need access to original mesh vertices */
+ 	vec3f *mesh_store;
+	short (*orig_norms)[3];
+
 	short mouse[2];
 	float size_3d;
 
+	float prev_radius;
+	float radius;
+
 	float *layer_disps;
-	vec3f *layer_store;
 	char flip;
 
 	char clip[3];
 	float cliptol[3];
 
-	// Grab brush
+	float anchored_rot;
+
+	/* Grab brush */
 	ListBase grab_active_verts[8];
 	float depth;
 
@@ -368,6 +376,7 @@
 	float pressure= 1;
 	short activedevice= get_activedevice();
 	float flip= a->flip ? -1:1;
+	float anchored = b->flag & SCULPT_BRUSH_ANCHORED ? 25 : 1;
 
 	const float strength_factor= G.scene->sculptdata.tablet_strength / 10.0f;
 	if(ELEM(activedevice, DEV_STYLUS, DEV_ERASER))
@@ -381,17 +390,17 @@
 	switch(G.scene->sculptdata.brush_type){
 	case DRAW_BRUSH:
 	case LAYER_BRUSH:
-		return b->strength / 5000.0f * dir * pressure * flip;
+		return b->strength / 5000.0f * dir * pressure * flip * anchored;
 	case SMOOTH_BRUSH:
-		return b->strength / 50.0f * pressure;
+		return b->strength / 50.0f * pressure * anchored;
 	case PINCH_BRUSH:
-		return b->strength / 1000.0f * dir * pressure * flip;
+		return b->strength / 1000.0f * dir * pressure * flip * anchored;
 	case GRAB_BRUSH:
 		return 1;
 	case INFLATE_BRUSH:
-		return b->strength / 5000.0f * dir * pressure * flip;
+		return b->strength / 5000.0f * dir * pressure * flip * anchored;
 	case FLATTEN_BRUSH:
-		return b->strength / 500.0f * pressure;
+		return b->strength / 500.0f * pressure * anchored;
 	default:
 		return 0;
 	}
@@ -411,42 +420,54 @@
 
 /* Currently only for the draw brush; finds average normal for all active
    vertices */
-vec3f calc_area_normal(const float *outdir, const ListBase* active_verts)
+void calc_area_normal(float out[3], const BrushAction *a, const float *outdir, const ListBase* active_verts)
 {
-	Mesh *me= get_mesh(OBACT);
-	vec3f area_normal= {0,0,0};
-	ActiveData *node= active_verts->first;
-	const int view= sculpt_data()->brush_type==DRAW_BRUSH ? sculptmode_brush()->view : 0;
+	Mesh *me = get_mesh(OBACT);
+	ActiveData *node = active_verts->first;
+	const int view = sculpt_data()->brush_type==DRAW_BRUSH ? sculptmode_brush()->view : 0;
 
-	while(node){
-		area_normal.x+= me->mvert[node->Index].no[0];
-		area_normal.y+= me->mvert[node->Index].no[1];
-		area_normal.z+= me->mvert[node->Index].no[2];
-		node= node->next;
+	out[0] = out[1] = out[2] = 0;
+
+	if(sculptmode_brush()->flag & SCULPT_BRUSH_ANCHORED) {
+		for(; node; node = node->next) {
+			out[0] += a->orig_norms[node->Index][0];
+			out[1] += a->orig_norms[node->Index][1];
+			out[2] += a->orig_norms[node->Index][2];
+		}
 	}
-	Normalize(&area_normal.x);
+	else {
+		for(; node; node = node->next) {
+			out[0] += me->mvert[node->Index].no[0];
+			out[1] += me->mvert[node->Index].no[1];
+			out[2] += me->mvert[node->Index].no[2];
+		}
+	}
 
+	Normalize(out);
+
 	if(outdir) {
-		area_normal.x= outdir[0] * view + area_normal.x * (10-view);
-		area_normal.y= outdir[1] * view + area_normal.y * (10-view);
-		area_normal.z= outdir[2] * view + area_normal.z * (10-view);
+		out[0] = outdir[0] * view + out[0] * (10-view);
+		out[1] = outdir[1] * view + out[1] * (10-view);
+		out[2] = outdir[2] * view + out[2] * (10-view);
 	}
 
-	Normalize(&area_normal.x);
-	return area_normal;
+	Normalize(out);
 }
+
 void do_draw_brush(const BrushAction *a, const ListBase* active_verts)
 {
 	Mesh *me= get_mesh(OBACT);
-	const vec3f area_normal= calc_area_normal(a->symm.out, active_verts);
+	float area_normal[3];
 	ActiveData *node= active_verts->first;
 
+	calc_area_normal(area_normal, a, a->symm.out, active_verts);
+
 	while(node){
 		float *co= me->mvert[node->Index].co;
 		
-		const float val[3]= {co[0]+area_normal.x*node->Fade*a->scale[0],
-		                     co[1]+area_normal.y*node->Fade*a->scale[1],
-		                     co[2]+area_normal.z*node->Fade*a->scale[2]};
+		const float val[3]= {co[0]+area_normal[0]*node->Fade*a->scale[0],
+		                     co[1]+area_normal[1]*node->Fade*a->scale[1],
+		                     co[2]+area_normal[2]*node->Fade*a->scale[2]};
 		                     
 		sculpt_clip(a, co, val);
 		
@@ -556,10 +577,12 @@
 void do_layer_brush(BrushAction *a, const ListBase *active_verts)
 {
 	Mesh *me= get_mesh(OBACT);
-	vec3f area_normal= calc_area_normal(NULL, active_verts);
+	float area_normal[3];
 	ActiveData *node= active_verts->first;
 	const float bstr= brush_strength(a);
 
+	calc_area_normal(area_normal, a, NULL, active_verts);
+
 	while(node){
 		float *disp= &a->layer_disps[node->Index];
 		
@@ -578,9 +601,9 @@
 			}
 
 			{
-				const float val[3]= {a->layer_store[node->Index].x+area_normal.x * *disp*a->scale[0],
-				                     a->layer_store[node->Index].y+area_normal.y * *disp*a->scale[1],
-				                     a->layer_store[node->Index].z+area_normal.z * *disp*a->scale[2]};
+				const float val[3]= {a->mesh_store[node->Index].x+area_normal[0] * *disp*a->scale[0],
+				                     a->mesh_store[node->Index].y+area_normal[1] * *disp*a->scale[1],
+				                     a->mesh_store[node->Index].z+area_normal[2] * *disp*a->scale[2]};
 				sculpt_clip(a, co, val);
 			}
 		}
@@ -642,9 +665,10 @@
 	Mesh *me= get_mesh(OBACT);
 	ActiveData *node= active_verts->first;
 	/* area_normal and cntr define the plane towards which vertices are squashed */
-	vec3f area_normal= calc_area_normal(a->symm.out, active_verts);
+	float area_normal[3];
 	float cntr[3];
-	
+
+	calc_area_normal(area_normal, a, a->symm.out, active_verts);
 	calc_flatten_center(me, node, cntr);
 
 	while(node){
@@ -652,11 +676,11 @@
 		float p1[3], sub1[3], sub2[3], intr[3], val[3];
 		
 		/* Find the intersection between squash-plane and vertex (along the area normal) */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list