[Bf-extensions-cvs] [ea296543] master: glTF importer: add extension to tmp file generated when importing textures

Julien Duroure noreply at git.blender.org
Sat Mar 28 13:12:13 CET 2020


Commit: ea2965438756165bc28b7d52e472b2c5984d64be
Author: Julien Duroure
Date:   Sat Mar 28 13:11:42 2020 +0100
Branches: master
https://developer.blender.org/rBAea2965438756165bc28b7d52e472b2c5984d64be

glTF importer: add extension to tmp file generated when importing textures

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/imp/gltf2_blender_image.py

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

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 55725ca8..bd71223d 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, 55),
+    "version": (1, 2, 56),
     'blender': (2, 82, 7),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_image.py b/io_scene_gltf2/blender/imp/gltf2_blender_image.py
index 92eed8d4..a0b01aed 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_image.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_image.py
@@ -52,7 +52,11 @@ class BlenderImage():
                 img_data, img_name = BinaryData.get_image_data(gltf, img_idx)
                 if img_data is None:
                     return
-                tmp_file = tempfile.NamedTemporaryFile(prefix='gltfimg', delete=False)
+                tmp_file = tempfile.NamedTemporaryFile(
+                    prefix='gltfimg-',
+                    suffix=_img_extension(img),
+                    delete=False,
+                )
                 tmp_file.write(img_data)
                 tmp_file.close()
                 path = tmp_file.name
@@ -74,3 +78,10 @@ class BlenderImage():
 def _uri_to_path(uri):
     uri = urllib.parse.unquote(uri)
     return normpath(uri)
+
+def _img_extension(img):
+    if img.mime_type == 'image/png':
+        return '.png'
+    if img.mime_type == 'image/jpeg':
+        return '.jpg'
+    return None



More information about the Bf-extensions-cvs mailing list