mikedh / trimesh

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

Creating a new mesh from indices changes the number of vertices in an unnexpected way. #2323

Open MartensCedric opened 2 weeks ago

MartensCedric commented 2 weeks ago

  mesh = trimesh.load(obj_filename)
  print(mesh)

  new_mesh = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces)
  print(new_mesh)

Output:

Notice how the vertices go from 555 to 505.

  <trimesh.Trimesh(vertices.shape=(555, 3), faces.shape=(968, 3), name=`suzanne.obj`)>
<trimesh.Trimesh(vertices.shape=(505, 3), faces.shape=(968, 3))>

suzanne.zip

mikedh commented 2 weeks ago

Hey, I think you probably want process=False to turn off vertex merging, which is on by default mostly so STL files don't show up as a triangle soup:

  mesh = trimesh.load(obj_filename, process=False)
  print(mesh)

  new_mesh = trimesh.Trimesh(vertices=mesh.vertices, faces=mesh.faces, process=False)
  print(new_mesh)
MartensCedric commented 2 weeks ago

but why is vertex merging off by default in the load but on when creating the object? Seems it should be consistent

mikedh commented 2 weeks ago

It's actually on for loading too, probably what's happening is since OBJ has explicit vertex normals it will only merge vertices if they have the same position AND normal, where in the second case it's only getting position passed in.