Alembic: add option to triangulate meshes upon export.
authorKévin Dietrich <kevin.dietrich@mailoo.org>
Fri, 9 Sep 2016 03:30:43 +0000 (05:30 +0200)
committerKévin Dietrich <kevin.dietrich@mailoo.org>
Fri, 9 Sep 2016 03:30:43 +0000 (05:30 +0200)
source/blender/alembic/ABC_alembic.h
source/blender/alembic/CMakeLists.txt
source/blender/alembic/intern/abc_exporter.cc
source/blender/alembic/intern/abc_exporter.h
source/blender/alembic/intern/abc_mesh.cc
source/blender/alembic/intern/alembic_capi.cc
source/blender/editors/io/io_alembic.c
source/blender/makesrna/intern/rna_scene_api.c

index cf121f8488c6b7f0fcf59ff6cf5c98be011509a4..e62713f57f5faddcd31fe1d28334b18168fd846d 100644 (file)
@@ -64,8 +64,12 @@ struct AlembicExportParams {
        unsigned int face_sets : 1;
        unsigned int use_subdiv_schema : 1;
        unsigned int packuv : 1;
+       unsigned int triangulate : 1;
 
        unsigned int compression_type : 1;
+
+       int quad_method;
+       int ngon_method;
        float global_scale;
 };
 
