§
    ÎÐj�.  ã                  ó°   — d Z ddlmZ ddlZ ej        ej        ¦  «        j        ZdZd"d„Z	d#d„Z
d$d„Zd%d„Zd&d„Zd'd„Zddœd(d„Zddœd)d„Zddœd*d!„ZdS )+aÓ  Exact triangle rasterizer in pure PyTorch (any device), with a z-buffer, perspective-correct barycentrics and UV-space
rasterization for texture baking.

Conventions (those of nvdiffrast, also followed by Hunyuan3D's custom_rasterizer):
- Inputs are clip-space vertices (x, y, z, w) after the projection matrix. Pixel (row r, column c) of an H x W image is the
  sample at NDC x = (2c + 1) / W - 1, y = (2r + 1) / H - 1: row 0 is NDC y = -1, so images of a camera with +Y up come
  out upside down (render.py flips them). custom_rasterizer puts NDC -1 / +1 on the first / last pixel centres instead:
  scale clip x by (W - 1) / W and clip y by (H - 1) / H to reproduce it.
- A pixel is covered by a face when its sample lies inside the triangle or on its edges and its depth z / w is within
  [-1, 1] (near / far planes). The nearest z / w wins; equal depths keep the smallest face id. There is no culling of
  back faces.
- Coverage uses the 2D homogeneous edge functions of Olano & Greer (1997) in float64: triangles crossing the camera plane
  (w <= 0) are rasterized correctly without clipping, and the edge functions of a shared edge are exact opposites, so
  neighbouring faces leave no cracks and overlap only on samples exactly on their common edge.
- Outputs: face_id int32 (-1 where empty), barycentrics float32 (weights of the face's corners 0, 1, 2, perspective
  correct, summing to 1, zero where empty) and depth float32 (z / w of the visible surface, zero where empty).

Work is bounded: faces are set up in chunks, and the pixels of their bounding boxes are enumerated in chunks of
`chunk_size` candidates (about 150 bytes each, so ~150 MiB at the default 1M); the z-buffer is one int64 per pixel (min of packed (depth, face id)).
é    )ÚannotationsNi   Úreturnútuple[int, int]c                óˆ   — t          | t          ¦  «        r| | fn)t          | d         ¦  «        t          | d         ¦  «        fS )Nr   é   )Ú
isinstanceÚint)Ú
resolutions    ú<C:\Users\johnn\OneDrive\Documents\AI\shared\mesh3d\raster.pyÚ_resolutionr      sC   € Ý'1°*½cÑ'BÔ'BÐpˆJ˜
Ð#Ð#ÍÈZÐXYÌ]ÑI[ÔI[Õ]`ÐakÐlmÔanÑ]oÔ]oÐHpÐpó    Úcornersútorch.Tensorú!tuple[torch.Tensor, torch.Tensor]c           	     óJ  — | d         | d         | d         }}}|                      dd¦  «        |                      dd¦  «        |                      dd¦  «        |                      dd¦  «        |                      dd¦  «        |                      dd¦  «        f\  }}}}}}	t          j        ||	z  ||z  z
  ||z  ||	z  z
  ||z  ||z  z
  gd¦  «        }
