[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45454] trunk/blender: Added Vertex Slide: Slides a vertex along a selected and connected edge (Shift+Ctrl+V)
Francisco De La Cruz
dlcs.frank at gmail.com
Sat Apr 7 05:15:21 CEST 2012
Revision: 45454
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45454
Author: xercesblue
Date: 2012-04-07 03:15:20 +0000 (Sat, 07 Apr 2012)
Log Message:
-----------
Added Vertex Slide: Slides a vertex along a selected and connected edge (Shift+Ctrl+V)
-
BMop: "vertslide vert=%e edge=%hfev distance_t=%f"
Modified Paths:
--------------
trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
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/editors/mesh/CMakeLists.txt
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_slide.c
trunk/blender/source/blender/editors/mesh/editmesh_slide.c
Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d.py 2012-04-07 02:19:11 UTC (rev 45453)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d.py 2012-04-07 03:15:20 UTC (rev 45454)
@@ -1684,6 +1684,7 @@
layout.operator("mesh.split")
layout.operator("mesh.separate")
layout.operator("mesh.vert_connect")
+ layout.operator("mesh.vert_slide")
layout.separator()
Modified: trunk/blender/source/blender/bmesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/bmesh/CMakeLists.txt 2012-04-07 02:19:11 UTC (rev 45453)
+++ trunk/blender/source/blender/bmesh/CMakeLists.txt 2012-04-07 03:15:20 UTC (rev 45454)
@@ -36,6 +36,7 @@
set(SRC
operators/bmo_bevel.c
operators/bmo_connect.c
+ operators/bmo_slide.c
operators/bmo_create.c
operators/bmo_dissolve.c
operators/bmo_dupe.c
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2012-04-07 02:19:11 UTC (rev 45453)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_opdefines.c 2012-04-07 03:15:20 UTC (rev 45454)
@@ -1103,6 +1103,23 @@
0
};
+/*
+ * Vertex Slide
+ *
+ * Translates vertes along an edge
+ */
+static BMOpDefine bmo_vert_slide_def = {
+"vertslide",
+ {{BMO_OP_SLOT_ELEMENT_BUF, "vert"},
+ {BMO_OP_SLOT_ELEMENT_BUF, "edge"},
+ {BMO_OP_SLOT_ELEMENT_BUF, "vertout"},
+ {BMO_OP_SLOT_FLT, "distance_t"},
+ {0} /* null-terminating sentinel */},
+ bmo_vert_slide_exec,
+ BMO_OP_FLAG_UNTAN_MULTIRES
+};
+
+
BMOpDefine *opdefines[] = {
&bmo_split_def,
&bmo_spin_def,
@@ -1170,6 +1187,7 @@
&bmo_bridge_loops_def,
&bmo_solidify_def,
&bmo_inset_def,
+ &bmo_vert_slide_def,
};
int bmesh_total_ops = (sizeof(opdefines) / sizeof(void *));
Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h 2012-04-07 02:19:11 UTC (rev 45453)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators_private.h 2012-04-07 03:15:20 UTC (rev 45454)
@@ -43,6 +43,7 @@
void bmo_dissolve_verts_exec(BMesh *bmesh, BMOperator *op);
void bmo_dissolve_limit_exec(BMesh *bmesh, BMOperator *op);
void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op);
+void bmo_vert_slide_exec(BMesh *bm, BMOperator *op);
void bmo_connectverts_exec(BMesh *bm, BMOperator *op);
void bmo_extrude_vert_indiv_exec(BMesh *bm, BMOperator *op);
void bmo_mesh_to_bmesh_exec(BMesh *bm, BMOperator *op);
Added: trunk/blender/source/blender/bmesh/operators/bmo_slide.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_slide.c (rev 0)
+++ trunk/blender/source/blender/bmesh/operators/bmo_slide.c 2012-04-07 03:15:20 UTC (rev 45454)
@@ -0,0 +1,122 @@
+/*
+ * ***** 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): Francisco De La Cruz
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/operators/bmo_slide.c
+* \ingroup bmesh
+*/
+
+#include "MEM_guardedalloc.h"
+
+#include "BKE_global.h"
+
+#include "BLI_math.h"
+#include "BLI_array.h"
+#include "BLI_utildefines.h"
+
+#include "bmesh.h"
+
+#include "intern/bmesh_operators_private.h" /* own include */
+
+#define EDGE_MARK 1
+#define VERT_MARK 2
+
+/*
+ * Slides a vertex along a connected edge
+ *
+ */
+void bmo_vert_slide_exec(BMesh *bm, BMOperator *op)
+{
+ BMOIter oiter;
+ BMIter iter;
+ BMHeader *h;
+ BMVert *vertex;
+ BMEdge *edge;
+ int is_start_v1 = 0;
+
+ /* Selection counts */
+ int selected_verts = 0;
+ int selected_edges = 0;
+
+ /* Get slide amount */
+ const float distance_t = BMO_slot_float_get(op, "distance_t");
+
+ /* Get start vertex */
+ vertex = BMO_iter_new(&oiter, bm, op, "vert", BM_VERT);
+
+
+ if (!vertex) {
+ if (G.debug & G_DEBUG)
+ fprintf(stderr, "vertslide: No vertex selected...");
+ return;
+ }
+
+ /* Count selected edges */
+ BMO_ITER(h, &oiter, bm, op, "edge", BM_VERT | BM_EDGE) {
+ switch (h->htype) {
+ case BM_VERT:
+ selected_verts++;
+ break;
+ case BM_EDGE:
+ selected_edges++;
+ /* Mark all selected edges (cast BMHeader->BMEdge) */
+ BMO_elem_flag_enable(bm, (BMElemF *)h, EDGE_MARK);
+ break;
+ }
+ }
+
+ /* Only allow sliding between two verts */
+
+ if (selected_verts != 2 || selected_edges == 0) {
+ if (G.debug & G_DEBUG)
+ fprintf(stderr, "vertslide: select a single edge\n");
+ return;
+ }
+
+ /* Make sure we get the correct edge. */
+ BM_ITER(edge, &iter, bm, BM_EDGES_OF_VERT, vertex) {
+ if (BMO_elem_flag_test(bm, edge, EDGE_MARK)) {
+ is_start_v1 = (edge->v1 == vertex);
+ break;
+ }
+ }
+
+ /* Found edge */
+ if (edge) {
+ BMVert *other = BM_edge_other_vert(edge, vertex);
+
+ /* mark */
+ BMO_elem_flag_enable(bm, vertex, VERT_MARK);
+
+ /* Interpolate */
+ interp_v3_v3v3(vertex->co, vertex->co, other->co, distance_t);
+ }
+
+ /* Deselect the edges */
+ BMO_slot_buffer_hflag_disable(bm, op, "edge", BM_ALL, BM_ELEM_SELECT, TRUE);
+
+ /* Return the new edge. The same previously marked with VERT_MARK */
+ BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK);
+ return;
+}
+
+#undef EDGE_MARK
+#undef VERT_MARK
Modified: trunk/blender/source/blender/editors/mesh/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/mesh/CMakeLists.txt 2012-04-07 02:19:11 UTC (rev 45453)
+++ trunk/blender/source/blender/editors/mesh/CMakeLists.txt 2012-04-07 03:15:20 UTC (rev 45454)
@@ -46,6 +46,7 @@
editmesh_select.c
editmesh_tools.c
editmesh_utils.c
+ editmesh_slide.c
mesh_data.c
mesh_ops.c
meshtools.c
Added: trunk/blender/source/blender/editors/mesh/editmesh_slide.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_slide.c (rev 0)
+++ trunk/blender/source/blender/editors/mesh/editmesh_slide.c 2012-04-07 03:15:20 UTC (rev 45454)
@@ -0,0 +1,695 @@
+/*
+ * ***** 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): Francisco De La Cruz
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/* Takes heavily from editmesh_loopcut.c */
+
+#include <float.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+
+#include "DNA_object_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_space_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_array.h"
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_blender.h"
+#include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mesh.h"
+#include "BKE_report.h"
+#include "BKE_tessmesh.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_mesh.h"
+#include "ED_space_api.h"
+
+#include "UI_resources.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "mesh_intern.h"
+
+#define VTX_SLIDE_SLIDE_SENS_F 15.0f
+#define VTX_SLIDE_SNAP_THRSH 0.3f
+
+/* Cusom VertexSlide Operator data */
+typedef struct VertexSlideOp {
+ /* Starting Vertex */
+ BMVert *start_vtx;
+ BMEdge *sel_edge;
+
+ ViewContext *view_context;
+ ARegion *active_region;
+
+ /* Draw callback handle */
+ void *draw_handle;
+
+ /* Active Object */
+ Object *obj;
+
+ /* Are we in slide mode */
+ int slide_mode;
+ int snap_n_weld;
+ int snap_to_end_vtx;
+ int snap_to_mid;
+
+ float distance;
+ float interp[3];
+
+ /* Edge Frame Count */
+ int disk_edges;
+
+ /* Edges */
+ BMEdge** edge_frame;
+
+ /* Slide Frame Endpoints */
+ float (*vtx_frame)[3];
+
+ /* Mouse Click 2d pos */
+ int m_co[2];
+
+} VertexSlideOp;
+
+static void vtx_slide_draw(const bContext *C, ARegion *ar, void *arg);
+static int edbm_vert_slide_exec(bContext *C, wmOperator *op);
+static void vtx_slide_exit(const bContext *C, wmOperator *op);
+static void vtx_slide_set_frame(VertexSlideOp *vso);
+
+static int vtx_slide_init(bContext *C, wmOperator *op)
+{
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BMEdit_FromObject(obedit);
+ BMEditSelection *ese = em->bm->selected.first;
+
+ /* Custom data */
+ VertexSlideOp *vso;
+
+ const char *header_str = "Vertex Slide: Hover over an edge and left-click to select slide edge. "
+ "Left-Shift: Midpoint Snap, Left-Alt: Snap, Left-Ctrl: Snap&Weld";
+
+ if (!obedit) {
+ BKE_report(op->reports, RPT_ERROR, "Vertex Slide Error: Not object in context");
+ return FALSE;
+ }
+
+ EDBM_selectmode_flush(em);
+ ese = em->bm->selected.first;
+
+ /* Is there a starting vertex ? */
+ if (ese == NULL || ese->htype != BM_VERT) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list