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.

aiRecord.py 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. #record
  2. from bge import logic
  3. from mathutils import Vector
  4. from aiSortData import *
  5. import math
  6. cont = logic.getCurrentController()
  7. own = cont.owner
  8. scene = logic.getCurrentScene()
  9. cube = cont.owner
  10. #obj = scene.objects["control_cube.002"]
  11. #sound_empty = scene.objects['replay_sound_empty']
  12. #path = logic.expandPath(own["filePath"])
  13. dict = logic.globalDict
  14. PAF = 0
  15. DAF = 0
  16. npc_index = own['npc_index']
  17. #print(dict['spawned_npc_decks'], npc_index, 'spawned deck list')
  18. deck = dict['spawned_npc_decks'][npc_index]
  19. trucks = dict['spawned_npc_trucks'][npc_index]
  20. #deck = scene.objects[deck]
  21. #print(own.children)
  22. #deck = own.children['npc_ed_deck']
  23. #trucks = own.children["npc_ed_trucks"]
  24. #throw_deck_empty = scene.objects["throw_deck_empty"]
  25. #wheel1 = trucks.children["npc_ed_rollen.000"]
  26. #wheel2 = trucks.children["npc_ed_rollen.001"]
  27. #wheel3 = trucks.children["npc_ed_rollen.002"]
  28. #wheel4 = trucks.children["npc_ed_rollen.003"]
  29. #try:
  30. # throw_deck = scene.objects['throw_deck']
  31. #except:
  32. # throw_deck = None
  33. #deckact = deck.actuators["Visibility"]
  34. #trucksact = trucks.actuators["Visibility"]
  35. #wheel1act = wheel1.actuators["Visibility"]
  36. #wheel2act = wheel2.actuators["Visibility"]
  37. #wheel3act = wheel3.actuators["Visibility"]
  38. #wheel4act = wheel4.actuators["Visibility"]
  39. class getData:
  40. def savePosition(obj, cut):
  41. position = [Vector(obj.worldPosition)[0],
  42. Vector(obj.worldPosition)[1],
  43. Vector(obj.worldPosition)[2]]
  44. position = str(position).strip("[]")
  45. position = position.replace(", ",",")
  46. writeData.addPosition(obj, position, cut)
  47. def saveOrientation(obj, cut):
  48. orientation = [Vector(obj.localOrientation.to_euler())[0],
  49. Vector(obj.localOrientation.to_euler())[1],
  50. Vector(obj.localOrientation.to_euler())[2]]
  51. orientation = str(orientation).strip("[]")
  52. orientation = orientation.replace(", ",",")
  53. writeData.addOrientation(obj, orientation, cut)
  54. def loadData(cont, own):
  55. npc_index = own['npc_index']
  56. #print(dict['spawned_npc_decks'], npc_index, 'spawned deck list')
  57. deck = dict['spawned_npc_decks'][npc_index]
  58. trucks = dict['spawned_npc_trucks'][npc_index]
  59. skater = dict['spawned_npcs'][npc_index]
  60. cube = own
  61. #Function for loading the data from
  62. #the disk and setting it.
  63. #print('load_data', own)
  64. objIndex = own["objIndex"]
  65. #print(own['objIndex'], 'objindex')
  66. own["valueIndex"] = objIndex + 1
  67. valueIndex = own["valueIndex"]
  68. playbackSpeed = own["playbackSpeed"]
  69. loadedPosition = own["loadedPosition"]
  70. loadedOrientation = own["loadedOrientation"]
  71. # print(loadedPosition)
  72. # loadedScale = own["loadedScale"]
  73. # loadedColor = own["loadedColor"]
  74. # loadedVisibility = own["loadedVisibility"]
  75. loadedSkaterAnim = own["loadedSkaterAnim"]
  76. loadedSkaterAnimf = own["loadedSkaterAnimF"]
  77. loadedDeckAnim = own["loadedDeckAnim"]
  78. loadedDeckAnimf = own["loadedDeckAnimF"]
  79. # loadedSrollVol = own["loadedSrollVol"]
  80. # loadedSrollPitch = own["loadedSrollPitch"]
  81. # loadedSgrind_cementlVol = own["loadedSgrind_cementVol"]
  82. # loadedSgrind_cementPitch = own["loadedSgrind_cementPitch"]
  83. # loadedSgrind_railVol = own["loadedSgrind_railVol"]
  84. # loadedSgrind_railPitch = own["loadedSgrind_railPitch"]
  85. # loadedSpopsound = own["loadedSpopsound"]
  86. # loadedSlandsound = own["loadedSlandsound"]
  87. # loadedSdeckvis = own["loadedSdeckvis"]
  88. # loadedtdPosition = own["loadedtdPosition"]
  89. # loadedtdOrientation = own["loadedtdOrientation"]
  90. # loadedSrevertsound = own["loadedSrevertsound"]
  91. #skater = own.children["npc_ed_arm"]
  92. #deck = own.children["deck"]
  93. #trucks = own.children["trucks"]
  94. num = 1
  95. obj = own
  96. readData.loadAll(own) #Load the file!!!
  97. #-----Position-----#
  98. own["lengthPos"] = readData.getLengthPos(own)
  99. lengthPos = own["lengthPos"]
  100. positionList = own['positionList']
  101. if lengthPos:
  102. if objIndex > lengthPos-1:
  103. own["objIndex"] = 0
  104. if objIndex < 0:
  105. own["objIndex"] = lengthPos-2
  106. name, position = readData.returnPosition(objIndex, valueIndex, own)
  107. name2, orientation = readData.returnOrientation(objIndex, valueIndex, own)
  108. try:
  109. if own['rpStartLoc_set'] == False:
  110. own['rpStartLoc'] = position
  111. print('setting npc_start_pos', position)
  112. own['npc_playback'] = False
  113. own['move'] = True
  114. tracker = scene.addObject('npc_tracker', own, 0)
  115. own['target_object_name'] = tracker
  116. tracker.worldPosition = position
  117. oXYZ = own.localOrientation.to_euler()
  118. oXYZ[0] = float(orientation[0])
  119. oXYZ[1] = float(orientation[1])
  120. oXYZ[2] = float(orientation[2])
  121. tracker.localOrientation = oXYZ.to_matrix()
  122. rot = [ 0.0, 0.0, -1.570796327]
  123. #tracker.applyRotation(rot,True)
  124. rotz = math.degrees(oXYZ[2])
  125. rotz -= 90
  126. if rotz < -180:
  127. rotz = rotz + 360
  128. own['rpStartZ'] = rotz
  129. else:
  130. cube.worldPosition = position
  131. deck.worldPosition = position
  132. trucks.worldPosition = position
  133. except:
  134. print('npc positioning not working')
  135. #pass
  136. #-----Orientation-----#
  137. own["lengthOri"] = readData.getLengthOri(own)
  138. lengthOri = own["lengthOri"]
  139. valueIndex = own['valueIndex']
  140. #print(valueIndex, objIndex, 'value Index')
  141. #if lengthPos:
  142. if lengthOri:
  143. if valueIndex > lengthOri-1:
  144. own["valueIndex"] = 0
  145. if objIndex < 0:
  146. own["objIndex"] = lengthOri-2
  147. name, orientation = readData.returnOrientation(objIndex, valueIndex, own)
  148. oXYZ = own.localOrientation.to_euler()
  149. oXYZ[0] = float(orientation[0])
  150. oXYZ[1] = float(orientation[1])
  151. oXYZ[2] = float(orientation[2])
  152. try:
  153. if own['rpStartLoc_set'] == True:
  154. own.localOrientation = oXYZ.to_matrix()
  155. deck.localOrientation = oXYZ.to_matrix()
  156. trucks.localOrientation = oXYZ.to_matrix()
  157. rot = [ 0.0, 0.0, -1.570796327]
  158. own.applyRotation(rot,True)
  159. else:
  160. own['rpStartLoc_set'] = True
  161. except:
  162. print('npc orientation not working')
  163. # #-----Scale-----#
  164. # own["lengthSca"] = readData.getLengthSca()
  165. # lengthSca = own["lengthSca"]
  166. #
  167. # if lengthSca:
  168. #
  169. # if valueIndex > lengthSca-1:
  170. # own["valueIndex"] = 0
  171. # if objIndex < 0:
  172. # own["objIndex"] = lengthSca-2
  173. #
  174. # name, scale = readData.returnScale(objIndex, valueIndex)
  175. #
  176. # if name in scene.objects:
  177. # try:
  178. # scene.objects[name].localScale = scale
  179. # except:
  180. # pass
  181. # #-----Color-----#
  182. # own["lengthCol"] = readData.getLengthCol()
  183. # lengthCol = own["lengthCol"]
  184. #
  185. # if lengthCol:
  186. # if valueIndex > lengthCol-1:
  187. # own["valueIndex"] = 0
  188. # if objIndex < 0:
  189. # own["objIndex"] = lengthCol-2
  190. # name, color = readData.returnColor(objIndex, valueIndex)
  191. #
  192. # if name in scene.objects:
  193. # try:
  194. # scene.objects[name].color = color
  195. # except:
  196. # pass
  197. # #-----Visibility-----#
  198. # own["lengthVis"] = readData.getLengthVis()
  199. # lengthVis = own["lengthVis"]
  200. #
  201. # if lengthVis:
  202. # if valueIndex > lengthVis-1:
  203. # own["valueIndex"] = 0
  204. # if objIndex < 0:
  205. # own["objIndex"] = lengthVis-2
  206. # name, visible = readData.returnVisibility(objIndex, valueIndex)
  207. #
  208. # if name in scene.objects:
  209. # try:
  210. # scene.objects[name].visible = int(visible)
  211. # except:
  212. # pass
  213. #-----Skater Animation Name-----#
  214. own["lengthSkaterAnim"] = readData.getLengthSkaterAnim(own)
  215. lengthSkaterAnim = own["lengthSkaterAnim"]
  216. #print("lengthskateranim", lengthSkaterAnim)
  217. if lengthSkaterAnim:
  218. if valueIndex > lengthSkaterAnim-1:
  219. own["valueIndex"] = 0
  220. if objIndex < 0:
  221. own["objIndex"] = lengthSkaterAnim-2
  222. name, skateranim = readData.returnSkaterAnim(objIndex, valueIndex, own)
  223. name, PAF = readData.returnSkaterAnimF(objIndex, valueIndex, own)
  224. PAF = round(float(PAF), 1)
  225. #print(valueIndex, skateranim, PAF, 'sa')
  226. PAF = float(PAF)
  227. if skater in own.children:
  228. #print("name in")
  229. try:
  230. skater.stopAction(0)
  231. skater.stopAction(1)
  232. skater.stopAction(2)
  233. skater.stopAction(3)
  234. skater.stopAction(9999)
  235. if skater != '' and skateranim != 'control_cube.002':
  236. skater.playAction(skateranim, PAF,PAF, layer=2, play_mode=1, speed=1)
  237. #print("Playing: ", skater, skateranim, PAF)
  238. except:
  239. print("something is wrong")
  240. #-----Deck Animation Name-----#
  241. own["lengthDeckAnim"] = readData.getLengthDeckAnim(own)
  242. lengthDeckAnim = own["lengthDeckAnim"]
  243. #print("lengthDeckanim", lengthDeckAnim)
  244. if lengthDeckAnim:
  245. if valueIndex > lengthDeckAnim-1:
  246. own["valueIndex"] = 0
  247. if objIndex < 0:
  248. own["objIndex"] = lengthDeckAnim-2
  249. name, deckanim = readData.returnDeckAnim(objIndex, valueIndex, own)
  250. name, DAF = readData.returnDeckAnimF(objIndex, valueIndex, own)
  251. name = 'npc_ed_deck'
  252. DAF = float(DAF)
  253. if deck in own.children:
  254. #print("name in")
  255. try:
  256. if deck != '' and deckanim != 'control_cube.002':
  257. deck.playAction(deckanim, DAF,DAF, layer=2, play_mode=1, speed=1)
  258. trucks.playAction(deckanim, DAF,DAF, layer=2, play_mode=1, speed=1)
  259. #print("Playing: ", deckanim, PAF)
  260. #print("Playing: ", deck, deckanim, DAF)
  261. except:
  262. print("deck something is wrong")
  263. #pass
  264. ##
  265. # #-----sroll-----#
  266. # own["lengthSrollVol"] = readData.getLengthSrollVol()
  267. # lengthSrollVol = own["lengthSrollVol"]
  268. # if lengthSrollVol:
  269. # if valueIndex > lengthSrollVol-1:
  270. # own["valueIndex"] = 0
  271. # if objIndex < 0:
  272. # own["objIndex"] = lengthSrollVol-2
  273. # name, srollVol = readData.returnSrollVol(objIndex, valueIndex)
  274. # name, srollPitch = readData.returnSrollPitch(objIndex, valueIndex)
  275. # if name in scene.objects:
  276. # try:
  277. # cube = scene.objects["control_cube.002"]
  278. # srollVol = round(srollVol, 2)
  279. # act = cube.actuators["sroll"]
  280. # if srollVol < .12:
  281. # act.volume = srollVol
  282. # act.pitch = srollPitch
  283. # act.startSound()
  284. # except:
  285. # pass
  286. ####
  287. ##
  288. # #-----grind cement-----#
  289. # own["lengthSgrind_cementVol"] = readData.getLengthSgrind_cementVol()
  290. # lengthSgrind_cementVol = own["lengthSgrind_cementVol"]
  291. # if lengthSgrind_cementVol:
  292. # if valueIndex > lengthSgrind_cementVol-1:
  293. # own["valueIndex"] = 0
  294. # if objIndex < 0:
  295. # own["objIndex"] = lengthSgrind_cementVol-2
  296. # name, sgrind_cementVol = readData.returnSgrind_cementVol(objIndex, valueIndex)
  297. # name, sgrind_cementPitch = readData.returnSgrind_cementPitch(objIndex, valueIndex)
  298. # if name in scene.objects:
  299. # try:
  300. # cube = scene.objects["control_cube.002"]
  301. # sgrind_cementVol = round(sgrind_cementVol, 2)
  302. # act = cube.actuators["grind_cement"]
  303. # if sgrind_cementVol < .2:
  304. # act.volume = sgrind_cementVol
  305. # act.pitch = sgrind_cementPitch
  306. # act.startSound()
  307. #
  308. # except:
  309. # pass
  310. ####
  311. ##
  312. # #-----grind rail-----#
  313. # own["lengthSgrind_railVol"] = readData.getLengthSgrind_railVol()
  314. # lengthSgrind_railVol = own["lengthSgrind_railVol"]
  315. # if lengthSgrind_railVol:
  316. # if valueIndex > lengthSgrind_railVol-1:
  317. # own["valueIndex"] = 0
  318. # if objIndex < 0:
  319. # own["objIndex"] = lengthSgrind_railVol-2
  320. # name, sgrind_railVol = readData.returnSgrind_railVol(objIndex, valueIndex)
  321. # name, sgrind_railPitch = readData.returnSgrind_railPitch(objIndex, valueIndex)
  322. # if name in scene.objects:
  323. # try:
  324. # cube = scene.objects["control_cube.002"]
  325. # sgrind_railVol = round(sgrind_railVol, 2)
  326. # act = cube.actuators["grind_rail"]
  327. # if sgrind_railVol < .2:
  328. # act.volume = sgrind_railVol
  329. # act.pitch = sgrind_railPitch
  330. # act.startSound()
  331. # #print("grindsound = ", sgrind_railVol, sgrind_railPitch)
  332. # except:
  333. # pass
  334. ####
  335. ##
  336. # #-----pop sound-----#
  337. # own["lengthSpopsound"] = readData.getLengthSpopsound()
  338. # lengthSpopsound = own["lengthSpopsound"]
  339. # if lengthSpopsound:
  340. # if valueIndex > lengthSpopsound-1:
  341. # own["valueIndex"] = 0
  342. # if objIndex < 0:
  343. # own["objIndex"] = lengthSpopsound-2
  344. # name, spopsound = readData.returnSpopsound(objIndex, valueIndex)
  345. # if name in scene.objects:
  346. # #act = sound_empty.actuators["pop"]
  347. # try:
  348. # #cube = scene.objects[sound_empty]
  349. # spopsound = round(spopsound, 2)
  350. # act = cube.actuators["pop"]
  351. # #act = sound_empty.actuators["pop"]
  352. # if spopsound == 1:
  353. # #act.volume_maximum = .7
  354. # #act.is3D = True
  355. # #act.distance_reference = 10.0
  356. # #act.distance_maximum = 50.0
  357. # act.volume = .6
  358. # act.startSound()
  359. # #print("grindsound = ", spopsound, sgrind_railPitch)
  360. # except:
  361. # print("sound passed")
  362. # pass
  363. ####
  364. ##
  365. # #-----land sound-----#
  366. # own["lengthSlandsound"] = readData.getLengthSlandsound()
  367. # lengthSlandsound = own["lengthSlandsound"]
  368. # if lengthSlandsound:
  369. # if valueIndex > lengthSlandsound-1:
  370. # own["valueIndex"] = 0
  371. # if objIndex < 0:
  372. # own["objIndex"] = lengthSlandsound-2
  373. # name, slandsound = readData.returnSlandsound(objIndex, valueIndex)
  374. # if name in scene.objects:
  375. # try:
  376. # cube = scene.objects["control_cube.002"]
  377. # slandsound = round(slandsound, 2)
  378. # act = cube.actuators["land"]
  379. # if slandsound == 1:
  380. # act.volume = .6
  381. # act.startSound()
  382. # #print("grindsound = ", slandsound, sgrind_railPitch)
  383. # except:
  384. # pass
  385. ####
  386. ####
  387. ##
  388. # #-----land sound-----#
  389. # own["lengthSdeckvis"] = readData.getLengthSdeckvis()
  390. # lengthSdeckvis = own["lengthSdeckvis"]
  391. # if lengthSdeckvis:
  392. # if valueIndex > lengthSdeckvis-1:
  393. # own["valueIndex"] = 0
  394. # if objIndex < 0:
  395. # own["objIndex"] = lengthSdeckvis-2
  396. # name, sdeckvis = readData.returnSdeckvis(objIndex, valueIndex)
  397. #
  398. #
  399. # if name in scene.objects:
  400. # try:
  401. # cube = scene.objects["control_cube.002"]
  402. # if sdeckvis == 1:
  403. # #print('setting deck visible')
  404. # deckact.visibility = True
  405. # trucksact.visibility = True
  406. # wheel1act.visibility = True
  407. # wheel2act.visibility = True
  408. # wheel3act.visibility = True
  409. # wheel4act.visibility = True
  410. # cont.activate(deck.actuators['Visibility'])
  411. # cont.activate(trucks.actuators['Visibility'])
  412. # cont.activate(wheel1.actuators['Visibility'])
  413. # cont.activate(wheel2.actuators['Visibility'])
  414. # cont.activate(wheel3.actuators['Visibility'])
  415. # cont.activate(wheel4.actuators['Visibility'])
  416. # for n in scene.objects:
  417. # if 'throw_deck' in n.name and 'empty' not in n.name:
  418. # n.endObject()
  419. ## if 'throw_deck' in scene.objects:
  420. # #print('ending td', n)
  421. # cont.activate(throw_deck.actuators['end_throw_deck'])
  422. #
  423. # #throwdeck.visibility = False
  424. # else:
  425. # #print('setting deck invisible')
  426. # deckact.visibility = False
  427. # trucksact.visibility = False
  428. # wheel1act.visibility = False
  429. # wheel2act.visibility = False
  430. # wheel3act.visibility = False
  431. # wheel4act.visibility = False
  432. # cont.activate(deck.actuators['Visibility'])
  433. # cont.activate(trucks.actuators['Visibility'])
  434. # cont.activate(wheel1.actuators['Visibility'])
  435. # cont.activate(wheel2.actuators['Visibility'])
  436. # cont.activate(wheel3.actuators['Visibility'])
  437. # cont.activate(wheel4.actuators['Visibility'])
  438. # #if throw_deck == None:
  439. # if 'throw_deck' not in scene.objects:
  440. # #print('no throwdeck')
  441. # #cont.deactivate(throw_deck.actuators['end_throw_deck'])
  442. # #throw_deck_empty.wordPosition.z = throw_deck_empty.wordPosition.z + 1
  443. # cont.activate(throw_deck_empty.actuators['throw_dec_act'])
  444. # #scene.addObject('throw_deck')
  445. # #throwdeck.visibility = True
  446. # throw_deck.suspendDynamics()
  447. # except:
  448. # pass
  449. ###
  450. # #-----Position-----#
  451. # own["lengthtdPos"] = readData.getLengthtdPos()
  452. # lengthPos = own["lengthtdPos"]
  453. #
  454. # if lengthPos:
  455. #
  456. # if objIndex > lengthPos-1:
  457. # own["objIndex"] = 0
  458. # if objIndex < 0:
  459. # own["objIndex"] = lengthPos-2
  460. # name, position = readData.returntdPosition(objIndex, valueIndex)
  461. # name = 'throw_deck'
  462. # if name in scene.objects:
  463. # try:
  464. # scene.objects[name].worldPosition = position
  465. # #print('recording tdPos', position)
  466. # except:
  467. # pass
  468. # #-----Orientation-----#
  469. # own["lengthtdOri"] = readData.getLengthtdOri()
  470. # lengthOri = own["lengthtdOri"]
  471. #
  472. # #if lengthPos:
  473. # if lengthOri:
  474. #
  475. # if valueIndex > lengthOri-1:
  476. # own["valueIndex"] = 0
  477. # if objIndex < 0:
  478. # own["objIndex"] = lengthOri-2
  479. # name, orientation = readData.returntdOrientation(objIndex, valueIndex)
  480. # name = 'throw_deck'
  481. # if name in scene.objects:
  482. #
  483. # oXYZ = scene.objects[name].localOrientation.to_euler()
  484. # oXYZ[0] = float(orientation[0])
  485. # oXYZ[1] = float(orientation[1])
  486. # oXYZ[2] = float(orientation[2])
  487. #
  488. # try:
  489. # #print('recording tdOri')
  490. # scene.objects[name].localOrientation = oXYZ.to_matrix()
  491. # except:
  492. # pass
  493. ##
  494. # #-----revert sound-----#
  495. # own["lengthSrevertsound"] = readData.getLengthSrevertsound()
  496. # lengthSrevertsound = own["lengthSrevertsound"]
  497. # if lengthSrevertsound:
  498. # if valueIndex > lengthSrevertsound-1:
  499. # own["valueIndex"] = 0
  500. # if objIndex < 0:
  501. # own["objIndex"] = lengthSrevertsound-2
  502. # name, srevertsound = readData.returnSrevertsound(objIndex, valueIndex)
  503. # if name in scene.objects:
  504. # try:
  505. # #cube = scene.objects[sound_empty]
  506. # srevertsound = round(srevertsound, 2)
  507. # act = cube.actuators["revertSound"]
  508. # if srevertsound == 1:
  509. # act.startSound()
  510. # #print("grindsound = ", spopsound, sgrind_railPitch)
  511. # except:
  512. # print("sound passed")
  513. # pass
  514. def main(recording_cutoff, cc):
  515. pass
  516. def breakOut():
  517. pass