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

Nicholas Bishop nicholasbishop at gmail.com
Fri Jan 25 05:17:43 CET 2008


Revision: 13396
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13396
Author:   nicholasbishop
Date:     2008-01-25 05:17:38 +0100 (Fri, 25 Jan 2008)

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

Cleaned up some old parts of sculpt. Got rid of the old EditData struct in favor of two new "brush action" structures, which split the symmetry data out from everything else. Cleaned up various names and such as well. There should be no user-visible changes.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BDR_sculptmode.h
    trunk/blender/source/blender/src/sculptmode-stroke.c
    trunk/blender/source/blender/src/sculptmode.c

Modified: trunk/blender/source/blender/include/BDR_sculptmode.h
===================================================================
--- trunk/blender/source/blender/include/BDR_sculptmode.h	2008-01-24 23:27:16 UTC (rev 13395)
+++ trunk/blender/source/blender/include/BDR_sculptmode.h	2008-01-25 04:17:38 UTC (rev 13396)
@@ -35,8 +35,8 @@
 #include "BKE_sculpt.h"
 
 struct uiBlock;
+struct BrushAction;
 struct BrushData;
-struct EditData;
 struct IndexNode;
 struct KeyBlock;
 struct Mesh;
@@ -65,7 +65,7 @@
 void sculpt_radialcontrol_start(int mode);
 
 struct BrushData *sculptmode_brush(void);
-void do_symmetrical_brush_actions(struct EditData *e, short *, short *);
+void do_symmetrical_brush_actions(struct BrushAction *a, short *, short *);
 
 void sculptmode_update_tex(void);
 char sculpt_modifiers_active(struct Object *ob);
@@ -76,8 +76,8 @@
 void sculpt_stroke_new(const int max);
 void sculpt_stroke_free();
 void sculpt_stroke_add_point(const short x, const short y);
-void sculpt_stroke_apply(struct EditData *);
-void sculpt_stroke_apply_all(struct EditData *e);
+void sculpt_stroke_apply(struct BrushAction *);
+void sculpt_stroke_apply_all(struct BrushAction *);
 void sculpt_stroke_draw();
 
 

Modified: trunk/blender/source/blender/src/sculptmode-stroke.c
===================================================================
--- trunk/blender/source/blender/src/sculptmode-stroke.c	2008-01-24 23:27:16 UTC (rev 13395)
+++ trunk/blender/source/blender/src/sculptmode-stroke.c	2008-01-25 04:17:38 UTC (rev 13396)
@@ -178,7 +178,7 @@
 }
 
 /* If partial is nonzero, cuts off apply after that length has been processed */
-static StrokePoint *sculpt_stroke_apply_generic(SculptStroke *stroke, struct EditData *e, const int partial)
+static StrokePoint *sculpt_stroke_apply_generic(SculptStroke *stroke, struct BrushAction *a, const int partial)
 {
 	const int sdspace = sculpt_data()->spacing;
 	const short spacing = sdspace > 0 ? sdspace : 2;
@@ -215,13 +215,13 @@
 		co[0] = p->x*v + p->next->x*u;
 		co[1] = p->y*v + p->next->y*u;
 
-		do_symmetrical_brush_actions(e, co, NULL);
+		do_symmetrical_brush_actions(a, co, NULL);
 	}
 
 	return p ? p->next : NULL;
 }
 
-void sculpt_stroke_apply(struct EditData *e)
+void sculpt_stroke_apply(struct BrushAction *a)
 {
 	SculptStroke *stroke = sculpt_session()->stroke;
 	/* TODO: make these values user-modifiable? */
@@ -232,7 +232,7 @@
 		sculpt_stroke_create_final();
 
 		if(sculpt_stroke_final_length(stroke) > min_len) {
-			StrokePoint *p = sculpt_stroke_apply_generic(stroke, e, partial_len);
+			StrokePoint *p = sculpt_stroke_apply_generic(stroke, a, partial_len);
 
 			/* Replace remaining values in stroke->loc with remaining stroke->final values */
 			stroke->index = -1;
@@ -249,14 +249,14 @@
 	}
 }
 
-void sculpt_stroke_apply_all(struct EditData *e)
+void sculpt_stroke_apply_all(struct BrushAction *a)
 {
 	SculptStroke *stroke = sculpt_session()->stroke;
 
 	sculpt_stroke_create_final();
 
 	if(stroke) {
-		sculpt_stroke_apply_generic(stroke, e, 0);
+		sculpt_stroke_apply_generic(stroke, a, 0);
 	}
 }
 

