[Bf-extensions-cvs] [1b00d422] master: Tentative fix for T59850: FBX: wrong alpha in some material imported by Unity.

Bastien Montagne noreply at git.blender.org
Sat May 11 15:46:02 CEST 2019


Commit: 1b00d422461a917623b751b3eb82ad7b522fc273
Author: Bastien Montagne
Date:   Sat May 11 15:43:25 2019 +0200
Branches: master
https://developer.blender.org/rBA1b00d422461a917623b751b3eb82ad7b522fc273

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... ;)

===================================================================

M	io_scene_fbx/__init__.py
M	io_scene_fbx/export_fbx_bin.py

===================================================================

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))



More information about the Bf-extensions-cvs mailing list