Skip to content
Snippets Groups Projects
Commit db2c65d9 authored by Bastien Montagne's avatar Bastien Montagne
Browse files

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

parent c4f78f14
Branches
Tags
No related merge requests found
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
bl_info = { bl_info = {
"name": "Wavefront OBJ format", "name": "Wavefront OBJ format",
"author": "Campbell Barton, Bastien Montagne", "author": "Campbell Barton, Bastien Montagne",
"version": (3, 6, 0), "version": (3, 7, 0),
"blender": (2, 81, 6), "blender": (2, 81, 6),
"location": "File > Import-Export", "location": "File > Import-Export",
"description": "Import-Export OBJ, Import OBJ mesh, UV's, materials and textures", "description": "Import-Export OBJ, Import OBJ mesh, UV's, materials and textures",
......
...@@ -91,8 +91,7 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict): ...@@ -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... # 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 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. # Emission, not in original MTL standard but seems pretty common, see T45766.
# XXX Not supported by current Principled-based shader. fw('Ke %.6f %.6f %.6f\n' % mat_wrap.emission_color[:3])
fw('Ke 0.0 0.0 0.0\n')
fw('Ni %.6f\n' % mat_wrap.ior) # Refraction index fw('Ni %.6f\n' % mat_wrap.ior) # Refraction index
fw('d %.6f\n' % mat_wrap.alpha) # Alpha (obj uses 'd' for dissolve) 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): ...@@ -121,7 +120,7 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
"map_Bump": "normalmap_texture", "map_Bump": "normalmap_texture",
"disp": None, # displacement... "disp": None, # displacement...
"refl": "metallic_texture", "refl": "metallic_texture",
"map_Ke": None # emission... "map_Ke": "emission_color_texture",
} }
for key, mat_wrap_key in sorted(image_map.items()): for key, mat_wrap_key in sorted(image_map.items()):
......
...@@ -187,8 +187,7 @@ def create_materials(filepath, relpath, ...@@ -187,8 +187,7 @@ def create_materials(filepath, relpath,
_generic_tex_set(mat_wrap.specular_texture, image, 'UV', map_offset, map_scale) _generic_tex_set(mat_wrap.specular_texture, image, 'UV', map_offset, map_scale)
elif type == 'Ke': elif type == 'Ke':
# XXX Not supported? _generic_tex_set(mat_wrap.emission_color_texture, image, 'UV', map_offset, map_scale)
print("WARNING, currently unsupported emit texture, skipped.")
elif type == 'Bump': elif type == 'Bump':
bump_mult = map_options.get(b'-bm') bump_mult = map_options.get(b'-bm')
...@@ -218,7 +217,7 @@ def create_materials(filepath, relpath, ...@@ -218,7 +217,7 @@ def create_materials(filepath, relpath,
else: else:
raise Exception("invalid type %r" % type) 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): do_highlight, do_reflection, do_transparency, do_glass):
# Finalize previous mat, if any. # Finalize previous mat, if any.
if context_material: if context_material:
...@@ -237,14 +236,6 @@ def create_materials(filepath, relpath, ...@@ -237,14 +236,6 @@ def create_materials(filepath, relpath,
if "roughness" not in context_material_vars: if "roughness" not in context_material_vars:
context_mat_wrap.roughness = 0.0 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? # FIXME, how else to use this?
if do_highlight: if do_highlight:
if "specular" not in context_material_vars: if "specular" not in context_material_vars:
...@@ -303,7 +294,6 @@ def create_materials(filepath, relpath, ...@@ -303,7 +294,6 @@ def create_materials(filepath, relpath,
do_transparency = False do_transparency = False
do_glass = False do_glass = False
spec_colors = [0.0, 0.0, 0.0] spec_colors = [0.0, 0.0, 0.0]
emit_colors = [0.0, 0.0, 0.0]
# print('\t\tloading mtl: %e' % mtlpath) # print('\t\tloading mtl: %e' % mtlpath)
context_material = None context_material = None
...@@ -319,7 +309,7 @@ def create_materials(filepath, relpath, ...@@ -319,7 +309,7 @@ def create_materials(filepath, relpath,
if line_id == b'newmtl': if line_id == b'newmtl':
# Finalize previous mat, if any. # 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) do_highlight, do_reflection, do_transparency, do_glass)
context_material_name = line_value(line_split) context_material_name = line_value(line_split)
...@@ -328,8 +318,7 @@ def create_materials(filepath, relpath, ...@@ -328,8 +318,7 @@ def create_materials(filepath, relpath,
context_mat_wrap = nodal_material_wrap_map[context_material] context_mat_wrap = nodal_material_wrap_map[context_material]
context_material_vars.clear() context_material_vars.clear()
spec_colors = [0.0, 0.0, 0.0] spec_colors[:] = [0.0, 0.0, 0.0]
emit_colors[:] = [0.0, 0.0, 0.0]
do_highlight = False do_highlight = False
do_reflection = False do_reflection = False
do_transparency = False do_transparency = False
...@@ -352,8 +341,8 @@ def create_materials(filepath, relpath, ...@@ -352,8 +341,8 @@ def create_materials(filepath, relpath,
elif line_id == b'ke': elif line_id == b'ke':
# We cannot set context_material.emit right now, we need final diffuse color as well for this. # We cannot set context_material.emit right now, we need final diffuse color as well for this.
# XXX Unsupported currently # XXX Unsupported currently
emit_colors[:] = [ col = (float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
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': elif line_id == b'ns':
# XXX Totally empirical conversion, trying to adapt it # 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)... # (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, ...@@ -469,7 +458,7 @@ def create_materials(filepath, relpath,
print("WARNING: %r:%r (ignored)" % (filepath, line)) print("WARNING: %r:%r (ignored)" % (filepath, line))
# Finalize last mat, if any. # 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) do_highlight, do_reflection, do_transparency, do_glass)
mtl.close() mtl.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment