Esempio n. 1
0
def getPlugMin(plug):
    obj = plug.attribute()
    if obj.hasFn(om2.MFn.kNumericAttribute):
        attr = om2.MFnNumericAttribute(obj)
        if attr.hasMin():
            return attr.getMin()
    elif obj.hasFn(om2.MFn.kUnitAttribute):
        attr = om2.MFnUnitAttribute(obj)
        if attr.hasMin():
            return attr.getMin()
    elif obj.hasFn(om2.MFn.kEnumAttribute):
        attr = om2.MFnEnumAttribute(obj)
        return attr.getMin()
Esempio n. 2
0
    def initialize():
        nAttr2 = om.MFnNumericAttribute()
        SampleValueOut.inValue = nAttr2.create('inValue', 'iv', om.MFnNumericData.kFloat, 0.0)
        nAttr2.keyable = True

        nAttrValueMode = om.MFnEnumAttribute()
        SampleValueOut.inSampleValueMode = nAttrValueMode.create('mode', 'im', 0)
        nAttrValueMode.addField("normal", 0)
        nAttrValueMode.addField("multiply", 1)

        nAttrRemapFromX = om.MFnNumericAttribute()
        SampleValueOut.inRemapFromX = nAttrRemapFromX.create('remapFromX', 'rfx', om.MFnNumericData.kFloat, 0.0)
        nAttrRemapFromX.keyable = True
        nAttrRemapFromX.storable = True

        nAttrRemapFromY = om.MFnNumericAttribute()
        SampleValueOut.inRemapFromY = nAttrRemapFromY.create('remapFromY', 'rfy', om.MFnNumericData.kFloat, 1.0)
        nAttrRemapFromY.keyable = True
        nAttrRemapFromY.storable = True

        nAttrRemapToX = om.MFnNumericAttribute()
        SampleValueOut.inRemapToX = nAttrRemapToX.create('remapToX', 'rtx', om.MFnNumericData.kFloat, 0.0)
        nAttrRemapToX.keyable = True
        nAttrRemapToX.storable = True

        nAttrRemapToY = om.MFnNumericAttribute()
        SampleValueOut.inRemapToY = nAttrRemapToY.create('remapToY', 'rty', om.MFnNumericData.kFloat, 1.0)
        nAttrRemapToY.keyable = True
        nAttrRemapToY.storable = True

        nAttrOut = om.MFnNumericAttribute()
        SampleValueOut.outValue= nAttrOut.create('outValue', 'ov', om.MFnNumericData.kFloat, 0.0)
        nAttrOut.keyable = False
        nAttrOut.storable = False

        # add the attributes
        om.MPxNode.addAttribute(SampleValueOut.inValue)
        om.MPxNode.addAttribute(SampleValueOut.inSampleValueMode)
        om.MPxNode.addAttribute(SampleValueOut.inRemapFromX)
        om.MPxNode.addAttribute(SampleValueOut.inRemapFromY)
        om.MPxNode.addAttribute(SampleValueOut.inRemapToX)
        om.MPxNode.addAttribute(SampleValueOut.inRemapToY)

        om.MPxNode.addAttribute(SampleValueOut.outValue)
        
        # establish effects on output
        om.MPxNode.attributeAffects(SampleValueOut.inValue,        SampleValueOut.outValue)
        om.MPxNode.attributeAffects(SampleValueOut.inRemapFromX,        SampleValueOut.outValue)
        om.MPxNode.attributeAffects(SampleValueOut.inRemapFromY,        SampleValueOut.outValue)
        om.MPxNode.attributeAffects(SampleValueOut.inRemapToX,          SampleValueOut.outValue)
        om.MPxNode.attributeAffects(SampleValueOut.inRemapToY,          SampleValueOut.outValue)
Esempio n. 3
0
def nodeInitializer():

    numAttr = om.MFnNumericAttribute()
    ligamentNode.output = numAttr.createPoint('output', 'output')
    numAttr.keyable = False
    #numAttr.hidden = True
    numAttr.array = True
    numAttr.storable = True
    numAttr.readable = True
    numAttr.writable = True
    om.MPxNode.addAttribute(ligamentNode.output)

    enumAttr = om.MFnEnumAttribute()
    ligamentNode.initilize = enumAttr.create("initialize", "init")
    enumAttr.addField("off", 0)
    enumAttr.addField("initialize", 1)
    enumAttr.addField("initialized", 2)
    enumAttr.keyable = True
    enumAttr.storable = True
    enumAttr.readable = True
    om.MPxNode.addAttribute(ligamentNode.initilize)
    ligamentNode.attributeAffects(ligamentNode.initilize, ligamentNode.output)

    typedAttr = om.MFnTypedAttribute()
    ligamentNode.inCurve = typedAttr.create("inCurve", "inCurve",
                                            om.MFnData.kNurbsCurve)
    typedAttr.storable = True
    typedAttr.readable = True
    om.MPxNode.addAttribute(ligamentNode.inCurve)
    ligamentNode.attributeAffects(ligamentNode.inCurve, ligamentNode.output)

    typedAttr = om.MFnTypedAttribute()
    ligamentNode.refCurve = typedAttr.create("refCurve", "refCurve",
                                             om.MFnData.kNurbsCurve)
    typedAttr.storable = True
    typedAttr.readable = True
    om.MPxNode.addAttribute(ligamentNode.refCurve)
    ligamentNode.attributeAffects(ligamentNode.refCurve, ligamentNode.output)

    nAttr = om.MFnNumericAttribute()
    ligamentNode.stiffness = nAttr.create("stiffness", "stiff",
                                          om.MFnNumericData.kFloat, 1.0)
    nAttr.setMin(0)
    nAttr.keyable = False
    nAttr.array = True
    nAttr.storable = True
    nAttr.readable = True
    nAttr.writable = True
    om.MPxNode.addAttribute(ligamentNode.stiffness)
    ligamentNode.attributeAffects(ligamentNode.stiffness, ligamentNode.output)
    def initialize():
        # We need to create an instance of the Numeric Attribute Function set
        # This lets us in turn create numeric attributes
        nAttr = om.MFnNumericAttribute()

        # Lets start b defining our two input attributes
        # We assign this to an attribute on the class
        # The arguments in order are:
        # long name, short name, attribute type, default value
        # A double is like a float but with **double** the precision
        MinMaxNode.inputA = nAttr.create('inputA', 'ia', om.MFnNumericData.kDouble, 0.0)

        # After each attribute, we can then configure it
        # the nAttr object remembers the last object created
        nAttr.storable = True  # Allows us to store data on this plug
        nAttr.keyable = True  # Allows us to key it, but also needed to see in Node Editor

        # Finally we can do the same for the next attribute
        MinMaxNode.inputB = nAttr.create('inputB', 'ib', om.MFnNumericData.kDouble, 0.0)
        nAttr.storable = True
        nAttr.keyable = True

        # Then lets create our output in the same way
        MinMaxNode.output = nAttr.create('output', 'out', om.MFnNumericData.kDouble, 0.0)
        nAttr.storable = True
        nAttr.writable = True

        # We should also create our mode selection
        # This is a different type called enum
        eAttr = om.MFnEnumAttribute()
        MinMaxNode.mode = eAttr.create('mode', 'm')
        eAttr.addField('min', 0)
        eAttr.addField('max', 1)
        eAttr.storable = True

        # We then add our attributes to the node
        # Otherwise they won't show up
        MinMaxNode.addAttribute(MinMaxNode.inputA)
        MinMaxNode.addAttribute(MinMaxNode.inputB)
        MinMaxNode.addAttribute(MinMaxNode.mode)
        MinMaxNode.addAttribute(MinMaxNode.output)

        # Finally we need to tell our node which attributes affect the output of other attributes
        # If we don't do this then our attributes won't update dynamically
        # In this case both our inputs affect the output
        # Our mode selection will also affect it
        MinMaxNode.attributeAffects(MinMaxNode.inputA, MinMaxNode.output)
        MinMaxNode.attributeAffects(MinMaxNode.inputB, MinMaxNode.output)
        MinMaxNode.attributeAffects(MinMaxNode.mode, MinMaxNode.output)
Esempio n. 5
0
    def initialize():
        numericAttr = om.MFnNumericAttribute()
        compoundAttr = om.MFnCompoundAttribute()
        enumAttr = om.MFnEnumAttribute()

        # output
        prScalarMath.output = numericAttr.create('output', 'output',
                                                 om.MFnNumericData.kDouble)
        numericAttr.array = True
        numericAttr.usesArrayDataBuilder = True
        numericAttr.writable = False
        prScalarMath.addAttribute(prScalarMath.output)

        # input
        prScalarMath.operation = enumAttr.create('operation', 'operation', 3)
        enumAttr.keyable = True
        # operation names from maya nodes (plusMinusAverage, multiplyDivide)
        enumAttr.addField('No operation', 0)
        enumAttr.addField('Sum +', 1)
        enumAttr.addField('Subtract -', 2)
        enumAttr.addField('Average', 3)
        enumAttr.addField('Multiply *', 4)
        enumAttr.addField('Divide /', 5)
        enumAttr.addField('Power ^', 6)
        enumAttr.addField('Root', 7)
        enumAttr.addField('Floor division //', 8)
        enumAttr.addField('Modulus %', 9)
        prScalarMath.addAttribute(prScalarMath.operation)
        prScalarMath.attributeAffects(prScalarMath.operation,
                                      prScalarMath.output)

        prScalarMath.input1 = numericAttr.create('input1', 'input1',
                                                 om.MFnNumericData.kDouble,
                                                 0.0)
        numericAttr.keyable = True

        prScalarMath.input2 = numericAttr.create('input2', 'input2',
                                                 om.MFnNumericData.kDouble,
                                                 1.0)
        numericAttr.keyable = True

        prScalarMath.input = compoundAttr.create('input', 'input')
        compoundAttr.addChild(prScalarMath.input1)
        compoundAttr.addChild(prScalarMath.input2)
        compoundAttr.array = True
        prScalarMath.addAttribute(prScalarMath.input)
        prScalarMath.attributeAffects(prScalarMath.input1, prScalarMath.output)
        prScalarMath.attributeAffects(prScalarMath.input2, prScalarMath.output)
Esempio n. 6
0
def makeBindAttr(nodeClass, name="bind", extras=None):
    """ create the default 'off, bind, bound' attr
	found on most nodes
	:param nodeClass : the node class to receive the attribute
	:type nodeClass : om.MPxNode
	:param extras : string list of bind options -
		'off, bind, bound' are always default and first
	"""
    bindFn = om.MFnEnumAttribute()
    nodeClass.aBind = bindFn.create(name, name, 1)
    extras = extras or []
    for i, val in enumerate(["off", "bind", "bound"] + extras):
        bindFn.addField(val, i)
    bindFn.keyable = True
    bindFn.hidden = False
    return nodeClass.aBind
    def initialize():
        eAttr = om.MFnEnumAttribute()
        CustomLocator.shape = eAttr.create('shape', 's')
        eAttr.storable = True

        # We can simply add shapes from the dictionary above
        for i, shape in enumerate(shapeNames):
            eAttr.addField(shape, i)

        CustomLocator.addAttribute(CustomLocator.shape)

        # Now add the color attribute
        nAttr = om.MFnNumericAttribute()
        CustomLocator.color = nAttr.createColor('color', 'col')
        nAttr.default = (0.5, 0.1, 0.1)
        nAttr.storable = True

        CustomLocator.addAttribute(CustomLocator.color)
Esempio n. 8
0
    def initialize():
        unitFn = om.MFnUnitAttribute()
        numericFn = om.MFnNumericAttribute()
        enumFn = om.MFnEnumAttribute()
        messageFn = om.MFnMessageAttribute()

        ######VECTOR
        drawVector.sourcePt = numericFn.createPoint('sourcePoint', 'sp')
        drawVector.aimPt = numericFn.createPoint('aimPoint', 'ap')
        drawVector.drawMessage = messageFn.create('drawMessage', 'drawMessage')
        drawVector.lineColor = numericFn.createColor('color', 'color')
        drawVector.lineWidth = numericFn.create('width', 'width',
                                                om.MFnNumericData.kFloat, 2.0)

        ######VECTOR
        om.MPxNode.addAttribute(drawVector.sourcePt)
        om.MPxNode.addAttribute(drawVector.aimPt)
        om.MPxNode.addAttribute(drawVector.drawMessage)
        om.MPxNode.addAttribute(drawVector.lineColor)
        om.MPxNode.addAttribute(drawVector.lineWidth)
Esempio n. 9
0
def plugDefault(plug):
    obj = plug.attribute()
    if obj.hasFn(om2.MFn.kNumericAttribute):
        attr = om2.MFnNumericAttribute(obj)
        return attr.default
    elif obj.hasFn(om2.MFn.kTypedAttribute):
        attr = om2.MFnTypedAttribute(obj)
        default = attr.default
        if default.apiType() == om2.MFn.kInvalid:
            return None
        elif default.apiType() == om2.MFn.kStringData:
            return om2.MFnStringData(default).string()
        return default
    elif obj.hasFn(om2.MFn.kUnitAttribute):
        attr = om2.MFnUnitAttribute(obj)
        return attr.default
    elif obj.hasFn(om2.MFn.kEnumAttribute):
        attr = om2.MFnEnumAttribute(obj)
        return attr.default
    return None
Esempio n. 10
0
def setPlugDefault(plug, default):
    obj = plug.attribute()
    if obj.hasFn(om2.MFn.kNumericAttribute):
        attr = om2.MFnNumericAttribute(obj)
        Type = attr.numericType()
        attr.default = tuple(default) if Type in (
            om2.MFnNumericData.k2Double, om2.MFnNumericData.k3Double,
            om2.MFnNumericData.k4Double) else default
        return True
    elif obj.hasFn(om2.MFn.kTypedAttribute):
        if not isinstance(default, om2.MObject):
            raise ValueError(
                "Wrong type passed to MFnTypeAttribute must be on type MObject, received : {}"
                .format(type(default)))
        attr = om2.MFnTypedAttribute(obj)
        attr.default = default
        return True
    elif obj.hasFn(om2.MFn.kUnitAttribute):
        if not isinstance(default, (om2.MAngle, om2.MDistance, om2.MTime)):
            raise ValueError(
                "Wrong type passed to MFnUnitAttribute must be on type MAngle,MDistance or MTime, received : {}"
                .format(type(default)))
        attr = om2.MFnUnitAttribute(obj)
        attr.default = default
        return True
    elif obj.hasFn(om2.MFn.kMatrixAttribute):
        attr = om2.MFnMatrixAttribute(obj)
        attr.default = default
        return True
    elif obj.hasFn(om2.MFn.kEnumAttribute):
        if not isinstance(default, (int, str)):
            raise ValueError(
                "Wrong type passed to MFnEnumAttribute must be on type int or float, received : {}"
                .format(type(default)))
        attr = om2.MFnEnumAttribute(obj)
        if isinstance(default, int):
            attr.default = default
        else:
            attr.setDefaultByName(default)
        return True
    return False
