diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-09-14 23:00:01 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-09-14 23:00:01 +0300 |
commit | 692f4691abc6a21f9d30f94a99882f2c46330903 (patch) | |
tree | e123e09c05a6938dfc44de0ade3aeb6616b1f46a /io_scene_fbx/import_fbx.py | |
parent | ad6d68161076025a51b145a3d6dbe03eefaf6cf9 (diff) |
FBX: support new color attributes, and sRGB/Linear/None colors option (T98721)
FBX exporter code was only supporting "Face Corner - Byte Color"
attribute type, using the deprecated Mesh.vertex_colors API. Update
the to use the new attributes API, and to handle all the attribute
combinations.
An option to pick between sRGB (default, matches current behavior),
Linear (requested in T82847) or None (don't export/import any color
attributes) has been added to the exporter and the importer.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D15942
Diffstat (limited to 'io_scene_fbx/import_fbx.py')
-rw-r--r-- | io_scene_fbx/import_fbx.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index 72d666c1..00376f38 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -1061,7 +1061,12 @@ def blen_read_geom_layer_uv(fbx_obj, mesh): ) -def blen_read_geom_layer_color(fbx_obj, mesh): +def blen_read_geom_layer_color(fbx_obj, mesh, colors_type): + if colors_type == 'NONE': + return + use_srgb = colors_type == 'SRGB' + layer_type = 'BYTE_COLOR' if use_srgb else 'FLOAT_COLOR' + color_prop_name = "color_srgb" if use_srgb else "color" # almost same as UV's for layer_id in (b'LayerElementColor',): for fbx_layer in elem_find_iter(fbx_obj, layer_id): @@ -1074,8 +1079,7 @@ def blen_read_geom_layer_color(fbx_obj, mesh): fbx_layer_data = elem_prop_first(elem_find_first(fbx_layer, b'Colors')) fbx_layer_index = elem_prop_first(elem_find_first(fbx_layer, b'ColorIndex')) - # Always init our new layers with full white opaque color. - color_lay = mesh.vertex_colors.new(name=fbx_layer_name, do_init=False) + color_lay = mesh.color_attributes.new(name=fbx_layer_name, type=layer_type, domain='CORNER') if color_lay is None: print("Failed to add {%r %r} vertex color layer to %r (probably too many of them?)" @@ -1090,7 +1094,7 @@ def blen_read_geom_layer_color(fbx_obj, mesh): continue blen_read_geom_array_mapped_polyloop( - mesh, blen_data, "color", + mesh, blen_data, color_prop_name, fbx_layer_data, fbx_layer_index, fbx_layer_mapping, fbx_layer_ref, 4, 4, layer_id, @@ -1289,7 +1293,7 @@ def blen_read_geom(fbx_tmpl, fbx_obj, settings): blen_read_geom_layer_material(fbx_obj, mesh) blen_read_geom_layer_uv(fbx_obj, mesh) - blen_read_geom_layer_color(fbx_obj, mesh) + blen_read_geom_layer_color(fbx_obj, mesh, settings.colors_type) if fbx_edges: # edges in fact index the polygons (NOT the vertices) @@ -2365,7 +2369,8 @@ def load(operator, context, filepath="", automatic_bone_orientation=False, primary_bone_axis='Y', secondary_bone_axis='X', - use_prepost_rot=True): + use_prepost_rot=True, + colors_type='SRGB'): global fbx_elem_nil fbx_elem_nil = FBXElem('', (), (), ()) @@ -2504,7 +2509,7 @@ def load(operator, context, filepath="", use_custom_props, use_custom_props_enum_as_string, nodal_material_wrap_map, image_cache, ignore_leaf_bones, force_connect_children, automatic_bone_orientation, bone_correction_matrix, - use_prepost_rot, + use_prepost_rot, colors_type, ) # #### And now, the "real" data. |