[Bf-extensions-cvs] [f9e25350] master: glTF importer: more perf

Julien Duroure noreply at git.blender.org
Tue Oct 1 20:56:17 CEST 2019


Commit: f9e25350dc87170cedacf1c41d382c69360f76d4
Author: Julien Duroure
Date:   Tue Oct 1 20:55:56 2019 +0200
Branches: master
https://developer.blender.org/rBAf9e25350dc87170cedacf1c41d382c69360f76d4

glTF importer: more perf

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
M	io_scene_gltf2/io/imp/gltf2_io_binary.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index de979ec6..7b53aa41 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": (0, 9, 79),
+    "version": (0, 9, 80),
     '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 2d3abb6c..1f7f7b66 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
@@ -145,26 +145,17 @@ class BlenderMesh():
                 for fi in range(face_idx, face_idx + prim.num_faces):
                     mesh.polygons[fi].use_smooth = True
             elif gltf.import_settings['import_shading'] == "NORMALS":
+                mesh_loops = mesh.loops
                 for fi in range(face_idx, face_idx + prim.num_faces):
                     poly = mesh.polygons[fi]
-                    calc_norm_vertices = []
+                    # "Flat normals" are when all the vertices in poly have the
+                    # poly's normal. Otherwise, smooth the poly.
                     for loop_idx in range(poly.loop_start, poly.loop_start + poly.loop_total):
-                        vert_idx = mesh.loops[loop_idx].vertex_index
-                        calc_norm_vertices.append(vert_idx)
-
-                        if len(calc_norm_vertices) == 3:
-                            # Calcul normal
-                            vert0 = mesh.vertices[calc_norm_vertices[0]].co
-                            vert1 = mesh.vertices[calc_norm_vertices[1]].co
-                            vert2 = mesh.vertices[calc_norm_vertices[2]].co
-                            calc_normal = (vert1 - vert0).cross(vert2 - vert0).normalized()
-
-                            # Compare normal to vertex normal
-                            for i in calc_norm_vertices:
-                                vec = Vector(bme.verts[i].normal)
-                                if not calc_normal.dot(vec) > 0.9999999:
-                                    poly.use_smooth = True
-                                    break
+                        vi = mesh_loops[loop_idx].vertex_index
+                        if poly.normal.dot(bme.verts[vi].normal) <= 0.9999999:
+                            poly.use_smooth = True
+                            break
+
             else:
                 # shouldn't happen
                 pass
diff --git a/io_scene_gltf2/io/imp/gltf2_io_binary.py b/io_scene_gltf2/io/imp/gltf2_io_binary.py
index f7a101df..4c5ea8f1 100755
--- a/io_scene_gltf2/io/imp/gltf2_io_binary.py
+++ b/io_scene_gltf2/io/imp/gltf2_io_binary.py
@@ -67,12 +67,11 @@ class BinaryData():
         else:
             stride = stride_
 
-        data = []
-        offset = 0
-        while len(data) < accessor.count:
-            element = struct.unpack_from(fmt, buffer_data, offset)
-            data.append(element)
-            offset += stride
+        unpack_from = struct.Struct(fmt).unpack_from
+        data = [
+            unpack_from(buffer_data, offset)
+            for offset in range(0, accessor.count*stride, stride)
+        ]
 
         if accessor.sparse:
             sparse_indices_data = BinaryData.get_data_from_sparse(gltf, accessor.sparse, "indices")
@@ -142,12 +141,11 @@ class BinaryData():
         else:
             stride = stride_
 
-        data = []
-        offset = 0
-        while len(data) < sparse.count:
-            element = struct.unpack_from(fmt, bin_data, offset)
-            data.append(element)
-            offset += stride
+        unpack_from = struct.Struct(fmt).unpack_from
+        data = [
+            unpack_from(bin_data, offset)
+            for offset in range(0, sparse.count*stride, stride)
+        ]
 
         return data



More information about the Bf-extensions-cvs mailing list