facebookresearch / facebookresearch/pytorch3d

Meshes.update_padded_

Open
#983 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
10k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

## 🚀 Feature
Currently, `update_padded` only exists as an out-of-place operation which shallow copies attributes onto a new object.
It would be nice to have an in-place version that just modifies the vertices of the existing Meshes object.

## Motivation
I'm updating a mesh, but I'm not generating the new vertices through pytorch3d, or some method such that I could use `offset_verts_`, but an auxiliary model.
I would like to reuse the existing Meshes object for better efficiency and to allow the use of side effects when convenient.

## Pitch
I may be missing some things (like updating normals if they'd been computed), but this could be enough:
```python
def update_padded_(self, new_verts_padded):
"""
In-place version of update_padded.

Args:
new_verts_padded: FloatTensor of shape (N, V, 3)

Returns:
Meshes with updated padded representations
"""

def check_shapes(x, size):
if x.shape[0] != size[0]:
raise ValueError("new values must have the same batch dimension.")
if x.shape[1] != size[1]:
raise ValueError("new values must have the same number of points.")
if x.shape[2] != size[2]:
raise ValueError("new values must have the same dimension.")

self._verts_padded = new_verts_padded

# update verts/faces packed if they are computed in self
if self._verts_packed is not None:
# update verts_packed
pad_to_packed = self.verts_padded_to_packed_idx()
new_verts_packed = new_verts_padded.reshape(-1, 3)[pad_to_packed, :]
self._verts_packed = new_verts_packed
self._verts_padded_to_packed_idx = pad_to_packed

return self
```

There's an obvious huge speed-up involved when not creating a new object.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing update_padded implementation and the Meshes cached representations mentioned in the issue, including padded and packed vertices. Done means an in-place method updates the existing mesh consistently, with the expected behavior for cached normals and other derived data resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.