[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46063] trunk/blender: bmesh: new wireframe tool

Campbell Barton ideasman42 at gmail.com
Sun Apr 29 12:44:01 CEST 2012


Revision: 46063
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46063
Author:   campbellbarton
Date:     2012-04-29 10:44:00 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
bmesh: new wireframe tool

- makes wireframe from faces.
- options similar to inset (even offset, relative scale)
- copies face settings and loops (uvs, vcolors)
- optionally replaces the existing geometry.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/math_vector.c
    trunk/blender/source/blender/bmesh/CMakeLists.txt
    trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h
    trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
    trunk/blender/source/blender/bmesh/intern/bmesh_queries.h
    trunk/blender/source/blender/bmesh/operators/bmo_inset.c
    trunk/blender/source/blender/editors/mesh/editmesh_tools.c
    trunk/blender/source/blender/editors/mesh/mesh_intern.h
    trunk/blender/source/blender/editors/mesh/mesh_ops.c

Added Paths:
-----------
    trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d.py	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d.py	2012-04-29 10:44:00 UTC (rev 46063)
@@ -1767,6 +1767,7 @@
         layout.operator("mesh.inset")
         layout.operator("mesh.bevel")
         layout.operator("mesh.solidify")
+        layout.operator("mesh.wireframe")
         layout.operator("mesh.sort_faces")
 
         layout.separator()

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2012-04-29 10:44:00 UTC (rev 46063)
@@ -186,6 +186,7 @@
 float angle_v3v3(const float a[3], const float b[3]);
 float angle_v3v3v3(const float a[3], const float b[3], const float c[3]);
 float angle_normalized_v3v3(const float v1[3], const float v2[3]);
+float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]);
 void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3]);
 void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
 void angle_poly_v3(float* angles, const float* verts[3], int len);

Modified: trunk/blender/source/blender/blenlib/intern/math_vector.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector.c	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/blenlib/intern/math_vector.c	2012-04-29 10:44:00 UTC (rev 46063)
@@ -217,6 +217,25 @@
 		return 2.0f * (float)saasin(len_v2v2(v2, v1) / 2.0f);
 }
 
