
<ac           @   s   d  Z  d d l Z d d l Td d l Z d d d     YZ d d d     YZ d d d	     YZ d
   Z d   Z d d  Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d S(   s  
**Project Name:**      MakeHuman

**Product Home Page:** http://www.makehuman.org/

**Code Home Page:**    https://bitbucket.org/MakeHuman/makehuman/

**Authors:**           Thomas Larsson

**Copyright(c):**      MakeHuman Team 2001-2014

**Licensing:**         AGPL3 (http://www.makehuman.org/doc/node/the_makehuman_application.html)

    This file is part of MakeHuman (www.makehuman.org).

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

**Coding Standards:**  See http://www.makehuman.org/node/165

Abstract
--------

TODO
iN(   t   *t   CTargetc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | |  _  | j d k ra | \ |  _ |  _ |  _ |  _ |  _ |  j d d !d k r t | _ q nZ | j d k r | \ |  _ |  _ |  _ |  _ n* | j d k r | \ |  _ |  _ |  _ n  d  S(   Nt
   TRANSFORMSi    i   t   LOCt   ROTATION_DIFFt   SINGLE_PROP(	   t   variablet   typet   idtypet   objectt   bonet   flagst   Truet   useLoct   datapath(   t   selft   vart   target(    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   __init__-   s    	$!c         C   s   t  j d |  j |  j  d  S(   Ns         <CTarget %s %s>(   t   logt   debugR   R	   (   R   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   display8   s    c         C   s   | j  d |  j |  j f  |  j j d k r{ | j  d |  j d |  j  |  j t @rk | j  d  q | j  d  nV |  j j d k r | j  d |  j d	  n) |  j j d
 k r | j  d |  j  n  | j  d  d  S(   Ns             Target %s %s
R   s#                transform_type '%s' ;
s                 bone_target '%s' ;
s-                transform_space 'LOCAL_SPACE' ;
s-                transform_space 'WORLD_SPACE' ;
R   s               bone_target '%s' ;
s-               transform_space 'WORLD_SPACE' ; 
R   s               data_path '%s' ;
s             end Target
(	   t   writeR	   R   R   R   R
   R   t   C_LOCR   (   R   t   fp(    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   write25;   s    

(   t   __name__t
   __module__R   R   R   (    (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR   ,   s   		t	   CVariablec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ g  |  _ x' | D] } |  j j t |  |   q" W|  j d k r` t | _ n^ |  j d k r t | _ t | _ n: |  j d k r | j	 r t | _ q n t
 d |  j   d  S(   NR   R   R   s   Unknown driver var type %s(   t   nameR   t   targetst   appendR   R   t   useModt   useKeypointst   Falset   coeffst	   NameError(   R   R   t   drvR   R   R   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR   O   s    					c         C   sH   t  j d |  j |  j  x |  j D] } | j   q# Wt  j d  d  S(   Ns       <CVariable %s %ss       >(   R   R   R   R   R   R   (   R   R   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR   `   s    c         C   sO   | j  d |  j |  j f  x |  j D] } | j |  q' W| j  d  d  S(   Ns           DriverVariable %s %s
s           end DriverVariable
(   R   R   R   R   R   (   R   R   R   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR   f   s    (   R   R   R   R   R   (    (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR   N   s   		t   CDriverc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | |  _  y | \ |  _ |  _ Wn | |  _ n X| |  _ | |  _ | |  _ | |  _ g  |  _ t |  _	 t |  _
 t |  _ x6 | D]. \ } }	 }
 |  j j t | |  |	 |
   q Wd  S(   N(   t   condt   drvtypet   exprt   extrat   channelt   indexR#   t	   variablesR"   R   R!   R    R   R   (   R   R'   t   drvdataR*   R+   R,   R#   R-   R   R   R   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR   n   s    									c         C   sH   t  j d |  j |  j  x |  j D] } | j   q# Wt  j d  d  S(   Ns     <CDriver %s %ds     >(   R   R   R+   R,   R-   R   (   R   R   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR      s    c         C   sw  | j  d d |  j |  j |  j f d |  j  |  j d k rX | j  d |  j  n  x |  j D] } | j |  qb W| j  d d  |  j r| j  d d	 d
  |  j	 \ } } |  j
 r | j  d | | |  j f  n | j  d | | |  j f  | j  d d d d d  n  |  j rZx1 |  j	 D]# \ } } | j  d | | f  q0Wn  | j  d d d d  d  S(   Ns   
s       FCurve %s %d %s
s         Driver %s
t   SCRIPTEDs           expression '%s' ;
s           show_debug_info True ;
s         end Driver
s         FModifier GENERATOR 
s           active False ;
s           use_additive False ;
s)           coefficients Array %s %s*One%s ;
s%           coefficients Array %s %s%s ;
s           show_expanded True ;
s           mode 'POLYNOMIAL' ;
s           mute False ;
s           poly_order 1 ;
s         end FModifier
s         kp %.4f %.4f ; 
s!         extrapolation 'CONSTANT' ;
s         lock False ;
s         select False ;
s       end FCurve
(   R   R+   R,   R'   R(   R)   R-   R   R    R#   R   R*   R!   (   R   R   R   t   a0t   a1t   xt   y(    (    s#   plugins/9_export_mhx\mhx_drivers.pyR      s6    		 	(   R   R   R   R   R   (    (    (    s#   plugins/9_export_mhx\mhx_drivers.pyR&   m   s   		c   	      C   s8   t  | | | | | | |  } |  r4 | j |   n  | S(   N(   R&   R   (	   R   R'   R.   R*   R+   R,   R#   R-   R%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeDriver   s    c      
   C   s   g  } x | D] \ } } } }	 g  }
 d } xm | D]e } | rT d | | | f } n d | | f } |
 j  d | d d | j | f g f  | d 7} q2 W| r d | | f } n  t |  t d |	 f d	 d
 | | f d d |
  } | j  |  q W| S(   Ni   s   ["%s%s_%s"]s   ["%s%s"]s   x%dR   t   OBJECTs   %s.%sR/   t    s,   pose.bones["%s"].constraints["%s"].influenceii    (   i    i   (   R   R   R4   R   (   R   t   amtt   driverst   suffixt   prefixt
   driverListR
   t   cnst   propsR)   t   drvVarst   nt   propR   R%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writePropDrivers   s"    )c   
   
   C   s   g  } x} | D]u } t  | |  r d d d | j d | | f f g f } t |  t d d d | d d | g  }	 | j |	  q q W| S(   NR2   R   R5   s   ["%s%s"]R/   R6   s   key_blocks["%s"].valueii    i   (   s   SCRIPTEDR2   (   i    i   (   t   useThisShapeR   R4   R   R   (
   R   R7   t   skeyst   proxyR:   t   callbackR;   t   skeyt   drvVarR%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeShapePropDrivers   s    (c   	   	   C   sy   g  } d } xE | D]= } | j  d | d d | j d | f g f  | d 7} q Wt |  t d | f d | | d	 |  S(
   Ni   s   x%dR   R5   s   ["%s"]R/   R6   i    (   i    i   (   R   R   R4   R   (	   R   R7   R=   R)   t   dataPathR,   R>   R?   R@   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writePropDriver   s    -c      
   C   s   g  } x | j    D] \ } } g  } | \ } } }	 }
 | j | d d | j | |	 t f g f  t |  d d d d | d |
 |  } | j |  q W| S(   NR   R5   s   toggle&T_Shapekeyst   AVERAGER6   s   texture_slots[%d].normal_factori(   t   itemsR   R   R   R4   (   R   R7   R8   R;   t   text   vlistR>   t   texnumt   targR+   R#   R%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeTextureDrivers   s    +%c      
   C   s   g  } t  | j    } | j   x | D] \ } } t | |  r) g  } | \ }	 }
 } } } } | j |
 d d | j |
 | t f g f  t |  d d d d | d | |  } | j |  q) q) W| S(   NR   R5   s   toggle&T_ShapekeysRK   R6   s   key_blocks["%s"].valuei(   t   listRL   t   sortRB   R   R   R   R4   (   R   R7   R8   RD   R;   t   dlistt   shapeRN   R>   t   fileRP   R+   R#   t   mint   maxR%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeShapeDrivers   s    
+%c         C   s  g  } d d g } x| D]\ } } } }	 | | k r= q q | rxad d g D] }
 g  } d } x^ |	 D]V \ } } | d 7} | j  d | d d | | |
 t f d | | |
 t f g f  qi Wt |  t d | f d	 d
 | |
 d | |  } | j  |  qP Wq g  } d } xV |	 D]N \ } } | d 7} | j  d | d d | | t f d | | t f g f  qWt |  t d | f d	 d
 | |
 d | |  } | j  |  q W| S(   Ni    i   t   _Lt   _Rs   x%dR   R5   R/   R6   s   key_blocks["%s"].valuei(   i    i    (   i   i   (   R   R   R4   R   (   R   R8   t   rigt   emptiesR;   R#   t   fnamet   lrR)   t   varsR9   R>   R?   R
   RP   R%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeTargetDrivers  s0    
4/
,/c      
   C   s  g  } x| D]\ } } } } } g  }	 | r= d | f }
 n d }
 x | D] \ } } } } | d k r |	 j  | | d | | t f d | | t f g f  qJ | d k rJ |	 j  | | d t j d | f g f  qJ qJ Wt |  t |
 d d | | f d	 | |	  } | j  |  q W| S(
   NR/   t   MINR   R5   R   s   ["%s"]R6   s,   pose.bones["%s"].constraints["%s"].influencei(   R   R   R7   R   R4   R   (   R   R8   R\   R;   R
   t   cnsNameR)   t   targst	   keypointsR>   R.   R   R   t   targ1t   targ2R%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeMuscleDrivers$  s    70+c      
   C   s   g  } x | j    D] \ } } t | |  r | \ } } } | d d t j | t f d t j | t f g f g }	 t |  t d d d | d | |	  }
 | j |
  q q W| S(   NR   R5   Rb   R6   s   key_blocks["%s"].valuei(   RL   RB   R7   R   R   R4   R   R   (   R   R8   RD   R;   RU   RN   Rf   Rg   Re   R>   R%   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeRotDiffDrivers6  s    %c   	      C   s   g  } xi | D]a } | \ } } } } | j  | d d | f d  d d d d d | j | | t f g f g f  q Wt |  t |  S(	   Nt   ROTER/   i    i   R2   R   R5   (   i    i   (   R   t   NoneR   R   t   writeDriversR   (	   R   R7   t   boneDriversR8   t
   boneDrivert   drivent   driverR+   R)   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   writeScriptedBoneDriversD  s    /c      
   C   si  g  } x\| D]T} | \ } } } } }	 }
 } | d k rh t  |  | | d d | | f |	 |
 |  } n | d k r t  |  | | d d | |	 |
 |  } n | d k r t  |  | | d d | |	 |
 |  } n | d k rt  |  | | d	 d
 | |	 |
 |  } nP | d k r8t  |  | | d d | |	 |
 |  } n t j |  t d |   | j |  q W| S(   Nt   INFLR6   s,   pose.bones["%s"].constraints["%s"].influenceRj   s   pose.bones["%s"].rotation_eulert   ROTQs$   pose.bones["%s"].rotation_quaternionR   s	   *theScales   pose.bones["%s"].locationt   SCALEs   pose.bones["%s"].scales   Unknown driver type %s(   R4   R   t   messageR$   R   (   R   R'   R8   R;   R%   R
   R   R.   R   R,   R#   R-   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyRl   N  s"    .((((c         C   sK   | s
 t  S| j d k r t  S|  | j k r0 t  S|  d  | j k rG t  St S(   Nt   Proxymeshesi(   R   R   t	   shapekeysR"   (   R   RD   (    (    s#   plugins/9_export_mhx\mhx_drivers.pyRB   c  s    (    (    (    (   t   __doc__t   armaturet   armature.flagsR   R   R   R&   R4   RA   Rk   RH   RJ   RQ   RY   Ra   Rh   Ri   Rq   Rl   RB   (    (    (    s#   plugins/9_export_mhx\mhx_drivers.pyt   <module>&   s$   
"E										
	