|
|
dd…ddf         |dd…df         z  |
dd…ddf         |dd…df         z  z   |
dd…dd	f         |dd…df         z  z   fS )
z¯corners [N, 3, 4] clip coordinates -> edge functions n [N, 3, 3] (coefficients of x, y, 1 in NDC; n_i vanishes on
    the edge opposite corner i) and det [N] (n_i . corner_i).©.r   ©.r   ©.é   éÿÿÿÿr   éþÿÿÿNr   é   )ÚrollÚtorchÚstack)r   ÚxÚyÚwÚx1Úy1Úw1Úx2Úy2Úw2Úns              r   Ú_edge_planesr&   "   sE  € ð �fŒo˜w vœ°¸´ˆ!€q€AØŸVšV B¨™]œ]¨A¯FªF°2°q©M¬M¸1¿6º6À"Àa¹=¼=È!Ï&Ê&ÐQSÐUVÉ-Ì-ÐYZ×Y_ÒY_Ð`bÐdeÑYfÔYfÐhi×hnÒhnÐoqÐstÑhuÔhuÐuÑ€BˆˆB��B˜ÝŒ�R˜"‘W˜r B™wÑ&¨¨R©°"°r±'Ñ(9¸2À¹7ÀRÈ"ÁWÑ;LÐMÈrÑRÔR€AØˆa����1�a�Œj˜1˜Q˜Q˜Q ˜Tœ7Ñ" Q q q q¨!¨Q w¤Z°!°A°A°A°q°D´'Ñ%9Ñ9¸A¸a¸a¸aÀÀA¸g¼JÈÈ1È1È1ÈaÈ4ÌÑ<PÑPÐPÐPr   ÚpixelsÚwidthr	   Úheightc                óº   — |                       |d¬¦  «        | |z  }}d|z  dz                        ¦   «         |z  dz
  d|z  dz                        ¦   «         |z  dz
  fS )NÚfloor©Úrounding_moder   r   )ÚdivÚdouble)r'   r(   r)   ÚrowsÚcolss        r   Ú_pixel_centersr2   +   sg   € Ø—’˜E°�Ñ9Ô9¸6ÀE¹>ˆ$€DØ�‰H�q‰L× Ò Ñ"Ô" UÑ*¨QÑ.°°T±¸A±×0EÒ0EÑ0GÔ0GÈ&Ñ0PÐSTÑ0TÐTÐTr   Údepthc                óÀ   — | dz                         t          j        ¦  «        }t          j        |dk     |dz  |¦  «                             t          j        ¦  «        dz  S )zWfloat32 depths -> int64 keys whose high 32 bits sort like the depths (-0 counts as +0).ç        r   iÿÿÿé    )Úviewr   Úint32ÚwhereÚtoÚint64)r3   Úbitss     r   Ú_depth_keysr=   0   sM   € à�C‰K×Ò�eœkÑ*Ô*€DÝŒ;�t˜a’x ¨
Ñ!2°DÑ9Ô9×<Ò<½U¼[ÑIÔIÈRÑOÐOr   ÚclipÚfacesc           	     ó‚  — | |                               ¦   «         }|                     d¦  «        \  }}}}t          |¦  «        \  }	}
|
dk    |dk                         d¦  «        z  }||f| |f||f| |f||f| |ffD ]"\  }}|||k                         d¦  «         z  }Œ#|                     ¦   «                              d¦  «        }||         |	|         |
|         ||         f\  }}	}
}t          j        |	|
 	                    ¦   «         dd…ddf         z  t          j
        d||	¦  «        |
dd…df         z  dd…df         gd¦  «        }|d         |d         z   }|                     dd¦  «        |                     dd¦  «        }}|dk    |dk    k    }|t          j        |||z
  d¦  «        z  d	         }t          j        |||||z
  z  z   gd¦  «        }t          j        |dk    |gd¦  «        }|d         }||dk    z                       d¦  «        }||dk    z  }|d
dd…f         t          j        ||d¦  «        d	         z  }t          j        t          d¦  «        t          j        | j        ¬¦  «        }t          j        |d	         ||¦  «                             d¦  «        }t          j        |d	         || ¦  «                             d¦  «        }t          j        |dd…df         | |¦  «        }t          j        |dd…df         ||¦  «        }t          j        ||gt          j        | j        ¬¦  «        }t          j        |dz   |z  dz
  dz  dz
  ¦  «                             dt+          ||¦  «        ¦  «                             ¦   «         }t          j        t          j        |dz   |z  dz
  dz  dz   ¦  «                             dt+          ||¦  «        ¦  «        |dz
  ¦  «                             ¦   «         }||k                         d¦  «        } ||          ||          ||          ||          fS )z°Face ids kept, their [n, 4, 3] planes (3 oriented edge functions + depth z/w, as coefficients of NDC x, y, 1) and
    their pixel bounding boxes (first and last (column, row)).r   r   r   Nz
fi,fic->fc©.r   r   g      ð?©.N.r   Úinf©ÚdtypeÚdeviceg�íµ ÷Æ°>)r/   Úunbindr&   ÚanyÚallÚnonzeroÚsqueezer   ÚcatÚsignÚeinsumr   r9   ÚtensorÚfloatÚfloat64rF   ÚaminÚamaxÚceilÚclampÚmaxÚlongÚminimumr+   )!r>   r?   r(   r)   r   r   r   Úzr   r%   ÚdetÚkeepÚvalueÚboundÚidsÚplanesÚnearÚ	followingÚnear_followingÚcrossingÚtÚpointsÚvalidÚpwÚ	unboundedÚndcÚbigÚlowÚhighÚsizeÚfirstÚlastÚinsides!                                    r   Ú_setuprq   6   s)  € ð �5Œk× Ò Ñ"Ô"€GØ—’ Ñ#Ô#�J€A€qˆ!ˆQÝ˜'Ñ"Ô"�F€A€sØ�1ŠH˜˜QšŸš A™œÑ&€DØ˜Q˜ 1 " a ¨1¨a¨&°A°2°q°'¸A¸q¸6ÀQÀBÈÀ7ÐKð (ð (‰ˆˆuØ�%˜%’-×$Ò$ QÑ'Ô'Ð'Ñ'ˆˆØ
�,Š,‰.Œ.×
 Ò
  Ñ
#Ô
#€CØ  œ q¨¤v¨s°3¬x¸¸3¼Ð?Ñ€GˆQ��QÝŒY˜˜CŸHšH™JœJ q q q¨$° }Ô5Ñ5½¼À\ÐSTÐVWÑ8XÔ8XÐ[^Ð_`Ð_`Ð_`ÐbfÐ_fÔ[gÑ8gÐijÐijÐijÐlpÐipÔ7qÐrÐtuÑvÔv€Fð �6Œ?˜W Vœ_Ñ,€DØ '§¢¨R°Ñ 3Ô 3°T·Y²Y¸rÀ1Ñ5EÔ5Eˆ~€IØ˜’	˜~°Ò2Ò3€HØ	•”˜H d¨^Ñ&;¸SÑAÔAÑ	AÀ9ÔM€AÝŒY˜ ¨1°	¸GÑ0CÑ+DÑ!DÐEÀqÑIÔI€FÝŒI�t˜q’y (Ð+¨QÑ/Ô/€EØ	�Œ€BØ˜" š'Ñ"×'Ò'¨Ñ*Ô*€IØ	ˆR�!ŠV�O€EØ
��b�q�b�Œ/�EœK¨¨r°3Ñ7Ô7¸	ÔBÑ
B€CÝ
Œ,•u˜U‘|”|­5¬=ÀÄÐ
MÑ
MÔ
M€CÝ
Œ+�e˜IÔ&¨¨SÑ
1Ô
1×
6Ò
6°qÑ
9Ô
9€CÝŒ;�u˜YÔ'¨¨s¨dÑ3Ô3×8Ò8¸Ñ;Ô;€DÝ
Œ+�i    4 Ô(¨3¨$°Ñ
4Ô
4€CÝŒ;�y    D Ô)¨3°Ñ5Ô5€DÝŒ<˜ ˜­u¬}ÀTÄ[ÐQÑQÔQ€DÝŒJ˜˜q™ DÑ(¨1Ñ,°Ñ1°DÑ8Ñ9Ô9×?Ò?ÀÅ3ÀuÈfÑCUÔCUÑVÔV×[Ò[Ñ]Ô]€EÝŒ=�œ t¨a¡x°4Ñ&7¸!Ñ&;¸qÑ%@À4Ñ%GÑHÔH×NÒNÈrÕSVÐW\Ð^dÑSeÔSeÑfÔfÐhlÐopÑhpÑqÔq×vÒvÑxÔx€DØ�eŠm× Ò  Ñ#Ô#€FØˆvŒ;˜˜vœ¨¨f¬°t¸F´|ÐCÐCr   Ú
chunk_sizec                ó´
  ‡'— | j         }t          |¦  «        dk    r>|                     d¦  «        |                     ¦   «         |                     ¦   «         f dS t	          j        ||z  ft          t          j        |¬¦  «        }	t          dt          |¦  «        t          ¦  «        D �]Ò}
t          | ||
|
t          z   …         ||¦  «        \  }Š'}}t          |¦  «        dk    rŒ>||
z  }ˆ'fd„t          d¦  «        D ¦   «         Š'|dd…df         |dd…df         z
  dz   }||dd…df         |dd…df         z
  dz   z  }|                     d¦  «        }||z
  t          |d         ¦  «        }}t          d||¦  «        D �]÷}t	          j        |t	          j        |t          ||z   |¦  «        |¬¦  «        d	¬
