o
    ij                  	   @   s   d Z ddlZddlZddlZddlZddlZddlZddlZej	
ej	eZej	ej	eddddZej	dej	eddd ddlmZmZ dd	lmZ dd
lmZmZ dZg dee Zdd Zedkrqe  dS dS )aN  Publish one preprocessed solo-dataset GT clip in the E2E turn viewer.

This intentionally bypasses both the VQ codecs and the motion generator. It
uses the same basis-to-channel/rest-pose conversion as the production body
renderer so visual inspection can separate source/preprocessing/retargeting
problems from learned-model errors.
    Nz..zmotion-blenderexperimentsz
wave-handslib)FINGER_BONES_qmul)
write_vrma)ARKIT_52_NAMESrender_face   )hipsspinechest
upperChestneckheadleftShoulderleftUpperArmleftLowerArmleftHandrightShoulderrightUpperArmrightLowerArm	rightHandleftUpperLegleftLowerLegleftFootrightUpperLegrightLowerLeg	rightFootc                     s  t  } | jddd | jddd | jddd | jddd |  }tjtd	d
|j}tj	|r;t
| dt| t }tj|jdd1}|d tj}dd |d D }t|d }t|d }t|d }	t|d }
W d    n1 sw   Y  |jdd  dkrtd|j |tkrtdtjtjtd	ddd  t fddtD }t|d  |tj}t|tttj|dd  d t }t|j|j |jd\}}t | }t!tj|dd }t"#|jtt$|t%d!d |D d"| W d    n	1 sw   Y  t&'|jtj|d# |j|j tt$|t$t(|ddd#d$||tj)|j|	|
t*|d%d&t*t | d%d'd(}t!tj|d)d }t"j#||ddd* W d    n	1 spw   Y  t+t"j,|dd%d* d S )+Nz--npzT)requiredz--wavz--idz	--emotionneutral)defaultoutputsturnsz7 already exists; choose another id to avoid overwritingF)allow_picklevrm_rotationsc                 S   s   g | ]}t |qS  )str.0vr%   r%   render_solo_gt_turn.py
<listcomp>8   s    zmain.<locals>.<listcomp>
bone_names
dataset_idsplitsegment_typespeech_ratio   ),      z$expected (T,44,4) GT rotations, got z:dataset bone order does not match the E2E 44-bone contractzkemix_rest_table.npyc                    s(   g | ]}t j |g d t jdqS ))        r4   r4   g      ?)dtype)npasarraygetfloat64)r(   bonerestr%   r*   r+   F   s    z	body.vrma)root_translation
rest_quats)scenario_idz	face.jsonwc                 S   s   g | ]	}d d |D qS )c                 S   s   g | ]	}t t|d qS )r3   )roundfloatr'   r%   r%   r*   r+   _   s    z#main.<locals>.<listcomp>.<listcomp>r%   )r(   rowr%   r%   r*   r+   ^   s    )r?   fps
num_framesnamesblendshapesz	audio.wav%preprocessed_gt_no_codec_no_generator   r4   )face_sbody_stotal_s)idemotionrD   face_framesbody_framesfacebodyaudiobody_sourcer-   dataset_split
source_npzr/   r0   timingz	meta.json)ensure_asciiindent)-argparseArgumentParseradd_argument
parse_argsospathjoinHERErM   existsFileExistsErrormakedirstimer6   loadnpzastyper9   r&   rB   shape
ValueErrorBONES44WHitemstackr   float32r   FPSr   wavrN   openjsondumpintr   shutilcopyfilelenabspathrA   printdumps)apargsturn_dirstarteddataq_basissource_bonesr-   r.   r/   r0   
rest_array	q_channelt_face_startrG   rO   rJ   fmetar%   r;   r*   main'   s   
	
	
r   __main__)__doc__rZ   rs   r^   rv   sysre   numpyr6   r_   dirnamery   __file__ra   r`   rl   insertvrma_to_npzr   r   vrma_writerr   face_v3_inferr   r   rp   listrk   r   __name__r%   r%   r%   r*   <module>   s0    
	X
