コード例 #1
0
ファイル: zooMirror.py プロジェクト: sgodanas/cgm_tools
    def Init(cls):
        attrMsg = MFnMessageAttribute()

        cls.controlA = attrMsg.create("controlA", "ca")
        cls.controlB = attrMsg.create("controlB", "cb")
        cls.addAttribute(cls.controlA)
        cls.addAttribute(cls.controlB)

        attrEnum = MFnEnumAttribute()
        cls.axis = attrEnum.create("axis", "ax")
        attrEnum.addField('x', 0)
        attrEnum.addField('y', 1)
        attrEnum.addField('z', 2)
        attrEnum.setDefault('x')
        attrEnum.setKeyable(False)
        attrEnum.setChannelBox(True)

        cls.addAttribute(cls.axis)

        cls.axis = attrEnum.create("flipAxes", "flax")
        for n, thisAxes in enumerate(cls.FLIP_AXES):
            if thisAxes:
                enumStr = ''.join([ax.asName() for ax in thisAxes])
            else:
                enumStr = 'none'

            attrEnum.addField(enumStr, n)

        attrEnum.setKeyable(False)
        attrEnum.setChannelBox(True)

        cls.addAttribute(cls.axis)

        numAttr = MFnNumericAttribute()
        cls.neverDoT = numAttr.create("neverDoT", "nvt",
                                      MFnNumericData.kBoolean)
        cls.neverDoR = numAttr.create("neverDoR", "nvr",
                                      MFnNumericData.kBoolean)
        cls.neverDoOther = numAttr.create("neverDoOther", "nvo",
                                          MFnNumericData.kBoolean)

        cls.addAttribute(cls.neverDoT)
        cls.addAttribute(cls.neverDoR)
        cls.addAttribute(cls.neverDoOther)

        cls.worldSpace = numAttr.create("worldSpace", "ws",
                                        MFnNumericData.kBoolean, True)
        cls.addAttribute(cls.worldSpace)
コード例 #2
0
ファイル: plug_utils.py プロジェクト: lefan2016/maya_utils
def getPlugValue(in_plug):
    '''
    @param in_plug: MPlug, to get value from
    '''
    plugs = []
    if in_plug.isCompound():
        for i in in_plug.numChildren():
            plugs.append(in_plug.child(i))
    elif in_plug.isArray():
        for i in in_plug.numElements():
            plugs.append(in_plug.getElementByPhysicalIndex(i))
    else:
        plugs.append(in_plug)

    out = [] #compound list of all data in the plug or its child plugs
    for plug in plugs:
        attr = plug.attribute()
        if attr.hasFn(MFn.kNumericAttribute):
            type = MFnNumericAttribute(attr).unitType()
            if type in (MFnNumericData.kBoolean, MFnNumericData.kByte):
                out.append(plug.asBool())
            elif type == MFnNumericData.kChar:
                out.append(plug.asChar())
            elif type == MFnNumericData.kShort:
                out.append(plug.asShort())
            elif type in (MFnNumericData.kInt, MFnNumericData.kLong):
                out.append(plug.asInt())
            elif type == MFnNumericData.kFloat:
                out.append(plug.asFloat())
            elif type == MFnNumericData.kDouble:
                out.append(plug.asDouble())
        elif attr.hasFn(MFn.kUnitAttribute):
            type = MFnUnitAttribute(attr).unitType()
            if type == MFnUnitAttribute.kAngle:
                out.append(plug.asMAngle())
            elif type == MFnUnitAttribute.kDistance:
                out.append(plug.asMDistance())
            elif type == MFnUnitAttribute.kTime:
                out.append(plug.asMTime())
        elif attr.hasFn(MFn.kTypedAttribute):
            type = MFnTypedAttribute(attr).attrType()
            if type == MFnData.kString:
                out.append(plug.asString())
        else:
            #last resort for unimplemented data types
            out.append(plug.asMObject())
    return out