Esempio n. 11
0
def enumNames(plug):
    """Returns the 'plug' enumeration field names.

    :param plug: the MPlug to query
    :type plug: om2.MPlug
    :return: A sequence of enum names
    :rtype: list(str)
    """
    obj = plug.attribute()
    enumoptions = []
    if obj.hasFn(om2.MFn.kEnumAttribute):
        attr = om2.MFnEnumAttribute(obj)
        min = attr.getMin()
        max = attr.getMax()
        for i in xrange(min, max + 1):
            # enums can be a bit screwed, i.e 5 options but max 10
            try:
                enumoptions.append(attr.fieldName(i))
            except:
                pass
    return enumoptions
Esempio n. 12
0
def set_space(nodes, space_name):
    """Set the given nodes to the given existing space.

    Args:
        nodes: Maya API objects to set to given space
        space_name: space name to switch nodes into
    """
    for node in nodes:
        dep_node = om2.MFnDependencyNode(node)
        node_full_name = dep_node.absoluteName()
        attr = om2.MFnEnumAttribute(dep_node.attribute('spaces'))
        space_index = attr.fieldValue(space_name)

        world_position = cmds.xform(node_full_name, q=True, ws=True, t=True)
        world_rotation = cmds.xform(node_full_name, q=True, ws=True, ro=True)

        dep_node.findPlug('spaces', True).setInt(space_index)
        cmds.setAttr('{0}.spaces'.format(node_full_name), space_index)

        cmds.xform(node_full_name, ws=True, t=world_position)
        cmds.xform(node_full_name, ws=True, ro=world_rotation)
Esempio n. 13
0
 def create_attr(self, attrs):
     if attrs[0] == "dofSep" or attrs[0] == "fovSep":
         field_dict = {"dofSep": "DoF", "fovSep": "FoV"}
         fn = OpenMaya.MFnEnumAttribute()
         attr = fn.create(attrs[0], attrs[1], 0)
         fn.addField(field_dict[attrs[0]], 0)
         fn.keyable = True
         fn.setNiceNameOverride("----------")
         return attr
     fn = OpenMaya.MFnNumericAttribute()
     attr = fn.create(attrs[0], attrs[1], OpenMaya.MFnNumericData.kFloat,
                      self.defaults[attrs[0]])
     if attrs[0] == "fov":
         fn.setMax(180)
         fn.setNiceNameOverride("FoV")
     else:
         fn.setMax(1000)
     fn.setMin(0)
     if attrs[0] == "oldWidth" or attrs[0] == "oldMid":
         fn.keyable = False
     else:
         fn.keyable = True
     return attr
Esempio n. 14
0
    def initialize(cls):
        nAttr = om.MFnNumericAttribute()
        enumAttr = om.MFnEnumAttribute()
        matAttr = om.MFnMatrixAttribute()
        uAttr = om.MFnUnitAttribute()
        typedAttr = om.MFnTypedAttribute()

        cls.shapeAttr = enumAttr.create('shape', 'sh', 0)
        enumAttr.addField('Custom', -1)
        for idx, shape in enumerate(shapes):
            enumAttr.addField(shape['name'], idx)
        enumAttr.channelBox = True
        cls.addAttribute(cls.shapeAttr)

        cls.customMeshAttr = typedAttr.create("inCustomMesh", "icm",
                                              om.MFnMeshData.kMesh)
        typedAttr.storable = False
        # The kReset constant is missing from the Python 2.0 API.
        typedAttr.disconnectBehavior = 1
        cls.addAttribute(cls.customMeshAttr)

        cls.transformAttr = matAttr.create('transform', 't',
                                           om.MFnMatrixAttribute.kFloat)
        matAttr.keyable = False
        cls.addAttribute(cls.transformAttr)

        localRotateX = uAttr.create('localRotateX', 'lrx',
                                    om.MFnUnitAttribute.kAngle, 0.0)
        localRotateY = uAttr.create('localRotateY', 'lry',
                                    om.MFnUnitAttribute.kAngle, 0.0)
        localRotateZ = uAttr.create('localRotateZ', 'lrz',
                                    om.MFnUnitAttribute.kAngle, 0.0)
        cls.localRotateAttr = nAttr.create('localRotate', 'lr', localRotateX,
                                           localRotateY, localRotateZ)
        nAttr.channelBox = True
        nAttr.keyable = False
        cls.addAttribute(cls.localRotateAttr)

        cls.localTranslateAttr = nAttr.createPoint('localPosition', 'lp')
        nAttr.channelBox = True
        nAttr.keyable = False
        cls.addAttribute(cls.localTranslateAttr)

        localScaleX = nAttr.create('localScaleX', 'lsx',
                                   om.MFnNumericData.kFloat, 1)
        localScaleY = nAttr.create('localScaleY', 'lsy',
                                   om.MFnNumericData.kFloat, 1)
        localScaleZ = nAttr.create('localScaleZ', 'lsz',
                                   om.MFnNumericData.kFloat, 1)
        cls.localScaleAttr = nAttr.create('localScale', 'ls', localScaleX,
                                          localScaleY, localScaleZ)
        nAttr.channelBox = True
        nAttr.keyable = False
        cls.addAttribute(cls.localScaleAttr)

        cls.colorAttr = nAttr.createColor('color', 'dc')
        nAttr.default = (.38, 0, 0.02)
        cls.addAttribute(cls.colorAttr)

        cls.alphaAttr = nAttr.create('alpha', 'a', om.MFnNumericData.kFloat,
                                     0.333)
        nAttr.setSoftMin(0)
        nAttr.setSoftMax(1)
        nAttr.keyable = False
        cls.addAttribute(cls.alphaAttr)

        cls.borderColorAttr = nAttr.createColor('borderColor', 'bc')
        nAttr.default = (-1, -1, -1)
        cls.addAttribute(cls.borderColorAttr)

        cls.borderAlphaAttr = nAttr.create('borderAlpha', 'ba',
                                           om.MFnNumericData.kFloat, 1)
        nAttr.setSoftMin(0)
        nAttr.setSoftMax(1)
        nAttr.keyable = False
        cls.addAttribute(cls.borderAlphaAttr)

        cls.xrayAttr = nAttr.create('xray', 'xr', om.MFnNumericData.kBoolean,
                                    True)
        nAttr.keyable = False
        nAttr.channelBox = True
        cls.addAttribute(cls.xrayAttr)
Esempio n. 15
0
    def initialize():
        numeric_attribute = om.MFnNumericAttribute()
        enum_attribute = om.MFnEnumAttribute()
        compound_attribute = om.MFnCompoundAttribute()

        # OUTPUT
        prPyMath.result = numeric_attribute.create("result", "result", om.MFnNumericData.kFloat, 0.0)
        numeric_attribute.writable = False
        prPyMath.addAttribute(prPyMath.result)

        prPyMath.result1 = numeric_attribute.create("result1", "result1", om.MFnNumericData.kFloat, 0.0)
        numeric_attribute.writable = False
        prPyMath.addAttribute(prPyMath.result1)

        # DATA
        prPyMath.e = numeric_attribute.create('e', 'e', om.MFnNumericData.kFloat, math.e)
        numeric_attribute.keyable = False
        prPyMath.addAttribute(prPyMath.e)

        prPyMath.pi = numeric_attribute.create('pi', 'pi', om.MFnNumericData.kFloat, math.pi)
        numeric_attribute.keyable = False
        prPyMath.addAttribute(prPyMath.pi)

        # FUNCTIONS
        prPyMath.func = enum_attribute.create("function", "function", 0)
        for index, data in get_math_function_data().iteritems():
            enum_attribute.addField(data['name'], index)
        enum_attribute.keyable = True
        prPyMath.addAttribute(prPyMath.func)
        prPyMath.attributeAffects(prPyMath.func, prPyMath.result)
        prPyMath.attributeAffects(prPyMath.func, prPyMath.result1)

        # ARGUMENTS
        prPyMath.x = numeric_attribute.create('x', 'x', om.MFnNumericData.kFloat, 0.0)
        numeric_attribute.keyable = True
        prPyMath.addAttribute(prPyMath.x)
        prPyMath.attributeAffects(prPyMath.x, prPyMath.result)
        prPyMath.attributeAffects(prPyMath.x, prPyMath.result1)

        prPyMath.y = numeric_attribute.create('y', 'y', om.MFnNumericData.kFloat, 0.0)
        numeric_attribute.keyable = True
        prPyMath.addAttribute(prPyMath.y)
        prPyMath.attributeAffects(prPyMath.y, prPyMath.result)

        prPyMath.i = numeric_attribute.create('i', 'i', om.MFnNumericData.kInt, 0.0)
        numeric_attribute.keyable = True
        prPyMath.addAttribute(prPyMath.i)
        prPyMath.attributeAffects(prPyMath.i, prPyMath.result)

        prPyMath.base = numeric_attribute.create('base', 'base', om.MFnNumericData.kFloat, math.e)
        numeric_attribute.keyable = True
        prPyMath.addAttribute(prPyMath.base)
        prPyMath.attributeAffects(prPyMath.base, prPyMath.result)

        prPyMath.iterable = numeric_attribute.create('iterable', 'iterable', om.MFnNumericData.kFloat)
        numeric_attribute.array = True
        numeric_attribute.keyable = True
        prPyMath.addAttribute(prPyMath.iterable)
        prPyMath.attributeAffects(prPyMath.iterable, prPyMath.result)

        prPyMath.arguments = compound_attribute.create('arguments', 'arguments')
        compound_attribute.addChild(prPyMath.x)
        compound_attribute.addChild(prPyMath.y)
        compound_attribute.addChild(prPyMath.i)
        compound_attribute.addChild(prPyMath.base)
        compound_attribute.addChild(prPyMath.iterable)
        prPyMath.addAttribute(prPyMath.arguments)

        # UTILITY
        prPyMath.ignore_errors = numeric_attribute.create('ignore_errors', 'ignore_errors', om.MFnNumericData.kBoolean, False)
        numeric_attribute.keyable = True
        prPyMath.addAttribute(prPyMath.ignore_errors)
Esempio n. 16
0
    def initialize(cls):
        nAttr = OpenMaya.MFnNumericAttribute()
        tAttr = OpenMaya.MFnTypedAttribute()
        enumAttr = OpenMaya.MFnEnumAttribute()
        compAttr = OpenMaya.MFnCompoundAttribute()
        matrixAttr = OpenMaya.MFnMatrixAttribute()
        messageAttr = OpenMaya.MFnMessageAttribute()

        cls.boundingBoxCorner1 = nAttr.create("boundingBoxCorner1", "bb1", OpenMaya.MFnNumericData.k3Double, 0)
        nAttr.keyable = False
        cls.addAttribute(cls.boundingBoxCorner1)
        cls.boundingBoxCorner2 = nAttr.create("boundingBoxCorner2", "bb2", OpenMaya.MFnNumericData.k3Double, 0)
        nAttr.keyable = False
        cls.addAttribute(cls.boundingBoxCorner2)

        cls.forgeID = tAttr.create("forgeID", "fid", OpenMaya.MFnData.kString, OpenMaya.MObject.kNullObj)
        cls.addAttribute(cls.forgeID)

        cls.handleMatrix = matrixAttr.create("handleMatrix", "hm", OpenMaya.MFnMatrixAttribute.kDouble)
        cls.addAttribute(cls.handleMatrix)

        cls.guideInverseScale = nAttr.create("guideInverseScale", "gis", OpenMaya.MFnNumericData.k3Double, 1.0)
        cls.addAttribute(cls.guideInverseScale)

        cls.guide = messageAttr.create("guide", "g")
        cls.addAttribute(cls.guide)

        cls.parentHandle = messageAttr.create("parentHandle", "ph")
        cls.addAttribute(cls.parentHandle)

        cls.parentHandleMatrix = matrixAttr.create("parentHandleMatrix", "phm", OpenMaya.MFnMatrixAttribute.kDouble)
        cls.addAttribute(cls.parentHandleMatrix)

        cls.childHandle = messageAttr.create("childHandle", "ch")
        messageAttr.array = True
        cls.addAttribute(cls.childHandle)

        cls.childHandleMatrix = matrixAttr.create("childHandleMatrix", "chm", OpenMaya.MFnMatrixAttribute.kDouble)
        matrixAttr.array = True
        cls.addAttribute(cls.childHandleMatrix)

        cls.orientTarget = messageAttr.create("orientTarget", "ot")
        cls.addAttribute(cls.orientTarget)

        cls.orientTargetMatrix = matrixAttr.create("orientTargetMatrix", "otm", OpenMaya.MFnMatrixAttribute.kDouble)
        cls.addAttribute(cls.orientTargetMatrix)

        cls.childPosition = nAttr.create("childPosition", "cpos", OpenMaya.MFnNumericData.k3Double, 0)
        nAttr.array = True
        nAttr.usesArrayDataBuilder = True
        cls.addAttribute(cls.childPosition)

        cls.jointRotateOrder = enumAttr.create("jointRotateOrder", "jro", 0)
        enumAttr.addField("xyz", 0)
        enumAttr.addField("yzx", 1)
        enumAttr.addField("zxy", 2)
        enumAttr.addField("xzy", 3)
        enumAttr.addField("yxz", 4)
        enumAttr.addField("zyx", 5)
        enumAttr.keyable = False
        cls.addAttribute(cls.jointRotateOrder)

        cls.jointSide = enumAttr.create("jointSide", "js", 0)
        enumAttr.addField("center", 0)
        enumAttr.addField("left", 1)
        enumAttr.addField("right", 2)
        enumAttr.addField("none", 3)
        enumAttr.keyable = True
        cls.addAttribute(cls.jointSide)

        cls.jointExcludeFromBind = nAttr.create("jointExcludeFromBind", "jeb", OpenMaya.MFnNumericData.kBoolean, 0)
        cls.addAttribute(cls.jointExcludeFromBind)

        cls.aimAxis = enumAttr.create("aimAxis", "aa", 0)
        enumAttr.addField("X", 0)
        enumAttr.addField("Y", 1)
        enumAttr.addField("Z", 2)
        enumAttr.addField("-X", 3)
        enumAttr.addField("-Y", 4)
        enumAttr.addField("-Z", 5)
        enumAttr.keyable = False
        cls.addAttribute(cls.aimAxis)

        cls.upAxis = enumAttr.create("upAxis", "ua", 2)
        enumAttr.addField("X", 0)
        enumAttr.addField("Y", 1)
        enumAttr.addField("Z", 2)
        enumAttr.addField("-X", 3)
        enumAttr.addField("-Y", 4)
        enumAttr.addField("-Z", 5)
        enumAttr.keyable = False
        cls.addAttribute(cls.upAxis)

        cls.aimVector = nAttr.create("aimVector", "av", OpenMaya.MFnNumericData.k3Double)
        cls.addAttribute(cls.aimVector)

        cls.upVector = nAttr.create("upVector", "uv", OpenMaya.MFnNumericData.k3Double)
        cls.addAttribute(cls.upVector)

        cls.useGuideAim = nAttr.create("useGuideAim", "uga", OpenMaya.MFnNumericData.kBoolean)
        cls.addAttribute(cls.useGuideAim)

        cls.jointMatrix = matrixAttr.create("jointMatrix", "jm", OpenMaya.MFnMatrixAttribute.kDouble)
        cls.addAttribute(cls.jointMatrix)

        cls.handleColor = nAttr.createColor("handleColor", "hc")
        cls.addAttribute(cls.handleColor)

        cls.handleStyle = enumAttr.create("handleStyle", "hs", 0)
        enumAttr.addField("basic", 0)
        enumAttr.addField("spine", 1)
        enumAttr.addField("limb", 2)
        enumAttr.addField("limb base", 3)
        enumAttr.addField("limb hinge", 4)
        enumAttr.addField("limb end", 5)
        enumAttr.addField("free", 6)
        enumAttr.addField("world", 7)
        cls.addAttribute(cls.handleStyle)

        cls.attributeAffects(cls.handleMatrix, cls.boundingBoxCorner1)
        cls.attributeAffects(cls.handleMatrix, cls.boundingBoxCorner2)
        cls.attributeAffects(cls.handleMatrix, cls.childPosition)
        cls.attributeAffects(cls.childHandleMatrix, cls.boundingBoxCorner1)
        cls.attributeAffects(cls.childHandleMatrix, cls.boundingBoxCorner2)
        cls.attributeAffects(cls.childHandleMatrix, cls.childPosition)
        cls.attributeAffects(cls.handleStyle, cls.boundingBoxCorner1)
        cls.attributeAffects(cls.handleStyle, cls.boundingBoxCorner2)

        cls.attributeAffects(cls.handleMatrix, cls.jointMatrix)
        cls.attributeAffects(cls.orientTargetMatrix, cls.jointMatrix)
        cls.attributeAffects(cls.parentHandleMatrix, cls.jointMatrix)
        cls.attributeAffects(cls.aimAxis, cls.jointMatrix)
        cls.attributeAffects(cls.upAxis, cls.jointMatrix)
        cls.attributeAffects(cls.aimVector, cls.jointMatrix)
        cls.attributeAffects(cls.upVector, cls.jointMatrix)
        cls.attributeAffects(cls.useGuideAim, cls.jointMatrix)
