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 <b.mont29@gmail.com>2019-11-18 12:41:01 +0300
committerBastien Montagne <b.mont29@gmail.com>2019-11-18 12:41:01 +0300
commit4fd8ee12dbaba9fb21dad8f3c2a8718fb69f27a0 (patch)
treebdd9674f61da92a7c5dd38de3084f8c1c28a7a96 /io_scene_obj
parent9714cfe4a72b8bf8f61d917bbfdeb31397fe4f0c (diff)
Fix T71618: Can't import OBJs that have single-value colors in their MTL file.
MTL standard does consider g and b values as optional...
Diffstat (limited to 'io_scene_obj')
-rw-r--r--io_scene_obj/__init__.py2
-rw-r--r--io_scene_obj/import_obj.py21
2 files changed, 15 insertions, 8 deletions
diff --git a/io_scene_obj/__init__.py b/io_scene_obj/__init__.py
index 399a4d29..e121bb66 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, 7, 0),
+ "version": (3, 8, 0),
"blender": (2, 81, 6),
"location": "File > Import-Export",
"description": "Import-Export OBJ, Import OBJ mesh, UV's, materials and textures",
diff --git a/io_scene_obj/import_obj.py b/io_scene_obj/import_obj.py
index 4d640d44..0c2d6995 100644
--- a/io_scene_obj/import_obj.py
+++ b/io_scene_obj/import_obj.py
@@ -326,23 +326,30 @@ def create_materials(filepath, relpath,
elif context_material:
+ def _get_colors(line_split):
+ # OBJ 'allows' one or two components values, treat single component as greyscale, and two as blue = 0.0.
+ ln = len(line_split)
+ if ln == 2:
+ return [float_func(line_split[1])] * 3
+ elif ln == 3:
+ return [float_func(line_split[1]), float_func(line_split[2]), 0.0]
+ else:
+ return [float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3])]
+
# we need to make a material to assign properties to it.
if line_id == b'ka':
- refl = (float_func(line_split[1]) + float_func(line_split[2]) + float_func(line_split[3])) / 3.0
+ refl = sum(_get_colors(line_split)) / 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.base_color = col
+ context_mat_wrap.base_color = _get_colors(line_split)
elif line_id == b'ks':
- spec_colors[:] = [
- float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3])]
+ spec_colors[:] = _get_colors(line_split)
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 Unsupported currently
- col = (float_func(line_split[1]), float_func(line_split[2]), float_func(line_split[3]))
- context_mat_wrap.emission_color = col
+ context_mat_wrap.emission_color = _get_colors(line_split)
elif line_id == b'ns':
# 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)...