diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2012-11-20 00:40:08 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2012-11-20 00:40:08 +0400 |
commit | e174c6a47f1c557919fdd53a2482d02273372229 (patch) | |
tree | d7ffb18deae6615fd6ba7d953d385e42ea8166d2 /source/blender/modifiers/intern/MOD_triangulate.c | |
parent | ade96d28403207f6deae1f257bc130fb76dfff13 (diff) |
Triangulate modifier
Useful for bump map baking where a consistent triangulation should be enforced when baking/exporting/importing, to avoid artifacts caused by a different triangulation of the mesh by that which was used for baking by internal/external tools.
documentation is here http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.65/More_Features
Will probably add some pictures too to demonstrate the issue that is solved more clearly.
Currently using the skin modifier icon, will soon change that.
Review by Brecht, thanks!
Diffstat (limited to 'source/blender/modifiers/intern/MOD_triangulate.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_triangulate.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/source/blender/modifiers/intern/MOD_triangulate.c b/source/blender/modifiers/intern/MOD_triangulate.c new file mode 100644 index 00000000000..a9ec30067bf --- /dev/null +++ b/source/blender/modifiers/intern/MOD_triangulate.c @@ -0,0 +1,147 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Antony Riakiotakis + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +/** \file blender/modifiers/intern/MOD_triangulate.c + * \ingroup modifiers + */ +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_object_types.h" +#include "DNA_modifier_types.h" + +#include "BLI_utildefines.h" +#include "BLI_string.h" +#include "BLI_array.h" + +#include "BKE_cdderivedmesh.h" +#include "BKE_deform.h" +#include "BKE_DerivedMesh.h" +#include "BKE_mesh.h" +#include "BKE_modifier.h" +#include "BKE_tessmesh.h" + +#include "MOD_util.h" + +/* triangulation modifier, directly calls the bmesh operator */ + +static DerivedMesh *triangulate(DerivedMesh *dm, char use_beauty) +{ + DerivedMesh *result; + BMesh *bm; + + bm = DM_to_bmesh(dm); + + BMO_push(bm, NULL); + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, + "triangulate faces=%af use_beauty=%b", use_beauty); + + BMO_pop(bm); + + result = CDDM_from_bmesh(bm, FALSE); + BM_mesh_free(bm); + + CDDM_calc_edges(result); + CDDM_calc_normals(result); + + return result; +} + + +static void initData(ModifierData *md) +{ + TriangulateModifierData *tmd = (TriangulateModifierData *)md; + + /* Enable in editmode by default */ + md->mode |= eModifierMode_Editmode; + tmd->beauty = TRUE; +} + + +static void copyData(ModifierData *md, ModifierData *target) +{ + TriangulateModifierData *smd = (TriangulateModifierData *) md; + TriangulateModifierData *tsmd = (TriangulateModifierData *) target; + + *tsmd = *smd; +} + +static DerivedMesh *applyModifierEM(ModifierData *md, + Object *UNUSED(ob), + struct BMEditMesh *UNUSED(em), + DerivedMesh *dm) +{ + TriangulateModifierData *tmd = (TriangulateModifierData *)md; + DerivedMesh *result; + if (!(result = triangulate(dm, tmd->beauty))) { + return dm; + } + + return result; +} + +static DerivedMesh *applyModifier(ModifierData *md, + Object *UNUSED(ob), + DerivedMesh *dm, + ModifierApplyFlag UNUSED(flag)) +{ + TriangulateModifierData *tmd = (TriangulateModifierData *)md; + DerivedMesh *result; + if(!(result = triangulate(dm, tmd->beauty))) { + return dm; + } + + return result; +} + +ModifierTypeInfo modifierType_Triangulate = { + /* name */ "Triangulate", + /* structName */ "TriangulateModifierData", + /* structSize */ sizeof(TriangulateModifierData), + /* type */ eModifierTypeType_Constructive, + /* flags */ eModifierTypeFlag_AcceptsMesh | + eModifierTypeFlag_SupportsEditmode | + eModifierTypeFlag_SupportsMapping | + eModifierTypeFlag_EnableInEditmode | + eModifierTypeFlag_AcceptsCVs, + + /* copyData */ copyData, + /* deformVerts */ NULL, + /* deformMatrices */ NULL, + /* deformVertsEM */ NULL, + /* deformMatricesEM */ NULL, + /* applyModifier */ applyModifier, + /* applyModifierEM */ applyModifierEM, + /* initData */ initData, + /* requiredDataMask */ NULL, //requiredDataMask, + /* freeData */ NULL, + /* isDisabled */ NULL, + /* updateDepgraph */ NULL, + /* dependsOnTime */ NULL, + /* dependsOnNormals */ NULL, + /* foreachObjectLink */ NULL, + /* foreachIDLink */ NULL, +}; |