def initialize(): # output expmap cAttr = OpenMaya.MFnCompoundAttribute() mlEulerToExpmap.expmap = cAttr.create(expmapName[0], expmapName[1]) cAttr.setNiceNameOverride(expmapName[2]) mlEulerToExpmap.expmapElement = [] for i in xrange(0, 3): nAttr = OpenMaya.MFnNumericAttribute() mlEulerToExpmap.expmapElement = mlEulerToExpmap.expmapElement + \ [nAttr.create(expmapElementName[i][0], expmapElementName[i][1], OpenMaya.MFnNumericData.kDouble, 0.0)] nAttr.setNiceNameOverride(expmapElementName[i][2]) nAttr.keyable = False nAttr.writable = False cAttr.addChild(mlEulerToExpmap.expmapElement[i]) mlEulerToExpmap.addAttribute(mlEulerToExpmap.expmap) # input Euler angles cAttr = OpenMaya.MFnCompoundAttribute() mlEulerToExpmap.rotate = cAttr.create(rotateName[0], rotateName[1]) cAttr.setNiceNameOverride(rotateName[2]) mlEulerToExpmap.eulerAngles = [] for i in xrange(0, 3): uAttr = OpenMaya.MFnUnitAttribute() mlEulerToExpmap.eulerAngles = mlEulerToExpmap.eulerAngles + \ [uAttr.create(eulerAngleName[i][0], eulerAngleName[i][1], OpenMaya.MFnUnitAttribute.kAngle, 0.0)] uAttr.setNiceNameOverride(eulerAngleName[i][2]) uAttr.keyable = True uAttr.readable = False cAttr.addChild(mlEulerToExpmap.eulerAngles[i]) mlEulerToExpmap.addAttribute(mlEulerToExpmap.rotate) mlEulerToExpmap.attributeAffects(mlEulerToExpmap.rotate, mlEulerToExpmap.expmap) # input rotation order nAttr = OpenMaya.MFnNumericAttribute() mlEulerToExpmap.rotateOrder = nAttr.create( rotateOrderName[0], rotateOrderName[1], OpenMaya.MFnNumericData.kInt, 0) nAttr.setNiceNameOverride(rotateOrderName[2]) nAttr.readable = False mlEulerToExpmap.addAttribute(mlEulerToExpmap.rotateOrder) mlEulerToExpmap.attributeAffects(mlEulerToExpmap.rotateOrder, mlEulerToExpmap.expmap)
def addExtraPathAttr(self, transform, path=defaultPath): """ add extra path attribute, for extra exports Args: transform: MObject or Pymel.core.nodetypes.Transform """ if isinstance(transform, pm.nodetypes.Transform): transform = OpenMaya.MSelectionList().add(str(transform)).getDependNode(0) transform_fn = OpenMaya.MFnTransform(transform) if not transform_fn.hasAttribute(self.attrCompoundName): logger.info('%s does not has attribute: %s' % (transform_fn.fullPathName(), self.attrCompoundName)) return # get compound attr using api compoudAttr = transform_fn.attribute(self.attrCompoundName) compoudAttr_fn = OpenMaya.MFnCompoundAttribute(compoudAttr) logger.debug('addExtraPathAttr: CompoundAttr: %s' % compoudAttr_fn.name) compoudAttr_childs = compoudAttr_fn.numChildren() # create new string attribute to store new path stringData = OpenMaya.MFnStringData().create(path) # mobject string data with path fAttr = OpenMaya.MFnTypedAttribute() pathAttr = fAttr.create('%s%s' % (self.attrPathName, compoudAttr_childs), 'pt%s' % compoudAttr_childs, OpenMaya.MFnData.kString, stringData) fAttr.keyable = True fAttr.storable = True fAttr.readable = True fAttr.writable = True # add attribute transform_fn.addAttribute(pathAttr) logger.debug('addExtraPathAttr: Attr created: %s%s' % (self.attrPathName, compoudAttr_childs)) # add new path attribute under compoundAttr compoudAttr_fn.addChild(pathAttr) logger.debug('addExtraPathAttr: Set as child of %s: %s' % (compoudAttr_fn.name, fAttr.name))
def parseCompoundAttribute(self, name, shortName, attrInfo): """ Given a JSON subsection describing a compound attribute create the attribute and all children, and set all of the provided flags/members for it. name = Attribute long name shortName = Attribute short name attrInfo = JSON object containing the main attribute information """ jsonDebug('parseCompoundAttribute(%s : %s)' % (name, attrInfo)) attr = None try: cAttr = omAPI.MFnCompoundAttribute() attr = cAttr.create(name, shortName) # Recursively create all children, and children of children, etc. if JsonKeys.kKeyChildren in attrInfo: childInfo = attrInfo[JsonKeys.kKeyChildren] tmpAttr = self.currentAttribute for child in childInfo: jsonDebug('Add compound child %s' % child) childAttr = self.parseAttribute(child) cAttr.addChild(childAttr) self.currentAttribute = tmpAttr except Exception, e: self.reportError('Error creating compound: %s' % str(e))
def initialize(): numericAttr = om.MFnNumericAttribute() compoundAttr = om.MFnCompoundAttribute() typedAttr = om.MFnTypedAttribute() # output prMotionPath.outTranslate = numericAttr.createPoint('outTranslate', 'outTranslate') numericAttr.writable = False prMotionPath.output = compoundAttr.create('output', 'output') compoundAttr.addChild(prMotionPath.outTranslate) compoundAttr.array = True compoundAttr.usesArrayDataBuilder = True prMotionPath.addAttribute(prMotionPath.output) # input prMotionPath.inputCurve = typedAttr.create('inputCurve', 'inputCurve', om.MFnNurbsCurveData.kNurbsCurve) prMotionPath.addAttribute(prMotionPath.inputCurve) prMotionPath.attributeAffects(prMotionPath.inputCurve, prMotionPath.outTranslate) prMotionPath.fractionMode = numericAttr.create('fractionMode', 'fractionMode', om.MFnNumericData.kBoolean, True) numericAttr.keyable = True prMotionPath.addAttribute(prMotionPath.fractionMode) prMotionPath.attributeAffects(prMotionPath.fractionMode, prMotionPath.outTranslate) prMotionPath.uValue = numericAttr.create('uValue', 'uValue', om.MFnNumericData.kFloat, 0.0) numericAttr.keyable = True numericAttr.array = True numericAttr.usesArrayDataBuilder = True prMotionPath.addAttribute(prMotionPath.uValue) prMotionPath.attributeAffects(prMotionPath.uValue, prMotionPath.outTranslate)
def addCompoundAttribute(node, longName, shortName, attrMap, isArray=False): """ :param node: the node to add the compound attribute too. :type node: om2.MObject :param longName: the compound longName :type longName: str :param shortName: the compound shortName :type shortName: str :param attrMap: [{"name":str, "type": attrtypes.kType, "isArray": bool}] :type attrMap: list(dict()) :return: the MObject attached to the compound attribute :rtype: om2.MObject ::example: >>>attrMap = [{"name":"something", "type": attrtypes.kMFnMessageAttribute, "isArray": False}] >>> print attrMap # result <OpenMaya.MObject object at 0x00000000678CA790> # """ compound = om2.MFnCompoundAttribute() compObj = compound.create(longName, shortName) compound.array = isArray for attrData in attrMap: child = addAttribute(node, shortName=attrData["name"], longName=attrData["name"], attrType=attrData["type"], isArray=attrData["isArray"], apply=False) compound.addChild(child.object()) mod = om2.MDGModifier() mod.addAttribute(node, compObj) mod.doIt() return compObj
def _addSeqAttr(obj): ''' Add `.sequence` attribute to a Script node to enable the custom Sequence api. Safe to run repeatedly since it only adds required attrs. ''' if not obj: return if not obj.hasAttr('sequence'): mobj = core.capi.asMObject(obj) cattr = OpenMaya.MFnCompoundAttribute() nattr = OpenMaya.MFnNumericAttribute() tattr = OpenMaya.MFnTypedAttribute() mattr = OpenMaya.MFnMessageAttribute() sequence = cattr.create("sequence", 'seq') cattr.array = True for long, short, type in _dataSequenceAttr: if type is OpenMaya.MFnStringData.kString: newAttr = tattr.create(long, short, type) elif type is OpenMaya.MFnNumericData.kInt: newAttr = nattr.create(long, short, type, 0) elif type == 'message': newAttr = mattr.create(long, short) cattr.addChild(newAttr) mobj.addAttribute(sequence) if not obj.hasAttr('animNotes'): obj.addAttr('animNotes', dt='string') obj.animNotes.set('')
def _addOutputControls(obj, side): ''' Adds attributes to card for tracking the created controls. Used in conjunction with OutputControls. :param PyNode obj: The card to add attributes to :param str side: Either "Left", "Right" or "Center" ''' if obj.hasAttr('output' + side): return mobj = core.capi.asMObject(obj) cattr = OpenMaya.MFnCompoundAttribute() mattr = OpenMaya.MFnMessageAttribute() nattr = OpenMaya.MFnNumericAttribute() extraNodes = cattr.create('output' + side, 'out' + side[0]) cattr.array = True link = mattr.create('outputLink' + side, 'ol' + side[0]) type = nattr.create('out' + side + 'Type', 'o' + side[0] + 't', OpenMaya.MFnNumericData.kInt, 0) cattr.addChild(link) cattr.addChild(type) mobj.addAttribute(extraNodes)
def removeExtraPath(self, transform, index): """ Removes an attribute inside the compound attribute. Removes the index attr and the rest of attributes, then recreate the rest of attributes. Args: transform: Pymel.core.nodetypes.Transform index: index of attr to delete inside the compound attr """ assert isinstance(transform, pm.nodetypes.Transform), 'Transform arg must be a Pymel.core.nodetypes.Transform' # store path attributes paths = transform.attr(self.attrCompoundName).get() # get mDagPath mSellist = OpenMaya.MSelectionList().add(str(transform)) mDagPath = mSellist.getDagPath(0) # access to compound attribute, we need to delete desired paths mFnTransform = OpenMaya.MFnTransform(mDagPath) compoundAttr = mFnTransform.attribute(self.attrCompoundName) mfnCompoundAttr = OpenMaya.MFnCompoundAttribute(compoundAttr) for i in range(index, len(paths)): try: # delete path attribute inside compound attribute child = mfnCompoundAttr.child(index) # MObject attribute mFnTransform.removeAttribute(child) # use OpenMaya.MFnTransform to delete the attribute except: logger.warn('can not delete attr: %s.%s%s' % (transform, self.attrPathName, index)) # once we have deleted all attributes, we recreate the rest of attributes for i in range(index, len(paths)): if i != index: self.addExtraPathAttr(transform, paths[i])
def creator(longName, shortName): children = [ creator(longName + str(i), shortName + str(i)) for (i, (fnclass, creator)) in enumerate(childrenCreators) ] if Plug._isVector(type): # special case for compound of homogeneous numeric or unit types # using MFnCompoundAttribute is not enough as maya won't create # unitConversion nodes on plug parent on connection in this case # We need to create a MFnNumericAttribute to solve that args = [longName, shortName] + children obj = OpenMaya.MFnNumericAttribute().create(*args) else: obj = OpenMaya.MFnCompoundAttribute().create( longName, shortName) attr = OpenMaya.MFnCompoundAttribute(obj) for child in children: attr.addChild(child) return obj
def create_skeleton_compound(classtype, name): mComp = OpenMaya.MFnCompoundAttribute() compound = mComp.create(name, name) setattr(classtype, name, compound) mComp.array = True mComp.storable = True mComp.writable = True mAttr = OpenMaya.MFnMatrixAttribute() srcMatrix = mAttr.create(name + "SrcMatrix", name + "SrcMatrix") setattr(classtype, name + "SrcMatrix", srcMatrix) mAttr.array = False mAttr.storable = True mAttr.writable = True nAttr = OpenMaya.MFnNumericAttribute() boneParent = nAttr.create(name + "BoneParent", name + "BoneParent", OpenMaya.MFnNumericData.kInt, -1) setattr(classtype, name + "BoneParent", boneParent) nAttr.array = False nAttr.storable = True nAttr.writable = True nAttr = OpenMaya.MFnNumericAttribute() translateScale = nAttr.create(name + "TranslateScale", name + "TranslateScale", OpenMaya.MFnNumericData.kFloat, 0) setattr(classtype, name + "TranslateScale", translateScale) nAttr.array = False nAttr.storable = True nAttr.writable = True nAttr = OpenMaya.MFnNumericAttribute() targetTranslate = nAttr.create(name + "TargetTranslate", name + "TargetTranslate", OpenMaya.MFnNumericData.k3Float) setattr(classtype, name + "TargetTranslate", targetTranslate) nAttr.array = False nAttr.storable = True nAttr.writable = True nAttr.keyable = True classtype.addAttribute(srcMatrix) classtype.addAttribute(boneParent) classtype.addAttribute(translateScale) classtype.addAttribute(targetTranslate) mComp.addChild(srcMatrix) mComp.addChild(boneParent) mComp.addChild(translateScale) mComp.addChild(targetTranslate) classtype.addAttribute(compound) return compound
def initialize(cls): unit_attr = om.MFnUnitAttribute() numeric_attr = om.MFnNumericAttribute() compound_attr = om.MFnCompoundAttribute() cls.frame_time = numeric_attr.create("time", "tm", om.MFnNumericData.kDouble, 0.0) numeric_attr.keyable = True numeric_attr.readable = False # This is a compount attribute of 3 values for the input Controller Translate cls.controller_translate = compound_attr.create( "controllerTranslate", 'ct') cls.mct_X = unit_attr.create("controllerTranlateX", "ctX", om.MFnUnitAttribute.kDistance, 0.0) unit_attr.keyable = True unit_attr.readable = False compound_attr.addChild(cls.mct_X) cls.mct_Y = unit_attr.create("controllerTranlateY", "ctY", om.MFnUnitAttribute.kDistance, 0.0) unit_attr.keyable = True unit_attr.readable = False compound_attr.addChild(cls.mct_Y) cls.mct_Z = unit_attr.create("controllerTranlateZ", "ctZ", om.MFnUnitAttribute.kDistance, 0.0) unit_attr.keyable = True unit_attr.readable = False compound_attr.addChild(cls.mct_Z) # Output plugs cls.plant_foot_out = numeric_attr.create("PlantFootOut", "pfo", om.MFnNumericData.kDouble, 0.0) cls.step_forward_out = numeric_attr.create("StepsForward", "sf", om.MFnNumericData.kDouble, 0.0) cls.translateX = numeric_attr.create("TranslateX", "tx", om.MFnNumericData.kDouble, 0.0) cls.translateZ = numeric_attr.create("TranslateZ", "tz", om.MFnNumericData.kDouble, 0.0) cls.rotateY = unit_attr.create("RotateY", "ry", om.MFnUnitAttribute.kAngle, 0.0) cls.addAttribute(cls.frame_time) cls.addAttribute(cls.controller_translate) cls.addAttribute(cls.plant_foot_out) cls.addAttribute(cls.step_forward_out) cls.addAttribute(cls.translateX) cls.addAttribute(cls.translateZ) cls.addAttribute(cls.rotateY) cls.attributeAffects(cls.frame_time, cls.plant_foot_out) cls.attributeAffects(cls.mct_X, cls.step_forward_out) cls.attributeAffects(cls.mct_Y, cls.step_forward_out) cls.attributeAffects(cls.mct_Z, cls.step_forward_out)
def initialize(): nAttrAllPoseInfoList = om.MFnCompoundAttribute() SampleValueBlender.inAllSampleInfoList = nAttrAllPoseInfoList.create( 'allSampleInfoList', 'pil') nAttrAllPoseInfoList.keyable = True nAttrAllPoseInfoList.array = True nAttrAllPoseInfoList.storable = True nAttrAllPoseInfoList.indexMatters = False nAttrPoseName = om.MFnTypedAttribute() SampleValueBlender.inPoseName = nAttrPoseName.create( 'poseName', 'pn', om.MFnData.kString) nAttrPoseName.keyable = True nAttrSampleValue = om.MFnNumericAttribute() SampleValueBlender.inSampleValue = nAttrSampleValue.create( 'sampleValue', 'sv', om.MFnNumericData.kFloat, 0.0) nAttrSampleValue.keyable = True nAttrSampleValue.array = True nAttrSampleValue.storable = True nAttrValueMode = om.MFnEnumAttribute() SampleValueBlender.inSampleValueMode = nAttrValueMode.create( 'sampleValueMode', 'm', 0) nAttrValueMode.addField("normal", 0) nAttrValueMode.addField("multiply", 1) nAttrAllPoseInfoList.addChild(SampleValueBlender.inPoseName) nAttrAllPoseInfoList.addChild(SampleValueBlender.inSampleValue) nAttrAllPoseInfoList.addChild(SampleValueBlender.inSampleValueMode) nAttrNum1 = om.MFnNumericAttribute() SampleValueBlender.inOverridingIntensity = nAttrNum1.create( "overridingIntensity", "oi", om.MFnNumericData.kFloat, 0.0) nAttrNum1.keyable = False nAttrNum2 = om.MFnNumericAttribute() SampleValueBlender.inOverridingWeight = nAttrNum2.create( "overridingWeight", "ow", om.MFnNumericData.kFloat, 1.0) nAttrNum2.keyable = False nAttrOut = om.MFnNumericAttribute() SampleValueBlender.outWeightList = nAttrOut.create( 'outWeightList', 'owl', om.MFnNumericData.kFloat, 0.0) nAttrOut.array = True nAttrOut.storable = True nAttrOut.usesArrayDataBuilder = True # add the attributes om.MPxNode.addAttribute(SampleValueBlender.inAllSampleInfoList) om.MPxNode.addAttribute(SampleValueBlender.outWeightList) om.MPxNode.attributeAffects(SampleValueBlender.inAllSampleInfoList, SampleValueBlender.outWeightList)
def _create_max_comp_attr(cls): """Create attr. """ comp_attr = OpenMaya.MFnCompoundAttribute() cls.barMaxComp = comp_attr.create("barMaxComp", "maxc") # has max has_max_attr = OpenMaya.MFnNumericAttribute() cls.barHasMax = has_max_attr.create("barHasMax", "hMax", OpenMaya.MFnNumericData.kBoolean, ValueBarLocatorData.barHasMax) # max visibility max_vis_attr = OpenMaya.MFnNumericAttribute() cls.barMaxVisibility = max_vis_attr.create( "barMaxVisibility", "maxV", OpenMaya.MFnNumericData.kBoolean, ValueBarLocatorData.barMaxVisibility) # max value max_val_attr = OpenMaya.MFnNumericAttribute() cls.barMaxValue = max_val_attr.create("barMaxValue", "max", OpenMaya.MFnNumericData.kFloat, ValueBarLocatorData.barMaxValue) # max color max_col_attr = OpenMaya.MFnNumericAttribute() cls.barMaxColor = max_col_attr.create( "barMaxColor", "maxC", OpenMaya.MFnNumericData.k3Double, ) max_col_attr.usedAsColor = True max_col_attr.default = ValueBarLocatorData.barMaxColor # create attr hierarchy comp_attr.addChild(cls.barHasMax) comp_attr.addChild(cls.barMaxVisibility) comp_attr.addChild(cls.barMaxValue) comp_attr.addChild(cls.barMaxColor) # add comp attr res = cls.addAttribute(cls.barMaxComp) return res
def _create_min_comp_attr(cls): """Create attr. """ comp_attr = OpenMaya.MFnCompoundAttribute() cls.barMinComp = comp_attr.create("barMinComp", "minc") # has min has_min_attr = OpenMaya.MFnNumericAttribute() cls.barHasMin = has_min_attr.create("barHasMin", "hMin", OpenMaya.MFnNumericData.kBoolean, ValueBarLocatorData.barHasMin) # min visibility min_vis_attr = OpenMaya.MFnNumericAttribute() cls.barMinVisibility = min_vis_attr.create( "barMinVisibility", "minV", OpenMaya.MFnNumericData.kBoolean, ValueBarLocatorData.barMinVisibility) # min value min_val_attr = OpenMaya.MFnNumericAttribute() cls.barMinValue = min_val_attr.create("barMinValue", "min", OpenMaya.MFnNumericData.kFloat, ValueBarLocatorData.barMinValue) # min color min_col_attr = OpenMaya.MFnNumericAttribute() cls.barMinColor = min_col_attr.create( "barMinColor", "minC", OpenMaya.MFnNumericData.k3Double, ) min_col_attr.usedAsColor = True min_col_attr.default = ValueBarLocatorData.barMinColor # create attr hierarchy comp_attr.addChild(cls.barHasMin) comp_attr.addChild(cls.barMinVisibility) comp_attr.addChild(cls.barMinValue) comp_attr.addChild(cls.barMinColor) # add comp attr res = cls.addAttribute(cls.barMinComp) return res
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)
def addAttributes(self, path=defaultPath): """ This method adds the attributes necessary to use the script. At the end, refresh the self list. Is necessary use constructList after this method for refresh the items list Args: path: path where export the fbx """ # todo: extract attr creation out of the loop # get active selection mSelList = OpenMaya.MGlobal.getActiveSelectionList() mSelList_It = OpenMaya.MItSelectionList(mSelList, OpenMaya.MFn.kTransform) # iterate and find if items with the attribute, if have not, add. while not mSelList_It.isDone(): transform = mSelList_It.getDagPath() transform_DN = mSelList_It.getDependNode() transform_fn = OpenMaya.MFnTransform(transform) # create attributes fAttr = OpenMaya.MFnNumericAttribute() boolAttr = fAttr.create(self.attrBoolName, self.attrBoolName, OpenMaya.MFnNumericData.kBoolean, True) # get an mObject atttr fAttr.keyable = True fAttr.storable = True fAttr.readable = True fAttr.writable = True # compoundAttr fAttr = OpenMaya.MFnCompoundAttribute() compoundAttr = fAttr.create(self.attrCompoundName, 'fe') fAttr.addChild(boolAttr) fAttr.keyable = True fAttr.storable = True fAttr.readable = True fAttr.writable = True # check if we have yet the attribute if transform_fn.hasAttribute(self.attrBoolName): logger.info('%s already has attribute: %s' % (transform, self.attrBoolName)) else: # add attribute if it does not exist in the node transform_fn.addAttribute(compoundAttr) self.addExtraPathAttr(transform_DN,path) mSelList_It.next()
def addJointArrayAttr(obj): ''' .. todo:: Eventually this should be abstracted. ''' mobj = core.capi.asMObject(obj) cAttr = OpenMaya.MFnCompoundAttribute() mList = cAttr.create('joints', 'jnts') cAttr.array = True mAttr = OpenMaya.MFnMessageAttribute() jMsg = mAttr.create('jmsg', 'jmsg') cAttr.addChild(jMsg) mobj.addAttribute(mList)
def create_capsule_compound(classtype, name): mComp = OpenMaya.MFnCompoundAttribute() compound = mComp.create(name, name) setattr(classtype, name, compound) mComp.array = False mComp.storable = True mComp.writable = True mAttr = OpenMaya.MFnMatrixAttribute() matrix = mAttr.create(name + "Matrix", name + "Matrix") setattr(classtype, name + "Matrix", matrix) mAttr.array = False mAttr.storable = True mAttr.writable = True nAttr = OpenMaya.MFnNumericAttribute() radius = nAttr.create(name + "Radius", name + "Radius", OpenMaya.MFnNumericData.kDouble, 0.5) setattr(classtype, name + "Radius", radius) nAttr.array = False nAttr.storable = True nAttr.writable = True nAttr = OpenMaya.MFnNumericAttribute() height = nAttr.create(name + "Height", name + "Height", OpenMaya.MFnNumericData.kDouble, 1.0) setattr(classtype, name + "Height", height) nAttr.array = False nAttr.storable = True nAttr.writable = True classtype.addAttribute(matrix) classtype.addAttribute(radius) classtype.addAttribute(height) mComp.addChild(matrix) mComp.addChild(radius) mComp.addChild(height) classtype.addAttribute(compound) return compound
def addAttribute(): m_selectionList = OpenMaya.MGlobal.getActiveSelectionList() # mobject of first item of Mselection m_DepNode = m_selectionList.getDependNode(0) # set FnDependencyNode m_node_fn = OpenMaya.MFnDependencyNode(m_DepNode) #BoolAttribute fAttr = OpenMaya.MFnNumericAttribute() aSampleBool = fAttr.create('SampleBool', 'sb', OpenMaya.MFnNumericData.kBoolean, True) # get an mObject atttr fAttr.keyable = True fAttr.storable = True fAttr.readable = True fAttr.writable = True #StringAttribute fAttr = OpenMaya.MFnTypedAttribute() aSampleText = fAttr.create('sampleTXT', 'st', OpenMaya.MFnData.kString) fAttr.keyable = True fAttr.storable = True fAttr.readable = True fAttr.writable = True #multi Compound Attribute fAttr = OpenMaya.MFnCompoundAttribute() aCompound = fAttr.create('sampleCompound', 'sc') fAttr.addChild(aSampleBool) fAttr.addChild(aSampleText) # fAttr.array = True # this create a way to duplicate the attr multiple times fAttr.keyable = True fAttr.storable = True fAttr.readable = True fAttr.writable = True m_node_fn.addAttribute(aCompound)
def initialize(): # output Weight nAttr = om.MFnNumericAttribute() compositeCentroidNode.outputWeight = nAttr.create( 'outputWeight', 'ow', om.MFnNumericData.kFloat, 0.0) compositeCentroidNode.addAttribute(compositeCentroidNode.outputWeight) # output Position nAttr = om.MFnNumericAttribute() compositeCentroidNode.outputPosition = nAttr.create( 'outputPosition', 'op', om.MFnNumericData.k3Float, 1.0) compositeCentroidNode.addAttribute( compositeCentroidNode.outputPosition) # input child nAttr = om.MFnNumericAttribute() compositeCentroidNode.inputWeight = nAttr.create( "weight", "w", om.MFnNumericData.kFloat, 0) nAttr.readable = True nAttr = om.MFnNumericAttribute() compositeCentroidNode.inputPosition = nAttr.create( "position", "p", om.MFnNumericData.k3Float) nAttr.readable = True # input Array cAttr = om.MFnCompoundAttribute() compositeCentroidNode.inputArray = cAttr.create("inputArray", "ia") cAttr.array = True cAttr.readable = False cAttr.indexMatters = False cAttr.addChild(compositeCentroidNode.inputWeight) cAttr.addChild(compositeCentroidNode.inputPosition) cAttr.readable = True cAttr.usesArrayDataBuilder = True compositeCentroidNode.addAttribute(compositeCentroidNode.inputArray) compositeCentroidNode.attributeAffects( compositeCentroidNode.inputArray, compositeCentroidNode.outputPosition )
def initialize(): numericAttr = om.MFnNumericAttribute() compoundAttr = om.MFnCompoundAttribute() # output prVectorBlend.output = numericAttr.createPoint('output', 'output') numericAttr.array = True numericAttr.usesArrayDataBuilder = True numericAttr.writable = False prVectorBlend.addAttribute(prVectorBlend.output) # input prVectorBlend.blender = numericAttr.create('blender', 'blender', om.MFnNumericData.kFloat, defaultValue=0.5) numericAttr.setSoftMin(0.0) numericAttr.setSoftMax(1.0) numericAttr.keyable = True prVectorBlend.addAttribute(prVectorBlend.blender) prVectorBlend.attributeAffects(prVectorBlend.blender, prVectorBlend.output) prVectorBlend.normalizeOutput = numericAttr.create('normalizeOutput', 'normalizeOutput', om.MFnNumericData.kBoolean, False) numericAttr.keyable = True prVectorBlend.addAttribute(prVectorBlend.normalizeOutput) prVectorBlend.attributeAffects(prVectorBlend.normalizeOutput, prVectorBlend.output) prVectorBlend.input1 = numericAttr.createPoint('input1', 'input1') numericAttr.keyable = True prVectorBlend.input2 = numericAttr.createPoint('input2', 'input2') numericAttr.keyable = True prVectorBlend.input = compoundAttr.create('input', 'input') compoundAttr.addChild(prVectorBlend.input1) compoundAttr.addChild(prVectorBlend.input2) compoundAttr.array = True prVectorBlend.addAttribute(prVectorBlend.input) prVectorBlend.attributeAffects(prVectorBlend.input1, prVectorBlend.output) prVectorBlend.attributeAffects(prVectorBlend.input2, prVectorBlend.output)
def initialize(): nAttrBaseMesh = om.MFnTypedAttribute() FacialControllerConstraint.inBaseMesh = nAttrBaseMesh.create( 'inBaseMesh', 'ibm', om.MFnMeshData.kMesh) nAttrBaseMesh.keyable = True nAttr1 = om.MFnNumericAttribute() FacialControllerConstraint.inPointIndex = nAttr1.create( 'inPointIndex', 'ivi', om.MFnNumericData.kInt, 0) nAttr1.keyable = True nAttr2 = om.MFnNumericAttribute() FacialControllerConstraint.inWeightList = nAttr2.create( 'inWeightList', 'iwl', om.MFnNumericData.kFloat, 0.0) nAttr2.keyable = True nAttr2.array = True nAttr2 = om.MFnNumericAttribute() FacialControllerConstraint.inOffsetX = nAttr2.create( 'inOffsetX', 'iox', om.MFnNumericData.kFloat, 0.0) nAttr2.keyable = True nAttr2 = om.MFnNumericAttribute() FacialControllerConstraint.inOffsetY = nAttr2.create( 'inOffsetY', 'ioy', om.MFnNumericData.kFloat, 0.0) nAttr2.keyable = True nAttr2 = om.MFnNumericAttribute() FacialControllerConstraint.inOffsetZ = nAttr2.create( 'inOffsetZ', 'ioz', om.MFnNumericData.kFloat, 0.0) nAttr2.keyable = True nAttrBlendshapeInfoList = om.MFnCompoundAttribute() FacialControllerConstraint.inBlendshapeInfoList = nAttrBlendshapeInfoList.create( 'inBlendshapeInfoList', 'ibsl') nAttrBlendshapeInfoList.keyable = True nAttrBlendshapeInfoList.array = True nAttrBlendshapeInfoList.indexMatters = False nAttr0 = om.MFnTypedAttribute() FacialControllerConstraint.inMesh = nAttr0.create( 'inMesh', 'ims', om.MFnMeshData.kMesh) nAttr0.keyable = True nAttrBlendshapeInfoList.addChild(FacialControllerConstraint.inMesh) nAttrBlendshapeInfoList.addChild( FacialControllerConstraint.inWeightList) nAttrOut = om.MFnNumericAttribute() FacialControllerConstraint.outPositionX = nAttrOut.create( 'outPositionX', 'ox', om.MFnNumericData.kFloat, 0.0) nAttrOut.keyable = False nAttrOut.storable = False FacialControllerConstraint.outPositionY = nAttrOut.create( 'outPositionY', 'oy', om.MFnNumericData.kFloat, 0.0) nAttrOut.keyable = False nAttrOut.storable = False FacialControllerConstraint.outPositionZ = nAttrOut.create( 'outPositionZ', 'oz', om.MFnNumericData.kFloat, 0.0) nAttrOut.keyable = False nAttrOut.storable = False # add the attributes om.MPxNode.addAttribute( FacialControllerConstraint.inBlendshapeInfoList) om.MPxNode.addAttribute(FacialControllerConstraint.inPointIndex) om.MPxNode.addAttribute(FacialControllerConstraint.inBaseMesh) om.MPxNode.addAttribute(FacialControllerConstraint.inOffsetX) om.MPxNode.addAttribute(FacialControllerConstraint.inOffsetY) om.MPxNode.addAttribute(FacialControllerConstraint.inOffsetZ) om.MPxNode.addAttribute(FacialControllerConstraint.outPositionX) om.MPxNode.addAttribute(FacialControllerConstraint.outPositionY) om.MPxNode.addAttribute(FacialControllerConstraint.outPositionZ) # establish effects on output om.MPxNode.attributeAffects(FacialControllerConstraint.inPointIndex, FacialControllerConstraint.outPositionX) om.MPxNode.attributeAffects(FacialControllerConstraint.inPointIndex, FacialControllerConstraint.outPositionY) om.MPxNode.attributeAffects(FacialControllerConstraint.inPointIndex, FacialControllerConstraint.outPositionZ) om.MPxNode.attributeAffects(FacialControllerConstraint.inOffsetX, FacialControllerConstraint.outPositionX) om.MPxNode.attributeAffects(FacialControllerConstraint.inOffsetY, FacialControllerConstraint.outPositionY) om.MPxNode.attributeAffects(FacialControllerConstraint.inOffsetZ, FacialControllerConstraint.outPositionZ) om.MPxNode.attributeAffects( FacialControllerConstraint.inBlendshapeInfoList, FacialControllerConstraint.outPositionX) om.MPxNode.attributeAffects( FacialControllerConstraint.inBlendshapeInfoList, FacialControllerConstraint.outPositionY) om.MPxNode.attributeAffects( FacialControllerConstraint.inBlendshapeInfoList, FacialControllerConstraint.outPositionZ)
def nodeInitializer(): ''' Defines the input and output attributes as static variables in our plug-in class. ''' # The following function set will allow us to create our attributes. angleAttributeFn = OpenMaya.MFnUnitAttribute() numericAttributeFn = OpenMaya.MFnNumericAttribute() compoundAttributeFn = OpenMaya.MFnCompoundAttribute() #==================================# # INPUT NODE ATTRIBUTE(S) # #==================================# robotLimitRotation.JinAttr = angleAttributeFn.create( 'jIn', 'jIn', OpenMaya.MFnUnitAttribute.kAngle) angleAttributeFn.storable = True angleAttributeFn.writable = True angleAttributeFn.hidden = False robotLimitRotation.addAttribute(robotLimitRotation.JinAttr) ## Limits ## robotLimitRotation.limits = compoundAttributeFn.create( 'jointLimits', 'jointLimits') robotLimitRotation.upperLimitAttr = angleAttributeFn.create( 'upperLimit', 'upperLimit', OpenMaya.MFnUnitAttribute.kAngle) angleAttributeFn.storable = True angleAttributeFn.writable = True angleAttributeFn.hidden = False compoundAttributeFn.addChild(robotLimitRotation.upperLimitAttr) robotLimitRotation.lowerLimitAttr = angleAttributeFn.create( 'lowerLimit', 'lowerLimit', OpenMaya.MFnUnitAttribute.kAngle) angleAttributeFn.storable = True angleAttributeFn.writable = True angleAttributeFn.hidden = False compoundAttributeFn.addChild(robotLimitRotation.lowerLimitAttr) robotLimitRotation.addAttribute(robotLimitRotation.limits) #----------# robotLimitRotation.ikAttr = numericAttributeFn.create( 'ik', 'ik', OpenMaya.MFnNumericData.kBoolean, 1) numericAttributeFn.writable = True numericAttributeFn.storable = True numericAttributeFn.hidden = False robotLimitRotation.addAttribute(robotLimitRotation.ikAttr) #==================================# # OUTPUT NODE ATTRIBUTE(S) # #==================================# robotLimitRotation.JoutAttr = angleAttributeFn.create( 'jOut', 'jOut', OpenMaya.MFnUnitAttribute.kAngle) angleAttributeFn.storable = False angleAttributeFn.writable = False angleAttributeFn.readable = True angleAttributeFn.hidden = False robotLimitRotation.addAttribute(robotLimitRotation.JoutAttr) #===================================# # NODE ATTRIBUTE DEPENDENCIES # #===================================# robotLimitRotation.attributeAffects(robotLimitRotation.JinAttr, robotLimitRotation.JoutAttr) robotLimitRotation.attributeAffects(robotLimitRotation.upperLimitAttr, robotLimitRotation.JoutAttr) robotLimitRotation.attributeAffects(robotLimitRotation.lowerLimitAttr, robotLimitRotation.JoutAttr) robotLimitRotation.attributeAffects(robotLimitRotation.ikAttr, robotLimitRotation.JoutAttr)
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)
def initialize(): nAttr0 = om.MFnMatrixAttribute() MatrixCombine.inInitialMatrix = nAttr0.create('initialMatrix', 'im') nAttr0.keyable = False nAttrAllWeightList = om.MFnCompoundAttribute() MatrixCombine.inAllPoseInfoList = nAttrAllWeightList.create( 'allPoseInfoList', 'pil') nAttrAllWeightList.keyable = True nAttrAllWeightList.array = True nAttrAllWeightList.storable = True nAttrAllWeightList.indexMatters = False nAttrPoseName = om.MFnTypedAttribute() MatrixCombine.inPoseName = nAttrPoseName.create( 'poseName', 'pl', om.MFnData.kString) nAttrPoseName.keyable = True nAttrMatList = om.MFnMatrixAttribute() MatrixCombine.inPoseMatrix = nAttrMatList.create("poseMatrix", 'pm') nAttrMatList.keyable = True nAttrWeightInPose = om.MFnNumericAttribute() MatrixCombine.inPoseWeights = nAttrWeightInPose.create( 'poseWeightList', 'pwl', om.MFnNumericData.kFloat, 0.0) nAttrWeightInPose.keyable = True nAttrWeightInPose.array = True nAttrWeightInPose.storable = True nAttrWeightInPose.indexMatters = False nAttrAllWeightList.addChild(MatrixCombine.inPoseName) nAttrAllWeightList.addChild(MatrixCombine.inPoseMatrix) nAttrAllWeightList.addChild(MatrixCombine.inPoseWeights) nAttrNum = om.MFnNumericAttribute() MatrixCombine.inEditMode = nAttrNum.create("editMode", "emd", om.MFnNumericData.kFloat, 0.0) nAttrNum.keyable = False nAttrEditMatrix = om.MFnMatrixAttribute() MatrixCombine.inEditMatrix = nAttrEditMatrix.create( "editMatrix", "emx") nAttrEditMatrix.keyable = False nAttrNum1 = om.MFnNumericAttribute() MatrixCombine.inOverridingIntensity = nAttrNum1.create( "overridingIntensity", "oi", om.MFnNumericData.kFloat, 0.0) nAttrNum1.keyable = False nAttrNum2 = om.MFnNumericAttribute() MatrixCombine.inOverridingWeight = nAttrNum2.create( "overridingWeight", "ow", om.MFnNumericData.kFloat, 1.0) nAttrNum2.keyable = False nAttrNum2 = om.MFnNumericAttribute() MatrixCombine.inOverridingPoseIndex = nAttrNum2.create( "overridingPoseIndex", "oid", om.MFnNumericData.kInt, 0) nAttrNum2.keyable = False nAttrOut = om.MFnNumericAttribute() MatrixCombine.outTranslationX = nAttrOut.create( 'outTranslationX', 'otx', om.MFnNumericData.kFloat, 0.0) nAttrOut.keyable = False nAttrOut.storable = False nAttrOut = om.MFnNumericAttribute() MatrixCombine.outTranslationY = nAttrOut.create( 'outTranslationY', 'oty', om.MFnNumericData.kFloat, 0.0) nAttrOut.keyable = False nAttrOut.storable = False nAttrOut = om.MFnNumericAttribute() MatrixCombine.outTranslationZ = nAttrOut.create( 'outTranslationZ', 'otz', om.MFnNumericData.kFloat, 0.0) nAttrOut.keyable = False nAttrOut.storable = False nAttrOut = om.MFnUnitAttribute() MatrixCombine.outRotationX = nAttrOut.create( 'outRotationX', 'orx', om.MFnUnitAttribute.kAngle, 0.0) nAttrOut.keyable = False nAttrOut.storable = False nAttrOut = om.MFnUnitAttribute() MatrixCombine.outRotationY = nAttrOut.create( 'outRotationY', 'ory', om.MFnUnitAttribute.kAngle, 0.0) nAttrOut.keyable = False nAttrOut.storable = False nAttrOut = om.MFnUnitAttribute() MatrixCombine.outRotationZ = nAttrOut.create( 'outRotationZ', 'orz', om.MFnUnitAttribute.kAngle, 0.0) nAttrOut.keyable = False nAttrOut.storable = False # add the attributes om.MPxNode.addAttribute(MatrixCombine.inInitialMatrix) om.MPxNode.addAttribute(MatrixCombine.inEditMode) om.MPxNode.addAttribute(MatrixCombine.inEditMatrix) om.MPxNode.addAttribute(MatrixCombine.inOverridingPoseIndex) om.MPxNode.addAttribute(MatrixCombine.inOverridingIntensity) om.MPxNode.addAttribute(MatrixCombine.inOverridingWeight) om.MPxNode.addAttribute(MatrixCombine.inAllPoseInfoList) om.MPxNode.addAttribute(MatrixCombine.outTranslationX) om.MPxNode.addAttribute(MatrixCombine.outTranslationY) om.MPxNode.addAttribute(MatrixCombine.outTranslationZ) om.MPxNode.addAttribute(MatrixCombine.outRotationX) om.MPxNode.addAttribute(MatrixCombine.outRotationY) om.MPxNode.addAttribute(MatrixCombine.outRotationZ) # establish effects on output om.MPxNode.attributeAffects(MatrixCombine.inOverridingIntensity, MatrixCombine.outTranslationX) om.MPxNode.attributeAffects(MatrixCombine.inOverridingPoseIndex, MatrixCombine.outTranslationX) om.MPxNode.attributeAffects(MatrixCombine.inOverridingWeight, MatrixCombine.outTranslationX) om.MPxNode.attributeAffects(MatrixCombine.inInitialMatrix, MatrixCombine.outTranslationX) om.MPxNode.attributeAffects(MatrixCombine.inAllPoseInfoList, MatrixCombine.outTranslationX) om.MPxNode.attributeAffects(MatrixCombine.inEditMode, MatrixCombine.outTranslationX) om.MPxNode.attributeAffects(MatrixCombine.inAllPoseInfoList, MatrixCombine.outRotationX) om.MPxNode.attributeAffects(MatrixCombine.inAllPoseInfoList, MatrixCombine.outRotationY) om.MPxNode.attributeAffects(MatrixCombine.inAllPoseInfoList, MatrixCombine.outRotationZ)
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)
def nodeInitializer(): ''' Defines the input and output attributes as static variables in our plug-in class. ''' # The following function set will allow us to create our attributes. angleAttributeFn = OpenMaya.MFnUnitAttribute() numericAttributeFn = OpenMaya.MFnNumericAttribute() compoundAttributeFn = OpenMaya.MFnCompoundAttribute() #==================================# # INPUT NODE ATTRIBUTE(S) # #==================================# robotLimitBlender.value_in_attr = angleAttributeFn.create( 'value', 'value', OpenMaya.MFnUnitAttribute.kAngle) angleAttributeFn.storable = True angleAttributeFn.writable = True angleAttributeFn.hidden = False robotLimitBlender.addAttribute(robotLimitBlender.value_in_attr) ## Limits ## robotLimitBlender.limits = compoundAttributeFn.create( 'axisLimits', 'axisLimits') robotLimitBlender.upper_limit_attr = angleAttributeFn.create( 'upperLimit', 'upperLimit', OpenMaya.MFnUnitAttribute.kAngle) angleAttributeFn.storable = True angleAttributeFn.writable = True angleAttributeFn.hidden = False compoundAttributeFn.addChild(robotLimitBlender.upper_limit_attr) robotLimitBlender.lower_limit_attr = angleAttributeFn.create( 'lowerLimit', 'lowerLimit', OpenMaya.MFnUnitAttribute.kAngle) angleAttributeFn.storable = True angleAttributeFn.writable = True angleAttributeFn.hidden = False compoundAttributeFn.addChild(robotLimitBlender.lower_limit_attr) robotLimitBlender.addAttribute(robotLimitBlender.limits) #----------# robotLimitBlender.shader_range_attr = numericAttributeFn.create( 'shaderRange', 'shaderRange', OpenMaya.MFnNumericData.kFloat, 20.0) numericAttributeFn.writable = True numericAttributeFn.storable = True numericAttributeFn.hidden = False robotLimitBlender.addAttribute(robotLimitBlender.shader_range_attr) #==================================# # OUTPUT NODE ATTRIBUTE(S) # #==================================# robotLimitBlender.blend_attr = numericAttributeFn.create( 'blend', 'blend', OpenMaya.MFnNumericData.kFloat) numericAttributeFn.storable = False numericAttributeFn.writable = False numericAttributeFn.readable = True numericAttributeFn.hidden = False robotLimitBlender.addAttribute(robotLimitBlender.blend_attr) #===================================# # NODE ATTRIBUTE DEPENDENCIES # #===================================# robotLimitBlender.attributeAffects(robotLimitBlender.value_in_attr, robotLimitBlender.blend_attr) robotLimitBlender.attributeAffects(robotLimitBlender.upper_limit_attr, robotLimitBlender.blend_attr) robotLimitBlender.attributeAffects(robotLimitBlender.lower_limit_attr, robotLimitBlender.blend_attr) robotLimitBlender.attributeAffects(robotLimitBlender.shader_range_attr, robotLimitBlender.blend_attr)
def postConstructor(layer): # backward compatibility for when layers derived from overrideManager class # They were defined as: # " # The overrideManager class has an array of override elements that represents the overrides currently applied to # the scene where each such element holds a connection from the target attribute (the attribute being overridden) # and a connection from the apply node operating on that attribute. If there are more than one apply node # operating on the same target attribute they form a chain where the first one in the chain is connected to the element. # " # i.e. They were the end point of the apply connection override nodes # layer._backwardCompID = None if OpenMaya1_0.MFileIO.isReadingFile(): # if file was saved in a visible layer with override manager attributes used (i.e. connection override using layer as override manager), # then opening file will fail if these attributes are missing. # 1) Create dynamic attribute array on file open # 2) Transfer them to the apply nodes after file open (all apply overrides hold original and most prioritary override hold target) # 3) Remove dynamic attributes array fnCompoundAttr = OpenMaya.MFnCompoundAttribute() aOverrides = fnCompoundAttr.create("overrides", "ovrs") aTarget = utils.createGenericAttr("target", "tg") aApplyNode = utils.createDstMsgAttr("applyNode", "an") fnCompoundAttr.addChild(aTarget) fnCompoundAttr.addChild(aApplyNode) fnCompoundAttr.array = True OpenMaya.MFnDependencyNode(layer.thisMObject()).addAttribute(aOverrides) if not OpenMaya1_0.MFileIO.isReferencingFile(): handle = OpenMaya.MObjectHandle(layer.thisMObject()) def transferAttributes(clientData=None): if layer._backwardCompID is None: return OpenMaya.MSceneMessage.removeCallback(layer._backwardCompID) layer._backwardCompID = None if not handle.isValid(): # layer was destroyed before the end of file open return arrayPlug = OpenMaya.MPlug(layer.thisMObject(), aOverrides) for i in xrange(arrayPlug.evaluateNumElements()): plug = arrayPlug.elementByLogicalIndex(i) target = plug.child(aTarget) applyOv = plug.child(aApplyNode) # target and applyOv plugs are always as a pair. # # Since apply override nodes are always in the scene # (never referenced, and thus never unloaded), the # connection to them must exist. # # The target plug is different: if the target pointed # to a referenced node, that node might not be loaded, # and thus target would not be connected. For versions # of Maya where this code applies, there is no way to # recover the target by name, so the whole apply # override node chain is stale, and should be removed. # Otherwise, connection apply override unapply code # pre-conditions and invariants cannot be guaranteed. # # Correctness is still obtained through brute force # post-read re-application of the render layer (see # model.renderSetup.RenderSetup._afterOpenCB). ao = OpenMaya.MFnDependencyNode( applyOv.source().node()).userNode() if target.isConnected: ao.connectTarget(target.source()) utils.disconnect(target.source(), target) utils.disconnect(applyOv.source(), applyOv) else: # Apply override node chain is stale. Get rid of it. # This will disconnect applyOv from its source. deleteApplyOverrideChain(ao) OpenMaya.MFnDependencyNode(layer.thisMObject()).removeAttribute(aOverrides) # transferAttributes is a closure around declared variables in this function (postConstructor) # That's why it can still reference them when called on after open callback # It's a call-once function (called after file open). # (Attributes only need to be transfered once, applying layers later on will no longer use the layer as override manager) layer._transferAttributes = transferAttributes layer._backwardCompID = OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kAfterOpen, layer._transferAttributes, None)
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)
def processJoint(rootJointDag): dagIter = om.MItDag() dagIter.reset(rootJointDag, om.MItDag.kDepthFirst, om.MFn.kJoint) while not dagIter.isDone(): # Obtain the current item. curJointObj = dagIter.currentItem() # Make our MFnDagNode function set operate on the current DAG object. dagFn = om.MFnDagNode(curJointObj) #dgNodeFn=om.MFnDependencyNode(curJointObj) curJointName = dagFn.name() fatherCount = dagFn.parentCount() childCount = dagFn.childCount() quaternion = om.MQuaternion() if not dagFn.hasAttribute("quaternionVec"): uAttrFn = om.MFnNumericAttribute() qAttrFn = om.MFnCompoundAttribute() qAttr = qAttrFn.create('quaternionVec', 'qn') qAttrX = uAttrFn.create('quaternionVecX', 'qnx', om.MFnNumericData.kDouble) qAttrY = uAttrFn.create('quaternionVecY', 'qny', om.MFnNumericData.kDouble) qAttrZ = uAttrFn.create('quaternionVecZ', 'qnz', om.MFnNumericData.kDouble) qAttrW = uAttrFn.create('quaternionVecW', 'qnw', om.MFnNumericData.kDouble) qAttrFn.addChild(qAttrX) qAttrFn.addChild(qAttrY) qAttrFn.addChild(qAttrZ) qAttrFn.addChild(qAttrW) qAttrFn.writable = True qAttrFn.readable = True qAttrFn.keyable = True qAttrFn.storable = True qAttrFn.displayable = True qAttrFn.channelBox = True qAttrFn.dynamic = True dagFn.addAttribute(qAttr) # The root joint, a.k.a belly joint if "Belly" in curJointName: # Get joint position # To avoid issues like freezeTransform, recommend rotate pivot to attain the position p0 = cmds.xform(curJointName, absolute=True, query=True, worldSpace=True, rotatePivot=True) #translateVec=om.MVector((p0[0],p0[1],p0[2])) for i in range(childCount): childJointObj = dagFn.child(i) childFn = om.MFnDagNode(childJointObj) childJointName = childFn.name() if "Chest" in childJointName: p1 = cmds.xform(childJointName, absolute=True, query=True, worldSpace=True, rotatePivot=True) newUp = om.MVector(p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]) quaternion = om.MVector.kYaxisVector.rotateTo(newUp) # If it is not root joint, a.k.a not Belly joint else: fatherJointObj = dagFn.parent(0) fatherFn = om.MFnDagNode(fatherJointObj) fatherJointName = fatherFn.name() # Find father joint's location to construct quaternion matrix and negative translate matrix p1 = cmds.xform(curJointName, absolute=True, query=True, worldSpace=True, rotatePivot=True) p0 = cmds.xform(fatherJointName, absolute=True, query=True, worldSpace=True, rotatePivot=True) oldUp = om.MVector((p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2])) # Find child joint's location to construct quaternion matrix and translate matrix if childCount == 1: childJointObj = dagFn.child(0) childFn = om.MFnDagNode(childJointObj) childJointName = childFn.name() p2 = cmds.xform(childJointName, absolute=True, query=True, worldSpace=True, rotatePivot=True) newUp = om.MVector(p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]) quaternion = oldUp.rotateTo(newUp) # If has no child joint,i.e. an end joint, then no rotaion is needed, # However, Hip joint is an exception elif childCount == 0: if "Hip" in curJointName: newUp = om.MVector(p0[0] - p1[0], p0[1] - p1[1], p0[2] - p1[2]) quaternion = om.MVector.kYnegAxisVector.rotateTo(newUp) # Have multiple children, e.g. Neck else: if not "Neck" in curJointName: raise ValueError(curJointName + "shouldn't have multiple children") for i in range(childCount): childJointObj = dagFn.child(i) childFn = om.MFnDagNode(childJointObj) childJointName = childFn.name() if "Head" in childJointName: p2 = cmds.xform(childJointName, absolute=True, query=True, worldSpace=True, rotatePivot=True) newUp = om.MVector(p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]) quaternion = oldUp.rotateTo(newUp) # Networked plugs contain the actual connection data between two nodes, # and maybe some other flags as required, such as whether the plug is locked. # Maya is free to create and destroy them as it needs to, and no notifications are sent when that happens. # Non-networked plugs can be thought of as named references to a plug. They belong to you and have the lifespan you dictate. # In C++ terms a non-networked plug is like a copy of an object and a networked plug is like a pointer to it. mPlug = dagFn.findPlug('quaternionVec', False) for i in range(4): childPlug = mPlug.child(i) value = quaternion[i] childPlug.setDouble(value) dagIter.next()