
C\c           @   s  d  d l  Z d  d l Z d  d l j Z d  d l Z d d& d     YZ d d 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 e d  Z d 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 S('   iNt   ReproUpdatingc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t
   repro_node(   t   selfR   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   __init__   s    c         C   s   t  j j d |  j d  d  S(   Ns   %s.updatingi   (   t   mayat   cmdst   setAttrR   (   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt	   __enter__   s    c         C   sn   t  j j d |  j d  t  j j d |  j  rP t  j j d |  j d  n t  j j d |  j d  d  S(   Ns   %s.updatingi    s   %s.finishUpdatingi   (   R   R   R   R   t   getAttr(   R   t   typet   valuet	   traceback(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   __exit__   s    (   t   __name__t
   __module__R   R   R   (    (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyR    
   s   		c         C   s  |  d k ri t j j d d d d  p* g  } t |  d k ri d } x | D] } t |  } qL W| Sn  t j j d d t d | p d } t j j d	 d
 | d } t j j | d t d } t j j	 | d d d d t j j
 d | d |  t j j
 d | d |  t j j
 d | d |  |  d k	 rwt j j |   rwt j j
 d |  d | d t qwn  t j j | d d  | S(   s   
    Create a repro node and attach it to the selected MASH Waiter node or to the node specified by mash_network_node

    :param mash_network_node: Mash Waiter node or None to use the selected one
    :return: Repro node
    t   sli   R	   t   MASH_Waiteri    t
   MASH_Reprot   sst   namet   mesht   nt	   MeshShapet   pt   longNamet   mashOutFiltert   attributeTypet   bools
   %s.outMeshs	   %s.inMeshs   %s.worldInverseMatrix[0]s   %s.meshMatrixs
   %s.messages   %s.meshMessages   %s.outputPointss   %s.inputPointst   fs   .normalModeN(   t   NoneR   R   t   lst   lent   create_mash_repro_nodet
   createNodet   Truet   listRelativest   addAttrt   connectAttrt	   objExistsR   (   t   mash_network_nodeR   t
   mash_nodesR   t   nodet   repro_mesh_shapet
   repro_mesh(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyR       s&    !$'c         C   s   d |  | f } d } t  j j | d t p1 g  } t } x* | sf | | k } | sb | d 7} q= Pq= Wt  j j d | | f d t | S(   s   
    Create a new index inside the multi array, using the first available

    :param node: Node name
    :param multi_attr: Multi attribute name
    :return: new index created
    s   %s.%si    t   mii   s   %s[%d]R	   (   R   R   R   R"   t   False(   R)   t
   multi_attrt   attrt   next_availablet   multit
   found_next(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt"   new_non_numeric_multi_add_new_item6   s    	 c         C   s:   t  j j |  d t d d d t d t d t p3 g  } | S(   so   
    Get all mesh nodes inside a group

    :param group_node: Group node name
    :return: List of meshes
    t   lR	   R   t   dagt   lft   ni(   R   R   R   R"   (   t
   group_nodet   mashes(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_meshes_from_groupN   s    6c   	      C   s  t  j j d |  | f d t p% g  } x| D]} t  j j d |  | | f d d p] g  } x | D] } t  j j d |  | | | f d t d d p g  } | rg t  j j d	 | d
 d d d d p g  } xR | D]J } t j d |  s q n  t  j j d j | j	 d  d   d t q Wt  j j
 |  qg qg Wq/ Wt  j j d |  | f d t phg  } x | D] } t |  | |  qrWt  j j d |  | f d t S(   sy   
    Remove an index from the Repro node

    :param mash_repro_node: MASH Repro node
    :param index: Object index
    s#   %s.instancedGroup[%d].instancedMeshR,   s/   %s.instancedGroup[%d].instancedMesh[%d].groupIdi   s3   %s.instancedGroup[%d].instancedMesh[%d].groupId[%d]t   st   tt   groupIds
   %s.groupIdi    t   dR   s/   .instObjGroups.objectGroups\[\d\].objectGroupIdt   .it   bs    %s.instancedGroup[%d].proxyGroups   %s.instancedGroup[%d](   R   R   R   R"   t   listConnectionst   ret   searcht   removeMultiInstancet   joint   splitt   deletet   clean_proxy_index(	   t   mash_repro_nodet   indexR,   t   it   gi_mit   gidR=   t   group_ids_connectionst   groupIdConn(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   clean_indexY   s     (+4,0(c   
   	   C   so  t  j j d |  | | f d t p( g  } x| D]} t  j j d |  | | | f d d pc g  } x | D] } t  j j d |  | | | | f d t d d p g  } | rm t  j j d	 | d
 d d d d p g  } xR | D]J }	 t j d |	  sq n  t  j j d j |	 j	 d  d   d t q Wt  j j
 |  qm qm Wq2 Wt  j j d |  | | f d t S(   s   
    Remove a proxy index from the Repro node

    :param mash_repro_node: MASH Repro node
    :param instance_index: Object index
    :param index: Proxy index
    s*   %s.instancedGroup[%d].proxyGroup[%d].proxyR,   s;   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupIdi   s?   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupId[%d]R;   R<   R=   s
   %s.groupIdi    R>   R   s/   .instObjGroups.objectGroups\[\d\].objectGroupIdR?   iR@   s$   %s.instancedGroup[%d].proxyGroup[%d](   R   R   R   R"   RA   RB   RC   RD   RE   RF   RG   (
   RI   t   instance_indexRJ   R,   RK   RL   RM   t   group_idRN   RO   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyRH   s   s    +.7,0c         C   s   | d k	 r< t |  |  t j j d |  | f d t n t |  d  } t j j d |  | f d t d |  | f | f S(   s   
    Initialize a instanced object index

    :param mash_repro_node: MASH Repro node
    :param index: Object index
    :return: Attribute name created and his index
    s   %s.instancedGroup[%d]R	   t   instancedGroups&   %s.instancedGroup[%d].instancedMesh[0]N(   R   RP   R   R   R   R"   R3   (   RI   RJ   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   initialize_index   s    # c         C   s   | d k	 rB t |  | |  t j j d |  | | f d t n t |  d |  } t j j d |  | | f d t d |  | | f | f S(   s   
    Initialize a proxy object index

    :param mash_repro_node: MASH Repro node
    :param instance_index: Object index
    :param index: Proxy index
    :return: Attribute name created and his index
    s$   %s.instancedGroup[%d].proxyGroup[%d]R	   s   instancedGroup[%d].proxyGroups-   %s.instancedGroup[%d].proxyGroup[%d].proxy[0]N(   R   RH   R   R   R   R"   R3   (   RI   RQ   RJ   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   initialize_proxy_index   s    	&#c         C   s"   t  j j |  d d p g  } | S(   s   
    Get all shading groups connected to the shape node

    :param shape_node: Maya shape node
    :return: List of shading groups attached to the shape node
    R	   t   shadingEngine(   R   R   RA   (   t
   shape_nodet   sg_nodes(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_shading_groups   s    c         C   s   i  } t  j j d |  d d } | r? | d d g | d <n  t  j j d |  d d p^ g  } xs | D]k } t  j j d	 |  | f d d } | rh t  j j d
 |  | f  } | d d
 |  | f g | | <qh qh W| S(   s   
    Get all groups ids and shading groups connected to the shape node

    :param shape_node: Maya shape node
    :return: Map of group ids and their shading groups
    s   %s.instObjGroups[0]R	   RV   i    is    %s.instObjGroups[0].objectGroupsR,   i   s$   %s.instObjGroups[0].objectGroups[%d]s2   %s.instObjGroups[0].objectGroups[%d].objectGroupIdN(   R   R   RA   R   R   (   RW   t   gidst   defaul_connectionsR,   RK   t   sg_connectionsRR   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_groupids_and_shaders   s    ""%c         C   sv   t  j j d d |  d t rJ t  j j d |  d t d d d t pI g  St  j j d	 |  d
 t d d d t pu g  S(   s   
    Get out mesh connected to the Repro node

    :param mash_repro_node: MASH Repro node
    :return: Mesh connected to the output of the Repro node
    t   meshMessageR)   t   exs   %s.meshMessageR;   R	   R   t   shapess
   %s.outMeshR>   (   R   R   t   attributeQueryR"   RA   (   RI   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_out_mesh   s    ,c         C   s8   t  j j d |  | f d t } | r4 | d d Sd S(   s   
    Get the next free index for the multi attribute

    :param node: Node
    :param attribute: Attribute name
    :return: Index of the first free not connected index
    s   %s.%st   multiIndicesii   i    (   R   R   R   R"   (   R)   t	   attributet   indices(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_next_multi_index   s    "c         C   s   t  j j d |  | f d t p% g  } d } | r xH | D]/ } t  j j d |  | | f  s; | } Pq; q; W| d d } n  | S(   s   
    Get the first free index not connected fo the multi attribute

    :param node: Node
    :param attribute: Attribute name
    :return: Index of the first free not connected index
    s   %s.%sR,   i    s	   %s.%s[%d]ii   (   R   R   R   R"   RA   (   R)   Rd   R,   RJ   t   idx(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt"   get_free_index_without_connections   s    (c         C   sH   t  j j d |  | f d t p% g  } | s2 d S| j   | d d S(   s   
    Get the first free index not connected fo the multi attribute

    :param node: Node
    :param attribute: Attribute name
    :return: Index of the first free not connected index
    s   %s.%sR,   i    ii   (   R   R   R   R"   t   sort(   R)   Rd   R,   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_free_index   s
    (
c         C   s  t  |   } | s d S| d } t j j |  d k rW t j j | d t d } n  t |  } g  } x7 | D]/ } | j d  d | k rp | j |  qp qp W| s d St	 |   t j j
 d | d d	 d
 d d d p g  }	 x4 |	 D], }
 d |
 k r t j j d | |
  q q Wt j j d |  d t p>g  } x | D] } t j j d |  | f d t psg  } | st |  |  qHn  t |  d k rt j j
 d |  | | d f d d pg  } t |  d k r?t |  |  q?qHt j j
 d |  | f d d pg  } t |  d k rHt |  |  qHqHWt |  |  \ } } t j j d | d |  t j j d | d |  xt |  D]\ } } t j j d | d | | f  t j j d | d | | f  t |  } d } x| j   D]x} | | } t j j d d t } | rt j j d | d |  | | | f  | d k rt j j | d d |  | | | f  n# t j j d |  | | | f d  t j j d | d t t j j d  | | f d t d } | rt | d!  } n t | d!  } t j j d | d" | | f d# t | d }
 |
 sZqn  d } | rxt |
 d$  } n t |
 d$  } t j j d | d% |
 | f  d } | rt |
 d&  } n t |
 d&  } y1 t j j d  | | f d' |
 | f d# t WnC t |
 d&  } t j j d  | | f d' |
 | f d# t n Xt j j d( |
 d) | | f d# t | d 7} qqWqWt j j d* |  } | st j j | d+ d, d- d. n  Wd QX| S(/   sB  
    Connect the mesh group node to the Repro node

    :param mash_repro_node: MASH Repro node
    :param group_node: Group node
    :param index: Attribute index, if None it use the first free available index
    :param: new_connection: Optimisations can be enabled for new connections 
    :return: Attribute index
    Ni    R   R   t   |is   %s.instObjGroups[0]R	   RV   R>   i   t   initialShadingGroups   %s.instancedGroupR,   s#   %s.instancedGroup[%d].instancedMeshs,   %s.instancedGroup[%d].instancedMesh[%d].meshR;   s"   %s.instancedGroup[%d].groupMessages
   %s.messages   %s.groupMessages   %s.worldMatrix[0]s   %s.groupMatrixs
   %s.outMeshs   %s.instancedMesh[%d].meshs   %s.worldMatrixs   %s.instancedMesh[%d].matrixR=   R   s
   %s.groupIds3   %s.instancedGroup[%d].instancedMesh[%d].groupId[%d]s>   %s.instancedGroup[%d].instancedMesh[%d].inputShaderGroupId[%d]s$   %s.instObjGroups[0].objectGroups[%d]s   instObjGroups[0].objectGroupss2   %s.instObjGroups[0].objectGroups[%d].objectGroupIdR   t
   groupNodess   %s.groupNodes[%d]t   dagSetMemberss   %s.dagSetMembers[%d]s   %s.memberWireframeColors3   %s.instObjGroups[0].objectGroups[%d].objectGrpColors   %s.mashOutFilterR   R   R   R   (   Rb   R   R   t
   objectTypeR#   R"   R:   RF   t   appendR    RA   t   disconnectAttrR   RP   R   RT   R%   t	   enumerateR]   t   keysR!   R   Rf   Rh   Rj   R&   R$   (   RI   R8   RJ   t   new_connectiont
   out_meshest   out_mesht
   meshes_tmpt   meshesR   t   init_shading_connectiont   sgt
   num_groupst   groupt	   child_idst   connectionst   groups_connectionsR.   RK   RZ   t   counterRM   t   sg_datat   group_id_nodet   obj_inst_group_idt   group_node_indext   dag_set_member_idt   hasMASHFlag(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   connect_mesh_group  s    

."(/(!!
'*# '
!11'%c         C   s  t  |   } | s d S| d } t j j |  d k rW t j j | d t d } n  t |  } g  } x7 | D]/ } | j d  d | k rp | j |  qp qp W| s d St	 |   t j j
 d | d d	 d
 d d d p g  }	 x4 |	 D], }
 d |
 k r t j j d | |
  q q Wt j j d |  | f d t pDg  } x| D]	} t j j d |  | | f d t p|g  } | st |  | |  qNn  t |  d k rt j j
 d |  | | | d f d d pg  } t |  d k rWt |  | |  qWqNt j j
 d |  | | f d d p/g  } t |  d k rNt |  | |  qNqNWt |  | |  \ } } t j j d | d |  t j j d | d |  xt |  D]\ } } t j j d | d | | f  t j j d | d | | f  t |  } d } x| j   D]} | | } t j j d d t } | r#t j j d | d |  | | | | f  | d k rt j j | d d |  | | | | f  n& t j j d |  | | | | f d  t j j d | d t t j j d  | | f d t t | d!  } t j j d | d" | | f  | d }
 |
 sZq#n  t |
 d#  } t j j d | d$ |
 | f  t |
 d%  } y+ t j j d  | | f d& |
 | f  Wn= t |
 d%  } t j j d  | | f d& |
 | f  n Xt j j d' |
 d( | | f  | d 7} q#q#WqWt j j d) |  } | sut j j | d* d+ d, d- n  Wd QX| S(.   s,  
    Connect the mesh group node to the Repro node as proxy obejct

    :param mash_repro_node: MASH Repro node
    :param group_node: Group node
    :param instance_index: Object index
    :param index: Attribute index, if None it use the first free available index
    :return: Attribute index
    Ni    R   R   Rk   is   %s.instObjGroups[0]R	   RV   R>   i   Rl   s    %s.instancedGroup[%d].proxyGroupR,   s*   %s.instancedGroup[%d].proxyGroup[%d].proxys8   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyMeshR;   s6   %s.instancedGroup[%d].proxyGroup[%d].proxyGroupMessages
   %s.messages   %s.proxyGroupMessages   %s.worldMatrix[0]s   %s.proxyGroupMatrixs
   %s.outMeshs   %s.proxy[%d].proxyMeshs   %s.worldMatrixs   %s.proxy[%d].proxyMatrixR=   R   s
   %s.groupIds?   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupId[%d]sJ   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyInputShaderGroupId[%d]s$   %s.instObjGroups[0].objectGroups[%d]s   instObjGroups[0].objectGroupss2   %s.instObjGroups[0].objectGroups[%d].objectGroupIdRm   s   %s.groupNodes[%d]Rn   s   %s.dagSetMembers[%d]s   %s.memberWireframeColors3   %s.instObjGroups[0].objectGroups[%d].objectGrpColors   %s.mashOutFilterR   R   R   R   (   Rb   R   R   Ro   R#   R"   R:   RF   Rp   R    RA   Rq   R   RH   R   RU   R%   Rr   R]   Rs   R!   R   Rh   Rj   R&   R$   (   RI   R8   RQ   RJ   Ru   Rv   Rw   Rx   R   Ry   Rz   R{   R|   R}   R~   R   R.   RK   RZ   R   RM   R   R   R   R   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   connect_proxy_groupt  s    

.(+2+!!
*-& !
!++!%c         C   s  i  } t  j j d |  d t p% g  } xs| D]k} t  j j d |  | f d d pZ g  } t |  d k ru q/ n  i  | | <| d | | d <t  j j d |  | f  | | d	 <t  j j d
 |  | f d t p g  } i  | | d <x | D] } t  j j d |  | | f d d p g  } t |  d k r;q n  i  | | d | <| d | | d | d <t  j j d |  | | f  | | d | d <q Wq/ W| S(   s   
    Get a map of all the objects and proxy objects connected to the Repro node

    :param mash_repro_node: MASH Repro node
    :return: Map af all connected object
    s   %s.instancedGroupR,   s"   %s.instancedGroup[%d].groupMessageR;   i   i    R|   s!   %s.instancedGroup[%d].displayTypet   displayTypes    %s.instancedGroup[%d].proxyGroupt   proxiess6   %s.instancedGroup[%d].proxyGroup[%d].proxyGroupMessages-   %s.instancedGroup[%d].proxyGroup[%d].proxyLodt   proxyLod(   R   R   R   R"   RA   R   (   RI   t   datat	   group_idst   g_idR~   t   p_idst   p_id(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_data_layout  s&    "(
$(+7c   
      C   s  t  |   t |   } | j   } | j   | | k r| j |  } x. t | t |   D] } t |  | |  q` Wx?t | d t |   D]$} t |  | | | d  } t	 j
 j d |  | f | | | d  x | | | d j   D] } t |  | | | d | d |  } t	 j
 j d |  | | f | | | d | d  t	 j
 j d | | | d | d  }	 |	 r t	 j
 j | | | d | d d	 d
 q q Wq Wt	 j
 j d | | | d  }	 |	 rt	 j
 j | | | d d	 d
 qn  Wd QXd S(   s   
    Remove an object from the Repro node

    :param mash_repro_node: MASH Repro node
    :param index: Object index
    :return: None
    i   R|   s!   %s.instancedGroup[%d].displayTypeR   R   s-   %s.instancedGroup[%d].proxyGroup[%d].proxyLodR   s   %s.mashOutFiltert   atR   N(   R    R   Rs   Ri   RJ   t   rangeR   RP   R   R   R   R   R   R&   t
   deleteAttr(
   RI   RJ   R   Re   t   positionRK   t	   new_indexR   t   new_p_indexR   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   remove_mesh_group  s(    
 )&4*5"c   	   
   C   s  t  |   {t |   } | | d j   } | j   | | k r| j |  } x1 t | t |   D] } t |  | | |  qh Wx t | d t |   D] } d | | d | | k r t |  | | d | | d |  } t	 j
 j d |  | | f | | d | | d  t	 j
 j d | | d | | d  } | r|t	 j
 j | | d | | d d d q|q q Wn  Wd	 QXd	 S(
   s   
    Remove a proxy object from the Repro node

    :param mash_repro_node: MASH Repro node
    :param instance_index: Object index
    :param index: Proxy index
    :return: None
    R   i   R|   s-   %s.instancedGroup[%d].proxyGroup[%d].proxyLodR   s   %s.mashOutFilterR   R   N(   R    R   Rs   Ri   RJ   R   R   RH   R   R   R   R   R&   R   (	   RI   RQ   RJ   R   Re   R   RK   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   remove_proxy_group  s    	
 &4*c   	      C   s  t  |   t |   } | j   } | j   x | D] } t |  |  q6 Wx | D] } t |  | | d  } t j j d |  | f | | d  xn | | d j   D]X } t	 |  | | d | d |  } t j j d |  | | f | | d | d  q WqT WWd QXd S(   s   
    Reorder the instanced objects

    :param mash_repro_node: MASH Repro node
    :param new_order: list with the new index order
    :return: None
    R|   s!   %s.instancedGroup[%d].displayTypeR   R   s-   %s.instancedGroup[%d].proxyGroup[%d].proxyLodR   N(
   R    R   Rs   Ri   RP   R   R   R   R   R   (	   RI   t	   new_orderR   Re   RJ   RK   R   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   reorder_mesh_group_node&  s    
%"c      
   C   s   t  |    t |   } | | d j   } | j   x | D] } t |  | |  q> Wx` | D]X } t |  | | d | d |  } t j j d |  | | f | | d | d  q_ WWd QXd S(   s   
    Reorder the proxies of an instanced object

    :param mash_repro_node: MASH Repro node
    :param instance_index: Objects index
    :param new_order: List with the new index order
    :return: None
    R   R|   s-   %s.instancedGroup[%d].proxyGroup[%d].proxyLodR   N(	   R    R   Rs   Ri   RH   R   R   R   R   (   RI   RQ   R   R   Re   RJ   RK   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   reorder_proxy_group_node;  s    	
"c         C   s   t  |   } t |  | | d |  } t j j d |  | f | | d  xn | | d j   D]X } t |  | | d | d |  } t j j d |  | | f | | d | d  q` Wd S(   s   
    Refresh an instanced object, updating all the meshes and shaders

    :param mash_repro_node: MASH Repro node
    :param index: Objects index
    :return: None
    R|   s!   %s.instancedGroup[%d].displayTypeR   R   s-   %s.instancedGroup[%d].proxyGroup[%d].proxyLodR   N(   R   R   R   R   R   Rs   R   (   RI   RJ   R   R   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   refresh_mesh_groupN  s    %"c         C   se   t  |   } t |  | | d | d | |  } t j j d |  | | f | | d | d  d S(   s   
    Refresh an instanced object, updating all the meshes and shaders

    :param mash_repro_node: MASH Repro node
    :param instance_index: Objects index
    :param index: Proxy index
    :return: None
    R   R|   s-   %s.instancedGroup[%d].proxyGroup[%d].proxyLodR   N(   R   R   R   R   R   (   RI   RQ   RJ   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   refresh_proxy_group]  s    	%c         C   s   t  j j d |  d t p g  } xY | D]Q } t  j j d |  | f d d d d pZ g  } | r) | d | k rz | Sq) q) Wd S(	   s   
    Return the index of the group node connected to the Repro node

    :param mash_repro_node: MASH Repro node
    :param group_node: Group node name
    :return: Object index
    s   %s.instancedGroupR,   s"   %s.instancedGroup[%d].groupMessageR   i    R;   i   N(   R   R   R   R"   RA   R   (   RI   R8   Re   RJ   R~   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_group_indexk  s    ".c         C   s   t  | t  r! t |  |  } n | } t j j d |  | f d t pL g  } x\ | D]T } t j j d |  | | f d d d d p g  } | rV | d | k r | SqV qV Wd S(	   s   
    Return the index of the proxy group node connected to the Repro node

    :param mash_repro_node: MASH Repro node
    :param group_node: Group node name or group index
    :param proxy_node: Proxy group node name
    :return: Object index
    s    %s.instancedGroup[%d].proxyGroupR,   s6   %s.instancedGroup[%d].proxyGroup[%d].proxyGroupMessageR   i    R;   i   N(	   t
   isinstancet   strR   R   R   R   R"   RA   R   (   RI   R8   t
   proxy_nodet   group_indexRe   RJ   R~   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_proxy_group_index|  s    	(1c         C   sP   t  j j d |  d t p g  } | j |  | j | |  t |  |  d S(   s   
    Move an object to a new index, the other objects are shifted

    :param mash_repro_node: MASH Repro node
    :param old: Old group index
    :param new: New group index
    :return: None
    s   %s.instancedGroupR,   N(   R   R   R   R"   t   popt   insertR   (   RI   t   oldt   newR   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   move_group_node  s    	"c         C   sY   t  j j d |  | f d t p% g  } | j |  | j | |  t |  | |  d S(   s   
    Move an proxy object to a new index, the other objects are shifted

    :param mash_repro_node: MASH Repro node
    :param instance_index: Instanced object index
    :param old: Old group index
    :param new: New group index
    :return: None
    s    %s.instancedGroup[%d].proxyGroupR,   N(   R   R   R   R"   R   R   R   (   RI   RQ   R   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   move_proxy_group_node  s    
(c         C   sR   t  j   } | j |   t  j   } | j d |  t  j |  } | j   d S(   sC   
    Force a redraw of a mesh

    :param mash_node: mesh node
    i    N(   t   omt   MSelectionListt   addt   MObjectt   getDependNodet   MFnMesht   updateSurface(   t	   mesh_nodet   sel_listR)   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyR     s    c         C   sT  t  j j d |  | | f d t } x(| D] } t  j j d |  | | | f d t d d pc g  } | r t  j j d | d d	 d
 d d
 p g  } xR | D]J } t j d |  s q n  t  j j d j | j	 d  d   d t q Wt  j j
 |  n  t  j j d |  | | | f d t t  j j d |  | | | f d t q, Wd S(   s   
    Remove all the shader of the object attached to the repro node

    :param mash_repro_node: Mash repro node
    :param instanced_index: Object index
    :param mesh_index: Mesh index
    s/   %s.instancedGroup[%d].instancedMesh[%d].groupIdR,   s3   %s.instancedGroup[%d].instancedMesh[%d].groupId[%d]R;   R<   R=   s
   %s.groupIdi    R>   i   R   s/   .instObjGroups.objectGroups\[\d\].objectGroupIdR?   iR@   s>   %s.instancedGroup[%d].instancedMesh[%d].inputShaderGroupId[%d]N(   R   R   R   R"   RA   RB   RC   RD   RE   RF   RG   (   RI   t   instanced_indext
   mesh_indext   group_ids_miRM   R=   RN   RO   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   clean_mesh_shaders  s    %4,0&c         C   sY  t  |   } | s d S| d } | } | } t |  } d }	 x| j   D]}
 | |
 } t j j d d t } | rK t j j d | d |  | | |	 f  |
 d k r t j j | d d	 |  | | |	 f  n# t j j d	 |  | | |	 f d  t j j	 d
 | d t t j j	 d | | f d t t
 | d  } t j j d | d | | f  | d } | syqK n  t
 | d  } t j j d | d | | f  t
 | d  } y+ t j j d | | f d | | f  Wn= t | d  } t j j d | | f d | | f  n Xt j j d | d | | f  |	 d 7}	 qK qK Wd S(   s   
    Update all the shader of the object attached to the repro node

    :param mash_repro_node: Mash repro node
    :param instanced_index: Object index
    :param mesh_index: Mesh index
    :param mesh: mesh node
    Ni    R=   R   s
   %s.groupIds3   %s.instancedGroup[%d].instancedMesh[%d].groupId[%d]ii   s>   %s.instancedGroup[%d].instancedMesh[%d].inputShaderGroupId[%d]s   %s.instObjGroups[0]R	   s$   %s.instObjGroups[0].objectGroups[%d]s   instObjGroups[0].objectGroupss2   %s.instObjGroups[0].objectGroups[%d].objectGroupIdRm   s
   %s.messages   %s.groupNodes[%d]Rn   s   %s.dagSetMembers[%d]s   %s.memberWireframeColors3   %s.instObjGroups[0].objectGroups[%d].objectGrpColor(   Rb   R]   Rs   R   R   R!   R"   R%   R   R   Rh   Rj   (   RI   R   R   R   Ru   Rv   RJ   RK   RZ   R   RM   R   R   R   Rz   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   update_mesh_shaders  sB    	

'*# !
!++!c         C   s=   t  j j d |  | | f d d } | d  k r5 d  S| d S(   Ns6   %s.instancedGroup[%d].proxyGroup[%d].proxyGroupMessageR;   i   i    (   R   R   RA   R   (   RI   RQ   t   proxy_indext   conns(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   get_proxy_mesh  s    %c   	      C   sf  t  j j d |  | | | f d d p+ g  } x1| D])} t  j j d |  | | | | f d t d d po g  } | rt  j j d | d	 d
 d d d p g  } xR | D]J } t j d |  s q n  t  j j d j | j	 d  d   d t q Wt  j j
 |  n  t  j j d |  | | | | f d t t  j j d |  | | | | f d t q5 Wd S(   s   
    Remove all the shader of the oproxy bject attached to the repro node

    :param mash_repro_node: Mash repro node
    :param instanced_index: Object index
    :param proxy_index: Proxy index
    :param mesh_index: Mesh index
    s;   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupIdR,   i   s?   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupId[%d]R;   R<   R=   s
   %s.groupIdi    R>   R   s/   .instObjGroups.objectGroups\[\d\].objectGroupIdR?   iR@   sJ   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyInputShaderGroupId[%d]N(   R   R   R   RA   R"   RB   RC   RD   RE   RF   RG   (	   RI   RQ   R   R   RL   RM   RR   RN   RO   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   clean_proxy_mesh_shaders  s    	.7,0)c      	   C   sb  t  |   } | s d S| d } | } | } t |  }	 d }
 x|	 j   D]} |	 | } t j j d d t } | rK t j j d | d |  | | | |
 f  | d k r t j j | d d	 |  | | | |
 f  n& t j j d	 |  | | | |
 f d  t j j	 d
 | d t t j j	 d | | f d t t
 | d  } t j j d | d | | f  | d } | sqK n  t
 | d  } t j j d | d | | f  t
 | d  } y+ t j j d | | f d | | f  Wn= t | d  } t j j d | | f d | | f  n Xt j j d | d | | f  |
 d 7}
 qK qK Wd S(   s  
    Update all the shader of the proxy object attached to the repro node

    :param mash_repro_node: Mash repro node
    :param instanced_index: Object index
    :param proxy_index: Proxy index
    :param mesh_index: Mesh index
    :param mesh: mesh node
    Ni    R=   R   s
   %s.groupIds?   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupId[%d]ii   sJ   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyInputShaderGroupId[%d]s   %s.instObjGroups[0]R	   s$   %s.instObjGroups[0].objectGroups[%d]s   instObjGroups[0].objectGroupss2   %s.instObjGroups[0].objectGroups[%d].objectGroupIdRm   s
   %s.messages   %s.groupNodes[%d]Rn   s   %s.dagSetMembers[%d]s   %s.memberWireframeColors3   %s.instObjGroups[0].objectGroups[%d].objectGrpColor(   Rb   R]   Rs   R   R   R!   R"   R%   R   R   Rh   Rj   (   RI   RQ   R   R   R   Ru   Rv   RJ   RK   RZ   R   RM   R   R   R   Rz   R   R   (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   update_proxy_mesh_shaders  sB    


*-& !
!++!c      
   C   s  t  j j |   s d St  j j d |  d t d t d d pA g  } x| D]} t |   } | j d  } | d } | d	 d
 k rt | d | d j d  d | d j d  ! } t | d | d j d  d | d j d  ! } g  } t  j j	 d | | | f d t pg  }	 t  j j	 d | | | f d t pIg  }	 g  }
 x7 |	 D]/ } |
 j
 t  j j	 d | | | | f   qYWt } t t |
  t | j    A rt } nx
