
    8jq                    B   % S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	  SSK
rSSKJr  SSKJr  SS	KJr  \" \5      R'                  5       R(                  S
   S-  S-  S-  rSr/ SQrSqS\S'   SS jr\\S4             SS jjr\\S4             SS jjrg)u  Expressive compile: blend user-authored L1/L3/L5 presets within emotion family.

Philosophy: when a turn has an emotion label, the user's authored presets ARE
the ground truth. VAD determines intensity level (L1 mild, L5 extreme) via RBF
distance weighting on anchor VAD — NOT by blending with parametric rules or
other emotion families.

Result: full expressivity of authored L5 poses at extreme VAD, faithful fall-off
to L3/L1 at milder VAD. Emotion label is dominant.
    )annotationsN)Path)DictListOptional   )LIPSYNC_ONLY)parametric_layer)validate_vad   dataemotionzemotion_vad_anchors.jsongffffff?)                  +   ,   z*Optional[Dict[str, Dict[int, np.ndarray]]]_anchor_cachec            
     D   [         b  [         $ [        R                  " [        R	                  SS95      S   n 0 nU R                  5        HK  u  p#U Vs0 s H6  n[        US   5      [        R                  " US   [        R                  S9_M8     snX'   MM     Uq U$ s  snf )Nzutf-8)encodinganchorslevelvaddtype)
r   jsonloads_ANCHOR_PATH	read_textitemsintnpasarrayfloat32)rawoutemoentrieses        _/home/ubuntu/service/kemix-engine/package/face/animasync-face-v3/scripts/compiler/expressive.py_load_anchorsr.   -   s     
**\++W+=
>y
IC,.C		U\]U\PQC'
ORZZ%

%KKU\] $MJ ^s   =B      ?c           	     l   [        U5      nU b  U S:X  as  UR                  S5      nUb<  [        R                  " [        R                  " US   [        R
                  S9SS5      $ [        R                  " S[        R
                  S9$ [        5       R                  U 5      nUc#  [        R                  " S[        R
                  S9$ / n/ n	/ n
S	 Hq  nU  S
U 3nX;  d  X;  a  M  UR                  U5        U	R                  X{   5        U
R                  [        R                  " X,   S   [        R
                  S95        Ms     U
(       d#  [        R                  " S[        R
                  S9$ [        R                  " U	 Vs/ s H$  n[        R                  R                  X-
  5      PM&     sn[        R
                  S9n[        R                  " US-  * SUS-  -  -  5      nXR                  5       -  n[        R                  " U
SS9nUSS2S4   U-  R                  SS9nU(       aQ  [        U5      n[        R                  " U[        R                   S9n[        R"                  " UU   UUU   -  5      UU'   [        R                  " USS5      R%                  [        R
                  5      $ s  snf )u  Return 52-dim blendshape by blending authored L1/L3/L5 presets of emotion,
with optional channel-masked parametric overlay (Option E).

Args:
    emotion: emotion family name (e.g. 'crying'). None → neutral.
    vad: (3,) target VAD.
    presets: dict with keys like 'crying_L1', 'crying_L3', 'crying_L5'.
    sigma: RBF bandwidth for level blending.
    parametric_overlay_channels: list of channel indices on which to add
        the parametric layer's output via max() merge. Defaults to
        mouth/cheek "valence-coloring" channels. Pass None or [] to disable.
    parametric_overlay_intensity: scalar α applied to the parametric
        output before max-merge (1.0 = pure max, lower = milder coloring).

Option E rationale: emotion + within-emotion RBF defines the structural
pose (eyes, brows, jaw). Valence then continuously colors the mouth/cheek
so happy-surprise (V+) and sad-surprise (V−) become visually distinct
without re-authoring presets per V quadrant.
Nneutral
neutral_L3bsr   r   r   4   )r         _Lr   g       @)axisg        r/   )r   getr%   clipr&   r'   zerosr.   appendarraylinalgnormexpsumstackr
   int64maximumastype)r   r   presetssigmaparametric_overlay_channelsparametric_overlay_intensityr1   r   levelsanchor_vads
bs_vectorsLkeyavdistsweightsbs_stackr)   parammasks                       r-   compile_expressiverU   9   s-   6 s
C'Y.++l+772::gdm2::F1MMxx"**--o!!'*Gxx"**-- F$&K#%J	A3!1a7:&"**W\$%7rzzJK  xx"**-- HHE2biinnSX.ERZZXEffuz]cEQJ&678G{{}G xx
+H1d7h&
+
+
+
3C # %zz5RXXFJJs4y*Ft*TUD	773S!((44# Fs   +J1c           
         UR                   S   n[        R                  " US4[        R                  S9n[	        U5       H  n[        X   X   UUUUS9Xx'   M     U$ )z-Batch version. vads: (N, 3). Returns (N, 52).r   r4   r   )rG   rH   rI   )shaper%   emptyr'   rangerU   )	emotionsvadsrF   rG   rH   rI   Nr)   is	            r-   compile_expressive_batchr^      s^     	

1A
((Ar7"**
-C1X#K'(C)E	
  J    )returnz Dict[str, Dict[int, np.ndarray]])r   zOptional[str]r   
np.ndarrayrF   Dict[str, dict]rG   floatrH   Optional[List[int]]rI   rc   r`   ra   )rZ   zList[Optional[str]]r[   ra   rF   rb   rG   rc   rH   rd   rI   rc   r`   ra   )__doc__
__future__r   r   pathlibr   typingr   r   r   numpyr%   	constantsr	   
parametricr
   utilsr   __file__resolveparentsr!   EXPRESSIVE_SIGMAMOUTH_CHEEK_OVERLAY_CHANNELSr   __annotations__r.   rU   r^    r_   r-   <module>rt      s$  	 #   ' '  # ( H~%%'//2V;iGJdd     =A9 @	  $7S*-H5H5	H5 H5 	H5
 "5H5 #(H5 H5^ $7S*-!
  	
 "5 #( r_   