code: def test_texture_sampling(self):
      device = torch.device("cuda:0")
      batch_size = 6
      # verts
      verts = torch.rand(
          (batch_size, 6, 3), device=device, dtype=torch.float32
      )
      verts[:, :3, 2] = 1.0
      verts[:, 3:, 2] = -1.0
      # textures
      texts = torch.rand(
          (batch_size, 6, 3), device=device, dtype=torch.float32
      )
      # faces
      faces = torch.tensor(
          [[0, 1, 2], [3, 4, 5]], device=device, dtype=torch.int64
      )
      faces = faces.view(1, 2, 3).expand(batch_size, -1, -1)
  
      meshes = Meshes(
          verts=verts, faces=faces, textures=TexturesVertex(texts)
      )
  
      num_samples = 24
      samples, normals, textures = sample_points_from_meshes(
          meshes,
          num_samples=num_samples,
          return_normals=True,
          return_textures=True,
      )
  
      textures_naive = torch.zeros(
          (batch_size, num_samples, 3),
          dtype=torch.float32,
          device=device,
      )
      for n in range(batch_size):
          for i in range(num_samples):
              p = samples[n, i]
              if p[2] > 0.0:  # sampled from 1st face
                  v0, v1, v2 = (
                      verts[n, 0, :2],
                      verts[n, 1, :2],
                      verts[n, 2, :2],
                  )
                  w0, w1, w2 = barycentric_coordinates(
                      p[:2], v0, v1, v2
                  )
                  t0, t1, t2 = texts[n, 0], texts[n, 1], texts[n, 2]
              else:  # sampled from 2nd face
                  v0, v1, v2 = (
                      verts[n, 3, :2],
                      verts[n, 4, :2],
                      verts[n, 5, :2],
                  )
                  w0, w1, w2 = barycentric_coordinates(
                      p[:2], v0, v1, v2
                  )
                  t0, t1, t2 = texts[n, 3], texts[n, 4], texts[n, 5]
  
              tt = w0 * t0 + w1 * t1 + w2 * t2
              textures_naive[n, i] = tt
  
      self.assertClose(textures, textures_naive)
  
imports: import unittest
  import numpy
  import torch
  from PIL import Image
  from pytorch3d.io import load_objs_as_meshes
  from pytorch3d.ops import sample_points_from_meshes
  from pytorch3d.renderer import TexturesVertex
  from pytorch3d.renderer.cameras import FoVPerspectiveCameras, look_at_view_transform
  from pytorch3d.renderer.mesh.rasterize_meshes import barycentric_coordinates
  from pytorch3d.renderer.points import NormWeightedCompositor, PointsRasterizationSettings, PointsRasterizer, PointsRenderer
  from pytorch3d.structures import Meshes, Pointclouds
  from pytorch3d.utils.ico_sphere import ico_sphere
  from .common_testing import get_pytorch3d_dir, get_random_cuda_device, get_tests_dir, TestCaseMixin
label_desc: Use image node_id 8 for calling the TestSamplePoints obj's underlying member method code with example usage: obj.test_texture_sampling() without return types