
    ljL                    2   d Z ddlmZ ddgZddlZddlmZmZ ddlZ	ddl
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ddlm Z  ddl!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z)  G d de'          Z* G d de*          Z+dS )zHA scene suitable for rendering three-dimensional objects and animations.    )annotationsThreeDSceneSpecialThreeDSceneN)IterableSequence)Line)
ThreeDAxes)OpenGLMobject)Sphere)ValueTracker   )config)	Animation)	Transform)ThreeDCamera)DEGREESRendererType)Mobject)VectorizedPointVGroup)OpenGLCamera)Scene)merge_dicts_recursivelyc                       e Zd ZdZeddf fd	Z	 	 	 	 	 	 d&d'dZd(d)dZd*dZ	 	 	 d+d,dZ	d Z
ddddddg fd-dZd. fdZd/d!Zd/d"Zd/d#Zd/d$Zd% Z xZS )0r   z}
    This is a Scene, with special configurations and properties that
    make it suitable for Three Dimensional Scenes.
    Nc                    || _         |dt          z  dt          z  d}|| _         t                      j        dd|i| d S )NF   iyphithetacamera_class )ambient_camera_rotationr   (default_angled_camera_orientation_kwargssuper__init__)selfr    r"   r#   kwargs	__class__s        T/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/scene/three_d_scene.pyr%   zThreeDScene.__init__%   se     (?$3;G|8 84
 5 	5 	==l=f=====    r   float | Noner   gammazoomfocal_distanceframe_center Mobject | Sequence[float] | Nonec                   || j         j                            |           || j         j                            |           || j         j                            |           || j         j                            |           || j         j                            |           |&| j         j        j                            |           dS dS )a  
        This method sets the orientation of the camera in the scene.

        Parameters
        ----------
        phi
            The polar angle i.e the angle between Z_AXIS and Camera through ORIGIN in radians.

        theta
            The azimuthal angle i.e the angle that spins the camera around the Z_AXIS.

        focal_distance
            The focal_distance of the Camera.

        gamma
            The rotation of the camera about the vector from the ORIGIN to the Camera.

        zoom
            The zoom factor of the scene.

        frame_center
            The new center of the camera frame in cartesian coordinates.

        N)	renderercameraset_phi	set_thetaset_focal_distance	set_gammaset_zoom_frame_centermove_to)r&   r   r   r,   r-   r.   r/   r'   s           r)   set_camera_orientationz"ThreeDScene.set_camera_orientation7   s    D ?M ((---M **5111%M 33NCCCM **5111M ))$///#M .66|DDDDD $#r*   {Gz?ratefloataboutstrc                @                                    	 t          j        t          j        k    r\| j        j        | j        j        | j        j        d}|         	                    fd           | 
                               dS t          j        t          j        k    rR| j        }|j        |j        |j        d|	                    fd           | 
                    | j                   dS dS # t          $ r}t!          d          |d}~ww xY w)a  
        This method begins an ambient rotation of the camera about the Z_AXIS,
        in the anticlockwise direction

        Parameters
        ----------
        rate
            The rate at which the camera should rotate about the Z_AXIS.
            Negative rate means clockwise rotation.
        about
            one of 3 options: ["theta", "phi", "gamma"]. defaults to theta.
        r   r   r,   c                4                         |z            S N)increment_value)mdtr=   xs     r)   <lambda>z;ThreeDScene.begin_ambient_camera_rotation.<locals>.<lambda>~   s    A,=,=dRi,H,H r*   c                ,              |z            S rD   r!   )rF   rG   r?   methodsr=   s     r)   rI   z;ThreeDScene.begin_ambient_camera_rotation.<locals>.<lambda>   s    ngenTBY.G.G r*   Invalid ambient rotation angle.N)lowerr   r2   r   CAIROr3   theta_trackerphi_trackergamma_trackeradd_updateraddOPENGLincrement_thetaincrement_phiincrement_gamma	Exception
ValueError)r&   r=   r?   trackerscamerK   rH   s    ``   @@r)   begin_ambient_camera_rotationz)ThreeDScene.begin_ambient_camera_rotationf   s=    [[]]	G,"444![6;2![6 
 #+5/HHHHHIIIL$777$(K 0, 0 
  G G G G G GHHH%%%%% 87  	G 	G 	G>??QF	Gs   A4C> A*C> >
DDDc                   |                                 }	 t          j        t          j        k    rW| j        j        | j        j        | j        j        d}||         }|	                                 | 
                    |           dS t          j        t          j        k    r| j        	                                 dS dS # t          $ r}t          d          |d}~ww xY w)z.This method stops all ambient camera rotation.rB   rL   N)rM   r   r2   r   rN   r3   rO   rP   rQ   clear_updatersremoverT   rX   rY   )r&   r?   rZ   rH   r\   s        r)   stop_ambient_camera_rotationz(ThreeDScene.stop_ambient_camera_rotation   s    [[]]	G,"444![6;2![6 
 #+5/  """AL$777**,,,,, 87 	G 	G 	G>??QF	Gs   A/B> 3B> >
CCC   
origin_phiorigin_thetac                   #| j         j        j                                        #| j         j        j                                        t          d          fd}| j         j        j                            |           |                     | j         j        j                   t          d          fd}| j         j        j                            |           |                     | j         j        j                   dS )a  
        This method creates a 3D camera rotation illusion around
        the current camera orientation.

        Parameters
        ----------
        rate
            The rate at which the camera rotation illusion should operate.
        origin_phi
            The polar angle the camera should move around. Defaults
            to the current phi angle.
        origin_theta
            The azimutal angle the camera should move around. Defaults
            to the current theta angle.
        Nr   c                                         |z             dt          j                                                  z  }|                     |z             S )Ng?)rE   npsin	get_value	set_value)rF   rG   val_for_left_rightrd   r=   val_tracker_thetas      r)   update_thetazBThreeDScene.begin_3dillusion_camera_rotation.<locals>.update_theta   sU    --b4i888!$rv.?.I.I.K.K'L'L!L;;|.@@AAAr*   c                                         |z             dt          j                                                  z  dz
  }|                     |z             S )Ng?)rE   rg   cosri   rj   )rF   rG   val_for_up_downrc   r=   val_tracker_phis      r)   
update_phiz@ThreeDScene.begin_3dillusion_camera_rotation.<locals>.update_phi   sW    ++BI666!BF?+D+D+F+F$G$GG#MO;;zO;<<<r*   )r2   r3   rO   ri   rP   r   rR   rS   )r&   r=   rc   rd   rm   rr   rq   rl   s    ```  @@r)    begin_3dillusion_camera_rotationz,ThreeDScene.begin_3dillusion_camera_rotation   s!   * =/=GGIIL-9CCEEJ(OO	B 	B 	B 	B 	B 	B 	B
 	*66|DDD%3444&q//	= 	= 	= 	= 	= 	= 	=
 	(44Z@@@%122222r*   c                "   | j         j        j                                         |                     | j         j        j                   | j         j        j                                         |                     | j         j        j                   dS )z0This method stops all illusion camera rotations.N)r2   r3   rO   r_   r`   rP   r&   s    r)   stop_3dillusion_camera_rotationz+ThreeDScene.stop_3dillusion_camera_rotation   sp    *99;;;DM(6777(77999DM(455555r*   added_animsIterable[Animation]c                L   g }	t           j        t          j        k    r|  || j        j        f|| j        j        f|| j        j        f|| j        j        f|| j        j	        fg}
|
D ]4\  }}|-|	
                    |j                            |                     5|7|	
                    | j        j        j                            |                     nt           j        t          j        k    r| j        }|                                }|j        |j        |j        |j        |j        d}|8t+          |t,                    r|                                }t1          |          }d}|t           j        ||j        z  z  }|dg|dg|dg|dg|dgfD ]\  }}| ||         |           |t7          j        dd	
           |	t;          ||          gz  }	 | j        |	|z   i | |;t           j        t          j        k    r#|                     | j        j                   dS dS dS )a  
        This method animates the movement of the camera
        to the given spherical coordinates.

        Parameters
        ----------
        phi
            The polar angle i.e the angle between Z_AXIS and Camera through ORIGIN in radians.

        theta
            The azimuthal angle i.e the angle that spins the camera around the Z_AXIS.

        focal_distance
            The radial focal_distance between ORIGIN and Camera.

        gamma
            The rotation of the camera about the vector from the ORIGIN to the Camera.

        zoom
            The zoom factor of the camera.

        frame_center
            The new center of the camera frame in cartesian coordinates.

        added_anims
            Any other animations to be played at the same time.

        N)r   r   r,   r-   r/   r   r   r,   r-   r/   z3focal distance of OpenGLCamera can not be adjusted.r   )