Esempio n. 17
0
    def initialize():
        """
        Defines the set of attributes for our node. The attributes
        declared in this function are assigned as static members to our
        depthShader class. Instances of ReflectionLocatorNode will use these attributes
        to create plugs for use in the compute() method.
        :return:
        """
        eAttr = OpenMaya.MFnEnumAttribute()
        nAttr = OpenMaya.MFnNumericAttribute()
        mAttr = OpenMaya.MFnMatrixAttribute()

        # plane shape
        ReflectionLocatorNode.ui_type = eAttr.create("locatorShape", "ls", 0)
        eAttr.addField("rect", 1)
        eAttr.addField("locator", 2)
        eAttr.addField("circle", 3)
        eAttr.default = 2
        ReflectionLocatorNode.addAttribute(ReflectionLocatorNode.ui_type)

        # creates a vector attribute
        global defaultOutputPoint
        ReflectionLocatorNode.output_point = nAttr.create(
            'output', 'out', OpenMaya.MFnNumericData.k3Double)
        nAttr.storable = False
        nAttr.hidden = False
        nAttr.default = (defaultOutputPoint[0], defaultOutputPoint[1],
                         defaultOutputPoint[2])
        ReflectionLocatorNode.addAttribute(ReflectionLocatorNode.output_point)

        # creates a vector attribute
        global defaultInputPoint
        ReflectionLocatorNode.input_point = nAttr.create(
            'input', 'in', OpenMaya.MFnNumericData.k3Double)
        nAttr.storable = True
        nAttr.hidden = False
        nAttr.keyable = True
        nAttr.default = (defaultInputPoint[0], defaultInputPoint[1],
                         defaultInputPoint[2])
        ReflectionLocatorNode.addAttribute(ReflectionLocatorNode.input_point)
        ReflectionLocatorNode.attributeAffects(
            ReflectionLocatorNode.input_point,
            ReflectionLocatorNode.output_point)

        # create a matrix attribute
        ReflectionLocatorNode.plane_matrix = mAttr.create(
            "planeMatrix", "planeMatrix")
        ReflectionLocatorNode.addAttribute(ReflectionLocatorNode.plane_matrix)
        ReflectionLocatorNode.attributeAffects(
            ReflectionLocatorNode.plane_matrix,
            ReflectionLocatorNode.output_point)

        # create a reflected parentInverse attribute
        ReflectionLocatorNode.parent_inverse = mAttr.create(
            "reflectedParentInverse", "rpi")
        ReflectionLocatorNode.addAttribute(
            ReflectionLocatorNode.parent_inverse)
        ReflectionLocatorNode.attributeAffects(
            ReflectionLocatorNode.parent_inverse,
            ReflectionLocatorNode.output_point)

        # create a line width attribute to change the width of a line drawing
        global defaultLineWidth
        ReflectionLocatorNode.line_width = nAttr.create(
            "lineWidth", "lw", OpenMaya.MFnNumericData.kFloat,
            defaultLineWidth)
        nAttr.setMin(0.0)
        nAttr.storable = False
        nAttr.keyable = True
        ReflectionLocatorNode.addAttribute(ReflectionLocatorNode.line_width)

        # create a color attribute
        global defaultPlaneColor
        ReflectionLocatorNode.plane_color = nAttr.createColor(
            'planeColor', 'pc')
        nAttr.storable = True
        nAttr.default = (defaultPlaneColor[0], defaultPlaneColor[1],
                         defaultPlaneColor[2])
        ReflectionLocatorNode.addAttribute(ReflectionLocatorNode.plane_color)

        # create a scale attribute
        global defaultScaleValue
        ReflectionLocatorNode.scale = nAttr.create(
            "scale", "scale", OpenMaya.MFnNumericData.kDouble,
            defaultScaleValue)
        nAttr.keyable = True
        ReflectionLocatorNode.addAttribute(ReflectionLocatorNode.scale)
        ReflectionLocatorNode.attributeAffects(
            ReflectionLocatorNode.scale, ReflectionLocatorNode.output_point)
Esempio n. 18
0
    def initialize(cls):
        fnUnit = api.MFnUnitAttribute()
        fnNumeric = api.MFnNumericAttribute()
        fnEnum = api.MFnEnumAttribute()

        cls.aMethod = fnEnum.create('method', 'met')
        fnEnum.addField('Stereographic Projection', 0)
        fnEnum.addField('Exponential Map', 1)
        cls.addAttribute(cls.aMethod)

        cls.aReverseOrder = fnNumeric.create('reverseOrder', 'ror',
                                             api.MFnNumericData.kBoolean,
                                             False)
        cls.addAttribute(cls.aReverseOrder)

        cls.aRotateX = fnUnit.create('rotateX', 'rx',
                                     api.MFnUnitAttribute.kAngle, 0.)
        cls.aRotateY = fnUnit.create('rotateY', 'ry',
                                     api.MFnUnitAttribute.kAngle, 0.)
        cls.aRotateZ = fnUnit.create('rotateZ', 'rz',
                                     api.MFnUnitAttribute.kAngle, 0.)
        cls.aRotate = fnNumeric.create('rotate', 'r', cls.aRotateX,
                                       cls.aRotateY, cls.aRotateZ)
        cls.addAttribute(cls.aRotate)

        cls.aRotateOrder = fnEnum.create('rotateOrder', 'ro')
        fnEnum.addField('xyz', 0)
        fnEnum.addField('yzx', 1)
        fnEnum.addField('zxy', 2)
        fnEnum.addField('xzy', 3)
        fnEnum.addField('yxz', 4)
        fnEnum.addField('zyx', 5)
        cls.addAttribute(cls.aRotateOrder)

        cls.aAxisOrientX = fnUnit.create('axisOrientX', 'aox',
                                         api.MFnUnitAttribute.kAngle, 0.)
        cls.aAxisOrientY = fnUnit.create('axisOrientY', 'aoy',
                                         api.MFnUnitAttribute.kAngle, 0.)
        cls.aAxisOrientZ = fnUnit.create('axisOrientZ', 'aoz',
                                         api.MFnUnitAttribute.kAngle, 0.)
        cls.aAxisOrient = fnNumeric.create('axisOrient', 'ao',
                                           cls.aAxisOrientX, cls.aAxisOrientY,
                                           cls.aAxisOrientZ)
        cls.addAttribute(cls.aAxisOrient)

        cls.aOutRoll = fnUnit.create('outRoll', 'orl',
                                     api.MFnUnitAttribute.kAngle, 0.)
        cls.aOutBendH = fnUnit.create('outBendH', 'obh',
                                      api.MFnUnitAttribute.kAngle, 0.)
        cls.aOutBendV = fnUnit.create('outBendV', 'obv',
                                      api.MFnUnitAttribute.kAngle, 0.)
        cls.aOutDecomposedAngle = fnNumeric.create('outDecomposedAngle', 'oda',
                                                   cls.aOutRoll, cls.aOutBendH,
                                                   cls.aOutBendV)
        fnNumeric.writable = False
        fnNumeric.storable = False
        cls.addAttribute(cls.aOutDecomposedAngle)

        cls.attributeAffects(cls.aMethod, cls.aOutDecomposedAngle)
        cls.attributeAffects(cls.aReverseOrder, cls.aOutDecomposedAngle)
        cls.attributeAffects(cls.aRotate, cls.aOutDecomposedAngle)
        cls.attributeAffects(cls.aRotateOrder, cls.aOutDecomposedAngle)
        cls.attributeAffects(cls.aAxisOrient, cls.aOutDecomposedAngle)
Esempio n. 19
0
    def initialize():

        numFn = om.MFnNumericAttribute()
        speedTracker.size = numFn.create("fontSize", "fs",
                                         om.MFnNumericData.kInt)
        numFn.default = 12.0
        numFn.storable = True
        numFn.readable = True
        numFn.writable = True
        numFn.keyable = True

        om.MPxNode.addAttribute(speedTracker.size)

        vectorFn = om.MFnNumericAttribute()
        speedTracker.input = vectorFn.createPoint('input', 'i')
        om.MPxNode.addAttribute(speedTracker.input)

        vectorFn = om.MFnNumericAttribute()
        speedTracker.parentPosition = vectorFn.createPoint(
            'parentPosition', 'pp')
        om.MPxNode.addAttribute(speedTracker.parentPosition)

        numFn = om.MFnNumericAttribute()
        speedTracker.output = numFn.create("output", "out",
                                           om.MFnNumericData.kFloat)
        om.MPxNode.addAttribute(speedTracker.output)

        speedTracker.attributeAffects(speedTracker.input, speedTracker.output)

        numFn = om.MFnNumericAttribute()
        speedTracker.fps = numFn.create("framesPerSecond", "fps",
                                        om.MFnNumericData.kFloat)
        numFn.default = 24.0
        numFn.storable = True
        numFn.readable = True
        numFn.writable = True
        numFn.keyable = True

        om.MPxNode.addAttribute(speedTracker.fps)
        speedTracker.attributeAffects(speedTracker.fps, speedTracker.output)

        enumAttr = om.MFnEnumAttribute()
        speedTracker.workingUnits = enumAttr.create("workingUnits", "wu")
        enumAttr.addField("cm", 0)
        enumAttr.addField("meter", 1)
        enumAttr.storable = True
        enumAttr.readable = True
        enumAttr.writable = True
        enumAttr.default = 0
        enumAttr.keyable = True
        om.MPxNode.addAttribute(speedTracker.workingUnits)
        speedTracker.attributeAffects(speedTracker.workingUnits,
                                      speedTracker.output)

        enumAttr = om.MFnEnumAttribute()
        speedTracker.timeUnits = enumAttr.create("timeUnits", "tu")
        enumAttr.addField("sec", 0)
        enumAttr.addField("min", 1)
        enumAttr.addField("hour", 2)
        enumAttr.storable = True
        enumAttr.readable = True
        enumAttr.writable = True
        enumAttr.default = 0
        enumAttr.keyable = True
        om.MPxNode.addAttribute(speedTracker.timeUnits)
        speedTracker.attributeAffects(speedTracker.timeUnits,
                                      speedTracker.output)

        enumAttr = om.MFnEnumAttribute()
        speedTracker.scaleUnits = enumAttr.create("scaleUnits", "su")
        enumAttr.addField("mm", 0)
        enumAttr.addField("cm", 1)
        enumAttr.addField("m", 2)
        enumAttr.addField("km", 3)
        enumAttr.default = 1
        enumAttr.storable = True
        enumAttr.readable = True
        enumAttr.writable = True
        enumAttr.keyable = True

        om.MPxNode.addAttribute(speedTracker.scaleUnits)
        speedTracker.attributeAffects(speedTracker.scaleUnits,
                                      speedTracker.output)