|	 D]} t  j j	 d | | | | f  } t  j j	 d | | | | f  } t  j j d | | | | f d t d t p?g  } | sNqn  t  j j d | d d t d t d d p}g  } | sqn  | d } | | k r| | d | k rqqn  t } PqW| rt | | |  t | | | |   t |  } | rt | d  n  Pqn  | d	 d k rK t | d | d j d  d | d j d  ! } t | d | d j d  d | d j d  ! } t | d | d j d  d | d j d  ! } g  } t  j j	 d | | | | f d t pg  }	 t  j j	 d | | | | f d t p+g  }	 g  }
 x: |	 D]2 } |
 j
 t  j j	 d | | | | | f   q;Wt } t t |
  t | j    A rt } nx|	 D]} t  j j	 d | | | | | f  } t  j j	 d | | | | | f  } t  j j d | | | | | f d t d t p-g  } | s<qn  t  j j d | d d t d t d d pkg  } | szqn  | d } | | k r| | d | k rqqn  t } PqW| rt | | | |  t | | | | |   t |  } | r
t | d  n  PqqK qK Wd S(   sn   
    Refresh shader connection on the repro nodes attacched to this mesh

    :param mesh_node: mesh node
    Ns
   %s.outMeshR>   R   R	   R   R?   i    iR   i   t   [t   ]i   s/   %s.instancedGroup[%d].instancedMesh[%d].groupIdR,   s:   %s.instancedGroup[%d].instancedMesh[%d].inputShaderGroupIds>   %s.instancedGroup[%d].instancedMesh[%d].inputShaderGroupId[%d]s3   %s.instancedGroup[%d].instancedMesh[%d].groupId[%d]R;   s
   %s.messageRV   t	   proxyMeshi   s;   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupIdsF   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyInputShaderGroupIdsJ   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyInputShaderGroupId[%d]s?   %s.instancedGroup[%d].proxyGroup[%d].proxy[%d].proxyGroupId[%d](   R   R   R&   RA   R"   R]   RF   t   intRJ   R   Rp   R-   t   listt   setRs   R   R   Rb   R   R   R   (   R   t   mash_repro_nodest
   repro_plugt   sgst   repro_splitR   t   instanced_idt   mesh_idt   input_shader_group_idsR,   t   mi_idst   idt   updated_shadert   igidRM   t   gid_connectionst   sg_connectedt   shaderRu   t   proxy_id(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   refresh_shaders_connectionsN  s    .
55++-"	""42
	555..0"	%%72
	c         C   s   t  |   } | s d  S| d } t j j | d t d } | rs t j j d | d  t j j d | d  n. t j j d | d  t j j d | d  d  S(   Ni    R   s   %s.overrideEnabledi   s   %s.overrideShading(   Rb   R   R   R#   R"   R   (   RI   R
   Ru   Rv   t	   transform(    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   set_out_mesh_display_override  s    
(    (,   t	   maya.cmdsR   t   maya.melt   maya.OpenMayat   OpenMayaR   RB   R    R   R    R3   R:   RP   RH   RT   RU   RY   R]   Rb   Rf   Rh   Rj   R-   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sO   S:/Maya_2019_DI/build/Release/runTime/plug-ins/MASH/scripts/mash_repro_utils.pyt   <module>   sL   												o`														0			1	c