[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30181] branches/soc-2010-jwilkins: == Symmetry Feather ==

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jul 10 17:23:23 CEST 2010


Revision: 30181
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30181
Author:   jwilkins
Date:     2010-07-10 17:23:21 +0200 (Sat, 10 Jul 2010)

Log Message:
-----------
== Symmetry Feather ==

Symmetry feather reduces the strength of the brush if it overlaps with other symmetrical instances of the brush.  Works in mirror and radial modes.

Rearranged UI because symmetry seems to have enough options to deserve its own panel now.

Made 'lock axis' into a set of toggle buttons so if takes up less space.  

Modified Paths:
--------------
    branches/soc-2010-jwilkins/release/scripts/ui/properties_texture.py
    branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c

Modified: branches/soc-2010-jwilkins/release/scripts/ui/properties_texture.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/ui/properties_texture.py	2010-07-10 13:38:32 UTC (rev 30180)
+++ branches/soc-2010-jwilkins/release/scripts/ui/properties_texture.py	2010-07-10 15:23:21 UTC (rev 30181)
@@ -311,6 +311,9 @@
 
         if wide_ui:
             col = split.column()
+        else:
+            col.separator()
+
         col.prop(tex, "size")
 
 

Modified: branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-07-10 13:38:32 UTC (rev 30180)
+++ branches/soc-2010-jwilkins/release/scripts/ui/space_view3d_toolbar.py	2010-07-10 15:23:21 UTC (rev 30181)
@@ -815,6 +815,9 @@
 
             if wide_ui:
                 col = split.column()
+            else:
+                col.separator()
+
             col.prop(tex_slot, "size")
 
             col = layout.column()
@@ -1000,6 +1003,7 @@
 
 class VIEW3D_PT_sculpt_options(PaintPanel):
     bl_label = "Options"
+    bl_default_closed = True
 
     def poll(self, context):
         return (context.sculpt_object and context.tool_settings.sculpt)
@@ -1007,21 +1011,50 @@
     def draw(self, context):
         layout = self.layout
 
+        wide_ui = context.region.width > narrowui
+
         sculpt = context.tool_settings.sculpt
         settings = self.paint_settings(context)
         brush = settings.brush
 
-        col = layout.column()
+        split = layout.split()
 
+        col = split.column()
+
         edit = context.user_preferences.edit
         col.label(text="Unified Settings:")
         col.prop(edit, "sculpt_paint_use_unified_size", text="Size")
         col.prop(edit, "sculpt_paint_use_unified_strength", text="Strength")
 
-        col.separator()
+        if wide_ui:
+            col = split.column()
+        else:
+            col.separator()
 
-        split = self.layout.split()
+        col.label(text="Lock:")
+        row = col.row(align=True)
+        row.prop(sculpt, "lock_x", text="X", toggle=True)
+        row.prop(sculpt, "lock_y", text="Y", toggle=True)
+        row.prop(sculpt, "lock_z", text="Z", toggle=True)
 
+class VIEW3D_PT_sculpt_symmetry(PaintPanel):
+    bl_label = "Symmetry"
+    bl_default_closed = True
+
+    def poll(self, context):
+        return (context.sculpt_object and context.tool_settings.sculpt)
+
+    def draw(self, context):
+        wide_ui = context.region.width > narrowui
+
+        layout = self.layout
+
+        sculpt = context.tool_settings.sculpt
+        settings = self.paint_settings(context)
+        brush = settings.brush
+
+        split = layout.split()
+
         col = split.column()
 
         col.label(text="Mirror:")
@@ -1029,19 +1062,22 @@
         col.prop(sculpt, "symmetry_y", text="Y")
         col.prop(sculpt, "symmetry_z", text="Z")
 
+        if wide_ui:
+            col = split.column()
+        else:
+            col.separator()
+
         col.prop(sculpt, "radial_symm", text="Radial")
 
-        #col.separator()
-        #col.prop(sculpt, "use_symmetry_feather", text="Feather")
+        col = layout.column()
 
-        col = split.column()
-        col.label(text="Lock:")
-        col.prop(sculpt, "lock_x", text="X")
-        col.prop(sculpt, "lock_y", text="Y")
-        col.prop(sculpt, "lock_z", text="Z")
+        col.separator()
 
