From 053a39c15eee19e953add250c1868207f6b743ea Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 23 Jan 2022 09:12:58 -0500 Subject: [PATCH] Fix some bugs with the Blender scripts Inkscape now exits before it finishes writing its files, somehow. So, we need to wait for the files to be created. The Blender add-on also now correctly configures the lineart to use the secondary camera, which is rotated to avoid errors when rendering orthographically. --- scripts/blender/addons/macrovision/ops.py | 3 ++ scripts/process-model.py | 38 +++++++++++++++++------ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/scripts/blender/addons/macrovision/ops.py b/scripts/blender/addons/macrovision/ops.py index 9255dc30..2de78080 100644 --- a/scripts/blender/addons/macrovision/ops.py +++ b/scripts/blender/addons/macrovision/ops.py @@ -121,6 +121,9 @@ class MVConfigCollection(bpy.types.Operator): bpy.ops.object.lineart_clear_all() + new_obj.grease_pencil_modifiers[0].use_custom_camera = True + new_obj.grease_pencil_modifiers[0].source_camera = bpy.data.objects["cam2"] + return {'FINISHED'} class MVAssignMaterials(bpy.types.Operator): diff --git a/scripts/process-model.py b/scripts/process-model.py index 1211f82b..47cc49dc 100644 --- a/scripts/process-model.py +++ b/scripts/process-model.py @@ -4,11 +4,11 @@ import json import os import subprocess import pathlib - +import time from xml.dom import minidom # an affront to god -def combine(base_path, dark_path, medium_path, light_path, output_path): +def combine(base_path, dark_path, medium_path, light_path, tmp_output_path, output_path): base = open(base_path, "r", encoding="utf-8").read() dark = open(dark_path, "r", encoding="utf-8").read() medium = open(medium_path, "r", encoding="utf-8").read() @@ -19,10 +19,10 @@ def combine(base_path, dark_path, medium_path, light_path, output_path): medium_data = re.search("", "" + base_data + "\n" + dark_data + "\n" + medium_data) - with open(output_path, "w", encoding="utf-8") as f: + with open(tmp_output_path, "w", encoding="utf-8") as f: f.write(light_data) - return subprocess.Popen([INKSCAPE, "--without-gui", "--export-plain-svg=" + output_path, "--export-area-drawing", output_path], shell=False) + return subprocess.Popen([INKSCAPE, "--without-gui", "--export-plain-svg", "--export-area-drawing", "--export-filename=" + output_path, tmp_output_path], shell=False) configdir = pathlib.Path(__file__).parent configpath = configdir.joinpath("config.json") @@ -59,10 +59,13 @@ for data in all_data["forms"]: input_noline_raw = sourcedir.joinpath(name + "-" + view_name + "-" + "noline.png").__str__() result = outputdir.joinpath(name + "-" + view_name + ".svg").__str__() print(result) - if os.path.exists(result) and os.path.getmtime(input) < os.path.getmtime(result): - print("Skipping ", input) - continue - + if os.path.exists(result): + if os.path.getmtime(input) < os.path.getmtime(result): + print("Skipping ", input) + continue + else: + os.unlink(result) + input_base = sourcedir.joinpath(name + "-" + view_name + "-base.bmp").__str__() input_dark = sourcedir.joinpath(name + "-" + view_name + "-dark.bmp").__str__() input_medium = sourcedir.joinpath(name + "-" + view_name + "-medium.bmp").__str__() @@ -102,16 +105,29 @@ for data in all_data["forms"]: noline_result = sourcedir.joinpath(name + "-" + view_name + "-noline_processed.svg").__str__() - procs.append(combine(output_base, output_dark, output_medium, output_light, result)) - procs.append(combine(output_noline, output_noline, output_noline, output_noline, noline_result)) + result_tmp = outputdir.joinpath(name + "-" + view_name + "-tmp.svg").__str__() + noline_result_tmp = sourcedir.joinpath(name + "-" + view_name + "-noline_processed-tmp.svg").__str__() + procs.append(combine(output_base, output_dark, output_medium, output_light, result_tmp, result)) + procs.append(combine(output_noline, output_noline, output_noline, output_noline, noline_result_tmp, noline_result)) [proc.wait() for proc in procs] # we now learn how much height was added by the lineart! + # for some reason, the files aren't appearing for a moment after Inkscape quits + + while True: + if os.path.exists(result) and os.path.exists(noline_result): + break + time.sleep(0.1) + + os.unlink(result_tmp) + os.unlink(noline_result_tmp) + original_xml = minidom.parse(open(result)) noline_xml = minidom.parse(open(noline_result)) + original_height = float(original_xml.childNodes[0].attributes["height"].value[:-2]) noline_height = float(noline_xml.childNodes[0].attributes["height"].value[:-2]) @@ -124,6 +140,8 @@ for data in all_data["forms"]: view["extra"] = (height - bottom) / (top - bottom) view["bottom"] = bottom / height + os.unlink(noline_result) + # now we add the data