|
![](/i/fill.gif) |
I think I got it, maybe it can be usefull for someone:
------
# Convert expression to pov
angle = '20'
macros = {'F': ' ramo translate -x ',
'X': ' ramo translate -x ',
'-': ' rotate -z*' + angle + ' ',
'+': ' rotate z*' + angle + ' '}
def getsubstr(p):
count = 1;
pos = 0;
while count > 0:
if p[pos] == '[': count += 1
if p[pos] == ']': count -= 1
pos += 1;
return p[:pos]
def applymacro(p):
return macros.has_key(p) and macros[p] or ''
def trans(result):
p = result[0]
t = result[1:]
if p == '[':
sub = getsubstr(t)
newt = t[len(sub)+1:]
return "union { object {" + trans(sub) + "} object {" + trans(newt) + "} }"
if len(result) > 1:
r = trans(t)
if len(r) > 0:
return "union { object {" + r + "} " + applymacro(p) + "}"
return applymacro(p)
print trans(result)
------
Post a reply to this message
|
![](/i/fill.gif) |