Esempio n. 20
0
    def initialize():
        numericAttr = om.MFnNumericAttribute()
        enumAttr = om.MFnEnumAttribute()
        compoundAttr = om.MFnCompoundAttribute()

        # OUTPUT
        prPyMath.result = numericAttr.create('result', 'result',
                                             om.MFnNumericData.kFloat, 0.0)
        numericAttr.storable = False
        numericAttr.writable = False
        prPyMath.addAttribute(prPyMath.result)

        prPyMath.result1 = numericAttr.create('result1', 'result1',
                                              om.MFnNumericData.kFloat, 0.0)
        numericAttr.storable = False
        numericAttr.writable = False
        prPyMath.addAttribute(prPyMath.result1)

        # DATA
        prPyMath.e = numericAttr.create('e', 'e', om.MFnNumericData.kFloat,
                                        math.e)
        numericAttr.storable = False
        numericAttr.writable = False
        prPyMath.addAttribute(prPyMath.e)

        prPyMath.pi = numericAttr.create('pi', 'pi', om.MFnNumericData.kFloat,
                                         math.pi)
        numericAttr.storable = False
        numericAttr.writable = False
        prPyMath.addAttribute(prPyMath.pi)

        # FUNCTIONS
        prPyMath.func = enumAttr.create('function', 'function', 0)
        for index, data in getMathFunctionData().iteritems():
            enumAttr.addField(data['name'], index)
        enumAttr.keyable = True
        prPyMath.addAttribute(prPyMath.func)
        prPyMath.attributeAffects(prPyMath.func, prPyMath.result)
        prPyMath.attributeAffects(prPyMath.func, prPyMath.result1)

        # ARGUMENTS
        prPyMath.x = numericAttr.create('x', 'x', om.MFnNumericData.kFloat,
                                        0.0)
        numericAttr.keyable = True
        prPyMath.addAttribute(prPyMath.x)
        prPyMath.attributeAffects(prPyMath.x, prPyMath.result)
        prPyMath.attributeAffects(prPyMath.x, prPyMath.result1)

        prPyMath.y = numericAttr.create('y', 'y', om.MFnNumericData.kFloat,
                                        0.0)
        numericAttr.keyable = True
        prPyMath.addAttribute(prPyMath.y)
        prPyMath.attributeAffects(prPyMath.y, prPyMath.result)

        prPyMath.i = numericAttr.create('i', 'i', om.MFnNumericData.kInt, 0.0)
        numericAttr.keyable = True
        prPyMath.addAttribute(prPyMath.i)
        prPyMath.attributeAffects(prPyMath.i, prPyMath.result)

        prPyMath.base = numericAttr.create('base', 'base',
                                           om.MFnNumericData.kFloat, math.e)
        numericAttr.keyable = True
        prPyMath.addAttribute(prPyMath.base)
        prPyMath.attributeAffects(prPyMath.base, prPyMath.result)

        prPyMath.iterable = numericAttr.create('iterable', 'iterable',
                                               om.MFnNumericData.kFloat)
        numericAttr.array = True
        prPyMath.addAttribute(prPyMath.iterable)
        prPyMath.attributeAffects(prPyMath.iterable, prPyMath.result)

        prPyMath.arguments = compoundAttr.create('arguments', 'arguments')
        compoundAttr.addChild(prPyMath.x)
        compoundAttr.addChild(prPyMath.y)
        compoundAttr.addChild(prPyMath.i)
        compoundAttr.addChild(prPyMath.base)
        compoundAttr.addChild(prPyMath.iterable)
        prPyMath.addAttribute(prPyMath.arguments)

        # UTILITY
        prPyMath.xDegreesToRadians = numericAttr.create(
            'xDegreesToRadians', 'xDegreesToRadians',
            om.MFnNumericData.kBoolean, False)
        prPyMath.addAttribute(prPyMath.xDegreesToRadians)
        prPyMath.attributeAffects(prPyMath.xDegreesToRadians, prPyMath.result)
        prPyMath.attributeAffects(prPyMath.xDegreesToRadians, prPyMath.result1)

        prPyMath.ignoreErrors = numericAttr.create('ignoreErrors',
                                                   'ignoreErrors',
                                                   om.MFnNumericData.kBoolean,
                                                   False)
        prPyMath.addAttribute(prPyMath.ignoreErrors)

        prPyMath.resultDefault = numericAttr.create('resultDefault',
                                                    'resultDefault',
                                                    om.MFnNumericData.kFloat,
                                                    0.0)
        prPyMath.addAttribute(prPyMath.resultDefault)
        prPyMath.attributeAffects(prPyMath.resultDefault, prPyMath.result)

        prPyMath.result1Default = numericAttr.create('result1Default',
                                                     'result1Default',
                                                     om.MFnNumericData.kFloat,
                                                     0.0)
        prPyMath.addAttribute(prPyMath.result1Default)
        prPyMath.attributeAffects(prPyMath.result1Default, prPyMath.result1)
Esempio n. 21
0
    def initialize(cls):
        typed_attr = OpenMaya.MFnTypedAttribute()
        numeric_attr = OpenMaya.MFnNumericAttribute()
        enum_attr = OpenMaya.MFnEnumAttribute()

        for text_attribute in cls.TEXT_ATTRIBUTES:
            string_data = OpenMaya.MFnStringData().create('Placeholder')
            attr = typed_attr.create(text_attribute, text_attribute,
                                     OpenMaya.MFnData.kString, string_data)
            cls.addAttribute(attr)

        cls.top_text_padding = numeric_attr.create(
            'top_text_padding', 'top_text_padding',
            OpenMaya.MFnNumericData.kInt, 20)
        cls.addAttribute(cls.top_text_padding)

        cls.bottom_text_padding = numeric_attr.create(
            'bottom_text_padding', 'bottom_text_padding',
            OpenMaya.MFnNumericData.kInt, 20)
        cls.addAttribute(cls.bottom_text_padding)

        cls.top_text_color = numeric_attr.createColor('top_text_color',
                                                      'top_text_color')
        numeric_attr.default = (1.0, 1.0, 1.0)
        cls.addAttribute(cls.top_text_color)

        cls.bottom_text_color = numeric_attr.createColor(
            'bottom_text_color', 'bottom_text_color')
        numeric_attr.default = (1.0, 1.0, 1.0)
        cls.addAttribute(cls.bottom_text_color)

        cls.top_text_alpha = numeric_attr.create(
            'top_text_alpha', 'top_text_alpha', OpenMaya.MFnNumericData.kFloat,
            1.0)
        numeric_attr.setMin(0.0)
        numeric_attr.setMax(1.0)
        cls.addAttribute(cls.top_text_alpha)

        cls.bottom_text_alpha = numeric_attr.create(
            'bottom_text_alpha', 'bottom_text_alpha',
            OpenMaya.MFnNumericData.kFloat, 1.0)
        numeric_attr.setMin(0.0)
        numeric_attr.setMax(1.0)
        cls.addAttribute(cls.bottom_text_alpha)

        cls.top_text_font_weight = enum_attr.create('top_text_font_weight',
                                                    'top_text_font_weight', 2)
        enum_attr.addField('Normal', 0)
        enum_attr.addField('DemiBold', 1)
        enum_attr.addField('Bold', 2)
        cls.addAttribute(cls.top_text_font_weight)

        cls.bottom_text_font_weight = enum_attr.create(
            'bottom_text_font_weight', 'bottom_text_font_weight', 2)
        enum_attr.addField('Normal', 0)
        enum_attr.addField('DemiBold', 1)
        enum_attr.addField('Bold', 2)
        cls.addAttribute(cls.bottom_text_font_weight)

        cls.top_text_scale = numeric_attr.create(
            'top_text_scale', 'top_text_scale', OpenMaya.MFnNumericData.kFloat,
            1.0)
        numeric_attr.setMin(0.2)
        numeric_attr.setMax(5.0)
        cls.addAttribute(cls.top_text_scale)

        cls.bottom_text_scale = numeric_attr.create(
            'bottom_text_scale', 'bottom_text_scale',
            OpenMaya.MFnNumericData.kFloat, 1.0)
        numeric_attr.setMin(0.2)
        numeric_attr.setMax(5.0)
        cls.addAttribute(cls.bottom_text_scale)

        cls.top_border_enabled = numeric_attr.create(
            'top_border_enabled', 'top_border_enabled',
            OpenMaya.MFnNumericData.kBoolean, True)
        cls.addAttribute(cls.top_border_enabled)

        cls.bottom_border_enabled = numeric_attr.create(
            'bottom_border_enabled', 'bottom_border_enabled',
            OpenMaya.MFnNumericData.kBoolean, True)
        cls.addAttribute(cls.bottom_border_enabled)

        cls.border_color = numeric_attr.createColor('border_color',
                                                    'border_color')
        numeric_attr.default = (0.0, 0.0, 0.0)
        cls.addAttribute(cls.border_color)

        cls.border_alpha = numeric_attr.create('border_alpha', 'border_alpha',
                                               OpenMaya.MFnNumericData.kFloat,
                                               1.0)
        numeric_attr.setMin(0.0)
        numeric_attr.setMax(1.0)
        cls.addAttribute(cls.border_alpha)

        cls.border_scale = numeric_attr.create('border_scale', 'border_scale',
                                               OpenMaya.MFnNumericData.kFloat,
                                               1.0)
        numeric_attr.setMin(0.5)
        numeric_attr.setMax(2.0)
        cls.addAttribute(cls.border_scale)

        cls.crop_enabled = numeric_attr.create(
            'crop_enabled', 'crop_enabled', OpenMaya.MFnNumericData.kBoolean,
            False)
        cls.addAttribute(cls.crop_enabled)

        cls.crop_preset = enum_attr.create('crop_preset', 'crop_preset', 0)
        enum_attr.addField('format', 0)
        enum_attr.addField('square', 1)
        enum_attr.addField('4:3', 2)
        enum_attr.addField('16:9', 3)
        enum_attr.addField('14:9', 4)
        enum_attr.addField('1.66:1', 5)
        enum_attr.addField('1.85:1', 6)
        enum_attr.addField('2.35:1', 7)
        cls.addAttribute(cls.crop_preset)

        cls.crop_use_custom = numeric_attr.create(
            'crop_use_custom', 'crop_use_custom',
            OpenMaya.MFnNumericData.kBoolean, False)
        cls.addAttribute(cls.crop_use_custom)

        cls.crop_custom_width = numeric_attr.create(
            'crop_custom_width', 'crop_custom_width',
            OpenMaya.MFnNumericData.kInt, 1920)
        cls.addAttribute(cls.crop_custom_width)

        cls.crop_custom_height = numeric_attr.create(
            'crop_custom_height', 'crop_custom_height',
            OpenMaya.MFnNumericData.kInt, 1080)
        cls.addAttribute(cls.crop_custom_height)

        cls.counter_position = numeric_attr.create(
            'counter_position', 'counter_position',
            OpenMaya.MFnNumericData.kInt, 6)
        numeric_attr.setMin(0)
        numeric_attr.setMax(6)
        cls.addAttribute(cls.counter_position)

        cls.counter_padding = numeric_attr.create('counter_padding',
                                                  'counter_padding',
                                                  OpenMaya.MFnNumericData.kInt,
                                                  4)
        numeric_attr.setMin(2)
        numeric_attr.setMax(6)
        cls.addAttribute(cls.counter_padding)

        cls.frame_offset = numeric_attr.create('frame_offset', 'frame_offset',
                                               OpenMaya.MFnNumericData.kInt, 0)
        cls.addAttribute(cls.frame_offset)

        cls.cut_frame_enabled = numeric_attr.create(
            'cut_frame_enabled', 'cut_frame_enabled',
            OpenMaya.MFnNumericData.kBoolean, False)
        cls.addAttribute(cls.cut_frame_enabled)

        cls.cut_in = numeric_attr.create('cut_in', 'cut_in',
                                         OpenMaya.MFnNumericData.kInt, 1001)
        cls.addAttribute(cls.cut_in)

        cls.cut_out = numeric_attr.create('cut_out', 'cut_out',
                                          OpenMaya.MFnNumericData.kInt, 1001)
        cls.addAttribute(cls.cut_out)

        cls.focal_length_position = numeric_attr.create(
            'focal_length_position', 'focal_length_position',
            OpenMaya.MFnNumericData.kInt, 6)
        numeric_attr.setMin(0)
        numeric_attr.setMax(6)
        cls.addAttribute(cls.focal_length_position)
Esempio n. 22
0
    def prepareForDraw(self, obj_path, camera_path, frame_context, old_data):
        data = old_data
        if not isinstance(data, MagicMaskData):
            data = MagicMaskData()

        mask_node = OpenMaya.MFnDagNode(obj_path)

        data.text_fields = []
        for attribute in MagicMaskNode.TEXT_ATTRIBUTES:
            data.text_fields.append(
                mask_node.findPlug(attribute, False).asString())

        data.top_text_padding = mask_node.findPlug('top_text_padding',
                                                   False).asInt()
        data.bottom_text_padding = mask_node.findPlug('bottom_text_padding',
                                                      False).asInt()
        data.top_text_scale = mask_node.findPlug('top_text_scale',
                                                 False).asFloat()
        data.bottom_text_scale = mask_node.findPlug('bottom_text_scale',
                                                    False).asFloat()

        top_text_color_r = mask_node.findPlug('top_text_colorR',
                                              False).asFloat()
        top_text_color_g = mask_node.findPlug('top_text_colorG',
                                              False).asFloat()
        top_text_color_b = mask_node.findPlug('top_text_colorB',
                                              False).asFloat()
        top_text_color_a = mask_node.findPlug('top_text_alpha',
                                              False).asFloat()
        data.top_text_color = OpenMaya.MColor(
            (top_text_color_r, top_text_color_g, top_text_color_b,
             top_text_color_a))
        top_text_font_weight_plug = mask_node.findPlug('top_text_font_weight',
                                                       False)
        top_text_font_weight_attr = OpenMaya.MFnEnumAttribute(
            top_text_font_weight_plug.attribute())
        data.top_text_font_weight = FONT_WEIGHT_MAP.get(
            top_text_font_weight_attr.fieldName(
                top_text_font_weight_plug.asShort()))

        bottom_text_color_r = mask_node.findPlug('bottom_text_colorR',
                                                 False).asFloat()
        bottom_text_color_g = mask_node.findPlug('bottom_text_colorG',
                                                 False).asFloat()
        bottom_text_color_b = mask_node.findPlug('bottom_text_colorB',
                                                 False).asFloat()
        bottom_text_color_a = mask_node.findPlug('bottom_text_alpha',
                                                 False).asFloat()
        data.bottom_text_color = OpenMaya.MColor(
            (bottom_text_color_r, bottom_text_color_g, bottom_text_color_b,
             bottom_text_color_a))
        bottom_text_font_weight_plug = mask_node.findPlug(
            'bottom_text_font_weight', False)
        bottom_text_font_weight_attr = OpenMaya.MFnEnumAttribute(
            bottom_text_font_weight_plug.attribute())
        data.bottom_text_font_weight = FONT_WEIGHT_MAP.get(
            bottom_text_font_weight_attr.fieldName(
                bottom_text_font_weight_plug.asShort()))

        border_color_r = mask_node.findPlug('border_colorR', False).asFloat()
        border_color_g = mask_node.findPlug('border_colorG', False).asFloat()
        border_color_b = mask_node.findPlug('border_colorB', False).asFloat()
        border_color_a = mask_node.findPlug('border_alpha', False).asFloat()
        data.border_color = OpenMaya.MColor(
            (border_color_r, border_color_g, border_color_b, border_color_a))

        counter_position = mask_node.findPlug('counter_position',
                                              False).asInt()
        if 0 <= counter_position < MagicMaskNode.TEXT_POSITION_NUMBER:
            offset_frame = mask_node.findPlug('frame_offset', False).asInt()
            counter_padding = mask_node.findPlug('counter_padding',
                                                 False).asInt()
            current_frame = int(OpenMayaAnim.MAnimControl.currentTime().value)
            end_frame = int(OpenMayaAnim.MAnimControl.maxTime().value)

            frame_string = '{0} / {1}'.format(
                str(current_frame + offset_frame).zfill(counter_padding),
                str(end_frame + offset_frame).zfill(counter_padding))
            cut_frame_enabled = mask_node.findPlug('cut_frame_enabled',
                                                   False).asBool()
            if cut_frame_enabled:
                cut_in = mask_node.findPlug('cut_in', False).asInt()
                cut_out = mask_node.findPlug('cut_out', False).asInt()
                cut_string = '{0}-{1}'.format(cut_in, cut_out)
                data.text_fields[counter_position] = '{0} | {1}'.format(
                    cut_string, frame_string)
            else:
                data.text_fields[counter_position] = frame_string

        data.top_border_enabled = mask_node.findPlug('top_border_enabled',
                                                     False).asBool()
        data.bottom_border_enabled = mask_node.findPlug(
            'bottom_border_enabled', False).asBool()
        data.border_scale = mask_node.findPlug('border_scale', False).asFloat()

        data.crop_enabled = mask_node.findPlug('crop_enabled', False).asBool()
        crop_preset_plug = mask_node.findPlug('crop_preset', False)
        crop_preset_attr = OpenMaya.MFnEnumAttribute(
            crop_preset_plug.attribute())
        data.crop_preset = CROP_MAP.get(
            crop_preset_attr.fieldName(crop_preset_plug.asShort()))
        data.crop_use_custom = mask_node.findPlug('crop_use_custom',
                                                  False).asBool()
        data.crop_custom_width = mask_node.findPlug('crop_custom_width',
                                                    False).asFloat()
        data.crop_custom_height = mask_node.findPlug('crop_custom_height',
                                                     False).asFloat()

        focal_length_position = mask_node.findPlug('focal_length_position',
                                                   False).asInt()
        if 0 <= focal_length_position < MagicMaskNode.TEXT_POSITION_NUMBER:
            camera_path = frame_context.getCurrentCameraPath()
            camera = OpenMaya.MFnCamera(camera_path)
            focal_length_string = 'Focal Length: %.2f' % camera.focalLength
            data.text_fields[focal_length_position] = focal_length_string

        return data
    def initialize():
        e_attr = om.MFnEnumAttribute()
        c_attr = om.MFnCompoundAttribute()
        n_attr = om.MFnNumericAttribute()

        AimConstaraintNode.aim_axis = e_attr.create("aim_axis", "axa", 0)
        # e_attr.setChannelBox(True)
        e_attr.keyable = False
        e_attr.addField("X", 0)
        e_attr.addField("Y", 1)
        e_attr.addField("Z", 2)

        mat_attr = om.MFnMatrixAttribute()
        AimConstaraintNode.input_aim_matrix = mat_attr.create(
            "input_aim_matrix", "iam")
        mat_attr.writable = True
        mat_attr.readable = False
        mat_attr.keyable = True

        AimConstaraintNode.input_target_parent_matrix = mat_attr.create(
            "input_target_parent_matrix", "itm")
        mat_attr.writable = True
        mat_attr.readable = False
        mat_attr.keyable = True

        AimConstaraintNode.input_target_position = c_attr.create(
            "input_target_position", "iapos")
        c_attr.writable = True
        c_attr.readable = False
        c_attr.keyable = True

        AimConstaraintNode.input_target_position_x = n_attr.create(
            "input_target_pos_x", "itposx", om.MFnNumericData.kFloat, 0.0)
        n_attr.writable = True
        c_attr.addChild(AimConstaraintNode.input_target_position_x)

        AimConstaraintNode.input_target_position_y = n_attr.create(
            "input_target_pos_y", "itposy", om.MFnNumericData.kFloat, 0.0)
        n_attr.writable = True
        c_attr.addChild(AimConstaraintNode.input_target_position_y)

        AimConstaraintNode.input_target_position_z = n_attr.create(
            "input_target_pos_z", "itposz", om.MFnNumericData.kFloat, 0.0)
        c_attr.addChild(AimConstaraintNode.input_target_position_z)
        n_attr.writable = True

        rotate_attr = om.MFnCompoundAttribute()
        AimConstaraintNode.output_rotate = rotate_attr.create(
            "output_rotate", "or")
        rotate_attr.writable = True

        rotate_unit_attr = om.MFnUnitAttribute()
        AimConstaraintNode.koAngles = [0, 0, 0]

        out_rotate_name = [
            "output_rotateX", "output_rotateY", "output_rotateZ"
        ]
        out_rotate_shortname = ["orx", "ory", "orz"]
        for _ in range(3):
            AimConstaraintNode.koAngles[_] = rotate_unit_attr.create(
                out_rotate_name[_], out_rotate_shortname[_],
                om.MFnUnitAttribute.kAngle, 0.0)
            rotate_unit_attr.writable = True
            rotate_attr.addChild(AimConstaraintNode.koAngles[_])

        AimConstaraintNode.addAttribute(AimConstaraintNode.aim_axis)
        AimConstaraintNode.addAttribute(AimConstaraintNode.input_aim_matrix)
        AimConstaraintNode.addAttribute(
            AimConstaraintNode.input_target_position)

        AimConstaraintNode.addAttribute(
            AimConstaraintNode.input_target_parent_matrix)
        AimConstaraintNode.addAttribute(AimConstaraintNode.output_rotate)

        AimConstaraintNode.attributeAffects(AimConstaraintNode.aim_axis,
                                            AimConstaraintNode.output_rotate)
        AimConstaraintNode.attributeAffects(
            AimConstaraintNode.input_aim_matrix,
            AimConstaraintNode.output_rotate)
        AimConstaraintNode.attributeAffects(
            AimConstaraintNode.input_target_parent_matrix,
            AimConstaraintNode.output_rotate)
        AimConstaraintNode.attributeAffects(
            AimConstaraintNode.input_target_position,
            AimConstaraintNode.output_rotate)
    def initialize():
        """Set up the attributes and other details of the node."""

        # Create the plug-in Attributes
        nAttr = OpenMaya.MFnNumericAttribute()
        tAttr = OpenMaya.MFnTypedAttribute()
        cAttr = OpenMaya.MFnCompoundAttribute()
        eAttr = OpenMaya.MFnEnumAttribute()
        gAttr = OpenMaya.MFnGenericAttribute()
        uAttr = OpenMaya.MFnUnitAttribute()

        # Input Point X
        VelocityNode.m_input_point_x = nAttr.create(
            "inputPointX", "ipx", OpenMaya.MFnNumericData.kDouble, 0.0)
        nAttr.storable = True
        nAttr.keyable = True
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point_x)

        # Input Point Y
        VelocityNode.m_input_point_y = nAttr.create(
            "inputPointY", "ipy", OpenMaya.MFnNumericData.kDouble, 0.0)
        nAttr.storable = True
        nAttr.keyable = True
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point_y)

        # Input Point Z
        VelocityNode.m_input_point_z = nAttr.create(
            "inputPointZ", "ipz", OpenMaya.MFnNumericData.kDouble, 0.0)
        nAttr.storable = True
        nAttr.keyable = True
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point_z)

        # Input Point (parent of input Point* attributes)
        VelocityNode.m_input_point = nAttr.create("inputPoint", "ip",
                                                  VelocityNode.m_input_point_x,
                                                  VelocityNode.m_input_point_y,
                                                  VelocityNode.m_input_point_z)
        nAttr.storable = True
        nAttr.keyable = True
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_input_point)

        # Time
        VelocityNode.m_time = uAttr.create("time", "time",
                                           OpenMaya.MFnUnitAttribute.kTime,
                                           0.0)
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_time)

        # Time Interval
        VelocityNode.m_time_interval = uAttr.create(
            "timeInterval", "timeInterval", OpenMaya.MFnUnitAttribute.kTime,
            1.0)
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_time_interval)

        # Frames Per-Second
        VelocityNode.m_frames_per_second = nAttr.create(
            "framesPerSecond", "framesPerSecond",
            OpenMaya.MFnNumericData.kDouble, 24.0)
        nAttr.storable = True
        nAttr.keyable = True
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_frames_per_second)

        # Text Precision
        VelocityNode.m_text_precision = nAttr.create(
            "textPrecision", "textPrecision", OpenMaya.MFnNumericData.kInt, 3)
        nAttr.storable = True
        nAttr.keyable = True
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_text_precision)

        # Unit Scale
        VelocityNode.m_unit_scale = eAttr.create("scale", "scale",
                                                 UNIT_SCALE_DECIMETER_VALUE)
        for name, value in UNIT_SCALES:
            eAttr.addField(name, value)
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_unit_scale)

        # Display Unit
        VelocityNode.m_display_unit = eAttr.create(
            "displayUnit", "displayUnit", DISPLAY_UNIT_KM_PER_HOUR_VALUE)
        for name, value in DISPLAY_UNITS:
            eAttr.addField(name, value)
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_display_unit)

        # Out Speed
        VelocityNode.m_out_speed = nAttr.create(
            "outSpeed", "outSpeed", OpenMaya.MFnNumericData.kDouble, 0.0)
        nAttr.storable = False
        nAttr.keyable = False
        nAttr.readable = True
        nAttr.writable = False
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_speed)

        # Out Speed
        VelocityNode.m_out_speed_raw = nAttr.create(
            "outSpeedRaw", "outSpeedRaw", OpenMaya.MFnNumericData.kDouble, 0.0)
        nAttr.storable = False
        nAttr.keyable = False
        nAttr.readable = True
        nAttr.writable = False
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_speed_raw)

        # Out Speed Text
        string_data = OpenMaya.MFnStringData()
        string_obj = string_data.create()
        VelocityNode.m_out_speed_text = tAttr.create("outSpeedText",
                                                     "outSpeedText",
                                                     OpenMaya.MFnData.kString,
                                                     string_obj)
        tAttr.storable = False
        tAttr.keyable = False
        tAttr.readable = True
        tAttr.writable = False
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_speed_text)

        # Out Dummy node
        #
        # The attribute is used to trigger this node to compute values.
        # The value itself is not set, it is only used to help trigger a
        # compute.
        VelocityNode.m_out_dummy_float = nAttr.create(
            "outDummyFloat", "outDummyNodeFloat",
            OpenMaya.MFnNumericData.kDouble, 0.0)
        nAttr.storable = False
        nAttr.keyable = False
        nAttr.readable = True
        nAttr.writable = False
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_dummy_float)

        # Out Dummy String
        #
        # The attribute is used to trigger this node to compute values.
        # The value itself is not set, it is only used to help trigger a
        # compute.
        string_data = OpenMaya.MFnStringData()
        string_obj = string_data.create()
        VelocityNode.m_out_dummy_string = tAttr.create(
            "outDummyString", "outDummyString", OpenMaya.MFnData.kString,
            string_obj)
        tAttr.storable = False
        tAttr.keyable = False
        tAttr.readable = True
        tAttr.writable = False
        OpenMaya.MPxNode.addAttribute(VelocityNode.m_out_dummy_string)

        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point,
                                          VelocityNode.m_out_speed)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point,
                                          VelocityNode.m_out_speed_raw)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point,
                                          VelocityNode.m_out_speed_text)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point,
                                          VelocityNode.m_out_dummy_float)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_input_point,
                                          VelocityNode.m_out_dummy_string)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time,
                                          VelocityNode.m_out_speed)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time,
                                          VelocityNode.m_out_speed_raw)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time,
                                          VelocityNode.m_out_speed_text)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time,
                                          VelocityNode.m_out_dummy_float)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time,
                                          VelocityNode.m_out_dummy_string)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval,
                                          VelocityNode.m_out_speed)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval,
                                          VelocityNode.m_out_speed_raw)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval,
                                          VelocityNode.m_out_speed_text)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval,
                                          VelocityNode.m_out_dummy_float)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_time_interval,
                                          VelocityNode.m_out_dummy_string)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second,
                                          VelocityNode.m_out_speed)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second,
                                          VelocityNode.m_out_speed_raw)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second,
                                          VelocityNode.m_out_speed_text)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second,
                                          VelocityNode.m_out_dummy_float)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_frames_per_second,
                                          VelocityNode.m_out_dummy_string)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_text_precision,
                                          VelocityNode.m_out_speed_text)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_text_precision,
                                          VelocityNode.m_out_dummy_string)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale,
                                          VelocityNode.m_out_speed)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale,
                                          VelocityNode.m_out_speed_raw)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale,
                                          VelocityNode.m_out_speed_text)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale,
                                          VelocityNode.m_out_dummy_float)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_unit_scale,
                                          VelocityNode.m_out_dummy_string)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit,
                                          VelocityNode.m_out_speed)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit,
                                          VelocityNode.m_out_speed_raw)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit,
                                          VelocityNode.m_out_speed_text)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit,
                                          VelocityNode.m_out_dummy_float)
        OpenMaya.MPxNode.attributeAffects(VelocityNode.m_display_unit,
                                          VelocityNode.m_out_dummy_string)
        return
