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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. if 'dataList' not in master:
  16. for x in bone_list:
  17. master['dataList'] = True
  18. master[str(x) + '-pos'] = []
  19. master[str(x) + '-rot'] = []
  20. for x in deck_list:
  21. master['dataList'] = True
  22. master[str(x) + '-pos'] = []
  23. master[str(x) + '-rot'] = []
  24. for y in bone_list:
  25. x = armature.channels[y]
  26. pos = x.location
  27. if x.rotation_mode == 0:
  28. rot = x.rotation_quaternion
  29. else:
  30. rot = Vector(x.channel_matrix.to_euler())
  31. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  32. master[str(y) + '-pos'].pop(0)
  33. master[str(y) + '-rot'].pop(0)
  34. master[str(y) + '-pos'].pop(0)
  35. master[str(y) + '-rot'].pop(0)
  36. master[str(y) + '-pos'].append(pos)
  37. master[str(y) + '-rot'].append(rot)
  38. master[str(y) + '-pos'].append(pos)
  39. master[str(y) + '-rot'].append(rot)
  40. for y in deck_list:
  41. x = deck.channels[y]
  42. pos = x.location
  43. rot = x.rotation_quaternion
  44. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  45. master[str(y) + '-pos'].pop(0)
  46. master[str(y) + '-rot'].pop(0)
  47. master[str(y) + '-pos'].pop(0)
  48. master[str(y) + '-rot'].pop(0)
  49. master[str(y) + '-pos'].append(pos)
  50. master[str(y) + '-rot'].append(rot)
  51. master[str(y) + '-pos'].append(pos)
  52. master[str(y) + '-rot'].append(rot)
  53. def Playback(valueIndex):
  54. scene = bge.logic.getCurrentScene()
  55. #own = cont.owner
  56. master = scene.objects['control_cube.002']
  57. cam = scene.objects['Camera.003']
  58. armature = scene.objects['Char4']
  59. deck = scene.objects['deck_arm']
  60. for y in bone_list:
  61. x = armature.channels[y]
  62. pl = master[str(y) + '-pos']
  63. rl = master[str(y) + '-rot']
  64. try:
  65. if x.rotation_mode == 0:
  66. x.rotation_quaternion = rl[valueIndex]
  67. else:
  68. x.rotation_euler = rl[valueIndex]
  69. x.location = pl[valueIndex]
  70. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex)
  71. except:
  72. print('index out of range')
  73. for z in deck_list:
  74. x = deck.channels[z]
  75. pl = master[str(z) + '-pos']
  76. rl = master[str(z) + '-rot']
  77. try:
  78. x.rotation_quaternion = rl[valueIndex]
  79. x.location = pl[valueIndex]
  80. #print(x.rotation_mode, pl[valueIndex], 'mode', valueIndex, x.name)
  81. except:
  82. print('index out of range')
  83. armature.update()
  84. deck.update()