
    ^j8                       d Z ddlmZ ddlmZmZmZ ddlmZ ddl	Z	ddl	m
Z
mZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZ er.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 ddl"m#Z# d*d+dZ$d,dZ%d,dZ& G d d          Z' G d  d!ej                  Z( G d" d#e(          Z) G d$ d%e(          Z* G d& d'e'          Z+ G d( d)e'          Z, e             dS )-a  Loading of 3D scenes and models.

The :py:mod:`~pyglet.model` module provides an interface for loading 3D "scenes"
and models. A :py:class:`~pyglet.model.Scene` is a logical container that can
contain the data of one or more models, and is closely based on the design
of the glTF format.

The following example loads a ``"teapot.obj"`` file. The wavefront format
only contains a single model (mesh)::

    import pyglet

    window = pyglet.window.Window()
    batch = pyglet.graphics.Batch()

    scene = pyglet.model.load('teapot.obj')
    models = scene.create_models(batch=batch)

    @window.event
    def on_draw():
        batch.draw()

    pyglet.app.run()


You can also load scenes with :py:meth:`~pyglet.resource.scene`.
See :py:mod:`~pyglet.resource` for more information.
    )annotations)pisincos)TYPE_CHECKINGN)glgraphics)Mat4   )add_default_codecs)registry)MaterialSceneSimpleMaterial)BinaryIOTextIO)Texture)BatchGroup)ShaderProgram)
VertexList)ModelDecoderfilenamestrfileBinaryIO | TextIO | NonedecoderModelDecoder | Nonereturnr   c                \    |r|                     | |          S t          j         | |          S )a  Load a 3D scene from a file.

    Args:
        filename:
            Used to guess the scene format, or to load the file if ``file`` is unspecified.
        file:
            An open file containing the source of the scene data in any supported format.
        decoder:
            The specific decoder to use to load the Scene. If None, use default decoders
            that match the filename extension.
    )decode_codec_registry)r   r   r   s      P/home/agentuser/manim-venv/lib/python3.11/site-packages/pyglet/model/__init__.pyloadr$   4   s3      .~~h---!(D111    r   c                 |    t           j        j                            t          j        dft          j        df          S Nvertexfragment)pygletr   current_contextcreate_programMaterialGroupdefault_vert_srcdefault_frag_src r%   r#   get_default_shaderr1   F   s9    9$33]5SU]4^5B5SU_4`b b br%   c                 |    t           j        j                            t          j        dft          j        df          S r'   )r*   r   r+   r,   TexturedMaterialGroupr.   r/   r0   r%   r#   get_default_textured_shaderr4   K   s:    9$335J5[]e4f5J5[]g4hj j jr%   c                      e Zd ZdZdddZedd            Zej        dd            Zedd            Zej        dd            ZdS )ModelzJInstance of a 3D object.

    See the module documentation for usage.
    Nvertex_listslist[VertexList]groupslist[Group]batchBatch | Noner   Nonec                |    || _         || _        |pt          j                    | _        t                      | _        dS )af  Create a model instance.

        Args:
            vertex_lists:
                A list of :py:class:`~pyglet.graphics.VertexList` or
                :py:class:`~pyglet.graphics.IndexedVertexList`.
            groups:
                A list of :py:class:`~pyglet.model.TexturedMaterialGroup`, or
                 :py:class:`~pyglet.model.MaterialGroup`. Each group corresponds
                 to a vertex list in ``vertex_lists`` at the same index.
            batch:
                The batch to add the model to. If no batch is provided,
                the model will maintain its own internal batch.
        N)r7   r9   r	   r   _batchr
   _modelview_matrix)selfr7   r9   r;   s       r#   __init__zModel.__init__V   s9     )/x~//!%r%   r   c                    | j         S )a=  The graphics Batch that the Model belongs to.

        The Model can be migrated from one batch to another, or removed from
        a batch (for individual drawing). If not part of any batch, the Model
        will keep its own internal batch. Note that batch migration can be
        an expensive operation.
        )r?   rA   s    r#   r;   zModel.batchj   s     {r%   c                    | j         |k    rd S |t          j                    }t          | j        | j                  D ],\  }}| j                             |t          j        ||           -|| _         d S N)	r?   r	   r   zipr9   r7   migrater   GL_TRIANGLES)rA   r;   groupvlists       r#   r;   zModel.batchu   sv    ;%F=N$$ET->?? 	F 	FLE5KruEEEEr%   r
   c                    | j         S rF   )r@   rD   s    r#   matrixzModel.matrix   s    %%r%   rM   c                6    || _         | j        D ]	}||_        
d S rF   )r@   r9   rM   )rA   rM   rJ   s      r#   rM   zModel.matrix   s.    !'[ 	" 	"E!ELL	" 	"r%   rF   )r7   r8   r9   r:   r;   r<   r   r=   )r   r   )r;   r<   )r   r
   )rM   r
   )	__name__
__module____qualname____doc__rB   propertyr;   setterrM   r0   r%   r#   r6   r6   P   s         
( ( ( ( ((    X \
 
 
 \
 & & & X& ]" " " ]" " "r%   r6   c                  V     e Zd ZU ded<   ded<    e            Zded<   dd fdZ xZS )BaseMaterialGroupr   r.   r/   r
   rM   r   Nmaterialr   programr   orderintparentGroup | Noner   r=   c                h    t                                          ||           || _        || _        d S rF   )superrB   rW   rX   )rA   rW   rX   rY   r[   	__class__s        r#   rB   zBaseMaterialGroup.__init__   s/    ''' r%   r   N)
rW   r   rX   r   rY   rZ   r[   r\   r   r=   )rO   rP   rQ   __annotations__r
   rM   rB   __classcell__r_   s   @r#   rV   rV      ss         466F          r%   rV   c                  D     e Zd ZdZdZ	 dd fdZddZddZddZ xZ	S )r3   a  #version 330 core
    in vec3 POSITION;
    in vec3 NORMAL;
    in vec2 TEXCOORD_0;
    in vec4 COLOR_0;

    out vec3 position;
    out vec3 normal;
    out vec2 texcoord_0;
    out vec4 color_0;    

    uniform WindowBlock
    {
        mat4 projection;
        mat4 view;
    } window;

    uniform mat4 model;

    void main()
    {
        mat4 mv = window.view * model;
        vec4 pos = mv * vec4(POSITION, 1.0);
        gl_Position = window.projection * pos;
        mat3 normal_matrix = transpose(inverse(mat3(mv)));

        position = pos.xyz;
        normal = normal_matrix * NORMAL;
        texcoord_0 = TEXCOORD_0;
        color_0 = COLOR_0;
    }
    a  #version 330 core
    in vec4 color_0;
    in vec3 normal;
    in vec2 texcoord_0;
    in vec3 position;
    out vec4 final_colors;

    uniform sampler2D our_texture;

    void main()
    {
        float l = dot(normalize(-position), normalize(normal));
        vec4 tex_color = texture(our_texture, texcoord_0) * color_0;
        // 75/25 light ambient
        final_colors = tex_color * l * 0.75 + tex_color * vec4(0.25);
    }
    r   NrW   r   rX   r   texturer   rY   rZ   r[   r\   c                ^    t                                          ||||           || _        d S rF   )r^   rB   re   )rA   rW   rX   re   rY   r[   r_   s         r#   rB   zTexturedMaterialGroup.__init__   s,    7E6:::r%   r   r=   c                    t          j        t           j                   t          j        | j        j        | j        j                   | j                                         | j	        | j        d<   d S Nmodel)
r   glActiveTextureGL_TEXTURE0glBindTexturere   targetidrX   userM   rD   s    r#   	set_statezTexturedMaterialGroup.set_state   sY    
2>***
,dlo>>> $Wr%   c                p    t          | j        j        | j        j        | j        | j        | j        f          S rF   )hashre   rm   rn   rX   rY   r[   rD   s    r#   __hash__zTexturedMaterialGroup.__hash__   s,    T\($,/4<UYU`abbbr%   boolc                   | j         |j         u os| j        |j        k    oc| j        j        |j        j        k    oI| j        j        |j        j        k    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S rF   )r_   rW   re   rm   rn   rX   rY   r[   rA   others     r#   __eq__zTexturedMaterialGroup.__eq__   s    %/1 ,/,#u}';;, 5=#33, -	,
 
ek), u|+	-r%   r`   )
rW   r   rX   r   re   r   rY   rZ   r[   r\   r   r=   )r   rZ   )r   rt   )
rO   rP   rQ   r.   r/   rB   rp   rs   rx   rb   rc   s   @r#   r3   r3      s        @& KO      
, , , ,c c c c- - - - - - - -r%   r3   c                  *    e Zd ZdZdZd	dZd Zd ZdS )
r-   aF  #version 330 core
    in vec3 POSITION;
    in vec3 NORMAL;
    in vec4 COLOR_0;

    out vec4 color_0;
    out vec3 normal;
    out vec3 position;

    uniform WindowBlock
    {
        mat4 projection;
        mat4 view;
    } window;

    uniform mat4 model;

    void main()
    {
        mat4 mv = window.view * model;
        vec4 pos = mv * vec4(POSITION, 1.0);
        gl_Position = window.projection * pos;
        mat3 normal_matrix = transpose(inverse(mat3(mv)));

        position = pos.xyz;
        color_0 = COLOR_0;
        normal = normal_matrix * NORMAL;
    }
    a.  #version 330 core
    in vec4 color_0;
    in vec3 normal;
    in vec3 position;
    out vec4 final_colors;

    void main()
    {
        float l = dot(normalize(-position), normalize(normal));
        // 75/25 light ambient
        final_colors = color_0 * l * 0.75 + color_0 * vec4(0.25);
    }
    r   r=   c                V    | j                                          | j        | j         d<   d S rh   )rX   ro   rM   rD   s    r#   rp   zMaterialGroup.set_state  s*     $Wr%   c                P    t          | j        | j        | j        | j        f          S rF   )rr   rW   rX   rY   r[   rD   s    r#   rs   zMaterialGroup.__hash__  s!    T]DL$*dkJKKKr%   c                    | j         |j         u o?| j        |j        k    o/| j        |j        k    o| j        |j        k    o| j        |j        k    S rF   )r_   rW   rX   rY   r[   rv   s     r#   rx   zMaterialGroup.__eq__  s[    %/1 ,/,-, 
ek), u|+		-r%   Nry   )rO   rP   rQ   r.   r/   rp   rs   rx   r0   r%   r#   r-   r-      sY        :, , , ,L L L- - - - -r%   r-   c                  *     e Zd Z	 	 d fd	Zd Z xZS )Cube      ?r   r   r   r   Nc	                   || _         || _        || _        || _        || _        |r|nt                      | _        |r|nt          d          | _        t          j
                            | j        | j        |          | _        |                                 | _        t                                          | j        g| j        g| j                   d S )NcubenamerW   rX   r[   )_width_height_depth_colorr?   r1   _programr   	_materialr*   ri   r-   _group_create_vertexlist_vlistr^   rB   )
rA   widthheightdepthcolorrW   r;   rJ   rX   r_   s
            r#   rB   zCube.__init__   s    #*D0B0D0D &.N>v3N3N3Nl00$.RVR_hm0nn--//$+t{CCCCCr%   c                   | j         dz  }| j        dz  }| j        dz  }g | | | || | ||| | || || || | || ||||||| | || ||||||| | | || | | | || | ||| || ||| |||| ||| | ||| ||| | | | | }g d}g d}| j                            t          |          dz  t          j        j        || j	        | j
        d|fd|fd| j        t          |          dz  z  f          S )N   )Hr   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   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   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   fr;   rJ   POSITIONNORMALCOLOR_0)r   r   r   r   vertex_list_indexedlenr*   r   rI   r?   r   r   )rA   whdverticesnormalsindicess          r#   r   zCube._create_vertexlist2  s   K!OL1K!O
B

B

r
2
 
 
 "
 B	
 	
 2	
 
 r
 
 B
 
 
 B
 
 
 
 
 
 
 r
 2
 
 r
 
 
 
 
 
 
 "
  B!
  !
  !
" B#
" #
" B#
$ B%
$ %
$ 2%
& B'
& '
& '
* B+
* +
* 2+
, -
, -
, "-
. /
. /
. /
0 B1
0 1
0 1
4 B5
4 5
4 5
6 7
6 r7
6 7
8 9
8 r9
8 29
: B;
: ;
: B;
@; ; ;% % % }00X!1CVYE[]d7;{$+;>/9<g:=t{cRZmm_`N`?a9b	 1 d d 	dr%   )r   r   r   r   NNNNrO   rP   rQ   rB   r   rb   rc   s   @r#   r   r     s_        ?S@DD D D D D D$7d 7d 7d 7d 7d 7d 7dr%   r   c                  *     e Zd Z	 	 d fd	Zd Z xZS )Spherer      r   Nc	                   || _         || _        || _        || _        || _        |r|nt                      | _        |r|nt          d          | _        t          j
                            | j        | j        |          | _        |                                 | _        t                                          | j        g| j        g| j                   d S )Nspherer   r   )_radius_stacks_sectorsr   r?   r1   r   r   r   r*   ri   r-   r   r   r   r^   rB   )
rA   radiusstackssectorsr   rW   r;   rJ   rX   r_   s
            r#   rB   zSphere.__init__n  s    #*D0B0D0D &.P>x3P3P3Pl00$.RVR_hm0nn--//$+t{CCCCCr%   c                   | j         dz  }| j        }| j        }g }g }g }dt          z  |z  }t          |z  }t	          |dz             D ]D}	t          dz  |	|z  z
  }
t	          |dz             D ]}||z  }|                    |t          |
          z  t          |          z             |                    |t          |
          z  t          |          z             |                    |t          |
          z             |                    t          |
          t          |          z             |                    t          |
          t          |          z             |                    t          |
                     Ft	          |          D ]`}	t	          |          D ]N}|	|dz   z  |z   }||z   dz   }|                    |||dz   g           |                    ||dz   |dz   g           Oa| j	        
                    t          |          dz  t          j        j        || j        | j        d|fd|fd| j        t          |          dz  z  f          S )Nr   r   r   r   r   )r   r   r   r   rangeappendr   r   extendr   r   r   r*   r   rI   r?   r   r   )rA   r   r   r   r   r   r   sector_step
