@@ -32,6 +32,7 @@ def stl_to_triangles(fileinfo): # specify file
32
32
fd = open (fileinfo , mode = 'rb' )
33
33
text = fd .read ()
34
34
tris = [] # list of triangles to compound
35
+ keywords = [b'outer' , b'endloop' , b'endfacet' , b'solid' , b'endsolid' ]
35
36
if False : # prevent executing code for binary file
36
37
pass
37
38
# The following code for binary files must be updated:
@@ -60,16 +61,18 @@ def stl_to_triangles(fileinfo): # specify file
60
61
else :
61
62
fd .seek (0 )
62
63
fList = fd .readlines ()
64
+ print ('Number of lines =' , len (fList ))
63
65
64
66
# Decompose list into vertex positions and normals
65
67
ret = [] # will return a list of compounds if necessary
66
68
vs = []
67
69
vertices = 0
68
70
for line in fList :
69
71
FileLine = line .split ( )
70
- if FileLine [0 ] == b'facet' :
72
+ first = FileLine [0 ]
73
+ if first == b'facet' :
71
74
N = vec (float (FileLine [2 ]), float (FileLine [3 ]), float (FileLine [4 ]))
72
- elif FileLine [ 0 ] == b'vertex' :
75
+ elif first == b'vertex' :
73
76
vertices += 1
74
77
vs .append ( vertex (pos = vec (float (FileLine [1 ]), float (FileLine [2 ]), float (FileLine [3 ])), normal = N , color = color .white ) )
75
78
if len (vs ) == 3 :
@@ -80,16 +83,20 @@ def stl_to_triangles(fileinfo): # specify file
80
83
ret .append (compound (tris ))
81
84
tris = []
82
85
vertices = 0
86
+ elif first in keywords :
87
+ pass
88
+ else :
89
+ print (line ) # for debugging
83
90
if len (tris ) > 0 : ret .append (compound (tris ))
84
91
if len (ret ) == 1 : return ret [0 ]
85
92
else : return ret
86
93
87
94
if __name__ == '__main__' :
88
- man = stl_to_triangles ('z-as.stl' )
95
+ man = stl_to_triangles ('STLbot.stl' )
96
+ man .pos = vec (- 200 ,0 ,0 )
97
+ man .color = color .cyan
98
+ part = stl_to_triangles ('Part1.stl' )
99
+ part .size *= 200
100
+ part .pos = vec (250 ,0 ,0 )
101
+ part .color = color .orange
89
102
print ('Done' )
90
- # man.pos = vec(-200,0,0)
91
- # man.color = color.cyan
92
- # part = stl_to_triangles('Part1.stl')
93
- # part.size *= 200
94
- # part.pos = vec(250,0,0)
95
- # part.color = color.orange
0 commit comments