Exemple #1
0
    def getRigBuildData(self):
        """Get the graph definition of the guide for building the final rig.

        Returns:
            dict: The JSON data struture of the guide rig data

        """

        guideData = self.getData()
        guideJSONData = prepareToSave(guideData)

        rigBuildData = {'name': self.getName(), 'guideData': guideJSONData}

        componentsJson = []
        guideComponents = self.getChildrenByType('Component')
        for component in guideComponents:
            componentsJson.append(component.getRigBuildData())

        rigBuildData['components'] = componentsJson

        connectionsJson = []
        for component in guideComponents:
            for i in xrange(component.getNumInputs()):
                componentInput = component.getInputByIndex(i)
                if componentInput.isConnected():
                    componentOutput = componentInput.getConnection()
                    connectionJson = {
                        'source':
                        componentOutput.getParent().getDecoratedName() + '.' +
                        componentOutput.getName(),
                        'target':
                        component.getDecoratedName() + '.' +
                        componentInput.getName(),
                        'targetIndex':
                        componentInput.getIndex()
                    }
                    connectionsJson.append(connectionJson)

        rigBuildData['connections'] = connectionsJson

        return rigBuildData
Exemple #2
0
    def writeRigDefinitionFile(self, filepath):
        """Load a rig definition from a file on disk.

        Args:
            filepath (str): The file path of the rig definition file.

        Returns:
            bool: True if successful.

        """

        Profiler.getInstance().push("writeRigDefinitionFile:" + filepath)

        jsonData = self.getData()

        # now preprocess the data ready for saving to disk.
        pureJSON = prepareToSave(jsonData)

        with open(filepath,'w') as rigFile:
            rigFile.write(json.dumps(pureJSON, indent=2))

        Profiler.getInstance().pop()
Exemple #3
0
    def writeRigDefinitionFile(self, filepath):
        """Load a rig definition from a file on disk.

        Args:
            filepath (str): The file path of the rig definition file.

        Returns:
            bool: True if successful.

        """

        Profiler.getInstance().push("writeRigDefinitionFile:" + filepath)

        jsonData = self.getData()

        # now preprocess the data ready for saving to disk.
        pureJSON = prepareToSave(jsonData)

        with open(filepath, 'w') as rigFile:
            rigFile.write(json.dumps(pureJSON, indent=2))

        Profiler.getInstance().pop()
Exemple #4
0
    def writeGuideDefinitionFile(self, filepath):
        """Writes a rig definition to a file on disk.

        Arguments:
        filepath -- string, the file path of the rig definition file.

        Return:
        True if successful.

        """

        Profiler.getInstance().push("WriteGuideDefinitionFile:" + filepath)

        guideData = self.getRigBuildData()

        # now preprocess the data ready for saving to disk.
        pureJSON = prepareToSave(guideData)

        with open(filepath, 'w') as rigDef:
            rigDef.write(json.dumps(pureJSON, indent=2))

        Profiler.getInstance().pop()
Exemple #5
0
    def getRigBuildData(self):
        """Get the graph definition of the guide for building the final rig.

        Returns:
            dict: The JSON data struture of the guide rig data

        """

        guideData = self.getData()
        guideJSONData = prepareToSave(guideData)

        rigBuildData = {
            'name': self.getName(),
            'guideData': guideJSONData
        }

        componentsJson = []
        guideComponents = self.getChildrenByType('Component')
        for component in guideComponents:
            componentsJson.append(component.getRigBuildData())

        rigBuildData['components'] = componentsJson

        connectionsJson = []
        for component in guideComponents:
            for i in xrange(component.getNumInputs()):
                componentInput = component.getInputByIndex(i)
                if componentInput.isConnected():
                    componentOutput = componentInput.getConnection()
                    connectionJson = {
                        'source': componentOutput.getParent().getDecoratedName() + '.' + componentOutput.getName(),
                        'target': component.getDecoratedName() + '.' + componentInput.getName(),
                        'targetIndex': componentInput.getIndex()
                    }
                    connectionsJson.append(connectionJson)

        rigBuildData['connections'] = connectionsJson

        return rigBuildData
Exemple #6
0
    def writeGuideDefinitionFile(self, filepath):
        """Writes a rig definition to a file on disk.

        Arguments:
        filepath -- string, the file path of the rig definition file.

        Return:
        True if successful.

        """

        Profiler.getInstance().push("WriteGuideDefinitionFile:" + filepath)

        guideData = self.getRigBuildData()

        # now preprocess the data ready for saving to disk.
        pureJSON = prepareToSave(guideData)

        with open(filepath,'w') as rigDef:
            rigDef.write(json.dumps(pureJSON, indent=2))

        Profiler.getInstance().pop()
Exemple #7
0
import json

from kraken_examples.bob_guide_data import bob_guide_data
from kraken.helpers.utility_methods import prepareToSave, prepareToLoad


pureJSON = prepareToSave(bob_guide_data)
str1 = json.dumps(pureJSON, indent=2)
print str1

bob_guide_data = prepareToLoad(pureJSON)

# Check that we can preprocess a data struct 2X
bob_guide_data = prepareToLoad(bob_guide_data)

# Re export to pure json
pureJSON = prepareToSave(bob_guide_data)
str2 = json.dumps(pureJSON, indent=2)
print str1 == str2
Exemple #8
0
import json

from kraken_examples.bob_guide_data import bob_guide_data
from kraken.helpers.utility_methods import prepareToSave, prepareToLoad

pureJSON = prepareToSave(bob_guide_data)
str1 = json.dumps(pureJSON, indent=2)
print str1

bob_guide_data = prepareToLoad(pureJSON)

# Check that we can preprocess a data struct 2X
bob_guide_data = prepareToLoad(bob_guide_data)

# Re export to pure json
pureJSON = prepareToSave(bob_guide_data)
str2 = json.dumps(pureJSON, indent=2)
print str1 == str2
Exemple #9
0
import json
import os
import tempfile

from kraken.core.maths import *

from kraken.helpers.utility_methods import prepareToSave, prepareToLoad

from kraken_examples.biped.biped_guide_rig import BipedGuideRig


bipedGuide = BipedGuideRig('Biped_Guide')
guideData = bipedGuide.getData()
pureJSON = prepareToSave(guideData)

tmpFilePath = os.path.join(os.getcwd(), 'bipedGuideSaveTest.krg')
try:
    with open(tmpFilePath, 'w+b') as tempFile:
        tempFile.write(json.dumps(pureJSON, indent=2))

    with open(tmpFilePath, 'r') as tempFile:
        jsonData = json.load(tempFile)
        jsonData = prepareToLoad(jsonData)

        for k, v in jsonData.iteritems():
            print k

            if k == 'components':
                for i in xrange(len(v)):
                    print '\t' + v[i]['name']