sceneEditor.py 73 KB

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