2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-02-19 19:31:04 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bmesh
|
2012-02-27 21:27:19 +01:00
|
|
|
*
|
|
|
|
* \addtogroup bmesh BMesh
|
|
|
|
*
|
2019-04-29 14:04:24 +02:00
|
|
|
* \brief BMesh is a non-manifold boundary representation
|
|
|
|
* designed to support advanced editing operations.
|
2012-02-27 21:27:19 +01:00
|
|
|
* \section bm_structure The Structure
|
|
|
|
*
|
|
|
|
* BMesh stores topology in four main element structures:
|
|
|
|
*
|
|
|
|
* - Faces - BMFace
|
2023-01-10 20:49:51 +01:00
|
|
|
* - Loops - BMLoop, (stores per-face-vertex data, UVs, vertex-colors, etc)
|
2012-02-27 21:27:19 +01:00
|
|
|
* - Edges - BMEdge
|
|
|
|
* - Verts - BMVert
|
|
|
|
* \subsection bm_header_flags Header Flags
|
2019-04-29 14:04:24 +02:00
|
|
|
* Each element (vertex/edge/face/loop)
|
|
|
|
* in a mesh has an associated bit-field called "header flags".
|
2012-02-27 21:27:19 +01:00
|
|
|
*
|
2013-09-08 08:55:58 +02:00
|
|
|
* BMHeader flags should **never** be read or written to by bmesh operators (see Operators below).
|
2012-02-27 21:27:19 +01:00
|
|
|
*
|
2021-07-20 14:52:31 +02:00
|
|
|
* Access to header flags is done with `BM_elem_flag_*()` functions.
|
2012-02-27 21:27:19 +01: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 06:45:42 +02:00
|
|
|
* (among other things outlined later in this document), and define the face boundary.
|
2012-02-27 21:27:19 +01:00
|
|
|
* \subsection bm_loop The Loop
|
|
|
|
*
|
2015-09-17 23:39:56 +02:00
|
|
|
* Loops can be thought of as a *face-corner*, since faces don't reference verts or edges directly.
|
2014-09-27 08:31:40 +02: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 21:27:19 +01:00
|
|
|
*
|
2015-09-17 23:39:56 +02: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 21:27:19 +01:00
|
|
|
*
|
|
|
|
* - BMLoop#v - pointer to the vertex associated with this loop.
|
2013-09-08 08:55:58 +02:00
|
|
|
* - BMLoop#e - pointer to the edge associated with this loop,
|
2021-07-20 14:52:31 +02:00
|
|
|
* between verts `(loop->v, loop->next->v)`
|
2012-02-27 21:27:19 +01: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 04:36:14 +02:00
|
|
|
* Edges and Vertices in BMesh are primitive structures.
|
2012-02-27 21:27:19 +01:00
|
|
|
*
|
2015-08-01 04:36:14 +02: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 04:36:14 +02:00
|
|
|
* So it should only occur temporarily during editing operations.
|
2012-02-27 21:27:19 +01: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 21:27:19 +01:00
|
|
|
* \section bm_api The BMesh API
|
|
|
|
*
|
2019-04-29 14:04:24 +02:00
|
|
|
* One of the goals of the BMesh API is to make it easy
|
|
|
|
* and natural to produce highly maintainable code.
|
2012-02-27 21:27:19 +01: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 14:59:02 +02: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 21:27:19 +01: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 14:04:24 +02:00
|
|
|
* there are additional functions you can use for topological iteration,
|
|
|
|
* but their meant for internal bmesh code.
|
2012-02-27 21:27:19 +01:00
|
|
|
*
|
2019-04-29 14:04:24 +02:00
|
|
|
* Note that the walker API supports delimiter flags,
|
|
|
|
* to allow the caller to flag elements not to walk past.
|
2012-02-27 21:27:19 +01:00
|
|
|
* \subsection bm_ops Operators
|
|
|
|
*
|
|
|
|
* Operators are an integral part of BMesh. Unlike regular blender operators,
|
2023-03-27 03:08:14 +02:00
|
|
|
* BMesh operators (abbreviated to `bmo`) are designed to be nested (e.g. call other operators).
|
2012-02-27 21:27:19 +01:00
|
|
|
*
|
2019-04-29 14:04:24 +02: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 21:27:19 +01:00
|
|
|
* (and allows for chaining operators together).
|
|
|
|
*
|
|
|
|
* These slots are identified by name, using strings.
|
|
|
|
*
|
2021-07-20 14:52:31 +02:00
|
|
|
* Access to slots is done with `BMO_slot_***()` functions.
|
2012-02-27 21:27:19 +01:00
|
|
|
* \subsection bm_tool_flags Tool Flags
|
|
|
|
*
|
2019-04-29 14:04:24 +02:00
|
|
|
* The BMesh API provides a set of flags for faces, edges and vertices,
|
|
|
|
* which are private to an operator.
|
2012-02-27 21:27:19 +01: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).
|
|
|
|
*
|
2021-07-20 14:52:31 +02:00
|
|
|
* Access to tool flags is done with `BMO_elem_flag_***()` functions.
|
2012-02-27 21:27:19 +01:00
|
|
|
*
|
2013-09-08 08:55:58 +02:00
|
|
|
* \warning Operators are **never** allowed to read or write to header flags.
|
2012-02-27 21:27:19 +01: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 14:59:02 +02:00
|
|
|
* - pointer - #BMO_OP_SLOT_PTR
|
2013-09-08 08:55:58 +02: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 21:27:19 +01:00
|
|
|
* \subsection bm_slot_iter Slot Iterators
|
|
|
|
*
|
2019-04-29 14:04:24 +02:00
|
|
|
* Access to element buffers or maps must go through the slot iterator api,
|
|
|
|
* defined in bmesh_operators.h.
|
2012-02-27 21:27:19 +01: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 14:04:24 +02:00
|
|
|
* \note Element buffers may have elements of different types within the same buffer
|
|
|
|
* (this is supported by the API.
|
2012-02-28 20:10:53 +01:00
|
|
|
* \section bm_fname Function Naming Conventions
|
|
|
|
*
|
|
|
|
* These conventions should be used throughout the bmesh module.
|
|
|
|
*
|
2022-09-16 10:13:19 +02:00
|
|
|
* - `bmesh_kernel_*()` - Low level API, for primitive functions that others are built on top of.
|
2021-07-20 14:52:31 +02:00
|
|
|
* - `bmesh_***()` - Low level API function.
|
|
|
|
* - `bm_***()` - 'static' functions, not a part of the API at all,
|
2019-04-29 14:04:24 +02:00
|
|
|
* but use prefix since they operate on BMesh data.
|
2021-07-20 14:52:31 +02:00
|
|
|
* - `BM_***()` - High level BMesh API function for use anywhere.
|
|
|
|
* - `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 20:10:53 +01:00
|
|
|
*
|
2012-04-26 10:27:50 +02: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 14:04:24 +02: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 19:31:04 +01:00
|
|
|
*/
|
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_customdata.hh"
|
2012-03-24 02:24:58 +01: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 19:31:04 +01:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-02-19 19:31:04 +01:00
|
|
|
|
|
|
|
#include "bmesh_class.h"
|
|
|
|
|
|
|
|
/* include the rest of the API */
|
2012-03-21 13:08:16 +01:00
|
|
|
#include "intern/bmesh_error.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "intern/bmesh_operator_api.h"
|
2012-02-28 17:47:12 +01:00
|
|
|
|
2014-11-01 23:31:01 +01:00
|
|
|
#include "intern/bmesh_callback_generic.h"
|
2013-08-21 09:51:47 +02:00
|
|
|
#include "intern/bmesh_construct.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "intern/bmesh_core.h"
|
2014-01-16 23:21:30 +01:00
|
|
|
#include "intern/bmesh_delete.h"
|
2013-05-11 16:40:03 +02:00
|
|
|
#include "intern/bmesh_edgeloop.h"
|
2012-02-28 17:47:12 +01:00
|
|
|
#include "intern/bmesh_interp.h"
|
|
|
|
#include "intern/bmesh_iterators.h"
|
2012-12-30 19:24:08 +01:00
|
|
|
#include "intern/bmesh_log.h"
|
2012-02-28 17:47:12 +01:00
|
|
|
#include "intern/bmesh_marking.h"
|
2012-02-28 19:28:30 +01:00
|
|
|
#include "intern/bmesh_mesh.h"
|
2020-06-05 10:27:38 +02:00
|
|
|
#include "intern/bmesh_mesh_convert.h"
|
2022-01-19 05:09:48 +01:00
|
|
|
#include "intern/bmesh_mesh_debug.h"
|
2019-10-20 16:47:16 +02:00
|
|
|
#include "intern/bmesh_mesh_duplicate.h"
|
2021-06-07 16:45:54 +02:00
|
|
|
#include "intern/bmesh_mesh_normals.h"
|
2021-05-28 10:18:13 +02:00
|
|
|
#include "intern/bmesh_mesh_partial_update.h"
|
2021-06-01 04:58:52 +02:00
|
|
|
#include "intern/bmesh_mesh_tessellate.h"
|
2012-03-22 06:13:43 +01:00
|
|
|
#include "intern/bmesh_mesh_validate.h"
|
2012-02-28 19:28:30 +01:00
|
|
|
#include "intern/bmesh_mods.h"
|
2012-02-28 17:47:12 +01:00
|
|
|
#include "intern/bmesh_operators.h"
|
2012-02-28 19:28:30 +01:00
|
|
|
#include "intern/bmesh_polygon.h"
|
2015-12-09 06:21:43 +01:00
|
|
|
#include "intern/bmesh_polygon_edgenet.h"
|
2018-06-30 10:29:40 +02:00
|
|
|
#include "intern/bmesh_query.h"
|
2020-07-09 05:33:15 +02:00
|
|
|
#include "intern/bmesh_query_uv.h"
|
2012-02-28 17:47:12 +01:00
|
|
|
#include "intern/bmesh_walkers.h"
|
|
|
|
|
2012-03-24 02:24:58 +01:00
|
|
|
#include "intern/bmesh_inline.h"
|