¦  «        }t	          j        ||t          |¦  «        z   |¬¦  «        ||         z
  }|                     ||         d¬¦  «        }||||         z  z
  ||df         z   }|||df         z  }d|z  dz                        ¦   «         |z  dz
  }d|z  dz                        ¦   «         |z  dz
  }d}‰'dd…         D ]C}||         }|dd…df         |z  |dd…df         |z  z   |dd…df         z   dk    }|€|n||z  }ŒD‰'d         |         }|dd…df         |z  |dd…df         |z  z   |dd…df         z                        ¦   «         }t	          j        ||                     ¦   «         dk    z  t+          |¦  «        ||         z  t          ¦  «        }|	                     d||z  |z   |d¦  «         �Œù�ŒÔt/          |dz  d¦  «        } t          d||z  | ¦  «        D �]³}|	||| z   …         }|t          k    }!t	          j        |!|dz  d¦  «        }| ||                                       ¦   «         }"t1          |"¦  «        \  }#}$t3          t	          j        ||t          |¦  «        z   |¬¦  «        ||¦  «        \  }}|#d         |dd…df         z  |#d         |dd…df         z  z   |#d         z   }%|%|%                     dd	¬¦  «        z  }&t	          j        |!|d¦  «        |||t          |¦  «        z   …<   t	          j        |!dd…df         |&d¦  «        |||t          |¦  «        z   …<   t	          j        |!|&|"d         z                       d¦  «        |&|"d         z                       d¦  «        z  d¦  «        |||t          |¦  «        z   …<   �ŒµdS )z]Rasterizes one view into the flat outputs face_id [H * W], bary [H * W, 3] and depth [H * W].r   r   NrD   c                óL   •— g | ] }‰d d …|f                               ¦   «         ‘Œ!S )N)Ú
