From 5b3952d11ab2b9371bb447e577a468ea2bce0683 Mon Sep 17 00:00:00 2001 From: Yury <3dfigaro@noreply.localhost> Date: Fri, 14 Mar 2025 17:13:41 +0100 Subject: [PATCH] FBX Export: Add Smoothgroups option. Add 'Smoothing Groups' option for exporting polygon smoothing groups. Generates 'bitflags' smoothgroups values, ensuring no faces from different groups sharing a same boundary edge or vertex have the same bitflag value. NOTE: This type of smoothgroups will run out of group values (aka bitflags) with some specific topologies, e.g. a fan of over 31 flat faces sharing a same vertex (like the sides of a cone). In such cases, once all available values have been used, the remaining faces will get `0` (aka 'no group') value assigned. Original issue https://projects.blender.org/blender/blender-addons/issues/104434 Pull Request: https://projects.blender.org/blender/blender/pulls/135646 --- scripts/addons_core/io_scene_fbx/__init__.py | 5 +++-- scripts/addons_core/io_scene_fbx/export_fbx_bin.py | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/addons_core/io_scene_fbx/__init__.py b/scripts/addons_core/io_scene_fbx/__init__.py index ca6e334763e..0699a516d38 100644 --- a/scripts/addons_core/io_scene_fbx/__init__.py +++ b/scripts/addons_core/io_scene_fbx/__init__.py @@ -5,8 +5,8 @@ bl_info = { "name": "FBX format", "author": "Campbell Barton, Bastien Montagne, Jens Restemeier, @Mysteryem", - "version": (5, 12, 7), - "blender": (4, 2, 0), + "version": (5, 13, 0), + "blender": (4, 5, 0), "location": "File > Import-Export", "description": "FBX IO meshes, UVs, vertex colors, materials, textures, cameras, lamps and actions", "warning": "", @@ -391,6 +391,7 @@ class ExportFBX(bpy.types.Operator, ExportHelper): items=(('OFF', "Normals Only", "Export only normals instead of writing edge or face smoothing data"), ('FACE', "Face", "Write face smoothing"), ('EDGE', "Edge", "Write edge smoothing"), + ('SMOOTH_GROUP', "Smoothing Groups", "Write face smoothing groups"), ), description="Export smoothing information " "(prefer 'Normals Only' option if your target importer understand split normals)", diff --git a/scripts/addons_core/io_scene_fbx/export_fbx_bin.py b/scripts/addons_core/io_scene_fbx/export_fbx_bin.py index 397bc26771b..69e2b54f7fe 100644 --- a/scripts/addons_core/io_scene_fbx/export_fbx_bin.py +++ b/scripts/addons_core/io_scene_fbx/export_fbx_bin.py @@ -1032,7 +1032,7 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes): # And now, layers! # Smoothing. - if smooth_type in {'FACE', 'EDGE'}: + if smooth_type in {'FACE', 'EDGE', 'SMOOTH_GROUP'}: ps_fbx_dtype = np.int32 _map = b"" if smooth_type == 'FACE': @@ -1047,6 +1047,10 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes): # The mesh has no "sharp_face" attribute, so every face is smooth. t_ps = np.ones(len(me.polygons), dtype=ps_fbx_dtype) _map = b"ByPolygon" + elif smooth_type == 'SMOOTH_GROUP': + smoothing_groups = me.calc_smooth_groups(use_bitflags=True, use_boundary_vertices_for_bitflags=True)[0] + t_ps = np.asarray(smoothing_groups, dtype=ps_fbx_dtype) + _map = b"ByPolygon" else: # EDGE _map = b"ByEdge" if t_pvi_edge_indices.size: @@ -1503,7 +1507,7 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes): lay_tan = elem_empty(layer, b"LayerElement") elem_data_single_string(lay_tan, b"Type", b"LayerElementTangent") elem_data_single_int32(lay_tan, b"TypedIndex", 0) - if smooth_type in {'FACE', 'EDGE'}: + if smooth_type in {'FACE', 'EDGE', 'SMOOTH_GROUP'}: lay_smooth = elem_empty(layer, b"LayerElement") elem_data_single_string(lay_smooth, b"Type", b"LayerElementSmoothing") elem_data_single_int32(lay_smooth, b"TypedIndex", 0)