Skip to content

Commit

Permalink
Merge pull request #2322 from dbukenberger/master
Browse files Browse the repository at this point in the history
Fix vertex_attributes subdivisions and corresponding test added.
  • Loading branch information
mikedh authored Nov 9, 2024
2 parents 44498d8 + 82fd608 commit 2a769fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/test_remesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ def test_sub(self):
meshes = [g.trimesh.creation.box(), g.trimesh.creation.icosphere()]

for m in meshes:
# set vertex positions as attributes for trivial check after subdivision
m.vertex_attributes = {"pos": m.vertices}

s = m.subdivide(face_index=[0, len(m.faces) - 1])
# shouldn't have subdivided in-place
assert len(s.faces) > len(m.faces)
# area should be the same
assert g.np.isclose(m.area, s.area)
# volume should be the same
assert g.np.isclose(m.volume, s.volume)
# position attributes and actual vertices should be the same
assert g.np.allclose(s.vertex_attributes["pos"], s.vertices)

max_edge = m.scale / 50
s = m.subdivide_to_size(max_edge=max_edge)
Expand Down
6 changes: 1 addition & 5 deletions trimesh/remesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ def subdivide(
if vertex_attributes is not None:
new_attributes = {}
for key, values in vertex_attributes.items():
attr_tris = values[faces_subset]
attr_mid = np.vstack(
[attr_tris[:, g, :].mean(axis=1) for g in [[0, 1], [1, 2], [2, 0]]]
)
attr_mid = attr_mid[unique]
attr_mid = values[edges[unique]].mean(axis=1)
new_attributes[key] = np.vstack((values, attr_mid))
return new_vertices, new_faces, new_attributes

Expand Down

0 comments on commit 2a769fa

Please sign in to comment.