From 631af9f930d2fd2c76751204ff22239aa95f761d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Fri, 9 Sep 2016 05:30:43 +0200 Subject: Alembic: add option to triangulate meshes upon export. --- source/blender/alembic/ABC_alembic.h | 4 ++++ source/blender/alembic/CMakeLists.txt | 1 + source/blender/alembic/intern/abc_exporter.cc | 3 +++ source/blender/alembic/intern/abc_exporter.h | 4 ++++ source/blender/alembic/intern/abc_mesh.cc | 22 +++++++++++++++++++++- source/blender/alembic/intern/alembic_capi.cc | 3 +++ 6 files changed, 36 insertions(+), 1 deletion(-) (limited to 'source/blender/alembic') diff --git a/source/blender/alembic/ABC_alembic.h b/source/blender/alembic/ABC_alembic.h index cf121f8488c..e62713f57f5 100644 --- a/source/blender/alembic/ABC_alembic.h +++ b/source/blender/alembic/ABC_alembic.h @@ -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; }; diff --git a/source/blender/alembic/CMakeLists.txt b/source/blender/alembic/CMakeLists.txt index 6556354b016..ad85f79ef2e 100644 --- a/source/blender/alembic/CMakeLists.txt +++ b/source/blender/alembic/CMakeLists.txt @@ -28,6 +28,7 @@ set(INC ../blenkernel ../blenlib ../blenloader + ../bmesh ../editors/include ../makesdna ../makesrna diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc index bf1771278a8..50949624db2 100644 --- a/source/blender/alembic/intern/abc_exporter.cc +++ b/source/blender/alembic/intern/abc_exporter.cc @@ -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) diff --git a/source/blender/alembic/intern/abc_exporter.h b/source/blender/alembic/intern/abc_exporter.h index 070eb9ea81a..b99eb09c788 100644 --- a/source/blender/alembic/intern/abc_exporter.h +++ b/source/blender/alembic/intern/abc_exporter.h @@ -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]; diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc index b80b7c0c4c8..70af6af0827 100644 --- a/source/blender/alembic/intern/abc_mesh.cc +++ b/source/blender/alembic/intern/abc_mesh.cc @@ -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); diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc index d332b4b98bc..04ea8e82f52 100644 --- a/source/blender/alembic/intern/alembic_capi.cc +++ b/source/blender/alembic/intern/alembic_capi.cc @@ -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); -- cgit v1.2.3