[Bf-blender-cvs] [7719a63] strand_editmode: Use the X mirror option in new strand edit stroke brush tools.

Lukas Tönne noreply at git.blender.org
Mon Apr 20 14:24:35 CEST 2015


Commit: 7719a6365a8e496f75884113450e154bb3b9c33c
Author: Lukas Tönne
Date:   Mon Feb 9 09:39:01 2015 +0100
Branches: strand_editmode
https://developer.blender.org/rB7719a6365a8e496f75884113450e154bb3b9c33c

Use the X mirror option in new strand edit stroke brush tools.

Note that currently this has virtually no effect, because the mirror
option relies on exact positions of vertices, which does not happen with
random hair placement (the add brush has no mirror option yet).

Eventually topological mirroring should help with this case, but is not
implemented for either old or new strand edit yet.

===================================================================

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/hair/hair_edit.c
M	source/blender/editors/hair/hair_intern.h
M	source/blender/editors/hair/hair_stroke.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 3fdf21f..d4eb9ac 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1861,6 +1861,7 @@ class VIEW3D_PT_tools_hairmode(View3DPanel, Panel):
         ob = context.active_object
 
         col = layout.column(align=True)
+        col.prop(ob.data, "use_mirror_x")
 
 
 # Grease Pencil drawing tools
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/editors/hair/hair_edit.c
index 01cd1e4..6705991 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -37,6 +37,7 @@
 #include "BLI_math.h"
 
 #include "DNA_brush_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
@@ -130,6 +131,22 @@ int hair_edit_poll(bContext *C)
 	return false;
 }
 
+bool hair_use_mirror_x(Object *ob)
+{
+	if (ob->type == OB_MESH)
+		return ((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_X;
+	else
+		return false;
+}
+
+bool hair_use_mirror_topology(Object *ob)
+{
+	if (ob->type == OB_MESH)
+		return ((Mesh *)ob->data)->editflag & ME_EDIT_MIRROR_TOPO;
+	else
+		return false;
+}
+
 
 /* ==== BMesh utilities ==== */
 
diff --git a/source/blender/editors/hair/hair_intern.h b/source/blender/editors/hair/hair_intern.h
index 4854104..9644237 100644
--- a/source/blender/editors/hair/hair_intern.h
+++ b/source/blender/editors/hair/hair_intern.h
@@ -41,7 +41,12 @@ struct bContext;
 struct wmOperatorType;
 struct rcti;
 
+struct Object;
+
 /* hair_edit.c */
+bool hair_use_mirror_x(struct Object *ob);
+bool hair_use_mirror_topology(struct Object *ob);
+
 int hair_edit_toggle_poll(struct bContext *C);
 int hair_edit_poll(struct bContext *C);
 
diff --git a/source/blender/editors/hair/hair_stroke.c b/source/blender/editors/hair/hair_stroke.c
index 60953cd..7dbd7e5 100644
--- a/source/blender/editors/hair/hair_stroke.c
+++ b/source/blender/editors/hair/hair_stroke.c
@@ -39,6 +39,7 @@
 #include "BLI_rect.h"
 
 #include "DNA_brush_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -55,6 +56,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "ED_physics.h"
 #include "ED_view3d.h"
 
 #include "hair_intern.h"
@@ -218,11 +220,14 @@ static int hair_tool_apply_vertex(HairToolData *data, VertexToolCb cb, void *use
 	const float radsq = rad*rad;
 	const float threshold = 0.0f; /* XXX could be useful, is it needed? */
 	
-	BMVert *v;
+	BMVert *v, *v_mirr;
 	BMIter iter;
 	int tot = 0;
 	float dist, factor;
 	
+	if (hair_use_mirror_x(data->ob))
+		ED_strands_mirror_cache_begin(data->edit, 0, false, false, hair_use_mirror_topology(data->ob));
+	
 	BM_ITER_MESH(v, &iter, data->edit->bm, BM_VERTS_OF_MESH) {
 		if (!hair_test_vertex_inside_circle(&data->viewdata, data->mval, radsq, v, &dist))
 			continue;
@@ -231,9 +236,17 @@ static int hair_tool_apply_vertex(HairToolData *data, VertexToolCb cb, void *use
 		if (factor > threshold) {
 			cb(data, userdata, v, factor);
 			++tot;
+			
+			v_mirr = ED_strands_mirror_get(data->edit, v);
+			if (v_mirr)
+				cb(data, userdata, v_mirr, factor);
 		}
 	}
 	
+	/* apply mirror */
+	if (hair_use_mirror_x(data->ob))
+		ED_strands_mirror_cache_end(data->edit);
+	
 	return tot;
 }
 
@@ -249,7 +262,7 @@ static int hair_tool_apply_strand_edges(HairToolData *data, EdgeToolCb cb, void
 	const float radsq = rad*rad;
 	const float threshold = 0.0f; /* XXX could be useful, is it needed? */
 	
-	BMVert *v, *vprev;
+	BMVert *v, *vprev, *v_mirr, *vprev_mirr;
 	BMIter iter;
 	int k;
 	int tot = 0;
@@ -263,11 +276,16 @@ static int hair_tool_apply_strand_edges(HairToolData *data, EdgeToolCb cb, void
 				if (factor > threshold) {
 					cb(data, userdata, vprev, v, factor, lambda);
 					++tot;
+					
+					v_mirr = ED_strands_mirror_get(data->edit, v);
+					if (vprev_mirr && v_mirr)
+						cb(data, userdata, vprev_mirr, v_mirr, factor, lambda);
 				}
 			}
 		}
 		
 		vprev = v;
+		vprev_mirr = v_mirr;
 	}
 	
 	return tot;
@@ -282,10 +300,17 @@ static int hair_tool_apply_edge(HairToolData *data, EdgeToolCb cb, void *userdat
 	BMIter iter;
 	int tot = 0;
 	
+	if (hair_use_mirror_x(data->ob))
+		ED_strands_mirror_cache_begin(data->edit, 0, false, false, hair_use_mirror_topology(data->ob));
+	
 	BM_ITER_STRANDS(root, &iter, data->edit->bm, BM_STRANDS_OF_MESH) {
 		tot += hair_tool_apply_strand_edges(data, cb, userdata, root);
 	}
 	
+	/* apply mirror */
+	if (hair_use_mirror_x(data->ob))
+		ED_strands_mirror_cache_end(data->edit);
+	
 	return tot;
 }




More information about the Bf-blender-cvs mailing list