forked from carlosedubarreto/b3d_mocap_import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
1223 lines (1075 loc) · 57.2 KB
/
helper.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
import bpy
import math
class helper_functions(object):
def anim_to_origin():
f_start = bpy.context.scene.frame_start
f_end = bpy.context.scene.frame_end
bpy.context.scene.frame_current=f_start
#==========================================
#selecting and making the armature Active
#selecionando armature
#==========================================
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
obs = []
for ob in bpy.context.scene.objects:
if ob.type == 'ARMATURE':
obs.append(ob)
#obs
armature = obs[len(obs)-1].name
#bpy.data.objects[armature].select_set(True)
obs[len(obs)-1].select_set(True)
view_layer = bpy.context.view_layer
#Armature_obj = bpy.context.scene.objects[armature]
Armature_obj = obs[len(obs)-1]
view_layer.objects.active = Armature_obj
#############################################################################
##found that to move the animation to the center,
##I just have to subtract the inicial frame loc and rot from the other frames
#########
x_dif = bpy.context.object.pose.bones["Root"].rotation_euler[0] * -1
y_dif = bpy.context.object.pose.bones["Root"].rotation_euler[1] * -1
z_dif = bpy.context.object.pose.bones["Root"].rotation_euler[2] * -1
x_loc_dif = bpy.context.object.pose.bones["Root"].location[0] * -1
y_loc_dif = bpy.context.object.pose.bones["Root"].location[1] * -1
z_loc_dif = bpy.context.object.pose.bones["Root"].location[2] * -1
bpy.ops.object.mode_set(mode='EDIT')
z_high_to_add = bpy.context.object.data.edit_bones["Foot_L"].tail.z
bpy.ops.object.mode_set(mode='POSE')
range(f_start,f_end+1)
for f in range(f_start,f_end+1):
print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
# print('rot orig x: ',bpy.context.object.pose.bones["Root"].rotation_euler[0])
# print('rot x: ',bpy.context.object.pose.bones["Root"].rotation_euler[0] + x_dif)
bpy.context.object.pose.bones["Root"].rotation_euler[0] = bpy.context.object.pose.bones["Root"].rotation_euler[0] + x_dif
bpy.context.object.pose.bones["Root"].rotation_euler[1] = bpy.context.object.pose.bones["Root"].rotation_euler[1] + y_dif
bpy.context.object.pose.bones["Root"].rotation_euler[2] = bpy.context.object.pose.bones["Root"].rotation_euler[2] + z_dif
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='rotation_euler',frame=f)
#################
## location to origin
##
bpy.context.object.pose.bones["Root"].location[0] = bpy.context.object.pose.bones["Root"].location[0] + x_loc_dif
bpy.context.object.pose.bones["Root"].location[1] = bpy.context.object.pose.bones["Root"].location[1] + y_loc_dif
bpy.context.object.pose.bones["Root"].location[2] = bpy.context.object.pose.bones["Root"].location[2] + z_loc_dif
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='location',frame=f)
#Check if need to transpose axis
if abs(abs(math.degrees(x_dif))-90) < 45 or abs(abs(math.degrees(x_dif))-270) < 45:
# if 1==1:
#############################
#rotate oprientation z por y
for f in range(f_start,f_end+1):
print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
#changing location
bone_root_loc_x = bpy.context.object.pose.bones["Root"].location[0]
bone_root_loc_y = bpy.context.object.pose.bones["Root"].location[1]
bone_root_loc_z = bpy.context.object.pose.bones["Root"].location[2]
#changing orientation from z to y
#z=y
bpy.context.object.pose.bones["Root"].location[2] = bone_root_loc_y
#y=z
bpy.context.object.pose.bones["Root"].location[1] = bone_root_loc_z
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='location',frame=f)
#######################
## rotation orientation change
##
#rotation the rotation z to y
bone_root_rot_x = bpy.context.object.pose.bones["Root"].rotation_euler[0]
bone_root_rot_y = bpy.context.object.pose.bones["Root"].rotation_euler[1]
bone_root_rot_z = bpy.context.object.pose.bones["Root"].rotation_euler[2]
#changing orientation from z to y
#z=y
bpy.context.object.pose.bones["Root"].rotation_euler[2] = bone_root_rot_y
#y=z
bpy.context.object.pose.bones["Root"].rotation_euler[1] = bone_root_rot_z
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='rotation_euler',frame=f)
###############################
## adjust the foot to z=0
for f in range(f_start,f_end+1):
# print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
bpy.context.object.pose.bones["Root"].location[1] = bpy.context.object.pose.bones["Root"].location[1] + abs(z_high_to_add)
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='location',frame=f)
# print('org x: ', math.degrees(x_dif), 'orig y: ', math.degrees(y_dif), 'orig_z: ', math.degrees(z_dif))
rot_original = 'x: ', math.degrees(x_dif), ' y: ', math.degrees(y_dif), ' z: ', math.degrees(z_dif)
print(rot_original)
bpy.ops.object.mode_set(mode='OBJECT')
return (math.degrees(x_dif),math.degrees(y_dif),math.degrees(z_dif))
def compensate_rot(x,y,z):
f_start = bpy.context.scene.frame_start
f_end = bpy.context.scene.frame_end
#just to compensate grad
x_grad_compensate = x
y_grad_compensate = y
z_grad_compensate = z
for f in range(f_start,f_end+1):
print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
print('rot orig x: ',bpy.context.object.pose.bones["Root"].rotation_euler[0])
print('rot x: ',bpy.context.object.pose.bones["Root"].rotation_euler[0] +math.radians(x_grad_compensate))
bpy.context.object.pose.bones["Root"].rotation_euler[0] = bpy.context.object.pose.bones["Root"].rotation_euler[0] +math.radians(x_grad_compensate)
bpy.context.object.pose.bones["Root"].rotation_euler[1] = bpy.context.object.pose.bones["Root"].rotation_euler[1] +math.radians(y_grad_compensate)
bpy.context.object.pose.bones["Root"].rotation_euler[2] = bpy.context.object.pose.bones["Root"].rotation_euler[2] +math.radians(z_grad_compensate)
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='rotation_euler',frame=f)
return True
def rotate_orientation(from_axis,to_axis):
#############################
#rotate oprientation acording to choice on menu
f_start = bpy.context.scene.frame_start
f_end = bpy.context.scene.frame_end
if from_axis == 'x':
from_ax = 0
elif from_axis == 'y':
from_ax = 1
elif from_axis == 'z':
from_ax = 2
if to_axis == 'x':
to_ax = 0
elif to_axis == 'y':
to_ax = 1
elif to_axis == 'z':
to_ax = 2
if (from_axis == 'x' and to_axis == 'y') or (to_axis == 'x' and from_axis == 'y'):
rotate_axis = 'z'
elif (from_axis == 'y' and to_axis == 'z') or (to_axis == 'y' and from_axis == 'z'):
rotate_axis = 'x'
elif (from_axis == 'z' and to_axis == 'x') or (to_axis == 'z' and from_axis == 'x'):
rotate_axis = 'y'
if 'rotate_axis' in locals():
if rotate_axis == 'x':
rot_ax = 0
elif rotate_axis == 'y':
rot_ax = 1
elif rotate_axis == 'z':
rot_ax = 2
if from_axis != rot_ax:
for f in range(f_start,f_end+1):
print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
##################
#changing location
bone_root_loc = []
bone_root_loc.append(bpy.context.object.pose.bones["Root"].location[0])
bone_root_loc.append(bpy.context.object.pose.bones["Root"].location[1])
bone_root_loc.append(bpy.context.object.pose.bones["Root"].location[2])
# bone_root_loc_x = bpy.context.object.pose.bones["Root"].location[0]
# bone_root_loc_y = bpy.context.object.pose.bones["Root"].location[1]
# bone_root_loc_z = bpy.context.object.pose.bones["Root"].location[2]
#from-to
# bpy.context.object.pose.bones["Root"].location[2] = bone_root_loc_y
bpy.context.object.pose.bones["Root"].location[from_ax] = bone_root_loc[to_ax]
#to-from
# bpy.context.object.pose.bones["Root"].location[1] = bone_root_loc_z
bpy.context.object.pose.bones["Root"].location[to_ax] = bone_root_loc[from_ax]
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='location',frame=f)
#######################
## rotation orientation change
##
bone_root_rot=[]
bone_root_rot.append(bpy.context.object.pose.bones["Root"].rotation_euler[0])
bone_root_rot.append(bpy.context.object.pose.bones["Root"].rotation_euler[1])
bone_root_rot.append(bpy.context.object.pose.bones["Root"].rotation_euler[2])
# bone_root_rot_x = bpy.context.object.pose.bones["Root"].rotation_euler[0]
# bone_root_rot_y = bpy.context.object.pose.bones["Root"].rotation_euler[1]
# bone_root_rot_z = bpy.context.object.pose.bones["Root"].rotation_euler[2]
#from-to
bpy.context.object.pose.bones["Root"].rotation_euler[from_ax] = bone_root_rot[to_ax]
#to-from
bpy.context.object.pose.bones["Root"].rotation_euler[to_ax] = bone_root_rot[from_ax]
#convert adding 90 degrees
bpy.context.object.pose.bones["Root"].rotation_euler[rot_ax] = bpy.context.object.pose.bones["Root"].rotation_euler[rot_ax] + math.radians(-90)
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='rotation_euler',frame=f)
return True
def reset_loc(): #make the animation start from where the boneas are located
f_start = bpy.context.scene.frame_start
f_end = bpy.context.scene.frame_end
x_loc_dif = bpy.context.object.pose.bones["Root"].location[0] * -1
y_loc_dif = bpy.context.object.pose.bones["Root"].location[1] * -1
z_loc_dif = bpy.context.object.pose.bones["Root"].location[2] * -1
for f in range(f_start,f_end+1):
print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
#################
## location to origin
##
bpy.context.object.pose.bones["Root"].location[0] = bpy.context.object.pose.bones["Root"].location[0] + x_loc_dif
bpy.context.object.pose.bones["Root"].location[1] = bpy.context.object.pose.bones["Root"].location[1] + y_loc_dif
bpy.context.object.pose.bones["Root"].location[2] = bpy.context.object.pose.bones["Root"].location[2] + z_loc_dif
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='location',frame=f)
return True
def reset_rot():
f_start = bpy.context.scene.frame_start
f_end = bpy.context.scene.frame_end
x_dif = bpy.context.object.pose.bones["Root"].rotation_euler[0] * -1
y_dif = bpy.context.object.pose.bones["Root"].rotation_euler[1] * -1
z_dif = bpy.context.object.pose.bones["Root"].rotation_euler[2] * -1
for f in range(f_start,f_end+1):
print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
bpy.context.object.pose.bones["Root"].rotation_euler[0] = bpy.context.object.pose.bones["Root"].rotation_euler[0] + x_dif
bpy.context.object.pose.bones["Root"].rotation_euler[1] = bpy.context.object.pose.bones["Root"].rotation_euler[1] + y_dif
bpy.context.object.pose.bones["Root"].rotation_euler[2] = bpy.context.object.pose.bones["Root"].rotation_euler[2] + z_dif
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='rotation_euler',frame=f)
return True
def foot_high():
f_start = bpy.context.scene.frame_start
f_end = bpy.context.scene.frame_end
bpy.ops.object.mode_set(mode='EDIT')
z_high_to_add = bpy.context.object.data.edit_bones["Foot_L"].tail.z
bpy.ops.object.mode_set(mode='POSE')
for f in range(f_start,f_end+1):
# print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
bpy.context.object.pose.bones["Root"].location[1] = bpy.context.object.pose.bones["Root"].location[1] + abs(z_high_to_add)
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='location',frame=f)
bpy.ops.object.mode_set(mode='OBJECT')
return True
def compensate_rot(x,y,z):
f_start = bpy.context.scene.frame_start
f_end = bpy.context.scene.frame_end
#just to compensate grad
x_grad_compensate = x
y_grad_compensate = y
z_grad_compensate = z
for f in range(f_start,f_end+1):
print('frame: ',f)
bpy.context.scene.frame_current = f
bpy.context.view_layer.update()
print('rot orig x: ',bpy.context.object.pose.bones["Root"].rotation_euler[0])
print('rot x: ',bpy.context.object.pose.bones["Root"].rotation_euler[0] +math.radians(x_grad_compensate))
bpy.context.object.pose.bones["Root"].rotation_euler[0] = bpy.context.object.pose.bones["Root"].rotation_euler[0] +math.radians(x_grad_compensate)
bpy.context.object.pose.bones["Root"].rotation_euler[1] = bpy.context.object.pose.bones["Root"].rotation_euler[1] +math.radians(y_grad_compensate)
bpy.context.object.pose.bones["Root"].rotation_euler[2] = bpy.context.object.pose.bones["Root"].rotation_euler[2] +math.radians(z_grad_compensate)
bpy.context.object.pose.bones["Root"].keyframe_insert(data_path='rotation_euler',frame=f)
return True
def get_rotations():
bpy.context.scene.frame_current = 1
bpy.context.view_layer.update()
actual_rot_x = bpy.context.object.pose.bones["Root"].rotation_euler[0]
actual_rot_y = bpy.context.object.pose.bones["Root"].rotation_euler[1]
actual_rot_z = bpy.context.object.pose.bones["Root"].rotation_euler[2]
return (actual_rot_x, actual_rot_y, actual_rot_z)
# types = {'VIEW_3D', 'TIMELINE', 'GRAPH_EDITOR', 'DOPESHEET_EDITOR', 'NLA_EDITOR', 'IMAGE_EDITOR', 'SEQUENCE_EDITOR', 'CLIP_EDITOR', 'TEXT_EDITOR', 'NODE_EDITOR', 'LOGIC_EDITOR', 'PROPERTIES', 'OUTLINER', 'USER_PREFERENCES', 'INFO', 'FILE_BROWSER', 'CONSOLE'}
def smooth_curves(o):
current_area = bpy.context.area.type
layer = bpy.context.view_layer
# select all (relevant) bones
for b in o.data.bones:
b.select = False
o.data.bones[0].select = True
layer.update()
# change to graph editor
bpy.context.area.type = "GRAPH_EDITOR"
# # lock or unlock the respective fcurves
# for fc in o.animation_data.action.fcurves:
# print(fc.data_path)
# if "location" in fc.data_path:
# fc.lock = False
# else:
# fc.lock = True
layer.update()
# smooth curves of all selected bones
bpy.ops.graph.smooth()
# switch back to original area
bpy.context.area.type = current_area
# deselect all (relevant) bones
for b in o.data.bones:
b.select = False
layer.update()
return True
class skeleton_import(object):
def middle_point(p1,p2,p_middle):
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects[p1].select_set(True)
bpy.data.objects[p2].select_set(True)
bpy.context.view_layer.objects.active = bpy.data.objects[p2]
obs = bpy.context.selected_objects
n = len(obs)
# print('n: ',n)
assert(n)
#scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n
bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n
def create_dots(name, amount):
#remove Collection
if bpy.data.collections.find(name) >= 0:
collection = bpy.data.collections.get(name)
#
for obj in collection.objects:
bpy.data.objects.remove(obj, do_unlink=True)
bpy.data.collections.remove(collection)
#cria os pontos nuima collection chamada Points
#=====================================================
collection = bpy.data.collections.new(name)
bpy.context.scene.collection.children.link(collection)
#
layer_collection = bpy.context.view_layer.layer_collection.children[collection.name]
bpy.context.view_layer.active_layer_collection = layer_collection
#
for point in range(amount):
bpy.ops.mesh.primitive_plane_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.ops.mesh.merge(type='CENTER')
bpy.ops.object.editmode_toggle()
bpy.context.active_object.name = name+'.'+str(1000+point)[1:]
#=====================================================
def remove_dots(name):
#apagar collection points criada
collection = bpy.data.collections.get(name)
#
for obj in collection.objects:
bpy.data.objects.remove(obj, do_unlink=True)
bpy.data.collections.remove(collection)
def distance(point1, point2) -> float:
#Calculate distance between two points in 3D.
# return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2)
return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2)
def size_bone(point_name1, point_name2, bone):
p1 = bpy.data.objects[point_name1]
p2 = bpy.data.objects[point_name2]
#edit bones
if bpy.context.active_object.mode == 'EDIT':
bpy.context.object.data.edit_bones[bone].length= distance(p1,p2)
else:
bpy.ops.object.editmode_toggle()
bpy.context.object.data.edit_bones[bone].length= distance(p1,p2)
bpy.ops.object.editmode_toggle()
def create_bones(bones_list):
#===================================
#creating bones
#====================================
bpy.ops.object.armature_add(enter_editmode=True, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) #cria armature e primeiro bone
#bpy.ops.object.editmode_toggle()
#bpy.data.armatures['Armature'].edit_bones.active = bpy.context.object.data.edit_bones['Bone']
obs = []
for ob in bpy.context.scene.objects:
if ob.type == 'ARMATURE':
obs.append(ob)
#obs
bpy.ops.armature.select_all(action='DESELECT')
obs[len(obs)-1].data.edit_bones['Bone'].select_tail=True
bpy.ops.armature.bone_primitive_add()#Spine
#Neck
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
#Face
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
bpy.ops.armature.bone_primitive_add()#Arm_L
#Forearm_L
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
bpy.ops.armature.bone_primitive_add()#Arm_R
#Forearm_R
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
bpy.ops.armature.bone_primitive_add()#Thigh_L
#Leg_L
#Foot_L
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
bpy.ops.armature.bone_primitive_add()#Thigh_R
#Leg_R
#Foot_R
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
bpy.ops.armature.extrude_move(ARMATURE_OT_extrude={"forked":False}, TRANSFORM_OT_translate={"value":(0.0, 0.0, 0.1)})
for i in range(len(bones_list)):
obs[len(obs)-1].data.edit_bones[bones_list[i][0]].name = bones_list[i][1]
#Hierarquia
bpy.context.object.data.edit_bones["Spine"].parent = bpy.context.object.data.edit_bones["Root"]
bpy.context.object.data.edit_bones["Arm_L"].parent = bpy.context.object.data.edit_bones["Spine"]
bpy.context.object.data.edit_bones["Arm_R"].parent = bpy.context.object.data.edit_bones["Spine"]
bpy.context.object.data.edit_bones["Thigh_L"].parent = bpy.context.object.data.edit_bones["Root"]
bpy.context.object.data.edit_bones["Thigh_R"].parent = bpy.context.object.data.edit_bones["Root"]
bpy.ops.object.editmode_toggle()
def distance(point1, point2) -> float:
#Calculate distance between two points in 3D.
#return math.sqrt((point2[0] - point1[0]) ** 2 + (point2[1] - point1[1]) ** 2 + (point2[2] - point1[2]) ** 2)
return math.sqrt((point2.location[0] - point1.location[0]) ** 2 + (point2.location[1] - point1.location[1]) ** 2 + (point2.location[2] - point1.location[2]) ** 2)
def size_bone(point_name1, point_name2, bone):
p1 = bpy.data.objects[point_name1]
p2 = bpy.data.objects[point_name2]
#edit bones
if bpy.context.active_object.mode == 'EDIT':
bpy.context.object.data.edit_bones[bone].length= distance(p1,p2)
else:
bpy.ops.object.editmode_toggle()
bpy.context.object.data.edit_bones[bone].length= distance(p1,p2)
bpy.ops.object.editmode_toggle()
def size_ref_bone(p1,p2,p_final):
from mathutils import Vector
import bpy
## size of the reference bone (spine)
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects[p1].select_set(True)
bpy.data.objects[p2].select_set(True)
# bpy.context.view_layer.objects.active = bpy.data.objects['Point.034']
bpy.context.view_layer.objects.active = bpy.data.objects[p2]
obs = bpy.context.selected_objects
n = len(obs)
# print('n: ',n)
assert(n)
#scene.cursor.location = sum([o.matrix_world.translation for o in obs], Vector()) / n
#bpy.data.objects[p_middle].location = sum([o.matrix_world.translation for o in obs], Vector()) / n
x_subtract = abs(obs[0].matrix_world.translation.x - obs[1].matrix_world.translation.x)
y_subtract = abs(obs[0].matrix_world.translation.y - obs[1].matrix_world.translation.y)
z_subtract = abs(obs[0].matrix_world.translation.z - obs[1].matrix_world.translation.z)
max(x_subtract, y_subtract, z_subtract) #maior das medidas
unit_def = max(x_subtract, y_subtract, z_subtract)/3
#end of size of reference bone Spine
return unit_def
def size_of_bones(unit, root_size, spine_size, neck_size, face_size, thigh_size, leg_size, foot_size, arm_size, forearm_size):
#==========================================
#selecting and making the armature Active
#selecionando armature
#==========================================
bpy.ops.object.select_all(action='DESELECT')
#bpy.ops.armature.select_all(action='DESELECT')
obs = []
for ob in bpy.context.scene.objects:
if ob.type == 'ARMATURE':
obs.append(ob)
#obs
armature = obs[len(obs)-1].name
#bpy.data.objects[armature].select_set(True)
obs[len(obs)-1].select_set(True)
view_layer = bpy.context.view_layer
#Armature_obj = bpy.context.scene.objects[armature]
Armature_obj = obs[len(obs)-1]
view_layer.objects.active = Armature_obj
#converting to euler rotation
order = 'XYZ'
context = bpy.context
rig_object = context.active_object
for pb in rig_object.pose.bones:
pb.rotation_mode = order
bpy.ops.object.editmode_toggle()
#changing location
#resetting
bpy.context.object.data.edit_bones["Spine"].head.xy=0
bpy.context.object.data.edit_bones["Neck"].head.xy=0
bpy.context.object.data.edit_bones["Face"].head.xy=0
bpy.context.object.data.edit_bones["Arm_L"].head.xy=0
bpy.context.object.data.edit_bones["Forearm_L"].head.xy=0
bpy.context.object.data.edit_bones["Arm_R"].head.xy=0
bpy.context.object.data.edit_bones["Forearm_R"].head.xy=0
bpy.context.object.data.edit_bones["Thigh_L"].head.xy=0
bpy.context.object.data.edit_bones["Leg_L"].head.xy=0
bpy.context.object.data.edit_bones["Foot_L"].head.xy=0
bpy.context.object.data.edit_bones["Thigh_R"].head.xy=0
bpy.context.object.data.edit_bones["Leg_R"].head.xy=0
bpy.context.object.data.edit_bones["Foot_R"].head.xy=0
#tail
bpy.context.object.data.edit_bones["Face"].tail.xy=0
bpy.context.object.data.edit_bones["Neck"].tail.xy=0
bpy.context.object.data.edit_bones["Forearm_L"].tail.xy=0
bpy.context.object.data.edit_bones["Forearm_R"].tail.xy=0
bpy.context.object.data.edit_bones["Foot_L"].tail.xy=0
bpy.context.object.data.edit_bones["Foot_R"].tail.xy=0
bpy.context.object.data.edit_bones["Root"].length = root_size
bpy.context.object.data.edit_bones["Spine"].head.z = unit/2
bpy.context.object.data.edit_bones["Spine"].tail.z = spine_size
bpy.context.object.data.edit_bones["Neck"].tail.z = spine_size + neck_size
bpy.context.object.data.edit_bones["Neck"].tail.y = neck_size/3
bpy.context.object.data.edit_bones["Face"].tail.z = spine_size + neck_size
bpy.context.object.data.edit_bones["Face"].tail.y = face_size*-1
bpy.context.object.data.edit_bones["Arm_L"].head.z= spine_size
bpy.context.object.data.edit_bones["Arm_L"].head.x= unit*3/4
bpy.context.object.data.edit_bones["Forearm_L"].head.z= spine_size
bpy.context.object.data.edit_bones["Forearm_L"].head.x= unit + arm_size
bpy.context.object.data.edit_bones["Forearm_L"].tail.z= spine_size
bpy.context.object.data.edit_bones["Forearm_L"].tail.x= unit + arm_size + forearm_size
bpy.context.object.data.edit_bones["Arm_R"].head.z= spine_size
bpy.context.object.data.edit_bones["Arm_R"].head.x= (unit*3/4)*-1
bpy.context.object.data.edit_bones["Forearm_R"].head.z= spine_size
bpy.context.object.data.edit_bones["Forearm_R"].head.x= (unit + arm_size) *-1
bpy.context.object.data.edit_bones["Forearm_R"].tail.z= spine_size
bpy.context.object.data.edit_bones["Forearm_R"].tail.x= (unit + arm_size + forearm_size) *-1
bpy.context.object.data.edit_bones["Thigh_L"].head.x= unit*3/4
bpy.context.object.data.edit_bones["Thigh_L"].head.z= (unit/5)*-1
bpy.context.object.data.edit_bones["Leg_L"].head.x= unit*3/4
bpy.context.object.data.edit_bones["Leg_L"].head.z= (unit/5 + thigh_size)*-1
bpy.context.object.data.edit_bones["Foot_L"].head.x= unit*3/4
bpy.context.object.data.edit_bones["Foot_L"].head.z= (unit/5 + thigh_size + leg_size)*-1
bpy.context.object.data.edit_bones["Foot_L"].tail.x= unit*3/4
bpy.context.object.data.edit_bones["Foot_L"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1
bpy.context.object.data.edit_bones["Foot_L"].tail.y= foot_size/2*-1
bpy.context.object.data.edit_bones["Thigh_R"].head.x= unit*3/4*-1
bpy.context.object.data.edit_bones["Thigh_R"].head.z= (unit/5)*-1
bpy.context.object.data.edit_bones["Leg_R"].head.x= unit*3/4*-1
bpy.context.object.data.edit_bones["Leg_R"].head.z= (unit/5 + thigh_size)*-1
bpy.context.object.data.edit_bones["Foot_R"].head.x= unit*3/4*-1
bpy.context.object.data.edit_bones["Foot_R"].head.z= (unit/5 + thigh_size + leg_size)*-1
bpy.context.object.data.edit_bones["Foot_R"].tail.x= unit*3/4*-1
bpy.context.object.data.edit_bones["Foot_R"].tail.z= (unit/5 + thigh_size + leg_size + foot_size/2)*-1
bpy.context.object.data.edit_bones["Foot_R"].tail.y= foot_size/2*-1
bpy.ops.object.editmode_toggle()
def add_constraints(constraints, limit_rotation):
obs = []
for ob in bpy.context.scene.objects:
if ob.type == 'ARMATURE':
obs.append(ob)
#obs
bpy.ops.object.mode_set(mode='POSE')
for i in range(len(constraints)):
print('processar: ',constraints[i])
if constraints[i][1] == 'COPY_LOCATION' or constraints[i][1] == 'DAMPED_TRACK':
# print('in 1 j: ',j,' - name: ',constraints[i][0],' constraint: ',constraints[i][1])
obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[constraints[i][0]].bone
obs[len(obs)-1].pose.bones[constraints[i][0]].bone.select = True
#
bpy.ops.pose.constraint_add(type=constraints[i][1])
qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints)
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].target = bpy.data.objects[constraints[i][2]]
if constraints[i][1] == 'DAMPED_TRACK' and len(constraints[i])==4:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].track_axis = constraints[i][3]
#
if constraints[i][1] == 'LIMIT_ROTATION' and limit_rotation == True :
qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints)
if constraints[i][2] == 'LOCAL':
bpy.ops.pose.constraint_add(type=constraints[i][1])
qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints)
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].owner_space = constraints[i][2]
if constraints[i][2] == 'X':
if constraints[i][3] == True:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_x = constraints[i][3]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_x = constraints[i][4]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_x = constraints[i][5]
if constraints[i][2] == 'Y':
if constraints[i][3] == True:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_y = constraints[i][3]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_y = constraints[i][4]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_y = constraints[i][5]
if constraints[i][2] == 'Z':
if constraints[i][3] == True:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_z = constraints[i][3]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_z = constraints[i][4]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_z = constraints[i][5]
def add_constraints_track_X(constraints,limit_rotation):
obs = []
for ob in bpy.context.scene.objects:
if ob.type == 'ARMATURE':
obs.append(ob)
#obs
bpy.ops.object.mode_set(mode='POSE')
for i in range(len(constraints)):
print('processar: ',constraints[i])
if constraints[i][1] == 'COPY_LOCATION' or constraints[i][1] == 'DAMPED_TRACK':
# print('in 1 j: ',j,' - name: ',constraints[i][0],' constraint: ',constraints[i][1])
obs[len(obs)-1].data.bones.active = obs[len(obs)-1].pose.bones[constraints[i][0]].bone
obs[len(obs)-1].pose.bones[constraints[i][0]].bone.select = True
#
bpy.ops.pose.constraint_add(type=constraints[i][1])
qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints)
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].target = bpy.data.objects[constraints[i][2]]
if constraints[i][1] == 'DAMPED_TRACK' and len(constraints[i])>=4:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].track_axis = constraints[i][3]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].influence = constraints[i][4]
#
if constraints[i][1] == 'LIMIT_ROTATION' and limit_rotation == True:
qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints)
if constraints[i][2] == 'LOCAL':
bpy.ops.pose.constraint_add(type=constraints[i][1])
qtd_constraint = len(bpy.context.object.pose.bones[constraints[i][0]].constraints)
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].owner_space = constraints[i][2]
if constraints[i][2] == 'X':
if constraints[i][3] == True:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_x = constraints[i][3]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_x = constraints[i][4]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_x = constraints[i][5]
if constraints[i][2] == 'Y':
if constraints[i][3] == True:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_y = constraints[i][3]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_y = constraints[i][4]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_y = constraints[i][5]
if constraints[i][2] == 'Z':
if constraints[i][3] == True:
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].use_limit_z = constraints[i][3]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].min_z = constraints[i][4]
bpy.context.object.pose.bones[constraints[i][0]].constraints[qtd_constraint-1].max_z = constraints[i][5]
from builtins import object
from builtins import range
import os
import os.path
# import getopt
import sys
import xml.dom.minidom
import string
import re
import array
import bpy
#from bpy.props import BoolProperty, IntProperty, EnumProperty
import mathutils
#from bpy_extras.io_utils import ExportHelper
from os import remove
import time
#import math
import struct
# path = self.filepath
# context.scene.sk_value_prop.sk_smpl_path = os.path.dirname(self.filepath)
# context.scene.sk_value_prop.sk_smpl_path = self.filepath
"""
python cacheFileExample.py -f mayaCacheFile.xml
"""
def fileFormatError():
print("Error: unable to read cache format\n");
sys.exit(2)
def readTag(fd,tagFOR,blockTag):
count = 4
blockTag.append(fd.read(4))
# Padding
if tagFOR == "FOR8":
fd.read(4)
count = 8
return count
def readInt(fd,needSwap,tagFOR):
intArray = array.array('l')
size = 1
if tagFOR == "FOR8":
size = 2
intArray.fromfile(fd,size)
if needSwap:
intArray.byteswap()
return intArray[size - 1]
class CacheChannel(object):
m_channelName = ""
m_channelType = ""
m_channelInterp = ""
m_sampleType = ""
m_sampleRate = 0
m_startTime = 0
m_endTime = 0
def __init__(self,channelName,channelType,interpretation,samplingType,samplingRate,startTime,endTime):
self.m_channelName = channelName
self.m_channelType = channelType
self.m_channelInterp = interpretation
self.m_sampleType = samplingType
self.m_sampleRate = samplingRate
self.m_startTime = startTime
self.m_endTime = endTime
print("Channel Name =%s,type=%s,interp=%s,sampleType=%s,rate=%d,start=%d,end=%d\n"%(channelName, channelType, interpretation, samplingType, samplingRate, startTime, endTime))
class CacheFile(object):
m_baseFileName = ""
m_directory = ""
m_cacheType = ""
m_cacheStartTime = 0
m_cacheEndTime = 0
m_timePerFrame = 0
m_version = 0.0
m_channels = []
m_printChunkInfo = False
m_tagSize = 4
m_blockTypeSize = 4
m_glCount = 0
m_numFramesToPrint = 2
# m_numFramesToPrint = 135
#
########################################################################
# Description:
# Class constructor - tries to figure out full path to cache
# xml description file before calling parseDescriptionFile()
#
def __init__(self,fileName):
# fileName can be the full path to the .xml description file,
# or just the filename of the .xml file, with or without extension
# if it is in the current directory
dir = os.path.dirname(fileName)
fullPath = ""
if dir == "":
currDir = os.getcwd()
fullPath = os.path.join(currDir,fileName)
if not os.path.exists(fullPath):
fileName = fileName + '.xml';
fullPath = os.path.join(currDir,fileName)
if not os.path.exists(fullPath):
print("Sorry, can't find the file %s to be opened\n" % fullPath)
sys.exit(2)
else:
fullPath = fileName
#
self.m_baseFileName = os.path.basename(fileName).split('.')[0]
self.m_directory = os.path.dirname(fullPath)
self.parseDescriptionFile(fullPath)
########################################################################
# Description:
# Given the full path to the xml cache description file, this
# method parses its contents and sets the relevant member variables
#
def parseDescriptionFile(self,fullPath):
dom = xml.dom.minidom.parse(fullPath)
root = dom.getElementsByTagName("Autodesk_Cache_File")
allNodes = root[0].childNodes
for node in allNodes:
if node.nodeName == "cacheType":
self.m_cacheType = node.attributes.item(0).nodeValue
if node.nodeName == "time":
timeRange = node.attributes.item(0).nodeValue.split('-')
self.m_cacheStartTime = int(timeRange[0])
self.m_cacheEndTime = int(timeRange[1])
if node.nodeName == "cacheTimePerFrame":
self.m_timePerFrame = int(node.attributes.item(0).nodeValue)
if node.nodeName == "cacheVersion":
self.m_version = float(node.attributes.item(0).nodeValue)
if node.nodeName == "Channels":
self.parseChannels(node.childNodes)
########################################################################
# Description:
# helper method to extract channel information
#
def parseChannels(self,channels):
for channel in channels:
if re.compile("channel").match(channel.nodeName) != None :
channelName = ""
channelType = ""
channelInterp = ""
sampleType = ""
sampleRate = 0
startTime = 0
endTime = 0
for index in range(0,channel.attributes.length):
attrName = channel.attributes.item(index).nodeName
if attrName == "ChannelName":
channelName = channel.attributes.item(index).nodeValue
if attrName == "ChannelInterpretation":
channelInterp = channel.attributes.item(index).nodeValue
if attrName == "EndTime":
endTime = int(channel.attributes.item(index).nodeValue)
if attrName == "StartTime":
startTime = int(channel.attributes.item(index).nodeValue)
if attrName == "SamplingRate":
sampleRate = int(channel.attributes.item(index).nodeValue)
if attrName == "SamplingType":
sampleType = channel.attributes.item(index).nodeValue
if attrName == "ChannelType":
channelType = channel.attributes.item(index).nodeValue
channelObj = CacheChannel(channelName,channelType,channelInterp,sampleType,sampleRate,startTime,endTime)
self.m_channels.append(channelObj)
def printIntData( self, count, data, desc ):
if self.m_printChunkInfo:
print("%0.2d %d %s" % (count, data, desc ))
def printBlockSize( self, count, blockSize ):
if self.m_printChunkInfo:
print("%0.2d %d Bytes" % (count, blockSize))
def printTag( self, count, tag ):
if self.m_printChunkInfo:
print("%0.2d %s" % (count, tag))
def printString( self, text ):
if self.m_printChunkInfo:
print(text)
def printTime( self, count, time ):
if self.m_printChunkInfo:
print("%0.2d %d sec" % (count, time))
def readHeader( self, fd,needSwap,tagFOR ):
self.printString( "\nHEADER" )
#CACH
blockTag = fd.read(self.m_tagSize)
self.m_glCount += self.m_tagSize
self.printTag(self.m_glCount, blockTag)
#
#VRSN (version)
blockTagList = []
self.m_glCount += readTag(fd, tagFOR, blockTagList)
self.printTag( self.m_glCount, blockTagList[0] )
#
blockSize = readInt(fd,needSwap,tagFOR)
self.m_glCount += self.m_blockTypeSize
self.printBlockSize(self.m_glCount, blockSize)
#
version = fd.read(self.m_blockTypeSize)
self.m_glCount += self.m_blockTypeSize
self.printTag(self.m_glCount, version)
#
#STIM (start time)
blockTagList = []
self.m_glCount += readTag(fd, tagFOR, blockTagList)
self.printTag(self.m_glCount, blockTagList[0])
#
blockSize = readInt(fd,needSwap,tagFOR)
self.m_glCount += self.m_blockTypeSize
self.printBlockSize(self.m_glCount, blockSize)
#
startTime = readInt(fd,needSwap,tagFOR)
self.m_glCount += self.m_blockTypeSize
self.printTime( self.m_glCount, startTime )
#
#ETIM (end time)
blockTagList = []
self.m_tagSize = readTag(fd, tagFOR, blockTagList)
self.m_glCount += self.m_tagSize
self.printTag(self.m_glCount, blockTagList[0])
#
blockSize = readInt(fd,needSwap,tagFOR)
self.m_glCount += self.m_blockTypeSize
self.printBlockSize(self.m_glCount, blockSize)
#
endtime = readInt(fd,needSwap,tagFOR)
self.m_glCount += self.m_blockTypeSize
self.printTime( self.m_glCount, endtime )
def readData(self, fd, bytesRead, dataBlockSize, needSwap, tagFOR ):
# print "Data found at time %f seconds:\n"%(time/6000.0)
while bytesRead < dataBlockSize:
#
self.printString( "\nDATA" )
#
#channel name is next.
#the tag for this must be CHNM
blockTagList = []
bytesRead += readTag(fd, tagFOR, blockTagList)
self.m_glCount += bytesRead
self.printTag(self.m_glCount, blockTagList[0])
#
chnmTag = blockTagList[0]
if chnmTag != b"CHNM":
fileFormatError()
#
#Next comes a 32/64 bit that tells us how long the
#channel name is
chnmSize = readInt(fd,needSwap,tagFOR)
bytesRead += self.m_blockTypeSize
self.m_glCount += bytesRead
self.printBlockSize(self.m_glCount, chnmSize)
#
#The string is padded out to 32 bit boundaries,
#so we may need to read more than chnmSize
mask = 3
if tagFOR == b"FOR8":
mask = 7
chnmSizeToRead = (chnmSize + mask) & (~mask)
channelName = fd.read(chnmSize)
paddingSize = chnmSizeToRead-chnmSize
if paddingSize > 0:
fd.read(paddingSize)
bytesRead += chnmSizeToRead
self.m_glCount += bytesRead
self.printTag(self.m_glCount, channelName)
#
#Next is the SIZE field, which tells us the length
#of the data array
blockTagList = []
bytesRead += readTag(fd, tagFOR, blockTagList)