Fix T43487: Wavefront OBJ exporter should export more precise illum value in MTL file.
Was a TODO actually, now we try to match better illum values with current mesh material. Also, using mirror color as Ka instead of ambient one, when mirror is enabled in blen mat.
This commit is contained in:
parent
e9f9e43fca
commit
bd9fa80543
Notes:
blender-bot
2023-02-14 19:59:47 +01:00
Referenced by issue #43487, Wavefront OBJ exporter should export more precise illum value in MTL file
|
@ -21,7 +21,7 @@
|
|||
bl_info = {
|
||||
"name": "Wavefront OBJ format",
|
||||
"author": "Campbell Barton, Bastien Montagne",
|
||||
"version": (2, 1, 0),
|
||||
"version": (2, 1, 1),
|
||||
"blender": (2, 74, 0),
|
||||
"location": "File > Import-Export",
|
||||
"description": "Import-Export OBJ, Import OBJ mesh, UV's, "
|
||||
|
|
|
@ -73,6 +73,8 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
|
|||
fw('\nnewmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
|
||||
|
||||
if mat:
|
||||
use_mirror = mat.raytrace_mirror.use and mat.raytrace_mirror.reflect_factor != 0.0
|
||||
|
||||
# convert from blenders spec to 0 - 1000 range.
|
||||
if mat.specular_shader == 'WARDISO':
|
||||
tspec = (0.4 - mat.specular_slope) / 0.0004
|
||||
|
@ -81,7 +83,10 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
|
|||
fw('Ns %.6f\n' % tspec)
|
||||
del tspec
|
||||
|
||||
fw('Ka %.6f %.6f %.6f\n' % (mat.ambient * world_amb)[:]) # Ambient, uses mirror color,
|
||||
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('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"):
|
||||
|
@ -90,11 +95,24 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
|
|||
fw('Ni %.6f\n' % 1.0)
|
||||
fw('d %.6f\n' % mat.alpha) # Alpha (obj uses 'd' for dissolve)
|
||||
|
||||
# 0 to disable lighting, 1 for ambient & diffuse only (specular color set to black), 2 for full lighting.
|
||||
# See http://en.wikipedia.org/wiki/Wavefront_.obj_file for whole list of values...
|
||||
# Note that mapping is rather fuzzy sometimes, trying to do our best here.
|
||||
if mat.use_shadeless:
|
||||
fw('illum 0\n') # ignore lighting
|
||||
elif mat.specular_intensity == 0:
|
||||
fw('illum 1\n') # no specular.
|
||||
elif use_mirror:
|
||||
if mat.use_transparency and mat.transparency_method == 'RAYTRACE':
|
||||
if mat.raytrace_mirror.fresnel != 0.0:
|
||||
fw('illum 7\n') # Reflection, Transparency, Ray trace and Fresnel
|
||||
else:
|
||||
fw('illum 6\n') # Reflection, Transparency, Ray trace
|
||||
elif mat.raytrace_mirror.fresnel != 0.0:
|
||||
fw('illum 5\n') # Reflection, Ray trace and Fresnel
|
||||
else:
|
||||
fw('illum 3\n') # Reflection and Ray trace
|
||||
elif mat.use_transparency and mat.transparency_method == 'RAYTRACE':
|
||||
fw('illum 9\n') # 'Glass' transparency and no Ray trace reflection... fuzzy matching, but...
|
||||
else:
|
||||
fw('illum 2\n') # light normaly
|
||||
|
||||
|
|
Loading…
Reference in New Issue