Beispiel #1
0
def KrakenBuildGuideFromRig_Execute(sceneRig):

    # Deffered importing: We can only import the kraken modules after the
    # plugin has loaded, as it configures the python import paths on load.
    from kraken.core.objects.rig import Rig
    from kraken import plugins

    from kraken.helpers.utility_methods import prepareToSave, prepareToLoad

    if sceneRig == None and si.Interactive is True:
        pickSceneRig = si.PickElement(constants.siModelFilter,
                                      "Kraken: Pick Rig", "Kraken: Pick Rig")
        if pickSceneRig('ButtonPressed') == 0:
            pass
        else:
            pickedSceneRig = pickSceneRig('PickedElement')

            if pickedSceneRig.Properties('krakenRig') is None:
                log(
                    "Kraken: Picked object is not the top node of a Kraken Rig!",
                    4)
                return False

            sceneRig = pickedSceneRig
    else:
        if sceneRig.Properties('krakenRig') is None:
            log(
                "Kraken: 'sceneRig' argument is not the top node of a Kraken Rig!",
                4)
            return False

    if sceneRig.Properties('krakenRigData') is None:
        log("Kraken: 'sceneRig' does not have a 'krakenRigData' property!", 4)
        return False

    guideData = sceneRig.Properties('krakenRigData').Value

    rig = Rig()
    jsonData = json.loads(guideData)
    jsonData = prepareToLoad(jsonData)
    rig.loadRigDefinition(jsonData)
    rig.setName(rig.getName())

    builtRig = None
    progressBar = None
    try:

        progressBar = XSIUIToolkit.ProgressBar
        progressBar.Caption = "Building Kraken Rig: " + rig.getName()
        progressBar.CancelEnabled = False
        progressBar.Visible = True

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

    finally:
        if progressBar is not None:
            progressBar.Visible = False

    return builtRig
Beispiel #2
0
    def buildRig(self):

        try:
            self.window().setCursor(QtCore.Qt.WaitCursor)

            self.window().statusBar.showMessage('Building Rig')

            initConfigIndex = self.window().krakenMenu.configsWidget.currentIndex()

            self.synchGuideRig()

            rigBuildData = self.guideRig.getRigBuildData()
            rig = Rig()
            rig.loadRigDefinition(rigBuildData)

            rig.setName(rig.getName().replace('_guide', ''))

            if self.window().preferences.getPreferenceValue('delete_existing_rigs'):
                if self._builder:
                    self._builder.deleteBuildElements()

            self._builder = plugins.getBuilder()
            self._builder.build(rig)

            logger.inform('Rig Build Success')

            self.window().krakenMenu.setCurrentConfig(initConfigIndex)

        except Exception as e:
            logger.exception('Error Building')

        finally:
            self.window().setCursor(QtCore.Qt.ArrowCursor)
Beispiel #3
0
    def doIt(self, argList):

        selObjects = self.parseArgs(argList)
        if selObjects.length() < 1:
            OpenMaya.MGlobal.displayWarning('Kraken: No objects selected, Build Guide From Rig cancelled.')
            return False

        firstObj = OpenMaya.MObject()
        selObjects.getDependNode(0, firstObj)

        firstObjDepNode = maya.OpenMaya.MFnDependencyNode(firstObj)
        if firstObjDepNode.hasAttribute('krakenRig') is False:
            OpenMaya.MGlobal.displayWarning('Kraken: Selected object is not the top node of a Kraken Rig!')
            return False

        guideData = firstObjDepNode.findPlug("krakenRigData").asString()

        rig = Rig()
        jsonData = json.loads(guideData)
        jsonData = prepareToLoad(jsonData)
        rig.loadRigDefinition(jsonData)
        rig.setName(rig.getName())

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

        # return builtRig
        return None
