Summary:
Converts the directory specified to use the Ruff formatter in pyfmt
ruff_dog
If this diff causes merge conflicts when rebasing, please run
`hg status -n -0 --change . -I '**/*.{py,pyi}' | xargs -0 arc pyfmt`
on your diff, and amend any changes before rebasing onto latest.
That should help reduce or eliminate any merge conflicts.
allow-large-files
Reviewed By: bottler
Differential Revision: D66472063
fbshipit-source-id: 35841cb397e4f8e066e2159550d2f56b403b1bef
Summary:
Copypasting the docstring:
```
Split a mesh into submeshes, defined by face indices of the original Meshes object.
Args:
face_indices:
Let the original mesh have verts_list() of length N.
Can be either
- List of length N. The n-th element is a list of length num_submeshes_n
(empty lists are allowed). Each element of the n-th sublist is a LongTensor
of length num_faces.
- List of length N. The n-th element is a possibly empty padded LongTensor of
shape (num_submeshes_n, max_num_faces).
Returns:
Meshes object with selected submeshes. The submesh tensors are cloned.
Currently submeshing only works with no textures or with the TexturesVertex texture.
Example:
Take a Meshes object `cubes` with 4 meshes, each a translated cube. Then:
* len(cubes) is 4, len(cubes.verts_list()) is 4, len(cubes.faces_list()) is 4,
* [cube_verts.size for cube_verts in cubes.verts_list()] is [8, 8, 8, 8],
* [cube_faces.size for cube_faces in cubes.faces_list()] if [6, 6, 6, 6],
Now let front_facet, top_and_bottom, all_facets be LongTensors of
sizes (2), (4), and (12), each picking up a number of facets of a cube by specifying
the appropriate triangular faces.
Then let `subcubes = cubes.submeshes([[front_facet, top_and_bottom], [], [all_facets], []])`.
* len(subcubes) is 3.
* subcubes[0] is the front facet of the cube contained in cubes[0].
* subcubes[1] is a mesh containing the (disconnected) top and bottom facets of cubes[0].
* subcubes[2] is a clone of cubes[2].
* There are no submeshes of cubes[1] and cubes[3] in subcubes.
* subcubes[0] and subcubes[1] are not watertight. subcubes[2] is.
```
Reviewed By: bottler
Differential Revision: D35440657
fbshipit-source-id: 8a6d2d300ce226b5b9eb440688528b5e795195a1
Summary:
Sort a mesh's vertices in alphabetical order, and resort the face coords accordingly. Textured meshes are not supported yet, but will be added down the stack.
This, togehter with mesh equality, can be used to compare two meshes in a way invariant to vertex permutations, as shown in the unit tests.
We do not want the submeshing mechanism to guarantee any particular vertex order, leaving that up to the implementation, so we need this function for testing.
Reviewed By: bottler
Differential Revision: D35440656
fbshipit-source-id: 5a4dd921fdb00625a33da08b5fea79e20ac6402c
Summary: Adding a mesh equality operator. Two Meshes objects m1, m2 are equal iff their vertex lists, face lists, and normals lists are equal. Textures meshes are not supported yet, but will be added for vertex textures down the stack.
Reviewed By: bottler, nikhilaravi
Differential Revision: D35440655
fbshipit-source-id: 69974a59c091416afdb2892896859a189f5ebf3a
Summary:
The default behavior of Meshes (with verts=None, faces=None) throws an exception:
```
meshes = Meshes()
> ValueError: Verts and Faces must be either a list or a tensor with shape (batch_size, N, 3) where N is either the maximum number of verts or faces respectively.
```
Instead, let's default to an empty mesh, following e.g. PyTorch:
```
empty_tensor = torch.FloatTensor()
> torch.tensor([])
```
this change is backwards-compatible (you can still init with verts=[], faces=[]).
Reviewed By: bottler, nikhilaravi
Differential Revision: D35443453
fbshipit-source-id: d638a8fef49a089bf0da6dd2201727b94ceb21ec
Summary: Update all FB license strings to the new format.
Reviewed By: patricklabatut
Differential Revision: D33403538
fbshipit-source-id: 97a4596c5c888f3c54f44456dc07e718a387a02c
Summary:
Context: in the code we are releasing with CO3D dataset, we use `cuda()` on TensorProperties like Pointclouds and Cameras where we recursively move batch to a GPU. It would be good to push it to a release so we don’t need to depend on the nightly build.
Additionally, I aligned the logic of `.to("cuda")` without device index to the one of `torch.Tensor` where the current device is populated to index. It should not affect any actual use cases but some tests had to be changed.
Reviewed By: bottler
Differential Revision: D29659529
fbshipit-source-id: abe58aeaca14bacc68da3e6cf5ae07df3353e3ce
Summary:
Refactor of all functions to compute laplacian matrices in one file.
Support for:
* Standard Laplacian
* Cotangent Laplacian
* Norm Laplacian
Reviewed By: nikhilaravi
Differential Revision: D29297466
fbshipit-source-id: b96b88915ce8ef0c2f5693ec9b179fd27b70abf9
Summary:
Tidy uses of `torch.device` in `Meshes`:
- Allow `str` or `torch.device` in `Meshes.to()` method
- Consistently use `torch.device` for internal type
- Fix comparison of devices
Reviewed By: nikhilaravi
Differential Revision: D28969461
fbshipit-source-id: 16d3c1f5458954bb11fdf0efea88542e94dccd7a
Summary: Avoid test files explicitly importing TestCase objects from each other, because doing so causes the tests to be discovered twice by unittest discover. This means moving a few static functions out of their classes. I noticed this while trying to fix failures from yesterday.
Reviewed By: nikhilaravi
Differential Revision: D28194679
fbshipit-source-id: ac6e6585603bd4ef9c098cdd56891d94f8923ba6
Summary:
A couple of tests are failing in open source after my changes yesterday because of numerical issues calculating normals. In particular we have meshes with very few vertices and several faces, where the normals should be zero but end up non-negligible after F.normalize. I have no idea why the different environments produce different results, so that the tests are passing internally.
An example. Consider a mesh with the following faces:
```
tensor([[4, 0, 2],
[4, 1, 2],
[3, 1, 0],
[1, 3, 1],
[3, 0, 1],
[4, 0, 0],
[4, 0, 2]])
```
At vertex 3, there is one zero-area face and there are two other faces, which are back-to-back with each other. This vertex should have zero normal. The open source calculation produces a small but nonzero normal which varies unpredictably with changes in scale/offset, which can cause test failures.
In this diff, the main change is to increase the number of vertices to make this less likely to happen. Also a small change to init_mesh to make it not generate a batch of empty meshes.
Reviewed By: nikhilaravi
Differential Revision: D28220984
fbshipit-source-id: 79fdc62e5f5f8836de5a3a9980cfd6fe44590359
Summary: Add ability to ask a Meshes if it already has normals. If it does, then requesting normals will not trigger a calculation. MeshesFormatInterpreters will therefore be able to decide whether to save normals.
Reviewed By: theschnitz, nikhilaravi
Differential Revision: D27765261
fbshipit-source-id: 7c87dbf999d5616d20f5eb2c01039ee5ff65a830
Summary: Add ability to set the vertex normals when creating a Meshes, so that the pluggable loaders can return them from a file.
Reviewed By: nikhilaravi
Differential Revision: D27765258
fbshipit-source-id: b5ddaa00de3707f636f94d9f74d1da12ecce0608
Summary: If offset_verts_ is used to move meshes with a single vector, the normals won't change so don't need to recalculate. I am planning to allow user-specified vertex normals. This change means that user-specified vertex normals won't get overwritten when they don't need to be.
Reviewed By: nikhilaravi
Differential Revision: D27765256
fbshipit-source-id: f6e4d308ac9ac023030325cb75a18d39b966cf88
Summary:
It is common when trying things out to want to move a whole mesh or point cloud by the same amount. Here we allow the offset functions to broadcast.
Also add a sanity check to join_meshes_as_scene which it is easy to call wrongly.
Reviewed By: nikhilaravi
Differential Revision: D25980593
fbshipit-source-id: cdf1568e1317e3b81ad94ed4e608ba7eef81290b
Summary:
Allow, and make default, align_corners=True for texture maps. Allow changing the padding_mode and set the default to be "border" which produces more logical results. Some new documentation.
The previous behavior corresponds to padding_mode="zeros" and align_corners=False.
Reviewed By: gkioxari
Differential Revision: D23268775
fbshipit-source-id: 58d6229baa591baa69705bcf97471c80ba3651de
Summary:
Three changes to Meshes
1. `num_verts_per_mesh` and `num_faces_per_mesh` are assigned at construction time and are returned without the need for `compute_packed`
2. `update_padded` updates `verts_padded` and shallow copies faces list and faces_padded and existing attributes from construction.
3. `padded_to_packed_idx` does not need `compute_packed`
Reviewed By: nikhilaravi
Differential Revision: D21653674
fbshipit-source-id: dc6815a2e2a925fe4a834fe357919da2b2c14527
Summary: use assertClose in some tests, which enforces shape equality. Fixes some small problems, including graph_conv on an empty graph.
Reviewed By: nikhilaravi
Differential Revision: D20556912
fbshipit-source-id: 60a61eafe3c03ce0f6c9c1a842685708fb10ac5b
Summary: The shebang line `#!<path to interpreter>` is only required for Python scripts, so remove it on source files for class or function definitions. Additionally explicitly mark as executable the actual Python scripts in the codebase.
Reviewed By: nikhilaravi
Differential Revision: D20095778
fbshipit-source-id: d312599fba485e978a243292f88a180d71e1b55a