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:
authorJulien Duroure <julien.duroure@gmail.com>2020-01-24 00:20:29 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-01-24 00:20:29 +0300
commitf5f442a7a665bf219755a014701aafe967f806e7 (patch)
treec544eac03ec1420e147c7af042192988b6c90687 /io_scene_gltf2
parent75855d723895e25da855087bccbd0266773bad15 (diff)
glTF importer: performance improvement importing meshes & normals
Diffstat (limited to 'io_scene_gltf2')
-rwxr-xr-xio_scene_gltf2/__init__.py2
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_mesh.py23
-rwxr-xr-xio_scene_gltf2/blender/imp/gltf2_blender_primitive.py23
3 files changed, 23 insertions, 25 deletions
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index f051b08e..9410cd1d 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 e069069e..05a443a7 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 a046204b..ff654f18 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