contiguous)Ú.0Újr_   s     €r   ú
<listcomp>z#_rasterize_view.<locals>.<listcomp>f   s1   ø€ Ð>Ð>Ð>°�&˜˜˜˜A˜”,×)Ò)Ñ+Ô+Ð>Ð>Ð>r   é   r   )rF   T)Úrightr+   r,   r   r   rR   l   ÿÿ r   r   rA   )Úkeepdimr5   r   )rF   ÚlenÚfill_Úzero_r   ÚfullÚEMPTYr;   ÚrangeÚ
FACE_CHUNKrq   Úcumsumr	   ÚsearchsortedÚarangeÚminr.   r/   rP   r9   Úabsr=   Úscatter_reduce_rV   r&   r2   Úsum)(r>   r?   r)   r(   rr   Úface_idÚbaryr3   rF   ÚzbufferÚstartr^   rn   ro   Ú	box_widthÚcountsÚendsÚstartsÚtotalÚoffsetÚfaceÚlocalÚrowÚcolr   r   ÚhitÚplaneÚcoefficientsrp   rY   ÚkeysÚstepÚcoveredr   r%   Ú_ÚedgesÚweightsr_   s(                                          @r   Ú_rasterize_viewr¡   Z   sÒ  ø€ àŒ[€FÝ
ˆ5�z„z�Q‚€Ø�Š�bÑÔ˜4Ÿ:š:™<œ<¨¯ª©¬Ð6Ð6ØˆÝŒj˜& 5™.Ð*­E½¼ÈVÐTÑTÔT€GÝ�q�#˜e™*œ*¥jÑ1Ô1ð Hñ HˆÝ#)¨$°°e¸EÅJÑ<NÐ6NÔ0OÐQVÐX^Ñ#_Ô#_Ñ ˆˆV�U˜DÝˆs‰8Œ8�qŠ=ˆ=ØØˆu‰ˆØ>Ð>Ð>Ð>µU¸1±X´XÐ>Ñ>Ô>ˆØ˜˜˜˜A˜”J  q q q¨! t¤Ñ,¨qÑ0ˆ	Ø˜d 1 1 1 a 4œj¨5°°°°A°¬;Ñ6¸Ñ:Ñ;ˆØ�}Š}˜QÑÔˆØ˜v™¥s¨4°¬8¡}¤}�ˆÝ˜A˜u jÑ1Ô1ð 	Hñ 	HˆFåÔ% d­E¬L¸ÅÀVÈjÑEXÐZ_ÑA`ÔA`ÐioÐ,pÑ,pÔ,pÐx|Ð}Ñ}Ô}ˆDÝ”L ¨µ#°d±)´)Ñ);ÀFÐKÑKÔKÈfÐUYÌlÑZˆEØ—)’)˜I dœO¸7�)ÑCÔCˆCØ˜# 	¨$¤Ñ/Ñ/°%¸¸a¸´.Ñ@ˆCØ�5˜˜q˜”>Ñ!ˆCØ�S‘˜1‘×$Ò$Ñ&Ô&¨Ñ.°Ñ2ˆAØ�S‘˜1‘×$Ò$Ñ&Ô&¨Ñ/°!Ñ3ˆAØˆCØ   œð >ð >�Ø$ Tœ{�Ø% a a a¨ dÔ+¨aÑ/°,¸q¸q¸qÀ!¸tÔ2DÀqÑ2HÑHÈ<ÐXYÐXYÐXYÐ[\ÐX\ÔK]Ñ]ÐabÒb�Ø # �f�f°°v±��Ø! !œ9 Tœ?ˆLØ˜a˜a˜a ˜dÔ# aÑ'¨,°q°q°q¸!°tÔ*<¸qÑ*@Ñ@À<ÐPQÐPQÐPQÐSTÐPTÔCUÑU×\Ò\Ñ^Ô^ˆAÝ”;˜s a§e¢e¡g¤g°¢lÑ3µ[À±^´^ÀcÈ$ÄiÑ5OÕQVÑWÔWˆDØ×#Ò# A s¨U¡{°SÑ'8¸$ÀÑGÔGÐGÑGñ#	Hõ$ ˆz˜Q‰ Ñ"Ô"€DÝ˜˜6 E™>¨4Ñ0Ô0ð Mñ MˆØ�f˜V d™]Ð*Ô+ˆØ�’,ˆÝŒk˜' 3¨Ñ#3°QÑ7Ô7ˆØ�u˜S”zÔ"×)Ò)Ñ+Ô+ˆÝ˜GÑ$Ô$‰ˆˆ1Ý�eœl¨6°6½CÀ¹H¼HÑ3DÈVÐTÑTÔTÐV[Ð]cÑdÔd‰ˆˆ1Ø�&”	˜A˜a˜a˜a ˜gœJÑ&¨¨6¬°Q°q°q°q¸$°w´ZÑ)?Ñ?À!ÀFÄ)ÑKˆØ˜%Ÿ)š) A¨t˜)Ñ4Ô4Ñ4ˆÝ,1¬K¸ÀÀbÑ,IÔ,Iˆ��v¥ C¡¤Ñ(Ð(Ñ)Ý).¬°W¸Q¸Q¸QÀ¸WÔ5EÀwÐPSÑ)TÔ)TˆˆV�F�S ™XœXÑ%Ð%Ñ&Ý*/¬+°gÀÈ'ÐRXÌ/Ñ@Y×?^Ò?^Ð_`Ñ?aÔ?aÐelÐovÐw}Ôo~Ñe~÷  eDò  eDð  EFñ  eGô  eGñ  @Gð  ILñ  +Mô  +Mˆˆf�V�c #™hœhÑ&Ð&Ñ'Ñ'ðMð Mr   i   ©rr   Úclip_verticesc               ó   — t          |¦  «        \  }}| j        dk    r| d         n| }|j        |                     ¦   «         }}t	          j        t          |¦  «        ||t          j        |¬¦  «        }t	          j        t          |¦  «        ||dt          j        |¬¦  «        }	t	          j        t          |¦  «        ||t          j        |¬¦  «        }
t          |¦  «        D ]g\  }}t          |||||||                              d¦  «        |	|                              dd¦  «        |
|                              d¦  «        ¦  «         Œh||	|
fS )a›  Rasterizes triangles given in clip space (see the module docstring for the conventions).

    clip_vertices: [V, 4] or [B, V, 4] (one view per batch item, shared faces); faces [F, 3] integer; resolution: int or
    (height, width). Returns face_id [B, H, W] int32 (-1 = empty), bary [B, H, W, 3] float32 and depth [B, H, W] float32
    (z / w), on the device of clip_vertices (faces must be on the same device).r   NrD   r   r   )r   ÚndimrF   rW   r   Úemptyr|   r8   Úfloat32Ú	enumerater¡   r7   )r£   r?   r
   rr   r)   r(   ÚviewsrF   rŠ   r‹   r3   Úbr7   s                r   Ú	rasterizer«   Œ   s6  € õ   
Ñ+Ô+�M€FˆEØ#0Ô#5¸Ò#:Ð#:ˆM˜$ÔÐÀ€EØ”L %§*¢*¡,¤,ˆE€FÝŒk�#˜e™*œ* f¨e½5¼;ÈvÐVÑVÔV€GÝŒ;•s˜5‘z”z 6¨5°!½5¼=ÐQWÐXÑXÔX€DÝŒK�˜E™
œ
 F¨E½¼ÈvÐVÑVÔV€EÝ˜UÑ#Ô#ð }ð }‰ˆˆ4Ý˜˜e V¨U°JÀÈÄ
ÇÂÐPRÑ@SÔ@SÐUYÐZ[ÔU\×UaÒUaÐbdÐfgÑUhÔUhÐjoÐpqÔjr×jwÒjwÐxzÑj{Ôj{Ñ|Ô|Ð|Ð|Ø�D˜%ÐÐr   Ú
attributesrŠ   r‹   c               óØ  — |j         dk    }|r|d         |d         }}t          j        | j        t          j        ¦  «        }t          j        g |j        ¢| j        d         ‘R ||j        dœŽ}|                     ¦   «         }t          |j        d         ¦  «        D �]B}| j         dk    r| |         n| }	||          
                    d¦  «        ||          
                    dd¦  «        ||                              d|j        d         ¦  «        }}}
