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>2018-09-28 00:29:06 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2018-09-28 00:33:01 +0300
commitf9c31589f6bd0493f8f017fa4b37d192ad776936 (patch)
tree873431fbad3222a55ac0db64b285f8ec5596f5b0 /io_scene_obj
parent7197a830b1c55d7685c5bc08d770ef6f818f2f42 (diff)
OBJ IO: Initial support for modern shaders.
Based on new bpy_extras' node_shader_utils module. Note that this is still quiet rough on the edges, not all features previously supported (in 2.7x) are back yet (at least missing displacement, which should not be too hard to add, and real alpha handling, which is probably a bit more hairy). Also, some things like specular or mirror colors, ambient lighting, etc. do not exists in Principled BSDF shader, tried to work around it but there likely some room for improvements here too.
Diffstat (limited to 'io_scene_obj')
-rw-r--r--io_scene_obj/__init__.py2
-rw-r--r--io_scene_obj/export_obj.py174
-rw-r--r--io_scene_obj/import_obj.py166
3 files changed, 153 insertions, 189 deletions
diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py
index 54b55a50..4fc670a9 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": (3, 3, 7),
+ "version": (3, 4, 0),
"blender": (2, 80, 0),
"location": "File > Import-Export",
"description": "Import-Export OBJ, Import OBJ mesh, UV's, materials and textures",
diff --git a/io_scene_obj/export_obj.py b/io_scene_obj/export_obj.py
index 8184067d..417a54c3 100644
--- a/io_scene_obj/export_obj.py
+++ b/io_scene_obj/export_obj.py
@@ -21,8 +21,8 @@
import os
import bpy
-import mathutils
-import bpy_extras.io_utils
+from mathutils import Matrix, Vector, Color
+from bpy_extras import io_utils, node_shader_utils
from progress_report import ProgressReport, ProgressReportSubstep
@@ -44,10 +44,8 @@ def mesh_triangulate(me):
def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
- from mathutils import Color, Vector
-
world = scene.world
- world_amb = Color((0.0, 0.0, 0.0))
+ world_amb = Color((0.8, 0.8, 0.8))
source_dir = os.path.dirname(bpy.data.filepath)
dest_dir = os.path.dirname(filepath)
@@ -63,133 +61,99 @@ def write_mtl(scene, filepath, path_mode, copy_set, mtl_dict):
# Write material/image combinations we have used.
# Using mtl_dict.values() directly gives un-predictable order.
- for mtl_mat_name, mat, face_img in mtl_dict_values:
+ for mtl_mat_name, mat in mtl_dict_values:
# Get the Blender data for the material and the image.
# Having an image named None will make a bug, dont do it :)
fw('\nnewmtl %s\n' % mtl_mat_name) # Define a new material: matname_imgname
- if False and mat: # XXX TODO Support nodal materials.
- use_mirror = mat.raytrace_mirror.use and mat.raytrace_mirror.reflect_factor != 0.0
+ mat_wrap = node_shader_utils.PrincipledBSDFWrapper(mat) if mat else None
- # convert from blenders spec to 0 - 1000 range.
- if mat.specular_shader == 'WARDISO':
- tspec = (0.4 - mat.specular_slope) / 0.0004
- else:
- tspec = (mat.specular_hardness - 1) / 0.51
- fw('Ns %.6f\n' % tspec)
- del tspec
+ if mat_wrap:
+ use_mirror = mat_wrap.metallic != 0.0
+ use_transparency = mat_wrap.transmission != 0.0
+
+ # Convert from principled roughness to 0 - 1000 specular range.
+ # XXX Basic linear conversion, what would be best-matching formula here?
+ fw('Ns %.6f\n' % ((1.0 - mat_wrap.roughness) * 1000))
# Ambient
if use_mirror:
- fw('Ka %.6f %.6f %.6f\n' % (mat.raytrace_mirror.reflect_factor * mat.mirror_color)[:])
+ fw('Ka %.6f %.6f %.6f\n' % (mat_wrap.metallic, mat_wrap.metallic, mat_wrap.metallic))
else:
- 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
+ fw('Ka %.6f %.6f %.6f\n' % (1.0, 1.0, 1.0))
+ fw('Kd %.6f %.6f %.6f\n' % mat_wrap.diffuse_color[:3]) # Diffuse
+ # XXX TODO Find a way to handle tint and diffuse color, in a consistent way with import...
+ fw('Ks %.6f %.6f %.6f\n' % (mat_wrap.specular, mat_wrap.specular, mat_wrap.specular)) # 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:
- fw('Ni %.6f\n' % 1.0)
- fw('d %.6f\n' % mat.alpha) # Alpha (obj uses 'd' for dissolve)
+ # XXX Not supported by current Principled-based shader.
+ fw('Ke 0.0 0.0 0.0\n')
+ fw('Ni %.6f\n' % mat_wrap.ior) # Refraction index
+ fw('d %.6f\n' % (1.0 - mat_wrap.transmission)) # Alpha (obj uses 'd' for dissolve)
# 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:
+ if mat_wrap.specular == 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
+ if use_transparency:
+ fw('illum 6\n') # Reflection, Transparency, Ray trace
else:
fw('illum 3\n') # Reflection and Ray trace
- elif mat.use_transparency and mat.transparency_method == 'RAYTRACE':
+ elif use_transparency:
fw('illum 9\n') # 'Glass' transparency and no Ray trace reflection... fuzzy matching, but...
else:
fw('illum 2\n') # light normaly
- else:
- # Write a dummy material here?
- fw('Ns 0\n')
- fw('Ka %.6f %.6f %.6f\n' % world_amb[:]) # Ambient, uses mirror color,
- fw('Kd 0.8 0.8 0.8\n')
- fw('Ks 0.8 0.8 0.8\n')
- fw('d 1\n') # No alpha
- fw('illum 2\n') # light normaly
- # Write images!
- if face_img: # We have an image on the face!
- filepath = face_img.filepath
- if filepath: # may be '' for generated images
- # write relative image path
- filepath = bpy_extras.io_utils.path_reference(filepath, source_dir, dest_dir,
- path_mode, "", copy_set, face_img.library)
- fw('map_Kd %s\n' % filepath) # Diffuse mapping image
- del filepath
- else:
- # so we write the materials image.
- face_img = None
-
- if False and mat: # XXX TODO support nodal materials. If we have a material search for MTex image.
- image_map = {}
- # backwards so topmost are highest priority
- for mtex in reversed(mat.texture_slots):
- if mtex and mtex.texture and mtex.texture.type == 'IMAGE':
- image = mtex.texture.image
- if image:
- # texface overrides others
- if (mtex.use_map_color_diffuse and (face_img is None) and
- (mtex.use_map_warp is False) and (mtex.texture_coords != 'REFLECTION')):
- image_map["map_Kd"] = (mtex, image)
- if mtex.use_map_ambient:
- image_map["map_Ka"] = (mtex, image)
- # this is the Spec intensity channel but Ks stands for specular Color
- '''
- if mtex.use_map_specular:
- image_map["map_Ks"] = (mtex, image)
- '''
- if mtex.use_map_color_spec: # specular color
- image_map["map_Ks"] = (mtex, image)
- if mtex.use_map_hardness: # specular hardness/glossiness
- image_map["map_Ns"] = (mtex, image)
- if mtex.use_map_alpha:
- image_map["map_d"] = (mtex, image)
- if mtex.use_map_translucency:
- image_map["map_Tr"] = (mtex, image)
- if mtex.use_map_normal:
- image_map["map_Bump"] = (mtex, image)
- if mtex.use_map_displacement:
- image_map["disp"] = (mtex, image)
- if mtex.use_map_color_diffuse and (mtex.texture_coords == 'REFLECTION'):
- image_map["refl"] = (mtex, image)
- if mtex.use_map_emit:
- image_map["map_Ke"] = (mtex, image)
-
- for key, (mtex, image) in sorted(image_map.items()):
- filepath = bpy_extras.io_utils.path_reference(image.filepath, source_dir, dest_dir,
- path_mode, "", copy_set, image.library)
+ #### And now, the image textures...
+ image_map = {
+ "map_Kd": "diffuse_texture",
+ "map_Ka": None, # ambient...
+ "map_Ks": "specular_texture",
+ "map_Ns": "roughness_texture",
+ "map_d": "transmission_texture",
+ "map_Tr": None, # transmission roughness?
+ "map_Bump": "normalmap_texture",
+ "disp": None, # displacement...
+ "refl": "metallic_texture",
+ "map_Ke": None # emission...
+ }
+
+ for key, mat_wrap_key in sorted(image_map.items()):
+ if mat_wrap_key is None:
+ continue
+ tex_wrap = getattr(mat_wrap, mat_wrap_key, None)
+ if tex_wrap is None:
+ continue
+ image = tex_wrap.image
+ if image is None:
+ continue
+
+ filepath = io_utils.path_reference(image.filepath, source_dir, dest_dir,
+ path_mode, "", copy_set, image.library)
options = []
if key == "map_Bump":
- if mtex.normal_factor != 1.0:
- options.append('-bm %.6f' % mtex.normal_factor)
- if mtex.offset != Vector((0.0, 0.0, 0.0)):
- options.append('-o %.6f %.6f %.6f' % mtex.offset[:])
- if mtex.scale != Vector((1.0, 1.0, 1.0)):
- options.append('-s %.6f %.6f %.6f' % mtex.scale[:])
+ if mat_wrap.normalmap_strengh != 1.0:
+ options.append('-bm %.6f' % mat_wrap.normalmap_strengh)
+ if tex_wrap.translation != Vector((0.0, 0.0, 0.0)):
+ options.append('-o %.6f %.6f %.6f' % tex_wrap.translation[:])
+ if tex_wrap.scale != Vector((1.0, 1.0, 1.0)):
+ options.append('-s %.6f %.6f %.6f' % tex_wrap.scale[:])
if options:
fw('%s %s %s\n' % (key, " ".join(options), repr(filepath)[1:-1]))
else:
fw('%s %s\n' % (key, repr(filepath)[1:-1]))
+ else:
+ # Write a dummy material here?
+ fw('Ns 500\n')
+ fw('Ka 0.8 0.8 0.8\n')
+ fw('Kd 0.8 0.8 0.8\n')
+ fw('Ks 0.8 0.8 0.8\n')
+ fw('d 1\n') # No alpha
+ fw('illum 2\n') # light normaly
+
def test_nurbs_compat(ob):
if ob.type != 'CURVE':
@@ -295,7 +259,7 @@ def write_file(filepath, objects, depsgraph, scene,
write( 'c:\\test\\foobar.obj', Blender.Object.GetSelected() ) # Using default options.
"""
if EXPORT_GLOBAL_MATRIX is None:
- EXPORT_GLOBAL_MATRIX = mathutils.Matrix()
+ EXPORT_GLOBAL_MATRIX = Matrix()
def veckey3d(v):
return round(v.x, 4), round(v.y, 4), round(v.z, 4)
@@ -611,7 +575,7 @@ def write_file(filepath, objects, depsgraph, scene,
i += 1
tmp_ext = "_%3d" % i
mtl_name += tmp_ext
- mat_data = mtl_dict[key] = mtl_name, materials[f_mat], False
+ mat_data = mtl_dict[key] = mtl_name, materials[f_mat]
mtl_rev_dict[mtl_name] = key
if EXPORT_GROUP_BY_MAT:
@@ -690,7 +654,7 @@ def write_file(filepath, objects, depsgraph, scene,
write_mtl(scene, mtlfilepath, EXPORT_PATH_MODE, copy_set, mtl_dict)
# copy all collected files.
- bpy_extras.io_utils.path_reference_copy(copy_set)
+ io_utils.path_reference_copy(copy_set)
def _write(context, filepath,
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 2925ec82..8f914d6e 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -120,25 +120,27 @@ def create_materials(filepath, relpath,
# Absolute path - c:\.. etc would work here
image = obj_image_load(context_imagepath_map, line, DIR, use_image_search, relpath)
- texture = bpy.data.textures.new(name=type, type='IMAGE')
- if image is not None:
- texture.image = image
-
map_offset = map_options.get(b'-o')
map_scale = map_options.get(b'-s')
+ def _generic_tex_set(nodetex, image, texcoords, translation, scale):
+ nodetex.image = image
+ nodetex.texcoords = texcoords
+ if translation is not None:
+ nodetex.translation = translation
+ if scale is not None:
+ nodetex.scale = scale
+
# Adds textures for materials (rendering)
if type == 'Kd':
- mat_wrap.diffuse_image_set(image)
- mat_wrap.diffuse_mapping_set(coords='UV', translation=map_offset, scale=map_scale)
+ _generic_tex_set(mat_wrap.diffuse_texture, image, 'UV', map_offset, map_scale)
elif type == 'Ka':
# XXX Not supported?
print("WARNING, currently unsupported ambient texture, skipped.")
elif type == 'Ks':
- mat_wrap.specular_image_set(image)
- mat_wrap.specular_mapping_set(coords='UV', translation=map_offset, scale=map_scale)
+ _generic_tex_set(mat_wrap.specular_texture, image, 'UV', map_offset, map_scale)
elif type == 'Ke':
# XXX Not supported?
@@ -147,19 +149,18 @@ def create_materials(filepath, relpath,
elif type == 'Bump':
bump_mult = map_options.get(b'-bm')
bump_mult = float(bump_mult[0]) if (bump_mult is not None and len(bump_mult) > 1) else 1.0
+ mat_wrap.normalmap_strength_set(bump_mult)
- mat_wrap.normal_image_set(image)
- mat_wrap.normal_mapping_set(coords='UV', translation=map_offset, scale=map_scale)
- if bump_mult:
- mat_wrap.normal_factor_set(bump_mult)
+ _generic_tex_set(mat_wrap.normalmap_texture, image, 'UV', map_offset, map_scale)
elif type == 'D':
- mat_wrap.alpha_image_set(image)
- mat_wrap.alpha_mapping_set(coords='UV', translation=map_offset, scale=map_scale)
+ _generic_tex_set(mat_wrap.transmission_texture, image, 'UV', map_offset, map_scale)
elif type == 'disp':
- mat_wrap.bump_image_set(image)
- mat_wrap.bump_mapping_set(coords='UV', translation=map_offset, scale=map_scale)
+ # XXX Not supported?
+ print("WARNING, currently unsupported displacement texture, skipped.")
+ # ~ mat_wrap.bump_image_set(image)
+ # ~ mat_wrap.bump_mapping_set(coords='UV', translation=map_offset, scale=map_scale)
elif type == 'refl':
map_type = map_options.get(b'-type')
@@ -167,25 +168,12 @@ def create_materials(filepath, relpath,
print("WARNING, unsupported reflection type '%s', defaulting to 'sphere'"
"" % ' '.join(i.decode() for i in map_type))
- mat_wrap.diffuse_image_set(image, projection='SPHERE')
- mat_wrap.diffuse_mapping_set(coords='Reflection', translation=map_offset, scale=map_scale)
+ _generic_tex_set(mat_wrap.diffuse_texture, image, 'Reflection', map_offset, map_scale)
+ mat_wrap.diffuse_texture.projection = 'SPHERE'
else:
raise Exception("invalid type %r" % type)
- if map_offset:
- mtex.offset.x = float(map_offset[0])
- if len(map_offset) >= 2:
- mtex.offset.y = float(map_offset[1])
- if len(map_offset) >= 3:
- mtex.offset.z = float(map_offset[2])
- if map_scale:
- mtex.scale.x = float(map_scale[0])
- if len(map_scale) >= 2:
- mtex.scale.y = float(map_scale[1])
- if len(map_scale) >= 3:
- mtex.scale.z = float(map_scale[2])
-
# Add an MTL with the same name as the obj if no MTLs are spesified.
temp_mtl = os.path.splitext((os.path.basename(filepath)))[0] + ".mtl"
@@ -197,9 +185,10 @@ def create_materials(filepath, relpath,
for name in unique_materials: # .keys()
if name is not None:
ma = unique_materials[name] = bpy.data.materials.new(name.decode('utf-8', "replace"))
- from modules import cycles_shader_compat
- ma_wrap = cycles_shader_compat.CyclesShaderWrapper(ma)
+ from bpy_extras import node_shader_utils
+ ma_wrap = node_shader_utils.PrincipledBSDFWrapper(ma, is_readonly=False)
nodal_material_wrap_map[ma] = ma_wrap
+ ma_wrap.use_nodes = True
for libname in sorted(material_libs):
# print(libname)
@@ -207,13 +196,13 @@ def create_materials(filepath, relpath,
if not os.path.exists(mtlpath):
print("\tMaterial not found MTL: %r" % mtlpath)
else:
- do_ambient = True
+ # Note: with modern Principled BSDF shader, things like ambient, raytrace or fresnel are always 'ON'
+ # (i.e. automatically controlled by other parameters).
do_highlight = False
do_reflection = False
do_transparency = False
do_glass = False
- do_fresnel = False
- do_raytrace = False
+ spec_colors = [0.0, 0.0, 0.0]
emit_colors = [0.0, 0.0, 0.0]
# print('\t\tloading mtl: %e' % mtlpath)
@@ -231,41 +220,56 @@ def create_materials(filepath, relpath,
if line_id == b'newmtl':
# Finalize previous mat, if any.
if context_material:
+ if "specular" in context_material_vars:
+ # XXX This is highly approximated, not sure whether we can do better...
+ # TODO: Find a way to guesstimate best value from diffuse color...
+ # IDEA: Use standard deviation of both spec and diff colors (i.e. how far away they are
+ # from some grey), and apply the the proportion between those two as tint factor?
+ # ~ spec = sum(spec_color) / 3.0
+ # ~ spec_var = math.sqrt(sum((c - spec) ** 2 for c in spec_color) / 3.0)
+ # ~ diff = sum(context_mat_wrap.diffuse_color[:3]) / 3.0
+ # ~ diff_var = math.sqrt(sum((c - diff) ** 2 for c in context_mat_wrap.diffuse_color[:3]) / 3.0)
+ # ~ tint = min(1.0, spec_var / diff_var)
+ context_mat_wrap.specular = spec
+ context_mat_wrap.specular_tint = 0.0
+ if "roughness" not in context_material_vars:
+ context_mat_wrap.roughness = 0.0
+
+
emit_value = sum(emit_colors) / 3.0
if emit_value > 1e-6:
- print("WARNING, currently unsupported emit value, skipped.")
+ print("WARNING, emit value unsupported by Principled BSDF shader, skipped.")
# 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
-
+ # FIXME, how else to use this?
if do_highlight:
- context_mat_wrap.hardness_value_set(1.0)
- # FIXME, how else to use this?
- context_material.specular_intensity = 1.0
+ if "specular" not in context_material_vars:
+ context_mat_wrap.specular = 1.0
+ if "roughness" not in context_material_vars:
+ context_mat_wrap.roughness = 0.0
else:
- context_mat_wrap.hardness_value_set(0.0)
+ if "specular" not in context_material_vars:
+ context_mat_wrap.specular = 0.0
+ if "roughness" not in context_material_vars:
+ context_mat_wrap.roughness = 1.0
if do_reflection:
- context_mat_wrap.reflect_factor_set(1.0)
- context_material.metallic = 1.0
+ if "metallic" not in context_material_vars:
+ context_mat_wrap.metallic = 1.0
if do_transparency:
- if "alpha" not in context_material_vars:
- context_mat_wrap.alpha_value_set(0.0)
+ if "ior" not in context_material_vars:
+ context_mat_wrap.ior = 1.0
+ if "transmission" not in context_material_vars:
+ context_mat_wrap.transmission = 1.0
# EEVEE only
context_material.blend_method = 'BLEND'
if do_glass:
- print("WARNING, currently unsupported glass material, skipped.")
- # ~ if "ior" not in context_material_vars:
- # ~ context_material.raytrace_transparency.ior = 1.5
-
- if do_fresnel:
- print("WARNING, currently unsupported fresnel option, skipped.")
- # ~ context_material.raytrace_mirror.fresnel = 1.0 # could be any value for 'ON'
+ if "ior" not in context_material_vars:
+ context_mat_wrap.ior = 1.5
context_material_name = line_value(line_split)
context_material = unique_materials.get(context_material_name)
@@ -273,50 +277,54 @@ def create_materials(filepath, relpath,
context_mat_wrap = nodal_material_wrap_map[context_material]
context_material_vars.clear()
+ spec_colors = [0.0, 0.0, 0.0]
emit_colors[:] = [0.0, 0.0, 0.0]
- do_ambient = True
do_highlight = False
do_reflection = False
do_transparency = False
do_glass = False
- do_fresnel = False
- do_raytrace = False
elif context_material:
# we need to make a material to assign properties to it.
if line_id == b'ka':
- col = (float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
- context_mat_wrap.reflect_color_set(col)
+ refl = (float_func(line_split[1]) + float_func(line_split[2]) + float_func(line_split[3])) / 3.0
+ context_mat_wrap.metallic = refl
+ context_material_vars.add("metallic")
elif line_id == b'kd':
col = (float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
- context_mat_wrap.diffuse_color_set(col)
+ context_mat_wrap.diffuse_color[:3] = col
elif line_id == b'ks':
- col = (float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
- context_mat_wrap.specular_color_set(col)
- context_mat_wrap.hardness_value_set(1.0)
+ spec_color = (float_func(line_split[1]) + float_func(line_split[2]) + float_func(line_split[3]))
+ context_material_vars.add("specular")
elif line_id == b'ke':
# We cannot set context_material.emit right now, we need final diffuse color as well for this.
+ # XXX Unsuported currently
emit_colors[:] = [
float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3])]
elif line_id == b'ns':
- context_mat_wrap.hardness_value_set(((float_func(line_split[1]) + 3.0) / 50.0) - 0.65)
- elif line_id == b'ni': # Refraction index (between 1 and 3).
- print("WARNING, currently unsupported glass material, skipped.")
+ # XXX Basic linear conversion, what would be best-matching formula here?
+ context_mat_wrap.roughness = 1.0 - (float_func(line_split[1]) / 1000)
+ context_material_vars.add("roughness")
+ elif line_id == b'ni': # Refraction index (between 0.001 and 10).
+ context_mat_wrap.ior = float_func(line_split[1])
+ context_material_vars.add("ior")
elif line_id == b'd': # dissolve (transparency)
- context_mat_wrap.alpha_value_set(float_func(line_split[1]))
+ context_mat_wrap.transmission = 1.0 - float_func(line_split[1])
+ context_material_vars.add("transmission")
elif line_id == b'tr': # translucency
- print("WARNING, currently unsupported translucency option, skipped.")
+ print("WARNING, currently unsupported 'tr' translucency option, skipped.")
elif line_id == b'tf':
# rgb, filter color, blender has no support for this.
- pass
+ print("WARNING, currently unsupported 'tf' filter color option, skipped.")
elif line_id == b'illum':
illum = int(line_split[1])
# inline comments are from the spec, v4.2
if illum == 0:
# Color on and Ambient off
- do_ambient = False
+ print("WARNING, Principled BSDF shader does not support illumination 0 mode "
+ "(colors with no ambient), skipped.")
elif illum == 1:
# Color on and Ambient on
pass
@@ -326,32 +334,25 @@ def create_materials(filepath, relpath,
elif illum == 3:
# Reflection on and Ray trace on
do_reflection = True
- do_raytrace = True
elif illum == 4:
# Transparency: Glass on
# Reflection: Ray trace on
do_transparency = True
do_reflection = True
do_glass = True
- do_raytrace = True
elif illum == 5:
# Reflection: Fresnel on and Ray trace on
do_reflection = True
- do_fresnel = True
- do_raytrace = True
elif illum == 6:
# Transparency: Refraction on
# Reflection: Fresnel off and Ray trace on
do_transparency = True
do_reflection = True
- do_raytrace = True
elif illum == 7:
# Transparency: Refraction on
# Reflection: Fresnel on and Ray trace on
do_transparency = True
do_reflection = True
- do_fresnel = True
- do_raytrace = True
elif illum == 8:
# Reflection on and Ray trace off
do_reflection = True
@@ -359,12 +360,12 @@ def create_materials(filepath, relpath,
# Transparency: Glass on
# Reflection: Ray trace off
do_transparency = True
- do_reflection = True
+ do_reflection = False
do_glass = True
elif illum == 10:
# Casts shadows onto invisible surfaces
-
- # blender can't do this
+ print("WARNING, Principled BSDF shader does not support illumination 10 mode "
+ "(cast shadows on invisible surfaces), skipped.")
pass
elif line_id == b'map_ka':
@@ -410,7 +411,7 @@ def create_materials(filepath, relpath,
load_material_image(context_material, context_mat_wrap,
context_material_name, img_data, line, 'refl')
else:
- print("\t%r:%r (ignored)" % (filepath, line))
+ print("WARNING: %r:%r (ignored)" % (filepath, line))
mtl.close()
@@ -708,7 +709,6 @@ def create_mesh(new_objects,
for e in me.edges:
if e.key in sharp_edges:
e.use_edge_sharp = True
- me.show_edge_sharp = True
if verts_nor:
clnors = array.array('f', [0.0] * (len(me.loops) * 3))