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
|
|
|
|
*/
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
/* EdgeSplit modifier: Splits edges in the mesh according to sharpness flag
|
|
|
|
* or edge angle (can be used to achieve autosmoothing) */
|
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-05-09 04:06:48 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
#include "BLI_memarena.h"
|
|
|
|
#include "BLI_edgehash.h"
|
|
|
|
#include "BLI_math.h"
|
2010-07-19 04:44:37 +00:00
|
|
|
#include "BLI_array.h"
|
2011-06-01 19:30:19 +00:00
|
|
|
#include "BLI_smallhash.h"
|
2011-10-22 01:53:35 +00:00
|
|
|
#include "BLI_linklist.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_particle.h"
|
2010-07-19 04:44:37 +00:00
|
|
|
#include "BKE_tessmesh.h"
|
2011-02-27 06:19:40 +00:00
|
|
|
#include "BKE_mesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-07-19 04:44:37 +00:00
|
|
|
/* EdgeSplit */
|
|
|
|
/* EdgeSplit modifier: Splits edges in the mesh according to sharpness flag
|
|
|
|
* or edge angle (can be used to achieve autosmoothing)
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
#define EDGE_MARK 1
|
2010-07-19 04:44:37 +00:00
|
|
|
|
2011-10-10 14:56:09 +00:00
|
|
|
static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Object *ob)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2011-06-01 19:47:21 +00:00
|
|
|
BMesh *bm;
|
|
|
|
BMEditMesh *em;
|
2011-06-09 15:20:29 +00:00
|
|
|
DerivedMesh *cddm;
|
2011-11-28 03:41:14 +00:00
|
|
|
BMIter iter;
|
2011-06-01 19:47:21 +00:00
|
|
|
BMEdge *e;
|
2011-06-09 15:20:29 +00:00
|
|
|
/* int allocsize[] = {512, 512, 2048, 512}; */ /* UNUSED */
|
2010-07-19 04:44:37 +00:00
|
|
|
float threshold = cos((emd->split_angle + 0.00001) * M_PI / 180.0);
|
2011-06-01 19:30:19 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
if (!CDDM_Check(dm)) {
|
|
|
|
cddm = CDDM_copy(dm, 0);
|
|
|
|
} else cddm = dm;
|
2011-06-01 19:30:19 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
em = CDDM_To_BMesh(ob, dm, NULL);
|
|
|
|
bm = em->bm;
|
2011-06-05 00:54:14 +00:00
|
|
|
|
|
|
|
BM_Compute_Normals(bm);
|
2011-06-01 19:47:21 +00:00
|
|
|
BMO_push(bm, NULL);
|
2011-06-01 19:30:19 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
if (emd->flags & MOD_EDGESPLIT_FROMANGLE) {
|
2011-11-28 03:41:14 +00:00
|
|
|
BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {
|
|
|
|
/* check for 1 edge having 2 face users */
|
|
|
|
BMLoop *l1, *l2;
|
|
|
|
if ( (l1= e->l) &&
|
|
|
|
(l2= e->l->radial_next) != l1)
|
|
|
|
{
|
|
|
|
if (dot_v3v3(l1->f->no, l2->f->no) < threshold) {
|
|
|
|
BMO_SetFlag(bm, e, EDGE_MARK);
|
2011-06-01 19:30:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-05 00:54:14 +00:00
|
|
|
if (emd->flags & MOD_EDGESPLIT_FROMFLAG) {
|
|
|
|
BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {
|
|
|
|
if (BM_TestHFlag(e, BM_SHARP))
|
|
|
|
BMO_SetFlag(bm, e, EDGE_MARK);
|
|
|
|
}
|
2011-06-01 19:30:19 +00:00
|
|
|
}
|
2011-04-22 23:37:58 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
BMO_CallOpf(bm, "edgesplit edges=%fe", EDGE_MARK);
|
2011-06-01 19:30:19 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
BMO_pop(bm);
|
|
|
|
BMEdit_RecalcTesselation(em);
|
2011-06-01 19:30:19 +00:00
|
|
|
|
|
|
|
if (cddm != dm) {
|
|
|
|
cddm->needsFree = 1;
|
|
|
|
cddm->release(cddm);
|
|
|
|
}
|
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
cddm = CDDM_from_BMEditMesh(em, NULL, 1);
|
|
|
|
BMEdit_Free(em);
|
|
|
|
MEM_freeN(em);
|
2011-06-01 19:30:19 +00:00
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
return cddm;
|
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
|
|
|
{
|
2010-07-19 04:44:37 +00:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData*) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-07-19 04:44:37 +00:00
|
|
|
/* default to 30-degree split angle, sharpness from both angle & flag
|
2010-04-11 22:12:30 +00:00
|
|
|
*/
|
2010-07-19 04:44:37 +00:00
|
|
|
emd->split_angle = 30;
|
|
|
|
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
|
|
|
{
|
2010-07-19 04:44:37 +00:00
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData*) md;
|
|
|
|
EdgeSplitModifierData *temd = (EdgeSplitModifierData*) target;
|
|
|
|
|
|
|
|
temd->split_angle = emd->split_angle;
|
|
|
|
temd->flags = emd->flags;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DerivedMesh *edgesplitModifier_do(EdgeSplitModifierData *emd,
|
2011-06-01 19:47:21 +00:00
|
|
|
Object *ob, DerivedMesh *dm)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
if(!(emd->flags & (MOD_EDGESPLIT_FROMANGLE | MOD_EDGESPLIT_FROMFLAG)))
|
|
|
|
return dm;
|
|
|
|
|
2011-06-01 19:47:21 +00:00
|
|
|
return doEdgeSplit(dm, emd, ob);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static DerivedMesh *applyModifier(
|
|
|
|
ModifierData *md, Object *ob, DerivedMesh *derivedData,
|
2011-05-09 14:32:55 +00:00
|
|
|
int UNUSED(useRenderParams), int UNUSED(isFinalCalc))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
DerivedMesh *result;
|
|
|
|
EdgeSplitModifierData *emd = (EdgeSplitModifierData*) md;
|
|
|
|
|
|
|
|
result = edgesplitModifier_do(emd, ob, derivedData);
|
|
|
|
|
|
|
|
if(result != derivedData)
|
|
|
|
CDDM_calc_normals(result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-07-19 04:44:37 +00:00
|
|
|
static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob,
|
2011-05-09 14:32:55 +00:00
|
|
|
BMEditMesh *UNUSED(editData), DerivedMesh *derivedData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
return applyModifier(md, ob, derivedData, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_EdgeSplit = {
|
|
|
|
/* name */ "EdgeSplit",
|
|
|
|
/* structName */ "EdgeSplitModifierData",
|
|
|
|
/* structSize */ sizeof(EdgeSplitModifierData),
|
|
|
|
/* type */ eModifierTypeType_Constructive,
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh
|
|
|
|
| eModifierTypeFlag_AcceptsCVs
|
|
|
|
| eModifierTypeFlag_SupportsMapping
|
|
|
|
| eModifierTypeFlag_SupportsEditmode
|
|
|
|
| eModifierTypeFlag_EnableInEditmode,
|
|
|
|
|
|
|
|
/* 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,
|
|
|
|
/* applyModifierEM */ applyModifierEM,
|
|
|
|
/* 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
|
|
|
};
|