我想加载一个STL文件,并生成一组不同旋转的2D图像。
我根据this示例了解了使用numpy-stl的基础知识,最后以以下代码结束:
from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot
filename = '3001.stl'
# Create a new plot
figure = pyplot.figure()
axes = figure.gca(projection='3d')
# Load the STL files and add the vectors to the plot
mesh = mesh.Mesh.from_file(filename)
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(mesh.vectors, color='lightgrey'))
#axes.plot_surface(mesh.x,mesh.y,mesh.z)
# Auto scale to the mesh size
scale = mesh.points.flatten()
axes.auto_scale_xyz(scale, scale, scale)
#turn off grid and axis from display
pyplot.axis('off')
#set viewing angle
axes.view_init(azim=120)
# Show the plot to the screen
pyplot.show()
这很好用,只是我最终得到了一个组件的轮廓,缺乏很多细节。下面的图片是一块乐高积木。
我试着突出显示边缘。但这对模型是如何创建的很敏感,这对我来说不是很好。
我希望通过添加照明,阴影可以帮助添加缺失的细节,但我找不到这样做的方法。
你知道如何在下面的代码中添加光源来创建阴影吗?
发布于 2019-08-15 04:18:48
在厌倦了Mayavi的安装灾难后,我最终为此编写了自己的库。https://github.com/bwoodsend/vtkplotlib
你的代码应该是这样的
import vtkplotlib as vpl
from stl.mesh import Mesh
path = "your path here.stl"
# Read the STL using numpy-stl
mesh = Mesh.from_file(path)
# Plot the mesh
vpl.mesh_plot(mesh)
# Show the figure
vpl.show()
如果您希望砖块是蓝色的,可以将mesh_plot替换为
vpl.mesh_plot(mesh, color="blue")
发布于 2019-06-19 04:03:39
如果你不觉得Mayavi有用,你可以试试Panda3D,它是为图形/3D渲染应用而设计的。我发现做这样简单的事情非常简单。
https://stackoverflow.com/questions/51508506
复制相似问题