| 
									
										
										
										
											2012-02-19 18:31:04 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup bmesh | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \addtogroup bmesh BMesh | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * \brief BMesh is a non-manifold boundary representation | 
					
						
							|  |  |  |  * designed to support advanced editing operations. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \section bm_structure The Structure | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * BMesh stores topology in four main element structures: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * - Faces - BMFace | 
					
						
							|  |  |  |  * - Loops - BMLoop, (stores per-face-vertex data, UV's, vertex-colors, etc) | 
					
						
							|  |  |  |  * - Edges - BMEdge | 
					
						
							|  |  |  |  * - Verts - BMVert | 
					
						
							|  |  |  |  * \subsection bm_header_flags Header Flags | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * Each element (vertex/edge/face/loop) | 
					
						
							|  |  |  |  * in a mesh has an associated bit-field called "header flags". | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * BMHeader flags should **never** be read or written to by bmesh operators (see Operators below). | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * Access to header flags is done with ``BM_elem_flag_*()`` functions. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \subsection bm_faces Faces | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Faces in BMesh are stored as a circular linked list of loops. Loops store per-face-vertex data | 
					
						
							| 
									
										
										
										
											2020-09-11 14:45:42 +10:00
										 |  |  |  * (among other things outlined later in this document), and define the face boundary. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \subsection bm_loop The Loop | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-09-18 07:39:56 +10:00
										 |  |  |  * Loops can be thought of as a *face-corner*, since faces don't reference verts or edges directly. | 
					
						
							| 
									
										
										
										
											2014-09-27 16:31:40 +10:00
										 |  |  |  * Each loop connects the face to one of its corner vertices, | 
					
						
							|  |  |  |  * and also references an edge which connects this loop's vertex to the next loop's vertex. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-09-18 07:39:56 +10:00
										 |  |  |  * Loops allow faces to access their verts and edges, | 
					
						
							|  |  |  |  * while edges and faces store their loops, allowing access in the opposite direction too. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Loop pointers: | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * - BMLoop#v - pointer to the vertex associated with this loop. | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * - BMLoop#e - pointer to the edge associated with this loop, | 
					
						
							|  |  |  |  *   between verts ``(loop->v, loop->next->v)`` | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * - BMLoop#f - pointer to the face associated with this loop. | 
					
						
							|  |  |  |  * \subsection bm_two_side_face 2-Sided Faces | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * There are some situations where you need 2-sided faces (e.g. a face of two vertices). | 
					
						
							|  |  |  |  * This is supported by BMesh, but note that such faces should only be used as intermediary steps, | 
					
						
							|  |  |  |  * and should not end up in the final mesh. | 
					
						
							|  |  |  |  * \subsection bm_edges_and_verts Edges and Vertices | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-08-01 12:36:14 +10:00
										 |  |  |  * Edges and Vertices in BMesh are primitive structures. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-08-01 12:36:14 +10:00
										 |  |  |  * \note There can be more than one edge between two vertices in BMesh, | 
					
						
							| 
									
										
										
										
											2018-06-27 10:56:32 +02:00
										 |  |  |  * though the rest of Blender (i.e. DNA and evaluated Mesh) does not support this. | 
					
						
							| 
									
										
										
										
											2015-08-01 12:36:14 +10:00
										 |  |  |  * So it should only occur temporarily during editing operations. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \subsection bm_queries Queries | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The following topological queries are available: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * - Edges/Faces/Loops around a vertex. | 
					
						
							|  |  |  |  * - Faces around an edge. | 
					
						
							|  |  |  |  * - Loops around an edge. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * These are accessible through the iterator api, which is covered later in this document | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-06-30 10:29:40 +02:00
										 |  |  |  * See source/blender/bmesh/bmesh_query.h for more misc. queries. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \section bm_api The BMesh API | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * One of the goals of the BMesh API is to make it easy | 
					
						
							|  |  |  |  * and natural to produce highly maintainable code. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * Code duplication, etc are avoided where possible. | 
					
						
							|  |  |  |  * \subsection bm_iter_api Iterator API | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Most topological queries in BMesh go through an iterator API (see Queries above). | 
					
						
							| 
									
										
										
										
											2015-07-31 22:59:02 +10:00
										 |  |  |  * These are defined in bmesh_iterators.h. | 
					
						
							|  |  |  |  * If you can, please use the #BM_ITER_MESH, #BM_ITER_ELEM macros in bmesh_iterators.h | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \subsection bm_walker_api Walker API | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Topological queries that require a stack (e.g. recursive queries) go through the Walker API, | 
					
						
							|  |  |  |  * which is defined in bmesh_walkers.h. Currently the "walkers" are hard-coded into the API, | 
					
						
							|  |  |  |  * though a mechanism for plugging in new walkers needs to be added at some point. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Most topological queries should go through these two APIs; | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * there are additional functions you can use for topological iteration, | 
					
						
							|  |  |  |  * but their meant for internal bmesh code. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * Note that the walker API supports delimiter flags, | 
					
						
							|  |  |  |  * to allow the caller to flag elements not to walk past. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \subsection bm_ops Operators | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Operators are an integral part of BMesh. Unlike regular blender operators, | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * BMesh operators **bmo's** are designed to be nested (e.g. call other operators). | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * Each operator has a number of input/output "slots" | 
					
						
							|  |  |  |  * which are used to pass settings & data into/out of the operator | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * (and allows for chaining operators together). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * These slots are identified by name, using strings. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * Access to slots is done with ``BMO_slot_***()`` functions. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \subsection bm_tool_flags Tool Flags | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * The BMesh API provides a set of flags for faces, edges and vertices, | 
					
						
							|  |  |  |  * which are private to an operator. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * These flags may be used by the client operator code as needed | 
					
						
							|  |  |  |  * (a common example is flagging elements for use in another operator). | 
					
						
							|  |  |  |  * Each call to an operator allocates its own set of tool flags when it's executed, | 
					
						
							|  |  |  |  * avoiding flag conflicts between operators. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * These flags should not be confused with header flags, which are used to store persistent flags | 
					
						
							|  |  |  |  * (e.g. selection, hide status, etc). | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * Access to tool flags is done with ``BMO_elem_flag_***()`` functions. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * \warning Operators are **never** allowed to read or write to header flags. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * They act entirely on the data inside their input slots. | 
					
						
							|  |  |  |  * For example an operator should not check the selected state of an element, | 
					
						
							|  |  |  |  * there are some exceptions to this - some operators check of a face is smooth. | 
					
						
							|  |  |  |  * \subsection bm_slot_types Slot Types | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The following slot types are available: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * - integer - #BMO_OP_SLOT_INT | 
					
						
							|  |  |  |  * - boolean - #BMO_OP_SLOT_BOOL | 
					
						
							|  |  |  |  * - float   - #BMO_OP_SLOT_FLT | 
					
						
							| 
									
										
										
										
											2015-07-31 22:59:02 +10:00
										 |  |  |  * - pointer - #BMO_OP_SLOT_PTR | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * - matrix  - #BMO_OP_SLOT_MAT | 
					
						
							|  |  |  |  * - vector  - #BMO_OP_SLOT_VEC | 
					
						
							|  |  |  |  * - buffer  - #BMO_OP_SLOT_ELEMENT_BUF - a list of verts/edges/faces. | 
					
						
							|  |  |  |  * - map     - BMO_OP_SLOT_MAPPING - simple hash map. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * \subsection bm_slot_iter Slot Iterators | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * Access to element buffers or maps must go through the slot iterator api, | 
					
						
							|  |  |  |  * defined in bmesh_operators.h. | 
					
						
							| 
									
										
										
										
											2012-02-27 20:27:19 +00:00
										 |  |  |  * Use #BMO_ITER where ever possible. | 
					
						
							|  |  |  |  * \subsection bm_elem_buf Element Buffers | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The element buffer slot type is used to feed elements (verts/edges/faces) to operators. | 
					
						
							|  |  |  |  * Internally they are stored as pointer arrays (which happily has not caused any problems so far). | 
					
						
							|  |  |  |  * Many operators take in a buffer of elements, process it, | 
					
						
							|  |  |  |  * then spit out a new one; this allows operators to be chained together. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * \note Element buffers may have elements of different types within the same buffer | 
					
						
							|  |  |  |  * (this is supported by the API. | 
					
						
							| 
									
										
										
										
											2012-02-28 19:10:53 +00:00
										 |  |  |  * \section bm_fname Function Naming Conventions | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * These conventions should be used throughout the bmesh module. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-03-13 03:45:15 +11:00
										 |  |  |  * - ``bmesh_kernel_*()`` - Low level API, for primitive functions that others are built ontop of. | 
					
						
							|  |  |  |  * - ``bmesh_***()`` - Low level API function. | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * - ``bm_***()`` -     'static' functions, not a part of the API at all, | 
					
						
							|  |  |  |  *   but use prefix since they operate on BMesh data. | 
					
						
							| 
									
										
										
										
											2017-03-13 03:45:15 +11:00
										 |  |  |  * - ``BM_***()`` -     High level BMesh API function for use anywhere. | 
					
						
							| 
									
										
										
										
											2013-09-08 06:55:58 +00:00
										 |  |  |  * - ``BMO_***()`` -    High level operator API function for use anywhere. | 
					
						
							|  |  |  |  * - ``bmo_***()`` -    Low level / internal operator API functions. | 
					
						
							|  |  |  |  * - ``_bm_***()`` -    Functions which are called via macros only. | 
					
						
							| 
									
										
										
										
											2012-02-28 19:10:53 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-04-26 08:27:50 +00:00
										 |  |  |  * \section bm_todo BMesh TODO's | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * There may be a better place for this section, but adding here for now. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \subsection bm_todo_optimize Optimizations | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-29 22:04:24 +10:00
										 |  |  |  * - Skip normal calc when its not needed | 
					
						
							|  |  |  |  *   (when calling chain of operators & for modifiers, flag as dirty) | 
					
						
							|  |  |  |  * - Skip BMO flag allocation, its not needed in many cases, | 
					
						
							|  |  |  |  *   this is fairly redundant to calc by default. | 
					
						
							|  |  |  |  * - Ability to call BMO's with option not to create return data (will save some time) | 
					
						
							|  |  |  |  * - Binary diff UNDO, currently this uses huge amount of ram | 
					
						
							|  |  |  |  *   when all shapes are stored for each undo step for eg. | 
					
						
							|  |  |  |  * - Use two different iterator types for BMO map/buffer types. | 
					
						
							| 
									
										
										
										
											2012-02-19 18:31:04 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 01:24:58 +00:00
										 |  |  | #include "DNA_customdata_types.h" /* BMesh struct in bmesh_class.h uses */
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "DNA_listBase.h"         /* selection history uses */
 | 
					
						
							| 
									
										
										
										
											2012-02-19 18:31:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2012-02-19 18:31:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 18:16:39 +02:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 18:31:04 +00:00
										 |  |  | #include "bmesh_class.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* include the rest of the API */ | 
					
						
							| 
									
										
										
										
											2012-03-21 12:08:16 +00:00
										 |  |  | #include "intern/bmesh_error.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "intern/bmesh_operator_api.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-01 23:31:01 +01:00
										 |  |  | #include "intern/bmesh_callback_generic.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-21 07:51:47 +00:00
										 |  |  | #include "intern/bmesh_construct.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "intern/bmesh_core.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-17 09:21:30 +11:00
										 |  |  | #include "intern/bmesh_delete.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-11 14:40:03 +00:00
										 |  |  | #include "intern/bmesh_edgeloop.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | #include "intern/bmesh_interp.h"
 | 
					
						
							|  |  |  | #include "intern/bmesh_iterators.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-30 18:24:08 +00:00
										 |  |  | #include "intern/bmesh_log.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | #include "intern/bmesh_marking.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 18:28:30 +00:00
										 |  |  | #include "intern/bmesh_mesh.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-05 18:27:38 +10:00
										 |  |  | #include "intern/bmesh_mesh_convert.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-21 01:47:16 +11:00
										 |  |  | #include "intern/bmesh_mesh_duplicate.h"
 | 
					
						
							| 
									
										
										
										
											2021-06-08 00:45:54 +10:00
										 |  |  | #include "intern/bmesh_mesh_normals.h"
 | 
					
						
							| 
									
										
										
										
											2021-05-28 18:18:13 +10:00
										 |  |  | #include "intern/bmesh_mesh_partial_update.h"
 | 
					
						
							| 
									
										
										
										
											2021-06-01 12:58:52 +10:00
										 |  |  | #include "intern/bmesh_mesh_tessellate.h"
 | 
					
						
							| 
									
										
										
										
											2012-03-22 05:13:43 +00:00
										 |  |  | #include "intern/bmesh_mesh_validate.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 18:28:30 +00:00
										 |  |  | #include "intern/bmesh_mods.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | #include "intern/bmesh_operators.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 18:28:30 +00:00
										 |  |  | #include "intern/bmesh_polygon.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-09 16:21:43 +11:00
										 |  |  | #include "intern/bmesh_polygon_edgenet.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-30 10:29:40 +02:00
										 |  |  | #include "intern/bmesh_query.h"
 | 
					
						
							| 
									
										
										
										
											2020-07-09 13:33:15 +10:00
										 |  |  | #include "intern/bmesh_query_uv.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-28 16:47:12 +00:00
										 |  |  | #include "intern/bmesh_walkers.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 01:24:58 +00:00
										 |  |  | #include "intern/bmesh_inline.h"
 | 
					
						
							| 
									
										
										
										
											2012-02-19 18:31:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |