Example #1
0
def layer_verify(self, **kws):
    try:
        _str_func = ' layer_verify'.format(self)
        log.debug("|{0}| >> ... [{1}]".format(_str_func, self) + '-' * 80)

        if not self.getMessage('displayLayer'):
            mLayer = cgmMeta.validateObjArg(mc.createDisplayLayer(),
                                            'cgmNode',
                                            setClass=True)

            ATTR.copy_to(self.mNode, 'cgmName', mLayer.mNode, driven='target')
            mLayer.doStore('cgmName', 'main')
            mLayer.doName()
            self.connectChildNode(mLayer.mNode, 'displayLayer')

        if not self.getMessage('controlLayer'):
            mLayer = cgmMeta.validateObjArg(mc.createDisplayLayer(),
                                            'cgmNode',
                                            setClass=True)

            #ATTR.copy_to(self.mNode,'cgmName',mLayer.mNode,driven='target')
            mLayer.doStore('cgmName', 'control')
            mLayer.doName()
            self.connectChildNode(mLayer.mNode, 'controlLayer')

        return self.displayLayer, self.controlLayer
    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err)
Example #2
0
def limbRoot(self):
    try:
        _str_func = 'limbRoot'
        log_start(_str_func)
        ml_fkJoints = self.ml_fkJoints
        _short_module = self.mModule.mNode
        mHandleFactory = self.mHandleFactory

        #limbRoot ------------------------------------------------------------------------------
        log.debug("|{0}| >> LimbRoot".format(_str_func))
        idx = 0
        #if self.b_lever:
        #    idx = 1

        mLimbRootHandle = self.ml_prerigHandles[idx]
        mLimbRoot = ml_fkJoints[0].rigJoint.doCreateAt()

        _size_root = MATH.average(POS.get_bb_size(self.mRootFormHandle.mNode))

        #MATH.average(POS.get_bb_size(self.mRootFormHandle.mNode))
        mRootCrv = cgmMeta.validateObjArg(CURVES.create_fromName(
            'locatorForm', _size_root),
                                          'cgmObject',
                                          setClass=True)
        mRootCrv.doSnapTo(ml_fkJoints[0])  #mLimbRootHandle

        #SNAP.go(mRootCrv.mNode, ml_joints[0].mNode,position=False)

        CORERIG.shapeParent_in_place(mLimbRoot.mNode, mRootCrv.mNode, False)

        for a in 'cgmName', 'cgmDirection', 'cgmModifier':
            if ATTR.get(_short_module, a):
                ATTR.copy_to(_short_module,
                             a,
                             mLimbRoot.mNode,
                             driven='target')

        mLimbRoot.doStore('cgmTypeModifier', 'limbRoot')
        mLimbRoot.doName()

        mHandleFactory.color(mLimbRoot.mNode, controlType='sub')
        self.mRigNull.connectChildNode(mLimbRoot, 'limbRoot', 'rigNull')

    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
