code: def render_texture(
      vertices,
      triangles,
      texture,
      tex_coords,
      tex_triangles,
      h,
      w,
      c=3,
      mapping_type="nearest",
  ):
      """render mesh with texture map
      Args:
          vertices: [nver], 3
          triangles: [ntri, 3]
          texture: [tex_h, tex_w, 3]
          tex_coords: [ntexcoords, 3]
          tex_triangles: [ntri, 3]
          h: height of rendering
          w: width of rendering
          c: channel
          mapping_type: 'bilinear' or 'nearest'
      """
      assert triangles.shape[0] == tex_triangles.shape[0]
      tex_h, tex_w, _ = texture.shape
  
      # initial
      image = np.zeros((h, w, c))
      depth_buffer = np.zeros([h, w]) - 999999.0
  
      for i in range(triangles.shape[0]):
          tri = triangles[i, :]  # 3 vertex indices
          tex_tri = tex_triangles[i, :]  # 3 tex indice
  
          # the inner bounding box
          umin = max(int(np.ceil(np.min(vertices[tri, 0]))), 0)
          umax = min(int(np.floor(np.max(vertices[tri, 0]))), w - 1)
  
          vmin = max(int(np.ceil(np.min(vertices[tri, 1]))), 0)
          vmax = min(int(np.floor(np.max(vertices[tri, 1]))), h - 1)
  
          if umax < umin or vmax < vmin:
              continue
  
          for u in range(umin, umax + 1):
              for v in range(vmin, vmax + 1):
                  if not isPointInTri([u, v], vertices[tri, :2]):
                      continue
                  w0, w1, w2 = get_point_weight(
                      [u, v], vertices[tri, :2]
                  )
                  point_depth = (
                      w0 * vertices[tri[0], 2]
                      + w1 * vertices[tri[1], 2]
                      + w2 * vertices[tri[2], 2]
                  )
                  if point_depth > depth_buffer[v, u]:
                      # update depth
                      depth_buffer[v, u] = point_depth
  
                      # tex coord
                      tex_xy = (
                          w0 * tex_coords[tex_tri[0], :]
                          + w1 * tex_coords[tex_tri[1], :]
                          + w2 * tex_coords[tex_tri[2], :]
                      )
                      tex_xy[0] = max(
                          min(tex_xy[0], float(tex_w - 1)), 0.0
                      )
                      tex_xy[1] = max(
                          min(tex_xy[1], float(tex_h - 1)), 0.0
                      )
  
                      # nearest
                      if mapping_type == "nearest":
                          tex_xy = np.round(tex_xy).astype(np.int32)
                          tex_value = texture[tex_xy[1], tex_xy[0], :]
  
                      # bilinear
                      elif mapping_type == "bilinear":
                          # next 4 pixels
                          ul = texture[
                              int(np.floor(tex_xy[1])),
                              int(np.floor(tex_xy[0])),
                              :,
                          ]
                          ur = texture[
                              int(np.floor(tex_xy[1])),
                              int(np.ceil(tex_xy[0])),
                              :,
                          ]
                          dl = texture[
                              int(np.ceil(tex_xy[1])),
                              int(np.floor(tex_xy[0])),
                              :,
                          ]
                          dr = texture[
                              int(np.ceil(tex_xy[1])),
                              int(np.ceil(tex_xy[0])),
                              :,
                          ]
  
                          yd = tex_xy[1] - np.floor(tex_xy[1])
                          xd = tex_xy[0] - np.floor(tex_xy[0])
                          tex_value = (
                              ul * (1 - xd) * (1 - yd)
                              + ur * xd * (1 - yd)
                              + dl * (1 - xd) * yd
                              + dr * xd * yd
                          )
  
                      image[v, u, :] = tex_value
      return image
  
file_path: insightface/python-package/insightface/thirdparty/face3d/mesh_numpy/render.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  from time import time
label_desc: Use image node_id 6 for calling a global function with example usage: render_texture(vertices, triangles, texture, tex_coords, tex_triangles, h, w, c, mapping_type) and returns: image