
    j "                        d Z ddlZddlmZmZmZ ddlmZm	Z	m
Z
mZ  ej                  g dej                        Z G d d	ej                        Z G d
 de      Z G d de      Z G d de      Zde
ee   ee	e      f   fdZy)z
lighting.py
--------------

Hold basic information about lights.

Forked from the light model in `pyrender`:
https://github.com/mmatl/pyrender
    N   )transformationsutilvisual)ListNDArrayTuplefloat64)<   r   r      )dtypec                       e Zd ZdZd
dZed        Zej                  d        Zed        Zej                  d        Zed        Z	e	j                  d	        Z	y)Lighta  
    Base class for all light objects.

    Attributes
    ----------
    name : str, optional
        Name of the light.
    color : (4,) uint8
        RGBA value for the light's color in linear space.
    intensity : float
        Brightness of light. The units that this is defined in depend
        on the type of light: point and spot lights use luminous intensity
        in candela (lm/sr) while directional lights use illuminance
        in lux (lm/m2).
    radius : float
        Cutoff distance at which light's intensity may be considered to
        have reached zero. Supported only for point and spot lights
        Must be > 0.0
        If None, the radius is assumed to be infinite.
    Nc                     |,dt        j                  d      j                          | _        n|| _        || _        || _        || _        y )Nlight_   )r   	unique_iduppernamecolor	intensityradius)selfr   r   r   r   s        C/DATA/.local/lib/python3.12/site-packages/trimesh/scene/lighting.py__init__zLight.__init__*   sF    < !2!8!8!: ;<DI DI
"    c                     | j                   S N)_colorr   s    r   r   zLight.color6   s    {{r   c                     |t         | _        y t        j                  |      }t	        |j
                        dk(  r|d   }|j
                  dk7  rt        d      || _        y )Nr   r   )   zcouldn't convert color to RGBA!)_DEFAULT_RGBAr   r   to_rgbalenshape
ValueErrorr   values     r   r   zLight.color:   sU    ='DKNN5)E5;;1$a{{d" !BCCDKr   c                     | j                   S r   )
_intensityr    s    r   r   zLight.intensityG   s    r   c                 8    |t        |      | _        y d| _        y )Ng      ?)floatr+   r(   s     r   r   zLight.intensityK   s    #ElDO!DOr   c                     | j                   S r   )_radiusr    s    r   r   zLight.radiusR   s    ||r   c                 B    ||dk  r|| _         y t        |      | _         y )N        )r/   r-   r(   s     r   r   zLight.radiusV   s    =ECK DL <DLr   NNNN)
__name__
__module____qualname____doc__r   propertyr   setterr   r    r   r   r   r      s    *
   \\
  
    " "   ]]( (r   r   c                   $     e Zd ZdZd fd	Z xZS )DirectionalLightae  
    Directional lights are light sources that act as though they are
    infinitely far away and emit light in the direction of the local -z axis.
    This light type inherits the orientation of the node that it belongs to;
    position and scale are ignored except for their effect on the inherited
    node orientation. Because it is at an infinite distance, the light is
    not attenuated. Its intensity is defined in lumens per metre squared,
    or lux (lm/m2).

    Attributes
    ----------
    name : str, optional
        Name of the light.
    color : (4,) unit8
        RGBA value for the light's color in linear space.
    intensity : float
        Brightness of light. The units that this is defined in depend
        on the type of light.
        point and spot lights use luminous intensity in candela (lm/sr),
        while directional lights use illuminance in lux (lm/m2).
    radius : float
        Cutoff distance at which light's intensity may be considered to
        have reached zero. Supported only for point and spot lights, must be > 0.
        If None, the radius is assumed to be infinite.
    c                 ,    t         |   ||||       y N)r   r   r   r   superr   r   r   r   r   r   	__class__s        r   r   zDirectionalLight.__init__y       d%9VTr   r2   r3   r4   r5   r6   r   __classcell__rA   s   @r   r;   r;   ^   s    4U Ur   r;   c                   $     e Zd ZdZd fd	Z xZS )
PointLightaV  
    Point lights emit light in all directions from their position in space;
    rotation and scale are ignored except for their effect on the inherited
    node position. The brightness of the light attenuates in a physically
    correct manner as distance increases from the light's position (i.e.
    brightness goes like the inverse square of the distance). Point light
    intensity is defined in candela, which is lumens per square radian (lm/sr).

    Attributes
    ----------
    name : str, optional
        Name of the light.
    color : (4,) uint8
        RGBA value for the light's color in linear space.
    intensity : float
        Brightness of light. The units that this is defined in depend
        on the type of light.
        point and spot lights use luminous intensity in candela (lm/sr),
        while directional lights use illuminance in lux (lm/m2).
    radius : float
        Cutoff distance at which light's intensity may be considered to
        have reached zero. Supported only for point and spot lights, must be > 0.
        If None, the radius is assumed to be infinite.
    c                 ,    t         |   ||||       y r=   r>   r@   s        r   r   zPointLight.__init__   rB   r   r2   rC   rE   s   @r   rG   rG   }   s    2U Ur   rG   c                        e Zd ZdZdddddej
                  dz  f fd	Zed        Zej                  d        Zed        Z
e
j                  d	        Z
 xZS )
	SpotLighta  
    Spot lights emit light in a cone in the direction of the local -z axis.
    The angle and falloff of the cone is defined using two numbers, the
    `innerConeAngle` and `outerConeAngle`. As with point lights, the brightness
    also attenuates in a physically correct manner as distance increases from
    the light's position (i.e. brightness goes like the inverse square of the
    distance). Spot light intensity refers to the brightness inside the
    `innerConeAngle` (and at the location of the light) and is defined in
    candela, which is lumens per square radian (lm/sr). A spot light's position
    and orientation are inherited from its node transform. Inherited scale does
    not affect cone shape, and is ignored except for its effect on position
    and orientation.

    Attributes
    ----------
    name : str, optional
        Name of the light.
    color : (4,) uint8
        RGBA value for the light's color in linear space.
    intensity : float
        Brightness of light. The units that this is defined in depend
        on the type of light.
        point and spot lights use luminous intensity in candela (lm/sr),
        while directional lights use illuminance in lux (lm/m2).
    radius : float
        Cutoff distance at which light's intensity may be considered to
        have reached zero. Supported only for point and spot lights, must be > 0.
        If None, the radius is assumed to be infinite.
    innerConeAngle : float
        Angle, in radians, from centre of spotlight where falloff begins.
        Must be greater than or equal to `0` and less than `outerConeAngle`.
    outerConeAngle : float
        Angle, in radians, from centre of spotlight where falloff ends.
        Must be greater than `innerConeAngle` and less than or equal to `PI / 2.0`.
    Nr1   g      @c                 H    t         |   ||||       || _        || _        y r=   )r?   r   outerConeAngleinnerConeAngle)r   r   r   r   r   rM   rL   rA   s          r   r   zSpotLight.__init__   s+     	d%9VT,,r   c                     | j                   S r   )_innerConeAngler    s    r   rM   zSpotLight.innerConeAngle       ###r   c                 b    |dk  s|| j                   kD  rt        d      t        |      | _        y )Nr1   z"Invalid value for inner cone angle)rL   r'   r-   rO   r(   s     r   rM   zSpotLight.innerConeAngle   s.    3;%$"5"55ABB$U|r   c                     | j                   S r   )_outerConeAngler    s    r   rL   zSpotLight.outerConeAngle   rP   r   c                 v    |dk  s|t         j                  dz  dz   kD  rt        d      t        |      | _        y )Nr1   g       @g&.>z"Invalid value for outer cone angle)nppir'   r-   rS   r(   s     r   rL   zSpotLight.outerConeAngle   s5    3;%"%%#+"44ABB$U|r   )r3   r4   r5   r6   rU   rV   r   r7   rM   r8   rL   rD   rE   s   @r   rJ   rJ      s    "L uus{- $ $ , ,
 $ $ , ,r   rJ   returnc                     g }g }| j                   }|9|j                  d |D               |j                  d t        d      D               ||fS )aH  
    Generate a list of lights for a scene that looks decent.

    Parameters
    --------------
    scene : trimesh.Scene
      Scene with geometry

    Returns
    --------------
    lights : [Light]
      List of light objects
    transforms : (len(lights), 4, 4) float
      Transformation matrices for light positions.
    c              3   F   K   | ]  }t        j                  |        y wr   )r   translation_matrix).0bs     r   	<genexpr>zautolight.<locals>.<genexpr>   s     PA/<<Q?s   !c              3   0   K   | ]  }t                 y wr   )rG   )r[   _s     r   r]   zautolight.<locals>.<genexpr>   s     5HqjlHs   r   )boundsextendrange)scenelights
transformsr`   s       r   	autolightrf      sT    $ FJ \\FPPP5E!H55:r   )r6   numpyrU    r   r   r   typedr   r   r	   r
   arrayuint8r#   ABCr   r;   rG   rJ   rf   r9   r   r   <module>rm      s     , , 1 1 *"((;G(DHH G(TUu U>U U<D, D,Nd5k40@+AAB r   