Ë
    :vžj†/  ã                   óN   — d dl Z d dlZddlmZ  G d„ d«      Zd
d„Zd„ Zdefd	„Zy)é    Né   )Úutilc                   ó  — e Zd Z	 dd„Zd„ Zed„ «       Zej                  d„ «       Zed„ «       Zej                  d„ «       Zed„ «       Z	e	j                  d	„ «       Z	ed
„ «       Z
e
j                  d„ «       Z
d„ Zd„ Zd„ Zd„ Zy)ÚCameraNc                 ó|  — |€,dt        j                  d«      j                  «       › �| _        n|| _        |€|€t	        d«      ‚d| _        || _        || _        |€:| j                  dz  j                  «       j                  t        j                  «      }|| _        t        |«      | _        t        |«      | _        y)a‘  
        Create a new Camera object that stores camera intrinsic
        and extrinsic parameters.

        TODO: skew is not supported
        TODO: cx and cy that are not half of width and height

        Parameters
        ------------
        name : str or None
          Name for camera to be used as node name
        resolution : (2,) int
          Pixel size in (height, width)
        focal : (2,) float
          Focal length in pixels. Either pass this OR FOV
          but not both.  focal = (K[0][0], K[1][1])
        fov : (2,) float
          Field of view (fovx, fovy) in degrees
        z_near : float
          What is the closest
        NÚcamera_é   z$either focal length or FOV required!Fg      >@)r   Ú	unique_idÚupperÚnameÚ
ValueErrorÚ_focal_computedÚfocalÚfovÚroundÚastypeÚnpÚint64Ú
resolutionÚfloatÚz_farÚz_near)Úselfr   r   r   r   r   r   s          úf/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/scene/cameras.pyÚ__init__zCamera.__init__	   s®   € ð2 ˆ<à!¤$§.¡.°Ó"3×"9Ñ"9Ó";Ð!<Ð=ˆD�Ið ˆDŒIàˆ;˜5˜=ÜÐCÓDÐDð  %ˆÔð ˆŒ
ð ˆŒàÐàŸ(™( T™/×0Ñ0Ó2×9Ñ9¼"¿(¹(ÓCˆJØ$ˆŒô ˜5“\ˆŒ
ä˜F“mˆ�ó    c                 ó  — t        t        j                  | j                  «      t        j                  | j                  «      t        j                  | j
                  «      t        j                  | j                  «      ¬«      S )z:
        Safely get a copy of the current camera.
        )r   r   r   r   )r   ÚcopyÚdeepcopyr   r   r   r   ©r   s    r   r   zCamera.copy?   sQ   € ô Ü—‘˜tŸy™yÓ)Ü—}‘} T§_¡_Ó5Ü—-‘- §
¡
Ó+Ü—‘˜dŸh™hÓ'ô	
ð 	
r   c                 ó   — | j                   S )z 
        Get the camera resolution in pixels.

        Returns
        ------------
        resolution (2,) float
          Camera resolution in pixels
        )Ú_resolutionr    s    r   r   zCamera.resolutionJ   s   € ð ×ÑÐr   c                 óè   — t        j                  |t         j                  ¬«      }|j                  dk7  rt	        d«      ‚d|j
                  _        || _        | j                  rd| _	        yd| _
        y)z£
        Set the camera resolution in pixels.

        Parameters
        ------------
        resolution (2,) float
          Camera resolution in pixels
        ©Údtype©r   zresolution must be (2,) floatFN)r   Ú
asanyarrayr   Úshaper   ÚflagsÚ	writeabler"   r   Ú_focalÚ_fov©r   Úvaluess     r   r   zCamera.resolutionV   s]   € ô —‘˜v¬R¯X©XÔ6ˆØ�<‰<˜4ÒÜÐ<Ó=Ð=Ø!&ˆ�‰ÔØ!ˆÔà×ÒØˆD�Kð ˆD�Ir   c                 óì   — | j                   €]| j                  dt        j                  t        j                  | j
                  dz  «      «      z  z  }d|j                  _        || _         | j                   S )z¢
        Get the focal length in pixels for the camera.

        Returns
        ------------
        focal : (2,) float
          Focal length in pixels
        ç       @F)r+   r"   r   ÚtanÚradiansr,   r)   r*   )r   r   s     r   r   zCamera.focall   sZ   € ð �;‰;Ðà×$Ñ$¨¬b¯f©f´R·Z±ZÀÇ	Á	ÈCÁÓ5PÓ.QÑ(QÑRˆEØ$)ˆE�K‰KÔ!ØˆDŒKà�{‰{Ðr   c                 óâ   — |€d| _         yd| _        t        j                  |t        j                  ¬«      }|j
                  dk7  rt        d«      ‚d|j                  _        || _         d| _	        y)z£
        Set the focal length in pixels for the camera.

        Returns
        ------------
        focal : (2,) float
          Focal length in pixels.
        NFr$   r&   zfocal length must be (2,) float)
r+   r   r   r'   Úfloat64r(   r   r)   r*   r,   r-   s     r   r   zCamera.focal~   s`   € ð ˆ>ØˆD�Kð
 $)ˆDÔ Ü—]‘] 6´·±Ô<ˆFØ�|‰|˜tÒ#Ü Ð!BÓCÐCØ%*ˆF�L‰LÔ"à ˆDŒKàˆD�Ir   c                 óÄ   — t        j                  dt         j                  ¬«      }| j                  d   |d<   | j                  d   |d<   | j                  dz  |dd	…d	f<   |S )
z¥
        Get the intrinsic matrix for the Camera object.

        Returns
        -----------
        K : (3, 3) float
          Intrinsic matrix for camera
        é   r$   r   ©r   r   é   ©r8   r8   r0   Nr   )r   Úeyer4   r   r   )r   ÚKs     r   r;   zCamera.K˜   sY   € ô �F‰F�1œBŸJ™JÔ'ˆØ—*‘*˜Q‘-ˆˆ$‰Ø—*‘*˜Q‘-ˆˆ$‰Ø—?‘? SÑ(ˆˆ"ˆ1ˆ"ˆaˆ%‰Øˆr   c                 ó4  — |€y t        j                  |t         j                  ¬«      }|j                  dk7  rt	        d«      ‚t        j
                  |j                  «       g d¢   g d¢«      st	        d«      ‚|d   |d   g| _        |d d	…d	f   d	z  | _        y )
Nr$   )r6   r6   zmatrix must be (3,3)!)r8   r6   r	   é   é   )r   r   r   r   r8   z4matrix should only have focal length and resolution!r7   r9   r   )	r   r'   r4   r(   r   ÚallcloseÚflattenr   r   r-   s     r   r;   zCamera.K¨   sŠ   € àˆ>ØÜ—‘˜v¬R¯Z©ZÔ8ˆØ�<‰<˜6Ò!ÜÐ4Ó5Ð5ä�{‰{˜6Ÿ>™>Ó+ªOÑ<ºoÔNÜÐSÓTÐTð ˜T‘l F¨4¡LÐ1ˆŒ
à   !  Q ™-¨!Ñ+ˆ�r   c                 óì   — | j                   €]dt        j                  t        j                  | j                  dz  | j
                  z  «      «      z  }d|j                  _        || _         | j                   S )z™
        Get the field of view in degrees.

        Returns
        -------------
        fov : (2,) float
          XY field of view in degrees
        r0   F)r,   r   ÚdegreesÚarctanr"   r+   r)   r*   )r   r   s     r   r   z
Camera.fov¸   s[   € ð �9‰9ÐØœŸ
™
¤2§9¡9¨d×.>Ñ.>ÀÑ.DÈÏÉÑ-SÓ#TÓUÑUˆCØ"'ˆC�I‰IÔØˆDŒIØ�y‰yÐr   c                 óâ   — |€d| _         yd| _        t        j                  |t        j                  ¬«      }|j
                  dk7  rt        d«      ‚d|j                  _        || _         d| _	        y)z¡
        Set the field of view in degrees.

        Parameters
        -------------
        values : (2,) float
          Size of FOV to set in degrees
        NTr$   r&   zfov length must be (2,) intF)
r,   r   r   r'   r4   r(   r   r)   r*   r+   r-   s     r   r   z
Camera.fovÈ   s`   € ð ˆ>ØˆD�Ið
 $(ˆDÔ Ü—]‘] 6´·±Ô<ˆFØ�|‰|˜tÒ#Ü Ð!>Ó?Ð?Ø%*ˆF�L‰LÔ"àˆDŒIàˆD�Kr   c                 ó   — t        | «      S )zù
        Calculate ray direction vectors.

        Will return one ray per pixel, as set in self.resolution.

        Returns
        --------------
        vectors : (n, 3) float
          Ray direction vectors in camera frame with z == -1
        )Úcamera_to_raysr    s    r   Úto_rayszCamera.to_raysâ   s   € ô ˜dÓ#Ð#r   c                 ó@   — t        j                  t        | «       «      S )z¸
        Get ray spherical coordinates in radians.


        Returns
        --------------
        angles : (n, 2) float
          Ray spherical coordinate angles in radians.
        )r   rC   Úray_pixel_coordsr    s    r   ÚangleszCamera.anglesï   s   € ô �y‰yÔ*¨4Ó0Ð0Ó1Ð1r   c                 ó2   — t        |fd| j                  i|¤ŽS )a;  
        Generate transform for a camera to keep a list
        of points in the camera's field of view.

        Parameters
        -------------
        points : (n, 3) float
          Points in space
        rotation : None, or (4, 4) float
          Rotation matrix for initial rotation
        distance : None or float
          Distance from camera to center
        center : None, or (3,) float
          Center of field of view.

        Returns
        --------------
        transform : (4, 4) float
          Transformation matrix from world to camera
        r   )Úlook_atr   )r   ÚpointsÚkwargss      r   rL   zCamera.look_atû   s   € ô* �vÑ6 4§8¡8Ð6¨vÑ6Ð6r   c                 ó:   — d| j                   › d| j                  › �S )Nz<trimesh.scene.Camera> FOV: z Resolution: )r   r   r    s    r   Ú__repr__zCamera.__repr__  s   € Ø-¨d¯h©h¨Z°}ÀTÇ_Á_ÐDUÐVÐVr   )NNNNg{®Gáz„?g     @�@)Ú__name__Ú
__module__Ú__qualname__r   r   Úpropertyr   Úsetterr   r;   r   rG   rJ   rL   rP   © r   r   r   r      s×   „ àSYó4$òl	
ð ñ	 ó ð	 ð ×Ññó ðð* ñó ðð" ‡\�\ñó ðð2 ñó ðð ‡X�Xñ,ó ð,ð ñó ðð 	‡Z�Zñó ðò2$ò
2ò7ó.Wr   r   c                 óX  — |€t        j                  d«      }n%t        j                  |t         j                  ¬«      }t        j                  | t         j                  ¬«      } |dd…dd…f   j                  }|j                  | j                  «      j                  }|€.|j                  d¬«      dt        j                  |d¬«      z  z   }n|j                  |«      }||z  }t        j                  t        j                  |«      dz  «      }	|€St        j                  t        j                  |dd…dd	…f   «      |	z  |dd…d	f   dd…t         j                  f   z   «      }|�||z  }|dd…dd…f   j                  |«      }
|j                  «       }|
||dd…d	f   z  z   |dd…df<   |S )
aÇ  
    Generate transform for a camera to keep a list
    of points in the camera's field of view.

    Examples
    ------------
    ```python
    points = np.array([0, 0, 0], [1, 1, 1])
    scene.camera_transform = scene.camera.look_at(points)
    ```

    Parameters
    -------------
    points : (n, 3) float
      Points in space
    fov : (2,) float
      Field of view, in DEGREES
    rotation : None, or (4, 4) float
      Rotation matrix for initial rotation
    distance : None or float
      Distance from camera to center
    center : None, or (3,) float
      Center of field of view.

    Returns
    --------------
    transform : (4, 4) float
      Transformation matrix from world to camera
    Né   r$   r6   r   )Úaxisg      à?r0   r   )r   r:   r'   r4   ÚTÚdotÚminÚptpr1   r2   ÚmaxÚabsÚnewaxisr   )rM   r   ÚrotationÚdistanceÚcenterÚpadÚrinvÚpoints_cÚcenter_cÚtfovÚcenter_wÚcam_poses               r   rL   rL     sˆ  € ð> ÐÜ—6‘6˜!“9‰ä—=‘= ´·±Ô<ˆÜ�]‰]˜6¬¯©Ô4€Fð �B�Q�B˜˜˜�FÑ×Ñ€DØ�x‰x˜Ÿ™Ó!×#Ñ#€Hà€~à—<‘< Q�<Ó'¨#´·±°xÀaÔ0HÑ*HÑH‰ð —8‘8˜FÓ#ˆð �Ñ€Hô �6‰6”"—*‘*˜S“/ CÑ'Ó(€DàÐÜ—6‘6œ"Ÿ&™& ª!¨R¨a¨R¨%¡Ó1°DÑ8¸8ÂAÀqÀD¹>Ê!ÌRÏZÉZÈ-Ñ;XÑXÓYˆà
€Ø�C‰ˆð ˜˜˜˜B˜Q˜B˜Ñ×#Ñ# HÓ-€HØ�}‰}‹€HØ ¨H°R°a°R¸°U©OÑ!;Ñ;€HˆRˆaˆR�ˆU�Oà€Or   c                 óÐ  — | j                   }t        j                  | j                  «      dz  }t        j                  |«      }|dd|z  z
  z  }| }|\  }}|\  }}t        j                  ||g||gg| j                   ¬«      }	t        j                  d|d   dz
  g|d   dz
  dgg|¬«      j                  t        j                  «      }
|	j                  |
j                  k(  sJ ‚|	|
fS )a¶  
    Get the x-y coordinates of rays in camera coordinates at
    z == -1.

    One coordinate pair will be given for each pixel as defined in
    camera.resolution. If reshaped, the returned array corresponds
    to pixels of the rendered image.

    Examples
    ------------
    ```python
    xy = ray_pixel_coords(camera).reshape(
      tuple(camera.coordinates) + (2,))
    top_left == xy[0, 0]
    bottom_right == xy[-1, -1]
    ```

    Parameters
    --------------
    camera : trimesh.scene.Camera
      Camera object to generate rays from

    Returns
    --------------
    xy : (n, 2) float
      x-y coordinates of intersection of each camera ray
      with the z == -1 frame
    r0   r8   g      ð?)ÚboundsÚcountr   )
r   r   r2   r   r1   r   Úgrid_linspacer   r   r(   )ÚcameraÚresÚhalf_fovÚ	right_topÚleft_bottomÚrightÚtopÚleftÚbottomÚxyÚpixelss              r   rI   rI   [  sò   € ð< ×
Ñ
€CÜ�z‰z˜&Ÿ*™*Ó%¨Ñ+€Hä—‘�xÓ €Ià��c˜C‘i‘Ñ €IØ�*€Kð �J€Eˆ3Ø�L€Dˆ&ô 
×	Ñ	Ø�s�˜e V˜_Ð-°V×5FÑ5Fô
€Bô
 ×ÑØ�C˜‘F˜Q‘J� # a¡&¨1¡*¨a Ð1¸ôç�fŒR�X‰XÓð ð �8‰8�v—|‘|Ò#Ð#Ð#àˆvˆ:Ðr   ro   c                 ó´   — t        | «      \  }}t        j                  t        j                  |t        j
                  |dd…dd…f   «       f«      «      }||fS )aC  
    Calculate the trimesh.scene.Camera object to direction vectors.

    Will return one ray per pixel, as set in camera.resolution.

    Parameters
    --------------
    camera : trimesh.scene.Camera

    Returns
    --------------
    vectors : (n, 3) float
      Ray direction vectors in camera frame with z == -1
    Nr8   )rI   r   Úunitizer   Úcolumn_stackÚ	ones_like)ro   rx   ry   Úvectorss       r   rF   rF   ”  sP   € ô  " &Ó)�J€Bˆä�l‰lœ2Ÿ?™?¨B´·±¸bÂÀBÀQÀBÀ¹iÓ1HÐ0HÐ+IÓJÓK€GØ�Fˆ?Ðr   )NNNN)	r   Únumpyr   Ú r   r   rL   rI   rF   rV   r   r   Ú<module>r�      s6   ðÛ ã å ÷KWñ KWó\BòJ6ðr˜6ô r   