stack_stepistack_anglejsector_anglefirstseconds                  r#   r   zSphere._create_vertexlist  s{   !-"fw&&[
vz"" 		1 		1Aq&1z>1K7Q;'' 1 1 ;[)9)9 9C<M<M MNNN[)9)9 9C<M<M MNNN[)9)9 9:::s;//#l2C2CCDDDs;//#l2C2CCDDDs;//00001 v 	? 	?A7^^ ? ?Wq[)A-1,vvz:;;;vz519=>>>>	? }00X!1CVYE[]d7;{$+;>/9<g:=t{cRZmm_`N`?a9b	 1 d d 	dr%   )r   r   r   r   NNNNr   rc   s   @r#   r   r   l  s_        @T@DD D D D D D$#d #d #d #d #d #d #dr%   r   )NN)r   r   r   r   r   r   r   r   )r   r   )-rR   
__future__r   mathr   r   r   typingr   r*   r   r	   pyglet.mathr
   codecsr   _add_default_codecsr   r"   codecs.baser   r   r   r   r   pyglet.imager   pyglet.graphicsr   r   pyglet.graphics.shaderr   pyglet.graphics.vertexdomainr   pyglet.model.codecsr   r$   r1   r4   r6   rV   r3   r-   r   r   r0   r%   r#   <module>r      s   8 # " " " " "                                      = = = = = = / / / / / / 8 8 8 8 8 8 8 8 8 8 1''''''''$$$$$$,,,,,,,,444444777777$$$$$$0000002 2 2 2 2$b b b b
j j j j
:" :" :" :" :" :" :" :"z       H- H- H- H- H-- H- H- H-V8- 8- 8- 8- 8-% 8- 8- 8-vKd Kd Kd Kd Kd5 Kd Kd Kd\7d 7d 7d 7d 7dU 7d 7d 7dt       r%   