Ë
    Ûvžjl  ã                   óD   — d Z ddlZddlmZ ddlmZ d	d„Z G d„ d«      Zy)
zAnimation class for the vieweré    N)Únumpy_to_jsoné   )Ú	send_datac                 ó¦   — g }|› d| j                   › �}|j                  |«       | j                  D ]  }|j                  t	        ||«      «       Œ |S )z&Collect all paths in the assembly treeÚ/)ÚlabelÚappendÚchildrenÚextendÚcollect_paths)ÚassemblyÚpathÚresultÚnew_pathÚchilds        úe/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/ocp_vscode/animation.pyr   r      sP   € à€FØ��q˜Ÿ™Ð(Ð)€HØ
‡M�M�(ÔØ×"Ô"ˆØ�‰”m E¨8Ó4Õ5ð #à€Mó    c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)Ú	Animationz)Class to create animations for the viewerc                 óþ   — g | _         t        |d«      xr t        |d«       | _        t        |d«      | _        | j                  r)t	        |j
                  j                  «       «      | _        y t        |«      | _        y )NÚmatesÚfq_nameÚjoints)	ÚtracksÚhasattrÚis_cadqueryÚis_build123dÚlistÚobjectsÚkeysÚpathsr   )Úselfr   s     r   Ú__init__zAnimation.__init__&   so   € ØˆŒÜ" 8¨WÓ5ò 
¼gØ�ió?
ð ;
ˆÔô $ H¨hÓ7ˆÔØ×ÒÜ˜h×.Ñ.×3Ñ3Ó5Ó6ˆD�Jä& xÓ0ˆD�Jr   c                 ó^  — t        |«      t        |«      k7  rt        d«      ‚| j                  rS|j                  d«      j	                  d«      \  }}}|| j
                  vs|| j
                  dgz   vrt        d|› d�«      ‚| j                  r	 | j                  j                  ||||f«       y)aü	  
        Adding a three.js animation track.

        Parameters
        ----------
        path : string
            The path (or id) of the cad object for which this track is meant.
            Usually of the form `/top-level/level2/...`
        action : {"t", "tx", "ty", "tz", "q", "rx", "ry", "rz"}
            The action type:

            - "tx", "ty", "tz" for translations along the x, y or z-axis
            - "t" to add a position vector (3-dim array) to the current position of the CAD object
            - "rx", "ry", "rz" for rotations around x, y or z-axis
            - "q" to apply a quaternion to the location of the CAD object
        times : list of float or int
            An array of floats describing the points in time where CAD object (with id `path`) should be at the location
            defined by `action` and `values`
        values : list of float or int
            An array of same length as `times` defining the locations where the CAD objects should be according to the
            `action` provided. Formats:

            - "tx", "ty", "tz": float distance to move
            - "t": 3-dim tuples or lists defining the positions to move to
            - "rx", "ry", "rz": float angle in degrees
            - "q" quaternions of the form (x,y,z,w) the represent the rotation to be applied

        Examples
        --------
        ```
        AnimationTrack(
            '/bottom/left_middle/lower',                                # path
            'rz',                                                       # action
            [0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0],              # times (seconds)
            [-15.0, -15.0, -15.0, 9.7, 20.0, 9.7, -15.0, -15.0, -15.0]  # angles
        )

        AnimationTrack(
            'base/link_4_6',                                            # path
            't',                                                        # action
            [0.0, 1.0, 2.0, 3.0, 4.0],                                  # times (seconds)
            [[0.0, 0.0, 0.0], [0.0, 1.9509, 3.9049],
            [0.0 , -3.2974, -16.7545], [0.0 , 0.05894 , -32.0217],
            [0.0 , -3.2212, -13.3424]]                                 # 3-dim positions
        )
        ```

        See also
        --------

        - [three.js NumberKeyframeTrack](https://threejs.org/docs/index.html?q=track#api/en/animation/tracks/NumberKeyframeTrack)
        - [three.js QuaternionKeyframeTrack](https://threejs.org/docs/index.html?q=track#api/en/animation/tracks/QuaternionKeyframeTrack)

        z8Parameters 'times' and 'values' need to have same lengthr   Ú zPath 'z' does not exist in assemblyN)	ÚlenÚ
ValueErrorr   ÚstripÚ	partitionr!   r   r   r	   )r"   r   ÚactionÚtimesÚvaluesÚrootÚ_Úcq_paths           r   Ú	add_trackzAnimation.add_track1   s¥   € ôx ˆu‹:œ˜V›Ò$ÜÐWÓXÐXà×ÒØ#Ÿz™z¨#›×8Ñ8¸Ó=ÑˆD�!�Wà˜4Ÿ:™:Ñ%¨¸¿
¹
ÀbÀTÑ8IÑ)IÜ  6¨$¨Ð/KÐ!LÓMÐMà×ÒØð 	�‰×Ñ˜D &¨%°Ð8Õ9r   c                 óv   — | j                   dd|idœ}t        t        j                  t	        |«      «      «       y)zAnimate the tracksÚ	animationÚspeed)ÚdataÚtypeÚconfigN)r   r   ÚjsonÚloadsr   )r"   r3   r4   s      r   ÚanimatezAnimation.animate}   s-   € àŸ™¨[ÀWÈeÐDTÑUˆÜ”$—*‘*œ]¨4Ó0Ó1Õ2r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r0   r9   © r   r   r   r   #   s   „ Ù3ò	1òJ:óX3r   r   )r%   )r=   r7   Úocp_tessellate.utilsr   Úcommsr   r   r   r>   r   r   Ú<module>rA      s$   ðÙ $ó$ å .Ý ó÷]3ò ]3r   