[Bf-extensions-cvs] [a0c33fe9] master: glTF importer: big perf improvement for primitives sharing accessor(s)

Julien Duroure noreply at git.blender.org
Thu Sep 26 18:16:00 CEST 2019


Commit: a0c33fe957a9c7db0a239be0791e4715862c45ec
Author: Julien Duroure
Date:   Thu Sep 26 16:41:37 2019 +0200
Branches: master
https://developer.blender.org/rBAa0c33fe957a9c7db0a239be0791e4715862c45ec

glTF importer: big perf improvement for primitives sharing accessor(s)

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
M	io_scene_gltf2/blender/imp/gltf2_blender_primitive.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 5282cde6..cdc8b5a5 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, 74),
+    "version": (0, 9, 75),
     '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 ba22d0cc..cfe73058 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_mesh.py
@@ -40,6 +40,7 @@ class BlenderMesh():
         # primitive uses is set by giving an index into this list.
         materials = []
 
+        gltf.accessor_cache = {} # cache accessor data for primtives that share accessors
         # Process all primitives
         for prim in pymesh.primitives:
             prim.blender_texcoord = {}
@@ -76,7 +77,7 @@ class BlenderMesh():
         mesh.update()
 
         pymesh.blender_name = mesh.name
-
+        del gltf.accessor_cache # Remove cache
         return mesh
 
     @staticmethod
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
index 23625769..31edd0f6 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_primitive.py
@@ -44,9 +44,14 @@ class BlenderPrimitive():
             pyprimitive.num_faces = 0
             return
 
-        positions = BinaryData.get_data_from_accessor(gltf, attributes['POSITION'])
+        if attributes['POSITION'] not in gltf.accessor_cache.keys():
+            positions = BinaryData.get_data_from_accessor(gltf, attributes['POSITION'])
+            gltf.accessor_cache[attributes['POSITION']] = positions
+        else:
+            positions = gltf.accessor_cache[attributes['POSITION']]
 
         if pyprimitive.indices is not None:
+            # Not using cache, this is no usefull for indices
             indices = BinaryData.get_data_from_accessor(gltf, pyprimitive.indices)
             indices = [i[0] for i in indices]
         else:
@@ -109,7 +114,12 @@ class BlenderPrimitive():
 
         # Set normals
         if 'NORMAL' in attributes:
-            normals = BinaryData.get_data_from_accessor(gltf, attributes['NORMAL'])
+            if attributes['NORMAL'] not in gltf.accessor_cache.keys():
+                normals = BinaryData.get_data_from_accessor(gltf, attributes['NORMAL'])
+                gltf.accessor_cache[attributes['NORMAL']] = normals
+            else:
+                normals = gltf.accessor_cache[attributes['NORMAL']]
+
             for bidx, pidx in vert_idxs:
                 bme_verts[bidx].normal = normals[pidx]
 
@@ -125,7 +135,11 @@ class BlenderPrimitive():
             layer_name = 'COLOR_%d' % set_num
             layer = BlenderPrimitive.get_layer(bme.loops.layers.color, layer_name)
 
-            colors = BinaryData.get_data_from_accessor(gltf, attributes[layer_name])
+            if attributes[layer_name] not in gltf.accessor_cache.keys():
+                colors = BinaryData.get_data_from_accessor(gltf, attributes[layer_name])
+                gltf.accessor_cache[attributes[layer_name]] = colors
+            else:
+                colors = gltf.accessor_cache[attributes[layer_name]]
 
             # Check whether Blender takes RGB or RGBA colors (old versions only take RGB)
             num_components = len(colors[0])
@@ -163,7 +177,11 @@ class BlenderPrimitive():
 
             pyprimitive.blender_texcoord[set_num] = layer_name
 
-            uvs = BinaryData.get_data_from_accessor(gltf, attributes[layer_name])
+            if attributes[layer_name] not in gltf.accessor_cache.keys():
+                uvs = BinaryData.get_data_from_accessor(gltf, attributes[layer_name])
+                gltf.accessor_cache[attributes[layer_name]] = uvs
+            else:
+                uvs = gltf.accessor_cache[attributes[layer_name]]
 
             for bidx, pidx in vert_idxs:
                 # UV transform
@@ -180,8 +198,18 @@ class BlenderPrimitive():
         weight_sets = []
         set_num = 0
         while 'JOINTS_%d' % set_num in attributes and 'WEIGHTS_%d' % set_num in attributes:
-            joint_data = BinaryData.get_data_from_accessor(gltf, attributes['JOINTS_%d' % set_num])
-            weight_data = BinaryData.get_data_from_accessor(gltf, attributes['WEIGHTS_%d' % set_num])
+            if attributes['JOINTS_%d' % set_num] not in gltf.accessor_cache.keys():
+                joint_data = BinaryData.get_data_from_accessor(gltf, attributes['JOINTS_%d' % set_num])
+                gltf.accessor_cache[attributes['JOINTS_%d' % set_num]] = joint_data
+            else:
+                joint_data = gltf.accessor_cache[attributes['JOINTS_%d' % set_num]]
+
+            if attributes['WEIGHTS_%d' % set_num] not in gltf.accessor_cache.keys()
+                weight_data = BinaryData.get_data_from_accessor(gltf, attributes['WEIGHTS_%d' % set_num])
+                gltf.accessor_cache[attributes['WEIGHTS_%d' % set_num]] = weight_data
+            else:
+                weight_data = gltf.accessor_cache[attributes['WEIGHTS_%d' % set_num]]
+
             joint_sets.append(joint_data)
             weight_sets.append(weight_data)
 
@@ -206,7 +234,11 @@ class BlenderPrimitive():
             layer_name = pymesh.shapekey_names[sk]
             layer = BlenderPrimitive.get_layer(bme.verts.layers.shape, layer_name)
 
-            morph_positions = BinaryData.get_data_from_accessor(gltf, target['POSITION'])
+            if target['POSITION'] not in gltf.accessor_cache.keys():
+                morph_positions = BinaryData.get_data_from_accessor(gltf, target['POSITION'])
+                gltf.accessor_cache[target['POSITION']] = morph_positions
+            else:
+                morph_positions = gltf.accessor_cache[target['POSITION']]
 
             for bidx, pidx in vert_idxs:
                 bme_verts[bidx][layer] = (



More information about the Bf-extensions-cvs mailing list