2012-02-19 18:31:04 +00:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2007 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/bmesh/intern/bmesh_construct.c
|
|
|
|
* \ingroup bmesh
|
|
|
|
*
|
|
|
|
* BM construction functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2013-07-28 10:38:25 +00:00
|
|
|
#include "BLI_alloca.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "BLI_math.h"
|
2013-09-05 22:24:12 +00:00
|
|
|
#include "BLI_sort_utils.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
|
|
|
#include "bmesh.h"
|
2012-03-08 03:25:53 +00:00
|
|
|
#include "intern/bmesh_private.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
#define SELECT 1
|
|
|
|
|
2015-12-24 19:51:41 +11:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill in a vertex array from an edge array.
|
|
|
|
*
|
|
|
|
* \returns false if any verts aren't found.
|
|
|
|
*/
|
|
|
|
bool BM_verts_from_edges(BMVert **vert_arr, BMEdge **edge_arr, const int len)
|
|
|
|
{
|
|
|
|
int i, i_prev = len - 1;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
vert_arr[i] = BM_edge_share_vert(edge_arr[i_prev], edge_arr[i]);
|
|
|
|
if (vert_arr[i] == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
i_prev = i;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-28 11:45:53 +10:00
|
|
|
/**
|
|
|
|
* Fill in an edge array from a vertex array (connected polygon loop).
|
|
|
|
*
|
2015-12-24 19:51:41 +11:00
|
|
|
* \returns false if any edges aren't found.
|
2015-05-28 11:45:53 +10:00
|
|
|
*/
|
|
|
|
bool BM_edges_from_verts(BMEdge **edge_arr, BMVert **vert_arr, const int len)
|
|
|
|
{
|
|
|
|
int i, i_prev = len - 1;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
edge_arr[i_prev] = BM_edge_exists(vert_arr[i_prev], vert_arr[i]);
|
|
|
|
if (edge_arr[i_prev] == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
i_prev = i;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill in an edge array from a vertex array (connected polygon loop).
|
|
|
|
* Creating edges as-needed.
|
|
|
|
*/
|
|
|
|
void BM_edges_from_verts_ensure(BMesh *bm, BMEdge **edge_arr, BMVert **vert_arr, const int len)
|
|
|
|
{
|
|
|
|
int i, i_prev = len - 1;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
edge_arr[i_prev] = BM_edge_create(bm, vert_arr[i_prev], vert_arr[i], NULL, BM_CREATE_NO_DOUBLE);
|
|
|
|
i_prev = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* prototypes */
|
2015-04-25 20:15:20 +10:00
|
|
|
static void bm_loop_attrs_copy(
|
|
|
|
BMesh *source_mesh, BMesh *target_mesh,
|
2018-11-27 11:39:51 +11:00
|
|
|
const BMLoop *source_loop, BMLoop *target_loop, uint64_t cd_mask);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/**
|
|
|
|
* \brief Make Quad/Triangle
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* Creates a new quad or triangle from a list of 3 or 4 vertices.
|
2013-01-14 16:42:43 +00:00
|
|
|
* If \a no_double is true, then a check is done to see if a face
|
2012-02-29 06:55:10 +00:00
|
|
|
* with these vertices already exists and returns it instead.
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* If a pointer to an example face is provided, it's custom data
|
|
|
|
* and properties will be copied to the new face.
|
|
|
|
*
|
|
|
|
* \note The winding of the face is determined by the order
|
|
|
|
* of the vertices in the vertex array.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
|
|
|
|
2015-04-25 20:15:20 +10:00
|
|
|
BMFace *BM_face_create_quad_tri(
|
|
|
|
BMesh *bm,
|
|
|
|
BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4,
|
|
|
|
const BMFace *f_example, const eBMCreateFlag create_flag)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
BMVert *vtar[4] = {v1, v2, v3, v4};
|
2013-08-21 07:51:47 +00:00
|
|
|
return BM_face_create_verts(bm, vtar, v4 ? 4 : 3, f_example, create_flag, true);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 10:37:33 +00:00
|
|
|
/**
|
|
|
|
* \brief copies face loop data from shared adjacent faces.
|
2013-08-18 11:44:51 +00:00
|
|
|
*
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param filter_fn: A function that filters the source loops before copying (don't always want to copy all)
|
2013-08-18 11:44:51 +00:00
|
|
|
*
|
2012-04-13 10:37:33 +00:00
|
|
|
* \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,
|
2013-08-18 11:44:51 +00:00
|
|
|
* this way: a quad with 2 connected quads on either side will still get all 4 loops updated
|
|
|
|
*/
|
2015-04-25 20:15:20 +10:00
|
|
|
void BM_face_copy_shared(
|
|
|
|
BMesh *bm, BMFace *f,
|
2015-11-28 13:37:02 +11:00
|
|
|
BMLoopFilterFunc filter_fn, void *user_data)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2012-04-13 10:37:33 +00:00
|
|
|
BMLoop *l_first;
|
|
|
|
BMLoop *l_iter;
|
|
|
|
|
2013-08-18 11:44:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
do {
|
|
|
|
BLI_assert(BM_ELEM_API_FLAG_TEST(l_iter, _FLAG_OVERLAP) == 0);
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
#endif
|
|
|
|
|
2012-04-13 10:37:33 +00:00
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
do {
|
|
|
|
BMLoop *l_other = l_iter->radial_next;
|
|
|
|
|
|
|
|
if (l_other && l_other != l_iter) {
|
2013-08-18 11:44:51 +00:00
|
|
|
BMLoop *l_src[2];
|
|
|
|
BMLoop *l_dst[2] = {l_iter, l_iter->next};
|
2017-05-06 14:18:31 +10:00
|
|
|
uint j;
|
2013-08-18 11:44:51 +00:00
|
|
|
|
2012-04-13 10:37:33 +00:00
|
|
|
if (l_other->v == l_iter->v) {
|
2013-08-18 11:44:51 +00:00
|
|
|
l_src[0] = l_other;
|
|
|
|
l_src[1] = l_other->next;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-18 11:44:51 +00:00
|
|
|
l_src[0] = l_other->next;
|
|
|
|
l_src[1] = l_other;
|
2012-04-13 10:37:33 +00:00
|
|
|
}
|
2013-08-18 11:44:51 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
BLI_assert(l_dst[j]->v == l_src[j]->v);
|
|
|
|
if (BM_ELEM_API_FLAG_TEST(l_dst[j], _FLAG_OVERLAP) == 0) {
|
2015-11-28 13:37:02 +11:00
|
|
|
if ((filter_fn == NULL) || filter_fn(l_src[j], user_data)) {
|
2018-11-27 11:39:51 +11:00
|
|
|
bm_loop_attrs_copy(bm, bm, l_src[j], l_dst[j], 0x0);
|
2013-08-18 11:44:51 +00:00
|
|
|
BM_ELEM_API_FLAG_ENABLE(l_dst[j], _FLAG_OVERLAP);
|
|
|
|
}
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-13 10:37:33 +00:00
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2013-08-18 11:44:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
do {
|
|
|
|
BM_ELEM_API_FLAG_DISABLE(l_iter, _FLAG_OVERLAP);
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 07:42:48 +00:00
|
|
|
/**
|
2015-04-25 17:20:59 +10:00
|
|
|
* Given an array of edges,
|
|
|
|
* order them using the winding defined by \a v1 & \a v2
|
|
|
|
* into \a edges_sort & \a verts_sort.
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2015-04-25 17:20:59 +10:00
|
|
|
* All arrays must be \a len long.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2015-04-25 17:20:59 +10:00
|
|
|
static bool bm_edges_sort_winding(
|
|
|
|
BMVert *v1, BMVert *v2,
|
|
|
|
BMEdge **edges, const int len,
|
|
|
|
BMEdge **edges_sort, BMVert **verts_sort)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2015-04-25 17:20:59 +10:00
|
|
|
BMEdge *e_iter, *e_first;
|
|
|
|
BMVert *v_iter;
|
2013-01-03 08:06:12 +00:00
|
|
|
int i;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
/* all flags _must_ be cleared on exit! */
|
2012-02-19 18:31:04 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
BM_ELEM_API_FLAG_ENABLE(edges[i], _FLAG_MF);
|
2015-04-25 17:20:59 +10:00
|
|
|
BM_ELEM_API_FLAG_ENABLE(edges[i]->v1, _FLAG_MV);
|
|
|
|
BM_ELEM_API_FLAG_ENABLE(edges[i]->v2, _FLAG_MV);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
/* find first edge */
|
2015-04-25 21:14:55 +10:00
|
|
|
i = 0;
|
2015-04-25 17:20:59 +10:00
|
|
|
v_iter = v1;
|
|
|
|
e_iter = e_first = v1->e;
|
2012-02-19 18:31:04 +00:00
|
|
|
do {
|
2015-04-25 17:20:59 +10:00
|
|
|
if (BM_ELEM_API_FLAG_TEST(e_iter, _FLAG_MF) &&
|
|
|
|
(BM_edge_other_vert(e_iter, v_iter) == v2))
|
|
|
|
{
|
2015-04-25 21:14:55 +10:00
|
|
|
i = 1;
|
2015-04-25 17:20:59 +10:00
|
|
|
break;
|
2013-01-03 07:53:30 +00:00
|
|
|
}
|
2015-04-25 17:20:59 +10:00
|
|
|
} while ((e_iter = bmesh_disk_edge_next(e_iter, v_iter)) != e_first);
|
2015-04-25 21:14:55 +10:00
|
|
|
if (i == 0) {
|
2015-04-25 17:20:59 +10:00
|
|
|
goto error;
|
|
|
|
}
|
2013-01-03 07:53:30 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
/* entering loop will always succeed */
|
|
|
|
if (BM_ELEM_API_FLAG_TEST(e_iter, _FLAG_MF)) {
|
|
|
|
if (UNLIKELY(BM_ELEM_API_FLAG_TEST(v_iter, _FLAG_MV) == false)) {
|
|
|
|
/* vert is in loop multiple times */
|
|
|
|
goto error;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
BM_ELEM_API_FLAG_DISABLE(e_iter, _FLAG_MF);
|
|
|
|
edges_sort[i] = e_iter;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
BM_ELEM_API_FLAG_DISABLE(v_iter, _FLAG_MV);
|
|
|
|
verts_sort[i] = v_iter;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
i += 1;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
/* walk onto the next vertex */
|
|
|
|
v_iter = BM_edge_other_vert(e_iter, v_iter);
|
|
|
|
if (i == len) {
|
|
|
|
if (UNLIKELY(v_iter != verts_sort[0])) {
|
|
|
|
goto error;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2015-04-25 17:20:59 +10:00
|
|
|
break;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
e_first = e_iter;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2015-04-25 17:20:59 +10:00
|
|
|
} while ((e_iter = bmesh_disk_edge_next(e_iter, v_iter)) != e_first);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
if (i == len) {
|
|
|
|
return true;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
error:
|
2012-02-19 18:31:04 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2015-04-25 17:20:59 +10:00
|
|
|
BM_ELEM_API_FLAG_DISABLE(edges[i], _FLAG_MF);
|
|
|
|
BM_ELEM_API_FLAG_DISABLE(edges[i]->v1, _FLAG_MV);
|
|
|
|
BM_ELEM_API_FLAG_DISABLE(edges[i]->v2, _FLAG_MV);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
return false;
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
/**
|
|
|
|
* \brief Make NGon
|
|
|
|
*
|
|
|
|
* Makes an ngon from an unordered list of edges.
|
|
|
|
* Verts \a v1 and \a v2 define the winding of the new face.
|
|
|
|
*
|
|
|
|
* \a edges are not required to be ordered, simply to to form
|
|
|
|
* a single closed loop as a whole.
|
|
|
|
*
|
|
|
|
* \note While this function will work fine when the edges
|
|
|
|
* are already sorted, if the edges are always going to be sorted,
|
|
|
|
* #BM_face_create should be considered over this function as it
|
|
|
|
* avoids some unnecessary work.
|
|
|
|
*/
|
|
|
|
BMFace *BM_face_create_ngon(
|
|
|
|
BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, const int len,
|
|
|
|
const BMFace *f_example, const eBMCreateFlag create_flag)
|
|
|
|
{
|
|
|
|
BMEdge **edges_sort = BLI_array_alloca(edges_sort, len);
|
|
|
|
BMVert **verts_sort = BLI_array_alloca(verts_sort, len);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
BLI_assert(len && v1 && v2 && edges && bm);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2015-04-25 17:20:59 +10:00
|
|
|
if (bm_edges_sort_winding(v1, v2, edges, len, edges_sort, verts_sort)) {
|
|
|
|
return BM_face_create(bm, verts_sort, edges_sort, len, f_example, create_flag);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-27 05:52:28 +00:00
|
|
|
/**
|
|
|
|
* Create an ngon from an array of sorted verts
|
|
|
|
*
|
|
|
|
* Special features this has over other functions.
|
|
|
|
* - Optionally calculate winding based on surrounding edges.
|
|
|
|
* - Optionally create edges between vertices.
|
|
|
|
* - Uses verts so no need to find edges (handy when you only have verts)
|
|
|
|
*/
|
2015-04-25 20:15:20 +10:00
|
|
|
BMFace *BM_face_create_ngon_verts(
|
|
|
|
BMesh *bm, BMVert **vert_arr, const int len,
|
|
|
|
const BMFace *f_example, const eBMCreateFlag create_flag,
|
|
|
|
const bool calc_winding, const bool create_edges)
|
2013-03-27 05:52:28 +00:00
|
|
|
{
|
|
|
|
BMEdge **edge_arr = BLI_array_alloca(edge_arr, len);
|
2017-05-06 14:18:31 +10:00
|
|
|
uint winding[2] = {0, 0};
|
2013-03-27 05:52:28 +00:00
|
|
|
int i, i_prev = len - 1;
|
2013-07-25 18:43:05 +00:00
|
|
|
BMVert *v_winding[2] = {vert_arr[i_prev], vert_arr[0]};
|
2013-03-27 05:52:28 +00:00
|
|
|
|
|
|
|
BLI_assert(len > 2);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (create_edges) {
|
|
|
|
edge_arr[i] = BM_edge_create(bm, vert_arr[i_prev], vert_arr[i], NULL, BM_CREATE_NO_DOUBLE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
edge_arr[i] = BM_edge_exists(vert_arr[i_prev], vert_arr[i]);
|
|
|
|
if (edge_arr[i] == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calc_winding) {
|
|
|
|
/* the edge may exist already and be attached to a face
|
|
|
|
* in this case we can find the best winding to use for the new face */
|
|
|
|
if (edge_arr[i]->l) {
|
|
|
|
BMVert *test_v1, *test_v2;
|
|
|
|
/* we want to use the reverse winding to the existing order */
|
|
|
|
BM_edge_ordered_verts(edge_arr[i], &test_v2, &test_v1);
|
|
|
|
winding[(vert_arr[i_prev] == test_v2)]++;
|
2013-07-25 18:16:55 +00:00
|
|
|
BLI_assert(vert_arr[i_prev] == test_v2 || vert_arr[i_prev] == test_v1);
|
2013-03-27 05:52:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i_prev = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- */
|
|
|
|
|
|
|
|
if (calc_winding) {
|
|
|
|
if (winding[0] < winding[1]) {
|
|
|
|
winding[0] = 1;
|
|
|
|
winding[1] = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
winding[0] = 0;
|
|
|
|
winding[1] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
winding[0] = 0;
|
|
|
|
winding[1] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --- */
|
|
|
|
|
|
|
|
/* create the face */
|
2013-07-25 18:16:55 +00:00
|
|
|
return BM_face_create_ngon(
|
|
|
|
bm,
|
2013-07-25 18:43:05 +00:00
|
|
|
v_winding[winding[0]],
|
|
|
|
v_winding[winding[1]],
|
2013-08-21 07:51:47 +00:00
|
|
|
edge_arr, len,
|
|
|
|
f_example, create_flag);
|
2013-03-27 05:52:28 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 22:57:15 +00:00
|
|
|
/**
|
|
|
|
* Makes an NGon from an un-ordered set of verts
|
|
|
|
*
|
|
|
|
* assumes...
|
|
|
|
* - that verts are only once in the list.
|
|
|
|
* - that the verts have roughly planer bounds
|
|
|
|
* - that the verts are roughly circular
|
|
|
|
* there can be concave areas but overlapping folds from the center point will fail.
|
|
|
|
*
|
|
|
|
* a brief explanation of the method used
|
|
|
|
* - find the center point
|
|
|
|
* - find the normal of the vcloud
|
|
|
|
* - order the verts around the face based on their angle to the normal vector at the center point.
|
|
|
|
*
|
|
|
|
* \note Since this is a vcloud there is no direction.
|
|
|
|
*/
|
2017-01-20 06:06:06 +11:00
|
|
|
void BM_verts_sort_radial_plane(BMVert **vert_arr, int len)
|
2012-03-14 22:57:15 +00:00
|
|
|
{
|
2013-09-05 22:24:12 +00:00
|
|
|
struct SortIntByFloat *vang = BLI_array_alloca(vang, len);
|
2013-08-21 05:20:57 +00:00
|
|
|
BMVert **vert_arr_map = BLI_array_alloca(vert_arr_map, len);
|
|
|
|
|
2013-03-27 05:52:28 +00:00
|
|
|
float totv_inv = 1.0f / (float)len;
|
2012-03-14 22:57:15 +00:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
float cent[3], nor[3];
|
|
|
|
|
2014-04-27 00:23:36 +10:00
|
|
|
const float *far = NULL, *far_cross = NULL;
|
2012-03-14 22:57:15 +00:00
|
|
|
|
|
|
|
float far_vec[3];
|
|
|
|
float far_cross_vec[3];
|
|
|
|
float sign_vec[3]; /* work out if we are pos/neg angle */
|
|
|
|
|
2014-02-03 02:46:45 +11:00
|
|
|
float far_dist_sq, far_dist_max_sq;
|
2012-03-14 22:57:15 +00:00
|
|
|
float far_cross_dist, far_cross_best = 0.0f;
|
|
|
|
|
|
|
|
/* get the center point and collect vector array since we loop over these a lot */
|
|
|
|
zero_v3(cent);
|
2013-03-27 05:52:28 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2012-03-14 22:57:15 +00:00
|
|
|
madd_v3_v3fl(cent, vert_arr[i]->co, totv_inv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* find the far point from cent */
|
2014-02-03 02:46:45 +11:00
|
|
|
far_dist_max_sq = 0.0f;
|
2013-03-27 05:52:28 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2014-02-03 02:46:45 +11:00
|
|
|
far_dist_sq = len_squared_v3v3(vert_arr[i]->co, cent);
|
|
|
|
if (far_dist_sq > far_dist_max_sq || far == NULL) {
|
2012-03-14 22:57:15 +00:00
|
|
|
far = vert_arr[i]->co;
|
2014-02-03 02:46:45 +11:00
|
|
|
far_dist_max_sq = far_dist_sq;
|
2012-03-14 22:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_v3_v3v3(far_vec, far, cent);
|
2012-09-19 08:09:22 +00:00
|
|
|
// far_dist = len_v3(far_vec); /* real dist */ /* UNUSED */
|
2012-03-14 22:57:15 +00:00
|
|
|
|
|
|
|
/* --- */
|
|
|
|
|
|
|
|
/* find a point 90deg about to compare with */
|
|
|
|
far_cross_best = 0.0f;
|
2013-03-27 05:52:28 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2012-03-14 22:57:15 +00:00
|
|
|
|
|
|
|
if (far == vert_arr[i]->co) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub_v3_v3v3(far_cross_vec, vert_arr[i]->co, cent);
|
|
|
|
far_cross_dist = normalize_v3(far_cross_vec);
|
|
|
|
|
|
|
|
/* more of a weight then a distance */
|
|
|
|
far_cross_dist = (/* first we want to have a value close to zero mapped to 1 */
|
2012-11-09 09:33:28 +00:00
|
|
|
1.0f - fabsf(dot_v3v3(far_vec, far_cross_vec)) *
|
2012-03-14 22:57:15 +00:00
|
|
|
|
2012-11-09 09:33:28 +00:00
|
|
|
/* second we multiply by the distance
|
|
|
|
* so points close to the center are not preferred */
|
|
|
|
far_cross_dist);
|
2012-03-14 22:57:15 +00:00
|
|
|
|
|
|
|
if (far_cross_dist > far_cross_best || far_cross == NULL) {
|
|
|
|
far_cross = vert_arr[i]->co;
|
|
|
|
far_cross_best = far_cross_dist;
|
|
|
|
}
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-03-14 22:57:15 +00:00
|
|
|
sub_v3_v3v3(far_cross_vec, far_cross, cent);
|
|
|
|
|
|
|
|
/* --- */
|
|
|
|
|
|
|
|
/* now we have 2 vectors we can have a cross product */
|
|
|
|
cross_v3_v3v3(nor, far_vec, far_cross_vec);
|
|
|
|
normalize_v3(nor);
|
|
|
|
cross_v3_v3v3(sign_vec, far_vec, nor); /* this vector should match 'far_cross_vec' closely */
|
|
|
|
|
|
|
|
/* --- */
|
|
|
|
|
2012-04-07 12:37:15 +00:00
|
|
|
/* now calculate every points angle around the normal (signed) */
|
2013-03-27 05:52:28 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2017-01-19 07:59:32 +11:00
|
|
|
vang[i].sort_value = angle_signed_on_axis_v3v3v3_v3(far, cent, vert_arr[i]->co, nor);
|
2013-09-05 22:24:12 +00:00
|
|
|
vang[i].data = i;
|
2017-01-20 06:06:06 +11:00
|
|
|
vert_arr_map[i] = vert_arr[i];
|
2012-03-14 22:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sort by angle and magic! - we have our ngon */
|
2013-09-05 22:24:12 +00:00
|
|
|
qsort(vang, len, sizeof(*vang), BLI_sortutil_cmp_float);
|
2012-03-14 22:57:15 +00:00
|
|
|
|
|
|
|
/* --- */
|
|
|
|
|
2013-03-27 05:52:28 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
2017-01-20 06:06:06 +11:00
|
|
|
vert_arr[i] = vert_arr_map[vang[i].data];
|
2012-03-14 22:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
|
2015-04-25 20:15:20 +10:00
|
|
|
static void bm_vert_attrs_copy(
|
|
|
|
BMesh *source_mesh, BMesh *target_mesh,
|
2018-11-27 11:39:51 +11:00
|
|
|
const BMVert *source_vertex, BMVert *target_vertex, uint64_t cd_mask)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
if ((source_mesh == target_mesh) && (source_vertex == target_vertex)) {
|
2012-10-27 01:33:33 +00:00
|
|
|
BLI_assert(!"BMVert: source and targer match");
|
2012-02-19 18:31:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-27 11:39:51 +11:00
|
|
|
if ((cd_mask & CD_MASK_NORMAL) == 0) {
|
|
|
|
copy_v3_v3(target_vertex->no, source_vertex->no);
|
|
|
|
}
|
2014-09-24 18:50:29 +10:00
|
|
|
CustomData_bmesh_free_block_data(&target_mesh->vdata, target_vertex->head.data);
|
2012-02-19 18:31:04 +00:00
|
|
|
CustomData_bmesh_copy_data(&source_mesh->vdata, &target_mesh->vdata,
|
|
|
|
source_vertex->head.data, &target_vertex->head.data);
|
|
|
|
}
|
|
|
|
|
2015-04-25 20:15:20 +10:00
|
|
|
static void bm_edge_attrs_copy(
|
|
|
|
BMesh *source_mesh, BMesh *target_mesh,
|
2018-11-27 11:39:51 +11:00
|
|
|
const BMEdge *source_edge, BMEdge *target_edge, uint64_t UNUSED(cd_mask))
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
if ((source_mesh == target_mesh) && (source_edge == target_edge)) {
|
2012-10-27 01:33:33 +00:00
|
|
|
BLI_assert(!"BMEdge: source and targer match");
|
2012-02-19 18:31:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-24 18:50:29 +10:00
|
|
|
CustomData_bmesh_free_block_data(&target_mesh->edata, target_edge->head.data);
|
2012-02-19 18:31:04 +00:00
|
|
|
CustomData_bmesh_copy_data(&source_mesh->edata, &target_mesh->edata,
|
|
|
|
source_edge->head.data, &target_edge->head.data);
|
|
|
|
}
|
|
|
|
|
2015-04-25 20:15:20 +10:00
|
|
|
static void bm_loop_attrs_copy(
|
|
|
|
BMesh *source_mesh, BMesh *target_mesh,
|
2018-11-27 11:39:51 +11:00
|
|
|
const BMLoop *source_loop, BMLoop *target_loop, uint64_t UNUSED(cd_mask))
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
if ((source_mesh == target_mesh) && (source_loop == target_loop)) {
|
2012-10-27 01:33:33 +00:00
|
|
|
BLI_assert(!"BMLoop: source and targer match");
|
2012-02-19 18:31:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-24 18:50:29 +10:00
|
|
|
CustomData_bmesh_free_block_data(&target_mesh->ldata, target_loop->head.data);
|
2012-02-19 18:31:04 +00:00
|
|
|
CustomData_bmesh_copy_data(&source_mesh->ldata, &target_mesh->ldata,
|
|
|
|
source_loop->head.data, &target_loop->head.data);
|
|
|
|
}
|
|
|
|
|
2015-04-25 20:15:20 +10:00
|
|
|
static void bm_face_attrs_copy(
|
|
|
|
BMesh *source_mesh, BMesh *target_mesh,
|
2018-11-27 11:39:51 +11:00
|
|
|
const BMFace *source_face, BMFace *target_face, uint64_t cd_mask)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
if ((source_mesh == target_mesh) && (source_face == target_face)) {
|
2012-10-27 01:33:33 +00:00
|
|
|
BLI_assert(!"BMFace: source and targer match");
|
2012-02-19 18:31:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-27 11:39:51 +11:00
|
|
|
if ((cd_mask & CD_MASK_NORMAL) == 0) {
|
|
|
|
copy_v3_v3(target_face->no, source_face->no);
|
|
|
|
}
|
2014-09-24 18:50:29 +10:00
|
|
|
CustomData_bmesh_free_block_data(&target_mesh->pdata, target_face->head.data);
|
2012-02-19 18:31:04 +00:00
|
|
|
CustomData_bmesh_copy_data(&source_mesh->pdata, &target_mesh->pdata,
|
|
|
|
source_face->head.data, &target_face->head.data);
|
|
|
|
target_face->mat_nr = source_face->mat_nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BMESH_TODO: Special handling for hide flags? */
|
2013-07-11 12:43:34 +00:00
|
|
|
/* BMESH_TODO: swap src/dst args, everywhere else in bmesh does other way round */
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
|
|
|
* Copies attributes, e.g. customdata, header flags, etc, from one element
|
|
|
|
* to another of the same type.
|
|
|
|
*/
|
2015-04-25 20:15:20 +10:00
|
|
|
void BM_elem_attrs_copy_ex(
|
|
|
|
BMesh *bm_src, BMesh *bm_dst, const void *ele_src_v, void *ele_dst_v,
|
2018-11-27 11:39:51 +11:00
|
|
|
const char hflag_mask, const uint64_t cd_mask)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2013-07-11 12:43:34 +00:00
|
|
|
const BMHeader *ele_src = ele_src_v;
|
|
|
|
BMHeader *ele_dst = ele_dst_v;
|
2012-02-25 20:58:03 +00:00
|
|
|
|
2013-07-11 12:43:34 +00:00
|
|
|
BLI_assert(ele_src->htype == ele_dst->htype);
|
2013-08-23 13:00:43 +00:00
|
|
|
BLI_assert(ele_src != ele_dst);
|
2012-02-25 20:58:03 +00:00
|
|
|
|
2018-11-27 11:39:51 +11:00
|
|
|
/* Only support normal layer at the moment. */
|
|
|
|
BLI_assert((cd_mask & ~CD_MASK_NORMAL) == 0);
|
|
|
|
|
2013-07-11 12:43:34 +00:00
|
|
|
if ((hflag_mask & BM_ELEM_SELECT) == 0) {
|
|
|
|
/* First we copy select */
|
|
|
|
if (BM_elem_flag_test((BMElem *)ele_src, BM_ELEM_SELECT)) {
|
|
|
|
BM_elem_select_set(bm_dst, (BMElem *)ele_dst, true);
|
|
|
|
}
|
2012-02-25 20:58:03 +00:00
|
|
|
}
|
2013-07-11 12:43:34 +00:00
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* Now we copy flags */
|
2013-07-11 12:43:34 +00:00
|
|
|
if (hflag_mask == 0) {
|
|
|
|
ele_dst->hflag = ele_src->hflag;
|
|
|
|
}
|
2013-07-24 19:31:58 +00:00
|
|
|
else if (hflag_mask == 0xff) {
|
|
|
|
/* pass */
|
|
|
|
}
|
2013-07-11 12:43:34 +00:00
|
|
|
else {
|
|
|
|
ele_dst->hflag = ((ele_dst->hflag & hflag_mask) | (ele_src->hflag & ~hflag_mask));
|
|
|
|
}
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* Copy specific attributes */
|
2013-07-11 12:43:34 +00:00
|
|
|
switch (ele_dst->htype) {
|
2012-02-25 20:58:03 +00:00
|
|
|
case BM_VERT:
|
2018-11-27 11:39:51 +11:00
|
|
|
bm_vert_attrs_copy(bm_src, bm_dst, (const BMVert *)ele_src, (BMVert *)ele_dst, cd_mask);
|
2012-02-25 20:58:03 +00:00
|
|
|
break;
|
|
|
|
case BM_EDGE:
|
2018-11-27 11:39:51 +11:00
|
|
|
bm_edge_attrs_copy(bm_src, bm_dst, (const BMEdge *)ele_src, (BMEdge *)ele_dst, cd_mask);
|
2012-02-25 20:58:03 +00:00
|
|
|
break;
|
|
|
|
case BM_LOOP:
|
2018-11-27 11:39:51 +11:00
|
|
|
bm_loop_attrs_copy(bm_src, bm_dst, (const BMLoop *)ele_src, (BMLoop *)ele_dst, cd_mask);
|
2012-02-25 20:58:03 +00:00
|
|
|
break;
|
|
|
|
case BM_FACE:
|
2018-11-27 11:39:51 +11:00
|
|
|
bm_face_attrs_copy(bm_src, bm_dst, (const BMFace *)ele_src, (BMFace *)ele_dst, cd_mask);
|
2012-02-25 20:58:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BLI_assert(0);
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2012-02-25 20:58:03 +00:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 12:43:34 +00:00
|
|
|
void BM_elem_attrs_copy(BMesh *bm_src, BMesh *bm_dst, const void *ele_src, void *ele_dst)
|
|
|
|
{
|
|
|
|
/* BMESH_TODO, default 'use_flags' to false */
|
2018-11-27 11:39:51 +11:00
|
|
|
BM_elem_attrs_copy_ex(bm_src, bm_dst, ele_src, ele_dst, BM_ELEM_SELECT, 0x0);
|
2013-07-24 19:31:58 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 14:21:15 +11:00
|
|
|
void BM_elem_select_copy(BMesh *bm_dst, void *ele_dst_v, const void *ele_src_v)
|
2013-07-24 19:31:58 +00:00
|
|
|
{
|
|
|
|
BMHeader *ele_dst = ele_dst_v;
|
2013-08-13 00:35:23 +00:00
|
|
|
const BMHeader *ele_src = ele_src_v;
|
2013-07-24 19:31:58 +00:00
|
|
|
|
|
|
|
BLI_assert(ele_src->htype == ele_dst->htype);
|
|
|
|
|
|
|
|
if ((ele_src->hflag & BM_ELEM_SELECT) != (ele_dst->hflag & BM_ELEM_SELECT)) {
|
|
|
|
BM_elem_select_set(bm_dst, (BMElem *)ele_dst, (ele_src->hflag & BM_ELEM_SELECT) != 0);
|
|
|
|
}
|
2013-07-11 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 12:02:29 +00:00
|
|
|
/* helper function for 'BM_mesh_copy' */
|
2015-04-25 20:15:20 +10:00
|
|
|
static BMFace *bm_mesh_copy_new_face(
|
|
|
|
BMesh *bm_new, BMesh *bm_old,
|
|
|
|
BMVert **vtable, BMEdge **etable,
|
|
|
|
BMFace *f)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2013-05-25 20:47:06 +00:00
|
|
|
BMLoop **loops = BLI_array_alloca(loops, f->len);
|
|
|
|
BMVert **verts = BLI_array_alloca(verts, f->len);
|
|
|
|
BMEdge **edges = BLI_array_alloca(edges, f->len);
|
|
|
|
|
|
|
|
BMFace *f_new;
|
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
do {
|
|
|
|
loops[j] = l_iter;
|
|
|
|
verts[j] = vtable[BM_elem_index_get(l_iter->v)];
|
|
|
|
edges[j] = etable[BM_elem_index_get(l_iter->e)];
|
|
|
|
j++;
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
2013-08-21 07:51:47 +00:00
|
|
|
f_new = BM_face_create(bm_new, verts, edges, f->len, NULL, BM_CREATE_SKIP_CD);
|
2013-05-25 20:47:06 +00:00
|
|
|
|
|
|
|
if (UNLIKELY(f_new == NULL)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-12-19 09:13:06 +00:00
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
/* use totface in case adding some faces fails */
|
|
|
|
BM_elem_index_set(f_new, (bm_new->totface - 1)); /* set_inline */
|
|
|
|
|
2018-11-27 11:39:51 +11:00
|
|
|
BM_elem_attrs_copy_ex(bm_old, bm_new, f, f_new, 0xff, 0x0);
|
2013-07-24 19:31:58 +00:00
|
|
|
f_new->head.hflag = f->head.hflag; /* low level! don't do this for normal api use */
|
2013-05-25 20:47:06 +00:00
|
|
|
|
|
|
|
j = 0;
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f_new);
|
|
|
|
do {
|
|
|
|
BM_elem_attrs_copy(bm_old, bm_new, loops[j], l_iter);
|
|
|
|
j++;
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
|
|
|
return f_new;
|
|
|
|
}
|
|
|
|
|
2013-07-11 04:24:36 +00:00
|
|
|
void BM_mesh_copy_init_customdata(BMesh *bm_dst, BMesh *bm_src, const BMAllocTemplate *allocsize)
|
|
|
|
{
|
|
|
|
if (allocsize == NULL) {
|
|
|
|
allocsize = &bm_mesh_allocsize_default;
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomData_copy(&bm_src->vdata, &bm_dst->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
|
|
|
|
CustomData_copy(&bm_src->edata, &bm_dst->edata, CD_MASK_BMESH, CD_CALLOC, 0);
|
|
|
|
CustomData_copy(&bm_src->ldata, &bm_dst->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
|
|
|
|
CustomData_copy(&bm_src->pdata, &bm_dst->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
|
|
|
|
|
|
|
|
CustomData_bmesh_init_pool(&bm_dst->vdata, allocsize->totvert, BM_VERT);
|
|
|
|
CustomData_bmesh_init_pool(&bm_dst->edata, allocsize->totedge, BM_EDGE);
|
|
|
|
CustomData_bmesh_init_pool(&bm_dst->ldata, allocsize->totloop, BM_LOOP);
|
|
|
|
CustomData_bmesh_init_pool(&bm_dst->pdata, allocsize->totface, BM_FACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
BMesh *BM_mesh_copy(BMesh *bm_old)
|
|
|
|
{
|
2012-03-01 22:17:04 +00:00
|
|
|
BMesh *bm_new;
|
2013-05-25 20:47:06 +00:00
|
|
|
BMVert *v, *v_new, **vtable = NULL;
|
|
|
|
BMEdge *e, *e_new, **etable = NULL;
|
|
|
|
BMFace *f, *f_new, **ftable = NULL;
|
2012-04-24 21:19:18 +00:00
|
|
|
BMElem **eletable;
|
2012-02-19 18:31:04 +00:00
|
|
|
BMEditSelection *ese;
|
2013-05-25 20:47:06 +00:00
|
|
|
BMIter iter;
|
|
|
|
int i;
|
2013-09-24 03:31:00 +00:00
|
|
|
const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_BM(bm_old);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
/* allocate a bmesh */
|
2016-07-01 19:07:11 +10:00
|
|
|
bm_new = BM_mesh_create(
|
|
|
|
&allocsize,
|
|
|
|
&((struct BMeshCreateParams){.use_toolflags = bm_old->use_toolflags,}));
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-07-11 04:24:36 +00:00
|
|
|
BM_mesh_copy_init_customdata(bm_new, bm_old, &allocsize);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-03-01 22:17:04 +00:00
|
|
|
vtable = MEM_mallocN(sizeof(BMVert *) * bm_old->totvert, "BM_mesh_copy vtable");
|
|
|
|
etable = MEM_mallocN(sizeof(BMEdge *) * bm_old->totedge, "BM_mesh_copy etable");
|
|
|
|
ftable = MEM_mallocN(sizeof(BMFace *) * bm_old->totface, "BM_mesh_copy ftable");
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
BM_ITER_MESH_INDEX (v, &iter, bm_old, BM_VERTS_OF_MESH, i) {
|
2013-05-26 12:02:29 +00:00
|
|
|
/* copy between meshes so cant use 'example' argument */
|
|
|
|
v_new = BM_vert_create(bm_new, v->co, NULL, BM_CREATE_SKIP_CD);
|
2018-11-27 11:39:51 +11:00
|
|
|
BM_elem_attrs_copy_ex(bm_old, bm_new, v, v_new, 0xff, 0x0);
|
2013-07-24 19:31:58 +00:00
|
|
|
v_new->head.hflag = v->head.hflag; /* low level! don't do this for normal api use */
|
2013-05-25 20:47:06 +00:00
|
|
|
vtable[i] = v_new;
|
2012-02-19 18:31:04 +00:00
|
|
|
BM_elem_index_set(v, i); /* set_inline */
|
2013-05-25 20:47:06 +00:00
|
|
|
BM_elem_index_set(v_new, i); /* set_inline */
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2012-03-01 22:17:04 +00:00
|
|
|
bm_old->elem_index_dirty &= ~BM_VERT;
|
|
|
|
bm_new->elem_index_dirty &= ~BM_VERT;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
/* safety check */
|
2012-03-01 22:17:04 +00:00
|
|
|
BLI_assert(i == bm_old->totvert);
|
2018-06-04 08:48:38 +02:00
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
BM_ITER_MESH_INDEX (e, &iter, bm_old, BM_EDGES_OF_MESH, i) {
|
|
|
|
e_new = BM_edge_create(bm_new,
|
|
|
|
vtable[BM_elem_index_get(e->v1)],
|
|
|
|
vtable[BM_elem_index_get(e->v2)],
|
|
|
|
e, BM_CREATE_SKIP_CD);
|
|
|
|
|
2018-11-27 11:39:51 +11:00
|
|
|
BM_elem_attrs_copy_ex(bm_old, bm_new, e, e_new, 0xff, 0x0);
|
2013-07-24 19:31:58 +00:00
|
|
|
e_new->head.hflag = e->head.hflag; /* low level! don't do this for normal api use */
|
2013-05-25 20:47:06 +00:00
|
|
|
etable[i] = e_new;
|
2012-02-19 18:31:04 +00:00
|
|
|
BM_elem_index_set(e, i); /* set_inline */
|
2013-05-25 20:47:06 +00:00
|
|
|
BM_elem_index_set(e_new, i); /* set_inline */
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2012-03-01 22:17:04 +00:00
|
|
|
bm_old->elem_index_dirty &= ~BM_EDGE;
|
|
|
|
bm_new->elem_index_dirty &= ~BM_EDGE;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
/* safety check */
|
2012-03-01 22:17:04 +00:00
|
|
|
BLI_assert(i == bm_old->totedge);
|
2018-06-04 08:48:38 +02:00
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
BM_ITER_MESH_INDEX (f, &iter, bm_old, BM_FACES_OF_MESH, i) {
|
2012-02-19 18:31:04 +00:00
|
|
|
BM_elem_index_set(f, i); /* set_inline */
|
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
f_new = bm_mesh_copy_new_face(bm_new, bm_old, vtable, etable, f);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
ftable[i] = f_new;
|
2012-12-19 09:13:06 +00:00
|
|
|
|
2013-05-25 20:47:06 +00:00
|
|
|
if (f == bm_old->act_face) bm_new->act_face = f_new;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2012-03-01 22:17:04 +00:00
|
|
|
bm_old->elem_index_dirty &= ~BM_FACE;
|
|
|
|
bm_new->elem_index_dirty &= ~BM_FACE;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-07-24 19:31:58 +00:00
|
|
|
|
|
|
|
/* low level! don't do this for normal api use */
|
|
|
|
bm_new->totvertsel = bm_old->totvertsel;
|
|
|
|
bm_new->totedgesel = bm_old->totedgesel;
|
|
|
|
bm_new->totfacesel = bm_old->totfacesel;
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* safety check */
|
2012-03-01 22:17:04 +00:00
|
|
|
BLI_assert(i == bm_old->totface);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
/* copy over edit selection history */
|
2012-03-01 22:17:04 +00:00
|
|
|
for (ese = bm_old->selected.first; ese; ese = ese->next) {
|
2012-04-24 21:19:18 +00:00
|
|
|
BMElem *ele = NULL;
|
|
|
|
|
|
|
|
switch (ese->htype) {
|
|
|
|
case BM_VERT:
|
|
|
|
eletable = (BMElem **)vtable;
|
|
|
|
break;
|
|
|
|
case BM_EDGE:
|
|
|
|
eletable = (BMElem **)etable;
|
|
|
|
break;
|
|
|
|
case BM_FACE:
|
|
|
|
eletable = (BMElem **)ftable;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
eletable = NULL;
|
|
|
|
break;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2012-04-24 21:19:18 +00:00
|
|
|
|
|
|
|
if (eletable) {
|
|
|
|
ele = eletable[BM_elem_index_get(ese->ele)];
|
|
|
|
if (ele) {
|
|
|
|
BM_select_history_store(bm_new, ele);
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(etable);
|
|
|
|
MEM_freeN(vtable);
|
|
|
|
MEM_freeN(ftable);
|
|
|
|
|
2012-03-01 22:17:04 +00:00
|
|
|
return bm_new;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ME -> BM */
|
|
|
|
char BM_vert_flag_from_mflag(const char meflag)
|
|
|
|
{
|
|
|
|
return ( ((meflag & SELECT) ? BM_ELEM_SELECT : 0) |
|
|
|
|
((meflag & ME_HIDE) ? BM_ELEM_HIDDEN : 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
char BM_edge_flag_from_mflag(const short meflag)
|
|
|
|
{
|
|
|
|
return ( ((meflag & SELECT) ? BM_ELEM_SELECT : 0) |
|
|
|
|
((meflag & ME_SEAM) ? BM_ELEM_SEAM : 0) |
|
2012-05-22 07:26:45 +00:00
|
|
|
((meflag & ME_EDGEDRAW) ? BM_ELEM_DRAW : 0) |
|
2012-02-19 18:31:04 +00:00
|
|
|
((meflag & ME_SHARP) == 0 ? BM_ELEM_SMOOTH : 0) | /* invert */
|
|
|
|
((meflag & ME_HIDE) ? BM_ELEM_HIDDEN : 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
char BM_face_flag_from_mflag(const char meflag)
|
|
|
|
{
|
|
|
|
return ( ((meflag & ME_FACE_SEL) ? BM_ELEM_SELECT : 0) |
|
|
|
|
((meflag & ME_SMOOTH) ? BM_ELEM_SMOOTH : 0) |
|
|
|
|
((meflag & ME_HIDE) ? BM_ELEM_HIDDEN : 0)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* BM -> ME */
|
|
|
|
char BM_vert_flag_to_mflag(BMVert *eve)
|
|
|
|
{
|
|
|
|
const char hflag = eve->head.hflag;
|
|
|
|
|
|
|
|
return ( ((hflag & BM_ELEM_SELECT) ? SELECT : 0) |
|
|
|
|
((hflag & BM_ELEM_HIDDEN) ? ME_HIDE : 0)
|
|
|
|
);
|
|
|
|
}
|
2012-05-22 07:26:45 +00:00
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
short BM_edge_flag_to_mflag(BMEdge *eed)
|
|
|
|
{
|
|
|
|
const char hflag = eed->head.hflag;
|
|
|
|
|
2012-05-22 07:26:45 +00:00
|
|
|
return ( ((hflag & BM_ELEM_SELECT) ? SELECT : 0) |
|
|
|
|
((hflag & BM_ELEM_SEAM) ? ME_SEAM : 0) |
|
|
|
|
((hflag & BM_ELEM_DRAW) ? ME_EDGEDRAW : 0) |
|
|
|
|
((hflag & BM_ELEM_SMOOTH) == 0 ? ME_SHARP : 0) |
|
|
|
|
((hflag & BM_ELEM_HIDDEN) ? ME_HIDE : 0) |
|
|
|
|
((BM_edge_is_wire(eed)) ? ME_LOOSEEDGE : 0) | /* not typical */
|
|
|
|
ME_EDGERENDER
|
2012-02-19 18:31:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
char BM_face_flag_to_mflag(BMFace *efa)
|
|
|
|
{
|
|
|
|
const char hflag = efa->head.hflag;
|
|
|
|
|
|
|
|
return ( ((hflag & BM_ELEM_SELECT) ? ME_FACE_SEL : 0) |
|
|
|
|
((hflag & BM_ELEM_SMOOTH) ? ME_SMOOTH : 0) |
|
|
|
|
((hflag & BM_ELEM_HIDDEN) ? ME_HIDE : 0)
|
|
|
|
);
|
|
|
|
}
|