less copy protection, more size visualization
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

98 行
3.8 KiB

  1. import sys
  2. import re
  3. import json
  4. import glob
  5. import os
  6. import subprocess
  7. PREFIX = "PREFIX"
  8. def combine(base_path, highlight_path, output_path):
  9. base = open(base_path, "r", encoding="utf-8").read()
  10. highlight = open(highlight_path, "r", encoding="utf-8").read()
  11. base_data = re.search("<g.*", base, flags=re.DOTALL)[0][:-7]
  12. highlight_data = highlight.replace("</metadata>", "</metadata>" + base_data)
  13. with open(output_path, "w", encoding="utf-8") as f:
  14. f.write(highlight_data)
  15. subprocess.run([INKSCAPE, "--without-gui", "--export-plain-svg=" + output_path, "--export-area-drawing", output_path], shell=True)
  16. if len(sys.argv) <= 1:
  17. print(f"Usage: {sys.argv[0]} [location name]")
  18. sys.exit(1)
  19. template = """
  20. {{
  21. name: "{0}",
  22. sides: {{
  23. "Side": {{ height: math.unit({1}, "meters") }},
  24. "Front": {{ height: math.unit({2}, "meters") }},
  25. "Top": {{ height: math.unit({3}, "meters") }},
  26. }}
  27. }}"""
  28. path = os.path.dirname(sys.argv[0])
  29. config = json.load(open(os.path.join(path, "config.json"), "r", encoding="utf-8"))
  30. output = []
  31. os.makedirs("./combined/" + sys.argv[1], exist_ok=True)
  32. target_file = "vehicles"
  33. os.makedirs(f"{PREFIX}/furry/macrovision/media/" + target_file + "/" + sys.argv[1] + "/", exist_ok=True)
  34. POTRACE = config["potrace"]
  35. INKSCAPE = config["inkscape"]
  36. METERS_PER_UNIT = 0.03048 * 0.97681253/ 1.9898
  37. if sys.argv[1] == "Tanks":
  38. METERS_PER_UNIT /= 1.50811320755
  39. for path in glob.glob("*.json"):
  40. base_name = os.path.splitext(os.path.basename(path))[0]
  41. data = json.load(open(path, "r", encoding="utf-8"))
  42. sizes = {}
  43. for view, scale in data.items():
  44. name = base_name + "-" + view
  45. result = f"{PREFIX}/furry/macrovision/media/vehicles/" + sys.argv[1] + "/" + name + ".svg"
  46. if view == "Top":
  47. height = int(subprocess.check_output(["convert", name + ".png", "-trim", "-rotate", "270", "-format", "%[h]", "info:"], shell=True).decode("utf-8"))
  48. else:
  49. height = int(subprocess.check_output(["convert", name + ".png", "-trim", "-format", "%[h]", "info:"], shell=True).decode("utf-8"))
  50. sizes[view] = height / scale * METERS_PER_UNIT
  51. if os.path.exists(result) and os.path.getmtime(name + ".png") < os.path.getmtime(result):
  52. print("Skipping " + name)
  53. continue
  54. input_base = "base.bmp"
  55. input_highlight = "highlight.bmp"
  56. subprocess.run(["convert", name + ".png", "xc:#000000", "-channel", "RGB", "-clut", "-background", "#ffffff", "-flatten", input_base], shell=True)
  57. subprocess.run(["convert", name + ".png", "-background", "#ffffff", "-flatten", input_highlight], shell=True)
  58. # rotate the top view, since I capture it horizontally
  59. if view == "Top":
  60. subprocess.run(["mogrify", "-rotate", "270", input_base], shell=True)
  61. subprocess.run(["mogrify", "-rotate", "270", input_highlight], shell=True)
  62. base = "base.svg"
  63. subprocess.run([POTRACE, input_base, "-b", "svg", "-o", base], shell=True)
  64. highlight = "highlight.svg"
  65. subprocess.run([POTRACE, input_highlight, "-b", "svg", "-C", "#1a1a1a", "-o", highlight], shell=True)
  66. combine(base, highlight, result)
  67. os.unlink(input_base)
  68. os.unlink(input_highlight)
  69. output.append(template.format(base_name, sizes["Side"], sizes["Front"], sizes["Top"]))
  70. with open(f"{PREFIX}/furry/macrovision/presets/vehicles.js", "r", encoding="utf-8") as file:
  71. file_data = file.read()
  72. templated = "[" + ",".join(output) + "\n ];"
  73. file_data = re.sub("const data" + sys.argv[1] + " =.*?];", "const data" + sys.argv[1] + " = " + templated, file_data, flags=re.DOTALL)
  74. with open(f"{PREFIX}/furry/macrovision/presets/vehicles.js", "w", encoding="utf-8") as file:
  75. file.write(file_data)