stacklevel) r   r2   r   rN   r3   rP   rO   focal_distance_trackerrQ   zoom_trackerappendanimaterj   r9   r:   rT   copyr5   r4   r7   scale
isinstancer
   
get_centerlistframe_heightheightwarningswarnr   playr`   )r&   r   r   r,   r-   r.   r/   rw   r'   animsvalue_tracker_pairsvaluetrackerr[   cam2rK   
zoom_valuemethods                     r)   move_camerazThreeDScene.move_camera   so   N ?l000%dk-.12!CD12t{/0# #6 C Cw$LL!:!:5!A!ABBB'T[6>FF|TTUUU_ 333 $C88::D|
 $ G 'lM:: =#/#:#:#<#<L#L11J#0D3:4EF
  e V$~." + +v $#GFOE***)I    
 iT**++E	5;&1&111 #<;M(M(MKK122222 $#(M(Mr*   
animationsr   c                     t                      j        | | j        j                                        | j        j        j        gz   }t          fd|D                       r| j        S S )a  
        This method returns a list of all of the Mobjects in the Scene that
        are moving, that are also in the animations passed.

        Parameters
        ----------
        *animations
            The animations whose mobjects will be checked.
        c              3      K   | ]}|v V  	d S rD   r!   ).0cmmoving_mobjectss     r)   	<genexpr>z2ThreeDScene.get_moving_mobjects.<locals>.<genexpr>F  s(      ??r_$??????r*   )r$   get_moving_mobjectsr2   r3   get_value_trackersr9   anymobjects)r&   r   camera_mobjectsr   r(   s      @r)   r   zThreeDScene.get_moving_mobjects8  sz     6%''5zB-.AACCM .G
 
 ????????? 	!= r*   r   r   c                   t           j        t          j        k    r# | j        |   | j        j        j        |i | dS t           j        t          j        k    r.|D ]-}|                                 |                     |           ,dS dS )a4  
        This method is used to prevent the rotation and tilting
        of mobjects as the camera moves around. The mobject can
        still move in the x,y,z directions, but will always be
        at the angle (relative to the camera) that it was at
        when it was passed through this method.)

        Parameters
        ----------
        *mobjects
            The Mobject(s) whose orientation must be fixed.

        **kwargs
            Some valid kwargs are
                use_static_center_func : bool
                center_func : function
        N)	r   r2   r   rN   rS   r3   add_fixed_orientation_mobjectsrT   fix_orientation)r&   r   r'   mobs       r)   r   z*ThreeDScene.add_fixed_orientation_mobjectsJ  s    $ ?l000DHh?DM ?TVTTTTT_ 333  ##%%%	 43 r*   c                   t           j        t          j        k    r | j        |  |   | j        j        |  dS t           j        t          j        k    r.|D ]-}|                                 |                     |           ,dS dS )a[  
        This method is used to prevent the rotation and movement
        of mobjects as the camera moves around. The mobject is
        essentially overlaid, and is not impacted by the camera's
        movement in any way.

        Parameters
        ----------
        *mobjects
            The Mobjects whose orientation must be fixed.
        N)	r   r2   r   rN   rS   r3   add_fixed_in_frame_mobjectsrT   fix_in_framer&   r   r   s      r)   r   z'ThreeDScene.add_fixed_in_frame_mobjectse  s     ?l000DHh%3DK3X>>>>_ 333    """	 43 r*   c                    t           j        t          j        k    r | j        j        j        |  dS t           j        t          j        k    r.|D ]-}|                                 |                     |           ,dS dS )a  
        This method "unfixes" the orientation of the mobjects
        passed, meaning they will no longer be at the same angle
        relative to the camera. This only makes sense if the
        mobject was passed through add_fixed_orientation_mobjects first.

        Parameters
        ----------
        *mobjects
            The Mobjects whose orientation must be unfixed.
        N)	r   r2   r   rN   r3   !remove_fixed_orientation_mobjectsrT   unfix_orientationr`   r   s      r)   r   z-ThreeDScene.remove_fixed_orientation_mobjects{  s     ?l000BDM BHMMMM_ 333 ! !%%'''C    	 43! !r*   c                    t           j        t          j        k    r | j        j        j        |  dS t           j        t          j        k    r.|D ]-}|                                 |                     |           ,dS dS )a$  
         This method undoes what add_fixed_in_frame_mobjects does.
         It allows the mobject to be affected by the movement of
         the camera.

        Parameters
        ----------
        *mobjects
            The Mobjects whose position and orientation must be unfixed.
        N)	r   r2   r   rN   r3   remove_fixed_in_frame_mobjectsrT   unfix_from_framer`   r   s      r)   r   z*ThreeDScene.remove_fixed_in_frame_mobjects  s     ?l000?DM ?JJJJ_ 333 ! !$$&&&C    	 43! !r*   c                h    t          | j                  } |j        |            | j        di | dS )aq  
        This method sets the default_angled_camera_orientation to the
        keyword arguments passed, and sets the camera to that orientation.

        Parameters
        ----------
        **kwargs
            Some recognised kwargs are phi, theta, focal_distance, gamma,
            which have the same meaning as the parameters in set_camera_orientation.
        Nr!   )dict!default_camera_orientation_kwargsupdater;   r&   r'   r   s      r)   (set_to_default_angled_camera_orientationz4ThreeDScene.set_to_default_angled_camera_orientation  sL     2
 
 	f##--f-----r*   )NNNNNN)r   r+   r   r+   r,   r+   r-   r+   r.   r+   r/   r0   )r<   r   )r=   r>   r?   r@   )r   )rb   NN)r=   r>   rc   r+   rd   r+   )r   r+   r   r+   r,   r+   r-   r+   r.   r+   r/   r0   rw   rx   )r   r   )r   r   )__name__
__module____qualname____doc__r   r%   r;   r]   ra   rs   rv   r   r   r   r   r   r   r   __classcell__r(   s   @r)   r   r      s         " $15	> > > > > >( !""!'+9=-E -E -E -E -E^$G $G $G $G $GLG G G G( #'%)	,3 ,3 ,3 ,3 ,3\6 6 6 !""!'+9=+-c3 c3 c3 c3 c3J     $   6   ,! ! ! !(! ! ! !(. . . . . . .r*   c            	           e Zd ZdZdddddddg dddddd	d
dez  dez  dddiddiddidf fd	Zd Zd Zd Zd Z	 xZ
S )r   ak  An extension of :class:`ThreeDScene` with more settings.

    It has some extra configuration for axes, spheres,
    and an override for low quality rendering. Further key differences
    are:

    * The camera shades applicable 3DMobjects by default,
      except if rendering in low quality.
    * Some default params for Spheres and Axes have been added.

    T)should_apply_shadingexponential_projectionrb   r   )r   rb   r   )	unit_sizetick_frequencynumbers_with_elongated_ticksstroke_width)num_axis_piecesaxis_config)   0   )radius
resolutionr   ir   r   Fr   r   )   r   )camera_configthree_d_axes_configsphere_configc                   || _         || _        || _        || _        || _        || _        | j        j        d         t          d         k    ri }n| j        }t          ||          } t                      j
        di | d S )Npixel_widthr!   )cut_axes_at_radiusr   r   r   default_angled_camera_positionlow_quality_configr2   r   r   r$   r%   )
r&   r   r   r   r   r   r   r'   _configr(   s
            r)   r%   zSpecialThreeDScene.__init__  s    6 #5*#6 *.L+"4=&}59NNNGG-G)'6::##7#####r*   c           	     N   t          di | j        }|D ]}| j        r|                                }|                    d          }|                    d          }|                                }t          t          ||          t          ||          t          ||                    }|D ]	}d|_        
|	                    |j
                   |j        |j
        _        |j        D ]9}	|	                    t          d|	                                z                       :|S )z}Return a set of 3D axes.

        Returns
        -------
        :class:`.ThreeDAxes`
            A set of 3D axes.
        rb   Tg      ?r!   )r	   r   r   	get_startnumber_to_pointget_endr   r   shade_in_3dmatch_stylepiecessubmobjects
tick_marksrS   r   r   )
r&   axesaxisp0p1p2p3
new_piecespieceticks
             r)   get_axeszSpecialThreeDScene.get_axes  s)    55D455 	C 	CD& 	A^^%%))"--))!,,\\^^#DRLL$r2,,RMM
' - -E(,E%%&&t{333*4*@' C Ct/@/@)@AABBBBCr*   c                D    t          | j        |          }t          di |S )a1  
        Returns a sphere with the passed keyword arguments as properties.

        Parameters
        ----------
        **kwargs
            Any valid parameter of :class:`~.Sphere` or :class:`~.Surface`.

        Returns
        -------
        :class:`~.Sphere`
            The sphere object.
        r!   )r   r   r   r   s      r)   
get_spherezSpecialThreeDScene.get_sphere  s*     ));VDDr*   c                    | j         S )z
        Returns the default_angled_camera position.

        Returns
        -------
        dict
            Dictionary of phi, theta, focal_distance, and gamma.
        )r   ru   s    r)   get_default_camera_positionz.SpecialThreeDScene.get_default_camera_position  s     22r*   c                *     | j         di | j         dS )z(Sets the camera to its default position.Nr!   )r;   r   ru   s    r)   set_camera_to_default_positionz1SpecialThreeDScene.set_camera_to_default_position  s$    ##JJd&IJJJJJr*   )r   r   r   r   r   r%   r   r   r   r   r   r   s   @r)   r   r     s       
 
  /3tTT "#09		 !	 
 
 "#(;;<G^(
 (
 5e<$5q#9*H5
 
)&$ &$ &$ &$ &$ &$P  0     "	3 	3 	3K K K K K K Kr*   ),r   
__future__r   __all__r   collections.abcr   r   numpyrg   manim.mobject.geometry.liner   )manim.mobject.graphing.coordinate_systemsr	   #manim.mobject.opengl.opengl_mobjectr
   &manim.mobject.three_d.three_dimensionsr   manim.mobject.value_trackerr    r   animation.animationr   animation.transformr   camera.three_d_camerar   	constantsr   r   mobject.mobjectr    mobject.types.vectorized_mobjectr   r   renderer.opengl_rendererr   scene.scener   utils.config_opsr   r   r   r!   r*   r)   <module>r      s   N N " " " " " ".
/  . . . . . . . .     , , , , , , @ @ @ @ @ @ = = = = = = 9 9 9 9 9 9 4 4 4 4 4 4       + + + + + + + + + + + + 0 0 0 0 0 0 - - - - - - - - % % % % % % F F F F F F F F 3 3 3 3 3 3       6 6 6 6 6 6S. S. S. S. S.% S. S. S.lkK kK kK kK kK kK kK kK kK kKr*   