diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-09-26 22:43:14 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-09-26 22:43:14 +0300 |
commit | eba6fe23d3bb35175df5fd8fe3cfa25d1588c61a (patch) | |
tree | 6acb2c71fafc46e7004e284a1f4cafc6cc065978 /io_scene_gltf2/io | |
parent | 96036641899e5a9c84b5fd9963b49e6737328d4e (diff) |
glTF importer: refactoring accessor caching
Diffstat (limited to 'io_scene_gltf2/io')
-rwxr-xr-x | io_scene_gltf2/io/imp/gltf2_io_binary.py | 8 | ||||
-rwxr-xr-x | io_scene_gltf2/io/imp/gltf2_io_gltf.py | 1 |
2 files changed, 8 insertions, 1 deletions
diff --git a/io_scene_gltf2/io/imp/gltf2_io_binary.py b/io_scene_gltf2/io/imp/gltf2_io_binary.py index 92450672..f7a101df 100755 --- a/io_scene_gltf2/io/imp/gltf2_io_binary.py +++ b/io_scene_gltf2/io/imp/gltf2_io_binary.py @@ -46,8 +46,11 @@ class BinaryData(): return buffer[accessor_offset + bufferview_offset:accessor_offset + bufferview_offset + bufferView.byte_length] @staticmethod - def get_data_from_accessor(gltf, accessor_idx): + def get_data_from_accessor(gltf, accessor_idx, cache=False): """Get data from accessor.""" + if accessor_idx in gltf.accessor_cache: + return gltf.accessor_cache[accessor_idx] + accessor = gltf.data.accessors[accessor_idx] bufferView = gltf.data.buffer_views[accessor.buffer_view] # TODO initialize with 0 when not present! @@ -102,6 +105,9 @@ class BinaryData(): new_tuple += (float(i),) data[idx] = new_tuple + if cache: + gltf.accessor_cache[accessor_idx] = data + return data @staticmethod diff --git a/io_scene_gltf2/io/imp/gltf2_io_gltf.py b/io_scene_gltf2/io/imp/gltf2_io_gltf.py index f430027c..34f205f9 100755 --- a/io_scene_gltf2/io/imp/gltf2_io_gltf.py +++ b/io_scene_gltf2/io/imp/gltf2_io_gltf.py @@ -29,6 +29,7 @@ class glTFImporter(): self.filename = filename self.import_settings = import_settings self.buffers = {} + self.accessor_cache = {} if 'loglevel' not in self.import_settings.keys(): self.import_settings['loglevel'] = logging.ERROR |