+        col.prop(sculpt, "use_symmetry_feather", text="Feather")
+
 class VIEW3D_PT_tools_brush_appearance(PaintPanel):
     bl_label = "Appearance"
+    bl_default_closed = True
 
     def poll(self, context):
         return (context.sculpt_object and context.tool_settings.sculpt) or (context.vertex_paint_object and context.tool_settings.vertex_paint) or (context.weight_paint_object and context.tool_settings.weight_paint) or (context.texture_paint_object and context.tool_settings.image_paint)
@@ -1317,11 +1353,12 @@
     VIEW3D_PT_tools_posemode_options,
     VIEW3D_PT_tools_brush,
     VIEW3D_PT_tools_brush_texture,
-    VIEW3D_PT_tools_brush_tool,
     VIEW3D_PT_tools_brush_stroke,
     VIEW3D_PT_tools_brush_curve,
+    VIEW3D_PT_tools_brush_appearance,
+    VIEW3D_PT_tools_brush_tool,
+    VIEW3D_PT_sculpt_symmetry,
     VIEW3D_PT_sculpt_options,
-    VIEW3D_PT_tools_brush_appearance,
     VIEW3D_PT_tools_vertexpaint,
     VIEW3D_PT_tools_weightpaint_options,
 

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-07-10 13:38:32 UTC (rev 30180)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/sculpt.c	2010-07-10 15:23:21 UTC (rev 30181)
@@ -182,6 +182,7 @@
 
 	/* Variants */
 	float radius;
+	float radius_squared;
 	float true_location[3];
 	float location[3];
 
@@ -347,7 +348,7 @@
 
 static void sculpt_brush_test_init(SculptSession *ss, SculptBrushTest *test)
 {
-	test->radius_squared= ss->cache->radius*ss->cache->radius;
+	test->radius_squared= ss->cache->radius_squared;
 	copy_v3_v3(test->location, ss->cache->location);
 
 	//copy_v3_v3(test->true_location, ss->cache->true_location);
@@ -385,25 +386,24 @@
 	return 1;
 }
 
-static int sculpt_brush_test_cyl(SculptBrushTest *test, float x0[3], float x1[3], float x2[3])
+static int sculpt_brush_test_cyl(SculptBrushTest *test, float co[3], float location[3], float an[3])
 {
-	float t0[3], t1[3], t2[3], t3[3], dist;
+	if (sculpt_brush_test_fast(test, co)) {
+		float t1[3], t2[3], t3[3], dist;
 
-	sub_v3_v3v3(t0, x2, x1);
-	sub_v3_v3v3(t1, x1, x0);
-	sub_v3_v3v3(t2, x2, x1);
+		sub_v3_v3v3(t1, location, co);
+		sub_v3_v3v3(t2, x2, location);
 
-	cross_v3_v3v3(t3, t0, t1);
+		cross_v3_v3v3(t3, an, t1);
 
-	dist = len_v3(t3)/len_v3(t2);
+		dist = len_v3(t3)/len_v3(t2);
 
-	if (dist*dist < test->radius_squared) {
 		test->dist = dist;
+
 		return 1;
 	}
-	else {
-		return 0;
-	}
+
+	return 0;
 }
 
 #endif
@@ -518,6 +518,84 @@
 	return max;
 }
 
