导入、导出、处理、分析和查看三角形网格。
trimesh的Python项目详细描述
>>>>>>>>>>>>>>>>
trimesh是一个纯python(2.7-3.4+)库,用于加载和使用三角形网格。该库的目标是提供一个功能齐全且经过良好测试的trimesh对象,该对象允许以shapely库中的多边形对象的样式进行简单的操作和分析。
api基本上是稳定的,但这不应该依赖,也不能保证:如果计划使用trimesh部署某些内容,请安装特定版本。
我们很感激您的请求并及时回复!如果您愿意参与,这里有一个最新的潜在增强功能列表,但也欢迎不在该列表中的内容。下面是用python编写网格代码的一些技巧。
基本安装
保持trimesh易于安装是一个核心目标,因此只有硬依赖才是numpy。安装其他软件包会增加功能,但不是必需的。对于只使用numpy的最简单安装,pip
通常可以在windows、linux和osx上干净地安装trimesh
pip install trimesh
对于更多功能,如凸面外壳(scipy
)、图形操作(networkx
)、更快的光线查询(pyembree
)、矢量路径处理(shapely
和rtree
)、预览窗口(pyglet
)、更快的缓存检查(xxhash
)更重要的是,获得完整的rimesh安装是一个conda环境:
# this will install all soft dependencies available on your current platform
conda install -c conda-forge trimesh
安装trimesh 有关更多信息,请参阅高级安装文档 下面是从文件加载网格并为其面着色的示例。这是一个格式很好的
本例的ipython笔记本版本。另外,还可以查看截面示例或网格示例上函数的集成 trimesh包括一个可选的基于pyglet的查看器,用于调试和思辨。在用 如果从 您可以查看github network中使用trimesh的内容。精选几个: 快速推荐: 如果您想要按索引面、实例、颜色、纹理等,那么 在一般情况下, wavefront 一个经常出现的问题是如何引用库。一个快速的bibtex建议: 如果你想在一个使用trimesh的容器中部署一些东西,docker hub上提供了基于trimesh和依赖项的自动构建
pip install trimesh[easy]
快速启动
importnumpyasnpimporttrimesh# attach to logger so trimesh messages will be printed to consoletrimesh.util.attach_to_log()# mesh objects can be created from existing faces and vertex datamesh=trimesh.Trimesh(vertices=[[0,0,0],[0,0,1],[0,1,0]],faces=[[0,1,2]])# by default, Trimesh will do a light processing, which will# remove any NaN values and merge vertices that share position# if you want to not do this on load, you can pass `process=False`mesh=trimesh.Trimesh(vertices=[[0,0,0],[0,0,1],[0,1,0]],faces=[[0,1,2]],process=False)# mesh objects can be loaded from a file name or from a buffer# you can pass any of the kwargs for the `Trimesh` constructor# to `trimesh.load`, including `process=False` if you would like# to preserve the original loaded data without merging vertices# STL files will be a soup of disconnected triangles without# merging vertices however and will not register as watertightmesh=trimesh.load('../models/featuretype.STL')# is the current mesh watertight?mesh.is_watertight# what's the euler number for the mesh?mesh.euler_number# the convex hull is another Trimesh object that is available as a property# lets compare the volume of our mesh with the volume of its convex hullprint(mesh.volume/mesh.convex_hull.volume)# since the mesh is watertight, it means there is a# volumetric center of mass which we can set as the origin for our meshmesh.vertices-=mesh.center_mass# what's the moment of inertia for the mesh?mesh.moment_inertia# if there are multiple bodies in the mesh we can split the mesh by# connected components of face adjacency# since this example mesh is a single watertight body we get a list of one meshmesh.split()# facets are groups of coplanar adjacent faces# set each facet to a random color# colors are 8 bit RGBA by default (n, 4) np.uint8forfacetinmesh.facets:mesh.visual.face_colors[facet]=trimesh.visual.random_color()# preview mesh in an opengl window if you installed pyglet with pipmesh.show()# transform method can be passed a (4, 4) matrix and will cleanly apply the transformmesh.apply_transform(trimesh.transformations.random_rotation_matrix())# axis aligned bounding box is availablemesh.bounding_box.extents# a minimum volume oriented bounding box also available# primitives are subclasses of Trimesh objects which automatically generate# faces and vertices from data stored in the 'primitive' attributemesh.bounding_box_oriented.primitive.extentsmesh.bounding_box_oriented.primitive.transform# show the mesh appended with its oriented bounding box# the bounding box is a trimesh.primitives.Box object, which subclasses# Trimesh and lazily evaluates to fill in vertices and faces when requested# (press w in viewer to see triangles)(mesh+mesh.bounding_box_oriented).show()# bounding spheres and bounding cylinders of meshes are also# available, and will be the minimum volume version of each# except in certain degenerate cases, where they will be no worse# than a least squares fit version of the primitive.print(mesh.bounding_box_oriented.volume,mesh.bounding_cylinder.volume,mesh.bounding_sphere.volume)
功能
查看器
mesh.show()
打开的"网格视图"窗口中,可以使用以下命令:鼠标单击+拖动
旋转视图ctl+鼠标单击+拖动
平移视图鼠标滚轮
缩放z
返回基本视图
w
切换线框模式
c
切换背面消隐
f
在全屏和窗口模式之间切换
m
最大化窗口q
关闭窗口
a
在三种状态之间切换XYZ-RGB轴标记:关、在世界帧或在每一帧jupyter
笔记本中调用,mesh.show()
显示使用three.js
显示网格或场景的联机预览。为了获得更完整的渲染(PBR、更好的照明、着色器、更好的屏幕外支持等)pyrender被设计为与trimesh
对象交互操作。使用trimesh的项目
我应该使用哪种网格格式?
glb
或stl
。每次你用glb替换obj时,一个天使就会长出翅膀。glb
是一个非常好的选择。gltf/glb是一种指定得非常好的现代格式,易于快速解析:它有一个json头,描述二进制blob中的数据。它有一个简单的分层场景图,一个非常漂亮的基于物理的现代材料系统,支持几十到几百个库和一个库。r-efficient-transmission-of-3d-scenes-models" rel="nofollow">John Carmack endorsmentstl
可能是最常见的格式。stl
文件非常简单:它基本上只是一个三角形列表。它们非常坚固,是基本几何的最佳选择。obj
也很常见:不幸的是obj没有一个被广泛接受的规范,因此每个进口商和出口商实现的东西都略有不同,这使得它很难支持。它还允许一些不幸的事情,比如任意大小的多边形,有一个容易弄乱的面部表示,为材质和纹理引用其他文件,任意交错数据,并且解析速度慢。把glb
或ply
作为一种替代方法试试!我怎么能引用这个图书馆?
@software{trimesh,
author = {{Dawson-Haggerty et al.}},
title = {trimesh},
url = {https://trimsh.org/},
version = {3.2.0},
date = {2019-12-8},
}
容器
Docker拉Mikedh/Trimesh
推荐PyPI第三方库