Beispiel #4
0
    def doIt(self, argList):

        selObjects = self.parseArgs(argList)
        if selObjects.length() < 1:
            OpenMaya.MGlobal.displayWarning('Kraken: No objects selected, Build Rig cancelled.')
            return False

        firstObj = OpenMaya.MObject()
        selObjects.getDependNode(0, firstObj)

        firstObjDepNode = maya.OpenMaya.MFnDependencyNode(firstObj)
        if firstObjDepNode.hasAttribute('krakenRig') is False:
            OpenMaya.MGlobal.displayWarning('Kraken: Selected object is not the top node of a Kraken Rig!')
            return False

        guideName = firstObjDepNode.name()
        guideRig = BipedGuideRig(guideName)

        synchronizer = plugins.getSynchronizer()

        if guideRig.getName().endswith('_guide') is False:
            guideRig.setName(guideRig.getName() + '_guide')

        synchronizer.setTarget(guideRig)
        synchronizer.sync()

        rigBuildData = guideRig.getRigBuildData()
        rig = Rig()
        rig.loadRigDefinition(rigBuildData)
        rig.setName(rig.getName().replace('_guide', '_rig'))

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

        return builtRig
Beispiel #5
0
def buildBob(mode='guide'):

    Profiler.getInstance().push("bob_build")

    bobGuideRig = Rig("char_bob")
    bobGuideRig.loadRigDefinition(bob_guide_data)

    if mode == 'guide':
        builder = plugins.getBuilder()
        builder.build(bobGuideRig)

    elif mode == 'rig':
        synchronizer = plugins.getSynchronizer()
        synchronizer.setTarget(bobGuideRig)
        synchronizer.sync()

        bobRigData = bobGuideRig.getGuideData()
        bobRig = Rig()
        bobRig.loadRigDefinition(bobRigData)

        builder = plugins.getBuilder()
        builder.build(bobRig)

    else:
        LogMessage('Invalid mode set')

    Profiler.getInstance().pop()

    if __name__ == "__main__":
        print Profiler.getInstance().generateReport()
    else:
        if mode == 'guide':
            logHierarchy(bobGuideRig)
        elif mode == 'rig':
            logHierarchy(bobRig)
Beispiel #6
0
    def buildRig(self):

        try:
            self.window().statusBar().showMessage('Building Rig')

            initConfigIndex = self.window().krakenMenu.configsWidget.currentIndex()

            self.synchGuideRig()

            rigBuildData = self.guideRig.getRigBuildData()
            rig = Rig()
            rig.loadRigDefinition(rigBuildData)

            rig.setName(rig.getName().replace('_guide', ''))

            builder = plugins.getBuilder()
            builder.build(rig)

            self.window().krakenMenu.setCurrentConfig(initConfigIndex)

        except Exception as e:
            # Add the callstak to the log
            callstack = traceback.format_exc()
            print callstack
            self.reportMessage('Error Building', level='error', exception=e)
Beispiel #7
0
def buildBob(mode='guide'):

    Profiler.getInstance().push("bob_build")

    bobGuideRig = Rig("char_bob")
    bobGuideRig.loadRigDefinition(bob_guide_data)

    if mode == 'guide':
        builder = plugins.getBuilder()
        builder.build(bobGuideRig)

    elif mode == 'rig':
        synchronizer = plugins.getSynchronizer()
        synchronizer.setTarget(bobGuideRig)
        synchronizer.sync()

        bobRigData = bobGuideRig.getGuideData()
        bobRig = Rig()
        bobRig.loadRigDefinition(bobRigData)

        builder = plugins.getBuilder()
        builder.build(bobRig)

    else:
        print 'Invalid mode set'

    Profiler.getInstance().pop()

    if __name__ == "__main__":
        print Profiler.getInstance().generateReport()
    else:
        if mode == 'guide':
            logHierarchy(bobGuideRig)
        elif mode == 'rig':
            logHierarchy(bobRig)