コード例 #3
0
ファイル: zooMirror.py プロジェクト: sgodanas/cgm_tools
    def Init(cls):
        attrInWorldMatrix = MFnMatrixAttribute()
        attrInParentMatrixInv = MFnMatrixAttribute()

        attrMirrorAxis = MFnEnumAttribute()
        attrMirrorTranslation = MFnEnumAttribute()

        attrTargetParentMatrixInv = MFnMatrixAttribute()
        targetRotationOrder = MFnNumericAttribute()

        attrOutTranslate = MFnNumericAttribute()
        attrOutTranslateX = MFnUnitAttribute()
        attrOutTranslateY = MFnUnitAttribute()
        attrOutTranslateZ = MFnUnitAttribute()

        attrOutRotate = MFnNumericAttribute()
        attrOutRotateX = MFnUnitAttribute()
        attrOutRotateY = MFnUnitAttribute()
        attrOutRotateZ = MFnUnitAttribute()

        attrTargetJointOrient = MFnNumericAttribute()
        attrTargetJointOrientX = MFnUnitAttribute()
        attrTargetJointOrientY = MFnUnitAttribute()
        attrTargetJointOrientZ = MFnUnitAttribute()

        #create the world matrix
        cls.inWorldMatrix = attrInWorldMatrix.create("inWorldMatrix", "iwm")

        cls.addAttribute(cls.inWorldMatrix)

        #create the local matrix
        cls.inParentMatrixInv = attrInWorldMatrix.create(
            "inParentInverseMatrix", "ipmi")

        cls.addAttribute(cls.inParentMatrixInv)

        #create the mirror axis
        cls.mirrorAxis = attrMirrorAxis.create("mirrorAxis", "m")
        attrMirrorAxis.addField('x', 0)
        attrMirrorAxis.addField('y', 1)
        attrMirrorAxis.addField('z', 2)
        attrMirrorAxis.setDefault('x')
        attrMirrorAxis.setKeyable(False)
        attrMirrorAxis.setChannelBox(True)

        cls.addAttribute(cls.mirrorAxis)

        #create the mirror axis
        cls.mirrorTranslation = attrMirrorTranslation.create(
            "mirrorTranslation", "mt")
        for modeName, modeIdx in zip(cls.MIRROR_MODE_NAMES, cls.MIRROR_MODES):
            attrMirrorTranslation.addField(modeName, modeIdx)

        attrMirrorTranslation.setDefault(cls.MIRROR_DEFAULT)
        attrMirrorTranslation.setKeyable(False)
        attrMirrorTranslation.setChannelBox(True)

        cls.addAttribute(cls.mirrorTranslation)

        #create the out world matrix inverse
        cls.targetParentMatrixInv = attrTargetParentMatrixInv.create(
            "targetParentInverseMatrix", "owm")
        cls.addAttribute(cls.targetParentMatrixInv)

        #create the target rotation order attribute
        cls.targetRotationOrder = targetRotationOrder.create(
            "targetRotationOrder", "troo", MFnNumericData.kInt)
        cls.addAttribute(cls.targetRotationOrder)

        #create the joint orient compensation attributes
        cls.targetJointOrientX = attrTargetJointOrientX.create(
            "targetJointOrientX", "tjox", MFnUnitAttribute.kAngle)
        cls.targetJointOrientY = attrTargetJointOrientY.create(
            "targetJointOrientY", "tjoy", MFnUnitAttribute.kAngle)
        cls.targetJointOrientZ = attrTargetJointOrientZ.create(
            "targetJointOrientZ", "tjoz", MFnUnitAttribute.kAngle)
        cls.targetJointOrient = attrTargetJointOrient.create(
            "targetJointOrient", "tjo", cls.targetJointOrientX,
            cls.targetJointOrientY, cls.targetJointOrientZ)
        cls.addAttribute(cls.targetJointOrient)

        #create the out translate attributes
        cls.outTranslateX = attrOutTranslateX.create(
            "outTranslateX", "otx", MFnUnitAttribute.kDistance)
        cls.outTranslateY = attrOutTranslateY.create(
            "outTranslateY", "oty", MFnUnitAttribute.kDistance)
        cls.outTranslateZ = attrOutTranslateZ.create(
            "outTranslateZ", "otz", MFnUnitAttribute.kDistance)
        cls.outTranslate = attrOutTranslate.create("outTranslate", "ot",
                                                   cls.outTranslateX,
                                                   cls.outTranslateY,
                                                   cls.outTranslateZ)
        cls.addAttribute(cls.outTranslate)

        #create the out rotation attributes
        cls.outRotateX = attrOutRotateX.create("outRotateX", "orx",
                                               MFnUnitAttribute.kAngle)
        cls.outRotateY = attrOutRotateY.create("outRotateY", "ory",
                                               MFnUnitAttribute.kAngle)
        cls.outRotateZ = attrOutRotateZ.create("outRotateZ", "orz",
                                               MFnUnitAttribute.kAngle)
        cls.outRotate = attrOutRotate.create("outRotate", "or", cls.outRotateX,
                                             cls.outRotateY, cls.outRotateZ)
        cls.addAttribute(cls.outRotate)

        #setup attribute dependency relationships
        cls.attributeAffects(cls.inWorldMatrix, cls.outTranslate)
        cls.attributeAffects(cls.inWorldMatrix, cls.outRotate)

        cls.attributeAffects(cls.inParentMatrixInv, cls.outTranslate)
        cls.attributeAffects(cls.inParentMatrixInv, cls.outRotate)

        cls.attributeAffects(cls.mirrorAxis, cls.outTranslate)
        cls.attributeAffects(cls.mirrorAxis, cls.outRotate)

        cls.attributeAffects(cls.mirrorTranslation, cls.outTranslate)
        cls.attributeAffects(cls.mirrorTranslation, cls.outRotate)

        cls.attributeAffects(cls.targetParentMatrixInv, cls.outTranslate)
        cls.attributeAffects(cls.targetParentMatrixInv, cls.outRotate)

        cls.attributeAffects(cls.targetRotationOrder, cls.outTranslate)
        cls.attributeAffects(cls.targetRotationOrder, cls.outRotate)

        cls.attributeAffects(cls.targetJointOrient, cls.outRotate)