mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
2.94k stars 574 forks source link

trimesh/grouping.py:59: IndexError #1276

Open gleb-an opened 3 years ago

gleb-an commented 3 years ago

I got this error when I execute mesh.merge_vertices() or mesh.process() with the trimesh==3.9.20

        if hasattr(mesh, 'faces') and len(mesh.faces) > 0:
            referenced = np.zeros(len(mesh.vertices), dtype=bool)
>           referenced[mesh.faces] = True
E           IndexError: index 29 is out of bounds for axis 0 with size 28

../venv/lib/python3.8/site-packages/trimesh/grouping.py:59: IndexError

The same error I got with the 3.9.10 version.

This code works with the 3.9.1 version!

Python 3.8 OS Ubuntu 20.04

mikedh commented 3 years ago

Hey, is the mesh referencing vertices that don't exist? For example I can reproduce with:

    mesh = trimesh.Trimesh(vertices=[], faces=[[0,1,2]])
    mesh.merge_vertices()

Where faces reference vertices that aren't there. I added an early exit for the case where len(mesh.vertices) == 0 but in the wider case (faces reference non-existent vertices) I think raising an IndexError is probably the right thing to do.

gleb-an commented 3 years ago

I have arrays like this(attached) faces.txt vertices.txt Screenshot from 2021-06-24 17-44-27

gleb-an commented 2 years ago

any updates on this?