diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py index 1c43180dbe1faed6c7475316a57df59e40602db1..65a5b8f145698d6e1d0d83e920aceecba89a15f8 100644 --- a/io_scene_fbx/export_fbx_bin.py +++ b/io_scene_fbx/export_fbx_bin.py @@ -1309,7 +1309,7 @@ def fbx_data_material_elements(root, ma, scene_data): elem_props_template_set(tmpl, props, "p_number", b"DiffuseFactor", 1.0) # Principled BSDF only has an emissive color, so we assume factor to be always 1.0. elem_props_template_set(tmpl, props, "p_color", b"EmissiveColor", ma_wrap.emission_color) - elem_props_template_set(tmpl, props, "p_number", b"EmissiveFactor", 1.0) + elem_props_template_set(tmpl, props, "p_number", b"EmissiveFactor", ma_wrap.emission_strength) # 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) @@ -1808,7 +1808,7 @@ PRINCIPLED_TEXTURE_SOCKETS_TO_FBX = ( ("base_color_texture", b"DiffuseColor"), ("alpha_texture", b"TransparencyFactor"), # Will be inverted in fact, not much we can do really... # ("base_color_texture", b"TransparentColor"), # Uses diffuse color in Blender! - # ("emit", "emit", b"EmissiveFactor"), + ("emission_strength_texture", b"EmissiveFactor"), ("emission_color_texture", b"EmissiveColor"), # ("ambient", "ambient", b"AmbientFactor"), # ("", "", b"AmbientColor"), # World stuff in Blender, for now ignore... diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py index 3e0b2bfdc28ad017ffb84f781490c2302b7d1464..319c49728a91dd26488c6a3cbf3396c5f95d57f0 100644 --- a/io_scene_fbx/import_fbx.py +++ b/io_scene_fbx/import_fbx.py @@ -1457,10 +1457,9 @@ def blen_read_material(fbx_tmpl, fbx_obj, settings): # We have no metallic (a.k.a. reflection) color... # elem_props_get_color_rgb(fbx_props, b'ReflectionColor', const_color_white) ma_wrap.normalmap_strength = elem_props_get_number(fbx_props, b'BumpFactor', 1.0) - # For emission color we can take into account the factor, but only for default values, not in case of texture. - emission_factor = elem_props_get_number(fbx_props, b'EmissiveFactor', 1.0) - ma_wrap.emission_color = [c * emission_factor - for c in elem_props_get_color_rgb(fbx_props, b'EmissiveColor', const_color_black)] + # Emission strength and color + ma_wrap.emission_strength = elem_props_get_number(fbx_props, b'EmissiveFactor', 1.0) + ma_wrap.emission_color = elem_props_get_color_rgb(fbx_props, b'EmissiveColor', const_color_black) nodal_material_wrap_map[ma] = ma_wrap @@ -3151,6 +3150,9 @@ def load(operator, context, filepath="", elif lnk_type in {b'EmissiveColor'}: ma_wrap.emission_color_texture.image = image texture_mapping_set(fbx_lnk, ma_wrap.emission_color_texture) + elif lnk_type in {b'EmissiveFactor'}: + ma_wrap.emission_strength_texture.image = image + texture_mapping_set(fbx_lnk, ma_wrap.emission_strength_texture) else: print("WARNING: material link %r ignored" % lnk_type) diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py index dbd966a86bdefee46e2a5f3fd0ca83cccf5867c0..50cec8360d8ec9409b292efdf1155053448c66e7 100644 --- a/io_scene_obj/export_obj.py +++ b/io_scene_obj/export_obj.py @@ -88,7 +88,9 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict): # XXX TODO Find a way to handle tint and diffuse color, in a consistent way with import... fw('Ks %.6f %.6f %.6f\n' % (mat_wrap.specular, mat_wrap.specular, mat_wrap.specular)) # Specular # Emission, not in original MTL standard but seems pretty common, see T45766. - fw('Ke %.6f %.6f %.6f\n' % mat_wrap.emission_color[:3]) + emission_strength = mat_wrap.emission_strength + emission = [emission_strength * c for c in mat_wrap.emission_color[:3]] + fw('Ke %.6f %.6f %.6f\n' % tuple(emission)) fw('Ni %.6f\n' % mat_wrap.ior) # Refraction index fw('d %.6f\n' % mat_wrap.alpha) # Alpha (obj uses 'd' for dissolve) @@ -117,7 +119,7 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict): "map_Bump": "normalmap_texture", "disp": None, # displacement... "refl": "metallic_texture", - "map_Ke": "emission_color_texture", + "map_Ke": "emission_color_texture" if emission_strength != 0.0 else None, } for key, mat_wrap_key in sorted(image_map.items()): diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index db4efb9a0dfdb08a06ed1d26b07d08237e789758..85db6aec52cfccb132e7aa4c1d5bf7cba1596ef8 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -195,6 +195,7 @@ def create_materials(filepath, relpath, elif type == 'Ke': _generic_tex_set(mat_wrap.emission_color_texture, image, 'UV', map_offset, map_scale) + mat_wrap.emission_strength = 1.0 elif type == 'Bump': bump_mult = map_options.get(b'-bm') @@ -357,6 +358,7 @@ def create_materials(filepath, relpath, # We cannot set context_material.emit right now, we need final diffuse color as well for this. # XXX Unsupported currently context_mat_wrap.emission_color = _get_colors(line_split) + context_mat_wrap.emission_strength = 1.0 elif line_id == b'ns': # XXX Totally empirical conversion, trying to adapt it # (from 0.0 - 900.0 OBJ specular exponent range to 1.0 - 0.0 Principled BSDF range)...