Vivek's repaired code, plus model-path stuff

This commit is contained in:
Josh Yelon 2005-04-08 20:16:47 +00:00
parent ef53db4d3b
commit 8ad4201b8f

View File

@ -1,8 +1,9 @@
from ShowBaseGlobal import* import direct
from TkGlobal import* from direct.directbase.DirectStart import*
from direct.showbase.TkGlobal import*
from tkFileDialog import * from tkFileDialog import *
from DirectGlobals import * from direct.directtools.DirectGlobals import *
from AppShell import* from direct.tkwidgets.AppShell import*
from SideWindow import* from SideWindow import*
from duplicateWindow import* from duplicateWindow import*
@ -15,7 +16,7 @@ from seFileSaver import *
from propertyWindow import * from propertyWindow import *
import seParticlePanel import seParticlePanel
from collisionWindow import * from collisionWindow import *
from DirectGui import * from direct.gui.DirectGui import *
from MetadataPanel import * from MetadataPanel import *
from seBlendAnimPanel import * from seBlendAnimPanel import *
from controllerWindow import * from controllerWindow import *
@ -25,12 +26,12 @@ from AlignTool import *
import os import os
import string import string
import Dial from direct.tkwidgets import Dial
import Floater from direct.tkwidgets import Floater
import Slider from direct.tkwidgets import Slider
import Actor from direct.actor import Actor
import seAnimPanel import seAnimPanel
import Task from direct.task import Task
import math import math
@ -97,6 +98,7 @@ class myLevelEditor(AppShell):
def __init__(self, parent = None, **kw): def __init__(self, parent = None, **kw):
base.setBackgroundColor(0,0,0) base.setBackgroundColor(0,0,0)
self.parent = parent self.parent = parent
## Check TkTool is activated! ## ## Check TkTool is activated! ##
@ -104,7 +106,7 @@ class myLevelEditor(AppShell):
if self.wantTK: if self.wantTK:
pass pass
else: else:
taskMgr.remove('tkLoop') taskMgr.remove('tkloop')
spawnTkLoop() spawnTkLoop()
## Set up window frame ## Set up window frame
INITOPT = Pmw.INITOPT INITOPT = Pmw.INITOPT
@ -147,7 +149,7 @@ class myLevelEditor(AppShell):
self.initialiseoptions(myLevelEditor) self.initialiseoptions(myLevelEditor)
self.parent.resizable(False,False) ## Disable the ability to resize for this Window. self.parent.resizable(False,False) ## Disable the ability to resize for this Window.
######### Set the event handler ########## ######### Set the event handler ##########
self.dataFlowEvents = [ self.dataFlowEvents = [
## Event from Side Window ## Event from Side Window
@ -202,14 +204,14 @@ class myLevelEditor(AppShell):
['SEditor-ToggleBackface',self.toggleBackface], ['SEditor-ToggleBackface',self.toggleBackface],
['SEditor-ToggleTexture',self.toggleTexture], ['SEditor-ToggleTexture',self.toggleTexture],
['SEditor-ToggleWireframe',self.toggleWireframe], ['SEditor-ToggleWireframe',self.toggleWireframe],
['ParticlePanel_Added_Effect',self.addParticleEffect], ['ParticlePanel_Added_Effect',self.addParticleEffect],
] ]
################################# #################################
### Collision detection ### Collision detection
################################# #################################
self.cTrav = CollisionTraverser() self.cTrav = CollisionTraverser()
base.cTrav = self.cTrav base.cTrav = self.cTrav
for event in self.dataFlowEvents: for event in self.dataFlowEvents:
@ -223,7 +225,7 @@ class myLevelEditor(AppShell):
['SGE_Remove', self.remove], ['SGE_Remove', self.remove],
['SGE_Add Dummy', self.addDummyNode], ['SGE_Add Dummy', self.addDummyNode],
['SGE_Add Collision Object', self.addCollisionObj], ['SGE_Add Collision Object', self.addCollisionObj],
['SGE_Metadata', self.openMetadataPanel], ['SGE_Metadata', self.openMetadataPanel],
['SGE_Set as Reparent Target', self.setAsReparentTarget], ['SGE_Set as Reparent Target', self.setAsReparentTarget],
['SGE_Reparent to Target', self.reparentToNode], ['SGE_Reparent to Target', self.reparentToNode],
['SGE_Animation Panel', self.openAnimPanel], ['SGE_Animation Panel', self.openAnimPanel],
@ -255,17 +257,17 @@ class myLevelEditor(AppShell):
### Create SceneEditor Ver. DirectSession ### Create SceneEditor Ver. DirectSession
self.seSession = SeSession() self.seSession = SeSession()
self.seSession.enable() self.seSession.enable()
SEditor.camera.setPos(0,-50,10) SEditor.camera.setPos(0,-50,10)
self.placer=None self.placer=None
self.MopathPanel = None self.MopathPanel = None
self.alignPanelDict = {} self.alignPanelDict = {}
#self.quadview=QuadView() #self.quadview=QuadView()
self.lightingPanel = None
self.lightingPanel = None self.controllerPanel = None
self.controllerPanel = None self.particlePanel = None
self.particlePanel = None
### Create Side Window ### Create Side Window
self.sideWindow = sideWindow(worldColor = self.worldColor, self.sideWindow = sideWindow(worldColor = self.worldColor,
@ -285,6 +287,11 @@ class myLevelEditor(AppShell):
pass pass
def getPhotoImage(self,name):
modpath = ConfigVariableSearchPath("model-path")
path = modpath.findFile(Filename(name))
return PhotoImage(file=path.toOsSpecific())
def createInterface(self): def createInterface(self):
# The interior of the toplevel panel # The interior of the toplevel panel
interior = self.interior() interior = self.interior()
@ -293,42 +300,42 @@ class myLevelEditor(AppShell):
### Creating the Buttons in the window frame ### Creating the Buttons in the window frame
####################################################### #######################################################
buttonFrame = Frame(interior) buttonFrame = Frame(interior)
self.image=[] self.image=[]
self.image.append(PhotoImage(file='new.gif'))#0
self.image.append(PhotoImage(file='open.gif'))#1
self.image.append(PhotoImage(file='save.gif'))#2
self.image.append(PhotoImage(file='model.gif'))#3
self.image.append(PhotoImage(file='actor.gif'))#4
self.image.append(PhotoImage(file='placer.gif'))#5
self.image.append(PhotoImage(file='mopath.gif'))#6
self.image.append(PhotoImage(file='lights.gif'))#7
self.image.append(PhotoImage(file='particles.gif'))#8
self.image.append(PhotoImage(file='control.gif'))
self.image.append(PhotoImage(file='help.gif'))#9
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
self.image.append(PhotoImage(file='blank.gif'))
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 i = 0
for element in self.image: for element in self.image:
i += 1 i += 1
button = Button(buttonFrame, image = element, command=lambda n=i : self.buttonPushed(n)) button = Button(buttonFrame, image = element, command=lambda n=i : self.buttonPushed(n))
button.pack(fill=X, side = LEFT) button.pack(fill=X, side = LEFT)
buttonFrame.pack(fill=X, side=LEFT,expand=True) buttonFrame.pack(fill=X, side=LEFT,expand=True)
def buttonPushed(self, buttonIndex): def buttonPushed(self, buttonIndex):
################################################################# #################################################################
# buttonPushed(self, buttonNum) # buttonPushed(self, buttonNum)
@ -339,8 +346,8 @@ class myLevelEditor(AppShell):
#### Change here to process the button event further. #### Change here to process the button event further.
#### ####
if buttonIndex==1: # New Scene if buttonIndex==1: # New Scene
self.newScene() self.newScene()
return return
elif buttonIndex==2: # Open Scene elif buttonIndex==2: # Open Scene
self.openScene() self.openScene()
return return
@ -357,13 +364,13 @@ class myLevelEditor(AppShell):
self.openPlacerPanel() self.openPlacerPanel()
return return
elif buttonIndex==7: # Open Mopath Panel elif buttonIndex==7: # Open Mopath Panel
self.openMoPathPanel() self.openMoPathPanel()
return return
elif buttonIndex==8: # Open Lighting Panel elif buttonIndex==8: # Open Lighting Panel
self.openLightingPanel() self.openLightingPanel()
return return
elif buttonIndex==9: # Open Particle Panel elif buttonIndex==9: # Open Particle Panel
self.openParticlePanel() self.openParticlePanel()
return return
elif buttonIndex==10: elif buttonIndex==10:
self.openInputPanel() self.openInputPanel()
@ -570,7 +577,7 @@ class myLevelEditor(AppShell):
## Processing message events ## Processing message events
def makeDirty(self): def makeDirty(self):
self.Dirty=1 self.Dirty=1
def removeLight(self, lightNode): def removeLight(self, lightNode):
################################################################# #################################################################
@ -627,7 +634,7 @@ class myLevelEditor(AppShell):
list, lightNode = AllScene.createLight(type = type) list, lightNode = AllScene.createLight(type = type)
if self.lightingPanel != None: if self.lightingPanel != None:
self.lightingPanel.updateList(list,lightNode) self.lightingPanel.updateList(list,lightNode)
self.makeDirty() self.makeDirty()
return return
def lightingPanelClose(self): def lightingPanelClose(self):
@ -662,9 +669,9 @@ class myLevelEditor(AppShell):
return return
def openMetadataPanel(self,nodePath=None): def openMetadataPanel(self,nodePath=None):
print nodePath print nodePath
self.MetadataPanel=MetadataPanel(nodePath) self.MetadataPanel=MetadataPanel(nodePath)
pass pass
def duplicate(self, nodePath = None): def duplicate(self, nodePath = None):
################################################################# #################################################################
@ -706,7 +713,7 @@ class myLevelEditor(AppShell):
# #
################################################################# #################################################################
AllScene.addDummyNode(nodepath) AllScene.addDummyNode(nodepath)
self.makeDirty() self.makeDirty()
pass pass
def addCollisionObj(self, nodepath = None): def addCollisionObj(self, nodepath = None):
@ -820,67 +827,67 @@ class myLevelEditor(AppShell):
# and will reset the application title to "New Scene" # and will reset the application title to "New Scene"
################################################################# #################################################################
self.closeAllSubWindows() ## Close all sub window self.closeAllSubWindows() ## Close all sub window
if(self.CurrentFileName): if(self.CurrentFileName):
currentF=Filename(self.CurrentFileName) currentF=Filename(self.CurrentFileName)
self.CurrentFileName=None self.CurrentFileName=None
AllScene.resetAll() AllScene.resetAll()
currentModName=currentF.getBasenameWoExtension() currentModName=currentF.getBasenameWoExtension()
# Let us actually remove the scene from sys modules... this is done because every scene is loaded as a module # 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 # 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 there is ever a garbage colleciton bug..this might be a point to look at
if sys.modules.has_key(currentModName): if sys.modules.has_key(currentModName):
del sys.modules[currentModName] del sys.modules[currentModName]
print sys.getrefcount(AllScene.theScene) print sys.getrefcount(AllScene.theScene)
del AllScene.theScene del AllScene.theScene
else: else:
AllScene.resetAll() AllScene.resetAll()
self.parent.title('Scene Editor - New Scene') self.parent.title('Scene Editor - New Scene')
pass pass
def openScene(self): def openScene(self):
################################################################# #################################################################
# 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): if(self.CurrentFileName or self.Dirty):
saveScene = tkMessageBox._show("Load scene","Save the current scene?",icon = tkMessageBox.QUESTION,type = tkMessageBox.YESNOCANCEL) saveScene = tkMessageBox._show("Load scene","Save the current scene?",icon = tkMessageBox.QUESTION,type = tkMessageBox.YESNOCANCEL)
if (saveScene == "yes"): if (saveScene == "yes"):
self.saveScene() self.saveScene()
elif (saveScene == "cancel"): elif (saveScene == "cancel"):
return return
self.closeAllSubWindows() ## Close all sub window self.closeAllSubWindows() ## Close all sub window
if(self.CurrentFileName): if(self.CurrentFileName):
currentF=Filename(self.CurrentFileName) currentF=Filename(self.CurrentFileName)
AllScene.resetAll() AllScene.resetAll()
currentModName=currentF.getBasenameWoExtension() currentModName=currentF.getBasenameWoExtension()
# Let us actually remove the scene from sys modules... this is done because every scene is loaded as a module # 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 # 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 there is ever a garbage colleciton bug..this might be a point to look at
if sys.modules.has_key(currentModName): if sys.modules.has_key(currentModName):
del sys.modules[currentModName] del sys.modules[currentModName]
print sys.getrefcount(AllScene.theScene) print sys.getrefcount(AllScene.theScene)
del AllScene.theScene del AllScene.theScene
else: else:
AllScene.resetAll() AllScene.resetAll()
self.CurrentFileName = AllScene.loadScene() self.CurrentFileName = AllScene.loadScene()
if(self.CurrentFileName==None):
return
if(self.CurrentFileName==None): thefile=Filename(self.CurrentFileName)
return thedir=thefile.getFullpathWoExtension()
print "SCENE EDITOR::" + thedir
thefile=Filename(self.CurrentFileName) self.CurrentDirName=thedir
thedir=thefile.getFullpathWoExtension() if self.CurrentFileName != None:
print "SCENE EDITOR::" + thedir
self.CurrentDirName=thedir
if self.CurrentFileName != None:
self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension()) self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension())
if self.lightingPanel !=None: if self.lightingPanel !=None:
lightList=AllScene.getList() lightList=AllScene.getList()
self.lightingPanel.updateList(lightList) self.lightingPanel.updateList(lightList)
messenger.send('SGE_Update Explorer',[render]) messenger.send('SGE_Update Explorer',[render])
# Close the side window in order to reset all world settings to fit the scene we have loaded. # Close the side window in order to reset all world settings to fit the scene we have loaded.
self.sideWindow.quit() self.sideWindow.quit()
@ -905,45 +912,45 @@ class myLevelEditor(AppShell):
# If this filename exists in sys.modules you cannot use it # If this filename exists in sys.modules you cannot use it
################################################################# #################################################################
if(self.CurrentFileName): if(self.CurrentFileName):
f=FileSaver() f=FileSaver()
f.SaveFile(AllScene,self.CurrentFileName,self.CurrentDirName,1) f.SaveFile(AllScene,self.CurrentFileName,self.CurrentDirName,1)
self.Dirty=0 self.Dirty=0
else: else:
self.saveAsScene() self.saveAsScene()
pass pass
def saveAsScene(self): def saveAsScene(self):
################################################################# #################################################################
# saveAsScene(self) # saveAsScene(self)
# Ask for filename using a file save dialog # Ask for filename using a file save dialog
# If this filename exists in sys.modules you cannot use it # If this filename exists in sys.modules you cannot use it
# Instantiate FileSaver from seFileSaver.py and pass it the filename # Instantiate FileSaver from seFileSaver.py and pass it the filename
################################################################# #################################################################
fileName = tkFileDialog.asksaveasfilename(filetypes = [("PY","py")],title = "Save Scene") fileName = tkFileDialog.asksaveasfilename(filetypes = [("PY","py")],title = "Save Scene")
if(not fileName): if(not fileName):
return return
fCheck=Filename(fileName) fCheck=Filename(fileName)
#print fCheck.getBasenameWoExtension() #print fCheck.getBasenameWoExtension()
############################################################################### ###############################################################################
# !!!!! See if a module exists by this name... if it does you cannot use this filename !!!!! # !!!!! See if a module exists by this name... if it does you cannot use this filename !!!!!
############################################################################### ###############################################################################
if(sys.modules.has_key(fCheck.getBasenameWoExtension())): if(sys.modules.has_key(fCheck.getBasenameWoExtension())):
tkMessageBox.showwarning( tkMessageBox.showwarning(
"Save file", "Save file",
"Cannot save with this name because there is a system module with the same name. Please resave as something else." "Cannot save with this name because there is a system module with the same name. Please resave as something else."
) )
return return
self.CurrentDirName=fileName self.CurrentDirName=fileName
fileName=fileName+".py" fileName=fileName+".py"
f=FileSaver() f=FileSaver()
self.CurrentFileName=fileName self.CurrentFileName=fileName
f.SaveFile(AllScene,fileName,self.CurrentDirName,0) f.SaveFile(AllScene,fileName,self.CurrentDirName,0)
self.Dirty=0 self.Dirty=0
self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension()) self.parent.title('Scene Editor - '+ Filename.fromOsSpecific(self.CurrentFileName).getBasenameWoExtension())
pass pass
def loadModel(self): def loadModel(self):
@ -962,7 +969,7 @@ class myLevelEditor(AppShell):
title = 'Load New Model', title = 'Load New Model',
parent = self.parent) parent = self.parent)
if modelFilename: if modelFilename:
self.makeDirty() self.makeDirty()
if not AllScene.loadModel(modelFilename, Filename.fromOsSpecific(modelFilename)): if not AllScene.loadModel(modelFilename, Filename.fromOsSpecific(modelFilename)):
print '----Error! No Such Model File!' print '----Error! No Such Model File!'
pass pass
@ -983,9 +990,9 @@ class myLevelEditor(AppShell):
title = 'Load New Actor', title = 'Load New Actor',
parent = self.parent) parent = self.parent)
if ActorFilename: if ActorFilename:
self.makeDirty() self.makeDirty()
if not AllScene.loadActor(ActorFilename, Filename.fromOsSpecific(ActorFilename)): if not AllScene.loadActor(ActorFilename, Filename.fromOsSpecific(ActorFilename)):
print '----Error! No Such Model File!' print '----Error! No Such Model File!'
pass pass
@ -1162,24 +1169,24 @@ class myLevelEditor(AppShell):
return return
def addParticleEffect(self,effect_name,effect,node): def addParticleEffect(self,effect_name,effect,node):
AllScene.particleDict[effect_name]=effect AllScene.particleDict[effect_name]=effect
AllScene.particleNodes[effect_name]=node AllScene.particleNodes[effect_name]=node
if not self.ParticleEnable: if not self.ParticleEnable:
AllScene.particleNodes[effect_name].setTransparency(True) AllScene.particleNodes[effect_name].setTransparency(True)
AllScene.particleNodes[effect_name].setAlphaScale(0) AllScene.particleNodes[effect_name].setAlphaScale(0)
AllScene.particleNodes[effect_name].setBin("fixed",1) AllScene.particleNodes[effect_name].setBin("fixed",1)
return return
def openParticlePanel(self): def openParticlePanel(self):
if self.particlePanel != None: if self.particlePanel != None:
## There already has a Particle panel! ## There already has a Particle panel!
return return
if(len(AllScene.particleDict)==0): if(len(AllScene.particleDict)==0):
self.particlePanel=seParticlePanel.ParticlePanel() self.particlePanel=seParticlePanel.ParticlePanel()
else: else:
for effect in AllScene.particleDict: for effect in AllScene.particleDict:
theeffect=AllScene.particleDict[effect] theeffect=AllScene.particleDict[effect]
self.particlePanel=seParticlePanel.ParticlePanel(particleEffect=theeffect,effectsDict=AllScene.particleDict) self.particlePanel=seParticlePanel.ParticlePanel(particleEffect=theeffect,effectsDict=AllScene.particleDict)
pass pass
@ -1325,7 +1332,7 @@ class myLevelEditor(AppShell):
self.menuEdit.entryconfig('Duplicate', state=NORMAL) self.menuEdit.entryconfig('Duplicate', state=NORMAL)
self.menuEdit.entryconfig('Remove', state=NORMAL) self.menuEdit.entryconfig('Remove', state=NORMAL)
self.menuEdit.entryconfig('Object Properties', state=NORMAL) self.menuEdit.entryconfig('Object Properties', state=NORMAL)
if callBack: if callBack:
self.seSession.select(nodePath,fResetAncestry=1) self.seSession.select(nodePath,fResetAncestry=1)
messenger.send('SGE_Update Explorer',[render]) messenger.send('SGE_Update Explorer',[render])
if not taskMgr.hasTaskNamed('seMonitorSelectedNode'): if not taskMgr.hasTaskNamed('seMonitorSelectedNode'):