Support reading uv and uv map for ply format if texture_uv exists in ply file (#1100)

Summary:
When the ply format looks as follows:
  ```
comment TextureFile ***.png
element vertex 892
property double x
property double y
property double z
property double nx
property double ny
property double nz
property double texture_u
property double texture_v
```
`MeshPlyFormat` class will read uv from the ply file and read the uv map as commented as TextureFile.

Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/1100

Reviewed By: MichaelRamamonjisoa

Differential Revision: D50885176

Pulled By: bottler

fbshipit-source-id: be75b1ec9a17a1ed87dbcf846a9072ea967aec37
This commit is contained in:
YangHai
2023-11-14 07:44:14 -08:00
committed by Facebook GitHub Bot
parent f4f2209271
commit 55638f3bae
3 changed files with 97 additions and 6 deletions

28
tests/data/uvs.ply Normal file
View File

@@ -0,0 +1,28 @@
ply
format ascii 1.0
comment made by Greg Turk
comment this file is a cube
comment TextureFile test_nd_sphere.png
element vertex 8
property float x
property float y
property float z
property float texture_u
property float texture_v
element face 6
property list uchar int vertex_index
end_header
0 0 0 0 0
0 0 1 0.2 0.3
0 1 1 0.2 0.3
0 1 0 0.2 0.3
1 0 0 0.2 0.3
1 0 1 0.2 0.3
1 1 1 0.2 0.3
1 1 0 0.4 0.5
4 0 1 2 3
4 7 6 5 4
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0

View File

@@ -20,10 +20,11 @@ from pytorch3d.renderer.mesh import TexturesVertex
from pytorch3d.structures import Meshes, Pointclouds
from pytorch3d.utils import torus
from .common_testing import TestCaseMixin
from .common_testing import get_tests_dir, TestCaseMixin
global_path_manager = PathManager()
DATA_DIR = get_tests_dir() / "data"
def _load_ply_raw(stream):
@@ -778,6 +779,19 @@ class TestMeshPlyIO(TestCaseMixin, unittest.TestCase):
data["minus_ones"], [-1, 255, -1, 65535, -1, 4294967295]
)
def test_load_uvs(self):
io = IO()
mesh = io.load_mesh(DATA_DIR / "uvs.ply")
self.assertEqual(mesh.textures.verts_uvs_padded().shape, (1, 8, 2))
self.assertClose(
mesh.textures.verts_uvs_padded()[0],
torch.tensor([[0, 0]] + [[0.2, 0.3]] * 6 + [[0.4, 0.5]]),
)
self.assertEqual(
mesh.textures.faces_uvs_padded().shape, mesh.faces_padded().shape
)
self.assertEqual(mesh.textures.maps_padded().shape, (1, 512, 512, 3))
def test_bad_ply_syntax(self):
"""Some syntactically bad ply files."""
lines = [