Exemplo n.º 1
0
    def addOperators(self):
        """Create operators and set the relations for the component rig

        Apply operators, constraints, expressions to the hierarchy.
        In order to keep the code clean and easier to debug,
        we shouldn't create any new object in this method.

        """

        # Chain of deformers -------------------------------
        for i, loc in enumerate(self.loc):
            pm.parentConstraint(self.fk_ctl[i], loc, maintainOffset=False)

        # spring operators
        # settings aim contraints
        for i, tranCns in enumerate(self.spring_aim):
            if self.negate:
                aimAxis = "-xy"
            else:
                aimAxis = "xy"
            applyop.aimCns(tranCns, self.spring_target[i], aimAxis, 2,
                           [0, 1, 0], self.fk_npo[i], False)
            ori_cns = applyop.oriCns(tranCns, self.spring_cns[i])

            springOP = applyop.gear_spring_op(self.spring_target[i])

            blend_node = pm.createNode("pairBlend")

            pm.connectAttr(ori_cns.constraintRotate, blend_node.inRotate2)
            pm.connectAttr(self.aSpring_intensity, blend_node.weight)

            pm.disconnectAttr(ori_cns.constraintRotate,
                              self.spring_cns[i].rotate)

            pm.connectAttr(blend_node.outRotateX, self.spring_cns[i].rotateX)
            pm.connectAttr(blend_node.outRotateY, self.spring_cns[i].rotateY)
            pm.connectAttr(blend_node.outRotateZ, self.spring_cns[i].rotateZ)

            pm.connectAttr(self.aSpring_intensity, springOP + ".intensity")
            pm.connectAttr(self.aDamping[i], springOP + ".damping")
            pm.connectAttr(self.aStiffness[i], springOP + ".stiffness")
Exemplo n.º 2
0
    def addOperators(self):

        # Chain of deformers -------------------------------
        for i, loc in enumerate(self.loc):
            pm.parentConstraint(self.fk_ctl[i], loc, maintainOffset=False)

        # spring operators
        #settings aim contraints
        for i, tranCns in enumerate(self.spring_aim):
            if self.negate:
                aimAxis = "-xy"
            else:
                aimAxis = "xy"
            aop.aimCns(tranCns, self.spring_target[i], aimAxis, 2, [0,1,0], self.fk_npo[i], False)
            aop.oriCns(tranCns, self.spring_cns[i])

            springOP = aop.gear_spring_op(self.spring_target[i])

            pm.connectAttr(self.aSpring_intensity, springOP+".intensity")
            pm.connectAttr(self.aDamping[i], springOP+".damping")
            pm.connectAttr(self.aStiffness[i], springOP+".stiffness")
Exemplo n.º 3
0
def postSpring(dist = 5, hostUI = False,  hostUI2 = False, invertX=False ):

    """
    Create the dynamic spring rig. This spring system use the mgear_spring node. And transfer the position spring
    to rotation spring using an aim constraint.

    Note:
        The selected chain of object should be align with the X axis.

    Args:
        dist (float): The distance of the position spring.
        hostUI (dagNode): The spring active and intensity channel host.
        hostUI2 (dagNode): The daping and stiffness channel host for each object in the chain.
        invertX (bool): reverse the direction of the x axis.

    """
    oSel = pm.selected()

    if not hostUI2:
            hostUI2 = oSel[0]

    aSpring_active = att.addAttribute(hostUI2, "spring_active_%s"%oSel[0].name(), "double", 1.0, "___spring_active_______%s"%oSel[0].name(), "spring_active_%s"%oSel[0].name(), 0, 1)
    aSpring_intensity = att.addAttribute(hostUI2, "spring_intensity_%s"%oSel[0].name(), "double", 1.0, "___spring_intensity_______%s"%oSel[0].name(), "spring_intensity_%s"%oSel[0].name(), 0, 1)

    if invertX:
        dist = dist *-1
        #aim constraint
        aimAxis = "-xy"
    else:
        #aim constraint
        aimAxis = "xy"

    for obj in oSel:

        oParent = obj.getParent()



        oNpo = pm.PyNode(pm.createNode("transform", n= obj.name() + "_npo", p=oParent, ss=True))
        oNpo.setTransformation(obj.getMatrix())
        pm.parent(obj, oNpo)

        oSpring_cns = pm.PyNode(pm.createNode("transform", n= obj.name() + "_spr_cns", p=oNpo, ss=True))
        oSpring_cns.setTransformation(obj.getMatrix())
        pm.parent(obj, oSpring_cns)


        oSpringLvl = pm.PyNode(pm.createNode("transform", n= obj.name() + "_spr_lvl", p=oNpo, ss=True))
        oM = obj.getTransformation()
        oM.addTranslation([dist, 0,0], "object")
        oSpringLvl.setTransformation(oM.asMatrix())

        oSpringDriver = pm.PyNode(pm.createNode("transform", n= obj.name() + "_spr", p=oSpringLvl, ss=True))


        try:
                defSet = pm.PyNode("rig_PLOT_grp")
                pm.sets(defSet, add=oSpring_cns)
        except:
            defSet   =  pm.sets(name="rig_PLOT_grp")
            pm.sets(defSet, remove=obj)
            pm.sets(defSet, add=oSpring_cns)

        #adding attributes:
        if not hostUI:
            hostUI = obj


        aSpring_damping = att.addAttribute(hostUI, "spring_damping_%s"%obj.name(), "double", .5, "damping_%s"%obj.name(), "damping_%s"%obj.name(), 0, 1)
        aSpring_stiffness_ = att.addAttribute(hostUI, "spring_stiffness_%s"%obj.name(), "double", .5, "stiffness_%s"%obj.name(), "stiffness_%s"%obj.name(), 0, 1)




        cns = aop.aimCns(oSpring_cns, oSpringDriver, aimAxis, 2, [0,1,0], oNpo, False)

        #change from fcurves to spring
        pb_node = pm.createNode("pairBlend")

        pm.connectAttr(cns+".constraintRotateX", pb_node+".inRotateX2")
        pm.connectAttr(cns+".constraintRotateY", pb_node+".inRotateY2")
        pm.connectAttr(cns+".constraintRotateZ", pb_node+".inRotateZ2")
        pm.setAttr(pb_node+".translateXMode", 2)
        pm.setAttr(pb_node+".translateYMode", 2)
        pm.setAttr(pb_node+".translateZMode", 2)


        pm.connectAttr( pb_node+".outRotateX", oSpring_cns+".rotateX", f=True)
        pm.connectAttr( pb_node+".outRotateY", oSpring_cns+".rotateY", f=True)
        pm.connectAttr( pb_node+".outRotateZ", oSpring_cns+".rotateZ", f=True)
        pm.setKeyframe( oSpring_cns, at="rotateX")
        pm.setKeyframe( oSpring_cns, at="rotateY")
        pm.setKeyframe( oSpring_cns, at="rotateZ")

        #add sprint op
        springOP = aop.gear_spring_op(oSpringDriver)

        #connecting attributes
        pm.connectAttr(aSpring_active, pb_node+".weight")
        pm.connectAttr(aSpring_intensity, springOP+".intensity")
        pm.connectAttr(aSpring_damping, springOP+".damping")
        pm.connectAttr(aSpring_stiffness_, springOP+".stiffness")