Fix T70666: OBJ IO: Add support for new Emission option of Principled BSDF.

This commit is contained in:
Bastien Montagne 2019-10-10 17:20:16 +02:00
parent c4f78f1493
commit db2c65d9e7
Notes: blender-bot 2023-02-14 19:06:40 +01:00
Referenced by issue #94450, Problem with import obj file
Referenced by issue #70666, Exporting to FBX ignores the emission socket on the Principled BSDF
3 changed files with 10 additions and 22 deletions

View File

@ -21,7 +21,7 @@
bl_info = {
"name": "Wavefront OBJ format",
"author": "Campbell Barton, Bastien Montagne",
"version": (3, 6, 0),
"version": (3, 7, 0),
"blender": (2, 81, 6),
"location": "File > Import-Export",
"description": "Import-Export OBJ, Import OBJ mesh, UV's, materials and textures",

View File

@ -91,8 +91,7 @@ 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.
# XXX Not supported by current Principled-based shader.
fw('Ke 0.0 0.0 0.0\n')
fw('Ke %.6f %.6f %.6f\n' % mat_wrap.emission_color[:3])
fw('Ni %.6f\n' % mat_wrap.ior) # Refraction index
fw('d %.6f\n' % mat_wrap.alpha) # Alpha (obj uses 'd' for dissolve)
@ -121,7 +120,7 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
"map_Bump": "normalmap_texture",
"disp": None, # displacement...
"refl": "metallic_texture",
"map_Ke": None # emission...
"map_Ke": "emission_color_texture",
}
for key, mat_wrap_key in sorted(image_map.items()):

View File

@ -187,8 +187,7 @@ def create_materials(filepath, relpath,
_generic_tex_set(mat_wrap.specular_texture, image, 'UV', map_offset, map_scale)
elif type == 'Ke':
# XXX Not supported?
print("WARNING, currently unsupported emit texture, skipped.")
_generic_tex_set(mat_wrap.emission_color_texture, image, 'UV', map_offset, map_scale)
elif type == 'Bump':
bump_mult = map_options.get(b'-bm')
@ -218,7 +217,7 @@ def create_materials(filepath, relpath,
else:
raise Exception("invalid type %r" % type)
def finalize_material(context_material, context_material_vars, spec_colors, emit_colors,
def finalize_material(context_material, context_material_vars, spec_colors,
do_highlight, do_reflection, do_transparency, do_glass):
# Finalize previous mat, if any.
if context_material:
@ -237,14 +236,6 @@ def create_materials(filepath, relpath,
if "roughness" not in context_material_vars:
context_mat_wrap.roughness = 0.0
emit_value = sum(emit_colors) / 3.0
if emit_value > 1e-6:
print("WARNING, emit value unsupported by Principled BSDF shader, skipped.")
# We have to adapt it to diffuse color too...
emit_value /= sum(tuple(context_material.diffuse_color)[:3]) / 3.0
# ~ context_material.emit = emit_value
# FIXME, how else to use this?
if do_highlight:
if "specular" not in context_material_vars:
@ -303,7 +294,6 @@ def create_materials(filepath, relpath,
do_transparency = False
do_glass = False
spec_colors = [0.0, 0.0, 0.0]
emit_colors = [0.0, 0.0, 0.0]
# print('\t\tloading mtl: %e' % mtlpath)
context_material = None
@ -319,7 +309,7 @@ def create_materials(filepath, relpath,
if line_id == b'newmtl':
# Finalize previous mat, if any.
finalize_material(context_material, context_material_vars, spec_colors, emit_colors,
finalize_material(context_material, context_material_vars, spec_colors,
do_highlight, do_reflection, do_transparency, do_glass)
context_material_name = line_value(line_split)
@ -328,8 +318,7 @@ def create_materials(filepath, relpath,
context_mat_wrap = nodal_material_wrap_map[context_material]
context_material_vars.clear()
spec_colors = [0.0, 0.0, 0.0]
emit_colors[:] = [0.0, 0.0, 0.0]
spec_colors[:] = [0.0, 0.0, 0.0]
do_highlight = False
do_reflection = False
do_transparency = False
@ -352,8 +341,8 @@ def create_materials(filepath, relpath,
elif line_id == b'ke':
# We cannot set context_material.emit right now, we need final diffuse color as well for this.
# XXX Unsupported currently
emit_colors[:] = [
float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3])]
col = (float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
context_mat_wrap.emission_color = col
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)...
@ -469,7 +458,7 @@ def create_materials(filepath, relpath,
print("WARNING: %r:%r (ignored)" % (filepath, line))
# Finalize last mat, if any.
finalize_material(context_material, context_material_vars, spec_colors, emit_colors,
finalize_material(context_material, context_material_vars, spec_colors,
do_highlight, do_reflection, do_transparency, do_glass)
mtl.close()