Esempio n. 25
0
def nodeInitializer():
    # create attributes

    # pick your pointy poison
    solverAttrFn = om.MFnEnumAttribute()
    generalIk.aSolver = solverAttrFn.create("solver", "sol", 0)
    solverAttrFn.addField("CCD", 0)
    solverAttrFn.addField("FABRIK (not yet implemented)", 1)
    solverAttrFn.storable = True
    solverAttrFn.keyable = True
    solverAttrFn.readable = False
    solverAttrFn.writable = True
    om.MPxNode.addAttribute(generalIk.aSolver)

    iterAttrFn = om.MFnNumericAttribute()
    generalIk.aMaxIter = iterAttrFn.create("maxIterations", "mi",
                                           om.MFnNumericData.kLong, 30)
    iterAttrFn.storable = True
    iterAttrFn.keyable = True
    iterAttrFn.readable = False
    iterAttrFn.writable = True
    iterAttrFn.setMin(0)
    om.MPxNode.addAttribute(generalIk.aMaxIter)

    # how far will you go for perfection
    toleranceAttrFn = om.MFnNumericAttribute()
    generalIk.aTolerance = toleranceAttrFn.create("tolerance", "tol",
                                                  om.MFnNumericData.kDouble,
                                                  0.1)
    toleranceAttrFn.storable = True
    toleranceAttrFn.keyable = True
    toleranceAttrFn.readable = False
    toleranceAttrFn.writable = True
    toleranceAttrFn.setMin(0)
    om.MPxNode.addAttribute(generalIk.aTolerance)

    # weight of the world
    globalWeightAttrFn = om.MFnNumericAttribute()
    generalIk.aGlobalWeight = globalWeightAttrFn.create(
        "globalWeight", "globalWeight", om.MFnNumericData.kDouble, 0.8)
    globalWeightAttrFn.writable = True
    globalWeightAttrFn.keyable = True
    om.MPxNode.addAttribute(generalIk.aGlobalWeight)

    # let the past die?
    # cacheOnAttrFn = om.MFnNumericAttribute()
    # generalIk.aCacheOn = cacheOnAttrFn.create(
    # 	"cacheOn", "cacheOn", om.MFnNumericData.kBoolean, 1)
    # om.MPxNode.addAttribute(generalIk.aCacheOn)
    generalIk.aCacheOn = nodeio.makeBindAttr(generalIk, name="cache")
    om.MPxNode.addAttribute(generalIk.aCacheOn)

    # what are your goals in life
    targetMatAttrFn = om.MFnMatrixAttribute()
    generalIk.aTargetMat = targetMatAttrFn.create("targetMatrix", "targetMat",
                                                  1)
    targetMatAttrFn.storable = True
    targetMatAttrFn.readable = False
    targetMatAttrFn.keyable = False
    targetMatAttrFn.writable = True
    targetMatAttrFn.cached = True
    om.MPxNode.addAttribute(generalIk.aTargetMat)

    # compare and contrast
    endMatAttrFn = om.MFnMatrixAttribute()
    generalIk.aEndMat = endMatAttrFn.create("inputEndMatrix", "endMat", 1)
    endMatAttrFn.storable = True
    endMatAttrFn.readable = False
    endMatAttrFn.keyable = False
    endMatAttrFn.writable = True
    endMatAttrFn.cached = True
    om.MPxNode.addAttribute(generalIk.aEndMat)

    # once i built a tower
    jntMatAttrFn = om.MFnMatrixAttribute()
    generalIk.aJntMat = jntMatAttrFn.create("worldMatrix", "worldMatrix", 1)
    jntMatAttrFn.storable = False
    jntMatAttrFn.writable = True
    jntMatAttrFn.cached = False  # prevent ghost influences from staying

    # are you local
    jntLocalMatAttrFn = om.MFnMatrixAttribute()
    generalIk.aJntLocalMat = jntLocalMatAttrFn.create("localMatrix",
                                                      "localMatrix", 1)

    # joint orients
    orientRxAttrFn = om.MFnUnitAttribute()
    generalIk.aOrientRx = orientRxAttrFn.create("orientX", "orientX", 1, 0.0)

    orientRyAttrFn = om.MFnUnitAttribute()
    generalIk.aOrientRy = orientRyAttrFn.create("orientY", "orientY", 1, 0.0)

    orientRzAttrFn = om.MFnUnitAttribute()
    generalIk.aOrientRz = orientRzAttrFn.create("orientZ", "orientZ", 1, 0.0)

    orientRotAttrFn = om.MFnCompoundAttribute()
    generalIk.aOrientRot = orientRotAttrFn.create("orient", "orient")
    orientRotAttrFn.storable = False
    orientRotAttrFn.writable = True
    orientRotAttrFn.keyable = False
    orientRotAttrFn.addChild(generalIk.aOrientRx)
    orientRotAttrFn.addChild(generalIk.aOrientRy)
    orientRotAttrFn.addChild(generalIk.aOrientRz)

    # rotate order
    rotOrderAttrFn = om.MFnNumericAttribute()
    generalIk.aRotOrder = rotOrderAttrFn.create("rotateOrder", "rotateOrder",
                                                om.MFnNumericData.kLong, 0)

    # eye on the sky
    jntUpMatAttrFn = om.MFnMatrixAttribute()
    generalIk.aJntUpMat = jntUpMatAttrFn.create("upMatrix", "jntUpMat", 1)
    jntUpMatAttrFn.storable = True
    jntUpMatAttrFn.writable = True
    jntUpMatAttrFn.cached = True
    # om.MPxNode.addAttribute(generalIk.aJntUpMat)

    # but which way is up
    jntUpDirAttrFn = om.MFnNumericAttribute()
    generalIk.aJntUpDir = jntUpDirAttrFn.create("upDir", "upDir",
                                                om.MFnNumericData.k3Double)

    # who is the heftiest boi
    jntWeightAttrFn = om.MFnNumericAttribute()
    generalIk.aJntWeight = jntWeightAttrFn.create("weight", "jntWeight",
                                                  om.MFnNumericData.kDouble, 1)
    jntWeightAttrFn.storable = True
    jntWeightAttrFn.keyable = True
    jntWeightAttrFn.writable = True
    jntWeightAttrFn.setMin(0)
    # om.MPxNode.addAttribute(generalIk.aJntWeight)

    limitAttrFn = om.MFnCompoundAttribute()
    generalIk.aLimits = limitAttrFn.create("limits", "limits")

    # like really know them
    rxMaxAttrFn = om.MFnNumericAttribute()
    generalIk.aRxMax = rxMaxAttrFn.create("maxRotateX", "maxRx",
                                          om.MFnNumericData.kDouble, 0)
    # how low can you go
    rxMinAttrFn = om.MFnNumericAttribute()
    generalIk.aRxMin = rxMinAttrFn.create("minRotateX", "minRx",
                                          om.MFnNumericData.kDouble, 0)
    limitAttrFn.addChild(generalIk.aRxMax)
    limitAttrFn.addChild(generalIk.aRxMin)

    ## there is more to be done here

    # you will never break the chain
    jntArrayAttrFn = om.MFnCompoundAttribute()
    generalIk.aJnts = jntArrayAttrFn.create("inputJoints", "inputJoints")
    jntArrayAttrFn.array = True
    jntArrayAttrFn.usesArrayDataBuilder = True
    jntArrayAttrFn.addChild(generalIk.aJntMat)
    jntArrayAttrFn.addChild(generalIk.aJntLocalMat)
    jntArrayAttrFn.addChild(generalIk.aJntUpMat)
    jntArrayAttrFn.addChild(generalIk.aJntUpDir)
    jntArrayAttrFn.addChild(generalIk.aJntWeight)
    jntArrayAttrFn.addChild(generalIk.aOrientRot)
    jntArrayAttrFn.addChild(generalIk.aRotOrder)
    jntArrayAttrFn.addChild(generalIk.aLimits)
    # add limits later
    om.MPxNode.addAttribute(generalIk.aJnts)

    # fruits of labour
    outRxAttrFn = om.MFnUnitAttribute()
    generalIk.aOutRx = outRxAttrFn.create("rotateX", "outRx", 1, 0.0)
    outRxAttrFn.writable = False
    outRxAttrFn.keyable = False
    # om.MPxNode.addAttribute(generalIk.aOutRx)

    outRyAttrFn = om.MFnUnitAttribute()
    generalIk.aOutRy = outRyAttrFn.create("rotateY", "outRy", 1, 0.0)
    outRyAttrFn.writable = False
    outRyAttrFn.keyable = False
    # om.MPxNode.addAttribute(generalIk.aOutRy)

    outRzAttrFn = om.MFnUnitAttribute()
    generalIk.aOutRz = outRzAttrFn.create("rotateZ", "outRz", 1, 0.0)
    outRzAttrFn.writable = False
    outRzAttrFn.keyable = False
    # om.MPxNode.addAttribute(generalIk.aOutRz)

    outRotAttrFn = om.MFnCompoundAttribute()
    # generalIk.aOutRot = outRotAttrFn.create("outputRotate", "outRot",
    #     om.MFnNumericData.k3Double)
    generalIk.aOutRot = outRotAttrFn.create("rotate", "outRot")
    outRotAttrFn.storable = False
    outRotAttrFn.writable = False
    outRotAttrFn.keyable = False
    outRotAttrFn.addChild(generalIk.aOutRx)
    outRotAttrFn.addChild(generalIk.aOutRy)
    outRotAttrFn.addChild(generalIk.aOutRz)
    om.MPxNode.addAttribute(generalIk.aOutRot)

    # # add smooth jazz

    outTransAttrFn = om.MFnNumericAttribute()
    generalIk.aOutTrans = outTransAttrFn.create("translate", "outTrans",
                                                om.MFnNumericData.k3Double)
    outTransAttrFn.storable = False
    outTransAttrFn.writable = False
    outTransAttrFn.keyable = False
    om.MPxNode.addAttribute(generalIk.aOutTrans)

    # all that the sun touches
    outArrayAttrFn = om.MFnCompoundAttribute()
    generalIk.aOutArray = outArrayAttrFn.create("outputJoints", "out")
    outArrayAttrFn.array = True
    outArrayAttrFn.usesArrayDataBuilder = True
    outArrayAttrFn.storable = False
    outArrayAttrFn.writable = False
    outArrayAttrFn.keyable = False
    outArrayAttrFn.addChild(generalIk.aOutRot)
    outArrayAttrFn.addChild(generalIk.aOutTrans)
    om.MPxNode.addAttribute(generalIk.aOutArray)
    # investigate rolling this into the input hierarchy

    # convenience end attributes for babies
    outEndTransFn = om.MFnNumericAttribute()
    generalIk.aOutEndTrans = outEndTransFn.create("outputEndTranslate",
                                                  "outputEndTranslate",
                                                  om.MFnNumericData.k3Double)
    outEndTransFn.writable = False
    om.MPxNode.addAttribute(generalIk.aOutEndTrans)

    outEndRotFn = om.MFnCompoundAttribute()
    generalIk.aOutEndRot = outEndRotFn.create("outputEndRotate",
                                              "outputEndRotate")
    outEndRotFn.writable = False
    outEndRxAttrFn = om.MFnUnitAttribute()
    generalIk.aOutEndRx = outEndRxAttrFn.create("outputEndRotateX", "outEndRx",
                                                1, 0.0)
    outEndRotFn.addChild(generalIk.aOutEndRx)
    outEndRyAttrFn = om.MFnUnitAttribute()
    generalIk.aOutEndRy = outEndRyAttrFn.create("outputEndRotateY", "outEndRy",
                                                1, 0.0)
    outEndRotFn.addChild(generalIk.aOutEndRy)
    outEndRzAttrFn = om.MFnUnitAttribute()
    generalIk.aOutEndRz = outEndRzAttrFn.create("outputEndRotateZ", "outEndRz",
                                                1, 0.0)
    outEndRotFn.addChild(generalIk.aOutEndRz)
    om.MPxNode.addAttribute(generalIk.aOutEndRot)

    # debug
    debugTargetFn = om.MFnMatrixAttribute()
    generalIk.aDebugTarget = debugTargetFn.create("debugTarget", "debugTarget",
                                                  1)
    om.MPxNode.addAttribute(generalIk.aDebugTarget)

    debugOffset = om.MFnNumericAttribute()
    generalIk.aDebugOffset = debugOffset.create("debugOffset", "debugOffset",
                                                om.MFnNumericData.kDouble, 0)
    om.MPxNode.addAttribute(generalIk.aDebugOffset)

    # caching results to persist across graph evaluations
    cacheMatricesFn = om.MFnTypedAttribute()
    matrixArrayData = om.MFnMatrixArrayData().create()
    generalIk.aCacheMatrices = cacheMatricesFn.create(
        "cacheMatrices", "cacheMatrices", 12, matrixArrayData)  # matrix array
    cacheMatricesFn.writable = True
    cacheMatricesFn.readable = True
    cacheMatricesFn.cached = True
    cacheMatricesFn.keyable = True
    om.MPxNode.addAttribute(generalIk.aCacheMatrices)

    # everyone's counting on you
    drivers = [
        generalIk.aTargetMat, generalIk.aEndMat, generalIk.aJnts,
        generalIk.aMaxIter, generalIk.aGlobalWeight, generalIk.aTolerance,
        generalIk.aJntWeight, generalIk.aCacheOn
    ]
    driven = [
        generalIk.aOutArray, generalIk.aOutEndTrans, generalIk.aOutEndRot,
        generalIk.aDebugTarget, generalIk.aDebugOffset
    ]

    nodeio.setAttributeAffects(drivers, driven, generalIk)
