2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +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.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Daniel Dunbar
|
|
|
|
* Ton Roosendaal,
|
|
|
|
* Ben Batt,
|
|
|
|
* Brecht Van Lommel,
|
|
|
|
* Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-25 13:57:17 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_edgesplit.c
|
|
|
|
* \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"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "BLI_math.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
#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
|
|
|
|
2011-11-28 04:19:44 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
2010-07-19 04:44:37 +00:00
|
|
|
|
2013-06-19 08:19:36 +00:00
|
|
|
static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-02-12 15:02:33 +00:00
|
|
|
DerivedMesh *result;
|
2011-06-01 19:47:21 +00:00
|
|
|
BMesh *bm;
|
2011-11-28 03:41:14 +00:00
|
|
|
BMIter iter;
|
2011-06-01 19:47:21 +00:00
|
|
|
BMEdge *e;
|
Cleanup: Internal degrees removal.
This patch changes most of the reamining degrees usage in internal code into radians.
I let a few which I know off asside, for reasons explained below - and I'm not sure to have found out all of them.
WARNING: this introduces forward incompatibility, which means files saved from this version won't open 100% correctly
in previous versions (a few angle properties would use radians values as degrees...).
Details:
- Data:
-- Lamp.spotsize: Game engine exposed this setting in degrees, to not break the API here I kept it as such
(using getter/setter functions), still using radians internally.
-- Mesh.smoothresh: Didn't touch to this one, as we will hopefully replace it completely by loop normals currently in dev.
- Modifiers:
-- EdgeSplitModifierData.split_angle, BevelModifierData.bevel_angle: Done.
- Postprocessing:
-- WipeVars.angle (sequencer's effect), NodeBokehImage.angle, NodeBoxMask.rotation, NodeEllipseMask.rotation: Done.
- BGE:
-- bConstraintActuator: Orientation type done (the minloc[0] & maxloc[0] cases). Did not touch to 'limit location' type,
it can also limit rotation, but it exposes through RNA the same limit_min/limit_max, which hence
can be either distance or angle values, depending on the mode. Will leave this to BGE team.
-- bSoundActuator.cone_outer_angle_3d, bSoundActuator.cone_inner_angle_3d: Done (note I kept degrees in BGE itself,
as it seems this is the expected value here...).
-- bRadarSensor.angle: Done.
Reviewers: brecht, campbellbarton, sergey, gaiaclary, dfelinto, moguri, jbakker, lukastoenne, howardt
Reviewed By: brecht, campbellbarton, sergey, gaiaclary, moguri, jbakker, lukastoenne, howardt
Thanks to all!
Differential Revision: http://developer.blender.org/D59
2013-12-03 20:09:25 +01:00
|
|
|
float threshold = cosf(emd->split_angle + 0.000000175f);
|
2013-06-02 23:20:49 +00:00
|
|
|
const bool calc_face_normals = (emd->flags & MOD_EDGESPLIT_FROMANGLE) != 0;
|
2012-02-12 15:02:33 +00:00
|
|
|
|
2013-06-02 23:20:49 +00:00
|
|
|
bm = DM_to_bmesh(dm, calc_face_normals);
|
2011-06-01 19:30:19 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
if (emd->flags & MOD_EDGESPLIT_FROMANGLE) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
2011-11-28 03:41:14 +00:00
|
|
|
/* check for 1 edge having 2 face users */
|
|
|
|
BMLoop *l1, *l2;
|
2012-05-06 13:38:33 +00:00
|
|
|
if ((l1 = e->l) &&
|
|
|
|
(l2 = e->l->radial_next) != l1)
|
2011-11-28 03:41:14 +00:00
|
|
|
{
|
2012-07-17 17:55:23 +00:00
|
|
|
if (/* 3+ faces on this edge, always split */
|
2012-06-05 19:24:01 +00:00
|
|
|
UNLIKELY(l1 != l2->radial_next) ||
|
|
|
|
/* 2 face edge - check angle*/
|
|
|
|
(dot_v3v3(l1->f->no, l2->f->no) < threshold))
|
|
|
|
{
|
2012-12-12 12:57:27 +00:00
|
|
|
BM_elem_flag_enable(e, BM_ELEM_TAG);
|
2011-06-01 19:30:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-05 00:54:14 +00:00
|
|
|
if (emd->flags & MOD_EDGESPLIT_FROMFLAG) {
|
2012-04-19 13:47:58 +00:00
|
|
|
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
|
2012-03-05 21:17:24 +00:00
|
|
|
/* check for 2 or more edge users */
|
|
|
|
if ((e->l) &&
|
|
|
|
(e->l->next != e->l))
|
|
|
|
{
|
|
|
|
if (!BM_elem_flag_test(e, BM_ELEM_SMOOTH)) {
|
2012-12-12 12:57:27 +00:00
|
|
|
BM_elem_flag_enable(e, BM_ELEM_TAG);
|
2012-03-05 21:17:24 +00:00
|
|
|
}
|
2012-02-18 11:44:30 +00:00
|
|
|
}
|
2011-06-05 00:54:14 +00:00
|
|
|
}
|
2011-06-01 19:30:19 +00:00
|
|
|
}
|
2011-04-22 23:37:58 +00:00
|
|
|
|
2015-05-02 16:05:32 +10:00
|
|
|
BM_mesh_edgesplit(bm, false, true, false);
|
2012-01-22 21:12:18 +00:00
|
|
|
|
2012-03-22 05:13:43 +00:00
|
|
|
/* BM_mesh_validate(bm); */ /* for troubleshooting */
|
|
|
|
|
2014-01-23 14:50:50 +01:00
|
|
|
result = CDDM_from_bmesh(bm, true);
|
2012-10-24 07:24:11 +00:00
|
|
|
BM_mesh_free(bm);
|
2013-06-19 08:19:36 +00:00
|
|
|
|
|
|
|
result->dirty |= DM_DIRTY_NORMALS;
|
2012-02-12 15:02:33 +00:00
|
|
|
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
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-09 18:28:30 +00:00
|
|
|
/* default to 30-degree split angle, sharpness from both angle & flag */
|
Cleanup: Internal degrees removal.
This patch changes most of the reamining degrees usage in internal code into radians.
I let a few which I know off asside, for reasons explained below - and I'm not sure to have found out all of them.
WARNING: this introduces forward incompatibility, which means files saved from this version won't open 100% correctly
in previous versions (a few angle properties would use radians values as degrees...).
Details:
- Data:
-- Lamp.spotsize: Game engine exposed this setting in degrees, to not break the API here I kept it as such
(using getter/setter functions), still using radians internally.
-- Mesh.smoothresh: Didn't touch to this one, as we will hopefully replace it completely by loop normals currently in dev.
- Modifiers:
-- EdgeSplitModifierData.split_angle, BevelModifierData.bevel_angle: Done.
- Postprocessing:
-- WipeVars.angle (sequencer's effect), NodeBokehImage.angle, NodeBoxMask.rotation, NodeEllipseMask.rotation: Done.
- BGE:
-- bConstraintActuator: Orientation type done (the minloc[0] & maxloc[0] cases). Did not touch to 'limit location' type,
it can also limit rotation, but it exposes through RNA the same limit_min/limit_max, which hence
can be either distance or angle values, depending on the mode. Will leave this to BGE team.
-- bSoundActuator.cone_outer_angle_3d, bSoundActuator.cone_inner_angle_3d: Done (note I kept degrees in BGE itself,
as it seems this is the expected value here...).
-- bRadarSensor.angle: Done.
Reviewers: brecht, campbellbarton, sergey, gaiaclary, dfelinto, moguri, jbakker, lukastoenne, howardt
Reviewed By: brecht, campbellbarton, sergey, gaiaclary, moguri, jbakker, lukastoenne, howardt
Thanks to all!
Differential Revision: http://developer.blender.org/D59
2013-12-03 20:09:25 +01:00
|
|
|
emd->split_angle = DEG2RADF(30.0f);
|
2010-07-19 04:44:37 +00:00
|
|
|
emd->flags = MOD_EDGESPLIT_FROMANGLE | MOD_EDGESPLIT_FROMFLAG;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 04:44:37 +00:00
|
|
|
static void copyData(ModifierData *md, ModifierData *target)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2013-12-22 04:35:52 +11:00
|
|
|
#if 0
|
2012-05-06 13:38:33 +00:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData *) md;
|
|
|
|
EdgeSplitModifierData *temd = (EdgeSplitModifierData *) target;
|
2013-12-22 04:35:52 +11:00
|
|
|
#endif
|
|
|
|
modifier_copyData_generic(md, target);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 08:19:36 +00:00
|
|
|
static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), DerivedMesh *dm,
|
2012-05-09 15:00:26 +00:00
|
|
|
ModifierApplyFlag UNUSED(flag))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
DerivedMesh *result;
|
2012-05-06 13:38:33 +00:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-06-19 08:19:36 +00:00
|
|
|
if (!(emd->flags & (MOD_EDGESPLIT_FROMANGLE | MOD_EDGESPLIT_FROMFLAG)))
|
|
|
|
return dm;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-06-19 08:19:36 +00:00
|
|
|
result = doEdgeSplit(dm, emd);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_EdgeSplit = {
|
|
|
|
/* name */ "EdgeSplit",
|
|
|
|
/* structName */ "EdgeSplitModifierData",
|
|
|
|
/* structSize */ sizeof(EdgeSplitModifierData),
|
|
|
|
/* type */ eModifierTypeType_Constructive,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_AcceptsCVs |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_EnableInEditmode,
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* copyData */ copyData,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* applyModifier */ applyModifier,
|
2013-05-02 14:42:05 +00:00
|
|
|
/* applyModifierEM */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* requiredDataMask */ NULL,
|
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ NULL,
|
|
|
|
/* updateDepgraph */ NULL,
|
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ NULL,
|
|
|
|
/* foreachIDLink */ NULL,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachTexLink */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|