
    Mi)                     z    S SK r S SKrSSKJrJrJr  SSKJr  SSKJ	r	  SSK
JrJrJr   " S S	\	5      rS
 rSS jrg)    N   )cachinggroupingutil   )color)Visuals)PBRMaterialSimpleMaterialempty_materialc                       \ rS rSrSS jrS r\S 5       r\S 5       rS r	\S 5       r
\
R                  S	 5       r
SS
 jrS rS rS rS rS rSrg)TextureVisuals   Nc                    [         R                  " 5       U l        [         R                  " U R                  R                  5      U l        Xl        Uc"  Uc  [        5       U l        O[        US9U l        OX l        X@l
        g)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        p/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/visual/texture.py__init__TextureVisuals.__init__   sh    & ")!2!2!4mmD$:$:$C$CD } . 0 !/U ; %M,    c                 8    U R                   R                  5         g)zC
Dump the cache if anything in self.vertex_attributes
has changed.
N)r   verifyr   s    r   _verify_hashTextureVisuals._verify_hash2   s    
 	r   c                     g)zi
Return the type of visual data stored

Returns
----------
kind : str
  What type of visuals are defined
texture r!   s    r   kindTextureVisuals.kind9   s     r   c                 "    U R                   SLnU$ )ze
Check if any data is stored

Returns
----------
defined : bool
  Are UV coordinates and images set?
N)r   )r   oks     r   definedTextureVisuals.definedE   s     ]]$&	r   c                 6    U R                   R                  5       $ )zk
Get a CRC of the stored data.

Returns
--------------
crc : int
  Hash of items in self.vertex_attributes
)r   r   r!   s    r   r   TextureVisuals.__hash__R   s     %%..00r   c                 :    U R                   R                  SS5      $ )zm
Get the stored UV coordinates.

Returns
------------
uv : (n, 2) float or None
  Pixel position per-vertex.
r   N)r   getr!   s    r   r   TextureVisuals.uv]   s     %%))$55r   c                     Uc  U R                   R                  S5        g[        R                  " U[        R                  S9U R                   S'   g)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   r1   i   s<     >""&&t,+-==rzz+RD""4(r   c                     Uc  U R                   nUb  UR                  5       n[        UU R                  R                  5       [        R                  " U R                  5      S9nU$ )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   r;   TextureVisuals.copyx   sX     :B>B]]'')99T%8%89
 r   c                 x    U R                   R                  U R                  5      n[        R                  " US9nU$ )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   r@   TextureVisuals.to_color   s1     ''0  v6
r   c                     U R                   bY  [        R                  " U R                  R                  U   R                  5       5      nU R                  U R                   U   5      $ U R                  5       $ )z
Get a copy of
)r   r6   uniquemeshfacesflattenr;   )r   
face_indexindicess      r   face_subsetTextureVisuals.face_subset   sV     77ii		
 ; C C EFG99TWWW-..99;r   c                 P   0 nU R                   R                  5        H  u  p4[        U5      S:X  a  M   XA   X#'   M     U R                   R                  5         U R                   R                  U5        g! [         a'    [        R
                  R                  SU S35         M  f = f)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_verticesTextureVisuals.update_vertices   s     00668JC5zQF${ 9 	$$&%%g. ! F  #=cU!!DEFs   A44-B%$B%c                     g)zY
Apply a mask to remove or duplicate face properties,
not applicable to texture visuals.
Nr&   )r   rW   s     r   update_facesTextureVisuals.update_faces   s    r   c                     SSK Jn  U" X5      $ )a  
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)objectsra   )r   othersra   s      r   ra   TextureVisuals.concatenate   s     	)4((r   )r   r   r   r   r   )NNNN)N)__name__
__module____qualname____firstlineno__r   r"   propertyr'   r+   r   r   setterr;   r@   rL   r[   r^   ra   __static_attributes__r&   r   r   r   r      s    $-L 	 	 
 
	1 	6 	6 YYS S* /4)r   r   c                    UR                  SS5      nU(       Ga  U /nU R                  5       nUR                  [        R                  " US-   5      5        U H  n[        R
                  " SUS-   4S[        R                  S9n[        [        S5      U R                  UR                  5       H  u  pn
XU   U	'   M     [        R                  " US:g  U[        R                  5      nUR                  [        R                  " USS9R                  [        R                  5      5        M     U$ [        R                  " U 5      R                  S5      /nU H7  nUR                  [        R                  " U5      R                  S5      5        M9     [        R                   " U5      n["        R$                  " U5      u  pX   nUS	S	2S4   R'                  5       nUU   n[        R(                  " [+        U5      [        R                  S9n[        R                  " [+        U5      5      UU'   UU   R                  SU R,                  S   45      nU/nUR/                  UR                  5        U$ )
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      r3   r   )axisN)r0   maxappendr6   arangefullint64ziprangeTwherenan	nanmedianastyper7   reshapecolumn_stackr   unique_rowsargsortzerosrQ   shapeextend)rH   argskwargsrm   resultmax_idxargmasksifa	masks_nan	stackablestackrF   inversepairsorderremap	new_facess                       r   unmerge_facesr      s   @ ZZ 0%8N ))+bii!,- C GGQ!,bAEuQx#%%8aa 9 "eRVV<IMM",,yq9@@JK    u%--b12I s+33B78  OOI&E **51OF ME!Q$K!E%LE
 HHSZrxx0E99SZ(E%L g&&EKKN';<I [F
MM%''Mr   c                    [         R                  " U R                  [         R                  S9nS[         R                  " [         R
                  " U5      5      -  R                  [         R                  5      nU(       a4  [         R                  " S[         R                  S9UR                  5       -  nX4:g  R                  5       (       a  U R                  [        U5      US9$ U R                  5       $ )a  
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
r3   r   )resample)r6   arraysizeru   ceillog2r|   onesrq   anyresizetupler;   )r   r   squarer   new_sizes        r   power_resizer   >  s    & 88EJJbhh/D RWWRWWT]++33BHH=H 771BHH-> 	||E(Oh|??::<r   )r   F)r;   numpyr6    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   