|
dk                         ¦   «                              d¦  «        }t          dt          |¦  «        |¦  «        D ]‚}||||z   …         }|	||
|                              ¦   «                                                |¦  «        }||                              |¦  «        d         |z                       d¦  «        ||<   Œƒ�ŒD|r|d         n|S )	a<  Per-pixel attributes sum_k bary[k] * attributes[faces[face_id, k]], zero where face_id < 0.

    attributes [V, C] (shared) or [B, V, C] (per view); face_id [B, H, W] with bary [B, H, W, 3], or unbatched [H, W] with
    [H, W, 3] (then the result is [H, W, C]). Computed in float32 (float64 attributes stay float64).r   Nr   rD   r   r   r   rB   )r¥   r   Úpromote_typesrE   r§   ÚzerosÚshaperF   rW   r�   Úreshaper7   rJ   rK   r|   r:   r‰   )r¬   r?   rŠ   r‹   rr   Ú	unbatchedrE   Úoutrª   Úvaluesr^   r    Útargetr�   r“   r'   r   s                    r   Úinterpolater¶   �   sß  € ð
 ” Ò!€IØð 2Ø œ t¨D¤z�ˆÝÔ 
Ô 0µ%´-Ñ@Ô@€EÝ
Œ+Ð
_�w”}Ð
_ jÔ&6°rÔ&:Ð
_Ð
_À%ÐPWÔP^Ð
_Ð
_Ð
_€CØ�JŠJ‰LŒL€EÝ�7”= Ô#Ñ$Ô$ð Uñ UˆØ",¤/°QÒ"6Ð"6�˜A”�¸JˆØ& qœz×1Ò1°"Ñ5Ô5°t¸A´w·²ÀrÈ1Ñ7MÔ7MÈsÐSTÌvÏ{Ê{Ð[]Ð_bÔ_hÐikÔ_lÑOmÔOm�fˆWˆØ˜!’8×$Ò$Ñ&Ô&×.Ò.¨qÑ1Ô1ˆÝ˜A�s 7™|œ|¨ZÑ8Ô8ð 	Uð 	UˆFØ˜V F¨ZÑ$7Ð7Ô8ˆFØ˜U 3 v¤;×#3Ò#3Ñ#5Ô#5Ô6Ô7×:Ò:¸5ÑAÔAˆGØ% fœo×0Ò0°Ñ7Ô7¸	ÔBÀWÑL×QÒQÐRSÑTÔTˆF�6‰NˆNñ	Uð Ð'ˆ3ˆqŒ6ˆ6 CÐ'r   Úuvsc          
     óX  — t          j        |                      ¦   «         dz  dz
  t          j        | dd…dd…f         t           j        ¬¦  «        t          j        | dd…dd…f         t           j        ¬¦  «        gd¦  «        }t          ||||¬¦  «        \  }}}|d         |d         fS )aª  Texture-space rasterization for baking: texel [r, c] of an (H, W) texture is the sample at uv ((c + 0.5) / W,
    (r + 0.5) / H) (glTF uvs, v downwards, see mesh.py). Returns face_id [H, W] int32 (-1 = no face) and bary [H, W, 3];
    pass them to interpolate() with any per-vertex attribute (positions, normals, colours). Seams must be duplicated
    vertices (one index buffer); overlapping charts keep the smallest face id.r   r   N)rE   r¢   r   )r   rL   rP   Ú
