Skip to content

Commit

Permalink
Fix MTL save bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinzakka committed Sep 23, 2022
1 parent 0125bd2 commit 09c0e71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion obj2mjcf/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.19"
__version__ = "0.0.20"
14 changes: 10 additions & 4 deletions obj2mjcf/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"map_Kd",
)

# Character used to denote a comment in an MTL file.
_MTL_COMMENT_CHAR = "#"


class FillMode(enum.Enum):
FLOOD = enum.auto()
Expand Down Expand Up @@ -290,9 +293,12 @@ def process_obj(filename: Path, args: Args) -> None:
# Parse the MTL file into separate materials.
with open(mtl_filename, "r") as f:
lines = f.readlines()
lines = [
line.strip() for line in lines if not line.startswith("#") and line.strip()
]
# Remove comments.
lines = [line for line in lines if not line.startswith(_MTL_COMMENT_CHAR)]
# Remove empty lines.
lines = [line for line in lines if line.strip()]
# Remove trailing whitespace.
lines = [line.strip() for line in lines]
# Split at each new material definition.
for line in lines:
if line.startswith("newmtl"):
Expand Down Expand Up @@ -366,7 +372,7 @@ def process_obj(filename: Path, args: Args) -> None:
break
# Save the MTL file.
with open(work_dir / f"{mtl_name}.mtl", "w") as f:
f.write("".join(smtl))
f.write("\n".join(smtl))
# Edit the mtllib line to point to the new MTL file.
if len(sub_mtls) > 1:
savename = str(work_dir / f"{filename.stem}_{i}.obj")
Expand Down

0 comments on commit 09c0e71

Please sign in to comment.