commenting STL converter
This commit is contained in:
parent
44777756a5
commit
e64e5cac69
|
@ -1,7 +1,9 @@
|
|||
class Lexer:
|
||||
def __init__(self,Data):
|
||||
# remove first line...
|
||||
Data = Data.split("\n",1)[1]
|
||||
self.data = Data.split()
|
||||
# ... and last line
|
||||
self.data = self.data[0:len(self.data)-2]
|
||||
|
||||
def lex(self,indice):
|
||||
|
@ -14,15 +16,20 @@ class Parser:
|
|||
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
|
||||
triangle=0
|
||||
# for all the triangles
|
||||
for i in range(0,len(Data),21):
|
||||
# parsing X
|
||||
for j in range(0,3):
|
||||
list_triangles[a][0][j] = float(self.lexer.lex(i+8+j))
|
||||
list_triangles[triangle][0][j] = float(self.lexer.lex(i+8+j))
|
||||
# parsing Y
|
||||
for j in range(0,3):
|
||||
list_triangles[a][1][j] = float(self.lexer.lex(i+12+j))
|
||||
list_triangles[triangle][1][j] = float(self.lexer.lex(i+12+j))
|
||||
# parsing Z
|
||||
for j in range(0,3):
|
||||
list_triangles[a][2][j] = float(self.lexer.lex(i+16+j))
|
||||
a+=1
|
||||
list_triangles[triangle][2][j] = float(self.lexer.lex(i+16+j))
|
||||
|
||||
triangle+=1
|
||||
return list_triangles
|
||||
|
||||
|
||||
|
@ -31,9 +38,7 @@ with open("cube.stl") as file:
|
|||
lexer = Lexer(data)
|
||||
Data = lexer.getData()
|
||||
parser = Parser(lexer)
|
||||
import pprint
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
pp.pprint(parser.parse(Data))
|
||||
print(parser.parse(Data))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue