-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfour_d_humans_blender.py
5932 lines (4404 loc) · 226 KB
/
four_d_humans_blender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# from typing import Pattern
import bpy
from bpy.types import Operator
# from . helper import Helper
from bpy_extras.io_utils import ImportHelper,ExportHelper
from bpy.props import CollectionProperty
# from bpy.props import StringProperty
import json
import os,sys,glob
# from shutil import copyfile,rmtree,move
from os.path import join
from .panel import *
import shutil
import subprocess
import glob
import pickle
import mathutils
from mathutils import *
def read_pkl_data(context,character=0): #0=4d humans, 1=wham
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
#pegando a quantidade de characters
# import pickle
if character==0:
base_file = os.path.join(path_addon,'4D-Humans-main','outputs','results')
file_converted = os.path.join(base_file,'demo_video_converted.pkl')
file = file_converted
with open(file, 'rb') as handle:
b = pickle.load(handle)
num_character = 0
for fframe, data in enumerate(b.items()):
len_char = len(data[1]['smpl'])
print('len_char: ',len_char)
if num_character < len_char:
num_character = len_char
print('num_char:',num_character)
if character==1:
base_file = os.path.join(path_addon,'WHAM','output','demo','video')
file_converted = os.path.join(base_file,'wham_output.pickle')
file = file_converted
with open(file, 'rb') as handle:
b = pickle.load(handle)
list_characters = []
for i in b:
if len(b[i]) >0:
list_characters.append(str(i))
num_character = len(list_characters)
fourd_prop.str_list_characters = json.dumps(list_characters)
fourd_prop.int_tot_character = num_character
# def simple_gen_exec(context,code): #code: 0 - 4d humans, 1- WHAM, 2-SLAHMR
# def simple_gen_exec(context):
# fourd_prop = context.scene.fourd_prop
# path_addon = os.path.dirname(os.path.abspath(__file__))
# path_venv = fourd_prop.str_venv_path
# path_venv_4dhumans = join(path_venv,fourd_prop.str_custom_venv_name) #4d humans venv
# # path_venv_cuda = join(path_venv,fourd_prop.str_custom_venv_name,'CUDA')
# path_venv_activate_4dhumans = join(path_venv_4dhumans,'Scripts','activate.bat')
# drive_addon = path_addon.split(':')[0]
# rest_path_addon = path_addon.split(':')[1]
# rest_path_stable_diffusion = join(rest_path_addon,'stable-diffusion-main')
# if os.path.exists(path_venv_activate_4dhumans):
# with open(path_venv_activate_4dhumans, "rt") as fin: #cria um bat com a ativacao do venv e inclui instalacao dos pacotes para Stable diffusion
# with open(join(path_addon,'install_SDM_reqs.bat'), "wt") as fout:
# for line in fin:
# # fout.write(line.replace('####RESULTS_DIR####', folder_prj))
# fout.write(line)
# fout.write('\nrem %1 - drive env')
# fout.write('\nrem %2 - path to venv (wihtout drive)')
# fout.write('\nrem %3 - env_folder')
# fout.write('\n'+drive_addon+':')
# fout.write('\ncd'+rest_path_addon)
# fout.write('\ncd')
# fout.write('\npython -mpip install -r requirements.txt')
# fout.write('\necho --------------------------------------------------------------')
# fout.write('\necho YOU CAN CLOSE THIS WINDOW NOW')
# fout.write('\necho --------------------------------------------------------------')
# print('Re created install_SDM_reqs.bat')
# with open(join(path_addon,'stable-diffusion-main','req_local.txt'), "wt") as fout:
# fout.write('\n-e '+join(path_venv_full,'src','taming-transformers')+'\\.')
# fout.write('\n-e '+join(path_venv_full,'src','CLIP')+'\\.')
# print('Re created stable-diffusion-main/req_local.bat')
# with open(path_venv_activate, "rt") as fin: #Generic Python execution
# with open(join(path_addon,'execute_python_generic.bat'), "wt") as fout:
# for line in fin:
# # fout.write(line.replace('####RESULTS_DIR####', folder_prj))
# fout.write(line)
# fout.write('\n'+drive_addon+':')
# fout.write('\ncd'+rest_path_stable_diffusion)
# fout.write('\nEcho path of the addon, execute')
# fout.write('\ncd')
# fout.write('\necho --------------------------------------------------')
# fout.write('\npython %*')
# # fout.write('\n%*')
# print('Re created execute_python_generic.bat')
# with open(path_venv_activate_4dhumans, "rt") as fin: #Generic Python with custom folder
# with open(join(path_addon,'execute_python_generic_custom_folder.bat'), "wt") as fout:
# for line in fin:
# # fout.write(line.replace('####RESULTS_DIR####', folder_prj))
# fout.write(line)
# fout.write('\nEcho path of the addon, execute')
# fout.write('\ncd')
# fout.write('\necho --------------------------------------------------')
# fout.write('\npython %*')
# # fout.write('\n%*')
# print('Re created execute_python_generic_custom_folder.bat')
# if code == 1: #1 = WHAM
# path_venv_wham_full = join(path_venv,fourd_prop.str_custom_venv_name_wham)
# path_venv_activate_wham = join(path_venv_wham_full,'Scripts','activate.bat')
# with open(path_venv_activate_wham, "rt") as fin: #cria um bat com a ativacao do venv e inclui instalacao dos pacotes para Stable diffusion
# with open(join(path_addon,'execute_python_generic_custom_folder_wham.bat'), "wt") as fout:
# for line in fin:
# # fout.write(line.replace('####RESULTS_DIR####', folder_prj))
# fout.write(line)
# fout.write('\nEcho path of the addon, execute')
# fout.write('\ncd')
# fout.write('\necho --------------------------------------------------')
# fout.write('\npython %*')
# # fout.write('\n%*')
# print('Re created execute_python_generic_custom_folder_wham.bat')
def bind(context,rig,target):
# fourd_prop = context.scene.fourd_prop
scn = context.scene
scn.source.select_set(True)
bpy.context.view_layer.objects.active = scn.source
if bpy.context.active_object.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
#etapa 1 - duplica armature origem, e criar constraint de "copy transforms" mix: before original(aligned); target: local; owner: local
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True) # aplica transform no source
#duplicando armature para apply scale
bpy.ops.object.select_all(action='DESELECT')
if target == 'stg2':
scn.target_stg2.select_set(True)
else:
scn.target.select_set(True)
bpy.ops.object.duplicate(linked=False)
target_duplicate = bpy.context.selected_objects[0]
#com a armture destino duplicada, apply scale
# bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
scn.source.select_set(True)
if bpy.context.active_object.mode != 'EDIT':
bpy.ops.object.mode_set(mode='EDIT')
#copiando bones, e suas informacoes
for b in rig:
if scn.source.name.startswith('STG2_Armature') and b[0] in ["m_avg_root","m_avg_L_Hand","m_avg_R_Hand"]:
continue
bone = scn.source.data.edit_bones[b[0]]
copy_bone = scn.source.data.edit_bones.new(bone.name+'_CEB4D')
copy_bone.length = bone.length
if bone.parent:
copy_bone.parent = scn.source.data.edit_bones[bone.parent.name+'_CEB4D']
copy_bone.matrix = bone.matrix.copy()
#colocar copia do destino nesse rig
if b[1] != '':
bone_dest = target_duplicate.data.edit_bones[b[1]]
copy_bone_dest = scn.source.data.edit_bones.new(bone_dest.name+'_CP_CEB4D')
copy_bone_dest.length = bone_dest.length
copy_bone_dest.parent = scn.source.data.edit_bones[b[0]+'_CEB4D']
copy_bone_dest.matrix = bone_dest.matrix.copy()
#"""
bpy.ops.object.mode_set(mode='OBJECT')
for b in rig:
if scn.source.name.startswith('STG2_Armature') and b[0] in ["m_avg_root","m_avg_L_Hand","m_avg_R_Hand"]:
continue
scn.source.pose.bones[b[0]+'_CEB4D'].constraints.new('COPY_TRANSFORMS')
scn.source.pose.bones[b[0]+'_CEB4D'].constraints[0].target = scn.source
scn.source.pose.bones[b[0]+'_CEB4D'].constraints[0].subtarget = b[0]
scn.source.pose.bones[b[0]+'_CEB4D'].constraints[0].mix_mode = 'BEFORE'
scn.source.pose.bones[b[0]+'_CEB4D'].constraints[0].target_space = 'LOCAL'
scn.source.pose.bones[b[0]+'_CEB4D'].constraints[0].owner_space = 'LOCAL'
# fazr a copia do transform do armature clonado
for b in rig:
if b[1] != '':
if target == 'stg2':
cp_rot = scn.target_stg2.pose.bones[b[1]].constraints.new('COPY_ROTATION')
else:
cp_rot = scn.target.pose.bones[b[1]].constraints.new('COPY_ROTATION')
cp_rot.name = cp_rot.name + '_CEB4D'
cp_rot.target = scn.source
cp_rot.subtarget = b[1]+'_CP_CEB4D'
if b[0] == 'm_avg_Pelvis':
# if context.scene.target.name.startswith('STG2_'):
if target == 'stg2':
cp_loc = scn.target_stg2.pose.bones['Ctrl_Hips'].constraints.new('COPY_LOCATION')
else:
cp_loc = scn.target.pose.bones[b[1]].constraints.new('COPY_LOCATION')
cp_loc.name = cp_loc.name + '_CEB4D'
cp_loc.target = scn.source
cp_loc.subtarget = b[0]
#apagar a copia do armature que fiz para "apply scale"
bpy.ops.object.select_all(action='DESELECT')
target_duplicate.select_set(True)
bpy.context.view_layer.objects.active = target_duplicate
bpy.ops.object.delete() #apaga duplicata que fiz "apply transforms"
if target == 'stg2':
scn.target_stg2['bind']=1
else:
scn.target['bind']=1
# def unbind(context,type): #type = 0 apenas unbind, type =1 retaarget e depois unbind
def unbind(context,target):
scn = context.scene
armature = context.scene.source
armature.select_set(True)
bpy.context.view_layer.objects.active = armature #estou selecionando o armature aqui para poder fazer o mode abaixo funcionar, caso o personagem nao esteja selecionado
if bpy.context.active_object.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
armature.select_set(True)
bpy.context.view_layer.objects.active = armature
if target == 'stg2':
for b in scn.target_stg2.pose.bones:
for b_c in b.constraints:
if b_c.name.endswith('_CEB4D'):
b.constraints.remove(b_c)
scn.target_stg2['bind']=0
else:
for b in scn.target.pose.bones:
for b_c in b.constraints:
if b_c.name.endswith('_CEB4D'):
b.constraints.remove(b_c)
scn.target['bind']=0
## apagando bones criados
bpy.ops.object.mode_set(mode='EDIT')
for bone in armature.data.edit_bones:
# print(bone.name)
if bone.name.find("_CEB4D")> 0:
# print('apagar: ',bone.name)
armature.data.edit_bones.remove(bone)
bpy.ops.object.mode_set(mode='OBJECT')
def retarget(context,target):
fourd_prop = context.scene.fourd_prop
scn = context.scene
if target == 'stg2':
scn.target_stg2.select_set(True)
bpy.context.view_layer.objects.active = scn.target_stg2
else:
scn.target.select_set(True)
bpy.context.view_layer.objects.active = scn.target
start_frame = context.scene.frame_start
end_frame = context.scene.frame_end
# if context.scene.target.name.startswith('STG2_'):
if target == 'stg2':
bpy.ops.nla.bake(frame_start=start_frame, frame_end=end_frame,
only_selected=fourd_prop.bool_selected_bones, visual_keying=True, clear_constraints=False,
clear_parents=False, use_current_action=True, clean_curves=False, bake_types={'POSE'})
else:
bpy.ops.nla.bake(frame_start=start_frame, frame_end=end_frame,
only_selected=fourd_prop.bool_selected_bones, visual_keying=True, clear_constraints=True,
clear_parents=False, use_current_action=True, clean_curves=False, bake_types={'POSE'})
#removendo bones criados no bind
unbind(context,target)
if fourd_prop.bool_retarget_hide_source:
scn.source.hide_render = True
scn.source.hide_viewport = True
for ob in bpy.data.objects:
if ob.parent == scn.source:
src_mesh = ob
print('found mesh')
src_mesh.hide_viewport = True
src_mesh.hide_render = True
if target == 'stg2':
scn.target_stg2['bind']=0
else:
scn.target['bind']=0
class CreateVirtualEnviroment(Operator):
bl_idname = "fdh.create_virtual_env"
bl_label = "Create Venv"
bl_description = "Create Virtual Enviroment"
def execute(self,context):
import subprocess
import sys
fourd_prop = context.scene.fourd_prop
path_addon = os.path.dirname(os.path.abspath(__file__))
path_venv = fourd_prop.str_venv_path
env_folder_name = fourd_prop.str_custom_venv_name
# path_pip_ini = join(path_venv,fourd_prop.str_custom_venv_name,'pip.ini')
drive_env = path_venv.split(':')[0]
# rest_path_env = path_venv.split(':')[1]
# install venv
os.chdir(path_venv)#muda diretorio
if os.path.exists(join(path_venv,fourd_prop.str_custom_venv_name)):
print('Environment already created')
else:
subprocess.run([join(path_addon,'install_venv_p310.bat'),drive_env, path_addon , path_venv, env_folder_name]) #Cria o venv
#arquivo criado para poder usar o pip pra instalar tudo de uma so vez
# with open(path_pip_ini, "wt") as fout:
# fout.write('[global]')
# fout.write('\nindex-url=https://pypi.org/simple')
# fout.write('\nextra-index-url=https://download.pytorch.org/whl/cu116')
# print('pip.ini file created')
# simple_gen_exec(context)
# simple_gen_exec(context,0) #code: 0 - 4d humans, 1- WHAM, 2-SLAHMR
return{'FINISHED'}
class CreateVirtualEnviromentWHAM(Operator):
bl_idname = "fdh.create_virtual_env_wham"
bl_label = "Create WHAM Venv"
bl_description = "Create Virtual Enviroment for WHAM"
def execute(self,context):
import subprocess
import sys
fourd_prop = context.scene.fourd_prop
path_addon = os.path.dirname(os.path.abspath(__file__))
path_venv = fourd_prop.str_venv_path
env_folder_name_wham = fourd_prop.str_custom_venv_name_wham
# path_pip_ini = join(path_venv,fourd_prop.str_custom_venv_name,'pip.ini')
drive_env = path_venv.split(':')[0]
# rest_path_env = path_venv.split(':')[1]
# install venv
os.chdir(path_venv)#muda diretorio
if os.path.exists(join(path_venv,fourd_prop.str_custom_venv_name_wham)):
print('Environment already created')
else:
subprocess.run([join(path_addon,'install_venv_p39.bat'),drive_env, path_addon , path_venv, env_folder_name_wham]) #Cria o venv
#arquivo criado para poder usar o pip pra instalar tudo de uma so vez
# with open(path_pip_ini, "wt") as fout:
# fout.write('[global]')
# fout.write('\nindex-url=https://pypi.org/simple')
# fout.write('\nextra-index-url=https://download.pytorch.org/whl/cu116')
# print('pip.ini file created')
# simple_gen_exec(context)
# simple_gen_exec(context,1) #code: 0 - 4d humans, 1- WHAM, 2-SLAHMR
return{'FINISHED'}
class CreateVirtualEnviromentSLAHMR(Operator):
bl_idname = "fdh.create_virtual_env_slahmr"
bl_label = "Create SLAHMR Venv"
bl_description = "Create Virtual Enviroment for SLAHMR"
def execute(self,context):
import subprocess
import sys
fourd_prop = context.scene.fourd_prop
path_addon = os.path.dirname(os.path.abspath(__file__))
path_venv = fourd_prop.str_venv_path
env_folder_name_wham = fourd_prop.str_custom_venv_name_slahmr
# path_pip_ini = join(path_venv,fourd_prop.str_custom_venv_name,'pip.ini')
drive_env = path_venv.split(':')[0]
# rest_path_env = path_venv.split(':')[1]
# install venv
os.chdir(path_venv)#muda diretorio
if os.path.exists(join(path_venv,fourd_prop.str_custom_venv_name_slahmr)):
print('Environment already created')
else:
# subprocess.run([join(path_addon,'install_venv_p39.bat'),drive_env, path_addon , path_venv, env_folder_name_wham]) #Cria o venv
subprocess.run([join(path_addon,'install_venv_p310.bat'),drive_env, path_addon , path_venv, env_folder_name_wham]) #Cria o venv
# simple_gen_exec(context)
# simple_gen_exec(context,2) #code: 0 - 4d humans, 1- WHAM, 2-SLAHMR
return{'FINISHED'}
class InstallPYTORCHOnVenv(Operator):
bl_idname = "fdh.install_pytorch_venv"
bl_label = "Install Pytorch on Venv"
bl_description = "Install Pytorch, only needed you you dont have one already with the same version this addon needs"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name)
batch_file = 'install_pytorch.bat'
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
# fout.write('\npython sdm_unips/main_batch.py --session_name results --target '+fourd_prop.enum_target+' --test_dir "'+path_batch+'" --checkpoint "'+path_ckpt+'" %*')
fout.write('\npython -mpip install torch==1.13.0 torchvision==0.14.0 --index-url https://download.pytorch.org/whl/cu117')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,'install_pytorch.bat')+'" \"')
return{'FINISHED'}
class InstallPYTORCHOnVenvWHAM(Operator):
bl_idname = "fdh.install_pytorch_venv_wham"
bl_label = "Install Pytorch wham on Venv"
bl_description = "Install Pytorch, only needed you you dont have one already with the same version this addon needs"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_wham)
batch_file = 'install_pytorch_wham.bat'
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
# fout.write('\npython sdm_unips/main_batch.py --session_name results --target '+fourd_prop.enum_target+' --test_dir "'+path_batch+'" --checkpoint "'+path_ckpt+'" %*')
fout.write('\npython -mpip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,'install_pytorch_wham.bat')+'" \"')
return{'FINISHED'}
class InstallPYTORCHOnVenvSLAHMR(Operator):
bl_idname = "fdh.install_pytorch_venv_slahmr"
bl_label = "Install Pytorch slahmr on Venv"
bl_description = "Install Pytorch, only needed you you dont have one already with the same version this addon needs"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_slahmr)
batch_file = 'install_pytorch_slahmr.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
# fout.write('\npython sdm_unips/main_batch.py --session_name results --target '+fourd_prop.enum_target+' --test_dir "'+path_batch+'" --checkpoint "'+path_ckpt+'" %*')
fout.write('\npython -mpip install torch==1.13.0 torchvision==0.14.0 --index-url https://download.pytorch.org/whl/cu117')
# fout.write('\npython -mpip install torch-scatter -f https://data.pyg.org/whl/torch-1.13.0+cu117.html')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\ncd "slahmr"')
fout.write('\npython -mpip install torch_scatter-2.1.1+pt113cu117-cp310-cp310-win_amd64.whl')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,batch_file)+'" \"')
return{'FINISHED'}
class InstallPREDETECTRONOnVenv(Operator):
bl_idname = "fdh.install_pre_detectron_venv"
bl_label = "Install Pre Detectron on Venv"
bl_description = "Install Pre Detectron"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name)
batch_file = 'install_pre_detectron.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
# fout.write('\npython sdm_unips/main_batch.py --session_name results --target '+fourd_prop.enum_target+' --test_dir "'+path_batch+'" --checkpoint "'+path_ckpt+'" %*')
fout.write('\nset python_include="'+path_addon+'\\python_source\\include"')
fout.write('\nset python_pc="'+path_addon+'\\python_source\\PC"')
fout.write('\nset python_libs="'+path_addon+'\\python_source\\libs"')
fout.write('\nset INCLUDE=%python_include%;%python_pc%;%INCLUDE%')
fout.write('\nset LIB=%python_libs%;%LIB%')
fout.write('\npython -mpip install pywin32==305')
fout.write('\npython -mpip install Cython')
fout.write('\npython -mpip install git+https://github.com/facebookresearch/fvcore')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\npython -mpip install pycocotools-2.0-cp310-cp310-win_amd64.whl')
# fout.write('\ncd ..')
# fout.write('\npython -mpip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI')
fout.write('\npython -mpip install av==10.0.0')
fout.write('\npython -mpip install scipy==1.10.0')
fout.write('\npython -mpip install ninja')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
# fout.write('\npython -mpip install numpy==1.23.0')
# fout.write('\npython -mpip install -r "'+os.path.join(path_addon,'requirements_pre_detectron2.txt"'))
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,'install_pre_detectron.bat')+'" \"')
return{'FINISHED'}
class InstallWHAMOnVenv(Operator):
bl_idname = "fdh.install_wham_venv"
bl_label = "Install WHAM Reqs on Venv"
bl_description = "Install WHAM"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_wham)
batch_file = 'install_WHAM.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
# fout.write('\npython sdm_unips/main_batch.py --session_name results --target '+fourd_prop.enum_target+' --test_dir "'+path_batch+'" --checkpoint "'+path_ckpt+'" %*')
# fout.write('\nset python_include="'+path_addon+'\\python_source\\include"')
# fout.write('\nset python_pc="'+path_addon+'\\python_source\\PC"')
# fout.write('\nset python_libs="'+path_addon+'\\python_source\\libs"')
# fout.write('\nset INCLUDE=%python_include%;%python_pc%;%INCLUDE%')
# fout.write('\nset LIB=%python_libs%;%LIB%')
# fout.write('\npython -mpip install pywin32==305')
# fout.write('\npython -mpip install Cython')
# fout.write('\npython -mpip install git+https://github.com/facebookresearch/fvcore')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\ncd "WHAM"')
fout.write('\npython -mpip install -r requirements_wham.txt')
fout.write('\npython -mpip install mmpose-0.24.0-py2.py3-none-any.whl')
fout.write('\npython -mpip install dpvo-0.0.0-cp39-cp39-win_amd64.whl')
# fout.write('\ncd ..')
# fout.write('\npython -mpip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI')
# fout.write('\npython -mpip install scipy==1.10.0')
# fout.write('\npython -mpip install ninja')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
# fout.write('\npython -mpip install numpy==1.23.0')
# fout.write('\npython -mpip install -r "'+os.path.join(path_addon,'requirements_pre_detectron2.txt"'))
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,'install_WHAM.bat')+'" \"')
return{'FINISHED'}
class InstallSLAHMROnVenv(Operator):
bl_idname = "fdh.install_slahmr_venv_reqs"
bl_label = "Install SLAHMR Reqs on Venv"
bl_description = "Install SLAHMR"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_slahmr)
batch_file = 'install_SLAHMR.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\ncd "slahmr"')
fout.write('\npython -mpip install -r requirements_slahmr.txt')
# fout.write('\npython -mpip install mmpose-0.24.0-py2.py3-none-any.whl')
# fout.write('\npython -mpip install dpvo-0.0.0-cp39-cp39-win_amd64.whl')
# fout.write('\ncd ..')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,batch_file)+'" \"')
return{'FINISHED'}
class DownloadWHAMCheckpoints(Operator):
bl_idname = "fdh.download_whan_checkpoints"
bl_label = "WHAM Checkpoints"
bl_description = "WHAM Checkpoints"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_wham)
batch_file = 'install_WHAM_checkpoints.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\ncd "WHAM"')
# fout.write('\npython -mpip install -r requirements_wham.txt')
fout.write('\nif not exist "checkpoints" mkdir checkpoints')
fout.write('\nif not exist "checkpoints/wham_vit_w_3dpw.pth.tar" gdown "https://drive.google.com/uc?id=1i7kt9RlCCCNEW2aYaDWVr-G778JkLNcB&export=download&confirm=t" -O "checkpoints/wham_vit_w_3dpw.pth.tar"')
fout.write('\nif not exist "checkpoints/wham_vit_bedlam_w_3dpw.pth.tar" gdown "https://drive.google.com/uc?id=19qkI-a6xuwob9_RFNSPWf1yWErwVVlks&export=download&confirm=t" -O "checkpoints/wham_vit_bedlam_w_3dpw.pth.tar"')
fout.write('\nif not exist "checkpoints/hmr2a.ckpt" gdown "https://drive.google.com/uc?id=1J6l8teyZrL0zFzHhzkC7efRhU0ZJ5G9Y&export=download&confirm=t" -O "checkpoints/hmr2a.ckpt"')
fout.write('\nif not exist "checkpoints/dpvo.pth" gdown "https://drive.google.com/uc?id=1kXTV4EYb-BI3H7J-bkR3Bc4gT9zfnHGT&export=download&confirm=t" -O "checkpoints/dpvo.pth"')
fout.write('\nif not exist "checkpoints/yolov8x.pt" gdown "https://drive.google.com/uc?id=1zJ0KP23tXD42D47cw1Gs7zE2BA_V_ERo&export=download&confirm=t" -O "checkpoints/yolov8x.pt"')
fout.write('\nif not exist "checkpoints/vitpose-h-multi-coco.pth" gdown "https://drive.google.com/uc?id=1xyF7F3I7lWtdq82xmEPVQ5zl4HaasBso&export=download&confirm=t" -O "checkpoints/vitpose-h-multi-coco.pth"')
# fout.write('\ncd ..')
# fout.write('\npython -mpip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI')
# fout.write('\npython -mpip install scipy==1.10.0')
# fout.write('\npython -mpip install ninja')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
# fout.write('\npython -mpip install numpy==1.23.0')
# fout.write('\npython -mpip install -r "'+os.path.join(path_addon,'requirements_pre_detectron2.txt"'))
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,batch_file)+'" \"')
return{'FINISHED'}
class DownloadWHAMBodymodels(Operator):
bl_idname = "fdh.download_whan_bodymodels"
bl_label = "WHAM BodyModels"
bl_description = "WHAM BodyModels"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_wham)
batch_file = 'install_WHAM_bodymodels.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
# fout.write('\ncd "WHAM"')
# fout.write('\npython -mpip install -r requirements_wham.txt')
# fout.write('\nif not exist "dataset" mkdir dataset')
# fout.write('\nif not exist "dataset/body_models.tar.gz" gdown "https://drive.google.com/uc?id=1pbmzRbWGgae6noDIyQOnohzaVnX_csUZ&export=download&confirm=t" -O "dataset/body_models.tar.gz"')
fout.write('\ntartool wham/body_models.tar.gz wham/dataset')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,batch_file)+'" \"')
return{'FINISHED'}
class InstallDETECTRONOnVenv(Operator):
bl_idname = "fdh.install_detectron_venv"
bl_label = "Install Detectron on Venv"
bl_description = "Install Detectron"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name)
batch_file = 'install_detectron.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
# fout.write('\npython sdm_unips/main_batch.py --session_name results --target '+fourd_prop.enum_target+' --test_dir "'+path_batch+'" --checkpoint "'+path_ckpt+'" %*')
# fout.write('\nset python_include="'+path_addon+'\\python_source\\include"')
# fout.write('\nset python_pc="'+path_addon+'\\python_source\\PC"')
# fout.write('\nset python_libs="'+path_addon+'\\python_source\\libs"')
# fout.write('\nset INCLUDE=%python_pc%;%python_include%;%INCLUDE%')
# fout.write('\nset LIB=%python_libs%;%LIB%')
# fout.write('\npython -mpip install git+https://github.com/facebookresearch/detectron2.git')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\npython -mpip install detectron2-0.6-cp310-cp310-win_amd64.whl')
fout.write('\npython -mpip install mmcv_full-1.6.0-cp310-cp310-win_amd64.whl')
# fout.write('\npython -mpip install pytorch-lightning==2.2.5 smplx==0.1.28 pyrender opencv-python yacs scikit-image einops timm webdataset rich dill joblib scenedetect scikit-learn==1.3.0 pytube chumpy numpy==1.23.0')
fout.write('\npython -mpip install pytorch-lightning==2.2.5 smplx==0.1.28 pyrender==0.1.45 opencv-python==4.10.0.82 yacs==0.1.8 scikit-image==0.23.2 einops==0.8.0 timm==1.0.3 webdataset==0.2.86 rich==13.7.1 dill==0.3.8 joblib==1.4.2 scenedetect==0.6.4 scikit-learn==1.3.0 pytube==15.0.0 chumpy==0.70 numpy==1.23.0')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,'install_detectron.bat')+'" \"')
return{'FINISHED'}
class InstallDETECTRONOnVenvSLAHMR(Operator):
bl_idname = "fdh.install_detectron_venv_slahmr"
bl_label = "Install Detectron"
bl_description = "Install Detectron SLAHMR"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_slahmr)
batch_file = 'install_detectron_slahmr.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
# fout.write('\npython sdm_unips/main_batch.py --session_name results --target '+fourd_prop.enum_target+' --test_dir "'+path_batch+'" --checkpoint "'+path_ckpt+'" %*')
# fout.write('\nset python_include="'+path_addon+'\\python_source\\include"')
# fout.write('\nset python_pc="'+path_addon+'\\python_source\\PC"')
# fout.write('\nset python_libs="'+path_addon+'\\python_source\\libs"')
# fout.write('\nset INCLUDE=%python_pc%;%python_include%;%INCLUDE%')
# fout.write('\nset LIB=%python_libs%;%LIB%')
# fout.write('\npython -mpip install git+https://github.com/facebookresearch/detectron2.git')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\ncd "slahmr"')
fout.write('\npython -mpip install detectron2-0.6-cp310-cp310-win_amd64.whl')
# fout.write('\npython -mpip install torch_scatter-2.1.1+pt113cu117-cp310-cp310-win_amd64.whl')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,batch_file)+'" \"')
return{'FINISHED'}
class InstallSLAHMRandRESTOnVenv(Operator):
bl_idname = "fdh.install_slahmr_and_rest_venv"
bl_label = "Install SLAHMR and others on Venv"
bl_description = "Install SLAHMR & Others"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv = fourd_prop.str_venv_path
path_venv_full = join(path_venv,fourd_prop.str_custom_venv_name_slahmr)
batch_file = 'install_slahmr_and_others.bat'
drive_addon = path_addon.split(':')[0]
rest_path_addon = path_addon.split(':')[1]
with open(join(path_addon,batch_file), "wt") as fout:
fout.write('call \"'+join(path_venv_full,'Scripts','activate.bat')+'\"')
fout.write('\n'+drive_addon+':')
fout.write('\ncd "'+rest_path_addon+'"')
fout.write('\ncd "slahmr"')
fout.write('\npython -mpip install slahmr-0.0.0-py3-none-any.whl')
fout.write('\npython -mpip install mmpose-0.24.0-py2.py3-none-any.whl')
fout.write('\npython -mpip install droid_backends-0.0.0-cp310-cp310-win_amd64.whl')
fout.write('\npython -mpip install lietorch-0.2-cp310-cp310-win_amd64.whl')
fout.write('\npython -mpip install phalp-0.1.3-py3-none-any.whl')
fout.write('\npython -mpip install pandas==1.4.0')
fout.write('\npython -mpip install pytorch-lightning==2.2.0')
fout.write('\npython -mpip install webdataset==0.2.86')
fout.write('\npython -mpip install scikit-image==0.22.0')
fout.write('\npython -mpip install mmcv==1.3.9')
fout.write('\npython -mpip install git+https://github.com/nghorbani/configer@8cd1e3e556d9697298907800a743e120be57ac36')
fout.write('\npython -mpip install torchgeometry==0.1.2')
fout.write('\n@echo -----------------------------------------------')
fout.write('\n@echo --------- YOU CAN CLOSE THIS WINDOW ----------')
fout.write('\n@echo -----------------------------------------------')
#Executa oprocesso
os.system('start cmd /k \""'+join(path_addon,batch_file)+'" \"')
return{'FINISHED'}
class InstallREQPIXELOnVenv(Operator):
bl_idname = "fdh.install_reqs_venv"
bl_label = "Install Requirements on Venv"
bl_description = "Install Requirements"
def execute(self,context):
path_addon = os.path.dirname(os.path.abspath(__file__))
fourd_prop = context.scene.fourd_prop
path_venv =join(fourd_prop.str_venv_path,fourd_prop.str_custom_venv_name,'src')
drive = path_venv.split(':')[0]
rest_path = path_venv.split(':')[1]
os.system('start cmd /k \""'+join(path_addon,'install_SDM_reqs.bat')+'" '+drive+' '+rest_path+'\"')
return{'FINISHED'}
class VenvPathSelect(Operator, ImportHelper):
bl_idname = "fdh.venv_path_select"
bl_label = "Venv Path"
bl_description = "Select Venv Path"
# filename_ext = ".ckpt"
filter_glob: StringProperty(
# default="*.ckpt",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
def execute(self,context):
fourd_prop = context.scene.fourd_prop
path_venv_path = os.path.dirname(self.filepath)
fourd_prop.str_venv_path = os.path.dirname(self.filepath)
path_addon = os.path.dirname(os.path.abspath(__file__))
path_venv_path_txt = join(path_addon,'venv_path.txt')
with open(path_venv_path_txt, "wt") as fout:
fout.write(path_venv_path)
# simple_gen_exec(context)
return{'FINISHED'}
class ImportSMPLPKL(Operator, ImportHelper):
bl_idname = "fdh.import_smpl_pkl"
bl_label = "Import SMPL PKL"
bl_description = "Import SMPL PKL"
# filename_ext = ".ckpt"
filter_glob: StringProperty(
# default= ["*.jpg","*.png"],
# default= "*.png",
default= "*",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
files: CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)
directory: StringProperty(subtype='DIR_PATH')
option: IntProperty(name='character',default=0)#0=male, 1=female, 2=neutral
def execute(self,context):
fourd_prop = context.scene.fourd_prop
fourd_prop.str_videopath = self.filepath
from shutil import rmtree,copyfile
# # dfnrmvs_prop = context.scene.dfnrmvs_prop
path_addon = os.path.dirname(os.path.abspath(__file__))
# base_path_img = os.path.join(path_addon,'4D-Humans-main','datasets','TEST_DATA')
path_file = os.path.join(path_addon,'wham','dataset','body_models','smpl')
if not os.path.exists(path_file):
os.makedirs(path_file)
src = self.filepath
if self.option == 0: