Fix T47986: OBJ Import fails w/ imagepath encoding
This commit is contained in:
@@ -35,6 +35,7 @@ __all__ = (
|
|||||||
"extensions_audio",
|
"extensions_audio",
|
||||||
"is_subdir",
|
"is_subdir",
|
||||||
"module_names",
|
"module_names",
|
||||||
|
"native_pathsep",
|
||||||
"reduce_dirs",
|
"reduce_dirs",
|
||||||
"relpath",
|
"relpath",
|
||||||
"resolve_ncase",
|
"resolve_ncase",
|
||||||
@@ -349,6 +350,28 @@ def basename(path):
|
|||||||
return _os.path.basename(path[2:] if path[:2] in {"//", b"//"} else path)
|
return _os.path.basename(path[2:] if path[:2] in {"//", b"//"} else path)
|
||||||
|
|
||||||
|
|
||||||
|
def native_pathsep(path):
|
||||||
|
"""
|
||||||
|
Replace the path separator with the systems native ``os.sep``.
|
||||||
|
"""
|
||||||
|
if type(path) is str:
|
||||||
|
if _os.sep == "/":
|
||||||
|
return path.replace("\\", "/")
|
||||||
|
else:
|
||||||
|
if path.startswith("//"):
|
||||||
|
return "//" + path[2:].replace("/", "\\")
|
||||||
|
else:
|
||||||
|
return path.replace("/", "\\")
|
||||||
|
else: # bytes
|
||||||
|
if _os.sep == "/":
|
||||||
|
return path.replace(b"\\", b"/")
|
||||||
|
else:
|
||||||
|
if path.startswith(b"//"):
|
||||||
|
return b"//" + path[2:].replace(b"/", b"\\")
|
||||||
|
else:
|
||||||
|
return path.replace(b"/", b"\\")
|
||||||
|
|
||||||
|
|
||||||
def reduce_dirs(dirs):
|
def reduce_dirs(dirs):
|
||||||
"""
|
"""
|
||||||
Given a sequence of directories, remove duplicates and
|
Given a sequence of directories, remove duplicates and
|
||||||
|
|||||||
@@ -80,9 +80,12 @@ def load_image(imagepath,
|
|||||||
# Utility Functions
|
# Utility Functions
|
||||||
|
|
||||||
def _image_load_placeholder(path):
|
def _image_load_placeholder(path):
|
||||||
name = bpy.path.basename(path)
|
name = path
|
||||||
if type(name) == bytes:
|
if type(path) is str:
|
||||||
name = name.decode("utf-8", "replace")
|
name = name.encode("utf-8", "replace")
|
||||||
|
name = name.decode("utf-8", "replace")
|
||||||
|
name = os.path.basename(name)
|
||||||
|
|
||||||
image = bpy.data.images.new(name, 128, 128)
|
image = bpy.data.images.new(name, 128, 128)
|
||||||
# allow the path to be resolved later
|
# allow the path to be resolved later
|
||||||
image.filepath = path
|
image.filepath = path
|
||||||
@@ -147,6 +150,8 @@ def load_image(imagepath,
|
|||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
imagepath = bpy.path.native_pathsep(imagepath)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print("load_image('%s', '%s', ...)" % (imagepath, dirname))
|
print("load_image('%s', '%s', ...)" % (imagepath, dirname))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user