trimesh icon indicating copy to clipboard operation
trimesh copied to clipboard

trimesh.load .obj duplicates vertices

Open bootsmakes opened this issue 1 year ago • 3 comments

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 avatar Feb 18 '24 08:02 bootsmakes

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]

bootsmakes avatar Feb 18 '24 09:02 bootsmakes

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?)

mikedh avatar Feb 18 '24 18:02 mikedh

@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?

bootsmakes avatar Feb 25 '24 07:02 bootsmakes