[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18500] branches/blender2.5/blender/source /blender: Moved some more sculpt data into operator properties, also the test brush is now properly created so you can edit its state in the RNA viewer .

Nicholas Bishop nicholasbishop at gmail.com
Wed Jan 14 16:29:31 CET 2009


Revision: 18500
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18500
Author:   nicholasbishop
Date:     2009-01-14 16:29:29 +0100 (Wed, 14 Jan 2009)

Log Message:
-----------
Moved some more sculpt data into operator properties, also the test brush is now properly created so you can edit its state in the RNA viewer. Added an RNA property for the brush sculpt tool as well.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c
    branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c	2009-01-14 13:18:10 UTC (rev 18499)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/brush.c	2009-01-14 15:29:29 UTC (rev 18500)
@@ -70,6 +70,7 @@
 	brush->rate= 0.1f;
 	brush->innerradius= 0.5f;
 	brush->clone.alpha= 0.5;
+	brush->sculpt_tool = SCULPT_TOOL_DRAW;
 
 	/* enable fake user by default */
 	brush->id.flag |= LIB_FAKEUSER;

Modified: branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-14 13:18:10 UTC (rev 18499)
+++ branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-14 15:29:29 UTC (rev 18500)
@@ -124,13 +124,25 @@
 	float grab_delta[3];
 } BrushActionSymm;
 
+typedef enum StrokeFlags {
+	CLIP_X = 1,
+	CLIP_Y = 2,
+	CLIP_Z = 4
+} StrokeFlags;
+
 /* Cache stroke properties that don't change after
    the initialization at the start of a stroke. Used because
-   RNA property lookup isn't particularly fast. */
+   RNA property lookup isn't particularly fast.
+
+   For descriptions of these settings, check the operator properties.
+*/
 typedef struct StrokeCache {
 	float radius;
 	float scale[3];
 	float flip;
+	int flag;
+	float clip_tolerance[3];
+	int mouse[2];
 } StrokeCache;
 
 typedef struct BrushAction {
@@ -142,16 +154,11 @@
  	vec3f *mesh_store;
 	short (*orig_norms)[3];
 
-	short mouse[2];
-
 	float prev_radius;
 	float radius;
 
 	float *layer_disps;
 
-	char clip[3];
-	float cliptol[3];
-
 	float anchored_rot;
 
 	/* Grab brush */
@@ -371,28 +378,28 @@
 	switch(sd->brush->sculpt_tool){
 	case SCULPT_TOOL_DRAW:
 	case SCULPT_TOOL_LAYER:
-		return sd->brush->alpha / 5000.0f * dir * pressure * flip * anchored; /*XXX: not sure why? multiplied by G.vd->grid */;
+		return sd->brush->alpha / 50.0f * dir * pressure * flip * anchored; /*XXX: not sure why? multiplied by G.vd->grid */;
 	case SCULPT_TOOL_SMOOTH:
-		return sd->brush->alpha / 50.0f * pressure * anchored;
+		return sd->brush->alpha / .5f * pressure * anchored;
 	case SCULPT_TOOL_PINCH:
-		return sd->brush->alpha / 1000.0f * dir * pressure * flip * anchored;
+		return sd->brush->alpha / 10.0f * dir * pressure * flip * anchored;
 	case SCULPT_TOOL_GRAB:
 		return 1;
 	case SCULPT_TOOL_INFLATE:
-		return sd->brush->alpha / 5000.0f * dir * pressure * flip * anchored;
+		return sd->brush->alpha / 50.0f * dir * pressure * flip * anchored;
 	case SCULPT_TOOL_FLATTEN:
-		return sd->brush->alpha / 500.0f * pressure * anchored;
+		return sd->brush->alpha / 5.0f * pressure * anchored;
 	default:
 		return 0;
 	}
 }
 
 /* For clipping against a mirror modifier */
-void sculpt_clip(const BrushAction *a, float *co, const float val[3])
+void sculpt_clip(StrokeCache *cache, float *co, const float val[3])
 {
 	char i;
 	for(i=0; i<3; ++i) {
-		if(a->clip[i] && (fabs(co[i]) <= a->cliptol[i]))
+		if((cache->flag & (CLIP_X << i)) && (fabs(co[i]) <= cache->clip_tolerance[i]))
 			co[i]= 0.0f;
 		else
 			co[i]= val[i];
@@ -482,7 +489,7 @@
 		                     co[1]+area_normal[1]*node->Fade*ss->cache->scale[1],
 		                     co[2]+area_normal[2]*node->Fade*ss->cache->scale[2]};
 		                     
-		sculpt_clip(a, co, val);
+		sculpt_clip(ss->cache, co, val);
 		
 		node= node->next;
 	}
