basic Potter's STLAscii converter for Windmill
This commit is contained in:
parent
32c489c957
commit
44777756a5
|
@ -0,0 +1,40 @@
|
|||
class Lexer:
|
||||
def __init__(self,Data):
|
||||
Data = Data.split("\n",1)[1]
|
||||
self.data = Data.split()
|
||||
self.data = self.data[0:len(self.data)-2]
|
||||
|
||||
def lex(self,indice):
|
||||
return self.data[indice]
|
||||
def getData(self):
|
||||
return self.data
|
||||
|
||||
class Parser:
|
||||
def __init__(self,Lexer):
|
||||
self.lexer = Lexer
|
||||
def parse(self,Data):
|
||||
list_triangles = [[[0,0,0],[0,0,0],[0,0,0]] for i in range(int(len(Data)/21))]
|
||||
a=0
|
||||
for i in range(0,len(Data),21):
|
||||
for j in range(0,3):
|
||||
list_triangles[a][0][j] = float(self.lexer.lex(i+8+j))
|
||||
for j in range(0,3):
|
||||
list_triangles[a][1][j] = float(self.lexer.lex(i+12+j))
|
||||
for j in range(0,3):
|
||||
list_triangles[a][2][j] = float(self.lexer.lex(i+16+j))
|
||||
a+=1
|
||||
return list_triangles
|
||||
|
||||
|
||||
with open("cube.stl") as file:
|
||||
data = file.read()
|
||||
lexer = Lexer(data)
|
||||
Data = lexer.getData()
|
||||
parser = Parser(lexer)
|
||||
import pprint
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
pp.pprint(parser.parse(Data))
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue