def _loadComponents(self, componentsJson): """Loads components from a JSON dict. Args: componentsJson (dict): Dictionary of components to load. """ Profiler.getInstance().push("__loadComponents") beamSystem = BeamSystem.getInstance() for componentData in componentsJson: # trim off the class name to get the module path. modulePath = '.'.join(componentData['class'].split('.')[:-1]) if modulePath is not "": try: importlib.import_module(modulePath) except: print "Warning: Error finding module path: " + modulePath continue componentClass = beamSystem.getComponentClass(componentData['class']) if 'name' in componentData: component = componentClass(name=componentData['name'], parent=self) else: component = componentClass(parent=self) component.loadData(componentData) Profiler.getInstance().pop()
def loadRigDefinition(self, jsonData): """Load a rig definition from a JSON structure. Args: jsonData (dict): JSON data containing the rig definition. Returns: bool: True if successful. """ Profiler.getInstance().push("loadRigDefinition:" + self.getName()) beamSystem = BeamSystem.getInstance() if 'name' in jsonData: self.setName(jsonData['name']) if 'components' in jsonData: self._loadComponents(jsonData['components']) if 'connections' in jsonData: self._makeConnections(jsonData['connections']) if 'metaData' in jsonData: for k, v in jsonData['metaData'].iteritems(): self.setMetaDataItem(k, v) if 'guideData' in jsonData: self.setMetaDataItem('guideData', jsonData['guideData']) Profiler.getInstance().pop()
def loadExtension(self, extension): """Loads the given extension and updates the registeredTypes cache. Args: extension (str): The name of the extension to load. """ if extension not in self.loadedExtensions: Profiler.getInstance().push("loadExtension:" + extension) self.client.loadExtension(extension) self.registeredTypes = self.client.RT.types self.typeDescs = self.client.RT.getRegisteredTypes() # Cache the loaded extension so that we aviod refreshing the typeDescs cache(costly) self.loadedExtensions.append(extension) Profiler.getInstance().pop()
def loadCoreClient(self): if self.client is None: Profiler.getInstance().push("loadCoreClient") client = getFabricClient() if client is None: options = {'reportCallback': fabricCallback, 'guarded': True} client = rigging.beam.FabricEngine.Core.createClient(options) self.client = client self.loadExtension('Math') self.loadExtension('Kraken') self.loadExtension('KrakenForCanvas') print "loadCoreClient.self.client: ", self.client Profiler.getInstance().pop() print "loadCoreClient.self.client: ", self.client
def _makeConnections(self, connectionsJson): """Makes connections based on JSON dict. Args: connectionsJson (dict): Dictionary of connections to make. """ Profiler.getInstance().push("__makeConnections") for connectionData in connectionsJson: sourceComponentDecoratedName, outputName = connectionData['source'].split('.') targetComponentDecoratedName, inputName = connectionData['target'].split('.') connectionFailure = False sourceComponent = self.getChildByDecoratedName(sourceComponentDecoratedName) if sourceComponent is None: print("Warning: Error making connection:" + connectionData['source'] + " -> " + connectionData['target'] + ". Source component not found:" + sourceComponentDecoratedName) connectionFailure = True targetComponent = self.getChildByDecoratedName(targetComponentDecoratedName) if targetComponent is None: print("Warning: Error making connection:" + connectionData['source'] + " -> " + connectionData['target'] + ". Target component not found:" + targetComponentDecoratedName) connectionFailure = True outputPort = sourceComponent.getOutputByName(outputName) if outputPort is None: print("Warning: Error making connection:" + connectionData['source'] + " -> " + connectionData['target'] + ". Output '" + outputName + "' not found on Component:" + sourceComponent.getPath()) connectionFailure = True inputPort = targetComponent.getInputByName(inputName) if inputPort is None: print("Warning: Error making connection:" + connectionData['source'] + " -> " + connectionData['target'] + ". Input '" + inputName + "' not found on Component:" + targetComponent.getPath()) connectionFailure = True if connectionFailure is False: inputPort.setConnection(outputPort, index = connectionData.get('targetIndex', 0)) Profiler.getInstance().pop()
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()
def loadRigDefinitionFile(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("LoadRigDefinitionFile:" + filepath) if not os.path.exists(filepath): raise Exception("File not found:" + filepath) with open(filepath) as rigFile: jsonData = json.load(rigFile) # now preprocess the data ready for loading. jsonData = prepareToLoad(jsonData) self.loadRigDefinition(jsonData) Profiler.getInstance().pop()
def build(self, kSceneItem): """Builds a rig object. We have to re-order component children by walking the graph to ensure that inputs objects are in place for the dependent components. Args: kSceneItem (sceneitem): The item to be built. Returns: object: DCC Scene Item that is created. """ Profiler.getInstance().push("build:" + kSceneItem.getName()) traverser = Traverser('Children') traverser.addRootItem(kSceneItem) rootItems = traverser.traverse( discoverCallback=traverser.discoverChildren, discoveredItemsFirst=False) #print "builder.build.rootItems: ",rootItems traverser = Traverser('Build') for rootItem in rootItems: traverser.addRootItem(rootItem) traverser.traverse() #print "traverser.traverse(): ",traverser.traverse() try: self._preBuild(kSceneItem) objects3d = traverser.getItemsOfType('Object3D') print "builder.build.objects3d: ",objects3d attributeGroups = traverser.getItemsOfType(['AttributeGroup']) print "builder.build.attributeGroups: ", attributeGroups attributes = traverser.getItemsOfType(['Attribute']) print "builder.build.attributes: ", attributes # build all 3D objects and attributes self.__buildSceneItemList(objects3d, self._buildPhase_3DObjectsAttributes) self.__buildSceneItemList(attributeGroups, self._buildPhase_3DObjectsAttributes) self.__buildSceneItemList(attributes, self._buildPhase_3DObjectsAttributes) # connect all attributes self.__buildSceneItemList(attributes, self._buildPhase_AttributeConnections) # build all additional connections self.__buildSceneItemList(traverser.items, self._buildPhase_ConstraintsOperators) # lock parameters self.__buildSceneItemList(attributes, self._buildPhase_lockAttributes) # lock parameters self.__buildSceneItemList(traverser.items, self._buildPhase_lockTransformAttrs) finally: self._postBuild(kSceneItem) # Clear Config when finished. self.config.clearInstance() Profiler.getInstance().pop() return self.getDCCSceneItem(kSceneItem)
def __init__(self, name='arm', parent=None, *args, **kwargs): Profiler.getInstance().push("Construct Arm Guide Component:" + name) super(ArmComponentGuide, self).__init__(name, parent, *args, **kwargs) # =========== # Attributes # =========== # Add Component Params to IK control guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self) self.bicepFKCtrlSizeInputAttr = ScalarAttribute( 'bicepFKCtrlSize', value=1.75, minValue=0.0, maxValue=10.0, parent=guideSettingsAttrGrp) self.forearmFKCtrlSizeInputAttr = ScalarAttribute( 'forearmFKCtrlSize', value=1.5, minValue=0.0, maxValue=10.0, parent=guideSettingsAttrGrp) # ========= # Controls # ========= # Guide Controls self.bicepCtrl = Control('bicep', parent=self.ctrlCmpGrp, shape="sphere") self.bicepCtrl.setColor('blue') self.forearmCtrl = Control('forearm', parent=self.ctrlCmpGrp, shape="sphere") self.forearmCtrl.setColor('blue') self.wristCtrl = Control('wrist', parent=self.ctrlCmpGrp, shape="sphere") self.wristCtrl.setColor('blue') armGuideSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.bicepCtrl) self.armGuideDebugAttr = BoolAttribute('drawDebug', value=True, parent=armGuideSettingsAttrGrp) self.guideOpHost = Transform('guideOpHost', self.ctrlCmpGrp) # Guide Operator #self.armGuideKLOp = KLOperator('guide', 'TwoBoneIKGuideSolver', 'Beam') #self.addOperator(self.armGuideKLOp) # Add Att Inputs #self.armGuideKLOp.setInput('drawDebug', self.armGuideDebugAttr) #self.armGuideKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Source Inputs #self.armGuideKLOp.setInput('root', self.bicepCtrl) #self.armGuideKLOp.setInput('mid', self.forearmCtrl) #self.armGuideKLOp.setInput('end', self.wristCtrl) # Add Target Outputs #self.armGuideKLOp.setOutput('guideOpHost', self.guideOpHost) self.default_data = { "name": name, "location": "L", "bicepXfo": Xfo(Vec3(2.275, 15.3, -0.75)), "forearmXfo": Xfo(Vec3(5.0, 13.5, -0.75)), "wristXfo": Xfo(Vec3(7.2, 12.25, 0.5)), "bicepFKCtrlSize": self.bicepFKCtrlSizeInputAttr.getValue(), "forearmFKCtrlSize": self.forearmFKCtrlSizeInputAttr.getValue() } self.loadData(self.default_data) Profiler.getInstance().pop()
def __init__(self, name='arm', parent=None): Profiler.getInstance().push("Construct Arm Rig Component:" + name) super(ArmComponentRig, self).__init__(name, parent)
def __init__(self, name='arm', parent=None, *args, **kwargs): Profiler.getInstance().push("Construct Arm Guide Component:" + name) super(ArmComponentGuide, self).__init__(name, parent, *args, **kwargs)
def __init__(self, name='Hand', parent=None): Profiler.getInstance().push("Construct Hand Rig Component:" + name) super(HandComponentRig, self).__init__(name, parent)