Example #3
0
def register(
    controlObject=None,  #(mObject - None) -- The object to use as a control
    typeModifier=None,  #(string - None) -- Tag for cgmTypeModifier for naming
    copyTransform=None,  #(mObject - None) -- Object to copy the transform of for our control object
    copyPivot=None,  #(mObject - None) -- Object to copy the pivot of for our control object
    shapeParentTo=None,  #'(mObject - None) -- Object to shape parent our control curve to to use that transform
    useShape=None,  #'(mObject - None) -- Object to use the curve shape of for our control
    setRotateOrder=None,  #'(rotateOrder - None) -- Argument for a rotate order to set
    autoLockNHide=None,  #'(bool - None) -- Try to set lock and hide
    mirrorAxis=None,  #'(string - None) -- Mirror axis to set - using red9's setup terms
    mirrorSide=None,  #'(string/int - None) -- Mirror side - using red9's setup terms
    makeMirrorable=True,  #'(bool - True) -- Setup for mirrorability (using red9) -- implied by other mirror args
    addDynParentGroup=False,  #'(False) -- Add a dynParent group setup
    addExtraGroups=False,  #'(int - False) -- Number of nested extra groups desired
    addConstraintGroup=False,  #'(bool - False) -- If a group just above the control is desired for consraining
    freezeAll=False,  #'(bool - False) -- Freeze all transforms on the control object
    noFreeze=False,
    addSpacePivots=False,  #'(int - False) -- Number of space pivots to generate and connect
    controlType=None,  #'(string - None) -- Tag for cgmType
    aim=None,  #'(string/int - None) -- aim axis to use
    up=None,  #'(string/int - None) -- up axis to use
    out=None,  #'(string/int - None) -- out axis to use
    makeAimable=None,  #'(mObject - False) -- Make object aimable -- implied by aim/up/out):
    **kws):

    _str_func = 'register'
    """
    [{'step':'validate','call':self._validate},
    {'step':'Copy Transform','call':self._copyTransform},
    {'step':'Shape Parent','call':self._shapeParent},
    {'step':'Copy Pivot','call':self._copyPivot},
    {'step':'Naming','call':self._naming},
    {'step':'Aim Setup','call':self._aimSetup},
    {'step':'Rotate Order','call':self._rotateOrder},
    {'step':'Initial Freeze','call':self._initialFreeze},
    {'step':'Groups Setup','call':self._groupsSetup},
    {'step':'Space Pivot','call':self._spacePivots},
    {'step':'Mirror Setup','call':self._mirrorSetup},	                        
    {'step':'Freeze','call':self._freeze},
    {'step':'Mirror Attribute Bridges','call':self._mirrorAttributeBridges_},	                        
    {'step':'lock N Hide','call':self._lockNHide},
    {'step':'Return build','call':self._returnBuild}]
    """
    try:
        #Validate ================================================================================================
        mi_control = cgmMeta.validateObjArg(controlObject,
                                            'cgmControl',
                                            setClass=True)

        str_mirrorAxis = VALID.stringArg(mirrorAxis, calledFrom=_str_func)
        str_mirrorSide = cgmGeneral.verify_mirrorSideArg(
            mirrorSide)  #VALID.stringArg(mirrorSide,calledFrom = _str_func)
        b_makeMirrorable = VALID.boolArg(makeMirrorable, calledFrom=_str_func)

        _addMirrorAttributeBridges = kws.get('addMirrorAttributeBridges',
                                             False)
        addForwardBack = kws.get('addForwardBack', False)

        if _addMirrorAttributeBridges:
            if type(_addMirrorAttributeBridges) not in [list, tuple]:
                raise ValueError, "[Bad addMirrorAttributeBridge arg]{arg: %s}" % _addMirrorAttributeBridge
            for i, l in enumerate(_addMirrorAttributeBridges):
                if type(l) not in [list, tuple]:
                    raise ValueError, "[Bad addMirrorAttributeBridge arg: %s]{arg: %s}" % (
                        i, l)

        # Running lists ------------------------------------------------------------------------------------------
        ml_groups = []  #Holder for groups
        ml_constraintGroups = []
        ml_spacePivots = []

        #Copy Transform ================================================================================================
        if copyTransform is not None:
            mTarget = cgmMeta.validateObjArg(copyTransform,
                                             'cgmObject',
                                             noneValid=True)
            if not mTarget:
                raise StandardError, "Failed to find suitable copyTransform object: '%s" % copyTransform

            #Need to move this to default cgmNode stuff
            mBuffer = mi_control
            i_newTransform = cgmMeta.cgmObject(
                rigging.groupMeObject(mTarget.mNode, False))
            for a in mc.listAttr(mi_control.mNode, userDefined=True):
                ATTR.copy_to(mi_control.mNode, a, i_newTransform.mNode)
            curves.parentShapeInPlace(i_newTransform.mNode,
                                      mi_control.mNode)  #Parent shape
            i_newTransform.parent = mi_control.parent  #Copy parent
            mi_control = cgmMeta.asMeta(i_newTransform,
                                        'cgmControl',
                                        setClass=True)
            mc.delete(mBuffer.mNode)

        #ShapeParent ================================================================================================
        if shapeParentTo:
            i_target = cgmMeta.validateObjArg(shapeParentTo, 'cgmObject')
            CORERIG.shapeParent_in_place(i_target.mNode, mi_control.mNode)
            i_target = cgmMeta.asMeta(i_target, 'cgmControl', setClass=True)
            #mi_control.delete()
            mi_control = i_target  #replace the control with the joint

        if useShape is not None:
            i_shape = cgmMeta.validateObjArg(useShape,
                                             cgmMeta.cgmObject,
                                             mayaType='nurbsCurve')
            curves.parentShapeInPlace(mi_control.mNode, i_shape.mNode)

        #Copy Pivot ============================================================================================
        if copyPivot is not None:
            if issubclass(type(copyPivot), cgmMeta.cgmNode):
                i_target = copyPivot
            elif mc.objExists(copyPivot):
                i_target = cgmMeta.cgmObject(copyPivot)
            else:
                raise StandardError, "Failed to find suitable copyTransform object: '%s" % copyPivot

            #Need to move this to default cgmNode stuff
            mi_control.doCopyPivot(i_target.mNode)

        #Naming ============================================================================================
        mi_control.addAttr('cgmType', 'controlAnim', lock=True)
        if typeModifier is not None:
            mi_control.addAttr('cgmTypeModifier', str(typeModifier), lock=True)
        mi_control.doName()  #mi_control.doName(nameShapes=True)

        #Rotate Order ============================================================================================
        _rotateOrder = False
        if setRotateOrder is not None:
            _rotateOrder = setRotateOrder
        elif controlType in __d_rotateOrderDefaults__.keys():
            _rotateOrder = __d_rotateOrderDefaults__[controlType]
        elif mi_control.getAttr('cgmName') in __d_rotateOrderDefaults__.keys():
            _rotateOrder = __d_rotateOrderDefaults__[mi_control.getAttr(
                'cgmName')]
        else:
            log.debug("|{0}| >> Rotate order not set on: {1}".format(
                _str_func, mi_control.p_nameShort))

        #Set it ---------------------------------------------------------------
        if _rotateOrder:
            mRotateOrder = VALID.simpleOrientation(_rotateOrder)
            #dictionary.validateRotateOrderString(_rotateOrder)

            mc.xform(mi_control.mNode, rotateOrder=mRotateOrder.p_string)

        #Initial Freeze ============================================================================================
        if freezeAll:
            mc.makeIdentity(mi_control.mNode, apply=True, t=1, r=1, s=1, n=0)

        #Groups ============================================================================================
        if addDynParentGroup or addSpacePivots or mi_control.getAttr(
                'cgmName') == 'cog' or _addMirrorAttributeBridges:
            mi_control.addAttr('________________',
                               attrType='int',
                               keyable=False,
                               hidden=False,
                               lock=True)
            ATTR.reorder(mi_control.mNode, '________________', top=True)
        #Aim Setup ============================================================================================
        if aim is not None or up is not None or makeAimable:
            mi_control._verifyAimable()

        #First our master group:
        i_masterGroup = (cgmMeta.asMeta(mi_control.doGroup(True),
                                        'cgmObject',
                                        setClass=True))
        i_masterGroup.doStore('cgmName', mi_control)
        i_masterGroup.addAttr('cgmTypeModifier', 'master', lock=True)
        i_masterGroup.doName()
        mi_control.connectChildNode(i_masterGroup, 'masterGroup', 'groupChild')

        if addDynParentGroup:
            i_dynGroup = (cgmMeta.cgmObject(mi_control.doGroup(True)))
            i_dynGroup = cgmRigMeta.cgmDynParentGroup(dynChild=mi_control,
                                                      dynGroup=i_dynGroup)
            i_dynGroup.doName()
            """
            i_zeroGroup = (cgmMeta.cgmObject(mi_control.doGroup(True)))
            i_zeroGroup.addAttr('cgmTypeModifier','zero',lock=True)
            i_zeroGroup.doName()
            mi_control.connectChildNode(i_zeroGroup,'zeroGroup','groupChild')"""

        if addExtraGroups:
            for i in range(addExtraGroups):
                i_group = (cgmMeta.asMeta(mi_control.doGroup(True),
                                          'cgmObject',
                                          setClass=True))
                if type(
                        addExtraGroups
                ) == int and addExtraGroups > 1:  #Add iterator if necessary
                    i_group.addAttr('cgmIterator', str(i + 1), lock=True)
                    i_group.doName()
                ml_groups.append(i_group)
            mi_control.msgList_connect("extraGroups", ml_groups, 'groupChild')

        if addConstraintGroup:  #ConstraintGroups
            i_constraintGroup = (cgmMeta.asMeta(mi_control.doGroup(True),
                                                'cgmObject',
                                                setClass=True))
            i_constraintGroup.addAttr('cgmTypeModifier',
                                      'constraint',
                                      lock=True)
            i_constraintGroup.doName()
            ml_constraintGroups.append(i_constraintGroup)
            mi_control.connectChildNode(i_constraintGroup, 'constraintGroup',
                                        'groupChild')

        #Space Pivot ============================================================================================
        if addSpacePivots:
            parent = mi_control.getMessage('masterGroup')[0]
            for i in range(int(addSpacePivots)):
                #i_pivot = rUtils.create_spaceLocatorForObject(mi_control.mNode,parent)
                i_pivot = SPACEPIVOTS.create(mi_control.mNode, parent)
                ml_spacePivots.append(i_pivot)
                #log.info("spacePivot created: {0}".format(i_pivot.p_nameShort))

        #Mirror Setup ============================================================================================
        if str_mirrorSide is not None or b_makeMirrorable:
            for mObj in [mi_control] + ml_spacePivots:
                mi_control._verifyMirrorable()
                l_enum = cgmMeta.cgmAttr(mi_control, 'mirrorSide').p_enum
                if str_mirrorSide in l_enum:
                    #log.debug("|{0}| >> Rotate order not set on: {1}".format(_str_func,mi_control.p_nameShort))
                    #log.debug("%s >> %s >> found in : %s"%(_str_funcCombined, "mirrorSetup", l_enum))
                    mi_control.mirrorSide = l_enum.index(str_mirrorSide)
                if str_mirrorAxis:
                    mi_control.mirrorAxis = str_mirrorAxis
            for mObj in mi_control.msgList_get('spacePivots'):
                mObj._verifyMirrorable()
                mi_control.doConnectOut('mirrorAxis',
                                        mObj.mNode + '.mirrorAxis')
                mi_control.doConnectOut('mirrorSide',
                                        mObj.mNode + '.mirrorSide')

                #cgmMeta.cgmAttr(mObj,'mirrorSide').doConnectIn(mi_control,'mirrorSide')
                #cgmMeta.cgmAttr(mi_control,'mirrorAxis').doCopyTo(mObj,connectTargetToSource = 1)
                #ATTR.connect(mObj.mNode + '.mirrorAxis',"{0}.mirrorAxis".format(mi_control.mNode))
                #ATTR.connect(mObj.mNode + 'mirrorSide',"{0}.mirrorSide".format(mi_control.mNode))

        #Freeze ============================================================================================
        if not shapeParentTo and noFreeze is not True:
            if not freezeAll:
                if mi_control.getAttr(
                        'cgmName'
                ) == 'cog' or controlType in __l_fullFreezeTypes__:
                    mc.makeIdentity(mi_control.mNode,
                                    apply=True,
                                    t=1,
                                    r=1,
                                    s=1,
                                    n=0)
                else:
                    mc.makeIdentity(mi_control.mNode,
                                    apply=True,
                                    t=1,
                                    r=0,
                                    s=1,
                                    n=0)
            else:
                mc.makeIdentity(mi_control.mNode,
                                apply=True,
                                t=1,
                                r=1,
                                s=1,
                                n=0)

        #Mirror attriubte Bridges ==========================================================================
        if addForwardBack:
            mPlug_forwardBackDriver = cgmMeta.cgmAttr(mi_control,
                                                      "forwardBack",
                                                      attrType='float',
                                                      keyable=True)
            try:
                mPlug_forwardBackDriven = cgmMeta.validateAttrArg(
                    [mi_control, addForwardBack])['mi_plug']
            except Exception, error:
                raise StandardError, "push pull driver | %s" % (error)

            if str_mirrorSide.lower() == 'right':
                arg_forwardBack = "%s = -%s" % (
                    mPlug_forwardBackDriven.p_combinedShortName,
                    mPlug_forwardBackDriver.p_combinedShortName)
            else:
                arg_forwardBack = "%s = %s" % (
                    mPlug_forwardBackDriven.p_combinedShortName,
                    mPlug_forwardBackDriver.p_combinedShortName)

            mPlug_forwardBackDriven.p_locked = True
            mPlug_forwardBackDriven.p_hidden = True
            mPlug_forwardBackDriven.p_keyable = False
            NodeF.argsToNodes(arg_forwardBack).doBuild()

        if _addMirrorAttributeBridges:
            for l_bridge in _addMirrorAttributeBridges:
                _attrName = VALID.stringArg(l_bridge[0])
                _attrToBridge = VALID.stringArg(l_bridge[1])
                if not mi_control.hasAttr(_attrToBridge):
                    raise StandardError, "['%s' lacks the bridge attr '%s']" % (
                        mi_control.p_nameShort, _attrToBridge)

                mPlug_attrBridgeDriver = cgmMeta.cgmAttr(mi_control,
                                                         _attrName,
                                                         attrType='float',
                                                         keyable=True)
                try:
                    mPlug_attrBridgeDriven = cgmMeta.validateAttrArg(
                        [mi_control, _attrToBridge])['mi_plug']
                except Exception, error:
                    raise StandardError, "[validate control attribute bridge attr]{%s}" % (
                        error)

                if str_mirrorSide.lower() == 'right':
                    arg_attributeBridge = "%s = -%s" % (
                        mPlug_attrBridgeDriven.p_combinedShortName,
                        mPlug_attrBridgeDriver.p_combinedShortName)
                else:
                    arg_attributeBridge = "%s = %s" % (
                        mPlug_attrBridgeDriven.p_combinedShortName,
                        mPlug_attrBridgeDriver.p_combinedShortName)

                mPlug_attrBridgeDriven.p_locked = True
                mPlug_attrBridgeDriven.p_hidden = True
                mPlug_attrBridgeDriven.p_keyable = False
                NodeF.argsToNodes(arg_attributeBridge).doBuild()
