title: Need help making a 3D mesh given co-ordinates of the vertices and vertex indices of each face for 3D Slicer - trimesh python
body: <p>Given the following data:</p>
  <ol>
  <li>The Cartesian co-ordinates of the vertices in the surface mesh: n vertices x 3</li>
  <li>The vertex indices of each face in the surface mesh: n faces x 3</li>
  </ol>
  <p>I'm trying to export some 3D file that I can readily import to <a href="https://www.slicer.org/" rel="nofollow noreferrer">3D Slicer</a> for registration against a VTK file.</p>
  <p>Faces: <a href="https://pastebin.com/qWq7aiEs" rel="nofollow noreferrer">https://pastebin.com/qWq7aiEs</a></p>
  <p>Vertices: <a href="https://pastebin.com/VxsxsdcM" rel="nofollow noreferrer">https://pastebin.com/VxsxsdcM</a></p>
  <p>I have been trying various packages/libraries etc. and keep running into various issues. The following issue is using the <a href="https://pythonawesome.com/python-library-for-loading-and-using-triangular-meshes/" rel="nofollow noreferrer">Trimesh in Python</a> and I'm attributing the problem to my poor python ability rather than an issue with the package. I'm open to other solution as well.</p>
  <p>I imported the CSV, extracted the arrays then converted to lists to match the example. I wasn't certain how to use the faces data given the example, so I just made a list that matched the length of vertices, not sure if that's right at all.</p>
  <pre><code># Example: mesh objects can be created from existing faces and vertex data
  mesh = trimesh.Trimesh(vertices=[[0, 0, 0], [0, 0, 1], [0, 1, 0]],
                         faces=[[0, 1, 2]])
  
  # My attempt
  vertex_x = vertices_csv[:,0]
  vertex_y = vertices_csv[:,1]
  vertex_z = vertices_csv[:,2]
  vertex_x_list = vertex_x.tolist()
  vertex_y_list = vertex_y.tolist()
  vertex_z_list = vertex_z.tolist()
  faces_list_mesh = [i for i in range(len(vertex_x_list))]
  
  mesh = trimesh.Trimesh(vertices=[vertex_x_list, vertex_y_list, vertex_z_list],
  ...                        faces=[faces_list_mesh])
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;C:\...\Python\Python310\lib\site-packages\trimesh\base.py&quot;, line 190, in __init__
      self.process(validate=validate,
    File &quot;C:\...\Python\Python310\lib\site-packages\trimesh\base.py&quot;, line 232, in process
      self.merge_vertices(merge_tex=merge_tex,
    File &quot;C:\...\Python\Python310\lib\site-packages\trimesh\base.py&quot;, line 1123, in merge_vertices
      grouping.merge_vertices(
    File &quot;C:\...\Python\Python310\lib\site-packages\trimesh\grouping.py&quot;, line 70, in merge_vertices
      referenced[mesh.faces] = True
  IndexError: index 3 is out of bounds for axis 0 with size 3
  </code></pre>
  <p>Any advice how to troubleshoot is greatly appreciated!</p>