Python绑定为AdMeET、STL映射库
admesh的Python项目详细描述
此模块为ADMesh库提供绑定。它允许您以二进制或ascii stl格式操作三维模型,并在必要时部分修复它们。
安装
有适用于Linux和MacOS X的控制盘。您只需执行以下操作:
pip install admesh
如果你有一个不受上述支持的平台, 您需要安装cADMesh库。
此版本是为admesh 0.98.x设计的。请按照其中的说明进行操作。然后您可以像往常一样用one安装它,如下所示:
./setup.py install python3 setup.py install # for Python 3 pip install admesh # install directly from PyPI
如果admesh库位于非标准位置,则必须告诉编译器和链接器查找位置:
LDFLAGS='-L/path/to/library'CFLAGS='-I/path/to/header' ./setup.py install
用法
使用提供的Stl类。
importadmesh# load an STL filestl=admesh.Stl('file.stl')# observe the available methodshelp(stl)# read the statsstl.stats# see how many facets are therelen(stl)# walk the facetsforfacetinstl:# get the normalfacet['normal']# walk the verticesforvertexinfacet['vertex']:# read the coordinatesvertex['x']vertex['y']vertex['z']# add another set of facets# every facet is a tuple (vertices, normal) or a dictstl.add_facets([(((0,0,0),(0,1,0),(0,0,1)),(1,0,0)),{'vertex':[{'x':0,'y':0,'z':0},{'x':1,'y':0,'z':0},{'x':0,'y':0,'z':1}],'normal':{'x':0,'y':1,'z':0}},])
请注意,所有c admesh函数都以stl_前缀开头,而此模块的python方法不以前缀开头。还要注意,并不是所有的c admesh函数都提供了,因为有些函数需要更复杂的方法,因此不值得考虑。如果缺少某些函数,请创建new issue。