Ë
    :vžjµ)  ã                   óx   — d dl Z d dlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZ  G d„ d	e	«      Zd
„ Zdd„Zy)é    Né   )ÚcachingÚgroupingÚutilé   )Úcolor)ÚVisuals)ÚPBRMaterialÚSimpleMaterialÚempty_materialc                   óš   — e Zd Zdd„Zd„ Zed„ «       Zed„ «       Zd„ Zed„ «       Z	e	j                  d„ «       Z	dd	„Zd
„ Zd„ Zd„ Zd„ Zd„ Zy)ÚTextureVisualsNc                 ó$  — t        j                  «       | _        t        j                  | j                  j                  «      | _        || _        |€2|€t        «       | _        || _
        yt        |¬«      | _        || _
        y|| _        || _
        y)aÇ  
        Store a single material and per-vertex UV coordinates
        for a mesh.

        If passed UV coordinates and a single image it will
        create a SimpleMaterial for the image.

        Parameters
        --------------
        uv : (n, 2) float
          UV coordinates for the mesh
        material : Material
          Store images and properties
        image : PIL.Image
          Can be passed to automatically create material
        N)Úimage)r   Ú	DataStoreÚvertex_attributesÚCacheÚ__hash__Ú_cacheÚuvr   Úmaterialr   Úface_materials)Úselfr   r   r   r   s        úg/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/visual/texture.pyÚ__init__zTextureVisuals.__init__   s‚   € ô& ")×!2Ñ!2Ó!4ˆÔä—m‘m D×$:Ñ$:×$CÑ$CÓDˆŒð ˆŒàÐØˆ}Ü .Ó 0�”ð -ˆÕô !/°UÔ ;�”ð
 -ˆÕð %ˆDŒMà,ˆÕó    c                 ó8   — | j                   j                  «        y)z[
        Dump the cache if anything in self.vertex_attributes
        has changed.
        N)r   Úverify©r   s    r   Ú_verify_hashzTextureVisuals._verify_hash2   s   € ð
 	�‰×ÑÕr   c                  ó   — y)z™
        Return the type of visual data stored

        Returns
        ----------
        kind : str
          What type of visuals are defined
        Útexture© r   s    r   ÚkindzTextureVisuals.kind9   s   € ð r   c                 ó"   — | j                   du}|S )z•
        Check if any data is stored

        Returns
        ----------
        defined : bool
          Are UV coordinates and images set?
        N)r   )r   Úoks     r   ÚdefinedzTextureVisuals.definedE   s   € ð �]‰] $Ð&ˆØˆ	r   c                 ó6   — | j                   j                  «       S )z›
        Get a CRC of the stored data.

        Returns
        --------------
        crc : int
          Hash of items in self.vertex_attributes
        )r   r   r   s    r   r   zTextureVisuals.__hash__R   s   € ð ×%Ñ%×.Ñ.Ó0Ð0r   c                 ó:   — | j                   j                  dd«      S )z�
        Get the stored UV coordinates.

        Returns
        ------------
        uv : (n, 2) float or None
          Pixel position per-vertex.
        r   N)r   Úgetr   s    r   r   zTextureVisuals.uv]   s   € ð ×%Ñ%×)Ñ)¨$°Ó5Ð5r   c                 ó¤   — |€| j                   j                  d«       yt        j                  |t        j                  ¬«      | j                   d<   y)z­
        Set the UV coordinates.

        Parameters
        --------------
        values : (n, 2) float or None
          Pixel locations on a texture per- vertex
        Nr   ©Údtype)r   ÚpopÚnpÚ
asanyarrayÚfloat64)r   Úvaluess     r   r   zTextureVisuals.uvi   s<   € ð ˆ>Ø×"Ñ"×&Ñ& tÕ,ä+-¯=©=¸ÄrÇzÁzÔ+RˆD×"Ñ" 4Ò(r   c                 óÌ   — |€| j                   }|�|j                  «       }t        || j                  j                  «       t        j                  | j                  «      ¬«      }|S )zÁ
        Return a copy of the current TextureVisuals object.

        Returns
        ----------
        copied : TextureVisuals
          Contains the same information in a new object
        )r   r   r   )r   Úcopyr   r   r   )r   r   Úcopieds      r   r4   zTextureVisuals.copyx   sX   € ð ˆ:Ø—‘ˆBØˆ>Ø—‘“ˆBÜØØ—]‘]×'Ñ'Ó)ÜŸ9™9 T×%8Ñ%8Ó9ô