Esempio n. 26
0
    def initialize():
        matrixAttr = om.MFnMatrixAttribute()
        numericAttr = om.MFnNumericAttribute()
        enumAttr = om.MFnEnumAttribute()
        typedAttr = om.MFnTypedAttribute()

        # OUTPUT
        prUpCurveSpline.outputMatrix = matrixAttr.create(
            'outputMatrix', 'outputMatrix')
        matrixAttr.array = True
        matrixAttr.usesArrayDataBuilder = True
        matrixAttr.writable = False
        prUpCurveSpline.addAttribute(prUpCurveSpline.outputMatrix)

        # INPUTS
        prUpCurveSpline.curve = typedAttr.create(
            'curve', 'curve', om.MFnNurbsCurveData.kNurbsCurve)
        prUpCurveSpline.addAttribute(prUpCurveSpline.curve)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.curve,
                                         prUpCurveSpline.outputMatrix)

        prUpCurveSpline.upCurve = typedAttr.create(
            'upCurve', 'upCurve', om.MFnNurbsCurveData.kNurbsCurve)
        prUpCurveSpline.addAttribute(prUpCurveSpline.upCurve)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.upCurve,
                                         prUpCurveSpline.outputMatrix)

        prUpCurveSpline.startOrientMatrix = matrixAttr.create(
            'startOrientMatrix', 'startOrientMatrix')
        prUpCurveSpline.addAttribute(prUpCurveSpline.startOrientMatrix)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.startOrientMatrix,
                                         prUpCurveSpline.outputMatrix)

        prUpCurveSpline.endOrientMatrix = matrixAttr.create(
            'endOrientMatrix', 'endOrientMatrix')
        prUpCurveSpline.addAttribute(prUpCurveSpline.endOrientMatrix)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.endOrientMatrix,
                                         prUpCurveSpline.outputMatrix)

        # SETTINGS
        prUpCurveSpline.parameterType = enumAttr.create(
            'parameterType', 'parameterType', 1)
        enumAttr.addField('param', 0)
        enumAttr.addField('param normalized', 1)
        enumAttr.addField('length', 2)
        enumAttr.addField('fractionMode', 3)
        enumAttr.keyable = True
        prUpCurveSpline.addAttribute(prUpCurveSpline.parameterType)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.parameterType,
                                         prUpCurveSpline.outputMatrix)

        prUpCurveSpline.aimAxis = enumAttr.create('aimAxis', 'aimAxis', 0)
        enumAttr.addField('x', 0)
        enumAttr.addField('y', 1)
        enumAttr.addField('z', 2)
        enumAttr.addField('-x', 3)
        enumAttr.addField('-y', 4)
        enumAttr.addField('-z', 5)
        enumAttr.keyable = True
        prUpCurveSpline.addAttribute(prUpCurveSpline.aimAxis)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.aimAxis,
                                         prUpCurveSpline.outputMatrix)

        prUpCurveSpline.upAxis = enumAttr.create('upAxis', 'upAxis', 1)
        enumAttr.addField('x', 0)
        enumAttr.addField('y', 1)
        enumAttr.addField('z', 2)
        enumAttr.addField('-x', 3)
        enumAttr.addField('-y', 4)
        enumAttr.addField('-z', 5)
        enumAttr.keyable = True
        prUpCurveSpline.addAttribute(prUpCurveSpline.upAxis)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.upAxis,
                                         prUpCurveSpline.outputMatrix)

        prUpCurveSpline.startOrientMatrixWeight = numericAttr.create(
            'startOrientMatrixWeight', 'startOrientMatrixWeight',
            om.MFnNumericData.kFloat, 0.0)
        numericAttr.keyable = True
        numericAttr.setMin(0.0)
        numericAttr.setMax(1.0)
        prUpCurveSpline.addAttribute(prUpCurveSpline.startOrientMatrixWeight)
        prUpCurveSpline.attributeAffects(
            prUpCurveSpline.startOrientMatrixWeight,
            prUpCurveSpline.outputMatrix)

        prUpCurveSpline.endOrientMatrixWeight = numericAttr.create(
            'endOrientMatrixWeight', 'endOrientMatrixWeight',
            om.MFnNumericData.kFloat, 0.0)
        numericAttr.keyable = True
        numericAttr.setMin(0.0)
        numericAttr.setMax(1.0)
        prUpCurveSpline.addAttribute(prUpCurveSpline.endOrientMatrixWeight)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.endOrientMatrixWeight,
                                         prUpCurveSpline.outputMatrix)

        prUpCurveSpline.parameter = numericAttr.create(
            'parameter', 'parameter', om.MFnNumericData.kFloat, 0.0)
        numericAttr.keyable = True
        numericAttr.array = True
        numericAttr.usesArrayDataBuilder = True
        prUpCurveSpline.addAttribute(prUpCurveSpline.parameter)
        prUpCurveSpline.attributeAffects(prUpCurveSpline.parameter,
                                         prUpCurveSpline.outputMatrix)
Esempio n. 27
0
def buildConstraint(source, targets, maintainOffset=False,
                    constraintType=om2.MFn.kParentConstraint, **kwargs):
    """This Function build a space switching constraint.

    Currently Supporting types of
        kParentConstraint
        kPointConstraint
        kOrientConstraint

    :param source: The transform to drive
    :param source: om2.MObject
    :param targets: A dict containing the target information(see below example)
    :param targets: dict or None
    :param: maintainOffset: whether or not the constraint should maintain offset
    :type maintainOffset: bool
    :param constraintType: The maya api kType eg. om2.MFn.kParentConstraint, defaults to kParentConstraint
    :type constraintType: om2.MFn.kType
    :param kwargs: The cmds.kconstraintType extra arguments to use
    :type kwargs: dict

    .. code-block: python

        targets = []
        for n in ("locator1", "locator2", "locator3"):
            targets.append((n, nodes.createDagNode(n, "locator")))
        spaceNode =nodes.createDagNode("control", "locator")
        drivenNode = nodes.createDagNode("driven", "locator")
        spaces = {"spaceNode": spaceNode,
                    "attributeName": "parentSpace", "targets": targets}
        constraint, conditions = build(drivenNode, targets=spaces)

        # lets add to the existing system
        spaces = {"spaceNode": spaceNode, "attributeName": "parentSpace", "targets": (
                 ("locator8", nodes.createDagNode("locator8", "locator")),)}

        constraint, conditions = build(drivenNode, targets=spaces)

      )


    """
    # make sure we support the constrainttype the user wants
    assert constraintType in APITOCMDS_CONSTRAINT_MAP, "No Constraint of type: {}, supported".format(constraintType)

    spaceNode = targets.get("spaceNode")
    attrName = targets.get("attributeName", "parent")
    targetInfo = targets["targets"]
    targetLabels, targetNodes = zip(*targetInfo)

    # first try to find an existing constraint
    existingConstraint = findConstraint(source, constraintType, includeReferenced=False)
    # if we found existing constraint then check to see if the target is already
    # constraining, if so just excluded it.
    targetList = targetNodes
    if existingConstraint:
        existingTargets = list(iterTargetsFromConstraint(existingConstraint))
        targetList = [t for t in targetNodes if t not in existingTargets]
        # in the case that all target already exist just early out
        if not targetList:
            return None, []

    # create the constraint
    constraintMap = APITOCMDS_CONSTRAINT_MAP[constraintType]
    cmdsFunc = getattr(cmds, constraintMap["type"])
    arguments = {"maintainOffset": maintainOffset}
    arguments.update(kwargs)
    constraint = cmdsFunc(map(nodes.nameFromMObject, targetList), nodes.nameFromMObject(source),
                          **arguments)[0]
    # if we have been provided a spaceNode, which will contain our switch, otherwise ignore the setup of a switch
    # and just return the constraint
    constraintMObject = nodes.asMObject(constraint)
    if spaceNode is None:
        return constraintMObject, []

    spaceFn = om2.MFnDependencyNode(spaceNode)
    if spaceFn.hasAttribute(attrName):
        spacePlug = spaceFn.findPlug(attrName, False)
        existingFieldNames = plugs.enumNames(spacePlug)
        spaceAttr = om2.MFnEnumAttribute(spacePlug.attribute())
        # add any missing fields to enumAttribute
        for field in targetLabels:
            if field not in existingFieldNames:
                spaceAttr.addField(field, len(existingFieldNames))

    else:
        spaceAttr = nodes.addAttribute(spaceNode, attrName, attrName, attrType=attrtypes.kMFnkEnumAttribute,
                                       keyable=True,
                                       channelBox=True, locked=False,
                                       enums=targetLabels)
        spacePlug = om2.MPlug(spaceNode, spaceAttr.object())

    constraintFn = om2.MFnDependencyNode(constraintMObject)
    targetArray = constraintFn.findPlug("target", False)
    sourceShortName = nodes.nameFromMObject(source, partialName=True, includeNamespace=False)
    conditions = []
    constraintTargetWeightIndex = constraintMap["targetPlugIndex"]
    # first iterate over the target array on the constraint
    for index in targetArray.getExistingArrayAttributeIndices():
        targetElement = targetArray.elementByLogicalIndex(index)
        targetElementWeight = targetElement.child(constraintTargetWeightIndex)
        targetWeightSource = targetElementWeight.source()
        # just in case the target weight plug is disconnected
        if targetWeightSource is None:
            targetWeightSource = targetElementWeight
        else:
            # lets make sure that we're not already connected to a condition node
            # if so skip
            weightSourceNode = targetWeightSource.node()
            # if we connected to the constraint i.e spaceWO1
            if weightSourceNode == constraintMObject:
                upstreamWeight = targetWeightSource.source()
                if upstreamWeight and upstreamWeight.node().apiType() == om2.MFn.kCondition:
                    continue
            else:
                if weightSourceNode.apiType() == om2.MFn.kCondition:
                    continue
        targetNode = targetElement.child(0).source().node()
        targetShortName = nodes.nameFromMObject(targetNode, partialName=True, includeNamespace=False)
        # create the condition node and do the connections
        conditionNode = creation.conditionVector(firstTerm=spacePlug, secondTerm=float(targetElement.logicalIndex()),
                                                 colorIfTrue=(1.0, 0.0, 0.0),
                                                 colorIfFalse=(0.0, 0.0, 0.0), operation=0,
                                                 name="_".join([targetShortName, sourceShortName, "space"]))
        condFn = om2.MFnDependencyNode(conditionNode)
        plugs.connectPlugs(condFn.findPlug("outColorR", False), targetWeightSource)
        conditions.append(conditionNode)

    return constraintMObject, conditions
    def initialize():
        ''' Defines the input and output attributes as static variables in our plug-in class. '''

        # Input Attributes

        # Creates needed function sets
        numericAttributeFn  = OpenMaya.MFnNumericAttribute()
        enumAttr            = OpenMaya.MFnEnumAttribute()
        stringAttrFn        = OpenMaya.MFnTypedAttribute()
        # ____________________________

        MntLocatorNode.sizeAttribute    = numericAttributeFn.create('size', 'size', OpenMaya.MFnNumericData.kFloat, 1)
        numericAttributeFn.writable     =  True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     =  True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.setMin( 0.01 )
        numericAttributeFn.setMax( 100.0 )
        MntLocatorNode.addAttribute(MntLocatorNode.sizeAttribute)

        MntLocatorNode.areaVisibility   = numericAttributeFn.create('area_Visibility', 'area_Visibility', OpenMaya.MFnNumericData.kBoolean, False)
        numericAttributeFn.writable     =  True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     =  True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.areaVisibility)

        MntLocatorNode.colorAttribute = numericAttributeFn.createColor('color', 'color')
        numericAttributeFn.writable     = True
        numericAttributeFn.keyable      = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.storable     = True
        numericAttributeFn.hidden       = False
        MntLocatorNode.addAttribute(MntLocatorNode.colorAttribute)

        MntLocatorNode.opacityAttribute = numericAttributeFn.create('opacity', 'opacity', OpenMaya.MFnNumericData.kFloat, 1.0)
        numericAttributeFn.writable     = True
        numericAttributeFn.keyable      = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.storable     = True
        numericAttributeFn.hidden       = False
        numericAttributeFn.setMin(0.0)
        numericAttributeFn.setMax(1.0)
        MntLocatorNode.addAttribute(MntLocatorNode.opacityAttribute)

        MntLocatorNode.iconType = enumAttr.create('iconType', 'it', 1)
        enumAttr.addField('Bone', 0)
        enumAttr.addField('Circle', 1)
        enumAttr.addField('Square', 2)
        enumAttr.addField('Skull', 3)
        enumAttr.addField('Pelvis', 4)
        enumAttr.addField('Ribcage', 5)
        enumAttr.addField('Sphere', 6)
        enumAttr.addField('Disc', 7)
        enumAttr.addField('Circle3D', 8)
        enumAttr.hidden     = False
        enumAttr.channelBox = True
        MntLocatorNode.addAttribute(MntLocatorNode.iconType)

        MntLocatorNode.iconMainAxis = enumAttr.create('iconMainAxis', 'ima', 0)
        enumAttr.addField('X', 0)
        enumAttr.addField('Y', 1)
        enumAttr.addField('Z', 2)
        enumAttr.hidden       = True
        enumAttr.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.iconMainAxis)

        MntLocatorNode.showHierarchicalLinks= numericAttributeFn.create('show_hierarchical_links', 'show_hierarchical_links', OpenMaya.MFnNumericData.kBoolean, False)
        numericAttributeFn.writable     = True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     = True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.showHierarchicalLinks)

        MntLocatorNode.dottedLine = numericAttributeFn.create('use_dotted_line', 'use_dotted_line', OpenMaya.MFnNumericData.kBoolean, False)
        numericAttributeFn.writable   = True 
        numericAttributeFn.keyable    = False
        numericAttributeFn.storable   = True
        numericAttributeFn.hidden     = False
        numericAttributeFn.channelBox = True
        MntLocatorNode.addAttribute(MntLocatorNode.dottedLine)

        MntLocatorNode.dotsNumber = numericAttributeFn.create('dots_number', 'dots_number', OpenMaya.MFnNumericData.kInt, 5)
        numericAttributeFn.writable   = True 
        numericAttributeFn.keyable    = False
        numericAttributeFn.storable   = True
        numericAttributeFn.hidden     = False
        numericAttributeFn.channelBox = True
        numericAttributeFn.setMin(1)
        numericAttributeFn.setMax(16)
        MntLocatorNode.addAttribute(MntLocatorNode.dotsNumber)

        MntLocatorNode.lineWidth = numericAttributeFn.create('line_width', 'line_width', OpenMaya.MFnNumericData.kInt, 4)
        numericAttributeFn.writable    = True
        numericAttributeFn.keyable     = True
        numericAttributeFn.storable    = True
        numericAttributeFn.hidden      = False
        numericAttributeFn.channelBox  = True
        numericAttributeFn.setMin(1)
        numericAttributeFn.setMax(16)
        MntLocatorNode.addAttribute(MntLocatorNode.lineWidth)

        MntLocatorNode.lineColor = numericAttributeFn.createColor('line_color', 'line_color')
        numericAttributeFn.writable     = True
        numericAttributeFn.keyable      = False
        numericAttributeFn.channelBox   = True
        numericAttributeFn.storable     = True
        numericAttributeFn.hidden       = False
        MntLocatorNode.addAttribute(MntLocatorNode.lineColor)

        MntLocatorNode.labelAttribute = stringAttrFn.create('label', 'label', OpenMaya.MFnData.kString)
        stringAttrFn.writable = True
        stringAttrFn.readable = True
        MntLocatorNode.addAttribute(MntLocatorNode.labelAttribute)

        MntLocatorNode.interactiveRefresh = numericAttributeFn.create('interactiveRefresh', 'ir', OpenMaya.MFnNumericData.kBoolean, True)
        numericAttributeFn.writable     = True 
        numericAttributeFn.keyable      = False
        numericAttributeFn.storable     = True 
        numericAttributeFn.hidden       = False
        numericAttributeFn.channelBox   = True
        MntLocatorNode.addAttribute(MntLocatorNode.interactiveRefresh)
