def postbuild(self): # Group everything all_anms = libPymel.ls_root_anms() if not isinstance(self.grp_anms, CtrlRoot): self.grp_anms = CtrlRoot() self.grp_anms.build() self.grp_anms.rename('anm_root') all_anms.setParent(self.grp_anms) all_rigs = libPymel.ls_root_rigs() self.grp_rigs = RigNode(name='rigs', _create=True) all_rigs.setParent(self.grp_rigs) # note: self.grp_jnts is now handled in prebuild #all_jnts = libPymel.ls_root_jnts() #self.grp_jnts = pymel.createNode('joint', name='jnts') #all_jnts.setParent(self.grp_jnts) # Ensure self.grp_jnts is constraint to self.grp_anms # We use parentConstraint instead of connections in the the animator change self.grp_anms parent pymel.delete([child for child in self.grp_jnts.getChildren() if isinstance(child, pymel.nodetypes.Constraint)]) pymel.parentConstraint(self.grp_anms, self.grp_jnts) all_geos = libPymel.ls_root_geos() self.grp_geos = RigNode(name='geos', _create=True) all_geos.setParent(self.grp_geos) # Setup displayLayers self.layer_anm = pymel.createDisplayLayer(name='layer_anm', number=1, empty=True) pymel.editDisplayLayerMembers(self.layer_anm, self.grp_anms, noRecurse=True) self.layer_anm.color.set(17) # Yellow self.layer_rig = pymel.createDisplayLayer(name='layer_rig', number=1, empty=True) pymel.editDisplayLayerMembers(self.layer_rig, self.grp_rigs, noRecurse=True) pymel.editDisplayLayerMembers(self.layer_rig, self.grp_jnts, noRecurse=True) self.layer_rig.color.set(13) # Red #oLayerRig.visibility.set(0) # Hidden self.layer_rig.displayType.set(2) # Frozen self.layer_geo = pymel.createDisplayLayer(name='layer_geo', number=1, empty=True) pymel.editDisplayLayerMembers(self.layer_geo, self.grp_geos, noRecurse=True) self.layer_geo.color.set(12) # Green? self.layer_geo.displayType.set(2) # Frozen
class RigRoot(RigElement): def __init__(self): self.children = [] self.grp_anms = None self.grp_geos = None self.grp_jnts = None self.grp_rigs = None self.layer_anm = None self.layer_geo = None self.layer_rig = None def __str__(self): return '<rig {0}/>'.format('???') def AddPart(self, _part): #if not isinstance(_part, RigPart): # logging.error("[RigRoot:AddPart] Invalid RigPart '{0}' provided".format(_part)) self.children.append(_part) def prebuild(self): # Ensure we got a root joint # If needed, parent orphan joints to this one all_root_jnts = libPymel.ls_root_jnts() if not libPymel.is_valid_PyNode(self.grp_jnts): self.grp_jnts = pymel.createNode('joint', name='jnts') all_root_jnts.setParent(self.grp_jnts) def build(self, **kwargs): if self.isBuilt(): pymel.warning("Can't build {0} because it's already built!".format(self)) return False sTime = time.time() self.prebuild() #try: for child in self.children: #try: child.build(**kwargs) #except Exception, e: # logging.error("\n\nAUTORIG BUILD FAIL! (see log)\n") # traceback.print_stack() # logging.error(str(e)) # raise e self.postbuild() print ("[classRigRoot.Build] took {0} ms".format(time.time() - sTime)) return True def postbuild(self): # Group everything all_anms = libPymel.ls_root_anms() if not isinstance(self.grp_anms, CtrlRoot): self.grp_anms = CtrlRoot() self.grp_anms.build() self.grp_anms.rename('anm_root') all_anms.setParent(self.grp_anms) all_rigs = libPymel.ls_root_rigs() self.grp_rigs = RigNode(name='rigs', _create=True) all_rigs.setParent(self.grp_rigs) # note: self.grp_jnts is now handled in prebuild #all_jnts = libPymel.ls_root_jnts() #self.grp_jnts = pymel.createNode('joint', name='jnts') #all_jnts.setParent(self.grp_jnts) # Ensure self.grp_jnts is constraint to self.grp_anms # We use parentConstraint instead of connections in the the animator change self.grp_anms parent pymel.delete([child for child in self.grp_jnts.getChildren() if isinstance(child, pymel.nodetypes.Constraint)]) pymel.parentConstraint(self.grp_anms, self.grp_jnts) all_geos = libPymel.ls_root_geos() self.grp_geos = RigNode(name='geos', _create=True) all_geos.setParent(self.grp_geos) # Setup displayLayers self.layer_anm = pymel.createDisplayLayer(name='layer_anm', number=1, empty=True) pymel.editDisplayLayerMembers(self.layer_anm, self.grp_anms, noRecurse=True) self.layer_anm.color.set(17) # Yellow self.layer_rig = pymel.createDisplayLayer(name='layer_rig', number=1, empty=True) pymel.editDisplayLayerMembers(self.layer_rig, self.grp_rigs, noRecurse=True) pymel.editDisplayLayerMembers(self.layer_rig, self.grp_jnts, noRecurse=True) self.layer_rig.color.set(13) # Red #oLayerRig.visibility.set(0) # Hidden self.layer_rig.displayType.set(2) # Frozen self.layer_geo = pymel.createDisplayLayer(name='layer_geo', number=1, empty=True) pymel.editDisplayLayerMembers(self.layer_geo, self.grp_geos, noRecurse=True) self.layer_geo.color.set(12) # Green? self.layer_geo.displayType.set(2) # Frozen def unbuild(self, **kwargs): for child in self.children: child.unbuild(**kwargs) # Delete the rig group if it isnt used anymore if libPymel.is_valid_PyNode(self.grp_rigs) and len(self.grp_rigs.getChildren()) == 0: pymel.delete(self.grp_rigs) self.grp_rigs = None super(RigRoot, self).unbuild(**kwargs)
def create_footroll(self): oFoot = self.sysIK._chain_ik[self.iCtrlIndex] oToes = self.sysIK._chain_ik[self.iCtrlIndex+1] oTips = self.sysIK._chain_ik[self.iCtrlIndex+2] # Create FootRoll p3Foot = oFoot.getTranslation(space='world') #tmFoot = pymel.datatypes.Matrix(1,0,0,0,0,1,0,0,0,0,1,0, p3Foot[0], 0, p3Foot[2], 1) p3Toes = oToes.getTranslation(space='world') #tmToes = pymel.datatypes.Matrix(1,0,0,0,0,1,0,0,0,0,1,0, p3Toes[0], p3Toes[1], p3Toes[2], 1) fOffsetF = 5 fOffsetB = fOffsetF * 0.25 # Create pivots; TODO: Create side pivots oPivotM = RigNode(name=self._pNameMapRig.Serialize('pivotM')) oPivotM.build() oPivotM.t.set(p3Toes) # Optimisation: t.set is faster than setMatrix #oPivotM.setMatrix(tmToes) #oPivotM.r.set((0,0,0)) oPivotF = RigNode(name=self._pNameMapRig.Serialize('pivotF')) oPivotF.build() oPivotF.t.set(p3Foot + [0,0,fOffsetF]) # Optimisation: t.set is faster than setMatrix #oPivotF.setMatrix(pymel.datatypes.Matrix(1,0,0,0,0,1,0,0,0,0,1,0, 0,0,fOffsetF, 1) * tmFoot) #oPivotF.r.set((0,0,0)) oPivotB = RigNode(name=self._pNameMapRig.Serialize('pivotB')) oPivotB.build() oPivotB.t.set(p3Foot + [0,0,-fOffsetB]) # Optimisation: t.set is faster than setMatrix #oPivotB.setMatrix(pymel.datatypes.Matrix(1,0,0,0,0,1,0,0,0,0,1,0, 0,0,-fOffsetB, 1) * tmFoot) #oPivotB.r.set((0,0,0)) oFootRollRoot = RigNode(name=self._pNameMapRig.Serialize('footroll')) oFootRollRoot.build() # Create hyerarchy oPivotM.setParent(oPivotF) oPivotF.setParent(oPivotB) oPivotB.setParent(oFootRollRoot) oFootRollRoot.setParent(self.grp_rig) pymel.parentConstraint(self.sysIK.ctrlIK, oFootRollRoot, maintainOffset=True) # Create attributes oAttHolder = self.sysIK.ctrlIK pymel.addAttr(oAttHolder, longName='footRoll', k=True) pymel.addAttr(oAttHolder, longName='footRollThreshold', k=True, defaultValue=45) attFootRoll = oAttHolder.attr('footRoll') attFootRollThreshold = oAttHolder.attr('footRollThreshold') attRollF = libRigging.CreateUtilityNode('condition', operation=2, firstTerm=attFootRoll, secondTerm=attFootRollThreshold, colorIfFalseR=0, colorIfTrueR=(libRigging.CreateUtilityNode('plusMinusAverage', operation=2, input1D=[attFootRoll, attFootRollThreshold]).output1D)).outColorR # Substract attRollM = libRigging.CreateUtilityNode('condition', operation=2, firstTerm=attFootRoll, secondTerm=attFootRollThreshold, colorIfTrueR=attFootRollThreshold, colorIfFalseR=attFootRoll).outColorR # Less attRollB = libRigging.CreateUtilityNode('condition', operation=2, firstTerm=attFootRoll, secondTerm=0.0, colorIfTrueR=0, colorIfFalseR=attFootRoll).outColorR # Greater pymel.connectAttr(attRollM, oPivotM.rotateX) pymel.connectAttr(attRollF, oPivotF.rotateX) pymel.connectAttr(attRollB, oPivotB.rotateX) pymel.parentConstraint(self.sysIK.ctrlIK, self.sysIK.ctrl_swivel, maintainOffset=True) # TODO: Implement SpaceSwitch # Create ikHandles oIkHandleFoot, oIkEffectorFoot = pymel.ikHandle(startJoint=oFoot, endEffector=oToes, solver='ikSCsolver') oIkHandleFoot.rename(self._pNameMapRig.Serialize('ikHandle', 'foot')) oIkHandleFoot.setParent(oFootRollRoot) oIkHandleToes, oIkEffectorToes = pymel.ikHandle(startJoint=oToes, endEffector=oTips, solver='ikSCsolver') oIkHandleToes.rename(self._pNameMapRig.Serialize('ikHandle', 'ties')) oIkHandleToes.setParent(oFootRollRoot) # Connect ikHandles pymel.delete([o for o in self.sysIK._oIkHandle.getChildren() if isinstance(o, pymel.nodetypes.Constraint) and not isinstance(o, pymel.nodetypes.PoleVectorConstraint)]) pymel.parentConstraint(oPivotM, self.sysIK._oIkHandle, maintainOffset=True) pymel.parentConstraint(oPivotF, oIkHandleFoot, maintainOffset=True) pymel.parentConstraint(oPivotB, oIkHandleToes, maintainOffset=True)