From 3430fbc7013d037e153160d5de9bfbd887cecb4f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 5 Jul 2015 17:20:53 +0200 Subject: Fix T45316: Obj loading/saving brightness inconsistency. Fixes: * Wrong (off-by-one) import of specular hardness (aka specular exponent in OBJ). * Bad usage of world color when exporting ambient color (though it seems to make sense on first look, this is bad because impossible to 'undo' on import - merging data external to object itself). * Bad default values for diff/spec intensity in imported materials (OBJ does not have those, so we must assume they are 1.0). Thanks to Luke Brookes (propuke) for finding all those glitches! :) --- io_scene_obj/__init__.py | 2 +- io_scene_obj/export_obj.py | 5 +++-- io_scene_obj/import_obj.py | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'io_scene_obj') diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py index b356da75..e6452eb9 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": (2, 1, 3), + "version": (2, 1, 2), "blender": (2, 74, 0), "location": "File > Import-Export", "description": "Import-Export OBJ, Import OBJ mesh, UV's, " diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py index e7d646b0..00733dd1 100644 --- a/io_scene_obj/export_obj.py +++ b/io_scene_obj/export_obj.py @@ -79,14 +79,15 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict): if mat.specular_shader == 'WARDISO': tspec = (0.4 - mat.specular_slope) / 0.0004 else: - tspec = (mat.specular_hardness - 1) * 1.9607843137254901 + tspec = (mat.specular_hardness - 1) / 0.51 fw('Ns %.6f\n' % tspec) del tspec + # Ambient if use_mirror: fw('Ka %.6f %.6f %.6f\n' % (mat.raytrace_mirror.reflect_factor * mat.mirror_color)[:]) else: - fw('Ka %.6f %.6f %.6f\n' % (mat.ambient * world_amb)[:]) # Ambient, uses mirror color, + fw('Ka %.6f %.6f %.6f\n' % 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 if hasattr(mat, "raytrace_transparency") and hasattr(mat.raytrace_transparency, "ior"): diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py index 2ad8c0c2..b3f81541 100644 --- a/io_scene_obj/import_obj.py +++ b/io_scene_obj/import_obj.py @@ -205,11 +205,13 @@ def create_materials(filepath, relpath, elif line_id == b'kd': context_material.diffuse_color = ( float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3])) + context_material.diffuse_intensity = 1.0 elif line_id == b'ks': 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'ns': - context_material.specular_hardness = int((float_func(line_split[1]) * 0.51)) + context_material.specular_hardness = int((float_func(line_split[1]) * 0.51) + 1) elif line_id == b'ni': # Refraction index (between 1 and 3). context_material.raytrace_transparency.ior = max(1, min(float_func(line_split[1]), 3)) context_material_vars.add("ior") -- cgit v1.2.3