[Bf-extensions-cvs] [3430fbc] master: Fix T45316: Obj loading/saving brightness inconsistency.

Bastien Montagne noreply at git.blender.org
Sun Jul 5 17:24:58 CEST 2015


Commit: 3430fbc7013d037e153160d5de9bfbd887cecb4f
Author: Bastien Montagne
Date:   Sun Jul 5 17:20:53 2015 +0200
Branches: master
https://developer.blender.org/rBA3430fbc7013d037e153160d5de9bfbd887cecb4f

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! :)

===================================================================

M	io_scene_obj/__init__.py
M	io_scene_obj/export_obj.py
M	io_scene_obj/import_obj.py

===================================================================

diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py
index b356da7..e6452eb 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 e7d646b..00733dd 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 2ad8c0c..b3f8154 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")



More information about the Bf-extensions-cvs mailing list