+/* Uses symm to selectively flip any axis of a coordinate. */
+static void flip_coord(float out[3], float in[3], const char symm)
+{
+	if(symm & SCULPT_SYMM_X)
+		out[0]= -in[0];
+	else
+		out[0]= in[0];
+	if(symm & SCULPT_SYMM_Y)
+		out[1]= -in[1];
+	else
+		out[1]= in[1];
+	if(symm & SCULPT_SYMM_Z)
+		out[2]= -in[2];
+	else
+		out[2]= in[2];
+}
+
+float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle)
+{
+	float mirror[3];
+	float distsq;
+	float mat[4][4];
+	
+	flip_coord(mirror, cache->true_location, symm);
+
+	unit_m4(mat);
+	rotate_m4(mat, axis, angle);
+
+	mul_m4_v3(mat, mirror);
+
+	distsq = len_squared_v3v3(mirror, cache->true_location);
+
+	if (distsq <= 4*(cache->radius_squared))
+		return (2*(cache->radius) - sqrt(distsq))  /  (2*(cache->radius));
+	else
+		return 0;
+}
+
+static float calc_radial_symmetry_feather(Sculpt *sd, StrokeCache *cache, const char symm, const char axis)
+{
+	int i;
+	float overlap;
+
+	overlap = 0;
+	for(i = 1; i < sd->radial_symm[axis-'X']; ++i) {
+		const float angle = 2*M_PI*i/sd->radial_symm[axis-'X'];
+		overlap += calc_overlap(cache, symm, axis, angle);
+	}
+
+	return overlap;
+}
+
+static float calc_symmetry_feather(Sculpt *sd, StrokeCache* cache)
+{
+	if (sd->flags & SCULPT_SYMMETRY_FEATHER) {
+		float overlap;
+		int symm = cache->symmetry;
+		int i;
+
+		overlap = 0;
+		for (i = 0; i <= symm; i++) {
+			if(i == 0 || (symm & i && (symm != 5 || i != 3) && (symm != 6 || (i != 3 && i != 5)))) {
+
+				overlap += calc_overlap(cache, i, 0, 0);
+
+				overlap += calc_radial_symmetry_feather(sd, cache, i, 'X');
+				overlap += calc_radial_symmetry_feather(sd, cache, i, 'Y');
+				overlap += calc_radial_symmetry_feather(sd, cache, i, 'Z');
+			}
+		}
+
+		return 1/overlap;
+	}
+	else {
+		return 1;
+	}
+}
+
 /* 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. */
@@ -537,6 +615,7 @@
 	//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
 	//float overlap      = (brush->flag & BRUSH_SPACE_ATTEN && brush->flag & BRUSH_SPACE && !(brush->flag & BRUSH_ANCHORED)) && (brush->spacing < 50) ? (float)brush->spacing/50.0f : 1; // spacing is integer percentage of radius, divide by 50 to get normalized diameter
 	float flip         = dir * invert * pen_flip;
+	float feather      = calc_symmetry_feather(sd, cache);
 
 	// XXX not functionally cohesive to update this here
 	brush->autosmooth_overlap = overlap;
@@ -546,18 +625,18 @@
 		case SCULPT_TOOL_DRAW:
 		case SCULPT_TOOL_WAX:
 		case SCULPT_TOOL_LAYER:
-			return alpha * flip * pressure * overlap;
+			return alpha * flip * pressure * overlap * feather;
 
 		case SCULPT_TOOL_CREASE:
 		case SCULPT_TOOL_BLOB:
-			return alpha * flip * pressure * overlap;
+			return alpha * flip * pressure * overlap * feather;
 
 		case SCULPT_TOOL_INFLATE:
 			if (flip > 0) {
-				return 0.250f * alpha * flip * pressure * overlap;
+				return 0.250f * alpha * flip * pressure * overlap * feather;
 			}
 			else {
-				return 0.125f * alpha * flip * pressure * overlap;
+				return 0.125f * alpha * flip * pressure * overlap * feather;
 			}
 
 		case SCULPT_TOOL_FILL:
@@ -565,61 +644,43 @@
 		case SCULPT_TOOL_FLATTEN:
 			if (flip > 0) {
 				overlap = (1+overlap) / 2;
-				return alpha * flip * pressure * overlap;
+				return alpha * flip * pressure * overlap * feather;
 			}
 			else {
 				/* reduce strength for DEEPEN, PEAKS, and CONTRAST */
-				return 0.5f * alpha * flip * pressure * overlap; 
+				return 0.5f * alpha * flip * pressure * overlap * feather; 
 			}
 
 		case SCULPT_TOOL_SMOOTH:
-			return alpha * pressure;
+			return alpha * pressure * feather;
 
 		case SCULPT_TOOL_PINCH:
 			if (flip > 0) {
-				return alpha * flip * pressure * overlap;
+				return alpha * flip * pressure * overlap * feather;
 			}
 			else {
-				return 0.25f * alpha * flip * pressure * overlap;
+				return 0.25f * alpha * flip * pressure * overlap * feather;
 			}
 
 		case SCULPT_TOOL_NUDGE:
 			overlap = (1+overlap) / 2;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list