Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

boneRecord.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import bge
  2. from mathutils import Vector
  3. dict = bge.logic.globalDict
  4. dict['replay_record_length']
  5. bone_list = ["foot.ik.R", "foot.ik.L", "knee.pt.ik.R", "knee.pt.ik.L", "hips", "root", "spine", "spine-1", "chest", "chest-1", "clavicle.L", "clavicle.R", "deltoid.L", "deltoid.R", "upper_arm.fk.L", "upper_arm.fk.R", "forearm.fk.L", "forearm.fk.R", "hand.fk.L", "hand.fk.R", "neck", "head", "master",
  6. 'foot.rev.R', 'foot.rev.L', 'shin.ik.R', 'shin.ik.L', 'toe.rev.R', 'toe.rev.L']
  7. deck_list = ['main', 'turn']
  8. #bone_list = ['root', 'head']
  9. def Record():
  10. #print('bone recording')
  11. scene = bge.logic.getCurrentScene()
  12. #own = cont.owner
  13. master = scene.objects['control_cube.002']
  14. cam = scene.objects['Camera.003']
  15. armature = scene.objects['Char4']
  16. deck = scene.objects['deck_arm']
  17. if 'dataList' not in master:
  18. for x in bone_list:
  19. master['dataList'] = True
  20. master[str(x) + '-pos'] = []
  21. master[str(x) + '-rot'] = []
  22. for x in deck_list:
  23. master['dataList'] = True
  24. master[str(x) + '-pos'] = []
  25. master[str(x) + '-rot'] = []
  26. for y in bone_list:
  27. x = armature.channels[y]
  28. pos = x.location
  29. if x.rotation_mode == 0:
  30. rot = x.rotation_quaternion
  31. else:
  32. rot = Vector(x.channel_matrix.to_euler())
  33. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  34. master[str(y) + '-pos'].pop(0)
  35. master[str(y) + '-rot'].pop(0)
  36. master[str(y) + '-pos'].pop(0)
  37. master[str(y) + '-rot'].pop(0)
  38. master[str(y) + '-pos'].append(pos)
  39. master[str(y) + '-rot'].append(rot)
  40. master[str(y) + '-pos'].append(pos)
  41. master[str(y) + '-rot'].append(rot)
  42. # pl = master['foot.ik.R-pos'][len(master['foot.ik.R-pos']) - 1]
  43. # if dict['player_class'].obj['ragdoll_active']:
  44. # rdfp = armature.worldPosition - scene.objects['npc_ed_arm_phys_foot.ik.R'].worldPosition
  45. # print('rd foot pos', rdfp)
  46. # #print(dict['player_class'].obj['ragdoll_active'], 'is ragdolling')
  47. # else:
  48. # print('foot pos', pl)
  49. #print(len(master['foot.ik.R-pos']), 'br length---')
  50. for y in deck_list:
  51. x = deck.channels[y]
  52. pos = x.location
  53. rot = x.rotation_quaternion
  54. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  55. master[str(y) + '-pos'].pop(0)
  56. master[str(y) + '-rot'].pop(0)
  57. master[str(y) + '-pos'].pop(0)
  58. master[str(y) + '-rot'].pop(0)
  59. master[str(y) + '-pos'].append(pos)
  60. master[str(y) + '-rot'].append(rot)
  61. master[str(y) + '-pos'].append(pos)
  62. master[str(y) + '-rot'].append(rot)
  63. def Playback(valueIndex):
  64. scene = bge.logic.getCurrentScene()
  65. #own = cont.owner
  66. master = scene.objects['control_cube.002']
  67. #cam = scene.objects['Camera.003']
  68. armature = scene.objects['Char4']
  69. deck = scene.objects['deck_arm']
  70. for y in bone_list:
  71. x = armature.channels[y]
  72. pl = master[str(y) + '-pos']
  73. rl = master[str(y) + '-rot']
  74. try:
  75. if x.rotation_mode == 0:
  76. x.rotation_quaternion = rl[valueIndex]
  77. else:
  78. x.rotation_euler = rl[valueIndex]
  79. x.location = pl[valueIndex]
  80. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex)
  81. except:
  82. print('index out of range')
  83. for z in deck_list:
  84. x = deck.channels[z]
  85. pl = master[str(z) + '-pos']
  86. rl = master[str(z) + '-rot']
  87. try:
  88. x.rotation_quaternion = rl[valueIndex]
  89. x.location = pl[valueIndex]
  90. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex, x.name)
  91. except:
  92. print('index out of range')
  93. if armature.isPlayingAction(0):
  94. armature.stopAction(0)
  95. if armature.isPlayingAction(1):
  96. armature.stopAction(1)
  97. if armature.isPlayingAction(2):
  98. armature.stopAction(2)
  99. if armature.isPlayingAction(3):
  100. armature.stopAction(3)
  101. if armature.isPlayingAction(4):
  102. armature.stopAction(4)
  103. if armature.isPlayingAction(5):
  104. armature.stopAction(5)
  105. if armature.isPlayingAction(6):
  106. armature.stopAction(6)
  107. armature.update()
  108. deck.update()