Single function to load meshes from OBJs. join_meshes.

Summary:
Create the textures and the Meshes object from OBJ files in a single call.

There is functionality in OBJ files (like normals) which is ignored by this function.

Reviewed By: gkioxari

Differential Revision: D19691699

fbshipit-source-id: e26442ed80ff231b65b17d6c54c9d41e22b4e4a3
This commit is contained in:
Jeremy Reizenstein
2020-02-13 03:36:39 -08:00
committed by Facebook Github Bot
parent 23bb27956a
commit 8fe65d5f56
8 changed files with 218 additions and 44 deletions

View File

@@ -55,6 +55,9 @@ tex = Textures(verts_uvs=verts_uvs, faces_uvs=faces_uvs, maps=texture_image)
# Initialise the mesh with textures
meshes = Meshes(verts=[verts], faces=[faces.verts_idx], textures=tex)
```
The `load_objs_as_meshes` function provides this procedure.
## PLY
Ply files are flexible in the way they store additional information, pytorch3d

View File

@@ -87,7 +87,7 @@
"from skimage.io import imread\n",
"\n",
"# Util function for loading meshes\n",
"from pytorch3d.io import load_obj\n",
"from pytorch3d.io import load_objs_as_meshes\n",
"\n",
"# Data structures and functions for rendering\n",
"from pytorch3d.structures import Meshes, Textures\n",
@@ -232,25 +232,8 @@
"obj_filename = os.path.join(DATA_DIR, \"cow_mesh/cow.obj\")\n",
"\n",
"# Load obj file\n",
"verts, faces, aux = load_obj(obj_filename)\n",
"faces_idx = faces.verts_idx.to(device)\n",
"verts = verts.to(device)\n",
"\n",
"# Get textures from the outputs of the load_obj function\n",
"# the `aux` variable contains the texture maps and vertex uv coordinates. \n",
"# Refer to the `obj_io.load_obj` function for full API reference. \n",
"# Here we only have one texture map for the whole mesh. \n",
"verts_uvs = aux.verts_uvs[None, ...].to(device) # (N, V, 2)\n",
"faces_uvs = faces.textures_idx[None, ...].to(device) # (N, F, 3)\n",
"tex_maps = aux.texture_images\n",
"texture_image = list(tex_maps.values())[0]\n",
"texture_image = texture_image[None, ...].to(device) # (N, H, W, 3)\n",
"\n",
"# Create a textures object\n",
"tex = Textures(verts_uvs=verts_uvs, faces_uvs=faces_uvs, maps=texture_image)\n",
"\n",
"# Create a meshes object with textures\n",
"mesh = Meshes(verts=[verts], faces=[faces_idx], textures=tex)"
"mesh = load_objs_as_meshes([obj_filename], device=device)\n",
"texture_image=mesh.textures.maps_padded()"
]
},
{