def OnCreate(self, e): self.Unbind(wx.EVT_INIT_DIALOG) base.le.ui.bindKeyEvents(False) self.filename = None self.name = '' self.Ok = False self.assetType = "Static Mesh" self.importScene = NodePath(PandaNode("importScene")) self.import2d = NodePath(PandaNode("import2d")) self.import2dScaled = self.import2d.attachNewNode( PandaNode("import2dScaled")) self.objPreview = None self.thumbnailTaken = False self.Bind(wx.EVT_CLOSE, self.Close) base.direct.manipulationControl.disableManipulation() self.Show() #init all the panels from XRC for parenting later on self.mainPanel = xrc.XRCCTRL(self, "mainPanel") self.pandaPanel = xrc.XRCCTRL(self, "pandaPanel") self.animPanel = xrc.XRCCTRL(self, "animPanel") self.libraryPanel = xrc.XRCCTRL(self, "libraryPanel") self.typeSelector = xrc.XRCCTRL(self.libraryPanel, 'choiceAssetType') self.typeSelector.Bind(wx.EVT_CHOICE, self.onSwitchType) self.typeSelector.SetStringSelection(self.assetType) self.btnScreenshot = xrc.XRCCTRL(self.mainPanel, "btnScreenShot") self.btnScreenshot.Bind(wx.EVT_BUTTON, self.onScreenShot) self.btnScreenshot.Disable() self.imgThumbnail = xrc.XRCCTRL(self.libraryPanel, 'imgThumbnail') self.btnPlay = xrc.XRCCTRL(self.libraryPanel, "btnPlay") self.btnStop = xrc.XRCCTRL(self.libraryPanel, "btnStop") self.viewport = Viewport('persp', self.pandaPanel) self.viewport.SetClientSize((500, 500)) ViewportManager.updateAll() base.le.ui.wxStep() self.viewport.initialize() self.handles = ObjectHandles('importUIWidget') self.handles.hide() base.direct.manipulationControl.widgetList.append(self.handles) base.direct.drList.addDisplayRegionContext(self.viewport.cam) #apply a mask to make sure GUI stuff from the main window doesn't show up here self.viewport.cam2d.node().setCameraMask(LE_IMPORT_MASK) self.viewport.camera.reparentTo(self.importScene) self.viewport.camera.setPos(-19, -19, 19) self.viewport.camera.lookAt(0, 0, 0) self.viewport.cam2d.reparentTo(self.import2d) dlight = DirectionalLight('dlight') dlight.setColor(VBase4(0.8, 0.8, 0.8, 1)) dlnp = self.importScene.attachNewNode(dlight) self.importScene.setLight(dlnp) dlnp.setHpr(45, -45, 0) alight = AmbientLight('alight') alight.setColor(VBase4(0.25, 0.25, 0.25, 1)) alnp = self.importScene.attachNewNode(alight) self.importScene.setLight(alnp) fileSelector = xrc.XRCCTRL(self.mainPanel, 'btnLoadAsset') fileSelector.Bind(wx.EVT_BUTTON, self.onFileSelect) if self.assetType != "Library": self.nameInput = xrc.XRCCTRL(self.libraryPanel, 'txtObjName') self.nameInput.Bind(wx.EVT_TEXT, self.onNameInput) self.okButton = xrc.XRCCTRL(self.mainPanel, 'btnSendToLibrary') self.okButton.Bind(wx.EVT_BUTTON, self.onOk) self.okButton.Enable(False) self.animPanel = xrc.XRCCTRL(self.mainPanel, 'animPanel') self.btnImportAnim = xrc.XRCCTRL(self.animPanel, 'btnImportAnim') self.btnImportAnim.Bind(wx.EVT_BUTTON, self.onImportAnim) self.btnImportAnim.Enable(False) self.btnRemoveSelected = xrc.XRCCTRL(self.animPanel, 'btnRemoveSelected') self.btnRemoveSelected.Bind(wx.EVT_BUTTON, self.onRemoveSelected) self.btnRemoveSelected.Enable(False) self.listCtrlAnim = xrc.XRCCTRL(self.animPanel, 'listCtrlAnim') self.listCtrlAnim.__class__ = ListCtrlMultiEdit self.btnPlay.Bind(wx.EVT_BUTTON, self.onPlaySound) self.btnStop.Bind(wx.EVT_BUTTON, self.onStopSound) self.listCtrlAnim.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.onEditAnim) self.listCtrlAnim.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelectAnim) self.imgThumbnail.Bind(wx.EVT_BUTTON, self.onScreenShot) TextEditMixin.__init__(self.listCtrlAnim) self.Layout()
class ImportUI(wx.Dialog): def __init__(self, parent, id, title): #Pre creation routine to allow wx to do layout from XRC pre = wx.PreDialog() self.res = xrc.XmlResource(GUI_FILENAME) self.res.LoadOnDialog(pre, parent, 'dlgImportUI') self.PostCreate(pre) self.Bind(wx.EVT_INIT_DIALOG, self.OnCreate) self.parent = parent def OnCreate(self, e): self.Unbind(wx.EVT_INIT_DIALOG) base.le.ui.bindKeyEvents(False) self.filename = None self.name = '' self.Ok = False self.assetType = "Static Mesh" self.importScene = NodePath(PandaNode("importScene")) self.import2d = NodePath(PandaNode("import2d")) self.import2dScaled = self.import2d.attachNewNode( PandaNode("import2dScaled")) self.objPreview = None self.thumbnailTaken = False self.Bind(wx.EVT_CLOSE, self.Close) base.direct.manipulationControl.disableManipulation() self.Show() #init all the panels from XRC for parenting later on self.mainPanel = xrc.XRCCTRL(self, "mainPanel") self.pandaPanel = xrc.XRCCTRL(self, "pandaPanel") self.animPanel = xrc.XRCCTRL(self, "animPanel") self.libraryPanel = xrc.XRCCTRL(self, "libraryPanel") self.typeSelector = xrc.XRCCTRL(self.libraryPanel, 'choiceAssetType') self.typeSelector.Bind(wx.EVT_CHOICE, self.onSwitchType) self.typeSelector.SetStringSelection(self.assetType) self.btnScreenshot = xrc.XRCCTRL(self.mainPanel, "btnScreenShot") self.btnScreenshot.Bind(wx.EVT_BUTTON, self.onScreenShot) self.btnScreenshot.Disable() self.imgThumbnail = xrc.XRCCTRL(self.libraryPanel, 'imgThumbnail') self.btnPlay = xrc.XRCCTRL(self.libraryPanel, "btnPlay") self.btnStop = xrc.XRCCTRL(self.libraryPanel, "btnStop") self.viewport = Viewport('persp', self.pandaPanel) self.viewport.SetClientSize((500, 500)) ViewportManager.updateAll() base.le.ui.wxStep() self.viewport.initialize() self.handles = ObjectHandles('importUIWidget') self.handles.hide() base.direct.manipulationControl.widgetList.append(self.handles) base.direct.drList.addDisplayRegionContext(self.viewport.cam) #apply a mask to make sure GUI stuff from the main window doesn't show up here self.viewport.cam2d.node().setCameraMask(LE_IMPORT_MASK) self.viewport.camera.reparentTo(self.importScene) self.viewport.camera.setPos(-19, -19, 19) self.viewport.camera.lookAt(0, 0, 0) self.viewport.cam2d.reparentTo(self.import2d) dlight = DirectionalLight('dlight') dlight.setColor(VBase4(0.8, 0.8, 0.8, 1)) dlnp = self.importScene.attachNewNode(dlight) self.importScene.setLight(dlnp) dlnp.setHpr(45, -45, 0) alight = AmbientLight('alight') alight.setColor(VBase4(0.25, 0.25, 0.25, 1)) alnp = self.importScene.attachNewNode(alight) self.importScene.setLight(alnp) fileSelector = xrc.XRCCTRL(self.mainPanel, 'btnLoadAsset') fileSelector.Bind(wx.EVT_BUTTON, self.onFileSelect) if self.assetType != "Library": self.nameInput = xrc.XRCCTRL(self.libraryPanel, 'txtObjName') self.nameInput.Bind(wx.EVT_TEXT, self.onNameInput) self.okButton = xrc.XRCCTRL(self.mainPanel, 'btnSendToLibrary') self.okButton.Bind(wx.EVT_BUTTON, self.onOk) self.okButton.Enable(False) self.animPanel = xrc.XRCCTRL(self.mainPanel, 'animPanel') self.btnImportAnim = xrc.XRCCTRL(self.animPanel, 'btnImportAnim') self.btnImportAnim.Bind(wx.EVT_BUTTON, self.onImportAnim) self.btnImportAnim.Enable(False) self.btnRemoveSelected = xrc.XRCCTRL(self.animPanel, 'btnRemoveSelected') self.btnRemoveSelected.Bind(wx.EVT_BUTTON, self.onRemoveSelected) self.btnRemoveSelected.Enable(False) self.listCtrlAnim = xrc.XRCCTRL(self.animPanel, 'listCtrlAnim') self.listCtrlAnim.__class__ = ListCtrlMultiEdit self.btnPlay.Bind(wx.EVT_BUTTON, self.onPlaySound) self.btnStop.Bind(wx.EVT_BUTTON, self.onStopSound) self.listCtrlAnim.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.onEditAnim) self.listCtrlAnim.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelectAnim) self.imgThumbnail.Bind(wx.EVT_BUTTON, self.onScreenShot) TextEditMixin.__init__(self.listCtrlAnim) self.Layout() def onPlaySound(self, evt): base.sfxManagerList[0].stopAllSounds() self.objPreview.setLoop(False) self.objPreview.play() def onStopSound(self, evt): self.objPreview.stop() def onScreenShot(self, evt): if self.assetType == "Static Mesh" or self.assetType == "Actor": camnode = self.viewport.cam.node() dr = camnode.getDisplayRegion(0) filename = Filename("thumbnail") filename.setDirname(Util.getTempDir()) filename.setExtension("jpg") dr.saveScreenshot(filename) #resize to 60x60 cwd = os.getcwd() os.chdir(Filename(filename.getDirname()).toOsSpecific()) subprocess.call([ "image-resize", "-x 60", "-y 60", "-g 1", "-o" + filename.getBasename(), filename.getBasename() ]) os.chdir(cwd) self.imgThumbnail.SetBitmapLabel(wx.Bitmap( filename.toOsSpecific())) self.thumbnailTaken = True def onSwitchType(self, evt): self.assetType = self.typeSelector.GetStringSelection() self.nameInput.SetValue("") self.name = None self.filename = None self.thumbnailTaken = False self.btnScreenshot.Disable() if self.objPreview: if not isinstance(self.objPreview, AudioSound): self.objPreview.removeNode() if self.assetType == "Static Mesh" or self.assetType == "Actor": self.viewport.camera.setPos(-19, -19, 19) self.viewport.camera.lookAt(0, 0, 0) self.btnImportAnim.Enable(False) self.btnRemoveSelected.Enable(False) self.btnPlay.Enable(False) self.btnStop.Enable(False) base.sfxManagerList[0].stopAllSounds() self.listCtrlAnim.ClearAll() if self.assetType == "Actor": self.listCtrlAnim.InsertColumn(0, "Local Name") self.listCtrlAnim.InsertColumn(1, "Asset Name") self.listCtrlAnim.InsertColumn(2, "File") for i in range(self.listCtrlAnim.GetColumnCount()): self.listCtrlAnim.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER) def onNameInput(self, evt): iPoint = self.nameInput.GetInsertionPoint() self.nameInput.ChangeValue( Util.toAssetName(self.nameInput.GetValue(), False)) self.nameInput.SetInsertionPoint(iPoint) self.name = self.nameInput.GetValue() if self.name and self.filename: self.okButton.Enable(True) else: self.okButton.Enable(False) def onFileSelect(self, evt): self.thumbnailTaken = False fileType = "*.*" if self.assetType == "Static Mesh" or self.assetType == "Actor" or self.assetType == "Animation": fileType = "Egg files (*.egg;*.egg.pz)|*.egg;*.egg.pz" elif self.assetType == "Texture" or self.assetType == "Terrain": fileType = "Texture files (*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif;*.avi;*.mpg;*.mpeg;*.dds)|*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif;*.avi;*.mpg;*.mpeg;*.dds" elif self.assetType == "Shader": fileType = "Shader files (*.sha;*.cg)|*.sha;*.cg" elif self.assetType == "Sound": fileType = "Sound files (*.wav;*.mp3;*.aiff;*.ogg) | *.wav;*.mp3;*.aiff;*.ogg" elif self.assetType == "Texture Sequence": fileType = "Texture files (*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif)|*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif" elif self.assetType == "Journal Entry": fileType = "Journal Entry files (*.xml)|*.xml" elif self.assetType == "Conversation": fileType = "Conversation files (*.xml)|*.xml" if self.assetType != "Texture Sequence": dialog = wx.FileDialog(self, "Select a " + self.assetType + " file", wildcard=fileType, style=wx.FD_OPEN) else: dialog = wx.FileDialog(self, "Select the texture files to use.", wildcard=fileType, style=wx.FD_OPEN | wx.FD_MULTIPLE) if dialog.ShowModal() == wx.ID_OK: base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) if self.assetType != "Texture Sequence": self.filename = Filename.fromOsSpecific(dialog.GetPath()) self.name = self.filename.getBasenameWoExtension() else: filenames = [] for p in sorted(dialog.GetPaths()): filenames.append(Filename.fromOsSpecific(p)) self.name = filenames[0].getBasenameWoExtension().strip( '1234567890-_') self.okButton.Enable(True) self.nameInput.SetValue(self.name) if self.assetType == "Static Mesh": if self.objPreview: self.objPreview.removeNode() self.objPreview = loader.loadModel(self.filename) self.objPreview.reparentTo(self.importScene) self.btnScreenshot.Enable(True) center = self.objPreview.getBounds().getCenter() radius = self.objPreview.getBounds().getRadius() self.viewport.camera.setPos(center + Vec3(-radius * 2, -radius * 2, radius * 2)) self.viewport.camera.lookAt(center) self.viewport.camLens.setNearFar(radius / 10, radius * 1000) elif self.assetType == "Texture" or self.assetType == "Terrain": if self.objPreview: self.objPreview.removeNode() self.objPreview = OnscreenImage( parent=self.import2d, image=self.filename.getFullpath(), pos=(0.0, 0.0, 0.0)) x = float(self.objPreview.getTexture().getOrigFileXSize()) y = float(self.objPreview.getTexture().getOrigFileYSize()) if x == 0.0 or y == 0.0: x = float(self.objPreview.getTexture().getVideoWidth( )) * self.objPreview.getTexture().getTexScale().getX() y = float(self.objPreview.getTexture().getVideoHeight( )) * self.objPreview.getTexture().getTexScale().getY() self.objPreview.setTexScale( TextureStage.getDefault(), self.objPreview.getTexture().getTexScale()) if x > y: self.objPreview.setScale(1, 1, y / x) else: self.objPreview.setScale(x / y, 1, 1) self.objPreview.setLightOff(True) elif self.assetType == "Actor": self.btnImportAnim.Enable(True) if self.objPreview: self.objPreview.removeNode() self.objPreview = Actor(self.filename, {}) self.objPreview.reparentTo(self.importScene) self.btnScreenshot.Enable(True) center = self.objPreview.getBounds().getCenter() radius = self.objPreview.getBounds().getRadius() self.viewport.camera.setPos(center + Vec3(-radius * 2, -radius * 2, radius * 2)) self.viewport.camera.lookAt(center) self.viewport.camLens.setNearFar(radius / 10, radius * 1000) elif self.assetType == "Texture Sequence": tempFolder = Filename.fromOsSpecific(Util.getTempDir() + '/staging') if os.path.exists((tempFolder + ' /').toOsSpecific()): shutil.rmtree(tempFolder.toOsSpecific()) os.makedirs(tempFolder.toOsSpecific()) for f in filenames: dest = tempFolder + '/' + f.getBasename() shutil.copy(f.toOsSpecific(), tempFolder.toOsSpecific()) fileAtt = os.stat(dest.toOsSpecific())[0] if (not fileAtt & stat.S_IWRITE): os.chmod(dest.toOsSpecific(), stat.S_IWRITE) f.setDirname(tempFolder.getFullpath()) args = [ "egg-texture-cards", "-o", self.name + ".egg", "-fps", "30" ] for f in filenames: args.append(f.getBasename()) cwd = os.getcwd() os.chdir(tempFolder.toOsSpecific()) subprocess.call(args) os.chdir(cwd) self.filename = tempFolder + '/' + self.name + '.egg' if self.objPreview: self.objPreview.removeNode() self.objPreview = loader.loadModel(self.filename) self.objPreview.reparentTo(self.importScene) self.viewport.camera.setPos(0, -5, 0) self.viewport.camera.lookAt(0, 0, 0) self.viewport.camLens.setNearFar(0.1, 10000) self.okButton.Enable(True) elif self.assetType == "Sound": if self.objPreview: if not isinstance(self.objPreview, AudioSound): self.objPreview.removeNode() self.objPreview = loader.loadSfx(self.filename.getFullpath()) self.btnPlay.Enable() self.btnStop.Enable() base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) dialog.Destroy() def onImportAnim(self, evt): dialog = wx.FileDialog( self, "Select an animation file", style=wx.FD_OPEN, wildcard="Egg files(*.egg;*.egg.pz)|*.egg;*.egg.pz") if dialog.ShowModal() == wx.ID_OK: filename = Filename.fromOsSpecific(dialog.GetPath()) pos = self.listCtrlAnim.InsertStringItem( self.listCtrlAnim.GetItemCount(), filename.getBasenameWoExtension()) self.listCtrlAnim.SetStringItem(pos, 1, filename.getBasenameWoExtension()) self.listCtrlAnim.SetStringItem(pos, 2, filename.toOsSpecific()) self.listCtrlAnim.Select(pos, True) self.listCtrlAnim.EnsureVisible(pos) for i in range(self.listCtrlAnim.GetColumnCount()): self.listCtrlAnim.SetColumnWidth(i, wx.LIST_AUTOSIZE) self.btnRemoveSelected.Enable(True) def onEditAnim(self, evt): if evt.GetColumn() == 0: if Util.toAssetName(evt.GetText()) != evt.GetText(): evt.Veto() elif evt.GetColumn() == 1: if Util.toAssetName(evt.GetText()) != evt.GetText(): evt.Veto() else: evt.Veto() def onSelectAnim(self, evt): self.objPreview.stop() self.objPreview.unloadAnims() id = evt.GetItem().GetId() name = self.listCtrlAnim.GetItem(id, 0).GetText() file = Filename.fromOsSpecific( self.listCtrlAnim.GetItem(id, 2).GetText()) self.objPreview.loadAnims({name: file}) self.objPreview.loop(name) def onRemoveSelected(self, evt): toDelete = self.listCtrlAnim.GetFirstSelected() self.objPreview.stop() self.objPreview.unloadAnims() self.listCtrlAnim.DeleteItem(toDelete) if self.listCtrlAnim.GetItemCount() == 0: self.btnRemoveSelected.Enable(False) else: self.listCtrlAnim.Select(0) def onOk(self, evt): self.Ok = True libFile = (base.le.lib.projDir + '/lib.index').toOsSpecific() while True: #make sure that the library file is writable try: f = open(libFile, 'a') f.close() except IOError as e: dlg = wx.MessageDialog(self, "The library file '" + libFile + "' could not be written.\ Make sure that it is not marked read-only and click OK.", caption="Permission Denied", style=wx.OK | wx.CANCEL | wx.ICON_ERROR) if dlg.ShowModal() == wx.ID_CANCEL: self.Close() return else: break removedAssetsDir = Filename.fromOsSpecific( Util.getTempDir()) + '/removedAssets' if os.path.exists((removedAssetsDir + '/').toOsSpecific()): shutil.rmtree(removedAssetsDir.toOsSpecific()) self.removedAssets = [] if self.assetType == "Static Mesh" or self.assetType == "Texture Sequence": mesh = self.getMesh() while True: try: base.le.lib.checkMesh(mesh) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.oldAsset.__class__.__name__ == 'Mesh': self.restoreAssets() self.Close() return mesh.textures.remove(e.newAsset) mesh.textures.append(e.oldAsset) except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.asset.__class__.__name__ == 'Mesh': self.restoreAssets() self.Close() return mesh.textures.remove(e.asset) f = Filename.fromOsSpecific(e.destPath) f.makeRelativeTo(base.le.lib.projDir) mesh.textures.append(base.le.lib.filenameIndex[f]) except Library.TextureNotFoundError as e: message = "Egg file contains an invalid texture reference.\n" message += "Texture '" + e.filename.getFullpath( ) + "' not found.\n" message += "Please fix your texture paths in your egg file before importing." dialog = wx.MessageDialog(self, message, "Texture Not Found", style=wx.OK | wx.ICON_ERROR) dialog.ShowModal() dialog.Destroy() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addMesh(mesh, True) if self.thumbnailTaken: thumbnailPath = base.le.lib.projDir + '/Models/Thumbnails/' + \ mesh.filename.getBasenameWoExtension() + '.jpg' tempPath = Filename.fromOsSpecific(Util.getTempDir() + '/thumbnail.jpg') shutil.move(tempPath.toOsSpecific(),\ (thumbnailPath).toOsSpecific()) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Actor": actor = self.getActor() for anim in self.anims: while True: try: base.le.lib.checkAnimation(anim) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: self.anims.remove(e.newAsset) self.anims.append(e.oldAsset) except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: self.anims.remove(e.asset) f = Filename.fromOsSpecific(e.destPath) f.makeRelativeTo(base.le.lib.projDir) self.anims.append(base.le.lib.filenameIndex[f]) else: break while True: try: base.le.lib.checkActor(actor) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.oldAsset.__class__.__name__ == 'Actor': self.restoreAssets() self.Close() return actor.textures.remove(e.newAsset) actor.textures.append(e.oldAsset) except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.asset.__class__.__name__ == 'Actor': self.restoreAssets() self.Close() return actor.textures.remove(e.asset) f = Filename.fromOsSpecific(e.destPath) f.makeRelativeTo(base.le.lib.projDir) actor.textures.append(base.le.lib.filenameIndex[f]) except Library.TextureNotFoundError as e: message = "Egg file contains an invalid texture reference.\n" message += "Texture '" + e.filename.getFullpath( ) + "' not found.\n" message += "Please fix your texture paths in your egg file before importing." dialog = wx.MessageDialog(self, message, "Texture Not Found", style=wx.OK | wx.ICON_ERROR) dialog.ShowModal() dialog.Destroy() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) for anim in self.anims: base.le.lib.addAnimation(anim) base.le.lib.addActor(actor, True) if self.thumbnailTaken: thumbnailPath = base.le.lib.projDir + '/Models/Thumbnails/' + \ actor.filename.getBasenameWoExtension() + '.jpg' tempPath = Filename.fromOsSpecific(Util.getTempDir() + '/thumbnail.jpg') shutil.move(tempPath.toOsSpecific(), (thumbnailPath).toOsSpecific()) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Animation": anim = self.getAnimation() while True: try: base.le.lib.checkAnimation(anim) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addAnimation(anim) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Texture": tex = self.getTexture() while True: try: base.le.lib.checkTexture(tex) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addTexture(tex, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Shader": shader = self.getShader() while True: try: base.le.lib.checkShader(shader) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addShader(shader, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Sound": sound = self.getSound() while True: try: base.le.lib.checkSound(sound) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addSound(sound, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Terrain": tex = self.getTerrain() while True: try: base.le.lib.checkTerrain(tex) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if not result: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addTerrain(tex, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) #TODO: Take the Journal Entry import from Import assets. elif self.assetType == "Script": script = self.getScript() while True: try: base.le.lib.checkScript(script) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addScript(script, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Conversation": conversation = self.getConversation() while True: try: base.le.lib.checkConversation(conversation) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addConversation(conversation, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) if not base.le.saved: base.le.fNeedToSave = True base.le.ui.libraryUI.update() base.le.ui.storyObjUI.update() self.Close() #restores any assets that have been "deleted"(moved to temp folder) if we cancel an import #also restores assets that were removed from library def restoreAssets(self): #restore any files which were "deleted" for dir in ('Models', 'Textures', 'Shaders', 'Sounds', 'Journal_Entries', 'Conversations', 'Scripts'): d = os.path.join(Util.getTempDir(), 'removedAssets', dir) if os.path.exists(d): for file in os.listdir(d): shutil.move(os.path.join(d, file), (base.le.lib.projDir + '/' + dir + '/').toOsSpecific()) #add assets back into library for asset in self.removedAssets: base.le.lib.restoreAsset(asset) self.removedAssets = [] def Close(self, evt=None): self.viewport.Close() base.direct.manipulationControl.widgetList.remove(self.handles) base.direct.drList.removeDisplayRegionContext(self.viewport.cam) base.direct.manipulationControl.enableManipulation() base.le.ui.bindKeyEvents(True) self.Destroy() def getMesh(self): if self.thumbnailTaken: thumbnailPath = Filename('/Models/Thumbnails/' + self.filename.getBasenameWoExtension() + '.jpg') return Library.Mesh(Util.toAssetName(self.name), self.filename, thumbnailPath) else: return Library.Mesh(Util.toAssetName(self.name), self.filename) def getTexture(self): return Library.Texture(Util.toAssetName(self.name), self.filename) def getActor(self): self.anims, myAnims = self.getAnims() if self.thumbnailTaken: thumbnailPath = Filename('/Models/Thumbnails/' + self.filename.getBasenameWoExtension() + '.jpg') return Library.Actor(Util.toAssetName(self.name), self.filename, thumbnailPath, anims=myAnims) else: return Library.Actor(Util.toAssetName(self.name), self.filename, anims=myAnims) def getAnimation(self): return Library.Animation(Util.toAssetName(self.name), self.filename) def getAnims(self): anims = [] myAnims = {} for i in range(self.listCtrlAnim.GetItemCount()): a = Library.Animation( self.listCtrlAnim.GetItem(i, 1).GetText(), Filename.fromOsSpecific( self.listCtrlAnim.GetItem(i, 2).GetText())) if a not in anims: anims.append(a) myAnims[self.listCtrlAnim.GetItem(i, 0).GetText()] = a else: #if an equivalent animation is already in the list, use that one myAnims[self.listCtrlAnim.GetItem( i, 0).GetText()] = anims[anims.index(a)] return anims, myAnims def getShader(self): return Library.Shader(Util.toAssetName(self.name), self.filename) def getSound(self): return Library.Sound(Util.toAssetName(self.name), self.filename) def getTerrain(self): return Library.Terrain(Util.toAssetName(self.name), self.filename) def getJournalEntry(self): return Library.JournalEntry(Util.toAssetName(self.name), self.filename) def getScript(self): return Library.Script(Util.toAssetName(self.name), self.filename) def getConversation(self): return Library.ConversationAsset(Util.toAssetName(self.name), self.filename)
def onCreate(self, evt=None): base.le.deselectAll() self.Unbind(wx.EVT_INIT_DIALOG) # Ignore the main editor ## taskMgr.remove("mouseTask") base.le.ui.bindKeyEvents(False) ## base.le.ui.inPandaWindow = False ## self.Bind(wx.EVT_CHAR, self.onKeyEvent) ## self.Bind(wx.EVT_KEY_DOWN, self.onKeyDown) ## self.Bind(wx.EVT_KEY_UP, self.onKeyUp) self.Show() base.direct.manipulationControl.disableManipulation() self.Bind(wx.EVT_CLOSE, self.close) # main panel self.panelMain = xrc.XRCCTRL(self, 'mainPanel') self.pandaPanel = xrc.XRCCTRL(self, "pandaPanel") self.propsPanel = xrc.XRCCTRL(self, "propsPanel") self.ropePanel = xrc.XRCCTRL(self, "ropePanel") # text boxes self.txtX = xrc.XRCCTRL(self.propsPanel, 'txtX') self.txtY = xrc.XRCCTRL(self.propsPanel, 'txtY') self.txtZ = xrc.XRCCTRL(self.propsPanel, 'txtZ') self.txtX.SetValue(str(self.camera.getPos()[0])) self.txtY.SetValue(str(self.camera.getPos()[1])) self.txtZ.SetValue(str(self.camera.getPos()[2])) for x in (self.txtX, self.txtY, self.txtZ): x.Bind(wx.EVT_TEXT_ENTER, self.updatePos) self.txtH = xrc.XRCCTRL(self.propsPanel, 'txtH') self.txtP = xrc.XRCCTRL(self.propsPanel, 'txtP') self.txtR = xrc.XRCCTRL(self.propsPanel, 'txtR') self.txtH.SetValue(str(self.camera.getHpr()[0])) self.txtP.SetValue(str(self.camera.getHpr()[1])) self.txtR.SetValue(str(self.camera.getHpr()[2])) for x in (self.txtH, self.txtP, self.txtR): x.Bind(wx.EVT_TEXT_ENTER, self.updateHpr) self.txtHoriz = xrc.XRCCTRL(self.propsPanel, 'txtHoriz') self.txtVert = xrc.XRCCTRL(self.propsPanel, 'txtVert') self.txtHoriz.SetValue(str(self.camera.getLens().getFov()[0])) self.txtVert.SetValue(str(self.camera.getLens().getFov()[1])) for x in (self.txtHoriz, self.txtVert): x.Bind(wx.EVT_TEXT_ENTER, self.updateFov) self.txtNear = xrc.XRCCTRL(self.propsPanel, 'txtNear') self.txtFar = xrc.XRCCTRL(self.propsPanel, 'txtFar') self.txtNear.SetValue(str(self.camera.getLens().getNear())) self.txtFar.SetValue(str(self.camera.getLens().getFar())) for x in (self.txtNear, self.txtFar): x.Bind(wx.EVT_TEXT_ENTER, self.updateNearFar) self.txtRope = xrc.XRCCTRL(self.ropePanel, 'txtRope') self.txtSeqTime = xrc.XRCCTRL(self.ropePanel, 'txtSeq') self.txtLookAt = xrc.XRCCTRL(self.ropePanel, 'txtLookAt') #self.txtRope.Bind(wx.EVT_TEXT_ENTER, self.updateRope) self.txtSeqTime.Bind(wx.EVT_TEXT_ENTER, self.updateSeqTime) self.radioBoxOrientation = xrc.XRCCTRL(self.ropePanel, 'radioBoxOrientation') self.Bind(wx.EVT_RADIOBOX, self.onOrientationChange, self.radioBoxOrientation) #Preview Buttons self.btnPreview = xrc.XRCCTRL(self, "btnPlay") self.btnPreview.Bind(wx.EVT_BUTTON, self.previewSeq) self.btnStop = xrc.XRCCTRL(self, "btnReset") self.btnStop.Bind(wx.EVT_BUTTON, self.resetSeq) # buttons self.btnOk = xrc.XRCCTRL(self.panelMain, 'btnOk') self.btnCancel = xrc.XRCCTRL(self.panelMain, 'btnCancel') self.btnCancel.Bind(wx.EVT_BUTTON, self.close) self.btnOk.Bind(wx.EVT_BUTTON, self.onOk) self.ok = False # Camera view diff = 600 - (self.camera.getLens().getAspectRatio() * 600) self.SetSize((610 - diff, 759)) pos = self.GetPosition() self.SetPosition((pos[0] + (diff/2), pos[1])) self.pandaPanel.SetSize((self.camera.getLens().getAspectRatio()*600, 600)) self.camView = Viewport('persp', self.pandaPanel) self.camView.SetClientSize((self.camera.getLens().getAspectRatio()*600, 600)) ViewportManager.updateAll() base.le.ui.wxStep() self.camView.initialize() self.handles = ObjectHandles('camViewWidget') self.handles.hide() base.direct.manipulationControl.widgetList.append(self.handles) self.camView.cam.node().setLens(self.camera.getLens()) base.direct.drList.addDisplayRegionContext(self.camView.cam) self.camView.cam2d.node().setCameraMask(LE_CAM_MASK) self.camView.cam.node().setCameraMask(LE_CAM_MASK) self.camView.camera.reparentTo(render) self.camView.camera.setPos(self.camera.getPos()) self.camView.camera.setHpr(self.camera.getHpr()) base.le.ui.perspView.grid.hide(LE_CAM_MASK) #self.startPos = self.camera.getPos() #self.startHpr = self.camera.getHpr() self.Layout()
class CamViewDialog(wx.Dialog): def __init__(self, parent, camera): pre = wx.PreDialog() self.res = xrc.XmlResource('/XRC/ObjectUI/dlgCamView.xrc') self.res.LoadOnDialog(pre, parent, 'dlgCamView') self.PostCreate(pre) self.Bind(wx.EVT_INIT_DIALOG, self.onCreate) self.parent = parent # Get the cameras properties self.pos = camera.getPos() self.hpr = camera.getHpr() self.fov = camera.getLens().getFov() self.near = camera.getLens().getNear() self.far = camera.getLens().getFar() self.camera = camera def onCreate(self, evt=None): base.le.deselectAll() self.Unbind(wx.EVT_INIT_DIALOG) # Ignore the main editor ## taskMgr.remove("mouseTask") base.le.ui.bindKeyEvents(False) ## base.le.ui.inPandaWindow = False ## self.Bind(wx.EVT_CHAR, self.onKeyEvent) ## self.Bind(wx.EVT_KEY_DOWN, self.onKeyDown) ## self.Bind(wx.EVT_KEY_UP, self.onKeyUp) self.Show() base.direct.manipulationControl.disableManipulation() self.Bind(wx.EVT_CLOSE, self.close) # main panel self.panelMain = xrc.XRCCTRL(self, 'mainPanel') self.pandaPanel = xrc.XRCCTRL(self, "pandaPanel") self.propsPanel = xrc.XRCCTRL(self, "propsPanel") self.ropePanel = xrc.XRCCTRL(self, "ropePanel") # text boxes self.txtX = xrc.XRCCTRL(self.propsPanel, 'txtX') self.txtY = xrc.XRCCTRL(self.propsPanel, 'txtY') self.txtZ = xrc.XRCCTRL(self.propsPanel, 'txtZ') self.txtX.SetValue(str(self.camera.getPos()[0])) self.txtY.SetValue(str(self.camera.getPos()[1])) self.txtZ.SetValue(str(self.camera.getPos()[2])) for x in (self.txtX, self.txtY, self.txtZ): x.Bind(wx.EVT_TEXT_ENTER, self.updatePos) self.txtH = xrc.XRCCTRL(self.propsPanel, 'txtH') self.txtP = xrc.XRCCTRL(self.propsPanel, 'txtP') self.txtR = xrc.XRCCTRL(self.propsPanel, 'txtR') self.txtH.SetValue(str(self.camera.getHpr()[0])) self.txtP.SetValue(str(self.camera.getHpr()[1])) self.txtR.SetValue(str(self.camera.getHpr()[2])) for x in (self.txtH, self.txtP, self.txtR): x.Bind(wx.EVT_TEXT_ENTER, self.updateHpr) self.txtHoriz = xrc.XRCCTRL(self.propsPanel, 'txtHoriz') self.txtVert = xrc.XRCCTRL(self.propsPanel, 'txtVert') self.txtHoriz.SetValue(str(self.camera.getLens().getFov()[0])) self.txtVert.SetValue(str(self.camera.getLens().getFov()[1])) for x in (self.txtHoriz, self.txtVert): x.Bind(wx.EVT_TEXT_ENTER, self.updateFov) self.txtNear = xrc.XRCCTRL(self.propsPanel, 'txtNear') self.txtFar = xrc.XRCCTRL(self.propsPanel, 'txtFar') self.txtNear.SetValue(str(self.camera.getLens().getNear())) self.txtFar.SetValue(str(self.camera.getLens().getFar())) for x in (self.txtNear, self.txtFar): x.Bind(wx.EVT_TEXT_ENTER, self.updateNearFar) self.txtRope = xrc.XRCCTRL(self.ropePanel, 'txtRope') self.txtSeqTime = xrc.XRCCTRL(self.ropePanel, 'txtSeq') self.txtLookAt = xrc.XRCCTRL(self.ropePanel, 'txtLookAt') #self.txtRope.Bind(wx.EVT_TEXT_ENTER, self.updateRope) self.txtSeqTime.Bind(wx.EVT_TEXT_ENTER, self.updateSeqTime) self.radioBoxOrientation = xrc.XRCCTRL(self.ropePanel, 'radioBoxOrientation') self.Bind(wx.EVT_RADIOBOX, self.onOrientationChange, self.radioBoxOrientation) #Preview Buttons self.btnPreview = xrc.XRCCTRL(self, "btnPlay") self.btnPreview.Bind(wx.EVT_BUTTON, self.previewSeq) self.btnStop = xrc.XRCCTRL(self, "btnReset") self.btnStop.Bind(wx.EVT_BUTTON, self.resetSeq) # buttons self.btnOk = xrc.XRCCTRL(self.panelMain, 'btnOk') self.btnCancel = xrc.XRCCTRL(self.panelMain, 'btnCancel') self.btnCancel.Bind(wx.EVT_BUTTON, self.close) self.btnOk.Bind(wx.EVT_BUTTON, self.onOk) self.ok = False # Camera view diff = 600 - (self.camera.getLens().getAspectRatio() * 600) self.SetSize((610 - diff, 759)) pos = self.GetPosition() self.SetPosition((pos[0] + (diff/2), pos[1])) self.pandaPanel.SetSize((self.camera.getLens().getAspectRatio()*600, 600)) self.camView = Viewport('persp', self.pandaPanel) self.camView.SetClientSize((self.camera.getLens().getAspectRatio()*600, 600)) ViewportManager.updateAll() base.le.ui.wxStep() self.camView.initialize() self.handles = ObjectHandles('camViewWidget') self.handles.hide() base.direct.manipulationControl.widgetList.append(self.handles) self.camView.cam.node().setLens(self.camera.getLens()) base.direct.drList.addDisplayRegionContext(self.camView.cam) self.camView.cam2d.node().setCameraMask(LE_CAM_MASK) self.camView.cam.node().setCameraMask(LE_CAM_MASK) self.camView.camera.reparentTo(render) self.camView.camera.setPos(self.camera.getPos()) self.camView.camera.setHpr(self.camera.getHpr()) base.le.ui.perspView.grid.hide(LE_CAM_MASK) #self.startPos = self.camera.getPos() #self.startHpr = self.camera.getHpr() self.Layout() ## # setup the keys ## self.setupControls() def onOk(self, evt=None): self.ok = True self.close() def close(self, evt=None): self.camView.Close() base.direct.manipulationControl.enableManipulation() base.direct.drList.removeDisplayRegionContext(self.camView.cam) base.le.ui.bindKeyEvents(True) if not self.ok: self.camera.setPos(self.pos) self.camera.setHpr(self.hpr) self.camera.getLens().setFov(self.fov) self.camera.getLens().setNearFar(self.near,self.far) ## self.killControls() ## # Give control back to the main window ## taskMgr.add(base.le.ui.mouseTask,"mouseTask") self.Destroy() def updatePos(self, evt=None): try: x = float(self.txtX.GetValue()) y = float(self.txtY.GetValue()) z = float(self.txtZ.GetValue()) except ValueError as e: msg = wx.MessageDialog(self, e.message, "Invalid Input", wx.OK|wx.ICON_HAND) msg.ShowModal() msg.Destroy() self.txtX.SetValue(str(self.camera.getPos()[0])) self.txtY.SetValue(str(self.camera.getPos()[1])) self.txtZ.SetValue(str(self.camera.getPos()[2])) else: self.camera.setPos(Vec3(x, y, z)) self.camView.camera.setPos(Vec3(x, y, z)) def updateHpr(self, evt=None): try: h = float(self.txtH.GetValue()) p = float(self.txtP.GetValue()) r = float(self.txtR.GetValue()) except ValueError as e: msg = wx.MessageDialog(self, e.message, "Invalid Input", wx.OK|wx.ICON_HAND) msg.ShowModal() msg.Destroy() self.txtH.SetValue(str(self.camera.getHpr()[0])) self.txtP.SetValue(str(self.camera.getHpr()[1])) self.txtR.SetValue(str(self.camera.getHpr()[2])) else: self.camera.setHpr(Vec3(h, p, r)) self.camView.camera.setHpr(Vec3(h, p, r)) def updateFov(self, evt=None): try: h = float(self.txtHoriz.GetValue()) v = float(self.txtVert.GetValue()) except ValueError as e: msg = wx.MessageDialog(self, e.message, "Invalid Input", wx.OK|wx.ICON_HAND) msg.ShowModal() msg.Destroy() self.txtHoriz.SetValue(str(self.camera.getLens().getFov()[0])) self.txtVert.SetValue(str(self.camera.getLens().getFov()[1])) else: self.camera.getLens().setFov(Vec2(h,v)) self.camView.cam.node().getLens().setFov(Vec2(h, v)) def updateNearFar(self, evt=None): try: near = float(self.txtNear.GetValue()) far = float(self.txtFar.GetValue()) except ValueError as e: msg = wx.MessageDialog(self, e.message, "Invalid Input", wx.OK|wx.ICON_HAND) msg.ShowModal() msg.Destroy() self.txtNear.SetValue(str(self.camera.getLens().getNear())) self.txtFar.SetValue(str(self.camera.getLens().getFar())) else: self.camera.getLens().setNearFar(near, far) self.camView.cam.node().getLens().setNearFar(near, far) def updateSeqTime(self, evt=None): try: seq = float(self.txtSeqTime.GetValue()) #near = float(self.txtNear.GetValue()) #far = float(self.txtFar.GetValue()) except ValueError as e: msg = wx.MessageDialog(self, e.message, "Invalid Input", wx.OK|wx.ICON_HAND) msg.ShowModal() msg.Destroy() evt.Veto() else: pass #self.camera.getLens().setNearFar(near, far) #self.camView.cam.node().getLens().setNearFar(near, far) def onOrientationChange(self, evt = None): curchoice = self.radioBoxOrientation.GetSelection() #orientation = self.radioBoxOrientation.GetString(curchoice) #obj = self.editor.objectMgr.findObjectByNodePath(base.direct.selected.last) if(curchoice ==2): dlg = ObjectInputDialog(self) lookAtName = dlg.ShowModal() dlg.Destroy() if lookAtName: lookAt = self.parent.editor.objectMgr.findObjectById(lookAtName) self.camView.camera.lookAt(lookAt.getNodePath()) self.txtLookAt.ChangeValue(lookAtName) else: self.txtLookAt.ChangeValue("") def previewSeq(self, evt): #rope = self.editor.objectMgr.findObjectByNodePath(base.direct.selected.last) curChoice = self.radioBoxOrientation.GetSelection() if self.btnPreview.GetLabel() == "Play": ropeName = self.txtRope.GetValue() rope = self.parent.editor.objectMgr.findObjectById(ropeName) seqTime = self.txtSeqTime.GetValue() if(rope == None): msg = wx.MessageDialog(self, "Cannot create sequence with non-existent rope.","Invalid Rope" , wx.OK|wx.ICON_HAND) msg.ShowModal() msg.Destroy() return rope.genWaypointRope() self.previewSeq = Sequence() if(curChoice == 0): followPathTemp = True lookAtObj = None elif(curChoice == 1): followPathTemp = False lookAtObj = None else: followPathTemp = False lookAtName = self.txtLookAt.GetValue() lookAtObj = self.parent.editor.objectMgr.findObjectById(lookAtName) if(lookAt == None): msg = wx.MessageDialog(self, "Cannot create sequence with non-existent lookAt.","Invalid LookAt" , wx.OK|wx.ICON_HAND) msg.ShowModal() msg.Destroy() return else: lookAtObj = lookAtObj.getNodePath() temp =UniformRopeMotionInterval(rope.rope, self.camView.camera, float(seqTime), followPath=followPathTemp, lookAt=lookAtObj) self.previewSeq.append(temp) self.previewSeq.append(Func(self.resetPlayUI)) self.previewSeq.start()#self.runSeq(self.previewSeq) self.btnPreview.SetLabel("Pause") elif self.btnPreview.GetLabel() == "Pause": self.previewSeq.pause() self.btnPreview.SetLabel("Resume") elif self.btnPreview.GetLabel() == "Resume": self.previewSeq.resume() self.btnPreview.SetLabel("Pause") def resetPlayUI(self): self.btnPreview.SetLabel("Play") def resetSeq(self, evt): if self.previewSeq is not None: self.camView.camera.setPos(self.camera.getPos()) self.camView.camera.setHpr(self.camera.getHpr()) self.previewSeq.finish() self.btnPreview.SetLabel("Play") def onKeyEvent(self, evt): input = "" def onKeyDown(self, evt): input = "" def onKeyUp(self, evt): input = "" ## def setupControls(self): ## base.accept('w', taskMgr.add, [self.moveCamForward, 'moveCamForward']) ## base.accept('w-up', taskMgr.remove, ['moveCamForward']) ## base.accept('a', taskMgr.add, [self.moveCamLeft, 'moveCamLeft']) ## base.accept('a-up', taskMgr.remove, ['moveCamLeft']) ## base.accept('s', taskMgr.add, [self.moveCamBack, 'moveCamBack']) ## base.accept('s-up', taskMgr.remove, ['moveCamBack']) ## base.accept('d', taskMgr.add, [self.moveCamRight, 'moveCamRight']) ## base.accept('d-up', taskMgr.remove, ['moveCamRight']) ## base.accept('q', taskMgr.add, [self.moveCamUp, 'moveCamUp']) ## base.accept('q-up', taskMgr.remove, ['moveCamUp']) ## base.accept('e', taskMgr.add, [self.moveCamDown, 'moveCamDown']) ## base.accept('e-up', taskMgr.remove, ['moveCamDown']) ## base.accept('arrow_up', taskMgr.add, [self.rotateCamUp, 'rotateCamUp']) ## base.accept('arrow_up-up', taskMgr.remove, ['rotateCamUp']) ## base.accept('arrow_left', taskMgr.add, [self.turnCamLeft, 'turnCamLeft']) ## base.accept('arrow_left-up', taskMgr.remove, ['turnCamLeft']) ## base.accept('arrow_down', taskMgr.add, [self.rotateCamDown, 'rotateCamDown']) ## base.accept('arrow_down-up', taskMgr.remove, ['rotateCamDown']) ## base.accept('arrow_right', taskMgr.add, [self.turnCamRight, 'turnCamRight']) ## base.accept('arrow_right-up', taskMgr.remove, ['turnCamRight']) ## base.accept('n', taskMgr.add, [self.rotateCamLeft, 'rotateCamLeft']) ## base.accept('n-up', taskMgr.remove, ['rotateCamLeft']) ## base.accept('m', taskMgr.add, [self.rotateCamRight, 'rotateCamRight']) ## base.accept('m-up', taskMgr.remove, ['rotateCamRight']) ## def killControls(self): ## base.ignore('w') ## base.ignore('w-up') ## base.ignore('a') ## base.ignore('a-up') ## base.ignore('s') ## base.ignore('s-up') ## base.ignore('d') ## base.ignore('d-up') ## base.ignore('q') ## base.ignore('q-up') ## base.ignore('e') ## base.ignore('e-up') ## base.ignore('arrow_up') ## base.ignore('arrow_up-up') ## base.ignore('arrow_left') ## base.ignore('arrow_left-up') ## base.ignore('arrow_down') ## base.ignore('arrow_down-up') ## base.ignore('arrow_right') ## base.ignore('arrow_right-up') ## base.ignore('n') ## base.ignore('n-up') ## base.ignore('m') ## base.ignore('m-up') ## def moveCamForward(self, task): ## self.camera.setPos(self.camera, 0, 0.1, 0) ## self.camView.camera.setPos(self.camView.camera, 0, 0.1, 0) ## self.updateTextBoxes() ## return task.cont ## def moveCamBack(self, task): ## self.camera.setPos(self.camera, 0, -0.1, 0) ## self.camView.camera.setPos(self.camView.camera, 0, -0.1, 0) ## self.updateTextBoxes() ## return task.cont ## def moveCamLeft(self, task): ## self.camera.setPos(self.camera, -0.1, 0, 0) ## self.camView.camera.setPos(self.camView.camera, -0.1, 0, 0) ## self.updateTextBoxes() ## return task.cont ## def moveCamRight(self, task): ## self.camera.setPos(self.camera, 0.1, 0, 0) ## self.camView.camera.setPos(self.camView.camera, 0.1, 0, 0) ## self.updateTextBoxes() ## return task.cont ## def moveCamUp(self, task): ## self.camera.setPos(self.camera, 0, 0, 0.1) ## self.camView.camera.setPos(self.camView.camera, 0, 0, 0.1) ## self.updateTextBoxes() ## return task.cont ## def moveCamDown(self, task): ## self.camera.setPos(self.camera, 0, 0, -0.1) ## self.camView.camera.setPos(self.camView.camera, 0, 0, -0.1) ## self.updateTextBoxes() ## return task.cont ## def turnCamLeft(self, task): ## self.camera.setHpr(self.camera, 2.0, 0, 0) ## self.camView.camera.setHpr(self.camView.camera, 2.0, 0, 0) ## self.updateTextBoxes() ## return task.cont ## def turnCamRight(self, task): ## self.camera.setHpr(self.camera, -2.0, 0, 0) ## self.camView.camera.setHpr(self.camView.camera, -2.0, 0, 0) ## self.updateTextBoxes() ## return task.cont ## def rotateCamUp(self, task): ## self.camera.setHpr(self.camera, 0, 2.0, 0) ## self.camView.camera.setHpr(self.camView.camera, 0, 2.0, 0) ## self.updateTextBoxes() ## return task.cont ## def rotateCamDown(self, task): ## self.camera.setHpr(self.camera, 0, -2.0, 0) ## self.camView.camera.setHpr(self.camView.camera, 0, -2.0, 0) ## self.updateTextBoxes() ## return task.cont ## def rotateCamLeft(self, task): ## self.camera.setHpr(self.camera, 0, 0, 2.0) ## self.camView.camera.setHpr(self.camView.camera, 0, 0, 2.0) ## self.updateTextBoxes() ## return task.cont ## def rotateCamRight(self, task): ## self.camera.setHpr(self.camera, 0, 0, -2.0) ## self.camView.camera.setHpr(self.camView.camera, 0, 0, -2.0) ## self.updateTextBoxes() ## return task.cont ## def updateTextBoxes(self): ## self.txtX.SetValue(str(self.camera.getPos()[0])) ## self.txtY.SetValue(str(self.camera.getPos()[1])) ## self.txtZ.SetValue(str(self.camera.getPos()[2])) ## self.txtH.SetValue(str(self.camera.getHpr()[0])) ## self.txtP.SetValue(str(self.camera.getHpr()[1])) ## self.txtR.SetValue(str(self.camera.getHpr()[2]))
def OnCreate(self, e): self.Unbind(wx.EVT_INIT_DIALOG) base.le.ui.bindKeyEvents(False) self.filename = None self.name='' self.Ok = False self.assetType = "Static Mesh" self.importScene = NodePath(PandaNode("importScene")) self.import2d = NodePath(PandaNode("import2d")) self.import2dScaled =self.import2d.attachNewNode(PandaNode("import2dScaled")) self.objPreview = None self.thumbnailTaken = False self.Bind(wx.EVT_CLOSE, self.Close) base.direct.manipulationControl.disableManipulation() self.Show() #init all the panels from XRC for parenting later on self.mainPanel = xrc.XRCCTRL(self, "mainPanel") self.pandaPanel = xrc.XRCCTRL(self, "pandaPanel") self.animPanel = xrc.XRCCTRL(self, "animPanel") self.libraryPanel = xrc.XRCCTRL(self, "libraryPanel") self.typeSelector = xrc.XRCCTRL(self.libraryPanel, 'choiceAssetType') self.typeSelector.Bind(wx.EVT_CHOICE, self.onSwitchType) self.typeSelector.SetStringSelection(self.assetType) self.btnScreenshot = xrc.XRCCTRL(self.mainPanel, "btnScreenShot") self.btnScreenshot.Bind(wx.EVT_BUTTON, self.onScreenShot) self.btnScreenshot.Disable() self.imgThumbnail = xrc.XRCCTRL(self.libraryPanel, 'imgThumbnail') self.btnPlay = xrc.XRCCTRL(self.libraryPanel, "btnPlay") self.btnStop = xrc.XRCCTRL(self.libraryPanel, "btnStop") self.viewport = Viewport('persp', self.pandaPanel) self.viewport.SetClientSize((500,500)) ViewportManager.updateAll() base.le.ui.wxStep() self.viewport.initialize() self.handles = ObjectHandles('importUIWidget') self.handles.hide() base.direct.manipulationControl.widgetList.append(self.handles) base.direct.drList.addDisplayRegionContext(self.viewport.cam) #apply a mask to make sure GUI stuff from the main window doesn't show up here self.viewport.cam2d.node().setCameraMask(LE_IMPORT_MASK) self.viewport.camera.reparentTo(self.importScene) self.viewport.camera.setPos(-19,-19,19) self.viewport.camera.lookAt(0,0,0) self.viewport.cam2d.reparentTo(self.import2d) dlight = DirectionalLight('dlight') dlight.setColor(VBase4(0.8,0.8,0.8,1)) dlnp = self.importScene.attachNewNode(dlight) self.importScene.setLight(dlnp) dlnp.setHpr(45,-45,0) alight = AmbientLight('alight') alight.setColor(VBase4(0.25,0.25,0.25,1)) alnp = self.importScene.attachNewNode(alight) self.importScene.setLight(alnp) fileSelector = xrc.XRCCTRL(self.mainPanel, 'btnLoadAsset') fileSelector.Bind(wx.EVT_BUTTON, self.onFileSelect) if self.assetType != "Library": self.nameInput = xrc.XRCCTRL(self.libraryPanel, 'txtObjName') self.nameInput.Bind(wx.EVT_TEXT, self.onNameInput) self.okButton = xrc.XRCCTRL(self.mainPanel, 'btnSendToLibrary') self.okButton.Bind(wx.EVT_BUTTON, self.onOk) self.okButton.Enable(False) self.animPanel = xrc.XRCCTRL(self.mainPanel, 'animPanel') self.btnImportAnim = xrc.XRCCTRL(self.animPanel, 'btnImportAnim') self.btnImportAnim.Bind(wx.EVT_BUTTON, self.onImportAnim) self.btnImportAnim.Enable(False) self.btnRemoveSelected = xrc.XRCCTRL(self.animPanel, 'btnRemoveSelected') self.btnRemoveSelected.Bind(wx.EVT_BUTTON, self.onRemoveSelected) self.btnRemoveSelected.Enable(False) self.listCtrlAnim = xrc.XRCCTRL(self.animPanel, 'listCtrlAnim') self.listCtrlAnim.__class__ = ListCtrlMultiEdit self.btnPlay.Bind(wx.EVT_BUTTON, self.onPlaySound) self.btnStop.Bind(wx.EVT_BUTTON, self.onStopSound) self.listCtrlAnim.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.onEditAnim) self.listCtrlAnim.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelectAnim) self.imgThumbnail.Bind(wx.EVT_BUTTON, self.onScreenShot) TextEditMixin.__init__(self.listCtrlAnim) self.Layout()
class ImportUI(wx.Dialog): def __init__(self, parent, id, title): #Pre creation routine to allow wx to do layout from XRC pre = wx.PreDialog() self.res = xrc.XmlResource(GUI_FILENAME) self.res.LoadOnDialog(pre, parent, 'dlgImportUI') self.PostCreate(pre) self.Bind(wx.EVT_INIT_DIALOG, self.OnCreate) self.parent = parent def OnCreate(self, e): self.Unbind(wx.EVT_INIT_DIALOG) base.le.ui.bindKeyEvents(False) self.filename = None self.name='' self.Ok = False self.assetType = "Static Mesh" self.importScene = NodePath(PandaNode("importScene")) self.import2d = NodePath(PandaNode("import2d")) self.import2dScaled =self.import2d.attachNewNode(PandaNode("import2dScaled")) self.objPreview = None self.thumbnailTaken = False self.Bind(wx.EVT_CLOSE, self.Close) base.direct.manipulationControl.disableManipulation() self.Show() #init all the panels from XRC for parenting later on self.mainPanel = xrc.XRCCTRL(self, "mainPanel") self.pandaPanel = xrc.XRCCTRL(self, "pandaPanel") self.animPanel = xrc.XRCCTRL(self, "animPanel") self.libraryPanel = xrc.XRCCTRL(self, "libraryPanel") self.typeSelector = xrc.XRCCTRL(self.libraryPanel, 'choiceAssetType') self.typeSelector.Bind(wx.EVT_CHOICE, self.onSwitchType) self.typeSelector.SetStringSelection(self.assetType) self.btnScreenshot = xrc.XRCCTRL(self.mainPanel, "btnScreenShot") self.btnScreenshot.Bind(wx.EVT_BUTTON, self.onScreenShot) self.btnScreenshot.Disable() self.imgThumbnail = xrc.XRCCTRL(self.libraryPanel, 'imgThumbnail') self.btnPlay = xrc.XRCCTRL(self.libraryPanel, "btnPlay") self.btnStop = xrc.XRCCTRL(self.libraryPanel, "btnStop") self.viewport = Viewport('persp', self.pandaPanel) self.viewport.SetClientSize((500,500)) ViewportManager.updateAll() base.le.ui.wxStep() self.viewport.initialize() self.handles = ObjectHandles('importUIWidget') self.handles.hide() base.direct.manipulationControl.widgetList.append(self.handles) base.direct.drList.addDisplayRegionContext(self.viewport.cam) #apply a mask to make sure GUI stuff from the main window doesn't show up here self.viewport.cam2d.node().setCameraMask(LE_IMPORT_MASK) self.viewport.camera.reparentTo(self.importScene) self.viewport.camera.setPos(-19,-19,19) self.viewport.camera.lookAt(0,0,0) self.viewport.cam2d.reparentTo(self.import2d) dlight = DirectionalLight('dlight') dlight.setColor(VBase4(0.8,0.8,0.8,1)) dlnp = self.importScene.attachNewNode(dlight) self.importScene.setLight(dlnp) dlnp.setHpr(45,-45,0) alight = AmbientLight('alight') alight.setColor(VBase4(0.25,0.25,0.25,1)) alnp = self.importScene.attachNewNode(alight) self.importScene.setLight(alnp) fileSelector = xrc.XRCCTRL(self.mainPanel, 'btnLoadAsset') fileSelector.Bind(wx.EVT_BUTTON, self.onFileSelect) if self.assetType != "Library": self.nameInput = xrc.XRCCTRL(self.libraryPanel, 'txtObjName') self.nameInput.Bind(wx.EVT_TEXT, self.onNameInput) self.okButton = xrc.XRCCTRL(self.mainPanel, 'btnSendToLibrary') self.okButton.Bind(wx.EVT_BUTTON, self.onOk) self.okButton.Enable(False) self.animPanel = xrc.XRCCTRL(self.mainPanel, 'animPanel') self.btnImportAnim = xrc.XRCCTRL(self.animPanel, 'btnImportAnim') self.btnImportAnim.Bind(wx.EVT_BUTTON, self.onImportAnim) self.btnImportAnim.Enable(False) self.btnRemoveSelected = xrc.XRCCTRL(self.animPanel, 'btnRemoveSelected') self.btnRemoveSelected.Bind(wx.EVT_BUTTON, self.onRemoveSelected) self.btnRemoveSelected.Enable(False) self.listCtrlAnim = xrc.XRCCTRL(self.animPanel, 'listCtrlAnim') self.listCtrlAnim.__class__ = ListCtrlMultiEdit self.btnPlay.Bind(wx.EVT_BUTTON, self.onPlaySound) self.btnStop.Bind(wx.EVT_BUTTON, self.onStopSound) self.listCtrlAnim.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.onEditAnim) self.listCtrlAnim.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelectAnim) self.imgThumbnail.Bind(wx.EVT_BUTTON, self.onScreenShot) TextEditMixin.__init__(self.listCtrlAnim) self.Layout() def onPlaySound(self, evt): base.sfxManagerList[0].stopAllSounds() self.objPreview.setLoop(False) self.objPreview.play() def onStopSound(self, evt): self.objPreview.stop() def onScreenShot(self, evt): if self.assetType == "Static Mesh" or self.assetType == "Actor": camnode = self.viewport.cam.node() dr = camnode.getDisplayRegion(0) filename = Filename("thumbnail") filename.setDirname(Util.getTempDir()) filename.setExtension("jpg") dr.saveScreenshot(filename) #resize to 60x60 cwd = os.getcwd() os.chdir(Filename(filename.getDirname()).toOsSpecific()) subprocess.call(["image-resize","-x 60", "-y 60", "-g 1", "-o" + filename.getBasename(), filename.getBasename()]) os.chdir(cwd) self.imgThumbnail.SetBitmapLabel(wx.Bitmap(filename.toOsSpecific())) self.thumbnailTaken = True def onSwitchType(self, evt): self.assetType = self.typeSelector.GetStringSelection() self.nameInput.SetValue("") self.name = None self.filename = None self.thumbnailTaken = False self.btnScreenshot.Disable() if self.objPreview: if not isinstance(self.objPreview, AudioSound): self.objPreview.removeNode() if self.assetType == "Static Mesh" or self.assetType == "Actor": self.viewport.camera.setPos(-19,-19,19) self.viewport.camera.lookAt(0,0,0) self.btnImportAnim.Enable(False) self.btnRemoveSelected.Enable(False) self.btnPlay.Enable(False) self.btnStop.Enable(False) base.sfxManagerList[0].stopAllSounds() self.listCtrlAnim.ClearAll() if self.assetType == "Actor": self.listCtrlAnim.InsertColumn(0, "Local Name") self.listCtrlAnim.InsertColumn(1, "Asset Name") self.listCtrlAnim.InsertColumn(2, "File") for i in range(self.listCtrlAnim.GetColumnCount()): self.listCtrlAnim.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER) def onNameInput(self, evt): iPoint = self.nameInput.GetInsertionPoint() self.nameInput.ChangeValue(Util.toAssetName(self.nameInput.GetValue(), False)) self.nameInput.SetInsertionPoint(iPoint) self.name = self.nameInput.GetValue() if self.name and self.filename: self.okButton.Enable(True) else: self.okButton.Enable(False) def onFileSelect(self, evt): self.thumbnailTaken = False fileType = "*.*" if self.assetType == "Static Mesh" or self.assetType == "Actor" or self.assetType == "Animation": fileType = "Egg files (*.egg;*.egg.pz)|*.egg;*.egg.pz" elif self.assetType == "Texture" or self.assetType == "Terrain": fileType = "Texture files (*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif;*.avi;*.mpg;*.mpeg;*.dds)|*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif;*.avi;*.mpg;*.mpeg;*.dds" elif self.assetType == "Shader": fileType = "Shader files (*.sha;*.cg)|*.sha;*.cg" elif self.assetType == "Sound": fileType = "Sound files (*.wav;*.mp3;*.aiff;*.ogg) | *.wav;*.mp3;*.aiff;*.ogg" elif self.assetType == "Texture Sequence": fileType = "Texture files (*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif)|*.png;*.jpg;*.jpeg;*.bmp;*.rgb;*.tif" elif self.assetType == "Journal Entry": fileType = "Journal Entry files (*.xml)|*.xml" elif self.assetType == "Conversation": fileType = "Conversation files (*.xml)|*.xml" if self.assetType != "Texture Sequence": dialog = wx.FileDialog(self, "Select a " + self.assetType +" file", wildcard=fileType, style=wx.FD_OPEN ) else: dialog = wx.FileDialog(self, "Select the texture files to use.", wildcard=fileType, style=wx.FD_OPEN|wx.FD_MULTIPLE) if dialog.ShowModal() == wx.ID_OK: base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) if self.assetType != "Texture Sequence": self.filename = Filename.fromOsSpecific(dialog.GetPath()) self.name = self.filename.getBasenameWoExtension() else: filenames = [] for p in sorted(dialog.GetPaths()): filenames.append(Filename.fromOsSpecific(p)) self.name = filenames[0].getBasenameWoExtension().strip('1234567890-_') self.okButton.Enable(True) self.nameInput.SetValue(self.name) if self.assetType == "Static Mesh": if self.objPreview: self.objPreview.removeNode() self.objPreview = loader.loadModel(self.filename) self.objPreview.reparentTo(self.importScene) self.btnScreenshot.Enable(True) center = self.objPreview.getBounds().getCenter() radius = self.objPreview.getBounds().getRadius() self.viewport.camera.setPos(center + Vec3(-radius*2,-radius*2,radius*2)) self.viewport.camera.lookAt(center) self.viewport.camLens.setNearFar(radius/10, radius*1000) elif self.assetType == "Texture" or self.assetType == "Terrain": if self.objPreview: self.objPreview.removeNode() self.objPreview = OnscreenImage(parent=self.import2d, image = self.filename.getFullpath(), pos = (0.0,0.0,0.0)) x = float(self.objPreview.getTexture().getOrigFileXSize()) y = float(self.objPreview.getTexture().getOrigFileYSize()) if x == 0.0 or y == 0.0: x = float(self.objPreview.getTexture().getVideoWidth()) * self.objPreview.getTexture().getTexScale().getX() y = float(self.objPreview.getTexture().getVideoHeight()) * self.objPreview.getTexture().getTexScale().getY() self.objPreview.setTexScale(TextureStage.getDefault(), self.objPreview.getTexture().getTexScale()) if x>y: self.objPreview.setScale(1, 1, y/x) else: self.objPreview.setScale(x/y, 1, 1) self.objPreview.setLightOff(True) elif self.assetType == "Actor": self.btnImportAnim.Enable(True) if self.objPreview: self.objPreview.removeNode() self.objPreview = Actor(self.filename, {}) self.objPreview.reparentTo(self.importScene) self.btnScreenshot.Enable(True) center = self.objPreview.getBounds().getCenter() radius = self.objPreview.getBounds().getRadius() self.viewport.camera.setPos(center + Vec3(-radius*2,-radius*2,radius*2)) self.viewport.camera.lookAt(center) self.viewport.camLens.setNearFar(radius/10, radius*1000) elif self.assetType == "Texture Sequence": tempFolder = Filename.fromOsSpecific(Util.getTempDir() + '/staging') if os.path.exists((tempFolder + ' /').toOsSpecific()): shutil.rmtree(tempFolder.toOsSpecific()) os.makedirs(tempFolder.toOsSpecific()) for f in filenames: dest = tempFolder + '/' + f.getBasename() shutil.copy(f.toOsSpecific(), tempFolder.toOsSpecific()) fileAtt = os.stat(dest.toOsSpecific())[0] if (not fileAtt & stat.S_IWRITE): os.chmod(dest.toOsSpecific(), stat.S_IWRITE) f.setDirname(tempFolder.getFullpath()) args = ["egg-texture-cards","-o", self.name + ".egg", "-fps", "30"] for f in filenames: args.append(f.getBasename()) cwd = os.getcwd() os.chdir(tempFolder.toOsSpecific()) subprocess.call(args) os.chdir(cwd) self.filename = tempFolder + '/' + self.name + '.egg' if self.objPreview: self.objPreview.removeNode() self.objPreview = loader.loadModel(self.filename) self.objPreview.reparentTo(self.importScene) self.viewport.camera.setPos(0, -5, 0) self.viewport.camera.lookAt(0,0,0) self.viewport.camLens.setNearFar(0.1, 10000) self.okButton.Enable(True) elif self.assetType == "Sound": if self.objPreview: if not isinstance(self.objPreview, AudioSound): self.objPreview.removeNode() self.objPreview = loader.loadSfx(self.filename.getFullpath()) self.btnPlay.Enable() self.btnStop.Enable() base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) dialog.Destroy() def onImportAnim(self, evt): dialog = wx.FileDialog(self, "Select an animation file", style=wx.FD_OPEN, wildcard= "Egg files(*.egg;*.egg.pz)|*.egg;*.egg.pz") if dialog.ShowModal() == wx.ID_OK: filename = Filename.fromOsSpecific(dialog.GetPath()) pos = self.listCtrlAnim.InsertStringItem(self.listCtrlAnim.GetItemCount(), filename.getBasenameWoExtension()) self.listCtrlAnim.SetStringItem(pos, 1, filename.getBasenameWoExtension()) self.listCtrlAnim.SetStringItem(pos, 2, filename.toOsSpecific()) self.listCtrlAnim.Select(pos, True) self.listCtrlAnim.EnsureVisible(pos) for i in range(self.listCtrlAnim.GetColumnCount()): self.listCtrlAnim.SetColumnWidth(i, wx.LIST_AUTOSIZE) self.btnRemoveSelected.Enable(True) def onEditAnim(self, evt): if evt.GetColumn() == 0: if Util.toAssetName(evt.GetText()) != evt.GetText(): evt.Veto() elif evt.GetColumn() == 1: if Util.toAssetName(evt.GetText()) != evt.GetText(): evt.Veto() else: evt.Veto() def onSelectAnim(self, evt): self.objPreview.stop() self.objPreview.unloadAnims() id = evt.GetItem().GetId() name = self.listCtrlAnim.GetItem(id, 0).GetText() file = Filename.fromOsSpecific(self.listCtrlAnim.GetItem(id, 2).GetText()) self.objPreview.loadAnims({name:file}) self.objPreview.loop(name) def onRemoveSelected(self, evt): toDelete = self.listCtrlAnim.GetFirstSelected() self.objPreview.stop() self.objPreview.unloadAnims() self.listCtrlAnim.DeleteItem(toDelete) if self.listCtrlAnim.GetItemCount() == 0: self.btnRemoveSelected.Enable(False) else: self.listCtrlAnim.Select(0) def onOk(self, evt): self.Ok = True libFile =(base.le.lib.projDir + '/lib.index').toOsSpecific() while True: #make sure that the library file is writable try: f = open(libFile, 'a') f.close() except IOError as e: dlg = wx.MessageDialog(self, "The library file '" + libFile + "' could not be written.\ Make sure that it is not marked read-only and click OK.", caption = "Permission Denied", style = wx.OK|wx.CANCEL|wx.ICON_ERROR) if dlg.ShowModal() == wx.ID_CANCEL: self.Close() return else: break removedAssetsDir = Filename.fromOsSpecific(Util.getTempDir()) + '/removedAssets' if os.path.exists((removedAssetsDir + '/').toOsSpecific()): shutil.rmtree(removedAssetsDir.toOsSpecific()) self.removedAssets = [] if self.assetType == "Static Mesh" or self.assetType == "Texture Sequence": mesh = self.getMesh() while True: try: base.le.lib.checkMesh(mesh) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.oldAsset.__class__.__name__ == 'Mesh': self.restoreAssets() self.Close() return mesh.textures.remove(e.newAsset) mesh.textures.append(e.oldAsset) except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.asset.__class__.__name__ == 'Mesh': self.restoreAssets() self.Close() return mesh.textures.remove(e.asset) f = Filename.fromOsSpecific(e.destPath) f.makeRelativeTo(base.le.lib.projDir) mesh.textures.append(base.le.lib.filenameIndex[f]) except Library.TextureNotFoundError as e: message = "Egg file contains an invalid texture reference.\n" message += "Texture '" + e.filename.getFullpath() + "' not found.\n" message += "Please fix your texture paths in your egg file before importing." dialog = wx.MessageDialog(self, message, "Texture Not Found", style = wx.OK|wx.ICON_ERROR) dialog.ShowModal() dialog.Destroy() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addMesh(mesh, True) if self.thumbnailTaken: thumbnailPath = base.le.lib.projDir + '/Models/Thumbnails/' + \ mesh.filename.getBasenameWoExtension() + '.jpg' tempPath = Filename.fromOsSpecific(Util.getTempDir() + '/thumbnail.jpg') shutil.move(tempPath.toOsSpecific(),\ (thumbnailPath).toOsSpecific()) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Actor": actor = self.getActor() for anim in self.anims: while True: try: base.le.lib.checkAnimation(anim) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: self.anims.remove(e.newAsset) self.anims.append(e.oldAsset) except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: self.anims.remove(e.asset) f = Filename.fromOsSpecific(e.destPath) f.makeRelativeTo(base.le.lib.projDir) self.anims.append(base.le.lib.filenameIndex[f]) else: break while True: try: base.le.lib.checkActor(actor) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.oldAsset.__class__.__name__ == 'Actor': self.restoreAssets() self.Close() return actor.textures.remove(e.newAsset) actor.textures.append(e.oldAsset) except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL: self.restoreAssets() self.Close() return elif result == SKIP: if e.asset.__class__.__name__ == 'Actor': self.restoreAssets() self.Close() return actor.textures.remove(e.asset) f = Filename.fromOsSpecific(e.destPath) f.makeRelativeTo(base.le.lib.projDir) actor.textures.append(base.le.lib.filenameIndex[f]) except Library.TextureNotFoundError as e: message = "Egg file contains an invalid texture reference.\n" message += "Texture '" + e.filename.getFullpath() + "' not found.\n" message += "Please fix your texture paths in your egg file before importing." dialog = wx.MessageDialog(self, message, "Texture Not Found", style = wx.OK|wx.ICON_ERROR) dialog.ShowModal() dialog.Destroy() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) for anim in self.anims: base.le.lib.addAnimation(anim) base.le.lib.addActor(actor, True) if self.thumbnailTaken: thumbnailPath = base.le.lib.projDir + '/Models/Thumbnails/' + \ actor.filename.getBasenameWoExtension() + '.jpg' tempPath = Filename.fromOsSpecific(Util.getTempDir() + '/thumbnail.jpg') shutil.move(tempPath.toOsSpecific(), (thumbnailPath).toOsSpecific()) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Animation": anim = self.getAnimation() while True: try: base.le.lib.checkAnimation(anim) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addAnimation(anim) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Texture": tex = self.getTexture() while True: try: base.le.lib.checkTexture(tex) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addTexture(tex,True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Shader": shader = self.getShader() while True: try: base.le.lib.checkShader(shader) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addShader(shader, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Sound": sound = self.getSound() while True: try: base.le.lib.checkSound(sound) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addSound(sound, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Terrain": tex = self.getTerrain() while True: try: base.le.lib.checkTerrain(tex) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if not result: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addTerrain(tex, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) #TODO: Take the Journal Entry import from Import assets. elif self.assetType == "Script": script = self.getScript() while True: try: base.le.lib.checkScript(script) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addScript(script, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) elif self.assetType == "Conversation": conversation = self.getConversation() while True: try: base.le.lib.checkConversation(conversation) except Library.DuplicateNameError as e: dialog = DuplicateNameDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return except Library.FileCollisionError as e: dialog = FileCollisionDialog(self, -1, e) result = dialog.ShowModal() dialog.Destroy() if result == CANCEL or result == SKIP: self.restoreAssets() self.Close() return else: break base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) base.le.lib.addConversation(conversation, True) base.le.ui.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) if not base.le.saved: base.le.fNeedToSave = True base.le.ui.libraryUI.update() base.le.ui.storyObjUI.update() self.Close() #restores any assets that have been "deleted"(moved to temp folder) if we cancel an import #also restores assets that were removed from library def restoreAssets(self): #restore any files which were "deleted" for dir in ('Models', 'Textures', 'Shaders', 'Sounds', 'Journal_Entries', 'Conversations', 'Scripts'): d = os.path.join(Util.getTempDir(), 'removedAssets', dir) if os.path.exists(d): for file in os.listdir(d): shutil.move(os.path.join(d, file), (base.le.lib.projDir + '/' + dir + '/').toOsSpecific()) #add assets back into library for asset in self.removedAssets: base.le.lib.restoreAsset(asset) self.removedAssets = [] def Close(self, evt=None): self.viewport.Close() base.direct.manipulationControl.widgetList.remove(self.handles) base.direct.drList.removeDisplayRegionContext(self.viewport.cam) base.direct.manipulationControl.enableManipulation() base.le.ui.bindKeyEvents(True) self.Destroy() def getMesh(self): if self.thumbnailTaken: thumbnailPath = Filename('/Models/Thumbnails/' + self.filename.getBasenameWoExtension() + '.jpg') return Library.Mesh(Util.toAssetName(self.name), self.filename, thumbnailPath) else: return Library.Mesh(Util.toAssetName(self.name), self.filename) def getTexture(self): return Library.Texture(Util.toAssetName(self.name), self.filename) def getActor(self): self.anims, myAnims = self.getAnims() if self.thumbnailTaken: thumbnailPath = Filename('/Models/Thumbnails/' + self.filename.getBasenameWoExtension() + '.jpg') return Library.Actor(Util.toAssetName(self.name), self.filename, thumbnailPath, anims=myAnims) else: return Library.Actor(Util.toAssetName(self.name), self.filename, anims=myAnims) def getAnimation(self): return Library.Animation(Util.toAssetName(self.name), self.filename) def getAnims(self): anims = [] myAnims = {} for i in range(self.listCtrlAnim.GetItemCount()): a = Library.Animation(self.listCtrlAnim.GetItem(i,1).GetText(), Filename.fromOsSpecific(self.listCtrlAnim.GetItem(i,2).GetText())) if a not in anims: anims.append(a) myAnims[self.listCtrlAnim.GetItem(i, 0).GetText()] = a else: #if an equivalent animation is already in the list, use that one myAnims[self.listCtrlAnim.GetItem(i, 0).GetText()] = anims[anims.index(a)] return anims, myAnims def getShader(self): return Library.Shader(Util.toAssetName(self.name), self.filename) def getSound(self): return Library.Sound(Util.toAssetName(self.name), self.filename) def getTerrain(self): return Library.Terrain(Util.toAssetName(self.name), self.filename) def getJournalEntry(self): return Library.JournalEntry(Util.toAssetName(self.name),self.filename) def getScript(self): return Library.Script(Util.toAssetName(self.name),self.filename) def getConversation(self): return Library.ConversationAsset(Util.toAssetName(self.name), self.filename)