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>2015-08-13 13:04:04 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-08-13 13:04:04 +0300
commit94c9c4ee3370d1feb42fc978a1f0d2db07cb9431 (patch)
treeb1743b240253ba2d2c4b75ab3b225b6e86568956 /io_scene_obj
parent4c142e59206b8c751c3b80e3632b6c82476a26b3 (diff)
Fix T45766: Exported OBJ/MTL files do not include emissive lighting parameters.
ke/map_ke are not official .mtl specs, but seem to be rather common extension. map_ke was added three years ago to exporter only, this commit finishes the work by adding ke/map_ke to importer, and ke to exporter. NOTES: * mtl ke is a color, while in Blender emit is only a factor, using diffuse color. this implies there is some loss of data during import here. * I do not have the slightest idea about the range for ke values, so for now assuming a direct matching of Blender's emit value.
Diffstat (limited to 'io_scene_obj')
-rw-r--r--io_scene_obj/export_obj.py3
-rw-r--r--io_scene_obj/import_obj.py26
2 files changed, 28 insertions, 1 deletions
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index 7399c2e1..e458f2d7 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -90,6 +90,9 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
fw('Ka %.6f %.6f %.6f\n' % (mat.ambient, mat.ambient, mat.ambient)) # Do not use world color!
fw('Kd %.6f %.6f %.6f\n' % (mat.diffuse_intensity * mat.diffuse_color)[:]) # Diffuse
fw('Ks %.6f %.6f %.6f\n' % (mat.specular_intensity * mat.specular_color)[:]) # Specular
+ # Emission, not in original MTL standard but seems pretty common, see T45766.
+ # XXX Blender has no color emission, it's using diffuse color instead...
+ fw('Ke %.6f %.6f %.6f\n' % (mat.emit * mat.diffuse_color)[:])
if hasattr(mat, "raytrace_transparency") and hasattr(mat.raytrace_transparency, "ior"):
fw('Ni %.6f\n' % mat.raytrace_transparency.ior) # Refraction index
else:
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index a9888602..a0db075f 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -120,6 +120,14 @@ def create_materials(filepath, relpath,
mtex.texture_coords = 'UV'
mtex.use_map_color_spec = True
+ elif type == 'Ke':
+ mtex = blender_material.texture_slots.add()
+ mtex.use_map_color_diffuse = False
+
+ mtex.texture = texture
+ mtex.texture_coords = 'UV'
+ mtex.use_map_emit = True
+
elif type == 'Bump':
mtex = blender_material.texture_slots.add()
mtex.use_map_color_diffuse = False
@@ -190,6 +198,7 @@ def create_materials(filepath, relpath,
do_glass = False
do_fresnel = False
do_raytrace = False
+ emit_colors = [0.0, 0.0, 0.0]
# print('\t\tloading mtl: %e' % mtlpath)
context_material = None
@@ -203,8 +212,14 @@ def create_materials(filepath, relpath,
line_id = line_split[0].lower()
if line_id == b'newmtl':
- # Finalize preview mat, if any.
+ # Finalize previous mat, if any.
if context_material:
+ emit_value = sum(emit_colors) / 3.0
+ if emit_value > 1e-6:
+ # We have to adapt it to diffuse color too...
+ emit_value /= sum(context_material.diffuse_color) / 3.0
+ context_material.emit = emit_value
+
if not do_ambient:
context_material.ambient = 0.0
@@ -243,6 +258,7 @@ def create_materials(filepath, relpath,
context_material = unique_materials.get(context_material_name)
context_material_vars.clear()
+ emit_colors[:] = [0.0, 0.0, 0.0]
do_ambient = True
do_highlight = False
do_reflection = False
@@ -267,6 +283,10 @@ def create_materials(filepath, relpath,
context_material.specular_color = (
float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
context_material.specular_intensity = 1.0
+ elif line_id == b'ke':
+ # We cannot set context_material.emit right now, we need final diffuse color as well for this.
+ emit_colors[:] = [
+ float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3])]
elif line_id == b'ns':
context_material.specular_hardness = int((float_func(line_split[1]) * 0.51) + 1)
elif line_id == b'ni': # Refraction index (between 1 and 3).
@@ -351,6 +371,10 @@ def create_materials(filepath, relpath,
img_filepath = line_value(line.split())
if img_filepath:
load_material_image(context_material, context_material_name, img_filepath, 'Kd')
+ elif line_id == b'map_ke':
+ img_filepath = line_value(line.split())
+ if img_filepath:
+ load_material_image(context_material, context_material_name, img_filepath, 'Ke')
elif line_id in {b'map_bump', b'bump'}: # 'bump' is incorrect but some files use it.
img_filepath = line_value(line.split())
if img_filepath: