2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2012-12-12 12:57:27 +00:00
|
|
|
*
|
|
|
|
|
* EdgeSplit modifier
|
|
|
|
|
*
|
|
|
|
|
* Splits edges in the mesh according to sharpness flag
|
|
|
|
|
* or edge angle (can be used to achieve autosmoothing)
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-05-09 04:06:48 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "BLI_math.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
|
2018-05-07 12:26:42 +02:00
|
|
|
#include "BKE_mesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
|
|
2012-10-24 07:24:11 +00:00
|
|
|
#include "bmesh.h"
|
2013-08-23 04:22:07 +00:00
|
|
|
#include "bmesh_tools.h"
|
2012-10-24 07:24:11 +00:00
|
|
|
|
2017-08-01 09:06:34 +10:00
|
|
|
#include "MOD_modifiertypes.h"
|
2010-07-19 04:44:37 +00:00
|
|
|
|
2019-01-30 11:02:06 +01:00
|
|
|
static Mesh *doEdgeSplit(Mesh *mesh, EdgeSplitModifierData *emd)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *result;
|
|
|
|
|
BMesh *bm;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
BMEdge *e;
|
|
|
|
|
const float threshold = cosf(emd->split_angle + 0.000000175f);
|
|
|
|
|
const bool do_split_angle = (emd->flags & MOD_EDGESPLIT_FROMANGLE) != 0 &&
|
|
|
|
|
emd->split_angle < (float)M_PI;
|
|
|
|
|
const bool do_split_all = do_split_angle && emd->split_angle < FLT_EPSILON;
|
|
|
|
|
const bool calc_face_normals = do_split_angle && !do_split_all;
|
|
|
|
|
|
|
|
|
|
bm = BKE_mesh_to_bmesh_ex(mesh,
|
|
|
|
|
&(struct BMeshCreateParams){0},
|
|
|
|
|
&(struct BMeshFromMeshParams){
|
|
|
|
|
.calc_face_normal = calc_face_normals,
|
|
|
|
|
.add_key_index = false,
|
|
|
|
|
.use_shapekey = false,
|
|
|
|
|
.active_shapekey = 0,
|
|
|
|
|
.cd_mask_extra = {.vmask = CD_MASK_ORIGINDEX,
|
|
|
|
|
.emask = CD_MASK_ORIGINDEX,
|
|
|
|
|
.pmask = CD_MASK_ORIGINDEX},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (do_split_angle) {
|
|
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
|
|
|
|
/* check for 1 edge having 2 face users */
|
|
|
|
|
BMLoop *l1, *l2;
|
|
|
|
|
if ((l1 = e->l) && (l2 = e->l->radial_next) != l1) {
|
|
|
|
|
if (/* 3+ faces on this edge, always split */
|
|
|
|
|
UNLIKELY(l1 != l2->radial_next) ||
|
|
|
|
|
/* O° angle setting, we want to split on all edges. */
|
|
|
|
|
do_split_all ||
|
|
|
|
|
/* 2 face edge - check angle*/
|
|
|
|
|
(dot_v3v3(l1->f->no, l2->f->no) < threshold)) {
|
|
|
|
|
BM_elem_flag_enable(e, BM_ELEM_TAG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (emd->flags & MOD_EDGESPLIT_FROMFLAG) {
|
|
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
|
|
|
|
/* check for 2 or more edge users */
|
|
|
|
|
if ((e->l) && (e->l->next != e->l)) {
|
|
|
|
|
if (!BM_elem_flag_test(e, BM_ELEM_SMOOTH)) {
|
|
|
|
|
BM_elem_flag_enable(e, BM_ELEM_TAG);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BM_mesh_edgesplit(bm, false, true, false);
|
|
|
|
|
|
|
|
|
|
/* BM_mesh_validate(bm); */ /* for troubleshooting */
|
|
|
|
|
|
2019-09-16 10:45:49 +02:00
|
|
|
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL, mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
BM_mesh_free(bm);
|
|
|
|
|
|
|
|
|
|
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
|
|
|
|
|
return result;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-19 04:44:37 +00:00
|
|
|
static void initData(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* default to 30-degree split angle, sharpness from both angle & flag */
|
|
|
|
|
emd->split_angle = DEG2RADF(30.0f);
|
|
|
|
|
emd->flags = MOD_EDGESPLIT_FROMANGLE | MOD_EDGESPLIT_FROMFLAG;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx), Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *result;
|
|
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (!(emd->flags & (MOD_EDGESPLIT_FROMANGLE | MOD_EDGESPLIT_FROMFLAG))) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return mesh;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
result = doEdgeSplit(mesh, emd);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return result;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_EdgeSplit = {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* name */ "EdgeSplit",
|
|
|
|
|
/* structName */ "EdgeSplitModifierData",
|
|
|
|
|
/* structSize */ sizeof(EdgeSplitModifierData),
|
|
|
|
|
/* type */ eModifierTypeType_Constructive,
|
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_AcceptsCVs |
|
|
|
|
|
eModifierTypeFlag_SupportsMapping | eModifierTypeFlag_SupportsEditmode |
|
|
|
|
|
eModifierTypeFlag_EnableInEditmode,
|
|
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
/* copyData */ BKE_modifier_copydata_generic,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* deformVerts */ NULL,
|
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
|
/* deformMatricesEM */ NULL,
|
2020-04-21 13:09:41 +02:00
|
|
|
/* modifyMesh */ modifyMesh,
|
|
|
|
|
/* modifyHair */ NULL,
|
|
|
|
|
/* modifyPointCloud */ NULL,
|
|
|
|
|
/* modifyVolume */ NULL,
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* initData */ initData,
|
|
|
|
|
/* requiredDataMask */ NULL,
|
|
|
|
|
/* freeData */ NULL,
|
|
|
|
|
/* isDisabled */ NULL,
|
|
|
|
|
/* updateDepsgraph */ NULL,
|
|
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
|
/* foreachObjectLink */ NULL,
|
|
|
|
|
/* foreachIDLink */ NULL,
|
|
|
|
|
/* foreachTexLink */ NULL,
|
|
|
|
|
/* freeRuntimeData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|