当前位置:   article > 正文

基于numpy-stl将stl文件转换为顶点及面片数组_stl转mesh

stl转mesh

numpy-stl安装

pip install numpy-stl
  • 1

代码示例

import numpy as np
from stl import mesh


def meshFromStl(mesh_file):
	# load stl
	# mesh_file为本地的stl文件,例如"../gripper.stl"
    mesh_stl = mesh.Mesh.from_file(mesh_file)

    mesh_vectors = mesh_stl.vectors
    mesh_points_num = mesh_vectors.shape[0] * mesh_vectors.shape[1]
    mesh_points = mesh_vectors.reshape([mesh_points_num, 3])

    v_array, t_array = np.unique(mesh_points, return_inverse=True, axis=0)
    t_array = t_array.reshape([len(mesh_vectors), 3])
    return v_array, t_array # vertex array, triangles array
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  1. v_array 为stl网格的顶点坐标序列,shape=(n,3),这里n为此网格的顶点总数,其实就是浮点型的x,y,z三个浮点值组成的三维坐标
  2. t_array 为stl网格的三角面片序列,shape=(m,3),这里m为此网格的三角面片总数,其实就是对顶点序号(下标)的一种组合,三个顶点组成一个三角形
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/795216
推荐阅读
相关标签
  

闽ICP备14008679号