@@ -546,7 +553,7 @@
 		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(a, co, val);
+		sculpt_clip(ss->cache, co, val);
 		node= node->next;
 	}
 }
@@ -560,7 +567,7 @@
 		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);
+		sculpt_clip(ss->cache, co, val);
 		node= node->next;
 	}
 }
@@ -580,7 +587,7 @@
 		VecCopyf(add, grab_delta);
 		VecMulf(add, node->Fade);
 		VecAddf(add, add, co);
-		sculpt_clip(a, co, add);
+		sculpt_clip(ss->cache, co, add);
 
 		node= node->next;
 	}
@@ -616,7 +623,7 @@
 				const float val[3]= {a->mesh_store[node->Index].x+area_normal[0] * *disp*ss->cache->scale[0],
 				                     a->mesh_store[node->Index].y+area_normal[1] * *disp*ss->cache->scale[1],
 				                     a->mesh_store[node->Index].z+area_normal[2] * *disp*ss->cache->scale[2]};
-				sculpt_clip(a, co, val);
+				sculpt_clip(ss->cache, co, val);
 			}
 		}
 
@@ -642,7 +649,7 @@
 		add[2]*= ss->cache->scale[2];
 		VecAddf(add, add, co);
 		
-		sculpt_clip(a, co, add);
+		sculpt_clip(ss->cache, co, add);
 
 		node= node->next;
 	}
@@ -697,7 +704,7 @@
 		VecMulf(val, node->Fade);
 		VecAddf(val, val, co);
 		
-		sculpt_clip(a, co, val);
+		sculpt_clip(ss->cache, co, val);
 		
 		node= node->next;
 	}
