Added option to choose triangulation method on fbx export #104694

Open
Andrej wants to merge 1 commits from Andrej730/blender-addons:fbx-triangulation-methods into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 33 additions and 3 deletions
Showing only changes of commit 36ef660763 - Show all commits

View File

@ -512,6 +512,25 @@ class ExportFBX(bpy.types.Operator, ExportHelper):
description="Convert all faces to triangles", description="Convert all faces to triangles",
default=False, 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( use_custom_props: BoolProperty(
name="Custom Properties", name="Custom Properties",
description="Export 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") #sub.prop(operator, "use_mesh_modifiers_render")
layout.prop(operator, "use_mesh_edges") layout.prop(operator, "use_mesh_edges")
layout.prop(operator, "use_triangles") 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 = layout.row()
#~ sub.enabled = operator.mesh_smooth_type in {'OFF'} #~ sub.enabled = operator.mesh_smooth_type in {'OFF'}
sub.prop(operator, "use_tspace") sub.prop(operator, "use_tspace")

View File

@ -2567,7 +2567,9 @@ def fbx_data_from_scene(scene, depsgraph, settings):
import bmesh import bmesh
bm = bmesh.new() bm = bmesh.new()
bm.from_mesh(tmp_me) 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.to_mesh(tmp_me)
bm.free() bm.free()
# Usually the materials of the evaluated object will be the same, but modifiers, such as Geometry Nodes, # 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_mesh_edges=True,
use_tspace=True, use_tspace=True,
use_triangles=False, use_triangles=False,
triangulation_quad_method='BEAUTY',
triangulation_ngon_method='BEAUTY',
embed_textures=False, embed_textures=False,
use_custom_props=False, use_custom_props=False,
bake_space_transform=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, 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, bake_space_transform, global_matrix_inv, global_matrix_inv_transposed,
context_objects, object_types, use_mesh_modifiers, use_mesh_modifiers_render, 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, armature_nodetype, use_armature_deform_only,
add_leaf_bones, bone_correction_matrix, bone_correction_matrix_inv, 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, bake_anim, bake_anim_use_all_bones, bake_anim_use_nla_strips, bake_anim_use_all_actions,

View File

@ -1543,7 +1543,8 @@ FBXExportSettings = namedtuple("FBXExportSettings", (
"report", "to_axes", "global_matrix", "global_scale", "apply_unit_scale", "unit_scale", "report", "to_axes", "global_matrix", "global_scale", "apply_unit_scale", "unit_scale",
"bake_space_transform", "global_matrix_inv", "global_matrix_inv_transposed", "bake_space_transform", "global_matrix_inv", "global_matrix_inv_transposed",
"context_objects", "object_types", "use_mesh_modifiers", "use_mesh_modifiers_render", "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", "armature_nodetype", "use_armature_deform_only", "add_leaf_bones",
"bone_correction_matrix", "bone_correction_matrix_inv", "bone_correction_matrix", "bone_correction_matrix_inv",
"bake_anim", "bake_anim_use_all_bones", "bake_anim_use_nla_strips", "bake_anim_use_all_actions", "bake_anim", "bake_anim_use_all_bones", "bake_anim_use_nla_strips", "bake_anim_use_all_actions",