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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. deck_list = ['main', 'turn']
  7. #bone_list = ['root', 'head']
  8. def Record():
  9. scene = bge.logic.getCurrentScene()
  10. #own = cont.owner
  11. master = scene.objects['control_cube.002']
  12. cam = scene.objects['Camera.003']
  13. armature = scene.objects['Char4']
  14. deck = scene.objects['deck_arm']
  15. #print('bone recording')
  16. if 'dataList' not in master:
  17. for x in bone_list:
  18. master['dataList'] = True
  19. master[str(x) + '-pos'] = []
  20. master[str(x) + '-rot'] = []
  21. for x in deck_list:
  22. master['dataList'] = True
  23. master[str(x) + '-pos'] = []
  24. master[str(x) + '-rot'] = []
  25. for y in bone_list:
  26. x = armature.channels[y]
  27. pos = x.location
  28. if x.rotation_mode == 0:
  29. rot = x.rotation_quaternion
  30. else:
  31. rot = Vector(x.channel_matrix.to_euler())
  32. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  33. master[str(y) + '-pos'].pop(0)
  34. master[str(y) + '-rot'].pop(0)
  35. master[str(y) + '-pos'].pop(0)
  36. master[str(y) + '-rot'].pop(0)
  37. master[str(y) + '-pos'].append(pos)
  38. master[str(y) + '-rot'].append(rot)
  39. master[str(y) + '-pos'].append(pos)
  40. master[str(y) + '-rot'].append(rot)
  41. for y in deck_list:
  42. x = deck.channels[y]
  43. pos = x.location
  44. rot = x.rotation_quaternion
  45. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  46. master[str(y) + '-pos'].pop(0)
  47. master[str(y) + '-rot'].pop(0)
  48. master[str(y) + '-pos'].pop(0)
  49. master[str(y) + '-rot'].pop(0)
  50. master[str(y) + '-pos'].append(pos)
  51. master[str(y) + '-rot'].append(rot)
  52. master[str(y) + '-pos'].append(pos)
  53. master[str(y) + '-rot'].append(rot)
  54. def Playback(valueIndex):
  55. scene = bge.logic.getCurrentScene()
  56. #own = cont.owner
  57. master = scene.objects['control_cube.002']
  58. #cam = scene.objects['Camera.003']
  59. armature = scene.objects['Char4']
  60. deck = scene.objects['deck_arm']
  61. for y in bone_list:
  62. x = armature.channels[y]
  63. pl = master[str(y) + '-pos']
  64. rl = master[str(y) + '-rot']
  65. try:
  66. if x.rotation_mode == 0:
  67. x.rotation_quaternion = rl[valueIndex]
  68. else:
  69. x.rotation_euler = rl[valueIndex]
  70. x.location = pl[valueIndex]
  71. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex)
  72. except:
  73. print('index out of range')
  74. for z in deck_list:
  75. x = deck.channels[z]
  76. pl = master[str(z) + '-pos']
  77. rl = master[str(z) + '-rot']
  78. try:
  79. x.rotation_quaternion = rl[valueIndex]
  80. x.location = pl[valueIndex]
  81. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex, x.name)
  82. except:
  83. print('index out of range')
  84. if armature.isPlayingAction(0):
  85. armature.stopAction(0)
  86. if armature.isPlayingAction(1):
  87. armature.stopAction(1)
  88. if armature.isPlayingAction(2):
  89. armature.stopAction(2)
  90. if armature.isPlayingAction(3):
  91. armature.stopAction(3)
  92. if armature.isPlayingAction(4):
  93. armature.stopAction(4)
  94. if armature.isPlayingAction(5):
  95. armature.stopAction(5)
  96. if armature.isPlayingAction(6):
  97. armature.stopAction(6)
  98. armature.update()
  99. deck.update()