
    hJ                     z    S SK Jr  S SK Jr  S SK Jr  S SKrS SKrS SKJr  S SK	J	r	  SSK
Jr  S	 rS
 rS rS rS rg)    )absolute_import)division)print_functionN)io)time   )mesh_core_cythonc                     g)zread mesh
        r    )obj_names    _/var/www/fran/franai/venv/lib/python3.13/site-packages/insightface/thirdparty/face3d/mesh/io.pyread_objr      s     	
    c                     U R                  S5      S   S:X  a  [        R                  " X5        g[        R                  " U S-   U5        g)z'
Args:
    vertices: shape = (nver, 3)
.ascz.ascN)splitnpsavetxt)pathverticess     r   	write_ascr      s7    
 zz#re#


4"


4&=(+r   c                 *   UR                  5       nUS-  nU R                  S5      S   S:w  a  U S-   n [        U S5       n[        UR                  S   5       HB  nSR                  XS4   XS4   XS	4   X5S4   X5S4   X5S	4   5      nUR                  U5        MD     UR                  u  px[        UR                  S   5       H3  nS
R                  X%S	4   X%S4   X%S4   5      nUR                  U5        M5     SSS5        g! , (       d  f       g= f)zSave 3D face model with texture represented by colors.
Args:
    obj_name: str
    vertices: shape = (nver, 3)
    triangles: shape = (ntri, 3)
    colors: shape = (nver, 3)
r   r   r   obj.objwr   zv {} {} {} {} {} {}
   zf {} {} {}
N)copyr   openrangeshapeformatwrite)	r   r   	trianglescolorsfiskntris	            r   write_obj_with_colorsr,      s/     INI~~c2%'f$ 
h	 x~~a()A'..x1~x1~x[\X\~_eijfj_kmswxtxmy  |B  FG  CG  |H  IAGGAJ * OO	yq)*A%%i1oyA	UVRVXAGGAJ + 
		s   B<D
Dc                    U R                  S5      S   S:w  a  U S-   n U R                  SS5      nU R                  SS5      nUR                  5       nUS-  n[        U S5       nS	R	                  [
        R                  R                  U5      5      nUR                  U5        [        UR                  S
   5       H3  n	SR	                  XS
4   XS4   XS4   5      nUR                  U5        M5     [        UR                  S
   5       H1  n	SR	                  XIS
4   SXIS4   -
  5      nUR                  U5        M3     UR                  S5        [        UR                  S
   5       HB  n	SR	                  X)S4   X)S4   X)S4   X)S4   X)S
4   X)S
4   5      nUR                  U5        MD     SSS5        [        US5       nUR                  S5        SR	                  [
        R                  R                  U5      5      nUR                  U5        SSS5        [        Xc5        g! , (       d  f       N= f! , (       d  f       N+= f)aT  Save 3D face model with texture represented by texture map.
Ref: https://github.com/patrikhuber/eos/blob/bd00155ebae4b1a13b08bf5a991694d682abbada/include/eos/core/Mesh.hpp
Args:
    obj_name: str
    vertices: shape = (nver, 3)
    triangles: shape = (ntri, 3)
    texture: shape = (256,256,3)
    uv_coords: shape = (nver, 3) max value<=1
r   r   r   r   .mtl_texture.pngr   r   z
mtllib {}
r   zv {} {} {}
r   z	vt {} {}
zusemtl FaceTexture
zf {}/{} {}/{} {}/{}
Nnewmtl FaceTexture

map_Kd {}
)r   replacer   r    r#   osr   abspathr$   r!   r"   imsave)
r   r   r%   texture	uv_coordsmtl_nametexture_namer'   r)   r(   s
             r   write_obj_with_texturer:   =   s#    ~~c2%'f$/H##FN;L INI 
h	  !:;	
 x~~a()A%%h!tnh!tnhRStnUAGGAJ *
 yq)*A##IcNA	A#4FGAGGAJ + 	
&' yq)*A'..y1~y1~y[\Y\~_hklil_mox{|y|o}  @I  LM  JM  @N  OAGGAJ +% 
. 
h		&'  !>?	
 
 <!; 
	. 
	s   #EH'AH8'
H58
Ic                    U R                  S5      S   S:w  a  U S-   n U R                  SS5      nU R                  SS5      nUR                  5       nUS-  nUR                  [        R
                  5      R                  5       UR                  [        R
                  5      R                  5       UR                  [        R
                  5      R                  5       pSn[        R                  " [        R                  U 5      [        R                  [        R                  R                  U5      5      XX5UR                  S   UR                  S   UR                  S   5	        [        US	5       nUR                  S
5        SR!                  [        R                  R                  U5      5      n	UR                  U	5        SSS5        ["        R$                  " Xt5        g! , (       d  f       N%= f)aX  Save 3D face model with texture. 
Ref: https://github.com/patrikhuber/eos/blob/bd00155ebae4b1a13b08bf5a991694d682abbada/include/eos/core/Mesh.hpp
Args:
    obj_name: str
    vertices: shape = (nver, 3)
    triangles: shape = (ntri, 3)
    colors: shape = (nver, 3)
    texture: shape = (256,256,3)
    uv_coords: shape = (nver, 3) max value<=1
r   r   r   r   r.   r/   r   r   r   r0   r1   N)r   r2   r   astyper   float32r	   "write_obj_with_colors_texture_corestrencoder3   r   r4   r"   r    r$   r#   r   r5   )
r   r   r%   r&   r6   r7   r8   r9   r'   r)   s
             r   write_obj_with_colors_texturerA   p   s    ~~c2%'f$/H##FN;L INI #+//"**"="B"B"DfmmTVT^T^F_FdFdFfhqhxhxy{  zD  zD  iE  iJ  iJ  iLiH77

88LcjjY[Y`Y`YhYhiqYrNsu}  KQ  ^f  ^l  ^l  mn  ^o  qz  q@  q@  AB  qC  EN  ET  ET  UV  EW  X 
h		&'  !>?	
 
 IIl$ 
	s   /AG
G-)
__future__r   r   r   numpyr   r3   skimager   r   cythonr	   r   r   r,   r:   rA   r   r   r   <module>rF      s7    &  %  	   $
,>0"f%r   