diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-05-11 16:43:25 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-05-11 16:43:25 +0300 |
commit | 1b00d422461a917623b751b3eb82ad7b522fc273 (patch) | |
tree | b6178019e0886810d884da0cc4baf4f097a02be9 /io_scene_fbx | |
parent | 55d0ff708c617f190fd898c37f90b70a2fd6a293 (diff) |
Tentative fix for T59850: FBX: wrong alpha in some material imported by Unity.
Looks like FBX also likes to make a mess with materials' behaviors...
Many thanks to Thomas Chollet (@thomasch) for his help understanding how
Unity handles materials' alpha when importing from FBX.
Hopefully this won't break any other importer... ;)
Diffstat (limited to 'io_scene_fbx')
-rw-r--r-- | io_scene_fbx/__init__.py | 2 | ||||
-rw-r--r-- | io_scene_fbx/export_fbx_bin.py | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/io_scene_fbx/__init__.py b/io_scene_fbx/__init__.py index ac76f450..693cfe7d 100644 --- a/io_scene_fbx/__init__.py +++ b/io_scene_fbx/__init__.py @@ -21,7 +21,7 @@ bl_info = { "name": "FBX format", "author": "Campbell Barton, Bastien Montagne, Jens Restemeier", - "version": (4, 14, 6), + "version": (4, 14, 7), "blender": (2, 80, 0), "location": "File > Import-Export", "description": "FBX IO meshes, UV's, vertex colors, materials, textures, cameras, lamps and actions", diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index 055aa3e1..59fe3402 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -1257,7 +1257,18 @@ def fbx_data_material_elements(root, ma, scene_data): # Not in Principled BSDF, so assuming always 0 elem_props_template_set(tmpl, props, "p_color", b"AmbientColor", ambient_color) elem_props_template_set(tmpl, props, "p_number", b"AmbientFactor", 0.0) - elem_props_template_set(tmpl, props, "p_color", b"TransparentColor", ma_wrap.base_color) + # Sweetness... Looks like we are not the only ones to not know exactly how FBX is supposed to work (see T59850). + # According to one of its developers, Unity uses that formula to extract alpha value: + # + # alpha = 1 - TransparencyFactor + # if (alpha == 1 or alpha == 0): + # alpha = 1 - TransparentColor.r + # + # Until further info, let's assume this is correct way to do, hence the following code for TransparentColor. + if ma_wrap.transmission < 1.0e-5 or ma_wrap.transmission > (1.0 - 1.0e-5): + elem_props_template_set(tmpl, props, "p_color", b"TransparentColor", (ma_wrap.transmission,) * 3) + else: + elem_props_template_set(tmpl, props, "p_color", b"TransparentColor", ma_wrap.base_color) elem_props_template_set(tmpl, props, "p_number", b"TransparencyFactor", ma_wrap.transmission) elem_props_template_set(tmpl, props, "p_number", b"Opacity", 1.0 - ma_wrap.transmission) elem_props_template_set(tmpl, props, "p_vector_3d", b"NormalMap", (0.0, 0.0, 0.0)) |