numpy-stl
does what you want:
import stl
from stl import mesh
your_mesh = mesh.Mesh.from_file('INPUT.stl')
your_mesh.save('OUTPUT.stl',mode=stl.Mode.ASCII)
However if you want it to do by binary conversion, use this program I wrote in Python3 using this reference.
import struct
def ffb(x):
return str(round(struct.unpack('f',x)[0],6))
f=open('3dtest.stl','rb')
print(f.read(84))
temp=''
for j in range(4):
temp='facet normal: '
for i in range(3):
temp=temp+ffb(f.read(4))+' '
print (temp)
for n in range(3):
temp='vertex: '
for i in range(3):
temp=temp+ffb(f.read(4))+' '
print (temp)
attr=f.read(2)
print('###################################')
f.close()
temp=temp[:-1]
print(temp)
Result:
b'MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH\n\x0c\x00\x00\x00'
facet normal: 0.0 1.0 0.0
vertex: 12.671906 11.296659 0.0
vertex: -11.984282 11.296659 0.0
vertex: -11.984282 11.296659 10.0
###################################
facet normal: 0.0 1.0 -0.0
vertex: 12.671906 11.296659 0.0
vertex: -11.984282 11.296659 10.0
vertex: 12.671906 11.296659 10.0
###################################
facet normal: 1.0 0.0 0.0
vertex: 12.671906 -10.8055 0.0
vertex: 12.671906 11.296659 0.0
vertex: 12.671906 11.296659 10.0
###################################
facet normal: 1.0 0.0 0.0
vertex: 12.671906 -10.8055 0.0
vertex: 12.671906 11.296659 10.0
vertex: 12.671906 -10.8055 10.0
###################################
Same binary STL converted to text via numpy-stl
:
solid MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH-MESH
facet normal 0,000000 246,561890 0,000000
outer loop3
vertex 12,671906 11,296659 0,000000
vertex -11,984282 11,296659 0,000000
vertex -11,984282 11,296659 10,000000
endloop
endfacet
facet normal 0,000000 246,561890 -0,000000
outer loop
vertex 12,671906 11,296659 0,000000
vertex -11,984282 11,296659 10,000000
vertex 12,671906 11,296659 10,000000
endloop
endfacet
facet normal 221,021591 0,000000 0,000000
outer loop
vertex 12,671906 -10,805500 0,000000
vertex 12,671906 11,296659 0,000000
vertex 12,671906 11,296659 10,000000
endloop
endfacet
facet normal 221,021591 0,000000 0,000000
outer loop
vertex 12,671906 -10,805500 0,000000
vertex 12,671906 11,296659 10,000000
vertex 12,671906 -10,805500 10,000000
endloop
endfacet
numpy-stl
code:
import stl
from stl import mesh
your_mesh = mesh.Mesh.from_file('INPUT.stl')
your_mesh.save('OUTPUT.stl',mode=stl.Mode.ASCII)
I advise you to put 3d plotting on a loop via any language or renderer. Forward errors to /dev/null
and edit the file seeing what happens in realtime. I think that would be the best possible study. Of course while checking out sample output of the various geometry in another window.