Exemplo n.º 1
0
def getAngle(radius, joint1, joint2):
    segmentLen01 = RMRigTools.RMLenghtOfBone(joint1)

    if joint2:
        segmentLen02 = RMRigTools.RMLenghtOfBone(joint2)
    else:
        segmentLen02 = segmentLen01

    alpha = SegmentAngleInCircle(radius, segmentLen01)
    beta = SegmentAngleInCircle(radius, segmentLen02)
    return 180 - DeltaBetweenAngles(alpha, beta)
Exemplo n.º 2
0
def RMCreateBoxCtrl(Obj,
                    NameConv=None,
                    Xratio=1,
                    Yratio=1,
                    Zratio=1,
                    ParentBaseSize=False,
                    customSize=0,
                    name="",
                    centered=False):
    if not NameConv:
        NameConv = nameConvention.NameConvention()
    if name == "":
        defaultName = "BoxControl"
    else:
        defaultName = name

    Parents = pm.listRelatives(Obj, parent=True)

    if Parents and len(Parents) != 0 and ParentBaseSize == True:
        JntLength = RMRigTools.RMLenghtOfBone(Parents[0])
        Ctrl = RMCreateCubeLine(JntLength * Xratio,
                                JntLength * Yratio,
                                JntLength * Zratio,
                                name=defaultName,
                                centered=centered)
    else:
        if customSize != 0:
            JntLength = customSize

        elif pm.objectType(Obj) == "joint":
            JntLength = RMRigTools.RMLenghtOfBone(Obj)

        else:
            JntLength = 1
        Ctrl = RMCreateCubeLine(JntLength * Xratio,
                                JntLength * Yratio,
                                JntLength * Zratio,
                                name=defaultName,
                                centered=centered)

    if name == '' and NameConv.is_name_in_format(Obj):
        NameConv.rename_based_on_base_name(Obj, Ctrl)
    else:
        NameConv.rename_based_on_base_name(Obj, Ctrl, name=Ctrl)

    NameConv.rename_set_from_name(Ctrl, "control", "objectType")

    RMRigTools.RMAlign(Obj, Ctrl, 3)

    ResetGroup = RMRigTools.RMCreateGroupOnObj(Ctrl)
    return ResetGroup, Ctrl
Exemplo n.º 3
0
 def RMCreateHeadRig(self):
     headSize = RMRigTools.RMLenghtOfBone(self.HeadJoints[0])
     print '%s %s' % (self.rootHeadJoints, self.rootHeadJoints.__class__)
     resetHeadControl, headControl = RMRigShapeControls.RMImportMoveControl(
         self.rootHeadJoints, scale=headSize, name="head", Type="head")
     pm.parentConstraint(headControl, self.HeadJoints[0])
     return resetHeadControl, headControl
