
    Ti)                         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dS )    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dS )TextureVisualsNc                    t          j                    | _        t          j        | j        j                  | _        || _        |,|t                      | _        nt          |          | _        n|| _        || _
        dS )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/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/visual/texture.py__init__zTextureVisuals.__init__   s|    & ")!2!4!4mD$:$CDD } . 0 0 !/U ; ; ; %DM,    c                 8    | j                                          dS )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                     dS )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	     yr   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                 4    | 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00r   c                 8    | 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55r   c                     || j                             d           dS t          j        |t          j                  | j         d<   dS )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   sJ     >"&&t,,,,,+-=rz+R+R+RD"4(((r   c                     || j         }||                                }t          || 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
        N)r   r   r   )r   copyr   r   r   )r   r   copieds      r   r4   zTextureVisuals.copyx   sa     :B>B]''))9T%899
 
 
 r   c                 n    | 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   s3     ''00 v666
r   c                     | j         Vt          j        | j        j        |                                                   }|                     | j         |                   S |                                 S )z
        Get a copy of
        )r   r/   uniquemeshfacesflattenr4   )r   
face_indexindicess      r   face_subsetzTextureVisuals.face_subset   sW     7i	
 ; C C E EFFG99TWW-...99;;r   c                 T   i }| j                                         D ]X\  }}t          |          dk    r	 ||         ||<   &# t          $ r& t          j                            d| d           Y Uw xY w| j                                          | j                             |           dS )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6688 		F 		FJC5zzQF$T{  F F F  !Dc!D!D!DEEEEEF 	$$&&&%%g.....s   A-A21A2c                     dS )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   	 	 X	 
 
 X
	1 	1 	1 	6 	6 X	6 YS S YS   *     / / /4  ) ) ) ) )r   r   c                    |                     dd          }|r| g}|                                 }|                    t          j        |dz                        |D ]}t          j        d|dz   fdt          j                  }t          t          d          | j	        |j	                  D ]\  }}	}
|
||         |	<   t          j
        |dk    |t          j                  }|                    t          j        |d                              t          j                             |S t          j        |                               d          g}|D ]<}|                    t          j        |                              d                     =t          j        |          }t#          j        |          \  }}||         }|d	d	df                                         }||         }t          j        t+          |          t          j                  }t          j        t+          |                    ||<   ||                             d| j        d         f          }|g}|                    |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      sR   @ ZZ 0%88N  ))++bi!,,---  	L 	LC GQ!,bAAAEuQxx#%88    1aa "eRV<<IMM",yq999@@JJKKKK u%%--b112I  9 9s++33B778888 OI&&E *511OFG &ME!!!Q$K!!E%LE
 HSZZrx000E9SZZ((E%L g&&EKN';<<I [F
MM%'Mr   Fc                    t          j        | j        t           j                  }dt          j        t          j        |                    z                      t           j                  }|r5t          j        dt           j                  |                                z  }||k    	                                r$| 
                    t          |          |          S |                                 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    & 8EJbh///D RWRWT]]+++33BH==H  ?71BH---> 	 @||E(OOh|???::<<r   )r   F)r4   numpyr/    r   r   r   r   baser	   r   r
   r   r   r   r   r   r#   r   r   <module>r      s         & & & & & & & & & &             A A A A A A A A A AM) M) M) M) M)W M) M) M)`` ` `F           r   