mirror of
https://github.com/Tribes2-SCP/AssetCompat.git
synced 2026-01-19 20:24:53 +00:00
Fixed up the genmatlist script overall; genmatlist preserves directory & filename casing so the output should be compatible with case-sensitive file systems
This commit is contained in:
parent
3af016405d
commit
05181fadd7
|
|
@ -1,16 +1,66 @@
|
|||
import os
|
||||
import io
|
||||
import sys
|
||||
f = open ('../t3mats.txt','r')
|
||||
tf = open('materials.cs','w')
|
||||
for name in f:
|
||||
tf.write('singleton Material( "'+name.split('compat\\base\\textures\\')[-1].upper().replace('.png','').replace('.PNG','').rstrip("\n\r").split('\\')[-1]+'" )\n')
|
||||
tf.write('{\n')
|
||||
tf.write('diffuseMap[0] = "'+name.split('compat\\base\\textures\\')[-1].replace("\\","/").replace('.png','').replace('.PNG','').rstrip("\n\r")+'";\n')
|
||||
tf.write('mapTo = "'+name.split('compat\\base\\textures\\')[-1].upper().replace('.png','').replace('.PNG','').rstrip("\n\r").split('\\')[-1]+'";\n')
|
||||
tf.write('\n')
|
||||
tf.write('};\n')
|
||||
tf.close()
|
||||
|
||||
class Application(object):
|
||||
ignored_directories = ["textures", "commander", "gui", "details", "special"]
|
||||
|
||||
material_template = """
|
||||
singleton Material({name})
|
||||
{opening}
|
||||
diffuseMap[0] = "{path}";
|
||||
mapTo = "{name}";
|
||||
{closing};
|
||||
"""
|
||||
|
||||
def main(self):
|
||||
if (len(sys.argv) != 3):
|
||||
print("Usage: %s <material dir> <output material script>" % sys.argv[0])
|
||||
print("material dir is the root of the directory in which the Tribes 2 materials can be found.")
|
||||
print("output material script is the output script for Torque3D that allows proper material usage.")
|
||||
return
|
||||
|
||||
material_directory = sys.argv[1]
|
||||
output_location = sys.argv[2]
|
||||
|
||||
os.chdir(sys.argv[1])
|
||||
|
||||
# In this list we store dictionaries that store a name and a path
|
||||
materials = [ ]
|
||||
|
||||
# First, we generate a listing of the T2 matlist
|
||||
for path, directories, files in os.walk(".", topdown=True):
|
||||
# Don't recurse textures
|
||||
if (path == "."):
|
||||
for exclusion in self.ignored_directories:
|
||||
try:
|
||||
directories.remove("exclusion")
|
||||
except ValueError: pass
|
||||
|
||||
for file in files:
|
||||
if (os.path.isfile(file) is not True):
|
||||
continue
|
||||
|
||||
full_path = os.path.join(path, file)[2:]
|
||||
|
||||
material_name = os.path.basename(full_path)
|
||||
material_name = os.path.splitext(material_name)[0].upper()
|
||||
|
||||
material = { "name": material_name, "path": full_path, "opening": "{", "closing": "}" }
|
||||
materials.append(material)
|
||||
|
||||
# Now dump the output and we should be golden.
|
||||
try:
|
||||
with open(output_location, "w") as output_handle:
|
||||
for material in materials:
|
||||
output_handle.write(self.material_template.format(**material))
|
||||
|
||||
print("Wrote output to %s." % output_location)
|
||||
except OSError as e:
|
||||
print("FATAL: Failed to open %s for read or %s for write!" % (input_location, output_location))
|
||||
|
||||
if __name__ == "__main__":
|
||||
Application().main()
|
||||
|
||||
#singleton Material( BlankWhite )
|
||||
#{
|
||||
# diffuseMap[0] = "core/art/white";
|
||||
|
|
|
|||
Loading…
Reference in a new issue