code: def _load_obj(
      f_obj,
      *,
      data_dir: str,
      load_textures: bool = True,
      create_texture_atlas: bool = False,
      texture_atlas_size: int = 4,
      texture_wrap: Optional[str] = "repeat",
      path_manager: PathManager,
      device: Device = "cpu",
  ):
      """
      Load a mesh from a file-like object. See load_obj function more details.
      Any material files associated with the obj are expected to be in the
      directory given by data_dir.
      """
  
      if texture_wrap is not None and texture_wrap not in [
          "repeat",
          "clamp",
      ]:
          msg = "texture_wrap must be one of ['repeat', 'clamp'] or None, got %s"
          raise ValueError(msg % texture_wrap)
  
      (
          verts,
          normals,
          verts_uvs,
          faces_verts_idx,
          faces_normals_idx,
          faces_textures_idx,
          faces_materials_idx,
          material_names,
          mtl_path,
      ) = _parse_obj(f_obj, data_dir)
  
      verts = _make_tensor(
          verts, cols=3, dtype=torch.float32, device=device
      )  # (V, 3)
      normals = _make_tensor(
          normals,
          cols=3,
          dtype=torch.float32,
          device=device,
      )  # (N, 3)
      verts_uvs = _make_tensor(
          verts_uvs,
          cols=2,
          dtype=torch.float32,
          device=device,
      )  # (T, 2)
  
      faces_verts_idx = _format_faces_indices(
          faces_verts_idx, verts.shape[0], device=device
      )
  
      # Repeat for normals and textures if present.
      if len(faces_normals_idx):
          faces_normals_idx = _format_faces_indices(
              faces_normals_idx,
              normals.shape[0],
              device=device,
              pad_value=-1,
          )
      if len(faces_textures_idx):
          faces_textures_idx = _format_faces_indices(
              faces_textures_idx,
              verts_uvs.shape[0],
              device=device,
              pad_value=-1,
          )
      if len(faces_materials_idx):
          faces_materials_idx = torch.tensor(
              faces_materials_idx, dtype=torch.int64, device=device
          )
  
      texture_atlas = None
      material_colors, texture_images = _load_materials(
          material_names,
          mtl_path,
          data_dir=data_dir,
          load_textures=load_textures,
          path_manager=path_manager,
          device=device,
      )
  
      if material_colors and not material_names:
          # usemtl was not present but single material was present in the .mtl file
          material_names.append(next(iter(material_colors.keys())))
          # replace all -1 by 0 material idx
          if torch.is_tensor(faces_materials_idx):
              faces_materials_idx.clamp_(min=0)
  
      if create_texture_atlas:
          # Using the images and properties from the
          # material file make a per face texture map.
  
          # Create an array of strings of material names for each face.
          # If faces_materials_idx == -1 then that face doesn't have a material.
          idx = faces_materials_idx.cpu().numpy()
          face_material_names = np.array(material_names)[idx]  # (F,)
          face_material_names[idx == -1] = ""
  
          # Construct the atlas.
          texture_atlas = make_mesh_texture_atlas(
              material_colors,
              texture_images,
              face_material_names,
              faces_textures_idx,
              verts_uvs,
              texture_atlas_size,
              texture_wrap,
          )
  
      faces = _Faces(
          verts_idx=faces_verts_idx,
          normals_idx=faces_normals_idx,
          textures_idx=faces_textures_idx,
          materials_idx=faces_materials_idx,
      )
      aux = _Aux(
          normals=normals if len(normals) else None,
          verts_uvs=verts_uvs if len(verts_uvs) else None,
          material_colors=material_colors,
          texture_images=texture_images,
          texture_atlas=texture_atlas,
      )
      return verts, faces, aux
  
imports: import os
  import warnings
  from collections import namedtuple
  from pathlib import Path
  from typing import List, Optional
  import numpy
  import torch
  from iopath.common.file_io import PathManager
  from PIL import Image
  from pytorch3d.common.datatypes import Device
  from pytorch3d.io.mtl_io import load_mtl, make_mesh_texture_atlas
  from pytorch3d.io.utils import _check_faces_indices, _make_tensor, _open_file, PathOrStr
  from pytorch3d.renderer import TexturesAtlas, TexturesUV
  from pytorch3d.structures import join_meshes_as_batch, Meshes
  from .pluggable_formats import endswith, MeshFormatInterpreter
label_desc: Use image node_id 7 for calling a global function with example usage: _load_obj(f_obj) and returns: verts,  faces,  aux