]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/outfile.py
Use image path as texture identifier if available
[libs/gl.git] / blender / io_mspgl / outfile.py
1 import sys
2
3 class OutFile:
4         def __init__(self, fn):
5                 self.filename = fn
6                 if fn==None:
7                         self.file = sys.stdout
8                 else:
9                         self.file = open(fn, "w")
10                 self.indent = 0
11
12         def make(self, kwd, *params):
13                 pstr = ""
14                 for p in params:
15                         if type(p)==float:
16                                 pstr += " %#.6g"%p
17                         else:
18                                 pstr += " %s"%p
19                 return "%s%s"%(kwd, pstr)
20
21         def write(self, kwd, *params):
22                 self.file.write("%s%s;\n"%('\t'*self.indent, self.make(kwd, *params)))
23
24         def begin(self, kwd, *params):
25                 i = '\t'*self.indent
26                 self.file.write("%s%s\n%s{\n"%(i, self.make(kwd, *params), i))
27                 self.indent += 1
28
29         def end(self):
30                 self.indent -= 1
31                 self.file.write("%s};\n"%('\t'*self.indent))
32
33
34 def open_output(f):
35         if isinstance(f, OutFile):
36                 return f
37         return OutFile(f)