diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2020-04-18 10:39:07 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2020-04-18 10:39:07 +0300 |
commit | 45afacf7a630e7e77cdfc58c1b363e6e0e7747a5 (patch) | |
tree | 8fec5e6702a3061845857db8797507b20803d5bf /io_scene_gltf2/io | |
parent | 4ef5cd10f6895fbee5704d088fdbc493c0874dd9 (diff) |
glTF importer: use friendly filenames for temp image files
Diffstat (limited to 'io_scene_gltf2/io')
-rwxr-xr-x | io_scene_gltf2/io/imp/gltf2_io_binary.py | 18 | ||||
-rwxr-xr-x | io_scene_gltf2/io/imp/gltf2_io_gltf.py | 12 |
2 files changed, 13 insertions, 17 deletions
diff --git a/io_scene_gltf2/io/imp/gltf2_io_binary.py b/io_scene_gltf2/io/imp/gltf2_io_binary.py index 8815ed91..9057c17c 100755 --- a/io_scene_gltf2/io/imp/gltf2_io_binary.py +++ b/io_scene_gltf2/io/imp/gltf2_io_binary.py @@ -161,16 +161,14 @@ class BinaryData(): def get_image_data(gltf, img_idx): """Get data from image.""" pyimage = gltf.data.images[img_idx] - image_name = "Image_" + str(img_idx) - assert(not (pyimage.uri is not None and pyimage.buffer_view is not None)) + assert not ( + pyimage.uri is not None and + pyimage.buffer_view is not None + ) if pyimage.uri is not None: - data, file_name = gltf.load_uri(pyimage.uri) - return data, file_name or image_name - - elif pyimage.buffer_view is not None: - data = BinaryData.get_buffer_view(gltf, pyimage.buffer_view) - return data, image_name - - return None, None + return gltf.load_uri(pyimage.uri) + if pyimage.buffer_view is not None: + return BinaryData.get_buffer_view(gltf, pyimage.buffer_view) + return None diff --git a/io_scene_gltf2/io/imp/gltf2_io_gltf.py b/io_scene_gltf2/io/imp/gltf2_io_gltf.py index 3224a4a1..88ba5356 100755 --- a/io_scene_gltf2/io/imp/gltf2_io_gltf.py +++ b/io_scene_gltf2/io/imp/gltf2_io_gltf.py @@ -175,7 +175,7 @@ class glTFImporter(): buffer = self.data.buffers[buffer_idx] if buffer.uri: - data, _file_name = self.load_uri(buffer.uri) + data = self.load_uri(buffer.uri) if data is not None: self.buffers[buffer_idx] = data @@ -185,20 +185,18 @@ class glTFImporter(): self.buffers[buffer_idx] = self.glb_buffer def load_uri(self, uri): - """Loads a URI. - Returns the data and the filename of the resource, if there is one. - """ + """Loads a URI.""" sep = ';base64,' if uri.startswith('data:'): idx = uri.find(sep) if idx != -1: data = uri[idx + len(sep):] - return memoryview(base64.b64decode(data)), None + return memoryview(base64.b64decode(data)) path = join(dirname(self.filename), unquote(uri)) try: with open(path, 'rb') as f_: - return memoryview(f_.read()), basename(path) + return memoryview(f_.read()) except Exception: self.log.error("Couldn't read file: " + path) - return None, None + return None |