
    \
j'                         d Z ddlZddlT ddlmZ ddlmZ ddlmZmZm	Z	 ddlm
Z
mZ g d	Zdd
Z G d d          Z G d d          Z G d dej                  Z G d dej                  Z e	             dS )a
  Loading of 3D models.

A :py:class:`~pyglet.model.Model` is an instance of a 3D object.

The following example loads a ``"teapot.obj"`` model::

    import pyglet

    window = pyglet.window.Window()

    teapot = pyglet.model.load('teapot.obj')

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

    pyglet.app.run()


You can also load models with :py:meth:`~pyglet.resource.model`.
See :py:mod:`~pyglet.resource` for more information.


Efficient Drawing
=================

As with Sprites or Text, Models can be added to a
:py:class:`~pyglet.graphics.Batch` for efficient drawing. This is
preferred to calling their ``draw`` methods individually.  To do this,
simply pass in a reference to the :py:class:`~pyglet.graphics.Batch`
instance when loading the Model::


    import pyglet

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

    teapot = pyglet.model.load('teapot.obj', batch=batch)

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

    pyglet.app.run()


.. versionadded:: 1.4
    N)*)graphics   )ModelDecodeException)add_encodersadd_decodersadd_default_model_codecs)get_encodersget_decoders)      ?        r   r   r   r   r   r   r   r   r   r   r   r   r   r   c                 L   |st          | d          }t          |d          s&t          j        |                                          }	 |r+|                    || |          |                                 S d}t          |           D ]q}	 |                    || |          }|c |                                 S # t          $ r3}|r|j	        |j	        k     r|}|
                    d           Y d}~jd}~ww xY w|st          d          |# |                                 w xY w)a  Load a 3D model from a file.

    :Parameters:
        `filename` : str
            Used to guess the model format, and to load the file if `file` is
            unspecified.
        `file` : file-like object or None
            Source of model data in any supported format.        
        `decoder` : ModelDecoder or None
            If unspecified, all decoders that are registered for the filename
            extension are tried. An exception is raised if no codecs are
            registered for the file extension, or if decoding fails.
        `batch` : Batch or None
            An optional Batch instance to add this model to.

    :rtype: :py:mod:`~pyglet.model.Model`
    rbseekNr   z0No decoders are available for this model format.)openhasattrioBytesIOreaddecodecloser   r   exception_priorityr   )filenamefiledecoderbatchfirst_exceptionmodeles          O/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/model/__init__.pyloadr!   f   sP   &  $Hd##4   'z$))++&& 	">>$%88" 	

 #O'11 ! !!#NN45AAE LL 	

 , ! ! !+ ,+>AUUU*+IIaLLLLLLLL	! # _*+]^^^!!

s<   
D 7D B:#D :
C7)C2-D 2C77D D#c                       e Zd ZdZd Zed             Zej        d             Zed             Zej        d             Zd Z	dS )	ModelzJInstance of a 3D object.

    See the module documentation for usage.
    c                 H    || _         || _        || _        t          | _        dS )al  Create a model.

        :Parameters:
            `vertex_lists` : list
                A list of `~pyglet.graphics.VertexList` or
                `~pyglet.graphics.IndexedVertexList`.
            `groups` : list
                A list of `~pyglet.model.TexturedMaterialGroup`, or
                 `~pyglet.model.MaterialGroup`. Each group corresponds to
                 a vertex list in `vertex_lists` of the same index.
            `batch` : `~pyglet.graphics.Batch`
                Optional batch to add the model to. If no batch is provided,
                the model will maintain it's own internal batch.
        N)groupsvertex_lists_batch_default_identity_matrix)selfr&   r%   r   s       r    __init__zModel.__init__   s%     ((    c                     | j         S )ap  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 it's own internal batch. Note that batch migration can be
        an expensive operation.

        :type: :py:class:`pyglet.graphics.Batch`
        )r'   r*   s    r    r   zModel.batch   s     {r,   c                     | j         |k    rd S |t          j                                        }t	          | j        | j                  D ]'\  }}| j                             |t          ||           (|| _         d S N)	r'   pygletr   Batchzipr%   r&   migrateGL_TRIANGLES)r*   r   groupvlists       r    r   zModel.batch   sz    ;%F=O))++ET->?? 	C 	CLE5K|UEBBBBr,   c                     | j         S )zTransformation matrix.

        A 4x4 matrix containing the desired transformation to
        apply. The data should be provided as a flat list or tuple.

        :type: list or tuple
        )r)   r.   s    r    matrixzModel.matrix   s     |r,   c                 @    | j         D ]}||j        d d <   || _        d S r0   )r%   r9   r)   )r*   r9   r6   s      r    r9   zModel.matrix   s/    [ 	% 	%E$ELOOr,   c                 D    | j                             | j                   dS )zDraw the model.

        This is not recommended. See the module documentation
        for information on efficient drawing of multiple models.
        N)r'   draw_subsetr&   r.   s    r    drawz
