From c3810fc782d83c225056e930f40fadf3bef57825 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Tue, 24 Jan 2006 07:52:54 +0000 Subject: [PATCH] Fixed a lot of old stuff --- doc/SceneEditor/dataHolder.py | 4 +- doc/SceneEditor/quad.py | 3 +- doc/SceneEditor/sceneEditor.py | 244 +++++++++++++++++--------------- doc/SceneEditor/seFileSaver.py | 27 ++-- doc/SceneEditor/seForceGroup.py | 4 +- doc/SceneEditor/seParticles.py | 42 +++--- doc/SceneEditor/seSelection.py | 3 +- 7 files changed, 175 insertions(+), 152 deletions(-) diff --git a/doc/SceneEditor/dataHolder.py b/doc/SceneEditor/dataHolder.py index 6e39a91ed9..5378b129d3 100644 --- a/doc/SceneEditor/dataHolder.py +++ b/doc/SceneEditor/dataHolder.py @@ -750,8 +750,8 @@ class dataHolder: if self.collisionVisable: self.collisionDict[name].show() - - base.cTrav.addCollider(node, self.CollisionHandler) + #Manakel 2/12/2005: replace node by its nodepath + base.cTrav.addCollider( self.collisionDict[name], self.CollisionHandler) messenger.send('SGE_Update Explorer',[render]) diff --git a/doc/SceneEditor/quad.py b/doc/SceneEditor/quad.py index d35a7453ef..656345195a 100644 --- a/doc/SceneEditor/quad.py +++ b/doc/SceneEditor/quad.py @@ -10,7 +10,8 @@ from direct.showbase.ShowBaseGlobal import * from direct.interval.IntervalGlobal import * from direct.showbase import DirectObject import math -from pandac.MouseWatcher import * +#Manakel 2/12/2005: replace from pandac import by from pandac.PandaModules import +from pandac.PandaModules import MouseWatcher class ViewPort: diff --git a/doc/SceneEditor/sceneEditor.py b/doc/SceneEditor/sceneEditor.py index 3dce47db23..dfc9efa3ba 100644 --- a/doc/SceneEditor/sceneEditor.py +++ b/doc/SceneEditor/sceneEditor.py @@ -38,6 +38,7 @@ from direct.actor import Actor import seAnimPanel from direct.task import Task import math +from path import path ################################################################# @@ -154,7 +155,7 @@ class myLevelEditor(AppShell): 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 @@ -209,14 +210,16 @@ class myLevelEditor(AppShell): ['SEditor-ToggleBackface',self.toggleBackface], ['SEditor-ToggleTexture',self.toggleTexture], ['SEditor-ToggleWireframe',self.toggleWireframe], - ['ParticlePanel_Added_Effect',self.addParticleEffect], + ['ParticlePanel_Added_Effect',self.addParticleEffect], + ['f11',self.loadFromBam], + ['f12',self.saveAsBam], ] ################################# ### Collision detection ################################# - self.cTrav = CollisionTraverser() + self.cTrav = CollisionTraverser() base.cTrav = self.cTrav for event in self.dataFlowEvents: @@ -230,7 +233,7 @@ class myLevelEditor(AppShell): ['SGE_Remove', self.remove], ['SGE_Add Dummy', self.addDummyNode], ['SGE_Add Collision Object', self.addCollisionObj], - ['SGE_Metadata', self.openMetadataPanel], + ['SGE_Metadata', self.openMetadataPanel], ['SGE_Set as Reparent Target', self.setAsReparentTarget], ['SGE_Reparent to Target', self.reparentToNode], ['SGE_Animation Panel', self.openAnimPanel], @@ -262,17 +265,17 @@ class myLevelEditor(AppShell): ### Create SceneEditor Ver. DirectSession self.seSession = SeSession() self.seSession.enable() - SEditor.camera.setPos(0,-50,10) + SEditor.camera.setPos(0,-50,10) - self.placer=None - self.MopathPanel = None - self.alignPanelDict = {} - #self.quadview=QuadView() - + self.placer=None + self.MopathPanel = None + self.alignPanelDict = {} + #self.quadview=QuadView() + - self.lightingPanel = None - self.controllerPanel = None - self.particlePanel = None + self.lightingPanel = None + self.controllerPanel = None + self.particlePanel = None ### Create Side Window self.sideWindow = sideWindow(worldColor = self.worldColor, @@ -305,7 +308,7 @@ class myLevelEditor(AppShell): ### Creating the Buttons in the window frame ####################################################### buttonFrame = Frame(interior) - self.image=[] + self.image=[] self.image.append(self.getPhotoImage('models/icons/new.gif'))#0 self.image.append(self.getPhotoImage('models/icons/open.gif'))#1 @@ -327,20 +330,20 @@ class myLevelEditor(AppShell): 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) @@ -351,8 +354,8 @@ class myLevelEditor(AppShell): #### Change here to process the button event further. #### if buttonIndex==1: # New Scene - self.newScene() - return + self.newScene() + return elif buttonIndex==2: # Open Scene self.openScene() return @@ -369,13 +372,13 @@ class myLevelEditor(AppShell): self.openPlacerPanel() return elif buttonIndex==7: # Open Mopath Panel - self.openMoPathPanel() + self.openMoPathPanel() return elif buttonIndex==8: # Open Lighting Panel self.openLightingPanel() return elif buttonIndex==9: # Open Particle Panel - self.openParticlePanel() + self.openParticlePanel() return elif buttonIndex==10: self.openInputPanel() @@ -582,7 +585,7 @@ class myLevelEditor(AppShell): ## Processing message events def makeDirty(self): - self.Dirty=1 + self.Dirty=1 def removeLight(self, lightNode): ################################################################# @@ -639,7 +642,7 @@ class myLevelEditor(AppShell): list, lightNode = AllScene.createLight(type = type) if self.lightingPanel != None: self.lightingPanel.updateList(list,lightNode) - self.makeDirty() + self.makeDirty() return def lightingPanelClose(self): @@ -674,9 +677,9 @@ class myLevelEditor(AppShell): return def openMetadataPanel(self,nodePath=None): - print nodePath - self.MetadataPanel=MetadataPanel(nodePath) - pass + print nodePath + self.MetadataPanel=MetadataPanel(nodePath) + pass def duplicate(self, nodePath = None): ################################################################# @@ -718,7 +721,7 @@ class myLevelEditor(AppShell): # ################################################################# AllScene.addDummyNode(nodepath) - self.makeDirty() + self.makeDirty() pass def addCollisionObj(self, nodepath = None): @@ -832,67 +835,67 @@ class myLevelEditor(AppShell): # 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 + 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') + 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 - + # 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 + 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 + 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() + AllScene.resetAll() - self.CurrentFileName = AllScene.loadScene() - - if(self.CurrentFileName==None): - return + 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: + 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: + 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() @@ -917,45 +920,60 @@ class myLevelEditor(AppShell): # 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() + 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) + # 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( + 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" + 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()) + 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): @@ -974,7 +992,7 @@ class myLevelEditor(AppShell): title = 'Load New Model', parent = self.parent) if modelFilename: - self.makeDirty() + self.makeDirty() if not AllScene.loadModel(modelFilename, Filename.fromOsSpecific(modelFilename)): print '----Error! No Such Model File!' pass @@ -995,9 +1013,9 @@ class myLevelEditor(AppShell): title = 'Load New Actor', parent = self.parent) - + if ActorFilename: - self.makeDirty() + self.makeDirty() if not AllScene.loadActor(ActorFilename, Filename.fromOsSpecific(ActorFilename)): print '----Error! No Such Model File!' pass @@ -1174,24 +1192,24 @@ class myLevelEditor(AppShell): return def addParticleEffect(self,effect_name,effect,node): - AllScene.particleDict[effect_name]=effect - AllScene.particleNodes[effect_name]=node - if not self.ParticleEnable: + 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 + 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) + 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 @@ -1337,7 +1355,7 @@ class myLevelEditor(AppShell): self.menuEdit.entryconfig('Duplicate', state=NORMAL) self.menuEdit.entryconfig('Remove', state=NORMAL) self.menuEdit.entryconfig('Object Properties', state=NORMAL) - if callBack: + if callBack: self.seSession.select(nodePath,fResetAncestry=1) messenger.send('SGE_Update Explorer',[render]) if not taskMgr.hasTaskNamed('seMonitorSelectedNode'): diff --git a/doc/SceneEditor/seFileSaver.py b/doc/SceneEditor/seFileSaver.py index 6fec28658e..bdf2931c6a 100644 --- a/doc/SceneEditor/seFileSaver.py +++ b/doc/SceneEditor/seFileSaver.py @@ -360,17 +360,19 @@ class FileSaver: if(ActorAnimations!={}): #Check if a dictionary of animations exists for this actor for animation in ActorAnimations: #out_file.write(i2+ "self."+ actorS + ".loadAnims(" + str(ActorAnimations) +")\n") # Old way with absolute paths - print "ACTOR ANIMATIONS" + ActorAnimations[animation] - oldAnimPath=Filename(ActorAnimations[animation]) - oldAnim=oldAnimPath.toOsSpecific() - dirOS=Filename(dirname) - newAnim=dirOS.toOsSpecific() + "\\" + oldAnimPath.getBasename() - print "ACTOR ANIM SAVER:: Comparing" + oldAnim +"and" + newAnim - if(oldAnim!=newAnim): - shutil.copyfile(oldAnim,newAnim) - newAnimF=Filename.fromOsSpecific(newAnim) - ActorAnimationsInvoke[animation]="self.executionpath +" + "/" +newAnimF.getBasename() - ActorAnimations[animation]= self.savepath + "/" + newAnimF.getBasename() + #Manakel 2/12/2004: solve the not empty but not defined animation case + if not animation is None: + print "ACTOR ANIMATIONS:" + ActorAnimations[animation] + oldAnimPath=Filename(ActorAnimations[animation]) + oldAnim=oldAnimPath.toOsSpecific() + dirOS=Filename(dirname) + newAnim=dirOS.toOsSpecific() + "\\" + oldAnimPath.getBasename() + print "ACTOR ANIM SAVER:: Comparing" + oldAnim +"and" + newAnim + if(oldAnim!=newAnim): + shutil.copyfile(oldAnim,newAnim) + newAnimF=Filename.fromOsSpecific(newAnim) + ActorAnimationsInvoke[animation]="self.executionpath +" + "/" +newAnimF.getBasename() + ActorAnimations[animation]= self.savepath + "/" + newAnimF.getBasename() out_file.write(i2+"if(self.loadmode==1):\n") @@ -695,7 +697,8 @@ class FileSaver: if(parentname=="render" or parentname =="camera"): out_file.write(i2+"self.collisionDict[\"" + collnodeS + "\"]="+ parentname + ".attachNewNode(self." + collnodeS + "_Node)\n") else: - if(AllScene.particleDict.has_key(parent)): + #Manakel 2/12/2005: parent replaced by parent Name but why Parent name in partice and parent for other objects? + if(AllScene.particleDict.has_key(parentname)): out_file.write(i2+"self.collisionDict[\"" + collnodeS + "\"]=self."+ parentname + "getEffect().attachNewNode(self." + collnodeS + "_Node)\n") else: out_file.write(i2+"self.collisionDict[\"" + collnodeS + "\"]=self."+ parentname + ".attachNewNode(self." + collnodeS + "_Node)\n") diff --git a/doc/SceneEditor/seForceGroup.py b/doc/SceneEditor/seForceGroup.py index a62008ac2b..5b83f767d2 100644 --- a/doc/SceneEditor/seForceGroup.py +++ b/doc/SceneEditor/seForceGroup.py @@ -1,8 +1,8 @@ from pandac.PandaModules import * from direct.showbase.DirectObject import * from direct.showbase.PhysicsManagerGlobal import * - -from pandac import ForceNode +#Manakel 2/12/2005: replace from pandac import by from pandac.PandaModules import +from pandac.PandaModules import ForceNode from direct.directnotify import DirectNotifyGlobal import sys diff --git a/doc/SceneEditor/seParticles.py b/doc/SceneEditor/seParticles.py index 2a317020d8..66a23dec9e 100644 --- a/doc/SceneEditor/seParticles.py +++ b/doc/SceneEditor/seParticles.py @@ -1,28 +1,28 @@ from pandac.PandaModules import * from direct.particles.ParticleManagerGlobal import * from direct.showbase.PhysicsManagerGlobal import * - -from pandac import ParticleSystem -from pandac import BaseParticleFactory -from pandac import PointParticleFactory -from pandac import ZSpinParticleFactory +#Manakel 2/12/2005: replace from pandac import by from pandac.PandaModules import +from pandac.PandaModules import ParticleSystem +from pandac.PandaModules import BaseParticleFactory +from pandac.PandaModules import PointParticleFactory +from pandac.PandaModules import ZSpinParticleFactory #import OrientedParticleFactory -from pandac import BaseParticleRenderer -from pandac import PointParticleRenderer -from pandac import LineParticleRenderer -from pandac import GeomParticleRenderer -from pandac import SparkleParticleRenderer -from pandac import SpriteParticleRenderer -from pandac import BaseParticleEmitter -from pandac import BoxEmitter -from pandac import DiscEmitter -from pandac import LineEmitter -from pandac import PointEmitter -from pandac import RectangleEmitter -from pandac import RingEmitter -from pandac import SphereSurfaceEmitter -from pandac import SphereVolumeEmitter -from pandac import TangentRingEmitter +from pandac.PandaModules import BaseParticleRenderer +from pandac.PandaModules import PointParticleRenderer +from pandac.PandaModules import LineParticleRenderer +from pandac.PandaModules import GeomParticleRenderer +from pandac.PandaModules import SparkleParticleRenderer +from pandac.PandaModules import SpriteParticleRenderer +from pandac.PandaModules import BaseParticleEmitter +from pandac.PandaModules import BoxEmitter +from pandac.PandaModules import DiscEmitter +from pandac.PandaModules import LineEmitter +from pandac.PandaModules import PointEmitter +from pandac.PandaModules import RectangleEmitter +from pandac.PandaModules import RingEmitter +from pandac.PandaModules import SphereSurfaceEmitter +from pandac.PandaModules import SphereVolumeEmitter +from pandac.PandaModules import TangentRingEmitter import string import os from direct.directnotify import DirectNotifyGlobal diff --git a/doc/SceneEditor/seSelection.py b/doc/SceneEditor/seSelection.py index 212a51906c..2ec2ae25c3 100644 --- a/doc/SceneEditor/seSelection.py +++ b/doc/SceneEditor/seSelection.py @@ -403,7 +403,8 @@ class SelectionQueue(CollisionHandlerQueue): # And a traverser to do the actual collision tests self.ct = CollisionTraverser() # Let the traverser know about the collision node and the queue - self.ct.addCollider(self.collisionNode, self) + #Manakel 2/12/2005: replace CollisionNode by its nodepath + self.ct.addCollider(self.collisionNodePath, self) # List of objects that can't be selected self.unpickable = UNPICKABLE # Derived class must add Collider to complete initialization