Example #4
0
import cgm.core.lib.attribute_utils as ATTR
import cgm.core.lib.distance_utils as DIST


#Segment ------------------------------------------------------------------------------------------
SEGMENT.create

#Def ---------------------------------------
#Return change

i_curve = curveSegmentReturn['mSegmentCurve']

SEGMENT.add_subControl_toCurve

#Segment scale
ATTR.copy_to(i_curve.mNode,'segmentScaleMult',mi_cog.mNode,'squashStretch',driven='source')
ATTR.set_keyable(mi_cog.mNode,'squashStretch',False)

#MidFactor
l_keys = i_curve.getSequentialAttrDict('midFactor').keys()
for i,k in enumerate(l_keys):
    a = 'midFactor_{0}'.format(i)
    ATTR.copy_to(i_curve.mNode,a,ml_segmentHandles[1].mNode,driven='source')
    ATTR.set_keyable(ml_segmentHandles[1].mNode,a,False)
    if i == 1:
        ATTR.set(mi_handleIK.mNode,1)    
    

l_keys = i_curve.getSequentialAttrDict('scaleMult').keys()

Example #5
0
def spline(self,
           ml_ikJoints=None,
           ml_ribbonIkHandles=None,
           mIKControl=None,
           mIKBaseControl=None,
           ml_skinDrivers=None,
           mPlug_masterScale=None):
    try:
        _str_func = 'spline'
        log_start(_str_func)

        mBlock = self.mBlock
        mRigNull = self.mRigNull
        _offset = self.v_offset
        _jointOrientation = self.d_orientation['str']

        ml_ribbonIkHandles = mRigNull.msgList_get('ribbonIKDrivers')
        if not ml_ribbonIkHandles:
            raise ValueError, "No ribbon IKDriversFound"

        _aim = self.d_orientation['vectorAim']
        _aimNeg = self.d_orientation['vectorAimNeg']
        _up = self.d_orientation['vectorUp']
        _out = self.d_orientation['vectorOut']

        res_spline = IK.spline([mObj.mNode for mObj in ml_ikJoints],
                               orientation=_jointOrientation,
                               advancedTwistSetup=True,
                               baseName=self.d_module['partName'] + '_spline',
                               moduleInstance=self.mModule)

        mSplineCurve = res_spline['mSplineCurve']
        log.debug("|{0}| >> spline curve...".format(_str_func))

        mSplineCurve.doConnectIn('masterScale',
                                 mPlug_masterScale.p_combinedShortName)

        ATTR.copy_to(mSplineCurve.mNode,
                     'twistEnd',
                     mIKControl.mNode,
                     driven='source')
        ATTR.copy_to(mSplineCurve.mNode,
                     'twistStart',
                     mIKBaseControl.mNode,
                     driven='source')
        ATTR.copy_to(mSplineCurve.mNode,
                     'twistType',
                     mIKControl.mNode,
                     driven='source')

        #ATTR.set_default(mIKControl.mNode,'twistType',1)
        #ATTR.set(mIKControl.mNode,'twistType',1)

        mSkinCluster = cgmMeta.validateObjArg(mc.skinCluster(
            [mHandle.mNode for mHandle in ml_skinDrivers],
            mSplineCurve.mNode,
            tsb=True,
            maximumInfluences=2,
            normalizeWeights=1,
            dropoffRate=2.5),
                                              'cgmNode',
                                              setClass=True)

        mSkinCluster.doStore('cgmName', mSplineCurve)
        mSkinCluster.doName()

        mc.orientConstraint(mIKControl.mNode,
                            ml_ikJoints[-1].mNode,
                            maintainOffset=True)

    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
