| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709 |
- import sys
- try: import _tkinter
- except: sys.exit("Please install python module 'Tkinter'")
- import direct
- from direct.directbase.DirectStart import*
- from direct.showbase.TkGlobal import *
- from direct.showbase.TkGlobal import spawnTkLoop, Toplevel
- from tkFileDialog import *
- from direct.directtools.DirectGlobals import *
- from direct.tkwidgets.AppShell import*
- from SideWindow import*
- from duplicateWindow import*
- from lightingPanel import *
- from seMopathRecorder import *
- from seSession import *
- from quad import *
- from sePlacer import *
- from seFileSaver import *
- from propertyWindow import *
- import seParticlePanel
- from collisionWindow import *
- from direct.gui.DirectGui import *
- from MetadataPanel import *
- from seBlendAnimPanel import *
- from controllerWindow import *
- from AlignTool import *
- import os
- import string
- from direct.tkwidgets import Dial
- from direct.tkwidgets import Floater
- from direct.tkwidgets import Slider
- from direct.actor import Actor
- import seAnimPanel
- from direct.task import Task
- import math
- #################################################################
- # All scene and windows object will be stored in here.
- # So, any event which will or need to change contents
- # should be wirtten in here or imported into here!
- #################################################################
- from dataHolder import* ## Use this thing to Save/load data.
- AllScene = dataHolder()
- class myLevelEditor(AppShell):
- ## overridden the basic app info ##
- appname = 'Scene Editor - New Scene'
- appversion = '1.0'
- copyright = ('Copyright 2004 E.T.C. Carnegie Mellon U.' +
- ' All Rights Reserved')
- contactname = 'Jesse Schell, Shalin Shodhan & YiHong Lin'
- contactphone = '(412) 268-5791'
- contactemail = '[email protected]'
- frameWidth = 1024
- frameHeight = 80
- frameIniPosX = 0
- frameIniPosY = 0
- usecommandarea = 0
- usestatusarea = 0
- padx = 5
- pady = 5
- sideWindowCount = 0
- ## Basic World default setting (For side window)
- worldColor = [0,0,0,0]
- lightEnable = 1
- ParticleEnable = 1
- basedriveEnable = 0
- collision = 1
- backface = 0
- texture = 1
- wireframe = 0
- grid = 0
- widgetVis = 0
- enableAutoCamera = 1
- enableControl = False
- controlType = 'Keyboard'
- keyboardMapDict = {}
- keyboardSpeedDict = {}
-
- Scene=None
- isSelect = False
- nodeSelected = None
- undoDic = {}
- redoDic = {}
- animPanel = {}
- animBlendPanel = {}
- propertyWindow = {}
- CurrentFileName=None #Holds the current scene file name
- CurrentDirName=None # Holds the current file name without extension which is the path where file's data gets saved
- Dirty=0 # Keeps track of whether there are any modifications that should be saved
-
-
-
- def __init__(self, parent = None, **kw):
- base.setBackgroundColor(0,0,0)
- self.parent = parent
- ## Check TkTool is activated! ##
- self.wantTK = config.GetBool('want-tk', 0)
- if self.wantTK:
- pass
- else:
- taskMgr.remove('tkloop')
- spawnTkLoop()
- ## Set up window frame
- INITOPT = Pmw.INITOPT
- optiondefs = (
- ('title', self.appname, None),
- )
- self.defineoptions(kw, optiondefs)
- AppShell.__init__(self, parent)
- self.parent.geometry('%dx%d+%d+%d' % (self.frameWidth, self.frameHeight,self.frameIniPosX,self.frameIniPosY))
- ###### Put th directLabel on the screen to show the selected object Data
- self.posLabel = DirectLabel(
- relief = None,
- pos = (-1.3, 0, 0.90),
- text = "Position : X: 00.00 Y: 00.00 Z: 00.00",
- color = Vec4(1, 1, 1, 1),
- text_scale = 0.05,
- text_align = TextNode.ALeft
- )
- self.hprLabel = DirectLabel(
- relief = None,
- pos = (-1.3 , 0, 0.80),
- text = "Orientation: H: 00.00 P: 00.00 R: 00.00",
- color = Vec4(1, 1, 1, 1),
- text_scale = 0.05,
- text_align = TextNode.ALeft
- )
- self.scaleLabel = DirectLabel(
- relief = None,
- pos = (-1.3, 0, 0.70),
- text = "Scale : X: 00.00 Y: 00.00 Z: 00.00",
- color = Vec4(1, 1, 1, 1),
- text_scale = 0.05,
- text_align = TextNode.ALeft
- )
-
- self.initialiseoptions(myLevelEditor)
- self.parent.resizable(False,False) ## Disable the ability to resize for this Window.
-
- ######### Set the event handler ##########
- self.dataFlowEvents = [
- ## Event from Side Window
- ['SW_lightToggle',self.lightToggle],
- ['SW_collisionToggle',AllScene.toggleCollisionVisable],
- ['SW_particleToggle',self.toggleParticleVisable],
- ['SW_close',self.sideWindowClose],
- ## From Duplication Window
- ['DW_duplicating',self.duplicationObj],
- ## From Animation Panel
- ['AW_AnimationLoad',self.animationLoader],
- ['AW_removeAnim',self.animationRemove],
- ['AW_close',self.animPanelClose],
- ## From Blending Animation Window
- ['BAW_saveBlendAnim',self.animBlendPanelSave],
- ['BAW_removeBlendAnim',self.animBlendPanelRemove],
- ['BAW_renameBlendAnim',self.animBlendPanelRename],
- ['BAW_close',self.animBlendPanelClose],
- ## From Lighting Panel
- ['LP_selectLight', self.lightSelect],
- ['LP_addLight',self.addLight],
- ['LP_rename',self.lightRename],
- ['LP_removeLight',self.removeLight],
- ['LP_close',self.lightingPanelClose],
- ## From MotionPath Panel
- ['mPath_bindPathToNode',AllScene.bindCurveToNode],
- ['mPath_requestCurveList', self.requestCurveList],
- ['mPath_close', self.mopathClosed],
- ## From Property Window
- ['PW_removeCurveFromNode', AllScene.removeCurveFromNode],
- ['PW_removeAnimFromNode', AllScene.removeAnimation],
- ['PW_toggleLight', AllScene.toggleLightNode],
- ['PW_close', self.closePropertyWindow],
- ## From collisionWindow
- ['CW_addCollisionObj', AllScene.addCollisionObject],
- ## From AlignWindow
- ['ALW_close', self.closeAlignPanel],
- ['ALW_align', self.alignObject],
- ## From controllerWindow
- ['ControlW_close', self.closeInputPanel],
- ['ControlW_require', self.requestObjFromControlW],
- ['ControlW_controlSetting', self.setControlSet],
- ['ControlW_controlEnable', self.startControl],
- ['ControlW_controlDisable', self.stopControl],
- ['ControlW_saveSetting', AllScene.saveControlSetting],
- ## From Placer
- ['Placer_close', self.closePlacerPanel],
- ## From Particle Panel
- ['ParticlePanle_close', self.closeParticlePanel],
- ## From SEditor object which is a altered DirectSession
- ['SEditor-ToggleWidgetVis',self.toggleWidgetVis],
- ['SEditor-ToggleBackface',self.toggleBackface],
- ['SEditor-ToggleTexture',self.toggleTexture],
- ['SEditor-ToggleWireframe',self.toggleWireframe],
- ['ParticlePanel_Added_Effect',self.addParticleEffect],
- ['f11',self.loadFromBam],
- ['f12',self.saveAsBam],
- ]
-
- #################################
- ### Collision detection
- #################################
- self.cTrav = CollisionTraverser()
- base.cTrav = self.cTrav
- for event in self.dataFlowEvents:
- self.accept(event[0], event[1], extraArgs = event[2:])
-
- self.actionEvents = [
- # Scene graph explorer functions
- ['SGE_changeName', self.changeName],
- ['SGE_Properties', self.openPropertyPanel],
- ['SGE_Duplicate', self.duplicate],
- ['SGE_Remove', self.remove],
- ['SGE_Add Dummy', self.addDummyNode],
- ['SGE_Add Collision Object', self.addCollisionObj],
- ['SGE_Metadata', self.openMetadataPanel],
- ['SGE_Set as Reparent Target', self.setAsReparentTarget],
- ['SGE_Reparent to Target', self.reparentToNode],
- ['SGE_Animation Panel', self.openAnimPanel],
- ['SGE_Blend Animation Panel', self.openBlendAnimPanel],
- ['SGE_MoPath Panel', self.openMoPathPanel],
- ['SGE_Align Tool', self.openAlignPanel],
- ['SGE_Flash', self.flash],
- ['SGE_madeSelection', self.selectNode],
- ['select',self.selectNode],
- ['deselect', self.deSelectNode],
- ['se_selectedNodePath',self.selectFromScene],
- ['se_deselectedAll',self.deselectFromScene],
- ]
- ''' All messages starting with "SGE_" are generated in seSceneGraphExplorer'''
-
- for event in self.actionEvents:
- self.accept(event[0], event[1], extraArgs = event[2:])
- camera.toggleVis()
- self.selectNode(base.camera) ## Initially, we select camera as the first node...
- def appInit(self):
- #################################################################
- # appInit(self)
- # Initialize the application.
- # This function will be called when you call AppShell's constructor
- #################################################################
-
- ### Create SceneEditor Ver. DirectSession
- self.seSession = SeSession()
- self.seSession.enable()
- SEditor.camera.setPos(0,-50,10)
- self.placer=None
- self.MopathPanel = None
- self.alignPanelDict = {}
- #self.quadview=QuadView()
-
- self.lightingPanel = None
- self.controllerPanel = None
- self.particlePanel = None
- ### Create Side Window
- self.sideWindow = sideWindow(worldColor = self.worldColor,
- lightEnable = self.lightEnable,
- ParticleEnable = self.ParticleEnable,
- basedriveEnable = self.basedriveEnable,
- collision = self.collision,
- backface = self.backface,
- texture = self.texture,
- wireframe = self.wireframe,
- grid = self.grid,
- widgetVis = self.widgetVis,
- enableAutoCamera = self.enableAutoCamera)
- self.sideWindowCount = 1
- self.sideWindow.selectPage()
- messenger.send('SGE_Update Explorer',[render]) ## Update the Scene Graph
-
- pass
-
- def getPhotoImage(self,name):
- modpath = ConfigVariableSearchPath("model-path")
- path = modpath.findFile(Filename(name))
- return PhotoImage(file=path.toOsSpecific())
- def createInterface(self):
- # The interior of the toplevel panel
- interior = self.interior()
- #######################################################
- ### Creating the Buttons in the window frame
- #######################################################
- buttonFrame = Frame(interior)
- self.image=[]
- self.image.append(self.getPhotoImage('models/icons/new.gif'))#0
- self.image.append(self.getPhotoImage('models/icons/open.gif'))#1
- self.image.append(self.getPhotoImage('models/icons/save.gif'))#2
- self.image.append(self.getPhotoImage('models/icons/model.gif'))#3
- self.image.append(self.getPhotoImage('models/icons/actor.gif'))#4
- self.image.append(self.getPhotoImage('models/icons/placer.gif'))#5
- self.image.append(self.getPhotoImage('models/icons/mopath.gif'))#6
- self.image.append(self.getPhotoImage('models/icons/lights.gif'))#7
- self.image.append(self.getPhotoImage('models/icons/particles.gif'))#8
- self.image.append(self.getPhotoImage('models/icons/control.gif'))
- self.image.append(self.getPhotoImage('models/icons/help.gif'))#9
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- self.image.append(self.getPhotoImage('models/icons/blank.gif'))
- i = 0
- for element in self.image:
- i += 1
- button = Button(buttonFrame, image = element, command=lambda n=i : self.buttonPushed(n))
- button.pack(fill=X, side = LEFT)
-
- buttonFrame.pack(fill=X, side=LEFT,expand=True)
-
-
- def buttonPushed(self, buttonIndex):
- #################################################################
- # buttonPushed(self, buttonNum)
- # This function will handle all button events from top level window
- # Take the button index as a reference to sence which button has been pushed.
- #################################################################
- ####
- #### Change here to process the button event further.
- ####
- if buttonIndex==1: # New Scene
- self.newScene()
- return
- elif buttonIndex==2: # Open Scene
- self.openScene()
- return
- elif buttonIndex==3: # Save Scene
- self.saveScene()
- return
- elif buttonIndex==4: # Load Model
- self.loadModel()
- return
- elif buttonIndex==5: # Load Actor
- self.loadActor()
- return
- elif buttonIndex==6: # Open Placer
- self.openPlacerPanel()
- return
- elif buttonIndex==7: # Open Mopath Panel
- self.openMoPathPanel()
- return
- elif buttonIndex==8: # Open Lighting Panel
- self.openLightingPanel()
- return
- elif buttonIndex==9: # Open Particle Panel
- self.openParticlePanel()
- return
- elif buttonIndex==10:
- self.openInputPanel()
- return
- elif buttonIndex==11: # Help
- self.showAbout()
- return
- elif buttonIndex==12:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
- elif buttonIndex==13:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
- elif buttonIndex==14:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
- elif buttonIndex==15:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
- elif buttonIndex==16:
- print "Your scene will be eliminated within five seconds, Save your world!!!, Number %d."%buttonIndex
- return
- elif buttonIndex==17:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
- elif buttonIndex==18:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
- elif buttonIndex==19:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
- elif buttonIndex==20:
- print "You haven't defined the function for this Button, Number %d."%buttonIndex
- return
-
- return
- def createMenuBar(self):
- # Creates default menus. Can be overridden or simply augmented
- # Using button Add below
- self.menuBar.addmenuitem('Help', 'command',
- 'Get information on application',
- label='About...', command=self.showAbout)
- ## Creat stuff inside the "File"
- self.menuBar.addmenuitem('File', 'command', 'Creat New Scene',
- label='New Scene',
- command=self.newScene)
- self.menuBar.addmenuitem('File', 'command', 'Open a Scene',
- label='Open Scene',
- command=self.openScene)
- self.menuBar.addmenuitem('File', 'command', 'Save a Scene',
- label='Save Scene',
- command=self.saveScene)
- self.menuBar.addmenuitem('File', 'command', 'Save Scene as...',
- label='Save as...',
- command=self.saveAsScene)
- self.menuBar.addmenuitem('File', 'separator')
- self.menuBar.addmenuitem('File', 'command', 'Load Model',
- label='Load Model',
- command=self.loadModel)
- self.menuBar.addmenuitem('File', 'command', 'Load Actor',
- label='Load Actor',
- command=self.loadActor)
-
- self.menuBar.addmenuitem('File', 'separator')
- self.menuBar.addmenuitem('File', 'command', 'Import a Scene',
- label='Import...',
- command=self.importScene)
- self.menuBar.addmenuitem('File', 'separator')
-
- self.menuBar.addmenuitem('File', 'command', 'Quit this application',
- label='Exit',
- command=self.quit)
- ## Creat "Edit" on the menu and its stuff
- self.menuBar.addmenu('Edit', 'Editting tools')
- self.menuBar.addmenuitem('Edit', 'command', 'Un-do',
- label='Undo...',
- command=self.unDo)
- self.menuBar.addmenuitem('Edit', 'command', 'Re-do',
- label='Redo...',
- command=self.reDo)
- self.menuBar.addmenuitem('Edit', 'separator')
- self.menuBar.addmenuitem('Edit', 'command', 'Deselect nodepath',
- label='Deselect',
- command=self.deSelectNode)
- self.menuBar.addmenuitem('Edit', 'separator')
- self.menuBar.addmenuitem('Edit', 'command', 'Add a Dummy',
- label='Add Dummy',
- command=self.addDummy)
- self.menuBar.addmenuitem('Edit', 'command', 'Duplicate nodepath',
- label='Duplicate',
- command=self.duplicateNode)
- self.menuBar.addmenuitem('Edit', 'command', 'Remove the nodepath',
- label='Remove',
- command=self.removeNode)
- self.menuBar.addmenuitem('Edit', 'command', 'Show the object properties',
- label='Object Properties',
- command=self.showObjProp)
- self.menuBar.addmenuitem('Edit', 'separator')
- self.menuBar.addmenuitem('Edit', 'command', 'Show the Camera setting',
- label='Camera Setting',
- command=self.showCameraSetting)
- self.menuBar.addmenuitem('Edit', 'command', 'Render setting',
- label='Render Setting',
- command=self.showRenderSetting)
- ## Creat "Panel" on the menu and its stuff
- self.menuBar.addmenu('Panel', 'Panel tools')
- self.menuBar.addmenuitem('Panel', 'command', 'Open Side Window',
- label='Side Window',
- command=self.openSideWindow)
- self.menuBar.addmenuitem('Panel', 'command', 'Placer Panel',
- label='Placer Panel',
- command=self.openPlacerPanel)
- self.menuBar.addmenuitem('Panel', 'command', 'Animation Panel',
- label='Animation Panel',
- command=self.openAnimationPanel)
- self.menuBar.addmenuitem('Panel', 'command', 'Motion Path Panel',
- label='Mopath Panel',
- command=self.openMopathPanel)
- self.menuBar.addmenuitem('Panel', 'command', 'Lighting Panel',
- label='Lighting Panel',
- command=self.openLightingPanel)
- self.menuBar.addmenuitem('Panel', 'command', 'Particle Panel',
- label='Particle Panel',
- command=self.openParticlePanel)
- self.menuBar.addmenuitem('Panel', 'separator')
- self.menuBar.addmenuitem('Panel', 'command', 'Input control Panel',
- label='Input device panel',
- command=self.openInputPanel)
- self.menuBar.pack(fill=X, side = LEFT)
- ## get "Menu" items in order to control the entry status
- self.menuFile = self.menuBar.component('File-menu')
- self.menuEdit = self.menuBar.component('Edit-menu')
- self.menuPanel = self.menuBar.component('Panel-menu')
- ## Disable entries when user doesn't select anything
- if not self.isSelect:
- self.menuEdit.entryconfig('Deselect', state=DISABLED)
- self.menuEdit.entryconfig('Add Dummy', state=DISABLED)
- self.menuEdit.entryconfig('Duplicate', state=DISABLED)
- self.menuEdit.entryconfig('Remove', state=DISABLED)
- self.menuEdit.entryconfig('Object Properties', state=DISABLED)
- self.menuPanel.entryconfig('Animation Panel', state=DISABLED)
- self.menuPanel.entryconfig('Side Window', state=DISABLED)
-
- def onDestroy(self, event):
- #################################################################
- # If you have open any thing, please rewrite here!
- #################################################################
- if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
- taskMgr.remove('seMonitorSelectedNode')
- pass
- def closeAllSubWindows(self):
- #################################################################
- # closeAllSubWindows(self)
- # except side window. this function will close all sub window if there is any.
- #################################################################
- if self.lightingPanel != None:
- self.lightingPanel.quit()
- if self.placer != None:
- self.placer.quit()
- if self.MopathPanel != None:
- self.MopathPanel.quit()
- if self.particlePanel != None:
- self.particlePanel.quit()
- if self.controllerPanel != None:
- self.controllerPanel.quit()
- list = self.animPanel.keys()
- for index in list:
- self.animPanel[index].quit()
- list = self.animBlendPanel.keys()
- for index in list:
- self.animBlendPanel[index].quit()
- list = self.propertyWindow.keys()
- for index in list:
- self.propertyWindow[index].quit()
- list = self.alignPanelDict.keys()
- for index in list:
- self.alignPanelDict[index].quit()
- self.animPanel.clear()
- self.animBlendPanel.clear()
- self.propertyWindow.clear()
- self.alignPanelDict.clear()
- return
- ## Processing message events
- def makeDirty(self):
- self.Dirty=1
- def removeLight(self, lightNode):
- #################################################################
- # removeLight(self, lightNode)
- # This function will be called when user try to remove the light from lightingPanel
- # (by sending out the message)
- # So, in here we will call dataHolder(AllScene) to remove the light
- # and return a list contains the newest data of lights in he scene.
- # Then, this function will reset the lighting list in the lightingPanel
- #################################################################
- list = AllScene.removeObj(lightNode)
- if self.lightingPanel != None:
- self.lightingPanel.updateList(list)
- return
-
- def lightRename(self,oName, nName):
- #################################################################
- # lightRename(self,oName, nName)
- # This function will be called when user try to rename the light from lightingPanel
- # (by sending out the message)
- # So, in here we will call dataHolder(AllScene) to rename the light
- # and return a list contains the newest data of lights in he scene.
- # Then, this function will reset the lighting list in the lightingPanel
- #################################################################
- list, lightNode = AllScene.rename(oName, nName)
- if self.lightingPanel != None:
- self.lightingPanel.updateList(list,lightNode)
- return
-
- def lightSelect(self,lightName):
- #################################################################
- # lightSelect(self,lightName)
- # This function will be called when user try to select the light from lightingPanel
- # (by sending out the message)
- # So, in here we will call dataHolder(AllScene) to get the target light node
- # Then, this function will put this light node back into lighting
- # panel and update the data on the panel.
- #################################################################
- lightNode = AllScene.getLightNode(lightName)
- if self.lightingPanel != None:
- self.lightingPanel.updateDisplay(lightNode)
- return
-
- def addLight(self, type):
- #################################################################
- # addLight(self, type)
- # This function will be called when user try to add a light from lightingPanel
- # (by sending out the message)
- # So, in here we will call dataHolder(AllScene) to create a default light node
- # by the type that user assigned.
- # Then, this function will put this light node back into lighting
- # panel with the newest lighting list and update the data on the panel.
- #################################################################
- list, lightNode = AllScene.createLight(type = type)
- if self.lightingPanel != None:
- self.lightingPanel.updateList(list,lightNode)
- self.makeDirty()
- return
-
- def lightingPanelClose(self):
- #################################################################
- # lightingPanelClose(self)
- # This function will be called when user try to close the lighting panel
- # This function will re-config the state of the lighting panel button on the top screen
- # And it will set the self.lightingPanel to None
- #################################################################
- self.menuPanel.entryconfig('Lighting Panel', state=NORMAL)
- self.lightingPanel = None
- return
-
- def openPropertyPanel(self, nodePath = None):
- #################################################################
- # openPropertyPanel(self, nodePath = None)
- # This function will be called when user try to open a property window
- # for one specific node in the scene.
- # Here we will call dataHolder to get the basic properties
- # we would like to let user to see and cange.
- # And then we pass those information into propertyWindow
- #################################################################
- type, info = AllScene.getInfoOfThisNode(nodePath)
- name = nodePath.getName()
- if not self.propertyWindow.has_key(name):
- self.propertyWindow[name] = propertyWindow(nodePath, type,info )
- pass
- def closePropertyWindow(self, name):
- if self.propertyWindow.has_key(name):
- del self.propertyWindow[name]
- return
- def openMetadataPanel(self,nodePath=None):
- print nodePath
- self.MetadataPanel=MetadataPanel(nodePath)
- pass
- def duplicate(self, nodePath = None):
- #################################################################
- # duplicate(self, nodePath = None)
- # This function will be called when user try to open the duplication window
- #################################################################
- print '----Duplication!!'
- if nodePath != None:
- self.duplicateWindow = duplicateWindow(nodePath = nodePath)
- pass
- def remove(self, nodePath = None):
- #################################################################
- # remove(self, nodePath = None)
- # This function will be called when user try to delete a node from scene
- #
- # For safty issue,
- # we will do deselect first then remove the certain node.
- #
- #################################################################
- if nodePath==None:
- if self.nodeSelected == None:
- return
- nodePath = self.nodeSelected
- self.deSelectNode()
- if AllScene.isLight(nodePath.getName()):
- self.removeLight(nodePath)
- else:
- AllScene.removeObj(nodePath)
- pass
- def addDummyNode(self, nodepath = None):
- #################################################################
- # addDummyNode(self, nodepath = None)
- # This function will be called when user try to create a dummy node into scene
- #
- # Here we will call dataHolder to create a dummy node
- # and reparent it to the nodePath that user has assigned.
- #
- #################################################################
- AllScene.addDummyNode(nodepath)
- self.makeDirty()
- pass
- def addCollisionObj(self, nodepath = None):
- #################################################################
- # addCollisionObj(self, nodepath = None)
- # This function will be called when user try to create a collision object into the scene
- #
- # Here we will call collisionWindow to ask user what kind of collision objects they want to have.
- # Then, send the information and generated collision object to dataHolder to finish the whole process
- # and reparent it to the nodePath that user has assigned.
- #
- #################################################################
- self.collisionWindow = collisionWindow(nodepath)
- pass
- def setAsReparentTarget(self, nodepath = None):
- #################################################################
- # setAsReparentTarget(self, nodepath = None)
- # This function will be called when user select a nodePaht
- # and want to reparent other node under it. (Drom side window pop-up nemu)
- #################################################################
- SEditor.setActiveParent(nodepath)
- return
- def reparentToNode(self, nodepath = None):
- #################################################################
- # reparentToNode(self, nodepath = None)
- # This function will be call when user try to reparent a node to
- # that node he selected as a reparent target before.
- #
- # The whole reparent process is handled by seSession,
- # which is tunned from DirectSession
- #
- #################################################################
- SEditor.reparent(nodepath, fWrt = 1)
- return
-
- def openPlacerPanel(self, nodePath = None):
- #################################################################
- # openPlacerPanel(self, nodePath = None)
- # This function will be call when user try to open a placer panel.
- # This call will only success if there is no other placer panel been activated
- #################################################################
- if(self.placer==None):
- self.placer = Placer()
- self.menuPanel.entryconfig('Placer Panel', state=DISABLED)
- return
- def closePlacerPanel(self):
- #################################################################
- # closePlacerPanel(self)
- # This function will be called when user close the placer panel.
- # Here we will reset the self.placer back to None.
- # (You can think this is just like a reference count)
- #################################################################
- self.placer = None
- self.menuPanel.entryconfig('Placer Panel', state=NORMAL)
- return
-
- def openAnimPanel(self, nodePath = None):
- #################################################################
- # openAnimPanel(self, nodePath = None)
- # This function will be called when user tries to open an Animation Panel
- # This will generated a panel and put it
- # into a dictionary using the actor's name as an index.
- # So, if there already has an animation panel for the target actor,
- # it won't allow user to open another one.
- #################################################################
- name = nodePath.getName()
- if AllScene.isActor(name):
- if self.animPanel.has_key(name):
- print '---- You already have an animation panel for this Actor!'
- return
- else:
- Actor = AllScene.getActor(name)
- self.animPanel[name] = seAnimPanel.AnimPanel(aNode=Actor)
- pass
- def openMoPathPanel(self, nodepath = None):
- #################################################################
- # openMoPathPanel(self, nodepath = None)
- # This function will open a Motion Path Recorder for you.
- #################################################################
- if self.MopathPanel == None:
- self.MopathPanel = MopathRecorder()
- pass
- def mopathClosed(self):
- self.MopathPanel = None
- return
- def changeName(self, nodePath, nName):
- #################################################################
- # changeName(self, nodePath, nName)
- # This function will be called when user tries to change the name of the node
- #################################################################
- oName = nodePath.getName() # I need this line in order to check the obj name in the control panel.
- AllScene.rename(nodePath,nName)
-
- # reset the list in the controller panel if it has been opened.
- if (self.controllerPanel) != None:
- list = AllScene.getAllObjNameAsList()
- self.controllerPanel.resetNameList(list = list, name = oName, nodePath = nodePath)
- return
- # Take care things under File menu
- def newScene(self):
- #################################################################
- # newScene(self)
- # This function will clear whole stuff in the scene
- # and will reset the application title to "New Scene"
- #################################################################
- self.closeAllSubWindows() ## Close all sub window
- if(self.CurrentFileName):
- currentF=Filename(self.CurrentFileName)
- self.CurrentFileName=None
- AllScene.resetAll()
- currentModName=currentF.getBasenameWoExtension()
- # Let us actually remove the scene from sys modules... this is done because every scene is loaded as a module
- # And if we reload a scene python wont reload since its already in sys.modules... and hence we delete it
- # If there is ever a garbage colleciton bug..this might be a point to look at
- if sys.modules.has_key(currentModName):
- del sys.modules[currentModName]
- print sys.getrefcount(AllScene.theScene)
- del AllScene.theScene
- else:
- AllScene.resetAll()
- self.parent.title('Scene Editor - New Scene')
- pass
- def openScene(self):
- #################################################################
- # openScene(self)
- #################################################################
- # In the future try and provide merging of two scenes
-
- if(self.CurrentFileName or self.Dirty):
- saveScene = tkMessageBox._show("Load scene","Save the current scene?",icon = tkMessageBox.QUESTION,type = tkMessageBox.YESNOCANCEL)
- if (saveScene == "yes"):
- self.saveScene()
- elif (saveScene == "cancel"):
- return
-
- self.closeAllSubWindows() ## Close all sub window
- if(self.CurrentFileName):
- currentF=Filename(self.CurrentFileName)
- AllScene.resetAll()
- currentModName=currentF.getBasenameWoExtension()
- # Let us actually remove the scene from sys modules... this is done because every scene is loaded as a module
- # And if we reload a scene python wont reload since its already in sys.modules... and hence we delete it
- # If there is ever a garbage colleciton bug..this might be a point to look at
- if sys.modules.has_key(currentModName):
- del sys.modules[currentModName]
- print sys.getrefcount(AllScene.theScene)
- del AllScene.theScene
- else:
- AllScene.resetAll()
- self.CurrentFileName = AllScene.loadScene()
-
- if(self.CurrentFileName==None):
- return
- thefile=Filename(self.CurrentFileName)
- thedir=thefile.getFullpathWoExtension()
- print "SCENE EDITOR::" + thedir
- self.CurrentDirName=thedir
- if self.CurrentFileName != None:
- self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension())
- if self.lightingPanel !=None:
- lightList=AllScene.getList()
- self.lightingPanel.updateList(lightList)
- messenger.send('SGE_Update Explorer',[render])
-
- # Close the side window in order to reset all world settings to fit the scene we have loaded.
- self.sideWindow.quit()
- # Try to re-open the side window again
- while self.sideWindow == None:
- wColor = base.getBackgroundColor()
- self.worldColor[0] = wColor.getX()
- self.worldColor[1] = wColor.getY()
- self.worldColor[2] = wColor.getZ()
- self.worldColor[3] = wColor.getW()
- self.lightEnable = 1
- self.ParticleEnable = 1
- self.collision = 1
- self.openSideWindow()
- def saveScene(self):
- #################################################################
- # saveScene(self)
- # If this is an open file call saveAsScene
- # or else instantiate FileSaver from seFileSaver.py and pass it the filename
- # If this filename exists in sys.modules you cannot use it
- #################################################################
- if(self.CurrentFileName):
- f=FileSaver()
- f.SaveFile(AllScene,self.CurrentFileName,self.CurrentDirName,1)
- self.Dirty=0
- else:
- self.saveAsScene()
- pass
- def saveAsBam(self):
- fileName = tkFileDialog.asksaveasfilename(filetypes = [("BAM",".bam")],title = "Save Scenegraph as Bam file")
- theScene=render.find("**/Scene")
- if not theScene is None:
- theScene.writeBamFile(fileName)
- else:
- render.writeBamFile(fileName+".bad")
- print " Scenegraph saved as :" +str(fileName)
- def loadFromBam(self):
- fileName = tkFileDialog.askopenfilename(filetypes = [("BAM",".bam")],title = "Load Scenegraph from Bam file")
- if not fileName is None:
- d=path(fileName)
- scene=loader.loadModel(d.relpath())
- scene.reparentTo(render)
- def saveAsScene(self):
- #################################################################
- # saveAsScene(self)
- # Ask for filename using a file save dialog
- # If this filename exists in sys.modules you cannot use it
- # Instantiate FileSaver from seFileSaver.py and pass it the filename
- #################################################################
- fileName = tkFileDialog.asksaveasfilename(filetypes = [("PY","py")],title = "Save Scene")
- if(not fileName):
- return
- fCheck=Filename(fileName)
- #print fCheck.getBasenameWoExtension()
- ###############################################################################
- # !!!!! See if a module exists by this name... if it does you cannot use this filename !!!!!
- ###############################################################################
- if(sys.modules.has_key(fCheck.getBasenameWoExtension())):
- tkMessageBox.showwarning(
- "Save file",
- "Cannot save with this name because there is a system module with the same name. Please resave as something else."
- )
- return
- self.CurrentDirName=fileName
- fileName=fileName+".py"
- f=FileSaver()
- self.CurrentFileName=fileName
- f.SaveFile(AllScene,fileName,self.CurrentDirName,0)
- self.Dirty=0
- self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension())
- pass
- def loadModel(self):
- #################################################################
- # loadModel(self)
- # This function will be called when user tries to load a model into the scene.
- # Here we will pop-up a dialog to ask user which model file should be loaded in.
- # Then, pass the path to dataHolder to load the model in.
- #################################################################
- modelFilename = askopenfilename(
- defaultextension = '.egg',
- filetypes = (('Egg Files', '*.egg'),
- ('Bam Files', '*.bam'),
- ('All files', '*')),
- initialdir = '.',
- title = 'Load New Model',
- parent = self.parent)
- if modelFilename:
- self.makeDirty()
- if not AllScene.loadModel(modelFilename, Filename.fromOsSpecific(modelFilename)):
- print '----Error! No Such Model File!'
- pass
- def loadActor(self):
- #################################################################
- # loadActor(self)
- # This function will be called when user tries to load an Actor into the scene.
- # Here we will pop-up a dialog to ask user which Actor file should be loaded in.
- # Then, pass the path to dataHolder to load the Actor in.
- #################################################################
- ActorFilename = askopenfilename(
- defaultextension = '.egg',
- filetypes = (('Egg Files', '*.egg'),
- ('Bam Files', '*.bam'),
- ('All files', '*')),
- initialdir = '.',
- title = 'Load New Actor',
- parent = self.parent)
-
- if ActorFilename:
- self.makeDirty()
- if not AllScene.loadActor(ActorFilename, Filename.fromOsSpecific(ActorFilename)):
- print '----Error! No Such Model File!'
- pass
- def importScene(self):
- self.makeDirty()
- print '----God bless you Please Import!'
- pass
- ## Take care those things under Edit nemu
- def unDo(self):
- pass
-
- def reDo(self):
- pass
- def deSelectNode(self, nodePath=None):
- #################################################################
- # deSelectNode(self, nodePath=None)
- # This function will deselect the node which we have selected currently.
- # This will also remove the monitor task which monitor selected object's
- # position, orientation and scale each frame.
- #################################################################
- if nodePath != None:
- self.seSession.deselect(nodePath)
- if self.isSelect:
- self.isSelect = False
- #if self.nodeSelected != None:
- # self.nodeSelected.hideBounds()
- self.nodeSelected =None
- self.menuEdit.entryconfig('Deselect', state=DISABLED)
- self.menuEdit.entryconfig('Add Dummy', state=DISABLED)
- self.menuEdit.entryconfig('Duplicate', state=DISABLED)
- self.menuEdit.entryconfig('Remove', state=DISABLED)
- self.menuEdit.entryconfig('Object Properties', state=DISABLED)
- if self.sideWindowCount==1:
- self.sideWindow.SGE.deSelectTree()
- if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
- taskMgr.remove('seMonitorSelectedNode')
- return
- pass
- def addDummy(self):
- #################################################################
- # addDummy(self)
- # This function will do nothing but call other function
- # to add a dummy into the scene.
- #
- # Ok... this is really redundancy...
- #
- #################################################################
- self.addDummyNode(self.nodeSelected)
- pass
- def duplicateNode(self):
- #################################################################
- # duplicateNode(self)
- # This function will do nothing but call other function
- # to open the duplication window.
- #
- # Ok... this is really redundancy...
- #
- #################################################################
- if self.nodeSelected!=None:
- self.duplicate(self.nodeSelected)
- pass
- def removeNode(self):
- #################################################################
- # removeNode(self)
- # This function will do nothing but call other function
- # to remove the current selected node..
- #
- # Ok... this is really redundancy...
- #
- ################################################################
- self.remove(self.nodeSelected)
- pass
- def showObjProp(self):
- ################################################################
- # showObjProp(self)
- # This function will do nothing but call other function
- # to open the property window of current selected node..
- #
- # Ok... this is really redundancy...
- #
- ################################################################
- self.openPropertyPanel(self.nodeSelected)
- pass
- def showCameraSetting(self):
- ################################################################
- # showCameraSetting(self)
- # This function will do nothing but call other function
- # to open the property window of camera..
- #
- # Ok... this is really redundancy...
- #
- ################################################################
- self.openPropertyPanel(camera)
- pass
- def showRenderSetting(self):
- '''Currently, no idea what gonna pop-out here...'''
- pass
- ## Take care those thins under Edit nemu
- def openSideWindow(self):
- ################################################################
- # openSideWindow(self)
- # This function will open the side window and set the reference number
- # so that we can make sure there won't have two or more side windows in the same time.
- ################################################################
- if self.sideWindowCount==0:
- self.sideWindow = sideWindow(worldColor = self.worldColor,
- lightEnable = self.lightEnable,
- ParticleEnable = self.ParticleEnable,
- basedriveEnable = self.basedriveEnable,
- collision = self.collision,
- backface = self.backface,
- texture = self.texture,
- wireframe = self.wireframe,
- grid = self.grid,
- widgetVis = self.widgetVis,
- enableAutoCamera = self.enableAutoCamera)
- self.sideWindowCount = 1
- self.menuPanel.entryconfig('Side Window', state=DISABLED)
- return
-
- def openAnimationPanel(self):
- ################################################################
- # openAnimationPanel(self)
- # This function will do nothing but call other function
- # to open the animation window for selected node(if it is an Actor)..
- #
- # Ok... this is really redundancy...
- #
- ################################################################
- if AllScene.isActor(self.nodeSelected):
- self.openAnimPanel(self.nodeSelected)
- pass
-
- def openMopathPanel(self):
- ################################################################
- # openMopathPanel(self)
- # This function will create a Motion Path Recorder
- ################################################################
- MopathPanel = MopathRecorder()
- pass
- def toggleParticleVisable(self, visable):
- ################################################################
- # toggleParticleVisable(self, visable)
- # This function will be called each time user has toggled
- # the check box of Particle visibility in the side window.
- # The reason we keep track this is because
- # we have to know we should show/hide the model on the new-created particle
- ################################################################
- self.ParticleEnable = visable
- AllScene.toggleParticleVisable(visable)
- return
-
- def openLightingPanel(self):
- ################################################################
- # openLightingPanel(self)
- # open the lighting panel here.
- # If there is already exist a lighting panel, then do nothing
- ################################################################
- if self.lightingPanel==None:
- self.lightingPanel = lightingPanel(AllScene.getLightList())
- self.menuPanel.entryconfig('Lighting Panel', state=DISABLED)
- return
-
- def addParticleEffect(self,effect_name,effect,node):
- AllScene.particleDict[effect_name]=effect
- AllScene.particleNodes[effect_name]=node
- if not self.ParticleEnable:
- AllScene.particleNodes[effect_name].setTransparency(True)
- AllScene.particleNodes[effect_name].setAlphaScale(0)
- AllScene.particleNodes[effect_name].setBin("fixed",1)
- return
- def openParticlePanel(self):
- if self.particlePanel != None:
- ## There already has a Particle panel!
- return
- if(len(AllScene.particleDict)==0):
- self.particlePanel=seParticlePanel.ParticlePanel()
- else:
- for effect in AllScene.particleDict:
- theeffect=AllScene.particleDict[effect]
- self.particlePanel=seParticlePanel.ParticlePanel(particleEffect=theeffect,effectsDict=AllScene.particleDict)
- pass
- def closeParticlePanel(self):
- self.particlePanel = None
- return
-
- def openInputPanel(self):
- if self.controllerPanel==None:
- list = AllScene.getAllObjNameAsList()
- type, dataList = AllScene.getControlSetting()
- self.controllerPanel = controllerWindow(listOfObj = list, controlType = type, dataList = dataList)
- pass
- def closeInputPanel(self):
- self.controllerPanel = None
- return
- def requestObjFromControlW(self, name):
- ################################################################
- # requestObjFromControlW(self, name)
- # Call back function
- # Each time when user selects a node from Control Panel,
- # this function will be called.
- # This function will get the actual nodePath from dataHolder and then
- # set it back into controller panel
- ################################################################
- node = AllScene.getObjFromSceneByName(name)
-
- if (self.controllerPanel) != None and (node!=None):
- self.controllerPanel.setNodePathIn(node)
-
- return
- def setControlSet(self, controlType, dataList):
- if controlType == 'Keyboard':
- self.controlTarget = dataList[0]
- self.keyboardMapDict.clear()
- self.keyboardMapDict = dataList[1].copy()
- self.keyboardSpeedDict.clear()
- self.keyboardSpeedDict = dataList[2].copy()
- return
- def startControl(self, controlType, dataList):
- if not self.enableControl:
- self.enableControl = True
- else:
- # Stop the current control setting first
- # Also this will make sure we won't catch wrong keyboard message
- self.stopControl(controlType)
- self.enableControl = True
-
- self.setControlSet(controlType, dataList)
- self.lastContorlTimer = globalClock.getFrameTime()
- if controlType == 'Keyboard':
- self.controlType = 'Keyboard'
- self.keyControlEventDict = {}
- self.transNodeKeyboard = self.controlTarget.attachNewNode('transformNode')
- self.transNodeKeyboard.hide()
- for index in self.keyboardMapDict:
- self.keyControlEventDict[index] = 0
- self.accept(self.keyboardMapDict[index], lambda a = index:self.keyboardPushed(a))
- self.accept(self.keyboardMapDict[index]+'-up', lambda a = index:self.keyboardReleased(a))
- return
- def stopControl(self, controlType):
- if not self.enableControl:
- return
- if controlType == 'Keyboard':
- self.enableControl = False
- for index in self.keyboardMapDict:
- self.ignore(self.keyboardMapDict[index])
- self.ignore(self.keyboardMapDict[index]+'-up')
- taskMgr.remove("KeyboardControlTask")
- self.transNodeKeyboard.removeNode()
- return
- def keyboardPushed(self, key):
- self.keyControlEventDict[key] = 1
- if not taskMgr.hasTaskNamed("KeyboardControlTask"):
- self.keyboardLastTimer = globalClock.getFrameTime()
- taskMgr.add(self.keyboardControlTask, "KeyboardControlTask")
- return
- def keyboardReleased(self, key):
- self.keyControlEventDict[key] = 0
- for index in self.keyControlEventDict:
- if self.keyControlEventDict[index] == 1:
- return
- if taskMgr.hasTaskNamed("KeyboardControlTask"):
- taskMgr.remove("KeyboardControlTask")
- return
- def keyboardControlTask(self, task):
- newTimer = globalClock.getFrameTime()
- delta = newTimer - self.keyboardLastTimer
- self.keyboardLastTimer = newTimer
- pos = self.controlTarget.getPos()
- hpr = self.controlTarget.getHpr()
- scale = self.controlTarget.getScale()
- self.transNodeKeyboard.setPosHpr((self.keyControlEventDict['KeyRight']*self.keyboardSpeedDict['SpeedRight']-self.keyControlEventDict['KeyLeft']*self.keyboardSpeedDict['SpeedLeft'])*delta,
- (self.keyControlEventDict['KeyForward']*self.keyboardSpeedDict['SpeedForward']-self.keyControlEventDict['KeyBackward']*self.keyboardSpeedDict['SpeedBackward'])*delta,
- (self.keyControlEventDict['KeyUp']*self.keyboardSpeedDict['SpeedUp']-self.keyControlEventDict['KeyDown']*self.keyboardSpeedDict['SpeedDown'])*delta,
- (self.keyControlEventDict['KeyTurnLeft']*self.keyboardSpeedDict['SpeedTurnLeft']-self.keyControlEventDict['KeyTurnRight']*self.keyboardSpeedDict['SpeedTurnRight'])*delta,
- (self.keyControlEventDict['KeyTurnUp']*self.keyboardSpeedDict['SpeedTurnUp']-self.keyControlEventDict['KeyTurnDown']*self.keyboardSpeedDict['SpeedTurnDown'])*delta,
- (self.keyControlEventDict['KeyRollLeft']*self.keyboardSpeedDict['SpeedRollLeft']-self.keyControlEventDict['KeyRollRight']*self.keyboardSpeedDict['SpeedRollRight'])*delta)
- newPos = self.transNodeKeyboard.getPos(self.controlTarget.getParent())
- newHpr = self.transNodeKeyboard.getHpr(self.controlTarget.getParent())
- overAllScale = self.keyControlEventDict['KeyScaleUp']*self.keyboardSpeedDict['SpeedScaleUp']-self.keyControlEventDict['KeyScaleDown']*self.keyboardSpeedDict['SpeedScaleDown']
- newScale = Point3(scale.getX() + (overAllScale + self.keyControlEventDict['KeyScaleXUp']*self.keyboardSpeedDict['SpeedScaleXUp'] - self.keyControlEventDict['KeyScaleXDown']*self.keyboardSpeedDict['SpeedScaleXDown'])*delta,
- scale.getY() + (overAllScale + self.keyControlEventDict['KeyScaleYUp']*self.keyboardSpeedDict['SpeedScaleYUp'] - self.keyControlEventDict['KeyScaleYDown']*self.keyboardSpeedDict['SpeedScaleYDown'])*delta,
- scale.getZ() + (overAllScale + self.keyControlEventDict['KeyScaleZUp']*self.keyboardSpeedDict['SpeedScaleZUp'] - self.keyControlEventDict['KeyScaleZDown']*self.keyboardSpeedDict['SpeedScaleZDown'])*delta
- )
- self.controlTarget.setPos(newPos.getX(), newPos.getY() , newPos.getZ())
- self.controlTarget.setHpr(newHpr.getX(), newHpr.getY() , newHpr.getZ())
- self.controlTarget.setScale(newScale.getX(),newScale.getY(),newScale.getZ())
- self.transNodeKeyboard.setPosHpr(0,0,0,0,0,0)
- return Task.cont
-
- ## Misc
- ##### This one get the event from SGE (Scene Graph Explorer) and Picking
- def selectNode(self, nodePath=None, callBack = True):
- ################################################################
- # selectNode(self, nodePath=None, callBack = True)
- # This will be called when user try to select nodes from the
- # side window.
- # It will also call seSession to select this node in order to keep data's consistency
- ################################################################
- if nodePath==None:
- self.isSelect = False
- self.nodeSelected =None
- if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
- taskMgr.remove('seMonitorSelectedNode')
- return
- else:
- self.isSelect = True
- #if self.nodeSelected != None:
- # self.nodeSelected.hideBounds()
- self.nodeSelected = nodePath
- #self.nodeSelected.showBounds()
- self.menuEdit.entryconfig('Deselect', state=NORMAL)
- self.menuEdit.entryconfig('Add Dummy', state=NORMAL)
- self.menuEdit.entryconfig('Duplicate', state=NORMAL)
- self.menuEdit.entryconfig('Remove', state=NORMAL)
- self.menuEdit.entryconfig('Object Properties', state=NORMAL)
- if callBack:
- self.seSession.select(nodePath,fResetAncestry=1)
- messenger.send('SGE_Update Explorer',[render])
- if not taskMgr.hasTaskNamed('seMonitorSelectedNode'):
- self.oPos = self.nodeSelected.getPos()
- self.oHpr = self.nodeSelected.getHpr()
- self.oScale = self.nodeSelected.getScale()
- taskMgr.add(self.monitorSelectedNodeTask, 'seMonitorSelectedNode')
- return
- pass
- def selectFromScene(self, nodePath=None, callBack=True):
- ################################################################
- # selectFromScene(self, nodePath=None, callBack = True)
- # This will be called when user try to select nodes from the
- # scene. (By picking)
- # Actually this will be called by seSession
- # The reason we make two selections is we don't want they call each other and never stop...
- ################################################################
- if nodePath==None:
- self.isSelect = False
- self.nodeSelected =None
- if taskMgr.hasTaskNamed('seMonitorSelectedNode'):
- taskMgr.remove('seMonitorSelectedNode')
- return
- else:
- self.isSelect = True
- #if self.nodeSelected != None:
- # self.nodeSelected.hideBounds()
- self.nodeSelected = nodePath
- #self.nodeSelected.showBounds()
- self.menuEdit.entryconfig('Deselect', state=NORMAL)
- self.menuEdit.entryconfig('Add Dummy', state=NORMAL)
- self.menuEdit.entryconfig('Duplicate', state=NORMAL)
- self.menuEdit.entryconfig('Remove', state=NORMAL)
- self.menuEdit.entryconfig('Object Properties', state=NORMAL)
- self.sideWindow.SGE.selectNodePath(nodePath,callBack)
- messenger.send('SGE_Update Explorer',[render])
- if not taskMgr.hasTaskNamed('seMonitorSelectedNode'):
- self.oPos = self.nodeSelected.getPos()
- self.oHpr = self.nodeSelected.getHpr()
- self.oScale = self.nodeSelected.getScale()
- taskMgr.add(self.monitorSelectedNodeTask, 'seMonitorSelectedNode')
- return
- pass
- def monitorSelectedNodeTask(self, task):
- ################################################################
- # monitorSelectedNodeTask(self, task)
- # This is a function which will keep tracking
- # the position, orientation and scale data of selected node and update the display on the screen.
- # Alos, it will send out message to sychronize the data in the placer and property window.
- ################################################################
- if self.nodeSelected != None:
- pos = self.nodeSelected.getPos()
- hpr = self.nodeSelected.getHpr()
- scale = self.nodeSelected.getScale()
- if ((self.oPos != pos )or(self.oScale != scale)or(self.oHpr != hpr)):
- messenger.send('forPorpertyWindow'+self.nodeSelected.getName(),[pos, hpr, scale])
- messenger.send('placerUpdate')
- self.oPos = pos
- self.oScale = scale
- self.oHpr = hpr
- self.posLabel['text'] = "Position : X: %2.2f Y: %2.2f Z: %2.2f"%(pos.getX(), pos.getY(),pos.getZ())
- self.hprLabel['text'] = "Orientation: H: %2.2f P: %2.2f R: %2.2f"%(hpr.getX(), hpr.getY(),hpr.getZ())
- self.scaleLabel['text'] = "Scale : X: %2.2f Y: %2.2f Z: %2.2f"%(scale.getX(), scale.getY(),scale.getZ())
- return Task.cont
- def deselectFromScene(self):
- ################################################################
- # deselectFromScene(self)
- # This function will do nothing but call other function
- # to delete selected node...
- #
- # Ok... this is really redundancy...
- #
- ################################################################
- self.deSelectNode(self.nodeSelected)
- messenger.send('SGE_Update Explorer',[render])
- ##### Take care the even quest from Side Window
- def lightToggle(self):
- ################################################################
- # lightToggle(self)
- # This function will do nothing but call other function
- # to toggle the light...
- ################################################################
- self.makeDirty()
- AllScene.toggleLight()
- return
-
- def sideWindowClose(self,worldColor,lightEnable,ParticleEnable, basedriveEnable,collision,
- backface, texture, wireframe, grid, widgetVis, enableAutoCamera):
- ################################################################
- # sideWindowClose(self,worldColor,lightEnable,ParticleEnable, basedriveEnable,collision,
- # backface, texture, wireframe, grid, widgetVis, enableAutoCamera):
- # This function will be called when user close the side window.
- # Here we will restore all parameters about world setting back in the sceneEditor.
- # So, when next time people recall the side window, it will still keep the same world setting.
- ################################################################
- if self.sideWindowCount==1:
- self.worldColor = worldColor
- self.lightEnable = lightEnable
- self.ParticleEnable = ParticleEnable
- self.basedriveEnable = basedriveEnable
- self.collision = collision
- self.backface = backface
- self.texture = texture
- self.wireframe = wireframe
- self.grid = grid
- self.enableAutoCamera = enableAutoCamera
- self.widgetVis = widgetVis
- self.sideWindowCount=0
- self.sideWindow = None
- self.menuPanel.entryconfig('Side Window', state=NORMAL)
- return
- ## Process message from Duplication Window
- def duplicationObj(self, nodePath, pos, hpr, scale, num):
- ################################################################
- # duplicationObj(self, nodePath, pos, hpr, scale, num)
- # This function will do nothing but call other function
- # to duplicate selected node...
- #
- # Ok... this is really redundancy...
- #
- ################################################################
- AllScene.duplicateObj(nodePath, pos, hpr, scale, num)
- return
- ## Process message from Animation Panel
- def animationLoader(self, nodePath, Dic):
- name = nodePath.getName()
- AllScene.loadAnimation(name, Dic)
- return
- def animationRemove(self, nodePath, name):
- AllScene.removeAnimation(nodePath.getName(),name)
- return
- def animPanelClose(self, name):
- if self.animPanel.has_key(name):
- del self.animPanel[name]
- return
- ### Blend Animation Panel
- def openBlendAnimPanel(self, nodePath=None):
- ################################################################
- # openBlendAnimPanel(self, nodePath=None)
- # This function will get the user defined blending animation data from dataHolder.
- # And then open a blendAnimPanel by passing those data in.
- ################################################################
- name = nodePath.getName()
- if AllScene.isActor(name):
- if self.animBlendPanel.has_key(name):
- print '---- You already have an Blend Animation Panel for this Actor!'
- return
- else:
- Actor = AllScene.getActor(name)
- Dict = AllScene.getBlendAnimAsDict(name)
- self.animBlendPanel[name] = BlendAnimPanel(aNode=Actor, blendDict=Dict)
- pass
- return
- def animBlendPanelSave(self, actorName, blendName, animNameA, animNameB, effect):
- ################################################################
- # animBlendPanelSave(self, actorName, blendName, animNameA, animNameB, effect)
- # This function will call dataHolder to save the blended animation.
- # Then, it will reset the newest blended animation list back to animBlendPanel
- ################################################################
- dict = AllScene.saveBlendAnim(actorName, blendName, animNameA, animNameB, effect)
- self.animBlendPanel[actorName].setBlendAnimList(dict)
- return
- def animBlendPanelRemove(self, actorName, blendName):
- ################################################################
- # animBlendPanelRemove(self, actorName, blendName)
- # This function will call dataHolder to remove the blended animation.
- # Then, it will reset the newest blended animation list back to animBlendPanel
- ################################################################
- dict = AllScene.removeBlendAnim(actorName, blendName)
- self.animBlendPanel[actorName].setBlendAnimList(dict, True)
- return
- def animBlendPanelRename(self, actorName, nName, oName, animNameA, animNameB, effect):
- ################################################################
- # animBlendPanelRename(self, actorName, nName, oName, animNameA, animNameB, effect)
- # This function will call dataHolder to rename the blended animation.
- # Then, it will reset the newest blended animation list back to animBlendPanel
- ################################################################
- dict = AllScene.renameBlendAnim(actorName, nName, oName, animNameA, animNameB, effect)
- self.animBlendPanel[actorName].setBlendAnimList(dict)
- return
- def animBlendPanelClose(self, name):
- ################################################################
- # animBlendPanelClose(self, name)
- # This function will be called when Blend panel has been closed.
- # Here we will reset the reference dictionary so it can be open again.
- ################################################################
- if self.animBlendPanel.has_key(name):
- del self.animBlendPanel[name]
- return
- ## Process message from SEditor object
- def toggleWidgetVis(self):
- ################################################################
- # toggleWidgetVis(self)
- # This function will be called when user use the hot-key to change the
- # world setting. (From seSession)
- # In this function we will restore the change and let side window know
- # the hot-key ahs been pushed.
- ################################################################
- if self.sideWindow != None:
- self.sideWindow.toggleWidgetVisFromMainW()
- else:
- self.widgetVis = (self.widgetVis+1)%2
- def toggleBackface(self):
- ################################################################
- # toggleBackface(self)
- # This function will be called when user use the hot-key to change the
- # world setting. (From seSession)
- # In this function we will restore the change and let side window know
- # the hot-key ahs been pushed.
- ################################################################
- if self.sideWindow != None:
- self.sideWindow.toggleBackfaceFromMainW()
- else:
- self.backface = (self.backface+1)%2
- def toggleTexture(self):
- ################################################################
- # toggleTexture(self)
- # This function will be called when user use the hot-key to change the
- # world setting. (From seSession)
- # In this function we will restore the change and let side window know
- # the hot-key ahs been pushed.
- ################################################################
- if self.sideWindow != None:
- self.sideWindow.toggleTextureFromMainW()
- else:
- self.texture = (self.texture+1)%2
- def toggleWireframe(self):
- ################################################################
- # toggleWireframe(self)
- # This function will be called when user use the hot-key to change the
- # world setting. (From seSession)
- # In this function we will restore the change and let side window know
- # the hot-key ahs been pushed.
- ################################################################
- if self.sideWindow != None:
- self.sideWindow.toggleWireframeFromMainW()
- else:
- self.wireframe = (self.wireframe+1)%2
- def openAlignPanel(self, nodePath=None):
- name = nodePath.getName()
- if not self.alignPanelDict.has_key(name):
- list = AllScene.getAllObjNameAsList()
- if name in list:
- list.remove(name)
- else:
- return
- self.alignPanelDict[name] = AlignTool(nodePath = nodePath, list = list)
- return
- def closeAlignPanel(self, name=None):
- if self.alignPanelDict.has_key(name):
- del self.alignPanelDict[name]
- def alignObject(self, nodePath, name, list):
- target = AllScene.getObjFromSceneByName(name)
- pos = target.getPos()
- hpr = target.getHpr()
- scale = target.getScale()
- if list[0]: # Align X
- nodePath.setX(pos.getX())
- if list[1]: # Align Y
- nodePath.setY(pos.getY())
- if list[2]: # Align Z
- nodePath.setZ(pos.getZ())
- if list[3]: # Align H
- nodePath.setH(hpr.getX())
- if list[4]: # Align P
- nodePath.setP(hpr.getY())
- if list[5]: # Align R
- nodePath.setR(hpr.getZ())
- if list[6]: # Scale X
- nodePath.setSx(scale.getX())
- if list[7]: # Scale Y
- nodePath.setSy(scale.getY())
- if list[8]: # Scale Z
- nodePath.setSz(scale.getZ())
- return
- ### Event from Motion Path Panel
- def requestCurveList(self, nodePath,name):
- curveList = AllScene.getCurveList(nodePath)
- messenger.send('curveListFor'+name, [curveList])
- ## Steal from DirectSession...
- def flash(self, nodePath = 'None Given'):
- """ Highlight an object by setting it red for a few seconds """
- # Clean up any existing task
- taskMgr.remove('flashNodePath')
- # Spawn new task if appropriate
- if nodePath == 'None Given':
- # If nothing specified, try selected node path
- nodePath = self.selected.last
- if nodePath:
- if nodePath.hasColor():
- doneColor = nodePath.getColor()
- flashColor = VBase4(1) - doneColor
- flashColor.setW(1)
- else:
- doneColor = None
- flashColor = VBase4(1,0,0,1)
- # Temporarily set node path color
- nodePath.setColor(flashColor)
- # Clean up color in a few seconds
- t = taskMgr.doMethodLater(1.5,
- # This is just a dummy task
- self.flashDummy,
- 'flashNodePath')
- t.nodePath = nodePath
- t.doneColor = doneColor
- # This really does all the work
- t.uponDeath = self.flashDone
-
- def flashDummy(self, state):
- # Real work is done in upon death function
- return Task.done
-
- def flashDone(self,state):
- # Return node Path to original state
- if state.nodePath.isEmpty():
- # Node path doesn't exist anymore, bail
- return
- if state.doneColor:
- state.nodePath.setColor(state.doneColor)
- else:
- state.nodePath.clearColor()
-
- editor = myLevelEditor(parent = tkroot)
- run()
|