Exemplo n.º 4
0
    def RMCreateSpineIKSystem(self):

        self.spineIK, effector, self.spineCurve = pm.ikHandle(
            startJoint=self.spineJoints[0],
            endEffector=self.spineJoints[len(self.spineJoints) - 1],
            createCurve=True,
            numSpans=len(self.spineJoints),
            solver="ikSplineSolver",
            name="spineIK")

        self.NameConv.rename_based_on_base_name(
            self.spineJoints[len(self.spineJoints) - 1], self.spineIK)
        self.NameConv.rename_based_on_base_name(
            self.spineJoints[len(self.spineJoints) - 1],
            effector,
            name="spineIKEffector")
        self.NameConv.rename_based_on_base_name(
            self.spineJoints[len(self.spineJoints) - 1],
            self.spineCurve,
            name="spineIKCurve")

        Clusters = RMRigTools.RMCreateClustersOnCurve(self.spineCurve)
        ClustersGroup = RMRigTools.RMCreateGroupOnObj(Clusters[0])
        RMRigTools.RMParentArray(ClustersGroup, Clusters[1:])
        self.kinematics.append(ClustersGroup)
        self.kinematics.append(self.spineIK)

        #ResetCOG, COG = RMRigShapeControls.create_box_ctrl(self.spineJoints[0],Yratio=3,Zratio=3)
        ResetCOG, COG = RMRigShapeControls.RMImportMoveControl(
            self.spineJoints[0],
            scale=RMRigTools.RMLenghtOfBone(self.spineJoints[0]) * 7)

        self.NameConv.rename_set_from_name(COG, "COG", "name")

        ResetChest, Chest = RMRigShapeControls.RMCreateBoxCtrl(
            self.spineJoints[len(self.spineJoints) - 1], Yratio=3, Zratio=3)
        self.NameConv.rename_set_from_name(Chest, "Chest", "name")

        SpineLength = RMRigTools.RMPointDistance(COG, Chest)

        ResetChestRotation, ChestRotation = RMRigShapeControls.RMCircularControl(
            Chest, radius=SpineLength, name="ChestRotation")

        pm.parent(ResetChestRotation, Chest)

        pm.parentConstraint(ChestRotation, self.chestJoint, mo=True)

        self.ResetChestRotationControl = ResetChestRotation
        self.ChestRotationControl = ChestRotation

        #pm.parent(ResetChest,COG)

        pm.setAttr(self.spineIK + ".dTwistControlEnable", 1)
        pm.setAttr(self.spineIK + ".dWorldUpType", 4)
        #pm.setAttr(self.spineIK + ".dForwardAxis",0)#Valid Option only in Maya 2016
        pm.setAttr(self.spineIK + ".dWorldUpAxis", 0)
        pm.connectAttr(COG + ".worldMatrix[0]",
                       self.spineIK + ".dWorldUpMatrix")
        pm.connectAttr(Chest + ".worldMatrix[0]",
                       self.spineIK + ".dWorldUpMatrixEnd")

        locators = RMRigTools.RMCreateNLocatorsBetweenObjects(COG,
                                                              Chest,
                                                              3,
                                                              align="FirstObj")

        ChestControls = []
        ChestGroups = []
        AllSpine = [COG]
        spineControlGroup = pm.group(empty=True, name="SpineControls")
        self.NameConv.rename_name_in_format(spineControlGroup,
                                            name=spineControlGroup)

        self.secondaryControls
        for eachPosition in locators:
            ControlGroup, NewControl = RMRigShapeControls.RMImportMoveControl(
                eachPosition, scale=SpineLength)
            self.secondaryControls.append(NewControl)
            ChestGroups.append(ControlGroup)
            ChestControls.append(NewControl)
            AllSpine.append(NewControl)
            ResetTransformGroup = RMRigTools.RMCreateGroupOnObj(ControlGroup)
            print ResetTransformGroup
            print spineControlGroup
            pm.parent(ResetTransformGroup, spineControlGroup)
            pm.delete(eachPosition)
            RMRigTools.RMLockAndHideAttributes(NewControl, "111000000h")

        AllSpine.append(Chest)

        pm.parent(spineControlGroup, COG)

        ChestChildGroup = RMRigTools.RMCreateGroupOnObj(Chest,
                                                        Type="child",
                                                        NameConv=self.NameConv)
        pm.xform(ChestChildGroup,
                 t=[-SpineLength / 2, 0, 0],
                 os=True,
                 relative=True)
        spineEnds = [COG, ChestChildGroup]

        self.RMRedistributeConstraint(AllSpine,
                                      Clusters,
                                      3,
                                      ConstraintType="parent")
        self.RMRedistributeConstraint(spineEnds,
                                      ChestGroups,
                                      3,
                                      ConstraintType="parent")

        DeformedShape, OrigShape = pm.listRelatives(self.spineCurve,
                                                    children=True,
                                                    shapes=True)
        curveInfoOriginal = pm.shadingNode('curveInfo',
                                           asUtility=True,
                                           name="SpineCurveOriginalInfo")
        curveInfoDeformed = pm.shadingNode('curveInfo',
                                           asUtility=True,
                                           name="SpineCurveDeformedInfo")
        self.NameConv.rename_name_in_format(curveInfoOriginal,
                                            name=curveInfoOriginal)
        self.NameConv.rename_name_in_format(curveInfoDeformed,
                                            name=curveInfoDeformed)

        pm.connectAttr(OrigShape + ".worldSpace[0]",
                       curveInfoOriginal + ".inputCurve")
        pm.connectAttr(DeformedShape + ".worldSpace[0]",
                       curveInfoDeformed + ".inputCurve")
        curveScaleRatio = pm.shadingNode('multiplyDivide',
                                         asUtility=True,
                                         name="SpineScaleRatio")
        self.NameConv.rename_name_in_format(curveScaleRatio,
                                            name=curveScaleRatio)

        pm.connectAttr(curveInfoDeformed + ".arcLength",
                       curveScaleRatio + ".input1X")
        pm.connectAttr(curveInfoOriginal + ".arcLength",
                       curveScaleRatio + ".input2X")
        pm.setAttr(curveScaleRatio + ".operation", 2)

        #preparation for Scale multiplication function of each spine joint
        pm.addAttr(Chest,
                   at="float",
                   sn="ssf",
                   ln="spineSquashFactor",
                   hnv=1,
                   hxv=1,
                   h=0,
                   k=1,
                   smn=-10,
                   smx=10)

        GaussLen = len(self.spineJoints)
        center = len(self.spineJoints) / 2
        powMaxValue = 5
        powRate = powMaxValue / center
        index = 1

        for eachJoint in self.spineJoints[1:]:
            #translate stretch multiplication functions of each spine joint
            SpineStretchMult = pm.shadingNode(
                'multiplyDivide',
                asUtility=True,
                name="SpineTranslateStretchMult" +
                self.NameConv.get_a_short_name(eachJoint))
            self.NameConv.rename_name_in_format(SpineStretchMult,
                                                name=SpineStretchMult)
            CurrentXPosition = pm.getAttr(eachJoint + ".translateX")
            pm.setAttr(SpineStretchMult + ".input2X", CurrentXPosition)
            pm.connectAttr(curveScaleRatio + ".outputX",
                           SpineStretchMult + ".input1X")
            pm.connectAttr(SpineStretchMult + ".outputX",
                           eachJoint + ".translateX")

            #Scale multiplication function of each spine joint

            if index >= center:
                PowValue = (GaussLen - 1 - index)
            else:
                PowValue = index

            SpineStretchRatio = pm.shadingNode(
                'multiplyDivide',
                asUtility=True,
                name="SpineStretchRatio" +
                self.NameConv.get_a_short_name(eachJoint))
            self.NameConv.rename_name_in_format(SpineStretchRatio,
                                                name=SpineStretchRatio)
            pm.connectAttr(Chest + ".spineSquashFactor ",
                           SpineStretchRatio + ".input1X")
            pm.setAttr(SpineStretchRatio + ".input2X", PowValue)
            pm.setAttr(SpineStretchRatio + ".operation", 1)

            SpineScaleStretchPow = pm.shadingNode(
                'multiplyDivide',
                asUtility=True,
                name="SpineScaleStretchPow" +
                self.NameConv.get_a_short_name(eachJoint))
            self.NameConv.rename_name_in_format(SpineScaleStretchPow,
                                                name=SpineScaleStretchPow)
            pm.connectAttr(curveScaleRatio + ".outputX ",
                           SpineScaleStretchPow + ".input1X")
            pm.connectAttr(SpineStretchRatio + ".outputX ",
                           SpineScaleStretchPow + ".input2X")
            pm.setAttr(SpineScaleStretchPow + ".operation", 3)

            SpineInversScaleRatio = pm.shadingNode(
                'multiplyDivide',
                asUtility=True,
                name="SpineInverseScaleRatio")
            self.NameConv.rename_name_in_format(SpineInversScaleRatio,
                                                name=SpineInversScaleRatio)
            pm.connectAttr(SpineScaleStretchPow + ".outputX ",
                           SpineInversScaleRatio + ".input1X")
            pm.setAttr(SpineInversScaleRatio + ".input2X", -1)
            pm.setAttr(SpineInversScaleRatio + ".operation", 3)

            pm.connectAttr(SpineInversScaleRatio + ".outputX",
                           eachJoint + ".scaleY")
            pm.connectAttr(SpineInversScaleRatio + ".outputX",
                           eachJoint + ".scaleZ")
            index += 1

        resetWaist, waist = RMRigShapeControls.RMCircularControl(
            AllSpine[1], radius=SpineLength * .8, name="waist")

        pm.parent(ResetChest, waist)
        pm.parent(resetWaist, COG)

        self.chestControl = Chest
        self.resetChestControl = ResetChest
        self.waistControl = waist
        self.resetWaistControl = resetWaist
        self.COG = COG
        self.ResetCOG = ResetCOG
        self.SpineLength = SpineLength
