|
@@ -1,4 +1,5 @@
|
1
|
1
|
import mathutils
|
|
2
|
+import bge
|
2
|
3
|
|
3
|
4
|
def main():
|
4
|
5
|
|
|
@@ -564,58 +565,153 @@ def main():
|
564
|
565
|
print('new key!')
|
565
|
566
|
freecam['pg'] = 0
|
566
|
567
|
else:
|
567
|
|
- freecam['pg'] += 1
|
568
|
|
- freecam['last_key'] = freecam['cur_key']
|
569
|
|
-
|
570
|
|
-
|
|
568
|
+
|
|
569
|
+ num = own['objIndex'] - own['last_objIndex']
|
|
570
|
+
|
|
571
|
+ #print(num)
|
|
572
|
+ #freecam['clock'] += num
|
|
573
|
+ #print(num)
|
|
574
|
+ if num > 4:
|
|
575
|
+ num = 2
|
|
576
|
+ if num < -4:
|
|
577
|
+ num = -2
|
|
578
|
+ #print('-------************num is biiig')
|
|
579
|
+
|
|
580
|
+ freecam['pg'] += num
|
|
581
|
+ freecam['last_key'] = freecam['cur_key']
|
|
582
|
+
|
|
583
|
+ def draw_keys(keyframes, dict):
|
|
584
|
+ scene_list = bge.logic.getSceneList()
|
|
585
|
+ if 'replay_HUD' in scene_list:
|
|
586
|
+ hud = scene_list['replay_HUD']
|
|
587
|
+ ph = hud.objects['Circle']
|
|
588
|
+ for x in hud.objects:
|
|
589
|
+ if 'keyframe' in x:
|
|
590
|
+ x.endObject()
|
|
591
|
+ for y in keyframes:
|
|
592
|
+ place = (y / round((dict['replay_record_length']), 4) * 1000)
|
|
593
|
+ print('action frame', place)
|
|
594
|
+ added = hud.addObject('kf', ph)
|
|
595
|
+ added.scaling = [1.25,1,1]
|
|
596
|
+ added.playAction("replay_playhead", place, place, layer=1, play_mode=1, speed=0)
|
|
597
|
+ else:
|
|
598
|
+ print('no hud scene')
|
571
|
599
|
|
572
|
|
- keyframes = [190, 480,1050, 1800, 2500, 4000, 6000, 7000]
|
573
|
|
- positions = [mathutils.Vector([0,0,-1]), mathutils.Vector([-3,.5,-1]), mathutils.Vector([-4,1,-1]), mathutils.Vector([-5,2,-1]), mathutils.Vector([-5,-2,-1]), mathutils.Vector([-2,-2,-1]), mathutils.Vector([2,-2,-1]), mathutils.Vector([5,-3,-1])]
|
574
|
|
- kl = len(keyframes) - 1
|
|
600
|
+ keyframes = dict['rp_keyframes']
|
|
601
|
+ positions = dict['rp_positions']
|
|
602
|
+ orientations = dict['rp_orientations']
|
575
|
603
|
|
576
|
604
|
if 'inited' not in freecam:
|
577
|
605
|
freecam['inited'] = True
|
578
|
606
|
freecam['clock'] = 0
|
579
|
607
|
freecam['cur_key'] = 0
|
580
|
|
- freecam['last_key'] = kl
|
|
608
|
+ freecam['last_key'] = -1
|
581
|
609
|
freecam['cur_length'] = 0
|
582
|
610
|
freecam['pg'] = 0
|
583
|
611
|
freecam['last_position'] = 0
|
584
|
612
|
freecam['playback'] = True
|
585
|
613
|
|
586
|
|
- #clock(freecam)
|
587
|
|
-
|
588
|
|
- freecam['cur_length'] = transLength(freecam, keyframes, freecam['cur_key'], kl)
|
589
|
|
- getProgress(freecam)
|
590
|
|
- skip = False
|
591
|
|
- if own["objIndex"] > keyframes[kl]:
|
592
|
|
- skip = True
|
593
|
|
- if keyframes[freecam['cur_key']] > own["objIndex"]:
|
594
|
|
- pass
|
595
|
|
- else:
|
596
|
|
- if skip == False:
|
597
|
|
- try:
|
598
|
|
- freecam['last_position'] = freecam['cur_key']
|
599
|
|
- freecam['cur_key'] += 1
|
600
|
|
- temp = keyframes[freecam['cur_key']]
|
601
|
|
- freecam['pg'] = 0
|
602
|
|
-
|
603
|
|
- except:
|
604
|
|
- print('excepting')
|
605
|
|
- freecam['cur_key'] = 0
|
606
|
|
- freecam['last_position'] = kl
|
607
|
|
- freecam['pg'] = 0
|
608
|
|
-
|
609
|
|
- time = round(freecam['pg'] / freecam['cur_length'], 4) * 2
|
610
|
|
-
|
611
|
|
- #if own['playback'] == True:
|
612
|
|
- freecam.worldPosition = (positions[freecam['last_position']].lerp(positions[freecam['cur_key']], time))
|
613
|
|
-
|
|
614
|
+ if len(positions) > 1:
|
|
615
|
+ kl = len(keyframes) - 1
|
|
616
|
+ freecam['cur_length'] = transLength(freecam, keyframes, freecam['cur_key'], kl)
|
|
617
|
+ getProgress(freecam)
|
|
618
|
+ skip = False
|
|
619
|
+ if own["objIndex"] > keyframes[kl]:
|
|
620
|
+ skip = True
|
|
621
|
+ #skip = False
|
|
622
|
+ #print('skipping')
|
|
623
|
+ if freecam['cur_key'] != 0:
|
|
624
|
+ if keyframes[(freecam['cur_key'] - 1)] > own['objIndex']:
|
|
625
|
+ freecam['cur_key'] -= 1
|
|
626
|
+ freecam['last_position'] -= 1
|
|
627
|
+ if freecam['last_position'] == -1:
|
|
628
|
+ freecam['last_position'] = keyframes.len() - 1
|
|
629
|
+ print('backwards')
|
|
630
|
+ if keyframes[freecam['cur_key']] > own["objIndex"]:
|
|
631
|
+
|
|
632
|
+ pass
|
|
633
|
+ else:
|
|
634
|
+ if skip == False:
|
|
635
|
+ try:
|
|
636
|
+ freecam['last_position'] = freecam['cur_key']
|
|
637
|
+ freecam['cur_key'] += 1
|
|
638
|
+ temp = keyframes[freecam['cur_key']]
|
|
639
|
+ if freecam['cur_key'] != 0:
|
|
640
|
+ freecam['pg'] = 0
|
|
641
|
+ print('setting pg to 0')
|
|
642
|
+
|
|
643
|
+ except:
|
|
644
|
+ print('excepting')
|
|
645
|
+ freecam['cur_key'] = 0
|
|
646
|
+ freecam['last_position'] = kl
|
|
647
|
+ freecam['pg'] = 0
|
|
648
|
+
|
|
649
|
+ time = abs(round(freecam['pg'] / freecam['cur_length'], 6) )
|
614
|
650
|
|
615
|
|
- print('cur_key', freecam['cur_key'], freecam['last_position'], 'time: ', own["objIndex"], freecam['cur_length'], freecam['pg'], time)
|
616
|
|
-
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+ if own['objIndex'] != own['last_objIndex']:
|
|
654
|
+ freecam.worldPosition = (positions[freecam['last_position']].lerp(positions[freecam['cur_key']], time))
|
|
655
|
+ freecam.worldOrientation = (orientations[freecam['last_position']].lerp(orientations[freecam['cur_key']], time))
|
|
656
|
+ #print(positions)
|
|
657
|
+ #print(positions[freecam['last_position']], positions[freecam['cur_key']])
|
|
658
|
+ #print('cur_key', freecam['cur_key'], freecam['last_position'], 'time: ', own["objIndex"], freecam['cur_length'], freecam['pg'], time)
|
|
659
|
+ else:
|
|
660
|
+ pass
|
|
661
|
+ #print('not enough keys')
|
617
|
662
|
|
|
663
|
+ if dict['xBut'] == 1 and dict['last_xBut'] == 0:
|
|
664
|
+ print('chekcing for keyframe on', own['objIndex'])
|
|
665
|
+ if len(keyframes) > 1:
|
|
666
|
+ close = min(keyframes, key=lambda x:abs(x-own['objIndex']))
|
|
667
|
+ keys_away = abs(close - own['objIndex'])
|
|
668
|
+ else:
|
|
669
|
+ close = None
|
|
670
|
+ keys_away = 100000
|
|
671
|
+
|
|
672
|
+ print('--', close, keys_away)
|
|
673
|
+ if keys_away < 60:
|
|
674
|
+ print('index already exists')
|
|
675
|
+ ind = keyframes.index(close)
|
|
676
|
+ positions.pop(ind)
|
|
677
|
+ orientations.pop(ind)
|
|
678
|
+ keyframes.pop(ind)
|
|
679
|
+ dict['rp_keyframes'] = keyframes
|
|
680
|
+ dict['rp_positions'] = positions
|
|
681
|
+ dict['rp_orientations'] = orientations
|
|
682
|
+ if freecam['cur_key'] != 0:
|
|
683
|
+ freecam['cur_key'] -= 1
|
|
684
|
+ else:
|
|
685
|
+ freecam['cur_key'] = len(keyframes) -1
|
|
686
|
+ draw_keys(keyframes, dict)
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+ else:
|
|
690
|
+ keyframes.append(own['objIndex'])
|
|
691
|
+ positions.append(freecam.worldPosition.copy())
|
|
692
|
+ orientations.append(freecam.worldOrientation.copy())
|
|
693
|
+ tk = keyframes
|
|
694
|
+ z = [x for _,x in sorted(zip(keyframes, positions))]
|
|
695
|
+ v = [y for _,y in sorted(zip(tk, orientations))]
|
|
696
|
+ positions = z
|
|
697
|
+ orientations = v
|
|
698
|
+ keyframes.sort()
|
|
699
|
+ print('added keyframe on', own['objIndex'])
|
|
700
|
+ dict['rp_keyframes'] = keyframes
|
|
701
|
+ if own['objIndex'] in positions:
|
|
702
|
+ freecam['cur_key'] = positions.index(own['objIndex'])
|
|
703
|
+ # freecam['cur_length'] = freecam['cur_key']
|
|
704
|
+ # try:
|
|
705
|
+ # freecam['last_position'] = positions.index(own['objIndex']) -1
|
|
706
|
+ # except:
|
|
707
|
+ # freecam['last_position'] = len(positions) - 1
|
|
708
|
+
|
618
|
709
|
|
|
710
|
+ dict['rp_keyframes'] = keyframes
|
|
711
|
+ dict['rp_positions'] = positions
|
|
712
|
+ dict['rp_orientations'] = orientations
|
|
713
|
+ draw_keys(keyframes, dict)
|
|
714
|
+ #print('lp', dict['temp_list'])
|
619
|
715
|
|
620
|
716
|
|
621
|
717
|
|
|
@@ -638,7 +734,12 @@ def main():
|
638
|
734
|
########################################
|
639
|
735
|
if own['camnum'] == 0:
|
640
|
736
|
cam = camList["Camera.003"]
|
641
|
|
- scene.active_camera = cam
|
|
737
|
+ scene.active_camera = cam
|
|
738
|
+ dict['rp_keyframes'] = []
|
|
739
|
+ dict['rp_positions'] = []
|
|
740
|
+ dict['rp_orientations'] = []
|
|
741
|
+ freecam['cur_key'] = 0
|
|
742
|
+ freecam.worldOrientation = cam.worldOrientation
|
642
|
743
|
valueIndex = own['valueIndex']
|
643
|
744
|
n = (valueIndex / recording_cutoff) * 1000
|
644
|
745
|
n = int(round(n))
|
|
@@ -654,4 +755,5 @@ def main():
|
654
|
755
|
own['last_ltsBut'] = ltsBut
|
655
|
756
|
own['last_rtsBut'] = rtsBut
|
656
|
757
|
own['last_playback'] = own['playback']
|
|
758
|
+ own['last_objIndex'] = own['objIndex']
|
657
|
759
|
dict['playback'] = own['playback']
|