Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2012-11-20 00:40:08 +0400
committerAntony Riakiotakis <kalast@gmail.com>2012-11-20 00:40:08 +0400
commite174c6a47f1c557919fdd53a2482d02273372229 (patch)
treed7ffb18deae6615fd6ba7d953d385e42ea8166d2 /source/blender/modifiers
parentade96d28403207f6deae1f257bc130fb76dfff13 (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')
-rw-r--r--source/blender/modifiers/CMakeLists.txt1
-rw-r--r--source/blender/modifiers/MOD_modifiertypes.h1
-rw-r--r--source/blender/modifiers/intern/MOD_triangulate.c147
-rw-r--r--source/blender/modifiers/intern/MOD_util.c1
4 files changed, 150 insertions, 0 deletions
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 3a7066ff41a..cf3bb05849a 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -94,6 +94,7 @@ set(SRC
intern/MOD_weightvgedit.c
intern/MOD_weightvgmix.c
intern/MOD_weightvgproximity.c
+ intern/MOD_triangulate.c
MOD_modifiertypes.h
intern/MOD_boolean_util.h
diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h
index a4817ff775d..290ba193567 100644
--- a/source/blender/modifiers/MOD_modifiertypes.h
+++ b/source/blender/modifiers/MOD_modifiertypes.h
@@ -76,6 +76,7 @@ extern ModifierTypeInfo modifierType_DynamicPaint;
extern ModifierTypeInfo modifierType_Remesh;
extern ModifierTypeInfo modifierType_Skin;
extern ModifierTypeInfo modifierType_LaplacianSmooth;
+extern ModifierTypeInfo modifierType_Triangulate;
/* MOD_util.c */
void modifier_type_init(ModifierTypeInfo *types[]);
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,
+};
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index 3b769a30994..a27d5e5e03b 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -278,5 +278,6 @@ void modifier_type_init(ModifierTypeInfo *types[])
INIT_TYPE(Remesh);
INIT_TYPE(Skin);
INIT_TYPE(LaplacianSmooth);
+ INIT_TYPE(Triangulate);
#undef INIT_TYPE
}