Example #1
0
    def calculateUpVXfo(self, boneXfos, endXfo):
        """Calculates the transform for the UpV control.

        Args:
            boneXfos (list): Bone transforms.
            endXfo (Xfo): Transform for the end of the chain.

        Returns:
            Xfo: Up Vector transform.

        """

        # Calculate FW
        toFirst = boneXfos[1].tr.subtract(boneXfos[0].tr).unit()
        toTip = endXfo.tr.subtract(boneXfos[0].tr).unit()
        fw = toTip.cross(toFirst).unit()

        chainNormal = fw.cross(toTip).unit()
        chainZAxis = toTip.cross(chainNormal).unit()

        chainXfo = Xfo()
        chainXfo.setFromVectors(toTip.unit(), chainNormal, chainZAxis,
                                boneXfos[0].tr)

        rootToTip = endXfo.tr.subtract(boneXfos[0].tr).length()

        upVXfo = Xfo()
        upVXfo.tr = chainXfo.transformVector(
            Vec3(rootToTip / 2.0, rootToTip / 2.0, 0.0))

        return upVXfo
Example #2
0
    def computeOffset(self):
        """Invokes the constraint and computes the offset

        Returns:
            xfo: The offset to be used for the constraint.

        """

        if self._constrainee is None:
            return Xfo()
        if len(self._constrainers) == 0:
            return Xfo()
        if not self.getMaintainOffset():
            return Xfo()

        cls = self.__class__.__name__
        ks.loadExtension('KrakenForCanvas')
        rtVal = ks.rtVal('KrakenForCanvas::Kraken%s' % cls)

        rtVal.offset = ks.rtVal('Mat44', Mat44())
        for c in self._constrainers:
            rtVal.addConstrainer('',
                                 ks.rtVal('Xfo', c.globalXfo).toMat44('Mat44'))

        return Xfo(
            rtVal.computeOffset(
                "Xfo",
                ks.rtVal('Xfo', self._constrainee.xfo).toMat44('Mat44')))
