mikedh / trimesh

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

trimesh.load .obj duplicates vertices #2154

Open bootsmakes opened 8 months ago

bootsmakes commented 8 months ago

Hello, I'm trying to read a simple triangle cube with 8 verts and 12 faces, but mesh.vertices show 24 verts instead.

>>> import trimesh as tm
>>> mesh = tm.load("test.obj")
>>> mesh
<trimesh.Trimesh(vertices.shape=(24, 3), faces.shape=(12, 3), name=`test.obj`)>

test.zip

bootsmakes commented 8 months ago

Removing 'vt' and 'vn' entries in test.obj seems to fix the loader problem, but mesh.face_adjacency_tree.intersection is still incorrect.

radius = 0.5
bounds = np.column_stack((mesh.vertices - radius, mesh.vertices + radius))
candidates = [list(mesh.face_adjacency_tree.intersection(b)) for b in bounds]
>>> for i in candidates:
...    print(i)
...
[0, 1, 2, 5, 6, 10]
[0, 2, 3, 6, 7, 8]
[1, 2, 4, 10, 11, 12]
[2, 3, 4, 8, 12, 14]
[5, 6, 10, 9, 13, 15]
[6, 7, 8, 9, 15, 16]
[10, 11, 12, 13, 15, 17]
[8, 12, 14, 15, 16, 17]
mikedh commented 8 months ago

Hey, the OBJ format has a lot of gotchas, you may want to use a different format if you need to match the input (maybe OFF or GLB?). I think you probably want trimesh.load('test.obj', merge_norm=True, merge_tex=True) to avoid trimesh duplicating vertices to convert from the OBJ data structure to the trimesh one of n, 3 vertices and m, 3 faces.

mesh.face_adjacency_tree returns indexes of mesh.face_adjacency, which may not be what you want (maybe mesh.triangles_tree for face-index results, or mesh.kdtree for vertex-index results?)

bootsmakes commented 8 months ago

@mikedh Thanks. mean_curv[i] = (lengths angles signs).sum() / 2. Why is the discrete mean curvature divided by 2, unlike eq.(2) in the paper? Also are the discrete max and min curvature the eigenvalues of discrete anisotropic curvature measures described in Definition 4 of the paper?