123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743 |
- import mathutils
- import bge
-
- def main():
-
- #"""
- #Modified BGE Gameplay Recorder Version 2
- #originally written by Nicholas Anderson, aka Red Frost Games.
- #"""
- from bge import logic
- import Record
- import SortData
- dict = logic.globalDict
- #####Tweakables###############
- #Watch out! These numbers might bite!
- frame_rate = 60 #Set this to the framerate of your game.
- optimization = 1 #An integer, must be at least 1! Higher value will make a smaller saved file size. I do not reccomend setting it to anything other than 1 though.
- recording_cutoff = dict['replay_record_length']
- #recording_cutoff = 7300 #3600 #Frames at which the oldest recorded frame will be deleted. 0 is no cutoff.
- recorder_state = 1 #This is the main state of the recorder object. State will be reverted to this value when the user breaks out of the playback.
- allow_playback_break = True #Allow the player to resume playing from the position in the recording.
- #####Sensor names#############
- record_sensor = "Record"
- save_recording_sensor = "Save"
- load_recording_sensor = "Load"
- track_left_sensor = "Left"
- track_right_sensor = "Right"
- break_sensor = "Break"
- ##############################
-
-
-
- cont = logic.getCurrentController()
- own = cont.owner
-
- cont.sensors[record_sensor].skippedTicks = optimization
-
-
- #dict['recorder_on'] = recorder_on
- recorder_on = dict.get('recorder_on')
- own['recorder_on'] = recorder_on
- #print("recorder on: ", recorder_on)
-
- if recorder_on == 1:
- #----
- scene = logic.getCurrentScene()
- scene_list = logic.getSceneList()
- camList = scene.cameras
- followcam = camList["followcam"]
- freecam = camList["freecam"]
- skater = scene.objects["Char4"]
- cube = scene.objects["control_cube.002"]
- deck = scene.objects["b_deck"]
- trucks = scene.objects["b_trucks"]
- replay_cam_axis = own['replay_cam_axis']
- cam = own.actuators['Camera']
- #----
- joybutsens = "joyBut"
- #butt = cont.sensors[joybutsens]
- #aXis = cont.sensors["joysticksens"]
- #bk_but = 4
- back_on = dict['bkBut']
- #a_but = 0
- a_on = dict['aBut']
- #b_but = 1
- b_on = dict['bBut']
- #print(a on)
- last_back = own['last_back_but']
-
- lLR = dict['lLR']
- lUD = dict['lUD']
- rLR = dict['rLR']
- rUD = dict['rUD']
- lTrig = dict['lTrig']
- rTrig = dict['rTrig']
- aBut = dict['aBut']
- bBut = dict['bBut']
- xBut = dict['xBut']
- yBut = dict['yBut']
- lBump = dict['lBump']
- rBump = dict['rBump']
- bkBut = dict['bkBut']
- stBut = dict['stBut']
- xbBut = dict['xbBut']
- ltsBut = dict['ltsBut']
- rtsBut = dict['rtsBut']
- ldPad = dict['ldPad']
- rdPad = dict['rdPad']
- udPad = dict['udPad']
- ddPad = dict['ddPad']
-
- try:
- pause_state = dict['npause']
- last_pause = dict['last_npause']
- except:
- dict['npause'] = 0
- dict['last_npause'] = 0
- pause_state = 0
- last_pause = 0
-
- if own["playback"] != True:
- Record.main(recording_cutoff, cube)
-
- #if cont.sensors[save_recording_sensor].positive:
- #SortData.writeData.saveAll()
-
- #if cont.sensors[load_recording_sensor].positive or (cube["sel"] == 1 and cube["last_sel"] == 0):
- if own['back_state'] == 1 and back_on == 1 and last_back == 0:
- cube["last_sel"] == 1
- SortData.writeData.saveAll()
- own["playback"] = True
- own["playbackBroken"] = False
- freecam.worldPosition = own.worldPosition
- followcam.worldPosition = own.worldPosition
- cube['grindcement_vol'] = 0
- cube['grindcement_pitch'] = 0
- cube['grindrail_vol'] = 0
- cube['grindrail_pitch'] = 0
- cube['sroll_vol'] = 0
- cube['sroll_pitch'] = 0
-
-
- if own["playback"]:
- Record.loadData()
- #..................
- # if cont.sensors[track_left_sensor].positive:
- # own["objIndex"] -= 2
- # logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
-
- # if cont.sensors[track_right_sensor].positive:
- # own["objIndex"] += 2
- # logic.setLogicTicRate(frame_rate*own["playbackSpeed"])
-
- if own["playback"] == True:
- #print("objIndex = ", own["lengthPos"], own['objIndex'])
-
- if rTrig > .01 and rTrig < .02:
- own["objIndex"] += 2
- logic.setLogicTicRate(frame_rate*.5)
- if (rTrig >= .02 and rTrig < .06) or own['loop_play'] == 1:
- own["objIndex"] += 2
- logic.setLogicTicRate(frame_rate*1)
- #print(own['objIndex'])
- if rTrig >= .06 and rTrig < .09:
- own["objIndex"] += 2
- logic.setLogicTicRate(frame_rate*1.5)
- if lTrig > .01 and lTrig < .02:
- own["objIndex"] -= 2
- logic.setLogicTicRate(frame_rate*.5)
- if lTrig >= .02 and lTrig < .06:
- own["objIndex"] -= 2
- logic.setLogicTicRate(frame_rate*1)
- if lTrig >= .06 and lTrig < .09:
- if own['loop_play'] == 1:
- own["objIndex"] -= 6
- #logic.setLogicTicRate(frame_rate*1.5)
- else:
- own["objIndex"] -= 2
- logic.setLogicTicRate(frame_rate*1.5)
- if b_on == True and pause_state == 0:
- #print("bbut_on")
- own['objIndex'] = 0
- own['valueIndex'] = 0
- logic.setLogicTicRate(frame_rate*1)
-
- #....................
- if allow_playback_break:
-
- if own['back_state'] == 0 and back_on == 1 and last_back == 0:
- own["playbackBroken"] = True
- own["playback"] = False
-
- elif own["playbackBroken"] and back_on == 0:
- Record.breakOut()
-
- logic.setLogicTicRate(frame_rate)
- #set value index
- own.state = recorder_state
- own["playbackBroken"] = False
- skater.stopAction(9999)
- deck.stopAction(9999)
- trucks.stopAction(9999)
- cont.activate(own.actuators['replayCam'])
- #print("unbreak")
- own['loop_play'] = 0
-
- #print("valueIndex = ", own['valueIndex'])
- if back_on == 1 and own['back_but'] == 0:
- #print("change back state")
- if own['back_state'] == True:
- own['back_state'] = False
- #elif own['back_state'] == False:
- else:
- own['back_state'] = True
- ###
- if own['last_playback'] != own['playback']:
- if own['last_playback'] == True:
- cont.activate(own.actuators['remove_hud'])
- cont.activate(own.actuators['add_stance'])
- own['camnum'] = 0
- cam = camList["Camera.003"]
- scene.active_camera = cam
- #print("turning replay off", own['playback'])
-
-
- if own['last_playback'] == False:
- #print("turning replay on", own['playback'])
- cont.activate(own.actuators['add_hud'])
- cont.activate(own.actuators['remove_stance'])
- own['objIndex'] = 0
- own['valueIndex'] = 3
- logic.setLogicTicRate(frame_rate*1)
-
-
-
-
- if dict['rtsBut'] == False and dict['last_rtsBut'] == True and own['playback'] == True:
-
- if 'pause' in scene_list:
- #cont.activate(own.actuators['remove_overlay'])
- cont.activate(own.actuators['add_hud'])
- else:
- #cont.activate(own.actuators['add_overlay']) #pause
- cont.activate(own.actuators['remove_hud']) #replay
- cont.activate(own.actuators['pause_replay_remove'])
-
- if pause_state == 1 and last_pause == 1 and own["playback"]:
- #print('pause_on')
- if 'pause_replay' not in scene_list:
- cont.activate(own.actuators['pause_replay_add'])
- #print('pause_on')
-
- if pause_state != 1 and own["playback"]:
- if 'pause_replay' in scene_list:
- cont.activate(own.actuators['pause_replay_remove'])
- if own['playback'] and 'pause' in scene_list:
- cont.activate(cube.actuators['remove_overlay'])
-
- ####
- if a_on == 1 and own['a_but'] == False and pause_state == 0:
- if own['loop_play'] == 1:
- own['loop_play'] = 0
- else:
- own['loop_play'] = 1
- if rLR > .05 and own["playback"]:
- act = cont.actuators["replayCam"]
- if rLR > .07:
- act.dLoc = [ .06, 0.0, 0.0]
- else:
- act.dLoc = [ .03, 0.0, 0.0]
- #cont.deactivate(own.actuators['Camera'])
- cont.activate(own.actuators['replayCam'])
- #print("move")
- elif rLR < -.05 and own["playback"]:
- act = cont.actuators["replayCam"]
- if rLR < -.07:
- act.dLoc = [ -.06, 0.0, 0.0]
- else:
- act.dLoc = [ -.03, 0.0, 0.0]
- #cont.deactivate(own.actuators['Camera'])
- #act.damping = 6
- cont.activate(own.actuators['replayCam'])
- #print("move")
- else:
- #pass
- cont.deactivate(own.actuators['replayCam'])
- #cont.activate(own.actuators['Camera'])
- #print("back state: ", own['back_state'], "last_back_but: ", own['last_back_but'], "back_but :", own['back_but'])
- #integer
- #
- #0 = +X axis
- #
- #1 = +Y axis
- #
- #2 = +Z axis
- #
- #3 = -X axis
- #
- #4 = -Y axis
- #
- #5 = -Z axis
- # if rLR > .05 and own["playback"]:
- # if own['last_rtsBut'] == True and rtsBut == False:
- # if replay_cam_axis == 0:
- # replay_cam_axis = 1
- # elif replay_cam_axis == 1:
- # replay_cam_axis = 3
- # elif replay_cam_axis == 3 :
- # replay_cam_axis = 4
- # elif replay_cam_axis == 4:
- # replay_cam_axis = 0
- # cam.axis = replay_cam_axis
- # cont.activate(cam)
- # print("set replay_cam_axis: ", replay_cam_axis)
- # own['replay_cam_axis'] = replay_cam_axis
- if own['last_ltsBut'] == True and ltsBut == False and own['playback']:
- # get camera named SecurityCam
- if own['camnum'] == 1:
- own['camnum'] = 2
- elif own['camnum'] == 0:
- own['camnum'] = 1
- elif own['camnum'] == 2:
- own['camnum'] = 0
- if own['last_rtsBut'] == True and rtsBut == False and own['playback']:
- # get camera named SecurityCam
- if "replay_HUD" in scene_list:
- cont.activate(own.actuators['remove_hud'])
- else:
- cont.activate(own.actuators['add_hud'])
- if own['camnum'] == 1 and own['playback']:
-
- scene.active_camera = followcam
- #################
- camspeed1 = .04 #.015
- camspeed2 = .1 #.055
- camrot1 = .02 #.005
- camrot2 = .04 #.02
- # perc = (lUD * 100 * (10 / 80)) *2
- # perc = round(perc,2)
- # print(perc)
- # perc = .025 * perc
- # newUD = (lUD * .1) * 5
- # if lUD > .0005 or lUD < -.0005:
- # camspeed1 = abs(perc)
- # camspeed2 = abs(perc)
- #up
- if lUD < -0.080:
- followcam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
- cont.activate(followcam.actuators["up"])
- print("fastup")
- else:
- cont.deactivate(followcam.actuators["up"])
- # #down
- if lUD > .080:
- followcam.actuators["down"].dLoc = [ 0, 0, camspeed2]
- cont.activate(followcam.actuators["down"])
- else:
- cont.deactivate(followcam.actuators["down"])
- # #left
- if lLR < -0.080:
- followcam.actuators["left"].dLoc = [-camspeed2, 0, 0]
- cont.activate(followcam.actuators["left"])
- else:
- cont.deactivate(followcam.actuators["left"])
- # #right
- if lLR > 0.080:
- followcam.actuators["right"].dLoc = [camspeed2, 0, 0]
- cont.activate(followcam.actuators["right"])
- else:
- cont.deactivate(followcam.actuators["right"])
- #up
- if rUD < -0.080:
- followcam.actuators["rotup"].dLoc = [0, 0, camrot2]
- cont.activate(followcam.actuators["rotup"])
- #print("uppppppppppppppppppppppppppp")
- else:
- cont.deactivate(followcam.actuators["rotup"])
- # #down
- if rUD > .080:
- followcam.actuators["rotdown"].dLoc = [0, 0, -camrot2]
- cont.activate(followcam.actuators["rotdown"])
- else:
- cont.deactivate(followcam.actuators["rotdown"])
- # #left
- if rLR < -0.080:
- followcam.actuators["rotleft"].dRot = [0, 0, camrot2]
- cont.activate(followcam.actuators["rotleft"])
- else:
- cont.deactivate(followcam.actuators["rotleft"])
- # #right
- if rLR > 0.080:
- followcam.actuators["rotright"].dRot = [0, 0, -camrot2]
- cont.activate(followcam.actuators["rotright"])
- else:
- cont.deactivate(followcam.actuators["rotright"])
-
- #*********************************************
-
- if lUD > -0.080 and lUD < -0.030:
- followcam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
- cont.activate(followcam.actuators["up"])
- #print(lUD)
- else:
- cont.deactivate(followcam.actuators["up"])
- # #down
- if lUD < .080 and lUD > .03:
- followcam.actuators["down"].dLoc = [ 0, 0, camspeed1]
- cont.activate(followcam.actuators["down"])
- else:
- cont.deactivate(followcam.actuators["down"])
- # #left
- if lLR > -0.080 and lLR < -0.030:
- followcam.actuators["left"].dLoc = [-camspeed1, 0, 0]
- cont.activate(followcam.actuators["left"])
- else:
- cont.deactivate(followcam.actuators["left"])
- # #right
- if lLR < .080 and lLR > .03:
- followcam.actuators["right"].dLoc = [camspeed1, 0, 0]
- cont.activate(followcam.actuators["right"])
- else:
- cont.deactivate(followcam.actuators["right"])
- #up
- if rUD > -0.080 and rUD < -0.030:
- followcam.actuators["rotup"].dRot = [camrot1, 0, 0]
- cont.activate(followcam.actuators["rotup"])
- else:
- cont.deactivate(followcam.actuators["rotup"])
- # #down
- if rUD < .080 and rUD > .03:
- followcam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
- cont.activate(followcam.actuators["rotdown"])
- else:
- cont.deactivate(followcam.actuators["rotdown"])
- # #left
- if rLR > -0.080 and rLR < -0.030:
- followcam.actuators["rotleft"].dRot = [0, 0, camrot1]
- cont.activate(followcam.actuators["rotleft"])
- else:
- cont.deactivate(followcam.actuators["rotleft"])
- # #right
- if rLR < .080 and rLR > .03:
- followcam.actuators["rotright"].dRot = [0, 0, -camrot1]
- cont.activate(followcam.actuators["rotright"])
- else:
- cont.deactivate(followcam.actuators["rotright"])
-
- #################
-
- if own['camnum'] == 2 and own['playback']:
-
- scene.active_camera = freecam
-
- #act = freecam.actuators[
- camspeed1 = .015
- camspeed2 = .055
- camrot1 = .005
- camrot2 = .02
- #up
- if lUD < -0.080:
- freecam.actuators["up"].dLoc = [ 0, 0, -camspeed2]
- cont.activate(freecam.actuators["up"])
- #print("fastup")
- else:
- cont.deactivate(freecam.actuators["up"])
- # #down
- if lUD > .080:
- freecam.actuators["down"].dLoc = [ 0, 0, camspeed2]
- cont.activate(freecam.actuators["down"])
- else:
- cont.deactivate(freecam.actuators["down"])
- # #left
- if lLR < -0.080:
- freecam.actuators["left"].dLoc = [-camspeed2, 0, 0]
- cont.activate(freecam.actuators["left"])
- else:
- cont.deactivate(freecam.actuators["left"])
- # #right
- if lLR > 0.080:
- freecam.actuators["right"].dLoc = [camspeed2, 0, 0]
- cont.activate(freecam.actuators["right"])
- else:
- cont.deactivate(freecam.actuators["right"])
- #up
- if rUD < -0.080:
- freecam.actuators["rotup"].dRot = [camrot2, 0, 0]
- cont.activate(freecam.actuators["rotup"])
- else:
- cont.deactivate(freecam.actuators["rotup"])
- # #down
- if rUD > .080:
- freecam.actuators["rotdown"].dRot = [-camrot2, 0, 0]
- cont.activate(freecam.actuators["rotdown"])
- else:
- cont.deactivate(freecam.actuators["rotdown"])
- # #left
- if rLR < -0.080:
- freecam.actuators["rotleft"].dRot = [0, 0, camrot2]
- cont.activate(freecam.actuators["rotleft"])
- else:
- cont.deactivate(freecam.actuators["rotleft"])
- # #right
- if rLR > 0.080:
- freecam.actuators["rotright"].dRot = [0, 0, -camrot2]
- cont.activate(freecam.actuators["rotright"])
- else:
- cont.deactivate(freecam.actuators["rotright"])
-
- #*********************************************
-
- if lUD > -0.080 and lUD < -0.030:
- freecam.actuators["up"].dLoc = [ 0, 0, -camspeed1]
- cont.activate(freecam.actuators["up"])
- #print(lUD)
- else:
- cont.deactivate(freecam.actuators["up"])
- # #down
- if lUD < .080 and lUD > .03:
- freecam.actuators["down"].dLoc = [ 0, 0, camspeed1]
- cont.activate(freecam.actuators["down"])
- else:
- cont.deactivate(freecam.actuators["down"])
- # #left
- if lLR > -0.080 and lLR < -0.030:
- freecam.actuators["left"].dLoc = [-camspeed1, 0, 0]
- cont.activate(freecam.actuators["left"])
- else:
- cont.deactivate(freecam.actuators["left"])
- # #right
- if lLR < .080 and lLR > .03:
- freecam.actuators["right"].dLoc = [camspeed1, 0, 0]
- cont.activate(freecam.actuators["right"])
- else:
- cont.deactivate(freecam.actuators["right"])
- #up
- if rUD > -0.080 and rUD < -0.030:
- freecam.actuators["rotup"].dRot = [camrot1, 0, 0]
- cont.activate(freecam.actuators["rotup"])
- else:
- cont.deactivate(freecam.actuators["rotup"])
- # #down
- if rUD < .080 and rUD > .03:
- freecam.actuators["rotdown"].dRot = [-camrot1, 0, 0]
- cont.activate(freecam.actuators["rotdown"])
- else:
- cont.deactivate(freecam.actuators["rotdown"])
- # #left
- if rLR > -0.080 and rLR < -0.030:
- freecam.actuators["rotleft"].dRot = [0, 0, camrot1]
- cont.activate(freecam.actuators["rotleft"])
- else:
- cont.deactivate(freecam.actuators["rotleft"])
- # #right
- if rLR < .080 and rLR > .03:
- freecam.actuators["rotright"].dRot = [0, 0, -camrot1]
- cont.activate(freecam.actuators["rotright"])
- else:
- cont.deactivate(freecam.actuators["rotright"])
-
-
-
-
-
-
-
-
- #print('doing the keyframe stuff')
-
- anim_length = dict['replay_record_length']
-
- def clock(freecam, inc):
- pass
-
- def transLength(freecam, keyframes, id, kl):
- if id != 0:
- num = keyframes[id] - keyframes[(id-1)]
- else:
- tn = anim_length - keyframes[kl]
- num = tn + keyframes[0]
- freecam['last_position'] = kl
- return num
-
- def getProgress(freecam):
- if freecam['cur_key'] != freecam['last_key']:
- print('new key!')
- freecam['pg'] = 0
- else:
-
- num = own['objIndex'] - own['last_objIndex']
-
- #print(num)
- #freecam['clock'] += num
- #print(num)
- if num > 4:
- num = 2
- if num < -4:
- num = -2
- #print('-------************num is biiig')
-
- freecam['pg'] += num
- freecam['last_key'] = freecam['cur_key']
-
- def draw_keys(keyframes, dict):
- scene_list = bge.logic.getSceneList()
- if 'replay_HUD' in scene_list:
- hud = scene_list['replay_HUD']
- ph = hud.objects['Circle']
- for x in hud.objects:
- if 'keyframe' in x:
- x.endObject()
- for y in keyframes:
- place = (y / round((dict['replay_record_length']), 4) * 1000)
- print('action frame', place)
- added = hud.addObject('kf', ph)
- added.scaling = [1.25,1,1]
- added.playAction("replay_playhead", place, place, layer=1, play_mode=1, speed=0)
- else:
- print('no hud scene')
-
- keyframes = dict['rp_keyframes']
- positions = dict['rp_positions']
- orientations = dict['rp_orientations']
-
- if 'inited' not in freecam:
- freecam['inited'] = True
- freecam['clock'] = 0
- freecam['cur_key'] = 0
- freecam['last_key'] = -1
- freecam['cur_length'] = 0
- freecam['pg'] = 0
- freecam['last_position'] = 0
- freecam['playback'] = True
-
- if len(positions) > 1:
- kl = len(keyframes) - 1
- freecam['cur_length'] = transLength(freecam, keyframes, freecam['cur_key'], kl)
- getProgress(freecam)
- skip = False
- if own["objIndex"] > keyframes[kl]:
- skip = True
- #skip = False
- #print('skipping')
- if freecam['cur_key'] != 0:
- if keyframes[(freecam['cur_key'] - 1)] > own['objIndex']:
- freecam['cur_key'] -= 1
- freecam['last_position'] -= 1
- if freecam['last_position'] == -1:
- freecam['last_position'] = keyframes.len() - 1
- print('backwards')
- if keyframes[freecam['cur_key']] > own["objIndex"]:
-
- pass
- else:
- if skip == False:
- try:
- freecam['last_position'] = freecam['cur_key']
- freecam['cur_key'] += 1
- temp = keyframes[freecam['cur_key']]
- if freecam['cur_key'] != 0:
- freecam['pg'] = 0
- print('setting pg to 0')
-
- except:
- print('excepting')
- freecam['cur_key'] = 0
- freecam['last_position'] = kl
- freecam['pg'] = 0
-
- time = abs(round(freecam['pg'] / freecam['cur_length'], 6) )
-
-
-
- if own['objIndex'] != own['last_objIndex']:
- freecam.worldPosition = (positions[freecam['last_position']].lerp(positions[freecam['cur_key']], time))
- freecam.worldOrientation = (orientations[freecam['last_position']].lerp(orientations[freecam['cur_key']], time))
- #print(positions)
- #print(positions[freecam['last_position']], positions[freecam['cur_key']])
- #print('cur_key', freecam['cur_key'], freecam['last_position'], 'time: ', own["objIndex"], freecam['cur_length'], freecam['pg'], time)
- else:
- pass
- #print('not enough keys')
-
- if dict['xBut'] == 1 and dict['last_xBut'] == 0:
- print('chekcing for keyframe on', own['objIndex'])
- if len(keyframes) > 1:
- close = min(keyframes, key=lambda x:abs(x-own['objIndex']))
- keys_away = abs(close - own['objIndex'])
- else:
- close = None
- keys_away = 100000
-
- print('--', close, keys_away)
- if keys_away < 60:
- print('index already exists')
- ind = keyframes.index(close)
- positions.pop(ind)
- orientations.pop(ind)
- keyframes.pop(ind)
- dict['rp_keyframes'] = keyframes
- dict['rp_positions'] = positions
- dict['rp_orientations'] = orientations
- if freecam['cur_key'] != 0:
- freecam['cur_key'] -= 1
- else:
- freecam['cur_key'] = len(keyframes) -1
- draw_keys(keyframes, dict)
-
-
- else:
- keyframes.append(own['objIndex'])
- positions.append(freecam.worldPosition.copy())
- orientations.append(freecam.worldOrientation.copy())
- tk = keyframes
- z = [x for _,x in sorted(zip(keyframes, positions))]
- v = [y for _,y in sorted(zip(tk, orientations))]
- positions = z
- orientations = v
- keyframes.sort()
- print('added keyframe on', own['objIndex'])
- dict['rp_keyframes'] = keyframes
- if own['objIndex'] in positions:
- freecam['cur_key'] = positions.index(own['objIndex'])
- # freecam['cur_length'] = freecam['cur_key']
- # try:
- # freecam['last_position'] = positions.index(own['objIndex']) -1
- # except:
- # freecam['last_position'] = len(positions) - 1
-
-
- dict['rp_keyframes'] = keyframes
- dict['rp_positions'] = positions
- dict['rp_orientations'] = orientations
- draw_keys(keyframes, dict)
- #print('lp', dict['temp_list'])
-
-
- ########################################
- if own['camnum'] == 0:
- cam = camList["Camera.003"]
- scene.active_camera = cam
- dict['rp_keyframes'] = []
- dict['rp_positions'] = []
- dict['rp_orientations'] = []
- freecam['cur_key'] = 0
- if dict['npause'] == False:
- freecam.worldOrientation = cam.worldOrientation
- valueIndex = own['valueIndex']
- n = (valueIndex / recording_cutoff) * 1000
- n = int(round(n))
- #n = 10
- #print("n: ", n, "--", valueIndex, recording_cutoff)
- #dict = logic.globalDict #Get the global dictionary
- dict['playhead'] = n
-
- own['last_back_but'] = own['back_but']
- own['back_but'] = back_on
- own['last_a_but'] = own['a_but']
- own['a_but'] = a_on
- own['last_ltsBut'] = ltsBut
- own['last_rtsBut'] = rtsBut
- own['last_playback'] = own['playback']
- own['last_objIndex'] = own['objIndex']
- dict['playback'] = own['playback']
|