diff --git a/o3d_io/blender_texture_io.py b/o3d_io/blender_texture_io.py index 287b8fa..08229b3 100644 --- a/o3d_io/blender_texture_io.py +++ b/o3d_io/blender_texture_io.py @@ -31,11 +31,11 @@ def __init__(self, image): def load_image(base_file_path, texture_path, abs_path=False): if base_file_path[-3:] == "sco": - tex_file = os.path.dirname(base_file_path) + "\\texture\\" + texture_path.lower() + tex_file = os.path.join(os.path.dirname(base_file_path), "texture", texture_path.lower()) elif base_file_path[-3:] == "map": - tex_file = os.path.dirname(base_file_path) + "\\..\\..\\" + texture_path.lower() + tex_file = os.path.join(os.path.dirname(base_file_path), "..", "..", texture_path.lower()) else: - tex_file = os.path.dirname(base_file_path) + "\\..\\texture\\" + texture_path.lower() + tex_file = os.path.join(os.path.dirname(base_file_path), "..", "texture", texture_path.lower()) if abs_path: tex_file = texture_path.lower() diff --git a/o3d_io/io_o3d_import.py b/o3d_io/io_o3d_import.py index baf6d3e..993e0cb 100644 --- a/o3d_io/io_o3d_import.py +++ b/o3d_io/io_o3d_import.py @@ -24,6 +24,13 @@ def log(*args): print("[O3D_Import]", *args) +def platform_related_path(path): + """ + Return a string with correct path separators for the current platform + :param path: the path to convert + :return: the converted path + """ + return path.replace("/", os.sep).replace("\\", os.sep) def do_import(filepath, context, import_x, override_text_encoding, hide_lods): """ @@ -104,6 +111,7 @@ def do_import(filepath, context, import_x, override_text_encoding, hide_lods): continue # Load mesh + path_to_file = platform_related_path(path_to_file) with open(path_to_file, "rb") as f: o3d_bytes = f.read() log("[{0:.2f}%] Loading {1}...".format((index + 1) / len(files) * 100, path_to_file)) diff --git a/o3d_io/o3d_cfg_parser.py b/o3d_io/o3d_cfg_parser.py index 4fe6ead..2d235e9 100644 --- a/o3d_io/o3d_cfg_parser.py +++ b/o3d_io/o3d_cfg_parser.py @@ -46,7 +46,7 @@ def read_cfg(filepath, override_text_encoding): # get the folder folder = (os.path.dirname(filepath)) if filepath[-3:] == "sco": - folder += "\\model" + folder = os.path.join(folder, "model") # log("Loading " + filepath) encoding = override_text_encoding if override_text_encoding.strip() != "" else "1252" @@ -111,7 +111,7 @@ def read_cfg(filepath, override_text_encoding): elif current_command == "[mesh]": if param_ind == 0: current_mat = None - mesh_path = folder + "\\" + line + mesh_path = os.path.join(folder, line) if line[-4:] == ".o3d": if os.path.isfile(mesh_path): files.append((mesh_path, current_lod)) @@ -439,7 +439,7 @@ def read_cfg(filepath, override_text_encoding): else: cfg_data[current_lod]["cfg_data"][-1].append(line) - return cfg_data, (folder + "\\") + return cfg_data, (folder + os.path.sep) def write_additional_cfg_props(cfg_props, f):