2012-02-19 18:31:04 +00:00
|
|
|
/*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Geoffrey Bantle.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/bmesh/intern/bmesh_mesh.c
|
|
|
|
|
* \ingroup bmesh
|
|
|
|
|
*
|
|
|
|
|
* BM mesh level functions.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_listBase.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
#include "BLI_linklist_stack.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_math.h"
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
#include "BLI_stack.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
2013-04-13 20:31:52 +00:00
|
|
|
#include "BKE_editmesh.h"
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
#include "BKE_mesh.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
#include "BKE_multires.h"
|
|
|
|
|
|
2012-03-08 03:25:53 +00:00
|
|
|
#include "intern/bmesh_private.h"
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
/* used as an extern, defined in bmesh.h */
|
2012-12-03 05:38:28 +00:00
|
|
|
const BMAllocTemplate bm_mesh_allocsize_default = {512, 1024, 2048, 512};
|
|
|
|
|
const BMAllocTemplate bm_mesh_chunksize_default = {512, 1024, 2048, 512};
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-03-01 20:09:17 +00:00
|
|
|
static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2012-05-03 19:57:24 +00:00
|
|
|
bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize->totvert,
|
|
|
|
|
bm_mesh_chunksize_default.totvert, BLI_MEMPOOL_ALLOW_ITER);
|
|
|
|
|
bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize->totedge,
|
|
|
|
|
bm_mesh_chunksize_default.totedge, BLI_MEMPOOL_ALLOW_ITER);
|
|
|
|
|
bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize->totloop,
|
2014-04-05 10:57:32 +11:00
|
|
|
bm_mesh_chunksize_default.totloop, BLI_MEMPOOL_NOP);
|
2012-05-03 19:57:24 +00:00
|
|
|
bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize->totface,
|
|
|
|
|
bm_mesh_chunksize_default.totface, BLI_MEMPOOL_ALLOW_ITER);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
#ifdef USE_BMESH_HOLES
|
2014-04-05 10:57:32 +11:00
|
|
|
bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), 512, 512, BLI_MEMPOOL_NOP);
|
2012-02-19 18:31:04 +00:00
|
|
|
#endif
|
2012-11-18 12:14:22 +00:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-11-18 12:14:22 +00:00
|
|
|
void BM_mesh_elem_toolflags_ensure(BMesh *bm)
|
|
|
|
|
{
|
2012-12-12 05:04:01 +00:00
|
|
|
if (bm->vtoolflagpool && bm->etoolflagpool && bm->ftoolflagpool) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-11-18 12:14:22 +00:00
|
|
|
|
2014-04-08 11:59:28 +10:00
|
|
|
bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), bm->totvert, 512, BLI_MEMPOOL_NOP);
|
|
|
|
|
bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), bm->totedge, 512, BLI_MEMPOOL_NOP);
|
|
|
|
|
bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), bm->totface, 512, BLI_MEMPOOL_NOP);
|
2012-12-12 05:04:01 +00:00
|
|
|
|
2012-12-12 07:20:34 +00:00
|
|
|
#pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
|
2012-12-12 05:04:01 +00:00
|
|
|
{
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
BLI_mempool *toolflagpool = bm->vtoolflagpool;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMElemF *ele;
|
|
|
|
|
BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
|
|
|
|
|
ele->oflags = BLI_mempool_calloc(toolflagpool);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
BLI_mempool *toolflagpool = bm->etoolflagpool;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMElemF *ele;
|
|
|
|
|
BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
|
|
|
|
|
ele->oflags = BLI_mempool_calloc(toolflagpool);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
BLI_mempool *toolflagpool = bm->ftoolflagpool;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMElemF *ele;
|
|
|
|
|
BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
|
2012-11-18 12:14:22 +00:00
|
|
|
ele->oflags = BLI_mempool_calloc(toolflagpool);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-12-12 05:04:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
bm->totflags = 1;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-19 23:52:24 +00:00
|
|
|
void BM_mesh_elem_toolflags_clear(BMesh *bm)
|
|
|
|
|
{
|
2012-12-12 05:04:01 +00:00
|
|
|
if (bm->vtoolflagpool) {
|
|
|
|
|
BLI_mempool_destroy(bm->vtoolflagpool);
|
|
|
|
|
bm->vtoolflagpool = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (bm->etoolflagpool) {
|
|
|
|
|
BLI_mempool_destroy(bm->etoolflagpool);
|
|
|
|
|
bm->etoolflagpool = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (bm->ftoolflagpool) {
|
|
|
|
|
BLI_mempool_destroy(bm->ftoolflagpool);
|
|
|
|
|
bm->ftoolflagpool = NULL;
|
2012-11-19 23:52:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-29 06:55:10 +00:00
|
|
|
* \brief BMesh Make Mesh
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* Allocates a new BMesh structure.
|
|
|
|
|
*
|
|
|
|
|
* \return The New bmesh
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-28 18:28:30 +00:00
|
|
|
* \note ob is needed by multires
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2012-12-03 05:38:28 +00:00
|
|
|
BMesh *BM_mesh_create(const BMAllocTemplate *allocsize)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
/* allocate the structure */
|
|
|
|
|
BMesh *bm = MEM_callocN(sizeof(BMesh), __func__);
|
|
|
|
|
|
|
|
|
|
/* allocate the memory pools for the mesh elements */
|
2012-02-28 19:10:53 +00:00
|
|
|
bm_mempool_init(bm, allocsize);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-03-18 07:38:51 +00:00
|
|
|
/* allocate one flag pool that we don't get rid of. */
|
2012-02-19 18:31:04 +00:00
|
|
|
bm->stackdepth = 1;
|
2012-11-18 12:14:22 +00:00
|
|
|
bm->totflags = 0;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-10-31 09:50:24 +00:00
|
|
|
CustomData_reset(&bm->vdata);
|
|
|
|
|
CustomData_reset(&bm->edata);
|
|
|
|
|
CustomData_reset(&bm->ldata);
|
|
|
|
|
CustomData_reset(&bm->pdata);
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
return bm;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-29 06:55:10 +00:00
|
|
|
* \brief BMesh Free Mesh Data
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
|
|
|
|
* Frees a BMesh structure.
|
2012-02-28 18:28:30 +00:00
|
|
|
*
|
|
|
|
|
* \note frees mesh, but not actual BMesh struct
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
|
|
|
|
void BM_mesh_data_free(BMesh *bm)
|
|
|
|
|
{
|
|
|
|
|
BMVert *v;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
BMLoop *l;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
|
2012-04-03 00:28:38 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMIter itersub;
|
2013-05-08 12:59:56 +00:00
|
|
|
|
2013-05-09 07:02:51 +00:00
|
|
|
const bool is_ldata_free = CustomData_bmesh_has_free(&bm->ldata);
|
|
|
|
|
const bool is_pdata_free = CustomData_bmesh_has_free(&bm->pdata);
|
2013-05-08 12:59:56 +00:00
|
|
|
|
|
|
|
|
/* Check if we have to call free, if not we can avoid a lot of looping */
|
|
|
|
|
if (CustomData_bmesh_has_free(&(bm->vdata))) {
|
|
|
|
|
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
|
|
|
|
|
CustomData_bmesh_free_block(&(bm->vdata), &(v->head.data));
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2013-05-08 12:59:56 +00:00
|
|
|
if (CustomData_bmesh_has_free(&(bm->edata))) {
|
|
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
|
|
|
|
CustomData_bmesh_free_block(&(bm->edata), &(e->head.data));
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2013-05-08 12:59:56 +00:00
|
|
|
|
2013-05-09 07:02:51 +00:00
|
|
|
if (is_ldata_free || is_pdata_free) {
|
2013-05-08 12:59:56 +00:00
|
|
|
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
|
|
|
|
if (is_pdata_free)
|
|
|
|
|
CustomData_bmesh_free_block(&(bm->pdata), &(f->head.data));
|
|
|
|
|
if (is_ldata_free) {
|
|
|
|
|
BM_ITER_ELEM (l, &itersub, f, BM_LOOPS_OF_FACE) {
|
|
|
|
|
CustomData_bmesh_free_block(&(bm->ldata), &(l->head.data));
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free custom data pools, This should probably go in CustomData_free? */
|
|
|
|
|
if (bm->vdata.totlayer) BLI_mempool_destroy(bm->vdata.pool);
|
|
|
|
|
if (bm->edata.totlayer) BLI_mempool_destroy(bm->edata.pool);
|
|
|
|
|
if (bm->ldata.totlayer) BLI_mempool_destroy(bm->ldata.pool);
|
|
|
|
|
if (bm->pdata.totlayer) BLI_mempool_destroy(bm->pdata.pool);
|
|
|
|
|
|
|
|
|
|
/* free custom data */
|
|
|
|
|
CustomData_free(&bm->vdata, 0);
|
|
|
|
|
CustomData_free(&bm->edata, 0);
|
|
|
|
|
CustomData_free(&bm->ldata, 0);
|
|
|
|
|
CustomData_free(&bm->pdata, 0);
|
|
|
|
|
|
|
|
|
|
/* destroy element pools */
|
|
|
|
|
BLI_mempool_destroy(bm->vpool);
|
|
|
|
|
BLI_mempool_destroy(bm->epool);
|
|
|
|
|
BLI_mempool_destroy(bm->lpool);
|
|
|
|
|
BLI_mempool_destroy(bm->fpool);
|
|
|
|
|
|
2013-10-28 02:05:33 +00:00
|
|
|
if (bm->vtable) MEM_freeN(bm->vtable);
|
|
|
|
|
if (bm->etable) MEM_freeN(bm->etable);
|
|
|
|
|
if (bm->ftable) MEM_freeN(bm->ftable);
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* destroy flag pool */
|
2012-11-19 23:52:24 +00:00
|
|
|
BM_mesh_elem_toolflags_clear(bm);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
#ifdef USE_BMESH_HOLES
|
|
|
|
|
BLI_mempool_destroy(bm->looplistpool);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(&bm->selected);
|
|
|
|
|
|
|
|
|
|
BMO_error_clear(bm);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:28:30 +00:00
|
|
|
/**
|
2012-02-29 06:55:10 +00:00
|
|
|
* \brief BMesh Clear Mesh
|
|
|
|
|
*
|
|
|
|
|
* Clear all data in bm
|
2012-02-28 18:28:30 +00:00
|
|
|
*/
|
2012-02-19 18:31:04 +00:00
|
|
|
void BM_mesh_clear(BMesh *bm)
|
|
|
|
|
{
|
|
|
|
|
/* free old mesh */
|
|
|
|
|
BM_mesh_data_free(bm);
|
|
|
|
|
memset(bm, 0, sizeof(BMesh));
|
2012-03-11 19:58:56 +00:00
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* allocate the memory pools for the mesh elements */
|
2012-03-01 20:09:17 +00:00
|
|
|
bm_mempool_init(bm, &bm_mesh_allocsize_default);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
bm->stackdepth = 1;
|
2013-07-10 13:06:31 +00:00
|
|
|
bm->totflags = 0;
|
2012-12-03 05:40:48 +00:00
|
|
|
|
|
|
|
|
CustomData_reset(&bm->vdata);
|
|
|
|
|
CustomData_reset(&bm->edata);
|
|
|
|
|
CustomData_reset(&bm->ldata);
|
|
|
|
|
CustomData_reset(&bm->pdata);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/**
|
|
|
|
|
* \brief BMesh Free Mesh
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* Frees a BMesh data and its structure.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
|
|
|
|
void BM_mesh_free(BMesh *bm)
|
|
|
|
|
{
|
|
|
|
|
BM_mesh_data_free(bm);
|
2012-03-11 05:58:22 +00:00
|
|
|
|
|
|
|
|
if (bm->py_handle) {
|
2013-02-06 14:02:19 +00:00
|
|
|
/* keep this out of 'BM_mesh_data_free' because we want python
|
2012-03-11 05:58:22 +00:00
|
|
|
* to be able to clear the mesh and maintain access. */
|
|
|
|
|
bpy_bm_generic_invalidate(bm->py_handle);
|
|
|
|
|
bm->py_handle = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
MEM_freeN(bm);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/**
|
2014-02-12 20:48:09 +01:00
|
|
|
* Helpers for #BM_mesh_normals_update and #BM_verts_calc_normal_vcos
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2014-02-12 20:48:09 +01:00
|
|
|
static void bm_mesh_edges_calc_vectors(BMesh *bm, float (*edgevec)[3], const float (*vcos)[3])
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2014-02-12 20:48:09 +01:00
|
|
|
BMIter eiter;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
int index;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2014-02-12 20:48:09 +01:00
|
|
|
if (vcos) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2014-02-12 20:48:09 +01:00
|
|
|
BM_ITER_MESH_INDEX (e, &eiter, bm, BM_EDGES_OF_MESH, index) {
|
|
|
|
|
BM_elem_index_set(e, index); /* set_inline */
|
|
|
|
|
|
|
|
|
|
if (e->l) {
|
|
|
|
|
const float *v1_co = vcos ? vcos[BM_elem_index_get(e->v1)] : e->v1->co;
|
|
|
|
|
const float *v2_co = vcos ? vcos[BM_elem_index_get(e->v2)] : e->v2->co;
|
|
|
|
|
sub_v3_v3v3(edgevec[index], v2_co, v1_co);
|
|
|
|
|
normalize_v3(edgevec[index]);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2014-02-12 20:48:09 +01:00
|
|
|
else {
|
|
|
|
|
/* the edge vector will not be needed when the edge has no radial */
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-12 20:48:09 +01:00
|
|
|
bm->elem_index_dirty &= ~BM_EDGE;
|
|
|
|
|
}
|
2013-04-24 12:07:13 +00:00
|
|
|
|
2015-04-25 20:15:20 +10:00
|
|
|
static void bm_mesh_verts_calc_normals(
|
|
|
|
|
BMesh *bm, const float (*edgevec)[3], const float (*fnos)[3],
|
|
|
|
|
const float (*vcos)[3], float (*vnos)[3])
|
2014-02-12 20:48:09 +01:00
|
|
|
{
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, (vnos) ? (BM_EDGE | BM_VERT) : BM_EDGE);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
/* add weighted face normals to vertices */
|
2013-04-24 12:07:13 +00:00
|
|
|
{
|
|
|
|
|
BMIter fiter;
|
|
|
|
|
BMFace *f;
|
2014-02-12 20:48:09 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BM_ITER_MESH_INDEX (f, &fiter, bm, BM_FACES_OF_MESH, i) {
|
2013-04-24 12:07:13 +00:00
|
|
|
BMLoop *l_first, *l_iter;
|
2014-02-12 20:48:09 +01:00
|
|
|
const float *f_no = fnos ? fnos[i] : f->no;
|
|
|
|
|
|
2013-04-24 12:07:13 +00:00
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
|
do {
|
|
|
|
|
const float *e1diff, *e2diff;
|
|
|
|
|
float dotprod;
|
|
|
|
|
float fac;
|
2014-02-12 20:48:09 +01:00
|
|
|
float *v_no = vnos ? vnos[BM_elem_index_get(l_iter->v)] : l_iter->v->no;
|
2013-04-24 12:07:13 +00:00
|
|
|
|
|
|
|
|
/* calculate the dot product of the two edges that
|
|
|
|
|
* meet at the loop's vertex */
|
|
|
|
|
e1diff = edgevec[BM_elem_index_get(l_iter->prev->e)];
|
|
|
|
|
e2diff = edgevec[BM_elem_index_get(l_iter->e)];
|
|
|
|
|
dotprod = dot_v3v3(e1diff, e2diff);
|
|
|
|
|
|
|
|
|
|
/* edge vectors are calculated from e->v1 to e->v2, so
|
|
|
|
|
* adjust the dot product if one but not both loops
|
|
|
|
|
* actually runs from from e->v2 to e->v1 */
|
|
|
|
|
if ((l_iter->prev->e->v1 == l_iter->prev->v) ^ (l_iter->e->v1 == l_iter->v)) {
|
|
|
|
|
dotprod = -dotprod;
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-04-24 12:07:13 +00:00
|
|
|
fac = saacos(-dotprod);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2013-04-24 12:07:13 +00:00
|
|
|
/* accumulate weighted face normal into the vertex's normal */
|
2014-02-12 20:48:09 +01:00
|
|
|
madd_v3_v3fl(v_no, f_no, fac);
|
2013-04-24 12:07:13 +00:00
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
2013-04-24 12:07:13 +00:00
|
|
|
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
/* normalize the accumulated vertex normals */
|
2013-04-24 12:07:13 +00:00
|
|
|
{
|
|
|
|
|
BMIter viter;
|
|
|
|
|
BMVert *v;
|
2014-02-12 20:48:09 +01:00
|
|
|
int i;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2014-02-12 20:48:09 +01:00
|
|
|
BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
float *v_no = vnos ? vnos[i] : v->no;
|
|
|
|
|
if (UNLIKELY(normalize_v3(v_no) == 0.0f)) {
|
|
|
|
|
const float *v_co = vcos ? vcos[i] : v->co;
|
|
|
|
|
normalize_v3_v3(v_no, v_co);
|
2013-04-24 12:07:13 +00:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-12 20:48:09 +01:00
|
|
|
/**
|
|
|
|
|
* \brief BMesh Compute Normals
|
|
|
|
|
*
|
|
|
|
|
* Updates the normals of a mesh.
|
|
|
|
|
*/
|
|
|
|
|
void BM_mesh_normals_update(BMesh *bm)
|
|
|
|
|
{
|
|
|
|
|
float (*edgevec)[3] = MEM_mallocN(sizeof(*edgevec) * bm->totedge, __func__);
|
|
|
|
|
|
|
|
|
|
#pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
|
|
|
|
|
{
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
/* calculate all face normals */
|
|
|
|
|
BMIter fiter;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BM_ITER_MESH_INDEX (f, &fiter, bm, BM_FACES_OF_MESH, i) {
|
|
|
|
|
BM_elem_index_set(f, i); /* set_inline */
|
|
|
|
|
BM_face_normal_update(f);
|
|
|
|
|
}
|
|
|
|
|
bm->elem_index_dirty &= ~BM_FACE;
|
|
|
|
|
}
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
/* Zero out vertex normals */
|
|
|
|
|
BMIter viter;
|
|
|
|
|
BMVert *v;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
BM_elem_index_set(v, i); /* set_inline */
|
|
|
|
|
zero_v3(v->no);
|
|
|
|
|
}
|
|
|
|
|
bm->elem_index_dirty &= ~BM_VERT;
|
|
|
|
|
}
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
/* Compute normalized direction vectors for each edge.
|
|
|
|
|
* Directions will be used for calculating the weights of the face normals on the vertex normals.
|
|
|
|
|
*/
|
|
|
|
|
bm_mesh_edges_calc_vectors(bm, edgevec, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* end omp */
|
|
|
|
|
|
|
|
|
|
/* Add weighted face normals to vertices, and normalize vert normals. */
|
|
|
|
|
bm_mesh_verts_calc_normals(bm, (const float(*)[3])edgevec, NULL, NULL, NULL);
|
|
|
|
|
MEM_freeN(edgevec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \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).
|
|
|
|
|
*/
|
|
|
|
|
void BM_verts_calc_normal_vcos(BMesh *bm, const float (*fnos)[3], const float (*vcos)[3], float (*vnos)[3])
|
|
|
|
|
{
|
|
|
|
|
float (*edgevec)[3] = MEM_mallocN(sizeof(*edgevec) * bm->totedge, __func__);
|
|
|
|
|
|
|
|
|
|
/* Compute normalized direction vectors for each edge.
|
|
|
|
|
* Directions will be used for calculating the weights of the face normals on the vertex normals.
|
|
|
|
|
*/
|
|
|
|
|
bm_mesh_edges_calc_vectors(bm, edgevec, vcos);
|
|
|
|
|
|
|
|
|
|
/* Add weighted face normals to vertices, and normalize vert normals. */
|
|
|
|
|
bm_mesh_verts_calc_normals(bm, (const float(*)[3])edgevec, fnos, vcos, vnos);
|
|
|
|
|
MEM_freeN(edgevec);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
/**
|
|
|
|
|
* Helpers for #BM_mesh_loop_normals_update and #BM_loops_calc_normals_vnos
|
|
|
|
|
*/
|
2015-04-25 20:15:20 +10:00
|
|
|
static void bm_mesh_edges_sharp_tag(
|
|
|
|
|
BMesh *bm, const float (*vnos)[3], const float (*fnos)[3], float split_angle,
|
|
|
|
|
float (*r_lnos)[3])
|
2014-04-13 12:25:02 +02:00
|
|
|
{
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
BMIter eiter, viter;
|
|
|
|
|
BMVert *v;
|
2014-04-13 12:25:02 +02:00
|
|
|
BMEdge *e;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
const bool check_angle = (split_angle < (float)M_PI);
|
|
|
|
|
|
|
|
|
|
if (check_angle) {
|
|
|
|
|
split_angle = cosf(split_angle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2014-06-05 18:37:53 +10:00
|
|
|
char htype = BM_LOOP;
|
2014-04-15 16:18:27 +02:00
|
|
|
if (fnos) {
|
2014-06-05 18:37:53 +10:00
|
|
|
htype |= BM_FACE;
|
2014-04-15 16:18:27 +02:00
|
|
|
}
|
2014-06-05 18:37:53 +10:00
|
|
|
BM_mesh_elem_index_ensure(bm, htype);
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
/* Clear all vertices' tags (means they are all smooth for now). */
|
|
|
|
|
BM_ITER_MESH_INDEX (v, &viter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
BM_elem_index_set(v, i); /* set_inline */
|
|
|
|
|
BM_elem_flag_disable(v, BM_ELEM_TAG);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
|
|
BM_elem_index_set(e, i); /* set_inline */
|
|
|
|
|
BM_elem_flag_disable(e, BM_ELEM_TAG); /* Clear tag (means edge is sharp). */
|
|
|
|
|
|
|
|
|
|
/* An edge with only two loops, might be smooth... */
|
|
|
|
|
if (BM_edge_loop_pair(e, &l_a, &l_b)) {
|
|
|
|
|
bool is_angle_smooth = true;
|
|
|
|
|
if (check_angle) {
|
2014-04-20 23:12:18 +02:00
|
|
|
const float *no_a = fnos ? fnos[BM_elem_index_get(l_a->f)] : l_a->f->no;
|
2014-04-13 12:25:02 +02:00
|
|
|
const float *no_b = fnos ? fnos[BM_elem_index_get(l_b->f)] : l_b->f->no;
|
|
|
|
|
is_angle_smooth = (dot_v3v3(no_a, no_b) >= split_angle);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-28 18:37:30 +02:00
|
|
|
/* We only tag edges that are *really* smooth:
|
|
|
|
|
* If the angle between both its polys' normals is below split_angle value,
|
|
|
|
|
* and it is tagged as such,
|
|
|
|
|
* and both its faces are smooth,
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
* and both its faces have compatible (non-flipped) normals,
|
|
|
|
|
* i.e. both loops on the same edge do not share the same vertex.
|
2014-05-28 18:37:30 +02:00
|
|
|
*/
|
2014-04-13 12:25:02 +02:00
|
|
|
if (is_angle_smooth &&
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
BM_elem_flag_test(e, BM_ELEM_SMOOTH) &&
|
|
|
|
|
BM_elem_flag_test(l_a->f, BM_ELEM_SMOOTH) &&
|
|
|
|
|
BM_elem_flag_test(l_b->f, BM_ELEM_SMOOTH) &&
|
2014-05-28 18:37:30 +02:00
|
|
|
l_a->v != l_b->v)
|
2014-04-13 12:25:02 +02:00
|
|
|
{
|
|
|
|
|
const float *no;
|
|
|
|
|
BM_elem_flag_enable(e, BM_ELEM_TAG);
|
|
|
|
|
|
|
|
|
|
/* linked vertices might be fully smooth, copy their normals to loop ones. */
|
|
|
|
|
no = vnos ? vnos[BM_elem_index_get(l_a->v)] : l_a->v->no;
|
|
|
|
|
copy_v3_v3(r_lnos[BM_elem_index_get(l_a)], no);
|
|
|
|
|
no = vnos ? vnos[BM_elem_index_get(l_b->v)] : l_b->v->no;
|
|
|
|
|
copy_v3_v3(r_lnos[BM_elem_index_get(l_b)], no);
|
|
|
|
|
}
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
else {
|
|
|
|
|
/* Sharp edge, tag its verts as such. */
|
|
|
|
|
BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
|
|
|
|
|
BM_elem_flag_enable(e->v2, BM_ELEM_TAG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Sharp edge, tag its verts as such. */
|
|
|
|
|
BM_elem_flag_enable(e->v1, BM_ELEM_TAG);
|
|
|
|
|
BM_elem_flag_enable(e->v2, BM_ELEM_TAG);
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
bm->elem_index_dirty &= ~(BM_EDGE | BM_VERT);
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
/* 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], float (*r_lnos)[3],
|
|
|
|
|
MLoopNorSpaceArray *r_lnors_spacearr, short (*clnors_data)[2], const int cd_loop_clnors_offset)
|
2014-04-13 12:25:02 +02:00
|
|
|
{
|
|
|
|
|
BMIter fiter;
|
|
|
|
|
BMFace *f_curr;
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1);
|
|
|
|
|
|
|
|
|
|
MLoopNorSpaceArray _lnors_spacearr = {NULL};
|
2014-04-13 12:25:02 +02:00
|
|
|
|
|
|
|
|
/* Temp normal stack. */
|
|
|
|
|
BLI_SMALLSTACK_DECLARE(normal, float *);
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
/* Temp clnors stack. */
|
|
|
|
|
BLI_SMALLSTACK_DECLARE(clnors, short *);
|
|
|
|
|
/* Temp edge vectors stack, only used when computing lnor spacearr. */
|
|
|
|
|
BLI_Stack *edge_vectors = NULL;
|
2014-04-13 12:25:02 +02:00
|
|
|
|
|
|
|
|
{
|
2014-06-05 18:37:53 +10:00
|
|
|
char htype = BM_LOOP;
|
2014-04-15 16:18:27 +02:00
|
|
|
if (vcos) {
|
2014-06-05 18:37:53 +10:00
|
|
|
htype |= BM_VERT;
|
2014-04-15 16:18:27 +02:00
|
|
|
}
|
|
|
|
|
if (fnos) {
|
2014-06-05 18:37:53 +10:00
|
|
|
htype |= BM_FACE;
|
2014-04-15 16:18:27 +02:00
|
|
|
}
|
2014-06-05 18:37:53 +10:00
|
|
|
BM_mesh_elem_index_ensure(bm, htype);
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
if (!r_lnors_spacearr && has_clnors) {
|
|
|
|
|
/* We need to compute lnor spacearr if some custom lnor data are given to us! */
|
|
|
|
|
r_lnors_spacearr = &_lnors_spacearr;
|
|
|
|
|
}
|
|
|
|
|
if (r_lnors_spacearr) {
|
|
|
|
|
BKE_lnor_spacearr_init(r_lnors_spacearr, bm->totloop);
|
|
|
|
|
edge_vectors = BLI_stack_new(sizeof(float[3]), __func__);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
/* 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) {
|
|
|
|
|
BMLoop *l_curr, *l_first;
|
|
|
|
|
|
|
|
|
|
l_curr = l_first = BM_FACE_FIRST_LOOP(f_curr);
|
|
|
|
|
do {
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
if (BM_elem_flag_test(l_curr->e, BM_ELEM_TAG) &&
|
|
|
|
|
(!r_lnors_spacearr || BM_elem_flag_test(l_curr->v, BM_ELEM_TAG)))
|
|
|
|
|
{
|
|
|
|
|
/* A smooth edge, and we are not generating lnors_spacearr, or the related vertex is sharp.
|
2014-04-13 12:25:02 +02:00
|
|
|
* We skip it because it is either:
|
|
|
|
|
* - in the middle of a 'smooth fan' already computed (or that will be as soon as we hit
|
|
|
|
|
* one of its ends, i.e. one of its two sharp edges), or...
|
|
|
|
|
* - the related vertex is a "full smooth" one, in which case pre-populated normals from vertex
|
|
|
|
|
* are just fine!
|
|
|
|
|
*/
|
|
|
|
|
}
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
else if (!BM_elem_flag_test(l_curr->e, BM_ELEM_TAG) &&
|
|
|
|
|
!BM_elem_flag_test(l_curr->prev->e, BM_ELEM_TAG))
|
|
|
|
|
{
|
2014-04-13 12:25:02 +02:00
|
|
|
/* Simple case (both edges around that vertex are sharp in related polygon),
|
|
|
|
|
* this vertex just takes its poly normal.
|
|
|
|
|
*/
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
const int l_curr_index = BM_elem_index_get(l_curr);
|
2014-04-13 12:25:02 +02:00
|
|
|
const float *no = fnos ? fnos[BM_elem_index_get(f_curr)] : f_curr->no;
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
copy_v3_v3(r_lnos[l_curr_index], no);
|
|
|
|
|
|
|
|
|
|
/* If needed, generate this (simple!) lnor space. */
|
|
|
|
|
if (r_lnors_spacearr) {
|
|
|
|
|
float vec_curr[3], vec_prev[3];
|
|
|
|
|
MLoopNorSpace *lnor_space = BKE_lnor_space_create(r_lnors_spacearr);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const BMVert *v_pivot = l_curr->v;
|
|
|
|
|
const float *co_pivot = vcos ? vcos[BM_elem_index_get(v_pivot)] : v_pivot->co;
|
|
|
|
|
const BMVert *v_1 = BM_edge_other_vert(l_curr->e, v_pivot);
|
|
|
|
|
const float *co_1 = vcos ? vcos[BM_elem_index_get(v_1)] : v_1->co;
|
|
|
|
|
const BMVert *v_2 = BM_edge_other_vert(l_curr->prev->e, v_pivot);
|
|
|
|
|
const float *co_2 = vcos ? vcos[BM_elem_index_get(v_2)] : v_2->co;
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(vec_curr, co_1, co_pivot);
|
|
|
|
|
normalize_v3(vec_curr);
|
|
|
|
|
sub_v3_v3v3(vec_prev, co_2, co_pivot);
|
|
|
|
|
normalize_v3(vec_prev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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... */
|
|
|
|
|
BKE_lnor_space_add_loop(r_lnors_spacearr, lnor_space, l_curr_index, false);
|
|
|
|
|
|
|
|
|
|
if (has_clnors) {
|
|
|
|
|
short (*clnor)[2] = clnors_data ? &clnors_data[l_curr_index] :
|
|
|
|
|
BM_ELEM_CD_GET_VOID_P(l_curr, cd_loop_clnors_offset);
|
|
|
|
|
BKE_lnor_space_custom_data_to_normal(lnor_space, *clnor, r_lnos[l_curr_index]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
2014-05-28 18:37:30 +02:00
|
|
|
/* 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).
|
|
|
|
|
* All this due/thanks to link between normals and loop ordering.
|
|
|
|
|
*/
|
2014-04-13 12:25:02 +02:00
|
|
|
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).
|
|
|
|
|
*/
|
|
|
|
|
BMVert *v_pivot = l_curr->v;
|
|
|
|
|
BMEdge *e_next;
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
const BMEdge *e_org = l_curr->e;
|
2014-04-13 12:25:02 +02:00
|
|
|
BMLoop *lfan_pivot, *lfan_pivot_next;
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
int lfan_pivot_index;
|
2014-04-13 12:25:02 +02:00
|
|
|
float lnor[3] = {0.0f, 0.0f, 0.0f};
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
float vec_curr[3], vec_next[3], vec_org[3];
|
|
|
|
|
|
|
|
|
|
/* We validate clnors data on the fly - cheapest way to do! */
|
|
|
|
|
int clnors_avg[2] = {0, 0};
|
|
|
|
|
short (*clnor_ref)[2] = NULL;
|
|
|
|
|
int clnors_nbr = 0;
|
|
|
|
|
bool clnors_invalid = false;
|
2014-04-13 12:25:02 +02:00
|
|
|
|
|
|
|
|
const float *co_pivot = vcos ? vcos[BM_elem_index_get(v_pivot)] : v_pivot->co;
|
|
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
MLoopNorSpace *lnor_space = r_lnors_spacearr ? BKE_lnor_space_create(r_lnors_spacearr) : NULL;
|
|
|
|
|
|
|
|
|
|
BLI_assert((edge_vectors == NULL) || BLI_stack_is_empty(edge_vectors));
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
lfan_pivot = l_curr;
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
lfan_pivot_index = BM_elem_index_get(lfan_pivot);
|
2014-04-13 12:25:02 +02:00
|
|
|
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! */
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
sub_v3_v3v3(vec_org, co_2, co_pivot);
|
|
|
|
|
normalize_v3(vec_org);
|
|
|
|
|
copy_v3_v3(vec_curr, vec_org);
|
|
|
|
|
|
|
|
|
|
if (r_lnors_spacearr) {
|
|
|
|
|
BLI_stack_push(edge_vectors, vec_org);
|
|
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
/* Much simpler than in sibling code with basic Mesh data! */
|
|
|
|
|
lfan_pivot_next = BM_vert_step_fan_loop(lfan_pivot, &e_next);
|
2014-04-14 23:42:38 +02:00
|
|
|
if (lfan_pivot_next) {
|
|
|
|
|
BLI_assert(lfan_pivot_next->v == v_pivot);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* next edge is non-manifold, we have to find it ourselves! */
|
|
|
|
|
e_next = (lfan_pivot->e == e_next) ? lfan_pivot->prev->e : lfan_pivot->e;
|
|
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
|
|
|
|
|
/* 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...
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
sub_v3_v3v3(vec_next, co_2, co_pivot);
|
|
|
|
|
normalize_v3(vec_next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* Code similar to accumulate_vertex_normals_poly. */
|
|
|
|
|
/* Calculate angle between the two poly edges incident on this vertex. */
|
|
|
|
|
const BMFace *f = lfan_pivot->f;
|
|
|
|
|
const float fac = saacos(dot_v3v3(vec_next, vec_curr));
|
|
|
|
|
const float *no = fnos ? fnos[BM_elem_index_get(f)] : f->no;
|
|
|
|
|
/* Accumulate */
|
|
|
|
|
madd_v3_v3fl(lnor, no, fac);
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
|
|
|
|
|
if (has_clnors) {
|
|
|
|
|
/* Accumulate all clnors, if they are not all equal we have to fix that! */
|
|
|
|
|
short (*clnor)[2] = clnors_data ? &clnors_data[lfan_pivot_index] :
|
|
|
|
|
BM_ELEM_CD_GET_VOID_P(lfan_pivot, cd_loop_clnors_offset);
|
|
|
|
|
if (clnors_nbr) {
|
|
|
|
|
clnors_invalid |= ((*clnor_ref)[0] != (*clnor)[0] || (*clnor_ref)[1] != (*clnor)[1]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
clnor_ref = clnor;
|
|
|
|
|
}
|
|
|
|
|
clnors_avg[0] += (*clnor)[0];
|
|
|
|
|
clnors_avg[1] += (*clnor)[1];
|
|
|
|
|
clnors_nbr++;
|
|
|
|
|
/* We store here a pointer to all custom lnors processed. */
|
|
|
|
|
BLI_SMALLSTACK_PUSH(clnors, (short *)*clnor);
|
|
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We store here a pointer to all loop-normals processed. */
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
BLI_SMALLSTACK_PUSH(normal, (float *)r_lnos[lfan_pivot_index]);
|
|
|
|
|
|
|
|
|
|
if (r_lnors_spacearr) {
|
|
|
|
|
/* Assign current lnor space to current 'vertex' loop. */
|
|
|
|
|
BKE_lnor_space_add_loop(r_lnors_spacearr, lnor_space, lfan_pivot_index, true);
|
|
|
|
|
if (e_next != e_org) {
|
|
|
|
|
/* We store here all edges-normalized vectors processed. */
|
|
|
|
|
BLI_stack_push(edge_vectors, vec_next);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
if (!BM_elem_flag_test(e_next, BM_ELEM_TAG) || (e_next == e_org)) {
|
2014-04-13 12:25:02 +02:00
|
|
|
/* Next edge is sharp, we have finished with this fan of faces around this vert! */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy next edge vector to current one. */
|
|
|
|
|
copy_v3_v3(vec_curr, vec_next);
|
|
|
|
|
/* Next pivot loop to current one. */
|
|
|
|
|
lfan_pivot = lfan_pivot_next;
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
lfan_pivot_index = BM_elem_index_get(lfan_pivot);
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
{
|
|
|
|
|
float lnor_len = normalize_v3(lnor);
|
|
|
|
|
|
|
|
|
|
/* If we are generating lnor spacearr, we can now define the one for this fan. */
|
|
|
|
|
if (r_lnors_spacearr) {
|
|
|
|
|
if (UNLIKELY(lnor_len == 0.0f)) {
|
|
|
|
|
/* Use vertex normal as fallback! */
|
|
|
|
|
copy_v3_v3(lnor, r_lnos[lfan_pivot_index]);
|
|
|
|
|
lnor_len = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_lnor_space_define(lnor_space, lnor, vec_org, vec_next, edge_vectors);
|
|
|
|
|
|
|
|
|
|
if (has_clnors) {
|
|
|
|
|
if (clnors_invalid) {
|
|
|
|
|
short *clnor;
|
|
|
|
|
|
|
|
|
|
clnors_avg[0] /= clnors_nbr;
|
|
|
|
|
clnors_avg[1] /= clnors_nbr;
|
|
|
|
|
/* Fix/update all clnors of this fan with computed average value. */
|
|
|
|
|
printf("Invalid clnors in this fan!\n");
|
|
|
|
|
while ((clnor = BLI_SMALLSTACK_POP(clnors))) {
|
|
|
|
|
//print_v2("org clnor", clnor);
|
|
|
|
|
clnor[0] = (short)clnors_avg[0];
|
|
|
|
|
clnor[1] = (short)clnors_avg[1];
|
|
|
|
|
}
|
|
|
|
|
//print_v2("new clnors", clnors_avg);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* We still have to consume the stack! */
|
|
|
|
|
while (BLI_SMALLSTACK_POP(clnors));
|
|
|
|
|
}
|
|
|
|
|
BKE_lnor_space_custom_data_to_normal(lnor_space, *clnor_ref, lnor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In case we get a zero normal here, just use vertex normal already set! */
|
|
|
|
|
if (LIKELY(lnor_len != 0.0f)) {
|
|
|
|
|
/* Copy back the final computed normal into all related loop-normals. */
|
|
|
|
|
float *nor;
|
|
|
|
|
|
|
|
|
|
while ((nor = BLI_SMALLSTACK_POP(normal))) {
|
|
|
|
|
copy_v3_v3(nor, lnor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* We still have to consume the stack! */
|
|
|
|
|
while (BLI_SMALLSTACK_POP(normal));
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
|
|
|
|
|
/* 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);
|
2014-07-11 19:52:43 +02:00
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
} while ((l_curr = l_curr->next) != l_first);
|
|
|
|
|
}
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
|
|
|
|
|
if (r_lnors_spacearr) {
|
|
|
|
|
BLI_stack_free(edge_vectors);
|
|
|
|
|
if (r_lnors_spacearr == &_lnors_spacearr) {
|
|
|
|
|
BKE_lnor_spacearr_free(r_lnors_spacearr);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-06 20:14:18 +01:00
|
|
|
static void bm_mesh_loops_calc_normals_no_autosmooth(
|
|
|
|
|
BMesh *bm, const float (*vnos)[3], const float (*fnos)[3], float (*r_lnos)[3])
|
2015-01-19 14:11:40 +01:00
|
|
|
{
|
|
|
|
|
BMIter fiter;
|
|
|
|
|
BMFace *f_curr;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
char htype = BM_LOOP;
|
|
|
|
|
if (vnos) {
|
|
|
|
|
htype |= BM_VERT;
|
|
|
|
|
}
|
2015-02-06 20:14:18 +01:00
|
|
|
if (fnos) {
|
|
|
|
|
htype |= BM_FACE;
|
|
|
|
|
}
|
2015-01-19 14:11:40 +01:00
|
|
|
BM_mesh_elem_index_ensure(bm, htype);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BM_ITER_MESH (f_curr, &fiter, bm, BM_FACES_OF_MESH) {
|
|
|
|
|
BMLoop *l_curr, *l_first;
|
2015-02-06 20:14:18 +01:00
|
|
|
const bool is_face_flat = !BM_elem_flag_test(f_curr, BM_ELEM_SMOOTH);
|
2015-01-19 14:11:40 +01:00
|
|
|
|
|
|
|
|
l_curr = l_first = BM_FACE_FIRST_LOOP(f_curr);
|
|
|
|
|
do {
|
2015-02-06 20:14:18 +01:00
|
|
|
const float *no = is_face_flat ? (fnos ? fnos[BM_elem_index_get(f_curr)] : f_curr->no) :
|
|
|
|
|
(vnos ? vnos[BM_elem_index_get(l_curr->v)] : l_curr->v->no);
|
2015-01-19 14:11:40 +01:00
|
|
|
copy_v3_v3(r_lnos[BM_elem_index_get(l_curr)], no);
|
|
|
|
|
|
|
|
|
|
} while ((l_curr = l_curr->next) != l_first);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
#if 0 /* Unused currently */
|
|
|
|
|
/**
|
|
|
|
|
* \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)!
|
|
|
|
|
*/
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
void BM_mesh_loop_normals_update(
|
|
|
|
|
BMesh *bm, const bool use_split_normals, const float split_angle, float (*r_lnos)[3],
|
|
|
|
|
MLoopNorSpaceArray *r_lnors_spacearr, short (*clnors_data)[2], const int cd_loop_clnors_offset)
|
2014-04-13 12:25:02 +02:00
|
|
|
{
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1);
|
|
|
|
|
|
2015-01-19 14:11:40 +01:00
|
|
|
if (use_split_normals) {
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
/* Tag smooth edges and set lnos from vnos when they might be completely smooth...
|
|
|
|
|
* 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);
|
2014-04-13 12:25:02 +02:00
|
|
|
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
/* 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);
|
2015-01-19 14:11:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
BLI_assert(!r_lnors_spacearr);
|
2015-02-06 20:14:18 +01:00
|
|
|
bm_mesh_loops_calc_normals_no_autosmooth(bm, NULL, NULL, r_lnos);
|
2015-01-19 14:11:40 +01:00
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \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).
|
|
|
|
|
*/
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
void BM_loops_calc_normal_vcos(
|
|
|
|
|
BMesh *bm, const float (*vcos)[3], const float (*vnos)[3], const float (*fnos)[3],
|
|
|
|
|
const bool use_split_normals, const float split_angle, float (*r_lnos)[3],
|
|
|
|
|
MLoopNorSpaceArray *r_lnors_spacearr, short (*clnors_data)[2], const int cd_loop_clnors_offset)
|
2014-04-13 12:25:02 +02:00
|
|
|
{
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1);
|
|
|
|
|
|
2015-01-19 14:11:40 +01:00
|
|
|
if (use_split_normals) {
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
/* Tag smooth edges and set lnos from vnos when they might be completely smooth...
|
|
|
|
|
* When using custom loop normals, disable the angle feature! */
|
|
|
|
|
bm_mesh_edges_sharp_tag(bm, vnos, fnos, has_clnors ? (float)M_PI : split_angle, r_lnos);
|
2014-04-13 12:25:02 +02:00
|
|
|
|
2015-01-19 14:11:40 +01:00
|
|
|
/* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
bm_mesh_loops_calc_normals(bm, vcos, fnos, r_lnos, r_lnors_spacearr, clnors_data, cd_loop_clnors_offset);
|
2015-01-19 14:11:40 +01:00
|
|
|
}
|
|
|
|
|
else {
|
Add Custom Loop Normals.
This is the core code for it, tools (datatransfer and modifier) will come in next commits).
RNA api is already there, though.
See the code for details, but basically, we define, for each 'smooth fan'
(which is a set of adjacent loops around a same vertex that are smooth, i.e. have a single same normal),
a 'loop normal space' (or lnor space), using auto-computed normal and relevant edges, and store
custom normal as two angular factors inside that space. This allows to have custom normals
'following' deformations of the geometry, and to only save two shorts per loop in new clnor CDLayer.
Normal manipulation (editing, mixing, interpolating, etc.) shall always happen with plain 3D vectors normals,
and be converted back into storage format at the end.
Clnor computation has also been threaded (at least for Mesh case, not for BMesh), since the process can
be rather heavy with high poly meshes.
Also, bumping subversion, and fix mess in 2.70 versioning code.
2015-02-05 14:24:48 +01:00
|
|
|
BLI_assert(!r_lnors_spacearr);
|
2015-02-06 20:14:18 +01:00
|
|
|
bm_mesh_loops_calc_normals_no_autosmooth(bm, vnos, fnos, r_lnos);
|
2015-01-19 14:11:40 +01:00
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
|
|
|
|
|
2012-03-11 19:58:56 +00:00
|
|
|
static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from, int to)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
/* switch multires data out of tangent space */
|
|
|
|
|
if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
|
2013-04-16 05:59:48 +00:00
|
|
|
BMEditMesh *em = BKE_editmesh_create(bm, false);
|
2013-01-14 16:42:43 +00:00
|
|
|
DerivedMesh *dm = CDDM_from_editbmesh(em, true, false);
|
2012-02-19 18:31:04 +00:00
|
|
|
MDisps *mdisps;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
// int i = 0; // UNUSED
|
|
|
|
|
|
|
|
|
|
multires_set_space(dm, ob, from, to);
|
|
|
|
|
|
|
|
|
|
mdisps = CustomData_get_layer(&dm->loopData, CD_MDISPS);
|
|
|
|
|
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
|
2012-02-19 18:31:04 +00:00
|
|
|
BMLoop *l;
|
|
|
|
|
BMIter liter;
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
|
2012-02-19 18:31:04 +00:00
|
|
|
MDisps *lmd = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MDISPS);
|
|
|
|
|
|
|
|
|
|
if (!lmd->disps) {
|
|
|
|
|
printf("%s: warning - 'lmd->disps' == NULL\n", __func__);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lmd->disps && lmd->totdisp == mdisps->totdisp) {
|
|
|
|
|
memcpy(lmd->disps, mdisps->disps, sizeof(float) * 3 * lmd->totdisp);
|
|
|
|
|
}
|
|
|
|
|
else if (mdisps->disps) {
|
|
|
|
|
if (lmd->disps)
|
|
|
|
|
MEM_freeN(lmd->disps);
|
|
|
|
|
|
|
|
|
|
lmd->disps = MEM_dupallocN(mdisps->disps);
|
|
|
|
|
lmd->totdisp = mdisps->totdisp;
|
2012-03-14 03:10:18 +00:00
|
|
|
lmd->level = mdisps->level;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mdisps++;
|
|
|
|
|
// i += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dm->needsFree = 1;
|
|
|
|
|
dm->release(dm);
|
|
|
|
|
|
2013-04-16 05:59:48 +00:00
|
|
|
/* setting this to NULL prevents BKE_editmesh_free from freeing it */
|
2012-02-19 18:31:04 +00:00
|
|
|
em->bm = NULL;
|
2013-04-16 05:59:48 +00:00
|
|
|
BKE_editmesh_free(em);
|
2012-02-19 18:31:04 +00:00
|
|
|
MEM_freeN(em);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/**
|
|
|
|
|
* \brief BMesh Begin Edit
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* Functions for setting up a mesh for editing and cleaning up after
|
|
|
|
|
* the editing operations are done. These are called by the tools/operator
|
|
|
|
|
* API for each time a tool is executed.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
2013-04-14 06:22:34 +00:00
|
|
|
void bmesh_edit_begin(BMesh *UNUSED(bm), BMOpTypeFlag UNUSED(type_flag))
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2013-04-14 06:22:34 +00:00
|
|
|
/* Most operators seem to be using BMO_OPTYPE_FLAG_UNTAN_MULTIRES to change the MDisps to
|
2012-02-19 18:31:04 +00:00
|
|
|
* absolute space during mesh edits. With this enabled, changes to the topology
|
|
|
|
|
* (loop cuts, edge subdivides, etc) are not reflected in the higher levels of
|
|
|
|
|
* the mesh at all, which doesn't seem right. Turning off completely for now,
|
|
|
|
|
* until this is shown to be better for certain types of mesh edits. */
|
2012-09-16 00:26:36 +00:00
|
|
|
#ifdef BMOP_UNTAN_MULTIRES_ENABLED
|
2012-02-19 18:31:04 +00:00
|
|
|
/* switch multires data out of tangent space */
|
2013-04-14 06:22:34 +00:00
|
|
|
if ((type_flag & BMO_OPTYPE_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
|
2012-02-27 14:07:19 +00:00
|
|
|
bmesh_mdisps_space_set(bm, MULTIRES_SPACE_TANGENT, MULTIRES_SPACE_ABSOLUTE);
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
/* ensure correct normals, if possible */
|
|
|
|
|
bmesh_rationalize_normals(bm, 0);
|
|
|
|
|
BM_mesh_normals_update(bm);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/**
|
|
|
|
|
* \brief BMesh End Edit
|
|
|
|
|
*/
|
2013-04-14 06:22:34 +00:00
|
|
|
void bmesh_edit_end(BMesh *bm, BMOpTypeFlag type_flag)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2014-08-25 16:40:46 +10:00
|
|
|
ListBase select_history;
|
|
|
|
|
|
2013-04-14 06:22:34 +00:00
|
|
|
/* BMO_OPTYPE_FLAG_UNTAN_MULTIRES disabled for now, see comment above in bmesh_edit_begin. */
|
2012-09-16 00:26:36 +00:00
|
|
|
#ifdef BMOP_UNTAN_MULTIRES_ENABLED
|
2012-02-19 18:31:04 +00:00
|
|
|
/* switch multires data into tangent space */
|
2013-04-14 06:22:34 +00:00
|
|
|
if ((flag & BMO_OPTYPE_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
|
2012-02-19 18:31:04 +00:00
|
|
|
/* set normals to their previous winding */
|
|
|
|
|
bmesh_rationalize_normals(bm, 1);
|
2012-02-27 14:07:19 +00:00
|
|
|
bmesh_mdisps_space_set(bm, MULTIRES_SPACE_ABSOLUTE, MULTIRES_SPACE_TANGENT);
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
else if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) {
|
|
|
|
|
bmesh_rationalize_normals(bm, 1);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* compute normals, clear temp flags and flush selections */
|
2013-04-14 06:22:34 +00:00
|
|
|
if (type_flag & BMO_OPTYPE_FLAG_NORMALS_CALC) {
|
2013-04-24 12:07:13 +00:00
|
|
|
BM_mesh_normals_update(bm);
|
2013-04-14 06:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 16:40:46 +10:00
|
|
|
|
|
|
|
|
if ((type_flag & BMO_OPTYPE_FLAG_SELECT_VALIDATE) == 0) {
|
|
|
|
|
select_history = bm->selected;
|
|
|
|
|
BLI_listbase_clear(&bm->selected);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-14 06:22:34 +00:00
|
|
|
if (type_flag & BMO_OPTYPE_FLAG_SELECT_FLUSH) {
|
|
|
|
|
BM_mesh_select_mode_flush(bm);
|
|
|
|
|
}
|
2014-08-25 16:40:46 +10:00
|
|
|
|
|
|
|
|
if ((type_flag & BMO_OPTYPE_FLAG_SELECT_VALIDATE) == 0) {
|
|
|
|
|
bm->selected = select_history;
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
2014-06-05 18:37:53 +10:00
|
|
|
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
2014-06-05 18:50:10 +10:00
|
|
|
const char htype_needed = bm->elem_index_dirty & htype;
|
|
|
|
|
|
2012-02-19 18:31:04 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
BM_ELEM_INDEX_VALIDATE(bm, "Should Never Fail!", __func__);
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-06-05 18:50:10 +10:00
|
|
|
if (htype_needed == 0) {
|
|
|
|
|
goto finally;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* skip if we only need to operate on one element */
|
2014-07-20 01:30:29 +10:00
|
|
|
#pragma omp parallel sections if ((!ELEM(htype_needed, BM_VERT, BM_EDGE, BM_FACE, BM_LOOP, BM_FACE | BM_LOOP)) && \
|
2014-06-05 18:50:10 +10:00
|
|
|
(bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT))
|
2012-12-12 05:04:01 +00:00
|
|
|
{
|
|
|
|
|
#pragma omp section
|
2014-06-05 18:50:10 +10:00
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
{
|
2014-06-05 18:37:53 +10:00
|
|
|
if (htype & BM_VERT) {
|
2012-12-12 05:04:01 +00:00
|
|
|
if (bm->elem_index_dirty & BM_VERT) {
|
2012-12-22 08:37:34 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMElem *ele;
|
|
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
int index;
|
|
|
|
|
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, index) {
|
|
|
|
|
BM_elem_index_set(ele, index); /* set_ok */
|
|
|
|
|
}
|
|
|
|
|
BLI_assert(index == bm->totvert);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// printf("%s: skipping vert index calc!\n", __func__);
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
#pragma omp section
|
|
|
|
|
{
|
2014-06-05 18:37:53 +10:00
|
|
|
if (htype & BM_EDGE) {
|
2012-12-12 05:04:01 +00:00
|
|
|
if (bm->elem_index_dirty & BM_EDGE) {
|
2012-12-22 08:37:34 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMElem *ele;
|
|
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
int index;
|
|
|
|
|
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, index) {
|
|
|
|
|
BM_elem_index_set(ele, index); /* set_ok */
|
|
|
|
|
}
|
|
|
|
|
BLI_assert(index == bm->totedge);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// printf("%s: skipping edge index calc!\n", __func__);
|
|
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
#pragma omp section
|
|
|
|
|
{
|
2014-06-05 18:37:53 +10:00
|
|
|
if (htype & (BM_FACE | BM_LOOP)) {
|
2014-04-13 12:25:02 +02:00
|
|
|
if (bm->elem_index_dirty & (BM_FACE | BM_LOOP)) {
|
2012-12-22 08:37:34 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMElem *ele;
|
|
|
|
|
|
2014-06-05 18:37:53 +10:00
|
|
|
const bool update_face = (htype & BM_FACE) && (bm->elem_index_dirty & BM_FACE);
|
|
|
|
|
const bool update_loop = (htype & BM_LOOP) && (bm->elem_index_dirty & BM_LOOP);
|
2014-04-13 12:25:02 +02:00
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
int index;
|
2014-04-15 16:18:27 +02:00
|
|
|
int index_loop = 0;
|
|
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, index) {
|
2014-04-15 16:18:27 +02:00
|
|
|
if (update_face) {
|
|
|
|
|
BM_elem_index_set(ele, index); /* set_ok */
|
|
|
|
|
}
|
2014-04-13 12:25:02 +02:00
|
|
|
|
2014-04-15 16:18:27 +02:00
|
|
|
if (update_loop) {
|
|
|
|
|
BMLoop *l_iter, *l_first;
|
2014-04-13 12:25:02 +02:00
|
|
|
|
2014-04-15 16:18:27 +02:00
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP((BMFace *)ele);
|
|
|
|
|
do {
|
|
|
|
|
BM_elem_index_set(l_iter, index_loop++); /* set_ok */
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2014-04-13 12:25:02 +02:00
|
|
|
}
|
2012-12-12 05:04:01 +00:00
|
|
|
}
|
2014-04-15 16:18:27 +02:00
|
|
|
|
2012-12-12 05:04:01 +00:00
|
|
|
BLI_assert(index == bm->totface);
|
2014-04-15 16:18:27 +02:00
|
|
|
if (update_loop) {
|
|
|
|
|
BLI_assert(index_loop == bm->totloop);
|
|
|
|
|
}
|
2012-12-12 05:04:01 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2014-04-13 12:25:02 +02:00
|
|
|
// printf("%s: skipping face/loop index calc!\n", __func__);
|
2012-12-12 05:04:01 +00:00
|
|
|
}
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-12-12 05:04:01 +00:00
|
|
|
|
2014-06-05 18:50:10 +10:00
|
|
|
|
|
|
|
|
finally:
|
2014-06-05 18:37:53 +10:00
|
|
|
bm->elem_index_dirty &= ~htype;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-02-29 06:55:10 +00:00
|
|
|
/**
|
|
|
|
|
* Array checking/setting macros
|
|
|
|
|
*
|
|
|
|
|
* Currently vert/edge/loop/face index data is being abused, in a few areas of the code.
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* To avoid correcting them afterwards, set 'bm->elem_index_dirty' however its possible
|
|
|
|
|
* this flag is set incorrectly which could crash blender.
|
2012-02-19 18:31:04 +00:00
|
|
|
*
|
2012-02-29 06:55:10 +00:00
|
|
|
* These functions ensure its correct and are called more often in debug mode.
|
2012-02-19 18:31:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2015-04-25 20:15:20 +10:00
|
|
|
void BM_mesh_elem_index_validate(
|
|
|
|
|
BMesh *bm, const char *location, const char *func,
|
|
|
|
|
const char *msg_a, const char *msg_b)
|
2012-02-19 18:31:04 +00:00
|
|
|
{
|
|
|
|
|
const char iter_types[3] = {BM_VERTS_OF_MESH,
|
|
|
|
|
BM_EDGES_OF_MESH,
|
|
|
|
|
BM_FACES_OF_MESH};
|
|
|
|
|
|
|
|
|
|
const char flag_types[3] = {BM_VERT, BM_EDGE, BM_FACE};
|
|
|
|
|
const char *type_names[3] = {"vert", "edge", "face"};
|
|
|
|
|
|
|
|
|
|
BMIter iter;
|
2012-02-25 22:23:40 +00:00
|
|
|
BMElem *ele;
|
2012-02-19 18:31:04 +00:00
|
|
|
int i;
|
2013-01-14 16:42:43 +00:00
|
|
|
bool is_any_error = 0;
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2013-05-29 11:49:39 +00:00
|
|
|
const bool is_dirty = (flag_types[i] & bm->elem_index_dirty) != 0;
|
2012-02-19 18:31:04 +00:00
|
|
|
int index = 0;
|
2013-01-14 16:42:43 +00:00
|
|
|
bool is_error = false;
|
2012-02-19 18:31:04 +00:00
|
|
|
int err_val = 0;
|
|
|
|
|
int err_idx = 0;
|
|
|
|
|
|
2012-04-19 12:45:56 +00:00
|
|
|
BM_ITER_MESH (ele, &iter, bm, iter_types[i]) {
|
2012-02-19 18:31:04 +00:00
|
|
|
if (!is_dirty) {
|
|
|
|
|
if (BM_elem_index_get(ele) != index) {
|
|
|
|
|
err_val = BM_elem_index_get(ele);
|
|
|
|
|
err_idx = index;
|
2013-01-14 16:42:43 +00:00
|
|
|
is_error = true;
|
2012-02-19 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BM_elem_index_set(ele, index); /* set_ok */
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-14 16:42:43 +00:00
|
|
|
if ((is_error == true) && (is_dirty == false)) {
|
|
|
|
|
is_any_error = true;
|
2012-02-19 18:31:04 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid Index: at %s, %s, %s[%d] invalid index %d, '%s', '%s'\n",
|
|
|
|
|
location, func, type_names[i], err_idx, err_val, msg_a, msg_b);
|
|
|
|
|
}
|
2013-01-14 16:42:43 +00:00
|
|
|
else if ((is_error == false) && (is_dirty == true)) {
|
2012-02-19 18:31:04 +00:00
|
|
|
|
2012-04-19 12:45:56 +00:00
|
|
|
#if 0 /* mostly annoying */
|
2012-02-19 18:31:04 +00:00
|
|
|
|
|
|
|
|
/* dirty may have been incorrectly set */
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Invalid Dirty: at %s, %s (%s), dirty flag was set but all index values are correct, '%s', '%s'\n",
|
|
|
|
|
location, func, type_names[i], msg_a, msg_b);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0 /* mostly annoying, even in debug mode */
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (is_any_error == 0) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Valid Index Success: at %s, %s, '%s', '%s'\n",
|
|
|
|
|
location, func, msg_a, msg_b);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
(void) is_any_error; /* shut up the compiler */
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 02:05:33 +00:00
|
|
|
/* debug check only - no need to optimize */
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
bool BM_mesh_elem_table_check(BMesh *bm)
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMElem *ele;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (bm->vtable && ((bm->elem_table_dirty & BM_VERT) == 0)) {
|
|
|
|
|
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
if (ele != (BMElem *)bm->vtable[i]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bm->etable && ((bm->elem_table_dirty & BM_EDGE) == 0)) {
|
|
|
|
|
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) {
|
|
|
|
|
if (ele != (BMElem *)bm->etable[i]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bm->ftable && ((bm->elem_table_dirty & BM_FACE) == 0)) {
|
|
|
|
|
BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) {
|
|
|
|
|
if (ele != (BMElem *)bm->ftable[i]) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
|
|
|
|
|
{
|
|
|
|
|
/* assume if the array is non-null then its valid and no need to recalc */
|
|
|
|
|
const char htype_needed = (((bm->vtable && ((bm->elem_table_dirty & BM_VERT) == 0)) ? 0 : BM_VERT) |
|
|
|
|
|
((bm->etable && ((bm->elem_table_dirty & BM_EDGE) == 0)) ? 0 : BM_EDGE) |
|
|
|
|
|
((bm->ftable && ((bm->elem_table_dirty & BM_FACE) == 0)) ? 0 : BM_FACE)) & htype;
|
|
|
|
|
|
|
|
|
|
BLI_assert((htype & ~BM_ALL_NOLOOP) == 0);
|
|
|
|
|
|
|
|
|
|
/* in debug mode double check we didn't need to recalculate */
|
|
|
|
|
BLI_assert(BM_mesh_elem_table_check(bm) == true);
|
|
|
|
|
|
2014-06-05 08:10:26 +10:00
|
|
|
if (htype_needed == 0) {
|
2014-06-05 18:50:10 +10:00
|
|
|
goto finally;
|
2014-06-05 08:10:26 +10:00
|
|
|
}
|
|
|
|
|
|
2013-10-28 02:05:33 +00:00
|
|
|
if (htype_needed & BM_VERT) {
|
|
|
|
|
if (bm->vtable && bm->totvert <= bm->vtable_tot && bm->totvert * 2 >= bm->vtable_tot) {
|
|
|
|
|
/* pass (re-use the array) */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (bm->vtable)
|
|
|
|
|
MEM_freeN(bm->vtable);
|
|
|
|
|
bm->vtable = MEM_mallocN(sizeof(void **) * bm->totvert, "bm->vtable");
|
|
|
|
|
bm->vtable_tot = bm->totvert;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (htype_needed & BM_EDGE) {
|
|
|
|
|
if (bm->etable && bm->totedge <= bm->etable_tot && bm->totedge * 2 >= bm->etable_tot) {
|
|
|
|
|
/* pass (re-use the array) */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (bm->etable)
|
|
|
|
|
MEM_freeN(bm->etable);
|
|
|
|
|
bm->etable = MEM_mallocN(sizeof(void **) * bm->totedge, "bm->etable");
|
|
|
|
|
bm->etable_tot = bm->totedge;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (htype_needed & BM_FACE) {
|
|
|
|
|
if (bm->ftable && bm->totface <= bm->ftable_tot && bm->totface * 2 >= bm->ftable_tot) {
|
|
|
|
|
/* pass (re-use the array) */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (bm->ftable)
|
|
|
|
|
MEM_freeN(bm->ftable);
|
|
|
|
|
bm->ftable = MEM_mallocN(sizeof(void **) * bm->totface, "bm->ftable");
|
|
|
|
|
bm->ftable_tot = bm->totface;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 08:10:26 +10:00
|
|
|
/* skip if we only need to operate on one element */
|
2014-07-20 01:30:29 +10:00
|
|
|
#pragma omp parallel sections if ((!ELEM(htype_needed, BM_VERT, BM_EDGE, BM_FACE)) && \
|
2014-06-05 08:10:26 +10:00
|
|
|
(bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT))
|
2013-10-28 02:05:33 +00:00
|
|
|
{
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
if (htype_needed & BM_VERT) {
|
|
|
|
|
BM_iter_as_array(bm, BM_VERTS_OF_MESH, NULL, (void **)bm->vtable, bm->totvert);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
if (htype_needed & BM_EDGE) {
|
|
|
|
|
BM_iter_as_array(bm, BM_EDGES_OF_MESH, NULL, (void **)bm->etable, bm->totedge);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#pragma omp section
|
|
|
|
|
{
|
|
|
|
|
if (htype_needed & BM_FACE) {
|
|
|
|
|
BM_iter_as_array(bm, BM_FACES_OF_MESH, NULL, (void **)bm->ftable, bm->totface);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-03 19:12:04 +06:00
|
|
|
|
2014-06-05 18:50:10 +10:00
|
|
|
finally:
|
2014-02-03 19:12:04 +06:00
|
|
|
/* Only clear dirty flags when all the pointers and data are actually valid.
|
|
|
|
|
* This prevents possible threading issues when dirty flag check failed but
|
|
|
|
|
* data wasn't ready still.
|
|
|
|
|
*/
|
2014-06-05 18:50:10 +10:00
|
|
|
bm->elem_table_dirty &= ~htype_needed;
|
2013-10-28 02:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* use BM_mesh_elem_table_ensure where possible to avoid full rebuild */
|
|
|
|
|
void BM_mesh_elem_table_init(BMesh *bm, const char htype)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert((htype & ~BM_ALL_NOLOOP) == 0);
|
|
|
|
|
|
|
|
|
|
/* force recalc */
|
|
|
|
|
BM_mesh_elem_table_free(bm, BM_ALL_NOLOOP);
|
|
|
|
|
BM_mesh_elem_table_ensure(bm, htype);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BM_mesh_elem_table_free(BMesh *bm, const char htype)
|
|
|
|
|
{
|
|
|
|
|
if (htype & BM_VERT) {
|
|
|
|
|
MEM_SAFE_FREE(bm->vtable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (htype & BM_EDGE) {
|
|
|
|
|
MEM_SAFE_FREE(bm->etable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (htype & BM_FACE) {
|
|
|
|
|
MEM_SAFE_FREE(bm->ftable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 19:43:53 +00:00
|
|
|
BMVert *BM_vert_at_index(BMesh *bm, const int index)
|
2013-10-28 02:05:33 +00:00
|
|
|
{
|
|
|
|
|
BLI_assert((index >= 0) && (index < bm->totvert));
|
|
|
|
|
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
|
|
|
|
|
return bm->vtable[index];
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 19:43:53 +00:00
|
|
|
BMEdge *BM_edge_at_index(BMesh *bm, const int index)
|
2013-10-28 02:05:33 +00:00
|
|
|
{
|
|
|
|
|
BLI_assert((index >= 0) && (index < bm->totedge));
|
|
|
|
|
BLI_assert((bm->elem_table_dirty & BM_EDGE) == 0);
|
|
|
|
|
return bm->etable[index];
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 19:43:53 +00:00
|
|
|
BMFace *BM_face_at_index(BMesh *bm, const int index)
|
2013-10-28 02:05:33 +00:00
|
|
|
{
|
|
|
|
|
BLI_assert((index >= 0) && (index < bm->totface));
|
|
|
|
|
BLI_assert((bm->elem_table_dirty & BM_FACE) == 0);
|
|
|
|
|
return bm->ftable[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BMVert *BM_vert_at_index_find(BMesh *bm, const int index)
|
|
|
|
|
{
|
|
|
|
|
return BLI_mempool_findelem(bm->vpool, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BMEdge *BM_edge_at_index_find(BMesh *bm, const int index)
|
|
|
|
|
{
|
|
|
|
|
return BLI_mempool_findelem(bm->epool, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BMFace *BM_face_at_index_find(BMesh *bm, const int index)
|
|
|
|
|
{
|
|
|
|
|
return BLI_mempool_findelem(bm->fpool, index);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 01:33:09 +10:00
|
|
|
/**
|
|
|
|
|
* Use lookup table when available, else use slower find functions.
|
|
|
|
|
*
|
|
|
|
|
* \note Try to use #BM_mesh_elem_table_ensure instead.
|
|
|
|
|
*/
|
|
|
|
|
BMVert *BM_vert_at_index_find_or_table(BMesh *bm, const int index)
|
|
|
|
|
{
|
|
|
|
|
if ((bm->elem_table_dirty & BM_VERT) == 0) {
|
|
|
|
|
return (index < bm->totvert) ? bm->vtable[index] : NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return BM_vert_at_index_find(bm, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BMEdge *BM_edge_at_index_find_or_table(BMesh *bm, const int index)
|
|
|
|
|
{
|
|
|
|
|
if ((bm->elem_table_dirty & BM_EDGE) == 0) {
|
|
|
|
|
return (index < bm->totedge) ? bm->etable[index] : NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return BM_edge_at_index_find(bm, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BMFace *BM_face_at_index_find_or_table(BMesh *bm, const int index)
|
|
|
|
|
{
|
|
|
|
|
if ((bm->elem_table_dirty & BM_FACE) == 0) {
|
|
|
|
|
return (index < bm->totface) ? bm->ftable[index] : NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return BM_face_at_index_find(bm, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 02:05:33 +00:00
|
|
|
|
2012-04-23 01:19:50 +00:00
|
|
|
/**
|
|
|
|
|
* Return the amount of element of type 'type' in a given bmesh.
|
|
|
|
|
*/
|
|
|
|
|
int BM_mesh_elem_count(BMesh *bm, const char htype)
|
|
|
|
|
{
|
2013-06-19 18:59:54 +00:00
|
|
|
BLI_assert((htype & ~BM_ALL_NOLOOP) == 0);
|
|
|
|
|
|
2013-04-14 12:01:12 +00:00
|
|
|
switch (htype) {
|
|
|
|
|
case BM_VERT: return bm->totvert;
|
|
|
|
|
case BM_EDGE: return bm->totedge;
|
|
|
|
|
case BM_FACE: return bm->totface;
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-23 01:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-01 15:39:52 +10:00
|
|
|
/**
|
|
|
|
|
* Special case: Python uses custom-data layers to hold PyObject references.
|
|
|
|
|
* These have to be kept in-place, else the PyObject's we point to, wont point back to us.
|
|
|
|
|
*
|
|
|
|
|
* \note ``ele_src`` Is a duplicate, so we don't need to worry about getting in a feedback loop.
|
|
|
|
|
*
|
|
|
|
|
* \note If there are other customdata layers which need this functionality, it should be generalized.
|
|
|
|
|
* However #BM_mesh_remap is currently the only place where this is done.
|
|
|
|
|
*/
|
|
|
|
|
static void bm_mesh_remap_cd_update(
|
|
|
|
|
BMHeader *ele_dst, BMHeader *ele_src,
|
|
|
|
|
const int cd_elem_pyptr)
|
|
|
|
|
{
|
|
|
|
|
void **pyptr_dst_p = BM_ELEM_CD_GET_VOID_P(((BMElem *)ele_dst), cd_elem_pyptr);
|
|
|
|
|
void **pyptr_src_p = BM_ELEM_CD_GET_VOID_P(((BMElem *)ele_src), cd_elem_pyptr);
|
|
|
|
|
*pyptr_dst_p = *pyptr_src_p;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 12:31:39 +00:00
|
|
|
/**
|
|
|
|
|
* Remaps the vertices, edges and/or faces of the bmesh as indicated by vert/edge/face_idx arrays
|
|
|
|
|
* (xxx_idx[org_index] = new_index).
|
|
|
|
|
*
|
|
|
|
|
* 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...).
|
|
|
|
|
*
|
|
|
|
|
* WARNING: Be careful if you keep pointers to affected BM elements, or arrays, when using this func!
|
|
|
|
|
*/
|
2014-08-07 11:50:53 +10:00
|
|
|
void BM_mesh_remap(
|
|
|
|
|
BMesh *bm,
|
|
|
|
|
const unsigned int *vert_idx,
|
|
|
|
|
const unsigned int *edge_idx,
|
|
|
|
|
const unsigned int *face_idx)
|
2012-04-19 12:31:39 +00:00
|
|
|
{
|
|
|
|
|
/* Mapping old to new pointers. */
|
|
|
|
|
GHash *vptr_map = NULL, *eptr_map = NULL, *fptr_map = NULL;
|
|
|
|
|
BMIter iter, iterl;
|
|
|
|
|
BMVert *ve;
|
|
|
|
|
BMEdge *ed;
|
|
|
|
|
BMFace *fa;
|
|
|
|
|
BMLoop *lo;
|
|
|
|
|
|
|
|
|
|
if (!(vert_idx || edge_idx || face_idx))
|
|
|
|
|
return;
|
|
|
|
|
|
2014-08-07 11:50:53 +10:00
|
|
|
BM_mesh_elem_table_ensure(
|
|
|
|
|
bm,
|
|
|
|
|
(vert_idx ? BM_VERT : 0) |
|
|
|
|
|
(edge_idx ? BM_EDGE : 0) |
|
|
|
|
|
(face_idx ? BM_FACE : 0));
|
|
|
|
|
|
2013-08-24 20:16:14 +00:00
|
|
|
/* Remap Verts */
|
2012-04-19 12:31:39 +00:00
|
|
|
if (vert_idx) {
|
|
|
|
|
BMVert **verts_pool, *verts_copy, **vep;
|
|
|
|
|
int i, totvert = bm->totvert;
|
2014-08-07 11:50:53 +10:00
|
|
|
const unsigned int *new_idx;
|
2015-09-01 15:39:52 +10:00
|
|
|
const int cd_vert_pyptr = CustomData_get_offset(&bm->vdata, CD_BM_ELEM_PYPTR);
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
/* Init the old-to-new vert pointers mapping */
|
2013-08-24 17:33:47 +00:00
|
|
|
vptr_map = BLI_ghash_ptr_new_ex("BM_mesh_remap vert pointers mapping", bm->totvert);
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
/* Make a copy of all vertices. */
|
2014-08-07 11:50:53 +10:00
|
|
|
verts_pool = bm->vtable;
|
2012-04-19 12:31:39 +00:00
|
|
|
verts_copy = MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy");
|
|
|
|
|
for (i = totvert, ve = verts_copy + totvert - 1, vep = verts_pool + totvert - 1; i--; ve--, vep--) {
|
|
|
|
|
*ve = **vep;
|
|
|
|
|
/* printf("*vep: %p, verts_pool[%d]: %p\n", *vep, i, verts_pool[i]);*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy back verts to their new place, and update old2new pointers mapping. */
|
|
|
|
|
new_idx = vert_idx + totvert - 1;
|
|
|
|
|
ve = verts_copy + totvert - 1;
|
|
|
|
|
vep = verts_pool + totvert - 1; /* old, org pointer */
|
|
|
|
|
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);*/
|
2015-05-11 12:39:39 +10:00
|
|
|
BLI_ghash_insert(vptr_map, *vep, new_vep);
|
2015-09-01 15:39:52 +10:00
|
|
|
if (cd_vert_pyptr != -1) {
|
|
|
|
|
bm_mesh_remap_cd_update(&(*vep)->head, &new_vep->head, cd_vert_pyptr);
|
|
|
|
|
}
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
bm->elem_index_dirty |= BM_VERT;
|
2014-08-07 11:50:53 +10:00
|
|
|
bm->elem_table_dirty |= BM_VERT;
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(verts_copy);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 20:16:14 +00:00
|
|
|
/* Remap Edges */
|
2012-04-19 12:31:39 +00:00
|
|
|
if (edge_idx) {
|
|
|
|
|
BMEdge **edges_pool, *edges_copy, **edp;
|
|
|
|
|
int i, totedge = bm->totedge;
|
2014-08-07 11:50:53 +10:00
|
|
|
const unsigned int *new_idx;
|
2015-09-01 15:39:52 +10:00
|
|
|
const int cd_edge_pyptr = CustomData_get_offset(&bm->edata, CD_BM_ELEM_PYPTR);
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
/* Init the old-to-new vert pointers mapping */
|
2013-08-24 17:33:47 +00:00
|
|
|
eptr_map = BLI_ghash_ptr_new_ex("BM_mesh_remap edge pointers mapping", bm->totedge);
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
/* Make a copy of all vertices. */
|
2014-08-07 11:50:53 +10:00
|
|
|
edges_pool = bm->etable;
|
2012-04-19 12:31:39 +00:00
|
|
|
edges_copy = MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy");
|
|
|
|
|
for (i = totedge, ed = edges_copy + totedge - 1, edp = edges_pool + totedge - 1; i--; ed--, edp--) {
|
|
|
|
|
*ed = **edp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy back verts to their new place, and update old2new pointers mapping. */
|
|
|
|
|
new_idx = edge_idx + totedge - 1;
|
|
|
|
|
ed = edges_copy + totedge - 1;
|
|
|
|
|
edp = edges_pool + totedge - 1; /* old, org pointer */
|
|
|
|
|
for (i = totedge; i--; new_idx--, ed--, edp--) {
|
|
|
|
|
BMEdge *new_edp = edges_pool[*new_idx];
|
|
|
|
|
*new_edp = *ed;
|
2015-05-11 12:39:39 +10:00
|
|
|
BLI_ghash_insert(eptr_map, *edp, new_edp);
|
2012-05-01 14:13:14 +00:00
|
|
|
/* printf("mapping edge from %d to %d (%p/%p to %p)\n", i, *new_idx, *edp, edges_pool[i], new_edp);*/
|
2015-09-01 15:39:52 +10:00
|
|
|
if (cd_edge_pyptr != -1) {
|
|
|
|
|
bm_mesh_remap_cd_update(&(*edp)->head, &new_edp->head, cd_edge_pyptr);
|
|
|
|
|
}
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
bm->elem_index_dirty |= BM_EDGE;
|
2014-08-07 11:50:53 +10:00
|
|
|
bm->elem_table_dirty |= BM_EDGE;
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(edges_copy);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 20:16:14 +00:00
|
|
|
/* Remap Faces */
|
2012-04-19 12:31:39 +00:00
|
|
|
if (face_idx) {
|
|
|
|
|
BMFace **faces_pool, *faces_copy, **fap;
|
|
|
|
|
int i, totface = bm->totface;
|
2014-08-07 11:50:53 +10:00
|
|
|
const unsigned int *new_idx;
|
2015-09-01 15:39:52 +10:00
|
|
|
const int cd_poly_pyptr = CustomData_get_offset(&bm->pdata, CD_BM_ELEM_PYPTR);
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
/* Init the old-to-new vert pointers mapping */
|
2013-08-24 17:33:47 +00:00
|
|
|
fptr_map = BLI_ghash_ptr_new_ex("BM_mesh_remap face pointers mapping", bm->totface);
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
/* Make a copy of all vertices. */
|
2014-08-07 11:50:53 +10:00
|
|
|
faces_pool = bm->ftable;
|
2012-04-19 12:31:39 +00:00
|
|
|
faces_copy = MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy");
|
|
|
|
|
for (i = totface, fa = faces_copy + totface - 1, fap = faces_pool + totface - 1; i--; fa--, fap--) {
|
|
|
|
|
*fa = **fap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Copy back verts to their new place, and update old2new pointers mapping. */
|
|
|
|
|
new_idx = face_idx + totface - 1;
|
|
|
|
|
fa = faces_copy + totface - 1;
|
|
|
|
|
fap = faces_pool + totface - 1; /* old, org pointer */
|
|
|
|
|
for (i = totface; i--; new_idx--, fa--, fap--) {
|
|
|
|
|
BMFace *new_fap = faces_pool[*new_idx];
|
|
|
|
|
*new_fap = *fa;
|
2015-05-11 12:39:39 +10:00
|
|
|
BLI_ghash_insert(fptr_map, *fap, new_fap);
|
2015-09-01 15:39:52 +10:00
|
|
|
if (cd_poly_pyptr != -1) {
|
|
|
|
|
bm_mesh_remap_cd_update(&(*fap)->head, &new_fap->head, cd_poly_pyptr);
|
|
|
|
|
}
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
bm->elem_index_dirty |= BM_FACE | BM_LOOP;
|
2014-08-07 11:50:53 +10:00
|
|
|
bm->elem_table_dirty |= BM_FACE;
|
2012-04-19 12:31:39 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(faces_copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* And now, fix all vertices/edges/faces/loops pointers! */
|
|
|
|
|
/* Verts' pointers, only edge pointers... */
|
|
|
|
|
if (eptr_map) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (ve, &iter, bm, BM_VERTS_OF_MESH) {
|
2015-09-01 15:01:00 +10:00
|
|
|
/* printf("Vert e: %p -> %p\n", ve->e, BLI_ghash_lookup(eptr_map, ve->e));*/
|
2015-09-01 15:06:07 +10:00
|
|
|
if (ve->e) {
|
|
|
|
|
ve->e = BLI_ghash_lookup(eptr_map, ve->e);
|
|
|
|
|
BLI_assert(ve->e);
|
|
|
|
|
}
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-01 14:13:14 +00:00
|
|
|
/* 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) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (ed, &iter, bm, BM_EDGES_OF_MESH) {
|
2012-05-01 14:13:14 +00:00
|
|
|
if (vptr_map) {
|
2015-09-01 15:01:00 +10:00
|
|
|
/* 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);
|
2015-09-01 15:06:07 +10:00
|
|
|
BLI_assert(ed->v1);
|
|
|
|
|
BLI_assert(ed->v2);
|
2012-05-01 14:13:14 +00:00
|
|
|
}
|
|
|
|
|
if (eptr_map) {
|
|
|
|
|
/* printf("Edge v1_disk_link prev: %p -> %p\n", ed->v1_disk_link.prev,*/
|
2015-09-01 15:01:00 +10:00
|
|
|
/* BLI_ghash_lookup(eptr_map, ed->v1_disk_link.prev));*/
|
2012-05-01 14:13:14 +00:00
|
|
|
/* printf("Edge v1_disk_link next: %p -> %p\n", ed->v1_disk_link.next,*/
|
2015-09-01 15:01:00 +10:00
|
|
|
/* BLI_ghash_lookup(eptr_map, ed->v1_disk_link.next));*/
|
2012-05-01 14:13:14 +00:00
|
|
|
/* printf("Edge v2_disk_link prev: %p -> %p\n", ed->v2_disk_link.prev,*/
|
2015-09-01 15:01:00 +10:00
|
|
|
/* BLI_ghash_lookup(eptr_map, ed->v2_disk_link.prev));*/
|
2012-05-01 14:13:14 +00:00
|
|
|
/* printf("Edge v2_disk_link next: %p -> %p\n", ed->v2_disk_link.next,*/
|
2015-09-01 15:01:00 +10:00
|
|
|
/* 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);
|
|
|
|
|
ed->v2_disk_link.next = BLI_ghash_lookup(eptr_map, ed->v2_disk_link.next);
|
2015-09-01 15:06:07 +10:00
|
|
|
BLI_assert(ed->v1_disk_link.prev);
|
|
|
|
|
BLI_assert(ed->v1_disk_link.next);
|
|
|
|
|
BLI_assert(ed->v2_disk_link.prev);
|
|
|
|
|
BLI_assert(ed->v2_disk_link.next);
|
2012-05-01 14:13:14 +00:00
|
|
|
}
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Faces' pointers (loops, in fact), always needed... */
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (fa, &iter, bm, BM_FACES_OF_MESH) {
|
|
|
|
|
BM_ITER_ELEM (lo, &iterl, fa, BM_LOOPS_OF_FACE) {
|
2012-04-19 12:31:39 +00:00
|
|
|
if (vptr_map) {
|
2015-09-01 15:01:00 +10:00
|
|
|
/* printf("Loop v: %p -> %p\n", lo->v, BLI_ghash_lookup(vptr_map, lo->v));*/
|
|
|
|
|
lo->v = BLI_ghash_lookup(vptr_map, lo->v);
|
2015-09-01 15:06:07 +10:00
|
|
|
BLI_assert(lo->v);
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
if (eptr_map) {
|
2015-09-01 15:01:00 +10:00
|
|
|
/* printf("Loop e: %p -> %p\n", lo->e, BLI_ghash_lookup(eptr_map, lo->e));*/
|
|
|
|
|
lo->e = BLI_ghash_lookup(eptr_map, lo->e);
|
2015-09-01 15:06:07 +10:00
|
|
|
BLI_assert(lo->e);
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
if (fptr_map) {
|
2015-09-01 15:01:00 +10:00
|
|
|
/* printf("Loop f: %p -> %p\n", lo->f, BLI_ghash_lookup(fptr_map, lo->f));*/
|
|
|
|
|
lo->f = BLI_ghash_lookup(fptr_map, lo->f);
|
2015-09-01 15:06:07 +10:00
|
|
|
BLI_assert(lo->f);
|
2012-04-19 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 15:39:06 +11:00
|
|
|
/* Selection history */
|
|
|
|
|
{
|
|
|
|
|
BMEditSelection *ese;
|
|
|
|
|
for (ese = bm->selected.first; ese; ese = ese->next) {
|
|
|
|
|
switch (ese->htype) {
|
|
|
|
|
case BM_VERT:
|
|
|
|
|
if (vptr_map) {
|
|
|
|
|
ese->ele = BLI_ghash_lookup(vptr_map, ese->ele);
|
|
|
|
|
BLI_assert(ese->ele);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BM_EDGE:
|
|
|
|
|
if (eptr_map) {
|
|
|
|
|
ese->ele = BLI_ghash_lookup(eptr_map, ese->ele);
|
|
|
|
|
BLI_assert(ese->ele);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case BM_FACE:
|
|
|
|
|
if (fptr_map) {
|
|
|
|
|
ese->ele = BLI_ghash_lookup(fptr_map, ese->ele);
|
|
|
|
|
BLI_assert(ese->ele);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fptr_map) {
|
|
|
|
|
if (bm->act_face) {
|
|
|
|
|
bm->act_face = BLI_ghash_lookup(fptr_map, bm->act_face);
|
|
|
|
|
BLI_assert(bm->act_face);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-19 12:31:39 +00:00
|
|
|
if (vptr_map)
|
|
|
|
|
BLI_ghash_free(vptr_map, NULL, NULL);
|
|
|
|
|
if (eptr_map)
|
|
|
|
|
BLI_ghash_free(eptr_map, NULL, NULL);
|
|
|
|
|
if (fptr_map)
|
|
|
|
|
BLI_ghash_free(fptr_map, NULL, NULL);
|
|
|
|
|
}
|