[Bf-extensions-cvs] [5a937eda] master: glTF importer: manage escaped uri for texture files

Julien Duroure noreply at git.blender.org
Fri Aug 9 19:56:18 CEST 2019


Commit: 5a937edabb313e4924ba66c21a745ab142e9b5ef
Author: Julien Duroure
Date:   Fri Aug 9 19:43:24 2019 +0200
Branches: master
https://developer.blender.org/rBA5a937edabb313e4924ba66c21a745ab142e9b5ef

glTF importer: manage escaped uri for texture files

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

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/imp/gltf2_blender_image.py
M	io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.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 1dfd167d..b09561db 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, 45),
+    "version": (0, 9, 46),
     'blender': (2, 80, 0),
     '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 4d352362..546aa7e3 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_image.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_image.py
@@ -16,6 +16,7 @@ import bpy
 import os
 import tempfile
 from os.path import dirname, join, isfile, basename
+from urllib.parse import unquote
 
 from ...io.imp.gltf2_io_binary import BinaryData
 
@@ -40,8 +41,8 @@ class BlenderImage():
                 if idx != -1:
                     return False, None, None
 
-            if isfile(join(dirname(gltf.filename), pyimage.uri)):
-                return True, join(dirname(gltf.filename), pyimage.uri), basename(join(dirname(gltf.filename), pyimage.uri))
+            if isfile(join(dirname(gltf.filename), unquote(pyimage.uri))):
+                return True, join(dirname(gltf.filename), unquote(pyimage.uri)), basename(join(dirname(gltf.filename), unquote(pyimage.uri)))
             else:
                 gltf.log.error("Missing file (index " + str(img_idx) + "): " + pyimage.uri)
                 return False, None, None
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
index 16c6dbf1..62c3fb62 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
@@ -129,7 +129,6 @@ class BlenderPbr():
             mapping.location = -1500, 500
             mapping.vector_type = 'POINT'
             if text_node.image is not None: # Sometimes images can't be retrieved (bad gltf file ...)
-                print("OK")
                 tex_transform = text_node.image['tex_transform'][str(pypbr.base_color_texture.index)]
                 mapping.translation[0] = texture_transform_gltf_to_blender(tex_transform)['offset'][0]
                 mapping.translation[1] = texture_transform_gltf_to_blender(tex_transform)['offset'][1]
@@ -196,7 +195,6 @@ class BlenderPbr():
                 mapping.location = -1500, 500
             mapping.vector_type = 'POINT'
             if text_node.image is not None: # Sometimes images can't be retrieved (bad gltf file ...)
-                print("OK")
                 tex_transform = text_node.image['tex_transform'][str(pypbr.base_color_texture.index)]
                 mapping.translation[0] = texture_transform_gltf_to_blender(tex_transform)['offset'][0]
                 mapping.translation[1] = texture_transform_gltf_to_blender(tex_transform)['offset'][1]
diff --git a/io_scene_gltf2/io/imp/gltf2_io_binary.py b/io_scene_gltf2/io/imp/gltf2_io_binary.py
index 498d49e8..92450672 100755
--- a/io_scene_gltf2/io/imp/gltf2_io_binary.py
+++ b/io_scene_gltf2/io/imp/gltf2_io_binary.py
@@ -15,6 +15,7 @@
 import struct
 import base64
 from os.path import dirname, join, isfile, basename
+from urllib.parse import unquote
 
 
 class BinaryData():
@@ -159,9 +160,9 @@ class BinaryData():
                     data = pyimage.uri[idx + len(sep):]
                     return base64.b64decode(data), image_name
 
-            if isfile(join(dirname(gltf.filename), pyimage.uri)):
-                with open(join(dirname(gltf.filename), pyimage.uri), 'rb') as f_:
-                    return f_.read(), basename(join(dirname(gltf.filename), pyimage.uri))
+            if isfile(join(dirname(gltf.filename), unquote(pyimage.uri))):
+                with open(join(dirname(gltf.filename), unquote(pyimage.uri)), 'rb') as f_:
+                    return f_.read(), basename(join(dirname(gltf.filename), unquote(pyimage.uri)))
             else:
                 gltf.log.error("Missing file (index " + str(img_idx) + "): " + pyimage.uri)
                 return None, None



More information about the Bf-extensions-cvs mailing list