zeros_liker§   Ú	ones_liker«   )r·   r?   r
   rr   r>   rŠ   r‹   rž   s           r   Úrasterize_uvr»   ³   sÏ   € õ
 Œ9�c—i’i‘k”k A‘o¨Ñ)­5Ô+;¸CÀÀÀÀ2ÀAÀ2À¼JÍeÌmÐ+\Ñ+\Ô+\Õ^cÔ^mÐnqÐrsÐrsÐrsÐuwÐvwÐuwÐrwÔnxõ  AFô  ANð  _Oñ  _Oô  _Oð  Pð  RSñ  Tô  T€DÝ   u¨jÀZÐPÑPÔPÑ€GˆT�1Ø�1Œ:�t˜A”wÐÐr   )r   r   )r   r   r   r   )r'   r   r(   r	   r)   r	   r   r   )r3   r   r   r   )r>   r   r?   r   r(   r	   r)   r	   )
r>   r   r?   r   r)   r	   r(   r	   rr   r	   )r£   r   r?   r   rr   r	   )r¬   r   r?   r   rŠ   r   r‹   r   rr   r	   r   r   )r·   r   r?   r   rr   r	   r   r   )Ú__doc__Ú
__future__r   r   Úiinfor;   rV   r€   r‚   r   r&   r2   r=   rq   r¡   r«   r¶   r»   © r   r   ú<module>rÀ      sR  ððð ð( #Ð "Ð "Ð "Ð "Ð "à €€€àˆŒ�E”KÑ Ô Ô$€Ø€
ðqð qð qð qðQð Qð Qð QðUð Uð Uð Uð
Pð Pð Pð Pð!Dð !Dð !Dð !DðH/Mð /Mð /Mð /Mðd bið  ð  ð  ð  ð  ð  ð" @Gð (ð (ð (ð (ð (ð (ð, [bð ð ð ð ð ð ð ð r   