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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. for y in deck_list:
  43. x = deck.channels[y]
  44. pos = x.location
  45. rot = x.rotation_quaternion
  46. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  47. master[str(y) + '-pos'].pop(0)
  48. master[str(y) + '-rot'].pop(0)
  49. master[str(y) + '-pos'].pop(0)
  50. master[str(y) + '-rot'].pop(0)
  51. master[str(y) + '-pos'].append(pos)
  52. master[str(y) + '-rot'].append(rot)
  53. master[str(y) + '-pos'].append(pos)
  54. master[str(y) + '-rot'].append(rot)
  55. def Playback(valueIndex):
  56. scene = bge.logic.getCurrentScene()
  57. #own = cont.owner
  58. master = scene.objects['control_cube.002']
  59. #cam = scene.objects['Camera.003']
  60. armature = scene.objects['Char4']
  61. deck = scene.objects['deck_arm']
  62. for y in bone_list:
  63. x = armature.channels[y]
  64. pl = master[str(y) + '-pos']
  65. rl = master[str(y) + '-rot']
  66. try:
  67. if x.rotation_mode == 0:
  68. x.rotation_quaternion = rl[valueIndex]
  69. else:
  70. x.rotation_euler = rl[valueIndex]
  71. x.location = pl[valueIndex]
  72. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex)
  73. except:
  74. print('index out of range')
  75. for z in deck_list:
  76. x = deck.channels[z]
  77. pl = master[str(z) + '-pos']
  78. rl = master[str(z) + '-rot']
  79. try:
  80. x.rotation_quaternion = rl[valueIndex]
  81. x.location = pl[valueIndex]
  82. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex, x.name)
  83. except:
  84. print('index out of range')
  85. if armature.isPlayingAction(0):
  86. armature.stopAction(0)
  87. if armature.isPlayingAction(1):
  88. armature.stopAction(1)
  89. if armature.isPlayingAction(2):
  90. armature.stopAction(2)
  91. if armature.isPlayingAction(3):
  92. armature.stopAction(3)
  93. if armature.isPlayingAction(4):
  94. armature.stopAction(4)
  95. if armature.isPlayingAction(5):
  96. armature.stopAction(5)
  97. if armature.isPlayingAction(6):
  98. armature.stopAction(6)
  99. armature.update()
  100. deck.update()