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

Implemented MTL conversion for ACES and whatnot #383

Merged
31 changes: 31 additions & 0 deletions MCprep_addon/world_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import os
import math
from pathlib import Path
import shutil

import bpy
from bpy_extras.io_utils import ExportHelper, ImportHelper
Expand Down Expand Up @@ -310,6 +312,35 @@ def execute(self, context):
obj_import_mem_msg = (
"Memory error during OBJ import, try exporting a smaller world")
try:
try:
StandingPadAnimations marked this conversation as resolved.
Show resolved Hide resolved
BLENDER_STANDARD = (
"Standard",
"Filmic",
"Filmic Log",
"Raw",
"False Color"
)
MTL = self.filepath.rsplit(".", 1)[0] + '.mtl'
LINES = None
if bpy.context.scene.view_settings.view_transform not in BLENDER_STANDARD:
# This represents a new folder that'll backup the MTL file
original_mtl_path = Path(self.filepath).parent.absolute() / "ORIGINAL_MTLS" # Pathlib is weird when it comes to appending

# TODO: make sure this works in 2.7x. It should since 2.8 uses 3.7 but we should confirm nonetheless
original_mtl_path.mkdir(parents=True, exist_ok=True)
shutil.copy2(MTL, original_mtl_path.absolute()) # Copy the MTL with metadata

# Open the MTL
with open(MTL, 'r') as mtl_file:
LINES = mtl_file.readlines()
for index, line in enumerate(LINES):
if line.startswith("map_d"):
LINES[index] = "# " + line
with open(MTL, 'w') as mtl_file:
mtl_file.writelines(LINES)

except Exception:
self.report({"ERROR"}, "Failed to convert MTL for compatbility")
res = bpy.ops.import_scene.obj(
filepath=self.filepath, use_split_groups=True)
except MemoryError as err:
Expand Down