index 6556354b016824be8d66bb413601c5056385c3e7..ad85f79ef2ec746659329d9da3f1263675bf3456 100644 (file)
@@ -28,6 +28,7 @@ set(INC
        ../blenkernel
        ../blenlib
        ../blenloader
+       ../bmesh
        ../editors/include
        ../makesdna
        ../makesrna
index bf1771278a88661dfafc8ac21f969634b36f8aaa..50949624db203e17c54a14d675a559ce886ece15 100644 (file)
@@ -88,6 +88,9 @@ ExportSettings::ExportSettings()
     , export_ogawa(true)
     , pack_uv(false)
     , do_convert_axis(false)
+    , triangulate(false)
+    , quad_method(0)
+    , ngon_method(0)
 {}
 
 static bool object_is_smoke_sim(Object *ob)
index 070eb9ea81a23de4f507497fa1ccd8f84ff332f5..b99eb09c788a648c33002b52d7638ead2985f16a 100644 (file)
@@ -65,6 +65,10 @@ struct ExportSettings {
        bool export_child_hairs;
        bool export_ogawa;
        bool pack_uv;
+       bool triangulate;
+
+       int quad_method;
+       int ngon_method;
 
        bool do_convert_axis;
        float convert_matrix[3][3];
index b80b7c0c4c89d5e7ae3d16292b512a778e3c4a3b..70af6af08274306738cb4f17167ed6e75cf6a326 100644 (file)
@@ -37,8 +37,8 @@ extern "C" {
 #include "BLI_math_geom.h"
 #include "BLI_string.h"
 
+#include "BKE_cdderivedmesh.h"
 #include "BKE_depsgraph.h"
-#include "BKE_DerivedMesh.h"
 #include "BKE_main.h"
 #include "BKE_material.h"
 #include "BKE_mesh.h"
@@ -49,6 +49,9 @@ extern "C" {
 #include "WM_types.h"
 
 #include "ED_mesh.h"
+
+#include "bmesh.h"
+#include "bmesh_tools.h"
 }
 
 using Alembic::Abc::FloatArraySample;
@@ -538,6 +541,23 @@ DerivedMesh *AbcMeshWriter::getFinalMesh()
                m_subsurf_mod->mode &= ~eModifierMode_DisableTemporary;
        }
 
+       if (m_settings.triangulate) {
+               const bool tag_only = false;
+               const int quad_method = m_settings.quad_method;
+               const int ngon_method = m_settings.ngon_method;
+
+               BMesh *bm = DM_to_bmesh(dm, true);
+
+               BM_mesh_triangulate(bm, quad_method, ngon_method, tag_only, NULL, NULL, NULL);
+
+               DerivedMesh *result = CDDM_from_bmesh(bm, false);
+               BM_mesh_free(bm);
+
+               freeMesh(dm);
+
+               dm = result;
+       }
+
        m_custom_data_config.pack_uvs = m_settings.pack_uv;
        m_custom_data_config.mpoly = dm->getPolyArray(dm);
        m_custom_data_config.mloop = dm->getLoopArray(dm);
index d332b4b98bc107d735ded76b88b876bd459e280a..04ea8e82f52b460a01eafc2a8f02537642e7ac80 100644 (file)
@@ -351,6 +351,9 @@ void ABC_export(
        job->settings.export_ogawa = (params->compression_type == ABC_ARCHIVE_OGAWA);
        job->settings.pack_uv = params->packuv;
        job->settings.global_scale = params->global_scale;
+       job->settings.triangulate = params->triangulate;
+       job->settings.quad_method = params->quad_method;
+       job->settings.ngon_method = params->ngon_method;
 
        if (job->settings.frame_start > job->settings.frame_end) {
                std::swap(job->settings.frame_start, job->settings.frame_end);
index cd75983e0a041caf99e55c0c8f9963dde45ce7ac..61ad8549c6c48c37c1eaf2fb9689cfa93cb070f2 100644 (file)
@@ -34,6 +34,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_mesh_types.h"
+#include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
@@ -121,6 +122,9 @@ static int wm_alembic_export_exec(bContext *C, wmOperator *op)
            .use_subdiv_schema = RNA_boolean_get(op->ptr, "subdiv_schema"),
            .compression_type = RNA_enum_get(op->ptr, "compression_type"),
            .packuv = RNA_boolean_get(op->ptr, "packuv"),
+               .triangulate = RNA_boolean_get(op->ptr, "triangulate"),
+               .quad_method = RNA_boolean_get(op->ptr, "quad_method"),
+               .ngon_method = RNA_boolean_get(op->ptr, "ngon_method"),
 
            .global_scale = RNA_float_get(op->ptr, "global_scale"),
        };
@@ -212,6 +216,19 @@ static void ui_alembic_export_settings(uiLayout *layout, PointerRNA *imfptr)
 
        row = uiLayoutRow(box, false);
        uiItemR(row, imfptr, "apply_subdiv", 0, NULL, ICON_NONE);
+
+       row = uiLayoutRow(box, false);
+       uiItemR(row, imfptr, "triangulate", 0, NULL, ICON_NONE);
+
+       const bool triangulate = RNA_boolean_get(imfptr, "triangulate");
+
+       row = uiLayoutRow(box, false);
+       uiLayoutSetEnabled(row, triangulate);
+       uiItemR(row, imfptr, "quad_method", 0, NULL, ICON_NONE);
+
+       row = uiLayoutRow(box, false);
+       uiLayoutSetEnabled(row, triangulate);
+       uiItemR(row, imfptr, "ngon_method", 0, NULL, ICON_NONE);
 }
 
 static void wm_alembic_export_draw(bContext *UNUSED(C), wmOperator *op)
@@ -308,6 +325,15 @@ void WM_OT_alembic_export(wmOperatorType *ot)
        RNA_def_float(ot->srna, "global_scale", 1.0f, 0.0001f, 1000.0f, "Scale",
                      "Value by which to enlarge or shrink the objects with respect to the world's origin",
                      0.0001f, 1000.0f);
+
+       RNA_def_boolean(ot->srna, "triangulate", false, "Triangulate",
+                       "Export Polygons (Quads & NGons) as Triangles");
+
+       RNA_def_enum(ot->srna, "quad_method", rna_enum_modifier_triangulate_quad_method_items,
+                    MOD_TRIANGULATE_QUAD_SHORTEDGE, "Quad Method", "Method for splitting the quads into triangles");
+
+       RNA_def_enum(ot->srna, "ngon_method", rna_enum_modifier_triangulate_quad_method_items,
+                    MOD_TRIANGULATE_NGON_BEAUTY, "Polygon Method", "Method for splitting the polygons into triangles");
 }
 
 /* ************************************************************************** */
index 519f28bea24da3664328f311465a5d7425bd62be..85c0b01334f6a94c5a9d28f898fd689630b407a6 100644 (file)
@@ -210,7 +210,10 @@ static void rna_Scene_alembic_export(
         int use_subdiv_schema,
         int compression_type,
         int packuv,
-        float scale)
+        float scale,
+        int triangulate,
+        int quad_method,
+        int ngon_method)
 {
 /* We have to enable allow_threads, because we may change scene frame number
  * during export. */
@@ -240,6 +243,9 @@ static void rna_Scene_alembic_export(
            .use_subdiv_schema = use_subdiv_schema,
            .compression_type = compression_type,
            .packuv = packuv,
+               .triangulate = triangulate,
+               .quad_method = quad_method,
+               .ngon_method = ngon_method,
 
            .global_scale = scale,
        };
@@ -404,6 +410,9 @@ void RNA_api_scene(StructRNA *srna)
        RNA_def_enum(func, "compression_type", rna_enum_abc_compression_items, 0, "Compression", "");
        RNA_def_boolean(func, "packuv"          , 0, "Export with packed UV islands", "Export with packed UV islands");
        RNA_def_float(func, "scale", 1.0f, 0.0001f, 1000.0f, "Scale", "Value by which to enlarge or shrink the objects with respect to the world's origin", 0.0001f, 1000.0f);
+       RNA_def_boolean(func, "triangulate", 0, "Triangulate", "Export Polygons (Quads & NGons) as Triangles");
+       RNA_def_enum(func, "quad_method", rna_enum_modifier_triangulate_quad_method_items, 0, "Quad Method", "Method for splitting the quads into triangles");
+       RNA_def_enum(func, "ngon_method", rna_enum_modifier_triangulate_quad_method_items, 0, "Polygon Method", "Method for splitting the polygons into triangles");
 
        RNA_def_function_flag(func, FUNC_USE_CONTEXT);
 #endif