Beispiel #8
0
def KrakenBuildGuideFromRig_Execute(sceneRig):

    # Deffered importing: We can only import the kraken modules after the
    # plugin has loaded, as it configures the python import paths on load.
    from kraken.core.objects.rig import Rig
    from kraken import plugins

    from kraken.helpers.utility_methods import prepareToSave, prepareToLoad

    if sceneRig == None and si.Interactive is True:
        pickSceneRig = si.PickElement(constants.siModelFilter, "Kraken: Pick Rig", "Kraken: Pick Rig")
        if pickSceneRig('ButtonPressed') == 0:
            pass
        else:
            pickedSceneRig = pickSceneRig('PickedElement')

            if pickedSceneRig.Properties('krakenRig') is None:
                log("Kraken: Picked object is not the top node of a Kraken Rig!", 4)
                return False

            sceneRig = pickedSceneRig
    else:
        if sceneRig.Properties('krakenRig') is None:
            log("Kraken: 'sceneRig' argument is not the top node of a Kraken Rig!", 4)
            return False

    if sceneRig.Properties('krakenRigData') is None:
        log("Kraken: 'sceneRig' does not have a 'krakenRigData' property!", 4)
        return False

    guideData = sceneRig.Properties('krakenRigData').Value

    rig = Rig()
    jsonData = json.loads(guideData)
    jsonData = prepareToLoad(jsonData)
    rig.loadRigDefinition(jsonData)
    rig.setName(rig.getName())

    builtRig = None
    progressBar = None
    try:

        progressBar = XSIUIToolkit.ProgressBar
        progressBar.Caption = "Building Kraken Rig: " + rig.getName()
        progressBar.CancelEnabled = False
        progressBar.Visible = True

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

    finally:
        if progressBar is not None:
            progressBar.Visible = False

    return builtRig
Beispiel #9
0
def BuildKrakenRig_Execute(rigFilePath):

    # Deffered importing: We can only import the kraken modules after the
    # plugin has loaded, as it configures the python import paths on load.
    from kraken.core.objects.rig import Rig
    from kraken import plugins

    if rigFilePath == "" and si.Interactive is True:

        fileBrowser = XSIUIToolkit.FileBrowser
        fileBrowser.DialogTitle = "Select a Kraken Rig File"
        fileBrowser.InitialDirectory = si.ActiveProject3.Path
        fileBrowser.Filter = "Kraken Rig (*.krg)|*.krg||"
        fileBrowser.ShowOpen()

        fileName = fileBrowser.FilePathName
        if fileName != "":
             rigFilePath = fileName
        else:
            log("User Cancelled.", 4)
            return False

    elif rigFilePath == "" and si.Interactive is False:
        log("No rig file path specified in batch mode!", 2)
        return False

    guideRig = Rig()
    guideRig.loadRigDefinitionFile(rigFilePath)
    rigBuildData = guideRig.getRigBuildData()

    rig = Rig()
    rig.loadRigDefinition(rigBuildData)
    rig.setName(guideRig.getName().replace('_guide', ''))

    builtRig = None
    progressBar = None
    try:

        progressBar = XSIUIToolkit.ProgressBar
        progressBar.Caption = "Building Kraken Rig: " + rig.getName()
        progressBar.CancelEnabled = False
        progressBar.Visible = True

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

    finally:
        if progressBar is not None:
            progressBar.Visible = False

    return builtRig
