code: def make_mesh_texture_atlas(
      material_properties: Dict,
      texture_images: Dict,
      face_material_names,
      faces_uvs: torch.Tensor,
      verts_uvs: torch.Tensor,
      texture_size: int,
      texture_wrap: Optional[str],
  ) -> torch.Tensor:
      """
      Given properties for materials defined in the .mtl file, and the face texture uv
      coordinates, construct an (F, R, R, 3) texture atlas where R is the texture_size
      and F is the number of faces in the mesh.
  
      Args:
          material_properties: dict of properties for each material. If a material
                  does not have any properties it will have an empty dict.
          texture_images: dict of material names and texture images
          face_material_names: numpy array of the material name corresponding to each
              face. Faces which don't have an associated material will be an empty string.
              For these faces, a uniform white texture is assigned.
          faces_uvs: LongTensor of shape (F, 3,) giving the index into the verts_uvs for
              each face in the mesh.
          verts_uvs: FloatTensor of shape (V, 2) giving the uv coordinates for each vertex.
          texture_size: the resolution of the per face texture map returned by this function.
              Each face will have a texture map of shape (texture_size, texture_size, 3).
          texture_wrap: string, one of ["repeat", "clamp", None]
              If `texture_wrap="repeat"` for uv values outside the range [0, 1] the integer part
              is ignored and a repeating pattern is formed.
              If `texture_wrap="clamp"` the values are clamped to the range [0, 1].
              If None, do nothing.
  
      Returns:
          atlas: FloatTensor of shape (F, texture_size, texture_size, 3) giving the per
          face texture map.
      """
      # Create an R x R texture map per face in the mesh
      R = texture_size
      F = faces_uvs.shape[0]
  
      # Initialize the per face texture map to a white color.
      # TODO: allow customization of this base color?
      atlas = torch.ones(
          size=(F, R, R, 3),
          dtype=torch.float32,
          device=faces_uvs.device,
      )
  
      # Check for empty materials.
      if not material_properties and not texture_images:
          return atlas
  
      # Iterate through the material properties - not
      # all materials have texture images so this is
      # done first separately to the texture interpolation.
      for material_name, props in material_properties.items():
          # Bool to indicate which faces use this texture map.
          faces_material_ind = torch.from_numpy(
              face_material_names == material_name
          ).to(faces_uvs.device)
          if faces_material_ind.sum() > 0:
              # For these faces, update the base color to the
              # diffuse material color.
              if "diffuse_color" not in props:
                  continue
              atlas[faces_material_ind, ...] = props["diffuse_color"][
                  None, :
              ]
  
      # If there are vertex texture coordinates, create an (F, 3, 2)
      # tensor of the vertex textures per face.
      faces_verts_uvs = (
          verts_uvs[faces_uvs] if len(verts_uvs) > 0 else None
      )
  
      # Some meshes only have material properties and no texture image.
      # In this case, return the atlas here.
      if faces_verts_uvs is None:
          return atlas
  
      if texture_wrap == "repeat":
          # If texture uv coordinates are outside the range [0, 1] follow
          # the convention GL_REPEAT in OpenGL i.e the integer part of the coordinate
          # will be ignored and a repeating pattern is formed.
          # Shapenet data uses this format see:
          # https://shapenet.org/qaforum/index.php?qa=15&qa_1=why-is-the-texture-coordinate-in-the-obj-file-not-in-the-range # noqa: B950
          if (faces_verts_uvs > 1).any() or (faces_verts_uvs < 0).any():
              msg = "Texture UV coordinates outside the range [0, 1]. \
                  The integer part will be ignored to form a repeating pattern."
              warnings.warn(msg)
              faces_verts_uvs = faces_verts_uvs % 1
      elif texture_wrap == "clamp":
          # Clamp uv coordinates to the [0, 1] range.
          faces_verts_uvs = faces_verts_uvs.clamp(0.0, 1.0)
  
      # Iterate through the materials used in this mesh. Update the
      # texture atlas for the faces which use this material.
      # Faces without texture are white.
      for material_name, image in list(texture_images.items()):
          # Only use the RGB colors
          if image.shape[2] == 4:
              image = image[:, :, :3]
  
          # Reverse the image y direction
          image = torch.flip(image, [0]).type_as(faces_verts_uvs)
  
          # Bool to indicate which faces use this texture map.
          faces_material_ind = torch.from_numpy(
              face_material_names == material_name
          ).to(faces_verts_uvs.device)
  
          # Find the subset of faces which use this texture with this texture image
          uvs_subset = faces_verts_uvs[faces_material_ind, :, :]
  
          # Update the texture atlas for the faces which use this texture.
          # TODO: should the texture map values be multiplied
          # by the diffuse material color (i.e. use *= as the atlas has
          # been initialized to the diffuse color)?. This is
          # not being done in SoftRas.
          atlas[faces_material_ind, :, :] = make_material_atlas(
              image, uvs_subset, R
          )
  
      return atlas
  
file_path: pytorch3d/pytorch3d/io/mtl_io.py
imports: import os
  import warnings
  from typing import Dict, List, Optional, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from iopath.common.file_io import PathManager
  from pytorch3d.common.compat import meshgrid_ij
  from pytorch3d.common.datatypes import Device
  from pytorch3d.io.utils import _open_file, _read_image
label_desc: Use image node_id 1 for calling a global function with example usage: make_mesh_texture_atlas(material_properties, texture_images, face_material_names, faces_uvs, verts_uvs, texture_size, texture_wrap) and returns: atlas, atlas, atlas