Alembic: add option to triangulate meshes upon export.
This commit is contained in:
parent
78ea06fea4
commit
631af9f930
Notes:
blender-bot
2023-02-14 02:58:19 +01:00
Referenced by commit 04bfea0d67
, Fix T49369: Blender crashes/closes down application at alembic export of
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ set(INC
|
|||
../blenkernel
|
||||
../blenlib
|
||||
../blenloader
|
||||
../bmesh
|
||||
../editors/include
|
||||
../makesdna
|
||||
../makesrna
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue