Cleanup: comments (long lines) in bmesh
This commit is contained in:
@@ -22,7 +22,8 @@
|
||||
*
|
||||
* \addtogroup bmesh BMesh
|
||||
*
|
||||
* \brief BMesh is a non-manifold boundary representation designed to support advanced editing operations.
|
||||
* \brief BMesh is a non-manifold boundary representation
|
||||
* designed to support advanced editing operations.
|
||||
* \section bm_structure The Structure
|
||||
*
|
||||
* BMesh stores topology in four main element structures:
|
||||
@@ -32,7 +33,8 @@
|
||||
* - Edges - BMEdge
|
||||
* - Verts - BMVert
|
||||
* \subsection bm_header_flags Header Flags
|
||||
* Each element (vertex/edge/face/loop) in a mesh has an associated bit-field called "header flags".
|
||||
* Each element (vertex/edge/face/loop)
|
||||
* in a mesh has an associated bit-field called "header flags".
|
||||
*
|
||||
* BMHeader flags should **never** be read or written to by bmesh operators (see Operators below).
|
||||
*
|
||||
@@ -81,7 +83,8 @@
|
||||
* See source/blender/bmesh/bmesh_query.h for more misc. queries.
|
||||
* \section bm_api The BMesh API
|
||||
*
|
||||
* One of the goals of the BMesh API is to make it easy and natural to produce highly maintainable code.
|
||||
* One of the goals of the BMesh API is to make it easy
|
||||
* and natural to produce highly maintainable code.
|
||||
* Code duplication, etc are avoided where possible.
|
||||
* \subsection bm_iter_api Iterator API
|
||||
*
|
||||
@@ -95,15 +98,18 @@
|
||||
* though a mechanism for plugging in new walkers needs to be added at some point.
|
||||
*
|
||||
* Most topological queries should go through these two APIs;
|
||||
* there are additional functions you can use for topological iteration, but their meant for internal bmesh code.
|
||||
* there are additional functions you can use for topological iteration,
|
||||
* but their meant for internal bmesh code.
|
||||
*
|
||||
* Note that the walker API supports delimiter flags, to allow the caller to flag elements not to walk past.
|
||||
* Note that the walker API supports delimiter flags,
|
||||
* to allow the caller to flag elements not to walk past.
|
||||
* \subsection bm_ops Operators
|
||||
*
|
||||
* Operators are an integral part of BMesh. Unlike regular blender operators,
|
||||
* BMesh operators **bmo's** are designed to be nested (e.g. call other operators).
|
||||
*
|
||||
* Each operator has a number of input/output "slots" which are used to pass settings & data into/out of the operator
|
||||
* Each operator has a number of input/output "slots"
|
||||
* which are used to pass settings & data into/out of the operator
|
||||
* (and allows for chaining operators together).
|
||||
*
|
||||
* These slots are identified by name, using strings.
|
||||
@@ -111,7 +117,8 @@
|
||||
* Access to slots is done with ``BMO_slot_***()`` functions.
|
||||
* \subsection bm_tool_flags Tool Flags
|
||||
*
|
||||
* The BMesh API provides a set of flags for faces, edges and vertices, which are private to an operator.
|
||||
* The BMesh API provides a set of flags for faces, edges and vertices,
|
||||
* which are private to an operator.
|
||||
* 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 it's own set of tool flags when it's executed,
|
||||
@@ -140,7 +147,8 @@
|
||||
* - map - BMO_OP_SLOT_MAPPING - simple hash map.
|
||||
* \subsection bm_slot_iter Slot Iterators
|
||||
*
|
||||
* Access to element buffers or maps must go through the slot iterator api, defined in bmesh_operators.h.
|
||||
* Access to element buffers or maps must go through the slot iterator api,
|
||||
* defined in bmesh_operators.h.
|
||||
* Use #BMO_ITER where ever possible.
|
||||
* \subsection bm_elem_buf Element Buffers
|
||||
*
|
||||
@@ -149,14 +157,16 @@
|
||||
* Many operators take in a buffer of elements, process it,
|
||||
* then spit out a new one; this allows operators to be chained together.
|
||||
*
|
||||
* \note Element buffers may have elements of different types within the same buffer (this is supported by the API.
|
||||
* \note Element buffers may have elements of different types within the same buffer
|
||||
* (this is supported by the API.
|
||||
* \section bm_fname Function Naming Conventions
|
||||
*
|
||||
* These conventions should be used throughout the bmesh module.
|
||||
*
|
||||
* - ``bmesh_kernel_*()`` - Low level API, for primitive functions that others are built ontop of.
|
||||
* - ``bmesh_***()`` - Low level API function.
|
||||
* - ``bm_***()`` - 'static' functions, not apart of the API at all, but use prefix since they operate on BMesh data.
|
||||
* - ``bm_***()`` - 'static' functions, not apart of the API at all,
|
||||
* but use prefix since they operate on BMesh data.
|
||||
* - ``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.
|
||||
@@ -168,11 +178,14 @@
|
||||
*
|
||||
* \subsection bm_todo_optimize Optimizations
|
||||
*
|
||||
* - 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.
|
||||
* - 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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
/* bmesh data structures */
|
||||
|
||||
/* dissable holes for now, these are ifdef'd because they use more memory and cant be saved in DNA currently */
|
||||
/* dissable holes for now,
|
||||
* these are ifdef'd because they use more memory and cant be saved in DNA currently */
|
||||
// #define USE_BMESH_HOLES
|
||||
|
||||
struct BMEdge;
|
||||
@@ -98,10 +99,12 @@ typedef struct BMVert {
|
||||
float co[3]; /* vertex coordinates */
|
||||
float no[3]; /* vertex normal */
|
||||
|
||||
/* pointer to (any) edge using this vertex (for disk cycles)
|
||||
/**
|
||||
* Pointer to (any) edge using this vertex (for disk cycles).
|
||||
*
|
||||
* note: some higher level functions set this to different edges that use this vertex,
|
||||
* which is a bit of an abuse of internal bmesh data but also works OK for now (use with care!).
|
||||
* \note Some higher level functions set this to different edges that use this vertex,
|
||||
* which is a bit of an abuse of internal bmesh data but also works OK for now
|
||||
* (use with care!).
|
||||
*/
|
||||
struct BMEdge *e;
|
||||
} BMVert;
|
||||
@@ -125,8 +128,12 @@ typedef struct BMEdge {
|
||||
* to access the other loops using the edge */
|
||||
struct BMLoop *l;
|
||||
|
||||
/* disk cycle pointers
|
||||
* relative data: d1 indicates indicates the next/prev edge around vertex v1 and d2 does the same for v2 */
|
||||
/**
|
||||
* Disk Cycle Pointers
|
||||
*
|
||||
* relative data: d1 indicates indicates the next/prev
|
||||
* edge around vertex v1 and d2 does the same for v2.
|
||||
*/
|
||||
BMDiskLink v1_disk_link, v2_disk_link;
|
||||
} BMEdge;
|
||||
|
||||
@@ -281,7 +288,10 @@ typedef struct BMLoopNorEditData {
|
||||
|
||||
typedef struct BMLoopNorEditDataArray {
|
||||
BMLoopNorEditData *lnor_editdata;
|
||||
/* This one has full amount of loops, used to map loop index to actual BMLoopNorEditData struct. */
|
||||
/**
|
||||
* This one has full amount of loops,
|
||||
* used to map loop index to actual BMLoopNorEditData struct.
|
||||
*/
|
||||
BMLoopNorEditData **lidx_to_lnor_editdata;
|
||||
|
||||
int cd_custom_normal_offset;
|
||||
|
||||
@@ -124,7 +124,8 @@ BMFace *BM_face_create_quad_tri(BMesh *bm,
|
||||
/**
|
||||
* \brief copies face loop data from shared adjacent faces.
|
||||
*
|
||||
* \param filter_fn: A function that filters the source loops before copying (don't always want to copy all)
|
||||
* \param filter_fn: A function that filters the source loops before copying
|
||||
* (don't always want to copy all).
|
||||
*
|
||||
* \note when a matching edge is found, both loops of that edge are copied
|
||||
* this is done since the face may not be completely surrounded by faces,
|
||||
|
||||
@@ -140,7 +140,8 @@ BMVert *BM_vert_create(BMesh *bm,
|
||||
* \brief Main function for creating a new edge.
|
||||
*
|
||||
* \note Duplicate edges are supported by the API however users should _never_ see them.
|
||||
* so unless you need a unique edge or know the edge won't exist, you should call with \a no_double = true
|
||||
* so unless you need a unique edge or know the edge won't exist,
|
||||
* you should call with \a no_double = true.
|
||||
*/
|
||||
BMEdge *BM_edge_create(
|
||||
BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *e_example, const eBMCreateFlag create_flag)
|
||||
@@ -1417,8 +1418,9 @@ static BMFace *bm_face_create__sfme(BMesh *bm, BMFace *f_example)
|
||||
*
|
||||
* \warning this is a low level function, most likely you want to use #BM_face_split()
|
||||
*
|
||||
* Takes as input two vertices in a single face. An edge is created which divides the original face
|
||||
* into two distinct regions. One of the regions is assigned to the original face and it is closed off.
|
||||
* Takes as input two vertices in a single face.
|
||||
* An edge is created which divides the original face into two distinct regions.
|
||||
* One of the regions is assigned to the original face and it is closed off.
|
||||
* The second region has a new face assigned to it.
|
||||
*
|
||||
* \par Examples:
|
||||
@@ -1944,7 +1946,8 @@ BMEdge *bmesh_kernel_join_edge_kill_vert(BMesh *bm,
|
||||
*
|
||||
* Collapse an edge, merging surrounding data.
|
||||
*
|
||||
* Unlike #BM_vert_collapse_edge & #bmesh_kernel_join_edge_kill_vert which only handle 2 valence verts,
|
||||
* Unlike #BM_vert_collapse_edge & #bmesh_kernel_join_edge_kill_vert
|
||||
* which only handle 2 valence verts,
|
||||
* this can handle any number of connected edges/faces.
|
||||
*
|
||||
* <pre>
|
||||
@@ -2065,8 +2068,8 @@ BMVert *bmesh_kernel_join_vert_kill_edge(BMesh *bm,
|
||||
* before attempting to fuse \a f1 and \a f2.
|
||||
*
|
||||
* \note The order of arguments decides whether or not certain per-face attributes are present
|
||||
* in the resultant face. For instance vertex winding, material index, smooth flags, etc are inherited
|
||||
* from \a f1, not \a f2.
|
||||
* in the resultant face. For instance vertex winding, material index, smooth flags,
|
||||
* etc are inherited from \a f1, not \a f2.
|
||||
*
|
||||
* \return A BMFace pointer
|
||||
*/
|
||||
@@ -2413,7 +2416,8 @@ void bmesh_kernel_vert_separate(
|
||||
*
|
||||
* Takes a list of edges, which have been split from their original.
|
||||
*
|
||||
* Any edges which failed to split off in #bmesh_kernel_vert_separate will be merged back into the original edge.
|
||||
* Any edges which failed to split off in #bmesh_kernel_vert_separate
|
||||
* will be merged back into the original edge.
|
||||
*
|
||||
* \param edges_separate:
|
||||
* A list-of-lists, each list is from a single original edge (the first edge is the original),
|
||||
|
||||
@@ -264,7 +264,9 @@ static bool bm_loop_path_build_step(BLI_mempool *vs_pool,
|
||||
|
||||
BLI_mempool_free(vs_pool, vs);
|
||||
}
|
||||
/* bm->elem_index_dirty |= BM_VERT; */ /* Commented because used in a loop, and this flag has already been set. */
|
||||
|
||||
/* Commented because used in a loop, and this flag has already been set. */
|
||||
/* bm->elem_index_dirty |= BM_VERT; */
|
||||
|
||||
/* lb is now full of free'd items, overwrite */
|
||||
*lb = lb_tmp;
|
||||
|
||||
@@ -174,7 +174,8 @@ ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) BLI_INLINE
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Parallel (threaded) iterator, only available for most basic itertypes (verts/edges/faces of mesh).
|
||||
* \brief Parallel (threaded) iterator,
|
||||
* only available for most basic itertypes (verts/edges/faces of mesh).
|
||||
*
|
||||
* Uses BLI_task_parallel_mempool to iterate over all items of underlying matching mempool.
|
||||
*
|
||||
|
||||
@@ -1231,7 +1231,8 @@ void BM_mesh_elem_hflag_enable_test(BMesh *bm,
|
||||
|
||||
/* note, better not attempt a fast path for selection as done with de-select
|
||||
* because hidden geometry and different selection modes can give different results,
|
||||
* we could of course check for no hidden faces and then use quicker method but its not worth it. */
|
||||
* we could of course check for no hidden faces and then use
|
||||
* quicker method but its not worth it. */
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (htype & flag_types[i]) {
|
||||
|
||||
@@ -321,7 +321,8 @@ void BM_mesh_free(BMesh *bm)
|
||||
* Helpers for #BM_mesh_normals_update and #BM_verts_calc_normal_vcos
|
||||
*/
|
||||
|
||||
/* We use that existing internal API flag, assuming no other tool using it would run concurrently to clnors editing. */
|
||||
/* We use that existing internal API flag,
|
||||
* assuming no other tool using it would run concurrently to clnors editing. */
|
||||
#define BM_LNORSPACE_UPDATE _FLAG_MF
|
||||
|
||||
typedef struct BMEdgesCalcVectorsData {
|
||||
@@ -433,7 +434,8 @@ static void mesh_verts_calc_normals_accum_cb(void *userdata, MempoolIterData *mp
|
||||
virtual_lock += f_no[0] * fac;
|
||||
v_no[1] += f_no[1] * fac;
|
||||
v_no[2] += f_no[2] * fac;
|
||||
/* Second atomic operation to 'release' our lock on that vector and set its first scalar value. */
|
||||
/* Second atomic operation to 'release'
|
||||
* our lock on that vector and set its first scalar value. */
|
||||
/* Note that we do not need to loop here, since we 'locked' v_no[0],
|
||||
* nobody should have changed it in the mean time. */
|
||||
virtual_lock = atomic_cas_float(&v_no[0], FLT_MAX, virtual_lock);
|
||||
@@ -529,7 +531,8 @@ void BM_mesh_normals_update(BMesh *bm)
|
||||
/**
|
||||
* \brief BMesh Compute Normals from/to external data.
|
||||
*
|
||||
* Computes the vertex normals of a mesh into vnos, using given vertex coordinates (vcos) and polygon normals (fnos).
|
||||
* Computes the vertex normals of a mesh into vnos,
|
||||
* using given vertex coordinates (vcos) and polygon normals (fnos).
|
||||
*/
|
||||
void BM_verts_calc_normal_vcos(BMesh *bm,
|
||||
const float (*fnos)[3],
|
||||
@@ -573,9 +576,8 @@ static void bm_mesh_edges_sharp_tag(BMesh *bm,
|
||||
BM_mesh_elem_index_ensure(bm, htype);
|
||||
}
|
||||
|
||||
/* This first loop checks which edges are actually smooth, and pre-populate lnos with vnos (as if they were
|
||||
* all smooth).
|
||||
*/
|
||||
/* This first loop checks which edges are actually smooth,
|
||||
* and pre-populate lnos with vnos (as if they were all smooth). */
|
||||
BM_ITER_MESH_INDEX (e, &eiter, bm, BM_EDGES_OF_MESH, i) {
|
||||
BMLoop *l_a, *l_b;
|
||||
|
||||
@@ -613,7 +615,8 @@ static void bm_mesh_edges_sharp_tag(BMesh *bm,
|
||||
}
|
||||
}
|
||||
else if (do_sharp_edges_tag) {
|
||||
/* Note that we do not care about the other sharp-edge cases (sharp poly, non-manifold edge, etc.),
|
||||
/* Note that we do not care about the other sharp-edge cases
|
||||
* (sharp poly, non-manifold edge, etc.),
|
||||
* only tag edge as sharp when it is due to angle threashold. */
|
||||
BM_elem_flag_disable(e, BM_ELEM_SMOOTH);
|
||||
}
|
||||
@@ -626,7 +629,8 @@ static void bm_mesh_edges_sharp_tag(BMesh *bm,
|
||||
|
||||
/**
|
||||
* Check whether given loop is part of an unknown-so-far cyclic smooth fan, or not.
|
||||
* Needed because cyclic smooth fans have no obvious 'entry point', and yet we need to walk them once, and only once.
|
||||
* Needed because cyclic smooth fans have no obvious 'entry point',
|
||||
* and yet we need to walk them once, and only once.
|
||||
*/
|
||||
bool BM_loop_check_cyclic_smooth_fan(BMLoop *l_curr)
|
||||
{
|
||||
@@ -647,8 +651,9 @@ bool BM_loop_check_cyclic_smooth_fan(BMLoop *l_curr)
|
||||
/* Smooth loop/edge... */
|
||||
else if (BM_elem_flag_test(lfan_pivot_next, BM_ELEM_TAG)) {
|
||||
if (lfan_pivot_next == l_curr) {
|
||||
/* We walked around a whole cyclic smooth fan without finding any already-processed loop, means we can
|
||||
* use initial l_curr/l_prev edge as start for this smooth fan. */
|
||||
/* We walked around a whole cyclic smooth fan
|
||||
* without finding any already-processed loop,
|
||||
* means we can use initial l_curr/l_prev edge as start for this smooth fan. */
|
||||
return true;
|
||||
}
|
||||
/* ... already checked in some previous looping, we can abort. */
|
||||
@@ -661,8 +666,11 @@ bool BM_loop_check_cyclic_smooth_fan(BMLoop *l_curr)
|
||||
}
|
||||
}
|
||||
|
||||
/* BMesh version of BKE_mesh_normals_loop_split() in mesh_evaluate.c
|
||||
* Will use first clnors_data array, and fallback to cd_loop_clnors_offset (use NULL and -1 to not use clnors). */
|
||||
/**
|
||||
* BMesh version of BKE_mesh_normals_loop_split() in mesh_evaluate.c
|
||||
* Will use first clnors_data array, and fallback to cd_loop_clnors_offset
|
||||
* (use NULL and -1 to not use clnors).
|
||||
*/
|
||||
static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
const float (*vcos)[3],
|
||||
const float (*fnos)[3],
|
||||
@@ -718,7 +726,8 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
}
|
||||
bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP);
|
||||
|
||||
/* We now know edges that can be smoothed (they are tagged), and edges that will be hard (they aren't).
|
||||
/* We now know edges that can be smoothed (they are tagged),
|
||||
* and edges that will be hard (they aren't).
|
||||
* Now, time to generate the normals.
|
||||
*/
|
||||
BM_ITER_MESH (f_curr, &fiter, bm, BM_FACES_OF_MESH) {
|
||||
@@ -731,12 +740,15 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
continue;
|
||||
}
|
||||
/* A smooth edge, we have to check for cyclic smooth fan case.
|
||||
* If we find a new, never-processed cyclic smooth fan, we can do it now using that loop/edge as
|
||||
* 'entry point', otherwise we can skip it. */
|
||||
/* Note: In theory, we could make bm_mesh_loop_check_cyclic_smooth_fan() store mlfan_pivot's in a stack,
|
||||
* to avoid having to fan again around the vert during actual computation of clnor & clnorspace.
|
||||
* However, this would complicate the code, add more memory usage, and BM_vert_step_fan_loop()
|
||||
* is quite cheap in term of CPU cycles, so really think it's not worth it. */
|
||||
* If we find a new, never-processed cyclic smooth fan, we can do it now using that loop/edge
|
||||
* as 'entry point', otherwise we can skip it. */
|
||||
|
||||
/* Note: In theory, we could make bm_mesh_loop_check_cyclic_smooth_fan() store
|
||||
* mlfan_pivot's in a stack, to avoid having to fan again around
|
||||
* the vert during actual computation of clnor & clnorspace. However, this would complicate
|
||||
* the code, add more memory usage, and
|
||||
* BM_vert_step_fan_loop() is quite cheap in term of CPU cycles,
|
||||
* so really think it's not worth it. */
|
||||
if (BM_elem_flag_test(l_curr->e, BM_ELEM_TAG) &&
|
||||
(BM_elem_flag_test(l_curr, BM_ELEM_TAG) || !BM_loop_check_cyclic_smooth_fan(l_curr))) {
|
||||
}
|
||||
@@ -769,7 +781,8 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
}
|
||||
|
||||
BKE_lnor_space_define(lnor_space, r_lnos[l_curr_index], vec_curr, vec_prev, NULL);
|
||||
/* We know there is only one loop in this space, no need to create a linklist in this case... */
|
||||
/* We know there is only one loop in this space,
|
||||
* no need to create a linklist in this case... */
|
||||
BKE_lnor_space_add_loop(r_lnors_spacearr, lnor_space, l_curr_index, l_curr, true);
|
||||
|
||||
if (has_clnors) {
|
||||
@@ -780,20 +793,22 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
}
|
||||
}
|
||||
/* We *do not need* to check/tag loops as already computed!
|
||||
* Due to the fact a loop only links to one of its two edges, a same fan *will never be walked more than
|
||||
* once!*
|
||||
* Since we consider edges having neighbor faces with inverted (flipped) normals as sharp, we are sure that
|
||||
* no fan will be skipped, even only considering the case (sharp curr_edge, smooth prev_edge), and not the
|
||||
* alternative (smooth curr_edge, sharp prev_edge).
|
||||
* Due to the fact a loop only links to one of its two edges,
|
||||
* a same fan *will never be walked more than once!*
|
||||
* Since we consider edges having neighbor faces with inverted (flipped) normals as sharp,
|
||||
* we are sure that no fan will be skipped, even only considering the case
|
||||
* (sharp curr_edge, smooth prev_edge), and not the alternative
|
||||
* (smooth curr_edge, sharp prev_edge).
|
||||
* All this due/thanks to link between normals and loop ordering.
|
||||
*/
|
||||
else {
|
||||
/* We have to fan around current vertex, until we find the other non-smooth edge,
|
||||
* and accumulate face normals into the vertex!
|
||||
* Note in case this vertex has only one sharp edge, this is a waste because the normal is the same as
|
||||
* the vertex normal, but I do not see any easy way to detect that (would need to count number
|
||||
* of sharp edges per vertex, I doubt the additional memory usage would be worth it, especially as
|
||||
* it should not be a common case in real-life meshes anyway).
|
||||
* Note in case this vertex has only one sharp edge,
|
||||
* this is a waste because the normal is the same as the vertex normal,
|
||||
* but I do not see any easy way to detect that (would need to count number of sharp edges
|
||||
* per vertex, I doubt the additional memory usage would be worth it, especially as it
|
||||
* should not be a common case in real-life meshes anyway).
|
||||
*/
|
||||
BMVert *v_pivot = l_curr->v;
|
||||
BMEdge *e_next;
|
||||
@@ -820,7 +835,8 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
lfan_pivot_index = BM_elem_index_get(lfan_pivot);
|
||||
e_next = lfan_pivot->e; /* Current edge here, actually! */
|
||||
|
||||
/* Only need to compute previous edge's vector once, then we can just reuse old current one! */
|
||||
/* Only need to compute previous edge's vector once,
|
||||
* then we can just reuse old current one! */
|
||||
{
|
||||
const BMVert *v_2 = BM_edge_other_vert(e_next, v_pivot);
|
||||
const float *co_2 = vcos ? vcos[BM_elem_index_get(v_2)] : v_2->co;
|
||||
@@ -846,9 +862,10 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
}
|
||||
|
||||
/* Compute edge vector.
|
||||
* NOTE: We could pre-compute those into an array, in the first iteration, instead of computing them
|
||||
* twice (or more) here. However, time gained is not worth memory and time lost,
|
||||
* given the fact that this code should not be called that much in real-life meshes...
|
||||
* NOTE: We could pre-compute those into an array, in the first iteration,
|
||||
* instead of computing them twice (or more) here.
|
||||
* However, time gained is not worth memory and time lost,
|
||||
* given the fact that this code should not be called that much in real-life meshes.
|
||||
*/
|
||||
{
|
||||
const BMVert *v_2 = BM_edge_other_vert(e_next, v_pivot);
|
||||
@@ -970,7 +987,8 @@ static void bm_mesh_loops_calc_normals(BMesh *bm,
|
||||
}
|
||||
}
|
||||
|
||||
/* Tag related vertex as sharp, to avoid fanning around it again (in case it was a smooth one). */
|
||||
/* Tag related vertex as sharp, to avoid fanning around it again
|
||||
* (in case it was a smooth one). */
|
||||
if (r_lnors_spacearr) {
|
||||
BM_elem_flag_enable(l_curr->v, BM_ELEM_TAG);
|
||||
}
|
||||
@@ -1023,8 +1041,8 @@ static void bm_mesh_loops_calc_normals_no_autosmooth(BMesh *bm,
|
||||
/**
|
||||
* \brief BMesh Compute Loop Normals
|
||||
*
|
||||
* Updates the loop normals of a mesh. Assumes vertex and face normals are valid (else call BM_mesh_normals_update()
|
||||
* first)!
|
||||
* Updates the loop normals of a mesh.
|
||||
* Assumes vertex and face normals are valid (else call BM_mesh_normals_update() first)!
|
||||
*/
|
||||
void BM_mesh_loop_normals_update(BMesh *bm,
|
||||
const bool use_split_normals,
|
||||
@@ -1041,7 +1059,8 @@ void BM_mesh_loop_normals_update(BMesh *bm,
|
||||
* When using custom loop normals, disable the angle feature! */
|
||||
bm_mesh_edges_sharp_tag(bm, NULL, NULL, has_clnors ? (float)M_PI : split_angle, r_lnos);
|
||||
|
||||
/* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */
|
||||
/* Finish computing lnos by accumulating face normals
|
||||
* in each fan of faces defined by sharp edges. */
|
||||
bm_mesh_loops_calc_normals(
|
||||
bm, NULL, NULL, r_lnos, r_lnors_spacearr, clnors_data, cd_loop_clnors_offset);
|
||||
}
|
||||
@@ -1056,7 +1075,8 @@ void BM_mesh_loop_normals_update(BMesh *bm,
|
||||
* \brief BMesh Compute Loop Normals from/to external data.
|
||||
*
|
||||
* Compute split normals, i.e. vertex normals associated with each poly (hence 'loop normals').
|
||||
* Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry (splitting edges).
|
||||
* Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry
|
||||
* (splitting edges).
|
||||
*/
|
||||
void BM_loops_calc_normal_vcos(BMesh *bm,
|
||||
const float (*vcos)[3],
|
||||
@@ -1077,7 +1097,8 @@ void BM_loops_calc_normal_vcos(BMesh *bm,
|
||||
* When using custom loop normals, disable the angle feature! */
|
||||
bm_mesh_edges_sharp_tag(bm, vnos, fnos, r_lnos, has_clnors ? (float)M_PI : split_angle, false);
|
||||
|
||||
/* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */
|
||||
/* Finish computing lnos by accumulating face normals
|
||||
* in each fan of faces defined by sharp edges. */
|
||||
bm_mesh_loops_calc_normals(
|
||||
bm, vcos, fnos, r_lnos, r_lnors_spacearr, clnors_data, cd_loop_clnors_offset, do_rebuild);
|
||||
}
|
||||
@@ -1089,7 +1110,8 @@ void BM_loops_calc_normal_vcos(BMesh *bm,
|
||||
|
||||
/** Define sharp edges as needed to mimic 'autosmooth' from angle threshold.
|
||||
*
|
||||
* Used when defining an empty custom loop normals data layer, to keep same shading as with autosmooth!
|
||||
* Used when defining an empty custom loop normals data layer,
|
||||
* to keep same shading as with autosmooth!
|
||||
*/
|
||||
void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle)
|
||||
{
|
||||
@@ -1144,7 +1166,8 @@ void BM_lnorspace_invalidate(BMesh *bm, const bool do_invalidate_all)
|
||||
BMVert *v;
|
||||
BMLoop *l;
|
||||
BMIter viter, liter;
|
||||
/* Note: we could use temp tag of BMItem for that, but probably better not use it in such a low-level func?
|
||||
/* Note: we could use temp tag of BMItem for that,
|
||||
* but probably better not use it in such a low-level func?
|
||||
* --mont29 */
|
||||
BLI_bitmap *done_verts = BLI_BITMAP_NEW(bm->totvert, __func__);
|
||||
|
||||
@@ -1414,13 +1437,15 @@ static int bm_loop_normal_mark_indiv(BMesh *bm, BLI_bitmap *loops)
|
||||
|
||||
if (use_sel_face_history) {
|
||||
/* Using face history allows to select a single loop from a single face...
|
||||
* Note that this is On² piece of code, but it is not designed to be used with huge selection sets,
|
||||
* Note that this is On² piece of code,
|
||||
* but it is not designed to be used with huge selection sets,
|
||||
* rather with only a few items selected at most.*/
|
||||
printf("using face history selection\n");
|
||||
/* Goes from last selected to the first selected element. */
|
||||
for (ese = bm->selected.last; ese; ese = ese->prev) {
|
||||
if (ese->htype == BM_FACE) {
|
||||
/* If current face is selected, then any verts to be edited must have been selected before it. */
|
||||
/* If current face is selected,
|
||||
* then any verts to be edited must have been selected before it. */
|
||||
for (ese_prev = ese->prev; ese_prev; ese_prev = ese_prev->prev) {
|
||||
if (ese_prev->htype == BM_VERT) {
|
||||
bm_loop_normal_mark_indiv_do_loop(
|
||||
@@ -2078,11 +2103,13 @@ int BM_mesh_elem_count(BMesh *bm, const char htype)
|
||||
*
|
||||
* A NULL array means no changes.
|
||||
*
|
||||
* Note: - Does not mess with indices, just sets elem_index_dirty flag.
|
||||
* - For verts/edges/faces only (as loops must remain "ordered" and "aligned"
|
||||
* on a per-face basis...).
|
||||
* \note
|
||||
* - Does not mess with indices, just sets elem_index_dirty flag.
|
||||
* - For verts/edges/faces only (as loops must remain "ordered" and "aligned"
|
||||
* on a per-face basis...).
|
||||
*
|
||||
* WARNING: Be careful if you keep pointers to affected BM elements, or arrays, when using this func!
|
||||
* \warning Be careful if you keep pointers to affected BM elements,
|
||||
* or arrays, when using this func!
|
||||
*/
|
||||
void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const uint *face_idx)
|
||||
{
|
||||
@@ -2134,7 +2161,10 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const
|
||||
for (i = totvert; i--; new_idx--, ve--, vep--) {
|
||||
BMVert *new_vep = verts_pool[*new_idx];
|
||||
*new_vep = *ve;
|
||||
/* printf("mapping vert from %d to %d (%p/%p to %p)\n", i, *new_idx, *vep, verts_pool[i], new_vep);*/
|
||||
#if 0
|
||||
printf(
|
||||
"mapping vert from %d to %d (%p/%p to %p)\n", i, *new_idx, *vep, verts_pool[i], new_vep);
|
||||
#endif
|
||||
BLI_ghash_insert(vptr_map, *vep, new_vep);
|
||||
if (cd_vert_pyptr != -1) {
|
||||
void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)new_vep), cd_vert_pyptr);
|
||||
@@ -2183,7 +2213,10 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const
|
||||
BMEdge *new_edp = edges_pool[*new_idx];
|
||||
*new_edp = *ed;
|
||||
BLI_ghash_insert(eptr_map, *edp, new_edp);
|
||||
/* printf("mapping edge from %d to %d (%p/%p to %p)\n", i, *new_idx, *edp, edges_pool[i], new_edp);*/
|
||||
#if 0
|
||||
printf(
|
||||
"mapping edge from %d to %d (%p/%p to %p)\n", i, *new_idx, *edp, edges_pool[i], new_edp);
|
||||
#endif
|
||||
if (cd_edge_pyptr != -1) {
|
||||
void **pyptr = BM_ELEM_CD_GET_VOID_P(((BMElem *)new_edp), cd_edge_pyptr);
|
||||
*pyptr = pyptrs[*new_idx];
|
||||
@@ -2258,27 +2291,28 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const
|
||||
}
|
||||
}
|
||||
|
||||
/* Edges' pointers, only vert pointers (as we don't mess with loops!), and - ack! - edge pointers,
|
||||
/* Edges' pointers, only vert pointers (as we don't mess with loops!),
|
||||
* and - ack! - edge pointers,
|
||||
* as we have to handle disklinks... */
|
||||
if (vptr_map || eptr_map) {
|
||||
BM_ITER_MESH (ed, &iter, bm, BM_EDGES_OF_MESH) {
|
||||
if (vptr_map) {
|
||||
/* printf("Edge v1: %p -> %p\n", ed->v1, BLI_ghash_lookup(vptr_map, ed->v1));*/
|
||||
/* printf("Edge v2: %p -> %p\n", ed->v2, BLI_ghash_lookup(vptr_map, ed->v2));*/
|
||||
/* printf("Edge v1: %p -> %p\n", ed->v1, BLI_ghash_lookup(vptr_map, ed->v1));*/
|
||||
/* printf("Edge v2: %p -> %p\n", ed->v2, BLI_ghash_lookup(vptr_map, ed->v2));*/
|
||||
ed->v1 = BLI_ghash_lookup(vptr_map, ed->v1);
|
||||
ed->v2 = BLI_ghash_lookup(vptr_map, ed->v2);
|
||||
BLI_assert(ed->v1);
|
||||
BLI_assert(ed->v2);
|
||||
}
|
||||
if (eptr_map) {
|
||||
/* printf("Edge v1_disk_link prev: %p -> %p\n", ed->v1_disk_link.prev,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v1_disk_link.prev));*/
|
||||
/* printf("Edge v1_disk_link next: %p -> %p\n", ed->v1_disk_link.next,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v1_disk_link.next));*/
|
||||
/* printf("Edge v2_disk_link prev: %p -> %p\n", ed->v2_disk_link.prev,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v2_disk_link.prev));*/
|
||||
/* printf("Edge v2_disk_link next: %p -> %p\n", ed->v2_disk_link.next,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v2_disk_link.next));*/
|
||||
/* printf("Edge v1_disk_link prev: %p -> %p\n", ed->v1_disk_link.prev,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v1_disk_link.prev));*/
|
||||
/* printf("Edge v1_disk_link next: %p -> %p\n", ed->v1_disk_link.next,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v1_disk_link.next));*/
|
||||
/* printf("Edge v2_disk_link prev: %p -> %p\n", ed->v2_disk_link.prev,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v2_disk_link.prev));*/
|
||||
/* printf("Edge v2_disk_link next: %p -> %p\n", ed->v2_disk_link.next,*/
|
||||
/* BLI_ghash_lookup(eptr_map, ed->v2_disk_link.next));*/
|
||||
ed->v1_disk_link.prev = BLI_ghash_lookup(eptr_map, ed->v1_disk_link.prev);
|
||||
ed->v1_disk_link.next = BLI_ghash_lookup(eptr_map, ed->v1_disk_link.next);
|
||||
ed->v2_disk_link.prev = BLI_ghash_lookup(eptr_map, ed->v2_disk_link.prev);
|
||||
@@ -2571,7 +2605,8 @@ void BM_mesh_rebuild(BMesh *bm,
|
||||
#undef REMAP_EDGE
|
||||
|
||||
/* Cleanup, re-use local tables if the current mesh had tables allocated.
|
||||
* could use irrespective but it may use more memory then the caller wants (and not be needed). */
|
||||
* could use irrespective but it may use more memory then the caller wants
|
||||
* (and not be needed). */
|
||||
if (remap & BM_VERT) {
|
||||
if (bm->vtable) {
|
||||
SWAP(BMVert **, vtable_dst, bm->vtable);
|
||||
|
||||
@@ -33,33 +33,41 @@
|
||||
*
|
||||
* - Editmode operations when a shape key-block is active edits only that key-block.
|
||||
* - The first Basis key-block always matches the Mesh verts.
|
||||
* - Changing vertex locations of _any_ Basis will apply offsets to those shape keys using this as their Basis.
|
||||
* - Changing vertex locations of _any_ Basis
|
||||
* will apply offsets to those shape keys using this as their Basis.
|
||||
*
|
||||
* \subsection enter_editmode Entering EditMode - #BM_mesh_bm_from_me
|
||||
*
|
||||
* - the active key-block is used for BMesh vertex locations on entering edit-mode.
|
||||
* So obviously the meshes vertex locations remain unchanged and the shape key its self is not being edited directly.
|
||||
* Simply the #BMVert.co is a initialized from active shape key (when its set).
|
||||
* - all key-blocks are added as CustomData layers (read code for details).
|
||||
* - The active key-block is used for BMesh vertex locations on entering edit-mode.
|
||||
* So obviously the meshes vertex locations remain unchanged and the shape key
|
||||
* its self is not being edited directly.
|
||||
* Simply the #BMVert.co is a initialized from active shape key (when its set).
|
||||
* - All key-blocks are added as CustomData layers (read code for details).
|
||||
*
|
||||
* \subsection exit_editmode Exiting EditMode - #BM_mesh_bm_to_me
|
||||
*
|
||||
* This is where the most confusing code is! Won't attempt to document the details here, for that read the code.
|
||||
* This is where the most confusing code is! Won't attempt to document the details here,
|
||||
* for that read the code.
|
||||
* But basics are as follows.
|
||||
*
|
||||
* - Vertex locations (possibly modified from initial active key-block) are copied directly into #MVert.co
|
||||
* (special confusing note that these may be restored later, when editing the 'Basis', read on).
|
||||
* - if the 'Key' is relative, and the active key-block is the basis for ANY other key-blocks - get an array of offsets
|
||||
* between the new vertex locations and the original shape key (before entering edit-mode),
|
||||
* these offsets get applied later on to inactive key-blocks using the active one (which we are editing) as their Basis.
|
||||
* - Vertex locations (possibly modified from initial active key-block)
|
||||
* are copied directly into #MVert.co
|
||||
* (special confusing note that these may be restored later, when editing the 'Basis', read on).
|
||||
* - if the 'Key' is relative, and the active key-block is the basis for ANY other key-blocks -
|
||||
* get an array of offsets between the new vertex locations and the original shape key
|
||||
* (before entering edit-mode), these offsets get applied later on to inactive key-blocks
|
||||
* using the active one (which we are editing) as their Basis.
|
||||
*
|
||||
* Copying the locations back to the shape keys is quite confusing...
|
||||
* One main area of confusion is that when editing a 'Basis' key-block 'me->key->refkey'
|
||||
* The coords are written into the mesh, from the users perspective the Basis coords are written into the mesh
|
||||
* when exiting edit-mode.
|
||||
* The coords are written into the mesh, from the users perspective the Basis coords are written
|
||||
* into the mesh when exiting edit-mode.
|
||||
*
|
||||
* When _not_ editing the 'Basis', the original vertex locations (stored in the mesh and unchanged during edit-mode),
|
||||
* are copied back into the mesh.
|
||||
* When _not_ editing the 'Basis', the original vertex locations
|
||||
* (stored in the mesh and unchanged during edit-mode), are copied back into the mesh.
|
||||
*
|
||||
* This has the effect from the users POV of leaving the mesh un-touched, and only editing the active shape key-block.
|
||||
* This has the effect from the users POV of leaving the mesh un-touched,
|
||||
* and only editing the active shape key-block.
|
||||
*/
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
@@ -490,7 +498,8 @@ static BMVert **bm_to_mesh_vertex_map(BMesh *bm, int ototvert)
|
||||
const int keyi = BM_ELEM_CD_GET_INT(eve, cd_shape_keyindex_offset);
|
||||
if ((keyi != ORIGINDEX_NONE) && (keyi < ototvert) &&
|
||||
/* not fool-proof, but chances are if we have many verts with the same index,
|
||||
* we will want to use the first one, since the second is more likely to be a duplicate. */
|
||||
* we will want to use the first one,
|
||||
* since the second is more likely to be a duplicate. */
|
||||
(vertMap[keyi] == NULL)) {
|
||||
vertMap[keyi] = eve;
|
||||
}
|
||||
@@ -944,8 +953,9 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
|
||||
if (apply_offset) {
|
||||
add_v3_v3(fp, *ofs_pt++);
|
||||
/* Apply back new coordinates of offsetted shapekeys into BMesh.
|
||||
* Otherwise, in case we call again BM_mesh_bm_to_me on same BMesh, we'll apply diff from previous
|
||||
* call to BM_mesh_bm_to_me, to shapekey values from *original creation of the BMesh*. See T50524. */
|
||||
* Otherwise, in case we call again BM_mesh_bm_to_me on same BMesh,
|
||||
* we'll apply diff from previous call to BM_mesh_bm_to_me,
|
||||
* to shapekey values from *original creation of the BMesh*. See T50524. */
|
||||
copy_v3_v3(BM_ELEM_CD_GET_VOID_P(eve, cd_shape_offset), fp);
|
||||
}
|
||||
|
||||
@@ -977,8 +987,10 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
|
||||
}
|
||||
|
||||
/**
|
||||
* A version of #BM_mesh_bm_to_me intended for getting the mesh to pass to the modifier stack for evaluation,
|
||||
* instad of mode switching (where we make sure all data is kept and do expensive lookups to maintain shape keys).
|
||||
* A version of #BM_mesh_bm_to_me intended for getting the mesh
|
||||
* to pass to the modifier stack for evaluation,
|
||||
* instad of mode switching (where we make sure all data is kept
|
||||
* and do expensive lookups to maintain shape keys).
|
||||
*
|
||||
* Key differences:
|
||||
*
|
||||
|
||||
@@ -51,7 +51,8 @@
|
||||
# endif
|
||||
|
||||
/**
|
||||
* Check of this BMesh is valid, this function can be slow since its intended to help with debugging.
|
||||
* Check of this BMesh is valid,
|
||||
* this function can be slow since its intended to help with debugging.
|
||||
*
|
||||
* \return true when the mesh is valid.
|
||||
*/
|
||||
|
||||
@@ -322,13 +322,14 @@ BMFace *BM_face_split(BMesh *bm,
|
||||
*
|
||||
* Like BM_face_split, but with an edge split by \a n intermediate points with given coordinates.
|
||||
*
|
||||
* \param bm: The bmesh
|
||||
* \param f: the original face
|
||||
* \param l_a, l_b: Vertices which define the split edge, must be different
|
||||
* \param cos: Array of coordinates for intermediate points
|
||||
* \param n: Length of \a cos (must be > 0)
|
||||
* \param r_l: pointer which will receive the BMLoop for the first split edge (from \a l_a) in the new face
|
||||
* \param example: Edge used for attributes of splitting edge, if non-NULL
|
||||
* \param bm: The bmesh.
|
||||
* \param f: the original face.
|
||||
* \param l_a, l_b: Vertices which define the split edge, must be different.
|
||||
* \param cos: Array of coordinates for intermediate points.
|
||||
* \param n: Length of \a cos (must be > 0).
|
||||
* \param r_l: pointer which will receive the BMLoop.
|
||||
* for the first split edge (from \a l_a) in the new face.
|
||||
* \param example: Edge used for attributes of splitting edge, if non-NULL.
|
||||
*
|
||||
* \return Pointer to the newly created face representing one side of the split
|
||||
* if the split is successful (and the original original face will be the
|
||||
@@ -370,7 +371,8 @@ BMFace *BM_face_split_n(BMesh *bm,
|
||||
#else
|
||||
f_new = bmesh_kernel_split_face_make_edge(bm, f, l_a, l_b, &l_new, example, false);
|
||||
#endif
|
||||
/* bmesh_kernel_split_face_make_edge returns in 'l_new' a Loop for f_new going from 'v_a' to 'v_b'.
|
||||
/* bmesh_kernel_split_face_make_edge returns in 'l_new'
|
||||
* a Loop for f_new going from 'v_a' to 'v_b'.
|
||||
* The radial_next is for 'f' and goes from 'v_b' to 'v_a' */
|
||||
|
||||
if (f_new) {
|
||||
@@ -378,7 +380,8 @@ BMFace *BM_face_split_n(BMesh *bm,
|
||||
for (i = 0; i < n; i++) {
|
||||
v_new = bmesh_kernel_split_edge_make_vert(bm, v_b, e, &e_new);
|
||||
BLI_assert(v_new != NULL);
|
||||
/* bmesh_kernel_split_edge_make_vert returns in 'e_new' the edge going from 'v_new' to 'v_b' */
|
||||
/* bmesh_kernel_split_edge_make_vert returns in 'e_new'
|
||||
* the edge going from 'v_new' to 'v_b'. */
|
||||
copy_v3_v3(v_new->co, cos[i]);
|
||||
|
||||
/* interpolate the loop data for the loops with (v == v_new), using orig face */
|
||||
|
||||
@@ -121,7 +121,8 @@ static void bm_face_calc_poly_center_median_vertex_cos(const BMFace *f,
|
||||
/**
|
||||
* For tools that insist on using triangles, ideally we would cache this data.
|
||||
*
|
||||
* \param use_fixed_quad: When true, always split quad along (0 -> 2) regardless of concave corners,
|
||||
* \param use_fixed_quad: When true,
|
||||
* always split quad along (0 -> 2) regardless of concave corners,
|
||||
* (as done in #BM_mesh_calc_tessellation).
|
||||
* \param r_loops: Store face loop pointers, (f->len)
|
||||
* \param r_index: Store triangle triples, indices into \a r_loops, `((f->len - 2) * 3)`
|
||||
@@ -963,8 +964,8 @@ bool BM_face_point_inside_test(const BMFace *f, const float co[3])
|
||||
* with a length equal to (f->len - 3). It will be filled with the new
|
||||
* triangles (not including the original triangle).
|
||||
*
|
||||
* \param r_faces_double: When newly created faces are duplicates of existing faces, they're added to this list.
|
||||
* Caller must handle de-duplication.
|
||||
* \param r_faces_double: When newly created faces are duplicates of existing faces,
|
||||
* they're added to this list. Caller must handle de-duplication.
|
||||
* This is done because its possible _all_ faces exist already,
|
||||
* and in that case we would have to remove all faces including the one passed,
|
||||
* which causes complications adding/removing faces while looking over them.
|
||||
@@ -1156,8 +1157,8 @@ void BM_face_triangulate(BMesh *bm,
|
||||
l_iter = l_first = l_new;
|
||||
do {
|
||||
BMEdge *e = l_iter->e;
|
||||
/* confusing! if its not a boundary now, we know it will be later
|
||||
* since this will be an edge of one of the new faces which we're in the middle of creating */
|
||||
/* Confusing! if its not a boundary now, we know it will be later since this will be an
|
||||
* edge of one of the new faces which we're in the middle of creating. */
|
||||
bool is_new_edge = (l_iter == l_iter->radial_next);
|
||||
|
||||
if (is_new_edge) {
|
||||
|
||||
@@ -987,8 +987,10 @@ static int bm_face_split_edgenet_find_connection(const struct EdgeGroup_FindConn
|
||||
* Method for finding connection is as follows:
|
||||
*
|
||||
* - Cast a ray along either the positive or negative directions.
|
||||
* - Take the hit-edge, and cast rays to their vertices checking those rays don't intersect a closer edge.
|
||||
* - Keep taking the hit-edge and testing its verts until a vertex is found which isn't blocked by an edge.
|
||||
* - Take the hit-edge, and cast rays to their vertices
|
||||
* checking those rays don't intersect a closer edge.
|
||||
* - Keep taking the hit-edge and testing its verts
|
||||
* until a vertex is found which isn't blocked by an edge.
|
||||
*
|
||||
* \note It's possible none of the verts can be accessed (with self-intersecting lines).
|
||||
* In that case theres no right answer (without subdividing edges),
|
||||
@@ -1146,7 +1148,8 @@ static BMVert *bm_face_split_edgenet_partial_connect(BMesh *bm, BMVert *v_delimi
|
||||
}
|
||||
}
|
||||
|
||||
/* Detect if this is a delimiter by checking if we didn't walk any of edges connected to 'v_delimit' */
|
||||
/* Detect if this is a delimiter
|
||||
* by checking if we didn't walk any of edges connected to 'v_delimit'. */
|
||||
bool is_delimit = false;
|
||||
FOREACH_VERT_EDGE(v_delimit, e_iter, {
|
||||
BMVert *v_step = BM_edge_other_vert(e_iter, v_delimit);
|
||||
@@ -1500,7 +1503,8 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm,
|
||||
|
||||
/* Now create bvh tree
|
||||
*
|
||||
* Note that a large epsilon is used because meshes with dimensions of around 100+ need it. see T52329. */
|
||||
* Note that a large epsilon is used because meshes with dimensions of around 100+ need it.
|
||||
* see T52329. */
|
||||
BVHTree *bvhtree = BLI_bvhtree_new(edge_arr_len, 1e-4f, 8, 8);
|
||||
for (uint i = 0; i < edge_arr_len; i++) {
|
||||
const float e_cos[2][3] = {
|
||||
|
||||
@@ -311,9 +311,11 @@ float BM_loop_point_side_of_edge_test(const BMLoop *l, const float co[3])
|
||||
}
|
||||
|
||||
/**
|
||||
* Given 2 verts, find a face they share that has the lowest angle across these verts and give back both loops.
|
||||
* Given 2 verts,
|
||||
* find a face they share that has the lowest angle across these verts and give back both loops.
|
||||
*
|
||||
* This can be better then #BM_vert_pair_share_face_by_len because concave splits are ranked lowest.
|
||||
* This can be better then #BM_vert_pair_share_face_by_len
|
||||
* because concave splits are ranked lowest.
|
||||
*/
|
||||
BMFace *BM_vert_pair_share_face_by_angle(
|
||||
BMVert *v_a, BMVert *v_b, BMLoop **r_l_a, BMLoop **r_l_b, const bool allow_adjacent)
|
||||
@@ -1410,7 +1412,8 @@ BMLoop *BM_face_edge_share_loop(BMFace *f, BMEdge *e)
|
||||
* BM_face_create_ngon() on an arbitrary array of verts,
|
||||
* though be sure to pick an edge which has a face.
|
||||
*
|
||||
* \note This is in fact quite a simple check, mainly include this function so the intent is more obvious.
|
||||
* \note This is in fact quite a simple check,
|
||||
* mainly include this function so the intent is more obvious.
|
||||
* We know these 2 verts will _always_ make up the loops edge
|
||||
*/
|
||||
void BM_edge_ordered_verts_ex(const BMEdge *edge,
|
||||
@@ -1507,10 +1510,13 @@ float BM_loop_calc_face_angle(const BMLoop *l)
|
||||
*/
|
||||
float BM_loop_calc_face_normal_safe_ex(const BMLoop *l, const float epsilon_sq, float r_normal[3])
|
||||
{
|
||||
/* Note: we cannot use result of normal_tri_v3 here to detect colinear vectors (vertex on a straight line)
|
||||
* from zero value, because it does not normalize both vectors before making crossproduct.
|
||||
* Instead of adding two costly normalize computations, just check ourselves for colinear case. */
|
||||
/* Note: FEPSILON might need some finer tweaking at some point? Seems to be working OK for now though. */
|
||||
/* Note: we cannot use result of normal_tri_v3 here to detect colinear vectors
|
||||
* (vertex on a straight line) from zero value,
|
||||
* because it does not normalize both vectors before making crossproduct.
|
||||
* Instead of adding two costly normalize computations,
|
||||
* just check ourselves for colinear case. */
|
||||
/* Note: FEPSILON might need some finer tweaking at some point?
|
||||
* Seems to be working OK for now though. */
|
||||
float v1[3], v2[3], v_tmp[3];
|
||||
sub_v3_v3v3(v1, l->prev->v->co, l->v->co);
|
||||
sub_v3_v3v3(v2, l->next->v->co, l->v->co);
|
||||
|
||||
@@ -989,8 +989,9 @@ static void *bmw_EdgeLoopWalker_step(BMWalker *walker)
|
||||
|
||||
vert_edge_tot = BM_vert_edge_count_nonwire(v);
|
||||
|
||||
/* typical loopiong over edges in the middle of a mesh */
|
||||
/* however, why use 2 here at all? I guess for internal ngon loops it can be useful. Antony R. */
|
||||
/* Typical loopiong over edges in the middle of a mesh */
|
||||
/* However, why use 2 here at all?
|
||||
* I guess for internal ngon loops it can be useful. Antony R. */
|
||||
if (vert_edge_tot == 4 || vert_edge_tot == 2) {
|
||||
int i_opposite = vert_edge_tot / 2;
|
||||
int i = 0;
|
||||
|
||||
@@ -211,8 +211,11 @@ static void bridge_loop_pair(BMesh *bm,
|
||||
* +--------+ +--------+
|
||||
* </pre>
|
||||
*
|
||||
* When loops are aligned to the direction between the loops values of 'dir_a/b' is degenerate,
|
||||
* in this case compare the original directions (before they were corrected by 'el_dir'), see: T43013
|
||||
* When loops are aligned to the direction between
|
||||
* the loops values of 'dir_a/b' is degenerate,
|
||||
* in this case compare the original directions
|
||||
* (before they were corrected by 'el_dir'),
|
||||
* see: T43013
|
||||
*/
|
||||
test_a = dir_a_orig;
|
||||
test_b = dir_b_orig;
|
||||
|
||||
@@ -43,9 +43,11 @@
|
||||
* - never step over the same element twice (tag elements as #ELE_TOUCHED).
|
||||
* this avoids going into an eternal loop if there are many possible branches (see T45582).
|
||||
* - when running into a branch, create a new #PathLinkState state and add to the heap.
|
||||
* - when the target is reached, finish - since none of the other paths can be shorter then the one just found.
|
||||
* - when the target is reached,
|
||||
* finish - since none of the other paths can be shorter then the one just found.
|
||||
* - if the connection can't be found - fail.
|
||||
* - with the connection found, split all edges tagging verts (or tag verts that sit on the intersection).
|
||||
* - with the connection found, split all edges tagging verts
|
||||
* (or tag verts that sit on the intersection).
|
||||
* - run the standard connect operator.
|
||||
*/
|
||||
|
||||
@@ -520,7 +522,8 @@ static void bm_vert_pair_to_matrix(BMVert *v_pair[2], float r_unit_mat[3][3])
|
||||
project_plane_normalized_v3_v3v3(basis_nor_a, v_pair[0]->no, basis_dir);
|
||||
project_plane_normalized_v3_v3v3(basis_nor_b, v_pair[1]->no, basis_dir);
|
||||
|
||||
/* don't normalize before combining so as normals approach the direction, they have less effect (T46784). */
|
||||
/* Don't normalize before combining so as normals approach the direction,
|
||||
* they have less effect (T46784). */
|
||||
|
||||
/* combine the normals */
|
||||
/* for flipped faces */
|
||||
|
||||
@@ -230,8 +230,8 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op)
|
||||
*
|
||||
* Rather then do nothing, when 5+ verts are selected, check if they are in our history,
|
||||
* when this is so, we can make edges from them, but _not_ a face,
|
||||
* if it is the intention to make a face the user can just hit F again since there will be edges next
|
||||
* time around.
|
||||
* if it is the intention to make a face the user can just hit F again
|
||||
* since there will be edges next time around.
|
||||
*
|
||||
* if all history verts have ELE_NEW flagged and the total number of history verts == totv,
|
||||
* then we know the history contains all verts here and we can continue...
|
||||
|
||||
@@ -161,15 +161,15 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op)
|
||||
BLI_array_clear(faces);
|
||||
faces = NULL; /* forces different allocatio */
|
||||
|
||||
BMW_init(
|
||||
®walker,
|
||||
bm,
|
||||
BMW_ISLAND_MANIFOLD,
|
||||
BMW_MASK_NOP,
|
||||
BMW_MASK_NOP,
|
||||
FACE_MARK,
|
||||
BMW_FLAG_NOP, /* no need to check BMW_FLAG_TEST_HIDDEN, faces are already marked by the bmo */
|
||||
BMW_NIL_LAY);
|
||||
BMW_init(®walker,
|
||||
bm,
|
||||
BMW_ISLAND_MANIFOLD,
|
||||
BMW_MASK_NOP,
|
||||
BMW_MASK_NOP,
|
||||
FACE_MARK,
|
||||
/* no need to check BMW_FLAG_TEST_HIDDEN, faces are already marked by the bmo. */
|
||||
BMW_FLAG_NOP,
|
||||
BMW_NIL_LAY);
|
||||
|
||||
for (f_iter = BMW_begin(®walker, f); f_iter; f_iter = BMW_step(®walker)) {
|
||||
BLI_array_append(faces, f_iter);
|
||||
|
||||
@@ -659,7 +659,8 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
|
||||
BM_edge_calc_face_tangent(es->e_new, es->l, es->no);
|
||||
|
||||
if (es->e_new == es->e_old) { /* happens on boundary edges */
|
||||
/* take care here, we're creating this double edge which _must_ have its verts replaced later on */
|
||||
/* Take care here, we're creating this double edge which _must_
|
||||
* have its verts replaced later on. */
|
||||
es->e_old = BM_edge_create(bm, es->e_new->v1, es->e_new->v2, es->e_new, BM_CREATE_NOP);
|
||||
}
|
||||
|
||||
@@ -709,9 +710,10 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* execute the split and position verts, it would be most obvious to loop over verts
|
||||
* here but don't do this since we will be splitting them off (iterating stuff you modify is bad juju)
|
||||
* instead loop over edges then their verts */
|
||||
/* Execute the split and position verts, it would be most obvious to loop
|
||||
* over verts here but don't do this since we will be splitting them off
|
||||
* (iterating stuff you modify is bad juju)
|
||||
* instead loop over edges then their verts. */
|
||||
for (i = 0, es = edge_info; i < edge_info_len; i++, es++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
v = (j == 0) ? es->e_new->v1 : es->e_new->v2;
|
||||
@@ -1048,7 +1050,8 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
|
||||
|
||||
/* Copy for loop data, otherwise UV's and vcols are no good.
|
||||
* tiny speedup here we could be more clever and copy from known adjacent data
|
||||
* also - we could attempt to interpolate the loop data, this would be much slower but more useful too */
|
||||
* also - we could attempt to interpolate the loop data,
|
||||
* this would be much slower but more useful too. */
|
||||
if (0) {
|
||||
/* Don't use this because face boundaries have no adjacent loops and won't be filled in.
|
||||
* instead copy from the opposite side with the code below */
|
||||
@@ -1163,8 +1166,8 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op)
|
||||
float(*varr_co)[3];
|
||||
BMOIter oiter;
|
||||
|
||||
/* we need to re-calculate tagged normals, but for this purpose we can copy tagged verts from the
|
||||
* faces they inset from, */
|
||||
/* We need to re-calculate tagged normals,
|
||||
* but for this purpose we can copy tagged verts from the faces they inset from. */
|
||||
for (i = 0, es = edge_info; i < edge_info_len; i++, es++) {
|
||||
zero_v3(es->e_new->v1->no);
|
||||
zero_v3(es->e_new->v2->no);
|
||||
|
||||
@@ -42,7 +42,8 @@ static float quad_calc_error(const float v1[3],
|
||||
const float v3[3],
|
||||
const float v4[3])
|
||||
{
|
||||
/* gives a 'weight' to a pair of triangles that join an edge to decide how good a join they would make */
|
||||
/* Gives a 'weight' to a pair of triangles that join an edge
|
||||
* to decide how good a join they would make. */
|
||||
/* Note: this is more complicated than it needs to be and should be cleaned up.. */
|
||||
float error = 0.0f;
|
||||
|
||||
|
||||
@@ -44,7 +44,8 @@ static bool bmo_recalc_normal_loop_filter_cb(const BMLoop *l, void *UNUSED(user_
|
||||
* This uses a more comprehensive test to see if the furthest face from the center
|
||||
* is pointing towards the center or not.
|
||||
*
|
||||
* A simple test could just check the dot product of the faces-normal and the direction from the center,
|
||||
* A simple test could just check the dot product
|
||||
* of the faces-normal and the direction from the center,
|
||||
* however this can fail for faces which make a sharp spike. eg:
|
||||
*
|
||||
* <pre>
|
||||
@@ -67,7 +68,8 @@ static bool bmo_recalc_normal_loop_filter_cb(const BMLoop *l, void *UNUSED(user_
|
||||
*/
|
||||
|
||||
/**
|
||||
* \return a face index in \a faces and set \a r_is_flip if the face is flipped away from the center.
|
||||
* \return a face index in \a faces and set \a r_is_flip
|
||||
* if the face is flipped away from the center.
|
||||
*/
|
||||
static int recalc_face_normals_find_index(BMesh *bm,
|
||||
BMFace **faces,
|
||||
@@ -83,16 +85,23 @@ static int recalc_face_normals_find_index(BMesh *bm,
|
||||
int f_start_index;
|
||||
int i;
|
||||
|
||||
/* Search for the best loop. Members are compared in-order defined here. */
|
||||
/** Search for the best loop. Members are compared in-order defined here. */
|
||||
struct {
|
||||
/* Squared distance from the center to the loops vertex 'l->v'.
|
||||
* The normalized direction between the center and this vertex is also used for the dot-products below. */
|
||||
/**
|
||||
* Squared distance from the center to the loops vertex 'l->v'.
|
||||
* The normalized direction between the center and this vertex
|
||||
* is also used for the dot-products below.
|
||||
*/
|
||||
float dist_sq;
|
||||
/* Signed dot product using the normalized edge vector,
|
||||
* (best of 'l->prev->v' or 'l->next->v'). */
|
||||
/**
|
||||
* Signed dot product using the normalized edge vector,
|
||||
* (best of 'l->prev->v' or 'l->next->v').
|
||||
*/
|
||||
float edge_dot;
|
||||
/* Unsigned dot product using the loop-normal
|
||||
* (sign is used to check if we need to flip) */
|
||||
/**
|
||||
* Unsigned dot product using the loop-normal
|
||||
* (sign is used to check if we need to flip).
|
||||
*/
|
||||
float loop_dot;
|
||||
} best, test;
|
||||
|
||||
@@ -247,13 +256,14 @@ static void bmo_recalc_face_normals_array(BMesh *bm,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* put normal to the outside, and set the first direction flags in edges
|
||||
/**
|
||||
* Put normal to the outside, and set the first direction flags in edges
|
||||
*
|
||||
* then check the object, and set directions / direction-flags: but only for edges with 1 or 2 faces
|
||||
* this is in fact the 'select connected'
|
||||
* then check the object, and set directions / direction-flags:
|
||||
* but only for edges with 1 or 2 faces this is in fact the 'select connected'
|
||||
*
|
||||
* in case all faces were not done: start over with 'find the ultimate ...' */
|
||||
* in case all faces were not done: start over with 'find the ultimate ...'.
|
||||
*/
|
||||
|
||||
void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op)
|
||||
{
|
||||
|
||||
@@ -941,8 +941,8 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op)
|
||||
BMLoop *l;
|
||||
BMIter fiter, liter;
|
||||
|
||||
/* We cannot tag faces for UVs computing above, so we have to do it now, based on all its vertices
|
||||
* being tagged. */
|
||||
/* We cannot tag faces for UVs computing above,
|
||||
* so we have to do it now, based on all its vertices being tagged. */
|
||||
BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) {
|
||||
bool valid = true;
|
||||
|
||||
@@ -1537,7 +1537,8 @@ void BM_mesh_calc_uvs_cone(BMesh *bm,
|
||||
const float uv_width = 1.0f / (float)segments;
|
||||
const float uv_height = cap_ends ? 0.5f : 1.0f;
|
||||
|
||||
/* Note that all this allows us to handle all cases (real cone, truncated cone, with or without ends capped)
|
||||
/* Note that all this allows us to handle all cases
|
||||
* (real cone, truncated cone, with or without ends capped)
|
||||
* with a single common code. */
|
||||
const float uv_center_y = cap_ends ? 0.25f : 0.5f;
|
||||
const float uv_center_x_top = cap_ends ? 0.25f : 0.5f;
|
||||
@@ -1601,7 +1602,8 @@ void BM_mesh_calc_uvs_cone(BMesh *bm,
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* top or bottom face - so unwrap it by transforming back to a circle and using the X/Y coords */
|
||||
/* Top or bottom face - so unwrap it by transforming
|
||||
* back to a circle and using the X/Y coords. */
|
||||
BM_face_normal_update(f);
|
||||
|
||||
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
|
||||
|
||||
@@ -182,7 +182,8 @@ finally : {
|
||||
}
|
||||
|
||||
/**
|
||||
* \note with 'targetmap', multiple 'keys' are currently supported, though no callers should be using.
|
||||
* \note with 'targetmap', multiple 'keys' are currently supported,
|
||||
* though no callers should be using.
|
||||
* (because slot maps currently use GHash without the GHASH_FLAG_ALLOW_DUPES flag set)
|
||||
*/
|
||||
void bmo_weld_verts_exec(BMesh *bm, BMOperator *op)
|
||||
|
||||
@@ -151,14 +151,17 @@ static void bm_rotate_edges_shared(
|
||||
if (ok) {
|
||||
float cost = bm_edge_calc_rotate_cost(e);
|
||||
if (pass_type == PASS_TYPE_BOUNDARY) {
|
||||
/* Trick to ensure once started, non boundaries are handled before other boundary edges.
|
||||
/* Trick to ensure once started,
|
||||
* non boundaries are handled before other boundary edges.
|
||||
* This means the first longest boundary defines the starting point which is rotated
|
||||
* until all its connected edges are exhausted and the next boundary is popped off the heap.
|
||||
* until all its connected edges are exhausted
|
||||
* and the next boundary is popped off the heap.
|
||||
*
|
||||
* Without this we may rotate from different starting points and meet in the middle
|
||||
* with obviously uneven topology.
|
||||
*
|
||||
* Move from negative to positive value, inverting so large values are still handled first.
|
||||
* Move from negative to positive value,
|
||||
* inverting so large values are still handled first.
|
||||
*/
|
||||
cost = cost != 0.0f ? -1.0f / cost : FLT_MAX;
|
||||
}
|
||||
@@ -190,10 +193,12 @@ static void bm_rotate_edges_shared(
|
||||
|
||||
/* Note: we could validate all edges which have not been rotated
|
||||
* (not just previously degenerate edges).
|
||||
* However there is no real need - they can be left until they're popped off the queue. */
|
||||
* However there is no real need -
|
||||
* they can be left until they're popped off the queue. */
|
||||
|
||||
/* We don't know the exact topology after rotating the edge,
|
||||
* so loop over all faces attached to the new edge, typically this will only be two faces. */
|
||||
* so loop over all faces attached to the new edge,
|
||||
* typically this will only be two faces. */
|
||||
BMLoop *l_radial_iter = e_rotate->l;
|
||||
do {
|
||||
/* Skip this edge. */
|
||||
|
||||
@@ -187,7 +187,8 @@ static float bm_edge_calc_rotate_beauty__area(const float v1[3],
|
||||
/**
|
||||
* Important to lock degenerate here,
|
||||
* since the triangle pars will be projected into different 2D spaces.
|
||||
* Allowing to rotate out of a degenerate state can flip the faces (when performed iteratively).
|
||||
* Allowing to rotate out of a degenerate state can flip the faces
|
||||
* (when performed iteratively).
|
||||
*/
|
||||
return BLI_polyfill_beautify_quad_rotate_calc_ex(v1_xy, v2_xy, v3_xy, v4_xy, true);
|
||||
} while (false);
|
||||
|
||||
@@ -131,22 +131,36 @@ typedef struct ProfileSpacing {
|
||||
|
||||
/* An element in a cyclic boundary of a Vertex Mesh (VMesh) */
|
||||
typedef struct BoundVert {
|
||||
struct BoundVert *next, *prev; /* in CCW order */
|
||||
/** In CCW order. */
|
||||
struct BoundVert *next, *prev;
|
||||
NewVert nv;
|
||||
EdgeHalf *efirst; /* first of edges attached here: in CCW order */
|
||||
/** First of edges attached here: in CCW order. */
|
||||
EdgeHalf *efirst;
|
||||
EdgeHalf *elast;
|
||||
EdgeHalf *eon; /* the "edge between" that this is on, in offset_on_edge_between case */
|
||||
EdgeHalf *ebev; /* beveled edge whose left side is attached here, if any */
|
||||
int index; /* used for vmesh indexing */
|
||||
float sinratio; /* when eon set, ratio of sines of angles to eon edge */
|
||||
struct BoundVert *adjchain; /* adjustment chain or cycle link pointer */
|
||||
Profile profile; /* edge profile between this and next BoundVert */
|
||||
bool any_seam; /* are any of the edges attached here seams? */
|
||||
bool visited; /* used during delta adjust pass */
|
||||
bool is_arc_start; /* this boundvert begins an arc profile */
|
||||
bool is_patch_start; /* this boundvert begins a patch profile */
|
||||
int seam_len; /* length of seam starting from current boundvert to next boundvert with ccw ordering */
|
||||
int sharp_len; /* Same as seam_len but defines length of sharp edges */
|
||||
/** The "edge between" that this is on, in offset_on_edge_between case. */
|
||||
EdgeHalf *eon;
|
||||
/** Beveled edge whose left side is attached here, if any. */
|
||||
EdgeHalf *ebev;
|
||||
/** Used for vmesh indexing. */
|
||||
int index;
|
||||
/** When eon set, ratio of sines of angles to eon edge. */
|
||||
float sinratio;
|
||||
/** Adjustment chain or cycle link pointer. */
|
||||
struct BoundVert *adjchain;
|
||||
/** Edge profile between this and next BoundVert. */
|
||||
Profile profile;
|
||||
/** Are any of the edges attached here seams? */
|
||||
bool any_seam;
|
||||
/** Used during delta adjust pass */
|
||||
bool visited;
|
||||
/** This boundvert begins an arc profile */
|
||||
bool is_arc_start;
|
||||
/** This boundvert begins a patch profile */
|
||||
bool is_patch_start;
|
||||
/** Length of seam starting from current boundvert to next boundvert with ccw ordering */
|
||||
int seam_len;
|
||||
/** Same as seam_len but defines length of sharp edges */
|
||||
int sharp_len;
|
||||
// int _pad;
|
||||
} BoundVert;
|
||||
|
||||
@@ -167,78 +181,122 @@ typedef struct VMesh {
|
||||
|
||||
/* Data for a vertex involved in a bevel */
|
||||
typedef struct BevVert {
|
||||
BMVert *v; /* original mesh vertex */
|
||||
int edgecount; /* total number of edges around the vertex (excluding wire edges if edge beveling) */
|
||||
int selcount; /* number of selected edges around the vertex */
|
||||
int wirecount; /* count of wire edges */
|
||||
float offset; /* offset for this vertex, if vertex_only bevel */
|
||||
bool any_seam; /* any seams on attached edges? */
|
||||
bool visited; /* used in graph traversal */
|
||||
EdgeHalf *edges; /* array of size edgecount; CCW order from vertex normal side */
|
||||
BMEdge **wire_edges; /* array of size wirecount of wire edges */
|
||||
VMesh *vmesh; /* mesh structure for replacing vertex */
|
||||
/** Original mesh vertex */
|
||||
BMVert *v;
|
||||
/** Total number of edges around the vertex (excluding wire edges if edge beveling) */
|
||||
int edgecount;
|
||||
/** Number of selected edges around the vertex */
|
||||
int selcount;
|
||||
/** Count of wire edges */
|
||||
int wirecount;
|
||||
/** Offset for this vertex, if vertex_only bevel */
|
||||
float offset;
|
||||
/** Any seams on attached edges? */
|
||||
bool any_seam;
|
||||
/** Used in graph traversal */
|
||||
bool visited;
|
||||
/** Array of size edgecount; CCW order from vertex normal side */
|
||||
EdgeHalf *edges;
|
||||
/** Array of size wirecount of wire edges */
|
||||
BMEdge **wire_edges;
|
||||
/** Mesh structure for replacing vertex */
|
||||
VMesh *vmesh;
|
||||
} BevVert;
|
||||
|
||||
/* face classification: note depend on F_RECON > F_EDGE > F_VERT */
|
||||
typedef enum {
|
||||
F_NONE, /* used when there is no face at all */
|
||||
F_ORIG, /* original face, not touched */
|
||||
F_VERT, /* face for construction aroun a vert */
|
||||
F_EDGE, /* face for a beveled edge */
|
||||
F_RECON, /* reconstructed original face with some new verts */
|
||||
/** Used when there is no face at all */
|
||||
F_NONE,
|
||||
/** Original face, not touched */
|
||||
F_ORIG,
|
||||
/** Face for construction aroun a vert */
|
||||
F_VERT,
|
||||
/** Face for a beveled edge */
|
||||
F_EDGE,
|
||||
/** Reconstructed original face with some new verts */
|
||||
F_RECON,
|
||||
} FKind;
|
||||
|
||||
// static const char* fkind_names[] = {"F_NONE", "F_ORIG", "F_VERT", "F_EDGE", "F_RECON"}; /* DEBUG */
|
||||
#if 0
|
||||
static const char* fkind_names[] = {"F_NONE", "F_ORIG", "F_VERT", "F_EDGE", "F_RECON"}; /* DEBUG */
|
||||
#endif
|
||||
|
||||
/* Bevel parameters and state */
|
||||
typedef struct BevelParams {
|
||||
GHash *vert_hash; /* records BevVerts made: key BMVert*, value BevVert* */
|
||||
GHash *face_hash; /* records new faces: key BMFace*, value one of {VERT/EDGE/RECON}_POLY */
|
||||
MemArena *
|
||||
mem_arena; /* use for all allocs while bevel runs, if we need to free we can switch to mempool */
|
||||
ProfileSpacing pro_spacing; /* parameter values for evenly spaced profiles */
|
||||
/** Records BevVerts made: key BMVert*, value BevVert* */
|
||||
GHash *vert_hash;
|
||||
/** Records new faces: key BMFace*, value one of {VERT/EDGE/RECON}_POLY */
|
||||
GHash *face_hash;
|
||||
/** Use for all allocs while bevel runs, if we need to free we can switch to mempool. */
|
||||
MemArena *mem_arena;
|
||||
/** Parameter values for evenly spaced profiles. */
|
||||
ProfileSpacing pro_spacing;
|
||||
|
||||
float offset; /* blender units to offset each side of a beveled edge */
|
||||
int offset_type; /* how offset is measured; enum defined in bmesh_operators.h */
|
||||
int seg; /* number of segments in beveled edge profile */
|
||||
float profile; /* user profile setting */
|
||||
float pro_super_r; /* superellipse parameter for edge profile */
|
||||
bool vertex_only; /* bevel vertices only */
|
||||
bool use_weights; /* bevel amount affected by weights on edges or verts */
|
||||
bool loop_slide; /* should bevel prefer to slide along edges rather than keep widths spec? */
|
||||
bool limit_offset; /* should offsets be limited by collisions? */
|
||||
bool offset_adjust; /* should offsets be adjusted to try to get even widths? */
|
||||
bool mark_seam; /* should we propagate seam edge markings? */
|
||||
bool mark_sharp; /* should we propagate sharp edge markings? */
|
||||
bool harden_normals; /* should we harden normals? */
|
||||
const struct MDeformVert *dvert; /* vertex group array, maybe set if vertex_only */
|
||||
int vertex_group; /* vertex group index, maybe set if vertex_only */
|
||||
int mat_nr; /* if >= 0, material number for bevel; else material comes from adjacent faces */
|
||||
int face_strength_mode; /* setting face strength if > 0 */
|
||||
int miter_outer; /* what kind of miter pattern to use on reflex angles */
|
||||
int miter_inner; /* what kind of miter pattern to use on non-reflex angles */
|
||||
float spread; /* amount to spread when doing inside miter */
|
||||
float smoothresh; /* mesh's smoothresh, used if hardening */
|
||||
/** Blender units to offset each side of a beveled edge. */
|
||||
float offset;
|
||||
/** How offset is measured; enum defined in bmesh_operators.h */
|
||||
int offset_type;
|
||||
/** Number of segments in beveled edge profile. */
|
||||
int seg;
|
||||
/** User profile setting. */
|
||||
float profile;
|
||||
/** Superellipse parameter for edge profile. */
|
||||
float pro_super_r;
|
||||
/** Bevel vertices only. */
|
||||
bool vertex_only;
|
||||
/** Bevel amount affected by weights on edges or verts. */
|
||||
bool use_weights;
|
||||
/** Should bevel prefer to slide along edges rather than keep widths spec? */
|
||||
bool loop_slide;
|
||||
/** Should offsets be limited by collisions? */
|
||||
bool limit_offset;
|
||||
/** Should offsets be adjusted to try to get even widths? */
|
||||
bool offset_adjust;
|
||||
/** Should we propagate seam edge markings? */
|
||||
bool mark_seam;
|
||||
/** Should we propagate sharp edge markings? */
|
||||
bool mark_sharp;
|
||||
/** Should we harden normals? */
|
||||
bool harden_normals;
|
||||
/** Vertex group array, maybe set if vertex_only. */
|
||||
const struct MDeformVert *dvert;
|
||||
/** Vertex group index, maybe set if vertex_only. */
|
||||
int vertex_group;
|
||||
/** If >= 0, material number for bevel; else material comes from adjacent faces. */
|
||||
int mat_nr;
|
||||
/** Setting face strength if > 0. */
|
||||
int face_strength_mode;
|
||||
/** What kind of miter pattern to use on reflex angles. */
|
||||
int miter_outer;
|
||||
/** What kind of miter pattern to use on non-reflex angles. */
|
||||
int miter_inner;
|
||||
/** Amount to spread when doing inside miter. */
|
||||
float spread;
|
||||
/** Mesh's smoothresh, used if hardening. */
|
||||
float smoothresh;
|
||||
} BevelParams;
|
||||
|
||||
// #pragma GCC diagnostic ignored "-Wpadded"
|
||||
|
||||
// #include "bevdebug.c"
|
||||
|
||||
/* some flags to re-enable old behavior for a while, in case fixes broke things not caught by regression tests */
|
||||
/* Some flags to re-enable old behavior for a while,
|
||||
* in case fixes broke things not caught by regression tests. */
|
||||
static int bev_debug_flags = 0;
|
||||
#define DEBUG_OLD_PLANE_SPECIAL (bev_debug_flags & 1)
|
||||
#define DEBUG_OLD_PROJ_TO_PERP_PLANE (bev_debug_flags & 2)
|
||||
#define DEBUG_OLD_FLAT_MID (bev_debug_flags & 4)
|
||||
|
||||
/* use the unused _BM_ELEM_TAG_ALT flag to flag the 'long' loops (parallel to beveled edge) of edge-polygons */
|
||||
/* use the unused _BM_ELEM_TAG_ALT flag to flag the 'long' loops (parallel to beveled edge)
|
||||
* of edge-polygons. */
|
||||
#define BM_ELEM_LONG_TAG (1 << 6)
|
||||
|
||||
/* these flag values will get set on geom we want to return in 'out' slots for edges and verts */
|
||||
#define EDGE_OUT 4
|
||||
#define VERT_OUT 8
|
||||
|
||||
/* If we're called from the modifier, tool flags aren't available, but don't need output geometry */
|
||||
/* If we're called from the modifier, tool flags aren't available,
|
||||
* but don't need output geometry. */
|
||||
static void flag_out_edge(BMesh *bm, BMEdge *bme)
|
||||
{
|
||||
if (bm->use_toolflags) {
|
||||
@@ -622,7 +680,8 @@ static bool contig_ldata_across_loops(BMesh *bm, BMLoop *l1, BMLoop *l2, int lay
|
||||
type, (char *)l1->head.data + offset, (char *)l2->head.data + offset);
|
||||
}
|
||||
|
||||
/* Are all loop layers with have math (e.g., UVs) contiguous from face f1 to face f2 across edge e? */
|
||||
/* Are all loop layers with have math (e.g., UVs)
|
||||
* contiguous from face f1 to face f2 across edge e? */
|
||||
static bool contig_ldata_across_edge(BMesh *bm, BMEdge *e, BMFace *f1, BMFace *f2)
|
||||
{
|
||||
BMLoop *lef1, *lef2;
|
||||
@@ -867,8 +926,8 @@ static bool point_between_edges(float co[3], BMVert *v, BMFace *f, EdgeHalf *e1,
|
||||
* but if the offsets are not equal (allowing for this, as bevel modifier has edge weights that may
|
||||
* lead to different offsets) then meeting point can be found be intersecting offset lines.
|
||||
* If making the meeting point significantly changes the left or right offset from the user spec,
|
||||
* record the change in offset_l (or offset_r); later we can tell that a change has happened because
|
||||
* the offset will differ from its original value in offset_l_spec (or offset_r_spec).
|
||||
* record the change in offset_l (or offset_r); later we can tell that a change has happened
|
||||
* because the offset will differ from its original value in offset_l_spec (or offset_r_spec).
|
||||
*/
|
||||
static void offset_meet(
|
||||
EdgeHalf *e1, EdgeHalf *e2, BMVert *v, BMFace *f, bool edges_between, float meetco[3])
|
||||
@@ -1024,7 +1083,8 @@ static void offset_meet(
|
||||
}
|
||||
}
|
||||
|
||||
/* chosen so that 1/sin(BEVEL_GOOD_ANGLE) is about 4, giving that expansion factor to bevel width */
|
||||
/* Chosen so that 1/sin(BEVEL_GOOD_ANGLE) is about 4,
|
||||
* giving that expansion factor to bevel width. */
|
||||
#define BEVEL_GOOD_ANGLE 0.25f
|
||||
|
||||
/* Calculate the meeting point between e1 and e2 (one of which should have zero offsets),
|
||||
@@ -1780,7 +1840,8 @@ static void bevel_extend_edge_data(BevVert *bv)
|
||||
for (int k = 1; k < vm->seg; k++) {
|
||||
v2 = mesh_vert(vm, i % vm->count, 0, k)->v;
|
||||
|
||||
/* Here v1 & v2 are current and next BMverts, we find common edge and set its edge data */
|
||||
/* Here v1 & v2 are current and next BMverts,
|
||||
* we find common edge and set its edge data. */
|
||||
e = v1->e;
|
||||
while (e->v1 != v2 && e->v2 != v2) {
|
||||
if (e->v1 == v1) {
|
||||
@@ -1918,14 +1979,16 @@ static void bevel_harden_normals(BMesh *bm, BevelParams *bp)
|
||||
|
||||
/* If there is not already a custom split normal layer then making one (with BM_lnorspace_update)
|
||||
* will not respect the autosmooth angle between smooth faces. To get that to happen, we have
|
||||
* to mark the sharpen the edges that are only sharp because of the angle test -- otherwise would be smooth.
|
||||
* to mark the sharpen the edges that are only sharp because
|
||||
* of the angle test -- otherwise would be smooth.
|
||||
*/
|
||||
if (cd_clnors_offset == -1) {
|
||||
BM_edges_sharp_from_angle_set(bm, bp->smoothresh);
|
||||
bevel_edges_sharp_boundary(bm, bp);
|
||||
}
|
||||
|
||||
/* ensure that bm->lnor_spacearr has properly stored loop normals; side effect: ensures loop indices */
|
||||
/* Ensure that bm->lnor_spacearr has properly stored loop normals;
|
||||
* side effect: ensures loop indices. */
|
||||
BM_lnorspace_update(bm);
|
||||
|
||||
if (cd_clnors_offset == -1) {
|
||||
@@ -3143,7 +3206,8 @@ static VMesh *new_adj_vmesh(MemArena *mem_arena, int count, int seg, BoundVert *
|
||||
return vm;
|
||||
}
|
||||
|
||||
/* VMesh verts for vertex i have data for (i, 0 <= j <= ns2, 0 <= k <= ns), where ns2 = floor(nseg / 2).
|
||||
/* VMesh verts for vertex i have data for (i, 0 <= j <= ns2, 0 <= k <= ns),
|
||||
* where ns2 = floor(nseg / 2).
|
||||
* But these overlap data from previous and next i: there are some forced equivalences.
|
||||
* Let's call these indices the canonical ones: we will just calculate data for these
|
||||
* 0 <= j <= ns2, 0 <= k < ns2 (for odd ns2)
|
||||
@@ -4148,13 +4212,15 @@ static void closer_v3_v3v3v3(float r[3], float a[3], float b[3], float v[3])
|
||||
}
|
||||
|
||||
/* Special case of VMesh when profile == 1 and there are 3 or more beveled edges.
|
||||
* We want the effect of parallel offset lines (n/2 of them) on each side of the center, for even n.
|
||||
* Wherever they intersect with each other between two successive beveled edges, those intersections
|
||||
* are part of the vmesh rings.
|
||||
* We want the effect of parallel offset lines (n/2 of them)
|
||||
* on each side of the center, for even n.
|
||||
* Wherever they intersect with each other between two successive beveled edges,
|
||||
* those intersections are part of the vmesh rings.
|
||||
* We have to move the boundary edges too -- the usual method is to make one profile plane between
|
||||
* successive BoundVerts, but for the effect we want here, there will be two planes, one on each side
|
||||
* of the original edge.
|
||||
* At the moment, this is not called for odd number of segments, though code does something if it is.
|
||||
* successive BoundVerts, but for the effect we want here, there will be two planes,
|
||||
* one on each side of the original edge.
|
||||
* At the moment, this is not called for odd number of segments,
|
||||
* though code does something if it is.
|
||||
*/
|
||||
static VMesh *square_out_adj_vmesh(BevelParams *bp, BevVert *bv)
|
||||
{
|
||||
@@ -4574,8 +4640,9 @@ static void bevel_build_rings(BevelParams *bp, BMesh *bm, BevVert *bv)
|
||||
/* If we make a poly out of verts around bv, snapping to rep frep, will uv poly have zero area?
|
||||
* The uv poly is made by snapping all outside-of-frep vertices to the closest edge in frep.
|
||||
* Assume that this function is called when the only inside-of-frep vertex is vm->boundstart.
|
||||
* The poly will have zero area if the distance of that first vertex to some edge e is zero, and all
|
||||
* the other vertices snap to e or snap to an edge at a point that is essentially on e too. */
|
||||
* The poly will have zero area if the distance of that first vertex to some edge e is zero,
|
||||
* and all the other vertices snap to e or snap to an edge
|
||||
* at a point that is essentially on e too. */
|
||||
static bool is_bad_uv_poly(BevVert *bv, BMFace *frep)
|
||||
{
|
||||
BoundVert *v;
|
||||
@@ -4958,7 +5025,8 @@ static int bevel_edge_order_extend(BMesh *bm, BevVert *bv, int i)
|
||||
}
|
||||
/* at this point we should be back at invariant on entrance: path up to j */
|
||||
if (bestj > j) {
|
||||
/* save_path should have from j + 1 to bestj inclusive edges to add to edges[] before returning */
|
||||
/* save_path should have from j + 1 to bestj inclusive
|
||||
* edges to add to edges[] before returning. */
|
||||
for (k = j + 1; k <= bestj; k++) {
|
||||
BLI_assert(save_path[k - (j + 1)] != NULL);
|
||||
bv->edges[k].e = save_path[k - (j + 1)];
|
||||
@@ -4978,9 +5046,10 @@ static int bevel_edge_order_extend(BMesh *bm, BevVert *bv, int i)
|
||||
* Assume the first edge is already in bv->edges[0].e and it is tagged. */
|
||||
#ifdef FASTER_FASTORDER
|
||||
/* The alternative older code is O(n^2) where n = # of edges incident to bv->v.
|
||||
* This implementation is O(n * m) where m = average number of faces attached to an edge incident to bv->v,
|
||||
* which is almost certainly a small constant except in very strange cases. But this code produces different
|
||||
* choices of ordering than the legacy system, leading to differences in vertex orders etc. in user models,
|
||||
* This implementation is O(n * m) where m = average number of faces attached to an edge incident
|
||||
* to bv->v, which is almost certainly a small constant except in very strange cases.
|
||||
* But this code produces different choices of ordering than the legacy system,
|
||||
* leading to differences in vertex orders etc. in user models,
|
||||
* so for now will continue to use the legacy code. */
|
||||
static bool fast_bevel_edge_order(BevVert *bv)
|
||||
{
|
||||
|
||||
@@ -690,7 +690,8 @@ static void bm_decim_triangulate_end(BMesh *bm, const int edges_tri_tot)
|
||||
static void bm_edge_collapse_loop_customdata(
|
||||
BMesh *bm, BMLoop *l, BMVert *v_clear, BMVert *v_other, const float customdata_fac)
|
||||
{
|
||||
/* disable seam check - the seam check would have to be done per layer, its not really that important */
|
||||
/* Disable seam check - the seam check would have to be done per layer,
|
||||
* its not really that important. */
|
||||
//#define USE_SEAM
|
||||
/* these don't need to be updated, since they will get removed when the edge collapses */
|
||||
BMLoop *l_clear, *l_other;
|
||||
|
||||
@@ -350,7 +350,8 @@ void BM_mesh_decimate_dissolve_ex(BMesh *bm,
|
||||
BM_ITER_MESH_INDEX (e_iter, &iter, bm, BM_EDGES_OF_MESH, i) {
|
||||
earray[i] = e_iter;
|
||||
}
|
||||
/* remove all edges/verts left behind from dissolving, NULL'ing the vertex array so we dont re-use */
|
||||
/* Remove all edges/verts left behind from dissolving,
|
||||
* NULL'ing the vertex array so we dont re-use. */
|
||||
for (i = bm->totedge - 1; i != -1; i--) {
|
||||
e_iter = earray[i];
|
||||
|
||||
|
||||
@@ -116,7 +116,8 @@ static bool bm_vert_region_test_chain(BMVert *v, int *const depths[2], const int
|
||||
*
|
||||
* This is done in both directions, after that each vertices 'depth' is added to check
|
||||
* if its less than the number of passes needed to complete the search.
|
||||
* When it is, we know the path is one of possible paths that have the minimum topological distance.
|
||||
* When it is, we know the path is one of possible paths
|
||||
* that have the minimum topological distance.
|
||||
*
|
||||
* \note Only verts without BM_ELEM_TAG will be walked over.
|
||||
*/
|
||||
@@ -201,7 +202,8 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm,
|
||||
|
||||
#ifdef USE_EDGE_CHAIN
|
||||
/* Expand initial state to end-point vertices when they only have 2x edges,
|
||||
* this prevents odd behavior when source or destination are in the middle of a long chain of edges. */
|
||||
* this prevents odd behavior when source or destination are in the middle
|
||||
* of a long chain of edges. */
|
||||
if (ELEM(path_htype, BM_VERT, BM_EDGE)) {
|
||||
for (int i = 0; i < ele_verts_len[side]; i++) {
|
||||
BMVert *v = ele_verts[side][i];
|
||||
@@ -221,8 +223,8 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm,
|
||||
}
|
||||
#endif /* USE_EDGE_CHAIN */
|
||||
|
||||
/* Keep walking over connected geometry until we find all the vertices in `ele_verts[side_other]`,
|
||||
* or exit the loop when theres no connection. */
|
||||
/* Keep walking over connected geometry until we find all the vertices in
|
||||
* `ele_verts[side_other]`, or exit the loop when theres no connection. */
|
||||
found_all = false;
|
||||
for (pass = 1; (STACK_SIZE(stack) != 0); pass++) {
|
||||
while (STACK_SIZE(stack) != 0) {
|
||||
@@ -321,7 +323,8 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm,
|
||||
} while ((l_iter = l_iter->next) != l_first);
|
||||
#else
|
||||
/* Allowing a single failure on a face gives fewer 'gaps'.
|
||||
* While correct, in practice they're often part of what a user would consider the 'region'. */
|
||||
* While correct, in practice they're often part of what
|
||||
* a user would consider the 'region'. */
|
||||
int ok_tests = f->len > 3 ? 1 : 0; /* how many times we may fail */
|
||||
do {
|
||||
if (!bm_vert_region_test_chain(l_iter->v, depths, pass)) {
|
||||
|
||||
Reference in New Issue
Block a user