Beispiel #10
0
def BuildKrakenRig_Execute(rigFilePath):

    # Deffered importing: We can only import the kraken modules after the
    # plugin has loaded, as it configures the python import paths on load.
    from kraken.core.objects.rig import Rig
    from kraken import plugins

    if rigFilePath == "" and si.Interactive is True:

        fileBrowser = XSIUIToolkit.FileBrowser
        fileBrowser.DialogTitle = "Select a Kraken Rig File"
        fileBrowser.InitialDirectory = si.ActiveProject3.Path
        fileBrowser.Filter = "Kraken Rig (*.krg)|*.krg||"
        fileBrowser.ShowOpen()

        fileName = fileBrowser.FilePathName
        if fileName != "":
            rigFilePath = fileName
        else:
            log("User Cancelled.", 4)
            return False

    elif rigFilePath == "" and si.Interactive is False:
        log("No rig file path specified in batch mode!", 2)
        return False

    guideRig = Rig()
    guideRig.loadRigDefinitionFile(rigFilePath)
    rigBuildData = guideRig.getRigBuildData()

    rig = Rig()
    rig.loadRigDefinition(rigBuildData)
    rig.setName(guideRig.getName().replace('_guide', ''))

    builtRig = None
    progressBar = None
    try:

        progressBar = XSIUIToolkit.ProgressBar
        progressBar.Caption = "Building Kraken Rig: " + rig.getName()
        progressBar.CancelEnabled = False
        progressBar.Visible = True

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

    finally:
        if progressBar is not None:
            progressBar.Visible = False

    return builtRig
    def buildRig(self):

        try:
            self.window().statusBar().showMessage('Building Rig')

            self.synchGuideRig()

            rigBuildData = self.guideRig.getRigBuildData()
            rig = Rig()
            rig.loadRigDefinition(rigBuildData)

            rig.setName(rig.getName().replace('_guide', ''))

            builder = plugins.getBuilder()
            builder.build(rig)

        except Exception as e:
            print traceback.format_exc()

            statusBar = self.window().statusBar()
            warningLabel = QtGui.QLabel('Error Building: ' +
                                        ', '.join([x for x in e.args]))
            warningLabel.setMaximumWidth(200)
            warningLabel.setStyleSheet(
                "QLabel { border-radius: 3px; background-color: #AA0000}")

            def addWarning():
                self.window().statusBar().clearMessage()

                statusBar.addWidget(warningLabel, 1)
                statusBar.repaint()

                timer.start()

            def endWarning():
                timer.stop()
                statusBar.removeWidget(warningLabel)
                statusBar.repaint()

                self.window().statusBar().showMessage('Ready', 2000)

            timer = QtCore.QTimer()
            timer.setInterval(2000)
            timer.timeout.connect(endWarning)

            addWarning()
Beispiel #12
0
def main():

    os.environ['KRAKEN_DCC'] = 'KL'

    options, args = argOpts()

    ks = KrakenSystem.getInstance()
    numConfigs = len(ks.registeredConfigs)

    if options.config:
        directory, file = os.path.split(options.config)
        filebase, ext = os.path.splitext(file)
        sys.path = [directory] + sys.path  # prepend
        exec("import " + filebase)

        if len(ks.registeredConfigs) > numConfigs:
            configName = next(reversed(ks.registeredConfigs))
            print ("Using config %s from %s" % (configName, options.config))
            ks.getConfigClass(configName).makeCurrent()

        else:
            print ("Failed to use config in %s" % options.config)
            exit()

    guideRig = Rig()
    guideRig.loadRigDefinitionFile(args[0])

    rig = Rig()
    rig.loadRigDefinition(guideRig.getRigBuildData())

    builder = plugins.getBuilder()
    builder.setOutputFolder(args[1])

    config = builder.getConfig()

    config.setMetaData('RigTitle', os.path.split(args[0])[1].partition('.')[0])
    if options.constants:
        config.setMetaData('UseRigConstants', True)
    if options.numframes:
        config.setMetaData('ProfilingFrames', options.numframes)
    if options.logfile:
        config.setMetaData('ProfilingLogFile', options.logfile)

    builder.build(rig)
