Skip to content

Commit

Permalink
Merge pull request #62 from arnoclr/main
Browse files Browse the repository at this point in the history
fix: import on Unix file system
  • Loading branch information
space928 authored Jun 19, 2023
2 parents 3948706 + 697426e commit 5a56c00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions o3d_io/blender_texture_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions o3d_io/io_o3d_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions o3d_io/o3d_cfg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5a56c00

Please sign in to comment.