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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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", "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. def Record():
  7. scene = bge.logic.getCurrentScene()
  8. #own = cont.owner
  9. master = scene.objects['control_cube.002']
  10. cam = scene.objects['Camera.003']
  11. armature = scene.objects['Char4']
  12. if 'dataList' not in master:
  13. for x in bone_list:
  14. master['dataList'] = True
  15. master[str(x) + '-pos'] = []
  16. master[str(x) + '-rot'] = []
  17. for y in bone_list:
  18. x = armature.channels[y]
  19. #print('bone_name: ', x)
  20. #pos = (x.pose_head)+master.worldPosition
  21. pos = (x.pose_head)
  22. rot = Vector(x.channel_matrix.to_euler())
  23. #rot = x.rotation_euler
  24. if len(master[str(y) + '-pos']) > dict['replay_record_length']:
  25. master[str(y) + '-pos'].pop(0)
  26. master[str(y) + '-rot'].pop(0)
  27. master[str(y) + '-pos'].append(pos)
  28. master[str(y) + '-rot'].append(rot)
  29. def Playback(valueIndex):
  30. scene = bge.logic.getCurrentScene()
  31. #own = cont.owner
  32. master = scene.objects['control_cube.002']
  33. cam = scene.objects['Camera.003']
  34. armature = scene.objects['Char4']
  35. #armature.removeParent()
  36. #print(master['foot.ik.R-pos'], 'fooot rot')
  37. for y in bone_list:
  38. x = armature.channels[y]
  39. #x.location = [1,0,1]
  40. pl = master[str(y) + '-pos']
  41. rl = master[str(y) + '-rot']
  42. #print(valueIndex)
  43. #print(rl)
  44. #print(pl)
  45. #x.rotation_euler = rl[20]
  46. try:
  47. x.rotation_mode = 1
  48. x.location = pl[valueIndex]
  49. x.rotation_euler = rl[valueIndex]
  50. #x.rotation_euler = [1,1,1]
  51. print(x.rotation_mode, 'mode')
  52. except:
  53. print('index out of range')
  54. armature.update()
  55. #print('trying')