Model.draw   s#     	 122222r,   N)
__name__
__module____qualname____doc__r+   propertyr   setterr9   r=    r,   r    r#   r#      s         
) ) )( 
 
 X
 \
 
 \
   X ]  ]
3 3 3 3 3r,   r#   c                       e Zd ZdZddZdS )Material)namediffuseambientspecularemission	shininesstexture_nameNc                     || _         t          dz  | | _        t          dz  | | _        t          dz  | | _        t          dz  | | _        || _        || _        d S )N   )rG   GLfloatrH   rI   rJ   rK   rL   rM   )r*   rG   rH   rI   rJ   rK   rL   rM   s           r    r+   zMaterial.__init__   s^    	!g.!g. 1x0 1x0"(r,   r0   )r>   r?   r@   	__slots__r+   rD   r,   r    rF   rF      s-        cI) ) ) ) ) )r,   rF   c                   <     e Zd Zd fd	ZefdZd Zd Zd Z xZ	S )TexturedMaterialGroupNc                     t          t          |                                            || _        || _        t          dz  |pt           | _        d S N   )superrS   r+   materialtexturerP   r(   r9   )r*   rX   rY   r9   	__class__s       r    r+   zTexturedMaterialGroup.__init__   sH    #T**33555 |f&A0ABr,   c                    t          | j        j                   t          | j        j        | j        j                   | j        }t          |t          |j                   t          |t          |j
                   t          |t          |j                   t          |t          |j                   t          |t           |j                   t%                       t'          | j                   d S r0   )glEnablerY   targetglBindTextureidrX   glMaterialfv
GL_DIFFUSErH   
GL_AMBIENTrI   GL_SPECULARrJ   GL_EMISSIONrK   glMaterialfGL_SHININESSrL   glPushMatrixglMultMatrixfr9   r*   facerX   s      r    	set_statezTexturedMaterialGroup.set_state   s    $%%%dl)4<?;;;=T:x'7888T:x'7888T;(9:::T;(9:::D,(:;;;dk"""""r,   c                 |    t                       t          | j        j                   t          t                     d S r0   )glPopMatrix	glDisablerY   r]   GL_COLOR_MATERIALr.   s    r    unset_statez!TexturedMaterialGroup.unset_state  s3    $,%&&&#$$$$$r,   c                     dS NFrD   r*   others     r    __eq__zTexturedMaterialGroup.__eq__
  	     ur,   c                 L    t          | j        j        | j        j        f          S r0   )hashrY   r_   r]   r.   s    r    __hash__zTexturedMaterialGroup.__hash__  s    T\_dl&9:;;;r,   r0   
r>   r?   r@   r+   GL_FRONT_AND_BACKrk   rp   ru   ry   __classcell__rZ   s   @r    rS   rS      s        C C C C C C / # # # #% % %
  
< < < < < < <r,   rS   c                   <     e Zd Zd fd	ZefdZd Zd Zd Z xZ	S )MaterialGroupNc                     t          t          |                                            || _        t	          dz  |pt
           | _        d S rU   )rW   r   r+   rX   rP   r(   r9   )r*   rX   r9   rZ   s      r    r+   zMaterialGroup.__init__  s@    mT""++--- |f&A0ABr,   c                    t          t                     | j        }t          |t          |j                   t          |t          |j                   t          |t          |j	                   t          |t          |j                   t          |t          |j                   t                       t!          | j                   d S r0   )rn   GL_TEXTURE_2DrX   r`   ra   rH   rb   rI   rc   rJ   rd   rK   re   rf   rL   rg   rh   r9   ri   s      r    rk   zMaterialGroup.set_state  s    -   =T:x'7888T:x'7888T;(9:::T;(9:::D,(:;;;dk"""""r,   c                 J    t                       t          t                     d S r0   )rm   rn   ro   r.   s    r    rp   zMaterialGroup.unset_state&  s     #$$$$$r,   c                     dS rr   rD   rs   s     r    ru   zMaterialGroup.__eq__*  rv   r,   c                     | j         }t          t          |j                  t          |j                  z   t          |j                  z   t          |j                  z   |j        f          S r0   )rX   rx   tuplerH   rI   rJ   rK   rL   )r*   rX   s     r    ry   zMaterialGroup.__hash__/  sn    =U8+,,uX5E/F/FF8,--.05h6G0H0HIJRJ\^ _ _ 	_r,   r0   rz   r}   s   @r    r   r     s        C C C C C C
 / 
# 
# 
# 
#% % %  
_ _ _ _ _ _ _r,   r   )NNN)rA   r   	pyglet.glr1   r   codecsr   r   r   r	   r
   r   r(   r!   r#   rF   GrouprS   r   rD   r,   r    <module>r      s{  F0 0d 
			           ( ( ( ( ( ( H H H H H H H H H H . . . . . . . .) ) ) , , , ,^K3 K3 K3 K3 K3 K3 K3 K3\
) 
) 
) 
) 
) 
) 
) 
) <  <  <  <  <HN  <  <  <F_ _ _ _ _HN _ _ _D       r,   