ó
Q¡[c           @   su   d  d l  Z  d  d l j Z d  d l j j Z d  d l j Z	 d  d l
 m Z d „  Z d „  Z d d d „  ƒ  YZ d S(   iÿÿÿÿN(   t   MAnimControlc         C   s,   t  j ƒ  } | j |  ƒ | j d ƒ } | S(   Ni    (   t   nomt   MSelectionListt   addt   getDependNode(   t   nodeNamet   selt   thisNode(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   mashGetMObjectFromNameTwo   s    c         C   s9   t  j ƒ  } | j |  ƒ t  j ƒ  } | j d | ƒ | S(   Ni    (   t   oldR   R   t   MObjectR   (   R   R   R   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   mashGetMObjectFromNameOne   s
    t   MASHDatac           B   s×   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z RS(   sØ   
    MASHData prepares data from a MASH network, ready for use with the MASH_Python node.
    It also provides utility funcitons to make working with this data easier.
    This class uses the MAYA Python API 2.0
    c         C   s  t  |  _ t  |  _ | |  _ t | ƒ |  _ t j |  j ƒ |  _ t j	 ƒ  |  _
 t j	 ƒ  |  _ t j	 ƒ  |  _ t j ƒ  |  _ t j ƒ  |  _ t j	 ƒ  |  _ t j	 ƒ  |  _ t j ƒ  |  _ t j ƒ  |  _ t j ƒ  |  _ t j ƒ  |  _ t j	 ƒ  |  _ t j	 ƒ  |  _ t j	 ƒ  |  _ t j	 ƒ  |  _ t j	 ƒ  |  _ t j	 ƒ  |  _ t j ƒ  |  _ t j ƒ  |  _ t j	 ƒ  |  _ t j	 ƒ  |  _  t j ƒ  |  _! t j ƒ  |  _" t j ƒ  |  _# t j	 ƒ  |  _$ t j ƒ  |  _% t j	 ƒ  |  _& |  j j' d ƒ } t j( |  j | ƒ } | j) |  _ |  j* ƒ  d S(   s  
        Construct a new 'MASHData' object.

        :param  -- nodeName: The name of the MASH Python node
        :object -- thisNode: The MObject of this node
        :object -- fnNode: MFnDependencyNode function set of this node
        :return -- nothing
        t   outputPointsN(+   t   Falset   usingDynamicArrayst   initialisedR   R   R   R   t   MFnDependencyNodet   fnNodet   MVectorArrayt   positiont   scalet   rotationt   MDoubleArrayt   idt
   visibilityt   colort   uvTilet   framet	   MIntArrayt
   isAnimatedt   velocityt   angularVelocityt   velocityVect   angularVelocityVect   strengtht   outPositiont   outRotationt   outScalet   outIdt   outVisibilityt   outColort	   outUvTilet   outFramet   outIsAnimatedt   outVelocityt   outVelocityVect   outAngularVelocityt   outAngularVelocityVect	   attributet   MPlugt   isConnectedt   getData(   t   selfR   t   pointsAttributet
   pointsPlug(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   __init__'   sH    				c   
      C   s‰   t  |  j ƒ } t j | ƒ } | j d ƒ } t j | | ƒ } | j ƒ  } t j | ƒ } d | } t j j }	 | j	 | |	 ƒ r… n  d  S(   Nt   inputPointst   cs_(
   R   R   R	   R   R1   R2   t	   asMObjectt   MFnArrayAttrsDatat   Typet   checkArrayExist(
   R5   t   setNamet   thisNodeOldt
   fnThisNodet   inPointsAttributet   inPointsPlugt   inPointsObjt   inputPointsDatat   colourSetNamet   dataType(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   getColorSet[   s    
c         C   s©   t  j ƒ  } | j |  j | t  j j ƒ | j |  j | t  j j ƒ t  j j } |  j	 | } t  j
 t j | j ƒ t j | j ƒ t j | j ƒ ƒ } | j | ƒ | S(   sJ   
        Returns an MTransformationMatrix of the specified point.
        (   R   t   MTransformationMatrixt   setTranslationR   t   MSpacet   kWorldt   setScaleR   t   kXYZR   t   MEulerRotationt   matht   radianst   xt   yt   zt   setRotation(   R5   t   pointIdt   tmt   roR   t   angles(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt	   getMatrixh   s    9c         C   s•   | j  t j j ƒ } | j ƒ  } g  | j | j | j f D] } t j	 | ƒ ^ q: } | j
 t j j ƒ } | |  j | <| |  j | <| |  j | <d S(   sH   
        Sets the MTransformationMatrix for the specific point.
        N(   t   translationR   RK   RL   R   RR   RS   RT   RP   t   degreesR   R$   R%   R&   (   R5   t   matrixRV   t   post   eulerRott   angleRY   R   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt	   setMatrixv   s    4c         C   s»   t  j ƒ  } | j |  t  j j ƒ | j | j | j | j f t  j j	 ƒ t  j j
 } t  j t j | j ƒ t j | j ƒ t j | j ƒ ƒ } t  j | | ƒ } | j | t  j j ƒ | S(   s7   
        Returns a local MTransformationMatrix
        (   t   omRI   RJ   RK   t   kObjectRM   RR   RS   RT   RL   RN   t   MVectorRP   RQ   RO   t   rotateBy(   R   R   R   RW   RX   t	   radAnglesR_   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   createLocalMatrix‚   s    (9c         C   sF  |  j  d ƒ |  _ |  j  d ƒ |  _ |  j  d ƒ |  _ |  j  d ƒ } |  j  d ƒ } t j t |  j ƒ d ƒ |  _ x1 t d t | ƒ ƒ D] } | | j	 |  j | <qˆ Wt j t |  j ƒ d ƒ |  _
 x1 t d t | ƒ ƒ D] } | | j	 |  j
 | <qÚ W|  j |  _ |  j |  _ |  j |  _ |  j |  _ |  j
 |  _ |  j rB|  j  d	 ƒ |  _ |  j  d
 ƒ |  _ |  j d ƒ |  _ |  j d ƒ |  _ |  j d ƒ |  _ |  j d ƒ |  _ |  j  d ƒ |  _ |  j  d ƒ |  _ |  j  d ƒ |  _ |  j |  _ |  j |  _ |  j |  _ |  j |  _ |  j |  _  |  j |  _! |  j |  _" |  j |  _# n  d S(   sw   
        Internal - called from init. Gets the data from the in attributes and sets it to the class variables.
        t   positionInPPt   rotationInPPt	   scaleInPPt   visibilityInPPt   idInPPg      ð?i    g        t	   colorInPPt
   uvTileInPPt	   frameInPPt   velocityInPPt   isAnimatedInPPt   angularVelocityInPPt   velocityVecInPPt   angularVelocityVecInPPt   calculatedStrengthN($   t   getVectorArrayR   R   R   R   R   t   lenR   t   xrangeRR   R   R$   R%   R&   R(   R'   R   R   R   t   getDoubleArrayR   R   t   getIntArrayR   R    R!   R"   R#   R)   R*   R+   R-   R,   R/   R.   R0   (   R5   t   inVist   inIdt   i(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyR4      sD    	c         C   s   t  |  j ƒ S(   sC   
        Returns the number of points in the MASH network.
        (   Rw   R   (   R5   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   count¿   s    c         C   s÷  |  j  d |  j ƒ |  j  d |  j ƒ |  j  d |  j ƒ t j t |  j ƒ t j d d d ƒ ƒ } xN t	 d t |  j
 ƒ ƒ D]4 } t j |  j
 | |  j
 | |  j
 | ƒ | | <q| Wt j t |  j ƒ t j d d d ƒ ƒ } xN t	 d t |  j ƒ ƒ D]4 } t j |  j | |  j | |  j | ƒ | | <q÷ W|  j  d | ƒ |  j  d | ƒ |  j ró|  j  d	 |  j ƒ |  j  d
 |  j ƒ |  j d |  j ƒ |  j d |  j ƒ |  j  d |  j ƒ |  j d |  j ƒ |  j  d |  j ƒ |  j d |  j ƒ n  d S(   s5   
        Set the data to the out attributes.
        t   positionOutPPt   rotationOutPPt
   scaleOutPPg      ð?i    g        t   visibilityOutPPt   idOutPPt
   colorOutPPt   uvTileOutPPt
   frameOutPPt   velocityOutPPt   velocityVecOutPPt   angularVelocityOutPPt   angularVelocityVecOutPPt   isAnimatedOutPPN(   t   setVectorArrayR$   R%   R&   R   R   Rw   R   Rd   Rx   R(   R'   R   R)   R*   t   setDoubleArrayR+   R-   R.   R/   R0   t   setIntArrayR,   (   R5   t   outVisR}   R'   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   setDataÅ   s(    *2*2	c         C   sW   |  j  j | ƒ } t j |  j | ƒ } t j ƒ  } | j | ƒ | j | j ƒ  ƒ d S(   sL   
        Sets the specified vector array to the specified attribute
        N(	   R   R1   R   R2   R   t   MFnVectorArrayDatat   createt
   setMObjectt   object(   R5   t   channelNamet   arrayt   outAttributet   outPlugt   outData(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyRŒ   ã   s
    c         C   sW   |  j  j | ƒ } t j |  j | ƒ } t j ƒ  } | j | ƒ | j | j ƒ  ƒ d S(   sL   
        Sets the specified double array to the specified attribute
        N(	   R   R1   R   R2   R   t   MFnDoubleArrayDataR’   R“   R”   (   R5   R•   R–   R—   R˜   R™   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyR   í   s
    c         C   sW   |  j  j | ƒ } t j |  j | ƒ } t j ƒ  } | j | ƒ | j | j ƒ  ƒ d S(   sL   
        Sets the specified double array to the specified attribute
        N(	   R   R1   R   R2   R   t   MFnIntArrayDataR’   R“   R”   (   R5   R•   R–   R—   R˜   R™   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyRŽ   ÷   s
    c         C   sY   |  j  j | ƒ } t j |  j | ƒ } | j ƒ  } t j | ƒ } | j ƒ  } | } | S(   sE   
        Returns a double array from the specified attribute
        (   R   R1   R   R2   R   R;   Rš   R–   (   R5   R•   t   inAttributet   inPlugRD   t   inputPPDatat   inArrayt   copiedArray(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyRy     s    c         C   sY   |  j  j | ƒ } t j |  j | ƒ } | j ƒ  } t j | ƒ } | j ƒ  } | } | S(   sC   
        Returns an int array from the specified attribute
        (   R   R1   R   R2   R   R;   R›   R–   (   R5   R•   Rœ   R   RD   Rž   RŸ   R    (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyRz     s    c         C   sY   |  j  j | ƒ } t j |  j | ƒ } | j ƒ  } t j | ƒ } | j ƒ  } | } | S(   sE   
        Returns a vector array from the specified attribute
        (   R   R1   R   R2   R   R;   R‘   R–   (   R5   R•   Rœ   R   RD   Rž   RŸ   R    (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyRv     s    c         C   sÒ   g  } t  |  j ƒ } t j | ƒ } | j d ƒ } t j | | ƒ } | j ƒ  j ƒ  } t j | ƒ }	 |	 j	 ƒ  }
 | |
 k rÎ | d k r¬ |	 j
 | ƒ } |  j | | ƒ qÎ | d k rÎ |	 j | ƒ } qÎ n  | S(   sŠ   
        Returns a vector array from the specified channel name
        Please note, there is no write equivalent of this method.
        R9   t   vectort   double(   R   R   R	   R   R1   R2   t   asMDataHandlet   dataR<   t   listt   getVectorDatat   channelToListt   getDoubleData(   R5   R•   t   typeNameR    R@   R   R6   R7   t
   handleDataRE   t   channelst   dynamicArray(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   getNamedArray%  s    c         C   sp   t  |  j ƒ } t j | ƒ } | j d ƒ } t j | | ƒ } | j ƒ  j ƒ  } t j | ƒ } | j	 ƒ  } | S(   sG   
        Returns all the array names in the dynamic array data
        R9   (
   R   R   R	   R   R1   R2   R£   R¤   R<   R¥   (   R5   R@   R   R6   R7   Rª   RE   R«   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   getNamedArrays;  s    c         C   s1   |  j  j d ƒ } t j |  j | ƒ } | j ƒ  S(   s8   
        Returns the number of falloff objects.
        t
   strengthPP(   R   R1   R   R2   R   t   numConnectedElements(   R5   Rœ   R   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   getFalloffsCountH  s    c   	      C   s   t  |  j ƒ } t j | ƒ } | j d ƒ } t j | | ƒ } | j ƒ  | k rŒ | j | ƒ } | j ƒ  } t j	 | ƒ } | j
 ƒ  } | Sd S(   sË   
        Returns a doubleArray of strengths from a falloff object at the index specified.
        This happens through the old Maya Python API due to lack of support for MFnFloatArrayData in 2.0
        R¯   N(   R   R   R	   R   R1   R2   R°   t   connectionByPhysicalIndexR;   t   MFnFloatArrayDataR–   (	   R5   t   indext   oneNodet	   oneNodeFnRœ   R   RD   Rž   RŸ   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt
   getFalloffQ  s    c         C   s4   t  j ƒ  } t j j ƒ  } t | j | ƒ ƒ } | S(   sŒ   
        Returns the current frame. We do this via the MAnimControl and so it works reguardless of the state of the time attribute.
        (   R    t   currentTimeR   t   MTimet   uiUnitt   intt   asUnits(   R5   R¸   t   timeUnitR   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   getFramea  s    c         C   s—  |  j  |  j | t j d d d ƒ ƒ |  j  |  j | t j d d d ƒ ƒ |  j  |  j | t j d d d ƒ ƒ |  j  |  j | d ƒ |  j  |  j | d ƒ |  j r“|  j  |  j	 | t j d d d ƒ ƒ |  j  |  j
 | t j d d d ƒ ƒ |  j  |  j | d ƒ |  j  |  j | d ƒ |  j  |  j | d ƒ |  j  |  j | t j d d d ƒ ƒ |  j  |  j | t j d d d ƒ ƒ |  j  |  j | d ƒ n  d S(   sa   
        Resizes all the out arrays with default values - thus changing the point count.
        g        g      ð?i   i    N(   t   resizeMArrayR$   R   Rd   R%   R&   R(   R'   R   R)   R*   R+   R-   R/   R.   R0   R,   (   R5   R~   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   setPointCountj  s    %%%	%%%%c         C   sP   | t  | ƒ k rE x7 t t  | ƒ | d ƒ D] } | j | ƒ q+ Wn | | 3d S(   sÍ   
        If growing:
        Rather then using .setLength() we append to an MArray one by one in order to give ourselves a default value.
        If shrinking:
        Delete the unneeded entries.
        i   N(   Rw   t   ranget   append(   R5   t   lt   newsizet   objR}   (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyR¿   ~  s    c         C   s   | d  k s | j ƒ  d k r" d  S| j j d k r‹ xT t d | j ƒ  d ƒ D]7 } | | j | | j | | j f } | j | ƒ qM Wn  d  S(   Ni    R   i   (	   t   Nonet   lengtht	   __class__t   __name__RÁ   RR   RS   RT   RÂ   (   R5   t   channelt   destinationR}   t   vec(    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyR§   Œ  s    $N(   RÉ   t
   __module__t   __doc__R8   RH   RZ   Ra   Rg   R4   R~   R   RŒ   R   RŽ   Ry   Rz   Rv   R­   R®   R±   R·   R¾   RÀ   RÆ   R¿   R§   (    (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyR   !   s.   	4					0			
	
	
											(    (   RP   t	   maya.cmdst   cmdst   mct   maya.api.OpenMayat   apit   OpenMayaR   t   maya.OpenMayaR	   t   maya.api.OpenMayaAnimR    R   R   R   (    (    (    s7   G:\Soft\Maya\Maya2019\plug-ins\MASH\scripts\openMASH.pyt   <module>   s   		