ˆð ˆr   c                 ó|   — | j                   j                  | j                  «      }t        j                  |¬«      }|S )zì
        Convert textured visuals to a ColorVisuals with vertex
        color calculated from texture.

        Returns
        -----------
        vis : trimesh.visuals.ColorVisuals
          Contains vertex color from texture
        )Úvertex_colors)r   Úto_colorr   r   ÚColorVisuals)r   ÚcolorsÚviss      r   r8   zTextureVisuals.to_color�   s1   € ð —‘×'Ñ'¨¯©Ó0ˆä× Ñ ¨vÔ6ˆØˆ
r   c                 óê   — | j                   �Xt        j                  | j                  j                  |   j                  «       «      }| j                  | j                   |   «      S | j                  «       S )z
        Get a copy of
        )r   r/   ÚuniqueÚmeshÚfacesÚflattenr4   )r   Ú
face_indexÚindicess      r   Úface_subsetzTextureVisuals.face_subset�   sV   € ð �7‰7ÐÜ—i‘i §	¡	§¡°
Ñ ;× CÑ CÓ EÓFˆGØ—9‘9˜TŸW™W WÑ-Ó.Ð.à—9‘9“;Ðr   c                 óJ  — i }| j                   j                  «       D ]  \  }}t        |«      dk(  rŒ	 ||   ||<   Œ | j                   j                  «        | j                   j                  |«       y# t        $ r& t        j
                  j                  d|› d�«       Y Œ„w xY w)zâ
        Apply a mask to remove or duplicate vertex properties.

        Parameters
        ------------
        mask : (len(vertices),) bool or (n,) int
          Mask which can be used like: `vertex_attribute[mask]`
        r   zfailed to update visual: `Ú`N)	r   ÚitemsÚlenÚBaseExceptionr   ÚlogÚwarningÚclearÚupdate)r   ÚmaskÚupdatesÚkeyÚvalues        r   Úupdate_verticeszTextureVisuals.update_vertices§   sž   € ð ˆØ×0Ñ0×6Ñ6Ö8‰JˆC�ä�5‹z˜QŠØðFà$ T™{�˜’ð 9ð 	×Ñ×$Ñ$Ô&à×Ñ×%Ñ% gÕ.øô !ò Fä—‘× Ñ Ð#=¸c¸UÀ!Ð!DÖEðFús   ³A3Á3,B"Â!B"c                  ó   — y)zq
        Apply a mask to remove or duplicate face properties,
        not applicable to texture visuals.
        Nr#   )r   rM   s     r   Úupdate_faceszTextureVisuals.update_facesÁ   s   � r   c                 ó    — ddl m}  || |«      S )af  
        Concatenate this TextureVisuals object with others
        and return the result without modifying this visual.

        Parameters
        -----------
        others : (n,) Visuals
          Other visual objects to concatenate

        Returns
        -----------
        concatenated : TextureVisuals
          Concatenated visual objects
        r   )Úconcatenate)ÚobjectsrU   )r   ÚothersrU   s      r   rU   zTextureVisuals.concatenateÇ   s   € õ 	)á˜4 Ó(Ð(r   )NNNN)N)Ú__name__Ú
__module__Ú__qualname__r   r    Úpropertyr$   r'   r   r   Úsetterr4   r8   rC   rQ   rS   rU   r#   r   r   r   r      s†   „ ó$-òLð ñ	ó ð	ð ñ
ó ð
ò	1ð ñ	6ó ð	6ð ‡Y�YñSó ðSóò*ò ò/ò4ó)r   r   c                 óÒ  — |j                  dd«      }|�r| g}| j                  «       }|j                  t        j                  |dz   «      «       |D ]Ó  }t        j
                  d|dz   fdt        j                  ¬«      }t        t        d«      | j                  |j                  «      D ]  \  }}	}