Modified: trunk/blender/source/blender/src/sculptmode.c
===================================================================
--- trunk/blender/source/blender/src/sculptmode.c	2008-01-24 23:27:16 UTC (rev 13395)
+++ trunk/blender/source/blender/src/sculptmode.c	2008-01-25 04:17:38 UTC (rev 13396)
@@ -125,37 +125,40 @@
 	float dist;
 } ActiveData;
 
-typedef struct GrabData {
-	char firsttime;
-	ListBase active_verts[8];
-	unsigned char index;
-	vec3f delta, delta_symm;
-	float depth;
-} GrabData;
+typedef struct BrushActionSymm {
+	float center_3d[3];
+	char index;
 
-typedef struct EditData {
-	vec3f center;
-	float size;
-	char flip;
-	short mouse[2];
+	float up[3], right[3], out[3];
 
-	/* Adjust brush strength along each axis
-	   to adjust for object scaling */
-	float scale[3];
+	// Grab brush
+	float grab_delta[3];
+} BrushActionSymm;
 
-	/* View normals */
-	vec3f up, right, out;
+typedef struct BrushAction {
+	BrushActionSymm symm;
 
-	GrabData *grabdata;
+	char firsttime;
+
+	short mouse[2];
+	float size_3d;
+
 	float *layer_disps;
 	vec3f *layer_store;
-	
+	char flip;
+
 	char clip[3];
 	float cliptol[3];
-	
-	char symm;
-} EditData;
 
+	// Grab brush
+	ListBase grab_active_verts[8];
+	float depth;
+
+	/* Adjust brush strength along each axis
+	   to adjust for object scaling */
+	float scale[3];
+} BrushAction;
+
 typedef struct RectNode {
 	struct RectNode *next, *prev;
 	rcti r;
@@ -178,7 +181,7 @@
 }
 
 void sculpt_init_session(void);
-void init_editdata(EditData *e, short *, short *);
+void init_brushaction(BrushAction *a, short *, short *);
 void sculpt_undo_push(const short);
 
 SculptSession *sculpt_session(void)
@@ -294,18 +297,16 @@
 
 /* Uses window coordinates (x,y) and depth component z to find a point in
    modelspace */
-vec3f unproject(const short x, const short y, const float z)
+void unproject(float out[3], const short x, const short y, const float z)
 {
 	SculptSession *ss= sculpt_session();
 	double ux, uy, uz;
-	vec3f p;
 
         gluUnProject(x,y,z, ss->mats->modelview, ss->mats->projection,
 		     (GLint *)ss->mats->viewport, &ux, &uy, &uz );
-	p.x= ux;
-	p.y= uy;
-	p.z= uz;
-	return p;
+	out[0] = ux;
+	out[1] = uy;
+	out[2] = uz;
 }
 
 /* Convert a point in model coordinates to 2D screen coordinates. */
@@ -348,13 +349,13 @@
 /* Return modified brush strength. Includes the direction of the brush, positive
    values pull vertices, negative values push. Uses tablet pressure and a
    special multiplier found experimentally to scale the strength factor. */
-float brush_strength(EditData *e)
+float brush_strength(BrushAction *a)
 {
 	const BrushData* b= sculptmode_brush();
 	float dir= b->dir==1 ? 1 : -1;
 	float pressure= 1;
 	short activedevice= get_activedevice();
-	float flip= e->flip ? -1:1;
+	float flip= a->flip ? -1:1;
 
 	const float strength_factor= G.scene->sculptdata.tablet_strength / 10.0f;
 	if(ELEM(activedevice, DEV_STYLUS, DEV_ERASER))
@@ -385,11 +386,11 @@
 }
 
 /* For clipping against a mirror modifier */
-void sculpt_clip(const EditData *e, float *co, const float val[3])
+void sculpt_clip(const BrushAction *a, float *co, const float val[3])
 {
 	char i;
 	for(i=0; i<3; ++i) {
-		if(e->clip[i] && (fabs(co[i]) <= e->cliptol[i]))
+		if(a->clip[i] && (fabs(co[i]) <= a->cliptol[i]))
 			co[i]= 0.0f;
 		else
 			co[i]= val[i];
@@ -398,7 +399,7 @@
 
 /* Currently only for the draw brush; finds average normal for all active
    vertices */
-vec3f calc_area_normal(const vec3f *outdir, const ListBase* active_verts)
+vec3f calc_area_normal(const float *outdir, const ListBase* active_verts)
 {
 	Mesh *me= get_mesh(OBACT);
 	vec3f area_normal= {0,0,0};
@@ -412,28 +413,30 @@
 		node= node->next;
 	}
 	Normalize(&area_normal.x);
+
 	if(outdir) {
-		area_normal.x= outdir->x * view + area_normal.x * (10-view);
-		area_normal.y= outdir->y * view + area_normal.y * (10-view);
-		area_normal.z= outdir->z * view + area_normal.z * (10-view);
+		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);
 	}
+
 	Normalize(&area_normal.x);
 	return area_normal;
 }