Beispiel #13
0
def main():

    options, args = argOpts()

    ks = KrakenSystem.getInstance()
    numConfigs = len(ks.registeredConfigs)

    if options.config:
        directory, file = os.path.split(options.config)
        filebase, ext = os.path.splitext(file)
        sys.path = [directory] + sys.path  # prepend
        exec("import " + filebase)

        if len(ks.registeredConfigs) > numConfigs:
            configName = next(reversed(ks.registeredConfigs))
            print("Using config %s from %s" % (configName, options.config))
            ks.getConfigClass(configName).makeCurrent()

        else:
            print("Failed to use config in %s" % options.config)
            exit()

    guideRig = Rig()
    guideRig.loadRigDefinitionFile(args[0])

    rig = Rig()
    rig.loadRigDefinition(guideRig.getRigBuildData())

    builder = plugins.getBuilder()
    builder.setOutputFolder(args[1])

    config = builder.getConfig()

    config.setMetaData('RigTitle', os.path.split(args[0])[1].partition('.')[0])
    if options.constants:
        config.setMetaData('UseRigConstants', True)
    if options.numframes:
        config.setMetaData('ProfilingFrames', options.numframes)
    if options.logfile:
        config.setMetaData('ProfilingLogFile', options.logfile)
    if options.extensionname:
        config.setMetaData('RigTitle', options.extensionname)

    builder.build(rig)
    def buildRig(self):

        try:
            self.window().statusBar().showMessage('Building Rig')

            self.synchGuideRig()

            rigBuildData = self.guideRig.getRigBuildData()
            rig = Rig()
            rig.loadRigDefinition(rigBuildData)

            rig.setName(rig.getName().replace('_guide', ''))

            builder = plugins.getBuilder()
            builder.build(rig)

        except Exception as e:
            print traceback.format_exc()

            statusBar = self.window().statusBar()
            warningLabel = QtGui.QLabel('Error Building: ' + ', '.join([x for x in e.args]))
            warningLabel.setMaximumWidth(200)
            warningLabel.setStyleSheet("QLabel { border-radius: 3px; background-color: #AA0000}")

            def addWarning():
                self.window().statusBar().clearMessage()

                statusBar.addWidget(warningLabel, 1)
                statusBar.repaint()

                timer.start()

            def endWarning():
                timer.stop()
                statusBar.removeWidget(warningLabel)
                statusBar.repaint()

                self.window().statusBar().showMessage('Ready', 2000)

            timer = QtCore.QTimer()
            timer.setInterval(2000)
            timer.timeout.connect(endWarning)

            addWarning()
Beispiel #15
0
import json
import os

from kraken import plugins
from kraken.core.objects.rig import Rig
from kraken_examples.bob_guide_data import bob_guide_data
from kraken.core.profiler import Profiler
from kraken.helpers.utility_methods import logHierarchy


Profiler.getInstance().push("bob_build")

bobGuideRig = Rig("char_bob")
bobGuideRig.loadRigDefinition(bob_guide_data)

bobGuideRig.writeRigDefinitionFile('bob_guide.krg')

bobGuideRig2 = Rig()
bobGuideRig2.loadRigDefinitionFile('bob_guide.krg')

logHierarchy(bobGuideRig2)

os.remove('bob_guide.krg')
Beispiel #16
0
def KrakenBuildBipedRig_Execute(bipedGuide):

    # Deffered importing: We can only import the kraken modules after the
    # plugin has loaded, as it configures the python import paths on load.
    from kraken.core.objects.rig import Rig
    from kraken import plugins

    from kraken_examples.biped.biped_guide_rig import BipedGuideRig

    guideName = "Biped"
    if bipedGuide == None and si.Interactive is True:
        pickGuide = si.PickElement(constants.siModelFilter, "Kraken: Pick Guide Rig", "Kraken: Pick Guide Rig")
        if pickGuide('ButtonPressed') == 0:
            pass
        else:
            pickedGuide = pickGuide('PickedElement')

            if pickedGuide.Properties('krakenRig') is None:
                log("Kraken: Picked object is not the top node of a Kraken Rig!", 4)
                return False

            guideName = pickedGuide.Name
    else:
        if bipedGuide.Properties('krakenRig') is None:
            log("Kraken: 'bipedGuide' argument is not the top node of a Kraken Rig!", 4)
            return False

        guideName = bipedGuide.Name

    guideRig = BipedGuideRig(guideName)

    synchronizer = plugins.getSynchronizer()

    if guideRig.getName().endswith('_guide') is False:
        guideRig.setName(guideRig.getName() + '_guide')

    synchronizer.setTarget(guideRig)
    synchronizer.sync()

    rigBuildData = guideRig.getRigBuildData()
    rig = Rig()
    rig.loadRigDefinition(rigBuildData)
    rig.setName(rig.getName().replace('_guide', '_rig'))

    builtRig = None
    progressBar = None
    try:

        progressBar = XSIUIToolkit.ProgressBar
        progressBar.Caption = "Building Kraken Rig: " + rig.getName()
        progressBar.CancelEnabled = False
        progressBar.Visible = True

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

    finally:
        if progressBar is not None:
            progressBar.Visible = False

    return builtRig
