Esempio n. 1
0
 def OnNamespaceFilePathSwapped(self, objNS, pOldPath, pNewPath, applyEdits ):
     
     lScene = self.mSys.Scene
     
     if (False == applyEdits):
         
         # do we have any other instances with old path
         anyOtherInstance = False
         for ns in self.mSys.Scene.Namespaces:
             if isinstance(ns, FBFileReference):
                 refPath = ns.ReferenceFilePath
                 if pOldPath == refPath and ns != objNS:
                     anyOtherInstance = True
                     break
         
         if True == anyOtherInstance:
             misc.DisconnectAllShaders(objNS)
             misc.DescriptionDisconnect(objNS)
         else:
             misc.DeleteShadersGraph(objNS, pOldPath)
         
         modelsMask = []
         objNS.RevertRefEdit()
         imp.DoFbxShadersGraphImport(True, 2, objNS, modelsMask)
         
         # holder
         base = os.path.splitext(pNewPath)[0]
         newXml = base + '.xml'
         misc.DescriptionStore(objNS, str(newXml))
         
     else:
         misc.SwapShadersGraph(objNS, str(pOldPath), str(pNewPath))
Esempio n. 2
0
 def OnBtnShaderRestoreClicked(self):
     lIndexes = self.uiTableNamespace.selectedIndexes()
     for lIndex in lIndexes:
         if lIndex.column() == 0:
             lNSObj = self.mNSModel.GetNamespace(lIndex.row())
             lNSObj.RevertRefEdit()
             # if we have shaders graph, let's assign it from scratch
             imp.RestoreShadersGraph(lNSObj)
             
             self.mNSModel.Refresh( lIndex )
     self.UpdateUI()
Esempio n. 3
0
    def OnBtnLoadClicked( self ):
        
        lLoadCount = self.uiSpinLoadTimes.value()
        lBtnClicked, lName = PickRefName()
        if lBtnClicked == 2: return

        lNameList = FBStringList()
        if lLoadCount == 1:
            lNameList.Add( lName )
        else:
            for lCount in range( 0, lLoadCount ):
                if self.mSys.Scene.NamespaceGet( lName + str(lCount+1) ) <> None:
                    lMsgBox = QtGui.QMessageBox( QtGui.QMessageBox.Information, 'Loading', 'Creation of file reference %s will be skipped as it is already there.' % ( lName + str(lCount+1) ), QtGui.QMessageBox.Ok, self )
                    lMsgBox.exec_()
                else:
                    lNameList.Add( lName + str(lCount+1) )
        
        lStatus = self.mSys.Scene.NamespaceImportToMultiple( lNameList, str(self.uiEditFilePath.text()), True )
        # import shaders graph
        if True == lStatus:
            
            # create a description holder
            descHolder = FBCreateObject(misc.gDescAssetPath, misc.gDescTitle, lName + '_DescHolder')
            descProp = None
            
            if descHolder is not None:
                descProp = descHolder.PropertyList.Find('Reference Model')
                    
            
            # we do shaders graph copies
            for name in lNameList:
                objNS = self.mSys.Scene.NamespaceGet( name  )

                if descProp is not None:
                    FBConnect(objNS, descProp)
                
                if objNS.IsLoaded:
                    modelsMask = []
                    imp.DoFbxShadersGraphImport(True, 1, objNS, modelsMask)
                    if descHolder is not None:
                        prop = descHolder.PropertyList.Find('Store')
                        if prop is not None:
                            prop()
                else:
                    prop = objNS.PropertyCreate( 'FirstTime',  FBPropertyType.kFBPT_bool, 'Bool', False, True, None )
                    if prop is not None:
                        prop.Data = True
                    
        self.mNSModel.Refresh()
        self.UpdateUI()