Example #6
0
def settings(self, settingsPlace=None, ml_targets=None):
    try:
        _str_func = 'rp'
        log_start(_str_func)
        log.debug("|{0}| >> settings: {1}...".format(_str_func, settingsPlace))

        mBlock = self.mBlock
        mRigNull = self.mRigNull
        _offset = self.v_offset
        _jointOrientation = self.d_orientation['str']

        if settingsPlace == None:
            settingsPlace = mBlock.getEnumValueString('settingsPlace')

        if settingsPlace == 'cog':
            mCog = mRigNull.getMessageAsMeta('rigRoot')
            if mCog:
                log.debug("|{0}| >> Settings is cog...".format(_str_func))
                mRigNull.connectChildNode(mCog, 'settings',
                                          'rigNull')  #Connect
                return mCog
            else:
                log.warning(
                    "|{0}| >> Settings. Cog option but no cog found...".format(
                        _str_func))
                settingsPlace = 'start'

        mSettingsHelper = mBlock.getMessageAsMeta('settingsHelper')

        if settingsPlace in ['start', 'end']:
            if settingsPlace == 'start':
                _mTar = ml_targets[0]
            else:
                _mTar = ml_targets[self.int_handleEndIdx]

            #_settingsSize = _offset * 2
            if not mSettingsHelper:

                mMesh_tmp = mBlock.atUtils('get_castMesh')
                str_meshShape = mMesh_tmp.getShapes()[0]

                d_directions = {
                    'up': 'y+',
                    'down': 'y-',
                    'in': 'x+',
                    'out': 'x-'
                }

                str_settingsDirections = d_directions.get(
                    mBlock.getEnumValueString('settingsDirection'), 'y+')

                pos = RAYS.get_cast_pos(_mTar.mNode,
                                        str_settingsDirections,
                                        shapes=str_meshShape)
                if not pos:
                    log.debug(
                        cgmGEN.logString_msg(_str_func, 'standard IK end'))
                    pos = _mTar.getPositionByAxisDistance(
                        str_settingsDirections, _offset * 5)

                vec = MATH.get_vector_of_two_points(_mTar.p_position, pos)
                newPos = DIST.get_pos_by_vec_dist(pos, vec, _offset * 4)

                _settingsSize = _offset * 2

                mSettingsShape = cgmMeta.validateObjArg(CURVES.create_fromName(
                    'gear',
                    _settingsSize,
                    '{0}+'.format(_jointOrientation[2]),
                    baseSize=1.0),
                                                        'cgmObject',
                                                        setClass=True)

                mSettingsShape.doSnapTo(_mTar.mNode)

                #SNAPCALLS.get_special_pos([_mTar,str_meshShape],'castNear',str_settingsDirections,False)

                mSettingsShape.p_position = newPos
                mMesh_tmp.delete()

                SNAP.aim_atPoint(
                    mSettingsShape.mNode,
                    _mTar.p_position,
                    aimAxis=_jointOrientation[0] + '+',
                    mode='vector',
                    vectorUp=_mTar.getAxisVector(_jointOrientation[0] + '-'))
            else:
                mSettingsShape = mSettingsHelper.doDuplicate(po=False)

            mSettingsShape.parent = _mTar

            mSettings = mSettingsShape
            CORERIG.match_orientation(mSettings.mNode, _mTar.mNode)

            ATTR.copy_to(self.mModule.mNode,
                         'cgmName',
                         mSettings.mNode,
                         driven='target')

            mSettings.doStore('cgmTypeModifier', 'settings')
            mSettings.doName()
            self.mHandleFactory.color(mSettings.mNode, controlType='sub')
            mRigNull.connectChildNode(mSettings, 'settings',
                                      'rigNull')  #Connect

            #cgmGEN.func_snapShot(vars())
            #mSettings.select()
        else:
            raise ValueError, "Unknown settingsPlace: {1}".format(
                settingsPlace)

        return mSettings
    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
