简体   繁体   English

STL 文件到可读文本文件

[英]STL file to a readable text file

I am now studying 3d models (stl files and etc) and how it is made from scratch.我现在正在研究 3d 模型(stl 文件等)以及它是如何从头开始制作的。 What software do I need to use to see what's inside the stl file like this:我需要使用什么软件来查看 stl 文件中的内容,如下所示:

solid dart
    facet normal 0.00000E+000 0.00000E+000 -1.00000E+000
        outer loop
            vertex 3.10000E+001 4.15500E+001 1.00000E+000
            vertex 3.10000E+001 1.00000E+001 1.00000E+000
            vertex 1.00000E+000 2.50000E-001 1.00000E+000
        endloop
    endfacet
endsolid dart

I have been searching for those kinds of software but so far, no luck.我一直在寻找这些类型的软件,但到目前为止,没有运气。

STL files are available in ASCII format as well as in binary format. STL 文件有 ASCII 格式和二进制格式。 Most STL files are in binary format and can not be opened as text.大多数 STL 文件是二进制格式,不能作为文本打开。 To change the format, a CAD program can be used (change options in "Save as").要更改格式,可以使用 CAD 程序(在“另存为”中更改选项)。

In ASCII format, the representation is as follows:在ASCII格式中,表示如下:

solid dart
    facet normal 0.00000E+000 0.00000E+000 -1.00000E+000
        outer loop
            vertex 3.10000E+001 4.15500E+001 1.00000E+000
            vertex 3.10000E+001 1.00000E+001 1.00000E+000
            vertex 1.00000E+000 2.50000E-001 1.00000E+000
        endloop
    endfacet
endsolid dart

Thus, only the ASCII format allows manual checking of the coordinates of the vertices.因此,只有 ASCII 格式允许手动检查顶点坐标。

MeshLab ( http://www.meshlab.net ) is a widely used open source viewer for 3D models that handles well all the STL variants (and many other 3D files). MeshLab ( http://www.meshlab.net ) 是一种广泛使用的 3D 模型开源查看器,可以很好地处理所有 STL 变体(以及许多其他 3D 文件)。 Available for mac/win/linux适用于 mac/win/linux

There is also an online version that runs in your browser http://www.meshlabjs.net还有一个在线版本可以在您的浏览器中运行http://www.meshlabjs.net

numpy-stl does what you want: numpy-stl 做你想做的事:

from stl import mesh 
your_mesh = mesh.Mesh.from_file('3dtest.stl')
your_mesh.save('3dascii.stl',mod=stl.Mode.ASCII)  

However if you want it to do by binary conversion, simple code I wrote on python3 taking reference: https://www.fabbers.com/tech/STL_Format#Sct_binary但是,如果您希望它通过二进制转换来完成,我在 python3 上编写的简单代码参考: https://www.fabbers.com/tech/STL_Format#Sct_binary

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:相同的二进制 STL 通过 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: numpy-stl 代码:

from stl import mesh 
your_mesh = mesh.Mesh.from_file('3dtest.stl')
your_mesh.save('3dascii.stl',mod=stl.Mode.ASCII)  

I advise you to put 3d plotting on a loop via any lanuage or renderer.我建议您通过任何语言或渲染器将 3d 绘图放在一个循环中。 Forward errors to >/dev/null and edit the file seeing what happens in realtime.将错误转发到 >/dev/null 并编辑文件以查看实时发生的情况。 I think that would be the best possible study.我认为那将是最好的研究。 Ofcourse while checking out sample output stls of various geometry on antoher window.当然,在 window 上检查各种几何形状的样本 output stls 时。

You can use the open-source STL-Viewer software I made.您可以使用我制作的开源 STL-Viewer 软件。 It supports both Binary and ASCII formatted STL files.它支持二进制和 ASCII 格式的 STL 文件。 Here is the link: https://github.com/batu92k/STL-Viewer这是链接: https : //github.com/batu92k/STL-Viewer

Download MeshLab , Import your stl file, Export it as an stl file when you uncheck binary encoding下载MeshLab ,导入您的 stl 文件,当您取消选中二进制编码时将其导出为 stl 文件

OR或者

Download FreeCAD , Import your stl file, Export it as an ast file下载FreeCAD ,导入 stl 文件,将其导出为 ast 文件

Open the exported file with a text editor使用文本编辑器打开导出的文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM