Browse Source

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.
master
Fen Dweller 3 years ago
parent
commit
053a39c15e
2 changed files with 31 additions and 10 deletions
  1. +3
    -0
      scripts/blender/addons/macrovision/ops.py
  2. +28
    -10
      scripts/process-model.py

+ 3
- 0
scripts/blender/addons/macrovision/ops.py View File

@@ -121,6 +121,9 @@ class MVConfigCollection(bpy.types.Operator):


bpy.ops.object.lineart_clear_all() 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'} return {'FINISHED'}


class MVAssignMaterials(bpy.types.Operator): class MVAssignMaterials(bpy.types.Operator):


+ 28
- 10
scripts/process-model.py View File

@@ -4,11 +4,11 @@ import json
import os import os
import subprocess import subprocess
import pathlib import pathlib
import time
from xml.dom import minidom from xml.dom import minidom


# an affront to god # 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() base = open(base_path, "r", encoding="utf-8").read()
dark = open(dark_path, "r", encoding="utf-8").read() dark = open(dark_path, "r", encoding="utf-8").read()
medium = open(medium_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("<g.*", medium, flags=re.DOTALL)[0][:-7] medium_data = re.search("<g.*", medium, flags=re.DOTALL)[0][:-7]
light_data = light.replace("</metadata>", "</metadata>" + base_data + "\n" + dark_data + "\n" + medium_data) light_data = light.replace("</metadata>", "</metadata>" + 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) 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 configdir = pathlib.Path(__file__).parent
configpath = configdir.joinpath("config.json") 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__() input_noline_raw = sourcedir.joinpath(name + "-" + view_name + "-" + "noline.png").__str__()
result = outputdir.joinpath(name + "-" + view_name + ".svg").__str__() result = outputdir.joinpath(name + "-" + view_name + ".svg").__str__()
print(result) 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_base = sourcedir.joinpath(name + "-" + view_name + "-base.bmp").__str__()
input_dark = sourcedir.joinpath(name + "-" + view_name + "-dark.bmp").__str__() input_dark = sourcedir.joinpath(name + "-" + view_name + "-dark.bmp").__str__()
input_medium = sourcedir.joinpath(name + "-" + view_name + "-medium.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__() 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] [proc.wait() for proc in procs]


# we now learn how much height was added by the lineart! # 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)) original_xml = minidom.parse(open(result))
noline_xml = minidom.parse(open(noline_result)) noline_xml = minidom.parse(open(noline_result))



original_height = float(original_xml.childNodes[0].attributes["height"].value[:-2]) original_height = float(original_xml.childNodes[0].attributes["height"].value[:-2])
noline_height = float(noline_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["extra"] = (height - bottom) / (top - bottom)
view["bottom"] = bottom / height view["bottom"] = bottom / height


os.unlink(noline_result)



# now we add the data # now we add the data




Loading…
Cancel
Save