Esempio n. 29
0
    def initialize():
        nAttr = om.MFnNumericAttribute()
        eAttr = om.MFnEnumAttribute()
        typedAttr = om.MFnTypedAttribute()

        ## Add ui type attribute
        uiDrawManager.aUIType = eAttr.create("uiType", "ut", kText)
        eAttr.addField("text", kText)
        eAttr.addField("line", kLine)
        eAttr.addField("point", kPoint)
        eAttr.addField("rect", kRect)
        eAttr.addField("quad", kQuad)
        eAttr.addField("sphere", kSphere)
        eAttr.addField("circle", kCircle)
        eAttr.addField("arc", kArc)
        om.MPxNode.addAttribute(uiDrawManager.aUIType)

        ## Add color attribute
        uiDrawManager.aPrimitiveColor = nAttr.create("primitiveColor", "pc",
                                                     om.MFnNumericData.k3Float)
        nAttr.default = (1.0, 0.0, 0.0)
        nAttr.usedAsColor = True
        om.MPxNode.addAttribute(uiDrawManager.aPrimitiveColor)

        ## Add transparency attribute
        uiDrawManager.aPrimitiveTransparency = nAttr.create(
            "primitiveTransparency", "pt", om.MFnNumericData.kFloat, 0.0)
        nAttr.setSoftMin(0.0)
        nAttr.setSoftMax(1.0)
        om.MPxNode.addAttribute(uiDrawManager.aPrimitiveTransparency)

        ## add line width and line style attributes
        uiDrawManager.aLineWidth = nAttr.create("lineWidth", "lw",
                                                om.MFnNumericData.kFloat, 2.0)
        om.MPxNode.addAttribute(uiDrawManager.aLineWidth)

        uiDrawManager.aLineStyle = eAttr.create("lineStyle", "ls",
                                                omr.MUIDrawManager.kSolid)
        eAttr.addField("solid", omr.MUIDrawManager.kSolid)
        eAttr.addField("shortdotted", omr.MUIDrawManager.kShortDotted)
        eAttr.addField("shortdashed", omr.MUIDrawManager.kShortDashed)
        eAttr.addField("dashed", omr.MUIDrawManager.kDashed)
        eAttr.addField("dotted", omr.MUIDrawManager.kDotted)
        om.MPxNode.addAttribute(uiDrawManager.aLineStyle)

        ## Add filled attribute
        uiDrawManager.aIsFilled = nAttr.create("isFilled", "if",
                                               om.MFnNumericData.kBoolean, 0)
        om.MPxNode.addAttribute(uiDrawManager.aIsFilled)

        ## Add radius attribute
        uiDrawManager.aRadius = nAttr.create("radius", "ra",
                                             om.MFnNumericData.kDouble, 1.0)
        om.MPxNode.addAttribute(uiDrawManager.aRadius)

        ## add 2D attributes
        uiDrawManager.aDraw2D = nAttr.create("draw2D", "d2",
                                             om.MFnNumericData.kBoolean, 0)
        om.MPxNode.addAttribute(uiDrawManager.aDraw2D)

        uiDrawManager.aPosition = nAttr.create("position", "pos",
                                               om.MFnNumericData.k3Double)
        nAttr.default = (0.0, 0.0, 0.001)
        om.MPxNode.addAttribute(uiDrawManager.aPosition)

        ## Add text attributes.
        stringFn = om.MFnStringData()
        defaultText = stringFn.create("uiDrawManager-Text")
        uiDrawManager.aText = typedAttr.create("text", "t", om.MFnData.kString,
                                               defaultText)
        om.MPxNode.addAttribute(uiDrawManager.aText)

        uiDrawManager.aTextFontSize = nAttr.create(
            "textFontSize", "tfs", om.MFnNumericData.kInt,
            omr.MUIDrawManager.kDefaultFontSize)
        nAttr.setMin(-1)
        nAttr.setMax(99)
        om.MPxNode.addAttribute(uiDrawManager.aTextFontSize)

        uiDrawManager.fFontList = omr.MUIDrawManager.getFontList()
        if len(uiDrawManager.fFontList) == 0:
            sys.stderr.write("No font available!\n")

        uiDrawManager.aFontFaceName = eAttr.create("fontFaceName", "ffn", 0)
        for i in range(len(uiDrawManager.fFontList)):
            faceName = uiDrawManager.fFontList[i]
            eAttr.addField(faceName, i)
        om.MPxNode.addAttribute(uiDrawManager.aFontFaceName)

        uiDrawManager.aTextAlignment = eAttr.create("textAlignment", "ta",
                                                    omr.MUIDrawManager.kLeft)
        eAttr.addField("left", omr.MUIDrawManager.kLeft)
        eAttr.addField("center", omr.MUIDrawManager.kCenter)
        eAttr.addField("right", omr.MUIDrawManager.kRight)
        om.MPxNode.addAttribute(uiDrawManager.aTextAlignment)

        uiDrawManager.eTextIncline = eAttr.create(
            "textIncline", "tic", omr.MUIDrawManager.kInclineNormal)
        eAttr.addField("normal", omr.MUIDrawManager.kInclineNormal)
        eAttr.addField("italic", omr.MUIDrawManager.kInclineItalic)
        om.MPxNode.addAttribute(uiDrawManager.eTextIncline)

        uiDrawManager.aTextWeight = eAttr.create(
            "textWeight", "tw", omr.MUIDrawManager.kWeightBold)
        eAttr.addField("light", omr.MUIDrawManager.kWeightLight)
        eAttr.addField("bold", omr.MUIDrawManager.kWeightBold)
        om.MPxNode.addAttribute(uiDrawManager.aTextWeight)

        uiDrawManager.aTextStretch = nAttr.create(
            "textStretch", "ts", om.MFnNumericData.kInt,
            omr.MUIDrawManager.kStretchUnstretched)
        nAttr.setMin(50)
        nAttr.setMax(200)
        om.MPxNode.addAttribute(uiDrawManager.aTextStretch)

        uiDrawManager.aTextLine = eAttr.create("textLine", "tl", 0)
        eAttr.addField("none", 0)
        eAttr.addField("overline", omr.MUIDrawManager.kLineOverline)
        eAttr.addField("underline", omr.MUIDrawManager.kLineUnderline)
        eAttr.addField("strikeout", omr.MUIDrawManager.kLineStrikeoutLine)
        om.MPxNode.addAttribute(uiDrawManager.aTextLine)

        uiDrawManager.aTextBoxSize = nAttr.create("textBoxSize", "tbs",
                                                  om.MFnNumericData.k2Int)
        nAttr.default = (0, 0)
        om.MPxNode.addAttribute(uiDrawManager.aTextBoxSize)

        uiDrawManager.aTextBoxColor = nAttr.create("textBoxColor", "tbc",
                                                   om.MFnNumericData.k3Float)
        nAttr.default = (0.0, 1.0, 1.0)
        nAttr.usedAsColor = True
        om.MPxNode.addAttribute(uiDrawManager.aTextBoxColor)

        uiDrawManager.aTextBoxTransparency = nAttr.create(
            "textBoxTransparency", "tbt", om.MFnNumericData.kFloat, 0.0)
        nAttr.setSoftMin(0.0)
        nAttr.setSoftMax(1.0)
        om.MPxNode.addAttribute(uiDrawManager.aTextBoxTransparency)

        ## add point attributes
        uiDrawManager.aPointSize = nAttr.create("pointSize", "ps",
                                                om.MFnNumericData.kFloat, 2.0)
        om.MPxNode.addAttribute(uiDrawManager.aPointSize)

        ## add line attributes
        uiDrawManager.aLineStartPoint = nAttr.create(
            "lineStartPoint", "lsp", om.MFnNumericData.k3Double)
        nAttr.default = (0.0, 0.0, 0.0)
        om.MPxNode.addAttribute(uiDrawManager.aLineStartPoint)

        uiDrawManager.aLineEndPoint = nAttr.create("lineEndPoint", "lep",
                                                   om.MFnNumericData.k3Double)
        nAttr.default = (1.0, 1.0, 1.0)
        om.MPxNode.addAttribute(uiDrawManager.aLineEndPoint)

        ## add rect attributes
        uiDrawManager.aRectUp = nAttr.create("rectUp", "ru",
                                             om.MFnNumericData.k3Double)
        nAttr.default = (0.0, 1.0, 0.0)
        om.MPxNode.addAttribute(uiDrawManager.aRectUp)

        uiDrawManager.aRectNormal = nAttr.create("rectNormal", "rn",
                                                 om.MFnNumericData.k3Double)
        nAttr.default = (0.0, 0.0, 1.0)
        om.MPxNode.addAttribute(uiDrawManager.aRectNormal)

        uiDrawManager.aRectScale = nAttr.create("rectScale", "rs",
                                                om.MFnNumericData.k2Double)
        nAttr.default = (1.0, 1.0)
        om.MPxNode.addAttribute(uiDrawManager.aRectScale)

        ## add quad attributes
        defaultPosition = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0),
                           (0.0, 1.0, 0.0)]
        for i in range(4):
            fullName = "quadVertex" + str(i)
            shortName = "qv" + str(i)
            uiDrawManager.aQuadVertex[i] = nAttr.create(
                fullName, shortName, om.MFnNumericData.k3Double)
            nAttr.default = defaultPosition[i]
            om.MPxNode.addAttribute(uiDrawManager.aQuadVertex[i])

        ## add circle attributes
        uiDrawManager.aCircleNormal = nAttr.create("circleNormal", "cn",
                                                   om.MFnNumericData.k3Double)
        nAttr.default = (0.0, 0.0, 1.0)
        om.MPxNode.addAttribute(uiDrawManager.aCircleNormal)

        ## add arc attributes
        uiDrawManager.aArcStart = nAttr.create("arcStartVector", "asv",
                                               om.MFnNumericData.k3Double)
        nAttr.default = (1.0, 0.0, 0.0)
        om.MPxNode.addAttribute(uiDrawManager.aArcStart)

        uiDrawManager.aArcEnd = nAttr.create("arcEndVector", "aev",
                                             om.MFnNumericData.k3Double)
        nAttr.default = (0.0, 1.0, 0.0)
        om.MPxNode.addAttribute(uiDrawManager.aArcEnd)

        uiDrawManager.aArcNormal = nAttr.create("arcNormal", "an",
                                                om.MFnNumericData.k3Double)
        nAttr.default = (0.0, 0.0, 1.0)
        om.MPxNode.addAttribute(uiDrawManager.aArcNormal)
Esempio n. 30
0
    def initialize(cls):
        nAttr = OpenMaya.MFnNumericAttribute()
        tAttr = OpenMaya.MFnTypedAttribute()
        uAttr = OpenMaya.MFnUnitAttribute()
        enumAttr = OpenMaya.MFnEnumAttribute()
        compAttr = OpenMaya.MFnCompoundAttribute()
        matrixAttr = OpenMaya.MFnMatrixAttribute()
        messageAttr = OpenMaya.MFnMessageAttribute()

        cls.forgeID = tAttr.create("forgeID", "fid", OpenMaya.MFnData.kString,
                                   OpenMaya.MObject.kNullObj)
        cls.addAttribute(cls.forgeID)

        cls.guideMatrix = matrixAttr.create(
            "guideMatrix", "gm", OpenMaya.MFnMatrixAttribute.kDouble)
        cls.addAttribute(cls.guideMatrix)

        cls.handleInverseScale = nAttr.create("handleInverseScale", "his",
                                              OpenMaya.MFnNumericData.k3Double,
                                              1.0)
        cls.addAttribute(cls.handleInverseScale)

        cls.boundingBoxCorner1 = nAttr.create("boundingBoxCorner1", "bb1",
                                              OpenMaya.MFnNumericData.k3Double,
                                              0)
        nAttr.keyable = False
        cls.addAttribute(cls.boundingBoxCorner1)
        cls.boundingBoxCorner2 = nAttr.create("boundingBoxCorner2", "bb2",
                                              OpenMaya.MFnNumericData.k3Double,
                                              0)
        nAttr.keyable = False
        cls.addAttribute(cls.boundingBoxCorner2)

        cls.aimAxis = enumAttr.create("aimAxis", "aa", 0)
        enumAttr.addField("X", 0)
        enumAttr.addField("Y", 1)
        enumAttr.addField("Z", 2)
        enumAttr.addField("-X", 3)
        enumAttr.addField("-Y", 4)
        enumAttr.addField("-Z", 5)
        enumAttr.keyable = False
        cls.addAttribute(cls.aimAxis)

        cls.upAxis = enumAttr.create("upAxis", "ua", 2)
        enumAttr.addField("X", 0)
        enumAttr.addField("Y", 1)
        enumAttr.addField("Z", 2)
        enumAttr.addField("-X", 3)
        enumAttr.addField("-Y", 4)
        enumAttr.addField("-Z", 5)
        enumAttr.keyable = False
        cls.addAttribute(cls.upAxis)

        cls.aimVector = nAttr.create("aimVector", "av",
                                     OpenMaya.MFnNumericData.k3Double)
        cls.addAttribute(cls.aimVector)

        cls.upVector = nAttr.create("upVector", "uv",
                                    OpenMaya.MFnNumericData.k3Double)
        cls.addAttribute(cls.upVector)

        cls.provideAimVector = nAttr.create("provideAimVector", "pav",
                                            OpenMaya.MFnNumericData.kBoolean,
                                            0)
        cls.addAttribute(cls.provideAimVector)

        cls.handle = messageAttr.create("handle", "hndl")
        messageAttr.array = True
        cls.addAttribute(cls.handle)

        cls.handleColor = nAttr.createColor("handleColor", "hc")
        cls.addAttribute(cls.handleColor)

        cls.parentGuide = messageAttr.create("parentGuide", "pg")
        cls.addAttribute(cls.parentGuide)

        cls.parentGuideHandleIndex = nAttr.create(
            "parentGuideHandleIndex", "pghi", OpenMaya.MFnNumericData.kShort,
            -1)
        cls.addAttribute(cls.parentGuideHandleIndex)

        cls.childGuide = messageAttr.create("childGuide", "cg")
        cls.addAttribute(cls.childGuide)

        cls.attributeAffects(cls.guideMatrix, cls.boundingBoxCorner1)
        cls.attributeAffects(cls.guideMatrix, cls.boundingBoxCorner2)
        cls.attributeAffects(cls.guideMatrix, cls.handleInverseScale)
        cls.attributeAffects(cls.guideMatrix, cls.aimVector)
        cls.attributeAffects(cls.guideMatrix, cls.upVector)