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

Fix T94516: OBJ/MTL Material Roughness imported and exported inaccurately.

The addon would assume an OBJ range of [0.0-900.0] for the Ns value,
when it actually is supposed to be [0.0-1000.0].

WARNING: This is introducing a slight incompatibility (value shifting of
the roughness parameter) with older OBJ files exported by Blender.
parent 29c03b65
No related branches found
No related tags found
No related merge requests found
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
bl_info = { bl_info = {
"name": "Wavefront OBJ format", "name": "Wavefront OBJ format",
"author": "Campbell Barton, Bastien Montagne", "author": "Campbell Barton, Bastien Montagne",
"version": (3, 8, 1), "version": (3, 9, 0),
"blender": (2, 81, 6), "blender": (3, 0, 0),
"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",
"warning": "", "warning": "",
......
...@@ -74,9 +74,10 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict): ...@@ -74,9 +74,10 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
use_transparency = mat_wrap.alpha != 1.0 use_transparency = mat_wrap.alpha != 1.0
# XXX Totally empirical conversion, trying to adapt it # XXX Totally empirical conversion, trying to adapt it
# (from 1.0 - 0.0 Principled BSDF range to 0.0 - 900.0 OBJ specular exponent range)... # (from 1.0 - 0.0 Principled BSDF range to 0.0 - 1000.0 OBJ specular exponent range):
spec = (1.0 - mat_wrap.roughness) * 30 # (1.0 - bsdf_roughness)^2 * 1000
spec *= spec spec = (1.0 - mat_wrap.roughness)
spec *= spec * 1000
fw('Ns %.6f\n' % spec) fw('Ns %.6f\n' % spec)
# Ambient # Ambient
......
...@@ -361,9 +361,9 @@ def create_materials(filepath, relpath, ...@@ -361,9 +361,9 @@ def create_materials(filepath, relpath,
context_mat_wrap.emission_strength = 1.0 context_mat_wrap.emission_strength = 1.0
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 - 1000.0 OBJ specular exponent range to 1.0 - 0.0 Principled BSDF range)...
val = max(0.0, min(900.0, float_func(line_split[1]))) val = max(0.0, min(1000.0, float_func(line_split[1])))
context_mat_wrap.roughness = 1.0 - (sqrt(val) / 30) context_mat_wrap.roughness = 1.0 - (sqrt(val / 1000))
context_material_vars.add("roughness") context_material_vars.add("roughness")
elif line_id == b'ni': # Refraction index (between 0.001 and 10). elif line_id == b'ni': # Refraction index (between 0.001 and 10).
context_mat_wrap.ior = float_func(line_split[1]) context_mat_wrap.ior = float_func(line_split[1])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment