JavaProp2JSBCpCt now sorts the input files correctly if they contain negative numbers, added day-night texture animation XML creator (see https://forum.flightgear.org/viewtopic.php?f=5&t=40589)

This commit is contained in:
TheFGFSEagle 2022-07-13 00:19:50 +02:00
parent 34bea99108
commit a46d179f0c
2 changed files with 149 additions and 8 deletions

View File

@ -3,6 +3,7 @@
import argparse import argparse
import os import os
import natsort
from fgtools.utils.interpolator import Interpolator from fgtools.utils.interpolator import Interpolator
@ -93,18 +94,27 @@ if __name__ == "__main__":
args = argp.parse_args() args = argp.parse_args()
paths = []
for path in args.input_files: for path in args.input_files:
if not os.path.isfile(path): if not os.path.exists(path):
print(f"Error: input file {path} not found, exiting") print(f"Error: input file / directory {path} not found, exiting")
sys.exit(1) sys.exit(1)
if len(args.blade_angles) < len(args.input_files): if os.path.isfile(path):
paths.append(path)
else:
for file in natsort.realsorted(os.listdir(path)):
paths.append(os.path.join(path, file))
if len(args.blade_angles) < len(paths):
print("Error: less blade angles than input files") print("Error: less blade angles than input files")
elif len(args.blade_angles) > len(args.input_files): elif len(args.blade_angles) > len(paths):
args.blade_angles, rest = args.blade_angles[:len(args.input_files) + 1] args.blade_angles, rest = args.blade_angles[:len(paths) + 1]
print(f"Warning: skipping {len(rest)} blade angles because no corresponding data file was specified") print(f"Warning: skipping {len(rest)} blade angles because no corresponding data file was specified")
data = parse_data_files(args.input_files, args.blade_angles) print(paths)
data = parse_data_files(paths, args.blade_angles)
output = make_tables(data, args.max, args.indentation, args.resolution) output = make_tables(data, args.max, args.indentation, args.resolution)

131
scenery/create-day-night-xml.py Executable file
View File

@ -0,0 +1,131 @@
#!/usr/bin/env python
import os, sys, argparse
def get_texture_paths(folder="."):
texture_paths = {}
for name in os.listdir(folder):
path = os.path.relpath(os.path.join(folder, name), start=folder)
if name.endswith(".ac"):
with open(path, "r") as f:
if not path in texture_paths:
texture_paths[path] = {}
object = ""
for line in f:
if line.strip().startswith("name"):
object = line.split('"')[1]
if object == "world":
object = ""
continue
if line.strip().startswith("texture") and object:
texture_path = line.split('"')[1]
if not texture_path in texture_paths[path]:
texture_paths[path][texture_path] = []
texture_paths[path][texture_path].append(object)
if not texture_paths[path]:
print(path, "contains no texture, skipping")
if not texture_paths:
print(os.path.abspath(folder), "does not contain any AC files - exiting")
sys.exit(1)
return texture_paths
def write_xml_files(texture_paths, lit_suffix, overwrite):
for ac_path in texture_paths:
xml_path = ac_path.replace(".ac", ".xml")
if os.path.isfile(xml_path) and not overwrite:
print("XML file", xml_path, "already exists - skipping")
continue
with open(xml_path, "w") as xml_f:
xml_f.write("""<?xml version="1.0" encoding="utf-8"?>
<PropertyList>
<path>%s</path>""" % ac_path)
for texture_path in texture_paths[ac_path]:
texture_lit_path = texture_path.split(".")
texture_lit_path[-2] += lit_suffix
texture_lit_path = ".".join(texture_lit_path)
if not os.path.isfile(texture_lit_path):
print("Night texture", texture_lit_path, "does not exist - skipping objects")
break
xml_f.write("""
<animation>
<condition>
<greater-than>
<property>/sim/time/sun-angle-rad</property>
<value>1.49</value>
</greater-than>
</condition>
<type>material</type>""")
for object in texture_paths[ac_path][texture_path]:
xml_f.write(" <object-name>%s</object-name>" % object)
xml_f.write(""" <emission>
<red>1</red>
<green>1</green>
<blue>1</blue>
</emission>
<texture>%s</texture>
</animation>""" % texture_lit_path)
xml_f.write("""
<animation>
<type>material</type>
<condition>
<less-than-equals>
<property>/sim/time/sun-angle-rad</property>
<value>1.49</value>
</less-than-equals>
</condition>""")
for object in texture_paths[ac_path][texture_path]:
xml_f.write(" <object-name>%s</object-name>" % object)
xml_f.write(""" <emission>
<red>0</red>
<green>0</green>
<blue>0</blue>
</emission>
<texture>%s</texture>""" % texture_path)
xml_f.write("</animation>")
xml_f.write("</PropertyList>\n")
def main():
argp = argparse.ArgumentParser()
argp.add_argument("-o", "--overwrite",
help="Whether to overwrite XML files if any already exist, defaults to not overwriting",
action="store_true"
)
argp.add_argument("-s", "--lit-suffix",
help="What suffix the lit texture has (of the name itself, not the file extension), default is _LIT",
default="_LIT"
)
argp.add_argument("folder",
help="Folder / directory where the AC files and textures are in, default is working directory",
default="."
)
args = argp.parse_args()
if not os.path.isdir(args.folder):
print("Folder", args.folder, "does not exist - exiting")
sys.exit(1)
texture_paths = get_texture_paths(args.folder)
write_xml_files(texture_paths, args.lit_suffix, args.overwrite)
if __name__ == "__main__":
main()