Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import on Unix file system #62

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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