From a9c30a5811f0c7856a61110a88cc46c902eae413 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Sat, 25 Feb 2023 17:00:49 +0500 Subject: [PATCH 1/2] Option to prioritize active color at export Basically some software (like 3ds Max or Substance Painter) discard other color attributes besides the first one - so the option to prioritize active_color to be exportred first will be helpful in these cases. It is especially important since currently there is no option to move color attributes around in Blender. Explained it in details here - https://projects.blender.org/blender/blender/issues/104827 To solve that I've added that option in FBX exporter. --- io_scene_fbx/__init__.py | 8 ++++++++ io_scene_fbx/export_fbx_bin.py | 10 ++++++++-- io_scene_fbx/fbx_utils.py | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index 5a3a1390c..c9c38bab5 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -482,6 +482,13 @@ class ExportFBX(bpy.types.Operator, ExportHelper): description="Export vertex color attributes", default='SRGB', ) + prioritize_active_color: BoolProperty( + name="Prioritize Active Color", + description="Make sure active color will be exported first. Could be important " + "since some other software can discard other color attributes besides the first one " + "(e.g. 3ds Max, Substance Painter)", + default=False, + ) use_subsurf: BoolProperty( name="Export Subdivision Surface", description="Export the last Catmull-Rom subdivision modifier as FBX subdivision " @@ -787,6 +794,7 @@ class FBX_PT_export_geometry(bpy.types.Panel): #~ sub.enabled = operator.mesh_smooth_type in {'OFF'} sub.prop(operator, "use_tspace") layout.prop(operator, "colors_type") + layout.prop(operator, "prioritize_active_color") class FBX_PT_export_armature(bpy.types.Panel): diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index bd53b79d7..4d0a36d19 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -1257,7 +1257,12 @@ def fbx_data_mesh_elements(root, me_obj, scene_data, done_meshes): fbx_lcidx_dtype = np.int32 t_lvi = None - for colindex, collayer in enumerate(me.color_attributes): + color_attributes = me.color_attributes + if scene_data.settings.prioritize_active_color: + active_color = me.color_attributes.active_color + color_attributes = sorted(color_attributes, key=lambda x: x == active_color, reverse=True) + + for colindex, collayer in enumerate(color_attributes): is_point = collayer.domain == "POINT" vcollen = len(me.vertices if is_point else me.loops) # Each rgba component is flattened in the array @@ -3290,6 +3295,7 @@ def save_single(operator, scene, depsgraph, filepath="", bake_space_transform=False, armature_nodetype='NULL', colors_type='SRGB', + prioritize_active_color=False, **kwargs ): @@ -3357,7 +3363,7 @@ def save_single(operator, scene, depsgraph, filepath="", 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_step, bake_anim_simplify_factor, bake_anim_force_startend_keying, - False, media_settings, use_custom_props, colors_type, + False, media_settings, use_custom_props, colors_type, prioritize_active_color ) import bpy_extras.io_utils diff --git a/io_scene_fbx/fbx_utils.py b/io_scene_fbx/fbx_utils.py index 327601534..fc5dac272 100644 --- a/io_scene_fbx/fbx_utils.py +++ b/io_scene_fbx/fbx_utils.py @@ -1489,7 +1489,7 @@ FBXExportSettings = namedtuple("FBXExportSettings", ( "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_step", "bake_anim_simplify_factor", "bake_anim_force_startend_keying", - "use_metadata", "media_settings", "use_custom_props", "colors_type", + "use_metadata", "media_settings", "use_custom_props", "colors_type", "prioritize_active_color" )) # Helper container gathering some data we need multiple times: -- 2.30.2 From de0dc940aa8ba2a09875604e2f9ad278e62ac4de Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 6 Mar 2023 20:43:53 +0500 Subject: [PATCH 2/2] Removed other software names --- io_scene_fbx/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index c9c38bab5..adada3537 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -485,8 +485,7 @@ class ExportFBX(bpy.types.Operator, ExportHelper): prioritize_active_color: BoolProperty( name="Prioritize Active Color", description="Make sure active color will be exported first. Could be important " - "since some other software can discard other color attributes besides the first one " - "(e.g. 3ds Max, Substance Painter)", + "since some other software can discard other color attributes besides the first one.", default=False, ) use_subsurf: BoolProperty( -- 2.30.2