@@ -846,8 +853,8 @@
 				py %= sy-1;
 			avg= get_texcache_pixel_bilinear(ss, TC_SIZE*px/sx, TC_SIZE*py/sy);
 		} else {
-			float fx= (point_2d[0] - a->mouse[0]) / bsize;
-			float fy= (point_2d[1] - a->mouse[1]) / bsize;
+			float fx= (point_2d[0] - ss->cache->mouse[0]) / bsize;
+			float fy= (point_2d[1] - ss->cache->mouse[1]) / bsize;
 
 			float angle= atan2(fy, fx) - rot;
 			float flen= sqrtf(fx*fx + fy*fy);
@@ -1195,8 +1202,8 @@
 	   modelspace coords */
 	if(a->firsttime || !anchored) {
  		unproject(ss, a->symm.center_3d, mouse[0], mouse[1], mouse_depth);
- 		a->mouse[0] = mouse[0];
- 		a->mouse[1] = mouse[1];
+ 		/*a->mouse[0] = mouse[0];
+		  a->mouse[1] = mouse[1];*/
  	}
  
  	if(anchored) {
@@ -1237,23 +1244,8 @@
 	Normalize(a->symm.right);
 	Normalize(a->symm.out);
 	
-	/* Initialize mirror modifier clipping */
-	for(i=0; i<3; ++i) {
-		a->clip[i]= 0;
-		a->cliptol[i]= 0;
-	}
-	for(md= ob->modifiers.first; md; md= md->next) {
-		if(md->type==eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) {
-			const MirrorModifierData *mmd = (MirrorModifierData*) md;
-			
-			if(mmd->flag & MOD_MIR_CLIPPING) {
-				a->clip[mmd->axis]= 1;
-				if(mmd->tolerance > a->cliptol[mmd->axis])
-					a->cliptol[mmd->axis] = mmd->tolerance;
-			}
-		}
-	}
 
+
 	if(b->sculpt_tool == SCULPT_TOOL_GRAB) {
 		float gcenter[3];
 
@@ -1644,10 +1636,16 @@
 }
 
 /* Initialize the stroke cache invariants from operator properties */
-static int sculpt_update_cache_invariants(StrokeCache *cache, wmOperator *op)
+static int sculpt_update_cache_invariants(StrokeCache *cache, wmOperator *op, Object *ob)
 {
+
+	memset(cache, 0, sizeof(StrokeCache));
+
 	cache->radius = RNA_float_get(op->ptr, "radius");
 	RNA_float_get_array(op->ptr, "scale", cache->scale);
+	cache->flag = RNA_int_get(op->ptr, "flag");
+	RNA_float_get_array(op->ptr, "clip_tolerance", cache->clip_tolerance);
+	RNA_int_get_array(op->ptr, "mouse", cache->mouse);
 }
 
 /* Initialize the stroke cache variants from operator properties */
@@ -1661,10 +1659,12 @@
 {
 	SculptData *sd = &CTX_data_scene(C)->sculptdata;
 	Object *ob= CTX_data_active_object(C);
+	ModifierData *md;
 	float brush_center[3], brush_edge[3];
 	float depth = get_depth(C, event->x, event->y);
 	float size = brush_size(sd, sd->brush);
-	float scale[3];
+	float scale[3], clip_tolerance[3] = {0,0,0};
+	int mouse[2], flag = 0;
 
 	unproject(ss, brush_center, event->x, event->y, depth);
 	unproject(ss, brush_edge, event->x + size, event->y, depth);
@@ -1672,13 +1672,32 @@
 	RNA_float_set(op->ptr, "radius", VecLenf(brush_center, brush_edge));
 
 	/* Set scaling adjustment */
-	
 	scale[0] = 1.0f / ob->size[0];
 	scale[1] = 1.0f / ob->size[1];
 	scale[2] = 1.0f / ob->size[2];
 	RNA_float_set_array(op->ptr, "scale", scale);
 
-	sculpt_update_cache_invariants(ss->cache, op);
+	/* Initialize mirror modifier clipping */
+	for(md= ob->modifiers.first; md; md= md->next) {
+		if(md->type==eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) {
+			const MirrorModifierData *mmd = (MirrorModifierData*) md;
+			
+			/* Mark each axis that needs clipping along with its tolerance */
+			if(mmd->flag & MOD_MIR_CLIPPING) {
+				flag |= CLIP_X << mmd->axis;
+				if(mmd->tolerance > clip_tolerance[mmd->axis])
+					clip_tolerance[mmd->axis] = mmd->tolerance;
+			}
+		}
+	}
+	RNA_int_set(op->ptr, "flag", flag);
+	RNA_float_set_array(op->ptr, "clip_tolerance", clip_tolerance);
+
+	mouse[0] = event->x;
+	mouse[1] = event->y;
+	RNA_int_set_array(op->ptr, "mouse", mouse);
+
+	sculpt_update_cache_invariants(ss->cache, op, ob);
 }
 
 static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
@@ -1688,12 +1707,6 @@
 	Mesh *me = get_mesh(ob);
 	ARegion *ar = CTX_wm_region(C);
 
-	// XXX: temporary, just add one brush here for testing
-	sd->brush = MEM_callocN(sizeof(Brush), "test sculpt brush");
-	sd->brush->size = 25;
-	sd->brush->alpha = 50;
-	sd->brush->sculpt_tool = SCULPT_TOOL_DRAW;
-
 	// XXX: temporary, much of sculptsession data should be in rna properties
 	sd->session = MEM_callocN(sizeof(SculptSession), "test sculpt session");
 	sd->session->mvert = me->mvert;
@@ -1763,7 +1776,7 @@
 	ARegion *ar = CTX_wm_region(C);
 	SculptData *sd = &CTX_data_scene(C)->sculptdata;
 
-	sculpt_update_cache_invariants(sd->session->cache, op);
+	sculpt_update_cache_invariants(sd->session->cache, op, ob);
 
 	RNA_BEGIN(op->ptr, itemptr, "stroke") {
 		float loc[3];
@@ -1786,7 +1799,8 @@
 void SCULPT_OT_brush_stroke(wmOperatorType *ot)
 {
 	PropertyRNA *prop;
-	float vecdefault[] = {0,0,0};
+	float vec3f_def[] = {0,0,0};
+	int vec2i_def[] = {0,0};
 
 	ot->flag |= OPTYPE_REGISTER;
 
@@ -1811,7 +1825,18 @@
 	   to work as expected. */
 	prop= RNA_def_property(ot->srna, "scale", PROP_FLOAT, PROP_VECTOR);
 	RNA_def_property_array(prop, 3);
-	RNA_def_property_float_array_default(prop, vecdefault);
+	RNA_def_property_float_array_default(prop, vec3f_def);
+
+	prop= RNA_def_property(ot->srna, "flag", PROP_INT, PROP_NONE);
+
+	prop= RNA_def_property(ot->srna, "clip_tolerance", PROP_FLOAT, PROP_VECTOR);
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_float_array_default(prop, vec3f_def);
+
+	/* The initial 2D location of the mouse */
+	prop= RNA_def_property(ot->srna, "mouse", PROP_INT, PROP_VECTOR);
+	RNA_def_property_array(prop, 2);
+	RNA_def_property_int_array_default(prop, vec2i_def);
 }
 
 /**** Toggle operator for turning sculpt mode on or off ****/
@@ -1826,6 +1851,9 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list