| 
									
										
										
										
											2012-02-23 05:20:09 +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, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2012 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Campbell Barton | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 23:43:11 +00:00
										 |  |  | /** \file blender/python/bmesh/bmesh_py_utils.c
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  |  *  \ingroup pybmesh | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file defines the 'bmesh.utils' module. | 
					
						
							|  |  |  |  * Utility functions for operating on 'bmesh.types' | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | #include "../mathutils/mathutils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 01:24:58 +00:00
										 |  |  | #include "bmesh.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bmesh_py_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | #include "bmesh_py_utils.h" /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_vert_collapse_edge_doc, | 
					
						
							|  |  |  | ".. method:: vert_collapse_edge(vert, edge)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | "   Collapse a vertex into an edge.\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   :arg vert: The vert that will be collapsed.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "   :arg edge: The edge to collapse into.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type edge: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "   :return: The resulting edge from the collapse operation.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :rtype: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | static PyObject *bpy_bm_utils_vert_collapse_edge(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_BMEdge *py_edge; | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMEdge *e_new = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O!O!:vert_collapse_edge", | 
					
						
							|  |  |  | 	                      &BPy_BMVert_Type, &py_vert, | 
					
						
							|  |  |  | 	                      &BPy_BMEdge_Type, &py_edge)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_edge); | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* this doubles for checking that the verts are in the same mesh */ | 
					
						
							|  |  |  | 	if (!(py_edge->e->v1 == py_vert->v || | 
					
						
							|  |  |  | 	      py_edge->e->v2 == py_vert->v)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "vert_collapse_edge(vert, edge): the vertex is not found in the edge"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (BM_vert_edge_count(py_vert->v) > 2) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "vert_collapse_edge(vert, edge): vert has more then 2 connected edges"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = py_edge->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-26 05:48:12 +00:00
										 |  |  | 	e_new = BM_vert_collapse_edge(bm, py_edge->e, py_vert->v, TRUE); | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (e_new) { | 
					
						
							|  |  |  | 		return BPy_BMEdge_CreatePyObject(bm, e_new); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "vert_collapse_edge(vert, edge): no new edge created, internal error"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(bpy_bm_utils_vert_collapse_faces_doc, | 
					
						
							|  |  |  | ".. method:: vert_collapse_faces(vert, edge, fac, join_faces)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Split an edge, return the newly created data.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg vert: The vert that will be collapsed.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "   :arg edge: The edge to collapse into.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type edge: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "   :arg fac: The factor to use when merging customdata [0 - 1].\n" | 
					
						
							|  |  |  | "   :type fac: float\n" | 
					
						
							|  |  |  | "   :return: The resulting edge from the collapse operation.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :rtype: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | static PyObject *bpy_bm_utils_vert_collapse_faces(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_BMEdge *py_edge; | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float fac; | 
					
						
							|  |  |  | 	int do_join_faces; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMEdge *e_new = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O!O!fi:vert_collapse_faces", | 
					
						
							|  |  |  | 	                      &BPy_BMVert_Type, &py_vert, | 
					
						
							|  |  |  | 	                      &BPy_BMEdge_Type, &py_edge, | 
					
						
							|  |  |  | 	                      &fac, &do_join_faces)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_edge); | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* this doubles for checking that the verts are in the same mesh */ | 
					
						
							|  |  |  | 	if (!(py_edge->e->v1 == py_vert->v || | 
					
						
							|  |  |  | 	      py_edge->e->v2 == py_vert->v)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "vert_collapse_faces(vert, edge): the vertex is not found in the edge"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (BM_vert_edge_count(py_vert->v) > 2) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "vert_collapse_faces(vert, edge): vert has more then 2 connected edges"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = py_edge->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-26 05:48:12 +00:00
										 |  |  | 	e_new = BM_vert_collapse_faces(bm, py_edge->e, py_vert->v, CLAMPIS(fac, 0.0f, 1.0f), do_join_faces, TRUE); | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (e_new) { | 
					
						
							|  |  |  | 		return BPy_BMEdge_CreatePyObject(bm, e_new); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "vert_collapse_edge(vert, edge): no new edge created, internal error"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_vert_dissolve_doc, | 
					
						
							|  |  |  | ".. method:: vert_dissolve(vert)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Dissolve this vertex (will be removed).\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg vert: The vert to be dissolved.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "   :return: True when the vertex dissolve is successful.\n" | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | "   :rtype: boolean\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | static PyObject *bpy_bm_utils_vert_dissolve(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O!:vert_dissolve", | 
					
						
							|  |  |  | 	                      &BPy_BMVert_Type, &py_vert)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = py_vert->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return PyBool_FromLong((BM_vert_dissolve(bm, py_vert->v))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_vert_separate_doc, | 
					
						
							|  |  |  | ".. method:: vert_separate(vert, edges)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Separate this vertex at every edge.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg vert: The vert to be separated.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | "   :arg edges: The edges to separated.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type edges: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | "   :return: The newly separated verts (including the vertex passed).\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :rtype: tuple of :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | static PyObject *bpy_bm_utils_vert_separate(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert; | 
					
						
							|  |  |  | 	PyObject *edge_seq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMVert **elem; | 
					
						
							|  |  |  | 	int elem_len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* edges to split */ | 
					
						
							|  |  |  | 	BMEdge **edge_array; | 
					
						
							|  |  |  | 	Py_ssize_t edge_array_len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	PyObject *ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O!O:vert_separate", | 
					
						
							|  |  |  | 	                      &BPy_BMVert_Type, &py_vert, | 
					
						
							|  |  |  | 	                      &edge_seq)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = py_vert->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	edge_array = BPy_BMElem_PySeq_As_Array(&bm, edge_seq, 0, PY_SSIZE_T_MAX, | 
					
						
							| 
									
										
										
										
											2012-03-14 04:46:12 +00:00
										 |  |  | 	                                       &edge_array_len, BM_EDGE, | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | 	                                       TRUE, TRUE, "vert_separate(...)"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (edge_array == NULL) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (BM_vert_separate(bm, py_vert->v, &elem, &elem_len, edge_array, edge_array_len)) { | 
					
						
							|  |  |  | 		/* return collected verts */ | 
					
						
							|  |  |  | 		ret = BPy_BMElem_Array_As_Tuple(bm, (BMHeader **)elem, elem_len); | 
					
						
							|  |  |  | 		MEM_freeN(elem); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		ret = PyTuple_New(0); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	PyMem_FREE(edge_array); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_edge_split_doc, | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | ".. method:: edge_split(edge, vert, fac)\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   Split an edge, return the newly created data.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg edge: The edge to split.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type edge: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | "   :arg vert: One of the verts on the edge, defines the split direction.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "   :arg fac: The point on the edge where the new vert will be created [0 - 1].\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | "   :type fac: float\n" | 
					
						
							|  |  |  | "   :return: The newly created (edge, vert) pair.\n" | 
					
						
							|  |  |  | "   :rtype: tuple\n" | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_BMEdge *py_edge; | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert; | 
					
						
							|  |  |  | 	float fac; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMVert *v_new = NULL; | 
					
						
							|  |  |  | 	BMEdge *e_new = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O!O!f:edge_split", | 
					
						
							|  |  |  | 	                      &BPy_BMEdge_Type, &py_edge, | 
					
						
							|  |  |  | 	                      &BPy_BMVert_Type, &py_vert, | 
					
						
							|  |  |  | 	                      &fac)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_edge); | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 	/* this doubles for checking that the verts are in the same mesh */ | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | 	if (!(py_edge->e->v1 == py_vert->v || | 
					
						
							|  |  |  | 	      py_edge->e->v2 == py_vert->v)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "edge_split(edge, vert): the vertex is not found in the edge"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = py_edge->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 	v_new = BM_edge_split(bm, py_edge->e, py_vert->v, &e_new, CLAMPIS(fac, 0.0f, 1.0f)); | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (v_new && e_new) { | 
					
						
							|  |  |  | 		PyObject *ret = PyTuple_New(2); | 
					
						
							|  |  |  | 		PyTuple_SET_ITEM(ret, 0, BPy_BMEdge_CreatePyObject(bm, e_new)); | 
					
						
							|  |  |  | 		PyTuple_SET_ITEM(ret, 1, BPy_BMVert_CreatePyObject(bm, v_new)); | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "edge_split(edge, vert): couldn't split the edge, internal error"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(bpy_bm_utils_edge_rotate_doc, | 
					
						
							|  |  |  | ".. method:: edge_rotate(edge, ccw=False)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Rotate the edge and return the newly created edge.\n" | 
					
						
							|  |  |  | "   If rotating the edge fails, None will be returned.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg edge: The edge to rotate.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type edge: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | "   :arg ccw: When True the edge will be rotated counter clockwise.\n" | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | "   :type ccw: boolean\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | "   :return: The newly rotated edge.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :rtype: :class:`bmesh.types.BMEdge`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | static PyObject *bpy_bm_utils_edge_rotate(PyObject *UNUSED(self), PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_BMEdge *py_edge; | 
					
						
							|  |  |  | 	int do_ccw = FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMEdge *e_new = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "O!|i:edge_rotate", | 
					
						
							|  |  |  | 	                      &BPy_BMEdge_Type, &py_edge, | 
					
						
							|  |  |  | 	                      &do_ccw)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_edge); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = py_edge->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-05 00:50:18 +00:00
										 |  |  | 	e_new = BM_edge_rotate(bm, py_edge->e, do_ccw, 0); /* BMESH_TODO - expose to API */ | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (e_new) { | 
					
						
							|  |  |  | 		return BPy_BMEdge_CreatePyObject(bm, e_new); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		Py_RETURN_NONE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_face_split_doc, | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | ".. method:: face_split(face, vert_a, vert_b, coords=(), use_exist=True, example=None)\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-06-21 12:27:57 +00:00
										 |  |  | "   Face split with optional intermediate points.\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 11:27:22 +00:00
										 |  |  | "   :arg face: The face to cut.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type face: :class:`bmesh.types.BMFace`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 11:27:22 +00:00
										 |  |  | "   :arg vert_a: First vertex to cut in the face (face must contain the vert).\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert_a: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 11:27:22 +00:00
										 |  |  | "   :arg vert_b: Second vertex to cut in the face (face must contain the vert).\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert_b: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | "   :arg coords: Optional argument to define points inbetween *vert_a* and *vert_b*.\n" | 
					
						
							|  |  |  | "   :type coords: sequence of float triplets\n" | 
					
						
							|  |  |  | "   :arg use_exist: .Use an existing edge if it exists (Only used when *coords* argument is empty or omitted)\n" | 
					
						
							|  |  |  | "   :type use_exist: boolean\n" | 
					
						
							|  |  |  | "   :arg example: Newly created edge will copy settings from this one.\n" | 
					
						
							|  |  |  | "   :type example: :class:`bmesh.types.BMEdge`\n" | 
					
						
							|  |  |  | "   :return: The newly created face or None on failure.\n" | 
					
						
							|  |  |  | "   :rtype: (:class:`bmesh.types.BMFace`, :class:`bmesh.types.BMLoop`) pair\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args, PyObject *kw) | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | 	static const char *kwlist[] = {"face", "vert_a", "vert_b", | 
					
						
							|  |  |  | 	                               "coords", "use_exist", "example", NULL}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 	BPy_BMFace *py_face; | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert_a; | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert_b; | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* optional */ | 
					
						
							|  |  |  | 	PyObject *py_coords = NULL; | 
					
						
							|  |  |  | 	int edge_exists = TRUE; | 
					
						
							|  |  |  | 	BPy_BMEdge *py_edge_example = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float *coords; | 
					
						
							|  |  |  | 	int ncoords = 0; | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMFace *f_new = NULL; | 
					
						
							|  |  |  | 	BMLoop *l_new = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | 	if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!O!|OiO!:face_split", (char **)kwlist, | 
					
						
							|  |  |  | 	                                 &BPy_BMFace_Type, &py_face, | 
					
						
							|  |  |  | 	                                 &BPy_BMVert_Type, &py_vert_a, | 
					
						
							|  |  |  | 	                                 &BPy_BMVert_Type, &py_vert_b, | 
					
						
							|  |  |  | 	                                 &py_coords, | 
					
						
							|  |  |  | 	                                 &edge_exists, | 
					
						
							|  |  |  | 	                                 &BPy_BMEdge_Type, &py_edge_example)) | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_face); | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert_a); | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert_b); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 11:27:22 +00:00
										 |  |  | 	if (py_edge_example) { | 
					
						
							|  |  |  | 		BPY_BM_CHECK_OBJ(py_edge_example); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 	/* this doubles for checking that the verts are in the same mesh */ | 
					
						
							|  |  |  | 	if (BM_vert_in_face(py_face->f, py_vert_a->v) == FALSE || | 
					
						
							|  |  |  | 	    BM_vert_in_face(py_face->f, py_vert_b->v) == FALSE) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "face_split(...): one of the verts passed is not found in the face"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (py_vert_a->v == py_vert_b->v) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "face_split(...): vert arguments must differ"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | 	if (py_coords) { | 
					
						
							|  |  |  | 		ncoords = mathutils_array_parse_alloc_v(&coords, 3, py_coords, "face_split(...): "); | 
					
						
							|  |  |  | 		if (ncoords == -1) { | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* --- main function body --- */ | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 	bm = py_face->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | 	if (ncoords) { | 
					
						
							|  |  |  | 		f_new = BM_face_split_n(bm, py_face->f, | 
					
						
							|  |  |  | 		                        py_vert_a->v, py_vert_b->v, | 
					
						
							|  |  |  | 		                        (float (*)[3])coords, ncoords, | 
					
						
							|  |  |  | 		                        &l_new, py_edge_example ? py_edge_example->e : NULL); | 
					
						
							| 
									
										
										
										
											2012-06-26 16:58:58 +00:00
										 |  |  | 		PyMem_Free(coords); | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		f_new = BM_face_split(bm, py_face->f, | 
					
						
							|  |  |  | 		                      py_vert_a->v, py_vert_b->v, | 
					
						
							|  |  |  | 		                      &l_new, py_edge_example ? py_edge_example->e : NULL, edge_exists); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (f_new && l_new) { | 
					
						
							|  |  |  | 		PyObject *ret = PyTuple_New(2); | 
					
						
							|  |  |  | 		PyTuple_SET_ITEM(ret, 0, BPy_BMFace_CreatePyObject(bm, f_new)); | 
					
						
							|  |  |  | 		PyTuple_SET_ITEM(ret, 1, BPy_BMLoop_CreatePyObject(bm, l_new)); | 
					
						
							|  |  |  | 		return ret; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "face_split(...): couldn't split the face, internal error"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-24 11:04:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_face_join_doc, | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  | ".. method:: face_join(faces, remove=True)\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   Joins a sequence of faces.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-02-24 11:04:09 +00:00
										 |  |  | "   :arg faces: Sequence of faces.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type faces: :class:`bmesh.types.BMFace`\n" | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  | "   :arg remove: Remove the edges and vertices between the faces.\n" | 
					
						
							|  |  |  | "   :type remove: boolean\n" | 
					
						
							| 
									
										
										
										
											2012-02-24 06:44:04 +00:00
										 |  |  | "   :return: The newly created face or None on failure.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :rtype: :class:`bmesh.types.BMFace`\n" | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  | static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMesh *bm = NULL; | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  | 	PyObject *py_face_array; | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | 	BMFace **face_array; | 
					
						
							|  |  |  | 	Py_ssize_t face_seq_len = 0; | 
					
						
							|  |  |  | 	BMFace *f_new; | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  | 	int do_remove = TRUE; | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O|i:face_join", &py_face_array, &do_remove)) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	face_array = BPy_BMElem_PySeq_As_Array(&bm, py_face_array, 2, PY_SSIZE_T_MAX, | 
					
						
							| 
									
										
										
										
											2012-03-14 04:46:12 +00:00
										 |  |  | 	                                       &face_seq_len, BM_FACE, | 
					
						
							| 
									
										
										
										
											2012-02-24 04:59:13 +00:00
										 |  |  | 	                                       TRUE, TRUE, "face_join(...)"); | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (face_array == NULL) { | 
					
						
							|  |  |  | 		return NULL; /* error will be set */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Go ahead and join the face!
 | 
					
						
							|  |  |  | 	 * --------------------------- */ | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  | 	f_new = BM_faces_join(bm, face_array, (int)face_seq_len, do_remove); | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | 	PyMem_FREE(face_array); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 17:14:53 +00:00
										 |  |  | 	if (f_new) { | 
					
						
							|  |  |  | 		return BPy_BMFace_CreatePyObject(bm, f_new); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		Py_RETURN_NONE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-24 11:04:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_face_vert_separate_doc, | 
					
						
							|  |  |  | ".. method:: face_vert_separate(face, vert)\n" | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   Rip a vertex in a face away and add a new vertex.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | "   :arg face: The face to separate.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type face: :class:`bmesh.types.BMFace`\n" | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | "   :arg vert: A vertex in the face to separate.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | "   :return vert: The newly created vertex or None of failure.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :rtype vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   .. note::\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | "      This is the same as loop_separate, and has only been added for convenience.\n" | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | static PyObject *bpy_bm_utils_face_vert_separate(PyObject *UNUSED(self), PyObject *args) | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BPy_BMFace *py_face; | 
					
						
							|  |  |  | 	BPy_BMVert *py_vert; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMLoop *l; | 
					
						
							|  |  |  | 	BMVert *v_new; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "O!O!:face_vert_separate", | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | 	                      &BPy_BMFace_Type, &py_face, | 
					
						
							|  |  |  | 	                      &BPy_BMVert_Type, &py_vert)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_face); | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(py_vert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = py_face->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (bm != py_vert->bm) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "mesh elements are from different meshes"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	l = BM_face_vert_share_loop(py_face->f, py_vert->v); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (l == NULL) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, | 
					
						
							|  |  |  | 		                "vertex not found in face"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | 	v_new = BM_face_loop_separate(bm, l); | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (v_new != l->v) { | 
					
						
							|  |  |  | 		return BPy_BMVert_CreatePyObject(bm, v_new); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		Py_RETURN_NONE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-24 11:04:09 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_face_flip_doc, | 
					
						
							|  |  |  | ".. method:: face_flip(faces)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Flip the faces direction.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :arg face: Face to flip.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type face: :class:`bmesh.types.BMFace`\n" | 
					
						
							| 
									
										
										
										
											2012-02-24 11:04:09 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | static PyObject *bpy_bm_utils_face_flip(PyObject *UNUSED(self), BPy_BMFace *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!BPy_BMFace_Check(value)) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  | 		             "face_flip(face): BMFace expected, not '%.200s'", | 
					
						
							|  |  |  | 		             Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BM_face_normal_flip(value->bm, value->f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | PyDoc_STRVAR(bpy_bm_utils_loop_separate_doc, | 
					
						
							|  |  |  | ".. method:: loop_separate(loop)\n" | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | "\n" | 
					
						
							|  |  |  | "   Rip a vertex in a face away and add a new vertex.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | "   :arg loop: The to separate.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :type loop: :class:`bmesh.types.BMFace`\n" | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | "   :return vert: The newly created vertex or None of failure.\n" | 
					
						
							| 
									
										
										
										
											2012-03-11 04:07:22 +00:00
										 |  |  | "   :rtype vert: :class:`bmesh.types.BMVert`\n" | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | static PyObject *bpy_bm_utils_loop_separate(PyObject *UNUSED(self), BPy_BMLoop *value) | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BMesh *bm; | 
					
						
							|  |  |  | 	BMVert *v_new; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!BPy_BMLoop_Check(value)) { | 
					
						
							|  |  |  | 		PyErr_Format(PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | 		             "loop_separate(loop): BMLoop expected, not '%.200s'", | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | 		             Py_TYPE(value)->tp_name); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_BM_CHECK_OBJ(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bm = value->bm; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  | 	v_new = BM_face_loop_separate(bm, value->l); | 
					
						
							| 
									
										
										
										
											2012-03-08 20:00:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (v_new != value->l->v) { | 
					
						
							|  |  |  | 		return BPy_BMVert_CreatePyObject(bm, v_new); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		Py_RETURN_NONE; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | static struct PyMethodDef BPy_BM_utils_methods[] = { | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  |     {"vert_collapse_edge",  (PyCFunction)bpy_bm_utils_vert_collapse_edge,  METH_VARARGS, bpy_bm_utils_vert_collapse_edge_doc}, | 
					
						
							|  |  |  |     {"vert_collapse_faces", (PyCFunction)bpy_bm_utils_vert_collapse_faces, METH_VARARGS, bpy_bm_utils_vert_collapse_faces_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  |     {"vert_dissolve",       (PyCFunction)bpy_bm_utils_vert_dissolve,       METH_VARARGS, bpy_bm_utils_vert_dissolve_doc}, /* could use METH_O */ | 
					
						
							|  |  |  |     {"vert_separate",       (PyCFunction)bpy_bm_utils_vert_separate,       METH_VARARGS, bpy_bm_utils_vert_separate_doc}, | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  |     {"edge_split",          (PyCFunction)bpy_bm_utils_edge_split,          METH_VARARGS, bpy_bm_utils_edge_split_doc}, | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  |     {"edge_rotate",         (PyCFunction)bpy_bm_utils_edge_rotate,         METH_VARARGS, bpy_bm_utils_edge_rotate_doc}, | 
					
						
							| 
									
										
										
										
											2012-04-22 10:19:24 +00:00
										 |  |  |     {"face_split",          (PyCFunction)bpy_bm_utils_face_split,          METH_VARARGS | METH_KEYWORDS, bpy_bm_utils_face_split_doc}, | 
					
						
							| 
									
										
										
										
											2012-04-04 14:48:10 +00:00
										 |  |  |     {"face_join",           (PyCFunction)bpy_bm_utils_face_join,           METH_VARARGS, bpy_bm_utils_face_join_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  |     {"face_vert_separate",  (PyCFunction)bpy_bm_utils_face_vert_separate,  METH_VARARGS, bpy_bm_utils_face_vert_separate_doc}, | 
					
						
							| 
									
										
										
										
											2012-02-24 11:04:09 +00:00
										 |  |  |     {"face_flip",           (PyCFunction)bpy_bm_utils_face_flip,           METH_O,       bpy_bm_utils_face_flip_doc}, | 
					
						
							| 
									
										
										
										
											2012-03-09 00:01:38 +00:00
										 |  |  |     {"loop_separate",       (PyCFunction)bpy_bm_utils_loop_separate,       METH_O,       bpy_bm_utils_loop_separate_doc}, | 
					
						
							| 
									
										
										
										
											2012-02-23 10:29:04 +00:00
										 |  |  |     {NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 14:15:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 21:40:01 +00:00
										 |  |  | PyDoc_STRVAR(BPy_BM_utils_doc, | 
					
						
							| 
									
										
										
										
											2012-02-24 11:04:09 +00:00
										 |  |  | "This module provides access to blenders bmesh data structures." | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2012-06-26 21:40:01 +00:00
										 |  |  | static struct PyModuleDef BPy_BM_utils_module_def = { | 
					
						
							| 
									
										
										
										
											2012-02-23 11:27:22 +00:00
										 |  |  |     PyModuleDef_HEAD_INIT, | 
					
						
							|  |  |  |     "bmesh.utils",  /* m_name */ | 
					
						
							| 
									
										
										
										
											2012-06-26 21:40:01 +00:00
										 |  |  |     BPy_BM_utils_doc,  /* m_doc */ | 
					
						
							| 
									
										
										
										
											2012-02-23 11:27:22 +00:00
										 |  |  |     0,  /* m_size */ | 
					
						
							|  |  |  |     BPy_BM_utils_methods,  /* m_methods */ | 
					
						
							|  |  |  |     NULL,  /* m_reload */ | 
					
						
							|  |  |  |     NULL,  /* m_traverse */ | 
					
						
							|  |  |  |     NULL,  /* m_clear */ | 
					
						
							|  |  |  |     NULL,  /* m_free */ | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-24 12:57:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | PyObject *BPyInit_bmesh_utils(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *submodule; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 21:40:01 +00:00
										 |  |  | 	submodule = PyModule_Create(&BPy_BM_utils_module_def); | 
					
						
							| 
									
										
										
										
											2012-02-23 05:20:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return submodule; | 
					
						
							|  |  |  | } |