ó
    ÂèØhõ  ã                   óf   • S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  S	 r
SS
 jrSS jrg)a@  
functions about rendering mesh(from 3d obj to 2d image).
only use rasterization render here.
Note that:
1. Generally, render func includes camera, light, raterize. Here no camera and light(I write these in other files)
2. Generally, the input vertices are normalized to [-1,1] and cetered on [0, 0]. (in world space)
   Here, the vertices are using image coords, which centers on [w/2, h/2] with the y-axis pointing to oppisite direction.
 Means: render here only conducts interpolation.(I just want to make the input flexible)

Author: Yao Feng 
Mail: yaofeng1995@gmail.com
é    )Úabsolute_import)Údivision)Úprint_functionN)Útimeé   )Úmesh_core_cythonc                 óî  • [         R                  " X#/5      S-
  n[         R                  " X#/[         R                  S9S-
  n[         R                  " X#S/[         R                  S9nU R	                  [         R                  5      R                  5       n UR	                  [         R                  5      R                  5       n[        R                  " XXEUU R                  S   UR                  S   X#5	        g)a«  
Args:
    vertices: [nver, 3]
    triangles: [ntri, 3]
    h: height
    w: width
Returns:
    depth_buffer: [h, w] saves the depth, here, the bigger the z, the fronter the point.
    triangle_buffer: [h, w] saves the tri id(-1 for no triangle). 
    barycentric_weight: [h, w, 3] saves corresponding barycentric weight.

# Each triangle has 3 vertices & Each vertex has 3 coordinates x, y, z.
# h, w is the size of rendering
ç    ~„.A©Údtyper   é   r   N)	ÚnpÚzerosÚint32Úfloat32ÚastypeÚcopyr   Úrasterize_triangles_coreÚshape)ÚverticesÚ	trianglesÚhÚwÚdepth_bufferÚtriangle_bufferÚbarycentric_weights          Úc/var/www/fran/franai/venv/lib/python3.13/site-packages/insightface/thirdparty/face3d/mesh/render.pyÚrasterize_trianglesr      s¶   € ô" —8’8˜Q˜FÓ# gÑ-€LÜ—h’h ˜v¬r¯x©xÑ8¸1Ñ<€OÜŸš 1¨ )´R·Z±ZÑ@Ðà‰œrŸz™zÓ*×/Ñ/Ó1€HØ× Ñ ¤§¡Ó*×/Ñ/Ó1€Iä×-Ò-ØØÐ/AØ—‘˜qÑ! 9§?¡?°1Ñ#5Øõ	ó    c                 ó²  • Uc&  [         R                  " X4U4[         R                  S9nO=UR                  S   U:X  a&  UR                  S   U:X  a  UR                  S   U:X  d   eUn[         R                  " X4/[         R                  SS9S-
  nU R	                  [         R                  5      R                  5       n UR	                  [         R                  5      R                  5       nUR	                  [         R                  5      R                  5       n[        5       n	[        R                  " XpUUUU R                  S   UR                  S   X4U5
        U$ )zårender mesh with colors
Args:
    vertices: [nver, 3]
    triangles: [ntri, 3] 
    colors: [nver, 3]
    h: height
    w: width  
    c: channel
    BG: background image
Returns:
    image: [h, w, c]. rendered image./rendering.
r   r   r   é   ÚC©r   Úorderr
   )
r   r   r   r   r   r   r   r   r   Úrender_colors_core)
r   r   Úcolorsr   r   ÚcÚBGÚimager   Ústs
             r   Úrender_colorsr+   4   s  € ð 
zÜ—’˜! ˜¬B¯J©JÑ7‰àx‰x˜‰{˜aÓ B§H¡H¨Q¡K°1Ó$4¸¿¹À!¹ÈÓ9IÐIÐIØˆÜ—8’8˜Q˜F¬B¯J©JÀÑDÀwÑN€Lð ‰œrŸz™zÓ*×/Ñ/Ó1€HØ× Ñ ¤§¡Ó*×/Ñ/Ó1€IØ]‰]œ2Ÿ:™:Ó&×+Ñ+Ó-€Fä	‹€BÜ×'Ò'Ø ØØØ—‘˜qÑ! 9§?¡?°1Ñ#5Øaôð €Lr   c
                 óò  • U	c&  [         R                  " XVU4[         R                  S9n
O=U	R                  S   U:X  a&  U	R                  S   U:X  a  U	R                  S   U:X  d   eU	n
[         R                  " XV/[         R                  SS9S-
  nUR                  u  pÍnUS:X  a  [	        S5      nOUS	:X  a  [	        S5      nO[	        S5      nU R                  [         R                  5      R                  5       n UR                  [         R                  5      R                  5       nUR                  [         R                  5      R                  5       nUR                  [         R                  5      R                  5       nUR                  [         R                  5      R                  5       n[        R                  " X UX#UUU R                  S   UR                  S   UR                  S   XVUXÍUU5        U
$ )
a  render mesh with texture map
Args:
    vertices: [3, nver]
    triangles: [3, ntri]
    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'
r   r   r   r!   r"   r#   r
   ÚnearestÚbilinear)
r   r   r   r   Úintr   r   r   r   Úrender_texture_core)r   r   ÚtextureÚ
tex_coordsÚtex_trianglesr   r   r'   Úmapping_typer(   r)   r   Útex_hÚtex_wÚtex_cÚmts                   r   Úrender_texturer9   Y   s’  € ð 
zÜ—’˜! ˜¬B¯J©JÑ7‰àx‰x˜‰{˜aÓ B§H¡H¨Q¡K°1Ó$4¸¿¹À!¹ÈÓ9IÐIÐIØˆä—8’8˜Q˜F¬B¯J©JÀÑDÀwÑN€Là!Ÿ-™-Ñ€E%ØyÓ Ü‹V‰Ø	˜Ó	#Ü‹V‰ä‹Vˆð ‰œrŸz™zÓ*×/Ñ/Ó1€HØ× Ñ ¤§¡Ó*×/Ñ/Ó1€IØn‰nœRŸZ™ZÓ(×-Ñ-Ó/€GØ×"Ñ"¤2§:¡:Ó.×3Ñ3Ó5€JØ!×(Ñ(¬¯©Ó2×7Ñ7Ó9€Mä×(Ò(Ø Ø ]ØØ—‘˜qÑ! :×#3Ñ#3°AÑ#6¸	¿¹ÈÑ8JØaØ˜eØôð €Lr   )r   N)r   r-   N)Ú__doc__Ú
__future__r   r   r   Únumpyr   r   Úcythonr   r   r+   r9   © r   r   Ú<module>r?      s.   ðñõ 'Ý Ý %ã Ý å $òô<"õJ-r   