STL格式文件投影显示图

stl为numpy_stl库,不要下错了

from mpl_toolkits.mplot3d import Axes3D, art3d
from matplotlib import pyplot
from stl import mesh

angledict = {'FRONT': [0, 0], 'LEFT': [0, -90], 'TOP': [90, 0], 'REAR': [0, 180], 'RIGHT': [0, 90], 'BOTTOM': [-90, 0],
             'SOUTHWEST': [45, 45]}


def stltoviews(filename, viewmode):
    # 创建一个plot
    fig = pyplot.figure()
    axes = fig.add_axes(Axes3D(fig))
    # 加载stl文件,把读取到的向量信息加载到plot
    stl_mesh = mesh.Mesh.from_file(filename)
    poly = art3d.Poly3DCollection(stl_mesh.vectors, color='lightgrey')
    # poly.set_facecolor('b')
    poly.set_edgecolor('b')
    poly.set_alpha(0.9)
    axes.add_collection3d(poly)
    # 自动缩放网格尺寸
    scale = stl_mesh.points.flatten()
    axes.auto_scale_xyz(scale, scale, scale)
    # 是否显示坐标轴
    pyplot.axis('on')
    # 调整模型的角度
    axes.view_init(elev=angledict[viewmode][0], azim=angledict[viewmode][1])
    # 保存到本地文件
    pyplot.show()
    # pyplot.savefig('model.png')


# 本地文件
name = 'model.stl'
mode = 'TOP'
stltoviews(name, mode)

程序无渲染,仅提取缩略图使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值