Example #3
0
    def __init__(self, name='limb', parent=None, *args, **kwargs):

        Profiler.getInstance().push("Construct StretchyLimb Guide Component:" +
                                    name)
        super(StretchyLimbComponentGuide,
              self).__init__(name, parent, *args, **kwargs)

        # =========
        # Controls
        # ========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        # Guide Controls
        self.upperCtl = Control('upper',
                                parent=self.ctrlCmpGrp,
                                shape="sphere")
        self.lowerCtl = Control('lower',
                                parent=self.ctrlCmpGrp,
                                shape="sphere")
        self.endCtl = Control('end', parent=self.ctrlCmpGrp, shape="sphere")

        self.default_data = {
            "name": name,
            "location": "L",
            "upperXfo": Xfo(Vec3(0.9811, 9.769, -0.4572)),
            "lowerXfo": Xfo(Vec3(1.4488, 5.4418, -0.5348)),
            "endXfo": Xfo(Vec3(1.841, 1.1516, -1.237))
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
Example #4
0
    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(ArmComponentGuide, self).getRigBuildData()

        # values
        bicepPosition = self.bicepCtrl.xfo.tr
        forearmPosition = self.forearmCtrl.xfo.tr
        wristPosition = self.wristCtrl.xfo.tr

        # Calculate Bicep Xfo
        rootToWrist = wristPosition.subtract(bicepPosition).unit()
        rootToElbow = forearmPosition.subtract(bicepPosition).unit()

        bone1Normal = rootToWrist.cross(rootToElbow).unit()
        bone1ZAxis = rootToElbow.cross(bone1Normal).unit()

        bicepXfo = Xfo()
        bicepXfo.setFromVectors(rootToElbow, bone1Normal, bone1ZAxis,
                                bicepPosition)

        # Calculate Forearm Xfo
        elbowToWrist = wristPosition.subtract(forearmPosition).unit()
        elbowToRoot = bicepPosition.subtract(forearmPosition).unit()
        bone2Normal = elbowToRoot.cross(elbowToWrist).unit()
        bone2ZAxis = elbowToWrist.cross(bone2Normal).unit()
        forearmXfo = Xfo()
        forearmXfo.setFromVectors(elbowToWrist, bone2Normal, bone2ZAxis,
                                  forearmPosition)

        handXfo = Xfo()
        handXfo.tr = self.handCtrl.xfo.tr
        handXfo.ori = self.handCtrl.xfo.ori

        bicepLen = bicepPosition.subtract(forearmPosition).length()
        forearmLen = forearmPosition.subtract(wristPosition).length()

        armEndXfo = Xfo()
        armEndXfo.tr = wristPosition
        armEndXfo.ori = forearmXfo.ori

        upVXfo = xfoFromDirAndUpV(bicepPosition, wristPosition,
                                  forearmPosition)
        upVXfo.tr = forearmPosition
        upVXfo.tr = upVXfo.transformVector(Vec3(0, 0, 5))

        data['bicepXfo'] = bicepXfo
        data['forearmXfo'] = forearmXfo
        data['handXfo'] = handXfo
        data['armEndXfo'] = armEndXfo
        data['upVXfo'] = upVXfo
        data['forearmLen'] = forearmLen
        data['bicepLen'] = bicepLen

        return data
Example #5
0
    def __init__(self, name='leg', parent=None, data=None):

        Profiler.getInstance().push("Construct Leg Guide Component:" + name)
        super(LegComponentGuide, self).__init__(name, parent)


        # =========
        # Controls
        # ========

        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        # Guide Controls
        self.femurCtrl = Control('femur', parent=self.ctrlCmpGrp, shape="sphere")
        self.kneeCtrl = Control('knee', parent=self.ctrlCmpGrp, shape="sphere")
        self.ankleCtrl = Control('ankle', parent=self.ctrlCmpGrp, shape="sphere")
        self.toeCtrl = Control('toe', parent=self.ctrlCmpGrp, shape="sphere")
        self.toeTipCtrl = Control('toeTip', parent=self.ctrlCmpGrp, shape="sphere")

        if data is None:
            data = {
                    "name": name,
                    "location": "L",
                    "femurXfo": Xfo(Vec3(0.9811, 9.769, -0.4572)),
                    "kneeXfo": Xfo(Vec3(1.4488, 5.4418, -0.5348)),
                    "ankleXfo": Xfo(Vec3(1.841, 1.1516, -1.237)),
                    "toeXfo": Xfo(Vec3(1.85, 0.4, 0.25)),
                    "toeTipXfo": Xfo(Vec3(1.85, 0.4, 1.5))
                   }

        self.loadData(data)

        Profiler.getInstance().pop()
Example #6
0
    def __init__(self, name='clavicle', parent=None, data=None):

        Profiler.getInstance().push("Construct Clavicle Guide Component:" +
                                    name)
        super(ClavicleComponentGuide, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Guide Controls
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.clavicleCtrl = Control('clavicle',
                                    parent=self.ctrlCmpGrp,
                                    shape="sphere")
        self.clavicleUpVCtrl = Control('clavicleUpV',
                                       parent=self.ctrlCmpGrp,
                                       shape="triangle")
        self.clavicleUpVCtrl.setColor('red')
        self.clavicleEndCtrl = Control('clavicleEnd',
                                       parent=self.ctrlCmpGrp,
                                       shape="sphere")

        if data is None:
            data = {
                "name": name,
                "location": "L",
                "clavicleXfo": Xfo(Vec3(0.1322, 15.403, -0.5723)),
                "clavicleUpVXfo": Xfo(Vec3(0.0, 1.0, 0.0)),
                "clavicleEndXfo": Xfo(Vec3(2.27, 15.295, -0.753))
            }

        self.loadData(data)

        Profiler.getInstance().pop()
Example #7
0
    def __init__(self, name='head', parent=None, *args, **kwargs):

        Profiler.getInstance().push("Construct Head Guide Component:" + name)
        super(HeadComponentGuide, self).__init__(name, parent, *args, **kwargs)

        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        sphereCtrl = Control('sphere', shape='sphere')
        sphereCtrl.scalePoints(Vec3(0.375, 0.375, 0.375))

        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape='square')
        self.headCtrl.rotatePoints(90, 0, 0)
        self.headCtrl.translatePoints(Vec3(0.0, 0.5, 0.0))
        self.headCtrl.scalePoints(Vec3(1.8, 2.0, 2.0))

        self.eyeLeftCtrl = Control('eyeLeft',
                                   parent=self.headCtrl,
                                   shape='arrow_thin')
        self.eyeLeftCtrl.translatePoints(Vec3(0, 0, 0.5))
        self.eyeLeftCtrl.rotatePoints(0, 90, 0)
        self.eyeLeftCtrl.appendCurveData(sphereCtrl.getCurveData())

        self.eyeRightCtrl = Control('eyeRight',
                                    parent=self.headCtrl,
                                    shape='arrow_thin')
        self.eyeRightCtrl.translatePoints(Vec3(0, 0, 0.5))
        self.eyeRightCtrl.rotatePoints(0, 90, 0)
        self.eyeRightCtrl.appendCurveData(sphereCtrl.getCurveData())

        self.jawCtrl = Control('jaw', parent=self.headCtrl, shape='square')
        self.jawCtrl.rotatePoints(90, 0, 0)
        self.jawCtrl.rotatePoints(0, 90, 0)
        self.jawCtrl.translatePoints(Vec3(0.0, -0.5, 0.5))
        self.jawCtrl.scalePoints(Vec3(1.0, 0.8, 1.5))
        self.jawCtrl.setColor('orange')

        eyeXAlignOri = Quat()
        eyeXAlignOri.setFromAxisAndAngle(Vec3(0, 1, 0), Math_degToRad(-90))

        self.default_data = {
            "name": name,
            "location": "M",
            "headXfo": Xfo(Vec3(0.0, 17.5, -0.5)),
            "headCrvData": self.headCtrl.getCurveData(),
            "eyeLeftXfo": Xfo(tr=Vec3(0.375, 18.5, 0.5), ori=eyeXAlignOri),
            "eyeLeftCrvData": self.eyeLeftCtrl.getCurveData(),
            "eyeRightXfo": Xfo(tr=Vec3(-0.375, 18.5, 0.5), ori=eyeXAlignOri),
            "eyeRightCrvData": self.eyeRightCtrl.getCurveData(),
            "jawXfo": Xfo(Vec3(0.0, 17.875, -0.275)),
            "jawCrvData": self.jawCtrl.getCurveData()
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
Example #8
0
    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(StretchyLimbComponentGuide, self).getRigBuildData()

        # Values
        startPos = self.upperCtl.xfo.tr
        midPos = self.lowerCtl.xfo.tr
        endPos = self.endCtl.xfo.tr

        # Calculate Upper Xfo
        startToEnd = endPos.subtract(startPos).unit()
        startToMid = midPos.subtract(startPos).unit()

        bone1Normal = startToEnd.cross(startToMid).unit()
        bone1ZAxis = startToMid.cross(bone1Normal).unit()

        upperXfo = Xfo()
        upperXfo.setFromVectors(startToMid, bone1Normal, bone1ZAxis, startPos)

        # Calculate Lower Xfo
        midToEnd = endPos.subtract(midPos).unit()
        midToStart = startPos.subtract(midPos).unit()
        bone2Normal = midToStart.cross(midToEnd).unit()
        bone2ZAxis = midToEnd.cross(bone2Normal).unit()

        lowerXfo = Xfo()
        lowerXfo.setFromVectors(midToEnd, bone2Normal, bone2ZAxis, midPos)

        upperLen = startPos.subtract(midPos).length()
        lowerLen = endPos.subtract(midPos).length()

        handleXfo = Xfo()
        handleXfo.tr = endPos

        endXfo = Xfo()
        endXfo.tr = endPos
        # endXfo.ori = lowerXfo.ori

        upVXfo = xfoFromDirAndUpV(startPos, endPos, midPos)
        upVXfo.tr = midPos
        upVXfo.tr = upVXfo.transformVector(Vec3(0, 0, 5))

        data['upperXfo'] = upperXfo
        data['lowerXfo'] = lowerXfo
        data['endXfo'] = endXfo
        data['handleXfo'] = handleXfo
        data['upVXfo'] = upVXfo
        data['upperLen'] = upperLen
        data['lowerLen'] = lowerLen

        return data
Example #9
0
    def __init__(self, name='leg', parent=None, *args, **kwargs):

        Profiler.getInstance().push("Construct Leg Guide Component:" + name)
        super(LegComponentGuide, self).__init__(name, parent, *args, **kwargs)

        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        # Guide Controls
        self.femurCtrl = Control('femur',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")
        self.kneeCtrl = Control('knee', parent=self.ctrlCmpGrp, shape="sphere")
        self.ankleCtrl = Control('ankle',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")

        armGuideSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings",
                                                 parent=self.femurCtrl)
        self.armGuideDebugAttr = BoolAttribute('drawDebug',
                                               value=True,
                                               parent=armGuideSettingsAttrGrp)

        self.guideOpHost = Transform('guideOpHost', self.ctrlCmpGrp)

        # Guide Operator
        self.legGuideKLOp = KLOperator('guide', 'TwoBoneIKGuideSolver',
                                       'Kraken')
        self.addOperator(self.legGuideKLOp)

        # Add Att Inputs
        self.legGuideKLOp.setInput('drawDebug', self.armGuideDebugAttr)
        self.legGuideKLOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Source Inputs
        self.legGuideKLOp.setInput('root', self.femurCtrl)
        self.legGuideKLOp.setInput('mid', self.kneeCtrl)
        self.legGuideKLOp.setInput('end', self.ankleCtrl)

        # Add Target Outputs
        self.legGuideKLOp.setOutput('guideOpHost', self.guideOpHost)

        self.default_data = {
            "name": name,
            "location": "L",
            "createIKHandle": False,
            "femurXfo": Xfo(Vec3(1.0, 9.75, -0.5)),
            "kneeXfo": Xfo(Vec3(1.5, 5.5, -0.5)),
            "ankleXfo": Xfo(Vec3(1.75, 1.15, -1.25))
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
Example #10
0
    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(LegComponentGuide, self).getRigBuildData()

        # Values
        femurPosition = self.femurCtrl.xfo.tr
        kneePosition = self.kneeCtrl.xfo.tr
        anklePosition = self.ankleCtrl.xfo.tr

        # Calculate Bicep Xfo
        rootToWrist = anklePosition.subtract(femurPosition).unit()
        rootToKnee = kneePosition.subtract(femurPosition).unit()

        bone1Normal = rootToWrist.cross(rootToKnee).unit()
        bone1ZAxis = rootToKnee.cross(bone1Normal).unit()

        femurXfo = Xfo()
        femurXfo.setFromVectors(rootToKnee, bone1Normal, bone1ZAxis,
                                femurPosition)

        # Calculate Forearm Xfo
        elbowToWrist = anklePosition.subtract(kneePosition).unit()
        elbowToRoot = femurPosition.subtract(kneePosition).unit()
        bone2Normal = elbowToRoot.cross(elbowToWrist).unit()
        bone2ZAxis = elbowToWrist.cross(bone2Normal).unit()

        kneeXfo = Xfo()
        kneeXfo.setFromVectors(elbowToWrist, bone2Normal, bone2ZAxis,
                               kneePosition)

        femurLen = femurPosition.subtract(kneePosition).length()
        shinLen = kneePosition.subtract(anklePosition).length()

        handleXfo = Xfo()
        handleXfo.tr = anklePosition

        upVXfo = xfoFromDirAndUpV(femurPosition, anklePosition, kneePosition)
        upVXfo.tr = kneePosition
        upVXfo.tr = upVXfo.transformVector(Vec3(0, 0, 5))

        data['femurXfo'] = femurXfo
        data['kneeXfo'] = kneeXfo
        data['handleXfo'] = handleXfo
        data['upVXfo'] = upVXfo
        data['femurLen'] = femurLen
        data['shinLen'] = shinLen

        return data
Example #11
0
    def __init__(self, name, parent=None, flags=None, metaData=None):
        super(Object3D, self).__init__(name, parent=parent, metaData=metaData)
        self._children = []
        self._flags = {}
        self._attributeGroups = []
        self._constraints = []
        self._xfo = Xfo()
        self._ro = RotationOrder()
        self._color = None

        self._implicitAttrGrp = AttributeGroup("implicitAttrGrp", self)
        self._visibility = BoolAttribute('visibility', True,
                                         self._implicitAttrGrp)

        self._shapeVisibility = BoolAttribute('ShapeVisibility', True,
                                              self._implicitAttrGrp)

        if parent is not None:
            parent.addChild(self)

        if flags is not None:
            assert type(
                flags
            ) is str, "Flags argument must be a comma separated string."

            for flag in flags.replace(' ', '').split(','):
                if not re.match("[\w]*$", flag):
                    msg = "{} '{}' {} ({}: {}) {}\n".format(
                        "Invalid flag", flag, "set on", self.getName(),
                        self.getPath(), ". Alphanumeric and underscores only!")
                    logger.warn(msg)
                    continue

                self.setFlag(flag)
Example #12
0
    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig.

        Return:
        The JSON rig data object.

        """

        data = super(NeckComponentGuide, self).getRigBuildData()

        # values
        neckEndPosition = self.neckCtrl.xfo.tr
        neckPosition = self.neckEndCtrl.xfo.tr
        neckUpV = Vec3(0.0, 0.0, -1.0)

        # Calculate Neck Xfo
        rootToEnd = neckEndPosition.subtract(neckPosition).unit()
        rootToUpV = neckUpV.subtract(neckPosition).unit()
        bone1ZAxis = rootToUpV.cross(rootToEnd).unit()
        bone1Normal = bone1ZAxis.cross(rootToEnd).unit()

        neckXfo = Xfo()
        neckXfo.setFromVectors(rootToEnd, bone1Normal, bone1ZAxis, neckPosition)

        data['neckXfo'] = neckXfo

        return data
Example #13
0
    def __init__(self, name='head', parent=None):

        Profiler.getInstance().push("Construct Head Guide Component:" + name)
        super(FabriceHeadGuide, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape="circle")
        self.headCtrl.rotatePoints(90.0, 0.0, 0.0)
        self.headCtrl.scalePoints(Vec3(3.5, 3.5, 3.5))

        self.jawCtrl = Control('jaw', parent=self.ctrlCmpGrp, shape="cube")
        self.jawCtrl.alignOnZAxis()
        self.jawCtrl.scalePoints(Vec3(2.0, 0.5, 2.0))
        self.jawCtrl.alignOnYAxis(negative=True)
        self.jawCtrl.setColor('orange')

        data = {
            "name": name,
            "location": "M",
            "headXfo": Xfo(Vec3(0.0, 1.67, 1.75)),
            "headCtrlCrvData": self.headCtrl.getCurveData(),
            "jawPosition": Vec3(0.0, 1.2787, 2.0078),
            "jawCtrlCrvData": self.jawCtrl.getCurveData(),
        }

        self.loadData(data)

        Profiler.getInstance().pop()
Example #14
0
    def compute(self):
        """invokes the constraint and returns the resulting transform

        Returns:
            xfo: The result of the constraint in global space.

        """

        if self._constrainee is None:
            return None
        if len(self._constrainers) == 0:
            return None
        if self.getMaintainOffset():
            return self._constrainee.xfo

        cls = self.__class__.__name__
        ks.loadExtension('KrakenForCanvas')
        rtVal = ks.rtVal('KrakenForCanvas::Kraken%s' % cls)

        for c in self._constrainers:
            rtVal.addConstrainer('',
                                 ks.rtVal('Xfo', c.globalXfo).toMat44('Mat44'))

        # Using globalXfo here would cause a recursion
        return Xfo(
            rtVal.compute(
                "Xfo",
                ks.rtVal('Xfo', self._constrainee.xfo).toMat44('Mat44')))
Example #15
0
    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(FKChainComponentGuide, self).getRigBuildData()

        numJoints = self.numJoints.getValue()

        # Calculate Xfos
        fw = Vec3(0, 0, 1)
        boneXfos = []
        boneLengths = []

        for i in xrange(numJoints):
            boneVec = self.jointCtrls[i + 1].xfo.tr.subtract(
                self.jointCtrls[i].xfo.tr)
            boneLengths.append(boneVec.length())
            bone1Normal = fw.cross(boneVec).unit()
            bone1ZAxis = boneVec.cross(bone1Normal).unit()

            xfo = Xfo()
            xfo.setFromVectors(boneVec.unit(), bone1Normal, bone1ZAxis,
                               self.jointCtrls[i].xfo.tr)

            boneXfos.append(xfo)

        data['boneXfos'] = boneXfos
        data['endXfo'] = self.jointCtrls[-1].xfo
        data['boneLengths'] = boneLengths

        return data
Example #16
0
    def addFinger(self, name, data):

        fingerCtrls = []
        fingerJoints = []

        parentCtrl = self.handCtrl
        for i, joint in enumerate(data):
            if i == 0:
                jointName = name + 'Meta'
            else:
                jointName = name + str(i).zfill(2)

            jointXfo = joint.get('xfo', Xfo())
            jointCrvData = joint.get('curveData')

            # Create Controls
            newJointCtrlSpace = CtrlSpace(jointName, parent=parentCtrl)
            newJointCtrl = Control(jointName,
                                   parent=newJointCtrlSpace,
                                   shape='square')
            newJointCtrl.lockScale(True, True, True)
            newJointCtrl.lockTranslation(True, True, True)

            if jointCrvData is not None:
                newJointCtrl.setCurveData(jointCrvData)

            fingerCtrls.append(newJointCtrl)

            # Create Deformers
            jointDef = Joint(jointName, parent=self.defCmpGrp)
            fingerJoints.append(jointDef)

            # Create Constraints

            # Set Xfos
            newJointCtrlSpace.xfo = jointXfo
            newJointCtrl.xfo = jointXfo

            parentCtrl = newJointCtrl

        # =================
        # Create Operators
        # =================
        # Add Deformer KL Op
        deformersToCtrlsKLOp = KLOperator(name + 'DeformerKLOp',
                                          'MultiPoseConstraintSolver',
                                          'Kraken')
        self.addOperator(deformersToCtrlsKLOp)

        # Add Att Inputs
        deformersToCtrlsKLOp.setInput('drawDebug', self.drawDebugInputAttr)
        deformersToCtrlsKLOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        deformersToCtrlsKLOp.setInput('constrainers', fingerCtrls)

        # Add Xfo Outputs
        deformersToCtrlsKLOp.setOutput('constrainees', fingerJoints)

        return deformersToCtrlsKLOp
Example #17
0
    def generateGuideXfos(self, numSprings):
        """Generates the positions for the guide controls based on the number
        of joints.

        Args:
            numSprings (int): Number of joints to generate a transform for.

        Returns:
            list: Guide control positions.

        """

        guideXfos = []
        j = 0
        for i in xrange(numSprings):
            springXfo = Xfo()
            springXfo.tr.x = i % 5 * 2
            springXfo.tr.z = j * 2

            if i % 5 == 4:
                j += 1

            guideXfos.append(springXfo)

        return guideXfos
Example #18
0
    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(ClavicleComponentGuide, self).getRigBuildData()

        # Values
        claviclePosition = self.clavicleCtrl.xfo.tr
        clavicleUpV = self.clavicleUpVCtrl.xfo.tr
        clavicleEndPosition = self.clavicleEndCtrl.xfo.tr

        # Calculate Clavicle Xfo
        rootToEnd = clavicleEndPosition.subtract(claviclePosition).unit()
        rootToUpV = clavicleUpV.subtract(claviclePosition).unit()
        bone1ZAxis = rootToUpV.cross(rootToEnd).unit()
        bone1Normal = bone1ZAxis.cross(rootToEnd).unit()

        clavicleXfo = Xfo()
        clavicleXfo.setFromVectors(rootToEnd, bone1Normal, bone1ZAxis,
                                   claviclePosition)

        clavicleLen = claviclePosition.subtract(clavicleEndPosition).length()

        data['clavicleXfo'] = clavicleXfo
        data['clavicleLen'] = clavicleLen

        return data
Example #19
0
def __mirrorData(jsonData, plane):

    if isinstance(jsonData, Vec3):
        return jsonData

    if isinstance(jsonData, Quat):
        newQuat = Quat(jsonData)
        newQuat.mirror(plane)
        return newQuat

    elif isinstance(jsonData, Xfo):
        newXfo = Xfo(jsonData)
        if plane == 0:
            newXfo.tr.x = -newXfo.tr.x
        elif plane == 1:
            newXfo.tr.y = -newXfo.tr.y
        elif plane == 2:
            newXfo.tr.z = -newXfo.tr.z

        newXfo.ori.mirror(plane)
        return newXfo

    elif type(jsonData) is list:
        newList = []
        for item in jsonData:
            newList.append(__mirrorData(item, plane))
        return newList

    elif type(jsonData) is dict:
        newDict = {}
        for key, value in jsonData.iteritems():
            newDict[key] = __mirrorData(value, plane)
        return newDict

    return jsonData
Example #20
0
    def __init__(self, name='clavicle', parent=None):

        Profiler.getInstance().push("Construct Clavicle Guide Component:" + name)
        super(FabriceClavicleGuide, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # Guide Controls
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.clavicleCtrl = Control('clavicle', parent=self.ctrlCmpGrp, shape="cube")
        self.clavicleCtrl.alignOnXAxis()
        self.clavicleCtrl.scalePoints(Vec3(1.0, 0.25, 0.25))

        data = {
                "name": name,
                "location": "L",
                "clavicleXfo": Xfo(Vec3(0.1322, 15.403, -0.5723)),
                'clavicleCtrlCrvData': self.clavicleCtrl.getCurveData()
               }

        self.loadData(data)

        Profiler.getInstance().pop()
Example #21
0
    def placeFingers(self):

        spacing = 0.25
        length = spacing * (len(self.fingers.keys()) - 1)
        mid = length / 2.0
        startOffset = length - mid

        for i, finger in enumerate(self.fingers.keys()):

            parentCtrl = self.handCtrl
            numJoints = self.numJointsAttr.getValue()
            if finger == "thumb":
                numJoints = 3
            for y in xrange(numJoints + 1):
                if y == 1:
                    xOffset = 0.375
                else:
                    xOffset = 0.25

                if y == 0:
                    offsetVec = Vec3(xOffset, 0, startOffset - (i * spacing))
                else:
                    offsetVec = Vec3(xOffset, 0, 0)

                fingerPos = parentCtrl.xfo.transformVector(offsetVec)
                fingerXfo = Xfo(tr=fingerPos, ori=self.handCtrl.xfo.ori)

                self.fingers[finger][y].xfo = fingerXfo
                parentCtrl = self.fingers[finger][y]
Example #22
0
    def __init__(self, name='hand', parent=None, *args, **kwargs):

        Profiler.getInstance().push("Construct Hand Guide Component:" + name)
        super(HandComponentGuide, self).__init__(name, parent, *args, **kwargs)

        # =========
        # Controls
        # =========
        # Guide Controls
        self.guideSettingsAttrGrp = AttributeGroup("GuideSettings",
                                                   parent=self)
        self.digitNamesAttr = StringAttribute(
            'digitNames',
            value="thumb,index,middle,ring,pinky",
            parent=self.guideSettingsAttrGrp)
        self.digitNamesAttr.setValueChangeCallback(self.updateFingers)

        self.numJointsAttr = IntegerAttribute('numJoints',
                                              value=4,
                                              minValue=2,
                                              maxValue=20,
                                              parent=self.guideSettingsAttrGrp)
        self.numJointsAttr.setValueChangeCallback(self.resizeDigits)

        self.fingers = OrderedDict()

        self.handCtrl = Control('hand', parent=self.ctrlCmpGrp, shape="square")
        self.handCtrl.rotatePoints(0.0, 0.0, 90.0)
        self.handCtrl.scalePoints(Vec3(1.0, 0.75, 1.0))
        self.handCtrl.setColor('yellow')

        self.handGuideSettingsAttrGrp = AttributeGroup("Settings",
                                                       parent=self.handCtrl)
        self.ctrlShapeToggle = BoolAttribute(
            'ctrlShape_vis', value=False, parent=self.handGuideSettingsAttrGrp)
        self.handDebugInputAttr = BoolAttribute(
            'drawDebug', value=False, parent=self.handGuideSettingsAttrGrp)

        self.drawDebugInputAttr.connect(self.handDebugInputAttr)

        self.guideCtrlHrcGrp = HierarchyGroup('controlShapes',
                                              parent=self.ctrlCmpGrp)

        self.default_data = {
            "name": name,
            "location": "L",
            "handXfo": Xfo(Vec3(7.1886, 12.2819, 0.4906)),
            "digitNames": self.digitNamesAttr.getValue(),
            "numJoints": self.numJointsAttr.getValue(),
            "fingers": self.fingers
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
Example #23
0
    def getRigBuildData(self):

        data = super(mjEyelidComponentGuide, self).getRigBuildData()

        eyeballPosition = self.eyeballCtrl.xfo.tr
        eyeballOriXfo = Xfo()
        eyeballOriXfo.tr = eyeballPosition
        eyeballOriOffset = Quat(Vec3(0.0, 0.894, 0.0), -0.448)
        if self.getLocation() == "R":
            eyeballOriXfo.ori.subtract(eyeballOriOffset)

        data['eyeballXfo'] = eyeballOriXfo

        eyelidUpVOffset = Vec3(0.0, 0.2, 0.0)
        eyelidUpVXfo = Xfo()
        eyelidUpVXfo.tr = eyeballPosition.add(eyelidUpVOffset)

        data['eyelidUpVXfo'] = eyelidUpVXfo

        data['lidMedialXfo'] = self.lidMedialCtrl.xfo
        data['lidLateralXfo'] = self.lidLateralCtrl.xfo

        data['lidUpXfo'] = self.lidUpCtrl.xfo
        data['lidUpMedialXfo'] = self.lidUpMedialCtrl.xfo
        data['lidUpLateralXfo'] = self.lidUpLateralCtrl.xfo

        data['lidLowXfo'] = self.lidLowCtrl.xfo
        data['lidLowMedialXfo'] = self.lidLowMedialCtrl.xfo
        data['lidLowLateralXfo'] = self.lidLowLateralCtrl.xfo

        data['numUpDeformers'] = self.numUpDeformersAttr.getValue()
        data['numLowDeformers'] = self.numLowDeformersAttr.getValue()

        data['lidUpMedialBlink'] = self.upMedialFactorAttr.getValue()
        data['lidUpLateralBlink'] = self.upLateralFactorAttr.getValue()

        data['lidLowMedialBlink'] = self.lowMedialFactorAttr.getValue()
        data['lidLowLateralBlink'] = self.lowLateralFactorAttr.getValue()

        return data
Example #24
0
    def __init__(self, name, parent=None):
        super(Object3D, self).__init__(name, parent)
        self._component = None
        self._children = []
        self._flags = {}
        self._attributeGroups = []
        self._constraints = []
        self._xfo = Xfo()
        self._ro = RotationOrder()
        self._color = None
        self._visibility = True
        self._shapeVisibility = True

        if parent is not None:
            parent.addChild(self)
Example #25
0
    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(HandComponentGuide, self).getRigBuildData()

        data['handXfo'] = self.handCtrl.xfo

        fingerData = {}
        for finger in self.fingers.keys():

            fingerData[finger] = []
            for i, joint in enumerate(self.fingers[finger]):
                if i == len(self.fingers[finger]) - 1:
                    continue

                # Calculate Xfo
                boneVec = self.fingers[finger][
                    i + 1].xfo.tr - self.fingers[finger][i].xfo.tr
                bone1Normal = self.fingers[finger][i].xfo.ori.getZaxis().cross(
                    boneVec).unit()
                bone1ZAxis = boneVec.cross(bone1Normal).unit()

                jointXfo = Xfo()
                jointXfo.setFromVectors(boneVec.unit(), bone1Normal,
                                        bone1ZAxis,
                                        self.fingers[finger][i].xfo.tr)

                jointData = {
                    'curveData':
                    self.fingers[finger][i].shapeCtrl.getCurveData(),
                    'length':
                    self.fingers[finger][i].xfo.tr.distanceTo(
                        self.fingers[finger][i + 1].xfo.tr),
                    'xfo':
                    jointXfo
                }

                fingerData[finger].append(jointData)

        data['fingerData'] = fingerData

        return data
Example #26
0
    def generateGuideXfos(self, numJoints):
        """Generates the positions for the guide controls based on the number
        of joints.

        Args:
            numJoints (int): Number of joints to generate a transform for.

        Returns:
            list: Guide control positions.

        """

        guideXfos = []
        for i in xrange(numJoints + 1):
            guideXfos.append(Xfo(tr=Vec3(0, 0, i)))

        return guideXfos
Example #27
0
    def evaluate(self):
        """invokes the constraint causing the output value to be computed.

        Return:
        Boolean, True if successful.

        """

        if self.getMaintainOffset() is False:
            newXfo = Xfo()
            newXfo.ori.set(Vec3(), 0.0)
            for constrainer in self.getConstrainers():
                newXfo.tr = newXfo.tr.add(constrainer.xfo.tr)
                newXfo.ori = newXfo.ori.add(constrainer.xfo.ori)

            newXfo.ori.setUnit()
            self.getConstrainee().xfo = newXfo

        return True
Example #28
0
    def __init__(self, name, parent=None):
        super(Object3D, self).__init__(name, parent)
        self._children = []
        self._flags = {}
        self._attributeGroups = []
        self._constraints = []
        self._xfo = Xfo()
        self._ro = RotationOrder()
        self._color = None

        self._implicitAttrGrp = AttributeGroup("implicitAttrGrp", self)
        self._visibility = BoolAttribute('visibility', True,
                                         self._implicitAttrGrp)

        self._shapeVisibility = BoolAttribute('ShapeVisibility', True,
                                              self._implicitAttrGrp)

        if parent is not None:
            parent.addChild(self)
Example #29
0
    def updateNumJointControls(self, numJoints):
        """Load a saved guide representation from persisted data.

        Arguments:
        numJoints -- object, The number of joints inthe chain.

        Return:
        True if successful.

        """

        if numJoints == 0:
            raise IndexError("'numJoints' must be > 0")

        if numJoints + 1 > len(self.jointCtrls):
            for i in xrange(len(self.jointCtrls), numJoints + 1):
                if i == 0:
                    ctrlParent = self.ctrlCmpGrp
                else:
                    ctrlParent = self.jointCtrls[i - 1]

                newCtrl = Control('chain' + str(i + 1).zfill(2),
                                  parent=ctrlParent,
                                  shape="sphere")
                newCtrl.scalePoints(Vec3(0.25, 0.25, 0.25))
                # Generate thew new ctrl off the end of the existing one.
                newCtrl.xfo = self.jointCtrls[i - 1].xfo.multiply(
                    Xfo(Vec3(10.0, 0.0, 0.0)))
                self.jointCtrls.append(newCtrl)

        elif numJoints + 1 < len(self.jointCtrls):
            numExtraCtrls = len(self.jointCtrls) - (numJoints + 1)
            for i in xrange(numExtraCtrls):
                extraCtrl = self.jointCtrls.pop()
                extraCtrl.getParent().removeChild(extraCtrl)

        # Reset the control positions based on new number of joints
        jointPositions = self.generateGuidePositions(numJoints)
        for i in xrange(len(self.jointCtrls)):
            self.jointCtrls[i].xfo.tr = jointPositions[i]

        return True
Example #30
0
    def __init__(self, name='InsectLeg', parent=None):

        Profiler.getInstance().push("Construct InsectLeg Guide Component:" +
                                    name)
        super(InsectLegComponentGuide, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)
        self.numJoints = IntegerAttribute('numJoints',
                                          value=5,
                                          minValue=2,
                                          maxValue=20,
                                          parent=guideSettingsAttrGrp)
        self.numJoints.setValueChangeCallback(self.updateNumLegControls)

        self.jointCtrls = []

        numJoints = self.numJoints.getValue()
        jointPositions = self.generateGuidePositions(numJoints)

        for i in xrange(numJoints):
            self.jointCtrls.append(
                Control('leg' + str(i + 1).zfill(2),
                        parent=self.ctrlCmpGrp,
                        shape="sphere"))

        jointXfos = []
        for i in xrange(numJoints):
            jointXfos.append(Xfo(jointPositions[i]))

        data = {
            "location": "L",
            "jointPositions": jointXfos,
            "numJoints": self.numJoints.getValue()
        }

        self.loadData(data)

        Profiler.getInstance().pop()