
    9i                         S SK r S SKJrJr  S SKrS SKJr  S SKJrJ	r	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  \" 5       r\R0                  " \R2                  \R2                  S9 " S S\5      5       rg)    N)AnyDict)	Pipelines)gen_skeleton_bvhread_obj	write_obj)	MsDataset)
OutputKeys)Pipeline)	PIPELINES)Tasks)
get_logger)module_namec                      ^  \ rS rSrSrSU 4S jjrS\\\4   S\\\4   4S jr	S r
SS jrSS	 jrS
\\\4   S\\\4   4S jrS\\\4   S\\\4   4S jrSrU =r$ )Human3DAnimationPipeline   a'  Human3D library render pipeline
Example:

```python
>>> from modelscope.pipelines import pipeline
>>> human3d = pipeline(Tasks.human3d_animation,
            'damo/cv_3d-human-animation')
>>> human3d({
        'dataset_id': 'damo/3DHuman_synthetic_dataset', # dataset id (str)
        'case_id': '3f2a7538253e42a8', # case id (str)
        'action_dataset': 'damo/3DHuman_action_dataset', # action data id
        'action': 'ArmsHipHopDance' # action name or action file path (str)
        'save_dir': 'output' # save directory (str)
    })
>>> #
```
c                 v   > [         TU ]  " SSU0UD6  Xl        [        R	                  SU R                  5        g)z
use model to create a image sky change pipeline for image editing
Args:
    model (str or Model): model_id on modelscope hub
    device (str): only support gpu
modelz
model_dir:N )super__init__	model_dirloggerinfo)selfr   devicekwargs	__class__s       r/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/cv/human3d_animation_pipeline.pyr   !Human3DAnimationPipeline.__init__)   s1     	/u//L$..1    inputsreturnc                     U$ Nr   r   r"   s     r   
preprocess#Human3DAnimationPipeline.preprocess4       r!   c                     Xl         X l        X0l        [        U R                  U R                  U R                   U R                  5      nU$ r%   )case_dir
action_diractionr   r   )r   r+   r,   r-   statuss        r   gen_skeleton%Human3DAnimationPipeline.gen_skeleton7   s9     $!$..$//"&-->r!   c           	         [         R                  R                  U R                  5      n[         R                  R                  U R                  5      R                  SS5      nUc3  [         R                  R                  U R                  U< SU< S35      nO=[         R                  " USS9  [         R                  R                  UU< SU< S35      n[         R                  R                  U R                  S5      nU R                   SU S	U R                   S
U SU R                   3	n[         R                  " U5        U$ )Nz.npy -z.glbT)exist_okzskinning.pyz -b -P z  -- --input z --gltf_path z
 --action )ospathbasenamer+   r-   replacejoinmakedirsr   blendersystem)r   save_dir	case_nameaction_name	gltf_path	exec_pathcmds          r   gen_weights$Human3DAnimationPipeline.gen_weights?   s    GG$$T]]3	gg&&t{{3;;FBGT]]&/5> ?I KK40X&/0> ?IGGLL?	gi[dmm_i[
4;;-A
		#r!   c                    [         R                  R                  [         R                  R                  U5      5      nUR	                  SS5      n[        U5      n[        R                  " U5      nUS   n	XS'   XS'   [        X5        U R                  XRU5        U R                  U5      n
[         R                  R                  U
5      (       a  [        R                  S5        U
$ [        R                  S5        U
$ )N.objz.pngverticestexture_mapzsave animation succeed!zsave animation failed!)r5   r6   dirnameabspathr8   r   cv2imreadr   r/   rC   existsr   r   )r   	mesh_pathr,   r-   r=   r+   tex_pathmeshtexrG   r@   s              r   animate Human3DAnimationPipeline.animateP   s    77??277??9#=>$$VV4	"jj"
##Z!])"(7$$X.	77>>)$$KK12  KK01r!   inputc                    US   nUS   nUS   nUS   nSU;   a  US   nOS nSU;   a  US   U l         OSU l         UR                  S5      (       a  UnOUR                  S5      S	   nUR                  S5      S
   n	[        R                  " XUS9R
                  S   S   n
[        R                  R                  X5      n[        R                  R                  US5      n[        R                  SU5        UR                  S5      S	   nUR                  S5      S
   n	[        R                  " XSS9R
                  S   S   n[        R                  R                  US5      nU R                  X|XV5      n[        R                  U0$ )N
dataset_idcase_idaction_datasetr-   r=   r;   rF   /r   )	namespacesubset_namesplit_configtestzbody.objz
load mesh:)r[   split	actions_a)r;   endswithr_   r	   loadconfig_kwargsr5   r6   r9   r   r   rR   r
   OUTPUT)r   rT   rV   rW   action_data_idr-   r=   rN   dataset_name	user_namedata_dirr+   r,   outputs                 r   forward Human3DAnimationPipeline.forwardb   s   <(
	"/0xZ(HH +DL$DLF##I%++C04L"((-a0I ~~#%%2]>CCIKH ww||H6HXz:IL),%++C04"((-a0	^^'-88>@
 WW\\*k:
iVF!!6**r!   c                     U$ r%   r   r&   s     r   postprocess$Human3DAnimationPipeline.postprocess   r)   r!   )r-   r,   r;   r+   r   )gpur%   )__name__
__module____qualname____firstlineno____doc__r   r   strr   r'   r/   rC   rR   rj   rm   __static_attributes____classcell__)r   s   @r   r   r      s    $	2c3h DcN "$$+T#s(^ $+S#X $+L$sCx. T#s(^  r!   r   )r5   typingr   r   rK   modelscope.metainfor   &modelscope.models.cv.human3d_animationr   r   r   modelscope.msdatasetsr	   modelscope.outputsr
   modelscope.pipelines.baser   modelscope.pipelines.builderr   modelscope.utils.constantr   modelscope.utils.loggerr   r   register_modulehuman3d_animationr   r   r!   r   <module>r      sp    	  
 )? ? + ) . 2 + .	 	)D)DFsx sFsr!   