seBlendAnimPanel.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. #################################################################
  2. # collisionWindow.py
  3. # Written by Yi-Hong Lin, [email protected], 2004
  4. #################################################################
  5. # Import Tkinter, Pmw, and the floater code from this directory tree.
  6. from direct.tkwidgets.AppShell import *
  7. from direct.showbase.TkGlobal import *
  8. from tkSimpleDialog import askfloat
  9. import string
  10. import math
  11. import types
  12. from direct.task import Task
  13. FRAMES = 0
  14. SECONDS = 1
  15. #####################################################################################
  16. # BlendAnimPanel(AppShell)
  17. # This Panel will allow user to blend tow animations
  18. # that have already been loaded for this actor.
  19. # user can play and manipulate this blended animation
  20. # just like in the animation panel. And, they can save this blended animation.
  21. #####################################################################################
  22. class BlendAnimPanel(AppShell):
  23. # Override class variables
  24. appname = 'Blend Anim Panel'
  25. frameWidth = 575
  26. frameHeight = 450
  27. usecommandarea = 0
  28. usestatusarea = 0
  29. index = 0
  30. dragMode = False
  31. blendRatio = 0
  32. rateList= ['1/24.0', '0.1', '0.5', '1.0', '2.0', '5.0' , '10.0']
  33. enableBlend = False
  34. currentBlendName = None
  35. def __init__(self, aNode = None, blendDict={}, parent = None, **kw):
  36. INITOPT = Pmw.INITOPT
  37. self.id = 'BlendAnimPanel '+ aNode.getName()
  38. self.appname = self.id
  39. self.actorNode = aNode
  40. self.blendDict = blendDict.copy()
  41. if len(blendDict)>0:
  42. self.blendList = blendDict.keys()
  43. else:
  44. self.blendList = []
  45. optiondefs = (
  46. ('title', self.appname, None),
  47. ('actor', aNode, None),
  48. ('animList', [], None),
  49. ('blendAnimList', self.blendList, None),
  50. )
  51. self.defineoptions(kw, optiondefs)
  52. self.id = 'Blend AnimPanel '+ aNode.getName()
  53. self.nodeName = aNode.getName()
  54. # Initialize the superclass
  55. AppShell.__init__(self)
  56. # Execute option callbacks
  57. self.initialiseoptions(BlendAnimPanel)
  58. self.currTime = 0.0
  59. self.animNameA = None
  60. self.animNameB = None
  61. self.parent.resizable(False,False) ## Disable the ability to resize for this Window.
  62. def createInterface(self):
  63. # Handle to the toplevels interior
  64. interior = self.interior()
  65. self.menuBar.destroy()
  66. # show the actor's name
  67. actorFrame = Frame(interior)
  68. name_label = Label(actorFrame, text= self.nodeName,font=('MSSansSerif', 14),
  69. relief = SUNKEN, borderwidth=3)
  70. name_label.pack(side = TOP, expand = False)
  71. actorFrame.pack(side = TOP, expand = False, fill = X)
  72. # Create a frame to show is there any ore-blended animation and save, edit, rename button.
  73. group = Pmw.Group(interior, tag_pyclass=None)
  74. actorFrame = group.interior()
  75. group.pack(side = TOP, expand = False, fill = X)
  76. Label(actorFrame, text= "Blended:", font=('MSSansSerif', 10)).pack(side=LEFT)
  77. self.blendAnimEntry = self.createcomponent(
  78. 'Blended Animation', (), None,
  79. Pmw.ComboBox, (actorFrame,),
  80. labelpos = W, entry_width = 20, selectioncommand = self.setBlendAnim,
  81. scrolledlist_items = self['blendAnimList'])
  82. self.blendAnimEntry.pack(side=LEFT)
  83. Label(actorFrame, text= " ", font=('MSSansSerif', 10)).pack(side=LEFT)
  84. button = Button(actorFrame, text="Save", font=('MSSansSerif', 10),width = 12,
  85. command = self.saveButtonPushed).pack(side=LEFT)
  86. button = Button(actorFrame, text="Remove", font=('MSSansSerif', 10),width = 12,
  87. command = self.removeButtonPushed).pack(side=LEFT)
  88. button = Button(actorFrame, text="Rename", font=('MSSansSerif', 10),width = 12,
  89. command = self.renameButtonPushed).pack(side=LEFT)
  90. actorFrame.pack(side = TOP, expand = False, fill = X)
  91. # Create a frame to hold all the animation setting
  92. group = Pmw.Group(interior, tag_pyclass=None)
  93. actorFrame = group.interior()
  94. group.pack(side = TOP, expand = False, fill = X)
  95. Label(actorFrame, text= "Animation A:", font=('MSSansSerif', 10)).pack(side=LEFT)
  96. self['animList'] = self['actor'].getAnimNames()
  97. self.AnimEntryA = self.createcomponent(
  98. 'AnimationMenuA', (), None,
  99. Pmw.ComboBox, (actorFrame,),
  100. labelpos = W, entry_width = 20, entry_state = DISABLED,
  101. selectioncommand = lambda name, a = 'a' : self.setAnimation(name, AB=a),
  102. scrolledlist_items = self['animList'])
  103. self.AnimEntryA.pack(side=LEFT)
  104. Label(actorFrame, text= " ", font=('MSSansSerif', 10)).pack(side=LEFT,)
  105. Label(actorFrame, text= "Animation B:", font=('MSSansSerif', 10)).pack(side=LEFT)
  106. self['animList'] = self['actor'].getAnimNames()
  107. self.AnimEntryB = self.createcomponent(
  108. 'AnimationMenuB', (), None,
  109. Pmw.ComboBox, (actorFrame,),
  110. labelpos = W, entry_width = 20, entry_state = DISABLED,
  111. selectioncommand = lambda name, a = 'b' : self.setAnimation(name, AB=a),
  112. scrolledlist_items = self['animList'])
  113. self.AnimEntryB.pack(side=LEFT)
  114. actorFrame.pack(side = TOP, expand = False, fill = X)
  115. ### Blend Enable checkbox
  116. actorFrame = Frame(interior, relief = SUNKEN, bd = 1)
  117. Label(actorFrame, text= "Enable Blending:", font=('MSSansSerif', 10)).pack(side=LEFT,)
  118. self.blendVar = IntVar()
  119. self.blendVar.set(0)
  120. self.blendButton = self.createcomponent(
  121. 'blendButton', (), None,
  122. Checkbutton, (actorFrame,),
  123. variable = self.blendVar,
  124. command = self.toggleBlend)
  125. self.blendButton.pack(side=LEFT)
  126. actorFrame.pack(side = TOP, expand = False, fill = X)
  127. ## Ratio control
  128. actorFrame = Frame(interior)
  129. frameFrame = Frame(actorFrame, relief = SUNKEN, bd = 1)
  130. minRatioLabel = self.createcomponent(
  131. 'minRatioLabel', (), 'sLabel',
  132. Label, (frameFrame,),
  133. text = 0.00)
  134. minRatioLabel.pack(side = LEFT)
  135. self.ratioControl = self.createcomponent(
  136. 'ratio', (), None,
  137. Scale, (frameFrame,),
  138. from_ = 0.0, to = 1.0, resolution = 0.01,
  139. command = self.setRatio, length = 500,
  140. orient = HORIZONTAL, showvalue = 1)
  141. self.ratioControl.pack(side = LEFT, expand = 1)
  142. self.ratioControl.set(1.0)
  143. self.maxRatioLabel = self.createcomponent(
  144. 'maxRatioLabel', (), 'sLabel',
  145. Label, (frameFrame,),
  146. text = 1.00)
  147. self.maxRatioLabel.pack(side = LEFT)
  148. frameFrame.pack(side = LEFT, expand = 1, fill = X)
  149. actorFrame.pack(side = TOP, expand = True, fill = X)
  150. ###################################################################################
  151. ###################################################################################
  152. actorFrame = Frame(interior)
  153. Label(actorFrame, text= "Play Rate:", font=('MSSansSerif', 10)).pack(side=LEFT)
  154. self.playRateEntry = self.createcomponent(
  155. 'playRateMenu', (), None,
  156. Pmw.ComboBox, (actorFrame,),
  157. labelpos = W, entry_width = 20, selectioncommand = self.setPlayRate,
  158. scrolledlist_items = self.rateList)
  159. self.playRateEntry.pack(side=LEFT)
  160. self.playRateEntry.selectitem('1.0')
  161. ### Loop checkbox
  162. Label(actorFrame, text= " ", font=('MSSansSerif', 10)).pack(side=LEFT,)
  163. Label(actorFrame, text= "Loop:", font=('MSSansSerif', 10)).pack(side=LEFT,)
  164. self.loopVar = IntVar()
  165. self.loopVar.set(0)
  166. self.loopButton = self.createcomponent(
  167. 'loopButton', (), None,
  168. Checkbutton, (actorFrame,),
  169. variable = self.loopVar)
  170. self.loopButton.pack(side=LEFT)
  171. actorFrame.pack(side = TOP, expand = True, fill = X)
  172. ### Display Frames/Seconds
  173. actorFrame = Frame(interior)
  174. Label(actorFrame, text= "Frame/Second:", font=('MSSansSerif', 10)).pack(side=LEFT)
  175. self.unitsVar = IntVar()
  176. self.unitsVar.set(FRAMES)
  177. self.displayButton = self.createcomponent(
  178. 'displayButton', (), None,
  179. Checkbutton, (actorFrame,),
  180. command = self.updateDisplay,
  181. variable = self.unitsVar)
  182. self.displayButton.pack(side=LEFT)
  183. actorFrame.pack(side = TOP, expand = True, fill = X)
  184. ## scale control
  185. actorFrame = Frame(interior)
  186. frameFrame = Frame(actorFrame, relief = SUNKEN, bd = 1)
  187. self.minLabel = self.createcomponent(
  188. 'minLabel', (), 'sLabel',
  189. Label, (frameFrame,),
  190. text = 0)
  191. self.minLabel.pack(side = LEFT)
  192. self.frameControl = self.createcomponent(
  193. 'scale', (), None,
  194. Scale, (frameFrame,),
  195. from_ = 0, to = 24, resolution = 1.0,
  196. command = self.goTo, length = 500,
  197. orient = HORIZONTAL, showvalue = 1)
  198. self.frameControl.pack(side = LEFT, expand = 1)
  199. self.frameControl.bind('<Button-1>', self.onPress)
  200. self.frameControl.bind('<ButtonRelease-1>', self.onRelease)
  201. self.maxLabel = self.createcomponent(
  202. 'maxLabel', (), 'sLabel',
  203. Label, (frameFrame,),
  204. text = 24)
  205. self.maxLabel.pack(side = LEFT)
  206. frameFrame.pack(side = LEFT, expand = 1, fill = X)
  207. actorFrame.pack(side = TOP, expand = True, fill = X)
  208. ## button contorl
  209. actorFrame = Frame(interior)
  210. ButtomFrame = Frame(actorFrame, relief = SUNKEN, bd = 1,borderwidth=5)
  211. self.toStartButton = self.createcomponent(
  212. 'toStart', (), None,
  213. Button, (ButtomFrame,),
  214. text = '<<',
  215. width = 8,
  216. command = self.resetAllToZero)
  217. self.toStartButton.pack(side = LEFT, expand = 1, fill = X)
  218. self.playButton = self.createcomponent(
  219. 'playButton', (), None,
  220. Button, (ButtomFrame,),
  221. text = 'Play', width = 8,
  222. command = self.play)
  223. self.playButton.pack(side = LEFT, expand = 1, fill = X)
  224. self.stopButton = self.createcomponent(
  225. 'stopButton', (), None,
  226. Button, (ButtomFrame,),
  227. text = 'Stop', width = 8, state=DISABLED,
  228. command = self.stop)
  229. self.stopButton.pack(side = LEFT, expand = 1, fill = X)
  230. self.toEndButton = self.createcomponent(
  231. 'toEnd', (), None,
  232. Button, (ButtomFrame,),
  233. text = '>>',
  234. width = 8,
  235. command = self.resetAllToEnd)
  236. self.toEndButton.pack(side = LEFT, expand = 1, fill = X)
  237. ButtomFrame.pack(side = TOP, expand = True, fill = X)
  238. actorFrame.pack(expand = 1, fill = BOTH)
  239. def updateList(self):
  240. #################################################################
  241. # updateList(self)
  242. # This will reset the list of all animations that this actor has
  243. # to the animation entry A and B.
  244. #################################################################
  245. self['animList'] = self['actor'].getAnimNames()
  246. animL = self['actor'].getAnimNames()
  247. self.AnimEntryA.setlist(animL)
  248. self.AnimEntryB.setlist(animL)
  249. def play(self):
  250. #################################################################
  251. # play(self)
  252. # It works pretty much like what we have in the Animation Panel.
  253. # The only different now is that we set two "pose" here.
  254. # When you do the blending animation by setPose, you don't have
  255. # to set them simultaneously.
  256. #################################################################
  257. self.animNameA = self.AnimEntryA.get()
  258. self.animNameB = self.AnimEntryB.get()
  259. if (self.animNameA in self['animList'])and(self.animNameB in self['animList']):
  260. self.playButton.config(state=DISABLED)
  261. self.lastT = globalClock.getFrameTime()
  262. taskMgr.add(self.playTask, self.id + '_UpdateTask')
  263. self.stopButton.config(state=NORMAL)
  264. else:
  265. print '----Illegal Animaion name!!', self.animNameA + ', '+ self.animNameB
  266. return
  267. def playTask(self, task):
  268. #################################################################
  269. # playTask(self, task)
  270. # see play(self)
  271. #################################################################
  272. fLoop = self.loopVar.get()
  273. currT = globalClock.getFrameTime()
  274. deltaT = currT - self.lastT
  275. self.lastT = currT
  276. if self.dragMode:
  277. return Task.cont
  278. self.currTime = self.currTime + deltaT
  279. if (self.currTime > self.maxSeconds):
  280. if fLoop:
  281. self.currTime = self.currTime%self.duration
  282. self.gotoT(self.currTime)
  283. else:
  284. self.currTime = 0.0
  285. self.gotoT(0.0)
  286. self.playButton.config(state=NORMAL)
  287. self.stopButton.config(state=DISABLED)
  288. return Task.done
  289. else:
  290. self.gotoT(self.currTime)
  291. return Task.cont
  292. def stop(self):
  293. #################################################################
  294. # stop(self)
  295. # see play(self)
  296. #################################################################
  297. taskMgr.remove(self.id + '_UpdateTask')
  298. self.playButton.config(state=NORMAL)
  299. self.stopButton.config(state=DISABLED)
  300. return
  301. def setAnimation(self, animation, AB = 'a'):
  302. #################################################################
  303. # setAnimation(self, animation, AB = 'a')
  304. # see play(self)
  305. #################################################################
  306. print 'OK!!!'
  307. if AB == 'a':
  308. if self.animNameA != None:
  309. self['actor'].setControlEffect(self.animNameA, 1.0, 'modelRoot','lodRoot')
  310. self.animNameA = self.AnimEntryA.get()
  311. else:
  312. if self.animNameB != None:
  313. self['actor'].setControlEffect(self.animNameB, 1.0, 'modelRoot','lodRoot')
  314. self.animNameB = self.AnimEntryB.get()
  315. self.currTime = 0.0
  316. self.frameControl.set(0)
  317. self.updateDisplay()
  318. self.setRatio(self.blendRatio)
  319. return
  320. def setPlayRate(self,rate):
  321. #################################################################
  322. # setPlayRate(self,rate)
  323. # see play(self)
  324. #################################################################
  325. self.animNameA = self.AnimEntryA.get()
  326. if self.animNameA in self['animList']:
  327. self['actor'].setPlayRate(eval(rate), self.animNameA)
  328. self.updateDisplay()
  329. if self.animNameB in self['animList']:
  330. self['actor'].setPlayRate(eval(rate), self.animNameB)
  331. self.updateDisplay()
  332. return
  333. def updateDisplay(self):
  334. #################################################################
  335. # updateDisplay(self)
  336. # see play(self)
  337. #################################################################
  338. if not (self.animNameA in self['animList']):
  339. return
  340. self.fps = self['actor'].getFrameRate(self.animNameA)
  341. self.duration = self['actor'].getDuration(self.animNameA)
  342. self.maxFrame = self['actor'].getNumFrames(self.animNameA) - 1
  343. if not (self.animNameB in self['animList']):
  344. return
  345. if self.duration > self['actor'].getDuration(self.animNameB):
  346. self.duration = self['actor'].getDuration(self.animNameB)
  347. if self.maxFrame > self['actor'].getNumFrames(self.animNameB) - 1:
  348. self.maxFrame = self['actor'].getNumFrames(self.animNameB) - 1
  349. self.maxSeconds = self.duration
  350. if self.unitsVar.get() == FRAMES:
  351. fromFrame = 0
  352. toFrame = self.maxFrame
  353. self.minLabel['text'] = fromFrame
  354. self.maxLabel['text'] = toFrame
  355. self.frameControl.configure(from_ = fromFrame,
  356. to = toFrame,
  357. resolution = 1.0)
  358. else:
  359. self.minLabel['text'] = '0.0'
  360. self.maxLabel['text'] = "%.2f" % self.duration
  361. self.frameControl.configure(from_ = 0.0,
  362. to = self.duration,
  363. resolution = 0.01)
  364. def gotoT(self,time):
  365. #################################################################
  366. # gotoT(self,time)
  367. # see play(self)
  368. #################################################################
  369. if self.unitsVar.get() == FRAMES:
  370. self.frameControl.set(time * self.fps)
  371. else:
  372. self.frameControl.set(time)
  373. return
  374. def goTo(self,frame):
  375. #################################################################
  376. # goTo(self,frame)
  377. # see play(self)
  378. #################################################################
  379. if (self.animNameA in self['animList'])and(self.animNameB in self['animList']):
  380. # Convert scale value to float
  381. frame = string.atof(frame)
  382. # Now convert t to seconds for offset calculations
  383. if self.unitsVar.get() == FRAMES:
  384. frame = frame / self.fps
  385. if self.dragMode:
  386. self.currTime = frame
  387. self['actor'].pose(self.animNameA,
  388. min(self.maxFrame, int(frame * self.fps)))
  389. self['actor'].pose(self.animNameB,
  390. min(self.maxFrame, int(frame * self.fps)))
  391. return
  392. def onRelease(self,frame):
  393. #################################################################
  394. # onRelease(self,frame)
  395. # see play(self)
  396. #################################################################
  397. self.dragMode = False
  398. return
  399. def onPress(self,frame):
  400. #################################################################
  401. # onPress(self,frame)
  402. # see play(self)
  403. #################################################################
  404. self.dragMode = True
  405. return
  406. def resetAllToZero(self):
  407. #################################################################
  408. # resetAllToZero(self)
  409. # see play(self)
  410. #################################################################
  411. self.currTime = 0.0
  412. self.gotoT(0)
  413. return
  414. def resetAllToEnd(self):
  415. #################################################################
  416. # resetAllToEnd(self)
  417. # see play(self)
  418. #################################################################
  419. self.currTime = self.maxSeconds
  420. self.gotoT(self.duration)
  421. return
  422. def toggleBlend(self):
  423. #################################################################
  424. # toggleBlend(self)
  425. # This function will enable the blending option for the actor.
  426. # and call set ratio function to set the blending animation mixing in
  427. # current ratio.
  428. #
  429. # This blending enable will not be keep when you close the window!
  430. #
  431. #################################################################
  432. if self.blendVar.get():
  433. self.enableBlend = True
  434. self['actor'].enableBlend()
  435. self.setRatio(self.blendRatio)
  436. else:
  437. self.enableBlend = False
  438. self['actor'].disableBlend()
  439. return
  440. def setRatio(self, ratio):
  441. #################################################################
  442. # setRatio(self, ratio)
  443. # callback funtion
  444. # This one will be called each time when user drag the blend ratio
  445. # slider on the panel. This will set the blening ratio to both animation.
  446. # (Which is "setControlEffect")
  447. #################################################################
  448. self.blendRatio = float(ratio)
  449. if self.enableBlend:
  450. if self.animNameA in self['animList']:
  451. self['actor'].setControlEffect(self.animNameA, self.blendRatio, 'modelRoot','lodRoot')
  452. if self.animNameB in self['animList']:
  453. self['actor'].setControlEffect(self.animNameB, 1-self.blendRatio, 'modelRoot','lodRoot')
  454. return
  455. def setBlendAnim(self, name):
  456. #################################################################
  457. # setBlendAnim(self, name)
  458. # This function will be called each time when user try to select
  459. # a existing blending animation from the comboBox on the panel
  460. # This function will re-set every varaibles on the panel to what
  461. # it should be. For example, when user choose blending anim "R,"
  462. # which was blended by anim "a" and "b" with ratio "c,"
  463. # then this function will set Animation A to "a" and animation B
  464. # to "b" and set the ratio slider to "c" position.
  465. #################################################################
  466. if self.blendDict.has_key(name):
  467. self.currentBlendName = name
  468. animA = self.blendDict[name][0]
  469. animB = self.blendDict[name][1]
  470. ratio = self.blendDict[name][2]
  471. self.AnimEntryA.selectitem(animA)
  472. self.AnimEntryB.selectitem(animB)
  473. self.setAnimation(animA, AB = 'a')
  474. self.setAnimation(animB, AB = 'b')
  475. self.ratioControl.set(ratio)
  476. return
  477. def setBlendAnimList(self, dict, select=False):
  478. #################################################################
  479. # setBlendAnimList(self, dict, select=False)
  480. # This function will be called when we need to reset the dropdown list
  481. # of "Blend Anim."
  482. # About "selec" option, this now is mainly used when we remove
  483. # a blended animation from the actor. When it has been specified to True,
  484. # the function will not only reset the list, but will also automatically
  485. # select one from the top of list, if it is not empty.
  486. #################################################################
  487. self.blendDict.clear()
  488. del self.blendDict
  489. self.blendDict = dict.copy()
  490. print self.blendDict
  491. if len(self.blendDict)>0:
  492. self.blendList = self.blendDict.keys()
  493. else:
  494. self.blendList = []
  495. self.blendAnimEntry.setlist(self.blendList)
  496. if select:
  497. if len(self.blendList)>0:
  498. self.blendAnimEntry.selectitem(self.blendList[0])
  499. self.setBlendAnim(self.blendList[0])
  500. self.currentBlendName = self.blendList[0]
  501. else:
  502. self.blendAnimEntry.clear()
  503. self.currentBlendName = None
  504. return
  505. def saveButtonPushed(self):
  506. #################################################################
  507. # saveButtonPushed(self)
  508. # This function will be called when user clicked on the "Save" button
  509. # This functiont will collect all data on the panel and send them with
  510. # a message to sceneEditor to save the current blending animation
  511. # into the dataHolder.
  512. #################################################################
  513. name = self.blendAnimEntry.get()
  514. if name=='':
  515. Pmw.MessageDialog(None, title='Caution!',
  516. message_text = 'You have to give the blending animation a name first!',
  517. iconpos='s',
  518. defaultbutton = 'Close'
  519. )
  520. return
  521. elif (not(self.animNameA in self['animList']))or(not(self.animNameB in self['animList'])):
  522. Pmw.MessageDialog(None, title='Caution!',
  523. message_text = 'The Animations you have selected are not exist!',
  524. iconpos='s',
  525. defaultbutton = 'Close'
  526. )
  527. return
  528. else:
  529. messenger.send('BAW_saveBlendAnim', [self['actor'].getName(),
  530. name,
  531. self.animNameA,
  532. self.animNameB,
  533. self.blendRatio])
  534. self.currentBlendName = name
  535. return
  536. def removeButtonPushed(self):
  537. #################################################################
  538. # removeButtonPushed(self)
  539. # remove the current seleted blended animation from the actor.
  540. # This will send out a message to sceneEditor to delete the data inside
  541. # the dataHolder and then reset the list of here.
  542. #################################################################
  543. name = self.blendAnimEntry.get()
  544. messenger.send('BAW_removeBlendAnim', [self['actor'].getName(),name])
  545. return
  546. def renameButtonPushed(self):
  547. #################################################################
  548. # renameButtonPushed(self)
  549. # this function will be called when user click on the "Rename" button.
  550. # This function will collect all data on the panel and send them out
  551. # with a message to sceneEditor to rename and re-save all setting about
  552. # current animation.
  553. #################################################################
  554. oName = self.currentBlendName
  555. name = self.blendAnimEntry.get()
  556. if self.currentBlendName == None:
  557. Pmw.MessageDialog(None, title='Caution!',
  558. message_text = "You haven't select any blended animation!!",
  559. iconpos='s',
  560. defaultbutton = 'Close'
  561. )
  562. return
  563. elif name=='':
  564. Pmw.MessageDialog(None, title='Caution!',
  565. message_text = 'You have to give the blending animation a name first!',
  566. iconpos='s',
  567. defaultbutton = 'Close'
  568. )
  569. return
  570. elif (not(self.animNameA in self['animList']))or(not(self.animNameB in self['animList'])):
  571. Pmw.MessageDialog(None, title='Caution!',
  572. message_text = 'The Animations you have selected are not exist!',
  573. iconpos='s',
  574. defaultbutton = 'Close'
  575. )
  576. return
  577. else:
  578. messenger.send('BAW_renameBlendAnim', [self['actor'].getName(),
  579. name,
  580. oName,
  581. self.animNameA,
  582. self.animNameB,
  583. self.blendRatio]
  584. )
  585. self.currentBlendName = name
  586. return
  587. def onDestroy(self, event):
  588. #################################################################
  589. # onDestroy(self, event)
  590. # This function will be call when user try to close the window.
  591. # In here we will stop all tasks we have opend and disable the
  592. # blend setting of actor.
  593. # If we didn't disable the blend option, the next time you play
  594. # the animation via animation panel will cause some error.
  595. #################################################################
  596. if taskMgr.hasTaskNamed(self.id + '_UpdateTask'):
  597. taskMgr.remove(self.id + '_UpdateTask')
  598. messenger.send('BAW_close',[self.nodeName])
  599. self.actorNode.setControlEffect(self.animNameA, 1.0, 'modelRoot','lodRoot')
  600. self.actorNode.setControlEffect(self.animNameB, 1.0, 'modelRoot','lodRoot')
  601. self.actorNode.disableBlend()
  602. '''
  603. If you have open any thing, please rewrite here!
  604. '''
  605. pass