Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2019-10-10 18:20:16 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2019-10-10 18:20:16 +0300
commitdb2c65d9e7885809a9ac6ab09fa2585e6b35d353 (patch)
tree6c9844bb5ced862350dff6984ad20d4e411cd1f0
parentc4f78f14931be95e7f3bb31169579206369cc569 (diff)
Fix T70666: OBJ IO: Add support for new Emission option of Principled BSDF.
-rw-r--r--io_scene_obj/__init__.py2
-rw-r--r--io_scene_obj/export_obj.py5
-rw-r--r--io_scene_obj/import_obj.py25
3 files changed, 10 insertions, 22 deletions
diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py
index bddf758b..399a4d29 100644
--- a/io_scene_obj/__init__.py
+++ b/io_scene_obj/__init__.py
@@ -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",
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index bb331534..bb2b0e8d 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -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()):
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index f90528f9..4d640d44 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -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()