Exemplo n.º 5
0
    def Visibility(self):
        '''self.Spine = None
        self.LimbArmLeft = None
        self.LimbLegRight = None
        self.LimbLegLeft = None
        self.LimbArmRight = None
        self.LFfeet = None
        self.RHfeet = None
        self.moverMain = None
        self.Mover01 = None
        self.Mover02 = None
        self.placer = None
        self.NeckHead
        self.GHRightRig = None
        self.GHLeftRig = None
        '''
        VisSwitch = RMVisibilitySwitch.RMVisibilitySwitch()

        Vgroup, VControl = RMRigShapeControls.RMImportMoveControl(
            self.NeckHead.HeadJoints[0],
            scale=RMRigTools.RMLenghtOfBone(self.NeckHead.HeadJoints[0]),
            Type="v")
        pm.setAttr("%s.rotateX" % Vgroup, 0)
        pm.setAttr("%s.rotateY" % Vgroup, 0)
        pm.setAttr("%s.rotateZ" % Vgroup, 0)

        RMRigTools.RMAlign(self.NeckHead.HeadJoints[1], Vgroup, 1)

        pm.parentConstraint(self.Mover01, Vgroup, mo=True)
        pm.parent(Vgroup, "controls_grp")

        VisSwitch.ConstraintVisibility([
            self.LimbArmLeft.PoleVectorControl, self.LimbArmLeft.ikControl,
            self.LimbArmLeft.FKFirstLimbControl,
            self.LimbArmLeft.FKSecondLimbControl,
            self.LimbArmLeft.FKTrirdLimbControl,
            self.LimbArmLeft.SpaceSwitchControl,
            self.LimbArmRight.PoleVectorControl, self.LimbArmRight.ikControl,
            self.LimbArmRight.FKFirstLimbControl,
            self.LimbArmRight.FKSecondLimbControl,
            self.LimbArmRight.FKTrirdLimbControl,
            self.LimbArmRight.SpaceSwitchControl,
            self.LimbLegLeft.PoleVectorControl, self.LimbLegLeft.ikControl,
            self.LimbLegLeft.FKFirstLimbControl,
            self.LimbLegLeft.FKSecondLimbControl,
            self.LimbLegLeft.FKTrirdLimbControl,
            self.LimbLegLeft.SpaceSwitchControl,
            self.LimbLegRight.PoleVectorControl, self.LimbLegRight.ikControl,
            self.LimbLegRight.FKFirstLimbControl,
            self.LimbLegRight.FKSecondLimbControl,
            self.LimbLegRight.FKTrirdLimbControl,
            self.LimbLegRight.SpaceSwitchControl,
            self.Spine.rightClavicleControl, self.Spine.leftClavicleControl,
            self.Spine.waistControl, self.Spine.chestControl,
            self.Spine.hipControl, self.Spine.COG,
            self.LFfeet.SecondLimbFeetControl,
            self.RHfeet.SecondLimbFeetControl, self.GHRightRig.MainControl,
            self.GHLeftRig.MainControl
        ],
                                       VControl,
                                       VisibilitySwitch="Controls",
                                       visibilityType="lodVisibility")
        #print self.LFfeet.feetMainMoveIK
        #print self.RHfeet.feetMainMoveIK
        VisSwitch.ConstraintVisibility([
            self.LimbArmLeft.TJArm.TwistControl,
            self.LimbArmLeft.TJElbow.TwistControl,
            self.LimbArmRight.TJArm.TwistControl,
            self.LimbArmRight.TJElbow.TwistControl,
            self.LimbLegLeft.TJArm.TwistControl,
            self.LimbLegLeft.TJElbow.TwistControl,
            self.LimbLegRight.TJArm.TwistControl,
            self.LimbLegRight.TJElbow.TwistControl
        ],
                                       VControl,
                                       VisibilitySwitch="Secondary",
                                       visibilityType="lodVisibility")

        VisSwitch.ConstraintVisibility(["body_grp"],
                                       VControl,
                                       VisibilitySwitch="Geometry")
        VisSwitch.AddAffectedObject(VControl,
                                    self.Spine.secondaryControls,
                                    VisibilitySwitch="Secondary",
                                    visibilityType="lodVisibility")
        VisSwitch.AddAffectedObject(VControl,
                                    self.GHRightRig.fingerControlsReset,
                                    VisibilitySwitch="Controls",
                                    visibilityType="lodVisibility")
        VisSwitch.AddAffectedObject(VControl,
                                    self.GHLeftRig.fingerControlsReset,
                                    VisibilitySwitch="Controls",
                                    visibilityType="lodVisibility")

        RMRigTools.RMLockAndHideAttributes(VControl, "0000000000")
        #VisSwitch.AddEnumParameters( VControl, VisibilitySwitch = "Facial"   )

        pass