Summary:
If you join several meshes which have TexturesUV textures using join_meshes_as_scene then we amalgamate all the texture images in to a single one. This now checks if some of the images are equal (i.e. the tensors are the same tensor, in the `is` sense; they have the same `id` in Python) and only uses one copy if they are.
I have an example of a massive scene made of several textured meshes with some shared, where this makes the difference between fitting the data on the GPU and not.
Reviewed By: theschnitz
Differential Revision: D25982364
fbshipit-source-id: a8228805f38475c796302e27328a340d9b56c8ef
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 load normals when they are present in a PLY file.
Reviewed By: nikhilaravi
Differential Revision: D26458971
fbshipit-source-id: 658270b611f7624eab4f5f62ff438038e1d25723
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: When a PLY file contains colors in byte format, these are now scaled from 0..255 to [0,1], as they should be
Reviewed By: gkioxari
Differential Revision: D27765254
fbshipit-source-id: 526b5f5149d5e8cbffd7412b411be52c935fa4ad
Summary:
Include TexturesVertex colors when loading and saving Meshes to PLY files.
A couple of other improvements to the internals of ply_io, including using `None` instead of empty tensors for some missing data.
Reviewed By: gkioxari
Differential Revision: D27765260
fbshipit-source-id: b9857dc777c244b9d7d6643b608596d31435ecda
Summary:
When a list of Meshes is `join_batched()`, the `num_verts_per_mesh` in the list would be unexpectedly modified.
Also some cleanup around `_num_verts_per_mesh`.
Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/623
Test Plan: A modification to an existing test checks this.
Reviewed By: nikhilaravi
Differential Revision: D27682104
Pulled By: bottler
fbshipit-source-id: 9d00913dfb4869bd6c7d3f5cc9156b7b6f1aecc9
Summary: Simplify finding the data directories in the tests.
Reviewed By: nikhilaravi
Differential Revision: D27634293
fbshipit-source-id: dc308a7c86c41e6fae56a2ab58187c9f0335b575
Summary: Make common functions for finding directories where test data is found, instead of lots of tests using their own `__file__` while trying to get ./tests/data and the tutorials data.
Reviewed By: nikhilaravi
Differential Revision: D27633701
fbshipit-source-id: 1467bb6018cea16eba3cab097d713116d51071e9
Summary: flake8 no longer respects the black fmt:off message, so include specific line-length exclusion.
Reviewed By: nikhilaravi
Differential Revision: D27624641
fbshipit-source-id: adcdb6f55b382fbf252eede3f3ddeda0621da883
Summary:
Update `main` build to latest CircleCI image - Ubuntu 2020.04.
Avoid torch.logical_or and logical_and for PyTorch 1.4 compatibility.
Also speed up the test run with Pytorch 1.4.0 (which has no ninja) by not setting NVCC_FLAGS for it.
Reviewed By: theschnitz
Differential Revision: D27262327
fbshipit-source-id: ddc359d134b1dc755f8b20bd3f33bb080cb3a0e1
Summary: Avoid using the newish member function isfinite. We use torch.isfinite instead for torch 1.4.0 compatibility.
Reviewed By: nikhilaravi
Differential Revision: D26946672
fbshipit-source-id: 853c3716f40061152f1ea54a39eb60b565de7c2c
Summary:
- Fix the calculation of the non square NDC range when the H and W are not integer multiples.
- Add test for this case
Reviewed By: gkioxari
Differential Revision: D26613213
fbshipit-source-id: df6763cac602e9f1d516b41b432c4d2cfbaa356d
Summary: Implements the ascii OFF file format. This was discussed in https://github.com/facebookresearch/pytorch3d/issues/216
Reviewed By: theschnitz
Differential Revision: D25788834
fbshipit-source-id: c141d1f4ba3bad24e3c1f280a20aee782bfd74d6
Summary:
Fixes mostly related to the "main" build on circleci.
-Avoid error to do with tuple copy from initializer_list which is `explicit` on old compiler.
-Add better reporting to copyright test.
-Move to PackedTensorAccessor64 from the deprecated PackedTensorAccessor
-Avoid some warnings about mismatched comparisons.
The "main" build is the only one that runs the test_build stuff. In that area
-Fix my bad copyright fix D26275931 (3463f418b8) / 965c9c
-Add test that all tutorials are valid json.
Reviewed By: nikhilaravi
Differential Revision: D26366466
fbshipit-source-id: c4ab8b7e6647987069f7cb7144aa6ab7c24bcdac
Summary:
- Updated the C++/CUDA mesh rasterization kernels to handle the clipped faces. In particular this required careful handling of the distance calculation for faces which are cut into a quadrilateral by the image plane and then split into two sub triangles i.e. both sub triangles can't be part of the top K faces.
- Updated `rasterize_meshes.py` to use the utils functions to clip the meshes and convert the fragments back to in terms of the unclipped mesh
- Added end to end tests
Reviewed By: jcjohnson
Differential Revision: D26169685
fbshipit-source-id: d64cd0d656109b965f44a35c301b7c81f451cfa0
Summary: Small update to the cameras and rasterizer to correctly infer the type of camera (perspective vs orthographic).
Reviewed By: jcjohnson
Differential Revision: D26267225
fbshipit-source-id: a58ed3bc2ab25553d2a4307c734204c1d41b5176
Summary:
Instead of culling faces behind the camera, partially clip them if they intersect with the image plane.
This diff implements the utils functions for clipping.
There are 4 cases for the mesh faces which are all handled:
```
Case 1: the triangle is completely in front of the clipping plane (it is left
unchanged)
Case 2: the triangle is completely behind the clipping plane (it is culled)
Case 3: the triangle has exactly two vertices behind the clipping plane (it is
clipped into a smaller triangle)
Case 4: the triangle has exactly one vertex behind the clipping plane (it is clipped
into a smaller quadrilateral and divided into two triangular faces)
```
Reviewed By: jcjohnson
Differential Revision: D23108673
fbshipit-source-id: 550a8b6a982d06065dff10aba10d47e8b144ae52
Summary:
These two tests fail (with non-small differences) when the seed is changed or if certain environmental changes are made. We disable them pending investigation.
A small change to the tolerance at the failing assertion doesn't help. The change in common_testing helps diagnose this.
Reviewed By: shapovalov
Differential Revision: D26233419
fbshipit-source-id: 357afc1786825256c9bade101fb15707e4dea5ed
Summary: Corner case where there's nothing to do in this function.
Reviewed By: nikhilaravi
Differential Revision: D26073476
fbshipit-source-id: eb061683ffe35c1ffa8384c422a1557a636d52cd
Summary: We were double counting some pairs in some cases. Specifically if four or more faces share an edge, then some of them were getting double counted. This is a minimal tweak to avoid that.
Reviewed By: nikhilaravi
Differential Revision: D26073477
fbshipit-source-id: a40032acf3044bb98dd91cb29904614ef64d5599
Summary:
Plotly viewing from a specific camera location requires converting that location in to an (eye, at, up) specification. There may be other reasons to want to do this as well. I create a separate utility function for it.
I envisage more such utility functions for manipulating camera information, so I create a separate camera_utils.py file for such things.
Reviewed By: nikhilaravi
Differential Revision: D25981184
fbshipit-source-id: 0947bf98b212676c021f2fddf775bf436dee3487
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: Make `to` on Transform3D carry its member _transforms.
Reviewed By: nikhilaravi
Differential Revision: D25978611
fbshipit-source-id: 12b39e7a657f28d59ca60800bf9f4193a2c08197
Summary:
Allow PLY files to not contain faces. Allow loading pointclouds with color, at least encoded according to the way of some cloudcompare examples.
TODO: Allow vertex normals to be read, and allow vertex colors to be written. Make the return type of load_ply something more user friendly, like a dict.
Noticed in https://github.com/facebookresearch/pytorch3d/issues/209
Reviewed By: nikhilaravi
Differential Revision: D22573314
fbshipit-source-id: 72ba1f7c6417f5dfc83f2ebf359eff017057635c
Summary:
In the original implementation, I had considered PLY properties where there are mixed types of elements in a property to be rare and basically unimportant, so the implementation is very naive.
If we want to support pointcloud PLY files, we need to handle at least the subcase where there are no lists efficiently because this seems to be very common there.
Reviewed By: nikhilaravi, gkioxari
Differential Revision: D22573315
fbshipit-source-id: db6f29446d4e555a2e2b37d38c8e4450d061465b
Summary: We already have code for obj and ply formats. Here we actually make it available in `IO.load_mesh` and `IO.save_mesh`.
Reviewed By: theschnitz, nikhilaravi
Differential Revision: D25400650
fbshipit-source-id: f26d6d7fc46c48634a948eea4d255afad13b807b
Summary: Implemented a data structure for volumes.
Reviewed By: gkioxari
Differential Revision: D20342920
fbshipit-source-id: ccc23eaa183ed8a4e9cd7674b4dcf31e8a65c3c6
Summary: Extends `list_to_padded`/`padded_to_list` to work for tensors with an arbitrary number of input dimensions.
Reviewed By: nikhilaravi, gkioxari
Differential Revision: D23813969
fbshipit-source-id: 52c212a2ecdb3c4dfb6ac47217715e07998f37f1
Summary:
Make no internal functions inside pytorch3d/io interpret str paths except using a PathManager from iopath which they have been given. This means we no longer use any global PathManager object and we no longer use fvcore's deprecated file_io.
To preserve the APIs, various top level functions create their own default-initialized PathManager object if they are not provided one.
Reviewed By: theschnitz
Differential Revision: D25372969
fbshipit-source-id: c176ee31439645fa54a157d6f1aef18b09501569
Summary: Allowing usort, isort and black to coexist without fighting means we can't have imports commented as deprecated from the same module as other imports.
Reviewed By: nikhilaravi
Differential Revision: D25372970
fbshipit-source-id: 637f5a0025c0df9fbec47cba73ce5387f4f8b467
Summary:
Defines a function to run marching cubes algorithm on a single or batch of 3D scalar fields. Returns a mesh's faces and vertices.
UPDATES (12/18)
- Input data is now specified as a (B, D, H, W) tensor as opposed to a (B, W, H, D) tensor. This will now be compatible with the Volumes datastructure.
- Add an option to return output vertices in local coordinates instead of world coordinates.
Also added a small fix to remove the dype for device in Transforms3D - if passing in a torch.device instead of str it causes a pyre error.
Reviewed By: jcjohnson
Differential Revision: D24599019
fbshipit-source-id: 90554a200319fed8736a12371cc349e7108aacd0
Summary: Fixes the index out of bound errors for texture sampling from a texture atlas: when barycentric coordinates are 1.0, the integer index into the (R, R) per face texture map is R (max can only be R-1).
Reviewed By: gkioxari
Differential Revision: D25543803
fbshipit-source-id: 82d0935b981352b49c1d95d5a17f9cc88bad0a82
Summary:
Similar to non square image rasterization for meshes, apply the same updates to the pointcloud rasterizer.
Main API Change:
- PointRasterizationSettings now accepts a tuple/list of (H, W) for the image size.
Reviewed By: jcjohnson
Differential Revision: D25465206
fbshipit-source-id: 7370d83c431af1b972158cecae19d82364623380