| 
									
										
										
										
											2011-10-24 23:32:24 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +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-18 10:29:37 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2004 by Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Joseph Eagar | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 00:20:36 +00:00
										 |  |  | /** \file blender/editors/mesh/editmesh_tools.c
 | 
					
						
							|  |  |  |  *  \ingroup edmesh | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_material_types.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-11 08:46:56 +00:00
										 |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | #include "DNA_modifier_types.h"
 | 
					
						
							|  |  |  | #include "DNA_object_types.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-11 10:15:11 +00:00
										 |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | #include "BLI_rand.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | #include "BKE_material.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2011-05-02 00:58:33 +00:00
										 |  |  | #include "BKE_cdderivedmesh.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | #include "BKE_depsgraph.h"
 | 
					
						
							|  |  |  | #include "BKE_object.h"
 | 
					
						
							|  |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | #include "BKE_texture.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | #include "BKE_main.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-11 08:46:56 +00:00
										 |  |  | #include "BKE_tessmesh.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_mesh.h"
 | 
					
						
							|  |  |  | #include "ED_view3d.h"
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | #include "ED_transform.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | #include "ED_object.h"
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | #include "RE_render_ext.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | #include "mesh_intern.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | /* allow accumulated normals to form a new direction but don't
 | 
					
						
							|  |  |  |  * accept direct opposite directions else they will cancel each other out */ | 
					
						
							| 
									
										
										
										
											2011-11-16 17:37:20 +00:00
										 |  |  | static void add_normal_aligned(float nor[3], const float add[3]) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 	if (dot_v3v3(nor, add) < -0.9999f) { | 
					
						
							| 
									
										
										
										
											2011-11-16 17:37:20 +00:00
										 |  |  | 		sub_v3_v3(nor, add); | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 		add_v3_v3(nor, add); | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_subdivide_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-16 17:43:09 +00:00
										 |  |  | 	ToolSettings *ts = CTX_data_tool_settings(C); | 
					
						
							| 
									
										
										
										
											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-03-21 09:10:08 +00:00
										 |  |  | 	int cuts = RNA_int_get(op->ptr, "number_cuts"); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	float smooth = 0.292f * RNA_float_get(op->ptr, "smoothness"); | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	float fractal = RNA_float_get(op->ptr, "fractal") / 2.5f; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int flag = 0; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (smooth != 0.0f) | 
					
						
							| 
									
										
										
										
											2011-11-01 04:31:25 +00:00
										 |  |  | 		flag |= B_SMOOTH; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (fractal != 0.0f) | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 		flag |= B_FRACTAL; | 
					
						
							| 
									
										
										
										
											2011-03-28 00:29:45 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (RNA_boolean_get(op->ptr, "quadtri") &&  | 
					
						
							|  |  |  | 	    RNA_enum_get(op->ptr, "quadcorner") == SUBD_STRAIGHT_CUT) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		RNA_enum_set(op->ptr, "quadcorner", SUBD_INNERVERT); | 
					
						
							| 
									
										
										
										
											2011-03-28 00:29:45 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-13 02:42:50 +00:00
										 |  |  | 	BM_mesh_esubdivideflag(obedit, em->bm, BM_ELEM_SELECT, | 
					
						
							| 
									
										
										
										
											2012-02-27 14:07:19 +00:00
										 |  |  | 	                       smooth, fractal, | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	                       ts->editbutflag | flag, | 
					
						
							| 
									
										
										
										
											2012-02-27 14:07:19 +00:00
										 |  |  | 	                       cuts, 0, RNA_enum_get(op->ptr, "quadcorner"), | 
					
						
							|  |  |  | 	                       RNA_boolean_get(op->ptr, "quadtri"), | 
					
						
							|  |  |  | 	                       TRUE, RNA_int_get(op->ptr, "seed")); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-11 11:33:23 +00:00
										 |  |  | /* Note, these values must match delete_mesh() event values */ | 
					
						
							|  |  |  | static EnumPropertyItem prop_mesh_cornervert_types[] = { | 
					
						
							|  |  |  | 	{SUBD_INNERVERT,     "INNERVERT", 0,      "Inner Vert", ""}, | 
					
						
							|  |  |  | 	{SUBD_PATH,          "PATH", 0,           "Path", ""}, | 
					
						
							|  |  |  | 	{SUBD_STRAIGHT_CUT,  "STRAIGHT_CUT", 0,   "Straight Cut", ""}, | 
					
						
							|  |  |  | 	{SUBD_FAN,           "FAN", 0,            "Fan", ""}, | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | void MESH_OT_subdivide(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-20 22:27:08 +00:00
										 |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Subdivide"; | 
					
						
							|  |  |  | 	ot->description = "Subdivide selected edges"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_subdivide"; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_subdivide_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2012-03-20 22:27:08 +00:00
										 |  |  | 	prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, INT_MAX, "Number of Cuts", "", 1, 10); | 
					
						
							|  |  |  | 	/* avoid re-using last var because it can cause _very_ high poly meshes and annoy users (or worse crash) */ | 
					
						
							|  |  |  | 	RNA_def_property_flag(prop, PROP_SKIP_SAVE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-26 07:41:56 +00:00
										 |  |  | 	/* BMESH_TODO, this currently does nothing, just add to stop UI from erroring out! */ | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "smoothness", 0.0f, 0.0f, FLT_MAX, "Smoothness", "Smoothness factor (BMESH TODO)", 0.0f, 1.0f); | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-28 00:29:45 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "quadtri", 0, "Quad/Tri Mode", "Tries to prevent ngons"); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	RNA_def_enum(ot->srna, "quadcorner", prop_mesh_cornervert_types, SUBD_STRAIGHT_CUT, | 
					
						
							| 
									
										
										
										
											2012-03-19 19:17:17 +00:00
										 |  |  | 	             "Quad Corner Type", "How to subdivide quad corners (anything other than Straight Cut will prevent ngons)"); | 
					
						
							| 
									
										
										
										
											2011-03-28 00:29:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 	RNA_def_float(ot->srna, "fractal", 0.0f, 0.0f, FLT_MAX, "Fractal", "Fractal randomness factor", 0.0f, 1000.0f); | 
					
						
							| 
									
										
										
										
											2011-03-28 00:29:45 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "seed", 0, 0, 10000, "Random Seed", "Seed for the random number generator", 0, 50); | 
					
						
							| 
									
										
										
										
											2009-05-18 10:29:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void EMBM_project_snap_verts(bContext *C, ARegion *ar, Object *obedit, BMEditMesh *em) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +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_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 			float mval[2], vec[3], no_dummy[3]; | 
					
						
							|  |  |  | 			int dist_dummy; | 
					
						
							|  |  |  | 			mul_v3_m4v3(vec, obedit->obmat, eve->co); | 
					
						
							|  |  |  | 			project_float_noclip(ar, vec, mval); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if (snapObjectsContext(C, mval, &dist_dummy, vec, no_dummy, SNAP_NOT_OBEDIT)) { | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 				mul_v3_m4v3(eve->co, obedit->imat, vec); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | /* individual face extrude */ | 
					
						
							|  |  |  | /* will use vertex normals for extrusion directions, so *nor is unaffected */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static short edbm_extrude_face_indiv(BMEditMesh *em, wmOperator *op, const char hflag, float *UNUSED(nor)) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	BMOIter siter; | 
					
						
							|  |  |  | 	BMIter liter; | 
					
						
							|  |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	BMLoop *l; | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "extrude_face_indiv faces=%hf", hflag); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* deselect original verts */ | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BMO_ITER(f, &siter, em->bm, &bmop, "faceout", BM_FACE) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BM_elem_select_set(em->bm, f, TRUE); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* set face vertex normals to face normal */ | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 		BM_ITER(l, &liter, em->bm, BM_LOOPS_OF_FACE, f) { | 
					
						
							| 
									
										
										
										
											2011-09-12 05:51:35 +00:00
										 |  |  | 			copy_v3_v3(l->v->no, f->no); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 's'; // s is shrink/fatten
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | /* extrudes individual edges */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static short edbm_extrude_edges_indiv(BMEditMesh *em, wmOperator *op, const char hflag, float *UNUSED(nor)) | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "extrude_edge_only edges=%he", hflag); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* deselect original verts */ | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_VERT | BM_EDGE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 'n'; // n is normal grab
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | /* extrudes individual vertices */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static short edbm_extrude_verts_indiv(BMEditMesh *em, wmOperator *op, const char hflag, float *UNUSED(nor)) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "extrude_vert_indiv verts=%hv", hflag); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* deselect original verts */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_disable(em->bm, &bmop, "verts", BM_VERT, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-19 00:33:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "vertout", BM_VERT, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	return 'g'; // g is grab
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static short edbm_extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, float nor[3]) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMOIter siter; | 
					
						
							|  |  |  | 	BMOperator extop; | 
					
						
							|  |  |  | 	BMEdge *edge; | 
					
						
							|  |  |  | 	BMFace *f; | 
					
						
							|  |  |  | 	ModifierData *md; | 
					
						
							| 
									
										
										
										
											2012-02-27 14:57:09 +00:00
										 |  |  | 	BMElem *ele; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-28 09:48:00 +00:00
										 |  |  | 	BMO_op_init(bm, &extop, "extrude_face_region"); | 
					
						
							| 
									
										
										
										
											2012-03-30 17:30:49 +00:00
										 |  |  | 	BMO_slot_buffer_from_enabled_hflag(bm, &extop, "edgefacein", BM_VERT | BM_EDGE | BM_FACE, hflag); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* If a mirror modifier with clipping is on, we need to adjust some 
 | 
					
						
							|  |  |  | 	 * of the cases above to handle edges on the line of symmetry. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	md = obedit->modifiers.first; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (; md; md = md->next) { | 
					
						
							|  |  |  | 		if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) { | 
					
						
							|  |  |  | 			MirrorModifierData *mmd = (MirrorModifierData *) md; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if (mmd->flag & MOD_MIR_CLIPPING) { | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 				float mtx[4][4]; | 
					
						
							|  |  |  | 				if (mmd->mirror_ob) { | 
					
						
							|  |  |  | 					float imtx[4][4]; | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 					invert_m4_m4(imtx, mmd->mirror_ob->obmat); | 
					
						
							| 
									
										
										
										
											2011-12-16 23:50:55 +00:00
										 |  |  | 					mult_m4_m4m4(mtx, imtx, obedit->obmat); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				for (edge = BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, NULL); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				     edge; | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				     edge = BM_iter_step(&iter)) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2012-03-01 16:12:11 +00:00
										 |  |  | 					if (BM_elem_flag_test(edge, hflag) && | 
					
						
							|  |  |  | 					    BM_edge_is_boundary(edge) && | 
					
						
							|  |  |  | 					    BM_elem_flag_test(edge->l->f, hflag)) | 
					
						
							|  |  |  | 					{ | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 						float co1[3], co2[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 						copy_v3_v3(co1, edge->v1->co); | 
					
						
							|  |  |  | 						copy_v3_v3(co2, edge->v2->co); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						if (mmd->mirror_ob) { | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 							mul_v3_m4v3(co1, mtx, co1); | 
					
						
							|  |  |  | 							mul_v3_m4v3(co2, mtx, co2); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 						if (mmd->flag & MOD_MIR_AXIS_X) { | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 							if ((fabsf(co1[0]) < mmd->tolerance) && | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 							    (fabsf(co2[0]) < mmd->tolerance)) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 							{ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 								BMO_slot_map_ptr_insert(bm, &extop, "exclude", edge, NULL); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if (mmd->flag & MOD_MIR_AXIS_Y) { | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 							if ((fabsf(co1[1]) < mmd->tolerance) && | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 							    (fabsf(co2[1]) < mmd->tolerance)) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 							{ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 								BMO_slot_map_ptr_insert(bm, &extop, "exclude", edge, NULL); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						if (mmd->flag & MOD_MIR_AXIS_Z) { | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 							if ((fabsf(co1[2]) < mmd->tolerance) && | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 							    (fabsf(co2[2]) < mmd->tolerance)) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 							{ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 								BMO_slot_map_ptr_insert(bm, &extop, "exclude", edge, NULL); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-11-04 09:37:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &extop); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 20:18:09 +00:00
										 |  |  | 	zero_v3(nor); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-27 14:57:09 +00:00
										 |  |  | 	BMO_ITER(ele, &siter, bm, &extop, "geomout", BM_ALL) { | 
					
						
							|  |  |  | 		BM_elem_select_set(bm, ele, TRUE); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-27 14:57:09 +00:00
										 |  |  | 		if (ele->head.htype == BM_FACE) { | 
					
						
							|  |  |  | 			f = (BMFace *)ele; | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 			add_normal_aligned(nor, f->no); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 	normalize_v3(nor); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_finish(bm, &extop); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 20:18:09 +00:00
										 |  |  | 	/* grab / normal constraint */ | 
					
						
							|  |  |  | 	return is_zero_v3(nor) ? 'g' : 'n'; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-03-23 20:18:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static short edbm_extrude_vert(Object *obedit, BMEditMesh *em, const char hflag, float nor[3]) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* ensure vert flags are consistent for edge selections */ | 
					
						
							| 
									
										
										
										
											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, hflag)) { | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 			if (hflag & BM_ELEM_SELECT) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 				BM_elem_select_set(em->bm, eed->v1, TRUE); | 
					
						
							|  |  |  | 				BM_elem_select_set(em->bm, eed->v2, TRUE); | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_enable(eed->v1, hflag & ~BM_ELEM_SELECT); | 
					
						
							|  |  |  | 			BM_elem_flag_enable(eed->v2, hflag & ~BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(eed->v1, hflag) && BM_elem_flag_test(eed->v2, hflag)) { | 
					
						
							| 
									
										
										
										
											2012-02-12 06:24:12 +00:00
										 |  |  | 				if (hflag & BM_ELEM_SELECT) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 					BM_elem_select_set(em->bm, eed, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-19 00:33:54 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2011-09-30 04:27:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BM_elem_flag_enable(eed, hflag & ~BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	return edbm_extrude_edge(obedit, em, hflag, nor); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +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
										 |  |  | 	RegionView3D *rv3d = CTX_wm_region_view3d(C); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	int steps = RNA_int_get(op->ptr, "steps"); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	float offs = RNA_float_get(op->ptr, "offset"); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	float dvec[3], tmat[3][3], bmat[3][3], nor[3] = {0.0, 0.0, 0.0}; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	short a; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* dvec */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	normalize_v3_v3(dvec, rv3d->persinv[2]); | 
					
						
							|  |  |  | 	mul_v3_fl(dvec, offs); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* base correction */ | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 	copy_m3_m4(bmat, obedit->obmat); | 
					
						
							|  |  |  | 	invert_m3_m3(tmat, bmat); | 
					
						
							|  |  |  | 	mul_m3_v3(tmat, dvec); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (a = 0; a < steps; a++) { | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 		edbm_extrude_edge(obedit, em, BM_ELEM_SELECT, nor); | 
					
						
							| 
									
										
										
										
											2012-02-28 09:48:00 +00:00
										 |  |  | 		//BMO_op_callf(em->bm, "extrude_face_region edgefacein=%hef", BM_ELEM_SELECT);
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMO_op_callf(em->bm, "translate vec=%v verts=%hv", (float *)dvec, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 		//extrudeflag(obedit, em, SELECT, nor);
 | 
					
						
							|  |  |  | 		//translateflag(em, SELECT, dvec);
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_normals_update(em); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_extrude_repeat(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Extrude Repeat Mesh"; | 
					
						
							|  |  |  | 	ot->description = "Extrude selected vertices, edges or faces repeatedly"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_extrude_repeat"; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_extrude_repeat_exec; | 
					
						
							| 
									
										
										
										
											2012-03-08 00:23:28 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh_view3d; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "offset", 2.0f, 0.0f, 100.0f, "Offset", "", 0.0f, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "steps", 10, 0, 180, "Steps", "", 0, INT_MAX); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* generic extern called extruder */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_extrude_mesh(Scene *scene, Object *obedit, BMEditMesh *em, wmOperator *op, float *norin) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	short nr, transmode = 0; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	float stacknor[3] = {0.0f, 0.0f, 0.0f}; | 
					
						
							|  |  |  | 	float *nor = norin ? norin : stacknor; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 20:18:09 +00:00
										 |  |  | 	zero_v3(nor); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (em->bm->totvertsel == 0) nr = 0; | 
					
						
							|  |  |  | 		else if (em->bm->totvertsel == 1) nr = 4; | 
					
						
							|  |  |  | 		else if (em->bm->totedgesel == 0) nr = 4; | 
					
						
							|  |  |  | 		else if (em->bm->totfacesel == 0) | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			nr = 3;  // pupmenu("Extrude %t|Only Edges%x3|Only Vertices%x4");
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		else if (em->bm->totfacesel == 1) | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			nr = 1;  // pupmenu("Extrude %t|Region %x1|Only Edges%x3|Only Vertices%x4");
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		else  | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			nr = 1;  // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3|Only Vertices%x4");
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (em->bm->totedgesel == 0) nr = 0; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		nr = 1; | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | 		else if (em->totedgesel == 1) nr = 3; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		else if (em->totfacesel == 0) nr = 3; | 
					
						
							|  |  |  | 		else if (em->totfacesel == 1) | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			nr = 1;  // pupmenu("Extrude %t|Region %x1|Only Edges%x3");
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			nr = 1;  // pupmenu("Extrude %t|Region %x1||Individual Faces %x2|Only Edges%x3");
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		if (em->bm->totfacesel == 0) nr = 0; | 
					
						
							|  |  |  | 		else if (em->bm->totfacesel == 1) nr = 1; | 
					
						
							|  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			nr = 1;  // pupmenu("Extrude %t|Region %x1||Individual Faces %x2");
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (nr < 1) return 'g'; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-10 22:00:55 +00:00
										 |  |  | 	if (nr == 1 && (em->selectmode & SCE_SELECT_VERTEX)) | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 		transmode = edbm_extrude_vert(obedit, em, BM_ELEM_SELECT, nor); | 
					
						
							|  |  |  | 	else if (nr == 1) transmode = edbm_extrude_edge(obedit, em, BM_ELEM_SELECT, nor); | 
					
						
							|  |  |  | 	else if (nr == 4) transmode = edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT, nor); | 
					
						
							|  |  |  | 	else if (nr == 3) transmode = edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, nor); | 
					
						
							|  |  |  | 	else transmode = edbm_extrude_face_indiv(em, op, BM_ELEM_SELECT, nor); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (transmode == 0) { | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "Not a valid selection for extrude"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-23 20:18:09 +00:00
										 |  |  | 		/* We need to force immediate calculation here because
 | 
					
						
							|  |  |  | 		 * transform may use derived objects (which are now stale). | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * This shouldn't be necessary, derived queries should be | 
					
						
							|  |  |  | 		 * automatically building this data if invalid. Or something. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | //		DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
 | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 		object_handle_update(scene, obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* individual faces? */ | 
					
						
							|  |  |  | //		BIF_TransformSetUndo("Extrude");
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (nr == 2) { | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | //			initTransform(TFM_SHRINKFATTEN, CTX_NO_PET|CTX_NO_MIRROR);
 | 
					
						
							|  |  |  | //			Transform();
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | //			initTransform(TFM_TRANSLATION, CTX_NO_PET|CTX_NO_MIRROR);
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			if (transmode == 'n') { | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 				mul_m4_v3(obedit->obmat, nor); | 
					
						
							|  |  |  | 				sub_v3_v3v3(nor, nor, obedit->obmat[3]); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | //				BIF_setSingleAxisConstraint(nor, "along normal");
 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | //			Transform();
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return transmode; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | /* extrude without transform */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_extrude_region_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-22 04:45:18 +00:00
										 |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	edbm_extrude_mesh(scene, obedit, em, op, NULL); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* This normally happens when pushing undo but modal operators
 | 
					
						
							|  |  |  | 	 * like this one don't push undo data until after modal mode is | 
					
						
							|  |  |  | 	 * done.*/ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_normals_update(em); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_extrude_region(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Extrude Region"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_extrude_region"; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	//ot->invoke = mesh_extrude_region_invoke;
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_extrude_region_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_extrude_verts_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +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); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	float nor[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT, nor); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_extrude_verts_indiv(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Extrude Only Vertices"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_extrude_verts_indiv"; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_extrude_verts_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* to give to transform */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_extrude_edges_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +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); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	float nor[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT, nor); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | void MESH_OT_extrude_edges_indiv(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Extrude Only Edges"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_extrude_edges_indiv"; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_extrude_edges_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* to give to transform */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_extrude_faces_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +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); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	float nor[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	edbm_extrude_face_indiv(em, op, BM_ELEM_SELECT, nor); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_extrude_faces_indiv(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Extrude Individual Faces"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_extrude_faces_indiv"; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_extrude_faces_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); | 
					
						
							| 
									
										
										
										
											2009-05-18 14:55:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ******************** (de)select all operator **************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_all_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +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-12-02 19:43:53 +00:00
										 |  |  | 	int action = RNA_enum_get(op->ptr, "action"); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-12-02 19:43:53 +00:00
										 |  |  | 	switch (action) { | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		case SEL_TOGGLE: | 
					
						
							|  |  |  | 			EDBM_select_toggle_all(em); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_SELECT: | 
					
						
							|  |  |  | 			EDBM_flag_enable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_DESELECT: | 
					
						
							|  |  |  | 			EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case SEL_INVERT: | 
					
						
							|  |  |  | 			EDBM_select_swap(em); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-12-02 19:43:53 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | void MESH_OT_select_all(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-17 19:14:08 +00:00
										 |  |  | 	ot->name = "(De)select All"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_select_all"; | 
					
						
							| 
									
										
										
										
											2012-02-27 18:14:56 +00:00
										 |  |  | 	ot->description = "(De)select all vertices, edges or faces"; | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_all_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-12-01 14:12:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	WM_operator_properties_select_all(ot); | 
					
						
							| 
									
										
										
										
											2009-05-28 04:41:02 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_faces_select_interior_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (EDBM_select_interior_faces(em)) { | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit); | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_interior_faces(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Interior Faces"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_interior_faces"; | 
					
						
							|  |  |  | 	ot->description = "Select faces where all edges have more than 2 face users"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_faces_select_interior_exec; | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-02-19 20:27:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | /* *************** add-click-mesh (extrude) operator ************** */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent *event) | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ViewContext vc; | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 	BMVert *v1; | 
					
						
							| 
									
										
										
										
											2009-06-18 02:05:56 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	float min[3], max[3]; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int done = 0; | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 	short use_proj; | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	use_proj = (vc.scene->toolsettings->snap_flag & SCE_SNAP) &&    (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE); | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	INIT_MINMAX(min, max); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 	BM_ITER(v1, &iter, vc.em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_elem_flag_test(v1, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 			DO_MINMAX(v1->co, min, max); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			done = 1; | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* call extrude? */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (done) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		const short rot_src = RNA_boolean_get(op->ptr, "rotate_source"); | 
					
						
							| 
									
										
										
										
											2009-06-18 02:05:56 +00:00
										 |  |  | 		BMEdge *eed; | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 		float vec[3], cent[3], mat[3][3]; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		float nor[3] = {0.0, 0.0, 0.0}; | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* 2D normal calc */ | 
					
						
							|  |  |  | 		float mval_f[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		mval_f[0] = (float)event->mval[0]; | 
					
						
							|  |  |  | 		mval_f[1] = (float)event->mval[1]; | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 		/* check for edges that are half selected, use for rotation */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		done = 0; | 
					
						
							| 
									
										
										
										
											2009-06-18 02:05:56 +00:00
										 |  |  | 		BM_ITER(eed, &iter, vc.em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 				float co1[3], co2[3]; | 
					
						
							|  |  |  | 				mul_v3_m4v3(co1, vc.obedit->obmat, eed->v1->co); | 
					
						
							|  |  |  | 				mul_v3_m4v3(co2, vc.obedit->obmat, eed->v2->co); | 
					
						
							|  |  |  | 				project_float_noclip(vc.ar, co1, co1); | 
					
						
							|  |  |  | 				project_float_noclip(vc.ar, co2, co2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/* 2D rotate by 90d while adding.
 | 
					
						
							|  |  |  | 				 *  (x, y) = (y, -x) | 
					
						
							|  |  |  | 				 * | 
					
						
							|  |  |  | 				 * accumulate the screenspace normal in 2D, | 
					
						
							|  |  |  | 				 * with screenspace edge length weighting the result. */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 				if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) { | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 					nor[0] +=  (co1[1] - co2[1]); | 
					
						
							|  |  |  | 					nor[1] += -(co1[0] - co2[0]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					nor[0] +=  (co2[1] - co1[1]); | 
					
						
							|  |  |  | 					nor[1] += -(co2[0] - co1[0]); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			done = 1; | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (done) { | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 			float view_vec[3], cross[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* convert the 2D nomal into 3D */ | 
					
						
							|  |  |  | 			mul_mat3_m4_v3(vc.rv3d->viewinv, nor); /* worldspace */ | 
					
						
							|  |  |  | 			mul_mat3_m4_v3(vc.obedit->imat, nor); /* local space */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* correct the normal to be aligned on the view plane */ | 
					
						
							|  |  |  | 			copy_v3_v3(view_vec, vc.rv3d->viewinv[2]); | 
					
						
							|  |  |  | 			mul_mat3_m4_v3(vc.obedit->imat, view_vec); | 
					
						
							|  |  |  | 			cross_v3_v3v3(cross, nor, view_vec); | 
					
						
							|  |  |  | 			cross_v3_v3v3(nor, view_vec, cross); | 
					
						
							|  |  |  | 			normalize_v3(nor); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* center */ | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 		mid_v3_v3v3(cent, min, max); | 
					
						
							|  |  |  | 		copy_v3_v3(min, cent); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		mul_m4_v3(vc.obedit->obmat, min);  /* view space */ | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 		view3d_get_view_aligned_coordinate(&vc, min, event->mval, TRUE); | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 		mul_m4_v3(vc.obedit->imat, min); // back in object space
 | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		sub_v3_v3(min, cent); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* calculate rotation */ | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 		unit_m3(mat); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (done) { | 
					
						
							| 
									
										
										
										
											2012-03-28 06:34:18 +00:00
										 |  |  | 			float angle; | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-28 06:34:18 +00:00
										 |  |  | 			normalize_v3_v3(vec, min); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-28 06:34:18 +00:00
										 |  |  | 			angle = angle_normalized_v3v3(vec, nor); | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-28 06:34:18 +00:00
										 |  |  | 			if (angle != 0.0f) { | 
					
						
							|  |  |  | 				float axis[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				cross_v3_v3v3(axis, nor, vec); | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				/* halve the rotation if its applied twice */ | 
					
						
							| 
									
										
										
										
											2012-03-28 06:34:18 +00:00
										 |  |  | 				if (rot_src) { | 
					
						
							|  |  |  | 					angle *= 0.5f; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				axis_angle_to_mat3(mat, axis, angle); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (rot_src) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 			EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v mat=%m3", | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 			              BM_ELEM_SELECT, cent, mat); | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* also project the source, for retopo workflow */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if (use_proj) | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 				EMBM_project_snap_verts(C, vc.ar, vc.obedit, vc.em); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-18 02:05:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 		edbm_extrude_edge(vc.obedit, vc.em, BM_ELEM_SELECT, nor); | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		EDBM_op_callf(vc.em, op, "rotate verts=%hv cent=%v mat=%m3", | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		              BM_ELEM_SELECT, cent, mat); | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		EDBM_op_callf(vc.em, op, "translate verts=%hv vec=%v", | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		              BM_ELEM_SELECT, min); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		float *curs = give_cursor(vc.scene, vc.v3d); | 
					
						
							| 
									
										
										
										
											2009-06-18 03:04:27 +00:00
										 |  |  | 		BMOperator bmop; | 
					
						
							|  |  |  | 		BMOIter oiter; | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 		copy_v3_v3(min, curs); | 
					
						
							| 
									
										
										
										
											2011-05-08 23:43:18 +00:00
										 |  |  | 		view3d_get_view_aligned_coordinate(&vc, min, event->mval, 0); | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		invert_m4_m4(vc.obedit->imat, vc.obedit->obmat); | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 		mul_m4_v3(vc.obedit->imat, min); // back in object space
 | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		EDBM_op_init(vc.em, &bmop, op, "makevert co=%v", min); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMO_op_exec(vc.em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-23 05:35:49 +00:00
										 |  |  | 		BMO_ITER(v1, &oiter, vc.em->bm, &bmop, "newvertout", BM_VERT) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(vc.em->bm, v1, TRUE); | 
					
						
							| 
									
										
										
										
											2009-06-18 03:04:27 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_finish(vc.em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-06-18 03:04:27 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-18 02:05:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (use_proj) | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 		EMBM_project_snap_verts(C, vc.ar, vc.obedit, vc.em); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* This normally happens when pushing undo but modal operators
 | 
					
						
							|  |  |  | 	 * like this one don't push undo data until after modal mode is | 
					
						
							|  |  |  | 	 * done. */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_normals_update(vc.em); | 
					
						
							| 
									
										
										
										
											2011-11-01 23:38:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, vc.em, TRUE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Duplicate or Extrude at 3D Cursor"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_dupli_extrude_cursor"; | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_dupli_extrude_cursor_invoke; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->description = "Duplicate and extrude selected vertices, edges or faces towards the mouse cursor"; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-05-11 14:05:22 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "rotate_source", 1, "Rotate Source", "Rotate initial selection giving better shape"); | 
					
						
							| 
									
										
										
										
											2009-06-02 07:40:32 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | /* Note, these values must match delete_mesh() event values */ | 
					
						
							|  |  |  | static EnumPropertyItem prop_mesh_delete_types[] = { | 
					
						
							|  |  |  | 	{0, "VERT",      0, "Vertices", ""}, | 
					
						
							|  |  |  | 	{1,  "EDGE",      0, "Edges", ""}, | 
					
						
							|  |  |  | 	{2,  "FACE",      0, "Faces", ""}, | 
					
						
							|  |  |  | 	{3,  "EDGE_FACE", 0, "Edges & Faces", ""}, | 
					
						
							|  |  |  | 	{4,  "ONLY_FACE", 0, "Only Faces", ""}, | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_delete_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							|  |  |  | 	int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	if (type == 0) { | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "del geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)) /* Erase Vertices */ | 
					
						
							| 
									
										
										
										
											2009-06-23 05:35:49 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	else if (type == 1) { | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "del geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)) /* Erase Edges */ | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else if (type == 2) { | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "del geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)) /* Erase Faces */ | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	else if (type == 3) { | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "del geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES)) /* Edges and Faces */ | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	else if (type == 4) { | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 		//"Erase Only Faces";
 | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "del geom=%hf context=%i", | 
					
						
							|  |  |  | 		                   BM_ELEM_SELECT, DEL_ONLYFACES)) | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_delete(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Delete"; | 
					
						
							|  |  |  | 	ot->description = "Delete selected vertices, edges or faces"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_delete"; | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +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_delete_exec; | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-02-10 01:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	ot->prop = RNA_def_enum(ot->srna, "type", prop_mesh_delete_types, 0, "Type", "Method used for deleting mesh data"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-02-10 01:40:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_collapse_edge_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "collapse edges=%he", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | void MESH_OT_edge_collapse(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Edge Collapse"; | 
					
						
							|  |  |  | 	ot->description = "Collapse selected edges"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_edge_collapse"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_collapse_edge_exec; | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_collapse_edge_loop_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "dissolve_edge_loop edges=%he", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_edge_collapse_loop(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Edge Collapse Loop"; | 
					
						
							|  |  |  | 	ot->description = "Collapse selected edge loops"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_edge_collapse_loop"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_collapse_edge_loop_exec; | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_add_edge_face_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											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-06-18 01:31:50 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &bmop, op, "contextual_create geom=%hfev", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faceout", BM_FACE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_edge_face_add(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Make Edge/Face"; | 
					
						
							|  |  |  | 	ot->description = "Add an edge or face to selected"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_edge_face_add"; | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_add_edge_face_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-06-18 01:31:50 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-06-18 10:15:23 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************* SEAMS AND EDGES **************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_mark_seam(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Mesh *me = ((Mesh *)obedit->data); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	int clear = RNA_boolean_get(op->ptr, "clear"); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* auto-enable seams drawing */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (clear == 0) { | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 		me->drawflag |= ME_DRAWSEAMS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (clear) { | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 		BM_ITER(eed, &iter, bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_disable(eed, BM_ELEM_SEAM); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 		BM_ITER(eed, &iter, bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_enable(eed, BM_ELEM_SEAM); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_mark_seam(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Mark Seam"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_mark_seam"; | 
					
						
							|  |  |  | 	ot->description = "(un)mark selected edges as a seam"; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_mark_seam; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "clear", 0, "Clear", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_mark_sharp(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Mesh *me = ((Mesh *)obedit->data); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	int clear = RNA_boolean_get(op->ptr, "clear"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* auto-enable sharp edge drawing */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (clear == 0) { | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 		me->drawflag |= ME_DRAWSHARP; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (!clear) { | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 		BM_ITER(eed, &iter, bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-02-18 11:44:30 +00:00
										 |  |  | 			BM_elem_flag_disable(eed, BM_ELEM_SMOOTH); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 		BM_ITER(eed, &iter, bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2011-05-12 01:55:08 +00:00
										 |  |  | 				continue; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-02-18 11:44:30 +00:00
										 |  |  | 			BM_elem_flag_enable(eed, BM_ELEM_SMOOTH); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_mark_sharp(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Mark Sharp"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_mark_sharp"; | 
					
						
							|  |  |  | 	ot->description = "(un)mark selected edges as sharp"; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_mark_sharp; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-16 06:27:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "clear", 0, "Clear", ""); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-17 05:09:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_vert_connect(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-17 05:09:33 +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-07-17 05:09:33 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	int len = 0; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &bmop, op, "connectverts verts=%hv", BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &bmop); | 
					
						
							|  |  |  | 	len = BMO_slot_get(&bmop, "edgeout")->len; | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-17 05:09:33 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-17 05:09:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_vert_connect(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Vertex Connect"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_vert_connect"; | 
					
						
							| 
									
										
										
										
											2009-07-17 05:09:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_vert_connect; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-17 05:09:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-17 05:09:33 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-17 06:05:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_edge_split_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-17 06:05:09 +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-07-17 06:05:09 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	int len = 0; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &bmop, op, "edgesplit edges=%he", BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-03-23 03:10:44 +00:00
										 |  |  | 	len = BMO_slot_get(&bmop, "edgeout")->len; | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-17 06:05:09 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-17 06:05:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return len ? OPERATOR_FINISHED : OPERATOR_CANCELLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_edge_split(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Edge Split"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_edge_split"; | 
					
						
							| 
									
										
										
										
											2009-07-17 06:05:09 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_edge_split_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-17 06:05:09 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-17 06:05:09 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /****************** add duplicate operator ***************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_duplicate_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "dupe geom=%hvef", BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "newout", BM_ALL, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	WM_cursor_wait(1); | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	edbm_duplicate_exec(C, op); | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 	WM_cursor_wait(0); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_duplicate(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Duplicate"; | 
					
						
							|  |  |  | 	ot->description = "Duplicate selected vertices, edges or faces"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_duplicate"; | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_duplicate_invoke; | 
					
						
							|  |  |  | 	ot->exec = edbm_duplicate_exec; | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-21 08:39:58 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* to give to transform */ | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_flip_normals_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-22 02:57:40 +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-07-22 02:57:40 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "reversefaces faces=%hf", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2009-07-22 02:57:40 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-22 02:57:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_flip_normals(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Flip Normals"; | 
					
						
							| 
									
										
										
										
											2012-02-27 18:14:56 +00:00
										 |  |  | 	ot->description = "Flip the direction of selected faces' normals (and of their vertices)"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_flip_normals"; | 
					
						
							| 
									
										
										
										
											2009-07-22 02:57:40 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_flip_normals_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-22 02:57:40 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-22 02:57:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | static const EnumPropertyItem direction_items[] = { | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 	{DIRECTION_CW, "CW", 0, "Clockwise", ""}, | 
					
						
							|  |  |  | 	{DIRECTION_CCW, "CCW", 0, "Counter Clockwise", ""}, | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL}}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* only accepts 1 selected edge, or 2 selected faces */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_edge_rotate_selected_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +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-07-26 14:58:31 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2011-09-09 04:09:34 +00:00
										 |  |  | 	const int do_ccw = RNA_enum_get(op->ptr, "direction") == 1; | 
					
						
							| 
									
										
										
										
											2012-03-03 12:49:03 +00:00
										 |  |  | 	int tot = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (em->bm->totedgesel == 0) { | 
					
						
							|  |  |  | 		BKE_report(op->reports, RPT_ERROR, "Select edges or face pairs for edge loops to rotate about"); | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* first see if we have two adjacent faces */ | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 	BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-03-03 12:49:03 +00:00
										 |  |  | 		BM_elem_flag_disable(eed, BM_ELEM_TAG); | 
					
						
							|  |  |  | 		if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 			BMFace *fa, *fb; | 
					
						
							|  |  |  | 			if (BM_edge_face_pair(eed, &fa, &fb)) { | 
					
						
							|  |  |  | 				/* if both faces are selected we rotate between them,
 | 
					
						
							|  |  |  | 				 * otherwise - rotate between 2 unselected - but not mixed */ | 
					
						
							|  |  |  | 				if (BM_elem_flag_test(fa, BM_ELEM_SELECT) == BM_elem_flag_test(fb, BM_ELEM_SELECT)) { | 
					
						
							|  |  |  | 					BM_elem_flag_enable(eed, BM_ELEM_TAG); | 
					
						
							|  |  |  | 					tot++; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* ok, we don't have two adjacent faces, but we do have two selected ones.
 | 
					
						
							|  |  |  | 	 * that's an error condition.*/ | 
					
						
							| 
									
										
										
										
											2012-03-03 12:49:03 +00:00
										 |  |  | 	if (tot == 0) { | 
					
						
							|  |  |  | 		BKE_report(op->reports, RPT_ERROR, "Could not find any selected edges that can be rotated"); | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "edgerotate edges=%he ccw=%b", BM_ELEM_TAG, do_ccw); | 
					
						
							| 
									
										
										
										
											2011-09-09 04:09:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-15 23:23:04 +00:00
										 |  |  | 	/* avoids leaving old verts selected which can be a problem running multiple times,
 | 
					
						
							|  |  |  | 	 * since this means the edges become selected around the face which then attempt to rotate */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_disable(em->bm, &bmop, "edges", BM_EDGE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-15 23:23:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-03-15 23:23:04 +00:00
										 |  |  | 	/* edges may rotate into hidden vertices, if this does _not_ run we get an ilogical state */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_disable(em->bm, &bmop, "edgeout", BM_EDGE, BM_ELEM_HIDDEN, TRUE); | 
					
						
							|  |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "edgeout", BM_EDGE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-15 23:23:04 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_edge_rotate(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Rotate Selected Edge"; | 
					
						
							|  |  |  | 	ot->description = "Rotate selected edge or adjoining faces"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_edge_rotate"; | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_edge_rotate_selected_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2012-02-27 18:14:56 +00:00
										 |  |  | 	RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "Direction", "Direction to rotate edge around"); | 
					
						
							| 
									
										
										
										
											2009-07-26 14:58:31 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_hide_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +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 06:06:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_hide(em, RNA_boolean_get(op->ptr, "unselected")); | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_hide(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Hide Selection"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_hide"; | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_hide_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->description = "Hide (un)selected vertices, edges or faces"; | 
					
						
							| 
									
										
										
										
											2009-08-26 10:27:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected"); | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_reveal_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +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 06:06:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_reveal(em); | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_reveal(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Reveal Hidden"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_reveal"; | 
					
						
							|  |  |  | 	ot->description = "Reveal all hidden vertices, edges and faces"; | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_reveal_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-05 06:06:58 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_normals_make_consistent_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +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-06 08:23:10 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-09-06 04:06:05 +00:00
										 |  |  | 	/* doflip has to do with bmesh_rationalize_normals, it's an internal
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	 * thing */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "righthandfaces faces=%hf do_flip=%b", BM_ELEM_SELECT, TRUE)) | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2011-09-06 04:06:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 	if (RNA_boolean_get(op->ptr, "inside")) | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		EDBM_op_callf(em, op, "reversefaces faces=%hf", BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_normals_make_consistent(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Make Normals Consistent"; | 
					
						
							|  |  |  | 	ot->description = "Make face and vertex normals point either outside or inside the mesh"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_normals_make_consistent"; | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_normals_make_consistent_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-06 08:23:10 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "inside", 0, "Inside", ""); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_do_smooth_vertex_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27: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); | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 	ModifierData *md; | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 	int mirrx = FALSE, mirry = FALSE, mirrz = FALSE; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 	int i, repeat; | 
					
						
							| 
									
										
										
										
											2012-02-10 15:25:12 +00:00
										 |  |  | 	float clipdist = 0.0f; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-26 07:41:56 +00:00
										 |  |  | 	/* mirror before smooth */ | 
					
						
							|  |  |  | 	if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		EDBM_verts_mirror_cache_begin(em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-10-26 07:41:56 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 	/* if there is a mirror modifier with clipping, flag the verts that
 | 
					
						
							|  |  |  | 	 * are within tolerance of the plane(s) of reflection  | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (md = obedit->modifiers.first; md; md = md->next) { | 
					
						
							|  |  |  | 		if (md->type == eModifierType_Mirror && (md->mode & eModifierMode_Realtime)) { | 
					
						
							|  |  |  | 			MirrorModifierData *mmd = (MirrorModifierData *)md; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if (mmd->flag & MOD_MIR_CLIPPING) { | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 				if (mmd->flag & MOD_MIR_AXIS_X) | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 					mirrx = TRUE; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 				if (mmd->flag & MOD_MIR_AXIS_Y) | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 					mirry = TRUE; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 				if (mmd->flag & MOD_MIR_AXIS_Z) | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 					mirrz = TRUE; | 
					
						
							| 
									
										
										
										
											2012-02-10 15:25:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				clipdist = mmd->tolerance; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	repeat = RNA_int_get(op->ptr, "repeat"); | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 	if (!repeat) | 
					
						
							|  |  |  | 		repeat = 1; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (i = 0; i < repeat; i++) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 		                   "vertexsmooth verts=%hv mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f", | 
					
						
							|  |  |  | 		                   BM_ELEM_SELECT, mirrx, mirry, mirrz, clipdist)) | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-26 07:41:56 +00:00
										 |  |  | 	/* apply mirror */ | 
					
						
							|  |  |  | 	if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		EDBM_verts_mirror_apply(em, BM_ELEM_SELECT, 0); | 
					
						
							|  |  |  | 		EDBM_verts_mirror_cache_end(em); | 
					
						
							| 
									
										
										
										
											2011-10-26 07:41:56 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | }	 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | void MESH_OT_vertices_smooth(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Smooth Vertex"; | 
					
						
							|  |  |  | 	ot->description = "Flatten angles of selected vertices"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_vertices_smooth"; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_do_smooth_vertex_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-06 14:03:43 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of times to smooth the mesh", "", 1, INT_MAX); | 
					
						
							| 
									
										
										
											
												bmeshafied vertex smooth, and also added a 'repeat' option :) since the last operator panel works after this last 2.5 merge, yayscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen
											
										 
											2009-08-06 11:27:08 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
											
												Brought Extrude all the way back.  The contextual menu works,
as does only edges and individual faces extrude (individual vert 
extrude already did).
Note that I need to port this, after we all figure out how to handle
operators with variable transform follow-ons.
I also implemented the merge->collapse function, which is currently
accessable under ctrl->v, Bmesh Test Operator.  I still need to
implement the other merge modes, and properly hook everything into
the merge menu tool, which I plan on doing soon (tomorrow hopefully).
The cool thing about the collapse tool, is not only does it handle (all)
UV layers, it handles vcols as well.  To do this, I had to add a few math
functions to the customdata API, which seem to be working well.
											
										 
											2009-08-11 07:49:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | /********************** Smooth/Solid Operators *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 02:14:43 +00:00
										 |  |  | static void mesh_set_smooth_faces(BMEditMesh *em, short smooth) | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (em == NULL) return; | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +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_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 			BM_elem_flag_set(efa, BM_ELEM_SMOOTH, smooth); | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_faces_shade_smooth_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +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); | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mesh_set_smooth_faces(em, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_faces_shade_smooth(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Shade Smooth"; | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->description = "Display faces smooth (using vertex normals)"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_faces_shade_smooth"; | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_faces_shade_smooth_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_faces_shade_flat_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +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); | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mesh_set_smooth_faces(em, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_faces_shade_flat(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Shade Flat"; | 
					
						
							|  |  |  | 	ot->description = "Display faces flat"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_faces_shade_flat"; | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_faces_shade_flat_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
											
												subsurf works now! YES! take *that* subsurf_ccg.cscons/scons.py BF_QUICK=bf_python,bf_blenkernel,bf_blenlib,bf_blenloader,bf_editors_mesh,bf_bmesh,bf_editors_space_view3d,bf_editors_transform,bf_makesdna,bf_makesrna,bf_dna,bf_rn,bf_bmesh,bf_editors_object,editors_uvedit,editors_space_image,editors_screen,editors_space_screen,editors_space_api,bf_windowmanager,bf_wm still an issue with some modifier combinations though, and I think there's some memory corruption going on, need to valgrind it.
											
										 
											2009-08-25 10:21:10 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************** UV/Color Operators *************************/ | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_rotate_uvs_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* get the direction from RNA */ | 
					
						
							|  |  |  | 	int dir = RNA_enum_get(op->ptr, "direction"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "face_rotateuvs faces=%hf dir=%i", BM_ELEM_SELECT, dir); | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							| 
									
										
										
										
											2011-11-20 16:21:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-02 20:26:12 +00:00
										 |  |  | 	/* we succeeded */ | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_reverse_uvs_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-12 07:08:57 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-09-12 07:08:57 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 07:08:57 +00:00
										 |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "face_reverseuvs faces=%hf", BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 07:08:57 +00:00
										 |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 07:08:57 +00:00
										 |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							| 
									
										
										
										
											2011-11-20 16:21:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 07:08:57 +00:00
										 |  |  | 	/* we succeeded */ | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_rotate_colors_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	/* get the direction from RNA */ | 
					
						
							|  |  |  | 	int dir = RNA_enum_get(op->ptr, "direction"); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "face_rotatecolors faces=%hf dir=%i", BM_ELEM_SELECT, dir); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	/* dependencies graph and notification stuff */ | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	/* we succeeded */ | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_reverse_colors_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "face_reversecolors faces=%hf", BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* we succeeded */ | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_uvs_rotate(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Rotate UVs"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_uvs_rotate"; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_rotate_uvs_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 	RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CW, "Direction", "Direction to rotate UVs around"); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 07:08:57 +00:00
										 |  |  | //void MESH_OT_uvs_mirror(wmOperatorType *ot)
 | 
					
						
							|  |  |  | void MESH_OT_uvs_reverse(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Reverse UVs"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_uvs_reverse"; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_reverse_uvs_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 	//RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror UVs around");
 | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_colors_rotate(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Rotate Colors"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_colors_rotate"; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_rotate_colors_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2011-12-02 16:57:22 +00:00
										 |  |  | 	RNA_def_enum(ot->srna, "direction", direction_items, DIRECTION_CCW, "Direction", "Direction to rotate edge around"); | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | void MESH_OT_colors_reverse(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Reverse Colors"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_colors_reverse"; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_reverse_colors_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 	//RNA_def_enum(ot->srna, "axis", axis_items, DIRECTION_CW, "Axis", "Axis to mirror colors around");
 | 
					
						
							| 
									
										
										
										
											2009-08-28 10:17:31 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int merge_firstlast(BMEditMesh *em, int first, int uvmerge, wmOperator *wmop) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMVert *mergevert; | 
					
						
							|  |  |  | 	BMEditSelection *ese; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* do sanity check in mergemenu in edit.c ?*/ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (first == 0) { | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		ese = em->bm->selected.last; | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 		mergevert = (BMVert *)ese->ele; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		ese = em->bm->selected.first; | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 		mergevert = (BMVert *)ese->ele; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	if (!BM_elem_flag_test(mergevert, BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (uvmerge) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, wmop, "pointmerge_facedata verts=%hv snapv=%e", BM_ELEM_SELECT, mergevert)) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, wmop, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, mergevert->co)) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-12 04:03:26 +00:00
										 |  |  | static int merge_target(BMEditMesh *em, Scene *scene, View3D *v3d, Object *ob,  | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  |                         int target, int uvmerge, wmOperator *wmop) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	float *vco = NULL, co[3], cent[3] = {0.0f, 0.0f, 0.0f}; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (target) { | 
					
						
							| 
									
										
										
										
											2009-09-12 04:03:26 +00:00
										 |  |  | 		vco = give_cursor(scene, v3d); | 
					
						
							| 
									
										
										
										
											2011-09-12 05:51:35 +00:00
										 |  |  | 		copy_v3_v3(co, vco); | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 		mul_m4_v3(ob->imat, co); | 
					
						
							| 
									
										
										
										
											2011-09-07 06:49:20 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		float fac; | 
					
						
							|  |  |  | 		int i = 0; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +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)) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2011-11-07 09:02:10 +00:00
										 |  |  | 			add_v3_v3(cent, v->co); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (!i) | 
					
						
							|  |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		fac = 1.0f / (float)i; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		mul_v3_fl(cent, fac); | 
					
						
							|  |  |  | 		copy_v3_v3(co, cent); | 
					
						
							| 
									
										
										
										
											2010-07-19 04:44:37 +00:00
										 |  |  | 		vco = co; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-19 04:44:37 +00:00
										 |  |  | 	if (!vco) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (uvmerge) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, wmop, "vert_average_facedata verts=%hv", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, wmop, "pointmerge verts=%hv mergeco=%v", BM_ELEM_SELECT, co)) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_merge_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 	View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											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 status = 0, uvs = RNA_boolean_get(op->ptr, "uvs"); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 	switch (RNA_enum_get(op->ptr, "type")) { | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		case 3: | 
					
						
							| 
									
										
										
										
											2009-09-12 04:03:26 +00:00
										 |  |  | 			status = merge_target(em, scene, v3d, obedit, 0, uvs, op); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 4: | 
					
						
							| 
									
										
										
										
											2009-09-12 04:03:26 +00:00
										 |  |  | 			status = merge_target(em, scene, v3d, obedit, 1, uvs, op); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			status = merge_firstlast(em, 0, uvs, op); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 6: | 
					
						
							|  |  |  | 			status = merge_firstlast(em, 1, uvs, op); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 5: | 
					
						
							|  |  |  | 			status = 1; | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 			if (!EDBM_op_callf(em, op, "collapse edges=%he", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 				status = 0; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (!status) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | static EnumPropertyItem merge_type_items[] = { | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 	{6, "FIRST", 0, "At First", ""}, | 
					
						
							|  |  |  | 	{1, "LAST", 0, "At Last", ""}, | 
					
						
							|  |  |  | 	{3, "CENTER", 0, "At Center", ""}, | 
					
						
							|  |  |  | 	{4, "CURSOR", 0, "At Cursor", ""}, | 
					
						
							|  |  |  | 	{5, "COLLAPSE", 0, "Collapse", ""}, | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL}}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-31 05:11:04 +00:00
										 |  |  | static EnumPropertyItem *merge_type_itemf(bContext *C, PointerRNA *UNUSED(ptr),  PropertyRNA *UNUSED(prop), int *free) | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | {	 | 
					
						
							|  |  |  | 	Object *obedit; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	EnumPropertyItem *item = NULL; | 
					
						
							|  |  |  | 	int totitem = 0; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (!C) /* needed for docs */ | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		return merge_type_items; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (obedit && obedit->type == OB_MESH) { | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 		BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 			if (em->bm->selected.first && em->bm->selected.last && | 
					
						
							|  |  |  | 			    ((BMEditSelection *)em->bm->selected.first)->htype == BM_VERT && | 
					
						
							|  |  |  | 			    ((BMEditSelection *)em->bm->selected.last)->htype == BM_VERT) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 				RNA_enum_items_add_value(&item, &totitem, merge_type_items, 6); | 
					
						
							|  |  |  | 				RNA_enum_items_add_value(&item, &totitem, merge_type_items, 1); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			else if (em->bm->selected.first && ((BMEditSelection *)em->bm->selected.first)->htype == BM_VERT) { | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 				RNA_enum_items_add_value(&item, &totitem, merge_type_items, 1); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else if (em->bm->selected.last && ((BMEditSelection *)em->bm->selected.last)->htype == BM_VERT) { | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 				RNA_enum_items_add_value(&item, &totitem, merge_type_items, 6); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RNA_enum_items_add_value(&item, &totitem, merge_type_items, 3); | 
					
						
							|  |  |  | 		RNA_enum_items_add_value(&item, &totitem, merge_type_items, 4); | 
					
						
							|  |  |  | 		RNA_enum_items_add_value(&item, &totitem, merge_type_items, 5); | 
					
						
							|  |  |  | 		RNA_enum_item_end(&item, &totitem); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		*free = 1; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return item; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_merge(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Merge"; | 
					
						
							| 
									
										
										
										
											2012-03-27 17:53:31 +00:00
										 |  |  | 	ot->description = "Merge selected vertices"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_merge"; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_merge_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->invoke = WM_menu_invoke; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->prop = RNA_def_enum(ot->srna, "type", merge_type_items, 3, "Type", "Merge method to use"); | 
					
						
							| 
									
										
										
										
											2010-07-22 04:45:18 +00:00
										 |  |  | 	RNA_def_enum_funcs(ot->prop, merge_type_itemf); | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "uvs", 1, "UVs", "Move UVs according to merge"); | 
					
						
							| 
									
										
										
										
											2009-08-31 23:07:05 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_remove_doubles_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +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-09-09 06:28:58 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2012-02-19 20:29:04 +00:00
										 |  |  | 	int count; | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "finddoubles verts=%hv dist=%f", BM_ELEM_SELECT, RNA_float_get(op->ptr, "mergedist")); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 20:29:04 +00:00
										 |  |  | 	count = BMO_slot_map_count(em->bm, &bmop, "targetmapout"); | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "weldverts targetmap=%s", &bmop, "targetmapout")) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMO_op_finish(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-19 20:29:04 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 	BKE_reportf(op->reports, RPT_INFO, "Removed %d vert%s", count, (count == 1) ? "ex" : "ices"); | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_remove_doubles(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Remove Doubles"; | 
					
						
							| 
									
										
										
										
											2012-03-27 17:53:31 +00:00
										 |  |  | 	ot->description= "Remove duplicate vertices"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_remove_doubles"; | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_remove_doubles_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 	RNA_def_float(ot->srna, "mergedist", 0.0001f, 0.000001f, 50.0f,  | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	              "Merge Distance", | 
					
						
							|  |  |  | 	              "Minimum distance between elements to merge", 0.00001, 10.0); | 
					
						
							| 
									
										
										
										
											2009-09-09 06:28:58 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /************************ Vertex Path Operator *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct PathNode { | 
					
						
							|  |  |  | 	int u; | 
					
						
							|  |  |  | 	int visited; | 
					
						
							|  |  |  | 	ListBase edges; | 
					
						
							|  |  |  | } PathNode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct PathEdge { | 
					
						
							|  |  |  | 	struct PathEdge *next, *prev; | 
					
						
							|  |  |  | 	int v; | 
					
						
							|  |  |  | 	float w; | 
					
						
							|  |  |  | } PathEdge; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_vertex_path_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	BMEditSelection *sv, *ev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* get the type from RNA */ | 
					
						
							|  |  |  | 	int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sv = em->bm->selected.last; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (sv != NULL) | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 		ev = sv->prev; | 
					
						
							|  |  |  | 	else return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (ev == NULL) | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if ((sv->htype != BM_VERT) || (ev->htype != BM_VERT)) | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "vertexshortestpath startv=%e endv=%e type=%i", sv->ele, ev->ele, type); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* execute the operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* DO NOT clear the existing selection */ | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	/* EDBM_flag_disable_all(em, BM_ELEM_SELECT); */ | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +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-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finish the operator */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* we succeeded */ | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_vertex_path(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static const EnumPropertyItem type_items[] = { | 
					
						
							|  |  |  | 		{VPATH_SELECT_EDGE_LENGTH, "EDGE_LENGTH", 0, "Edge Length", NULL}, | 
					
						
							|  |  |  | 		{VPATH_SELECT_TOPOLOGICAL, "TOPOLOGICAL", 0, "Topological", NULL}, | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Vertex Path"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_vertex_path"; | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_vertex_path_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 	RNA_def_enum(ot->srna, "type", type_items, VPATH_SELECT_EDGE_LENGTH, "Type", "Method to compute distance"); | 
					
						
							| 
									
										
										
										
											2009-09-20 18:18:40 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | /********************** Rip Operator *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* helper to find edge for edge_rip */ | 
					
						
							| 
									
										
										
										
											2012-03-07 01:14:20 +00:00
										 |  |  | static float mesh_rip_edgedist(ARegion *ar, float mat[][4], float *co1, float *co2, const float mvalf[2]) | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-07 01:14:20 +00:00
										 |  |  | 	float vec1[3], vec2[3]; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 01:06:18 +00:00
										 |  |  | 	ED_view3d_project_float_v2(ar, co1, vec1, mat); | 
					
						
							|  |  |  | 	ED_view3d_project_float_v2(ar, co2, vec2, mat); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 	return dist_to_line_segment_v2(mvalf, vec1, vec2); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* based on mouse cursor position, it defines how is being ripped */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							|  |  |  | 	RegionView3D *rv3d = CTX_wm_region_view3d(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	BMOIter siter; | 
					
						
							| 
									
										
										
										
											2012-03-07 04:20:30 +00:00
										 |  |  | 	BMIter iter, eiter, liter; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 	BMLoop *l; | 
					
						
							| 
									
										
										
										
											2012-03-07 01:06:18 +00:00
										 |  |  | 	BMEdge *e, *e2; | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 	BMVert *v, *ripvert = NULL; | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 	int i, singlesel = FALSE; | 
					
						
							| 
									
										
										
										
											2011-09-12 05:24:45 +00:00
										 |  |  | 	float projectMat[4][4], fmval[3] = {event->mval[0], event->mval[1]}; | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 	float dist = FLT_MAX; | 
					
						
							| 
									
										
										
										
											2012-03-09 04:10:19 +00:00
										 |  |  | 	float d; | 
					
						
							| 
									
										
										
										
											2012-03-28 08:00:58 +00:00
										 |  |  | 	const int totedge_orig = bm->totedge; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 00:08:00 +00:00
										 |  |  | 	/* note on selection:
 | 
					
						
							|  |  |  | 	 * When calling edge split we operate on tagged edges rather then selected | 
					
						
							|  |  |  | 	 * this is important because the edges to operate on are extended by one, | 
					
						
							|  |  |  | 	 * but the selection is left alone. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * After calling edge split - the duplicated edges have the same selection state as the | 
					
						
							|  |  |  | 	 * original, so all we do is de-select the far side from the mouse and we have a | 
					
						
							|  |  |  | 	 * useful selection for grabbing. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-24 04:35:21 +00:00
										 |  |  | 	ED_view3d_ob_project_mat_get(rv3d, obedit, projectMat); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 	/* BM_ELEM_SELECT --> BM_ELEM_TAG */ | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 	BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-25 19:43:51 +00:00
										 |  |  | 		BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT)); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* handle case of one vert selected.  identify
 | 
					
						
							|  |  |  | 	 * closest edge around that vert to mouse cursor, | 
					
						
							|  |  |  | 	 * then rip two adjacent edges in the vert fan. */ | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 	if (bm->totvertsel == 1 && bm->totedgesel == 0 && bm->totfacesel == 0) { | 
					
						
							| 
									
										
										
										
											2012-03-07 00:08:00 +00:00
										 |  |  | 		BMEditSelection ese; | 
					
						
							|  |  |  | 		singlesel = TRUE; | 
					
						
							| 
									
										
										
										
											2009-11-04 09:37:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 00:08:00 +00:00
										 |  |  | 		/* find selected vert - same some time and check history first */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (EDBM_editselection_active_get(em, &ese) && ese.htype == BM_VERT) { | 
					
						
							| 
									
										
										
										
											2012-03-07 00:08:00 +00:00
										 |  |  | 			v = (BMVert *)ese.ele; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							|  |  |  | 				if (BM_elem_flag_test(v, BM_ELEM_SELECT)) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-10-24 05:43:27 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* this should be impossible, but sanity checks are a good thing */ | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 		if (!v) | 
					
						
							|  |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 		e2 = NULL; | 
					
						
							| 
									
										
										
										
											2012-03-28 05:44:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (v->e) { | 
					
						
							|  |  |  | 			/* find closest edge to mouse cursor */ | 
					
						
							|  |  |  | 			BM_ITER(e, &iter, bm, BM_EDGES_OF_VERT, v) { | 
					
						
							| 
									
										
										
										
											2012-03-28 08:00:58 +00:00
										 |  |  | 				if (!BM_elem_flag_test(e, BM_ELEM_HIDDEN) && BM_edge_face_count(e) == 2) { | 
					
						
							| 
									
										
										
										
											2012-03-28 05:44:38 +00:00
										 |  |  | 					d = mesh_rip_edgedist(ar, projectMat, e->v1->co, e->v2->co, fmval); | 
					
						
							|  |  |  | 					if (d < dist) { | 
					
						
							|  |  |  | 						dist = d; | 
					
						
							|  |  |  | 						e2 = e; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-03-28 05:44:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-28 05:44:38 +00:00
										 |  |  | 		if (!e2) { | 
					
						
							| 
									
										
										
										
											2012-03-28 08:00:58 +00:00
										 |  |  | 			BKE_report(op->reports, RPT_ERROR, "Selected vertex has no edge/face pairs attached"); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-03-28 05:44:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* rip two adjacent edges */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_edge_face_count(e2) == 1 || BM_vert_face_count(v) == 2) { | 
					
						
							| 
									
										
										
										
											2010-07-14 22:06:10 +00:00
										 |  |  | 			l = e2->l; | 
					
						
							| 
									
										
										
										
											2012-03-09 00:41:09 +00:00
										 |  |  | 			ripvert = BM_face_vert_separate(bm, l->f, v); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 			BLI_assert(ripvert); | 
					
						
							|  |  |  | 			if (!ripvert) { | 
					
						
							|  |  |  | 				return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		else if (BM_edge_face_count(e2) == 2) { | 
					
						
							| 
									
										
										
										
											2010-07-14 22:06:10 +00:00
										 |  |  | 			l = e2->l; | 
					
						
							| 
									
										
										
										
											2012-03-04 16:36:31 +00:00
										 |  |  | 			e = BM_face_other_edge_loop(l->f, e2, v)->e; | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_enable(e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2010-07-14 22:06:10 +00:00
										 |  |  | 			l = e2->l->radial_next; | 
					
						
							| 
									
										
										
										
											2012-03-04 16:36:31 +00:00
										 |  |  | 			e = BM_face_other_edge_loop(l->f, e2, v)->e; | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BM_elem_flag_enable(e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-11-04 09:37:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		dist = FLT_MAX; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* expand edge selection */ | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 		BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 			e2 = NULL; | 
					
						
							|  |  |  | 			i = 0; | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 			BM_ITER(e, &eiter, bm, BM_EDGES_OF_VERT, v) { | 
					
						
							| 
									
										
										
										
											2012-03-07 00:08:00 +00:00
										 |  |  | 				/* important to check selection rather then tag here
 | 
					
						
							|  |  |  | 				 * else we get feedback loop */ | 
					
						
							|  |  |  | 				if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 					e2 = e; | 
					
						
							|  |  |  | 					i++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2010-07-14 22:06:10 +00:00
										 |  |  | 			if (i == 1 && e2->l) { | 
					
						
							| 
									
										
										
										
											2012-03-04 16:36:31 +00:00
										 |  |  | 				l = BM_face_other_edge_loop(e2->l->f, e2, v); | 
					
						
							| 
									
										
										
										
											2011-09-12 15:10:59 +00:00
										 |  |  | 				l = l->radial_next; | 
					
						
							| 
									
										
										
										
											2012-03-04 16:36:31 +00:00
										 |  |  | 				l = BM_face_other_edge_loop(l->f, l->e, v); | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 				if (l) { | 
					
						
							| 
									
										
										
										
											2012-03-07 00:08:00 +00:00
										 |  |  | 					BM_elem_flag_enable(l->e, BM_ELEM_TAG); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-10-22 23:22:05 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &bmop, op, "edgesplit edges=%he verts=%hv use_verts=%b", | 
					
						
							| 
									
										
										
										
											2012-03-26 12:02:41 +00:00
										 |  |  | 	                  BM_ELEM_TAG, BM_ELEM_SELECT, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &bmop); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-28 08:00:58 +00:00
										 |  |  | 	if (totedge_orig == bm->totedge) { | 
					
						
							|  |  |  | 		EDBM_op_finish(em, &bmop, op, TRUE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BKE_report(op->reports, RPT_ERROR, "No edges could be ripped"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 	BMO_ITER(e, &siter, bm, &bmop, "edgeout", BM_EDGE) { | 
					
						
							|  |  |  | 		float cent[3] = {0, 0, 0}, mid[3]; | 
					
						
							| 
									
										
										
										
											2012-03-09 04:10:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		float vec[2]; | 
					
						
							|  |  |  | 		float fmval_tweak[2]; | 
					
						
							|  |  |  | 		float e_v1_co[2], e_v2_co[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 		BMVert *v1_other; | 
					
						
							|  |  |  | 		BMVert *v2_other; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 		/* method for calculating distance:
 | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * for each edge: calculate face center, then made a vector | 
					
						
							|  |  |  | 		 * from edge midpoint to face center.  offset edge midpoint | 
					
						
							|  |  |  | 		 * by a small amount along this vector. */ | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 		/* rather then the face center, get the middle of
 | 
					
						
							|  |  |  | 		 * both edge verts connected to this one */ | 
					
						
							|  |  |  | 		v1_other = BM_face_other_vert_loop(e->l->f, e->v2, e->v1)->v; | 
					
						
							|  |  |  | 		v2_other = BM_face_other_vert_loop(e->l->f, e->v1, e->v2)->v; | 
					
						
							|  |  |  | 		mid_v3_v3v3(cent, v1_other->co, v2_other->co); | 
					
						
							|  |  |  | 		mid_v3_v3v3(mid, e->v1->co, e->v2->co); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 		ED_view3d_project_float_v2(ar, cent, cent, projectMat); | 
					
						
							|  |  |  | 		ED_view3d_project_float_v2(ar, mid, mid, projectMat); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 04:10:19 +00:00
										 |  |  | 		ED_view3d_project_float_v2(ar, e->v1->co, e_v1_co, projectMat); | 
					
						
							|  |  |  | 		ED_view3d_project_float_v2(ar, e->v2->co, e_v2_co, projectMat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 		sub_v2_v2v2(vec, cent, mid); | 
					
						
							|  |  |  | 		normalize_v2(vec); | 
					
						
							| 
									
										
										
										
											2012-03-09 04:10:19 +00:00
										 |  |  | 		mul_v2_fl(vec, 0.01f); | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 04:10:19 +00:00
										 |  |  | 		/* rather then adding to both verts, subtract from the mouse */ | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 		sub_v2_v2v2(fmval_tweak, fmval, vec); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 04:10:19 +00:00
										 |  |  | 		if (dist_to_line_segment_v2(fmval_tweak, e_v1_co, e_v2_co) > | 
					
						
							|  |  |  | 		    dist_to_line_segment_v2(fmval,       e_v1_co, e_v2_co)) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2012-03-09 03:16:39 +00:00
										 |  |  | 			BM_elem_select_set(bm, e, FALSE); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 02:46:58 +00:00
										 |  |  | 	if (singlesel) { | 
					
						
							|  |  |  | 		BMVert *v_best = NULL; | 
					
						
							| 
									
										
										
										
											2012-03-07 04:20:30 +00:00
										 |  |  | 		float l_prev_co[3], l_next_co[3], l_corner_co[3]; | 
					
						
							|  |  |  | 		float scale; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 02:46:58 +00:00
										 |  |  | 		/* not good enough! - original vert may not be attached to the closest edge */ | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 		EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BM_elem_select_set(bm, ripvert, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-07 02:46:58 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		dist = FLT_MAX; | 
					
						
							|  |  |  | 		BM_ITER(v, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							|  |  |  | 			if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-03-07 03:46:30 +00:00
										 |  |  | 				/* disable by default, re-enable winner at end */ | 
					
						
							| 
									
										
										
										
											2012-03-07 02:46:58 +00:00
										 |  |  | 				BM_elem_select_set(bm, v, FALSE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-07 04:20:30 +00:00
										 |  |  | 				BM_ITER(l, &liter, bm, BM_LOOPS_OF_VERT, v) { | 
					
						
							|  |  |  | 					/* calculate a point in the face, rather then calculate the middle,
 | 
					
						
							|  |  |  | 					 * make a vector pointing between the 2 edges attached to this loop */ | 
					
						
							|  |  |  | 					sub_v3_v3v3(l_prev_co, l->prev->v->co, l->v->co); | 
					
						
							|  |  |  | 					sub_v3_v3v3(l_next_co, l->next->v->co, l->v->co); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					scale = normalize_v3(l_prev_co) + normalize_v3(l_next_co); | 
					
						
							|  |  |  | 					mul_v3_fl(l_prev_co, scale); | 
					
						
							|  |  |  | 					mul_v3_fl(l_next_co, scale); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					add_v3_v3v3(l_corner_co, l_prev_co, l_next_co); | 
					
						
							|  |  |  | 					add_v3_v3(l_corner_co, l->v->co); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					d = mesh_rip_edgedist(ar, projectMat, l->v->co, l_corner_co, fmval); | 
					
						
							| 
									
										
										
										
											2012-03-07 02:46:58 +00:00
										 |  |  | 					if (d < dist) { | 
					
						
							|  |  |  | 						v_best = v; | 
					
						
							|  |  |  | 						dist = d; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (v_best) { | 
					
						
							|  |  |  | 			BM_elem_select_set(bm, v_best, TRUE); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BLI_assert(singlesel ? (bm->totvertsel > 0) : (bm->totedgesel > 0)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-12 06:11:21 +00:00
										 |  |  | 	if (bm->totvertsel == 0) { | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_rip(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Rip"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_rip"; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_rip_invoke; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = EM_view3d_poll; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* to give to transform */ | 
					
						
							| 
									
										
										
										
											2010-07-19 04:44:37 +00:00
										 |  |  | 	Transform_Properties(ot, P_PROPORTIONAL); | 
					
						
							| 
									
										
										
										
											2009-10-07 21:19:58 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", ""); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************ Shape Operators *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | /* BMESH_TODO this should be properly encapsulated in a bmop.  but later.*/ | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | static void shape_propagate(BMEditMesh *em, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMVert *eve = NULL; | 
					
						
							|  |  |  | 	float *co; | 
					
						
							|  |  |  | 	int i, totshape = CustomData_number_of_layers(&em->bm->vdata, CD_SHAPEKEY); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!CustomData_has_layer(&em->bm->vdata, CD_SHAPEKEY)) { | 
					
						
							|  |  |  | 		BKE_report(op->reports, RPT_ERROR, "Mesh does not have shape keys"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	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_SELECT) || BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		for (i = 0; i < totshape; i++) { | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			co = CustomData_bmesh_get_n(&em->bm->vdata, eve->head.data, CD_SHAPEKEY, i); | 
					
						
							| 
									
										
										
										
											2011-09-12 05:51:35 +00:00
										 |  |  | 			copy_v3_v3(co, eve->co); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	//TAG Mesh Objects that share this data
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (base = scene->base.first; base; base = base->next) { | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (base->object && base->object->data == me) { | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			base->object->recalc = OB_RECALC_DATA; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_shape_propagate_to_all_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Mesh *me = obedit->data; | 
					
						
							|  |  |  | 	BMEditMesh *em = me->edit_btmesh; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	shape_propagate(em, op); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, FALSE); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_shape_propagate_to_all(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Shape Propagate"; | 
					
						
							|  |  |  | 	ot->description = "Apply selected vertex locations to all other shape keys"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_shape_propagate_to_all"; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_shape_propagate_to_all_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | /* BMESH_TODO this should be properly encapsulated in a bmop.  but later.*/ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_blend_from_shape_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Mesh *me = obedit->data; | 
					
						
							|  |  |  | 	BMEditMesh *em = me->edit_btmesh; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	float co[3], *sco; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	float blend = RNA_float_get(op->ptr, "blend"); | 
					
						
							|  |  |  | 	int shape = RNA_enum_get(op->ptr, "shape"); | 
					
						
							|  |  |  | 	int add = RNA_boolean_get(op->ptr, "add"); | 
					
						
							| 
									
										
										
										
											2010-07-19 04:44:37 +00:00
										 |  |  | 	int totshape; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* sanity check */ | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 	totshape = CustomData_number_of_layers(&em->bm->vdata, CD_SHAPEKEY); | 
					
						
							|  |  |  | 	if (totshape == 0 || shape < 0 || shape >= totshape) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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_SELECT) || BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		sco = CustomData_bmesh_get_n(&em->bm->vdata, eve->head.data, CD_SHAPEKEY, shape); | 
					
						
							| 
									
										
										
										
											2011-09-12 05:51:35 +00:00
										 |  |  | 		copy_v3_v3(co, sco); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (add) { | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 			mul_v3_fl(co, blend); | 
					
						
							|  |  |  | 			add_v3_v3v3(eve->co, eve->co, co); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2009-11-23 14:41:22 +00:00
										 |  |  | 			interp_v3_v3v3(eve->co, eve->co, co, blend); | 
					
						
							| 
									
										
										
										
											2012-03-06 17:23:26 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-09-12 05:51:35 +00:00
										 |  |  | 		copy_v3_v3(sco, co); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-31 05:11:04 +00:00
										 |  |  | static EnumPropertyItem *shape_itemf(bContext *C, PointerRNA *UNUSED(ptr),  PropertyRNA *UNUSED(prop), int *free) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | {	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-08 01:22:49 +00:00
										 |  |  | 	BMEditMesh *em; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	EnumPropertyItem *item = NULL; | 
					
						
							|  |  |  | 	int totitem = 0; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 01:22:49 +00:00
										 |  |  | 	if ((obedit && obedit->type == OB_MESH) && | 
					
						
							|  |  |  | 	    (em = BMEdit_FromObject(obedit)) && | 
					
						
							|  |  |  | 	    CustomData_has_layer(&em->bm->vdata, CD_SHAPEKEY)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		EnumPropertyItem tmp = {0, "", 0, "", ""}; | 
					
						
							| 
									
										
										
										
											2011-09-07 06:49:20 +00:00
										 |  |  | 		int a; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		for (a = 0; a < em->bm->vdata.totlayer; a++) { | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			if (em->bm->vdata.layers[a].type != CD_SHAPEKEY) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			tmp.value = totitem; | 
					
						
							|  |  |  | 			tmp.identifier = em->bm->vdata.layers[a].name; | 
					
						
							|  |  |  | 			tmp.name = em->bm->vdata.layers[a].name; | 
					
						
							| 
									
										
										
										
											2012-03-27 20:45:06 +00:00
										 |  |  | 			/* RNA_enum_item_add sets totitem itself! */ | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			RNA_enum_item_add(&item, &totitem, &tmp); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_enum_item_end(&item, &totitem); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	*free = 1; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return item; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_blend_from_shape(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PropertyRNA *prop; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	static EnumPropertyItem shape_items[] = {{0, NULL, 0, NULL, NULL}}; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Blend From Shape"; | 
					
						
							|  |  |  | 	ot->description = "Blend in shape from a shape key"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_blend_from_shape"; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_blend_from_shape_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->invoke = WM_operator_props_popup; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	prop = RNA_def_enum(ot->srna, "shape", shape_items, 0, "Shape", "Shape key to use for blending"); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 	RNA_def_enum_funcs(prop, shape_itemf); | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 	RNA_def_float(ot->srna, "blend", 1.0f, -FLT_MAX, FLT_MAX, "Blend", "Blending factor", -2.0f, 2.0f); | 
					
						
							| 
									
										
										
										
											2012-02-27 18:14:56 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "add", 1, "Add", "Add rather than blend between shapes"); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-07 12:45:55 +00:00
										 |  |  | /* BMESH_TODO - some way to select on an arbitrary axis */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_axis_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +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-11-07 23:10:18 +00:00
										 |  |  | 	BMEditSelection *ese = em->bm->selected.last; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int axis = RNA_enum_get(op->ptr, "axis"); | 
					
						
							|  |  |  | 	int mode = RNA_enum_get(op->ptr, "mode"); /* -1 == aligned, 0 == neg, 1 == pos */ | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (ese == NULL || ese->htype != BM_VERT) { | 
					
						
							| 
									
										
										
										
											2011-12-12 21:01:39 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_WARNING, "This operator requires an active vertex (last selected)"); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2011-12-12 21:01:39 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-02-25 22:23:40 +00:00
										 |  |  | 		BMVert *ev, *act_vert = (BMVert *)ese->ele; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 		BMIter iter; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		float value = act_vert->co[axis]; | 
					
						
							|  |  |  | 		float limit =  CTX_data_tool_settings(C)->doublimit; // XXX
 | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (mode == 0) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			value -= limit; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		else if (mode == 1) | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 			value += limit; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		BM_ITER(ev, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (!BM_elem_flag_test(ev, BM_ELEM_HIDDEN)) { | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 				switch (mode) { | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 					case -1: /* aligned */ | 
					
						
							|  |  |  | 						if (fabs(ev->co[axis] - value) < limit) | 
					
						
							|  |  |  | 							BM_elem_select_set(em->bm, ev, TRUE); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 0: /* neg */ | 
					
						
							|  |  |  | 						if (ev->co[axis] > value) | 
					
						
							|  |  |  | 							BM_elem_select_set(em->bm, ev, TRUE); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 1: /* pos */ | 
					
						
							|  |  |  | 						if (ev->co[axis] < value) | 
					
						
							|  |  |  | 							BM_elem_select_set(em->bm, ev, TRUE); | 
					
						
							|  |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_axis(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	static EnumPropertyItem axis_mode_items[] = { | 
					
						
							|  |  |  | 		{0,  "POSITIVE", 0, "Positive Axis", ""}, | 
					
						
							|  |  |  | 		{1,  "NEGATIVE", 0, "Negative Axis", ""}, | 
					
						
							|  |  |  | 		{-1, "ALIGNED",  0, "Aligned Axis", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL}}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	static EnumPropertyItem axis_items_xyz[] = { | 
					
						
							|  |  |  | 		{0, "X_AXIS", 0, "X Axis", ""}, | 
					
						
							|  |  |  | 		{1, "Y_AXIS", 0, "Y Axis", ""}, | 
					
						
							|  |  |  | 		{2, "Z_AXIS", 0, "Z Axis", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL}}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Axis"; | 
					
						
							|  |  |  | 	ot->description = "Select all data in the mesh on a single axis"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_axis"; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_axis_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "mode", axis_mode_items, 0, "Axis Mode", "Axis side to use when selecting"); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	RNA_def_enum(ot->srna, "axis", axis_items_xyz, 0, "Axis", "Select the axis to compare each vertex on"); | 
					
						
							| 
									
										
										
										
											2009-11-07 23:10:18 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_solidify_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2011-09-23 12:06:47 +00:00
										 |  |  | 	Mesh *me = obedit->data; | 
					
						
							|  |  |  | 	BMEditMesh *em = me->edit_btmesh; | 
					
						
							|  |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	float thickness = RNA_float_get(op->ptr, "thickness"); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &bmop, op, "solidify geom=%hf thickness=%f", BM_ELEM_SELECT, thickness)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-23 12:06:47 +00:00
										 |  |  | 	/* deselect only the faces in the region to be solidified (leave wire
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 	 * edges and loose verts selected, as there will be no corresponding | 
					
						
							|  |  |  | 	 * geometry selected below) */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_disable(bm, &bmop, "geom", BM_FACE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-23 12:06:47 +00:00
										 |  |  | 	/* run the solidify operator */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &bmop); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-23 12:06:47 +00:00
										 |  |  | 	/* select the newly generated faces */ | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(bm, &bmop, "geomout", BM_FACE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2011-09-23 12:06:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_solidify(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Solidify"; | 
					
						
							|  |  |  | 	ot->description = "Create a solid skin by extruding, compensating for sharp angles"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_solidify"; | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_solidify_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	prop = RNA_def_float(ot->srna, "thickness", 0.01f, -FLT_MAX, FLT_MAX, "thickness", "", -10.0f, 10.0f); | 
					
						
							| 
									
										
										
										
											2010-01-05 22:33:41 +00:00
										 |  |  | 	RNA_def_property_ui_range(prop, -10, 10, 0.1, 4); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define TRAIL_POLYLINE 1 /* For future use, They don't do anything yet */
 | 
					
						
							|  |  |  | #define TRAIL_FREEHAND 2
 | 
					
						
							|  |  |  | #define TRAIL_MIXED    3 /* (1|2) */
 | 
					
						
							|  |  |  | #define TRAIL_AUTO     4 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | #define TRAIL_MIDPOINTS 8
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct CutCurve { | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	float x; | 
					
						
							|  |  |  | 	float y; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } CutCurve; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ******************************************************************** */ | 
					
						
							|  |  |  | /* Knife Subdivide Tool.  Subdivides edges intersected by a mouse trail
 | 
					
						
							| 
									
										
										
										
											2012-02-27 13:47:53 +00:00
										 |  |  |  * drawn by user. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Currently mapped to KKey when in MeshEdit mode. | 
					
						
							|  |  |  |  * Usage: | 
					
						
							|  |  |  |  * - Hit Shift K, Select Centers or Exact | 
					
						
							|  |  |  |  * - Hold LMB down to draw path, hit RETKEY. | 
					
						
							|  |  |  |  * - ESC cancels as expected. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributed by Robert Wenzlaff (Det. Thorn). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2.5 Revamp: | 
					
						
							|  |  |  |  *  - non modal (no menu before cutting) | 
					
						
							|  |  |  |  *  - exit on mouse release | 
					
						
							|  |  |  |  *  - polygon/segment drawing can become handled by WM cb later | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * bmesh port version | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | #define KNIFE_EXACT     1
 | 
					
						
							|  |  |  | #define KNIFE_MIDPOINT  2
 | 
					
						
							|  |  |  | #define KNIFE_MULTICUT  3
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | static EnumPropertyItem knife_items[] = { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	{KNIFE_EXACT, "EXACT", 0, "Exact", ""}, | 
					
						
							|  |  |  | 	{KNIFE_MIDPOINT, "MIDPOINTS", 0, "Midpoints", ""}, | 
					
						
							|  |  |  | 	{KNIFE_MULTICUT, "MULTICUT", 0, "Multicut", ""}, | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-27 13:47:53 +00:00
										 |  |  | /* bm_edge_seg_isect() Determines if and where a mouse trail intersects an BMEdge */ | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-13 02:42:50 +00:00
										 |  |  | static float bm_edge_seg_isect(BMEdge *e, CutCurve *c, int len, char mode, | 
					
						
							|  |  |  |                                struct GHash *gh, int *isected) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #define MAXSLOPE 100000
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	float x11, y11, x12 = 0, y12 = 0, x2max, x2min, y2max; | 
					
						
							|  |  |  | 	float y2min, dist, lastdist = 0, xdiff2, xdiff1; | 
					
						
							|  |  |  | 	float m1, b1, m2, b2, x21, x22, y21, y22, xi; | 
					
						
							|  |  |  | 	float yi, x1min, x1max, y1max, y1min, perc = 0; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	float  *scr; | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	float threshold = 0.0; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	//threshold = 0.000001; /* tolerance for vertex intersection */
 | 
					
						
							| 
									
										
										
										
											2012-03-20 04:27:14 +00:00
										 |  |  | 	// XXX threshold = scene->toolsettings->select_thresh / 100;
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* Get screen coords of verts */ | 
					
						
							|  |  |  | 	scr = BLI_ghash_lookup(gh, e->v1); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	x21 = scr[0]; | 
					
						
							|  |  |  | 	y21 = scr[1]; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	scr = BLI_ghash_lookup(gh, e->v2); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	x22 = scr[0]; | 
					
						
							|  |  |  | 	y22 = scr[1]; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	xdiff2 = (x22 - x21); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	if (xdiff2) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		m2 = (y22 - y21) / xdiff2; | 
					
						
							|  |  |  | 		b2 = ((x22 * y21) - (x21 * y22)) / xdiff2; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		m2 = MAXSLOPE;  /* Verticle slope  */ | 
					
						
							|  |  |  | 		b2 = x22; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*isected = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 	/* check for _exact_ vertex intersection first */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (mode != KNIFE_MULTICUT) { | 
					
						
							|  |  |  | 		for (i = 0; i < len; i++) { | 
					
						
							|  |  |  | 			if (i > 0) { | 
					
						
							|  |  |  | 				x11 = x12; | 
					
						
							|  |  |  | 				y11 = y12; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				x11 = c[i].x; | 
					
						
							|  |  |  | 				y11 = c[i].y; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			x12 = c[i].x; | 
					
						
							|  |  |  | 			y12 = c[i].y; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 			/* test e->v1 */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			if ((x11 == x21 && y11 == y21) || (x12 == x21 && y12 == y21)) { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 				perc = 0; | 
					
						
							|  |  |  | 				*isected = 1; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				return perc; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 			/* test e->v2 */ | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			else if ((x11 == x22 && y11 == y22) || (x12 == x22 && y12 == y22)) { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 				perc = 0; | 
					
						
							|  |  |  | 				*isected = 2; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				return perc; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-07 00:08:00 +00:00
										 |  |  | 	/* now check for edge intersect (may produce vertex intersection as well) */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (i = 0; i < len; i++) { | 
					
						
							|  |  |  | 		if (i > 0) { | 
					
						
							|  |  |  | 			x11 = x12; | 
					
						
							|  |  |  | 			y11 = y12; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			x11 = c[i].x; | 
					
						
							|  |  |  | 			y11 = c[i].y; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		x12 = c[i].x; | 
					
						
							|  |  |  | 		y12 = c[i].y; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* Perp. Distance from point to line */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		if (m2 != MAXSLOPE) dist = (y12 - m2 * x12 - b2);  /* /sqrt(m2 * m2 + 1); Only looking for */ | 
					
						
							|  |  |  | 		/* change in sign.  Skip extra math */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		else dist = x22 - x12; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		if (i == 0) lastdist = dist; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* if dist changes sign, and intersect point in edge's Bound Box */ | 
					
						
							|  |  |  | 		if ((lastdist * dist) <= 0) { | 
					
						
							|  |  |  | 			xdiff1 = (x12 - x11); /* Equation of line between last 2 points */ | 
					
						
							| 
									
										
										
										
											2011-12-21 04:56:04 +00:00
										 |  |  | 			if (xdiff1) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				m1 = (y12 - y11) / xdiff1; | 
					
						
							|  |  |  | 				b1 = ((x12 * y11) - (x11 * y12)) / xdiff1; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				m1 = MAXSLOPE; | 
					
						
							|  |  |  | 				b1 = x12; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			x2max = MAX2(x21, x22) + 0.001; /* prevent missed edges   */ | 
					
						
							|  |  |  | 			x2min = MIN2(x21, x22) - 0.001; /* due to round off error */ | 
					
						
							|  |  |  | 			y2max = MAX2(y21, y22) + 0.001; | 
					
						
							|  |  |  | 			y2min = MIN2(y21, y22) - 0.001; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			/* Found an intersect,  calc intersect point */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			if (m1 == m2) { /* co-incident lines */ | 
					
						
							|  |  |  | 				/* cut at 50% of overlap area */ | 
					
						
							|  |  |  | 				x1max = MAX2(x11, x12); | 
					
						
							|  |  |  | 				x1min = MIN2(x11, x12); | 
					
						
							|  |  |  | 				xi = (MIN2(x2max, x1max) + MAX2(x2min, x1min)) / 2.0; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				y1max = MAX2(y11, y12); | 
					
						
							|  |  |  | 				y1min = MIN2(y11, y12); | 
					
						
							|  |  |  | 				yi = (MIN2(y2max, y1max) + MAX2(y2min, y1min)) / 2.0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (m2 == MAXSLOPE) { | 
					
						
							|  |  |  | 				xi = x22; | 
					
						
							|  |  |  | 				yi = m1 * x22 + b1; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			else if (m1 == MAXSLOPE) { | 
					
						
							|  |  |  | 				xi = x12; | 
					
						
							|  |  |  | 				yi = m2 * x12 + b2; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				xi = (b1 - b2) / (m2 - m1); | 
					
						
							|  |  |  | 				yi = (b1 * m2 - m1 * b2) / (m2 - m1); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			/* Intersect inside bounding box of edge?*/ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			if ((xi >= x2min) && (xi <= x2max) && (yi <= y2max) && (yi >= y2min)) { | 
					
						
							|  |  |  | 				/* test for vertex intersect that may be 'close enough'*/ | 
					
						
							|  |  |  | 				if (mode != KNIFE_MULTICUT) { | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 					if (xi <= (x21 + threshold) && xi >= (x21 - threshold)) { | 
					
						
							|  |  |  | 						if (yi <= (y21 + threshold) && yi >= (y21 - threshold)) { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 							*isected = 1; | 
					
						
							|  |  |  | 							perc = 0; | 
					
						
							|  |  |  | 							break; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 					if (xi <= (x22 + threshold) && xi >= (x22 - threshold)) { | 
					
						
							|  |  |  | 						if (yi <= (y22 + threshold) && yi >= (y22 - threshold)) { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 							*isected = 2; | 
					
						
							|  |  |  | 							perc = 0; | 
					
						
							|  |  |  | 							break; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				if ((m2 <= 1.0f) && (m2 >= -1.0f)) perc = (xi - x21) / (x22 - x21); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 				else perc = (yi - y21) / (y22 - y21);  /* lower slope more accurate */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				//isect = 32768.0 * (perc + 0.0000153); /* Percentage in 1 / 32768ths */
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		lastdist = dist; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 	return perc; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 04:54:53 +00:00
										 |  |  | #define MAX_CUTS 2048
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_knife_cut_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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-01-28 00:45:30 +00:00
										 |  |  | 	BMesh *bm = em->bm; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ARegion *ar = CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	BMVert *bv; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMEdge *be; | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	CutCurve curve[MAX_CUTS]; | 
					
						
							|  |  |  | 	struct GHash *gh; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	float isect = 0.0f; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	float  *scr, co[4]; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int len = 0, isected; | 
					
						
							|  |  |  | 	short numcuts = 1, mode = RNA_int_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* edit-object needed for matrix, and ar->regiondata for projections to work */ | 
					
						
							|  |  |  | 	if (ELEM3(NULL, obedit, ar, ar->regiondata)) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (bm->totvertsel < 2) { | 
					
						
							| 
									
										
										
										
											2010-02-18 10:09:52 +00:00
										 |  |  | 		//error("No edges are selected to operate on");
 | 
					
						
							| 
									
										
										
										
											2012-02-25 16:04:03 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* get the cut curve */ | 
					
						
							|  |  |  | 	RNA_BEGIN(op->ptr, itemptr, "path") { | 
					
						
							|  |  |  | 		RNA_float_get_array(&itemptr, "loc", (float *)&curve[len]); | 
					
						
							|  |  |  | 		len++; | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 		if (len >= MAX_CUTS) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	RNA_END; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (len < 2) { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* the floating point coordinates of verts in screen space will be stored in a hash table according to the vertices pointer */ | 
					
						
							| 
									
										
										
										
											2010-07-19 04:44:37 +00:00
										 |  |  | 	gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife cut exec"); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	for (bv = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); bv; bv = BM_iter_step(&iter)) { | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 		scr = MEM_mallocN(sizeof(float) * 2, "Vertex Screen Coordinates"); | 
					
						
							| 
									
										
										
										
											2011-09-12 05:51:35 +00:00
										 |  |  | 		copy_v3_v3(co, bv->co); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		co[3] = 1.0f; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		mul_m4_v4(obedit->obmat, co); | 
					
						
							|  |  |  | 		project_float(ar, co, scr); | 
					
						
							|  |  |  | 		BLI_ghash_insert(gh, bv, scr); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &bmop, op, "esubd")) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-11-16 17:09:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* store percentage of edge cut for KNIFE_EXACT here.*/ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	for (be = BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, NULL); be; be = BM_iter_step(&iter)) { | 
					
						
							| 
									
										
										
										
											2012-02-17 21:49:24 +00:00
										 |  |  | 		if (BM_elem_flag_test(be, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-13 02:42:50 +00:00
										 |  |  | 			isect = bm_edge_seg_isect(be, curve, len, mode, gh, &isected); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			if (isect != 0.0f) { | 
					
						
							|  |  |  | 				if (mode != KNIFE_MULTICUT && mode != KNIFE_MIDPOINT) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 					BMO_slot_map_float_insert(bm, &bmop, | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 					                          "edgepercents", | 
					
						
							|  |  |  | 					                          be, isect); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BMO_elem_flag_enable(bm, be, 1); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 				BMO_elem_flag_disable(bm, be, 1); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 			BMO_elem_flag_disable(bm, be, 1); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-30 17:30:49 +00:00
										 |  |  | 	BMO_slot_buffer_from_enabled_flag(bm, &bmop, "edges", BM_EDGE, 1); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (mode == KNIFE_MIDPOINT) numcuts = 1; | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_slot_int_set(&bmop, "numcuts", numcuts); | 
					
						
							| 
									
										
										
										
											2010-07-22 04:54:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_slot_int_set(&bmop, "flag", B_KNIFE); | 
					
						
							|  |  |  | 	BMO_slot_int_set(&bmop, "quadcornertype", SUBD_STRAIGHT_CUT); | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 	BMO_slot_bool_set(&bmop, "singleedge", FALSE); | 
					
						
							|  |  |  | 	BMO_slot_bool_set(&bmop, "gridfill", FALSE); | 
					
						
							| 
									
										
										
										
											2010-07-22 04:54:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_slot_float_set(&bmop, "radius", 0); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-05-11 20:40:03 +00:00
										 |  |  | 	BLI_ghash_free(gh, NULL, (GHashValFreeFP)MEM_freeN); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_knife_cut(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Knife Cut"; | 
					
						
							|  |  |  | 	ot->description = "Cut selected edges and faces into parts"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_knife_cut"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->invoke = WM_gesture_lines_invoke; | 
					
						
							|  |  |  | 	ot->modal = WM_gesture_lines_modal; | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_knife_cut_exec; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = EM_view3d_poll; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "type", knife_items, KNIFE_EXACT, "Type", ""); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* internal */ | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmOperator *wmop) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Base *basenew; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	Object *obedit = editbase->object; | 
					
						
							|  |  |  | 	Mesh *me = obedit->data; | 
					
						
							|  |  |  | 	BMEditMesh *em = me->edit_btmesh; | 
					
						
							| 
									
										
										
										
											2012-03-01 22:17:04 +00:00
										 |  |  | 	BMesh *bm_new; | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (!em) | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-11 19:58:56 +00:00
										 |  |  | 	bm_new = BM_mesh_create(&bm_mesh_allocsize_default); | 
					
						
							| 
									
										
										
										
											2012-03-01 22:17:04 +00:00
										 |  |  | 	CustomData_copy(&em->bm->vdata, &bm_new->vdata, CD_MASK_BMESH, CD_CALLOC, 0); | 
					
						
							|  |  |  | 	CustomData_copy(&em->bm->edata, &bm_new->edata, CD_MASK_BMESH, CD_CALLOC, 0); | 
					
						
							|  |  |  | 	CustomData_copy(&em->bm->ldata, &bm_new->ldata, CD_MASK_BMESH, CD_CALLOC, 0); | 
					
						
							|  |  |  | 	CustomData_copy(&em->bm->pdata, &bm_new->pdata, CD_MASK_BMESH, CD_CALLOC, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	CustomData_bmesh_init_pool(&bm_new->vdata, bm_mesh_allocsize_default.totvert, BM_VERT); | 
					
						
							|  |  |  | 	CustomData_bmesh_init_pool(&bm_new->edata, bm_mesh_allocsize_default.totedge, BM_EDGE); | 
					
						
							|  |  |  | 	CustomData_bmesh_init_pool(&bm_new->ldata, bm_mesh_allocsize_default.totloop, BM_LOOP); | 
					
						
							|  |  |  | 	CustomData_bmesh_init_pool(&bm_new->pdata, bm_mesh_allocsize_default.totface, BM_FACE); | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	basenew = ED_object_add_duplicate(bmain, scene, editbase, USER_DUP_MESH);   /* 0 = fully linked */ | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 	assign_matarar(basenew->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ED_base_object_select(basenew, BA_DESELECT); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_callf(em, wmop, "dupe geom=%hvef dest=%p", BM_ELEM_SELECT, bm_new); | 
					
						
							|  |  |  | 	EDBM_op_callf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_FACES); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* clean up any loose edges */ | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +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)) | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_edge_face_count(e) != 0) { | 
					
						
							|  |  |  | 			BM_elem_select_set(em->bm, e, FALSE); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_callf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_EDGES); | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* clean up any loose verts */ | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +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_HIDDEN)) | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		if (BM_vert_edge_count(v) != 0) { | 
					
						
							|  |  |  | 			BM_elem_select_set(em->bm, v, FALSE); | 
					
						
							| 
									
										
										
										
											2011-12-21 03:33:32 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_callf(em, wmop, "del geom=%hvef context=%i", BM_ELEM_SELECT, DEL_VERTS); | 
					
						
							| 
									
										
										
										
											2011-09-16 05:21:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-01 22:17:04 +00:00
										 |  |  | 	BM_mesh_normals_update(bm_new, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-29 03:06:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BM_mesh_bm_to_me(bm_new, basenew->object->data, FALSE); | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-01 22:17:04 +00:00
										 |  |  | 	BM_mesh_free(bm_new); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	((Mesh *)basenew->object->data)->edit_btmesh = NULL; | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-07 02:48:14 +00:00
										 |  |  | //BMESH_TODO
 | 
					
						
							|  |  |  | static int mesh_separate_material(Main *UNUSED(bmain), Scene *UNUSED(scene), Base *UNUSED(editbase), wmOperator *UNUSED(wmop)) | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | static int mesh_separate_loose(Main *bmain, Scene *scene, Base *editbase, wmOperator *wmop) | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 	BMVert *v; | 
					
						
							|  |  |  | 	BMEdge *e; | 
					
						
							|  |  |  | 	BMVert *v_seed; | 
					
						
							|  |  |  | 	BMWalker walker; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	int result = 0; | 
					
						
							|  |  |  | 	Object *obedit = editbase->object; | 
					
						
							|  |  |  | 	Mesh *me = obedit->data; | 
					
						
							|  |  |  | 	BMEditMesh *em = me->edit_btmesh; | 
					
						
							|  |  |  | 	BMesh *bm = em->bm; | 
					
						
							|  |  |  | 	int max_iter = bm->totvert; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	/* Clear all selected vertices */ | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BM_elem_select_set(bm, v, FALSE); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	/* Flush the selection to clear edge/face selections to match
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	 * selected vertices */ | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* A "while (true)" loop should work here as each iteration should
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	 * select and remove at least one vertex and when all vertices | 
					
						
							|  |  |  | 	 * are selected the loop will break out. But guard against bad | 
					
						
							|  |  |  | 	 * behavior by limiting iterations to the number of vertices in the | 
					
						
							|  |  |  | 	 * original mesh.*/ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (i = 0; i < max_iter; i++) { | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		/* Get a seed vertex to start the walk */ | 
					
						
							|  |  |  | 		v_seed = NULL; | 
					
						
							|  |  |  | 		BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							|  |  |  | 			v_seed = v; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* No vertices available, can't do anything */ | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		if (v_seed == NULL) { | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* Select the seed explicitly, in case it has no edges */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BM_elem_select_set(bm, v_seed, TRUE); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		/* Walk from the single vertex, selecting everything connected
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		 * to it */ | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_init(&walker, bm, BMW_SHELL, | 
					
						
							| 
									
										
										
										
											2012-03-29 13:09:07 +00:00
										 |  |  | 		         BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, | 
					
						
							|  |  |  | 		         BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		         BMW_NIL_LAY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		e = BMW_begin(&walker, v_seed); | 
					
						
							|  |  |  | 		for (; e; e = BMW_step(&walker)) { | 
					
						
							|  |  |  | 			BM_elem_select_set(bm, e->v1, TRUE); | 
					
						
							|  |  |  | 			BM_elem_select_set(bm, e->v2, TRUE); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMW_end(&walker); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		/* Flush the selection to get edge/face selections matching
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		 * the vertex selection */ | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 		EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 05:18:08 +00:00
										 |  |  | 		if (bm->totvert == bm->totvertsel) { | 
					
						
							|  |  |  | 			/* Every vertex selected, nothing to separate, work is done */ | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		/* Move selection into a separate object */ | 
					
						
							| 
									
										
										
										
											2011-08-28 17:15:24 +00:00
										 |  |  | 		result |= mesh_separate_selected(bmain, scene, editbase, wmop); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_separate_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 	Main *bmain = CTX_data_main(C); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  | 	Base *base = CTX_data_active_base(C); | 
					
						
							|  |  |  | 	int retval = 0, type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (type == 0) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		retval = mesh_separate_selected(bmain, scene, base, op); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (type == 1) | 
					
						
							| 
									
										
										
										
											2012-03-01 16:04:37 +00:00
										 |  |  | 		retval = mesh_separate_material(bmain, scene, base, op); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	else if (type == 2) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		retval = mesh_separate_loose(bmain, scene, base, op); | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	if (retval) { | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 		BMEditMesh *em = BMEdit_FromObject(base->object); | 
					
						
							|  |  |  | 		EDBM_update_generic(C, em, TRUE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* *************** Operator: separate parts *************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static EnumPropertyItem prop_separate_types[] = { | 
					
						
							|  |  |  | 	{0, "SELECTED", 0, "Selection", ""}, | 
					
						
							|  |  |  | 	{1, "MATERIAL", 0, "By Material", ""}, | 
					
						
							|  |  |  | 	{2, "LOOSE", 0, "By loose parts", ""}, | 
					
						
							|  |  |  | 	{0, NULL, 0, NULL, NULL} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_separate(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Separate"; | 
					
						
							|  |  |  | 	ot->description = "Separate selected geometry into a new mesh"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_separate"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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_separate_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->flag = OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-10-03 21:10:59 +00:00
										 |  |  | 	ot->prop = RNA_def_enum(ot->srna, "type", prop_separate_types, 0, "Type", ""); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_fill_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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-04-23 00:05:13 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &bmop, op, "triangle_fill edges=%he", BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-04-23 00:05:13 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-23 00:05:13 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2011-04-23 00:05:13 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* select new geometry */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_FACE | BM_EDGE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2011-04-23 00:05:13 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-04-23 00:05:13 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-07 13:54:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-04-23 00:05:13 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_fill(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Fill"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_fill"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_fill_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_beautify_fill_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "beautify_fill faces=%hf", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2011-04-22 23:37:58 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-04-23 00:05:13 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 04:32:40 +00:00
										 |  |  | void MESH_OT_beautify_fill(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Beautify Fill"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_beautify_fill"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_beautify_fill_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************** Quad/Tri Operators *************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_quads_convert_to_tris_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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-03-04 02:18:17 +00:00
										 |  |  | 	int use_beauty = RNA_boolean_get(op->ptr, "use_beauty"); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "triangulate faces=%hf use_beauty=%b", BM_ELEM_SELECT, use_beauty)) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2010-02-18 10:09:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_quads_convert_to_tris(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Quads to Tris"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_quads_convert_to_tris"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_quads_convert_to_tris_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-03-04 02:18:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "use_beauty", 1, "Beauty", "Use best triangulation division (currently quads only)"); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_tris_convert_to_quads_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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-02-18 10:09:52 +00:00
										 |  |  | 	int dosharp, douvs, dovcols, domaterials; | 
					
						
							|  |  |  | 	float limit = RNA_float_get(op->ptr, "limit"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dosharp = RNA_boolean_get(op->ptr, "sharp"); | 
					
						
							|  |  |  | 	douvs = RNA_boolean_get(op->ptr, "uvs"); | 
					
						
							|  |  |  | 	dovcols = RNA_boolean_get(op->ptr, "vcols"); | 
					
						
							|  |  |  | 	domaterials = RNA_boolean_get(op->ptr, "materials"); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 	                   "join_triangles faces=%hf limit=%f cmp_sharp=%b cmp_uvs=%b cmp_vcols=%b cmp_materials=%b", | 
					
						
							|  |  |  | 	                   BM_ELEM_SELECT, limit, dosharp, douvs, dovcols, domaterials)) | 
					
						
							| 
									
										
										
										
											2010-02-18 10:09:52 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_tris_convert_to_quads(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-18 09:41:39 +00:00
										 |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Tris to Quads"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_tris_convert_to_quads"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_tris_convert_to_quads_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-02-18 10:09:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	prop = RNA_def_float_rotation(ot->srna, "limit", 0, NULL, 0.0f, DEG2RADF(180.0f), | 
					
						
							| 
									
										
										
										
											2012-02-27 18:14:56 +00:00
										 |  |  | 	                              "Max Angle", "Angle Limit", 0.0f, DEG2RADF(180.0f)); | 
					
						
							| 
									
										
										
										
											2011-11-18 09:41:39 +00:00
										 |  |  | 	RNA_def_property_float_default(prop, DEG2RADF(40.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-18 10:09:52 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "uvs", 0, "Compare UVs", ""); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "vcols", 0, "Compare VCols", ""); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "sharp", 0, "Compare Sharp", ""); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "materials", 0, "Compare Materials", ""); | 
					
						
							| 
									
										
										
										
											2012-02-13 14:37:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_dissolve_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int use_verts = RNA_boolean_get(op->ptr, "use_verts"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (em->selectmode & SCE_SELECT_FACE) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "dissolve_faces faces=%hf use_verts=%b", BM_ELEM_SELECT, use_verts)) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (em->selectmode & SCE_SELECT_EDGE) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "dissolve_edges edges=%he use_verts=%b", BM_ELEM_SELECT, use_verts)) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (em->selectmode & SCE_SELECT_VERTEX) { | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_callf(em, op, "dissolve_verts verts=%hv", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_dissolve(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Dissolve"; | 
					
						
							|  |  |  | 	ot->description = "Dissolve geometry"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_dissolve"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_dissolve_exec; | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-03-23 10:30:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO, move dissolve into its own operator so this doesnt confuse non-dissolve options */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "use_verts", 0, "Dissolve Verts", | 
					
						
							|  |  |  | 	                "When dissolving faces/edges, also dissolve remaining vertices"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_dissolve_limited_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2012-02-13 14:37:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2012-02-13 14:37:07 +00:00
										 |  |  | 	float angle_limit = RNA_float_get(op->ptr, "angle_limit"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, | 
					
						
							| 
									
										
										
										
											2012-03-27 05:03:23 +00:00
										 |  |  | 	                   "dissolve_limit edges=%he verts=%hv angle_limit=%f", | 
					
						
							|  |  |  | 	                   BM_ELEM_SELECT, BM_ELEM_SELECT, angle_limit)) | 
					
						
							| 
									
										
										
										
											2012-02-13 14:37:07 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-02-18 10:09:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2012-02-13 14:37:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_dissolve_limited(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Limited Dissolve"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_dissolve_limited"; | 
					
						
							|  |  |  | 	ot->description = "Dissolve selected edges and verts, limited by the angle of surrounding geometry"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_dissolve_limited_exec; | 
					
						
							| 
									
										
										
										
											2012-02-13 14:37:07 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-02-13 14:37:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	prop = RNA_def_float_rotation(ot->srna, "angle_limit", 0, NULL, 0.0f, DEG2RADF(180.0f), | 
					
						
							|  |  |  | 	                              "Max Angle", "Angle Limit in Degrees", 0.0f, DEG2RADF(180.0f)); | 
					
						
							|  |  |  | 	RNA_def_property_float_default(prop, DEG2RADF(15.0f)); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_split_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(ob); | 
					
						
							| 
									
										
										
										
											2011-09-16 05:21:24 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, "split geom=%hvef use_only_faces=%b", BM_ELEM_SELECT, FALSE); | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-04-02 04:45:44 +00:00
										 |  |  | 	BM_mesh_elem_flag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, FALSE); | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "geomout", BM_ALL, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-09-09 14:58:49 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2011-09-16 05:21:24 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* Geometry has changed, need to recalc normals and looptris */ | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_normals_update(em); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-19 04:44:37 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_split(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Split"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_split"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_split_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_spin_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	ToolSettings *ts = CTX_data_tool_settings(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; | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 	BMOperator spinop; | 
					
						
							|  |  |  | 	float cent[3], axis[3], imat[3][3]; | 
					
						
							|  |  |  | 	float d[3] = {0.0f, 0.0f, 0.0f}; | 
					
						
							|  |  |  | 	int steps, dupli; | 
					
						
							|  |  |  | 	float degr; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	RNA_float_get_array(op->ptr, "center", cent); | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 	RNA_float_get_array(op->ptr, "axis", axis); | 
					
						
							|  |  |  | 	steps = RNA_int_get(op->ptr, "steps"); | 
					
						
							|  |  |  | 	degr = RNA_float_get(op->ptr, "degrees"); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (ts->editbutflag & B_CLOCKWISE) degr = -degr; | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 	dupli = RNA_boolean_get(op->ptr, "dupli"); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  | 	/* undo object transformation */ | 
					
						
							|  |  |  | 	copy_m3_m4(imat, obedit->imat); | 
					
						
							|  |  |  | 	sub_v3_v3(cent, obedit->obmat[3]); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	mul_m3_v3(imat, cent); | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 	mul_m3_v3(imat, axis); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &spinop, op, | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 	                  "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i ang=%f do_dupli=%b", | 
					
						
							|  |  |  | 	                  BM_ELEM_SELECT, cent, axis, d, steps, degr, dupli)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &spinop); | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(bm, &spinop, "lastout", BM_ALL, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &spinop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-07-25 12:18:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* get center and axis, in global coords */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_spin_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  | 	View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	RegionView3D *rv3d = ED_view3d_context_rv3d(C); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d)); | 
					
						
							|  |  |  | 	RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	return edbm_spin_exec(C, op); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_spin(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Spin"; | 
					
						
							| 
									
										
										
										
											2012-03-27 17:53:31 +00:00
										 |  |  | 	ot->description = "Extrude selected vertices in a circle around the cursor in indicated viewport"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_spin"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_spin_invoke; | 
					
						
							|  |  |  | 	ot->exec = edbm_spin_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = EM_view3d_poll; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "dupli", 0, "Dupli", "Make Duplicates"); | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "degrees", 90.0f, -FLT_MAX, FLT_MAX, "Degrees", "Degrees", -360.0f, 360.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, "Center", "Center in global view space", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_screw_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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; | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMVert *eve, *v1, *v2; | 
					
						
							|  |  |  | 	BMIter iter, eiter; | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 	BMOperator spinop; | 
					
						
							|  |  |  | 	float dvec[3], nor[3], cent[3], axis[3]; | 
					
						
							|  |  |  | 	float imat[3][3]; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	int steps, turns; | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 	int valence; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	turns = RNA_int_get(op->ptr, "turns"); | 
					
						
							|  |  |  | 	steps = RNA_int_get(op->ptr, "steps"); | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 	RNA_float_get_array(op->ptr, "center", cent); | 
					
						
							|  |  |  | 	RNA_float_get_array(op->ptr, "axis", axis); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* undo object transformation */ | 
					
						
							|  |  |  | 	copy_m3_m4(imat, obedit->imat); | 
					
						
							|  |  |  | 	sub_v3_v3(cent, obedit->obmat[3]); | 
					
						
							|  |  |  | 	mul_m3_v3(imat, cent); | 
					
						
							|  |  |  | 	mul_m3_v3(imat, axis); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* find two vertices with valence count == 1, more or less is wrong */ | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 	v1 = NULL; | 
					
						
							|  |  |  | 	v2 = NULL; | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	for (eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); eve; eve = BM_iter_step(&iter)) { | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		valence = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		for (eed = BM_iter_new(&eiter, em->bm, BM_EDGES_OF_VERT, eve); eed; eed = BM_iter_step(&eiter)) { | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 				valence++; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (valence == 1) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			if (v1 == NULL) { | 
					
						
							|  |  |  | 				v1 = eve; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (v2 == NULL) { | 
					
						
							|  |  |  | 				v2 = eve; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				v1 = NULL; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (v1 == NULL || v2 == NULL) { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "You have to select a string of connected vertices too"); | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* calculate dvec */ | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 	sub_v3_v3v3(dvec, v1->co, v2->co); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	mul_v3_fl(dvec, 1.0f / steps); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (dot_v3v3(nor, dvec) > 0.000f) | 
					
						
							| 
									
										
										
										
											2011-08-02 14:45:34 +00:00
										 |  |  | 		negate_v3(dvec); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_init(em, &spinop, op, | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 	                  "spin geom=%hvef cent=%v axis=%v dvec=%v steps=%i ang=%f do_dupli=%b", | 
					
						
							|  |  |  | 	                  BM_ELEM_SELECT, cent, axis, dvec, turns * steps, 360.0f * turns, FALSE)) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BMO_op_exec(bm, &spinop); | 
					
						
							| 
									
										
										
										
											2012-02-12 18:43:59 +00:00
										 |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(bm, &spinop, "lastout", BM_ALL, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &spinop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* get center and axis, in global coords */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_screw_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  | 	View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	RegionView3D *rv3d = ED_view3d_context_rv3d(C); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d)); | 
					
						
							|  |  |  | 	RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]); | 
					
						
							| 
									
										
										
										
											2011-07-25 22:43:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	return edbm_screw_exec(C, op); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_screw(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Screw"; | 
					
						
							| 
									
										
										
										
											2012-03-27 17:53:31 +00:00
										 |  |  | 	ot->description = "Extrude selected vertices in screw-shaped rotation around the cursor in indicated viewport"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->idname = "MESH_OT_screw"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->invoke = edbm_screw_invoke; | 
					
						
							|  |  |  | 	ot->exec = edbm_screw_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = EM_view3d_poll; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* props */ | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "steps", 9, 0, INT_MAX, "Steps", "Steps", 0, 256); | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "turns", 1, 0, INT_MAX, "Turns", "Turns", 0, 256); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	RNA_def_float_vector(ot->srna, "center", 3, NULL, -FLT_MAX, FLT_MAX, | 
					
						
							|  |  |  | 	                     "Center", "Center in global view space", -FLT_MAX, FLT_MAX); | 
					
						
							|  |  |  | 	RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, | 
					
						
							|  |  |  | 	                     "Axis", "Axis in global view space", -FLT_MAX, FLT_MAX); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_by_number_vertices_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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-06-26 20:23:27 +00:00
										 |  |  | 	BMFace *efa; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	int numverts = RNA_int_get(op->ptr, "number"); | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 	int type = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	for (efa = BM_iter_new(&iter, em->bm, BM_FACES_OF_MESH, NULL); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	     efa; efa = BM_iter_step(&iter)) { | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 		int select = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (type == 0 && efa->len < numverts) { | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 			select = 1; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (type == 1 && efa->len == numverts) { | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 			select = 1; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (type == 2 && efa->len > numverts) { | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 			select = 1; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else if (type == 3 && efa->len != numverts) { | 
					
						
							| 
									
										
										
										
											2012-03-07 07:32:15 +00:00
										 |  |  | 			select = 1; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (select) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, efa, TRUE); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_by_number_vertices(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 	static const EnumPropertyItem type_items[] = { | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 		{0, "LESS", 0, "Less Than", ""}, | 
					
						
							|  |  |  | 		{1, "EQUAL", 0, "Equal To", ""}, | 
					
						
							|  |  |  | 		{2, "GREATER", 0, "Greater Than", ""}, | 
					
						
							|  |  |  | 		{3, "NOTEQUAL", 0, "Not Equal To", ""}, | 
					
						
							|  |  |  | 		{0, NULL, 0, NULL, NULL}}; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select by Number of Vertices"; | 
					
						
							|  |  |  | 	ot->description = "Select vertices or faces by vertex count"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_by_number_vertices"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_by_number_vertices_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							|  |  |  | 	RNA_def_int(ot->srna, "number", 4, 3, INT_MAX, "Number of Vertices", "", 3, INT_MAX); | 
					
						
							|  |  |  | 	RNA_def_enum(ot->srna, "type", type_items, 1, "Type", "Type of comparison to make"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_loose_verts_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							| 
									
										
										
										
											2012-03-02 12:09:49 +00:00
										 |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMEdge *eed; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	for (eve = BM_iter_new(&iter, em->bm, BM_VERTS_OF_MESH, NULL); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	     eve; eve = BM_iter_step(&iter)) { | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (!eve->e) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, eve, TRUE); | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	for (eed = BM_iter_new(&iter, em->bm, BM_EDGES_OF_MESH, NULL); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	     eed; eed = BM_iter_step(&iter)) { | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (!eed->l) { | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 			BM_elem_select_set(em->bm, eed, TRUE); | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | void MESH_OT_select_loose_verts(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Select Loose Vertices/Edges"; | 
					
						
							| 
									
										
										
										
											2012-02-27 18:14:56 +00:00
										 |  |  | 	ot->description = "Select vertices with no edges nor faces, and edges with no faces"; | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 	ot->idname = "MESH_OT_select_loose_verts"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_loose_verts_exec; | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-06-26 20:23:27 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_select_mirror_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +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 extend = RNA_boolean_get(op->ptr, "extend"); | 
					
						
							| 
									
										
										
										
											2010-03-04 01:07:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 	EDBM_select_mirrored(obedit, em, extend); | 
					
						
							| 
									
										
										
										
											2012-02-10 06:16:21 +00:00
										 |  |  | 	EDBM_selectmode_flush(em); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data); | 
					
						
							| 
									
										
										
										
											2012-02-06 09:39:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_select_mirror(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Select Mirror"; | 
					
						
							|  |  |  | 	ot->description = "Select mesh items at mirrored locations"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_select_mirror"; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_select_mirror_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2010-01-28 00:45:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* props */ | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-10 14:56:09 +00:00
										 |  |  | #if 0 /* UNUSED */
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | /* qsort routines.  not sure how to make these
 | 
					
						
							|  |  |  |  * work, since we aren't using linked lists for | 
					
						
							|  |  |  |  * geometry anymore.  might need a sortof "swap" | 
					
						
							|  |  |  |  * function for bmesh elements. */ | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct xvertsort { | 
					
						
							|  |  |  | 	float x; | 
					
						
							|  |  |  | 	BMVert *v1; | 
					
						
							|  |  |  | } xvertsort; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int vergxco(const void *v1, const void *v2) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	const xvertsort *x1 = v1, *x2 = v2; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	if (x1->x > x2->x) return 1; | 
					
						
							|  |  |  | 	else if (x1->x < x2->x) return -1; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct facesort { | 
					
						
							|  |  |  | 	uintptr_t x; | 
					
						
							|  |  |  | 	struct EditFace *efa; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int vergface(const void *v1, const void *v2) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	const struct facesort *x1 = v1, *x2 = v2; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	if (x1->x > x2->x) return 1; | 
					
						
							|  |  |  | 	else if (x1->x < x2->x) return -1; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-09 02:45:52 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // XXX is this needed?
 | 
					
						
							|  |  |  | /* called from buttons */ | 
					
						
							| 
									
										
										
										
											2011-05-09 02:45:52 +00:00
										 |  |  | #if 0 /* UNUSED */
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | static void xsortvert_flag__doSetX(void *userData, EditVert *UNUSED(eve), int x, int UNUSED(y), int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	xvertsort *sortblock = userData; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sortblock[index].x = x; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-09 02:45:52 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* all verts with (flag & 'flag') are sorted */ | 
					
						
							| 
									
										
										
										
											2011-05-07 02:48:14 +00:00
										 |  |  | static void xsortvert_flag(bContext *UNUSED(C), int UNUSED(flag)) | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* BMESH_TODO */ | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | #if 0 //hrm, geometry isn't in linked lists anymore. . .
 | 
					
						
							|  |  |  | 	ViewContext vc; | 
					
						
							|  |  |  | 	BMEditMesh *em; | 
					
						
							|  |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							|  |  |  | 	xvertsort *sortblock; | 
					
						
							|  |  |  | 	ListBase tbase; | 
					
						
							|  |  |  | 	int i, amount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	em_setup_viewcontext(C, &vc); | 
					
						
							|  |  |  | 	em = vc.em; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	amount = em->bm->totvert; | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	sortblock = MEM_callocN(sizeof(xvertsort) * amount, "xsort"); | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +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_SELECT)) | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 			sortblock[i].v1 = eve; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d); | 
					
						
							| 
									
										
										
										
											2011-11-28 17:09:13 +00:00
										 |  |  | 	mesh_foreachScreenVert(&vc, xsortvert_flag__doSetX, sortblock, V3D_CLIP_TEST_OFF); | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	qsort(sortblock, amount, sizeof(xvertsort), vergxco); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	/* make temporal listbase */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	tbase.first = tbase.last = 0; | 
					
						
							|  |  |  | 	for (i = 0; i < amount; i++) { | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		eve = sortblock[i].v1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (eve) { | 
					
						
							|  |  |  | 			BLI_remlink(&vc.em->verts, eve); | 
					
						
							|  |  |  | 			BLI_addtail(&tbase, eve); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BLI_movelisttolist(&vc.em->verts, &tbase); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MEM_freeN(sortblock); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_vertices_sort_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	xsortvert_flag(C, SELECT); | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_vertices_sort(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Vertex Sort"; | 
					
						
							|  |  |  | 	ot->description = "Sort vertex order"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_vertices_sort"; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_vertices_sort_exec; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = EM_view3d_poll; /* uses view relative X axis to sort verts */ | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | /* ********************** SORT FACES ******************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void permutate(void *list, int num, int size, int *index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	void *buf; | 
					
						
							|  |  |  | 	int len; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = num * size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf = MEM_mallocN(len, "permutate"); | 
					
						
							|  |  |  | 	memcpy(buf, list, len); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for (i = 0; i < num; i++) { | 
					
						
							|  |  |  | 		memcpy((char *)list + (i * size), (char *)buf + (index[i] * size), size); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	MEM_freeN(buf); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* sort faces on view axis */ | 
					
						
							|  |  |  | static float *face_sort_floats; | 
					
						
							|  |  |  | static int float_sort(const void *v1, const void *v2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float x1, x2; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	x1 = face_sort_floats[((int *) v1)[0]]; | 
					
						
							|  |  |  | 	x2 = face_sort_floats[((int *) v2)[0]]; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (x1 > x2)       return  1; | 
					
						
							|  |  |  | 	else if (x1 < x2)  return -1; | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_sort_faces_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	RegionView3D *rv3d = ED_view3d_context_rv3d(C); | 
					
						
							|  |  |  | 	View3D *v3d = CTX_wm_view3d(C); | 
					
						
							|  |  |  | 	Object *ob = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 	Mesh *me; | 
					
						
							|  |  |  | 	CustomDataLayer *layer; | 
					
						
							|  |  |  | 	int i, j, *index; | 
					
						
							|  |  |  | 	int event; | 
					
						
							|  |  |  | 	float reverse = 1; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	// XXX int ctrl = 0;
 | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (!v3d) return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* This operator work in Object Mode, not in edit mode.
 | 
					
						
							|  |  |  | 	 * After talk with Campbell we agree that there is no point to port this to EditMesh right now. | 
					
						
							|  |  |  | 	 * so for now, we just exit_editmode and enter_editmode at the end of this function. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	ED_object_exit_editmode(C, EM_FREEDATA); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	me = ob->data; | 
					
						
							|  |  |  | 	if (me->totpoly == 0) { | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 		ED_object_enter_editmode(C, 0); | 
					
						
							|  |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	event = RNA_enum_get(op->ptr, "type"); | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XXX
 | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	//if (ctrl)
 | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 	//	reverse = -1;
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* create index list */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	index = (int *)MEM_mallocN(sizeof(int) * me->totpoly, "sort faces"); | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 	for (i = 0; i < me->totpoly; i++) { | 
					
						
							|  |  |  | 		index[i] = i; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	face_sort_floats = (float *) MEM_mallocN(sizeof(float) * me->totpoly, "sort faces float"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* sort index list instead of faces itself 
 | 
					
						
							|  |  |  | 	 * and apply this permutation to all face layers | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (event == 5) { | 
					
						
							|  |  |  | 		/* Random */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		for (i = 0; i < me->totpoly; i++) { | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 			face_sort_floats[i] = BLI_frand(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		qsort(index, me->totpoly, sizeof(int), float_sort); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 		MPoly *mp; | 
					
						
							|  |  |  | 		MLoop *ml; | 
					
						
							|  |  |  | 		MVert *mv; | 
					
						
							|  |  |  | 		float vec[3]; | 
					
						
							|  |  |  | 		float mat[4][4]; | 
					
						
							|  |  |  | 		float cur[3]; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (event == 1) | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 			mult_m4_m4m4(mat, rv3d->viewmat, OBACT->obmat);  /* apply the view matrix to the object matrix */ | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 		else if (event == 2) { /* sort from cursor */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			if (v3d && v3d->localvd) { | 
					
						
							| 
									
										
										
										
											2011-10-29 06:57:50 +00:00
										 |  |  | 				copy_v3_v3(cur, v3d->cursor); | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2011-10-29 06:57:50 +00:00
										 |  |  | 				copy_v3_v3(cur, scene->cursor); | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			invert_m4_m4(mat, OBACT->obmat); | 
					
						
							|  |  |  | 			mul_m4_v3(mat, cur); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		mp = me->mpoly; | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		for (i = 0; i < me->totpoly; i++, mp++) { | 
					
						
							|  |  |  | 			if (event == 3) { | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 				face_sort_floats[i] = ((float)mp->mat_nr) * reverse; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			else if (event == 4) { | 
					
						
							|  |  |  | 				/* selected first */ | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 				if (mp->flag & ME_FACE_SEL) | 
					
						
							|  |  |  | 					face_sort_floats[i] = 0.0; | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					face_sort_floats[i] = reverse; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 				/* find the face's center */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				ml = me->mloop + mp->loopstart; | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 				zero_v3(vec); | 
					
						
							|  |  |  | 				for (j = 0; j < mp->totloop; j++, ml++) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 					mv = me->mvert + ml->v; | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 					add_v3_v3(vec, mv->co); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				mul_v3_fl(vec, 1.0f / (float)mp->totloop); | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				if (event == 1) { /* sort on view axis */ | 
					
						
							|  |  |  | 					mul_m4_v3(mat, vec); | 
					
						
							|  |  |  | 					face_sort_floats[i] = vec[2] * reverse; | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				else if (event == 2) { /* distance from cursor */ | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 					face_sort_floats[i] = len_v3v3(cur, vec) * reverse; /* back to front */ | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		qsort(index, me->totpoly, sizeof(int), float_sort); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	MEM_freeN(face_sort_floats); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (i = 0; i < me->pdata.totlayer; i++) { | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 		layer = &me->pdata.layers[i]; | 
					
						
							|  |  |  | 		permutate(layer->data, me->totpoly, CustomData_sizeof(layer->type), index); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MEM_freeN(index); | 
					
						
							|  |  |  | 	DAG_id_tag_update(ob->data, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Return to editmode. */ | 
					
						
							|  |  |  | 	ED_object_enter_editmode(C, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_sort_faces(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	static EnumPropertyItem type_items[] = { | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 		{ 1, "VIEW_AXIS", 0, "View Axis", "" }, | 
					
						
							|  |  |  | 		{ 2, "CURSOR_DISTANCE", 0, "Cursor Distance", "" }, | 
					
						
							|  |  |  | 		{ 3, "MATERIAL", 0, "Material", "" }, | 
					
						
							|  |  |  | 		{ 4, "SELECTED", 0, "Selected", "" }, | 
					
						
							|  |  |  | 		{ 5, "RANDOMIZE", 0, "Randomize", "" }, | 
					
						
							|  |  |  | 		{ 0, NULL, 0, NULL, NULL }}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Sort Faces"; // XXX (Ctrl to reverse)%t|
 | 
					
						
							|  |  |  | 	ot->description = "The faces of the active Mesh Object are sorted, based on the current view"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_sort_faces"; | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +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_sort_faces_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", ""); | 
					
						
							| 
									
										
										
										
											2011-10-02 15:27:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | /* called from buttons */ | 
					
						
							|  |  |  | static void hashvert_flag(EditMesh *em, int flag) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* switch vertex order using hash table */ | 
					
						
							|  |  |  | 	EditVert *eve; | 
					
						
							|  |  |  | 	struct xvertsort *sortblock, *sb, onth, *newsort; | 
					
						
							|  |  |  | 	ListBase tbase; | 
					
						
							|  |  |  | 	int amount, a, b; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* count */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	eve = em->verts.first; | 
					
						
							|  |  |  | 	amount = 0; | 
					
						
							|  |  |  | 	while (eve) { | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (eve->f & flag) amount++; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		eve = eve->next; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (amount == 0) return; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* allocate memory */ | 
					
						
							| 
									
										
										
										
											2012-03-21 09:10:08 +00:00
										 |  |  | 	sb = sortblock = (struct xvertsort *)MEM_mallocN(sizeof(struct xvertsort) * amount, "sortremovedoub"); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	eve = em->verts.first; | 
					
						
							|  |  |  | 	while (eve) { | 
					
						
							| 
									
										
										
										
											2012-02-05 15:55:28 +00:00
										 |  |  | 		if (eve->f & flag) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 			sb->v1 = eve; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 			sb++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		eve = eve->next; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BLI_srand(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	sb = sortblock; | 
					
						
							|  |  |  | 	for (a = 0; a < amount; a++, sb++) { | 
					
						
							|  |  |  | 		b = (int)(amount * BLI_drand()); | 
					
						
							|  |  |  | 		if (b >= 0 && b < amount) { | 
					
						
							|  |  |  | 			newsort = sortblock + b; | 
					
						
							|  |  |  | 			onth = *sb; | 
					
						
							|  |  |  | 			*sb = *newsort; | 
					
						
							|  |  |  | 			*newsort = onth; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* make temporal listbase */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	tbase.first = tbase.last = 0; | 
					
						
							|  |  |  | 	sb = sortblock; | 
					
						
							|  |  |  | 	while (amount--) { | 
					
						
							|  |  |  | 		eve = sb->v1; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		BLI_remlink(&em->verts, eve); | 
					
						
							|  |  |  | 		BLI_addtail(&tbase, eve); | 
					
						
							|  |  |  | 		sb++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BLI_movelisttolist(&em->verts, &tbase); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	MEM_freeN(sortblock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_vertices_randomize_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +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
										 |  |  | #if 1 /* BMESH TODO */
 | 
					
						
							| 
									
										
										
										
											2011-05-13 13:17:30 +00:00
										 |  |  | 	(void)em; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2011-05-09 05:09:07 +00:00
										 |  |  | 	hashvert_flag(em, SELECT); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_vertices_randomize(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Vertex Randomize"; | 
					
						
							|  |  |  | 	ot->description = "Randomize vertex order"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_vertices_randomize"; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_vertices_randomize_exec; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /******end of qsort stuff ****/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_noise_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +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-02-27 06:19:40 +00:00
										 |  |  | 	Material *ma; | 
					
						
							|  |  |  | 	Tex *tex; | 
					
						
							|  |  |  | 	BMVert *eve; | 
					
						
							|  |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	float fac = RNA_float_get(op->ptr, "factor"); | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 10:49:15 +00:00
										 |  |  | 	if (em == NULL) { | 
					
						
							|  |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-02 10:49:15 +00:00
										 |  |  | 	if ((ma  = give_current_material(obedit, obedit->actcol)) == NULL || | 
					
						
							|  |  |  | 	    (tex = give_current_material_texture(ma)) == NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-09-23 13:31:48 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_WARNING, "Mesh has no material or texture assigned"); | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (tex->type == TEX_STUCCI) { | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		float b2, vec[3]; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		float ofs = tex->turbul / 200.0; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 		BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-03-02 10:49:15 +00:00
										 |  |  | 			if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				b2 = BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]); | 
					
						
							|  |  |  | 				if (tex->stype) ofs *= (b2 * b2); | 
					
						
							|  |  |  | 				vec[0] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0] + ofs, eve->co[1], eve->co[2])); | 
					
						
							|  |  |  | 				vec[1] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1] + ofs, eve->co[2])); | 
					
						
							|  |  |  | 				vec[2] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2] + ofs)); | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 				 | 
					
						
							|  |  |  | 				add_v3_v3(eve->co, vec); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		BM_ITER(eve, &iter, em->bm, BM_VERTS_OF_MESH, NULL) { | 
					
						
							| 
									
										
										
										
											2012-03-02 10:49:15 +00:00
										 |  |  | 			if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 				float tin, dum; | 
					
						
							|  |  |  | 				externtex(ma->mtex[0], eve->co, &tin, &dum, &dum, &dum, &dum, 0); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 				eve->co[2] += fac * tin; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_normals_update(em); | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_noise(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Noise"; | 
					
						
							|  |  |  | 	ot->description = "Use vertex coordinate as texture coordinate"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_noise"; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_noise_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-02-27 06:19:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_float(ot->srna, "factor", 0.1f, -FLT_MAX, FLT_MAX, "Factor", "", 0.0f, 1.0f); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | /* bevel! yay!!*/ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_bevel_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59: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); | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 	BMIter iter; | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 	BMEdge *eed; | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2012-03-13 01:55:25 +00:00
										 |  |  | 	float factor = RNA_float_get(op->ptr, "percent") /*, dfac */ /* UNUSED */, df, s; | 
					
						
							| 
									
										
										
										
											2011-04-24 07:45:24 +00:00
										 |  |  | 	int i, recursion = RNA_int_get(op->ptr, "recursion"); | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	const int use_even = RNA_boolean_get(op->ptr, "use_even"); | 
					
						
							|  |  |  | 	const int use_dist = RNA_boolean_get(op->ptr, "use_dist"); | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 	float *w = NULL, ftot; | 
					
						
							|  |  |  | 	int li; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 	BM_data_layer_add(em->bm, &em->bm->edata, CD_PROP_FLT); | 
					
						
							| 
									
										
										
										
											2012-02-26 22:38:49 +00:00
										 |  |  | 	li = CustomData_number_of_layers(&em->bm->edata, CD_PROP_FLT) - 1; | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { | 
					
						
							|  |  |  | 		float d = len_v3v3(eed->v1->co, eed->v2->co); | 
					
						
							|  |  |  | 		float *dv = CustomData_bmesh_get_n(&em->bm->edata, eed->head.data, CD_PROP_FLT, li); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		*dv = d; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	if (em == NULL) { | 
					
						
							|  |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 23:09:07 +00:00
										 |  |  | 	w = MEM_mallocN(sizeof(float) * recursion, "bevel weights"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	/* ugh, stupid math depends somewhat on angles!*/ | 
					
						
							|  |  |  | 	/* dfac = 1.0/(float)(recursion + 1); */ /* UNUSED */ | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 	df = 1.0; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (i = 0, ftot = 0.0f; i < recursion; i++) { | 
					
						
							| 
									
										
										
										
											2012-02-05 23:09:07 +00:00
										 |  |  | 		s = powf(df, 1.25f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		w[i] = s; | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 		ftot += s; | 
					
						
							| 
									
										
										
										
											2012-02-05 23:09:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 		df *= 2.0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-12-06 08:07:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-05 23:09:07 +00:00
										 |  |  | 	mul_vn_fl(w, recursion, 1.0f / (float)ftot); | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	for (i = 0; i < recursion; i++) { | 
					
						
							| 
									
										
										
										
											2012-03-13 01:11:08 +00:00
										 |  |  | 		float fac = w[recursion - i - 1] * factor; | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_init(em, &bmop, op, | 
					
						
							| 
									
										
										
										
											2012-02-20 01:52:35 +00:00
										 |  |  | 		                  "bevel geom=%hev percent=%f lengthlayer=%i use_lengths=%b use_even=%b use_dist=%b", | 
					
						
							|  |  |  | 		                  BM_ELEM_SELECT, fac, li, TRUE, use_even, use_dist)) | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-02-12 10:51:45 +00:00
										 |  |  | 		BMO_op_exec(em->bm, &bmop); | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 		if (!EDBM_op_finish(em, &bmop, op, TRUE)) | 
					
						
							| 
									
										
										
										
											2011-10-10 07:21:05 +00:00
										 |  |  | 			return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-22 14:55:12 +00:00
										 |  |  | 	BM_data_layer_free_n(em->bm, &em->bm->edata, CD_PROP_FLT, li); | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-02-05 23:09:07 +00:00
										 |  |  | 	MEM_freeN(w); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_mesh_normals_update(em); | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_bevel(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->name = "Bevel"; | 
					
						
							|  |  |  | 	ot->description = "Edge/Vertex Bevel"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_bevel"; | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_bevel_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-16 13:00:41 +00:00
										 |  |  | 	RNA_def_float(ot->srna, "percent", 0.5f, -FLT_MAX, FLT_MAX, "Percentage", "", 0.0f, 1.0f); | 
					
						
							| 
									
										
										
										
											2011-03-17 23:06:12 +00:00
										 |  |  | 	RNA_def_int(ot->srna, "recursion", 1, 1, 50, "Recursion Level", "Recursion Level", 1, 8); | 
					
						
							| 
									
										
										
										
											2011-12-13 09:57:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "use_even", FALSE, "Even",     "Calculate evenly spaced bevel"); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "use_dist", FALSE, "Distance", "Interpret the percent in blender units"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-17 22:59:54 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-02 00:58:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_bridge_edge_loops_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2011-08-15 23:38:51 +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-08-15 23:38:51 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_callf(em, op, "bridge_loops edges=%he", BM_ELEM_SELECT)) | 
					
						
							| 
									
										
										
										
											2011-08-15 23:38:51 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 	EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2011-08-15 23:38:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2011-08-15 23:38:51 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_bridge_edge_loops(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-23 03:10:44 +00:00
										 |  |  | 	ot->name = "Bridge Two Edge Loops"; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->description = "Make faces between two edge loops"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_bridge_edge_loops"; | 
					
						
							| 
									
										
										
										
											2011-08-15 23:38:51 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_bridge_edge_loops_exec; | 
					
						
							| 
									
										
										
										
											2012-02-10 18:09:19 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							| 
									
										
										
										
											2011-08-15 23:38:51 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2011-08-15 23:38:51 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "inside", 0, "Inside", ""); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | static int edbm_inset_exec(bContext *C, wmOperator *op) | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	Object *obedit = CTX_data_edit_object(C); | 
					
						
							|  |  |  | 	BMEditMesh *em = BMEdit_FromObject(obedit); | 
					
						
							|  |  |  | 	BMOperator bmop; | 
					
						
							| 
									
										
										
										
											2012-03-20 11:45:55 +00:00
										 |  |  | 	const int use_boundary        = FALSE; //RNA_boolean_get(op->ptr, "use_boundary");
 | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 	const int use_even_offset     = RNA_boolean_get(op->ptr, "use_even_offset"); | 
					
						
							|  |  |  | 	const int use_relative_offset = RNA_boolean_get(op->ptr, "use_relative_offset"); | 
					
						
							| 
									
										
										
										
											2012-03-19 21:40:17 +00:00
										 |  |  | 	const float thickness         = RNA_float_get(op->ptr, "thickness"); | 
					
						
							|  |  |  | 	const int use_outset          = RNA_boolean_get(op->ptr, "use_outset"); | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	EDBM_op_init(em, &bmop, op, | 
					
						
							| 
									
										
										
										
											2012-03-19 21:40:17 +00:00
										 |  |  | 	             "inset faces=%hf use_boundary=%b use_even_offset=%b use_relative_offset=%b thickness=%f use_outset=%b", | 
					
						
							|  |  |  | 	             BM_ELEM_SELECT, use_boundary, use_even_offset, use_relative_offset, thickness, use_outset); | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BMO_op_exec(em->bm, &bmop); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* deselect original verts */ | 
					
						
							|  |  |  | 	EDBM_flag_disable_all(em, BM_ELEM_SELECT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-19 08:36:27 +00:00
										 |  |  | 	BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faceout", BM_FACE, BM_ELEM_SELECT, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-27 04:46:52 +00:00
										 |  |  | 	if (!EDBM_op_finish(em, &bmop, op, TRUE)) { | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-03-27 00:01:35 +00:00
										 |  |  | 		EDBM_update_generic(C, em, TRUE); | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MESH_OT_inset(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PropertyRNA *prop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							|  |  |  | 	ot->name = "Inset Faces"; | 
					
						
							|  |  |  | 	ot->idname = "MESH_OT_inset"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-23 21:25:07 +00:00
										 |  |  | 	ot->exec = edbm_inset_exec; | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 	ot->poll = ED_operator_editmesh; | 
					
						
							|  |  |  | 	ot->description = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flags */ | 
					
						
							| 
									
										
										
										
											2012-03-26 02:56:48 +00:00
										 |  |  | 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* properties */ | 
					
						
							| 
									
										
										
										
											2012-03-20 11:45:55 +00:00
										 |  |  | 	// RNA_def_boolean(ot->srna, "use_boundary",        TRUE, "Boundary",  "Inset face boundries");
 | 
					
						
							| 
									
										
										
										
											2012-03-19 21:27:24 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "use_even_offset",     TRUE, "Offset Even",      "Scale the offset to give more even thickness"); | 
					
						
							|  |  |  | 	RNA_def_boolean(ot->srna, "use_relative_offset", FALSE, "Offset Relative", "Scale the offset by surrounding geometry"); | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	prop = RNA_def_float(ot->srna, "thickness", 0.01f, 0.0f, FLT_MAX, "thickness", "", 0.0f, 10.0f); | 
					
						
							|  |  |  | 	/* use 1 rather then 10 for max else dragging the button moves too far */ | 
					
						
							|  |  |  | 	RNA_def_property_ui_range(prop, 0.0, 1.0, 0.01, 4); | 
					
						
							| 
									
										
										
										
											2012-03-19 21:40:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 06:20:59 +00:00
										 |  |  | 	RNA_def_boolean(ot->srna, "use_outset", FALSE, "Outset", "Outset rather than inset"); | 
					
						
							| 
									
										
										
										
											2012-03-19 05:45:15 +00:00
										 |  |  | } |