diff --git a/.gitignore b/.gitignore index 65ea444..c9fc558 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.pyc -.venv/* +*venv/* *.egg-info/* diff --git a/rigsys/api/api_rig.py b/rigsys/api/api_rig.py index 9d32bfc..112e01b 100644 --- a/rigsys/api/api_rig.py +++ b/rigsys/api/api_rig.py @@ -6,9 +6,7 @@ import maya.cmds as cmds -import rigsys.modules.motion as motion -import rigsys.modules.utility as utility -import rigsys.modules.deformer as deformer +from ..modules import motion, utility logger = logging.getLogger(__name__) @@ -84,7 +82,7 @@ def preBuild(self) -> list: # Sort by build order allModules.sort(key=lambda x: x.buildOrder) - + return allModules def build(self, buildLevel: int = -1, buildProxiesOnly: bool = False, usedSavedProxyData: bool = False, @@ -131,7 +129,7 @@ def build(self, buildLevel: int = -1, buildProxiesOnly: bool = False, usedSavedP if module.isMuted: continue - + if buildProxiesOnly: if not module.bypassProxiesOnly and not isinstance(module, motion.MotionModuleBase): logger.info(f"Skipping module {module.getFullName()} for buildProxiesOnly flag...") diff --git a/rigsys/lib/joint.py b/rigsys/lib/joint.py index b20a04c..51fdabf 100644 --- a/rigsys/lib/joint.py +++ b/rigsys/lib/joint.py @@ -200,8 +200,9 @@ def axisToVector(axis): vec = [0, 0, -1] return vec -# Function that takes a string vector and returns the proper numerical vector. + def axisFlip(axis): + """Function that takes a string vector and returns the proper numerical vector.""" newAxis = None if axis == "+x": newAxis = "-x" @@ -217,6 +218,7 @@ def axisFlip(axis): newAxis = "+z" return newAxis + def getCrossAxis(aim, up): axies = [aim, up] crossAxis = "+y" diff --git a/rigsys/lib/proxy.py b/rigsys/lib/proxy.py index 92a50f3..c4a0710 100644 --- a/rigsys/lib/proxy.py +++ b/rigsys/lib/proxy.py @@ -71,9 +71,7 @@ def build(self): def buildProxyModule(self): if cmds.objExists("{}_{}_proxyMODULE".format(self.side, self.label)): - self.proxyModuleNode = "{}_{}_proxyMODULE".format(self.side, self.label) + self.proxyModuleNode = "{}_{}_proxyMODULE".format(self.side, self.label) else: self.proxyModuleNode = cmds.createNode("transform", n="{}_{}_proxyMODULE".format(self.side, self.label)) cmds.parent(self.proxyModuleNode, "proxies") - - diff --git a/rigsys/lib/skinning.py b/rigsys/lib/skinning.py index aa4c07f..de7e641 100644 --- a/rigsys/lib/skinning.py +++ b/rigsys/lib/skinning.py @@ -37,16 +37,17 @@ logger = logging.getLogger(__name__) -def writeSCLS(objects:list=[], path:str = "", suffix:str = "scls"): + +def writeSCLS(objects: list = [], path: str = "", suffix: str = "scls"): if len(objects) == 0: objects = cmds.ls(sl=1) if len(objects) == 0: cmds.error("No Objects provided or selected.") if path == "": cmds.error("Path is empty") - + for obj in objects: - cmds.deformerWeights(f"{obj}_{suffix}.json", + cmds.deformerWeights(f"{obj}_{suffix}.json", ex=True, p=path, deformer=f"{obj}_{suffix}", @@ -56,16 +57,17 @@ def writeSCLS(objects:list=[], path:str = "", suffix:str = "scls"): dv=1.0 ) -def readSCLS(objects:list=[], path:str = "", suffix:str = "scls"): + +def readSCLS(objects: list = [], path: str = "", suffix: str = "scls"): if len(objects) == 0: objects = cmds.ls(sl=1) if len(objects) == 0: cmds.error("No Objects provided or selected.") if path == "": cmds.error("Path is empty") - + for obj in objects: - cmds.deformerWeights(f"{obj}_{suffix}.json", + cmds.deformerWeights(f"{obj}_{suffix}.json", im=True, p=path, deformer=f"{obj}_{suffix}", @@ -75,7 +77,8 @@ def readSCLS(objects:list=[], path:str = "", suffix:str = "scls"): dv=1.0 ) -def createSCLS(object:str = "", joints:list = [], suffix:str = "scls", maxInfluences=4): + +def createSCLS(object: str = "", joints: list = [], suffix: str = "scls", maxInfluences=4): if object == "": object = cmds.ls(sl=1)[-1] if len(object) == 0: @@ -86,12 +89,13 @@ def createSCLS(object:str = "", joints:list = [], suffix:str = "scls", maxInflue if len(joints) == 0: cmds.error("Mo Joints Provided") - cmds.skinCluster(joints, - object, + cmds.skinCluster(joints, + object, n=f"{object}_{suffix}", tsb=True, mi=maxInfluences) - + + def getSelectedJoints(): print(cmds.ls(sl=1)) diff --git a/rigsys/modules/__init__.py b/rigsys/modules/__init__.py index 3af9217..0bef1c5 100644 --- a/rigsys/modules/__init__.py +++ b/rigsys/modules/__init__.py @@ -6,8 +6,4 @@ import rigsys.modules.export as export -allModuleTypes = {} -allModuleTypes.update(motion.moduleTypes) -allModuleTypes.update(deformer.moduleTypes) -allModuleTypes.update(utility.moduleTypes) -allModuleTypes.update(export.moduleTypes) +__all__ = ["motion", "deformer", "utility", "export"] diff --git a/rigsys/modules/deformer/__init__.py b/rigsys/modules/deformer/__init__.py index c654b86..c94af21 100644 --- a/rigsys/modules/deformer/__init__.py +++ b/rigsys/modules/deformer/__init__.py @@ -1,36 +1,9 @@ -"""Deformer modules. +"""Deformer modules.""" -The following code dynamically imports all subclasses of DeformerModuleBase present in this directory. That way, you can -import any module in this directory and it will automatically be available in the rigging system. -""" +from .deformerBase import DeformerModuleBase +from .skinClusterImportExport import skinClusterImportExport -from os.path import dirname, basename, isfile, join -import glob -import importlib -import inspect - -# This is the only line that needs to be changed per __init__.py file. Make sure to keep "as baseModule" at the end -from .deformerBase import DeformerModuleBase as baseModule - -# Import all modules in the current directory -modules = glob.glob(join(dirname(__file__), "*.py")) -__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] -for module in __all__: - importlib.import_module('.' + module, package=str(__name__)) - -# Get all the classes that inherit from baseModule -classes = {str(baseModule.__name__): baseModule} -for cls in baseModule.__subclasses__(): - classes[cls.__name__] = cls - for subClass in cls.__subclasses__(): - classes[subClass.__name__] = subClass - -# Import all the classes that inherit from baseModule -for cls in classes.values(): - classFilePath = inspect.getfile(cls) - importStatement = f"from .{basename(classFilePath)[:-3]} import {cls.__name__}" - exec(importStatement) - -__all__ = list(classes.keys()) - -moduleTypes = classes.copy() +__all__ = [ + "DeformerModuleBase", + "skinClusterImportExport", +] diff --git a/rigsys/modules/deformer/skinClusterImportExport.py b/rigsys/modules/deformer/skinClusterImportExport.py index 8c60a54..0ea3fbc 100644 --- a/rigsys/modules/deformer/skinClusterImportExport.py +++ b/rigsys/modules/deformer/skinClusterImportExport.py @@ -6,6 +6,7 @@ logger = logging.getLogger(__name__) + class skinClusterImportExport(deformerBase.DeformerModuleBase): """Build bind joints utility module.""" @@ -37,7 +38,7 @@ def run(self) -> None: cmds.error(f"Missing the following joints {gatherMissing}; for {self.obj}_scls") if self.path is None or self.path == "": cmds.error(f"Path is incorrect {self.path}") - + if self.createSCLS: self.createSkinCluster() if self.importSCLS: @@ -46,31 +47,33 @@ def run(self) -> None: self.writeWeights() def createSkinCluster(self): - cmds.skinCluster(self.joints, - self.obj, + cmds.skinCluster(self.joints, + self.obj, n=f"{self.obj}_scls", tsb=True, mi=self.maxInfluences) def writeWeights(self): print(f"Exporting {self.obj}_scls. . .") - cmds.deformerWeights(f"{self.obj}_scls.json", + cmds.deformerWeights(f"{self.obj}_scls.json", ex=True, p=self.path, deformer=f"{self.obj}_scls", m="index", at=["maintainMaxInfluences", "maxInfluences"], format="JSON", - dv=1.0 + dv=1.0, ) + def readWeights(self): print(f"Importing {self.obj}_scls. . .") - cmds.deformerWeights(f"{self.obj}_scls.json", - im=True, - p=self.path, - deformer=f"{self.obj}_scls", - m="index", - at=["maintainMaxInfluences", "maxInfluences"], - format="JSON", - dv=1.0 - ) \ No newline at end of file + cmds.deformerWeights( + f"{self.obj}_scls.json", + im=True, + p=self.path, + deformer=f"{self.obj}_scls", + m="index", + at=["maintainMaxInfluences", "maxInfluences"], + format="JSON", + dv=1.0 + ) diff --git a/rigsys/modules/export/__init__.py b/rigsys/modules/export/__init__.py index 367aa62..052a46f 100644 --- a/rigsys/modules/export/__init__.py +++ b/rigsys/modules/export/__init__.py @@ -1,36 +1,11 @@ -"""Export modules. +"""Export modules.""" -The following code dynamically imports all subclasses of ExportModuleBase present in this directory. That way, you can -import any module in this directory and it will automatically be available in the rigging system. -""" +from .exportBase import ExportModuleBase +from .fbxExport import FBXExport +from .mbExport import MBExport -from os.path import dirname, basename, isfile, join -import glob -import importlib -import inspect - -# This is the only line that needs to be changed per __init__.py file. Make sure to keep "as baseModule" at the end -from .exportBase import ExportModuleBase as baseModule - -# Import all modules in the current directory -modules = glob.glob(join(dirname(__file__), "*.py")) -__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] -for module in __all__: - importlib.import_module('.' + module, package=str(__name__)) - -# Get all the classes that inherit from baseModule -classes = {str(baseModule.__name__): baseModule} -for cls in baseModule.__subclasses__(): - classes[cls.__name__] = cls - for subClass in cls.__subclasses__(): - classes[subClass.__name__] = subClass - -# Import all the classes that inherit from baseModule -for cls in classes.values(): - classFilePath = inspect.getfile(cls) - importStatement = f"from .{basename(classFilePath)[:-3]} import {cls.__name__}" - exec(importStatement) - -__all__ = list(classes.keys()) - -moduleTypes = classes.copy() +__all__ = [ + "ExportModuleBase", + "FBXExport", + "MBExport", +] diff --git a/rigsys/modules/motion/FK.py b/rigsys/modules/motion/FK.py index 8b5f978..9ba9ab9 100644 --- a/rigsys/modules/motion/FK.py +++ b/rigsys/modules/motion/FK.py @@ -16,14 +16,14 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", aimAxis: str = "+x", upAxis: str = "-z") -> None: """Initialize the module.""" - super().__init__(rig, side, label, buildOrder, isMuted, - parent, mirror, bypassProxiesOnly, selectedPlug, + super().__init__(rig, side, label, buildOrder, isMuted, + parent, mirror, bypassProxiesOnly, selectedPlug, selectedSocket, aimAxis, upAxis) self.addOffsets = addOffsets self.ctrlShapes = ctrlShapes self.ctrlScale = ctrlScale - if self.ctrlScale == None: + if self.ctrlScale is None: self.ctrlScale = [1.0, 1.0, 1.0] self.segments = segments @@ -147,12 +147,12 @@ def buildModule(self): FKGrps.append(grp) FKCtrls.append(ctrl) ctrlObject = ctrlCrv.Ctrl( - node=ctrl, - shape="circle", - scale=[self.ctrlScale[0], self.ctrlScale[1], self.ctrlScale[2]], - offset=[0, 0, 0], - orient=[0, 90, 0] - ) + node=ctrl, + shape="circle", + scale=[self.ctrlScale[0], self.ctrlScale[1], self.ctrlScale[2]], + offset=[0, 0, 0], + orient=[0, 90, 0] + ) ctrlObject.giveCtrlShape() if self.addOffsets: @@ -163,7 +163,7 @@ def buildModule(self): ctrlObject = ctrlCrv.Ctrl( node=ctrl, shape="square", - scale=[self.ctrlScale[0]*0.85, self.ctrlScale[1]*0.85, self.ctrlScale[2]*0.85], + scale=[self.ctrlScale[0] * 0.85, self.ctrlScale[1] * 0.85, self.ctrlScale[2] * 0.85], offset=[0, 0, 0], orient=[0, 90, 0] ) @@ -191,13 +191,13 @@ def buildModule(self): sc = cmds.scaleConstraint(ctrl, fJnt, n=f"{fJnt}_sc", mo=0) if self.addOffsets: for og in oGrps: - cmds.parent(og, FKCtrls[index]) - index+=1 + cmds.parent(og, FKCtrls[index]) + index += 1 index = 0 for fg in FKGrps: if fg != FKGrps[-1]: - cmds.parent(FKGrps[index+1], FKCtrls[index]) - index+=1 + cmds.parent(FKGrps[index + 1], FKCtrls[index]) + index += 1 cmds.parent([FKGrps[0], FKJoints[0]], self.plugParent) self.addSocketMetaData() diff --git a/rigsys/modules/motion/FKRail.py b/rigsys/modules/motion/FKRail.py index 9c87212..6e0bdcb 100644 --- a/rigsys/modules/motion/FKRail.py +++ b/rigsys/modules/motion/FKRail.py @@ -17,8 +17,8 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", aimAxis: str = "+x", upAxis: str = "-z") -> None: """Initialize the module.""" - super().__init__(rig, side, label, buildOrder, isMuted, - parent, mirror, bypassProxiesOnly, selectedPlug, + super().__init__(rig, side, label, buildOrder, isMuted, + parent, mirror, bypassProxiesOnly, selectedPlug, selectedSocket, aimAxis, upAxis) if ctrlScale is None: diff --git a/rigsys/modules/motion/Root.py b/rigsys/modules/motion/Root.py index 428fe14..586f57c 100644 --- a/rigsys/modules/motion/Root.py +++ b/rigsys/modules/motion/Root.py @@ -16,8 +16,8 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", aimAxis: str = "+x", upAxis: str = "-z") -> None: """Initialize the module.""" - super().__init__(rig, side, label, buildOrder, isMuted, - parent, mirror, bypassProxiesOnly, selectedPlug, + super().__init__(rig, side, label, buildOrder, isMuted, + parent, mirror, bypassProxiesOnly, selectedPlug, selectedSocket, aimAxis, upAxis) if ctrlScale is None: diff --git a/rigsys/modules/motion/__init__.py b/rigsys/modules/motion/__init__.py index acacea9..47a99ee 100644 --- a/rigsys/modules/motion/__init__.py +++ b/rigsys/modules/motion/__init__.py @@ -1,36 +1,27 @@ -"""Motion modules. - -The following code dynamically imports all subclasses of MotionModuleBase present in this directory. That way, you can -import any module in this directory and it will automatically be available in the rigging system. -""" - -from os.path import dirname, basename, isfile, join -import glob -import importlib -import inspect - -# This is the only line that needs to be changed per __init__.py file. Make sure to keep "as baseModule" at the end -from .motionBase import MotionModuleBase as baseModule - -# Import all modules in the current directory -modules = glob.glob(join(dirname(__file__), "*.py")) -__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] -for module in __all__: - importlib.import_module('.' + module, package=str(__name__)) - -# Get all the classes that inherit from baseModule -classes = {str(baseModule.__name__): baseModule} -for cls in baseModule.__subclasses__(): - classes[cls.__name__] = cls - for subClass in cls.__subclasses__(): - classes[subClass.__name__] = subClass - -# Import all the classes that inherit from baseModule -for cls in classes.values(): - classFilePath = inspect.getfile(cls) - importStatement = f"from .{basename(classFilePath)[:-3]} import {cls.__name__}" - exec(importStatement) - -__all__ = list(classes.keys()) - -moduleTypes = classes.copy() +"""Motion modules.""" + +from .motionBase import MotionModuleBase +from .FK import FK +from .FKRail import FKSegment +from .IK import IK +from .Root import Root +from .floating import Floating +from .hand import Hand +from .limb import Limb +from .quadLimb import QuadLimb +from .ribbonBindIK import RibbonBindIK +from .testMotionModule import TestMotionModule + +__all__ = [ + "MotionModuleBase", + "FK", + "FKSegment", + "IK", + "Root", + "Floating", + "Hand", + "Limb", + "QuadLimb", + "RibbonBindIK", + "TestMotionModule", +] diff --git a/rigsys/modules/motion/hand.py b/rigsys/modules/motion/hand.py index 0eea81b..f00bd00 100644 --- a/rigsys/modules/motion/hand.py +++ b/rigsys/modules/motion/hand.py @@ -11,14 +11,16 @@ class Hand(motionBase.MotionModuleBase): """FK Motion Module.""" - def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, addOffset=True, meta: bool = True, - thumb: bool = True, numberOfFingers: int = 4, numberOfFingerJoints: int = 4, numberOfThumbJoints: int = 3, - buildOrder: int = 2000, isMuted: bool = False, parent: str = None, - mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", - aimAxis: str = "+x", upAxis: str = "-z") -> None: + def __init__( + self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, addOffset=True, meta: bool = True, + thumb: bool = True, numberOfFingers: int = 4, numberOfFingerJoints: int = 4, numberOfThumbJoints: int = 3, + buildOrder: int = 2000, isMuted: bool = False, parent: str = None, + mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", + aimAxis: str = "+x", upAxis: str = "-z" + ) -> None: """Initialize the module.""" - super().__init__(rig, side, label, buildOrder, isMuted, - parent, mirror, bypassProxiesOnly, selectedPlug, + super().__init__(rig, side, label, buildOrder, isMuted, + parent, mirror, bypassProxiesOnly, selectedPlug, selectedSocket, aimAxis, upAxis) self.addOffset = addOffset @@ -63,25 +65,25 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, name="Global", parent="Root" ), - } + } for i in range(self.numOfFingers): upVec = f"Finger{i}_UpVector" self.proxies[upVec] = proxy.Proxy( - position=[0, 0, 0], - rotation=[0, 0, 0], - side=self.side, - label=self.label, - name=upVec, - parent="Root" - ) + position=[0, 0, 0], + rotation=[0, 0, 0], + side=self.side, + label=self.label, + name=upVec, + parent="Root" + ) for j in range(self.numOfFingerJoints): name = f"Finger{i}_{j}" if j == 0: par = "Root" newPar = name else: - par = f"Finger{i}_{j-1}" + par = f"Finger{i}_{j-1}" self.proxies[name] = proxy.Proxy( position=[0, 0, 0], rotation=[0, 0, 0], @@ -93,22 +95,22 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, self.proxies[upVec].parent = "Root" if self.thumb: - upVec = f"Thumb_UpVector" + upVec = "Thumb_UpVector" self.proxies[upVec] = proxy.Proxy( - position=[0, 0, 0], - rotation=[0, 0, 0], - side=self.side, - label=self.label, - name=upVec, - parent="Root" - ) + position=[0, 0, 0], + rotation=[0, 0, 0], + side=self.side, + label=self.label, + name=upVec, + parent="Root" + ) for i in range(self.numOfThumbJoints): name = f"Thumb_{i}" if i == 0: par = "Root" newPar = name else: - par = f"Thumb_{i-1}" + par = f"Thumb_{i-1}" self.proxies[name] = proxy.Proxy( position=[0, 0, 0], rotation=[0, 0, 0], @@ -119,7 +121,6 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, ) self.proxies[upVec].parent = "Root" - self.socket = { "Start": None, "End": None @@ -169,7 +170,7 @@ def buildModule(self): jnt = cmds.createNode("joint", n=f"{name}") if val.parent is not None: parentDict[name] = par - + cmds.xform(jnt, ws=True, t=val.position) Joints.append(jnt) self.sockets[key] = jnt @@ -177,7 +178,7 @@ def buildModule(self): posAim = self.aimAxis aimVec = jointTools.axisToVector(posAim) - # posUp = self.upAxis + # posUp = self.upAxis # posUpVec = jointTools.axisToVector(posUp) crossAxis = jointTools.getCrossAxis(self.aimAxis, self.upAxis) crossVec = jointTools.axisToVector(crossAxis) @@ -185,16 +186,17 @@ def buildModule(self): for jnt in Joints: if self.proxies["Root"].name in jnt: ac = cmds.aimConstraint( - f"{self.side}_{self.label}_{self.proxies['End'].name}_proxy", - jnt, - n=f"{jnt}_ac", aim=aimVec, u=crossVec, wut="object", - wuo=f"{self.side}_{self.label}_{self.proxies['UpVector'].name}_proxy", - wu=[0, 1, 0], mo=0)[0] + f"{self.side}_{self.label}_{self.proxies['End'].name}_proxy", + jnt, + n=f"{jnt}_ac", aim=aimVec, u=crossVec, wut="object", + wuo=f"{self.side}_{self.label}_{self.proxies['UpVector'].name}_proxy", + wu=[0, 1, 0], mo=0 + )[0] cmds.delete(ac) cmds.makeIdentity(jnt, a=True) root = jnt self.bindJoints[root] = None - + for key, val in parentDict.items(): cmds.parent(key, val) @@ -210,7 +212,7 @@ def buildModule(self): cmds.makeIdentity(targets, a=True) fingerDict[name] = targets targets = [] - + if self.thumb: targets = [] upVectorTarget = f"{self.side}_{self.label}_Thumb_UpVector_proxy" @@ -223,10 +225,15 @@ def buildModule(self): fingerDict["Thumb"] = targets targets = [] - globalGrp = cmds.createNode("transform", - n=f"{self.side}_{self.label}_{self.proxies['Global'].name}_grp") - globalCtrl = cmds.createNode("transform", - n=f"{self.side}_{self.label}_{self.proxies['Global'].name}_CTRL", p=globalGrp) + globalGrp = cmds.createNode( + "transform", + n=f"{self.side}_{self.label}_{self.proxies['Global'].name}_grp", + ) + globalCtrl = cmds.createNode( + "transform", + n=f"{self.side}_{self.label}_{self.proxies['Global'].name}_CTRL", + p=globalGrp, + ) cmds.xform(globalGrp, ws=True, t=cmds.xform( f"{self.side}_{self.label}_{self.proxies['Global'].name}_proxy", q=True, ws=True, t=True )) @@ -242,17 +249,17 @@ def buildModule(self): orient=[0, 0, 0] ) globalCtrlObject.giveCtrlShape() - + count = 0 rate = 0 ratio = 1 / (len(fingerDict.keys()) * .5) for key, val in fingerDict.items(): # We Know the order of fingers, and finger joints. # - + tsMD = cmds.createNode("multiplyDivide", n=f"{self.side}_{key}_twistSplay_md") udMD = cmds.createNode("multiplyDivide", n=f"{self.side}_{key}_upDn_md") - + fingerGrp = [] upDnList = [] twistList = [] @@ -261,20 +268,20 @@ def buildModule(self): fingerCtrls = [] val.sort() for jnt in val: - grp = cmds.createNode("transform", n=f"{jnt}_grp") + grp = cmds.createNode("transform", n=f"{jnt}_grp") upDn = cmds.createNode("transform", n=f"{jnt}_upDn", p=grp) upDnList.append(upDn) if jnt == val[0]: twist = cmds.createNode("transform", n=f"{jnt}_twist", p=upDn) splay = cmds.createNode("transform", n=f"{jnt}_splay", p=twist) - ctrl = cmds.createNode("transform", n=f"{jnt}_CTRL", p=splay) + ctrl = cmds.createNode("transform", n=f"{jnt}_CTRL", p=splay) twistList.append(twist) splayList.append(splay) - + elif jnt == val[1]: if self.meta: nSplay = cmds.createNode("transform", n=f"{jnt}_splay", p=upDn) - ctrl = cmds.createNode("transform", n=f"{jnt}_CTRL", p=nSplay) + ctrl = cmds.createNode("transform", n=f"{jnt}_CTRL", p=nSplay) nSplayList.append(nSplay) else: ctrl = cmds.createNode("transform", n=f"{jnt}_CTRL", p=upDn) @@ -308,10 +315,10 @@ def buildModule(self): for xyz in aimVec: if xyz != 0: aimDirection = xyz - - cmds.setAttr(f"{tsMD}.input2.input2X", (1+rate)*-1) - cmds.setAttr(f"{tsMD}.input2.input2Y", (1+rate)) - cmds.setAttr(f"{tsMD}.input2.input2Z", ((1+rate)*-1.5)*aimDirection) + + cmds.setAttr(f"{tsMD}.input2.input2X", (1 + rate) * -1) + cmds.setAttr(f"{tsMD}.input2.input2Y", (1 + rate)) + cmds.setAttr(f"{tsMD}.input2.input2Z", ((1 + rate) * -1.5) * aimDirection) cmds.setAttr(f"{udMD}.input2.input2X", (1) * aimDirection) cmds.connectAttr(f"{globalCtrl}.rotateX", f"{tsMD}.input1.input1X") cmds.connectAttr(f"{globalCtrl}.rotateY", f"{tsMD}.input1.input1Y") @@ -319,15 +326,15 @@ def buildModule(self): cmds.connectAttr(f"{globalCtrl}.rotateZ", f"{udMD}.input1.input1X") for upDn in upDnList: cmds.connectAttr(f"{udMD}.output.outputX", f"{upDn}.rotateY") - for twist in twistList: + for twist in twistList: cmds.connectAttr(f"{tsMD}.output.outputX", f"{twist}.rotateY") for splay in splayList: cmds.connectAttr(f"{tsMD}.output.outputZ", f"{splay}.rotateZ") for nSplay in nSplayList: cmds.connectAttr(f"{tsMD}.output.outputZ", f"{nSplay}.rotateZ") - rate-=ratio + rate -= ratio - count+=1 + count += 1 cmds.parent(root, self.plugParent) cmds.parent(globalGrp, self.plugParent) diff --git a/rigsys/modules/motion/limb.py b/rigsys/modules/motion/limb.py index d7b75a3..3691cdd 100644 --- a/rigsys/modules/motion/limb.py +++ b/rigsys/modules/motion/limb.py @@ -11,15 +11,15 @@ class Limb(motionBase.MotionModuleBase): """Limb Motion Module.""" - def __init__(self, rig, side="", label="", + def __init__(self, rig, side="", label="", buildOrder: int = 2000, isMuted: bool = False, parent: str = None, mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", - aimAxis: str = "+x", upAxis: str = "-z", ctrlShapes="circle", ctrlScale=None, addOffset=True, - clavicle=True, pvMultiplier: float = 1.0, numberOfJoints: int = 11, + aimAxis: str = "+x", upAxis: str = "-z", ctrlShapes="circle", ctrlScale=None, addOffset=True, + clavicle=True, pvMultiplier: float = 1.0, numberOfJoints: int = 11, nameSet: dict = {"Root": "Root", "Start": "Start", "Mid": "Mid", "End": "End"}) -> None: """Initialize the module.""" super().__init__(rig, side, label, buildOrder, isMuted, - parent, mirror, bypassProxiesOnly, selectedPlug, + parent, mirror, bypassProxiesOnly, selectedPlug, selectedSocket, aimAxis, upAxis) self.addOffset = addOffset @@ -180,9 +180,10 @@ def buildSkeleton(self): # and aim those joints. Finally with the shoulder rotations set the clav will # be aimed and we can remove the constraint, parent the shoulder to the clavicle # and then freeze xforms - ac = cmds.aimConstraint(baseJoints[1], baseJoints[0], aim=aimVec, - u=upVec, wut="objectrotation", wu=upVec, wuo=baseJoints[1])[0] - + ac = cmds.aimConstraint( + baseJoints[1], baseJoints[0], aim=aimVec, u=upVec, wut="objectrotation", wu=upVec, wuo=baseJoints[1] + )[0] + cmds.parent(baseJoints[2], baseJoints[1]) cmds.parent(baseJoints[3], baseJoints[2]) @@ -419,7 +420,6 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): offsetVal = axisMultOffset * xyz offsetArray.append(offsetVal) - endCtrlObject = ctrlCrv.Ctrl( node=endCtrl, shape="box", @@ -510,8 +510,8 @@ def buildCounterJoints(self, baseJoints, socketConnector, endJoint): oc = cmds.orientConstraint(baseJoints[2], loRollEnd, n=f"{loRollEnd}_oc", mo=0) cmds.parent(loIK, baseJoints[3]) - - #Cleanup + + # Cleanup # cmds.parent([upIK, loIK], self.moduleUtilities) return [upRollStart, upRollEnd], [loRollStart, loRollEnd], upIK, loIK @@ -608,7 +608,7 @@ def buildRibbon(self, baseJoints, upRollJoints, loRollJoints, midOffset, endOffs ribbonOffsets.append(offset) ribbonControls.append(ctrl) ribbonJoints.append(jnt) - self.sockets[f"Ribbon_{i}"] = jnt + self.sockets[f"Ribbon_{i}"] = jnt ctrlObject = ctrlCrv.Ctrl( node=ctrl, shape="circle", @@ -671,14 +671,13 @@ def buildRibbon(self, baseJoints, upRollJoints, loRollJoints, midOffset, endOffs ptc = cmds.parentConstraint( midOffset, ribbonGroups[3], n=f"{ribbonGroups[3]}_ptc", mo=0) - - + posAim = self.aimAxis negAim = jointTools.axisFlip(self.aimAxis) posAimVec = jointTools.axisToVector(posAim) negAimVec = jointTools.axisToVector(negAim) - # posUp = self.upAxis + # posUp = self.upAxis # posUpVec = jointTools.axisToVector(posUp) crossAxis = jointTools.getCrossAxis(self.aimAxis, self.upAxis) crossVec = jointTools.axisToVector(crossAxis) diff --git a/rigsys/modules/motion/motionBase.py b/rigsys/modules/motion/motionBase.py index 0e8567b..2a7f683 100644 --- a/rigsys/modules/motion/motionBase.py +++ b/rigsys/modules/motion/motionBase.py @@ -120,13 +120,12 @@ def socketPlugParenting(self): ptc = cmds.parentConstraint(socket, self.selectedPlug, mo=1)[0] cmds.setAttr(f"{ptc}.interpType", 2) sc = cmds.scaleConstraint(socket, self.selectedPlug, mo=1) - + # # Get world # if self.parent is None: # worldSocket = list(self.sockets.values())[-1] # ptc = cmds.parentConstraint(worldSocket, self.) - def addSocketMetaData(self): cmds.addAttr(self.moduleNode, ln="SocketData", at="enum", en="--------") for key, val in self.sockets.items(): diff --git a/rigsys/modules/motion/quadLimb.py b/rigsys/modules/motion/quadLimb.py index 16bbb07..77691b6 100644 --- a/rigsys/modules/motion/quadLimb.py +++ b/rigsys/modules/motion/quadLimb.py @@ -7,24 +7,27 @@ import maya.cmds as cmds + class QuadLimb(motionBase.MotionModuleBase): """Quad Limb Motion Module""" - def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, addOffset=True, clavicle=True, - buildOrder: int = 2000, isMuted: bool = False, parent: str = None, - mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", - aimAxis: str = "+x", upAxis: str = "-z", pvMultiplier: float = 1.0, - curvedCalf: bool = True, ikCtrlToFloor: bool = True, foot: bool = False, - nameSet: dict = {"Root":"Root", "Start":"Start", "UpMid":"UpMid", "LoMid":"LoMid", "End":"End"}) -> None: + def __init__( + self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, addOffset=True, clavicle=True, + buildOrder: int = 2000, isMuted: bool = False, parent: str = None, + mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", + aimAxis: str = "+x", upAxis: str = "-z", pvMultiplier: float = 1.0, + curvedCalf: bool = True, ikCtrlToFloor: bool = True, foot: bool = False, + nameSet: dict = {"Root": "Root", "Start": "Start", "UpMid": "UpMid", "LoMid": "LoMid", "End": "End"} + ) -> None: """Initialize the module.""" - super().__init__(rig, side, label, buildOrder, isMuted, - parent, mirror, bypassProxiesOnly, selectedPlug, + super().__init__(rig, side, label, buildOrder, isMuted, + parent, mirror, bypassProxiesOnly, selectedPlug, selectedSocket, aimAxis, upAxis) self.addOffset = addOffset self.ctrlShapes = ctrlShapes self.ctrlScale = ctrlScale - if self.ctrlScale == None: + if self.ctrlScale is None: self.ctrlScale = [1.0, 1.0, 1.0] self.clavicle = clavicle @@ -75,7 +78,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, for i in range(1, 6): if previousParent is None: previousParent = self.nameSet["LoMid"] - self.proxies[f"{self.nameSet['LoMid']}_{i}"] = proxy.Proxy( + self.proxies[f"{self.nameSet['LoMid']}_{i}"] = proxy.Proxy( position=[5, 3, -1], rotation=[0, 0, 0], side=self.side, @@ -84,7 +87,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, parent=previousParent) previousParent = f"{self.nameSet['LoMid']}_{i}" - self.proxies[self.nameSet["End"]] = proxy.Proxy( + self.proxies[self.nameSet["End"]] = proxy.Proxy( position=[5, 1, 0], rotation=[0, 0, 0], side=self.side, @@ -100,7 +103,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name=self.nameSet["End"], parent=self.nameSet['LoMid']) - + if self.foot: self.proxies["Pivot"] = proxy.Proxy( position=[5, 1, 0], @@ -109,7 +112,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name="Pivot", parent=self.nameSet["End"]) - + self.proxies["Heel"] = proxy.Proxy( position=[5, 1, 0], rotation=[0, 0, 0], @@ -117,7 +120,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name="Heel", parent=self.nameSet["End"]) - + self.proxies["OutBank"] = proxy.Proxy( position=[5, 1, 0], rotation=[0, 0, 0], @@ -125,7 +128,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name="OutBank", parent=self.nameSet["End"]) - + self.proxies["InBank"] = proxy.Proxy( position=[5, 1, 0], rotation=[0, 0, 0], @@ -133,7 +136,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name="InBank", parent=self.nameSet["End"]) - + self.proxies['Ball'] = proxy.Proxy( position=[5, 1, 0], rotation=[0, 0, 0], @@ -141,7 +144,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name="Ball", parent="Pivot") - + self.proxies["Toe"] = proxy.Proxy( position=[5, 1, 0], rotation=[0, 0, 0], @@ -149,7 +152,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name="Toe", parent="Ball") - + self.proxies["Global"] = proxy.Proxy( position=[5, 1, 0], rotation=[0, 0, 0], @@ -157,8 +160,6 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, label=self.label, name="Global", parent=self.nameSet["End"]) - - # Module Based Variables self.poleVector = None @@ -171,7 +172,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="circle", ctrlScale=None, def buildProxies(self): """Build the proxies for the module.""" return super().buildProxies() - + def buildModule(self) -> None: """Run the module.""" @@ -193,10 +194,20 @@ def buildModule(self) -> None: self.plugs["World"] = self.worldParent baseJoints, FKJoints, IKJoints, upConnector = self.buildSkeleton() - IKControls, FKControls, upRollJoints, loRollJoints, upIK, loIK, guideIK = self.buildBaseControls(baseJoints, IKJoints, FKJoints, upConnector) + IKControls, FKControls, upRollJoints, loRollJoints, upIK, loIK, guideIK = self.buildBaseControls( + baseJoints, + IKJoints, + FKJoints, + upConnector, + ) if self.foot: - self.buildFoot(baseJoints, IKJoints, FKJoints, IKControls, FKControls, upIK, guideIK) - # IKControls, FKControls, midCtrl, endCtrl, upRollJoints, loRollJoints, upIK, loIK = self.buildBaseControls(baseJoints, IKJoints, FKJoints, upConnector) + self.buildFoot(baseJoints, IKJoints, FKJoints, IKControls, FKControls, upIK, guideIK) + # IKControls, FKControls, midCtrl, endCtrl, upRollJoints, loRollJoints, upIK, loIK = self.buildBaseControls( + # baseJoints, + # IKJoints, + # FKJoints, + # upConnector, + # ) # self.buildRibbon(baseJoints, upRollJoints, loRollJoints, midCtrl, endCtrl) # Cleanup @@ -204,8 +215,8 @@ def buildModule(self) -> None: self.addSocketMetaData() ''' - TODO: Working on the base skeleton. Should be positioned and built correctly? Will move onto - the controls which were duped from the limb module. Still needs the secondary IK limb + TODO: Working on the base skeleton. Should be positioned and built correctly? Will move onto + the controls which were duped from the limb module. Still needs the secondary IK limb that drives the orientation of the lower leg. ''' def buildSkeleton(self): @@ -232,7 +243,7 @@ def buildSkeleton(self): cmds.parent(self.poleVector, pvPar) destination = jointTools.getPoleVector(baseJoints[1], baseJoints[2], baseJoints[3], self.pvMultiplier) cmds.xform(pvPar, ws=True, t=destination) - + for i in ["X", "Y", "Z"]: cmds.setAttr(f"{self.poleVector}.localScale{i}", 0, l=True) @@ -240,8 +251,8 @@ def buildSkeleton(self): for j in baseJoints: if j is not baseJoints[0] and j is not baseJoints[1]: cmds.parent(j, baseJoints[index]) - index+=1 - + index += 1 + # cmds.parent(baseJoints[1], baseJoints[0]) # cmds.parent(baseJoints[2], baseJoints[1]) # cmds.parent(baseJoints[3], baseJoints[2]) @@ -252,17 +263,18 @@ def buildSkeleton(self): upVec = jointTools.axisToVector(self.upAxis) jointTools.aimSequence(baseJoints[1::], upObj=self.poleVector, aimAxis=self.aimAxis, upAxis=self.upAxis) - ac = cmds.aimConstraint(baseJoints[1], baseJoints[0], aim=aimVec, - u=upVec, wut="objectrotation", wu=upVec, wuo=baseJoints[1])[0] + ac = cmds.aimConstraint( + baseJoints[1], baseJoints[0], aim=aimVec, u=upVec, wut="objectrotation", wu=upVec, wuo=baseJoints[1] + )[0] cmds.delete(ac) cmds.parent(baseJoints[1], baseJoints[0]) cmds.makeIdentity(baseJoints[0], a=True) - + index = 1 for jnt in baseJoints[1::]: fkJnt = cmds.createNode("joint", n=f"{jnt}_FK") ikJnt = cmds.createNode("joint", n=f"{jnt}_IK") - + FKJoints.append(fkJnt) IKJoints.append(ikJnt) @@ -272,16 +284,15 @@ def buildSkeleton(self): cmds.xform([fkJnt, ikJnt], ws=True, ro=cmds.xform( jnt, q=True, ws=True, ro=True )) - cmds.makeIdentity([fkJnt, ikJnt], a=True) - + if jnt != baseJoints[1]: cmds.parent(fkJnt, f"{baseJoints[index]}_FK") cmds.parent(ikJnt, f"{baseJoints[index]}_IK") - index+=1 + index += 1 else: cmds.parent(fkJnt, baseJoints[0]) cmds.parent(ikJnt, baseJoints[0]) - + socketConnector = cmds.createNode("joint", n=f"{baseJoints[1]}_Connection") cmds.xform(socketConnector, ws=True, t=cmds.xform( baseJoints[1], q=True, ws=True, t=True @@ -294,21 +305,15 @@ def buildSkeleton(self): cmds.parent([baseJoints[1], FKJoints[0], IKJoints[0]], socketConnector) return baseJoints, FKJoints, IKJoints, socketConnector - def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): # Make 3 Point IK for Quad Calc:: Guide Joints / IK guideLength_1 = cmds.xform(IKJoints[2], q=True, a=True, t=True)[0] if self.curvedCalf: - guideLength_2 = (cmds.xform(IKJoints[1], q=True, a=True, t=True)[0] + - cmds.xform(IKJoints[3], q=True, a=True, t=True)[0] + - cmds.xform(IKJoints[4], q=True, a=True, t=True)[0] + - cmds.xform(IKJoints[5], q=True, a=True, t=True)[0] + - cmds.xform(IKJoints[6], q=True, a=True, t=True)[0] + - cmds.xform(IKJoints[7], q=True, a=True, t=True)[0] ) + guideLength_2 = sum(cmds.xform(IKJoints[1::], q=True, a=True, t=True)) else: - guideLength_2 = cmds.xform(IKJoints[1], q=True, a=True, t=True)[0] + cmds.xform(IKJoints[3], q=True, a=True, t=True)[0] - + guideLength_2 = cmds.xform(IKJoints[1], q=True, a=True, t=True)[0] + guideLength_2 += cmds.xform(IKJoints[3], q=True, a=True, t=True)[0] # Make joints startGuide = cmds.createNode("joint", n=f"{self.side}_{self.label}_StartGuide") @@ -328,7 +333,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): cmds.xform(midGuide, r=True, t=[guideLength_1, 0, 0]) cmds.xform(endGuide, r=True, t=[guideLength_2, 0, 0]) cmds.xform(midGuide, r=True, ro=[0, 90, 0]) - cmds.makeIdentity(startGuide, a=True) + cmds.makeIdentity(startGuide, a=True) # Generate IK, place IK, constrain guideIKHandle = cmds.ikHandle(n=f"{self.side}_{self.label}_GuideIK", sj=startGuide, ee=endGuide, sol="ikRPsolver", p=1) @@ -357,7 +362,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): node=ikCtrl, shape="box", scale=[self.ctrlScale[0], self.ctrlScale[1], self.ctrlScale[2]], - offset=[0, self.ctrlScale[1]*1, 0], + offset=[0, self.ctrlScale[1] * 1, 0], orient=[0, 0, 0] ) else: @@ -400,7 +405,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): pvCtrlObject = ctrlCrv.Ctrl( node=pvCtrl, shape="sphere", - scale=[self.ctrlScale[0]*0.75, self.ctrlScale[1]*0.75, self.ctrlScale[2]*0.75], + scale=[self.ctrlScale[0] * 0.75, self.ctrlScale[1] * 0.75, self.ctrlScale[2] * 0.75], offset=[0, 0, 0] ) pvCtrlObject.giveCtrlShape() @@ -408,7 +413,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): if self.curvedCalf: cmds.parent(pvPar, ikCtrl) - + # Make IK Handle ikRP = cmds.ikHandle(n=f"{self.side}_{self.label}_UP_IK", sj=IKJoints[0], ee=IKJoints[2], sol="ikRPsolver", p=1) effRP = cmds.rename(ikRP[1], f"{self.side}_{self.label}_UP_EFF") @@ -416,7 +421,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): # cmds.parent(ik, ikCtrl) Needs parenting to the calf IK oc = cmds.orientConstraint(ikCtrl, IKJoints[-1], n=f"{IKJoints}_oc", mo=1) pvc = cmds.poleVectorConstraint(self.poleVector, ikRP, n=f"{ikRP}_pvc") - pvc = cmds.poleVectorConstraint(self.poleVector, guideIKHandle, n=f"{guideIKHandle}_pvc") + pvc = cmds.poleVectorConstraint(self.poleVector, guideIKHandle, n=f"{guideIKHandle}_pvc") ikSC = cmds.ikHandle(n=f"{self.side}_{self.label}_LO_IK", sj=IKJoints[2], ee=IKJoints[-1], sol="ikSCsolver", p=1) effSC = cmds.rename(ikSC[1], f"{self.side}_{self.label}_LO_EFF") @@ -426,7 +431,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): # Add calf logic oc = cmds.orientConstraint(midGuide, ikOffsetGrp, n=f"{ikOffsetGrp}_oc", mo=0) cmds.parent([ikRP, ikSC], ikOffsetCtrl) - cmds.parent(guideIKHandle, ikCtrl) + cmds.parent(guideIKHandle, ikCtrl) # FK Controls for jnt in FKJoints: @@ -447,7 +452,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): ) fkCtrlObject.giveCtrlShape() ptc = cmds.parentConstraint(ctrl, jnt, n=f"{jnt}_ptc", mo=0) - + if len(FKControls) != 0: cmds.parent(grp, FKControls[-1]) FKControls.append(ctrl) @@ -458,17 +463,17 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): clavCtrlObject = ctrlCrv.Ctrl( node=clavCtrl, shape="sphere", - scale=[self.ctrlScale[0]*1.5, self.ctrlScale[1]*1.5, self.ctrlScale[2]*1.5], + scale=[self.ctrlScale[0] * 1.5, self.ctrlScale[1] * 1.5, self.ctrlScale[2] * 1.5], offset=[0, 0, 0] ) clavCtrlObject.giveCtrlShape() cmds.xform(clavGrp, ws=True, t=cmds.xform( - baseJoints[0], q=True, ws=True, t=True - )) + baseJoints[0], q=True, ws=True, t=True + )) cmds.xform(clavGrp, ws=True, ro=cmds.xform( - baseJoints[0], q=True, ws=True, ro=True - )) - + baseJoints[0], q=True, ws=True, ro=True + )) + ptc = cmds.parentConstraint(clavCtrl, baseJoints[0], n=f"{baseJoints[0]}_ptc", mo=0) fkPar = cmds.listRelatives(FKControls[0], p=True)[0] @@ -477,21 +482,21 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): localTransform = cmds.createNode('transform', n=f"{baseJoints[1]}_Local") cmds.xform(globalTransform, ws=True, t=cmds.xform( - baseJoints[1], q=True, ws=True, t=True - )) + baseJoints[1], q=True, ws=True, t=True + )) cmds.xform(globalTransform, ws=True, ro=cmds.xform( - baseJoints[1], q=True, ws=True, ro=True - )) + baseJoints[1], q=True, ws=True, ro=True + )) cmds.xform(localTransform, ws=True, t=cmds.xform( - baseJoints[1], q=True, ws=True, t=True - )) + baseJoints[1], q=True, ws=True, t=True + )) cmds.xform(localTransform, ws=True, ro=cmds.xform( - baseJoints[1], q=True, ws=True, ro=True - )) + baseJoints[1], q=True, ws=True, ro=True + )) cmds.parent(globalTransform, self.worldParent) cmds.parent(localTransform, clavCtrl) - + ptc = cmds.parentConstraint(clavCtrl, globalTransform, n=f"{globalTransform}_ptc", mo=1) oc = cmds.orientConstraint([globalTransform, localTransform], fkPar, n=f"{fkPar}_Lock_oc", mo=0)[0] cmds.setAttr(f"{oc}.interpType", 2) @@ -525,8 +530,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): cmds.connectAttr(f"{IKJoints[index]}.rotate", f"{bc}.color2") cmds.connectAttr(f"{bc}.output", f"{jnt}.rotate") - - index+=1 + index += 1 fkCtrlPar = cmds.listRelatives(FKControls[0], p=True)[0] cmds.connectAttr(f"{ikCtrl}.IK_FK_Switch", f"{fkCtrlPar}.visibility") rev = cmds.createNode("reverse", n=f"{self.side}_{self.label}_IKFK_rev") @@ -553,7 +557,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): shape="circle", scale=[self.ctrlScale[0], self.ctrlScale[1], self.ctrlScale[2]], offset=[0, 0, 0], - orient=[0, 90, 0] + orient=[0, 90, 0], ) ctrlOject.giveCtrlShape() @@ -578,7 +582,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): shape="circle", scale=[self.ctrlScale[0], self.ctrlScale[1], self.ctrlScale[2]], offset=[0, 0, 0], - orient=[0, 90, 0] + orient=[0, 90, 0], ) ctrlOject.giveCtrlShape() @@ -591,7 +595,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): else: self.bindJoints[jnt] = loJoints[len(loJoints) - 2] - index+=1 + index += 1 else: for i in range(3): name = f"{loRollJoints[0]}_{i}" @@ -604,7 +608,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): shape="circle", scale=[self.ctrlScale[0], self.ctrlScale[1], self.ctrlScale[2]], offset=[0, 0, 0], - orient=[0, 90, 0] + orient=[0, 90, 0], ) ctrlOject.giveCtrlShape() @@ -613,7 +617,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): self.sockets[name] = jnt self.bindJoints[jnt] = baseJoints[3] - # Constrain up and lo controls + # Constrain up and lo controls ptc = cmds.parentConstraint([upRollJoints[0], upRollJoints[1]], upGrps[0], n=f"{upGrps[0]}_ptc", mo=0)[0] cmds.setAttr(f"{ptc}.interpType", 2) cmds.setAttr(f"{ptc}.{upRollJoints[0]}W0", 3) @@ -633,7 +637,7 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): index = 0 for i in baseJoints[4:-1]: ptc = cmds.parentConstraint(i, loGrps[index], n=f"{loGrps[index]}_ptc", mo=0) - index+=1 + index += 1 else: ptc = cmds.parentConstraint([loRollJoints[0], loRollJoints[1]], loGrps[0], n=f"{loGrps[0]}_ptc", mo=0)[0] cmds.setAttr(f"{ptc}.interpType", 2) @@ -652,14 +656,13 @@ def buildBaseControls(self, baseJoints, IKJoints, FKJoints, socketConnector): # Cleanup if self.curvedCalf: - cmds.parent([clavGrp, cmds.listRelatives(FKControls[0], p=True)[0]], self.plugParent) + cmds.parent([clavGrp, cmds.listRelatives(FKControls[0], p=True)[0]], self.plugParent) else: cmds.parent([clavGrp, pvPar, cmds.listRelatives(FKControls[0], p=True)[0]], self.plugParent) cmds.parent(ikGrp, self.worldParent) - + cmds.parent(loGrps, self.plugParent) cmds.parent(upGrps, self.plugParent) - return IKControls, FKControls, upRollJoints, loRollJoints, upIK, loIK, guideIKHandle @@ -708,9 +711,9 @@ def buildCounterJoints(self, baseJoints, socketConnector): oc = cmds.orientConstraint(baseJoints[3], loRollEnd, n=f"{loRollEnd}_oc", mo=0) cmds.parent(loIK, baseJoints[-1]) # return [upRollStart, upRollEnd], [midRollStart, midRollEnd], [loRollStart, loRollEnd], upIK, midIK, loIK - + return [upRollStart, upRollEnd], [loRollStart, loRollEnd], upIK, loIK - + def buildFoot(self, baseJoints, IKJoints, FKJoints, IKControls, FKControls, upIK, guideIK): # for key, val in self.proxies.items(): # if key in omit: @@ -737,23 +740,20 @@ def buildFoot(self, baseJoints, IKJoints, FKJoints, IKControls, FKControls, upIK cmds.parent(ball, FKJoints[-1]) fk.append(ball) fk.append(toe) - jointTools.aimSequence(base, upObj=self.poleVector, - aimAxis=self.aimAxis, upAxis=self.upAxis) - jointTools.aimSequence(ik, upObj=self.poleVector, - aimAxis=self.aimAxis, upAxis=self.upAxis) - jointTools.aimSequence(fk, upObj=self.poleVector, - aimAxis=self.aimAxis, upAxis=self.upAxis) + jointTools.aimSequence(base, upObj=self.poleVector, aimAxis=self.aimAxis, upAxis=self.upAxis) + jointTools.aimSequence(ik, upObj=self.poleVector, aimAxis=self.aimAxis, upAxis=self.upAxis) + jointTools.aimSequence(fk, upObj=self.poleVector, aimAxis=self.aimAxis, upAxis=self.upAxis) index += 1 - cmds.makeIdentity([ball, toe], a=True) + cmds.makeIdentity([ball, toe], a=True) inverse = ["InBank", "OutBank", "Heel", "Pivot", "Toe", "Ball", self.nameSet["End"]] iJnts = [] index = 0 for i in inverse: jnt = cmds.createNode("joint", n=f"{label}_{i}_INV") - + if len(iJnts) > 0: - cmds.parent(jnt, iJnts[index-1]) + cmds.parent(jnt, iJnts[index - 1]) cmds.xform(jnt, ws=True, t=self.proxies[i].position) iJnts.append(jnt) @@ -764,7 +764,6 @@ def buildFoot(self, baseJoints, IKJoints, FKJoints, IKControls, FKControls, upIK else: self.bindJoints[jnt] = iJnts[len(iJnts) - 2] - ballIK = cmds.ikHandle(sj=IKJoints[-1], ee=ik[0], n=f"{ik[0]}_IK", sol="ikSCsolver") ballEFF = ballIK[1] ballIK = ballIK[0] @@ -795,7 +794,7 @@ def buildFoot(self, baseJoints, IKJoints, FKJoints, IKControls, FKControls, upIK cmds.setAttr(f"{i}.colorIfFalseR", 0) cmds.setAttr(f"{i}.colorIfFalseG", 0) cmds.setAttr(f"{i}.colorIfFalseB", 0) - + for i in ["X", "Y", "Z"]: if i != "X": cmds.setAttr(f"{rollMD}.input2{i}", -1) @@ -809,7 +808,7 @@ def buildFoot(self, baseJoints, IKJoints, FKJoints, IKControls, FKControls, upIK cmds.connectAttr(f"{globalCtrl}.rotateZ", f"{bankCD}.colorIfTrueR") cmds.connectAttr(f"{globalCtrl}.rotateZ", f"{bankCD}.colorIfFalseG") cmds.connectAttr(f"{globalCtrl}.rotateZ", f"{bankCD}.firstTerm") - cmds.connectAttr(f"{globalCtrl}.rotateX", f"{raiseCD}.colorIfTrueR") + cmds.connectAttr(f"{globalCtrl}.rotateX", f"{raiseCD}.colorIfTrueR") cmds.connectAttr(f"{globalCtrl}.rotateX", f"{raiseCD}.colorIfFalseG") cmds.connectAttr(f"{globalCtrl}.rotateX", f"{raiseCD}.firstTerm") # ["InBank", "OutBank", "Heel", "Pivot", "Toe", "Ball", self.nameSet["End"]] diff --git a/rigsys/modules/motion/ribbonBindIK.py b/rigsys/modules/motion/ribbonBindIK.py index 0cb75e4..faa09f3 100644 --- a/rigsys/modules/motion/ribbonBindIK.py +++ b/rigsys/modules/motion/ribbonBindIK.py @@ -10,12 +10,12 @@ class RibbonBindIK(motionBase.MotionModuleBase): """Root Motion Module.""" def __init__(self, rig, side="", label="", ctrlShapes="sphere", ctrlScale=None, addOffset=True, spans=5, - reverse=True, meta=True, numberOfJoints=10, localAxisTranslate = "X", buildOrder: int = 2000, - isMuted: bool = False, parent: str = None, mirror: bool = False, bypassProxiesOnly: bool = True, + reverse=True, meta=True, numberOfJoints=10, localAxisTranslate="X", buildOrder: int = 2000, + isMuted: bool = False, parent: str = None, mirror: bool = False, bypassProxiesOnly: bool = True, selectedPlug: str = "", selectedSocket: str = "", aimAxis: str = "+x", upAxis: str = "-z") -> None: """Initialize the module.""" - super().__init__(rig, side, label, buildOrder, isMuted, - parent, mirror, bypassProxiesOnly, selectedPlug, + super().__init__(rig, side, label, buildOrder, isMuted, + parent, mirror, bypassProxiesOnly, selectedPlug, selectedSocket, aimAxis, upAxis) if ctrlScale is None: @@ -71,7 +71,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="sphere", ctrlScale=None, self.proxies["End"] = self.proxies.pop("End") self.proxies["End"].parent = str(self.spans - 1) - + self.plugs = { "Local": None, "World": None @@ -83,7 +83,7 @@ def __init__(self, rig, side="", label="", ctrlShapes="sphere", ctrlScale=None, def buildProxies(self): """Build the proxies for the module.""" return super().buildProxies() - + def buildModule(self) -> None: """Run the module.""" @@ -104,7 +104,7 @@ def buildModule(self) -> None: self.worldParent = self.createWorldParent() self.plugs["Local"] = self.plugParent self.plugs["World"] = self.worldParent - + self.buildRibbons() # baseJoints, FKJoints, IKJoints, upConnector = self.buildSkeleton() @@ -129,7 +129,7 @@ def buildRibbons(self): else: self.upVector = cmds.createNode("transform", n=f"{name}_{key}_temp") cmds.xform(self.upVector, ws=True, t=val.position) - + jointTools.aimSequence(targets=targets, upObj=self.upVector) folGrp = cmds.createNode( "transform", n=f"{self.side}_{self.label}_follicles") @@ -147,22 +147,23 @@ def buildRibbons(self): cmds.reverseSurface(ribbon, d=3, ch=False, rpo=1) cmds.rebuildSurface( ribbon, rpo=1, rt=0, end=1, kr=0, kcp=0, kc=0, - su=self.spans-1, du=3, sv=1, dv=1, tol=0.01, fr=0, dir=2, ch=False + su=self.spans - 1, du=3, sv=1, dv=1, tol=0.01, fr=0, dir=2, ch=False ) self.buildRibbonControls(ribbon=ribbon, allFollicles=folGrp) cmds.delete(targets) cmds.delete(self.upVector) - def buildRibbonControls(self, ribbon, allFollicles): - ''' - Make a meta and local ribbon, one that is bound to the skeleton, and another bound to the meta. - ''' + """ + Make a meta and local ribbon, one that is bound to the skeleton, and another bound to the meta. + """ name = f"{self.side}_{self.label}" # Create Meta ribbon - metaRibbon = cmds.duplicate(ribbon, - n=f"{self.side}_{self.label}_Meta_rbn", - rc=True)[0] + metaRibbon = cmds.duplicate( + ribbon, + n=f"{self.side}_{self.label}_Meta_rbn", + rc=True + )[0] shape = cmds.listRelatives(metaRibbon, c=True, s=True)[0] # cmds.rename(shape, "{}_{}_{}Shape_rbn".format(self.name.side, self.name.label, self.proxies["Nurbs"].name)) @@ -204,10 +205,10 @@ def buildRibbonControls(self, ribbon, allFollicles): param = 1 param += paramInfl - mFollicles.append([fol, folShape]) + mFollicles.append([fol, folShape]) # Build Joints and controls - + # cmds.xform(jnt, ws=True, t=cmds.xform( # fol, q=True, ws=True, t=True # )) @@ -270,7 +271,7 @@ def buildRibbonControls(self, ribbon, allFollicles): param = 1 param += paramInfl - rFollicles.append([fol, folShape]) + rFollicles.append([fol, folShape]) # Joints and controls # grp = cmds.createNode("transform", n=f"{self.side}_{self.label}_{i}_Region_grp") diff --git a/rigsys/modules/utility/__init__.py b/rigsys/modules/utility/__init__.py index 12483a3..235f359 100644 --- a/rigsys/modules/utility/__init__.py +++ b/rigsys/modules/utility/__init__.py @@ -1,36 +1,15 @@ -"""Utility modules. - -The following code dynamically imports all subclasses of UtilityModuleBase present in this directory. That way, you can -import any module in this directory and it will automatically be available in the rigging system. -""" - -from os.path import dirname, basename, isfile, join -import glob -import importlib -import inspect - -# This is the only line that needs to be changed per __init__.py file. Make sure to keep "as baseModule" at the end -from .utilityBase import UtilityModuleBase as baseModule - -# Import all modules in the current directory -modules = glob.glob(join(dirname(__file__), "*.py")) -__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] -for module in __all__: - importlib.import_module('.' + module, package=str(__name__)) - -# Get all the classes that inherit from baseModule -classes = {str(baseModule.__name__): baseModule} -for cls in baseModule.__subclasses__(): - classes[cls.__name__] = cls - for subClass in cls.__subclasses__(): - classes[subClass.__name__] = subClass - -# Import all the classes that inherit from baseModule -for cls in classes.values(): - classFilePath = inspect.getfile(cls) - importStatement = f"from .{basename(classFilePath)[:-3]} import {cls.__name__}" - exec(importStatement) - -__all__ = list(classes.keys()) - -moduleTypes = classes.copy() +"""Utility modules.""" + +from .utilityBase import UtilityModuleBase +from .bindJoints import BindJoints +from .importModel import ImportModel +from .motionModuleParenting import MotionModuleParenting +from .runPythonCode import PythonCode + +__all__ = [ + "UtilityModuleBase", + "BindJoints", + "ImportModel", + "MotionModuleParenting", + "PythonCode", +] diff --git a/rigsys/modules/utility/bindJoints.py b/rigsys/modules/utility/bindJoints.py index d7d76c3..db7a7ae 100644 --- a/rigsys/modules/utility/bindJoints.py +++ b/rigsys/modules/utility/bindJoints.py @@ -6,6 +6,7 @@ logger = logging.getLogger(__name__) + class BindJoints(utilityBase.UtilityModuleBase): """Build bind joints utility module.""" @@ -23,7 +24,7 @@ def run(self) -> None: for module in motionModules: # if not module.isRun: # logger.error(f"Module not run: {module.getFullName()}. Unable to perform parenting.") - # continue + # continue for jnt in module.bindJoints.keys(): bindJoint = cmds.createNode("joint", n=f"{jnt}_bind") @@ -70,7 +71,7 @@ def run(self) -> None: cmds.parent(f"{jnt}_bind", f"{constructedBind}") else: if self.underGroup is not None or self.underGroup != "": - + if cmds.objExists(self.underGroup): for jnt, parJnt in module.bindJoints.items(): diff --git a/rigsys/modules/utility/importModel.py b/rigsys/modules/utility/importModel.py index 5487148..3e002e9 100644 --- a/rigsys/modules/utility/importModel.py +++ b/rigsys/modules/utility/importModel.py @@ -15,7 +15,7 @@ class ImportModel(utilityBase.UtilityModuleBase): """Import model utility module.""" def __init__(self, rig, side: str = "", label: str = "", buildOrder: int = 3000, isMuted: bool = False, - mirror: bool = False, bypassProxiesOnly: bool = True, + mirror: bool = False, bypassProxiesOnly: bool = True, filePath: str = "", underGroup: str = None) -> None: """Initialize the module.""" super().__init__(rig, side, label, buildOrder, isMuted, mirror, bypassProxiesOnly) diff --git a/rigsys/test/testRunner.py b/rigsys/test/testRunner.py index 9507dcb..34fe2c8 100644 --- a/rigsys/test/testRunner.py +++ b/rigsys/test/testRunner.py @@ -1,12 +1,13 @@ """Run all tests in the test folder.""" import logging -import os import pytest import sys import maya.cmds as cmds +from pathlib import Path + from rigsys.utils.unload import unloadPackages, nukePycFiles @@ -43,13 +44,10 @@ def runTests(pattern="test_"): unloadPackages(silent=False, packages=["rigsys"]) nukePycFiles() - testPath = os.path.dirname(__file__) + test_path = Path(__file__).parent + fix_stdout() - try: - pytest.main([testPath, "-k", pattern]) - except Exception: - logger.warning("Error running tests. Trying again with fixed stdout.") - fix_stdout() + pytest.main([test_path, "-k", pattern]) cmds.file(new=True, force=True)