-void do_draw_brush(const EditData *e, const ListBase* active_verts)
+void do_draw_brush(const BrushAction *a, const ListBase* active_verts)
 {
 	Mesh *me= get_mesh(OBACT);
-	const vec3f area_normal= calc_area_normal(&e->out, active_verts);
+	const vec3f area_normal= calc_area_normal(a->symm.out, active_verts);
 	ActiveData *node= active_verts->first;
 
 	while(node){
 		float *co= me->mvert[node->Index].co;
 		
-		const float val[3]= {co[0]+area_normal.x*node->Fade*e->scale[0],
-		                     co[1]+area_normal.y*node->Fade*e->scale[1],
-		                     co[2]+area_normal.z*node->Fade*e->scale[2]};
+		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]};
 		                     
-		sculpt_clip(e, co, val);
+		sculpt_clip(a, co, val);
 		
 		node= node->next;
 	}
@@ -489,7 +492,7 @@
 	return avg;
 }
 
-void do_smooth_brush(const EditData *e, const ListBase* active_verts)
+void do_smooth_brush(const BrushAction *a, const ListBase* active_verts)
 {
 	ActiveData *node= active_verts->first;
 	Mesh *me= get_mesh(OBACT);
@@ -500,53 +503,53 @@
 		const float val[3]= {co[0]+(avg.x-co[0])*node->Fade,
 		                     co[1]+(avg.y-co[1])*node->Fade,
 		                     co[2]+(avg.z-co[2])*node->Fade};
-		sculpt_clip(e, co, val);
+		sculpt_clip(a, co, val);
 		node= node->next;
 	}
 }
 
-void do_pinch_brush(const EditData *e, const ListBase* active_verts)
+void do_pinch_brush(const BrushAction *a, const ListBase* active_verts)
 {
 	Mesh *me= get_mesh(OBACT);
  	ActiveData *node= active_verts->first;
 
 	while(node) {
 		float *co= me->mvert[node->Index].co;
-		const float val[3]= {co[0]+(e->center.x-co[0])*node->Fade,
-		                     co[1]+(e->center.y-co[1])*node->Fade,
-		                     co[2]+(e->center.z-co[2])*node->Fade};
-		sculpt_clip(e, co, val);
+		const float val[3]= {co[0]+(a->symm.center_3d[0]-co[0])*node->Fade,
+		                     co[1]+(a->symm.center_3d[1]-co[1])*node->Fade,
+		                     co[2]+(a->symm.center_3d[2]-co[2])*node->Fade};
+		sculpt_clip(a, co, val);
 		node= node->next;
 	}
 }
 
-void do_grab_brush(EditData *e)
+void do_grab_brush(BrushAction *a)
 {
 	Mesh *me= get_mesh(OBACT);
-	ActiveData *node= e->grabdata->active_verts[e->grabdata->index].first;
+	ActiveData *node= a->grab_active_verts[a->symm.index].first;
 	float add[3];
 
 	while(node) {
 		float *co= me->mvert[node->Index].co;
 		
-		VecCopyf(add, &e->grabdata->delta_symm.x);
+		VecCopyf(add, a->symm.grab_delta);
 		VecMulf(add, node->Fade);
 		VecAddf(add, add, co);
-		sculpt_clip(e, co, add);
+		sculpt_clip(a, co, add);
 
 		node= node->next;
 	}
 }
 
-void do_layer_brush(EditData *e, const ListBase *active_verts)
+void do_layer_brush(BrushAction *a, const ListBase *active_verts)
 {
 	Mesh *me= get_mesh(OBACT);
 	vec3f area_normal= calc_area_normal(NULL, active_verts);
 	ActiveData *node= active_verts->first;
-	const float bstr= brush_strength(e);
+	const float bstr= brush_strength(a);
 
 	while(node){
-		float *disp= &e->layer_disps[node->Index];
+		float *disp= &a->layer_disps[node->Index];
 		
 		if((bstr > 0 && *disp < bstr) ||

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list