Python T3D Exporter Module

Discussions about Coding and Scripting
Post Reply
User avatar
Gustavo6046
Godlike
Posts: 1462
Joined: Mon Jun 01, 2015 7:08 pm
Personal rank: Resident Wallaby
Location: Porto Alegre, Brazil
Contact:

Python T3D Exporter Module

Post by Gustavo6046 »

This module is an importable module which eases when handcrafting T3D brushes. Normally though it is easier to import it and use it currently in a 3D modeller. ^^
It is loaded with it's own bugs, including breaking ones. :confused2: Well I want feedback and help in it... so :noidea

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()
"Everyone is an idea man. Everybody thinks they have a revolutionary new game concept that no one else has ever thought of. Having cool ideas will rarely get you anywhere in the games industry. You have to be able to implement your ideas or provide some useful skill. Never join a project whose idea man or leader has no obvious development skills. Never join a project that only has a web designer. You have your own ideas. Focus on them carefully and in small chunks and you will be able to develop cool projects."

Weapon of Destruction
Post Reply