def AddAReference():

    lDialog = FBFilePopup()
    lDialog.Style = FBFilePopupStyle.kFBFilePopupOpen
    lDialog.Filter = '*.fbx'

    if lDialog.Execute():
        fname = lDialog.FullFilename

        lBtnClicked, lName = PickRefName()
        if lBtnClicked == 2: return

        lNameList = FBStringList()
        lNameList.Add(lName)

        lStatus = mSys.Scene.NamespaceImportToMultiple(lNameList, fname, True)
        # import shaders graph
        if True == lStatus:

            # create a description holder
            descHolder = FBCreateObject(misc.gDescAssetPath, misc.gDescTitle,
                                        lName + '_DescHolder')
            descProp = None

            if descHolder is not None:
                descProp = descHolder.PropertyList.Find('Reference Model')

            # we do shaders graph copies
            for name in lNameList:
                objNS = mSys.Scene.NamespaceGet(name)

                if descProp is not None:
                    FBConnect(objNS, descProp)

                if objNS.IsLoaded:
                    modelsMask = []
                    imp.DoFbxShadersGraphImport(True, 1, objNS, modelsMask)
                    if descHolder is not None:
                        prop = descHolder.PropertyList.Find('Store')
                        if prop is not None:
                            prop()
                else:
                    FBMessageBox("Reference A File",
                                 "Failed to load a reference", "Ok")
Esempio n. 5
0
    def OnBtnShowShaderEditsClicked(self):
        
        if self.mSingleSelection:
            lIndexes = self.uiTableNamespace.selectedIndexes()
            lNSObj = self.mNSModel.GetNamespace(lIndexes[0].row())
        
            lShaders = []
            lList = []
            
            misc.CollectReferenceContent(lNSObj, lList)
            
            for lPlug in lList:
                
                if isinstance(lPlug, FBModel):
                    for lShader in lPlug.Shaders:
                        if not (lShader in lShaders):
                            lShaders.append(lShader)

            # compare shaders with shaders Graph description
            text = imp.CompareShadersGraph(lNSObj, lShaders)
            
            lMsgBox = QtGui.QMessageBox( self )
            lMsgBox.setText( text )
            lMsgBox.exec_()
Esempio n. 6
0
lNSObj = None

if len(lRefName) > 0:

    for ns in lScene.Namespaces:
        if isinstance(ns, FBFileReference) and lRefName == ns.LongName:
            if False == os.path.isfile(ns.ReferenceFilePath):
                FBMessageBox('Reference A File',
                             'Referenced file is not found!', 'Ok')
            else:
                lNSObj = ns
            break

if lNSObj is not None:
    filename = lNSObj.ReferenceFilePath
    isUpdated = imp.HasReferenceNewUpdate(lNSObj)
    lOption = 3

    if isUpdated:
        # ask user to reload a shaders graph
        lOption = FBMessageBox(
            "External File Changed",
            "Please choose the following action for Reference: %s!" %
            (filename), "Load", "Merge", "Ignore")

    if lOption <> 3:
        lUndo = FBUndoManager()
        lUndo.Clear()

        modelsMask = []
Esempio n. 7
0
                # do we have any other instances with old path
                anyOtherInstance = False
                for ns in self.mSys.Scene.Namespaces:
                    if isinstance(ns, FBFileReference):
                        refPath = ns.ReferenceFilePath
                        if pOldPath == refPath and ns != objNS:
                            anyOtherInstance = True
                            break
                
                if True == anyOtherInstance:
                    misc.DisconnectAllShaders(objNS)
                    misc.DescriptionDisconnect(objNS)
                else:
                    misc.DeleteShadersGraph(objNS, pOldPath)
                
                modelsMask = []
                objNS.RevertRefEdit()
                imp.DoFbxShadersGraphImport(True, 2, objNS, modelsMask)
                
                # holder
                base = os.path.splitext(pNewPath)[0]
                newXml = base + '.xml'
                misc.DescriptionStore(objNS, str(newXml))
                
            else:
                misc.SwapShadersGraph(objNS, str(pOldPath), str(pNewPath))         
                
            
# Remove temp sys.path
#sys.path.remove( os.path.join( os.path.dirname(lCurFilePath), 'MBFileRefAdvanced' ) )
sys.path.remove( os.path.dirname(lCurFilePath) )
Esempio n. 8
0
import inspect
import sys
import os

