sceneEditor.py 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  1. import sys
  2. try: import _tkinter
  3. except: sys.exit("Please install python module 'Tkinter'")
  4. import direct
  5. from direct.directbase.DirectStart import*
  6. from direct.showbase.TkGlobal import*
  7. from tkFileDialog import *
  8. from direct.directtools.DirectGlobals import *
  9. from direct.tkwidgets.AppShell import*
  10. from SideWindow import*
  11. from duplicateWindow import*
  12. from lightingPanel import *
  13. from seMopathRecorder import *
  14. from seSession import *
  15. from quad import *
  16. from sePlacer import *
  17. from seFileSaver import *
  18. from propertyWindow import *
  19. import seParticlePanel
  20. from collisionWindow import *
  21. from direct.gui.DirectGui import *
  22. from MetadataPanel import *
  23. from seBlendAnimPanel import *
  24. from controllerWindow import *
  25. from AlignTool import *
  26. import os
  27. import string
  28. from direct.tkwidgets import Dial
  29. from direct.tkwidgets import Floater
  30. from direct.tkwidgets import Slider
  31. from direct.actor import Actor
  32. import seAnimPanel
  33. from direct.task import Task
  34. import math
  35. #################################################################
  36. # All scene and windows object will be stored in here.
  37. # So, any event which will or need to change contents
  38. # should be wirtten in here or imported into here!
  39. #################################################################
  40. from dataHolder import* ## Use this thing to Save/load data.
  41. AllScene = dataHolder()
  42. class myLevelEditor(AppShell):
  43. ## overridden the basic app info ##
  44. appname = 'Scene Editor - New Scene'
  45. appversion = '1.0'
  46. copyright = ('Copyright 2004 E.T.C. Carnegie Mellon U.' +
  47. ' All Rights Reserved')
  48. contactname = 'Jesse Schell, Shalin Shodhan & YiHong Lin'
  49. contactphone = '(412) 268-5791'
  50. contactemail = '[email protected]'
  51. frameWidth = 1024
  52. frameHeight = 80
  53. frameIniPosX = 0
  54. frameIniPosY = 0
  55. usecommandarea = 0
  56. usestatusarea = 0
  57. padx = 5
  58. pady = 5
  59. sideWindowCount = 0
  60. ## Basic World default setting (For side window)
  61. worldColor = [0,0,0,0]
  62. lightEnable = 1
  63. ParticleEnable = 1
  64. basedriveEnable = 0
  65. collision = 1
  66. backface = 0
  67. texture = 1
  68. wireframe = 0
  69. grid = 0
  70. widgetVis = 0
  71. enableAutoCamera = 1
  72. enableControl = False
  73. controlType = 'Keyboard'
  74. keyboardMapDict = {}
  75. keyboardSpeedDict = {}
  76. Scene=None
  77. isSelect = False
  78. nodeSelected = None
  79. undoDic = {}
  80. redoDic = {}
  81. animPanel = {}
  82. animBlendPanel = {}
  83. propertyWindow = {}
  84. CurrentFileName=None #Holds the current scene file name
  85. CurrentDirName=None # Holds the current file name without extension which is the path where file's data gets saved
  86. Dirty=0 # Keeps track of whether there are any modifications that should be saved
  87. def __init__(self, parent = None, **kw):
  88. base.setBackgroundColor(0,0,0)
  89. self.parent = parent
  90. ## Check TkTool is activated! ##
  91. self.wantTK = config.GetBool('want-tk', 0)
  92. if self.wantTK:
  93. pass
  94. else:
  95. taskMgr.remove('tkloop')
  96. spawnTkLoop()
  97. ## Set up window frame
  98. INITOPT = Pmw.INITOPT
  99. optiondefs = (
  100. ('title', self.appname, None),
  101. )
  102. self.defineoptions(kw, optiondefs)
  103. AppShell.__init__(self, parent)
  104. self.parent.geometry('%dx%d+%d+%d' % (self.frameWidth, self.frameHeight,self.frameIniPosX,self.frameIniPosY))
  105. ###### Put th directLabel on the screen to show the selected object Data
  106. self.posLabel = DirectLabel(
  107. relief = None,
  108. pos = (-1.3, 0, 0.90),
  109. text = "Position : X: 00.00 Y: 00.00 Z: 00.00",
  110. color = Vec4(1, 1, 1, 1),
  111. text_scale = 0.05,
  112. text_align = TextNode.ALeft
  113. )
  114. self.hprLabel = DirectLabel(
  115. relief = None,
  116. pos = (-1.3 , 0, 0.80),
  117. text = "Orientation: H: 00.00 P: 00.00 R: 00.00",
  118. color = Vec4(1, 1, 1, 1),
  119. text_scale = 0.05,
  120. text_align = TextNode.ALeft
  121. )
  122. self.scaleLabel = DirectLabel(
  123. relief = None,
  124. pos = (-1.3, 0, 0.70),
  125. text = "Scale : X: 00.00 Y: 00.00 Z: 00.00",
  126. color = Vec4(1, 1, 1, 1),
  127. text_scale = 0.05,
  128. text_align = TextNode.ALeft
  129. )
  130. self.initialiseoptions(myLevelEditor)
  131. self.parent.resizable(False,False) ## Disable the ability to resize for this Window.
  132. ######### Set the event handler ##########
  133. self.dataFlowEvents = [
  134. ## Event from Side Window
  135. ['SW_lightToggle',self.lightToggle],
  136. ['SW_collisionToggle',AllScene.toggleCollisionVisable],
  137. ['SW_particleToggle',self.toggleParticleVisable],
  138. ['SW_close',self.sideWindowClose],
  139. ## From Duplication Window
  140. ['DW_duplicating',self.duplicationObj],
  141. ## From Animation Panel
  142. ['AW_AnimationLoad',self.animationLoader],
  143. ['AW_removeAnim',self.animationRemove],
  144. ['AW_close',self.animPanelClose],
  145. ## From Blending Animation Window
  146. ['BAW_saveBlendAnim',self.animBlendPanelSave],
  147. ['BAW_removeBlendAnim',self.animBlendPanelRemove],
  148. ['BAW_renameBlendAnim',self.animBlendPanelRename],
  149. ['BAW_close',self.animBlendPanelClose],
  150. ## From Lighting Panel
  151. ['LP_selectLight', self.lightSelect],
  152. ['LP_addLight',self.addLight],
  153. ['LP_rename',self.lightRename],
  154. ['LP_removeLight',self.removeLight],
  155. ['LP_close',self.lightingPanelClose],
  156. ## From MotionPath Panel
  157. ['mPath_bindPathToNode',AllScene.bindCurveToNode],
  158. ['mPath_requestCurveList', self.requestCurveList],
  159. ['mPath_close', self.mopathClosed],
  160. ## From Property Window
  161. ['PW_removeCurveFromNode', AllScene.removeCurveFromNode],
  162. ['PW_removeAnimFromNode', AllScene.removeAnimation],
  163. ['PW_toggleLight', AllScene.toggleLightNode],
  164. ['PW_close', self.closePropertyWindow],
  165. ## From collisionWindow
  166. ['CW_addCollisionObj', AllScene.addCollisionObject],
  167. ## From AlignWindow
  168. ['ALW_close', self.closeAlignPanel],
  169. ['ALW_align', self.alignObject],
  170. ## From controllerWindow
  171. ['ControlW_close', self.closeInputPanel],
  172. ['ControlW_require', self.requestObjFromControlW],
  173. ['ControlW_controlSetting', self.setControlSet],
  174. ['ControlW_controlEnable', self.startControl],
  175. ['ControlW_controlDisable', self.stopControl],
  176. ['ControlW_saveSetting', AllScene.saveControlSetting],
  177. ## From Placer
  178. ['Placer_close', self.closePlacerPanel],
  179. ## From Particle Panel
  180. ['ParticlePanle_close', self.closeParticlePanel],
  181. ## From SEditor object which is a altered DirectSession
  182. ['SEditor-ToggleWidgetVis',self.toggleWidgetVis],
  183. ['SEditor-ToggleBackface',self.toggleBackface],
  184. ['SEditor-ToggleTexture',self.toggleTexture],
  185. ['SEditor-ToggleWireframe',self.toggleWireframe],
  186. ['ParticlePanel_Added_Effect',self.addParticleEffect],
  187. ]
  188. #################################
  189. ### Collision detection
  190. #################################
  191. self.cTrav = CollisionTraverser()
  192. base.cTrav = self.cTrav
  193. for event in self.dataFlowEvents:
  194. self.accept(event[0], event[1], extraArgs = event[2:])
  195. self.actionEvents = [
  196. # Scene graph explorer functions
  197. ['SGE_changeName', self.changeName],
  198. ['SGE_Properties', self.openPropertyPanel],
  199. ['SGE_Duplicate', self.duplicate],
  200. ['SGE_Remove', self.remove],
  201. ['SGE_Add Dummy', self.addDummyNode],
  202. ['SGE_Add Collision Object', self.addCollisionObj],
  203. ['SGE_Metadata', self.openMetadataPanel],
  204. ['SGE_Set as Reparent Target', self.setAsReparentTarget],
  205. ['SGE_Reparent to Target', self.reparentToNode],
  206. ['SGE_Animation Panel', self.openAnimPanel],
  207. ['SGE_Blend Animation Panel', self.openBlendAnimPanel],
  208. ['SGE_MoPath Panel', self.openMoPathPanel],
  209. ['SGE_Align Tool', self.openAlignPanel],
  210. ['SGE_Flash', self.flash],
  211. ['SGE_madeSelection', self.selectNode],
  212. ['select',self.selectNode],
  213. ['deselect', self.deSelectNode],
  214. ['se_selectedNodePath',self.selectFromScene],
  215. ['se_deselectedAll',self.deselectFromScene],
  216. ]
  217. ''' All messages starting with "SGE_" are generated in seSceneGraphExplorer'''
  218. for event in self.actionEvents:
  219. self.accept(event[0], event[1], extraArgs = event[2:])
  220. camera.toggleVis()
  221. self.selectNode(base.camera) ## Initially, we select camera as the first node...
  222. def appInit(self):
  223. #################################################################
  224. # appInit(self)
  225. # Initialize the application.
  226. # This function will be called when you call AppShell's constructor
  227. #################################################################
  228. ### Create SceneEditor Ver. DirectSession
  229. self.seSession = SeSession()
  230. self.seSession.enable()
  231. SEditor.camera.setPos(0,-50,10)
  232. self.placer=None
  233. self.MopathPanel = None
  234. self.alignPanelDict = {}
  235. #self.quadview=QuadView()
  236. self.lightingPanel = None
  237. self.controllerPanel = None
  238. self.particlePanel = None
  239. ### Create Side Window
  240. self.sideWindow = sideWindow(worldColor = self.worldColor,
  241. lightEnable = self.lightEnable,
  242. ParticleEnable = self.ParticleEnable,
  243. basedriveEnable = self.basedriveEnable,
  244. collision = self.collision,
  245. backface = self.backface,
  246. texture = self.texture,
  247. wireframe = self.wireframe,
  248. grid = self.grid,
  249. widgetVis = self.widgetVis,
  250. enableAutoCamera = self.enableAutoCamera)
  251. self.sideWindowCount = 1
  252. self.sideWindow.selectPage()
  253. messenger.send('SGE_Update Explorer',[render]) ## Update the Scene Graph
  254. pass
  255. def getPhotoImage(self,name):
  256. modpath = ConfigVariableSearchPath("model-path")
  257. path = modpath.findFile(Filename(name))
  258. return PhotoImage(file=path.toOsSpecific())
  259. def createInterface(self):
  260. # The interior of the toplevel panel
  261. interior = self.interior()
  262. #######################################################
  263. ### Creating the Buttons in the window frame
  264. #######################################################
  265. buttonFrame = Frame(interior)
  266. self.image=[]
  267. self.image.append(self.getPhotoImage('models/icons/new.gif'))#0
  268. self.image.append(self.getPhotoImage('models/icons/open.gif'))#1
  269. self.image.append(self.getPhotoImage('models/icons/save.gif'))#2
  270. self.image.append(self.getPhotoImage('models/icons/model.gif'))#3
  271. self.image.append(self.getPhotoImage('models/icons/actor.gif'))#4
  272. self.image.append(self.getPhotoImage('models/icons/placer.gif'))#5
  273. self.image.append(self.getPhotoImage('models/icons/mopath.gif'))#6
  274. self.image.append(self.getPhotoImage('models/icons/lights.gif'))#7
  275. self.image.append(self.getPhotoImage('models/icons/particles.gif'))#8
  276. self.image.append(self.getPhotoImage('models/icons/control.gif'))
  277. self.image.append(self.getPhotoImage('models/icons/help.gif'))#9
  278. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  279. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  280. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  281. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  282. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  283. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  284. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  285. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  286. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  287. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  288. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  289. self.image.append(self.getPhotoImage('models/icons/blank.gif'))
  290. i = 0
  291. for element in self.image:
  292. i += 1
  293. button = Button(buttonFrame, image = element, command=lambda n=i : self.buttonPushed(n))
  294. button.pack(fill=X, side = LEFT)
  295. buttonFrame.pack(fill=X, side=LEFT,expand=True)
  296. def buttonPushed(self, buttonIndex):
  297. #################################################################
  298. # buttonPushed(self, buttonNum)
  299. # This function will handle all button events from top level window
  300. # Take the button index as a reference to sence which button has been pushed.
  301. #################################################################
  302. ####
  303. #### Change here to process the button event further.
  304. ####
  305. if buttonIndex==1: # New Scene
  306. self.newScene()
  307. return
  308. elif buttonIndex==2: # Open Scene
  309. self.openScene()
  310. return
  311. elif buttonIndex==3: # Save Scene
  312. self.saveScene()
  313. return
  314. elif buttonIndex==4: # Load Model
  315. self.loadModel()
  316. return
  317. elif buttonIndex==5: # Load Actor
  318. self.loadActor()
  319. return
  320. elif buttonIndex==6: # Open Placer
  321. self.openPlacerPanel()
  322. return
  323. elif buttonIndex==7: # Open Mopath Panel
  324. self.openMoPathPanel()
  325. return
  326. elif buttonIndex==8: # Open Lighting Panel
  327. self.openLightingPanel()
  328. return
  329. elif buttonIndex==9: # Open Particle Panel
  330. self.openParticlePanel()
  331. return
  332. elif buttonIndex==10:
  333. self.openInputPanel()
  334. return
  335. elif buttonIndex==11: # Help
  336. self.showAbout()
  337. return
  338. elif buttonIndex==12:
  339. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  340. return
  341. elif buttonIndex==13:
  342. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  343. return
  344. elif buttonIndex==14:
  345. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  346. return
  347. elif buttonIndex==15:
  348. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  349. return
  350. elif buttonIndex==16:
  351. print "Your scene will be eliminated within five seconds, Save your world!!!, Number %d."%buttonIndex
  352. return
  353. elif buttonIndex==17:
  354. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  355. return
  356. elif buttonIndex==18:
  357. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  358. return
  359. elif buttonIndex==19:
  360. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  361. return
  362. elif buttonIndex==20:
  363. print "You haven't defined the function for this Button, Number %d."%buttonIndex
  364. return
  365. return
  366. def createMenuBar(self):
  367. # Creates default menus. Can be overridden or simply augmented
  368. # Using button Add below
  369. self.menuBar.addmenuitem('Help', 'command',
  370. 'Get information on application',
  371. label='About...', command=self.showAbout)
  372. ## Creat stuff inside the "File"
  373. self.menuBar.addmenuitem('File', 'command', 'Creat New Scene',
  374. label='New Scene',
  375. command=self.newScene)
  376. self.menuBar.addmenuitem('File', 'command', 'Open a Scene',
  377. label='Open Scene',
  378. command=self.openScene)
  379. self.menuBar.addmenuitem('File', 'command', 'Save a Scene',
  380. label='Save Scene',
  381. command=self.saveScene)
  382. self.menuBar.addmenuitem('File', 'command', 'Save Scene as...',
  383. label='Save as...',
  384. command=self.saveAsScene)
  385. self.menuBar.addmenuitem('File', 'separator')
  386. self.menuBar.addmenuitem('File', 'command', 'Load Model',
  387. label='Load Model',
  388. command=self.loadModel)
  389. self.menuBar.addmenuitem('File', 'command', 'Load Actor',
  390. label='Load Actor',
  391. command=self.loadActor)
  392. self.menuBar.addmenuitem('File', 'separator')
  393. self.menuBar.addmenuitem('File', 'command', 'Import a Scene',
  394. label='Import...',
  395. command=self.importScene)
  396. self.menuBar.addmenuitem('File', 'separator')
  397. self.menuBar.addmenuitem('File', 'command', 'Quit this application',
  398. label='Exit',
  399. command=self.quit)
  400. ## Creat "Edit" on the menu and its stuff
  401. self.menuBar.addmenu('Edit', 'Editting tools')
  402. self.menuBar.addmenuitem('Edit', 'command', 'Un-do',
  403. label='Undo...',
  404. command=self.unDo)
  405. self.menuBar.addmenuitem('Edit', 'command', 'Re-do',
  406. label='Redo...',
  407. command=self.reDo)
  408. self.menuBar.addmenuitem('Edit', 'separator')
  409. self.menuBar.addmenuitem('Edit', 'command', 'Deselect nodepath',
  410. label='Deselect',
  411. command=self.deSelectNode)
  412. self.menuBar.addmenuitem('Edit', 'separator')
  413. self.menuBar.addmenuitem('Edit', 'command', 'Add a Dummy',
  414. label='Add Dummy',
  415. command=self.addDummy)
  416. self.menuBar.addmenuitem('Edit', 'command', 'Duplicate nodepath',
  417. label='Duplicate',
  418. command=self.duplicateNode)
  419. self.menuBar.addmenuitem('Edit', 'command', 'Remove the nodepath',
  420. label='Remove',
  421. command=self.removeNode)
  422. self.menuBar.addmenuitem('Edit', 'command', 'Show the object properties',
  423. label='Object Properties',
  424. command=self.showObjProp)
  425. self.menuBar.addmenuitem('Edit', 'separator')
  426. self.menuBar.addmenuitem('Edit', 'command', 'Show the Camera setting',
  427. label='Camera Setting',
  428. command=self.showCameraSetting)
  429. self.menuBar.addmenuitem('Edit', 'command', 'Render setting',
  430. label='Render Setting',
  431. command=self.showRenderSetting)
  432. ## Creat "Panel" on the menu and its stuff
  433. self.menuBar.addmenu('Panel', 'Panel tools')
  434. self.menuBar.addmenuitem('Panel', 'command', 'Open Side Window',
  435. label='Side Window',
  436. command=self.openSideWindow)
  437. self.menuBar.addmenuitem('Panel', 'command', 'Placer Panel',
  438. label='Placer Panel',
  439. command=self.openPlacerPanel)
  440. self.menuBar.addmenuitem('Panel', 'command', 'Animation Panel',
  441. label='Animation Panel',
  442. command=self.openAnimationPanel)
  443. self.menuBar.addmenuitem('Panel', 'command', 'Motion Path Panel',
  444. label='Mopath Panel',
  445. command=self.openMopathPanel)
  446. self.menuBar.addmenuitem('Panel', 'command', 'Lighting Panel',
  447. label='Lighting Panel',
  448. command=self.openLightingPanel)
  449. self.menuBar.addmenuitem('Panel', 'command', 'Particle Panel',
  450. label='Particle Panel',
  451. command=self.openParticlePanel)
  452. self.menuBar.addmenuitem('Panel', 'separator')
  453. self.menuBar.addmenuitem('Panel', 'command', 'Input control Panel',
  454. label='Input device panel',
  455. command=self.openInputPanel)
  456. self.menuBar.pack(fill=X, side = LEFT)
  457. ## get "Menu" items in order to control the entry status
  458. self.menuFile = self.menuBar.component('File-menu')
  459. self.menuEdit = self.menuBar.component('Edit-menu')
  460. self.menuPanel = self.menuBar.component('Panel-menu')
  461. ## Disable entries when user doesn't select anything
  462. if not self.isSelect:
  463. self.menuEdit.entryconfig('Deselect', state=DISABLED)
  464. self.menuEdit.entryconfig('Add Dummy', state=DISABLED)
  465. self.menuEdit.entryconfig('Duplicate', state=DISABLED)
  466. self.menuEdit.entryconfig('Remove', state=DISABLED)
  467. self.menuEdit.entryconfig('Object Properties', state=DISABLED)
  468. self.menuPanel.entryconfig('Animation Panel', state=DISABLED)
  469. self.menuPanel.entryconfig('Side Window', state=DISABLED)
  470. def onDestroy(self, event):
  471. #################################################################
  472. # If you have open any thing, please rewrite here!
  473. #################################################################
  474. if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
  475. taskMgr.remove('seMonitorSelectedNode')
  476. pass
  477. def closeAllSubWindows(self):
  478. #################################################################
  479. # closeAllSubWindows(self)
  480. # except side window. this function will close all sub window if there is any.
  481. #################################################################
  482. if self.lightingPanel != None:
  483. self.lightingPanel.quit()
  484. if self.placer != None:
  485. self.placer.quit()
  486. if self.MopathPanel != None:
  487. self.MopathPanel.quit()
  488. if self.particlePanel != None:
  489. self.particlePanel.quit()
  490. if self.controllerPanel != None:
  491. self.controllerPanel.quit()
  492. list = self.animPanel.keys()
  493. for index in list:
  494. self.animPanel[index].quit()
  495. list = self.animBlendPanel.keys()
  496. for index in list:
  497. self.animBlendPanel[index].quit()
  498. list = self.propertyWindow.keys()
  499. for index in list:
  500. self.propertyWindow[index].quit()
  501. list = self.alignPanelDict.keys()
  502. for index in list:
  503. self.alignPanelDict[index].quit()
  504. self.animPanel.clear()
  505. self.animBlendPanel.clear()
  506. self.propertyWindow.clear()
  507. self.alignPanelDict.clear()
  508. return
  509. ## Processing message events
  510. def makeDirty(self):
  511. self.Dirty=1
  512. def removeLight(self, lightNode):
  513. #################################################################
  514. # removeLight(self, lightNode)
  515. # This function will be called when user try to remove the light from lightingPanel
  516. # (by sending out the message)
  517. # So, in here we will call dataHolder(AllScene) to remove the light
  518. # and return a list contains the newest data of lights in he scene.
  519. # Then, this function will reset the lighting list in the lightingPanel
  520. #################################################################
  521. list = AllScene.removeObj(lightNode)
  522. if self.lightingPanel != None:
  523. self.lightingPanel.updateList(list)
  524. return
  525. def lightRename(self,oName, nName):
  526. #################################################################
  527. # lightRename(self,oName, nName)
  528. # This function will be called when user try to rename the light from lightingPanel
  529. # (by sending out the message)
  530. # So, in here we will call dataHolder(AllScene) to rename the light
  531. # and return a list contains the newest data of lights in he scene.
  532. # Then, this function will reset the lighting list in the lightingPanel
  533. #################################################################
  534. list, lightNode = AllScene.rename(oName, nName)
  535. if self.lightingPanel != None:
  536. self.lightingPanel.updateList(list,lightNode)
  537. return
  538. def lightSelect(self,lightName):
  539. #################################################################
  540. # lightSelect(self,lightName)
  541. # This function will be called when user try to select the light from lightingPanel
  542. # (by sending out the message)
  543. # So, in here we will call dataHolder(AllScene) to get the target light node
  544. # Then, this function will put this light node back into lighting
  545. # panel and update the data on the panel.
  546. #################################################################
  547. lightNode = AllScene.getLightNode(lightName)
  548. if self.lightingPanel != None:
  549. self.lightingPanel.updateDisplay(lightNode)
  550. return
  551. def addLight(self, type):
  552. #################################################################
  553. # addLight(self, type)
  554. # This function will be called when user try to add a light from lightingPanel
  555. # (by sending out the message)
  556. # So, in here we will call dataHolder(AllScene) to create a default light node
  557. # by the type that user assigned.
  558. # Then, this function will put this light node back into lighting
  559. # panel with the newest lighting list and update the data on the panel.
  560. #################################################################
  561. list, lightNode = AllScene.createLight(type = type)
  562. if self.lightingPanel != None:
  563. self.lightingPanel.updateList(list,lightNode)
  564. self.makeDirty()
  565. return
  566. def lightingPanelClose(self):
  567. #################################################################
  568. # lightingPanelClose(self)
  569. # This function will be called when user try to close the lighting panel
  570. # This function will re-config the state of the lighting panel button on the top screen
  571. # And it will set the self.lightingPanel to None
  572. #################################################################
  573. self.menuPanel.entryconfig('Lighting Panel', state=NORMAL)
  574. self.lightingPanel = None
  575. return
  576. def openPropertyPanel(self, nodePath = None):
  577. #################################################################
  578. # openPropertyPanel(self, nodePath = None)
  579. # This function will be called when user try to open a property window
  580. # for one specific node in the scene.
  581. # Here we will call dataHolder to get the basic properties
  582. # we would like to let user to see and cange.
  583. # And then we pass those information into propertyWindow
  584. #################################################################
  585. type, info = AllScene.getInfoOfThisNode(nodePath)
  586. name = nodePath.getName()
  587. if not self.propertyWindow.has_key(name):
  588. self.propertyWindow[name] = propertyWindow(nodePath, type,info )
  589. pass
  590. def closePropertyWindow(self, name):
  591. if self.propertyWindow.has_key(name):
  592. del self.propertyWindow[name]
  593. return
  594. def openMetadataPanel(self,nodePath=None):
  595. print nodePath
  596. self.MetadataPanel=MetadataPanel(nodePath)
  597. pass
  598. def duplicate(self, nodePath = None):
  599. #################################################################
  600. # duplicate(self, nodePath = None)
  601. # This function will be called when user try to open the duplication window
  602. #################################################################
  603. print '----Duplication!!'
  604. if nodePath != None:
  605. self.duplicateWindow = duplicateWindow(nodePath = nodePath)
  606. pass
  607. def remove(self, nodePath = None):
  608. #################################################################
  609. # remove(self, nodePath = None)
  610. # This function will be called when user try to delete a node from scene
  611. #
  612. # For safty issue,
  613. # we will do deselect first then remove the certain node.
  614. #
  615. #################################################################
  616. if nodePath==None:
  617. if self.nodeSelected == None:
  618. return
  619. nodePath = self.nodeSelected
  620. self.deSelectNode()
  621. if AllScene.isLight(nodePath.getName()):
  622. self.removeLight(nodePath)
  623. else:
  624. AllScene.removeObj(nodePath)
  625. pass
  626. def addDummyNode(self, nodepath = None):
  627. #################################################################
  628. # addDummyNode(self, nodepath = None)
  629. # This function will be called when user try to create a dummy node into scene
  630. #
  631. # Here we will call dataHolder to create a dummy node
  632. # and reparent it to the nodePath that user has assigned.
  633. #
  634. #################################################################
  635. AllScene.addDummyNode(nodepath)
  636. self.makeDirty()
  637. pass
  638. def addCollisionObj(self, nodepath = None):
  639. #################################################################
  640. # addCollisionObj(self, nodepath = None)
  641. # This function will be called when user try to create a collision object into the scene
  642. #
  643. # Here we will call collisionWindow to ask user what kind of collision objects they want to have.
  644. # Then, send the information and generated collision object to dataHolder to finish the whole process
  645. # and reparent it to the nodePath that user has assigned.
  646. #
  647. #################################################################
  648. self.collisionWindow = collisionWindow(nodepath)
  649. pass
  650. def setAsReparentTarget(self, nodepath = None):
  651. #################################################################
  652. # setAsReparentTarget(self, nodepath = None)
  653. # This function will be called when user select a nodePaht
  654. # and want to reparent other node under it. (Drom side window pop-up nemu)
  655. #################################################################
  656. SEditor.setActiveParent(nodepath)
  657. return
  658. def reparentToNode(self, nodepath = None):
  659. #################################################################
  660. # reparentToNode(self, nodepath = None)
  661. # This function will be call when user try to reparent a node to
  662. # that node he selected as a reparent target before.
  663. #
  664. # The whole reparent process is handled by seSession,
  665. # which is tunned from DirectSession
  666. #
  667. #################################################################
  668. SEditor.reparent(nodepath, fWrt = 1)
  669. return
  670. def openPlacerPanel(self, nodePath = None):
  671. #################################################################
  672. # openPlacerPanel(self, nodePath = None)
  673. # This function will be call when user try to open a placer panel.
  674. # This call will only success if there is no other placer panel been activated
  675. #################################################################
  676. if(self.placer==None):
  677. self.placer = Placer()
  678. self.menuPanel.entryconfig('Placer Panel', state=DISABLED)
  679. return
  680. def closePlacerPanel(self):
  681. #################################################################
  682. # closePlacerPanel(self)
  683. # This function will be called when user close the placer panel.
  684. # Here we will reset the self.placer back to None.
  685. # (You can think this is just like a reference count)
  686. #################################################################
  687. self.placer = None
  688. self.menuPanel.entryconfig('Placer Panel', state=NORMAL)
  689. return
  690. def openAnimPanel(self, nodePath = None):
  691. #################################################################
  692. # openAnimPanel(self, nodePath = None)
  693. # This function will be called when user tries to open an Animation Panel
  694. # This will generated a panel and put it
  695. # into a dictionary using the actor's name as an index.
  696. # So, if there already has an animation panel for the target actor,
  697. # it won't allow user to open another one.
  698. #################################################################
  699. name = nodePath.getName()
  700. if AllScene.isActor(name):
  701. if self.animPanel.has_key(name):
  702. print '---- You already have an animation panel for this Actor!'
  703. return
  704. else:
  705. Actor = AllScene.getActor(name)
  706. self.animPanel[name] = seAnimPanel.AnimPanel(aNode=Actor)
  707. pass
  708. def openMoPathPanel(self, nodepath = None):
  709. #################################################################
  710. # openMoPathPanel(self, nodepath = None)
  711. # This function will open a Motion Path Recorder for you.
  712. #################################################################
  713. if self.MopathPanel == None:
  714. self.MopathPanel = MopathRecorder()
  715. pass
  716. def mopathClosed(self):
  717. self.MopathPanel = None
  718. return
  719. def changeName(self, nodePath, nName):
  720. #################################################################
  721. # changeName(self, nodePath, nName)
  722. # This function will be called when user tries to change the name of the node
  723. #################################################################
  724. oName = nodePath.getName() # I need this line in order to check the obj name in the control panel.
  725. AllScene.rename(nodePath,nName)
  726. # reset the list in the controller panel if it has been opened.
  727. if (self.controllerPanel) != None:
  728. list = AllScene.getAllObjNameAsList()
  729. self.controllerPanel.resetNameList(list = list, name = oName, nodePath = nodePath)
  730. return
  731. # Take care things under File menu
  732. def newScene(self):
  733. #################################################################
  734. # newScene(self)
  735. # This function will clear whole stuff in the scene
  736. # and will reset the application title to "New Scene"
  737. #################################################################
  738. self.closeAllSubWindows() ## Close all sub window
  739. if(self.CurrentFileName):
  740. currentF=Filename(self.CurrentFileName)
  741. self.CurrentFileName=None
  742. AllScene.resetAll()
  743. currentModName=currentF.getBasenameWoExtension()
  744. # Let us actually remove the scene from sys modules... this is done because every scene is loaded as a module
  745. # And if we reload a scene python wont reload since its already in sys.modules... and hence we delete it
  746. # If there is ever a garbage colleciton bug..this might be a point to look at
  747. if sys.modules.has_key(currentModName):
  748. del sys.modules[currentModName]
  749. print sys.getrefcount(AllScene.theScene)
  750. del AllScene.theScene
  751. else:
  752. AllScene.resetAll()
  753. self.parent.title('Scene Editor - New Scene')
  754. pass
  755. def openScene(self):
  756. #################################################################
  757. # openScene(self)
  758. #################################################################
  759. # In the future try and provide merging of two scenes
  760. if(self.CurrentFileName or self.Dirty):
  761. saveScene = tkMessageBox._show("Load scene","Save the current scene?",icon = tkMessageBox.QUESTION,type = tkMessageBox.YESNOCANCEL)
  762. if (saveScene == "yes"):
  763. self.saveScene()
  764. elif (saveScene == "cancel"):
  765. return
  766. self.closeAllSubWindows() ## Close all sub window
  767. if(self.CurrentFileName):
  768. currentF=Filename(self.CurrentFileName)
  769. AllScene.resetAll()
  770. currentModName=currentF.getBasenameWoExtension()
  771. # Let us actually remove the scene from sys modules... this is done because every scene is loaded as a module
  772. # And if we reload a scene python wont reload since its already in sys.modules... and hence we delete it
  773. # If there is ever a garbage colleciton bug..this might be a point to look at
  774. if sys.modules.has_key(currentModName):
  775. del sys.modules[currentModName]
  776. print sys.getrefcount(AllScene.theScene)
  777. del AllScene.theScene
  778. else:
  779. AllScene.resetAll()
  780. self.CurrentFileName = AllScene.loadScene()
  781. if(self.CurrentFileName==None):
  782. return
  783. thefile=Filename(self.CurrentFileName)
  784. thedir=thefile.getFullpathWoExtension()
  785. print "SCENE EDITOR::" + thedir
  786. self.CurrentDirName=thedir
  787. if self.CurrentFileName != None:
  788. self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension())
  789. if self.lightingPanel !=None:
  790. lightList=AllScene.getList()
  791. self.lightingPanel.updateList(lightList)
  792. messenger.send('SGE_Update Explorer',[render])
  793. # Close the side window in order to reset all world settings to fit the scene we have loaded.
  794. self.sideWindow.quit()
  795. # Try to re-open the side window again
  796. while self.sideWindow == None:
  797. wColor = base.getBackgroundColor()
  798. self.worldColor[0] = wColor.getX()
  799. self.worldColor[1] = wColor.getY()
  800. self.worldColor[2] = wColor.getZ()
  801. self.worldColor[3] = wColor.getW()
  802. self.lightEnable = 1
  803. self.ParticleEnable = 1
  804. self.collision = 1
  805. self.openSideWindow()
  806. def saveScene(self):
  807. #################################################################
  808. # saveScene(self)
  809. # If this is an open file call saveAsScene
  810. # or else instantiate FileSaver from seFileSaver.py and pass it the filename
  811. # If this filename exists in sys.modules you cannot use it
  812. #################################################################
  813. if(self.CurrentFileName):
  814. f=FileSaver()
  815. f.SaveFile(AllScene,self.CurrentFileName,self.CurrentDirName,1)
  816. self.Dirty=0
  817. else:
  818. self.saveAsScene()
  819. pass
  820. def saveAsScene(self):
  821. #################################################################
  822. # saveAsScene(self)
  823. # Ask for filename using a file save dialog
  824. # If this filename exists in sys.modules you cannot use it
  825. # Instantiate FileSaver from seFileSaver.py and pass it the filename
  826. #################################################################
  827. fileName = tkFileDialog.asksaveasfilename(filetypes = [("PY","py")],title = "Save Scene")
  828. if(not fileName):
  829. return
  830. fCheck=Filename(fileName)
  831. #print fCheck.getBasenameWoExtension()
  832. ###############################################################################
  833. # !!!!! See if a module exists by this name... if it does you cannot use this filename !!!!!
  834. ###############################################################################
  835. if(sys.modules.has_key(fCheck.getBasenameWoExtension())):
  836. tkMessageBox.showwarning(
  837. "Save file",
  838. "Cannot save with this name because there is a system module with the same name. Please resave as something else."
  839. )
  840. return
  841. self.CurrentDirName=fileName
  842. fileName=fileName+".py"
  843. f=FileSaver()
  844. self.CurrentFileName=fileName
  845. f.SaveFile(AllScene,fileName,self.CurrentDirName,0)
  846. self.Dirty=0
  847. self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension())
  848. pass
  849. def loadModel(self):
  850. #################################################################
  851. # loadModel(self)
  852. # This function will be called when user tries to load a model into the scene.
  853. # Here we will pop-up a dialog to ask user which model file should be loaded in.
  854. # Then, pass the path to dataHolder to load the model in.
  855. #################################################################
  856. modelFilename = askopenfilename(
  857. defaultextension = '.egg',
  858. filetypes = (('Egg Files', '*.egg'),
  859. ('Bam Files', '*.bam'),
  860. ('All files', '*')),
  861. initialdir = '.',
  862. title = 'Load New Model',
  863. parent = self.parent)
  864. if modelFilename:
  865. self.makeDirty()
  866. if not AllScene.loadModel(modelFilename, Filename.fromOsSpecific(modelFilename)):
  867. print '----Error! No Such Model File!'
  868. pass
  869. def loadActor(self):
  870. #################################################################
  871. # loadActor(self)
  872. # This function will be called when user tries to load an Actor into the scene.
  873. # Here we will pop-up a dialog to ask user which Actor file should be loaded in.
  874. # Then, pass the path to dataHolder to load the Actor in.
  875. #################################################################
  876. ActorFilename = askopenfilename(
  877. defaultextension = '.egg',
  878. filetypes = (('Egg Files', '*.egg'),
  879. ('Bam Files', '*.bam'),
  880. ('All files', '*')),
  881. initialdir = '.',
  882. title = 'Load New Actor',
  883. parent = self.parent)
  884. if ActorFilename:
  885. self.makeDirty()
  886. if not AllScene.loadActor(ActorFilename, Filename.fromOsSpecific(ActorFilename)):
  887. print '----Error! No Such Model File!'
  888. pass
  889. def importScene(self):
  890. self.makeDirty()
  891. print '----God bless you Please Import!'
  892. pass
  893. ## Take care those things under Edit nemu
  894. def unDo(self):
  895. pass
  896. def reDo(self):
  897. pass
  898. def deSelectNode(self, nodePath=None):
  899. #################################################################
  900. # deSelectNode(self, nodePath=None)
  901. # This function will deselect the node which we have selected currently.
  902. # This will also remove the monitor task which monitor selected object's
  903. # position, orientation and scale each frame.
  904. #################################################################
  905. if nodePath != None:
  906. self.seSession.deselect(nodePath)
  907. if self.isSelect:
  908. self.isSelect = False
  909. #if self.nodeSelected != None:
  910. # self.nodeSelected.hideBounds()
  911. self.nodeSelected =None
  912. self.menuEdit.entryconfig('Deselect', state=DISABLED)
  913. self.menuEdit.entryconfig('Add Dummy', state=DISABLED)
  914. self.menuEdit.entryconfig('Duplicate', state=DISABLED)
  915. self.menuEdit.entryconfig('Remove', state=DISABLED)
  916. self.menuEdit.entryconfig('Object Properties', state=DISABLED)
  917. if self.sideWindowCount==1:
  918. self.sideWindow.SGE.deSelectTree()
  919. if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
  920. taskMgr.remove('seMonitorSelectedNode')
  921. return
  922. pass
  923. def addDummy(self):
  924. #################################################################
  925. # addDummy(self)
  926. # This function will do nothing but call other function
  927. # to add a dummy into the scene.
  928. #
  929. # Ok... this is really redundancy...
  930. #
  931. #################################################################
  932. self.addDummyNode(self.nodeSelected)
  933. pass
  934. def duplicateNode(self):
  935. #################################################################
  936. # duplicateNode(self)
  937. # This function will do nothing but call other function
  938. # to open the duplication window.
  939. #
  940. # Ok... this is really redundancy...
  941. #
  942. #################################################################
  943. if self.nodeSelected!=None:
  944. self.duplicate(self.nodeSelected)
  945. pass
  946. def removeNode(self):
  947. #################################################################
  948. # removeNode(self)
  949. # This function will do nothing but call other function
  950. # to remove the current selected node..
  951. #
  952. # Ok... this is really redundancy...
  953. #
  954. ################################################################
  955. self.remove(self.nodeSelected)
  956. pass
  957. def showObjProp(self):
  958. ################################################################
  959. # showObjProp(self)
  960. # This function will do nothing but call other function
  961. # to open the property window of current selected node..
  962. #
  963. # Ok... this is really redundancy...
  964. #
  965. ################################################################
  966. self.openPropertyPanel(self.nodeSelected)
  967. pass
  968. def showCameraSetting(self):
  969. ################################################################
  970. # showCameraSetting(self)
  971. # This function will do nothing but call other function
  972. # to open the property window of camera..
  973. #
  974. # Ok... this is really redundancy...
  975. #
  976. ################################################################
  977. self.openPropertyPanel(camera)
  978. pass
  979. def showRenderSetting(self):
  980. '''Currently, no idea what gonna pop-out here...'''
  981. pass
  982. ## Take care those thins under Edit nemu
  983. def openSideWindow(self):
  984. ################################################################
  985. # openSideWindow(self)
  986. # This function will open the side window and set the reference number
  987. # so that we can make sure there won't have two or more side windows in the same time.
  988. ################################################################
  989. if self.sideWindowCount==0:
  990. self.sideWindow = sideWindow(worldColor = self.worldColor,
  991. lightEnable = self.lightEnable,
  992. ParticleEnable = self.ParticleEnable,
  993. basedriveEnable = self.basedriveEnable,
  994. collision = self.collision,
  995. backface = self.backface,
  996. texture = self.texture,
  997. wireframe = self.wireframe,
  998. grid = self.grid,
  999. widgetVis = self.widgetVis,
  1000. enableAutoCamera = self.enableAutoCamera)
  1001. self.sideWindowCount = 1
  1002. self.menuPanel.entryconfig('Side Window', state=DISABLED)
  1003. return
  1004. def openAnimationPanel(self):
  1005. ################################################################
  1006. # openAnimationPanel(self)
  1007. # This function will do nothing but call other function
  1008. # to open the animation window for selected node(if it is an Actor)..
  1009. #
  1010. # Ok... this is really redundancy...
  1011. #
  1012. ################################################################
  1013. if AllScene.isActor(self.nodeSelected):
  1014. self.openAnimPanel(self.nodeSelected)
  1015. pass
  1016. def openMopathPanel(self):
  1017. ################################################################
  1018. # openMopathPanel(self)
  1019. # This function will create a Motion Path Recorder
  1020. ################################################################
  1021. MopathPanel = MopathRecorder()
  1022. pass
  1023. def toggleParticleVisable(self, visable):
  1024. ################################################################
  1025. # toggleParticleVisable(self, visable)
  1026. # This function will be called each time user has toggled
  1027. # the check box of Particle visibility in the side window.
  1028. # The reason we keep track this is because
  1029. # we have to know we should show/hide the model on the new-created particle
  1030. ################################################################
  1031. self.ParticleEnable = visable
  1032. AllScene.toggleParticleVisable(visable)
  1033. return
  1034. def openLightingPanel(self):
  1035. ################################################################
  1036. # openLightingPanel(self)
  1037. # open the lighting panel here.
  1038. # If there is already exist a lighting panel, then do nothing
  1039. ################################################################
  1040. if self.lightingPanel==None:
  1041. self.lightingPanel = lightingPanel(AllScene.getLightList())
  1042. self.menuPanel.entryconfig('Lighting Panel', state=DISABLED)
  1043. return
  1044. def addParticleEffect(self,effect_name,effect,node):
  1045. AllScene.particleDict[effect_name]=effect
  1046. AllScene.particleNodes[effect_name]=node
  1047. if not self.ParticleEnable:
  1048. AllScene.particleNodes[effect_name].setTransparency(True)
  1049. AllScene.particleNodes[effect_name].setAlphaScale(0)
  1050. AllScene.particleNodes[effect_name].setBin("fixed",1)
  1051. return
  1052. def openParticlePanel(self):
  1053. if self.particlePanel != None:
  1054. ## There already has a Particle panel!
  1055. return
  1056. if(len(AllScene.particleDict)==0):
  1057. self.particlePanel=seParticlePanel.ParticlePanel()
  1058. else:
  1059. for effect in AllScene.particleDict:
  1060. theeffect=AllScene.particleDict[effect]
  1061. self.particlePanel=seParticlePanel.ParticlePanel(particleEffect=theeffect,effectsDict=AllScene.particleDict)
  1062. pass
  1063. def closeParticlePanel(self):
  1064. self.particlePanel = None
  1065. return
  1066. def openInputPanel(self):
  1067. if self.controllerPanel==None:
  1068. list = AllScene.getAllObjNameAsList()
  1069. type, dataList = AllScene.getControlSetting()
  1070. self.controllerPanel = controllerWindow(listOfObj = list, controlType = type, dataList = dataList)
  1071. pass
  1072. def closeInputPanel(self):
  1073. self.controllerPanel = None
  1074. return
  1075. def requestObjFromControlW(self, name):
  1076. ################################################################
  1077. # requestObjFromControlW(self, name)
  1078. # Call back function
  1079. # Each time when user selects a node from Control Panel,
  1080. # this function will be called.
  1081. # This function will get the actual nodePath from dataHolder and then
  1082. # set it back into controller panel
  1083. ################################################################
  1084. node = AllScene.getObjFromSceneByName(name)
  1085. if (self.controllerPanel) != None and (node!=None):
  1086. self.controllerPanel.setNodePathIn(node)
  1087. return
  1088. def setControlSet(self, controlType, dataList):
  1089. if controlType == 'Keyboard':
  1090. self.controlTarget = dataList[0]
  1091. self.keyboardMapDict.clear()
  1092. self.keyboardMapDict = dataList[1].copy()
  1093. self.keyboardSpeedDict.clear()
  1094. self.keyboardSpeedDict = dataList[2].copy()
  1095. return
  1096. def startControl(self, controlType, dataList):
  1097. if not self.enableControl:
  1098. self.enableControl = True
  1099. else:
  1100. # Stop the current control setting first
  1101. # Also this will make sure we won't catch wrong keyboard message
  1102. self.stopControl(controlType)
  1103. self.enableControl = True
  1104. self.setControlSet(controlType, dataList)
  1105. self.lastContorlTimer = globalClock.getFrameTime()
  1106. if controlType == 'Keyboard':
  1107. self.controlType = 'Keyboard'
  1108. self.keyControlEventDict = {}
  1109. self.transNodeKeyboard = self.controlTarget.attachNewNode('transformNode')
  1110. self.transNodeKeyboard.hide()
  1111. for index in self.keyboardMapDict:
  1112. self.keyControlEventDict[index] = 0
  1113. self.accept(self.keyboardMapDict[index], lambda a = index:self.keyboardPushed(a))
  1114. self.accept(self.keyboardMapDict[index]+'-up', lambda a = index:self.keyboardReleased(a))
  1115. return
  1116. def stopControl(self, controlType):
  1117. if not self.enableControl:
  1118. return
  1119. if controlType == 'Keyboard':
  1120. self.enableControl = False
  1121. for index in self.keyboardMapDict:
  1122. self.ignore(self.keyboardMapDict[index])
  1123. self.ignore(self.keyboardMapDict[index]+'-up')
  1124. taskMgr.remove("KeyboardControlTask")
  1125. self.transNodeKeyboard.removeNode()
  1126. return
  1127. def keyboardPushed(self, key):
  1128. self.keyControlEventDict[key] = 1
  1129. if not taskMgr.hasTaskNamed("KeyboardControlTask"):
  1130. self.keyboardLastTimer = globalClock.getFrameTime()
  1131. taskMgr.add(self.keyboardControlTask, "KeyboardControlTask")
  1132. return
  1133. def keyboardReleased(self, key):
  1134. self.keyControlEventDict[key] = 0
  1135. for index in self.keyControlEventDict:
  1136. if self.keyControlEventDict[index] == 1:
  1137. return
  1138. if taskMgr.hasTaskNamed("KeyboardControlTask"):
  1139. taskMgr.remove("KeyboardControlTask")
  1140. return
  1141. def keyboardControlTask(self, task):
  1142. newTimer = globalClock.getFrameTime()
  1143. delta = newTimer - self.keyboardLastTimer
  1144. self.keyboardLastTimer = newTimer
  1145. pos = self.controlTarget.getPos()
  1146. hpr = self.controlTarget.getHpr()
  1147. scale = self.controlTarget.getScale()
  1148. self.transNodeKeyboard.setPosHpr((self.keyControlEventDict['KeyRight']*self.keyboardSpeedDict['SpeedRight']-self.keyControlEventDict['KeyLeft']*self.keyboardSpeedDict['SpeedLeft'])*delta,
  1149. (self.keyControlEventDict['KeyForward']*self.keyboardSpeedDict['SpeedForward']-self.keyControlEventDict['KeyBackward']*self.keyboardSpeedDict['SpeedBackward'])*delta,
  1150. (self.keyControlEventDict['KeyUp']*self.keyboardSpeedDict['SpeedUp']-self.keyControlEventDict['KeyDown']*self.keyboardSpeedDict['SpeedDown'])*delta,
  1151. (self.keyControlEventDict['KeyTurnLeft']*self.keyboardSpeedDict['SpeedTurnLeft']-self.keyControlEventDict['KeyTurnRight']*self.keyboardSpeedDict['SpeedTurnRight'])*delta,
  1152. (self.keyControlEventDict['KeyTurnUp']*self.keyboardSpeedDict['SpeedTurnUp']-self.keyControlEventDict['KeyTurnDown']*self.keyboardSpeedDict['SpeedTurnDown'])*delta,
  1153. (self.keyControlEventDict['KeyRollLeft']*self.keyboardSpeedDict['SpeedRollLeft']-self.keyControlEventDict['KeyRollRight']*self.keyboardSpeedDict['SpeedRollRight'])*delta)
  1154. newPos = self.transNodeKeyboard.getPos(self.controlTarget.getParent())
  1155. newHpr = self.transNodeKeyboard.getHpr(self.controlTarget.getParent())
  1156. overAllScale = self.keyControlEventDict['KeyScaleUp']*self.keyboardSpeedDict['SpeedScaleUp']-self.keyControlEventDict['KeyScaleDown']*self.keyboardSpeedDict['SpeedScaleDown']
  1157. newScale = Point3(scale.getX() + (overAllScale + self.keyControlEventDict['KeyScaleXUp']*self.keyboardSpeedDict['SpeedScaleXUp'] - self.keyControlEventDict['KeyScaleXDown']*self.keyboardSpeedDict['SpeedScaleXDown'])*delta,
  1158. scale.getY() + (overAllScale + self.keyControlEventDict['KeyScaleYUp']*self.keyboardSpeedDict['SpeedScaleYUp'] - self.keyControlEventDict['KeyScaleYDown']*self.keyboardSpeedDict['SpeedScaleYDown'])*delta,
  1159. scale.getZ() + (overAllScale + self.keyControlEventDict['KeyScaleZUp']*self.keyboardSpeedDict['SpeedScaleZUp'] - self.keyControlEventDict['KeyScaleZDown']*self.keyboardSpeedDict['SpeedScaleZDown'])*delta
  1160. )
  1161. self.controlTarget.setPos(newPos.getX(), newPos.getY() , newPos.getZ())
  1162. self.controlTarget.setHpr(newHpr.getX(), newHpr.getY() , newHpr.getZ())
  1163. self.controlTarget.setScale(newScale.getX(),newScale.getY(),newScale.getZ())
  1164. self.transNodeKeyboard.setPosHpr(0,0,0,0,0,0)
  1165. return Task.cont
  1166. ## Misc
  1167. ##### This one get the event from SGE (Scene Graph Explorer) and Picking
  1168. def selectNode(self, nodePath=None, callBack = True):
  1169. ################################################################
  1170. # selectNode(self, nodePath=None, callBack = True)
  1171. # This will be called when user try to select nodes from the
  1172. # side window.
  1173. # It will also call seSession to select this node in order to keep data's consistency
  1174. ################################################################
  1175. if nodePath==None:
  1176. self.isSelect = False
  1177. self.nodeSelected =None
  1178. if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
  1179. taskMgr.remove('seMonitorSelectedNode')
  1180. return
  1181. else:
  1182. self.isSelect = True
  1183. #if self.nodeSelected != None:
  1184. # self.nodeSelected.hideBounds()
  1185. self.nodeSelected = nodePath
  1186. #self.nodeSelected.showBounds()
  1187. self.menuEdit.entryconfig('Deselect', state=NORMAL)
  1188. self.menuEdit.entryconfig('Add Dummy', state=NORMAL)
  1189. self.menuEdit.entryconfig('Duplicate', state=NORMAL)
  1190. self.menuEdit.entryconfig('Remove', state=NORMAL)
  1191. self.menuEdit.entryconfig('Object Properties', state=NORMAL)
  1192. if callBack:
  1193. self.seSession.select(nodePath,fResetAncestry=1)
  1194. messenger.send('SGE_Update Explorer',[render])
  1195. if not taskMgr.hasTaskNamed('seMonitorSelectedNode'):
  1196. self.oPos = self.nodeSelected.getPos()
  1197. self.oHpr = self.nodeSelected.getHpr()
  1198. self.oScale = self.nodeSelected.getScale()
  1199. taskMgr.add(self.monitorSelectedNodeTask, 'seMonitorSelectedNode')
  1200. return
  1201. pass
  1202. def selectFromScene(self, nodePath=None, callBack=True):
  1203. ################################################################
  1204. # selectFromScene(self, nodePath=None, callBack = True)
  1205. # This will be called when user try to select nodes from the
  1206. # scene. (By picking)
  1207. # Actually this will be called by seSession
  1208. # The reason we make two selections is we don't want they call each other and never stop...
  1209. ################################################################
  1210. if nodePath==None:
  1211. self.isSelect = False
  1212. self.nodeSelected =None
  1213. if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
  1214. taskMgr.remove('seMonitorSelectedNode')
  1215. return
  1216. else:
  1217. self.isSelect = True
  1218. #if self.nodeSelected != None:
  1219. # self.nodeSelected.hideBounds()
  1220. self.nodeSelected = nodePath
  1221. #self.nodeSelected.showBounds()
  1222. self.menuEdit.entryconfig('Deselect', state=NORMAL)
  1223. self.menuEdit.entryconfig('Add Dummy', state=NORMAL)
  1224. self.menuEdit.entryconfig('Duplicate', state=NORMAL)
  1225. self.menuEdit.entryconfig('Remove', state=NORMAL)
  1226. self.menuEdit.entryconfig('Object Properties', state=NORMAL)
  1227. self.sideWindow.SGE.selectNodePath(nodePath,callBack)
  1228. messenger.send('SGE_Update Explorer',[render])
  1229. if not taskMgr.hasTaskNamed('seMonitorSelectedNode'):
  1230. self.oPos = self.nodeSelected.getPos()
  1231. self.oHpr = self.nodeSelected.getHpr()
  1232. self.oScale = self.nodeSelected.getScale()
  1233. taskMgr.add(self.monitorSelectedNodeTask, 'seMonitorSelectedNode')
  1234. return
  1235. pass
  1236. def monitorSelectedNodeTask(self, task):
  1237. ################################################################
  1238. # monitorSelectedNodeTask(self, task)
  1239. # This is a function which will keep tracking
  1240. # the position, orientation and scale data of selected node and update the display on the screen.
  1241. # Alos, it will send out message to sychronize the data in the placer and property window.
  1242. ################################################################
  1243. if self.nodeSelected != None:
  1244. pos = self.nodeSelected.getPos()
  1245. hpr = self.nodeSelected.getHpr()
  1246. scale = self.nodeSelected.getScale()
  1247. if ((self.oPos != pos )or(self.oScale != scale)or(self.oHpr != hpr)):
  1248. messenger.send('forPorpertyWindow'+self.nodeSelected.getName(),[pos, hpr, scale])
  1249. messenger.send('placerUpdate')
  1250. self.oPos = pos
  1251. self.oScale = scale
  1252. self.oHpr = hpr
  1253. self.posLabel['text'] = "Position : X: %2.2f Y: %2.2f Z: %2.2f"%(pos.getX(), pos.getY(),pos.getZ())
  1254. self.hprLabel['text'] = "Orientation: H: %2.2f P: %2.2f R: %2.2f"%(hpr.getX(), hpr.getY(),hpr.getZ())
  1255. self.scaleLabel['text'] = "Scale : X: %2.2f Y: %2.2f Z: %2.2f"%(scale.getX(), scale.getY(),scale.getZ())
  1256. return Task.cont
  1257. def deselectFromScene(self):
  1258. ################################################################
  1259. # deselectFromScene(self)
  1260. # This function will do nothing but call other function
  1261. # to delete selected node...
  1262. #
  1263. # Ok... this is really redundancy...
  1264. #
  1265. ################################################################
  1266. self.deSelectNode(self.nodeSelected)
  1267. messenger.send('SGE_Update Explorer',[render])
  1268. ##### Take care the even quest from Side Window
  1269. def lightToggle(self):
  1270. ################################################################
  1271. # lightToggle(self)
  1272. # This function will do nothing but call other function
  1273. # to toggle the light...
  1274. ################################################################
  1275. self.makeDirty()
  1276. AllScene.toggleLight()
  1277. return
  1278. def sideWindowClose(self,worldColor,lightEnable,ParticleEnable, basedriveEnable,collision,
  1279. backface, texture, wireframe, grid, widgetVis, enableAutoCamera):
  1280. ################################################################
  1281. # sideWindowClose(self,worldColor,lightEnable,ParticleEnable, basedriveEnable,collision,
  1282. # backface, texture, wireframe, grid, widgetVis, enableAutoCamera):
  1283. # This function will be called when user close the side window.
  1284. # Here we will restore all parameters about world setting back in the sceneEditor.
  1285. # So, when next time people recall the side window, it will still keep the same world setting.
  1286. ################################################################
  1287. if self.sideWindowCount==1:
  1288. self.worldColor = worldColor
  1289. self.lightEnable = lightEnable
  1290. self.ParticleEnable = ParticleEnable
  1291. self.basedriveEnable = basedriveEnable
  1292. self.collision = collision
  1293. self.backface = backface
  1294. self.texture = texture
  1295. self.wireframe = wireframe
  1296. self.grid = grid
  1297. self.enableAutoCamera = enableAutoCamera
  1298. self.widgetVis = widgetVis
  1299. self.sideWindowCount=0
  1300. self.sideWindow = None
  1301. self.menuPanel.entryconfig('Side Window', state=NORMAL)
  1302. return
  1303. ## Process message from Duplication Window
  1304. def duplicationObj(self, nodePath, pos, hpr, scale, num):
  1305. ################################################################
  1306. # duplicationObj(self, nodePath, pos, hpr, scale, num)
  1307. # This function will do nothing but call other function
  1308. # to duplicate selected node...
  1309. #
  1310. # Ok... this is really redundancy...
  1311. #
  1312. ################################################################
  1313. AllScene.duplicateObj(nodePath, pos, hpr, scale, num)
  1314. return
  1315. ## Process message from Animation Panel
  1316. def animationLoader(self, nodePath, Dic):
  1317. name = nodePath.getName()
  1318. AllScene.loadAnimation(name, Dic)
  1319. return
  1320. def animationRemove(self, nodePath, name):
  1321. AllScene.removeAnimation(nodePath.getName(),name)
  1322. return
  1323. def animPanelClose(self, name):
  1324. if self.animPanel.has_key(name):
  1325. del self.animPanel[name]
  1326. return
  1327. ### Blend Animation Panel
  1328. def openBlendAnimPanel(self, nodePath=None):
  1329. ################################################################
  1330. # openBlendAnimPanel(self, nodePath=None)
  1331. # This function will get the user defined blending animation data from dataHolder.
  1332. # And then open a blendAnimPanel by passing those data in.
  1333. ################################################################
  1334. name = nodePath.getName()
  1335. if AllScene.isActor(name):
  1336. if self.animBlendPanel.has_key(name):
  1337. print '---- You already have an Blend Animation Panel for this Actor!'
  1338. return
  1339. else:
  1340. Actor = AllScene.getActor(name)
  1341. Dict = AllScene.getBlendAnimAsDict(name)
  1342. self.animBlendPanel[name] = BlendAnimPanel(aNode=Actor, blendDict=Dict)
  1343. pass
  1344. return
  1345. def animBlendPanelSave(self, actorName, blendName, animNameA, animNameB, effect):
  1346. ################################################################
  1347. # animBlendPanelSave(self, actorName, blendName, animNameA, animNameB, effect)
  1348. # This function will call dataHolder to save the blended animation.
  1349. # Then, it will reset the newest blended animation list back to animBlendPanel
  1350. ################################################################
  1351. dict = AllScene.saveBlendAnim(actorName, blendName, animNameA, animNameB, effect)
  1352. self.animBlendPanel[actorName].setBlendAnimList(dict)
  1353. return
  1354. def animBlendPanelRemove(self, actorName, blendName):
  1355. ################################################################
  1356. # animBlendPanelRemove(self, actorName, blendName)
  1357. # This function will call dataHolder to remove the blended animation.
  1358. # Then, it will reset the newest blended animation list back to animBlendPanel
  1359. ################################################################
  1360. dict = AllScene.removeBlendAnim(actorName, blendName)
  1361. self.animBlendPanel[actorName].setBlendAnimList(dict, True)
  1362. return
  1363. def animBlendPanelRename(self, actorName, nName, oName, animNameA, animNameB, effect):
  1364. ################################################################
  1365. # animBlendPanelRename(self, actorName, nName, oName, animNameA, animNameB, effect)
  1366. # This function will call dataHolder to rename the blended animation.
  1367. # Then, it will reset the newest blended animation list back to animBlendPanel
  1368. ################################################################
  1369. dict = AllScene.renameBlendAnim(actorName, nName, oName, animNameA, animNameB, effect)
  1370. self.animBlendPanel[actorName].setBlendAnimList(dict)
  1371. return
  1372. def animBlendPanelClose(self, name):
  1373. ################################################################
  1374. # animBlendPanelClose(self, name)
  1375. # This function will be called when Blend panel has been closed.
  1376. # Here we will reset the reference dictionary so it can be open again.
  1377. ################################################################
  1378. if self.animBlendPanel.has_key(name):
  1379. del self.animBlendPanel[name]
  1380. return
  1381. ## Process message from SEditor object
  1382. def toggleWidgetVis(self):
  1383. ################################################################
  1384. # toggleWidgetVis(self)
  1385. # This function will be called when user use the hot-key to change the
  1386. # world setting. (From seSession)
  1387. # In this function we will restore the change and let side window know
  1388. # the hot-key ahs been pushed.
  1389. ################################################################
  1390. if self.sideWindow != None:
  1391. self.sideWindow.toggleWidgetVisFromMainW()
  1392. else:
  1393. self.widgetVis = (self.widgetVis+1)%2
  1394. def toggleBackface(self):
  1395. ################################################################
  1396. # toggleBackface(self)
  1397. # This function will be called when user use the hot-key to change the
  1398. # world setting. (From seSession)
  1399. # In this function we will restore the change and let side window know
  1400. # the hot-key ahs been pushed.
  1401. ################################################################
  1402. if self.sideWindow != None:
  1403. self.sideWindow.toggleBackfaceFromMainW()
  1404. else:
  1405. self.backface = (self.backface+1)%2
  1406. def toggleTexture(self):
  1407. ################################################################
  1408. # toggleTexture(self)
  1409. # This function will be called when user use the hot-key to change the
  1410. # world setting. (From seSession)
  1411. # In this function we will restore the change and let side window know
  1412. # the hot-key ahs been pushed.
  1413. ################################################################
  1414. if self.sideWindow != None:
  1415. self.sideWindow.toggleTextureFromMainW()
  1416. else:
  1417. self.texture = (self.texture+1)%2
  1418. def toggleWireframe(self):
  1419. ################################################################
  1420. # toggleWireframe(self)
  1421. # This function will be called when user use the hot-key to change the
  1422. # world setting. (From seSession)
  1423. # In this function we will restore the change and let side window know
  1424. # the hot-key ahs been pushed.
  1425. ################################################################
  1426. if self.sideWindow != None:
  1427. self.sideWindow.toggleWireframeFromMainW()
  1428. else:
  1429. self.wireframe = (self.wireframe+1)%2
  1430. def openAlignPanel(self, nodePath=None):
  1431. name = nodePath.getName()
  1432. if not self.alignPanelDict.has_key(name):
  1433. list = AllScene.getAllObjNameAsList()
  1434. if name in list:
  1435. list.remove(name)
  1436. else:
  1437. return
  1438. self.alignPanelDict[name] = AlignTool(nodePath = nodePath, list = list)
  1439. return
  1440. def closeAlignPanel(self, name=None):
  1441. if self.alignPanelDict.has_key(name):
  1442. del self.alignPanelDict[name]
  1443. def alignObject(self, nodePath, name, list):
  1444. target = AllScene.getObjFromSceneByName(name)
  1445. pos = target.getPos()
  1446. hpr = target.getHpr()
  1447. scale = target.getScale()
  1448. if list[0]: # Align X
  1449. nodePath.setX(pos.getX())
  1450. if list[1]: # Align Y
  1451. nodePath.setY(pos.getY())
  1452. if list[2]: # Align Z
  1453. nodePath.setZ(pos.getZ())
  1454. if list[3]: # Align H
  1455. nodePath.setH(hpr.getX())
  1456. if list[4]: # Align P
  1457. nodePath.setP(hpr.getY())
  1458. if list[5]: # Align R
  1459. nodePath.setR(hpr.getZ())
  1460. if list[6]: # Scale X
  1461. nodePath.setSx(scale.getX())
  1462. if list[7]: # Scale Y
  1463. nodePath.setSy(scale.getY())
  1464. if list[8]: # Scale Z
  1465. nodePath.setSz(scale.getZ())
  1466. return
  1467. ### Event from Motion Path Panel
  1468. def requestCurveList(self, nodePath,name):
  1469. curveList = AllScene.getCurveList(nodePath)
  1470. messenger.send('curveListFor'+name, [curveList])
  1471. ## Steal from DirectSession...
  1472. def flash(self, nodePath = 'None Given'):
  1473. """ Highlight an object by setting it red for a few seconds """
  1474. # Clean up any existing task
  1475. taskMgr.remove('flashNodePath')
  1476. # Spawn new task if appropriate
  1477. if nodePath == 'None Given':
  1478. # If nothing specified, try selected node path
  1479. nodePath = self.selected.last
  1480. if nodePath:
  1481. if nodePath.hasColor():
  1482. doneColor = nodePath.getColor()
  1483. flashColor = VBase4(1) - doneColor
  1484. flashColor.setW(1)
  1485. else:
  1486. doneColor = None
  1487. flashColor = VBase4(1,0,0,1)
  1488. # Temporarily set node path color
  1489. nodePath.setColor(flashColor)
  1490. # Clean up color in a few seconds
  1491. t = taskMgr.doMethodLater(1.5,
  1492. # This is just a dummy task
  1493. self.flashDummy,
  1494. 'flashNodePath')
  1495. t.nodePath = nodePath
  1496. t.doneColor = doneColor
  1497. # This really does all the work
  1498. t.uponDeath = self.flashDone
  1499. def flashDummy(self, state):
  1500. # Real work is done in upon death function
  1501. return Task.done
  1502. def flashDone(self,state):
  1503. # Return node Path to original state
  1504. if state.nodePath.isEmpty():
  1505. # Node path doesn't exist anymore, bail
  1506. return
  1507. if state.doneColor:
  1508. state.nodePath.setColor(state.doneColor)
  1509. else:
  1510. state.nodePath.clearColor()
  1511. editor = myLevelEditor(parent = tkroot)
  1512. run()