|
||   |	<   Œ t        j                  |dk7  |t        j                  «      }|j                  t        j                  |d¬«      j                  t        j                  «      «       ŒÕ |S t        j                  | «      j                  d«      g}|D ]5  }|j                  t        j                  |«      j                  d«      «       Œ7 t        j                   |«      }t#        j$                  |«      \  }}||   }|d	d	…df   j'                  «       }||   }t        j(                  t+        |«      t        j                  ¬«      }t        j                  t+        |«      «      ||<   ||   j                  d| j,                  d   f«      }|g}|j/                  |j                  «       |S )
a¿  
    Textured meshes can come with faces referencing vertex
    indices (`v`) and an array the same shape which references
    vertex texture indices (`vt`) and sometimes even normal (`vn`).

    Vertex locations with different values of any of these can't
    be considered the "same" vertex, and for our simple data
    model we need to not combine these vertices.

    Parameters
    -------------
    faces : (n, d) int
      References vertex indices
    *args : (n, d) int
      Various references of corresponding values
      This is usually UV coordinates or normal indexes
    maintain_faces : bool
      Do not alter original faces and return no-op masks.

    Returns
    -------------
    new_faces : (m, d) int
      New faces for masked vertices
    mask_v : (p,) int
      A mask to apply to vertices
    mask_* : (p,) int
      A mask to apply to vt array to get matching UV coordinates
      Returns as many of these as args were passed
    Úmaintain_facesFr   é   éÿÿÿÿr,   r   )ÚaxisN)r*   ÚmaxÚappendr/   ÚarangeÚfullÚint64ÚzipÚrangeÚTÚwhereÚnanÚ	nanmedianÚastyper0   ÚreshapeÚcolumn_stackr   Úunique_rowsÚargsortÚzerosrG   ÚshapeÚextend)r?   ÚargsÚkwargsr^   ÚresultÚmax_idxÚargÚmasksÚiÚfÚaÚ	masks_nanÚ	stackableÚstackr=   ÚinverseÚpairsÚorderÚremapÚ	new_facess                       r   Úunmerge_facesr†   Û   sû  € ð@ —Z‘ZÐ 0°%Ó8€Nò à�ˆà—)‘)“+ˆà�‰”b—i‘i ¨!¡Ó,Ô-ó ˆCô —G‘G˜Q ¨!¡Ð,¨b¼¿¹ÔAˆEäœu Q›x¨¯©°#·%±%Ö8‘��1�aØ��a‘˜’ð 9ô Ÿ™ ¨"¡¨e´R·V±VÓ<ˆIØ�M‰Mœ"Ÿ,™, y°qÔ9×@Ñ@ÄÇÁÓJÕKð ð  ˆô —‘˜uÓ%×-Ñ-¨bÓ1Ð2€Ió ˆØ×ÑœŸ™ sÓ+×3Ñ3°BÓ7Õ8ð ô �O‰O˜IÓ&€Eô ×*Ñ*¨5Ó1�O€FˆGð �&‰M€Eà’!�Q�$‰K×ÑÓ!€Eà�%‰L€Eô
 �H‰H”S˜“Z¤r§x¡xÔ0€EÜ—9‘9œS ›ZÓ(€Eˆ%�Lð �g‘×&Ñ&¨¨E¯K©K¸©NÐ';Ó<€Ið ˆ[€FØ
‡M�M�%—'‘'Ôà€Mr   c                 óÞ  — t        j                  | j                  t         j                  ¬«      }dt        j                  t        j
                  |«      «      z  j                  t         j                  «      }|r6t        j                  dt         j                  ¬«      |j                  «       z  }||k7  j                  «       r| j                  t        |«      |¬«      S | j                  «       S )aF  
    Resize a PIL image so every dimension is a power of two.

    Parameters
    ------------
    image : PIL.Image
      Input image
    resample : int
      Passed to Image.resize
    square : bool
      If True, upsize to a square image

    Returns
    -------------
    resized : PIL.Image
      Input image resized
    r,   r   )Úresample)r/   ÚarrayÚsizerf   ÚceilÚlog2rm   Úonesrb   ÚanyÚresizeÚtupler4   )r   rˆ   ÚsquarerŠ   Únew_sizes        r   Úpower_resizer“   >  s¢   € ô& �8‰8�E—J‘J¤b§h¡hÔ/€Dð ”R—W‘WœRŸW™W T›]Ó+Ñ+×3Ñ3´B·H±HÓ=€Hñ Ü—7‘7˜1¤B§H¡HÔ-°·±³Ñ>ˆð 	�Ñ×ÑÔØ�|‰|œE (›O°hˆ|Ó?Ð?à�:‰:‹<Ðr   )r   F)r4   Únumpyr/   Ú r   r   r   r   Úbaser	   r   r
   r   r   r   r†   r“   r#   r   r   Ú<module>r—      s8   ðÛ ã ç &Ñ &Ý Ý ß AÑ AôM)�Wô M)ò``ôF r   