It is loaded with it's own bugs, including breaking ones. Well I want feedback and help in it... so
Code: Select all
#-------------------------------------------------------------------------------
# Name: Gustavo's Console Brush Maker
# Purpose: Making terrain generation for UT99 easy and quick.
#
# Author: Gustavo Ramos "Gustavo6046" Rehermann
#
# Created: 21/01/2016
# Copyright: (c)Gustavo6046 2016
# Licence: CC-BY.
#-------------------------------------------------------------------------------
import sys
vertexes = []
polys = []
class Polygon:
"""One polygon.
Used for each polygon at .t3d exporting
mechanism that exports the brush terrain."""
x = []
t3d_str = ""
def __init__(self, *VertexList):
t3d_str = "Begin Polygon\n"
for x in VertexList:
self.x = x
t3d_str += "Vertex " + self.x[0] + ". " + self.x[1] + ", " + self.x[2] + "\n"
t3d_str = "End Polygon\n"
def getrep():
return t3d_str
def ExportT3D(filename):
"""Exports a .t3d file based on global variables.
Normally it takes the vertex and poly lists to export.
Return codes:
(0) Succesful.
(1) One of the items isn't a poly.
(2) Polys isn't a list.
(3) IOError during file opening.
(4) IOError during file writing."""
global polys
try:
outputx = open(filename, "w")
except IOError:
outputx.close()
return 3
if type(polys) != list:
outputx.close()
return 2
for x in polys:
if type(x) != Polygon:
outputx.close()
return 1 #returns 1 if one of the items aren't a polygon.
try:
outputx.write("Begin Map\nBegin Actor Class=Brush Name=Brush0\nLocation=(X=0.000000,Y=0.000000,Z=0.000000)\nBegin Brush Name=Brush\nBegin PolyList\n")
except IOError:
outputx.close()
return 4
for x in polys:
try:
outputx.write(x.getrep())
except IOError:
outputx.close()
return 4
try:
outputx.write("End PolyList\nEnd Brush\nEnd Actor")
except IOError:
outputx.close()
return 4
outputx.close()
return 0
def updateVertexList(vertexes):
tempv = []
print "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
for x in range(len(vertexes)):
tempv.append(vertexes[x])
if x % 3 == 0:
print "Vertex " + str((x + 1) / 3) + " xyz: " + str(tempv) + "\n"
tempv = []
def main():
global vertexes
global polys
while True:
updateVertexList(vertexes)
print "Command list: \"addvertex <x> <y> <z>\", \"linkvertexes <vertex1index> <vertex2index> <vertex3index> [vertex$index] ... [vertexNindex]\", \"export <filename>\"\n"
try:
command = raw_input("Enter command: ")
except KeyboardInterrupt:
sys.exit()
commandargs = command.split(" ")
if commandargs[0] == "addvertex":
vertexes.append(float(commandargs[1]))
vertexes.append(float(commandargs[2]))
vertexes.append(float(commandargs[3]))
elif commandargs[0] == "linkvertexes":
tempvertexes = []
for x in range(len(vertexes) / 3):
for y in commandargs:
try:
if x == int(y):
tvl = []
tvl.append(vertexes[x * 3 - 2])
tvl.append(vertexes[x * 3 - 1])
tvl.append(vertexes[x * 3])
tempvertexes.append(tvl)
break
except ValueError:
continue
temppoly = Polygon(tempvertexes)
polys.append()
elif commandargs[0] == "export":
ExportT3D(commandargs[1])
else:
print "Wrong command!\n"
if __name__ == '__main__':
main()