diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index f051b08e1c7ad4e3e27e41a3cf14c5e5daa7ecce..9410cd1da6a4c9b608142c698d83540095fc4fd7 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -15,7 +15,7 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (1, 2, 5), + "version": (1, 2, 6), 'blender': (2, 81, 6), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py index e069069efc044a09df873160bc612fea44104f98..05a443a7b150df4baaf03efde81a1d75a8b468d0 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py @@ -124,19 +124,14 @@ class BlenderMesh(): if gltf.import_settings['import_shading'] == "NORMALS": mesh.create_normals_split() - # use_smooth for faces + use_smooths = [] # whether to smooth for each poly face_idx = 0 for prim in pymesh.primitives: - if 'NORMAL' not in prim.attributes: - face_idx += prim.num_faces - continue - - if gltf.import_settings['import_shading'] == "FLAT": - for fi in range(face_idx, face_idx + prim.num_faces): - mesh.polygons[fi].use_smooth = False + if gltf.import_settings['import_shading'] == "FLAT" or \ + 'NORMAL' not in prim.attributes: + use_smooths += [False] * prim.num_faces elif gltf.import_settings['import_shading'] == "SMOOTH": - for fi in range(face_idx, face_idx + prim.num_faces): - mesh.polygons[fi].use_smooth = True + use_smooths += [True] * prim.num_faces elif gltf.import_settings['import_shading'] == "NORMALS": mesh_loops = mesh.loops for fi in range(face_idx, face_idx + prim.num_faces): @@ -146,14 +141,16 @@ class BlenderMesh(): for loop_idx in range(poly.loop_start, poly.loop_start + poly.loop_total): vi = mesh_loops[loop_idx].vertex_index if poly.normal.dot(bme.verts[vi].normal) <= 0.9999999: - poly.use_smooth = True + use_smooths.append(True) break - + else: + use_smooths.append(False) else: # shouldn't happen - pass + assert False face_idx += prim.num_faces + mesh.polygons.foreach_set('use_smooth', use_smooths) # Custom normals, now that every update is done if gltf.import_settings['import_shading'] == "NORMALS": diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py index a046204b207afe441415d7a47e7d6d1f74811168..ff654f18d3f9d291f6b0638db46db886aef5052c 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py @@ -155,9 +155,10 @@ class BlenderPrimitive(): pyprimitive.num_faces = 0 for face in faces: try: - face = bme_faces.new(tuple( - bme_verts[pidx_to_bidx[i]] - for i in face + face = bme_faces.new(( + bme_verts[pidx_to_bidx[face[0]]], + bme_verts[pidx_to_bidx[face[1]]], + bme_verts[pidx_to_bidx[face[2]]], )) if material_index is not None: @@ -204,15 +205,15 @@ class BlenderPrimitive(): ) for bidx, pidx in vert_idxs: + color = colors[pidx] + col = ( + color_linear_to_srgb(color[0]), + color_linear_to_srgb(color[1]), + color_linear_to_srgb(color[2]), + color[3] if is_rgba else 1.0, + )[:blender_num_components] for loop in bme_verts[bidx].link_loops: - color = colors[pidx] - col = ( - color_linear_to_srgb(color[0]), - color_linear_to_srgb(color[1]), - color_linear_to_srgb(color[2]), - color[3] if is_rgba else 1.0, - ) - loop[layer] = col[:blender_num_components] + loop[layer] = col set_num += 1