Example #7
0
def rootOrCog(self, mHandle=None):
    try:
        _str_func = 'rootOrCog'
        log_start(_str_func)

        mBlock = self.mBlock
        ml_prerigHandles = self.ml_prerigHandles
        ml_formHandles = self.ml_formHandles
        _offset = self.v_offset
        if mBlock.getMessage('cogHelper') and mBlock.getMayaAttr('addCog'):
            log.debug("|{0}| >> Cog...".format(_str_func))
            mCogHelper = mBlock.cogHelper

            mCog = mCogHelper.doCreateAt(setClass=True)
            CORERIG.shapeParent_in_place(mCog.mNode,
                                         mCogHelper.shapeHelper.mNode)

            #Cast a simple curve
            #Cv's 4,2 |

            ml_shapes = self.atBuilderUtils('shapes_fromCast',
                                            targets=mCogHelper.shapeHelper,
                                            offset=_offset * 2.0,
                                            mode='singleCast')  #'segmentHan
            CORERIG.shapeParent_in_place(mCog.mNode, ml_shapes[0].mNode, False)

            CORERIG.override_color(mCog.mNode, 'white')

            mCog.doStore('cgmName', 'cog')
            mCog.doStore('cgmAlias', 'cog')
            mCog.doName()

            self.mRigNull.connectChildNode(mCog, 'rigRoot',
                                           'rigNull')  #Connect
            self.mRigNull.connectChildNode(mCog, 'settings',
                                           'rigNull')  #Connect

        else:  #Root =============================================================================
            log.debug("|{0}| >> Root...".format(_str_func))

            mRootHandle = ml_prerigHandles[0]
            #mRoot = ml_joints[0].doCreateAt()

            ml_joints = self.d_joints['ml_moduleJoints']
            mRoot = ml_joints[0].doCreateAt()

            #_size_root =  MATH.average(mHandleFactory.get_axisBox_size(ml_formHandles[0].mNode))
            _bb_root = POS.get_bb_size(ml_formHandles[0].loftCurve.mNode, True)
            _size_root = MATH.average(_bb_root)
            mRootCrv = cgmMeta.validateObjArg(CURVES.create_fromName(
                'cubeOpen', _size_root * 1.5),
                                              'cgmObject',
                                              setClass=True)
            mRootCrv.doSnapTo(mRootHandle)

            #SNAP.go(mRootCrv.mNode, ml_joints[0].mNode,position=False)

            CORERIG.shapeParent_in_place(mRoot.mNode, mRootCrv.mNode, False)

            ATTR.copy_to(self.mModule.mNode,
                         'cgmName',
                         mRoot.mNode,
                         driven='target')
            mRoot.doStore('cgmTypeModifier', 'root')
            mRoot.doName()

            self.mHandleFactory.color(mRoot.mNode, controlType='sub')

            self.mRigNull.connectChildNode(mRoot, 'rigRoot',
                                           'rigNull')  #Connect

    except Exception, err:
        cgmGEN.cgmExceptCB(Exception, err, localDat=vars())
