2011-10-24 23:32:24 +00:00
|
|
|
/*
|
2009-05-16 16:18:08 +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,
|
2011-12-02 03:18:34 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-05-16 16:18:08 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
/** \file blender/blenkernel/intern/editderivedmesh.c
|
|
|
|
|
* \ingroup bke
|
2013-04-16 05:46:17 +00:00
|
|
|
*
|
|
|
|
|
* basic design:
|
|
|
|
|
*
|
|
|
|
|
* the bmesh derivedmesh exposes the mesh as triangles. it stores pointers
|
|
|
|
|
* to three loops per triangle. the derivedmesh stores a cache of tessellations
|
|
|
|
|
* for each face. this cache will smartly update as needed (though at first
|
|
|
|
|
* it'll simply be more brute force). keeping track of face/edge counts may
|
2013-10-31 14:10:01 +00:00
|
|
|
* be a small problem.
|
2013-04-16 05:46:17 +00:00
|
|
|
*
|
|
|
|
|
* this won't be the most efficient thing, considering that internal edges and
|
|
|
|
|
* faces of tessellations are exposed. looking up an edge by index in particular
|
|
|
|
|
* is likely to be a little slow.
|
2011-12-02 03:18:34 +00:00
|
|
|
*/
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2017-09-25 09:56:02 +02:00
|
|
|
#include "atomic_ops.h"
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "BLI_math.h"
|
2018-02-18 21:27:33 +11:00
|
|
|
#include "BLI_jitter_2d.h"
|
2013-04-18 17:23:02 +00:00
|
|
|
#include "BLI_bitmap.h"
|
2016-04-26 18:43:02 +10:00
|
|
|
#include "BLI_task.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
2013-04-16 05:46:17 +00:00
|
|
|
#include "BKE_editmesh.h"
|
2013-04-17 09:27:23 +00:00
|
|
|
#include "BKE_editmesh_bvh.h"
|
2017-05-09 08:50:45 +10:00
|
|
|
#include "BKE_editmesh_tangent.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "DNA_object_types.h"
|
2018-04-19 11:03:58 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
typedef struct EditDerivedBMesh {
|
|
|
|
|
DerivedMesh dm;
|
|
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
BMEditMesh *em;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
EditMeshData emd;
|
2009-05-16 16:18:08 +00:00
|
|
|
} EditDerivedBMesh;
|
|
|
|
|
|
2013-07-22 16:49:37 +00:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Lazy initialize datastructures */
|
|
|
|
|
|
|
|
|
|
static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm);
|
|
|
|
|
|
|
|
|
|
static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm)
|
|
|
|
|
{
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos && (bmdm->emd.vertexNos == NULL)) {
|
2013-07-22 16:49:37 +00:00
|
|
|
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
const float (*vertexCos)[3], (*polyNos)[3];
|
|
|
|
|
float (*vertexNos)[3];
|
|
|
|
|
|
|
|
|
|
/* calculate vertex normals from poly normals */
|
|
|
|
|
emDM_ensurePolyNormals(bmdm);
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
polyNos = bmdm->emd.polyNos;
|
|
|
|
|
vertexCos = bmdm->emd.vertexCos;
|
2014-02-12 20:48:09 +01:00
|
|
|
vertexNos = MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__);
|
2013-07-22 16:49:37 +00:00
|
|
|
|
2014-02-12 20:48:09 +01:00
|
|
|
BM_verts_calc_normal_vcos(bm, polyNos, vertexCos, vertexNos);
|
2013-07-22 16:49:37 +00:00
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
bmdm->emd.vertexNos = (const float (*)[3])vertexNos;
|
2013-07-22 16:49:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
|
|
|
|
|
{
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos && (bmdm->emd.polyNos == NULL)) {
|
2013-07-22 16:49:37 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
const float (*vertexCos)[3];
|
|
|
|
|
float (*polyNos)[3];
|
|
|
|
|
|
|
|
|
|
BMFace *efa;
|
|
|
|
|
BMIter fiter;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
|
|
|
|
|
polyNos = MEM_mallocN(sizeof(*polyNos) * bm->totface, __func__);
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
vertexCos = bmdm->emd.vertexCos;
|
2013-07-22 16:49:37 +00:00
|
|
|
|
|
|
|
|
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
|
|
|
|
|
BM_elem_index_set(efa, i); /* set_inline */
|
|
|
|
|
BM_face_calc_normal_vcos(bm, efa, polyNos[i], vertexCos);
|
|
|
|
|
}
|
|
|
|
|
bm->elem_index_dirty &= ~BM_FACE;
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
bmdm->emd.polyNos = (const float (*)[3])polyNos;
|
2013-07-22 16:49:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
|
|
|
|
|
{
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.polyCos == NULL) {
|
2013-07-22 16:49:37 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
float (*polyCos)[3];
|
|
|
|
|
|
|
|
|
|
BMFace *efa;
|
|
|
|
|
BMIter fiter;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
polyCos = MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__);
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
2013-07-22 16:49:37 +00:00
|
|
|
const float (*vertexCos)[3];
|
2018-04-19 11:03:58 +02:00
|
|
|
vertexCos = bmdm->emd.vertexCos;
|
2013-07-22 16:49:37 +00:00
|
|
|
|
2017-06-01 15:04:22 +10:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
|
2013-07-22 16:49:37 +00:00
|
|
|
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
|
|
|
|
|
BM_face_calc_center_mean_vcos(bm, efa, polyCos[i], vertexCos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
|
|
|
|
|
BM_face_calc_center_mean(efa, polyCos[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
bmdm->emd.polyCos = (const float (*)[3])polyCos;
|
2013-07-22 16:49:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 17:36:43 +00:00
|
|
|
static void emDM_calcNormals(DerivedMesh *dm)
|
2011-11-13 15:13:59 +00:00
|
|
|
{
|
|
|
|
|
/* Nothing to do: normals are already calculated and stored on the
|
2012-03-03 20:19:11 +00:00
|
|
|
* BMVerts and BMFaces */
|
2013-05-30 17:36:43 +00:00
|
|
|
dm->dirty &= ~DM_DIRTY_NORMALS;
|
2011-11-13 15:13:59 +00: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
|
|
|
static void emDM_calcLoopNormalsSpaceArray(
|
|
|
|
|
DerivedMesh *dm, const bool use_split_normals, const float split_angle, MLoopNorSpaceArray *r_lnors_spacearr);
|
|
|
|
|
|
2015-01-19 14:11:40 +01:00
|
|
|
static void emDM_calcLoopNormals(DerivedMesh *dm, const bool use_split_normals, const float split_angle)
|
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
|
|
|
{
|
|
|
|
|
emDM_calcLoopNormalsSpaceArray(dm, use_split_normals, split_angle, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* #define DEBUG_CLNORS */
|
|
|
|
|
|
|
|
|
|
static void emDM_calcLoopNormalsSpaceArray(
|
|
|
|
|
DerivedMesh *dm, const bool use_split_normals, const float split_angle, MLoopNorSpaceArray *r_lnors_spacearr)
|
2014-04-13 12:18:51 +02:00
|
|
|
{
|
2014-04-13 12:25:02 +02:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
const float (*vertexCos)[3], (*vertexNos)[3], (*polyNos)[3];
|
|
|
|
|
float (*loopNos)[3];
|
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
|
|
|
short (*clnors_data)[2];
|
|
|
|
|
int cd_loop_clnors_offset;
|
2014-04-13 12:25:02 +02:00
|
|
|
|
|
|
|
|
/* calculate loop normals from poly and vertex normals */
|
|
|
|
|
emDM_ensureVertNormals(bmdm);
|
2014-04-20 23:12:18 +02:00
|
|
|
emDM_ensurePolyNormals(bmdm);
|
2014-04-13 12:25:02 +02:00
|
|
|
dm->dirty &= ~DM_DIRTY_NORMALS;
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
vertexCos = bmdm->emd.vertexCos;
|
|
|
|
|
vertexNos = bmdm->emd.vertexNos;
|
|
|
|
|
polyNos = bmdm->emd.polyNos;
|
2014-04-13 12:25:02 +02:00
|
|
|
|
|
|
|
|
loopNos = dm->getLoopDataArray(dm, CD_NORMAL);
|
|
|
|
|
if (!loopNos) {
|
|
|
|
|
DM_add_loop_layer(dm, CD_NORMAL, CD_CALLOC, NULL);
|
|
|
|
|
loopNos = dm->getLoopDataArray(dm, CD_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
|
|
|
/* We can have both, give priority to dm's data, and fallback to bm's ones. */
|
|
|
|
|
clnors_data = dm->getLoopDataArray(dm, CD_CUSTOMLOOPNORMAL);
|
|
|
|
|
cd_loop_clnors_offset = clnors_data ? -1 : CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
|
|
|
|
|
|
|
|
|
|
BM_loops_calc_normal_vcos(bm, vertexCos, vertexNos, polyNos, use_split_normals, split_angle, loopNos,
|
|
|
|
|
r_lnors_spacearr, clnors_data, cd_loop_clnors_offset);
|
|
|
|
|
#ifdef DEBUG_CLNORS
|
|
|
|
|
if (r_lnors_spacearr) {
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < numLoops; i++) {
|
|
|
|
|
if (r_lnors_spacearr->lspacearr[i]->ref_alpha != 0.0f) {
|
|
|
|
|
LinkNode *loops = r_lnors_spacearr->lspacearr[i]->loops;
|
|
|
|
|
printf("Loop %d uses lnor space %p:\n", i, r_lnors_spacearr->lspacearr[i]);
|
|
|
|
|
print_v3("\tfinal lnor:", loopNos[i]);
|
|
|
|
|
print_v3("\tauto lnor:", r_lnors_spacearr->lspacearr[i]->vec_lnor);
|
|
|
|
|
print_v3("\tref_vec:", r_lnors_spacearr->lspacearr[i]->vec_ref);
|
|
|
|
|
printf("\talpha: %f\n\tbeta: %f\n\tloops: %p\n", r_lnors_spacearr->lspacearr[i]->ref_alpha,
|
|
|
|
|
r_lnors_spacearr->lspacearr[i]->ref_beta, r_lnors_spacearr->lspacearr[i]->loops);
|
|
|
|
|
printf("\t\t(shared with loops");
|
|
|
|
|
while (loops) {
|
|
|
|
|
printf(" %d", GET_INT_FROM_POINTER(loops->link));
|
|
|
|
|
loops = loops->next;
|
|
|
|
|
}
|
|
|
|
|
printf(")\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("Loop %d has no lnor space\n", i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2014-04-13 12:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 18:43:02 +10:00
|
|
|
static void emDM_calc_loop_tangents(
|
|
|
|
|
DerivedMesh *dm, bool calc_active_tangent,
|
2017-05-09 08:50:45 +10:00
|
|
|
const char (*tangent_names)[MAX_NAME], int tangent_names_len)
|
2015-08-24 15:14:34 +10:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMEditMesh *em = bmdm->em;
|
2017-05-24 22:33:21 +10:00
|
|
|
|
|
|
|
|
if (CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV) == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
const float (*poly_normals)[3] = bmdm->emd.polyNos;
|
2017-05-09 08:50:45 +10:00
|
|
|
const float (*loop_normals)[3] = CustomData_get_layer(&dm->loopData, CD_NORMAL);
|
|
|
|
|
const float (*vert_orco)[3] = dm->getVertDataArray(dm, CD_ORCO); /* can be NULL */
|
|
|
|
|
BKE_editmesh_loop_tangent_calc(
|
|
|
|
|
em, calc_active_tangent,
|
|
|
|
|
tangent_names, tangent_names_len,
|
|
|
|
|
poly_normals, loop_normals,
|
|
|
|
|
vert_orco,
|
|
|
|
|
&dm->loopData, dm->numLoopData,
|
|
|
|
|
&dm->tangent_mask);
|
2015-08-24 15:14:34 +10:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 15:05:01 +11:00
|
|
|
|
2012-03-02 16:05:54 +00:00
|
|
|
static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm))
|
2009-06-23 05:35:49 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
/* do nothing */
|
2009-06-23 05:35:49 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2016-11-23 17:19:03 -02:00
|
|
|
static void emDM_recalcLoopTri(DerivedMesh *dm)
|
2015-07-17 03:36:03 +10:00
|
|
|
{
|
2016-11-23 17:19:03 -02:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
|
|
|
|
MLoopTri *mlooptri;
|
|
|
|
|
const int tottri = bmdm->em->tottri;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
DM_ensure_looptri_data(dm);
|
2017-09-19 13:57:46 +02:00
|
|
|
mlooptri = dm->looptris.array_wip;
|
2016-11-23 17:19:03 -02:00
|
|
|
|
2017-09-20 20:45:51 +02:00
|
|
|
BLI_assert(tottri == 0 || mlooptri != NULL);
|
2016-11-23 17:19:03 -02:00
|
|
|
BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num);
|
|
|
|
|
BLI_assert(tottri == dm->looptris.num);
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bmdm->em->bm, BM_FACE | BM_LOOP);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < tottri; i++) {
|
|
|
|
|
BMLoop **ltri = looptris[i];
|
|
|
|
|
MLoopTri *lt = &mlooptri[i];
|
|
|
|
|
|
|
|
|
|
ARRAY_SET_ITEMS(
|
2017-03-12 02:40:04 +11:00
|
|
|
lt->tri,
|
|
|
|
|
BM_elem_index_get(ltri[0]),
|
|
|
|
|
BM_elem_index_get(ltri[1]),
|
|
|
|
|
BM_elem_index_get(ltri[2]));
|
2016-11-23 17:19:03 -02:00
|
|
|
lt->poly = BM_elem_index_get(ltri[0]->f);
|
|
|
|
|
}
|
2017-09-19 13:57:46 +02:00
|
|
|
|
|
|
|
|
BLI_assert(dm->looptris.array == NULL);
|
2017-09-25 10:40:50 +02:00
|
|
|
atomic_cas_ptr((void **)&dm->looptris.array, dm->looptris.array, dm->looptris.array_wip);
|
2017-09-25 09:56:02 +02:00
|
|
|
dm->looptris.array_wip = NULL;
|
2015-07-17 03:36:03 +10:00
|
|
|
}
|
|
|
|
|
|
2013-07-22 22:59:47 +00:00
|
|
|
static void emDM_foreachMappedVert(
|
|
|
|
|
DerivedMesh *dm,
|
|
|
|
|
void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
|
|
|
|
|
void *userData,
|
|
|
|
|
DMForeachFlag flag)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
|
|
|
|
const float (*vertexCos)[3] = bmdm->emd.vertexCos;
|
2013-07-22 22:59:47 +00:00
|
|
|
const float (*vertexNos)[3];
|
|
|
|
|
|
|
|
|
|
if (flag & DM_FOREACH_USE_NORMAL) {
|
|
|
|
|
emDM_ensureVertNormals(bmdm);
|
2018-04-19 11:03:58 +02:00
|
|
|
vertexNos = bmdm->emd.vertexNos;
|
2013-07-22 22:59:47 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
vertexNos = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2013-07-22 22:59:47 +00:00
|
|
|
const float *no = (flag & DM_FOREACH_USE_NORMAL) ? vertexNos[i] : NULL;
|
|
|
|
|
func(userData, i, vertexCos[i], no, NULL);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2013-07-22 22:59:47 +00:00
|
|
|
const float *no = (flag & DM_FOREACH_USE_NORMAL) ? eve->no : NULL;
|
|
|
|
|
func(userData, i, eve->co, no, NULL);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-18 05:54:31 +10:00
|
|
|
static void emDM_foreachMappedEdge(
|
|
|
|
|
DerivedMesh *dm,
|
|
|
|
|
void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]),
|
|
|
|
|
void *userData)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *eed;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
|
2011-12-02 03:18:34 +00:00
|
|
|
func(userData, i,
|
2018-04-19 11:03:58 +02:00
|
|
|
bmdm->emd.vertexCos[BM_elem_index_get(eed->v1)],
|
|
|
|
|
bmdm->emd.vertexCos[BM_elem_index_get(eed->v2)]);
|
2012-05-13 14:47:53 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
|
2009-05-16 16:18:08 +00:00
|
|
|
func(userData, i, eed->v1->co, eed->v2->co);
|
2012-05-13 14:47:53 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 15:18:11 +02:00
|
|
|
static void emDM_foreachMappedLoop(
|
|
|
|
|
DerivedMesh *dm,
|
|
|
|
|
void (*func)(void *userData, int vertex_index, int face_index, const float co[3], const float no[3]),
|
|
|
|
|
void *userData,
|
|
|
|
|
DMForeachFlag flag)
|
|
|
|
|
{
|
|
|
|
|
/* We can't use dm->getLoopDataLayout(dm) here, we want to always access dm->loopData, EditDerivedBMesh would
|
|
|
|
|
* return loop data from bmesh itself. */
|
|
|
|
|
const float (*lnors)[3] = (flag & DM_FOREACH_USE_NORMAL) ? DM_get_loop_data_layer(dm, CD_NORMAL) : NULL;
|
|
|
|
|
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
BMFace *efa;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
const float (*vertexCos)[3] = bmdm->emd.vertexCos;
|
2014-04-23 15:18:11 +02:00
|
|
|
int f_idx;
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
|
|
|
|
|
BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, f_idx) {
|
|
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
|
|
|
|
|
do {
|
|
|
|
|
const BMVert *eve = l_iter->v;
|
|
|
|
|
const int v_idx = BM_elem_index_get(eve);
|
|
|
|
|
const float *no = lnors ? *lnors++ : NULL;
|
|
|
|
|
func(userData, v_idx, f_idx, vertexCos ? vertexCos[v_idx] : eve->co, no);
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-22 22:59:47 +00:00
|
|
|
static void emDM_foreachMappedFaceCenter(
|
|
|
|
|
DerivedMesh *dm,
|
|
|
|
|
void (*func)(void *userData, int index, const float co[3], const float no[3]),
|
|
|
|
|
void *userData,
|
|
|
|
|
DMForeachFlag flag)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2013-07-22 16:49:37 +00:00
|
|
|
const float (*polyNos)[3];
|
|
|
|
|
const float (*polyCos)[3];
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *efa;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-07-22 16:49:37 +00:00
|
|
|
emDM_ensurePolyCenters(bmdm);
|
2018-04-19 11:03:58 +02:00
|
|
|
polyCos = bmdm->emd.polyCos; /* always set */
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-07-22 22:59:47 +00:00
|
|
|
if (flag & DM_FOREACH_USE_NORMAL) {
|
|
|
|
|
emDM_ensurePolyNormals(bmdm);
|
2018-04-19 11:03:58 +02:00
|
|
|
polyNos = bmdm->emd.polyNos; /* maybe NULL */
|
2013-07-22 22:59:47 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
polyNos = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (polyNos) {
|
|
|
|
|
BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
|
|
|
|
|
const float *no = polyNos[i];
|
|
|
|
|
func(userData, i, polyCos[i], no);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
|
|
|
|
|
const float *no = (flag & DM_FOREACH_USE_NORMAL) ? efa->no : NULL;
|
|
|
|
|
func(userData, i, polyCos[i], no);
|
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getMinMax(DerivedMesh *dm, float r_min[3], float r_max[3])
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
if (bm->totvert) {
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2018-04-19 11:03:58 +02:00
|
|
|
minmax_v3v3_v3(r_min, r_max, bmdm->emd.vertexCos[i]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
|
|
|
|
|
minmax_v3v3_v3(r_min, r_max, eve->co);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
zero_v3(r_min);
|
|
|
|
|
zero_v3(r_max);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumVerts(DerivedMesh *dm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totvert;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumEdges(DerivedMesh *dm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totedge;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumTessFaces(DerivedMesh *dm)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->tottri;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumLoops(DerivedMesh *dm)
|
2011-11-30 18:03:56 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totloop;
|
2011-11-30 18:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static int emDM_getNumPolys(DerivedMesh *dm)
|
2009-06-23 05:35:49 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return bmdm->em->bm->totface;
|
2009-06-23 05:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 22:36:15 +11:00
|
|
|
static void bmvert_to_mvert(BMesh *bm, BMVert *ev, MVert *r_vert)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
{
|
2014-04-27 00:20:13 +10:00
|
|
|
const float *f;
|
2013-01-09 18:20:11 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
copy_v3_v3(r_vert->co, ev->co);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
normal_float_to_short_v3(r_vert->no, ev->no);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->flag = BM_vert_flag_to_mflag(ev);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-01-09 18:20:11 +00:00
|
|
|
if ((f = CustomData_bmesh_get(&bm->vdata, ev->head.data, CD_BWEIGHT))) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->bweight = (unsigned char)((*f) * 255.0f);
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getVert(DerivedMesh *dm, int index, MVert *r_vert)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:58:49 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMVert *ev;
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
if (UNLIKELY(index < 0 || index >= bm->totvert)) {
|
2013-04-13 20:40:34 +00:00
|
|
|
BLI_assert(!"error in emDM_getVert");
|
2009-05-16 16:18:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 02:05:33 +00:00
|
|
|
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
|
|
|
|
|
ev = bm->vtable[index]; /* should be BM_vert_at_index() */
|
2013-04-13 20:58:49 +00:00
|
|
|
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
2012-02-19 01:51:36 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
bmvert_to_mvert(bm, ev, r_vert);
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos)
|
|
|
|
|
copy_v3_v3(r_vert->co, bmdm->emd.vertexCos[index]);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-09 12:59:31 +00:00
|
|
|
static void emDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
|
|
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(index < 0 || index >= bm->totvert)) {
|
|
|
|
|
BLI_assert(!"error in emDM_getVertCo");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
|
|
|
|
copy_v3_v3(r_co, bmdm->emd.vertexCos[index]);
|
2013-07-09 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-10-28 02:05:33 +00:00
|
|
|
BMVert *ev;
|
|
|
|
|
|
|
|
|
|
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
|
|
|
|
|
ev = bm->vtable[index]; /* should be BM_vert_at_index() */
|
2013-07-09 12:59:31 +00:00
|
|
|
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
|
|
|
|
copy_v3_v3(r_co, ev->co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emDM_getVertNo(DerivedMesh *dm, int index, float r_no[3])
|
|
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(index < 0 || index >= bm->totvert)) {
|
|
|
|
|
BLI_assert(!"error in emDM_getVertNo");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-22 16:49:37 +00:00
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
2013-07-22 16:49:37 +00:00
|
|
|
emDM_ensureVertNormals(bmdm);
|
2018-04-19 11:03:58 +02:00
|
|
|
copy_v3_v3(r_no, bmdm->emd.vertexNos[index]);
|
2013-07-09 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-10-28 02:05:33 +00:00
|
|
|
BMVert *ev;
|
|
|
|
|
|
|
|
|
|
BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
|
|
|
|
|
ev = bm->vtable[index]; /* should be BM_vert_at_index() */
|
2013-07-09 12:59:31 +00:00
|
|
|
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
|
|
|
|
copy_v3_v3(r_no, ev->no);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void emDM_getPolyNo(DerivedMesh *dm, int index, float r_no[3])
|
|
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(index < 0 || index >= bm->totface)) {
|
|
|
|
|
BLI_assert(!"error in emDM_getPolyNo");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
2013-07-22 16:49:37 +00:00
|
|
|
emDM_ensurePolyNormals(bmdm);
|
2018-04-19 11:03:58 +02:00
|
|
|
copy_v3_v3(r_no, bmdm->emd.polyNos[index]);
|
2013-07-09 12:59:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-10-28 02:05:33 +00:00
|
|
|
BMFace *efa;
|
|
|
|
|
|
|
|
|
|
BLI_assert((bm->elem_table_dirty & BM_FACE) == 0);
|
|
|
|
|
efa = bm->ftable[index]; /* should be BM_vert_at_index() */
|
2013-07-09 12:59:31 +00:00
|
|
|
// efa = BM_face_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
|
|
|
|
copy_v3_v3(r_no, efa->no);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *r_edge)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMEdge *e;
|
2014-04-27 00:20:13 +10:00
|
|
|
const float *f;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
if (UNLIKELY(index < 0 || index >= bm->totedge)) {
|
2013-04-13 20:40:34 +00:00
|
|
|
BLI_assert(!"error in emDM_getEdge");
|
2009-06-23 05:35:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 02:05:33 +00:00
|
|
|
BLI_assert((bm->elem_table_dirty & BM_EDGE) == 0);
|
|
|
|
|
e = bm->etable[index]; /* should be BM_edge_at_index() */
|
2013-04-13 20:58:49 +00:00
|
|
|
// e = BM_edge_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->flag = BM_edge_flag_to_mflag(e);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->v1 = BM_elem_index_get(e->v1);
|
|
|
|
|
r_edge->v2 = BM_elem_index_get(e->v2);
|
2013-01-09 18:20:11 +00:00
|
|
|
|
|
|
|
|
if ((f = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BWEIGHT))) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->bweight = (unsigned char)((*f) * 255.0f);
|
2013-01-09 18:20:11 +00:00
|
|
|
}
|
|
|
|
|
if ((f = CustomData_bmesh_get(&bm->edata, e->head.data, CD_CREASE))) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->crease = (unsigned char)((*f) * 255.0f);
|
2013-01-09 18:20:11 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getTessFace(DerivedMesh *dm, int index, MFace *r_face)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *ef;
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:40:34 +00:00
|
|
|
if (UNLIKELY(index < 0 || index >= bmdm->em->tottri)) {
|
|
|
|
|
BLI_assert(!"error in emDM_getTessFace");
|
2009-06-23 05:35:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
ltri = bmdm->em->looptris[index];
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 17:57:11 +00:00
|
|
|
ef = ltri[0]->f;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->mat_nr = (unsigned char) ef->mat_nr;
|
|
|
|
|
r_face->flag = BM_face_flag_to_mflag(ef);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->v1 = BM_elem_index_get(ltri[0]->v);
|
|
|
|
|
r_face->v2 = BM_elem_index_get(ltri[1]->v);
|
|
|
|
|
r_face->v3 = BM_elem_index_get(ltri[2]->v);
|
|
|
|
|
r_face->v4 = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
test_index_face(r_face, NULL, 0, 3);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyVertArray(DerivedMesh *dm, MVert *r_vert)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-04-17 13:07:13 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMVert *eve;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
2013-01-10 04:43:31 +00:00
|
|
|
const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
2012-05-13 14:47:53 +00:00
|
|
|
int i;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2018-04-19 11:03:58 +02:00
|
|
|
copy_v3_v3(r_vert->co, bmdm->emd.vertexCos[i]);
|
2013-04-13 20:58:49 +00:00
|
|
|
normal_float_to_short_v3(r_vert->no, eve->no);
|
|
|
|
|
r_vert->flag = BM_vert_flag_to_mflag(eve);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset) : 0;
|
2013-01-10 04:43:31 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert++;
|
2012-05-13 14:47:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
|
2013-04-13 20:58:49 +00:00
|
|
|
copy_v3_v3(r_vert->co, eve->co);
|
|
|
|
|
normal_float_to_short_v3(r_vert->no, eve->no);
|
|
|
|
|
r_vert->flag = BM_vert_flag_to_mflag(eve);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert->bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset) : 0;
|
2013-01-10 04:43:31 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_vert++;
|
2010-07-14 22:06:10 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *r_edge)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = ((EditDerivedBMesh *)dm)->em->bm;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMEdge *eed;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
2013-01-10 04:43:31 +00:00
|
|
|
|
|
|
|
|
const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
|
|
|
|
|
const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->v1 = BM_elem_index_get(eed->v1);
|
|
|
|
|
r_edge->v2 = BM_elem_index_get(eed->v2);
|
2010-07-14 22:06:10 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->flag = BM_edge_flag_to_mflag(eed);
|
2012-05-13 14:47:53 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge->crease = (cd_edge_crease_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_crease_offset) : 0;
|
|
|
|
|
r_edge->bweight = (cd_edge_bweight_offset != -1) ? BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_bweight_offset) : 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_edge++;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyTessFaceArray(DerivedMesh *dm, MFace *r_face)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
|
|
|
|
struct BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
2009-05-16 16:18:08 +00:00
|
|
|
BMFace *ef;
|
|
|
|
|
int i;
|
|
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
for (i = 0; i < bmdm->em->tottri; i++, r_face++) {
|
2013-04-13 17:57:11 +00:00
|
|
|
BMLoop **ltri = looptris[i];
|
|
|
|
|
ef = ltri[0]->f;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->mat_nr = (unsigned char) ef->mat_nr;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->flag = BM_face_flag_to_mflag(ef);
|
|
|
|
|
r_face->edcode = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_face->v1 = BM_elem_index_get(ltri[0]->v);
|
|
|
|
|
r_face->v2 = BM_elem_index_get(ltri[1]->v);
|
|
|
|
|
r_face->v3 = BM_elem_index_get(ltri[2]->v);
|
|
|
|
|
r_face->v4 = 0;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
test_index_face(r_face, NULL, 0, 3);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyLoopArray(DerivedMesh *dm, MLoop *r_loop)
|
2011-06-14 03:16:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2013-07-22 18:01:27 +00:00
|
|
|
BMIter iter;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMFace *efa;
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2012-02-12 10:51:45 +00:00
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE);
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
|
2013-07-22 18:01:27 +00:00
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
|
|
|
|
|
do {
|
2013-07-23 15:05:33 +00:00
|
|
|
r_loop->v = BM_elem_index_get(l_iter->v);
|
|
|
|
|
r_loop->e = BM_elem_index_get(l_iter->e);
|
2013-04-13 20:58:49 +00:00
|
|
|
r_loop++;
|
2013-07-22 18:01:27 +00:00
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2011-06-14 03:16:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_copyPolyArray(DerivedMesh *dm, MPoly *r_poly)
|
2011-06-14 03:16:08 +00:00
|
|
|
{
|
2012-02-19 01:51:36 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2011-07-03 17:07:07 +00:00
|
|
|
BMIter iter;
|
2012-05-13 14:47:53 +00:00
|
|
|
BMFace *efa;
|
2011-09-26 05:10:37 +00:00
|
|
|
int i;
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2011-09-26 05:10:37 +00:00
|
|
|
i = 0;
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
|
2013-04-13 20:58:49 +00:00
|
|
|
r_poly->flag = BM_face_flag_to_mflag(efa);
|
|
|
|
|
r_poly->loopstart = i;
|
|
|
|
|
r_poly->totloop = efa->len;
|
|
|
|
|
r_poly->mat_nr = efa->mat_nr;
|
2011-06-14 03:16:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
r_poly++;
|
2012-05-13 14:47:53 +00:00
|
|
|
i += efa->len;
|
2011-06-14 03:16:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void *emDM_getTessFaceDataArray(DerivedMesh *dm, int type)
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2013-04-13 20:31:52 +00:00
|
|
|
BMesh *bm = bmdm->em->bm;
|
2009-05-16 16:18:08 +00:00
|
|
|
void *datalayer;
|
|
|
|
|
|
2009-08-15 17:31:28 +00:00
|
|
|
datalayer = DM_get_tessface_data_layer(dm, type);
|
2011-12-02 03:18:34 +00:00
|
|
|
if (datalayer)
|
2009-05-16 16:18:08 +00:00
|
|
|
return datalayer;
|
|
|
|
|
|
2012-04-16 04:17:33 +00:00
|
|
|
/* layers are store per face for editmesh, we convert to a temporary
|
2009-05-16 16:18:08 +00:00
|
|
|
* data layer array in the derivedmesh when these are requested */
|
2011-12-02 03:18:34 +00:00
|
|
|
if (type == CD_MTFACE || type == CD_MCOL) {
|
2015-01-01 23:26:03 +11:00
|
|
|
const char *bmdata;
|
|
|
|
|
char *data;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2017-05-25 15:11:00 +10:00
|
|
|
bool has_type_source = CustomData_has_layer(&bm->ldata, (type == CD_MTFACE) ? CD_MLOOPUV : CD_MLOOPCOL);
|
2017-05-25 02:44:58 +10:00
|
|
|
|
|
|
|
|
if (has_type_source) {
|
2011-09-07 06:49:20 +00:00
|
|
|
/* offset = bm->pdata.layers[index].offset; */ /* UNUSED */
|
2013-05-10 06:46:32 +00:00
|
|
|
BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
2012-04-16 04:17:33 +00:00
|
|
|
const int size = CustomData_sizeof(type);
|
|
|
|
|
int i, j;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-08-15 17:31:28 +00:00
|
|
|
DM_add_tessface_layer(dm, type, CD_CALLOC, NULL);
|
2017-05-25 02:44:58 +10:00
|
|
|
const int index = CustomData_get_layer_index(&dm->faceData, type);
|
2009-05-16 16:18:08 +00:00
|
|
|
dm->faceData.layers[index].flag |= CD_FLAG_TEMPORARY;
|
|
|
|
|
|
2009-08-15 17:31:28 +00:00
|
|
|
data = datalayer = DM_get_tessface_data_layer(dm, type);
|
2012-04-16 04:17:33 +00:00
|
|
|
|
|
|
|
|
if (type == CD_MTFACE) {
|
2013-05-10 06:46:32 +00:00
|
|
|
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
|
|
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
for (i = 0; i < bmdm->em->tottri; i++, data += size) {
|
2012-04-16 04:17:33 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2013-05-10 06:46:32 +00:00
|
|
|
// bmdata = CustomData_bmesh_get(&bm->ldata, looptris[i][j]->head.data, CD_MLOOPUV);
|
|
|
|
|
bmdata = BM_ELEM_CD_GET_VOID_P(looptris[i][j], cd_loop_uv_offset);
|
2015-01-01 23:26:03 +11:00
|
|
|
copy_v2_v2(((MTFace *)data)->uv[j], ((const MLoopUV *)bmdata)->uv);
|
2012-04-16 04:17:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-05-10 06:46:32 +00:00
|
|
|
const int cd_loop_color_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPCOL);
|
2013-04-13 20:31:52 +00:00
|
|
|
for (i = 0; i < bmdm->em->tottri; i++, data += size) {
|
2012-04-16 04:17:33 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2013-05-10 06:46:32 +00:00
|
|
|
// bmdata = CustomData_bmesh_get(&bm->ldata, looptris[i][j]->head.data, CD_MLOOPCOL);
|
|
|
|
|
bmdata = BM_ELEM_CD_GET_VOID_P(looptris[i][j], cd_loop_color_offset);
|
2015-01-01 23:26:03 +11:00
|
|
|
MESH_MLOOPCOL_TO_MCOL(((const MLoopCol *)bmdata), (((MCol *)data) + j));
|
2012-04-16 04:17:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:25:02 +02:00
|
|
|
/* Special handling for CD_TESSLOOPNORMAL, we generate it on demand as well. */
|
|
|
|
|
if (type == CD_TESSLOOPNORMAL) {
|
|
|
|
|
const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
|
|
|
|
|
|
|
|
|
|
if (lnors) {
|
|
|
|
|
BMLoop *(*looptris)[3] = bmdm->em->looptris;
|
|
|
|
|
short (*tlnors)[4][3], (*tlnor)[4][3];
|
|
|
|
|
int index, i, j;
|
|
|
|
|
|
|
|
|
|
DM_add_tessface_layer(dm, type, CD_CALLOC, NULL);
|
|
|
|
|
index = CustomData_get_layer_index(&dm->faceData, type);
|
|
|
|
|
dm->faceData.layers[index].flag |= CD_FLAG_TEMPORARY;
|
|
|
|
|
|
|
|
|
|
tlnor = tlnors = DM_get_tessface_data_layer(dm, type);
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_LOOP);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < bmdm->em->tottri; i++, tlnor++, looptris++) {
|
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
|
normal_float_to_short_v3((*tlnor)[j], lnors[BM_elem_index_get((*looptris)[j])]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
return datalayer;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
static void emDM_getVertCos(DerivedMesh *dm, float (*r_cos)[3])
|
2011-05-09 22:16:31 +00:00
|
|
|
{
|
2013-04-13 20:58:49 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BMesh *bm = bmdm->em->bm;
|
2011-05-09 22:16:31 +00:00
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
int i;
|
2011-05-10 23:48:09 +00:00
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2018-04-19 11:03:58 +02:00
|
|
|
copy_v3_v3(r_cos[i], bmdm->emd.vertexCos[i]);
|
2011-12-02 03:18:34 +00:00
|
|
|
}
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
|
copy_v3_v3(r_cos[i], eve->co);
|
2011-05-09 22:16:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
static void emDM_release(DerivedMesh *dm)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 10:06:25 +00:00
|
|
|
{
|
2012-05-03 21:19:31 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
|
|
|
|
if (DM_release(dm)) {
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.vertexCos) {
|
|
|
|
|
MEM_freeN((void *)bmdm->emd.vertexCos);
|
|
|
|
|
if (bmdm->emd.vertexNos) {
|
|
|
|
|
MEM_freeN((void *)bmdm->emd.vertexNos);
|
2013-07-22 16:49:37 +00:00
|
|
|
}
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.polyNos) {
|
|
|
|
|
MEM_freeN((void *)bmdm->emd.polyNos);
|
2013-07-22 16:49:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
if (bmdm->emd.polyCos) {
|
|
|
|
|
MEM_freeN((void *)bmdm->emd.polyCos);
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2009-05-16 16:18:08 +00:00
|
|
|
MEM_freeN(bmdm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getVertDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->vdata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getEdgeDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->edata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getTessFaceDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2011-05-10 17:01:26 +00:00
|
|
|
return &bmdm->dm.faceData;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 02:14:43 +00:00
|
|
|
static CustomData *bmDm_getLoopDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->ldata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-29 13:01:51 +00:00
|
|
|
static CustomData *bmDm_getPolyDataLayout(DerivedMesh *dm)
|
2009-08-18 20:05:08 +00:00
|
|
|
{
|
2012-05-12 19:18:02 +00:00
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
return &bmdm->em->bm->pdata;
|
2009-08-18 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-22 21:20:09 +10:00
|
|
|
/**
|
|
|
|
|
* \note This may be called per-draw,
|
|
|
|
|
* avoid allocating large arrays where possible and keep this a thin wrapper for #BMesh.
|
|
|
|
|
*/
|
2015-07-18 05:54:31 +10:00
|
|
|
DerivedMesh *getEditDerivedBMesh(
|
2016-06-22 21:20:09 +10:00
|
|
|
BMEditMesh *em, struct Object *UNUSED(ob),
|
|
|
|
|
CustomDataMask data_mask,
|
2015-07-18 05:54:31 +10:00
|
|
|
float (*vertexCos)[3])
|
2009-05-16 16:18:08 +00:00
|
|
|
{
|
2011-09-12 02:44:17 +00:00
|
|
|
EditDerivedBMesh *bmdm = MEM_callocN(sizeof(*bmdm), __func__);
|
2009-05-16 16:18:08 +00:00
|
|
|
BMesh *bm = em->bm;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:31:52 +00:00
|
|
|
bmdm->em = em;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
DM_init((DerivedMesh *)bmdm, DM_TYPE_EDITBMESH, bm->totvert,
|
|
|
|
|
bm->totedge, em->tottri, bm->totloop, bm->totface);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-01-10 04:43:31 +00:00
|
|
|
/* could also get from the objects mesh directly */
|
|
|
|
|
bmdm->dm.cd_flag = BM_mesh_cd_flag_from_bmesh(bm);
|
|
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
bmdm->dm.getVertCos = emDM_getVertCos;
|
|
|
|
|
bmdm->dm.getMinMax = emDM_getMinMax;
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2009-08-18 20:05:08 +00:00
|
|
|
bmdm->dm.getVertDataLayout = bmDm_getVertDataLayout;
|
|
|
|
|
bmdm->dm.getEdgeDataLayout = bmDm_getEdgeDataLayout;
|
|
|
|
|
bmdm->dm.getTessFaceDataLayout = bmDm_getTessFaceDataLayout;
|
|
|
|
|
bmdm->dm.getLoopDataLayout = bmDm_getLoopDataLayout;
|
2011-11-29 13:01:51 +00:00
|
|
|
bmdm->dm.getPolyDataLayout = bmDm_getPolyDataLayout;
|
2009-08-18 20:05:08 +00:00
|
|
|
|
2011-12-02 03:18:34 +00:00
|
|
|
bmdm->dm.getNumVerts = emDM_getNumVerts;
|
|
|
|
|
bmdm->dm.getNumEdges = emDM_getNumEdges;
|
|
|
|
|
bmdm->dm.getNumTessFaces = emDM_getNumTessFaces;
|
|
|
|
|
bmdm->dm.getNumLoops = emDM_getNumLoops;
|
|
|
|
|
bmdm->dm.getNumPolys = emDM_getNumPolys;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.getVert = emDM_getVert;
|
2013-07-09 12:59:31 +00:00
|
|
|
bmdm->dm.getVertCo = emDM_getVertCo;
|
|
|
|
|
bmdm->dm.getVertNo = emDM_getVertNo;
|
|
|
|
|
bmdm->dm.getPolyNo = emDM_getPolyNo;
|
2011-12-02 03:18:34 +00:00
|
|
|
bmdm->dm.getEdge = emDM_getEdge;
|
|
|
|
|
bmdm->dm.getTessFace = emDM_getTessFace;
|
|
|
|
|
bmdm->dm.copyVertArray = emDM_copyVertArray;
|
|
|
|
|
bmdm->dm.copyEdgeArray = emDM_copyEdgeArray;
|
|
|
|
|
bmdm->dm.copyTessFaceArray = emDM_copyTessFaceArray;
|
|
|
|
|
bmdm->dm.copyLoopArray = emDM_copyLoopArray;
|
|
|
|
|
bmdm->dm.copyPolyArray = emDM_copyPolyArray;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.getTessFaceDataArray = emDM_getTessFaceDataArray;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.calcNormals = emDM_calcNormals;
|
2014-04-13 12:18:51 +02:00
|
|
|
bmdm->dm.calcLoopNormals = emDM_calcLoopNormals;
|
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
|
|
|
bmdm->dm.calcLoopNormalsSpaceArray = emDM_calcLoopNormalsSpaceArray;
|
2016-04-26 18:43:02 +10:00
|
|
|
bmdm->dm.calcLoopTangents = emDM_calc_loop_tangents;
|
2012-03-02 16:05:54 +00:00
|
|
|
bmdm->dm.recalcTessellation = emDM_recalcTessellation;
|
2015-07-17 03:36:03 +10:00
|
|
|
bmdm->dm.recalcLoopTri = emDM_recalcLoopTri;
|
2011-12-02 03:18:34 +00:00
|
|
|
|
|
|
|
|
bmdm->dm.foreachMappedVert = emDM_foreachMappedVert;
|
2014-04-23 15:18:11 +02:00
|
|
|
bmdm->dm.foreachMappedLoop = emDM_foreachMappedLoop;
|
2011-12-02 03:18:34 +00:00
|
|
|
bmdm->dm.foreachMappedEdge = emDM_foreachMappedEdge;
|
|
|
|
|
bmdm->dm.foreachMappedFaceCenter = emDM_foreachMappedFaceCenter;
|
|
|
|
|
|
|
|
|
|
bmdm->dm.release = emDM_release;
|
|
|
|
|
|
2018-04-19 11:03:58 +02:00
|
|
|
bmdm->emd.vertexCos = (const float (*)[3])vertexCos;
|
2013-07-09 12:59:31 +00:00
|
|
|
bmdm->dm.deformedOnly = (vertexCos != NULL);
|
2009-05-16 16:18:08 +00:00
|
|
|
|
2016-06-22 21:20:09 +10:00
|
|
|
const int cd_dvert_offset = (data_mask & CD_MASK_MDEFORMVERT) ?
|
|
|
|
|
CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT) : -1;
|
|
|
|
|
|
2013-05-27 12:42:48 +00:00
|
|
|
if (cd_dvert_offset != -1) {
|
2009-05-16 16:18:08 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMVert *eve;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
DM_add_vert_layer(&bmdm->dm, CD_MDEFORMVERT, CD_CALLOC, NULL);
|
2011-12-02 03:18:34 +00:00
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2009-05-16 16:18:08 +00:00
|
|
|
DM_set_vert_data(&bmdm->dm, i, CD_MDEFORMVERT,
|
2013-05-27 12:42:48 +00:00
|
|
|
BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset));
|
2012-05-03 21:19:31 +00:00
|
|
|
}
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-22 21:20:09 +10:00
|
|
|
const int cd_skin_offset = (data_mask & CD_MASK_MVERT_SKIN) ?
|
|
|
|
|
CustomData_get_offset(&bm->vdata, CD_MVERT_SKIN) : -1;
|
|
|
|
|
|
2013-05-27 12:42:48 +00:00
|
|
|
if (cd_skin_offset != -1) {
|
2012-05-22 15:29:27 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMVert *eve;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
DM_add_vert_layer(&bmdm->dm, CD_MVERT_SKIN, CD_CALLOC, NULL);
|
|
|
|
|
|
2013-04-13 20:58:49 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
2012-05-22 15:29:27 +00:00
|
|
|
DM_set_vert_data(&bmdm->dm, i, CD_MVERT_SKIN,
|
2013-05-27 12:42:48 +00:00
|
|
|
BM_ELEM_CD_GET_VOID_P(eve, cd_skin_offset));
|
2012-05-22 15:29:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 21:19:31 +00:00
|
|
|
return (DerivedMesh *)bmdm;
|
2009-05-16 16:18:08 +00:00
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* StatVis Functions */
|
|
|
|
|
|
|
|
|
|
static void axis_from_enum_v3(float v[3], const char axis)
|
|
|
|
|
{
|
|
|
|
|
zero_v3(v);
|
|
|
|
|
if (axis < 3) v[axis] = 1.0f;
|
|
|
|
|
else v[axis - 3] = -1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void statvis_calc_overhang(
|
|
|
|
|
BMEditMesh *em,
|
2013-04-18 04:24:18 +00:00
|
|
|
const float (*polyNos)[3],
|
2013-04-17 09:27:23 +00:00
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max, const char axis,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMFace *f;
|
|
|
|
|
float dir[3];
|
|
|
|
|
int index;
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
2014-02-24 19:53:44 +11:00
|
|
|
bool is_max;
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
/* fallback */
|
2014-03-23 11:35:52 +01:00
|
|
|
unsigned char col_fallback[4] = {64, 64, 64, 255}; /* gray */
|
|
|
|
|
unsigned char col_fallback_max[4] = {0, 0, 0, 255}; /* max color */
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
BLI_assert(min <= max);
|
|
|
|
|
|
|
|
|
|
axis_from_enum_v3(dir, axis);
|
|
|
|
|
|
2013-04-17 23:30:19 +00:00
|
|
|
if (LIKELY(em->ob)) {
|
|
|
|
|
mul_transposed_mat3_m4_v3(em->ob->obmat, dir);
|
|
|
|
|
normalize_v3(dir);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-24 19:53:44 +11:00
|
|
|
/* fallback max */
|
|
|
|
|
{
|
|
|
|
|
float fcol[3];
|
|
|
|
|
weight_to_rgb(fcol, 1.0f);
|
2014-03-23 11:35:52 +01:00
|
|
|
rgb_float_to_uchar(col_fallback_max, fcol);
|
2014-02-24 19:53:44 +11:00
|
|
|
}
|
|
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
/* now convert into global space */
|
|
|
|
|
BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, index) {
|
|
|
|
|
float fac = angle_normalized_v3v3(polyNos ? polyNos[index] : f->no, dir) / (float)M_PI;
|
|
|
|
|
|
|
|
|
|
/* remap */
|
2014-02-24 19:53:44 +11:00
|
|
|
if ((is_max = (fac <= max)) && (fac >= min)) {
|
2013-04-17 09:27:23 +00:00
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
fac = 1.0f - fac;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[index], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-10-11 01:44:47 +02:00
|
|
|
const unsigned char *fallback = is_max ? col_fallback_max : col_fallback;
|
|
|
|
|
copy_v4_v4_uchar(r_face_colors[index], fallback);
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* so we can use jitter values for face interpolation */
|
|
|
|
|
static void uv_from_jitter_v2(float uv[2])
|
|
|
|
|
{
|
|
|
|
|
uv[0] += 0.5f;
|
|
|
|
|
uv[1] += 0.5f;
|
|
|
|
|
if (uv[0] + uv[1] > 1.0f) {
|
|
|
|
|
uv[0] = 1.0f - uv[0];
|
|
|
|
|
uv[1] = 1.0f - uv[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLAMP(uv[0], 0.0f, 1.0f);
|
|
|
|
|
CLAMP(uv[1], 0.0f, 1.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void statvis_calc_thickness(
|
|
|
|
|
BMEditMesh *em,
|
2013-04-18 04:24:18 +00:00
|
|
|
const float (*vertexCos)[3],
|
2013-04-17 09:27:23 +00:00
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max, const int samples,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
2013-04-28 22:35:08 +00:00
|
|
|
const float eps_offset = 0.00002f; /* values <= 0.00001 give errors */
|
2013-04-17 09:27:23 +00:00
|
|
|
float *face_dists = (float *)r_face_colors; /* cheating */
|
|
|
|
|
const bool use_jit = samples < 32;
|
|
|
|
|
float jit_ofs[32][2];
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
const int tottri = em->tottri;
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
struct BMLoop *(*looptris)[3] = em->looptris;
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
2015-10-11 01:44:47 +02:00
|
|
|
const unsigned char col_fallback[4] = {64, 64, 64, 255};
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
struct BMBVHTree *bmtree;
|
|
|
|
|
|
|
|
|
|
BLI_assert(min <= max);
|
|
|
|
|
|
2015-05-05 17:08:29 +10:00
|
|
|
copy_vn_fl(face_dists, em->bm->totface, max);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
if (use_jit) {
|
|
|
|
|
int j;
|
|
|
|
|
BLI_assert(samples < 32);
|
2014-03-18 10:50:24 +11:00
|
|
|
BLI_jitter_init(jit_ofs, samples);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
for (j = 0; j < samples; j++) {
|
|
|
|
|
uv_from_jitter_v2(jit_ofs[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-18 18:20:21 +11:00
|
|
|
bmtree = BKE_bmbvh_new_from_editmesh(em, 0, vertexCos, false);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < tottri; i++) {
|
|
|
|
|
BMFace *f_hit;
|
|
|
|
|
BMLoop **ltri = looptris[i];
|
|
|
|
|
const int index = BM_elem_index_get(ltri[0]->f);
|
|
|
|
|
const float *cos[3];
|
|
|
|
|
float ray_co[3];
|
|
|
|
|
float ray_no[3];
|
|
|
|
|
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
cos[0] = vertexCos[BM_elem_index_get(ltri[0]->v)];
|
|
|
|
|
cos[1] = vertexCos[BM_elem_index_get(ltri[1]->v)];
|
2013-04-17 23:30:19 +00:00
|
|
|
cos[2] = vertexCos[BM_elem_index_get(ltri[2]->v)];
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cos[0] = ltri[0]->v->co;
|
|
|
|
|
cos[1] = ltri[1]->v->co;
|
|
|
|
|
cos[2] = ltri[2]->v->co;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
normal_tri_v3(ray_no, cos[2], cos[1], cos[0]);
|
|
|
|
|
|
2013-04-20 16:29:37 +00:00
|
|
|
#define FACE_RAY_TEST_ANGLE \
|
2013-08-30 16:34:44 +00:00
|
|
|
f_hit = BKE_bmbvh_ray_cast(bmtree, ray_co, ray_no, 0.0f, \
|
2013-04-20 16:29:37 +00:00
|
|
|
&dist, NULL, NULL); \
|
2013-04-20 16:49:02 +00:00
|
|
|
if (f_hit && dist < face_dists[index]) { \
|
2013-04-20 16:29:37 +00:00
|
|
|
float angle_fac = fabsf(dot_v3v3(ltri[0]->f->no, f_hit->no)); \
|
|
|
|
|
angle_fac = 1.0f - angle_fac; \
|
|
|
|
|
angle_fac = angle_fac * angle_fac * angle_fac; \
|
|
|
|
|
angle_fac = 1.0f - angle_fac; \
|
|
|
|
|
dist /= angle_fac; \
|
|
|
|
|
if (dist < face_dists[index]) { \
|
|
|
|
|
face_dists[index] = dist; \
|
|
|
|
|
} \
|
|
|
|
|
} (void)0
|
|
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
if (use_jit) {
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; j < samples; j++) {
|
2013-04-20 16:29:37 +00:00
|
|
|
float dist = face_dists[index];
|
2013-04-17 09:27:23 +00:00
|
|
|
interp_v3_v3v3v3_uv(ray_co, cos[0], cos[1], cos[2], jit_ofs[j]);
|
|
|
|
|
madd_v3_v3fl(ray_co, ray_no, eps_offset);
|
|
|
|
|
|
2013-04-20 16:29:37 +00:00
|
|
|
FACE_RAY_TEST_ANGLE;
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-04-20 16:29:37 +00:00
|
|
|
float dist = face_dists[index];
|
2013-04-17 09:27:23 +00:00
|
|
|
mid_v3_v3v3v3(ray_co, cos[0], cos[1], cos[2]);
|
|
|
|
|
madd_v3_v3fl(ray_co, ray_no, eps_offset);
|
|
|
|
|
|
2013-04-20 16:29:37 +00:00
|
|
|
FACE_RAY_TEST_ANGLE;
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_bmbvh_free(bmtree);
|
|
|
|
|
|
2013-04-17 09:27:23 +00:00
|
|
|
/* convert floats into color! */
|
|
|
|
|
for (i = 0; i < bm->totface; i++) {
|
|
|
|
|
float fac = face_dists[i];
|
|
|
|
|
|
|
|
|
|
/* important not '<=' */
|
|
|
|
|
if (fac < max) {
|
|
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
fac = 1.0f - fac;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[i], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-10-11 01:44:47 +02:00
|
|
|
copy_v4_v4_uchar(r_face_colors[i], col_fallback);
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void statvis_calc_intersect(
|
|
|
|
|
BMEditMesh *em,
|
2013-04-18 04:24:18 +00:00
|
|
|
const float (*vertexCos)[3],
|
2013-04-17 09:27:23 +00:00
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
BMesh *bm = em->bm;
|
2015-08-20 19:09:20 +10:00
|
|
|
int i;
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
/* fallback */
|
|
|
|
|
// const char col_fallback[4] = {64, 64, 64, 255};
|
2015-08-20 19:09:20 +10:00
|
|
|
float fcol[3];
|
|
|
|
|
unsigned char col[3];
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
struct BMBVHTree *bmtree;
|
2015-08-20 19:09:20 +10:00
|
|
|
BVHTreeOverlap *overlap;
|
|
|
|
|
unsigned int overlap_len;
|
2013-04-17 09:27:23 +00:00
|
|
|
|
|
|
|
|
memset(r_face_colors, 64, sizeof(int) * em->bm->totface);
|
|
|
|
|
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-18 18:20:21 +11:00
|
|
|
bmtree = BKE_bmbvh_new_from_editmesh(em, 0, vertexCos, false);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
2015-08-20 19:09:20 +10:00
|
|
|
overlap = BKE_bmbvh_overlap(bmtree, bmtree, &overlap_len);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
2015-08-20 19:09:20 +10:00
|
|
|
/* same for all faces */
|
|
|
|
|
weight_to_rgb(fcol, 1.0f);
|
|
|
|
|
rgb_float_to_uchar(col, fcol);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
2015-08-20 19:09:20 +10:00
|
|
|
if (overlap) {
|
|
|
|
|
for (i = 0; i < overlap_len; i++) {
|
|
|
|
|
BMFace *f_hit_pair[2] = {
|
|
|
|
|
em->looptris[overlap[i].indexA][0]->f,
|
|
|
|
|
em->looptris[overlap[i].indexB][0]->f,
|
|
|
|
|
};
|
|
|
|
|
int j;
|
2013-04-17 09:27:23 +00:00
|
|
|
|
2015-08-20 19:09:20 +10:00
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
|
BMFace *f_hit = f_hit_pair[j];
|
|
|
|
|
int index;
|
2013-04-17 09:27:23 +00:00
|
|
|
|
2015-08-20 19:09:20 +10:00
|
|
|
index = BM_elem_index_get(f_hit);
|
2013-04-17 09:27:23 +00:00
|
|
|
|
2015-10-11 01:44:47 +02:00
|
|
|
copy_v3_v3_uchar(r_face_colors[index], col);
|
2015-08-20 19:09:20 +10:00
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
2015-08-20 19:09:20 +10:00
|
|
|
MEM_freeN(overlap);
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BKE_bmbvh_free(bmtree);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 04:24:18 +00:00
|
|
|
static void statvis_calc_distort(
|
|
|
|
|
BMEditMesh *em,
|
2013-07-22 16:49:37 +00:00
|
|
|
const float (*vertexCos)[3], const float (*polyNos)[3],
|
2013-04-18 04:24:18 +00:00
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_face_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMFace *f;
|
2013-07-22 16:49:37 +00:00
|
|
|
const float *f_no;
|
2013-04-18 04:24:18 +00:00
|
|
|
int index;
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
2015-10-11 01:44:47 +02:00
|
|
|
const unsigned char col_fallback[4] = {64, 64, 64, 255};
|
2013-04-18 04:24:18 +00:00
|
|
|
|
|
|
|
|
/* now convert into global space */
|
|
|
|
|
BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, index) {
|
|
|
|
|
float fac;
|
|
|
|
|
|
|
|
|
|
if (f->len == 3) {
|
|
|
|
|
fac = -1.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BMLoop *l_iter, *l_first;
|
|
|
|
|
if (vertexCos) {
|
2013-07-22 16:49:37 +00:00
|
|
|
f_no = polyNos[index];
|
2013-04-18 04:24:18 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-07-22 16:49:37 +00:00
|
|
|
f_no = f->no;
|
2013-04-18 04:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fac = 0.0f;
|
|
|
|
|
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
|
|
|
|
|
do {
|
|
|
|
|
float no_corner[3];
|
|
|
|
|
if (vertexCos) {
|
|
|
|
|
normal_tri_v3(no_corner,
|
|
|
|
|
vertexCos[BM_elem_index_get(l_iter->prev->v)],
|
|
|
|
|
vertexCos[BM_elem_index_get(l_iter->v)],
|
|
|
|
|
vertexCos[BM_elem_index_get(l_iter->next->v)]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-07-12 23:06:59 +10:00
|
|
|
BM_loop_calc_face_normal_safe(l_iter, no_corner);
|
2013-04-18 04:24:18 +00:00
|
|
|
}
|
2013-04-18 09:12:06 +00:00
|
|
|
/* simple way to detect (what is most likely) concave */
|
|
|
|
|
if (dot_v3v3(f_no, no_corner) < 0.0f) {
|
|
|
|
|
negate_v3(no_corner);
|
|
|
|
|
}
|
2013-04-18 04:24:18 +00:00
|
|
|
fac = max_ff(fac, angle_normalized_v3v3(f_no, no_corner));
|
|
|
|
|
} while ((l_iter = l_iter->next) != l_first);
|
2013-04-18 09:12:06 +00:00
|
|
|
fac *= 2.0f;
|
2013-04-18 04:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remap */
|
|
|
|
|
if (fac >= min) {
|
|
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_face_colors[index], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-10-11 01:44:47 +02:00
|
|
|
copy_v4_v4_uchar(r_face_colors[index], col_fallback);
|
2013-04-18 04:24:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 17:09:56 +00:00
|
|
|
static void statvis_calc_sharp(
|
|
|
|
|
BMEditMesh *em,
|
|
|
|
|
const float (*vertexCos)[3],
|
|
|
|
|
/* values for calculating */
|
|
|
|
|
const float min, const float max,
|
|
|
|
|
/* result */
|
|
|
|
|
unsigned char (*r_vert_colors)[4])
|
|
|
|
|
{
|
|
|
|
|
float *vert_angles = (float *)r_vert_colors; /* cheating */
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMesh *bm = em->bm;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
//float f_no[3];
|
|
|
|
|
const float minmax_irange = 1.0f / (max - min);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* fallback */
|
2015-10-11 01:44:47 +02:00
|
|
|
const unsigned char col_fallback[4] = {64, 64, 64, 255};
|
2013-04-18 17:09:56 +00:00
|
|
|
|
|
|
|
|
(void)vertexCos; /* TODO */
|
|
|
|
|
|
2015-05-05 17:08:29 +10:00
|
|
|
copy_vn_fl(vert_angles, em->bm->totvert, -M_PI);
|
2013-04-18 17:09:56 +00:00
|
|
|
|
|
|
|
|
/* first assign float values to verts */
|
|
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
|
|
|
|
float angle = BM_edge_calc_face_angle_signed(e);
|
|
|
|
|
float *col1 = &vert_angles[BM_elem_index_get(e->v1)];
|
|
|
|
|
float *col2 = &vert_angles[BM_elem_index_get(e->v2)];
|
|
|
|
|
*col1 = max_ff(*col1, angle);
|
|
|
|
|
*col2 = max_ff(*col2, angle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* convert floats into color! */
|
|
|
|
|
for (i = 0; i < bm->totvert; i++) {
|
|
|
|
|
float fac = vert_angles[i];
|
|
|
|
|
|
|
|
|
|
/* important not '<=' */
|
|
|
|
|
if (fac > min) {
|
|
|
|
|
float fcol[3];
|
|
|
|
|
fac = (fac - min) * minmax_irange;
|
|
|
|
|
CLAMP(fac, 0.0f, 1.0f);
|
|
|
|
|
weight_to_rgb(fcol, fac);
|
|
|
|
|
rgb_float_to_uchar(r_vert_colors[i], fcol);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2015-10-11 01:44:47 +02:00
|
|
|
copy_v4_v4_uchar(r_vert_colors[i], col_fallback);
|
2013-04-18 17:09:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 05:54:31 +10:00
|
|
|
void BKE_editmesh_statvis_calc(
|
|
|
|
|
BMEditMesh *em, DerivedMesh *dm,
|
|
|
|
|
const MeshStatVis *statvis)
|
2013-04-17 09:27:23 +00:00
|
|
|
{
|
|
|
|
|
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
|
|
|
|
BLI_assert(dm == NULL || dm->type == DM_TYPE_EDITBMESH);
|
|
|
|
|
|
|
|
|
|
switch (statvis->type) {
|
|
|
|
|
case SCE_STATVIS_OVERHANG:
|
2013-04-17 23:30:19 +00:00
|
|
|
{
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis_calc_overhang(
|
2018-04-19 11:03:58 +02:00
|
|
|
em, bmdm ? bmdm->emd.polyNos : NULL,
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis->overhang_min / (float)M_PI,
|
|
|
|
|
statvis->overhang_max / (float)M_PI,
|
|
|
|
|
statvis->overhang_axis,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
2013-04-17 09:27:23 +00:00
|
|
|
break;
|
2013-04-17 23:30:19 +00:00
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
case SCE_STATVIS_THICKNESS:
|
2013-04-17 23:30:19 +00:00
|
|
|
{
|
|
|
|
|
const float scale = 1.0f / mat4_to_scale(em->ob->obmat);
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis_calc_thickness(
|
2018-04-19 11:03:58 +02:00
|
|
|
em, bmdm ? bmdm->emd.vertexCos : NULL,
|
2013-04-17 23:30:19 +00:00
|
|
|
statvis->thickness_min * scale,
|
|
|
|
|
statvis->thickness_max * scale,
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis->thickness_samples,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
2013-04-17 09:27:23 +00:00
|
|
|
break;
|
2013-04-17 23:30:19 +00:00
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
case SCE_STATVIS_INTERSECT:
|
2013-04-17 23:30:19 +00:00
|
|
|
{
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-04-17 09:27:23 +00:00
|
|
|
statvis_calc_intersect(
|
2018-04-19 11:03:58 +02:00
|
|
|
em, bmdm ? bmdm->emd.vertexCos : NULL,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
2013-04-17 09:27:23 +00:00
|
|
|
break;
|
2013-04-17 23:30:19 +00:00
|
|
|
}
|
2013-04-18 04:24:18 +00:00
|
|
|
case SCE_STATVIS_DISTORT:
|
|
|
|
|
{
|
2013-04-18 17:09:56 +00:00
|
|
|
BKE_editmesh_color_ensure(em, BM_FACE);
|
2013-07-22 16:49:37 +00:00
|
|
|
|
|
|
|
|
if (bmdm)
|
|
|
|
|
emDM_ensurePolyNormals(bmdm);
|
|
|
|
|
|
2013-04-18 04:24:18 +00:00
|
|
|
statvis_calc_distort(
|
2018-04-19 11:03:58 +02:00
|
|
|
em, bmdm ? bmdm->emd.vertexCos : NULL, bmdm ? bmdm->emd.polyNos : NULL,
|
2013-04-18 09:12:06 +00:00
|
|
|
statvis->distort_min,
|
|
|
|
|
statvis->distort_max,
|
2013-04-18 17:09:56 +00:00
|
|
|
em->derivedFaceColor);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case SCE_STATVIS_SHARP:
|
|
|
|
|
{
|
|
|
|
|
BKE_editmesh_color_ensure(em, BM_VERT);
|
|
|
|
|
statvis_calc_sharp(
|
2018-04-19 11:03:58 +02:00
|
|
|
em, bmdm ? bmdm->emd.vertexCos : NULL,
|
2013-04-18 17:09:56 +00:00
|
|
|
statvis->sharp_min,
|
|
|
|
|
statvis->sharp_max,
|
|
|
|
|
/* in this case they are vertex colors */
|
|
|
|
|
em->derivedVertColor);
|
2013-04-18 04:24:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2013-04-17 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-04-18 01:20:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/* Editmesh Vert Coords */
|
|
|
|
|
|
|
|
|
|
struct CageUserData {
|
|
|
|
|
int totvert;
|
|
|
|
|
float (*cos_cage)[3];
|
2013-07-22 23:20:48 +00:00
|
|
|
BLI_bitmap *visit_bitmap;
|
2013-04-18 01:20:04 +00:00
|
|
|
};
|
|
|
|
|
|
2015-07-18 05:54:31 +10:00
|
|
|
static void cage_mapped_verts_callback(
|
|
|
|
|
void *userData, int index, const float co[3],
|
|
|
|
|
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
|
2013-04-18 01:20:04 +00:00
|
|
|
{
|
|
|
|
|
struct CageUserData *data = userData;
|
|
|
|
|
|
2014-06-06 16:05:15 +10:00
|
|
|
if ((index >= 0 && index < data->totvert) && (!BLI_BITMAP_TEST(data->visit_bitmap, index))) {
|
|
|
|
|
BLI_BITMAP_ENABLE(data->visit_bitmap, index);
|
2013-04-18 01:20:04 +00:00
|
|
|
copy_v3_v3(data->cos_cage[index], co);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
float (*BKE_editmesh_vertexCos_get(struct Depsgraph *depsgraph, BMEditMesh *em, Scene *scene, int *r_numVerts))[3]
|
2013-04-18 01:20:04 +00:00
|
|
|
{
|
|
|
|
|
DerivedMesh *cage, *final;
|
2013-07-22 23:20:48 +00:00
|
|
|
BLI_bitmap *visit_bitmap;
|
2013-04-18 01:20:04 +00:00
|
|
|
struct CageUserData data;
|
|
|
|
|
float (*cos_cage)[3];
|
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
cage = editbmesh_get_derived_cage_and_final(depsgraph, scene, em->ob, em, CD_MASK_BAREMESH, &final);
|
2013-04-18 01:20:04 +00:00
|
|
|
cos_cage = MEM_callocN(sizeof(*cos_cage) * em->bm->totvert, "bmbvh cos_cage");
|
|
|
|
|
|
|
|
|
|
/* when initializing cage verts, we only want the first cage coordinate for each vertex,
|
|
|
|
|
* so that e.g. mirror or array use original vertex coordinates and not mirrored or duplicate */
|
|
|
|
|
visit_bitmap = BLI_BITMAP_NEW(em->bm->totvert, __func__);
|
|
|
|
|
|
|
|
|
|
data.totvert = em->bm->totvert;
|
|
|
|
|
data.cos_cage = cos_cage;
|
|
|
|
|
data.visit_bitmap = visit_bitmap;
|
|
|
|
|
|
2013-07-22 22:59:47 +00:00
|
|
|
cage->foreachMappedVert(cage, cage_mapped_verts_callback, &data, DM_FOREACH_NOP);
|
2013-04-18 01:20:04 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(visit_bitmap);
|
|
|
|
|
|
|
|
|
|
if (r_numVerts) {
|
|
|
|
|
*r_numVerts = em->bm->totvert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cos_cage;
|
|
|
|
|
}
|