python类addAttr()的实例源码

maya_tools.py 文件源码 项目:gozbruh 作者: LumaPictures 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def export(objs):
    """Save files.

    Checks for gozbruhParent attr.

    gozbruhParent is used to import objects in correct order in ZBrush
    gozbruhParent determines the top level tool in ZBrush

    If no instance exists, it is created

    Returns
    -------
    list of (str, str)
        list of object, parent pairs
    """
    parents = []

    for obj in objs:
        # export each file individually
        cmds.select(cl=True)
        cmds.select(obj)
        cmds.delete(ch=True)
        ascii_path = utils.make_maya_filepath(obj)
        cmds.file(ascii_path,
                  force=True,
                  options="v=0",
                  type="mayaAscii",
                  exportSelected=True)
        if cmds.attributeQuery('gozbruhParent', node=obj, exists=True):
            # object existed in zbrush, has 'parent' tool
            parent = cmds.getAttr(obj + '.gozbruhParent')
            # append to the end of parents
            parents.append((obj, parent))
        else:
            cmds.addAttr(obj, longName='gozbruhParent', dataType='string')
            cmds.setAttr(obj + '.gozbruhParent', obj, type='string')
            # prepend to the beginning of parents, we want these objects
            # imported first
            parents = [(obj, obj)] + parents

        # maya is often run as root, this makes sure osx can open/save
        # files not needed if maya is run un-privileged
        os.chmod(ascii_path, 0o777)
    return parents
ml_stopwatch.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def addMarksToScene(marks):
    '''
    This is temp and will possibly be rolled into future releases.
    '''

    start,end = utl.frameRange()
    camera = utl.getCurrentCamera()
    camShape = mc.listRelatives(camera, shapes=True)[0]
    aov = mc.getAttr(camShape+'.horizontalFilmAperture')

    name = 'ml_stopwatch_'

    numStopwatches = len(mc.ls(name+'*', type='locator'))
    top = mc.spaceLocator(name=name+'#')

    ename = ':'.join([str(x) for x in marks])
    mc.addAttr(top, longName='keyTimes', at='enum', enumName=ename, keyable=True)

    markRange = float(marks[-1]-marks[0])
    viewWidth = aov*2
    viewHeight = -0.4*aov+(numStopwatches*aov*0.08)
    depth = 5

    for mark in marks[1:-1]:

        ann = mc.annotate(top, text=str(mark))
        mc.setAttr(ann+'.displayArrow', 0)

        #parent
        annT = mc.parent(mc.listRelatives(ann, parent=True, path=True), top)[0]
        annT = mc.rename(annT, 'mark_'+str(round(mark)))
        ann = mc.listRelatives(annT, shapes=True, path=True)[0]

        #set the position
        normalX = float(mark-marks[0])/markRange-0.5
        mc.setAttr(annT+'.translateX', viewWidth*normalX*2)
        mc.setAttr(annT+'.translateY', viewHeight)
        mc.setAttr(annT+'.translateZ', -depth)

        #keyframe for color
        mc.setAttr(ann+'.overrideEnabled', 1)

        mc.setKeyframe(ann, attribute='overrideColor', value=17, time=(int(marks[0]-1),int(mark+1)))
        mc.setKeyframe(ann, attribute='overrideColor', value=13, time=(int(mark),))
        mc.keyTangent(ann+'.overrideColor', ott='step')


    mc.select(clear=True)    
    mc.parentConstraint(camera, top)
ml_centerOfMass.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def createCenterOfMass(*args):
    '''
    Create a center of mass node, and constrain it to the 
    character based on the selected root node.
    '''

    sel = mc.ls(sl=True)

    if not len(sel) == 1:
        raise RuntimeError('Please select the root control of your puppet.')

    print 'Create Center Of Mass Node'
    print '--------------------------'

    meshes = meshesFromReference(sel[0]) or meshesFromHistory(sel[0])

    if not meshes:
        raise RuntimeError('Could not determine geomerty from selected control. Make sure geo is visible.')

    mc.select(meshes)
    mc.refresh()

    print 'Discovered Meshes:'
    for mesh in meshes:
        print '\t',mesh

    skinnedMeshes = []
    for mesh in meshes:
        if utl.getSkinCluster(mesh):
            skinnedMeshes.append(mesh)
            continue
        hist = mc.listHistory(mesh, breadthFirst=True)
        skins = mc.ls(hist, type='skinCluster')
        if not skins:
            warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh))
            continue
        outGeo = mc.listConnections(skins[0]+'.outputGeometry[0]', source=False)
        outGeo = mc.ls(outGeo, type=['mesh','transform'])
        if not outGeo:
            warnings.warn('Could not find a skinned mesh affecting {}'.format(mesh))
            continue
        skinnedMeshes.append(outGeo[0])

    if not skinnedMeshes:
        raise RuntimeError('Could not determine skinned geometry from selected control. This tool will only work if geo is skinned.')

    locator = centerOfMassLocator(skinnedMeshes)

    mc.addAttr(locator, longName=COM_ATTR, attributeType='message')
    mc.connectAttr('.'.join((sel[0],'message')), '.'.join((locator,COM_ATTR)))

    mc.select(sel)
    return locator
ml_worldBake.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def matchBakeLocators(parent=None, bakeOnOnes=False, constrainSource=False):

    #get neccesary nodes
    objs = mc.ls(sl=True)
    if not objs:
        OpenMaya.MGlobal.displayWarning('Select an Object')
        return

    locs = list()
    cutIndex = dict()
    noKeys = list()
    noKeysLoc = list()

    for obj in objs:


        name = mc.ls(obj, shortNames=True)[0]
        if ':' in name:
            name = obj.rpartition(':')[-1]

        locator = mc.spaceLocator(name='worldBake_'+name+'_#')[0]
        mc.setAttr(locator+'.rotateOrder', 3)


        mc.addAttr(locator, longName='ml_bakeSource', attributeType='message')
        mc.connectAttr('.'.join((obj,'message')), '.'.join((locator,'ml_bakeSource')))
        mc.addAttr(locator, longName='ml_bakeSourceName', dataType='string')
        mc.setAttr('.'.join((locator,'ml_bakeSourceName')), name, type='string')

        if parent:
            locator = mc.parent(locator, parent)[0]

        locs.append(locator)

        #should look through all trans and rot
        if not mc.keyframe(obj, query=True, name=True):
            noKeys.append(obj)  
            noKeysLoc.append(locator)

    utl.matchBake(objs, locs, bakeOnOnes=bakeOnOnes)

    if not bakeOnOnes and noKeys:
        utl.matchBake(noKeys, noKeysLoc, bakeOnOnes=True)

    if constrainSource:
        mc.cutKey(objs)
        for loc, obj in zip(locs, objs):
            mc.parentConstraint(loc, obj)


问题


面经


文章

微信
公众号

扫码关注公众号