+/**
+ * angle between 2 vectors defined by 3 coords, about an axis. */
+float angle_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3])
+{
+	float v1_proj[3], v2_proj[3], tproj[3];
+
+	sub_v3_v3v3(v1_proj, v1, v2);
+	sub_v3_v3v3(v2_proj, v3, v2);
+
+	/* project the vectors onto the axis */
+	project_v3_v3v3(tproj, v1_proj, axis);
+	sub_v3_v3(v1_proj, tproj);
+
+	project_v3_v3v3(tproj, v2_proj, axis);
+	sub_v3_v3(v2_proj, tproj);
+
+	return angle_v3v3(v1_proj, v2_proj);
+}
+
 void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3])
 {
 	float ed1[3], ed2[3], ed3[3];

Modified: trunk/blender/source/blender/bmesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/bmesh/CMakeLists.txt	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/bmesh/CMakeLists.txt	2012-04-29 10:44:00 UTC (rev 46063)
@@ -51,6 +51,7 @@
 	operators/bmo_subdivide.h
 	operators/bmo_triangulate.c
 	operators/bmo_utils.c
+	operators/bmo_wireframe.c
 
 	intern/bmesh_construct.c
 	intern/bmesh_construct.h

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2012-04-29 10:44:00 UTC (rev 46063)
@@ -1109,6 +1109,25 @@
 };
 
 /*
+ * Wire Frame
+ *
+ * Makes a wire copy of faces.
+ */
+static BMOpDefine bmo_wireframe_def = {
+	"wireframe",
+	{{BMO_OP_SLOT_ELEMENT_BUF, "faces"},   /* input faces */
+	 {BMO_OP_SLOT_ELEMENT_BUF, "faceout"}, /* output faces */
+	 {BMO_OP_SLOT_BOOL, "use_boundary"},
+	 {BMO_OP_SLOT_BOOL, "use_even_offset"},
+	 {BMO_OP_SLOT_FLT, "thickness"},
+	 {BMO_OP_SLOT_BOOL, "use_relative_offset"},
+	 {BMO_OP_SLOT_FLT, "depth"},
+	 {0} /* null-terminating sentinel */},
+	bmo_wireframe_exec,
+	0
+};
+
+/*
  * Vertex Slide
  *
  * Translates vertes along an edge
@@ -1192,6 +1211,7 @@
 	&bmo_bridge_loops_def,
 	&bmo_solidify_def,
 	&bmo_inset_def,
+	&bmo_wireframe_def,
 	&bmo_vertex_slide_def,
 };
 

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h	2012-04-29 10:44:00 UTC (rev 46063)
@@ -100,5 +100,6 @@
 void bmo_bridge_loops_exec(BMesh *bm, BMOperator *op);
 void bmo_solidify_face_region_exec(BMesh *bm, BMOperator *op);
 void bmo_inset_exec(BMesh *bm, BMOperator *op);
+void bmo_wireframe_exec(BMesh *bm, BMOperator *op);
 
 #endif /* __BMESH_OPERATORS_PRIVATE_H__ */

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_queries.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_queries.c	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_queries.c	2012-04-29 10:44:00 UTC (rev 46063)
@@ -928,6 +928,28 @@
 }
 
 /**
+ * \note quite an obscure function.
+ * used in bmesh operators that have a relative scale options,
+ */
+float BM_vert_calc_mean_tagged_edge_length(BMVert *v)
+{
+	BMIter iter;
+	BMEdge *e;
+	int tot;
+	float length = 0.0f;
+
+	BM_ITER_ELEM_INDEX (e, &iter, v, BM_EDGES_OF_VERT, tot) {
+		BMVert *v_other = BM_edge_other_vert(e, v);
+		if (BM_elem_flag_test(v_other, BM_ELEM_TAG)) {
+			length += BM_edge_calc_length(e);
+		}
+	}
+
+	return length / (float)tot;
+}
+
+
+/**
  * Returns the edge existing between v1 and v2, or NULL if there isn't one.
  *
  * \note multiple edges may exist between any two vertices, and therefore

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_queries.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_queries.h	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_queries.h	2012-04-29 10:44:00 UTC (rev 46063)
@@ -65,6 +65,7 @@
 
 float   BM_vert_calc_edge_angle(BMVert *v);
 float   BM_vert_calc_shell_factor(BMVert *v);
+float   BM_vert_calc_mean_tagged_edge_length(BMVert *v);
 
 BMEdge *BM_edge_exists(BMVert *v1, BMVert *v2);
 

Modified: trunk/blender/source/blender/bmesh/operators/bmo_inset.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_inset.c	2012-04-29 10:15:04 UTC (rev 46062)
+++ trunk/blender/source/blender/bmesh/operators/bmo_inset.c	2012-04-29 10:44:00 UTC (rev 46063)
@@ -80,23 +80,6 @@
 	}
 }
 
-float bm_vert_avg_tag_dist(BMVert *v)
-{
-	BMIter iter;
-	BMEdge *e;
-	int tot;
-	float length = 0.0f;
-
-	BM_ITER_ELEM_INDEX (e, &iter, v, BM_EDGES_OF_VERT, tot) {
-		BMVert *v_other = BM_edge_other_vert(e, v);
-		if (BM_elem_flag_test(v_other, BM_ELEM_TAG)) {
-			length += BM_edge_calc_length(e);
-		}
-	}
-
-	return length / (float)tot;
-}
-
 /**
  * implementation is as follows...
  *
@@ -544,7 +527,7 @@
 		BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) {
 			if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
 				const float fac = (depth *
-				                   (use_relative_offset ? bm_vert_avg_tag_dist(v) : 1.0f) *
+				                   (use_relative_offset ? BM_vert_calc_mean_tagged_edge_length(v) : 1.0f) *
 				                   (use_even_boundry    ? BM_vert_calc_shell_factor(v) : 1.0f));
 				madd_v3_v3v3fl(varr_co[i], v->co, v->no, fac);
 			}

Added: trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c	                        (rev 0)
+++ trunk/blender/source/blender/bmesh/operators/bmo_wireframe.c	2012-04-29 10:44:00 UTC (rev 46063)
@@ -0,0 +1,371 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/operators/bmo_wireframe.c
+ *  \ingroup bmesh
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "bmesh.h"
+
+#include "intern/bmesh_operators_private.h" /* own include */
+
+BMLoop *bm_edge_tag_faceloop(BMEdge *e)
+{
+	BMLoop *l, *l_first;
+
+	l = l_first = e->l;
+	do {
+		if (BM_elem_flag_test(l->f, BM_ELEM_TAG)) {
+			return l;
+		}
+	} while ((l = l->radial_next) != l_first);
+
+	/* in the case this is used, we know this will never happen */
+	return NULL;
+}
+
+static void bm_vert_boundary_tangent(BMVert *v, float r_no[3], float r_no_face[3],
+                                     BMVert **r_va_other, BMVert **r_vb_other)
+{
+	BMIter iter;
+	BMEdge *e_iter;
+
+	BMEdge *e_a = NULL, *e_b = NULL;
+	BMVert *v_a, *v_b;
+
+	BMLoop *l_a, *l_b;
+
+	float no_face[3], no_edge[3];
+	float tvec_a[3], tvec_b[3];
+
+	/* get 2 boundary edges, there should only _be_ 2,
+	 * in case there are more - results wont be valid of course */
+	BM_ITER_ELEM (e_iter, &iter, v, BM_EDGES_OF_VERT) {
+		if (BM_elem_flag_test(e_iter, BM_ELEM_TAG)) {
+			if (e_a == NULL) {
+				e_a = e_iter;
+			}
+			else {
+				e_b = e_iter;
+				break;
+			}
+		}
+	}
+
+	l_a = bm_edge_tag_faceloop(e_a);
+	l_b = bm_edge_tag_faceloop(e_b);
+
+	/* average edge face normal */
+	add_v3_v3v3(no_face, l_a->f->no, l_b->f->no);
+
+	/* average edge direction */
+	v_a = BM_edge_other_vert(e_a, v);
+	v_b = BM_edge_other_vert(e_b, v);
+
+	sub_v3_v3v3(tvec_a, v->co, v_a->co);
+	sub_v3_v3v3(tvec_b, v_b->co, v->co);
+	normalize_v3(tvec_a);
+	normalize_v3(tvec_b);
+	add_v3_v3v3(no_edge, tvec_a, tvec_b); /* not unit length but this is ok */
+
+
+	/* find the normal */
+	cross_v3_v3v3(r_no, no_edge, no_face);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list