From 36ef660763a2daa60ce22be936b47ab2c8c0362e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 15 Jun 2023 12:45:43 +0500 Subject: [PATCH] Added option to choose triangulation method on fbx export --- io_scene_fbx/__init__.py | 24 ++++++++++++++++++++++++ io_scene_fbx/export_fbx_bin.py | 9 +++++++-- io_scene_fbx/fbx_utils.py | 3 ++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 0c0c15eca..78f5f61e6 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -512,6 +512,25 @@ class ExportFBX(bpy.types.Operator, ExportHelper): description="Convert all faces to triangles", default=False, ) + triangulation_quad_method: EnumProperty( + name="Quad Method", + items=(('BEAUTY', "Beauty", "Split the quads in nice triangles, slower method"), + ('FIXED', "Fixed", "Split the quads on the first and third vertices"), + ('ALTERNATE', "Fixed Alternate", "Split the quads on the 2nd and 4th vertices"), + ('SHORT_EDGE', "Shortest Diagonal", "Split the quads along their shortest diagonal"), + ('LONG_EDGE', "Longest Diagonal", "Split the quads along their longest diagonal"), + ), + description="Method for splitting the quads into triangles", + default='BEAUTY', + ) + triangulation_ngon_method: EnumProperty( + name="N-gon Method", + items=(('BEAUTY', "Beauty", "Arrange the new triangles evenly (slow)"), + ('EAR_CLIP', "Clip", "Split the polygons with an ear clipping algorithm"), + ), + description="Method for splitting the n-gons into triangles", + default='BEAUTY', + ) use_custom_props: BoolProperty( name="Custom Properties", description="Export custom properties", @@ -791,6 +810,11 @@ class FBX_PT_export_geometry(bpy.types.Panel): #sub.prop(operator, "use_mesh_modifiers_render") layout.prop(operator, "use_mesh_edges") layout.prop(operator, "use_triangles") + if operator.use_triangles: + layout.label(text="Triangulation settings") + box = layout.box() + box.prop(operator, "triangulation_quad_method") + box.prop(operator, "triangulation_ngon_method") sub = layout.row() #~ sub.enabled = operator.mesh_smooth_type in {'OFF'} sub.prop(operator, "use_tspace") diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index 66cd9e691..4d671ea9e 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -2567,7 +2567,9 @@ def fbx_data_from_scene(scene, depsgraph, settings): import bmesh bm = bmesh.new() bm.from_mesh(tmp_me) - bmesh.ops.triangulate(bm, faces=bm.faces) + bmesh.ops.triangulate(bm, faces=bm.faces, + quad_method=settings.triangulation_quad_method, + ngon_method=settings.triangulation_ngon_method) bm.to_mesh(tmp_me) bm.free() # Usually the materials of the evaluated object will be the same, but modifiers, such as Geometry Nodes, @@ -3294,6 +3296,8 @@ def save_single(operator, scene, depsgraph, filepath="", use_mesh_edges=True, use_tspace=True, use_triangles=False, + triangulation_quad_method='BEAUTY', + triangulation_ngon_method='BEAUTY', embed_textures=False, use_custom_props=False, bake_space_transform=False, @@ -3362,7 +3366,8 @@ def save_single(operator, scene, depsgraph, filepath="", operator.report, (axis_up, axis_forward), global_matrix, global_scale, apply_unit_scale, unit_scale, bake_space_transform, global_matrix_inv, global_matrix_inv_transposed, context_objects, object_types, use_mesh_modifiers, use_mesh_modifiers_render, - mesh_smooth_type, use_subsurf, use_mesh_edges, use_tspace, use_triangles, + mesh_smooth_type, use_subsurf, use_mesh_edges, use_tspace, + use_triangles, triangulation_quad_method, triangulation_ngon_method, armature_nodetype, use_armature_deform_only, add_leaf_bones, bone_correction_matrix, bone_correction_matrix_inv, bake_anim, bake_anim_use_all_bones, bake_anim_use_nla_strips, bake_anim_use_all_actions, diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py index 3bbb342d3..1035cdc9a 100644 --- a/io_scene_fbx/fbx_utils.py +++ b/io_scene_fbx/fbx_utils.py @@ -1543,7 +1543,8 @@ FBXExportSettings = namedtuple("FBXExportSettings", ( "report", "to_axes", "global_matrix", "global_scale", "apply_unit_scale", "unit_scale", "bake_space_transform", "global_matrix_inv", "global_matrix_inv_transposed", "context_objects", "object_types", "use_mesh_modifiers", "use_mesh_modifiers_render", - "mesh_smooth_type", "use_subsurf", "use_mesh_edges", "use_tspace", "use_triangles", + "mesh_smooth_type", "use_subsurf", "use_mesh_edges", "use_tspace", + "use_triangles", "triangulation_quad_method", "triangulation_ngon_method", "armature_nodetype", "use_armature_deform_only", "add_leaf_bones", "bone_correction_matrix", "bone_correction_matrix_inv", "bake_anim", "bake_anim_use_all_bones", "bake_anim_use_nla_strips", "bake_anim_use_all_actions", -- 2.30.2