USD Export: option to triangulate meshes
This allows for the source of truth data in the Blender scene to remain untouched while producing triangulated output suitable for game and VR pipelines, where only triangles are ingested. This addition aligns USD with some of the other exporters which offer a similar feature. Co-authored-by: Charles Wardlaw <cwardlaw@nvidia.com> Pull Request: https://projects.blender.org/blender/blender/pulls/121274
This commit is contained in:
committed by
Jesse Yurkovich
parent
896ef010f6
commit
b2d1979882
@@ -29,6 +29,7 @@
|
||||
|
||||
# include "RNA_access.hh"
|
||||
# include "RNA_define.hh"
|
||||
# include "RNA_enum_types.hh"
|
||||
|
||||
# include "UI_interface.hh"
|
||||
# include "UI_resources.hh"
|
||||
@@ -232,6 +233,10 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
|
||||
const bool export_custom_properties = RNA_boolean_get(op->ptr, "export_custom_properties");
|
||||
const bool author_blender_name = RNA_boolean_get(op->ptr, "author_blender_name");
|
||||
|
||||
const bool triangulate_meshes = RNA_boolean_get(op->ptr, "triangulate_meshes");
|
||||
const int quad_method = RNA_enum_get(op->ptr, "quad_method");
|
||||
const int ngon_method = RNA_enum_get(op->ptr, "ngon_method");
|
||||
|
||||
const bool convert_orientation = RNA_boolean_get(op->ptr, "convert_orientation");
|
||||
|
||||
const int global_forward = RNA_enum_get(op->ptr, "export_global_forward_selection");
|
||||
@@ -264,6 +269,9 @@ static int wm_usd_export_exec(bContext *C, wmOperator *op)
|
||||
relative_paths,
|
||||
export_custom_properties,
|
||||
author_blender_name,
|
||||
triangulate_meshes,
|
||||
quad_method,
|
||||
ngon_method,
|
||||
convert_orientation,
|
||||
eIOAxis(global_forward),
|
||||
eIOAxis(global_up),
|
||||
@@ -312,6 +320,14 @@ static void wm_usd_export_draw(bContext *C, wmOperator *op)
|
||||
uiItemR(row, ptr, "author_blender_name", UI_ITEM_NONE, nullptr, ICON_NONE);
|
||||
uiLayoutSetActive(row, RNA_boolean_get(op->ptr, "export_custom_properties"));
|
||||
|
||||
col = uiLayoutColumn(box, true);
|
||||
uiItemR(col, ptr, "triangulate_meshes", UI_ITEM_NONE, nullptr, ICON_NONE);
|
||||
|
||||
uiLayout *sub = uiLayoutColumn(col, false);
|
||||
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "triangulate_meshes"));
|
||||
uiItemR(sub, ptr, "quad_method", UI_ITEM_NONE, IFACE_("Method Quads"), ICON_NONE);
|
||||
uiItemR(sub, ptr, "ngon_method", UI_ITEM_NONE, IFACE_("Polygons"), ICON_NONE);
|
||||
|
||||
col = uiLayoutColumnWithHeading(box, true, IFACE_("Rigging"));
|
||||
uiItemR(col, ptr, "export_armatures", UI_ITEM_NONE, nullptr, ICON_NONE);
|
||||
row = uiLayoutRow(col, true);
|
||||
@@ -601,6 +617,26 @@ void WM_OT_usd_export(wmOperatorType *ot)
|
||||
RNA_def_boolean(ot->srna, "export_curves", true, "Curves", "Export all curves");
|
||||
|
||||
RNA_def_boolean(ot->srna, "export_volumes", true, "Volumes", "Export all volumes");
|
||||
|
||||
RNA_def_boolean(ot->srna,
|
||||
"triangulate_meshes",
|
||||
false,
|
||||
"Triangulate Meshes",
|
||||
"Triangulate meshes during export");
|
||||
|
||||
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_ngon_method_items,
|
||||
MOD_TRIANGULATE_NGON_BEAUTY,
|
||||
"N-gon Method",
|
||||
"Method for splitting the n-gons into triangles");
|
||||
}
|
||||
|
||||
/* ====== USD Import ====== */
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include "BKE_object.hh"
|
||||
#include "BKE_report.hh"
|
||||
|
||||
#include "bmesh.hh"
|
||||
#include "bmesh_tools.hh"
|
||||
|
||||
#include "DEG_depsgraph.hh"
|
||||
|
||||
#include "DNA_key_types.h"
|
||||
@@ -95,6 +98,29 @@ void USDGenericMeshWriter::do_write(HierarchyContext &context)
|
||||
return;
|
||||
}
|
||||
|
||||
if (usd_export_context_.export_params.triangulate_meshes) {
|
||||
const bool tag_only = false;
|
||||
const int quad_method = usd_export_context_.export_params.quad_method;
|
||||
const int ngon_method = usd_export_context_.export_params.ngon_method;
|
||||
|
||||
BMeshCreateParams bmesh_create_params{};
|
||||
BMeshFromMeshParams bmesh_from_mesh_params{};
|
||||
bmesh_from_mesh_params.calc_face_normal = true;
|
||||
bmesh_from_mesh_params.calc_vert_normal = true;
|
||||
BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, &bmesh_create_params, &bmesh_from_mesh_params);
|
||||
|
||||
BM_mesh_triangulate(bm, quad_method, ngon_method, 4, tag_only, nullptr, nullptr, nullptr);
|
||||
|
||||
Mesh *triangulated_mesh = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, mesh);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
if (needsfree) {
|
||||
free_export_mesh(mesh);
|
||||
}
|
||||
mesh = triangulated_mesh;
|
||||
needsfree = true;
|
||||
}
|
||||
|
||||
try {
|
||||
/* Fetch the subdiv modifier, if one exists and it is the last modifier. */
|
||||
const SubsurfModifierData *subsurfData = get_last_subdiv_modifier(
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "DEG_depsgraph.hh"
|
||||
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "RNA_types.hh"
|
||||
|
||||
struct bContext;
|
||||
@@ -105,6 +106,9 @@ struct USDExportParams {
|
||||
bool relative_paths = true;
|
||||
bool export_custom_properties = true;
|
||||
bool author_blender_name = true;
|
||||
bool triangulate_meshes = false;
|
||||
int quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE;
|
||||
int ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
|
||||
bool convert_orientation = false;
|
||||
enum eIOAxis forward_axis = eIOAxis::IO_AXIS_NEGATIVE_Z;
|
||||
enum eIOAxis up_axis = eIOAxis::IO_AXIS_Y;
|
||||
|
||||
Reference in New Issue
Block a user