
    kjz                    p    d Z ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
 ddlmZ  G d	 d
          ZdS )z1
Wrapper for a loaded mesh / vao with properties
    )annotations)OptionalN)VAO   )Camera)Meshc                     e Zd ZdZ	 	 	 	 d7d8dZed9d            Zej        d:d            Zed;d            Zej        d<d            Zed=d            Z	e	j        d>d            Z	ed?d            Z
e
j        d@d            Z
ed?d            Zej        d@d            ZedAd            ZdBd!Z	 dCdDd'ZdEd,ZdFd-ZdGd3ZdHd5ZdId6ZdS )JNodezA generic scene node containing a mesh or camera
    and/or a container for other nodes. Nodes and their children
    represents the scene tree.
    NnameOptional[str]cameraOptional[Camera]meshOptional[Mesh]matrixOptional[glm.mat4]c                ~    || _         || _        || _        || _        t	          j        d          | _        g | _        dS )zCreate a node.

        Keyword Args:
            name: Name of the node
            camera: Camera to store in the node
            mesh: Mesh to store in the node
            matrix: The node's matrix
        g      ?N)_name_camera_mesh_matrixglmmat4_matrix_global	_children)selfr   r   r   r   s        U/home/agentuser/manim-venv/lib/python3.11/site-packages/moderngl_window/scene/node.py__init__zNode.__init__   s;     

!hsmm')    returnc                    | j         S )zstr: Get or set the node namer   r   s    r   r   z	Node.name0        zr   valuestrNonec                    || _         d S Nr"   r   r%   s     r   r   z	Node.name5       


r   c                    | j         S )z<:py:class:`~moderngl_window.scene.Mesh`: The mesh if presentr   r#   s    r   r   z	Node.mesh9   r$   r   r   c                    || _         d S r)   r-   r*   s     r   r   z	Node.mesh>   r+   r   c                    | j         S )z@:py:class:`~moderngl_window.scene.Camera`: The camera if presentr   r#   s    r   r   zNode.cameraB        |r   r   c                    || _         d S r)   r0   r*   s     r   r   zNode.cameraG       r   c                    | j         S )zglm.mat4x4: Note matrix (local)r   r#   s    r   r   zNode.matrixK   r1   r   glm.mat4c                    || _         d S r)   r5   r*   s     r   r   zNode.matrixP   r3   r   c                    | j         S )zNglm.matx4: The global node matrix containing transformations from parent nodesr   r#   s    r   matrix_globalzNode.matrix_globalT   s     ""r   c                    || _         d S r)   r9   r*   s     r   r:   zNode.matrix_globalY   s    #r   list['Node']c                    | j         S )zlist: List of children)r   r#   s    r   childrenzNode.children]   s     ~r   node'Node'c                :    | j                             |           dS )z`Add a child to this node

        Args:
            node (Node): Node to add as a child
        N)r   append)r   r?   s     r   	add_childzNode.add_childb   s      	d#####r           projection_matrixcamera_matrixtimefloatc                    | j         r#| j                             || j        ||           | j        D ]}|                    |||           dS )zDraw node and children.

        Keyword Args:
            projection_matrix: projection matrix
            camera_matrix: camera_matrix
            time: The current time
        )rE   model_matrixrF   rG   )rE   rF   rG   N)r   drawr   r   )r   rE   rF   rG   childs        r   rK   z	Node.drawj   s     : 	JOO"3!0+	     ^ 	 	EJJ"3+     	 	r   programmoderngl.Programvaor   c                    | j         rL|
J d            | j        
J d            |
J d            | j                             || j        |||           | j        D ]}|                    ||||           dS )a0  Draw bounding box around the node and children.

        Keyword Args:
            projection_matrix: projection matrix
            camera_matrix: camera_matrix
            program (moderngl.Program): The program to render the bbox
            vao: The vertex array representing the bounding box
        N1Can not draw bbox, the projection matrix is empty-Can not draw bbox, the global matrix is emptyz-Can not draw bbox, the camera matrix is empty)r   r   	draw_bboxr>   )r   rE   rF   rM   rO   rL   s         r   rS   zNode.draw_bbox   s     : 	!--B .--&224c222 ,,.],,,J  !4#6wPS   ] 	L 	LEOO-}gsKKKK	L 	Lr   c                    | j         r>|
J d            | j        
J d            | j                             || j        |           | j        D ]}|                    || j        |           dS )zRender the node as wireframe.

        Keyword Args:
            projection_matrix (bytes): projection matrix
            camera_matrix (bytes): camera_matrix
            program (moderngl.Program): The program to render wireframe
        NrQ   rR   )r   r   draw_wireframer>   )r   rE   rF   rM   rL   s        r   rU   zNode.draw_wireframe   s     : 	W!--B .--&224c222J%%&79LgVVV] 	R 	RE  !2D4GQQQQ	R 	Rr   view_matrixbbox_minglm.vec3 | Nonebbox_maxtuple[glm.vec3, glm.vec3]c                    | j         
| j         |z  }| j        r| j                            |||          \  }}| j        D ]}|                    |||          \  }}||fS )zRecursive calculation of scene bbox.

        Keyword Args:
            view_matrix (numpy.ndarray): view matrix
            bbox_min: min bbox values
            bbox_max: max bbox values
        )r   r   calc_global_bboxr   )r   rV   rW   rY   rL   s        r   r\   zNode.calc_global_bbox   s~     <#,4K: 	^!%!<!<[(T\!]!]Hh^ 	Y 	YE!&!7!7Xx!X!XHhh!!r   parent_matrixc                    | j         5|| j         z  | _        | j        D ]}|                    | j                   dS || _        | j        D ]}|                    |           dS )z|Calculate the model matrix related to all parents.

        Args:
            parent_matrix: Matrix for parent node
        N)r   r   r   calc_model_mat)r   r]   rL   s      r   r_   zNode.calc_model_mat   s     <#"/$,">D : :$$T%89999: : #0D 4 4$$]33334 4r   c                6    d                     | j                  S )Nz<Node name={}>)formatr   r#   s    r   __repr__zNode.__repr__   s    &&ty111r   )NNNN)r   r   r   r   r   r   r   r   )r    r   )r%   r&   r    r'   )r    r   )r%   r   r    r'   )r    r   )r%   r   r    r'   )r    r   )r%   r6   r    r'   )r    r<   )r?   r@   r    r'   )rD   )rE   r6   rF   r6   rG   rH   r    r'   )
rE   r   rF   r   rM   rN   rO   r   r    r'   )rE   r   rF   r   rM   rN   r    r'   )rV   r6   rW   rX   rY   rX   r    rZ   )r]   r6   r    r'   )r    r&   )__name__
__module____qualname____doc__r   propertyr   setterr   r   r   r:   r>   rC   rK   rS   rU   r\   r_   rb    r   r   r
   r
      sO         ##'#%)* * * * *2    X 
[   [    X 
[   [    X ]   ]    X ]   ] # # # X# $ $ $ $    X$ $ $ $ 	    8L L L L8R R R R." " " "*4 4 4 4"2 2 2 2 2 2r   r
   )rf   
__future__r   typingr   r   modernglmoderngl_window.opengl.vaor   r   r   r   r   r
   ri   r   r   <module>rn      s     # " " " " "       



  * * * * * *            O2 O2 O2 O2 O2 O2 O2 O2 O2 O2r   