| 
									
										
										
										
											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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.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"
 | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | #include "BLI_heap.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_displist.h"
 | 
					
						
							|  |  |  | #include "BKE_depsgraph.h"
 | 
					
						
							|  |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | #include "BKE_paint.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-11 08:46:56 +00:00
										 |  |  | #include "BKE_tessmesh.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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-11 10:15:11 +00:00
										 |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-11 08:46:56 +00:00
										 |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | #include "mesh_intern.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ****************************** MIRROR **************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | void EDBM_select_mirrored(Object *UNUSED(obedit), BMEditMesh *em, int extend) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 	BMVert *v1, *v2; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2011-05-10 23:48:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 	BM_ITER(v1, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (!BM_elem_flag_test(v1, BM_ELEM_SELECT) || BM_elem_flag_test(v1, BM_ELEM_HIDDEN)) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_disable(v1, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_enable(v1, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EDBM_CacheMirrorVerts(em, TRUE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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
										 |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(v1, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (!BM_elem_flag_test(v1, BM_ELEM_TAG) || BM_elem_flag_test(v1, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		v2 = EDBM_GetMirrorVert(em, v1); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (v2 && !BM_elem_flag_test(v2, BM_ELEM_HIDDEN)) { | 
					
						
							|  |  |  | 			BM_elem_select_set(em->bm, v2, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	EDBM_EndMirrorCache(em); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | void EDBM_automerge(Scene *scene, Object *obedit, int update) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	BMEditMesh *em; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	if ((scene->toolsettings->automerge) && | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	    (obedit && obedit->type == OB_MESH)) | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 		em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 		if (!em) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMO_op_callf(em->bm, "automerge verts=%hv dist=%f", BM_ELEM_SELECT, scene->toolsettings->doublimit); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 		if (update) { | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 			DAG_id_tag_update(obedit->data, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ****************************** SELECTION ROUTINES **************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +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... */ | 
					
						
							| 
									
										
										
										
											2011-05-13 04:04:53 +00:00
										 |  |  | static void draw_triangulated(int mcords[][2], 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; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* 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 */ | 
					
						
							| 
									
										
										
										
											2010-07-19 04:44:37 +00:00
										 |  |  | 	filldisplist(&lb, &lb, 0); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	freedisplist(&lb); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* reads rect, and builds selection array for quick lookup */ | 
					
						
							|  |  |  | /* returns if all is OK */ | 
					
						
							|  |  |  | int EDBM_init_backbuf_border(ViewContext *vc, short xmin, short ymin, short xmax, short ymax) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	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) { | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 	if (buf == NULL) return 0; | 
					
						
							|  |  |  | 	if (bm_vertoffs == 0) return 0; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int EDBM_check_backbuf(unsigned int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (selbuf == NULL) return 1; | 
					
						
							|  |  |  | 	if (index > 0 && index <= bm_vertoffs) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		return selbuf[index]; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EDBM_free_backbuf(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											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'  | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-05-13 04:04:53 +00:00
										 |  |  | int EDBM_mask_init_backbuf_border(ViewContext *vc, 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))) { | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 	if (buf == NULL) return 0; | 
					
						
							|  |  |  | 	if (bm_vertoffs == 0) return 0; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dr = buf->rect; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 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(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	glFinish();	/* to be sure readpixels sees mask */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* grab mask */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	drm = bufmask->rect; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (bufmask == NULL) { | 
					
						
							|  |  |  | 		return 0; /* only when mem alloc fails, go crash somewhere else! */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* circle shaped sample area */ | 
					
						
							|  |  |  | int EDBM_init_backbuf_circle(ViewContext *vc, short xs, short ys, short rads) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	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))) { | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											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) return 0; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +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); | 
					
						
							|  |  |  | 	if (bm_vertoffs == 0) return 0; | 
					
						
							|  |  |  | 	if (buf == NULL) return 0; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void findnearestvert__doClosest(void *userData, BMVert *eve, int x, int y, int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct { short mval[2], pass, select, strict; int dist, lastIndex, closestIndex; BMVert *closest; } *data = userData; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		int temp = abs(data->mval[0] - x) + abs(data->mval[1]- y); | 
					
						
							| 
									
										
										
										
											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 { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				temp += 5; | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (temp < data->dist) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data->dist = temp; | 
					
						
							|  |  |  | 			data->closest = eve; | 
					
						
							|  |  |  | 			data->closestIndex = index; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static unsigned int findnearestvert__backbufIndextest(void *handle, unsigned int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	if (eve && BM_elem_flag_test(eve, BM_ELEM_SELECT)) return 0; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											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-04 04:35:12 +00:00
										 |  |  |  * 		if SELECT, selected vertice are given a 5 pixel bias to make them further than unselect verts | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  |  * 		if 0, unselected vertice are given the bias | 
					
						
							|  |  |  |  * strict: if 1, the vertice corresponding to the sel parameter are ignored and not just biased  | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | BMVert *EDBM_findnearestvert(ViewContext *vc, int *dist, short sel, short strict) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		int distance; | 
					
						
							|  |  |  | 		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
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		eve = BM_vert_at_index(vc->em->bm, index - 1); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (eve && distance < *dist) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			*dist = distance; | 
					
						
							|  |  |  | 			return eve; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		struct { short mval[2], pass, select, strict; int 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; | 
					
						
							|  |  |  | 		data.mval[0] = vc->mval[0]; | 
					
						
							|  |  |  | 		data.mval[1] = vc->mval[1]; | 
					
						
							|  |  |  | 		data.select = sel; | 
					
						
							|  |  |  | 		data.dist = *dist; | 
					
						
							|  |  |  | 		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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-28 17:09:13 +00:00
										 |  |  | 		mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, V3D_CLIP_TEST_RV3D_CLIPPING); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2011-11-28 17:09:13 +00:00
										 |  |  | 			mesh_foreachScreenVert(vc, findnearestvert__doClosest, &data, V3D_CLIP_TEST_RV3D_CLIPPING); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		*dist = data.dist; | 
					
						
							|  |  |  | 		lastSelected = data.closest; | 
					
						
							|  |  |  | 		lastSelectedIndex = data.closestIndex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return data.closest; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | /* returns labda for closest distance v1 to line-piece v2 - v3 */ | 
					
						
							| 
									
										
										
										
											2011-05-11 02:14:43 +00:00
										 |  |  | float labda_PdistVL2Dfl(const float v1[3], const float v2[3], const float v3[3]) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float rc[2], len; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	rc[0] = v3[0] - v2[0]; | 
					
						
							|  |  |  | 	rc[1] = v3[1] - v2[1]; | 
					
						
							|  |  |  | 	len = rc[0] * rc[0] + rc[1] * rc[1]; | 
					
						
							|  |  |  | 	if (len == 0.0f) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		return 0.0f; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 	return (rc[0] * (v1[0] - v2[0]) + rc[1] * (v1[1] - v2[1])) / len; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* note; uses v3d, so needs active 3d window */ | 
					
						
							| 
									
										
										
										
											2011-05-07 02:48:14 +00:00
										 |  |  | static void findnearestedge__doClosest(void *userData, BMEdge *eed, int x0, int y0, int x1, int y1, int UNUSED(index)) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct { ViewContext vc; float mval[2]; int dist; BMEdge *closest; } *data = userData; | 
					
						
							|  |  |  | 	float v1[2], v2[2]; | 
					
						
							|  |  |  | 	int distance; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	v1[0] = x0; | 
					
						
							|  |  |  | 	v1[1] = y0; | 
					
						
							|  |  |  | 	v2[0] = x1; | 
					
						
							|  |  |  | 	v2[1] = y1; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	distance = dist_to_line_segment_v2(data->mval, v1, v2); | 
					
						
							| 
									
										
										
										
											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-02-10 18:09:19 +00:00
										 |  |  | 			float labda = labda_PdistVL2Dfl(data->mval, v1, v2); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			float vec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			vec[0] = eed->v1->co[0] + labda * (eed->v2->co[0] - eed->v1->co[0]); | 
					
						
							|  |  |  | 			vec[1] = eed->v1->co[1] + labda * (eed->v2->co[1] - eed->v1->co[1]); | 
					
						
							|  |  |  | 			vec[2] = eed->v1->co[2] + labda * (eed->v2->co[2] - eed->v1->co[2]); | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 			mul_m4_v3(data->vc.obedit->obmat, vec); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-28 13:03:56 +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; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | BMEdge *EDBM_findnearestedge(ViewContext *vc, int *dist) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (vc->v3d->drawtype > OB_WIRE && (vc->v3d->flag & V3D_ZBUF_SELECT)) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		int 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); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		eed = BM_edge_at_index(vc->em->bm, index - 1); | 
					
						
							| 
									
										
										
										
											2009-11-09 22:47:55 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (eed && distance < *dist) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			*dist = distance; | 
					
						
							|  |  |  | 			return eed; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		struct { ViewContext vc; float mval[2]; int dist; BMEdge *closest; } data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		data.vc = *vc; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		data.mval[0] = vc->mval[0]; | 
					
						
							|  |  |  | 		data.mval[1] = vc->mval[1]; | 
					
						
							|  |  |  | 		data.dist = *dist; | 
					
						
							|  |  |  | 		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
										 |  |  | 
 | 
					
						
							|  |  |  | 		mesh_foreachScreenEdge(vc, findnearestedge__doClosest, &data, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		*dist = data.dist; | 
					
						
							|  |  |  | 		return data.closest; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-07 02:48:14 +00:00
										 |  |  | static void findnearestface__getDistance(void *userData, BMFace *efa, int x, int y, int UNUSED(index)) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct { short mval[2]; int dist; BMFace *toFace; } *data = userData; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (efa == data->toFace) { | 
					
						
							|  |  |  | 		int temp = abs(data->mval[0] - x) + abs(data->mval[1] - y); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (temp < data->dist) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data->dist = temp; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | static void findnearestface__doClosest(void *userData, BMFace *efa, int x, int y, int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct { short mval[2], pass; int dist, lastIndex, closestIndex; BMFace *closest; } *data = userData; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  | 		int temp = abs(data->mval[0] - x) + abs(data->mval[1] - y); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (temp < data->dist) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data->dist = temp; | 
					
						
							|  |  |  | 			data->closest = efa; | 
					
						
							|  |  |  | 			data->closestIndex = index; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | BMFace *EDBM_findnearestface(ViewContext *vc, int *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]); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		efa = BM_face_at_index(vc->em->bm, index - 1); | 
					
						
							| 
									
										
										
										
											2010-09-25 01:54:58 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		if (efa) { | 
					
						
							|  |  |  | 			struct { short mval[2]; int dist; BMFace *toFace; } data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			data.mval[0] = vc->mval[0]; | 
					
						
							|  |  |  | 			data.mval[1] = vc->mval[1]; | 
					
						
							|  |  |  | 			data.dist = 0x7FFF;		/* largest short */ | 
					
						
							|  |  |  | 			data.toFace = efa; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			mesh_foreachScreenFace(vc, findnearestface__getDistance, &data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			if (vc->em->selectmode == SCE_SELECT_FACE || data.dist < *dist) {	/* only faces, no dist check */ | 
					
						
							|  |  |  | 				*dist = data.dist; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				return efa; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		struct { short mval[2], pass; int 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; | 
					
						
							|  |  |  | 		data.mval[0] = vc->mval[0]; | 
					
						
							|  |  |  | 		data.mval[1] = vc->mval[1]; | 
					
						
							|  |  |  | 		data.dist = *dist; | 
					
						
							|  |  |  | 		data.closest = NULL; | 
					
						
							|  |  |  | 		data.closestIndex = 0; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | 		data.pass = 0; | 
					
						
							|  |  |  | 		mesh_foreachScreenFace(vc, findnearestface__doClosest, &data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (data.dist > 3) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			data.pass = 1; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 			mesh_foreachScreenFace(vc, findnearestface__doClosest, &data); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		*dist = data.dist; | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  | 	int dist = 75; | 
					
						
							| 
									
										
										
										
											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-02-28 07:42:48 +00:00
										 |  |  | 		*r_eve = EDBM_findnearestvert(vc, &dist, BM_ELEM_SELECT, 0); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_FACE) | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 		*r_efa = EDBM_findnearestface(vc, &dist); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +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-02-28 07:42:48 +00:00
										 |  |  | 		*r_eed = EDBM_findnearestedge(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 ************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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", ""}, | 
					
						
							| 
									
										
										
										
											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", ""}, | 
					
						
							|  |  |  | 	{SIMEDGE_SEAM, "SEAM", 0, "Seam", ""}, | 
					
						
							|  |  |  | 	{SIMEDGE_SHARP, "SHARP", 0, "Sharpness", ""}, | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	{SIMFACE_MATERIAL, "MATERIAL", 0, "Material", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_IMAGE, "IMAGE", 0, "Image", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_AREA, "AREA", 0, "Area", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_PERIMETER, "PERIMETER", 0, "Perimeter", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_NORMAL, "NORMAL", 0, "Normal", ""}, | 
					
						
							|  |  |  | 	{SIMFACE_COPLANAR, "COPLANAR", 0, "Co-planar", ""}, | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(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 */ | 
					
						
							|  |  |  | 	int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2012-03-21 07:49:05 +00:00
										 |  |  | 	float thresh = RNA_float_get(op->ptr, "threshold"); | 
					
						
							| 
									
										
										
										
											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-02-20 01:52:35 +00:00
										 |  |  | 	EDBM_InitOpf(em, &bmop, op, "similarfaces faces=%hf type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faceout", BM_ALL, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	if (!EDBM_FinishOp(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
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* dependencies graph and notification stuff */ | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	DAG_id_tag_update(ob->data, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); | 
					
						
							| 
									
										
										
										
											2009-08-22 04:45:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* we succeeded */ | 
					
						
							|  |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* get the type from RNA */ | 
					
						
							|  |  |  | 	int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2012-03-21 07:49:05 +00:00
										 |  |  | 	float thresh = RNA_float_get(op->ptr, "threshold"); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 	EDBM_InitOpf(em, &bmop, op, "similaredges edges=%he type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "edgeout", BM_ALL, 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 */ | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	if (!EDBM_FinishOp(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
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* dependencies graph and notification stuff */ | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	DAG_id_tag_update(ob->data, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); | 
					
						
							| 
									
										
										
										
											2009-08-28 09:36:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* we succeeded */ | 
					
						
							|  |  |  | 	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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	/* get the type from RNA */ | 
					
						
							|  |  |  | 	int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2012-03-21 07:49:05 +00:00
										 |  |  | 	float thresh = RNA_float_get(op->ptr, "threshold"); | 
					
						
							| 
									
										
										
										
											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-02-20 01:52:35 +00:00
										 |  |  | 	EDBM_InitOpf(em, &bmop, op, "similarverts verts=%hv type=%i thresh=%f", BM_ELEM_SELECT, type, thresh); | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "vertout", BM_ALL, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	if (!EDBM_FinishOp(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
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* dependencies graph and notification stuff */ | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	DAG_id_tag_update(ob->data, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:59:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* we succeeded */ | 
					
						
							|  |  |  | 	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-02-10 18:09:19 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 	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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	Object *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; | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 		BMEditMesh *em = BMEdit_FromObject(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-02-10 18:09:19 +00:00
										 |  |  | 			for (a = SIMFACE_MATERIAL; a <= SIMFACE_COPLANAR; 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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	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"; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	ot->description = "Select similar vertices, edges or faces by property types"; | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +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
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "threshold", 0.0, 0.0, 1.0, "Threshold", "", 0.01, 1.0); | 
					
						
							| 
									
										
										
										
											2009-08-18 20:05:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | /* ***************************************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ****************  LOOP SELECTS *************** */ | 
					
						
							| 
									
										
										
										
											2009-07-29 00:43:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-16 21:33:12 +00:00
										 |  |  | static void walker_select(BMEditMesh *em, int walkercode, void *start, int 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-02-06 05:18:08 +00:00
										 |  |  | 	         BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							|  |  |  | 	         BMW_NIL_LAY); | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 	ele = BMW_begin(&walker, start); | 
					
						
							|  |  |  | 	for ( ; 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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMEdge **edarray; | 
					
						
							| 
									
										
										
										
											2011-06-26 01:11:03 +00:00
										 |  |  | 	int edindex; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int looptype = 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-02-12 10:51:45 +00:00
										 |  |  | 	for (eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); | 
					
						
							|  |  |  | 	    eed; eed = BM_iter_step(&iter)) { | 
					
						
							| 
									
										
										
										
											2011-06-26 01:11:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-02-12 10:51:45 +00:00
										 |  |  | 	for (eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	     eed; | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	     eed = BM_iter_step(&iter)) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-06-26 01:11:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (looptype) { | 
					
						
							| 
									
										
										
										
											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]; | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +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]; | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +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())
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +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"; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	ot->description = "Select a loop of connected edges by connection type"; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +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) ************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-13 04:04:53 +00:00
										 |  |  | static void mouse_mesh_loop(bContext *C, int mval[2], short extend, short 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; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int select = TRUE; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	int dist = 50; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	vc.mval[0] = mval[0]; | 
					
						
							|  |  |  | 	vc.mval[1] = mval[1]; | 
					
						
							|  |  |  | 	em = vc.em; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	eed = EDBM_findnearestedge(&vc, &dist); | 
					
						
							|  |  |  | 	if (eed) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (extend == 0) { | 
					
						
							| 
									
										
										
										
											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-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(eed, BM_ELEM_SELECT) == 0) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			select = TRUE; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (extend) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +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); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | //			if (EM_texFaceCheck())
 | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  | 				/* TODO: would be nice if the edge vertex chosen here
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				 * was the one closer to the selection pointer, instead | 
					
						
							|  |  |  | 				 * of arbitrarily selecting the first one */ | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 				EDBM_store_selection(em, eed->v1); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 				EDBM_store_selection(em, eed); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* TODO: would be nice if the nearest face that
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			 * belongs to the selected edge could be set to | 
					
						
							|  |  |  | 			 * active here in face select mode */ | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_loop_invoke(bContext *C, wmOperator *op, wmEvent *event) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	view3d_operator_needs_opengl(C); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	mouse_mesh_loop(C, event->mval, RNA_boolean_get(op->ptr, "extend"), | 
					
						
							|  |  |  | 					RNA_boolean_get(op->ptr, "ring")); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* 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"; | 
					
						
							|  |  |  | 	ot->description = "Select a loop"; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	ot->description = "Select a loop of connected edges"; | 
					
						
							| 
									
										
										
										
											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"); | 
					
						
							|  |  |  | 	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"); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "ring", 1, "Select Ring", "Select ring"); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | /* ******************* edgetag_shortest_path and helpers ****************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | static float edgetag_cut_cost(BMEditMesh *UNUSED(em), BMEdge *e1, BMEdge *e2, BMVert *v) | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMVert *v1 = (e1->v1 == v) ? e1->v2 : e1->v1; | 
					
						
							|  |  |  | 	BMVert *v2 = (e2->v1 == v) ? e2->v2 : e2->v1; | 
					
						
							|  |  |  | 	float cost, d1[3], d2[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* The cost is based on the simple sum of the length of the two edgees... */ | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	sub_v3_v3v3(d1, v->co, v1->co); | 
					
						
							|  |  |  | 	sub_v3_v3v3(d2, v2->co, v->co); | 
					
						
							|  |  |  | 	cost = len_v3(d1); | 
					
						
							|  |  |  | 	cost += len_v3(d2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 	/* but is biased to give higher values to sharp turns, so that it will take
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	 * paths with fewer "turns" when selecting between equal-weighted paths between | 
					
						
							|  |  |  | 	 * the two edges */ | 
					
						
							|  |  |  | 	cost = cost + 0.5f * cost * (2.0f - sqrt(fabs(dot_v3v3(d1, d2)))); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return cost; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void edgetag_add_adjacent(BMEditMesh *em, SmallHash *visithash, Heap *heap, int mednum, int vertnum,  | 
					
						
							|  |  |  | 								 int *nedges, int *edges, int *prevedge, float *cost) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMEdge *e1 = EDBM_get_edge_for_index(em, mednum); | 
					
						
							|  |  |  | 	BMVert *v = EDBM_get_vert_for_index(em, vertnum); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int startadj, endadj = nedges[vertnum + 1]; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (startadj = nedges[vertnum]; startadj < endadj; startadj++) { | 
					
						
							|  |  |  | 		int adjnum = edges[startadj]; | 
					
						
							|  |  |  | 		BMEdge *e2 = EDBM_get_edge_for_index(em, adjnum); | 
					
						
							|  |  |  | 		float newcost; | 
					
						
							|  |  |  | 		float cutcost; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (BLI_smallhash_haskey(visithash, (uintptr_t)e2)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		cutcost = edgetag_cut_cost(em, e1, e2, v); | 
					
						
							|  |  |  | 		newcost = cost[mednum] + cutcost; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (cost[adjnum] > newcost) { | 
					
						
							|  |  |  | 			cost[adjnum] = newcost; | 
					
						
							|  |  |  | 			prevedge[adjnum] = mednum; | 
					
						
							|  |  |  | 			BLI_heap_insert(heap, newcost, SET_INT_IN_POINTER(adjnum)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void edgetag_context_set(BMEditMesh *em, Scene *scene, BMEdge *e, int val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	switch (scene->toolsettings->edge_mode) { | 
					
						
							|  |  |  | 	case EDGE_MODE_SELECT: | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BM_elem_select_set(em->bm, e, val); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case EDGE_MODE_TAG_SEAM: | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 		BM_elem_flag_set(e, BM_ELEM_SEAM, val); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case EDGE_MODE_TAG_SHARP: | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 		BM_elem_flag_set(e, BM_ELEM_SMOOTH, !val); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	case EDGE_MODE_TAG_CREASE: | 
					
						
							|  |  |  | 	 { | 
					
						
							|  |  |  | 		float *crease = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_CREASE); | 
					
						
							| 
									
										
										
										
											2012-03-20 04:27:14 +00:00
										 |  |  | 		*crease = (val) ? 1.0f : 0.0f; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  | 	case EDGE_MODE_TAG_BEVEL: | 
					
						
							|  |  |  | 	 { | 
					
						
							|  |  |  | 		float *bweight = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_BWEIGHT); | 
					
						
							| 
									
										
										
										
											2012-03-20 04:27:14 +00:00
										 |  |  | 		*bweight = (val) ? 1.0f : 0.0f; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int edgetag_context_check(Scene *scene, BMEditMesh *em, BMEdge *e) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	switch (scene->toolsettings->edge_mode) { | 
					
						
							|  |  |  | 	case EDGE_MODE_SELECT: | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		return BM_elem_flag_test(e, BM_ELEM_SELECT) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	case EDGE_MODE_TAG_SEAM: | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		return BM_elem_flag_test(e, BM_ELEM_SEAM); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	case EDGE_MODE_TAG_SHARP: | 
					
						
							| 
									
										
										
										
											2012-02-18 11:44:30 +00:00
										 |  |  | 		return !BM_elem_flag_test(e, BM_ELEM_SMOOTH); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	case EDGE_MODE_TAG_CREASE:	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		return BM_elem_float_data_get(&em->bm->edata, e, CD_CREASE) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	case EDGE_MODE_TAG_BEVEL: | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		return BM_elem_float_data_get(&em->bm->edata, e, CD_BWEIGHT) ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int edgetag_shortest_path(Scene *scene, BMEditMesh *em, BMEdge *source, BMEdge *target) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	Heap *heap; | 
					
						
							|  |  |  | 	SmallHash visithash; | 
					
						
							|  |  |  | 	float *cost; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int i, totvert = 0, totedge = 0, *nedges, *edges, *prevedge, mednum = -1, nedgeswap = 0; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	int targetnum; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BLI_smallhash_init(&visithash); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-16 12:38:40 +00:00
										 |  |  | 	/* note, would pass BM_EDGE except we are looping over all edges anyway */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BM_mesh_elem_index_ensure(em->bm, BM_VERT /* | BM_EDGE */); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-16 16:44:10 +00:00
										 |  |  | 		e->oflags[0].f = 0; /* XXX, whats this for, BMESH_TODO, double check if this is needed */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 			BLI_smallhash_insert(&visithash, (uintptr_t)e, NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-11-16 12:38:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BM_elem_index_set(e, totedge); /* set_inline */ | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		totedge++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-11-16 12:38:40 +00:00
										 |  |  | 	em->bm->elem_index_dirty &= ~BM_EDGE; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* alloc */ | 
					
						
							| 
									
										
										
										
											2011-12-08 12:53:43 +00:00
										 |  |  | 	totvert = em->bm->totvert; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	nedges = MEM_callocN(sizeof(*nedges) * totvert + 1, "SeamPathNEdges"); | 
					
						
							|  |  |  | 	edges = MEM_mallocN(sizeof(*edges) * totedge * 2, "SeamPathEdges"); | 
					
						
							|  |  |  | 	prevedge = MEM_mallocN(sizeof(*prevedge) * totedge, "SeamPathPrevious"); | 
					
						
							|  |  |  | 	cost = MEM_mallocN(sizeof(*cost) * totedge, "SeamPathCost"); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* count edges, compute adjacent edges offsets and fill adjacent */ | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		nedges[BM_elem_index_get(e->v1) + 1]++; | 
					
						
							|  |  |  | 		nedges[BM_elem_index_get(e->v2) + 1]++; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 1; i < totvert; i++) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		int newswap = nedges[i + 1]; | 
					
						
							|  |  |  | 		nedges[i + 1] = nedgeswap + nedges[i]; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		nedgeswap = newswap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	nedges[0] = nedges[1] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	i = 0; | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		edges[nedges[BM_elem_index_get(e->v1) + 1]++] = i; | 
					
						
							|  |  |  | 		edges[nedges[BM_elem_index_get(e->v2) + 1]++] = i; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		cost[i] = 1e20f; | 
					
						
							|  |  |  | 		prevedge[i] = -1; | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Arrays are now filled as follows: | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2012-03-09 00:41:09 +00:00
										 |  |  | 	 *	nedges[n] = sum of the # of edges incident to all vertices numbered 0 through n - 1 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	 *	edges[edges[n]..edges[n - 1]] = the indices of of the edges incident to vertex n | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	 * | 
					
						
							|  |  |  | 	 * As the search continues, prevedge[n] will be the previous edge on the shortest | 
					
						
							|  |  |  | 	 * path found so far to edge n. The visitedhash will of course contain entries | 
					
						
							|  |  |  | 	 * for edges that have been visited, cost[n] will contain the length of the shortest | 
					
						
							|  |  |  | 	 * path to edge n found so far, Finally, heap is a priority heap which is built on the | 
					
						
							|  |  |  | 	 * the same data as the cost arry, but inverted: it is a worklist of edges prioritized | 
					
						
							|  |  |  | 	 * by the shortest path found so far to the edge. | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-07 06:49:20 +00:00
										 |  |  | #if 0 /* UNUSED */ /* this block does nothing, not sure why its here? - campbell */
 | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	for (i = 0; i < totvert; i++) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		int start = nedges[i], end = nedges[i + 1], cur; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		for (cur = start; cur < end; cur++) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			BMEdge *e = EDBM_get_edge_for_index(em, edges[cur]); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-09-07 06:49:20 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* regular dijkstra shortest path, but over edges instead of vertices */ | 
					
						
							|  |  |  | 	heap = BLI_heap_new(); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BLI_heap_insert(heap, 0.0f, SET_INT_IN_POINTER(BM_elem_index_get(source))); | 
					
						
							|  |  |  | 	cost[BM_elem_index_get(source)] = 0.0f; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	EDBM_init_index_arrays(em, 1, 1, 0); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	targetnum = BM_elem_index_get(target); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (!BLI_heap_empty(heap)) { | 
					
						
							|  |  |  | 		mednum = GET_INT_FROM_POINTER(BLI_heap_popmin(heap)); | 
					
						
							|  |  |  | 		e = EDBM_get_edge_for_index(em, mednum); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (mednum == targetnum) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (BLI_smallhash_haskey(&visithash, (uintptr_t)e)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BLI_smallhash_insert(&visithash, (uintptr_t)e, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		edgetag_add_adjacent(em, &visithash, heap, mednum, BM_elem_index_get(e->v1), nedges, edges, prevedge, cost); | 
					
						
							|  |  |  | 		edgetag_add_adjacent(em, &visithash, heap, mednum, BM_elem_index_get(e->v2), nedges, edges, prevedge, cost); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (mednum == targetnum) { | 
					
						
							|  |  |  | 		short allseams = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* Check whether the path is already completely tagged.
 | 
					
						
							|  |  |  | 		 * if it is, the tags will be cleared instead of set. */ | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		mednum = targetnum; | 
					
						
							|  |  |  | 		do { | 
					
						
							|  |  |  | 			e = EDBM_get_edge_for_index(em, mednum); | 
					
						
							|  |  |  | 			if (!edgetag_context_check(scene, em, e)) { | 
					
						
							|  |  |  | 				allseams = 0; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			mednum = prevedge[mednum]; | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		} while (mednum != BM_elem_index_get(source)); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* Follow path back and source and add or remove tags */ | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 		mednum = targetnum; | 
					
						
							|  |  |  | 		do { | 
					
						
							|  |  |  | 			e = EDBM_get_edge_for_index(em, mednum); | 
					
						
							|  |  |  | 			if (allseams) | 
					
						
							|  |  |  | 				edgetag_context_set(em, scene, e, 0); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				edgetag_context_set(em, scene, e, 1); | 
					
						
							|  |  |  | 			mednum = prevedge[mednum]; | 
					
						
							|  |  |  | 		} while (mednum != -1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	EDBM_free_index_arrays(em); | 
					
						
							|  |  |  | 	MEM_freeN(nedges); | 
					
						
							|  |  |  | 	MEM_freeN(edges); | 
					
						
							|  |  |  | 	MEM_freeN(prevedge); | 
					
						
							|  |  |  | 	MEM_freeN(cost); | 
					
						
							|  |  |  | 	BLI_heap_free(heap, NULL); | 
					
						
							|  |  |  | 	BLI_smallhash_release(&visithash); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | /* ******************* mesh shortest path select, uses prev-selected edge ****************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* since you want to create paths with multiple selects, it doesn't have extend option */ | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | static void mouse_mesh_shortest_path(bContext *C, int mval[2]) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	ViewContext vc; | 
					
						
							| 
									
										
										
										
											2009-05-18 08:46:04 +00:00
										 |  |  | 	BMEditMesh *em; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 	BMEdge *e; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int dist = 50; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	vc.mval[0] = mval[0]; | 
					
						
							|  |  |  | 	vc.mval[1] = mval[1]; | 
					
						
							|  |  |  | 	em = vc.em; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	e = EDBM_findnearestedge(&vc, &dist); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (e) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		Mesh *me = vc.obedit->data; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		int path = 0; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-07-17 10:54:00 +00:00
										 |  |  | 		if (em->bm->selected.last) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			BMEditSelection *ese = em->bm->selected.last; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if (ese && ese->htype == BM_EDGE) { | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 				BMEdge *e_act; | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 				e_act = (BMEdge *)ese->ele; | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 				if (e_act != e) { | 
					
						
							|  |  |  | 					if (edgetag_shortest_path(vc.scene, em, e_act, e)) { | 
					
						
							|  |  |  | 						EDBM_remove_selection(em, e_act); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 						path = 1; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (path == 0) { | 
					
						
							|  |  |  | 			int act = (edgetag_context_check(vc.scene, em, e) == 0); | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 			edgetag_context_set(em, vc.scene, e, act); /* switch the edge option */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* even if this is selected it may not be in the selection list */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (edgetag_context_check(vc.scene, em, e) == 0) | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 			EDBM_remove_selection(em, e); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2011-09-06 03:32:58 +00:00
										 |  |  | 			EDBM_store_selection(em, e); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 		/* force drawmode for mesh */ | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 		switch (CTX_data_tool_settings(C)->edge_mode) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			case EDGE_MODE_TAG_SEAM: | 
					
						
							|  |  |  | 				me->drawflag |= ME_DRAWSEAMS; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case EDGE_MODE_TAG_SHARP: | 
					
						
							|  |  |  | 				me->drawflag |= ME_DRAWSHARP; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case EDGE_MODE_TAG_CREASE:	 | 
					
						
							|  |  |  | 				me->drawflag |= ME_DRAWCREASES; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case EDGE_MODE_TAG_BEVEL: | 
					
						
							|  |  |  | 				me->drawflag |= ME_DRAWBWEIGHTS; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		DAG_id_tag_update(ob->data, OB_RECALC_DATA); | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_shortest_path_select_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	view3d_operator_needs_opengl(C); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mouse_mesh_shortest_path(C, event->mval); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-05-23 03:24:15 +00:00
										 |  |  | void MESH_OT_select_shortest_path(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Shortest Path Select"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_shortest_path"; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_shortest_path_select_invoke; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 	ot->description = "Select shortest path between two selections"; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************** */ | 
					
						
							|  |  |  | /* here actual select happens */ | 
					
						
							|  |  |  | /* gets called via generic mouse select operator */ | 
					
						
							| 
									
										
										
										
											2011-05-13 04:04:53 +00:00
										 |  |  | int mouse_mesh(bContext *C, const int mval[2], short extend) | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											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]; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (unified_findnearest(&vc, &eve, &eed, &efa)) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		if (extend == 0) EDBM_flag_disable_all(vc.em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (efa) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			/* set the last selected face */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_active_face_set(vc.em->bm, efa); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				EDBM_store_selection(vc.em, efa); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(vc.em->bm, efa, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			else if (extend) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				EDBM_remove_selection(vc.em, efa); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(vc.em->bm, efa, FALSE); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		else if (eed) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 				EDBM_store_selection(vc.em, eed); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(vc.em->bm, eed, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			else if (extend) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				EDBM_remove_selection(vc.em, eed); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(vc.em->bm, eed, FALSE); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		else if (eve) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				EDBM_store_selection(vc.em, eve); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(vc.em->bm, eve, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			else if (extend) { | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 				EDBM_remove_selection(vc.em, eve); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(vc.em->bm, eve, FALSE); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush(vc.em); | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 		   | 
					
						
							|  |  |  | //		if (EM_texFaceCheck()) {
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | //			BIF_preview_changed(ID_MA);
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2009-05-16 16:18:08 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void EDBM_strip_selections(BMEditMesh *em) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	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-02-10 18:09:19 +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
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-02-10 03:03:42 +00:00
										 |  |  | 		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 */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); | 
					
						
							|  |  |  | 		for ( ; eve; eve = BM_iter_step(&iter)) BM_elem_select_set(em->bm, eve, FALSE); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); | 
					
						
							|  |  |  | 		for ( ; eed; eed = BM_iter_step(&iter)) { | 
					
						
							|  |  |  | 			if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 				BM_elem_select_set(em->bm, eed, TRUE); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* selects faces based on edge status */ | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		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 */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); | 
					
						
							|  |  |  | 		for ( ; eed; eed = BM_iter_step(&iter)) BM_elem_select_set(em->bm, eed, FALSE); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); | 
					
						
							|  |  |  | 		for ( ; efa; efa = BM_iter_step(&iter)) { | 
					
						
							|  |  |  | 			if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 				BM_elem_select_set(em->bm, efa, TRUE); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EDBM_convertsel(BMEditMesh *em, short oldmode, short selectmode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* have to find out what the selectionmode was previously */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (oldmode == SCE_SELECT_VERTEX) { | 
					
						
							|  |  |  | 		if (selectmode == SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			/* select all edges associated with every selected vertex */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); | 
					
						
							|  |  |  | 			for ( ; eed; eed = BM_iter_step(&iter)) { | 
					
						
							|  |  |  | 				if ( (BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) || | 
					
						
							|  |  |  | 				      BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))) | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 					BM_elem_select_set(em->bm, eed, TRUE); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}		 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		else if (selectmode == SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			BMIter liter; | 
					
						
							|  |  |  | 			BMLoop *l; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			/* select all faces associated with every selected vertex */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); | 
					
						
							|  |  |  | 			for ( ; efa; efa = BM_iter_step(&iter)) { | 
					
						
							|  |  |  | 				l = BM_iter_new(&liter, em->bm, BM_LOOPS_OF_FACE, efa); | 
					
						
							|  |  |  | 				for (; l; l = BM_iter_step(&liter)) { | 
					
						
							|  |  |  | 					if (BM_elem_flag_test(l->v, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 						BM_elem_select_set(em->bm, efa, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (oldmode == SCE_SELECT_EDGE) { | 
					
						
							|  |  |  | 		if (selectmode == SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 			BMIter liter; | 
					
						
							|  |  |  | 			BMLoop *l; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			/* select all faces associated with every selected vertex */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); | 
					
						
							|  |  |  | 			for ( ; efa; efa = BM_iter_step(&iter)) { | 
					
						
							|  |  |  | 				l = BM_iter_new(&liter, em->bm, BM_LOOPS_OF_FACE, efa); | 
					
						
							|  |  |  | 				for (; l; l = BM_iter_step(&liter)) { | 
					
						
							|  |  |  | 					if (BM_elem_flag_test(l->v, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 						BM_elem_select_set(em->bm, efa, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_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) { | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_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) { | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, eed, !BM_elem_flag_test(eed, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, efa, !BM_elem_flag_test(efa, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | //	if (EM_texFaceCheck())
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-28 19:30:44 +00:00
										 |  |  | int 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; | 
					
						
							|  |  |  | 	int ok; | 
					
						
							|  |  |  | 	int change = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							|  |  |  | 		if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ok = TRUE; | 
					
						
							|  |  |  | 		BM_ITER(eed, &eiter, bm, BM_EDGES_OF_FACE, efa) { | 
					
						
							|  |  |  | 			if (BM_edge_face_count(eed) < 3) { | 
					
						
							|  |  |  | 				ok = FALSE; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (ok) { | 
					
						
							|  |  |  | 			BM_elem_select_set(bm, efa, TRUE); | 
					
						
							|  |  |  | 			change = TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return change; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 		BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (em->selectmode == SCE_SELECT_FACE) | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 			RNA_boolean_set(op->ptr, "limit", TRUE); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			RNA_boolean_set(op->ptr, "limit", FALSE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, 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) { | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +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-02-25 19:43:51 +00:00
										 |  |  | 			/* hflag no-seam --> bmo-tag */ | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 			BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 				/* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ | 
					
						
							|  |  |  | 				BMO_elem_flag_set(bm, e, BM_ELEM_SELECT, !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, | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 		         BMW_MASK_NOP, limit ? BM_ELEM_SELECT : BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		e = BMW_begin(&walker, efa); | 
					
						
							|  |  |  | 		for (; efa; efa = BMW_step(&walker)) { | 
					
						
							|  |  |  | 			BM_elem_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-02-06 05:18:08 +00:00
										 |  |  | 		         BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							|  |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		e = BMW_begin(&walker, eed->v1); | 
					
						
							|  |  |  | 		for ( ; e; e = BMW_step(&walker)) { | 
					
						
							|  |  |  | 			BM_elem_select_set(bm, e, 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
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											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"; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2012-02-27 18:14:56 +00:00
										 |  |  | 	ot->description = "(De)select all vertices linked to the edge under the mouse cursor"; | 
					
						
							| 
									
										
										
										
											2009-08-01 00:53:04 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +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
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_linked_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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMWalker walker; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 	int limit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	linked_limit_default(C, op); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	limit = RNA_boolean_get(op->ptr, "limit"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 	if (em->selectmode == SCE_SELECT_FACE) { | 
					
						
							|  |  |  | 		BMFace *efa; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 			BM_elem_flag_set(efa, BM_ELEM_TAG, (BM_elem_flag_test(efa, BM_ELEM_SELECT) && | 
					
						
							|  |  |  | 			                                    !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 		if (limit) { | 
					
						
							|  |  |  | 			BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 				/* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ | 
					
						
							|  |  |  | 				BMO_elem_flag_set(bm, e, BM_ELEM_SELECT, !BM_elem_flag_test(e, BM_ELEM_SEAM)); | 
					
						
							| 
									
										
										
										
											2012-02-09 01:53:14 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_init(&walker, bm, BMW_ISLAND, | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 		         BMW_MASK_NOP, limit ? BM_ELEM_SELECT : BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(efa, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 				e = BMW_begin(&walker, efa); | 
					
						
							|  |  |  | 				for (; efa; efa = BMW_step(&walker)) { | 
					
						
							|  |  |  | 					BM_elem_select_set(bm, efa, TRUE); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_end(&walker); | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 	else  { | 
					
						
							|  |  |  | 		BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-03-02 10:49:15 +00:00
										 |  |  | 			if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BM_elem_flag_enable(v, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BM_elem_flag_disable(v, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_init(&walker, em->bm, BMW_SHELL, | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		         BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							|  |  |  | 		         BMW_NIL_LAY); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 		BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(v, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 				e = BMW_begin(&walker, v); | 
					
						
							|  |  |  | 				for (; e; e = BMW_step(&walker)) { | 
					
						
							|  |  |  | 					BM_elem_select_set(em->bm, e->v1, TRUE); | 
					
						
							|  |  |  | 					BM_elem_select_set(em->bm, e->v2, TRUE); | 
					
						
							| 
									
										
										
										
											2011-11-24 01:33:41 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_end(&walker); | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_linked(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Linked All"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_linked"; | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_linked_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 	ot->description = "Select all vertices linked to the active mesh"; | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-05 02:34:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "limit", 0, "Limit by Seams", ""); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +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-02-10 18:09:19 +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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +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-02-10 18:09:19 +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-02-10 18:09:19 +00:00
										 |  |  | 	short mask_vert = 0, mask_edge = 0, mask_loop = 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) { | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	case BM_VERT: | 
					
						
							|  |  |  | 		itertype = BM_VERTS_OF_MESH; | 
					
						
							|  |  |  | 		walktype = BMW_CONNECTED_VERTEX; | 
					
						
							|  |  |  | 		flushtype = SCE_SELECT_VERTEX; | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 		mask_vert = BM_ELEM_SELECT; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case BM_EDGE: | 
					
						
							|  |  |  | 		itertype = BM_EDGES_OF_MESH; | 
					
						
							|  |  |  | 		walktype = BMW_SHELL; | 
					
						
							|  |  |  | 		flushtype = SCE_SELECT_EDGE; | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 		mask_edge = BM_ELEM_SELECT; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case BM_FACE: | 
					
						
							|  |  |  | 		itertype = BM_FACES_OF_MESH; | 
					
						
							|  |  |  | 		walktype = BMW_ISLAND; | 
					
						
							|  |  |  | 		flushtype = SCE_SELECT_FACE; | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 		mask_face = BM_ELEM_SELECT; | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2011-09-26 00:32:45 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-02-25 22:23:40 +00:00
										 |  |  | 	BM_ITER(ele, &iter, bm, itertype, NULL) { | 
					
						
							|  |  |  | 		if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 			/* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 			BMO_elem_flag_enable(bm, (BMElemF *)ele, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											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-02-06 05:18:08 +00:00
										 |  |  | 	         mask_vert, mask_edge, mask_loop, mask_face, | 
					
						
							|  |  |  | 	         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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)) { | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 		/* Deselect elements that aren't at "nth" depth from active */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if ((offset + BMW_current_depth(&walker)) % nth) { | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 			BM_elem_select_set(bm, ele, FALSE); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMEditSelection *ese; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ese = (BMEditSelection *)em->bm->selected.last; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (ese) { | 
					
						
							| 
									
										
										
										
											2011-11-01 14:36:23 +00:00
										 |  |  | 		switch(ese->htype) { | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		case BM_VERT: | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 			*r_eve = (BMVert *)ese->ele; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		case BM_EDGE: | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 			*r_eed = (BMEdge *)ese->ele; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		case BM_FACE: | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 			*r_efa = (BMFace *)ese->ele; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		f = BM_active_face_get(em->bm, TRUE); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (f) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | static int EM_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); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int nth = RNA_int_get(op->ptr, "nth"); | 
					
						
							|  |  |  | 	int offset = RNA_int_get(op->ptr, "offset"); | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	offset = MIN2(nth, offset); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (EM_deselect_nth(em, nth, offset) == 0) { | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DAG_id_tag_update(obedit->data, OB_RECALC_DATA); | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_nth(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Nth"; | 
					
						
							|  |  |  | 	ot->description = ""; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_nth"; | 
					
						
							| 
									
										
										
										
											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-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "nth", 2, 2, 100, "Nth Selection", "", 1, INT_MAX); | 
					
						
							| 
									
										
										
										
											2011-09-26 03:38:30 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "offset", 0, 0, 100, "Offset", "", 0, INT_MAX); | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		Mesh *me = vc->obedit->data; | 
					
						
							|  |  |  | 		vc->em = me->edit_btmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* poll call for mesh operators requiring a view3d context */ | 
					
						
							|  |  |  | int EM_view3d_poll(bContext *C) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (ED_operator_editmesh(C) && ED_operator_view3d_active(C)) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMLoop *l1, *l2; | 
					
						
							|  |  |  | 	float sharp = RNA_float_get(op->ptr, "sharpness"), angle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-29 01:05:35 +00:00
										 |  |  | 	sharp = DEG2RADF(sharp); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(e, BM_ELEM_HIDDEN) || !e->l) | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 22:06:10 +00:00
										 |  |  | 		l1 = e->l; | 
					
						
							|  |  |  | 		l2 = l1->radial_next; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (l1 == l2) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* edge has exactly two neighboring faces, check angle */ | 
					
						
							| 
									
										
										
										
											2012-02-10 07:55:33 +00:00
										 |  |  | 		angle = angle_normalized_v3v3(l1->f->no, l2->f->no); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 07:55:33 +00:00
										 |  |  | 		if (fabsf(angle) > sharp) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, e, TRUE); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_edges_select_sharp(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Sharp Edges"; | 
					
						
							|  |  |  | 	ot->description = "Marked selected edges as sharp"; | 
					
						
							|  |  |  | 	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-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "sharpness", 1.0f, 0.01f, FLT_MAX, "sharpness", "", 1.0f, 180.0f); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMIter iter, liter, liter2; | 
					
						
							|  |  |  | 	BMFace *f, **stack = NULL; | 
					
						
							|  |  |  | 	BLI_array_declare(stack); | 
					
						
							|  |  |  | 	BMLoop *l, *l2; | 
					
						
							|  |  |  | 	float sharp = RNA_float_get(op->ptr, "sharpness"); | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sharp = (sharp * M_PI) / 180.0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(f, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		BM_elem_flag_disable(f, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(f, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(f, BM_ELEM_HIDDEN) || !BM_elem_flag_test(f, BM_ELEM_SELECT) || BM_elem_flag_test(f, BM_ELEM_TAG)) | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BLI_array_empty(stack); | 
					
						
							|  |  |  | 		i = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BLI_array_growone(stack); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		stack[i - 1] = f; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		while (i) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			f = stack[i - 1]; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 			i--; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->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
										 |  |  | 
 | 
					
						
							|  |  |  | 			BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, f) { | 
					
						
							|  |  |  | 				BM_ITER(l2, &liter2, em->bm, BM_LOOPS_OF_LOOP, l) { | 
					
						
							|  |  |  | 					float angle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					/* edge has exactly two neighboring faces, check angle */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  | 					/* invalidate: edge too sharp */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 					if (angle < sharp) { | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 						BLI_array_growone(stack); | 
					
						
							|  |  |  | 						stack[i] = l2->f; | 
					
						
							|  |  |  | 						i++; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BLI_array_free(stack); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_faces_select_linked_flat(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* 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-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "sharpness", 1.0f, 0.01f, FLT_MAX, "sharpness", "", 1.0f, 180.0f); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* 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) { | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "Doesn't work in face selection mode"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-03-22 07:53:11 +00:00
										 |  |  | 		if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN) && !BM_vert_is_manifold(v)) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, v, TRUE); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 		if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && BM_edge_face_count(e) != 2) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, e, TRUE); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	float randfac =  RNA_float_get(op->ptr, "percent") / 100.0f; | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	BLI_srand(BLI_rand()); /* random seed */ | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BLI_frand() < randfac) { | 
					
						
							|  |  |  | 				BM_elem_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) { | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 		BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BLI_frand() < randfac) { | 
					
						
							|  |  |  | 				BM_elem_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 { | 
					
						
							|  |  |  | 		BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) && BLI_frand() < randfac) { | 
					
						
							|  |  |  | 				BM_elem_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
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											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-02-10 18:09:19 +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); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", 0, | 
					
						
							|  |  |  | 	                "Extend Selection", "Extend selection instead of deselecting everything first"); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		BM_elem_flag_disable(v, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(f, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							|  |  |  | 		BMLoop *l; | 
					
						
							|  |  |  | 		BMIter liter; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, f) { | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(em->bm, l->v, FALSE); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(v, BM_ELEM_TAG)) { | 
					
						
							|  |  |  | 			BM_elem_select_set(em->bm, v, TRUE); | 
					
						
							| 
									
										
										
										
											2011-03-27 02:56:41 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit); | 
					
						
							|  |  |  | 	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"; | 
					
						
							|  |  |  | 	ot->description = ""; | 
					
						
							| 
									
										
										
										
											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-02-10 18:09:19 +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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2011-10-15 14:47:37 +00:00
										 |  |  | 	ViewContext vc; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		BM_elem_flag_disable(e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(f, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							|  |  |  | 		BMLoop *l1, *l2; | 
					
						
							|  |  |  | 		BMIter liter1, liter2; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		BM_ITER(l1, &liter1, em->bm, BM_LOOPS_OF_FACE, f) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			int tot = 0, totsel = 0; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			BM_ITER(l2, &liter2, em->bm, BM_LOOPS_OF_EDGE, l1->e) { | 
					
						
							|  |  |  | 				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
										 |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(e, BM_ELEM_TAG) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_edge_select_set(em->bm, e, TRUE); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +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"; | 
					
						
							| 
									
										
										
										
											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-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int loop_find_region(BMEditMesh *em, 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
										 |  |  | { | 
					
						
							|  |  |  | 	BLI_array_declare(region); | 
					
						
							|  |  |  | 	BLI_array_declare(stack); | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 	BMFace **region = NULL; | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	BMFace **stack = NULL; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		BM_ITER(l1, &liter1, em->bm, BM_LOOPS_OF_FACE, f) { | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			BM_ITER(l2, &liter2, em->bm, BM_LOOPS_OF_EDGE, l1->e) { | 
					
						
							|  |  |  | 				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); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(f, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 		BM_elem_flag_disable(f, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_EDGE, e) { | 
					
						
							|  |  |  | 			if (BLI_smallhash_haskey(&visithash, (uintptr_t)l->f)) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 						 | 
					
						
							| 
									
										
										
										
											2012-02-28 07:42:48 +00:00
										 |  |  | 			c = loop_find_region(em, 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); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 				BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, region[j]) { | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	int selbigger = RNA_boolean_get(op->ptr, "select_bigger"); | 
					
						
							|  |  |  | 	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 */ | 
					
						
							| 
									
										
										
										
											2012-02-25 16:04:03 +00:00
										 |  |  | 	a = loop_find_regions(em, selbigger); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	b = loop_find_regions(em, !selbigger); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ((a <= b) ^ selbigger) { | 
					
						
							|  |  |  | 		loop_find_regions(em, selbigger); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(f, &iter, em->bm, BM_FACES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											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)) { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_face_select_set(em->bm, f, TRUE); | 
					
						
							| 
									
										
										
										
											2011-05-01 20:43:54 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data); | 
					
						
							|  |  |  | 	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"; | 
					
						
							| 
									
										
										
										
											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-02-10 18:09:19 +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"); | 
					
						
							|  |  |  | } |