Example #8
0
def armature_verify(self):
    """
    First pass on armature setup
    """
    _str_func = 'verify_armature'
    log.debug("|{0}| >> ...".format(_str_func) + cgmGEN._str_hardBreak)
    log.debug(self)

    if not self.getMessage('armature'):
        log.debug("|{0}| >> missing plug. Creating armature dag...".format(
            _str_func))
        mArmature = self.masterNull.doCreateAt(setClass=True)
    else:
        mArmature = self.getMessageAsMeta('armature')

    ATTR.copy_to(self.mNode, 'cgmName', mArmature.mNode, driven='target')
    mArmature.addAttr('puppet', attrType='messageSimple')
    if not mArmature.connectParentNode(self.mNode, 'puppet', 'armature'):
        raise StandardError, "Failed to connect masterNull to puppet network!"

    mArmature.addAttr('cgmType', initialValue='ignore', lock=True)
    mArmature.addAttr('cgmModuleType', value='master', lock=True)
    mArmature.addAttr('geoGroup', attrType='messageSimple', lock=True)
    mArmature.addAttr('skeletonGroup', attrType='messageSimple', lock=True)

    #See if it's named properly. Need to loop back after scene stuff is querying properly
    mArmature.doName()
    mArmature.dagLock(True, ignore='v')

    mc.editDisplayLayerMembers(self.displayLayer.mNode,
                               mArmature.mNode,
                               noRecurse=True)
    #editDisplayLayerMembers -noRecurse master_displayLayer `ls -selection`;

    for attr in 'geo', 'skeleton':
        _plug = attr + 'Group'

        if mArmature.getMessage(_plug):
            mGroup = mArmature.getMessageAsMeta(_plug)
            if mGroup.getParent(asMeta=1) != mArmature:
                mGroup.dagLock(False)
                mGroup.p_parent = mArmature
                mGroup.dagLock(True)
            continue

        if not self.masterNull.getMessage(_plug):
            log.debug("|{0}| >> missing plug. Creating: {1}".format(
                _str_func, attr))
            mGroup = self.masterNull.doCreateAt(setClass=True)
            self.masterNull.connectChildNode(mGroup, _plug, 'module')
        else:
            mGroup = self.masterNull.getMessageAsMeta(_plug)
            mGroup.dagLock(False)

        mArmature.connectChildNode(mGroup, _plug)
        mGroup.p_parent = mArmature
        mGroup.dagLock(True)
        mGroup.rename(attr)

        log.debug("|{0}| >> attr: {1} | mGroup: {2}".format(
            _str_func, attr, mGroup))
    return