lCurFilePath = inspect.currentframe().f_code.co_filename
sys.path.append( os.path.dirname(lCurFilePath) )
#sys.path.append( os.path.join( os.path.dirname(lCurFilePath), 'MBFileRefAdvanced' ) )

import FbxShadersGraphImport as imp
#import FbxShadersGraphMisc as misc

lRefName = ''
lSystem = FBSystem()
lScene = lSystem.Scene

if len(lRefName) > 0:
    
    for ns in lScene.Namespaces:
        if isinstance(ns, FBFileReference) and lRefName == ns.LongName:
            
            ns.IsLoaded = False
            ns.IsLoaded = True
            
            ns.RevertRefEdit()
            # if we have shaders graph, let's assign it from scratch
            imp.RestoreShadersGraph(ns)            
            
            
# Remove temp sys.path
#sys.path.remove( os.path.join( os.path.dirname(lCurFilePath), 'MBFileRefAdvanced' ) )
sys.path.remove( os.path.dirname(lCurFilePath) )
Esempio n. 9
0
    def OnTimer( self ):
        for lFilePath, lReload in self.mNSModel.mRefFileReload.items():
            
            if False == os.path.isfile(lFilePath) and True == lReload:
                FBMessageBox( "External File Not Found", "The referenced file '%s' is not found!\nReference goes offline" % ( lFilePath ), "Ok" )
                
                if lFilePath in self.mNSModel.mRefFilePath:
                    for lFileRefName in self.mNSModel.mRefFilePath[lFilePath]:
                        lFileRefObj = FBFindObjectByFullName( 'FileReference::' + lFileRefName )
                        
                        if lFileRefObj is not None:
                            self.mNSModel.RemoveFileFromWatcher( lFileRefObj )
                            lFileRefObj.IsLoaded = False
                                
                    self.mNSModel.mRefFileReload[lFilePath] = False
                
                self.UpdateUI()
                self.UpdateTreeNamespace()
                
            elif lReload:
                FBMessageBox( "External File Changed", "The referenced file '%s' has been changed externally!" % ( lFilePath ), "OK" )
                if lFilePath in self.mNSModel.mRefFilePath:
                    for lFileRefName in self.mNSModel.mRefFilePath[lFilePath]:
                        lNSObj = FBFindObjectByFullName( 'FileReference::' + lFileRefName )
                        lOption = FBMessageBox( "External File Changed", "Please choose the following action for Reference: %s!" % ( lFileRefName ), "Load", "Merge", "Ignore" )
                        
                        if lOption <> 3:
                            lUndo = FBUndoManager()
                            lUndo.Clear()
                            
                            diff = []
                            
                            edits = ''
                            misc.DisconnectAllShaders(lNSObj)
                            if lNSObj.GetContentModified( FBPlugModificationFlag.kFBContentAllModifiedMask ):
                                edits = lNSObj.GetRefEdit()
                            
                            lNSObj.IsLoaded = False
                            lNSObj.IsLoaded = True
                            
                            filename = lNSObj.ReferenceFilePath
                            
                            base = os.path.splitext(filename)[0]
                            xmlname = base + '.xml'
                            
                            if lOption == 2:
                                
                                imp.DoFbxShadersGraphImport(True, 2, lNSObj, diff)
                                if len(edits) > 0:
                                    lNSObj.RevertRefEdit()
                                    lNSObj.ApplyRefEditPyScriptFromString( edits )
                                 
                                imp.LoadShaderGraphConnections(xmlname, xmlname, lNSObj, True)
                                
                            else:
                                modelsMask = []
                                lNSObj.RevertRefEdit()
                                imp.DoFbxShadersGraphImport(True, 2, lNSObj, modelsMask)
                            
                            # store new xml data
                            misc.DescriptionStore(lNSObj)
                            
                    self.mNSModel.mRefFileReload[lFilePath] = False

        self.mNSModel.UpdateFileWatcher()