| 
									
										
										
										
											2011-10-24 23:32:24 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  |  * ***** 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, | 
					
						
							| 
									
										
										
										
											2012-02-11 04:16:17 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2004 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): none yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 00:20:36 +00:00
										 |  |  | /** \file blender/editors/mesh/editmesh_select.c
 | 
					
						
							|  |  |  |  *  \ingroup edmesh | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | #include "BLI_listbase.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-04 01:23:51 +00:00
										 |  |  | #include "BLI_linklist.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-17 05:33:55 +00:00
										 |  |  | #include "BLI_linklist_stack.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | #include "BLI_rand.h"
 | 
					
						
							| 
									
										
										
										
											2009-09-17 23:05:33 +00:00
										 |  |  | #include "BLI_array.h"
 | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | #include "BLI_smallhash.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_displist.h"
 | 
					
						
							|  |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | #include "BKE_paint.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-13 20:31:52 +00:00
										 |  |  | #include "BKE_editmesh.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "IMB_imbuf_types.h"
 | 
					
						
							|  |  |  | #include "IMB_imbuf.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_mesh.h"
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | #include "ED_view3d.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BIF_gl.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 17:13:09 +00:00
										 |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-13 06:44:43 +00:00
										 |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-28 17:13:09 +00:00
										 |  |  | #include "DNA_object_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-16 17:12:39 +00:00
										 |  |  | #include "GPU_extensions.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | #include "UI_resources.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | #include "mesh_intern.h"  /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | /* use bmesh operator flags for a few operators */ | 
					
						
							|  |  |  | #define BMO_ELE_TAG 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | /* ****************************** MIRROR **************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 05:58:51 +00:00
										 |  |  | void EDBM_select_mirrored(BMEditMesh *em, bool extend, | 
					
						
							|  |  |  |                           int *r_totmirr, int *r_totfail) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-28 17:13:09 +00:00
										 |  |  | 	Mesh *me = (Mesh *)em->ob->data; | 
					
						
							| 
									
										
										
										
											2013-07-01 21:56:59 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2013-06-05 05:58:51 +00:00
										 |  |  | 	int totmirr = 0; | 
					
						
							|  |  |  | 	int totfail = 0; | 
					
						
							| 
									
										
										
										
											2013-06-28 17:13:09 +00:00
										 |  |  | 	bool use_topology = (me && (me->editflag & ME_EDIT_MIRROR_TOPO)); | 
					
						
							| 
									
										
										
										
											2013-06-05 05:58:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	*r_totmirr = *r_totfail = 0; | 
					
						
							| 
									
										
										
										
											2011-05-10 23:48:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 21:56:59 +00:00
										 |  |  | 	/* select -> tag */ | 
					
						
							|  |  |  | 	if (bm->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							|  |  |  | 		BMVert *v; | 
					
						
							|  |  |  | 		BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 			BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-07-01 21:56:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							|  |  |  | 		BMEdge *e; | 
					
						
							|  |  |  | 		BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { | 
					
						
							|  |  |  | 			BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		BMFace *f; | 
					
						
							|  |  |  | 		BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 			BM_elem_flag_set(f, BM_ELEM_TAG, BM_elem_flag_test(f, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 17:13:09 +00:00
										 |  |  | 	EDBM_verts_mirror_cache_begin(em, 0, true, true, use_topology); | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!extend) | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 21:56:59 +00:00
										 |  |  | 	if (bm->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							|  |  |  | 		BMVert *v; | 
					
						
							|  |  |  | 		BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 			if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN) && BM_elem_flag_test(v, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 				BMVert *v_mirr = EDBM_verts_mirror_get(em, v); | 
					
						
							|  |  |  | 				if (v_mirr && !BM_elem_flag_test(v_mirr, BM_ELEM_HIDDEN)) { | 
					
						
							|  |  |  | 					BM_vert_select_set(bm, v_mirr, true); | 
					
						
							|  |  |  | 					totmirr++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					totfail++; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-06-05 05:58:51 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-07-01 21:56:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							|  |  |  | 		BMEdge *e; | 
					
						
							|  |  |  | 		BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { | 
					
						
							|  |  |  | 			if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && BM_elem_flag_test(e, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 				BMEdge *e_mirr = EDBM_verts_mirror_get_edge(em, e); | 
					
						
							|  |  |  | 				if (e_mirr && !BM_elem_flag_test(e_mirr, BM_ELEM_HIDDEN)) { | 
					
						
							|  |  |  | 					BM_edge_select_set(bm, e_mirr, true); | 
					
						
							|  |  |  | 					totmirr++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					totfail++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		BMFace *f; | 
					
						
							|  |  |  | 		BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 			if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN) && BM_elem_flag_test(f, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 				BMFace *f_mirr = EDBM_verts_mirror_get_face(em, f); | 
					
						
							|  |  |  | 				if (f_mirr && !BM_elem_flag_test(f_mirr, BM_ELEM_HIDDEN)) { | 
					
						
							|  |  |  | 					BM_face_select_set(bm, f_mirr, true); | 
					
						
							|  |  |  | 					totmirr++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					totfail++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_verts_mirror_cache_end(em); | 
					
						
							| 
									
										
										
										
											2013-06-05 05:58:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	*r_totmirr = totmirr; | 
					
						
							|  |  |  | 	*r_totfail = totfail; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-16 05:13:12 +00:00
										 |  |  | void EDBM_automerge(Scene *scene, Object *obedit, bool update, const char hflag) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-16 05:13:12 +00:00
										 |  |  | 	int ok; | 
					
						
							|  |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2012-12-13 00:41:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-16 05:13:12 +00:00
										 |  |  | 	ok = BMO_op_callf(em->bm, BMO_FLAG_DEFAULTS, | 
					
						
							|  |  |  | 	                  "automerge verts=%hv dist=%f", | 
					
						
							|  |  |  | 	                  hflag, scene->toolsettings->doublimit); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-16 05:13:12 +00:00
										 |  |  | 	if (LIKELY(ok) && update) { | 
					
						
							|  |  |  | 		EDBM_update_generic(em, true, true); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ****************************** SELECTION ROUTINES **************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | unsigned int bm_solidoffs = 0, bm_wireoffs = 0, bm_vertoffs = 0;    /* set in drawobject.c ... for colorindices */ | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* facilities for border select and circle select */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | static char *selbuf = NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* opengl doesn't support concave... */ | 
					
						
							| 
									
										
										
										
											2012-10-05 15:44:11 +00:00
										 |  |  | static void draw_triangulated(const int mcords[][2], const short tot) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ListBase lb = {NULL, NULL}; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	DispList *dl; | 
					
						
							|  |  |  | 	float *fp; | 
					
						
							|  |  |  | 	int a; | 
					
						
							| 
									
										
										
										
											2013-04-26 21:04:12 +00:00
										 |  |  | 	const float z_up[3] = {0.0f, 0.0f, 1.0f}; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* make displist */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	dl = MEM_callocN(sizeof(DispList), "poly disp"); | 
					
						
							|  |  |  | 	dl->type = DL_POLY; | 
					
						
							|  |  |  | 	dl->parts = 1; | 
					
						
							|  |  |  | 	dl->nr = tot; | 
					
						
							|  |  |  | 	dl->verts = fp = MEM_callocN(tot * 3 * sizeof(float), "poly verts"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	BLI_addtail(&lb, dl); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (a = 0; a < tot; a++, fp += 3) { | 
					
						
							|  |  |  | 		fp[0] = (float)mcords[a][0]; | 
					
						
							|  |  |  | 		fp[1] = (float)mcords[a][1]; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* do the fill */ | 
					
						
							| 
									
										
										
										
											2013-04-26 21:04:12 +00:00
										 |  |  | 	BKE_displist_fill(&lb, &lb, z_up, false); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* do the draw */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	dl = lb.first;  /* filldisplist adds in head of list */ | 
					
						
							|  |  |  | 	if (dl->type == DL_INDEX3) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		int *index; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		a = dl->parts; | 
					
						
							|  |  |  | 		fp = dl->verts; | 
					
						
							|  |  |  | 		index = dl->index; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		glBegin(GL_TRIANGLES); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		while (a--) { | 
					
						
							|  |  |  | 			glVertex3fv(fp + 3 * index[0]); | 
					
						
							|  |  |  | 			glVertex3fv(fp + 3 * index[1]); | 
					
						
							|  |  |  | 			glVertex3fv(fp + 3 * index[2]); | 
					
						
							|  |  |  | 			index += 3; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		glEnd(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-05-07 06:58:03 +00:00
										 |  |  | 	BKE_displist_free(&lb); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* reads rect, and builds selection array for quick lookup */ | 
					
						
							|  |  |  | /* returns if all is OK */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | bool EDBM_backbuf_border_init(ViewContext *vc, short xmin, short ymin, short xmax, short ymax) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ImBuf *buf; | 
					
						
							|  |  |  | 	unsigned int *dr; | 
					
						
							|  |  |  | 	int a; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->obedit == NULL || vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	buf = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (buf == NULL) return false; | 
					
						
							|  |  |  | 	if (bm_vertoffs == 0) return false; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dr = buf->rect; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* build selection lookup */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	a = (xmax - xmin + 1) * (ymax - ymin + 1); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	while (a--) { | 
					
						
							|  |  |  | 		if (*dr > 0 && *dr <= bm_vertoffs) | 
					
						
							|  |  |  | 			selbuf[*dr] = 1; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		dr++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	IMB_freeImBuf(buf); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | int EDBM_backbuf_check(unsigned int index) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-03 07:02:52 +00:00
										 |  |  | 	/* odd logic, if selbuf is NULL we assume no zbuf-selection is enabled
 | 
					
						
							|  |  |  | 	 * and just ignore the depth buffer, this is error prone since its possible | 
					
						
							|  |  |  | 	 * code doesn't set the depth buffer by accident, but leave for now. - Campbell */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (selbuf == NULL) return 1; | 
					
						
							| 
									
										
										
										
											2013-10-03 07:02:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (index > 0 && index <= bm_vertoffs) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		return selbuf[index]; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | void EDBM_backbuf_free(void) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (selbuf) MEM_freeN(selbuf); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	selbuf = NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* mcords is a polygon mask
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  |  * - grab backbuffer, | 
					
						
							|  |  |  |  * - draw with black in backbuffer,  | 
					
						
							|  |  |  |  * - grab again and compare | 
					
						
							|  |  |  |  * returns 'OK'  | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | bool EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short tot, short xmin, short ymin, short xmax, short ymax) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned int *dr, *drm; | 
					
						
							|  |  |  | 	struct ImBuf *buf, *bufmask; | 
					
						
							|  |  |  | 	int a; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* method in use for face selecting too */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->obedit == NULL) { | 
					
						
							| 
									
										
										
										
											2012-03-10 22:00:55 +00:00
										 |  |  | 		if (!(paint_facesel_test(vc->obact) || paint_vertsel_test(vc->obact))) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2012-03-10 22:00:55 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	else if (vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	buf = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (buf == NULL) return false; | 
					
						
							|  |  |  | 	if (bm_vertoffs == 0) return false; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dr = buf->rect; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-16 17:12:39 +00:00
										 |  |  | 	if (vc->rv3d->gpuoffscreen) | 
					
						
							|  |  |  | 		GPU_offscreen_bind(vc->rv3d->gpuoffscreen); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	/* draw the mask */ | 
					
						
							|  |  |  | 	glDisable(GL_DEPTH_TEST); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	glColor3ub(0, 0, 0); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* yah, opengl doesn't do concave... tsk! */ | 
					
						
							|  |  |  | 	ED_region_pixelspace(vc->ar); | 
					
						
							| 
									
										
										
										
											2012-02-25 16:04:03 +00:00
										 |  |  | 	draw_triangulated(mcords, tot); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	glBegin(GL_LINE_LOOP);  /* for zero sized masks, lines */ | 
					
						
							|  |  |  | 	for (a = 0; a < tot; a++) { | 
					
						
							|  |  |  | 		glVertex2iv(mcords[a]); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	glEnd(); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	glFinish(); /* to be sure readpixels sees mask */ | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-03-16 17:12:39 +00:00
										 |  |  | 	if (vc->rv3d->gpuoffscreen) | 
					
						
							|  |  |  | 		GPU_offscreen_unbind(vc->rv3d->gpuoffscreen); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	/* grab mask */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); | 
					
						
							| 
									
										
										
										
											2012-09-11 02:18:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (bufmask == NULL) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		return false;  /* only when mem alloc fails, go crash somewhere else! */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-09-11 02:18:27 +00:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		drm = bufmask->rect; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	/* build selection lookup */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	a = (xmax - xmin + 1) * (ymax - ymin + 1); | 
					
						
							|  |  |  | 	while (a--) { | 
					
						
							|  |  |  | 		if (*dr > 0 && *dr <= bm_vertoffs && *drm == 0) selbuf[*dr] = 1; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		dr++; drm++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	IMB_freeImBuf(buf); | 
					
						
							|  |  |  | 	IMB_freeImBuf(bufmask); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* circle shaped sample area */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | bool EDBM_backbuf_circle_init(ViewContext *vc, short xs, short ys, short rads) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ImBuf *buf; | 
					
						
							|  |  |  | 	unsigned int *dr; | 
					
						
							|  |  |  | 	short xmin, ymin, xmax, ymax, xc, yc; | 
					
						
							|  |  |  | 	int radsq; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* method in use for face selecting too */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->obedit == NULL) { | 
					
						
							| 
									
										
										
										
											2012-03-10 22:00:55 +00:00
										 |  |  | 		if (!(paint_facesel_test(vc->obact) || paint_vertsel_test(vc->obact))) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2012-03-10 22:00:55 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-03-09 03:46:30 +00:00
										 |  |  | 	else if (vc->v3d->drawtype < OB_SOLID || (vc->v3d->flag & V3D_ZBUF_SELECT) == 0) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2013-03-09 03:46:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	xmin = xs - rads; xmax = xs + rads; | 
					
						
							|  |  |  | 	ymin = ys - rads; ymax = ys + rads; | 
					
						
							|  |  |  | 	buf = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (bm_vertoffs == 0) return false; | 
					
						
							|  |  |  | 	if (buf == NULL) return false; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dr = buf->rect; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* build selection lookup */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); | 
					
						
							|  |  |  | 	radsq = rads * rads; | 
					
						
							|  |  |  | 	for (yc = -rads; yc <= rads; yc++) { | 
					
						
							|  |  |  | 		for (xc = -rads; xc <= rads; xc++, dr++) { | 
					
						
							|  |  |  | 			if (xc * xc + yc * yc < radsq) { | 
					
						
							|  |  |  | 				if (*dr > 0 && *dr <= bm_vertoffs) selbuf[*dr] = 1; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	IMB_freeImBuf(buf); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | static void findnearestvert__doClosest(void *userData, BMVert *eve, const float screen_co[2], int index) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	struct { float mval_fl[2], pass, select, strict; float dist, lastIndex, closestIndex; BMVert *closest; } *data = userData; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (data->pass == 0) { | 
					
						
							|  |  |  | 		if (index <= data->lastIndex) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (index > data->lastIndex) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (data->dist > 3) { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		float dist_test = len_manhattan_v2v2(data->mval_fl, screen_co); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(eve, BM_ELEM_SELECT) == data->select) { | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 			if (data->strict == 1) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 				dist_test += 5; | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		if (dist_test < data->dist) { | 
					
						
							|  |  |  | 			data->dist = dist_test; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data->closest = eve; | 
					
						
							|  |  |  | 			data->closestIndex = index; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | static bool findnearestvert__backbufIndextest(void *handle, unsigned int index) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	BMEditMesh *em = (BMEditMesh *)handle; | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMVert *eve = BM_vert_at_index(em->bm, index - 1); | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | 	return !(eve && BM_elem_flag_test(eve, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * findnearestvert | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * dist (in/out): minimal distance to the nearest and at the end, actual distance | 
					
						
							|  |  |  |  * sel: selection bias | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  |  *      if SELECT, selected vertice are given a 5 pixel bias to make them further than unselect verts | 
					
						
							|  |  |  |  *      if 0, unselected vertice are given the bias | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  |  * strict: if 1, the vertice corresponding to the sel parameter are ignored and not just biased  | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | BMVert *EDBM_vert_find_nearest(ViewContext *vc, float *r_dist, const bool sel, const bool strict) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		float distance; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		unsigned int index; | 
					
						
							|  |  |  | 		BMVert *eve; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (strict) { | 
					
						
							|  |  |  | 			index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, | 
					
						
							|  |  |  | 			                                   strict, vc->em, findnearestvert__backbufIndextest); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_wireoffs, 0xFFFFFF, &distance, | 
					
						
							|  |  |  | 			                                   0, NULL, NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2013-07-20 15:07:57 +00:00
										 |  |  | 		eve = index ? BM_vert_at_index(vc->em->bm, index - 1) : NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		if (eve && distance < *r_dist) { | 
					
						
							|  |  |  | 			*r_dist = distance; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return eve; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		struct { float mval_fl[2], pass, select, strict; float dist, lastIndex, closestIndex; BMVert *closest; } data; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		static int lastSelectedIndex = 0; | 
					
						
							|  |  |  | 		static BMVert *lastSelected = NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (lastSelected && BM_vert_at_index(vc->em->bm, lastSelectedIndex) != lastSelected) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			lastSelectedIndex = 0; | 
					
						
							|  |  |  | 			lastSelected = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		data.lastIndex = lastSelectedIndex; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		data.mval_fl[0] = vc->mval[0]; | 
					
						
							|  |  |  | 		data.mval_fl[1] = vc->mval[1]; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		data.select = sel ? BM_ELEM_SELECT : 0; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		data.dist = *r_dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		data.strict = strict; | 
					
						
							|  |  |  | 		data.closest = NULL; | 
					
						
							|  |  |  | 		data.closestIndex = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		data.pass = 0; | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 04:03:22 +00:00
										 |  |  | 		mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (data.dist > 3) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data.pass = 1; | 
					
						
							| 
									
										
										
										
											2012-10-10 04:03:22 +00:00
										 |  |  | 			mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		*r_dist = data.dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		lastSelected = data.closest; | 
					
						
							|  |  |  | 		lastSelectedIndex = data.closestIndex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return data.closest; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* note; uses v3d, so needs active 3d window */ | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | static void findnearestedge__doClosest(void *userData, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int UNUSED(index)) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	struct { ViewContext vc; float mval_fl[2]; float dist; BMEdge *closest; } *data = userData; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	int distance; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	distance = dist_to_line_segment_v2(data->mval_fl, screen_co_a, screen_co_b); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		distance += 5; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (distance < data->dist) { | 
					
						
							|  |  |  | 		if (data->vc.rv3d->rflag & RV3D_CLIPPING) { | 
					
						
							| 
									
										
										
										
											2012-12-11 14:18:37 +00:00
										 |  |  | 			float lambda = line_point_factor_v2(data->mval_fl, screen_co_a, screen_co_b); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			float vec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:18:37 +00:00
										 |  |  | 			vec[0] = eed->v1->co[0] + lambda * (eed->v2->co[0] - eed->v1->co[0]); | 
					
						
							|  |  |  | 			vec[1] = eed->v1->co[1] + lambda * (eed->v2->co[1] - eed->v1->co[1]); | 
					
						
							|  |  |  | 			vec[2] = eed->v1->co[2] + lambda * (eed->v2->co[2] - eed->v1->co[2]); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			if (ED_view3d_clipping_test(data->vc.rv3d, vec, true) == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				data->dist = distance; | 
					
						
							|  |  |  | 				data->closest = eed; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			data->dist = distance; | 
					
						
							|  |  |  | 			data->closest = eed; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | BMEdge *EDBM_edge_find_nearest(ViewContext *vc, float *r_dist) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		float distance; | 
					
						
							| 
									
										
										
										
											2009-11-09 22:47:55 +00:00
										 |  |  | 		unsigned int index; | 
					
						
							|  |  |  | 		BMEdge *eed; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		view3d_validate_backbuf(vc); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 		index = view3d_sample_backbuf_rect(vc, vc->mval, 50, bm_solidoffs, bm_wireoffs, &distance, 0, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2013-07-20 15:07:57 +00:00
										 |  |  | 		eed = index ? BM_edge_at_index(vc->em->bm, index - 1) : NULL; | 
					
						
							| 
									
										
										
										
											2009-11-09 22:47:55 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		if (eed && distance < *r_dist) { | 
					
						
							|  |  |  | 			*r_dist = distance; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return eed; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		struct { ViewContext vc; float mval_fl[2]; float dist; BMEdge *closest; } data; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		data.vc = *vc; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		data.mval_fl[0] = vc->mval[0]; | 
					
						
							|  |  |  | 		data.mval_fl[1] = vc->mval[1]; | 
					
						
							|  |  |  | 		data.dist = *r_dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		data.closest = NULL; | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 		ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 04:03:22 +00:00
										 |  |  | 		mesh_foreachScreenEdge(vc, findnearestedge__doClosest, &data, V3D_PROJ_TEST_CLIP_WIN); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		*r_dist = data.dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		return data.closest; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | static void findnearestface__getDistance(void *userData, BMFace *efa, const float screen_co[2], int UNUSED(index)) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	struct { float mval_fl[2]; float dist; BMFace *toFace; } *data = userData; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (efa == data->toFace) { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		const float dist_test = len_manhattan_v2v2(data->mval_fl, screen_co); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		if (dist_test < data->dist) { | 
					
						
							|  |  |  | 			data->dist = dist_test; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | static void findnearestface__doClosest(void *userData, BMFace *efa, const float screen_co[2], int index) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	struct { float mval_fl[2], pass; float dist, lastIndex, closestIndex; BMFace *closest; } *data = userData; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (data->pass == 0) { | 
					
						
							|  |  |  | 		if (index <= data->lastIndex) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (index > data->lastIndex) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (data->dist > 3) { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		const float dist_test = len_manhattan_v2v2(data->mval_fl, screen_co); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		if (dist_test < data->dist) { | 
					
						
							|  |  |  | 			data->dist = dist_test; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data->closest = efa; | 
					
						
							|  |  |  | 			data->closestIndex = index; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | BMFace *EDBM_face_find_nearest(ViewContext *vc, float *r_dist) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { | 
					
						
							| 
									
										
										
										
											2010-09-25 01:54:58 +00:00
										 |  |  | 		unsigned int index; | 
					
						
							|  |  |  | 		BMFace *efa; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		view3d_validate_backbuf(vc); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-25 01:54:58 +00:00
										 |  |  | 		index = view3d_sample_backbuf(vc, vc->mval[0], vc->mval[1]); | 
					
						
							| 
									
										
										
										
											2013-07-20 15:07:57 +00:00
										 |  |  | 		efa = index ? BM_face_at_index(vc->em->bm, index - 1) : NULL; | 
					
						
							| 
									
										
										
										
											2010-09-25 01:54:58 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		if (efa) { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 			struct { float mval_fl[2]; float dist; BMFace *toFace; } data; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 			data.mval_fl[0] = vc->mval[0]; | 
					
						
							|  |  |  | 			data.mval_fl[1] = vc->mval[1]; | 
					
						
							| 
									
										
										
										
											2012-12-11 14:21:52 +00:00
										 |  |  | 			data.dist = FLT_MAX; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data.toFace = efa; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 13:00:52 +00:00
										 |  |  | 			ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 04:03:22 +00:00
										 |  |  | 			mesh_foreachScreenFace(vc, findnearestface__getDistance, &data, V3D_PROJ_TEST_CLIP_DEFAULT); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 			if ((vc->em->selectmode == SCE_SELECT_FACE) || (data.dist < *r_dist)) {  /* only faces, no dist check */ | 
					
						
							|  |  |  | 				*r_dist = data.dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				return efa; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		struct { float mval_fl[2], pass; float dist, lastIndex, closestIndex; BMFace *closest; } data; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		static int lastSelectedIndex = 0; | 
					
						
							|  |  |  | 		static BMFace *lastSelected = NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (lastSelected && BM_face_at_index(vc->em->bm, lastSelectedIndex) != lastSelected) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			lastSelectedIndex = 0; | 
					
						
							|  |  |  | 			lastSelected = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		data.lastIndex = lastSelectedIndex; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		data.mval_fl[0] = vc->mval[0]; | 
					
						
							|  |  |  | 		data.mval_fl[1] = vc->mval[1]; | 
					
						
							|  |  |  | 		data.dist = *r_dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		data.closest = NULL; | 
					
						
							|  |  |  | 		data.closestIndex = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		data.pass = 0; | 
					
						
							| 
									
										
										
										
											2013-05-08 13:00:52 +00:00
										 |  |  | 		ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d); | 
					
						
							| 
									
										
										
										
											2012-10-10 04:03:22 +00:00
										 |  |  | 		mesh_foreachScreenFace(vc, findnearestface__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		if (data.dist > 3.0f) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data.pass = 1; | 
					
						
							| 
									
										
										
										
											2012-10-10 04:03:22 +00:00
										 |  |  | 			mesh_foreachScreenFace(vc, findnearestface__doClosest, &data, V3D_PROJ_TEST_CLIP_DEFAULT); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 		*r_dist = data.dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		lastSelected = data.closest; | 
					
						
							|  |  |  | 		lastSelectedIndex = data.closestIndex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return data.closest; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* best distance based on screen coords. 
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  |  * use em->selectmode to define how to use  | 
					
						
							|  |  |  |  * selected vertices and edges get disadvantage | 
					
						
							|  |  |  |  * return 1 if found one | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | static int unified_findnearest(ViewContext *vc, BMVert **r_eve, BMEdge **r_eed, BMFace **r_efa) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	BMEditMesh *em = vc->em; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	float dist = 75.0f; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	*r_eve = NULL; | 
					
						
							|  |  |  | 	*r_eed = NULL; | 
					
						
							|  |  |  | 	*r_efa = NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* no afterqueue (yet), so we check it now, otherwise the em_xxxofs indices are bad */ | 
					
						
							|  |  |  | 	view3d_validate_backbuf(vc); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		*r_eve = EDBM_vert_find_nearest(vc, &dist, BM_ELEM_SELECT, 0); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_FACE) | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		*r_efa = EDBM_face_find_nearest(vc, &dist); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	dist -= 20; /* since edges select lines, we give dots advantage of 20 pix */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_EDGE) | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		*r_eed = EDBM_edge_find_nearest(vc, &dist); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* return only one of 3 pointers, for frontbuffer redraws */ | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	if (*r_eed) { | 
					
						
							|  |  |  | 		*r_efa = NULL; *r_eve = NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	else if (*r_efa) { | 
					
						
							|  |  |  | 		*r_eve = NULL; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	return (*r_eve || *r_eed || *r_efa); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ****************  SIMILAR "group" SELECTS. FACE, EDGE AND VERTEX ************** */ | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | static EnumPropertyItem prop_similar_compare_types[] = { | 
					
						
							|  |  |  | 	{SIM_CMP_EQ, "EQUAL", 0, "Equal", ""}, | 
					
						
							|  |  |  | 	{SIM_CMP_GT, "GREATER", 0, "Greater", ""}, | 
					
						
							| 
									
										
										
										
											2012-11-01 04:27:59 +00:00
										 |  |  | 	{SIM_CMP_LT, "LESS", 0, "Less", ""}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL} | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | static EnumPropertyItem prop_similar_types[] = { | 
					
						
							|  |  |  | 	{SIMVERT_NORMAL, "NORMAL", 0, "Normal", ""}, | 
					
						
							|  |  |  | 	{SIMVERT_FACE, "FACE", 0, "Amount of Adjacent Faces", ""}, | 
					
						
							|  |  |  | 	{SIMVERT_VGROUP, "VGROUP", 0, "Vertex Groups", ""}, | 
					
						
							| 
									
										
										
										
											2012-06-15 01:43:01 +00:00
										 |  |  | 	{SIMVERT_EDGE, "EDGE", 0, "Amount of connecting edges", ""}, | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	{SIMEDGE_LENGTH, "LENGTH", 0, "Length", ""}, | 
					
						
							|  |  |  | 	{SIMEDGE_DIR, "DIR", 0, "Direction", ""}, | 
					
						
							|  |  |  | 	{SIMEDGE_FACE, "FACE", 0, "Amount of Faces Around an Edge", ""}, | 
					
						
							|  |  |  | 	{SIMEDGE_FACE_ANGLE, "FACE_ANGLE", 0, "Face Angles", ""}, | 
					
						
							|  |  |  | 	{SIMEDGE_CREASE, "CREASE", 0, "Crease", ""}, | 
					
						
							| 
									
										
										
										
											2012-05-12 14:06:35 +00:00
										 |  |  | 	{SIMEDGE_BEVEL, "BEVEL", 0, "Bevel", ""}, | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	{SIMEDGE_SEAM, "SEAM", 0, "Seam", ""}, | 
					
						
							|  |  |  | 	{SIMEDGE_SHARP, "SHARP", 0, "Sharpness", ""}, | 
					
						
							| 
									
										
										
										
											2012-12-20 07:57:26 +00:00
										 |  |  | #ifdef WITH_FREESTYLE
 | 
					
						
							| 
									
										
										
										
											2012-02-21 01:40:04 +00:00
										 |  |  | 	{SIMEDGE_FREESTYLE, "FREESTYLE_EDGE", 0, "Freestyle Edge Marks", ""}, | 
					
						
							| 
									
										
										
										
											2012-12-20 07:57:26 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	{SIMFACE_MATERIAL, "MATERIAL", 0, "Material", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_IMAGE, "IMAGE", 0, "Image", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_AREA, "AREA", 0, "Area", ""}, | 
					
						
							| 
									
										
										
										
											2012-10-30 06:43:30 +00:00
										 |  |  | 	{SIMFACE_SIDES, "SIDES", 0, "Polygon Sides", ""}, | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 	{SIMFACE_PERIMETER, "PERIMETER", 0, "Perimeter", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_NORMAL, "NORMAL", 0, "Normal", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_COPLANAR, "COPLANAR", 0, "Co-planar", ""}, | 
					
						
							| 
									
										
										
										
											2012-12-20 07:57:26 +00:00
										 |  |  | #ifdef WITH_FREESTYLE
 | 
					
						
							| 
									
										
										
										
											2012-02-21 01:40:04 +00:00
										 |  |  | 	{SIMFACE_FREESTYLE, "FREESTYLE_FACE", 0, "Freestyle Face Marks", ""}, | 
					
						
							| 
									
										
										
										
											2012-12-20 07:57:26 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	{0, NULL, 0, NULL, NULL} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | /* selects new faces/edges/verts based on the existing selection */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | static int similar_face_select_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(ob); | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 	/* get the type from RNA */ | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	const int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							|  |  |  | 	const float thresh = RNA_float_get(op->ptr, "threshold"); | 
					
						
							|  |  |  | 	const int compare = RNA_enum_get(op->ptr, "compare"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, | 
					
						
							|  |  |  | 	             "similar_faces faces=%hf type=%i thresh=%f compare=%i", | 
					
						
							|  |  |  | 	             BM_ELEM_SELECT, type, thresh, compare); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* clear the existing selection */ | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* select the output */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true); | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, true)) { | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	EDBM_update_generic(em, false, false); | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | }	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ***************************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* EDGE GROUP */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* wrap the above function but do selection flushing edge to face */ | 
					
						
							|  |  |  | static int similar_edge_select_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(ob); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* get the type from RNA */ | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	const int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							|  |  |  | 	const float thresh = RNA_float_get(op->ptr, "threshold"); | 
					
						
							|  |  |  | 	const int compare = RNA_enum_get(op->ptr, "compare"); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, | 
					
						
							|  |  |  | 	             "similar_edges edges=%he type=%i thresh=%f compare=%i", | 
					
						
							|  |  |  | 	             BM_ELEM_SELECT, type, thresh, compare); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* clear the existing selection */ | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* select the output */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_SELECT, true); | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, true)) { | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	EDBM_update_generic(em, false, false); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ********************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  |  * VERT GROUP | 
					
						
							|  |  |  |  * mode 1: same normal | 
					
						
							|  |  |  |  * mode 2: same number of face users | 
					
						
							|  |  |  |  * mode 3: same vertex groups | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | static int similar_vert_select_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(ob); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	/* get the type from RNA */ | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	const int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	const float thresh = RNA_float_get(op->ptr, "threshold"); | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	const int compare = RNA_enum_get(op->ptr, "compare"); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, | 
					
						
							|  |  |  | 	             "similar_verts verts=%hv type=%i thresh=%f compare=%i", | 
					
						
							|  |  |  | 	             BM_ELEM_SELECT, type, thresh, compare); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 	/* clear the existing selection */ | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 	/* select the output */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, true)) { | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	EDBM_update_generic(em, false, false); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_similar_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-21 07:49:05 +00:00
										 |  |  | 	ToolSettings *ts = CTX_data_tool_settings(C); | 
					
						
							|  |  |  | 	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "threshold"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	const int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 07:49:05 +00:00
										 |  |  | 	if (!RNA_property_is_set(op->ptr, prop)) { | 
					
						
							|  |  |  | 		RNA_property_float_set(op->ptr, prop, ts->select_thresh); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		ts->select_thresh = RNA_property_float_get(op->ptr, prop); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if      (type < 100) return similar_vert_select_exec(C, op); | 
					
						
							|  |  |  | 	else if (type < 200) return similar_edge_select_exec(C, op); | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	else                 return similar_face_select_exec(C, op); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | static EnumPropertyItem *select_similar_type_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), | 
					
						
							|  |  |  |                                                    int *free) | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-17 10:42:24 +00:00
										 |  |  | 	Object *obedit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!C) /* needed for docs and i18n tools */ | 
					
						
							|  |  |  | 		return prop_similar_types; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2011-09-07 06:49:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (obedit && obedit->type == OB_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		EnumPropertyItem *item = NULL; | 
					
						
							|  |  |  | 		int a, totitem = 0; | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 		BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			for (a = SIMVERT_NORMAL; a < SIMEDGE_LENGTH; a++) { | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 				RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			for (a = SIMEDGE_LENGTH; a < SIMFACE_MATERIAL; a++) { | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 				RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (em->selectmode & SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2012-12-20 07:57:26 +00:00
										 |  |  | #ifdef WITH_FREESTYLE
 | 
					
						
							| 
									
										
										
										
											2013-07-19 16:44:17 +00:00
										 |  |  | 			const int a_end = SIMFACE_FREESTYLE; | 
					
						
							| 
									
										
										
										
											2012-12-20 07:57:26 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2013-07-19 16:44:17 +00:00
										 |  |  | 			const int a_end = SIMFACE_COPLANAR; | 
					
						
							| 
									
										
										
										
											2012-12-20 07:57:26 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-07-19 16:44:17 +00:00
										 |  |  | 			for (a = SIMFACE_MATERIAL; a <= a_end; a++) { | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 				RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 		RNA_enum_item_end(&item, &totitem); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		*free = 1; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return item; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-17 10:42:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_similar(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Similar"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_similar"; | 
					
						
							| 
									
										
										
										
											2012-04-15 10:07:57 +00:00
										 |  |  | 	ot->description = "Select similar vertices, edges or faces by property types"; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->invoke = WM_menu_invoke; | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_similar_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	prop = ot->prop = RNA_def_enum(ot->srna, "type", prop_similar_types, SIMVERT_NORMAL, "Type", ""); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 	RNA_def_enum_funcs(prop, select_similar_type_itemf); | 
					
						
							| 
									
										
										
										
											2012-03-21 07:49:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-30 07:29:17 +00:00
										 |  |  | 	RNA_def_enum(ot->srna, "compare", prop_similar_compare_types, SIM_CMP_EQ, "Compare", ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "threshold", 0.0, 0.0, 1.0, "Threshold", "", 0.0, 1.0); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ****************  Mode Select *************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int edbm_select_mode_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	const int type        = RNA_enum_get(op->ptr,    "type"); | 
					
						
							|  |  |  | 	const int action      = RNA_enum_get(op->ptr,    "action"); | 
					
						
							|  |  |  | 	const bool use_extend = RNA_boolean_get(op->ptr, "use_extend"); | 
					
						
							|  |  |  | 	const bool use_expand = RNA_boolean_get(op->ptr, "use_expand"); | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (EDBM_selectmode_toggle(C, type, action, use_extend, use_expand)) { | 
					
						
							|  |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int edbm_select_mode_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-02-28 16:37:18 +00:00
										 |  |  | 	/* detecting these options based on shift/ctrl here is weak, but it's done
 | 
					
						
							|  |  |  | 	 * to make this work when clicking buttons or menus */ | 
					
						
							|  |  |  | 	if (!RNA_struct_property_is_set(op->ptr, "use_extend")) | 
					
						
							|  |  |  | 		RNA_boolean_set(op->ptr, "use_extend", event->shift); | 
					
						
							|  |  |  | 	if (!RNA_struct_property_is_set(op->ptr, "use_expand")) | 
					
						
							|  |  |  | 		RNA_boolean_set(op->ptr, "use_expand", event->ctrl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 	return edbm_select_mode_exec(C, op); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_mode(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static EnumPropertyItem elem_items[] = { | 
					
						
							|  |  |  | 		{SCE_SELECT_VERTEX, "VERT", ICON_VERTEXSEL, "Vertices", ""}, | 
					
						
							|  |  |  | 		{SCE_SELECT_EDGE,   "EDGE", ICON_EDGESEL, "Edges", ""}, | 
					
						
							|  |  |  | 		{SCE_SELECT_FACE,   "FACE", ICON_FACESEL, "Faces", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL}, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static EnumPropertyItem actions_items[] = { | 
					
						
							|  |  |  | 		{0, "DISABLE", 0, "Disable", "Disable selected markers"}, | 
					
						
							|  |  |  | 		{1, "ENABLE", 0, "Enable", "Enable selected markers"}, | 
					
						
							|  |  |  | 		{2, "TOGGLE", 0, "Toggle", "Toggle disabled flag for selected markers"}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Mode"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_mode"; | 
					
						
							|  |  |  | 	ot->description = "Change selection mode"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->invoke = edbm_select_mode_invoke; | 
					
						
							|  |  |  | 	ot->exec = edbm_select_mode_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	prop = RNA_def_boolean(ot->srna, "use_extend", false, "Extend", ""); | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 	RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	prop = RNA_def_boolean(ot->srna, "use_expand", false, "Expand", ""); | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 	RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							|  |  |  | 	ot->prop = prop = RNA_def_enum(ot->srna, "type", elem_items, 0, "Type", ""); | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "action", actions_items, 2, "Action", "Selection action to execute"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | /* ***************************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ****************  LOOP SELECTS *************** */ | 
					
						
							| 
									
										
										
										
											2009-07-29 00:43:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | static void walker_select(BMEditMesh *em, int walkercode, void *start, const bool select) | 
					
						
							| 
									
										
										
										
											2009-06-16 20:33:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 	BMElem *ele; | 
					
						
							| 
									
										
										
										
											2009-06-16 20:33:13 +00:00
										 |  |  | 	BMWalker walker; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMW_init(&walker, bm, walkercode, | 
					
						
							| 
									
										
										
										
											2012-03-29 13:09:07 +00:00
										 |  |  | 	         BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							| 
									
										
										
										
											2012-03-30 08:43:47 +00:00
										 |  |  | 	         BMW_FLAG_TEST_HIDDEN, | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 	         BMW_NIL_LAY); | 
					
						
							| 
									
										
										
										
											2013-01-14 09:53:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (ele = BMW_begin(&walker, start); ele; ele = BMW_step(&walker)) { | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		if (!select) { | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 			BM_select_history_remove(bm, ele); | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 		BM_elem_select_set(bm, ele, select); | 
					
						
							| 
									
										
										
										
											2009-06-16 20:33:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMW_end(&walker); | 
					
						
							| 
									
										
										
										
											2009-06-16 20:33:13 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_loop_multiselect_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMEdge **edarray; | 
					
						
							| 
									
										
										
										
											2011-06-26 01:11:03 +00:00
										 |  |  | 	int edindex; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	const bool is_ring = RNA_boolean_get(op->ptr, "ring"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-06-26 01:11:03 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	int totedgesel = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-20 19:49:27 +00:00
										 |  |  | 	BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-06-26 01:11:03 +00:00
										 |  |  | 			totedgesel++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	edarray = MEM_mallocN(sizeof(BMEdge *) * totedgesel, "edge array"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	edindex = 0; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-05-20 19:49:27 +00:00
										 |  |  | 	BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			edarray[edindex] = eed; | 
					
						
							| 
									
										
										
										
											2011-06-26 01:11:03 +00:00
										 |  |  | 			edindex++; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (is_ring) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		for (edindex = 0; edindex < totedgesel; edindex += 1) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			eed = edarray[edindex]; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			walker_select(em, BMW_EDGERING, eed, true); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		for (edindex = 0; edindex < totedgesel; edindex += 1) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			eed = edarray[edindex]; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			walker_select(em, BMW_LOOP, eed, true); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	MEM_freeN(edarray); | 
					
						
							|  |  |  | //	if (EM_texFaceCheck())
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-23 03:24:15 +00:00
										 |  |  | void MESH_OT_loop_multi_select(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Multi Select Loops"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_loop_multi_select"; | 
					
						
							| 
									
										
										
										
											2012-04-15 10:07:57 +00:00
										 |  |  | 	ot->description = "Select a loop of connected edges by connection type"; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_loop_multiselect_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "ring", 0, "Ring", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | /* ***************** MAIN MOUSE SELECTION ************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ***************** loop select (non modal) ************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | static void mouse_mesh_loop(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle, bool ring) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ViewContext vc; | 
					
						
							| 
									
										
										
										
											2009-05-18 08:46:04 +00:00
										 |  |  | 	BMEditMesh *em; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	BMEdge *eed; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	bool select = true; | 
					
						
							| 
									
										
										
										
											2012-10-10 01:22:19 +00:00
										 |  |  | 	float dist = 50.0f; | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 	float mvalf[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 	mvalf[0] = (float)(vc.mval[0] = mval[0]); | 
					
						
							|  |  |  | 	mvalf[1] = (float)(vc.mval[1] = mval[1]); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	em = vc.em; | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	/* no afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad */ | 
					
						
							|  |  |  | 	view3d_validate_backbuf(&vc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	eed = EDBM_edge_find_nearest(&vc, &dist); | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	if (eed) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		if (extend == false && deselect == false && toggle == false) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-11-21 01:51:31 +00:00
										 |  |  | 		if (extend) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			select = true; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-11-21 01:51:31 +00:00
										 |  |  | 		else if (deselect) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			select = false; | 
					
						
							| 
									
										
										
										
											2012-11-21 01:51:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (BM_elem_flag_test(eed, BM_ELEM_SELECT) == 0) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			select = true; | 
					
						
							| 
									
										
										
										
											2012-11-21 01:51:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (toggle) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			select = false; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (em->selectmode & SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2009-06-16 21:33:12 +00:00
										 |  |  | 			walker_select(em, BMW_FACELOOP, eed, select); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							|  |  |  | 			if (ring) | 
					
						
							| 
									
										
										
										
											2009-07-29 00:43:05 +00:00
										 |  |  | 				walker_select(em, BMW_EDGERING, eed, select); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2009-06-16 21:33:12 +00:00
										 |  |  | 				walker_select(em, BMW_LOOP, eed, select); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		else if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							|  |  |  | 			if (ring) | 
					
						
							| 
									
										
										
										
											2009-07-29 00:43:05 +00:00
										 |  |  | 				walker_select(em, BMW_EDGERING, eed, select); | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-04 14:59:20 +00:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2009-06-16 21:33:12 +00:00
										 |  |  | 				walker_select(em, BMW_LOOP, eed, select); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		/* sets as active, useful for other tools */ | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		if (select) { | 
					
						
							|  |  |  | 			if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-10-05 04:18:52 +00:00
										 |  |  | 				/* Find nearest vert from mouse
 | 
					
						
							|  |  |  | 				 * (initialize to large values incase only one vertex can be projected) */ | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 				float v1_co[2], v2_co[2]; | 
					
						
							| 
									
										
										
										
											2012-10-05 04:18:52 +00:00
										 |  |  | 				float length_1 = FLT_MAX; | 
					
						
							|  |  |  | 				float length_2 = FLT_MAX; | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				/* We can't be sure this has already been set... */ | 
					
						
							|  |  |  | 				ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d); | 
					
						
							| 
									
										
										
										
											2012-10-05 04:18:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 03:49:47 +00:00
										 |  |  | 				if (ED_view3d_project_float_object(vc.ar, eed->v1->co, v1_co, V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { | 
					
						
							| 
									
										
										
										
											2012-10-05 04:18:52 +00:00
										 |  |  | 					length_1 = len_squared_v2v2(mvalf, v1_co); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 03:49:47 +00:00
										 |  |  | 				if (ED_view3d_project_float_object(vc.ar, eed->v2->co, v2_co, V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { | 
					
						
							| 
									
										
										
										
											2012-10-05 04:18:52 +00:00
										 |  |  | 					length_2 = len_squared_v2v2(mvalf, v2_co); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | 				printf("mouse to v1: %f\nmouse to v2: %f\n", len_squared_v2v2(mvalf, v1_co), | 
					
						
							|  |  |  | 				       len_squared_v2v2(mvalf, v2_co)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-10-05 04:18:52 +00:00
										 |  |  | 				BM_select_history_store(em->bm, (length_1 < length_2) ? eed->v1 : eed->v2); | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-04-24 21:19:18 +00:00
										 |  |  | 				BM_select_history_store(em->bm, eed); | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 			else if (em->selectmode & SCE_SELECT_FACE) { | 
					
						
							|  |  |  | 				/* Select the face of eed which is the nearest of mouse. */ | 
					
						
							|  |  |  | 				BMFace *f, *efa = NULL; | 
					
						
							|  |  |  | 				BMIter iterf; | 
					
						
							| 
									
										
										
										
											2013-03-16 20:49:46 +00:00
										 |  |  | 				float best_dist = FLT_MAX; | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				/* We can't be sure this has already been set... */ | 
					
						
							|  |  |  | 				ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 08:21:40 +00:00
										 |  |  | 				BM_ITER_ELEM (f, &iterf, eed, BM_FACES_OF_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 					if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 						float cent[3]; | 
					
						
							|  |  |  | 						float co[2], tdist; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						BM_face_calc_center_mean(f, cent); | 
					
						
							| 
									
										
										
										
											2012-12-21 03:49:47 +00:00
										 |  |  | 						if (ED_view3d_project_float_object(vc.ar, cent, co, V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK) { | 
					
						
							| 
									
										
										
										
											2012-10-05 04:18:52 +00:00
										 |  |  | 							tdist = len_squared_v2v2(mvalf, co); | 
					
						
							|  |  |  | 							if (tdist < best_dist) { | 
					
						
							|  |  |  | /*								printf("Best face: %p (%f)\n", f, tdist);*/ | 
					
						
							|  |  |  | 								best_dist = tdist; | 
					
						
							|  |  |  | 								efa = f; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (efa) { | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 					BM_mesh_active_face_set(em->bm, efa); | 
					
						
							| 
									
										
										
										
											2012-06-25 13:32:04 +00:00
										 |  |  | 					BM_select_history_store(em->bm, efa); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int edbm_select_loop_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	view3d_operator_needs_opengl(C); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	mouse_mesh_loop(C, event->mval, | 
					
						
							|  |  |  | 	                RNA_boolean_get(op->ptr, "extend"), | 
					
						
							| 
									
										
										
										
											2012-11-21 01:51:31 +00:00
										 |  |  | 	                RNA_boolean_get(op->ptr, "deselect"), | 
					
						
							|  |  |  | 	                RNA_boolean_get(op->ptr, "toggle"), | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	                RNA_boolean_get(op->ptr, "ring")); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* cannot do tweaks for as long this keymap is after transform map */ | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-23 03:24:15 +00:00
										 |  |  | void MESH_OT_loop_select(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Loop Select"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_loop_select"; | 
					
						
							| 
									
										
										
										
											2012-04-15 10:07:57 +00:00
										 |  |  | 	ot->description = "Select a loop of connected edges"; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_select_loop_invoke; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh_region_view3d; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-27 12:53:23 +00:00
										 |  |  | 	ot->flag = OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2011-09-07 08:34:15 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "Extend the selection"); | 
					
						
							| 
									
										
										
										
											2012-11-21 01:51:31 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Remove from the selection"); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "toggle", 0, "Toggle Select", "Toggle the selection"); | 
					
						
							| 
									
										
										
										
											2011-09-07 08:34:15 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "ring", 0, "Select Ring", "Select ring"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-01 16:04:37 +00:00
										 |  |  | void MESH_OT_edgering_select(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2011-09-07 08:34:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* description */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Edge Ring Select"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_edgering_select"; | 
					
						
							|  |  |  | 	ot->description = "Select an edge ring"; | 
					
						
							| 
									
										
										
										
											2011-09-07 08:34:15 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_select_loop_invoke; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh_region_view3d; | 
					
						
							| 
									
										
										
										
											2011-09-07 08:34:15 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-27 12:53:23 +00:00
										 |  |  | 	ot->flag = OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-09-07 08:34:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection"); | 
					
						
							| 
									
										
										
										
											2012-11-21 01:51:31 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Remove from the selection"); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "toggle", 0, "Toggle Select", "Toggle the selection"); | 
					
						
							| 
									
										
										
										
											2011-09-07 08:34:15 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "ring", 1, "Select Ring", "Select ring"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | /* ******************** (de)select all operator **************** */ | 
					
						
							|  |  |  | static int edbm_select_all_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	const int action = RNA_enum_get(op->ptr, "action"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (action) { | 
					
						
							|  |  |  | 		case SEL_TOGGLE: | 
					
						
							|  |  |  | 			EDBM_select_toggle_all(em); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_SELECT: | 
					
						
							|  |  |  | 			EDBM_flag_enable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_DESELECT: | 
					
						
							|  |  |  | 			EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_INVERT: | 
					
						
							|  |  |  | 			EDBM_select_swap(em); | 
					
						
							|  |  |  | 			EDBM_selectmode_flush(em); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_all(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "(De)select All"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_all"; | 
					
						
							|  |  |  | 	ot->description = "(De)select all vertices, edges or faces"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = edbm_select_all_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_operator_properties_select_all(ot); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int edbm_faces_select_interior_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (EDBM_select_interior_faces(em)) { | 
					
						
							|  |  |  | 		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_interior_faces(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Interior Faces"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_interior_faces"; | 
					
						
							|  |  |  | 	ot->description = "Select faces where all edges have more than 2 face users"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = edbm_faces_select_interior_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************** */ | 
					
						
							|  |  |  | /* here actual select happens */ | 
					
						
							|  |  |  | /* gets called via generic mouse select operator */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | bool EDBM_select_pick(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ViewContext vc; | 
					
						
							| 
									
										
										
										
											2009-05-18 08:46:04 +00:00
										 |  |  | 	BMVert *eve = NULL; | 
					
						
							|  |  |  | 	BMEdge *eed = NULL; | 
					
						
							|  |  |  | 	BMFace *efa = NULL; | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	/* setup view context for argument to callbacks */ | 
					
						
							|  |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	vc.mval[0] = mval[0]; | 
					
						
							|  |  |  | 	vc.mval[1] = mval[1]; | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (unified_findnearest(&vc, &eve, &eed, &efa)) { | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* Deselect everything */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		if (extend == false && deselect == false && toggle == false) | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			EDBM_flag_disable_all(vc.em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (efa) { | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			if (extend) { | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 				/* set the last selected face */ | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 				BM_mesh_active_face_set(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				/* Work-around: deselect first, so we can guarantee it will */ | 
					
						
							|  |  |  | 				/* be active even if it was already selected */ | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				BM_select_history_remove(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_face_select_set(vc.em->bm, efa, false); | 
					
						
							| 
									
										
										
										
											2012-04-24 21:19:18 +00:00
										 |  |  | 				BM_select_history_store(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_face_select_set(vc.em->bm, efa, true); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			else if (deselect) { | 
					
						
							| 
									
										
										
										
											2012-04-24 21:19:18 +00:00
										 |  |  | 				BM_select_history_remove(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_face_select_set(vc.em->bm, efa, false); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 				/* set the last selected face */ | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 				BM_mesh_active_face_set(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 					BM_select_history_store(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_face_select_set(vc.em->bm, efa, true); | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else if (toggle) { | 
					
						
							|  |  |  | 					BM_select_history_remove(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_face_select_set(vc.em->bm, efa, false); | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		else if (eed) { | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			if (extend) { | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 				/* Work-around: deselect first, so we can guarantee it will */ | 
					
						
							|  |  |  | 				/* be active even if it was already selected */ | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				BM_select_history_remove(vc.em->bm, eed); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_edge_select_set(vc.em->bm, eed, false); | 
					
						
							| 
									
										
										
										
											2012-04-24 21:19:18 +00:00
										 |  |  | 				BM_select_history_store(vc.em->bm, eed); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_edge_select_set(vc.em->bm, eed, true); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			else if (deselect) { | 
					
						
							| 
									
										
										
										
											2012-04-24 21:19:18 +00:00
										 |  |  | 				BM_select_history_remove(vc.em->bm, eed); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_edge_select_set(vc.em->bm, eed, false); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			else { | 
					
						
							|  |  |  | 				if (!BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 					BM_select_history_store(vc.em->bm, eed); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_edge_select_set(vc.em->bm, eed, true); | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else if (toggle) { | 
					
						
							|  |  |  | 					BM_select_history_remove(vc.em->bm, eed); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_edge_select_set(vc.em->bm, eed, false); | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		else if (eve) { | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			if (extend) { | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 				/* Work-around: deselect first, so we can guarantee it will */ | 
					
						
							|  |  |  | 				/* be active even if it was already selected */ | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				BM_select_history_remove(vc.em->bm, eve); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_vert_select_set(vc.em->bm, eve, false); | 
					
						
							| 
									
										
										
										
											2012-04-24 21:19:18 +00:00
										 |  |  | 				BM_select_history_store(vc.em->bm, eve); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_vert_select_set(vc.em->bm, eve, true); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			else if (deselect) { | 
					
						
							| 
									
										
										
										
											2012-04-24 21:19:18 +00:00
										 |  |  | 				BM_select_history_remove(vc.em->bm, eve); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_vert_select_set(vc.em->bm, eve, false); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 			else { | 
					
						
							|  |  |  | 				if (!BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 					BM_select_history_store(vc.em->bm, eve); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_vert_select_set(vc.em->bm, eve, true); | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				else if (toggle) { | 
					
						
							|  |  |  | 					BM_select_history_remove(vc.em->bm, eve); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_vert_select_set(vc.em->bm, eve, false); | 
					
						
							| 
									
										
										
										
											2012-05-24 21:05:27 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(vc.em); | 
					
						
							| 
									
										
										
										
											2012-07-06 23:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-02 11:51:36 +00:00
										 |  |  | 		/* change active material on object */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (efa && efa->mat_nr != vc.obedit->actcol - 1) { | 
					
						
							|  |  |  | 			vc.obedit->actcol = efa->mat_nr + 1; | 
					
						
							|  |  |  | 			vc.em->mat_nr = efa->mat_nr; | 
					
						
							| 
									
										
										
										
											2012-04-02 11:51:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-26 08:52:07 +00:00
										 |  |  | 			WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, NULL); | 
					
						
							| 
									
										
										
										
											2012-04-02 11:51:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | static void edbm_strip_selections(BMEditMesh *em) | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMEditSelection *ese, *nextese; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (!(em->selectmode & SCE_SELECT_VERTEX)) { | 
					
						
							| 
									
										
										
										
											2009-07-17 10:54:00 +00:00
										 |  |  | 		ese = em->bm->selected.first; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		while (ese) { | 
					
						
							|  |  |  | 			nextese = ese->next; | 
					
						
							|  |  |  | 			if (ese->htype == BM_VERT) BLI_freelinkN(&(em->bm->selected), ese); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			ese = nextese; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (!(em->selectmode & SCE_SELECT_EDGE)) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		ese = em->bm->selected.first; | 
					
						
							|  |  |  | 		while (ese) { | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			nextese = ese->next; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if (ese->htype == BM_EDGE) BLI_freelinkN(&(em->bm->selected), ese); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			ese = nextese; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (!(em->selectmode & SCE_SELECT_FACE)) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		ese = em->bm->selected.first; | 
					
						
							|  |  |  | 		while (ese) { | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			nextese = ese->next; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if (ese->htype == BM_FACE) BLI_freelinkN(&(em->bm->selected), ese); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			ese = nextese; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | /* when switching select mode, makes sure selection is consistent for editing */ | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | /* also for paranoia checks to make sure edge or face mode works */ | 
					
						
							|  |  |  | void EDBM_selectmode_set(BMEditMesh *em) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	em->bm->selectmode = em->selectmode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	edbm_strip_selections(em); /* strip BMEditSelections from em->selected that are not relevant to new mode */ | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (em->bm->totvertsel == 0 && | 
					
						
							|  |  |  | 	    em->bm->totedgesel == 0 && | 
					
						
							|  |  |  | 	    em->bm->totfacesel == 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		if (em->bm->totvertsel) { | 
					
						
							|  |  |  | 			EDBM_select_flush(em); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		/* deselect vertices, and select again based on edge select */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 			BM_vert_select_set(em->bm, eve, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (em->bm->totedgesel) { | 
					
						
							|  |  |  | 			BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							|  |  |  | 				if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 					BM_edge_select_set(em->bm, eed, true); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* selects faces based on edge status */ | 
					
						
							|  |  |  | 			EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (em->selectmode & SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		/* deselect eges, and select again based on face select */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							|  |  |  | 			BM_edge_select_set(em->bm, eed, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (em->bm->totfacesel) { | 
					
						
							| 
									
										
										
										
											2013-07-24 18:38:55 +00:00
										 |  |  | 			BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 					BM_face_select_set(em->bm, efa, true); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Flush the selection up: | 
					
						
							|  |  |  |  * - vert -> edge | 
					
						
							|  |  |  |  * - edge -> face | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-07-20 09:49:54 +00:00
										 |  |  | void EDBM_selectmode_convert(BMEditMesh *em, const short selectmode_old, const short selectmode_new) | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-11 23:33:59 +00:00
										 |  |  | 	/* first tag-to-select, then select --- this avoids a feedback loop */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* have to find out what the selectionmode was previously */ | 
					
						
							| 
									
										
										
										
											2012-07-20 09:49:54 +00:00
										 |  |  | 	if (selectmode_old == SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		if (em->bm->totvertsel == 0) { | 
					
						
							|  |  |  | 			/* pass */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (selectmode_new == SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-11-11 23:33:59 +00:00
										 |  |  | 			/* select all edges associated with every selected vert */ | 
					
						
							|  |  |  | 			BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							|  |  |  | 				BM_elem_flag_set(eed, BM_ELEM_TAG, BM_edge_is_any_vert_flag_test(eed, BM_ELEM_SELECT)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							|  |  |  | 				if (BM_elem_flag_test(eed, BM_ELEM_TAG)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_edge_select_set(em->bm, eed, true); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-10-21 05:46:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-07-20 09:49:54 +00:00
										 |  |  | 		else if (selectmode_new == SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2012-11-11 23:33:59 +00:00
										 |  |  | 			/* select all faces associated with every selected vert */ | 
					
						
							|  |  |  | 			BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 				BM_elem_flag_set(efa, BM_ELEM_TAG, BM_face_is_any_vert_flag_test(efa, BM_ELEM_SELECT)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 				if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_face_select_set(em->bm, efa, true); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-20 09:49:54 +00:00
										 |  |  | 	else if (selectmode_old == SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		if (em->bm->totedgesel == 0) { | 
					
						
							|  |  |  | 			/* pass */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (selectmode_new == SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2012-11-11 23:33:59 +00:00
										 |  |  | 			/* select all faces associated with every selected edge */ | 
					
						
							|  |  |  | 			BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 				BM_elem_flag_set(efa, BM_ELEM_TAG, BM_face_is_any_edge_flag_test(efa, BM_ELEM_SELECT)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 				if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 					BM_face_select_set(em->bm, efa, true); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | /* user facing function, does notification and undo push */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | bool EDBM_selectmode_toggle(bContext *C, const short selectmode_new, | 
					
						
							|  |  |  |                             const int action, const bool use_extend, const bool use_expand) | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ToolSettings *ts = CTX_data_tool_settings(C); | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	BMEditMesh *em = NULL; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	bool ret = false; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (obedit && obedit->type == OB_MESH) { | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 		em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (em == NULL) { | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (action) { | 
					
						
							|  |  |  | 		case -1: | 
					
						
							|  |  |  | 			/* already set */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 0:  /* disable */ | 
					
						
							|  |  |  | 			/* check we have something to do */ | 
					
						
							|  |  |  | 			if ((em->selectmode & selectmode_new) == 0) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			em->selectmode &= ~selectmode_new; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1:  /* enable */ | 
					
						
							|  |  |  | 			/* check we have something to do */ | 
					
						
							|  |  |  | 			if ((em->selectmode & selectmode_new) != 0) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			em->selectmode |= selectmode_new; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2:  /* toggle */ | 
					
						
							|  |  |  | 			/* can't disable this flag if its the only one set */ | 
					
						
							|  |  |  | 			if (em->selectmode == selectmode_new) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				return false; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			em->selectmode ^= selectmode_new; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			BLI_assert(0); | 
					
						
							| 
									
										
										
										
											2013-07-21 08:16:37 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (selectmode_new) { | 
					
						
							|  |  |  | 		case SCE_SELECT_VERTEX: | 
					
						
							|  |  |  | 			if (use_extend == 0 || em->selectmode == 0) | 
					
						
							|  |  |  | 				em->selectmode = SCE_SELECT_VERTEX; | 
					
						
							|  |  |  | 			ts->selectmode = em->selectmode; | 
					
						
							|  |  |  | 			EDBM_selectmode_set(em); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			ret = true; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case SCE_SELECT_EDGE: | 
					
						
							|  |  |  | 			if (use_extend == 0 || em->selectmode == 0) { | 
					
						
							|  |  |  | 				if (use_expand) { | 
					
						
							|  |  |  | 					const short selmode_max = highest_order_bit_s(ts->selectmode); | 
					
						
							|  |  |  | 					if (selmode_max == SCE_SELECT_VERTEX) { | 
					
						
							|  |  |  | 						EDBM_selectmode_convert(em, selmode_max, SCE_SELECT_EDGE); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				em->selectmode = SCE_SELECT_EDGE; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ts->selectmode = em->selectmode; | 
					
						
							|  |  |  | 			EDBM_selectmode_set(em); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			ret = true; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case SCE_SELECT_FACE: | 
					
						
							|  |  |  | 			if (use_extend == 0 || em->selectmode == 0) { | 
					
						
							|  |  |  | 				if (use_expand) { | 
					
						
							|  |  |  | 					const short selmode_max = highest_order_bit_s(ts->selectmode); | 
					
						
							|  |  |  | 					if (ELEM(selmode_max, SCE_SELECT_VERTEX, SCE_SELECT_EDGE)) { | 
					
						
							|  |  |  | 						EDBM_selectmode_convert(em, selmode_max, SCE_SELECT_FACE); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				em->selectmode = SCE_SELECT_FACE; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			ts->selectmode = em->selectmode; | 
					
						
							|  |  |  | 			EDBM_selectmode_set(em); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			ret = true; | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			BLI_assert(0); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if (ret == true) { | 
					
						
							| 
									
										
										
										
											2012-11-13 05:44:49 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 		WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Use to disable a selectmode if its enabled, Using another mode as a fallback | 
					
						
							|  |  |  |  * if the disabled mode is the only mode set. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \return true if the mode is changed. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | bool EDBM_selectmode_disable(Scene *scene, BMEditMesh *em, | 
					
						
							|  |  |  |                              const short selectmode_disable, | 
					
						
							|  |  |  |                              const short selectmode_fallback) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* note essential, but switch out of vertex mode since the
 | 
					
						
							|  |  |  | 	 * selected regions wont be nicely isolated after flushing */ | 
					
						
							|  |  |  | 	if (em->selectmode & selectmode_disable) { | 
					
						
							|  |  |  | 		if (em->selectmode == selectmode_disable) { | 
					
						
							|  |  |  | 			em->selectmode = selectmode_fallback; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			em->selectmode &= ~selectmode_disable; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		scene->toolsettings->selectmode = em->selectmode; | 
					
						
							|  |  |  | 		EDBM_selectmode_set(em); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, scene); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-28 19:30:44 +00:00
										 |  |  | void EDBM_deselect_by_material(BMEditMesh *em, const short index, const short select) | 
					
						
							| 
									
										
										
										
											2011-08-16 18:45:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2011-08-16 18:45:03 +00:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (efa->mat_nr == index) { | 
					
						
							| 
									
										
										
										
											2012-04-20 16:55:47 +00:00
										 |  |  | 			BM_face_select_set(em->bm, efa, select); | 
					
						
							| 
									
										
										
										
											2011-08-16 18:45:03 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 23:41:33 +00:00
										 |  |  | void EDBM_select_toggle_all(BMEditMesh *em) /* exported for UV */ | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel) | 
					
						
							|  |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		EDBM_flag_enable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-08-16 18:45:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | void EDBM_select_swap(BMEditMesh *em) /* exported for UV */ | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->bm->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2012-04-20 16:55:47 +00:00
										 |  |  | 			BM_vert_select_set(em->bm, eve, !BM_elem_flag_test(eve, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2012-04-20 16:55:47 +00:00
										 |  |  | 			BM_edge_select_set(em->bm, eed, !BM_elem_flag_test(eed, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2012-04-20 16:55:47 +00:00
										 |  |  | 			BM_face_select_set(em->bm, efa, !BM_elem_flag_test(efa, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | //	if (EM_texFaceCheck())
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | bool EDBM_select_interior_faces(BMEditMesh *em) | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMIter eiter; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	bool ok; | 
					
						
							|  |  |  | 	bool change = false; | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 		if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		ok = true; | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_ELEM (eed, &eiter, efa, BM_EDGES_OF_FACE) { | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 			if (BM_edge_face_count(eed) < 3) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				ok = false; | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ok) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			BM_face_select_set(bm, efa, true); | 
					
						
							|  |  |  | 			change = true; | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return change; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /************************ Select Linked Operator *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | static void linked_limit_default(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (!RNA_struct_property_is_set(op->ptr, "limit")) { | 
					
						
							|  |  |  | 		Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 		BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (em->selectmode == SCE_SELECT_FACE) | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			RNA_boolean_set(op->ptr, "limit", true); | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			RNA_boolean_set(op->ptr, "limit", false); | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | static int edbm_select_linked_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMWalker walker; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int limit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	linked_limit_default(C, op); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	limit = RNA_boolean_get(op->ptr, "limit"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (em->selectmode == SCE_SELECT_FACE) { | 
					
						
							|  |  |  | 		BMFace *efa; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 			BM_elem_flag_set(efa, BM_ELEM_TAG, (BM_elem_flag_test(efa, BM_ELEM_SELECT) && | 
					
						
							|  |  |  | 			                                    !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (limit) { | 
					
						
							|  |  |  | 			/* grr, shouldn't need to alloc BMO flags here */ | 
					
						
							|  |  |  | 			BM_mesh_elem_toolflags_ensure(bm); | 
					
						
							|  |  |  | 			BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 				BMO_elem_flag_set(bm, e, BMO_ELE_TAG, !BM_elem_flag_test(e, BM_ELEM_SEAM)); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BMW_init(&walker, bm, BMW_ISLAND, | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 		         BMW_MASK_NOP, limit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 		         BMW_FLAG_TEST_HIDDEN, | 
					
						
							|  |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 			if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 				for (efa = BMW_begin(&walker, efa); efa; efa = BMW_step(&walker)) { | 
					
						
							|  |  |  | 					BM_face_select_set(bm, efa, true); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		BMW_end(&walker); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (limit) { | 
					
						
							|  |  |  | 			BM_mesh_elem_toolflags_clear(bm); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 			if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 				BM_elem_flag_enable(v, BM_ELEM_TAG); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				BM_elem_flag_disable(v, BM_ELEM_TAG); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BMW_init(&walker, em->bm, BMW_SHELL, | 
					
						
							|  |  |  | 		         BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							|  |  |  | 		         BMW_FLAG_TEST_HIDDEN, | 
					
						
							|  |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 			if (BM_elem_flag_test(v, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 				for (e = BMW_begin(&walker, v); e; e = BMW_step(&walker)) { | 
					
						
							|  |  |  | 					BM_edge_select_set(em->bm, e, true); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		BMW_end(&walker); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_linked(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Linked All"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_linked"; | 
					
						
							|  |  |  | 	ot->description = "Select all vertices linked to the active mesh"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = edbm_select_linked_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 09:03:46 +00:00
										 |  |  | static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	ViewContext vc; | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 	BMesh *bm; | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	BMWalker walker; | 
					
						
							|  |  |  | 	BMEditMesh *em; | 
					
						
							|  |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMEdge *e, *eed; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int sel = !RNA_boolean_get(op->ptr, "deselect"); | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int limit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	linked_limit_default(C, op); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	limit = RNA_boolean_get(op->ptr, "limit"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	/* unified_finednearest needs ogl */ | 
					
						
							|  |  |  | 	view3d_operator_needs_opengl(C); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* setup view context for argument to callbacks */ | 
					
						
							|  |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							|  |  |  | 	em = vc.em; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (em->bm->totedge == 0) | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	bm = em->bm; | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	vc.mval[0] = event->mval[0]; | 
					
						
							|  |  |  | 	vc.mval[1] = event->mval[1]; | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* return warning! */ | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (unified_findnearest(&vc, &eve, &eed, &efa) == 0) { | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 	if (em->selectmode == SCE_SELECT_FACE) { | 
					
						
							|  |  |  | 		BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (efa == NULL) | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 		if (limit) { | 
					
						
							| 
									
										
										
										
											2012-11-20 20:45:04 +00:00
										 |  |  | 			/* grr, shouldn't need to alloc BMO flags here */ | 
					
						
							|  |  |  | 			BM_mesh_elem_toolflags_ensure(bm); | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 			/* hflag no-seam --> bmo-tag */ | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 			BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 				BMO_elem_flag_set(bm, e, BMO_ELE_TAG, !BM_elem_flag_test(e, BM_ELEM_SEAM)); | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* walk */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_init(&walker, bm, BMW_ISLAND, | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 		         BMW_MASK_NOP, limit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							| 
									
										
										
										
											2012-03-29 13:09:07 +00:00
										 |  |  | 		         BMW_FLAG_TEST_HIDDEN, | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-14 09:53:56 +00:00
										 |  |  | 		for (efa = BMW_begin(&walker, efa); efa; efa = BMW_step(&walker)) { | 
					
						
							| 
									
										
										
										
											2012-04-20 16:55:47 +00:00
										 |  |  | 			BM_face_select_set(bm, efa, sel); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_end(&walker); | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		if (efa) { | 
					
						
							| 
									
										
										
										
											2012-02-06 22:57:25 +00:00
										 |  |  | 			eed = BM_FACE_FIRST_LOOP(efa)->e; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (!eed) { | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 			if (!eve || !eve->e) | 
					
						
							|  |  |  | 				return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			eed = eve->e; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_init(&walker, bm, BMW_SHELL, | 
					
						
							| 
									
										
										
										
											2012-03-29 13:09:07 +00:00
										 |  |  | 		         BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							|  |  |  | 		         BMW_FLAG_TEST_HIDDEN, | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-14 09:53:56 +00:00
										 |  |  | 		for (e = BMW_begin(&walker, eed->v1); e; e = BMW_step(&walker)) { | 
					
						
							| 
									
										
										
										
											2012-04-20 16:55:47 +00:00
										 |  |  | 			BM_edge_select_set(bm, e, sel); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_end(&walker); | 
					
						
							| 
									
										
										
										
											2012-03-30 00:58:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-11 10:14:46 +00:00
										 |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_linked_pick(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Linked"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_linked_pick"; | 
					
						
							| 
									
										
										
										
											2012-04-15 10:07:57 +00:00
										 |  |  | 	ot->description = "(De)select all vertices linked to the edge under the mouse cursor"; | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_select_linked_pick_invoke; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", ""); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", ""); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | static int edbm_select_face_by_sides_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	BMFace *efa; | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	const int numverts = RNA_int_get(op->ptr, "number"); | 
					
						
							|  |  |  | 	const int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	if (!RNA_boolean_get(op->ptr, "extend")) | 
					
						
							|  |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 		int select; | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 		switch (type) { | 
					
						
							|  |  |  | 			case 0: | 
					
						
							|  |  |  | 				select = (efa->len < numverts); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 1: | 
					
						
							|  |  |  | 				select = (efa->len == numverts); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 2: | 
					
						
							|  |  |  | 				select = (efa->len > numverts); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 3: | 
					
						
							|  |  |  | 				select = (efa->len != numverts); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				BLI_assert(0); | 
					
						
							|  |  |  | 				select = false; | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 		if (select) { | 
					
						
							|  |  |  | 			BM_face_select_set(em->bm, efa, true); | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-11-19 23:52:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | void MESH_OT_select_face_by_sides(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static const EnumPropertyItem type_items[] = { | 
					
						
							|  |  |  | 		{0, "LESS", 0, "Less Than", ""}, | 
					
						
							|  |  |  | 		{1, "EQUAL", 0, "Equal To", ""}, | 
					
						
							|  |  |  | 		{2, "GREATER", 0, "Greater Than", ""}, | 
					
						
							|  |  |  | 		{3, "NOTEQUAL", 0, "Not Equal To", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Faces by Sides"; | 
					
						
							|  |  |  | 	ot->description = "Select vertices or faces by the number of polygon sides"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_face_by_sides"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = edbm_select_face_by_sides_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "number", 4, 3, INT_MAX, "Number of Vertices", "", 3, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "type", type_items, 1, "Type", "Type of comparison to make"); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend the selection"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 16:59:53 +00:00
										 |  |  | static int edbm_select_loose_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-04-29 16:59:53 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!RNA_boolean_get(op->ptr, "extend")) | 
					
						
							|  |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 16:59:53 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							|  |  |  | 		BMVert *eve; | 
					
						
							|  |  |  | 		BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 			if (!eve->e) { | 
					
						
							|  |  |  | 				BM_vert_select_set(bm, eve, true); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-11-19 23:52:24 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 16:59:53 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							|  |  |  | 		BMEdge *eed; | 
					
						
							|  |  |  | 		BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) { | 
					
						
							|  |  |  | 			if (BM_edge_is_wire(eed)) { | 
					
						
							|  |  |  | 				BM_edge_select_set(bm, eed, true); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (em->selectmode & SCE_SELECT_FACE) { | 
					
						
							|  |  |  | 		BMFace *efa; | 
					
						
							|  |  |  | 		BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 			BMIter liter; | 
					
						
							|  |  |  | 			BMLoop *l; | 
					
						
							|  |  |  | 			bool is_loose = true; | 
					
						
							|  |  |  | 			BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { | 
					
						
							|  |  |  | 				if (!BM_edge_is_boundary(l->e)) { | 
					
						
							|  |  |  | 					is_loose = false; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (is_loose) { | 
					
						
							|  |  |  | 				BM_face_select_set(bm, efa, true); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2012-03-29 13:09:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-29 16:59:53 +00:00
										 |  |  | void MESH_OT_select_loose(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2013-04-29 16:59:53 +00:00
										 |  |  | 	ot->name = "Select Loose Geometry"; | 
					
						
							|  |  |  | 	ot->description = "Select loose geometry based on the selection mode"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_loose"; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2013-04-29 16:59:53 +00:00
										 |  |  | 	ot->exec = edbm_select_loose_exec; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2013-01-08 17:30:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int edbm_select_mirror_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	bool extend = RNA_boolean_get(op->ptr, "extend"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (em->bm->totvert && em->bm->totvertsel) { | 
					
						
							| 
									
										
										
										
											2013-06-05 05:58:51 +00:00
										 |  |  | 		int totmirr, totfail; | 
					
						
							| 
									
										
										
										
											2013-07-01 21:56:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 05:58:51 +00:00
										 |  |  | 		EDBM_select_mirrored(em, extend, &totmirr, &totfail); | 
					
						
							|  |  |  | 		if (totmirr) { | 
					
						
							|  |  |  | 			EDBM_selectmode_flush(em); | 
					
						
							|  |  |  | 			WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 21:56:59 +00:00
										 |  |  | 		ED_mesh_report_mirror_ex(op, totmirr, totfail, em->bm->selectmode); | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | void MESH_OT_select_mirror(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	ot->name = "Select Mirror"; | 
					
						
							|  |  |  | 	ot->description = "Select mesh items at mirrored locations"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_mirror"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	ot->exec = edbm_select_mirror_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection"); | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ******************** **************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_more_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 	EDBM_select_more(em); | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_more(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select More"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_more"; | 
					
						
							|  |  |  | 	ot->description = "Select more vertices, edges or faces connected to initial selection"; | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_more_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_less_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 	EDBM_select_less(em); | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_less(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Less"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_less"; | 
					
						
							|  |  |  | 	ot->description = "Deselect vertices, edges or faces at the boundary of each selection region"; | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_less_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-05 07:15:17 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | /* Walk all reachable elements of the same type as h_act in breadth-first
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  |  * order, starting from h_act. Deselects elements if the depth when they | 
					
						
							|  |  |  |  * are reached is not a multiple of "nth". */ | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | static void walker_deselect_nth(BMEditMesh *em, int nth, int offset, BMHeader *h_act) | 
					
						
							| 
									
										
										
										
											2011-09-26 00:32:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 	BMElem *ele; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	BMWalker walker; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	int walktype = 0, itertype = 0, flushtype = 0; | 
					
						
							| 
									
										
										
										
											2012-03-29 13:09:07 +00:00
										 |  |  | 	short mask_vert = 0, mask_edge = 0, mask_face = 0; | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	/* No active element from which to start - nothing to do */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (h_act == NULL) { | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	/* Determine which type of iter, walker, and select flush to use
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	 * based on type of the elements being deselected */ | 
					
						
							| 
									
										
										
										
											2011-11-01 14:36:23 +00:00
										 |  |  | 	switch (h_act->htype) { | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		case BM_VERT: | 
					
						
							|  |  |  | 			itertype = BM_VERTS_OF_MESH; | 
					
						
							|  |  |  | 			walktype = BMW_CONNECTED_VERTEX; | 
					
						
							|  |  |  | 			flushtype = SCE_SELECT_VERTEX; | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 			mask_vert = BMO_ELE_TAG; | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case BM_EDGE: | 
					
						
							|  |  |  | 			itertype = BM_EDGES_OF_MESH; | 
					
						
							|  |  |  | 			walktype = BMW_SHELL; | 
					
						
							|  |  |  | 			flushtype = SCE_SELECT_EDGE; | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 			mask_edge = BMO_ELE_TAG; | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case BM_FACE: | 
					
						
							|  |  |  | 			itertype = BM_FACES_OF_MESH; | 
					
						
							|  |  |  | 			walktype = BMW_ISLAND; | 
					
						
							|  |  |  | 			flushtype = SCE_SELECT_FACE; | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 			mask_face = BMO_ELE_TAG; | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-09-26 00:32:45 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 20:45:04 +00:00
										 |  |  | 	/* grr, shouldn't need to alloc BMO flags here */ | 
					
						
							|  |  |  | 	BM_mesh_elem_toolflags_ensure(bm); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	/* Walker restrictions uses BMO flags, not header flags,
 | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 	 * so transfer BM_ELEM_SELECT from HFlags onto a BMO flag layer. */ | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	BMO_push(bm, NULL); | 
					
						
							| 
									
										
										
										
											2012-04-19 12:45:56 +00:00
										 |  |  | 	BM_ITER_MESH (ele, &iter, bm, itertype) { | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 		if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2013-04-15 04:34:14 +00:00
										 |  |  | 			BMO_elem_flag_enable(bm, (BMElemF *)ele, BMO_ELE_TAG); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	/* Walk over selected elements starting at active */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMW_init(&walker, bm, walktype, | 
					
						
							| 
									
										
										
										
											2012-03-29 13:09:07 +00:00
										 |  |  | 	         mask_vert, mask_edge, mask_face, | 
					
						
							| 
									
										
										
										
											2012-04-16 09:34:43 +00:00
										 |  |  | 	         BMW_FLAG_NOP, /* don't use BMW_FLAG_TEST_HIDDEN here since we want to desel all */ | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 	         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-16 16:04:12 +00:00
										 |  |  | 	/* use tag to avoid touching the same verts twice */ | 
					
						
							|  |  |  | 	BM_ITER_MESH (ele, &iter, bm, itertype) { | 
					
						
							|  |  |  | 		BM_elem_flag_disable(ele, BM_ELEM_TAG); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	BLI_assert(walker.order == BMW_BREADTH_FIRST); | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 	for (ele = BMW_begin(&walker, h_act); ele != NULL; ele = BMW_step(&walker)) { | 
					
						
							| 
									
										
										
										
											2012-10-16 16:04:12 +00:00
										 |  |  | 		if (!BM_elem_flag_test(ele, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 			/* Deselect elements that aren't at "nth" depth from active */ | 
					
						
							|  |  |  | 			if ((offset + BMW_current_depth(&walker)) % nth) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_elem_select_set(bm, ele, false); | 
					
						
							| 
									
										
										
										
											2012-10-16 16:04:12 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			BM_elem_flag_enable(ele, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMW_end(&walker); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	BMO_pop(bm); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	/* Flush selection up */ | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush_ex(em, flushtype); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed, BMFace **r_efa) | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 	BMElem *ele; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	*r_eve = NULL; | 
					
						
							|  |  |  | 	*r_eed = NULL; | 
					
						
							|  |  |  | 	*r_efa = NULL; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 	ele = BM_mesh_active_elem_get(em->bm); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-23 18:49:44 +00:00
										 |  |  | 	if (ele && BM_elem_flag_test(ele, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2013-06-27 01:10:19 +00:00
										 |  |  | 		switch (ele->head.htype) { | 
					
						
							|  |  |  | 			case BM_VERT: | 
					
						
							|  |  |  | 				*r_eve = (BMVert *)ele; | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			case BM_EDGE: | 
					
						
							|  |  |  | 				*r_eed = (BMEdge *)ele; | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			case BM_FACE: | 
					
						
							|  |  |  | 				*r_efa = (BMFace *)ele; | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2013-07-23 18:49:44 +00:00
										 |  |  | 		BMVert *v; | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 				*r_eve = v; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2013-07-23 18:49:44 +00:00
										 |  |  | 		BMEdge *e; | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 				*r_eed = e; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (em->selectmode & SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2013-07-23 18:49:44 +00:00
										 |  |  | 		BMFace *f = BM_mesh_active_face_get(em->bm, true, false); | 
					
						
							|  |  |  | 		if (f && BM_elem_flag_test(f, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 			*r_efa = f; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | static bool edbm_deselect_nth(BMEditMesh *em, int nth, int offset) | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	deselect_nth_active(em, &v, &e, &f); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	if (v) { | 
					
						
							| 
									
										
										
										
											2011-09-27 11:38:55 +00:00
										 |  |  | 		walker_deselect_nth(em, nth, offset, &v->head); | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (e) { | 
					
						
							| 
									
										
										
										
											2011-09-27 11:38:55 +00:00
										 |  |  | 		walker_deselect_nth(em, nth, offset, &e->head); | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (f) { | 
					
						
							| 
									
										
										
										
											2011-09-27 11:38:55 +00:00
										 |  |  | 		walker_deselect_nth(em, nth, offset, &f->head); | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_nth_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	const int nth = RNA_int_get(op->ptr, "nth"); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int offset = RNA_int_get(op->ptr, "offset"); | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-17 15:02:26 +00:00
										 |  |  | 	/* so input of offset zero ends up being (nth - 1) */ | 
					
						
							| 
									
										
										
										
											2013-09-05 20:54:32 +00:00
										 |  |  | 	offset = mod_i(offset, nth); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-05 14:58:30 +00:00
										 |  |  | 	if (edbm_deselect_nth(em, nth, offset) == false) { | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "Mesh has no active vert/edge/face"); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	EDBM_update_generic(em, false, false); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_nth(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-11-01 05:07:15 +00:00
										 |  |  | 	ot->name = "Checker Deselect"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_select_nth"; | 
					
						
							| 
									
										
										
										
											2013-02-23 11:51:10 +00:00
										 |  |  | 	ot->description = "Deselect every Nth element starting from the active vertex, edge or face"; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_nth_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-11 23:46:12 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "nth", 2, 2, INT_MAX, "Nth Selection", "", 2, 100); | 
					
						
							| 
									
										
										
										
											2013-09-05 20:54:32 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "offset", 0, INT_MIN, INT_MAX, "Offset", "", -100, 100); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void em_setup_viewcontext(bContext *C, ViewContext *vc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	view3d_set_viewcontext(C, vc); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (vc->obedit) { | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 		vc->em = BKE_editmesh_from_object(vc->obedit); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_sharp_edges_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* Find edges that have exactly two neighboring faces,
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 	 * check the angle between those faces, and if angle is | 
					
						
							|  |  |  | 	 * small enough, select the edge | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMLoop *l1, *l2; | 
					
						
							| 
									
										
										
										
											2012-09-14 11:10:03 +00:00
										 |  |  | 	const float sharp = RNA_float_get(op->ptr, "sharpness"); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 		if (BM_elem_flag_test(e, BM_ELEM_HIDDEN) == false && | 
					
						
							| 
									
										
										
										
											2012-09-14 11:10:03 +00:00
										 |  |  | 		    BM_edge_loop_pair(e, &l1, &l2)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			/* edge has exactly two neighboring faces, check angle */ | 
					
						
							|  |  |  | 			const float angle = angle_normalized_v3v3(l1->f->no, l2->f->no); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-14 11:10:03 +00:00
										 |  |  | 			if (fabsf(angle) > sharp) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_edge_select_set(em->bm, e, true); | 
					
						
							| 
									
										
										
										
											2012-09-14 11:10:03 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_edges_select_sharp(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-20 13:56:42 +00:00
										 |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Sharp Edges"; | 
					
						
							| 
									
										
										
										
											2012-05-20 13:56:42 +00:00
										 |  |  | 	ot->description = "Select all sharp-enough edges"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_edges_select_sharp"; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_sharp_edges_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2012-05-20 13:56:42 +00:00
										 |  |  | 	prop = RNA_def_float_rotation(ot->srna, "sharpness", 0, NULL, DEG2RADF(0.01f), DEG2RADF(180.0f), | 
					
						
							|  |  |  | 	                              "Sharpness", "", DEG2RADF(1.0f), DEG2RADF(180.0f)); | 
					
						
							| 
									
										
										
										
											2012-09-14 11:10:03 +00:00
										 |  |  | 	RNA_def_property_float_default(prop, DEG2RADF(30.0f)); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_linked_flat_faces_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 05:33:55 +00:00
										 |  |  | 	BLI_LINKSTACK_DECLARE(stack, BMFace *); | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMIter iter, liter, liter2; | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 	BMFace *f; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMLoop *l, *l2; | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 	const float angle_limit = RNA_float_get(op->ptr, "sharpness"); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-23 18:03:40 +00:00
										 |  |  | 	BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 04:06:49 +00:00
										 |  |  | 	BLI_LINKSTACK_INIT(stack); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 	BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | 
					
						
							|  |  |  | 		if ((BM_elem_flag_test(f, BM_ELEM_HIDDEN) != 0) || | 
					
						
							|  |  |  | 		    (BM_elem_flag_test(f, BM_ELEM_TAG)    != 0) || | 
					
						
							|  |  |  | 		    (BM_elem_flag_test(f, BM_ELEM_SELECT) == 0)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 04:06:49 +00:00
										 |  |  | 		BLI_assert(BLI_LINKSTACK_SIZE(stack) == 0); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 		do { | 
					
						
							|  |  |  | 			BM_face_select_set(bm, f, true); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_enable(f, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 			BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | 
					
						
							|  |  |  | 				BM_ITER_ELEM (l2, &liter2, l, BM_LOOPS_OF_LOOP) { | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 					float angle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 					if (BM_elem_flag_test(l2->f, BM_ELEM_TAG) || | 
					
						
							|  |  |  | 					    BM_elem_flag_test(l2->f, BM_ELEM_HIDDEN)) | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 						continue; | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 					angle = angle_normalized_v3v3(f->no, l2->f->no); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-25 21:24:09 +00:00
										 |  |  | 					if (angle < angle_limit) { | 
					
						
							| 
									
										
										
										
											2013-08-17 05:33:55 +00:00
										 |  |  | 						BLI_LINKSTACK_PUSH(stack, l2->f); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-08-17 05:33:55 +00:00
										 |  |  | 		} while ((f = BLI_LINKSTACK_POP(stack))); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-17 05:33:55 +00:00
										 |  |  | 	BLI_LINKSTACK_FREE(stack); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_faces_select_linked_flat(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-20 13:56:42 +00:00
										 |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Linked Flat Faces"; | 
					
						
							|  |  |  | 	ot->description = "Select linked faces by angle"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_faces_select_linked_flat"; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_linked_flat_faces_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2012-05-20 13:56:42 +00:00
										 |  |  | 	prop = RNA_def_float_rotation(ot->srna, "sharpness", 0, NULL, DEG2RADF(0.01f), DEG2RADF(180.0f), | 
					
						
							|  |  |  | 	                              "Sharpness", "", DEG2RADF(1.0f), DEG2RADF(180.0f)); | 
					
						
							|  |  |  | 	RNA_def_property_float_default(prop, DEG2RADF(1.0f)); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_non_manifold_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-12 10:48:10 +00:00
										 |  |  | 	if (!RNA_boolean_get(op->ptr, "extend")) | 
					
						
							|  |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	/* Selects isolated verts, and edges that do not have 2 neighboring
 | 
					
						
							|  |  |  | 	 * faces | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (em->selectmode == SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2012-10-26 17:32:50 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "Does not work in face selection mode"); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-03-22 07:53:11 +00:00
										 |  |  | 		if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN) && !BM_vert_is_manifold(v)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			BM_vert_select_set(em->bm, v, true); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-04-18 06:57:28 +00:00
										 |  |  | 		if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && !BM_edge_is_manifold(e)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			BM_edge_select_set(em->bm, e, true); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-16 15:45:30 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_non_manifold(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Non Manifold"; | 
					
						
							|  |  |  | 	ot->description = "Select all non-manifold vertices or edges"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_non_manifold"; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_non_manifold_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2013-01-12 10:48:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", true, "Extend", "Extend the selection"); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_random_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	const float randfac =  RNA_float_get(op->ptr, "percent") / 100.0f; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (!RNA_boolean_get(op->ptr, "extend")) | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BLI_frand() < randfac) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_vert_select_set(em->bm, eve, true); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BLI_frand() < randfac) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_edge_select_set(em->bm, eed, true); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BLI_frand() < randfac) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_face_select_set(em->bm, efa, true); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_random(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Random"; | 
					
						
							|  |  |  | 	ot->description = "Randomly select vertices"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_random"; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_random_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, | 
					
						
							|  |  |  | 	                         "Percent", "Percentage of elements to select randomly", 0.f, 100.0f); | 
					
						
							| 
									
										
										
										
											2013-03-02 12:05:25 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection"); | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 06:07:26 +00:00
										 |  |  | static int edbm_select_ungrouped_poll(bContext *C) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (ED_operator_editmesh(C)) { | 
					
						
							|  |  |  | 		Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 		BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-05-27 12:42:48 +00:00
										 |  |  | 		const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); | 
					
						
							| 
									
										
										
										
											2013-05-01 06:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if ((em->selectmode & SCE_SELECT_VERTEX) == 0) { | 
					
						
							|  |  |  | 			CTX_wm_operator_poll_msg_set(C, "Must be in vertex selection mode"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-27 12:42:48 +00:00
										 |  |  | 		else if (obedit->defbase.first == NULL || cd_dvert_offset == -1) { | 
					
						
							| 
									
										
										
										
											2013-05-01 06:07:26 +00:00
										 |  |  | 			CTX_wm_operator_poll_msg_set(C, "No weights/vertex groups on object"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | static int edbm_select_ungrouped_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-05-27 12:42:48 +00:00
										 |  |  | 	const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!RNA_boolean_get(op->ptr, "extend")) { | 
					
						
							|  |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 		if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { | 
					
						
							| 
									
										
										
										
											2013-05-27 12:42:48 +00:00
										 |  |  | 			MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset); | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | 			/* no dv or dv set with no weight */ | 
					
						
							| 
									
										
										
										
											2013-05-01 05:59:58 +00:00
										 |  |  | 			if (ELEM(NULL, dv, dv->dw)) { | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | 				BM_vert_select_set(em->bm, eve, true); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 05:59:58 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_ungrouped(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Ungrouped"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_ungrouped"; | 
					
						
							|  |  |  | 	ot->description = "Select vertices without a group"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = edbm_select_ungrouped_exec; | 
					
						
							| 
									
										
										
										
											2013-05-01 06:07:26 +00:00
										 |  |  | 	ot->poll = edbm_select_ungrouped_poll; | 
					
						
							| 
									
										
										
										
											2013-03-16 16:11:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend the selection"); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* BMESH_TODO - some way to select on an arbitrary axis */ | 
					
						
							|  |  |  | static int edbm_select_axis_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMVert *v_act = BM_mesh_active_vert_get(bm); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 	const int axis = RNA_enum_get(op->ptr, "axis"); | 
					
						
							|  |  |  | 	const int mode = RNA_enum_get(op->ptr, "mode"); /* -1 == aligned, 0 == neg, 1 == pos */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 	if (v_act == NULL) { | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_WARNING, "This operator requires an active vertex (last selected)"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 		BMVert *v; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 		BMIter iter; | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 		const float limit =  CTX_data_tool_settings(C)->doublimit; // XXX
 | 
					
						
							|  |  |  | 		float value = v_act->co[axis]; | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (mode == 0) | 
					
						
							|  |  |  | 			value -= limit; | 
					
						
							|  |  |  | 		else if (mode == 1) | 
					
						
							|  |  |  | 			value += limit; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 		BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { | 
					
						
							|  |  |  | 			if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 				switch (mode) { | 
					
						
							|  |  |  | 					case -1: /* aligned */ | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 						if (fabsf(v->co[axis] - value) < limit) | 
					
						
							|  |  |  | 							BM_vert_select_set(bm, v, true); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					case 0: /* neg */ | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 						if (v->co[axis] > value) | 
					
						
							|  |  |  | 							BM_vert_select_set(bm, v, true); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					case 1: /* pos */ | 
					
						
							| 
									
										
										
										
											2013-06-24 04:51:56 +00:00
										 |  |  | 						if (v->co[axis] < value) | 
					
						
							|  |  |  | 							BM_vert_select_set(bm, v, true); | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_axis(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static EnumPropertyItem axis_mode_items[] = { | 
					
						
							|  |  |  | 		{0,  "POSITIVE", 0, "Positive Axis", ""}, | 
					
						
							|  |  |  | 		{1,  "NEGATIVE", 0, "Negative Axis", ""}, | 
					
						
							|  |  |  | 		{-1, "ALIGNED",  0, "Aligned Axis", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static EnumPropertyItem axis_items_xyz[] = { | 
					
						
							|  |  |  | 		{0, "X_AXIS", 0, "X Axis", ""}, | 
					
						
							|  |  |  | 		{1, "Y_AXIS", 0, "Y Axis", ""}, | 
					
						
							|  |  |  | 		{2, "Z_AXIS", 0, "Z Axis", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Axis"; | 
					
						
							|  |  |  | 	ot->description = "Select all data in the mesh on a single axis"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_axis"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							|  |  |  | 	ot->exec = edbm_select_axis_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							|  |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "mode", axis_mode_items, 0, "Axis Mode", "Axis side to use when selecting"); | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "axis", axis_items_xyz, 0, "Axis", "Select the axis to compare each vertex on"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_next_loop_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		BM_elem_flag_disable(v, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 		BMLoop *l; | 
					
						
							|  |  |  | 		BMIter liter; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | 
					
						
							| 
									
										
										
										
											2012-03-02 10:49:15 +00:00
										 |  |  | 			if (BM_elem_flag_test(l->v, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BM_elem_flag_enable(l->next->v, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 				BM_vert_select_set(em->bm, l->v, false); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(v, BM_ELEM_TAG)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			BM_vert_select_set(em->bm, v, true); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_next_loop(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Next Loop"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_next_loop"; | 
					
						
							| 
									
										
										
										
											2012-04-15 10:07:57 +00:00
										 |  |  | 	ot->description = "Select next edge loop adjacent to a selected loop"; | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_next_loop_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_region_to_loop_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	BM_mesh_elem_hflag_disable_all(em->bm, BM_EDGE, BM_ELEM_TAG, false); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		BMLoop *l1, *l2; | 
					
						
							|  |  |  | 		BMIter liter1, liter2; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_ELEM (l1, &liter1, f, BM_LOOPS_OF_FACE) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			int tot = 0, totsel = 0; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 			BM_ITER_ELEM (l2, &liter2, l1->e, BM_LOOPS_OF_EDGE) { | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 				tot++; | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				totsel += BM_elem_flag_test(l2->f, BM_ELEM_SELECT) != 0; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if ((tot != totsel && totsel > 0) || (totsel == 1 && tot == 1)) | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BM_elem_flag_enable(l1->e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-04-19 16:57:50 +00:00
										 |  |  | 		if (BM_elem_flag_test(e, BM_ELEM_TAG)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			BM_edge_select_set(em->bm, e, true); | 
					
						
							| 
									
										
										
										
											2012-04-19 16:57:50 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-10-15 14:47:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* If in face-only select mode, switch to edge select mode so that
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 	 * an edge-only selection is not inconsistent state */ | 
					
						
							| 
									
										
										
										
											2011-10-15 14:47:37 +00:00
										 |  |  | 	if (em->selectmode == SCE_SELECT_FACE) { | 
					
						
							|  |  |  | 		em->selectmode = SCE_SELECT_EDGE; | 
					
						
							|  |  |  | 		EDBM_selectmode_set(em); | 
					
						
							|  |  |  | 		EDBM_selectmode_to_scene(C); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2011-10-15 14:47:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_region_to_loop(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Boundary Loop"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_region_to_loop"; | 
					
						
							| 
									
										
										
										
											2012-04-15 10:07:57 +00:00
										 |  |  | 	ot->description = "Select boundary edges around the selected faces"; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_region_to_loop_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 14:38:09 +00:00
										 |  |  | static int loop_find_region(BMLoop *l, int flag, | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  |                             SmallHash *fhash, BMFace ***region_out) | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	BMFace **region = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	BMFace **stack = NULL; | 
					
						
							| 
									
										
										
										
											2013-07-28 09:05:27 +00:00
										 |  |  | 	BLI_array_declare(region); | 
					
						
							|  |  |  | 	BLI_array_declare(stack); | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	BMFace *f; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BLI_array_append(stack, l->f); | 
					
						
							|  |  |  | 	BLI_smallhash_insert(fhash, (uintptr_t)l->f, NULL); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	while (BLI_array_count(stack) > 0) { | 
					
						
							|  |  |  | 		BMIter liter1, liter2; | 
					
						
							|  |  |  | 		BMLoop *l1, *l2; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		f = BLI_array_pop(stack); | 
					
						
							|  |  |  | 		BLI_array_append(region, f); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_ELEM (l1, &liter1, f, BM_LOOPS_OF_FACE) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(l1->e, flag)) | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 			BM_ITER_ELEM (l2, &liter2, l1->e, BM_LOOPS_OF_EDGE) { | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 				if (BLI_smallhash_haskey(fhash, (uintptr_t)l2->f)) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				BLI_array_append(stack, l2->f); | 
					
						
							|  |  |  | 				BLI_smallhash_insert(fhash, (uintptr_t)l2->f, NULL); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BLI_array_free(stack); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	*region_out = region; | 
					
						
							|  |  |  | 	return BLI_array_count(region); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 02:14:43 +00:00
										 |  |  | static int verg_radial(const void *va, const void *vb) | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	BMEdge *e1 = *((void **)va); | 
					
						
							|  |  |  | 	BMEdge *e2 = *((void **)vb); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	int a, b; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	a = BM_edge_face_count(e1); | 
					
						
							|  |  |  | 	b = BM_edge_face_count(e2); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (a > b)  return -1; | 
					
						
							|  |  |  | 	if (a == b) return  0; | 
					
						
							|  |  |  | 	if (a < b)  return  1; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int loop_find_regions(BMEditMesh *em, int selbigger) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SmallHash visithash; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	BMEdge *e, **edges = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	BLI_array_declare(edges); | 
					
						
							|  |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	int count = 0, i; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BLI_smallhash_init(&visithash); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		BM_elem_flag_disable(f, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			BLI_array_append(edges, e); | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_enable(e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_disable(e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* sort edges by radial cycle length */ | 
					
						
							|  |  |  | 	qsort(edges,  BLI_array_count(edges), sizeof(void *), verg_radial); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (i = 0; i < BLI_array_count(edges); i++) { | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		BMIter liter; | 
					
						
							|  |  |  | 		BMLoop *l; | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 		BMFace **region = NULL, **region_out; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		int c, tot = 0; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		e = edges[i]; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (!BM_elem_flag_test(e, BM_ELEM_TAG)) | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 		BM_ITER_ELEM (l, &liter, e, BM_LOOPS_OF_EDGE) { | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			if (BLI_smallhash_haskey(&visithash, (uintptr_t)l->f)) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 						 | 
					
						
							| 
									
										
										
										
											2012-04-19 14:38:09 +00:00
										 |  |  | 			c = loop_find_region(l, BM_ELEM_SELECT, &visithash, ®ion_out); | 
					
						
							| 
									
										
										
										
											2011-09-30 15:15:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			if (!region || (selbigger ? c >= tot : c < tot)) { | 
					
						
							| 
									
										
										
										
											2011-09-30 15:15:57 +00:00
										 |  |  | 				/* this region is the best seen so far */ | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 				tot = c; | 
					
						
							| 
									
										
										
										
											2011-09-30 15:15:57 +00:00
										 |  |  | 				if (region) { | 
					
						
							|  |  |  | 					/* free the previous best */ | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 					MEM_freeN(region); | 
					
						
							| 
									
										
										
										
											2011-09-30 15:15:57 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				/* track the current region as the new best */ | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 				region = region_out; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-09-30 15:15:57 +00:00
										 |  |  | 			else { | 
					
						
							|  |  |  | 				/* this region is not as good as best so far, just free it */ | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 				MEM_freeN(region_out); | 
					
						
							| 
									
										
										
										
											2011-09-30 15:15:57 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (region) { | 
					
						
							|  |  |  | 			int j; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			for (j = 0; j < tot; j++) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BM_elem_flag_enable(region[j], BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 				BM_ITER_ELEM (l, &liter, region[j], BM_LOOPS_OF_FACE) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 					BM_elem_flag_disable(l->e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			count += tot; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			MEM_freeN(region); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BLI_array_free(edges); | 
					
						
							|  |  |  | 	BLI_smallhash_release(&visithash); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return count; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_loop_to_region_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2013-04-16 05:59:48 +00:00
										 |  |  | 	BMEditMesh *em = BKE_editmesh_from_object(obedit); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMFace *f; | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	const bool select_bigger = RNA_boolean_get(op->ptr, "select_bigger"); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	int a, b; | 
					
						
							| 
									
										
										
										
											2011-10-15 14:47:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* find the set of regions with smallest number of total faces */ | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	a = loop_find_regions(em, select_bigger); | 
					
						
							|  |  |  | 	b = loop_find_regions(em, !select_bigger); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 	if ((a <= b) ^ select_bigger) { | 
					
						
							|  |  |  | 		loop_find_regions(em, select_bigger); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-04-19 13:47:58 +00:00
										 |  |  | 	BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(f, BM_ELEM_TAG) && !BM_elem_flag_test(f, BM_ELEM_HIDDEN)) { | 
					
						
							| 
									
										
										
										
											2013-03-24 12:13:13 +00:00
										 |  |  | 			BM_face_select_set(em->bm, f, true); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-06-27 05:19:25 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_loop_to_region(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Loop Inner-Region"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_loop_to_region"; | 
					
						
							| 
									
										
										
										
											2012-04-15 10:07:57 +00:00
										 |  |  | 	ot->description = "Select region of faces inside of a selected loop of edges"; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_loop_to_region_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "select_bigger", 0, "Select Bigger", "Select bigger regions instead of smaller ones"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-04-01 10:18:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-04 01:23:51 +00:00
										 |  |  | /************************ Select Path Operator *************************/ |