Beispiel #17
0
os.environ['KRAKEN_DCC'] = 'Canvas'

args = sys.argv[1:]
if len(args) != 2:
    print "\nPlease provide the rig file to convert and the target folder as command line arguments."
    exit(1)

from kraken import plugins
from kraken.core.objects.locator import Locator
from kraken.core.objects.rig import Rig

guideRig = Rig()
guideRig.loadRigDefinitionFile(args[0])

rig = Rig()
rig.loadRigDefinition(guideRig.getRigBuildData())

builder = plugins.getBuilder()
builder.setOutputFolder(args[1])

config = builder.getConfig()
config.setExplicitNaming(True)

config.setMetaData('RigTitle', os.path.split(args[0])[1].partition('.')[0])
config.setMetaData('SetupDebugDrawing', True)
config.setMetaData('CollapseComponents', False)
config.setMetaData('AddCollectJointsNode', True)

builder.build(rig)

Beispiel #18
0
def KrakenBuildBipedRig_Execute(bipedGuide):

    # Deffered importing: We can only import the kraken modules after the
    # plugin has loaded, as it configures the python import paths on load.
    from kraken.core.objects.rig import Rig
    from kraken import plugins

    from kraken_examples.biped.biped_guide_rig import BipedGuideRig

    guideName = "Biped"
    if bipedGuide == None and si.Interactive is True:
        pickGuide = si.PickElement(constants.siModelFilter,
                                   "Kraken: Pick Guide Rig",
                                   "Kraken: Pick Guide Rig")
        if pickGuide('ButtonPressed') == 0:
            pass
        else:
            pickedGuide = pickGuide('PickedElement')

            if pickedGuide.Properties('krakenRig') is None:
                log(
                    "Kraken: Picked object is not the top node of a Kraken Rig!",
                    4)
                return False

            guideName = pickedGuide.Name
    else:
        if bipedGuide.Properties('krakenRig') is None:
            log(
                "Kraken: 'bipedGuide' argument is not the top node of a Kraken Rig!",
                4)
            return False

        guideName = bipedGuide.Name

    guideRig = BipedGuideRig(guideName)

    synchronizer = plugins.getSynchronizer()

    if guideRig.getName().endswith('_guide') is False:
        guideRig.setName(guideRig.getName() + '_guide')

    synchronizer.setTarget(guideRig)
    synchronizer.sync()

    rigBuildData = guideRig.getRigBuildData()
    rig = Rig()
    rig.loadRigDefinition(rigBuildData)
    rig.setName(rig.getName().replace('_guide', '_rig'))

    builtRig = None
    progressBar = None
    try:

        progressBar = XSIUIToolkit.ProgressBar
        progressBar.Caption = "Building Kraken Rig: " + rig.getName()
        progressBar.CancelEnabled = False
        progressBar.Visible = True

        builder = plugins.getBuilder()
        builtRig = builder.build(rig)

    finally:
        if progressBar is not None:
            progressBar.Visible = False

    return builtRig