Base on the answer of scurest
, I can get the following result(top: Geometry Parametric, bottom: triangle face index), you can check pixel-level correspondence in tev:
To distinguish from the background, I add an offset to face index: uvs[2 * loopi] = poly.index + 1
, and I shuffled the face index to make it easier to visualize(the colors of adjacent faces may be almost the same under 256 different colors):
import cv2
import numpy as np
path_img_idx = "UVMap_TriFaceIndex_01.exr"
img_idx = cv2.imread(path_img_idx, -1)
img_idx = img_idx[:, :, 0].astype(np.int32)
max_idx = np.max(img_idx)
lut = np.arange(1, max_idx + 1)
np.random.shuffle(lut)
lut = np.array([0, *lut]).astype(np.int32) # 0 for background
img_idx = lut[img_idx] # https://stackoverflow.com/a/67765996/10636347
img_idx = (img_idx / max_idx * 255).astype(np.uint8)
img_idx_vis = cv2.applyColorMap(img_idx, cv2.COLORMAP_JET)
cv2.imwrite(path_img_idx[:-4] + "_vis.png", img_idx_vis)