Python maya.cmds 模块,spaceLocator() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用maya.cmds.spaceLocator()

项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def test_set_transform_stack(self):
        loc = cmds.spaceLocator(name='spine_ctrl')[0]
        nulls = control.create_transform_stack(loc, 2)
        self.assertEqual(2, len(nulls))
        parent = cmds.listRelatives(loc, parent=True, path=True)[0]
        self.assertEqual('spine_1nul', parent)
        parent = cmds.listRelatives(parent, parent=True, path=True)[0]
        self.assertEqual('spine_2nul', parent)

        nulls = control.create_transform_stack(loc, 3)
        self.assertEqual(3, len(nulls))
        parent = cmds.listRelatives(loc, parent=True, path=True)[0]
        self.assertEqual('spine_1nul', parent)
        parent = cmds.listRelatives(parent, parent=True, path=True)[0]
        self.assertEqual('spine_2nul', parent)
        parent = cmds.listRelatives(parent, parent=True, path=True)[0]
        self.assertEqual('spine_3nul', parent)
项目:SETools    作者:dtzxporter    | 项目源码 | 文件源码
def PlaceNote():
    # Notetrack number
    note_tracks = 0
    # We need to ask for a name
    if not (cmds.objExists("SENotes")):
        # We need to make the SENotes parent first
        base_track = cmds.spaceLocator()
        # Rename
        cmds.rename(base_track, "SENotes")
    # Notetrack name
    noteName = "new_notetrack" + str(note_tracks)
    # Now we can make the child (if you have > 50000 notetracks, we got a problem...)
    for npos in xrange(note_tracks, 50000):
        # Setup
        noteName = "new_notetrack" + str(npos)
        # Check
        if not (cmds.objExists(noteName)):
            # Exit
            break
    # Now make it and parent it
    notetrack = cmds.spaceLocator()
    # Rename
    cmds.rename(notetrack, noteName)
    # Parent it
    mel.eval("parent " + noteName + " SENotes")
    # Get current time
    currentFrame = cmds.currentTime(query = True)
    # Key it
    cmds.setKeyframe(noteName, time = currentFrame)
    # Log it
    print("A new notetrack was created")

# Selects all bones
项目:mayakit    作者:danbradham    | 项目源码 | 文件源码
def new_strand(hair_system=None):

    if not hair_system:
        selection = cmds.ls(sl=True, dag=True, leaf=True, type='hairSystem')
        if selection:
            hair_system = selection[0]

    start = om.MVector(0, 0, 0)
    end = om.MVector(0, 0, 24)

    start_loc = cmds.spaceLocator(name='strand_start#')[0]
    end_loc = cmds.spaceLocator(name='strand_end#')[0]
    cmds.xform(end_loc, ws=True, translation=end)

    tta = cmds.createNode('transformsToArrays')
    cmds.connectAttr(start_loc + '.worldMatrix', tta + '.inTransforms[0].inMatrix')
    cmds.connectAttr(end_loc + '.worldMatrix', tta + '.inTransforms[1].inMatrix')
    pcc = cmds.createNode('pointCloudToCurve')
    cmds.connectAttr(tta + '.outPositionPP', pcc + '.inArray')
    expand_grp = cmds.group([start_loc, end_loc], name='strand_expand_grp#')

    curve, curve_shape = curve_between(start, end, name='strand_curve#')
    cmds.connectAttr(pcc + '.outCurve', curve_shape + '.create')
    root_grp = cmds.group(empty=True, name='strand_grp#')
    cmds.parent([expand_grp, curve], root_grp)

    follicle_nodes, out_curve_nodes = add_curve_to_system(curve_shape, hair_system)
    follicle_shape = follicle_nodes[1]
    cmds.setAttr(follicle_shape + '.pointLock', 3)
    cmds.setAttr(follicle_shape + '.sampleDensity', 24)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def center_locator(*args):
    """creates a center loc on the avg position"""

    sel = cmds.ls(sl=True, fl=True)
    if sel:
        ps = []
        for vtx in sel:
            ps.append(cmds.xform(vtx, q=True, ws=True, rp=True))

        # this is cool!
        center = [sum(y)/len(y) for y in zip(*ps)]

        loc = cmds.spaceLocator(name="center_locator")
        cmds.xform(loc, ws=True, t=center)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def closest_pt_on_mesh_rotation(point, mesh, *args):
# TODO - generalize for various orientations, and various rotation orders
    """
    takes a point (can be name of transform or iterable(3) of rotations and a poly mesh and gives the rotation [rot
    order xyz] (for
    aim along y) align to surface of
    the xform at that point
    """
    if isinstance(point, basestring):
        if isType(point, "transform"):
            cmds.select(point, r=True)
            ptPos = cmds.xform(point, ws=True, q=True, rp=True)
            name = point
        else:
            cmds.warning("zbw_rig.closest_pt_on_mesh_position: the string you gave me isn't a transform")
            return ()
    elif isinstance(point, (list, tuple)):
        if len(point) == 3:
            ptPos = point
            name = mesh
        else:
            cmds.warning("zbw_rig.closest_pt_on_mesh_position: there are not the right number of entries in the "
                         "list you gave me")

    # get the rotations to align to normal at this point
    loc = cmds.spaceLocator()
    CPOMesh = closest_pt_on_mesh_position(point, mesh)
    cmds.xform(loc, ws=True, t=CPOMesh)
    aimVec = (0, 1, 0)
    upVec = (0, 1, 0)
    nc = cmds.normalConstraint(mesh, loc, aim=aimVec, upVector=upVec)
    rot = cmds.xform(loc, ws=True, q=True, ro=True)
    cmds.delete(nc, loc)
    return (rot)
项目:3D_Software_and_Python    作者:p4vv37    | 项目源码 | 文件源码
def change_hierarchy_and_animate():
    """
    Function modifies the hierarchy of scene and creates some final animations, that ware not possible to create earlier.
    It also creates cameras and lights.
    """
    cmds.lookThru( 'perspView', 'RenderCamera1') # Change the perspective viewport to the render camera.

    top_locator = cmds.spaceLocator() # Parent for all the elemements that will rotate together
    objects_list = ['land', 'water', 'cloud', 'shark', ]

    for obj in objects_list:
        cmds.parent(obj, top_locator)

    cmds.setKeyframe(top_locator, attribute='rotateY', v=20, time=260, itt="plateau", ott="plateau")
    cmds.setKeyframe(top_locator, attribute='rotateY', v=0, time=0, itt="linear", ott="linear")

    dome_light = cmds.polySphere(r=500) # This sphere is a substitute of a skylight in 3Ds Max
    cmds.polyNormal(dome_light, normalMode=0) # The normals have to point to inside

    cmds.setAttr(dome_light[0]+".miDeriveFromMaya", 0) # Enable changes in object render settings
    cmds.setAttr(dome_light[0]+".miVisible", 0) # This object will be invisible to camera
    cmds.setAttr(dome_light[0]+".miShadow", 0) # And will not affect shadows
    cmds.rename(dome_light[0], "dome_light")

    area_light = cmds.shadingNode('areaLight', asLight=True)
    cmds.scale(25, 25, 25, area_light, absolute=True)
    cmds.move(-230.59, 178.425, 99.192, area_light)
    cmds.rotate(0, -68.929, -37.987, area_light)

    cmds.setAttr(area_light+".intensity", 120000.0)
    cmds.setAttr(area_light+".areaLight", 1)
    cmds.setAttr(area_light+".areaType", 1)
    cmds.setAttr(area_light+".decayRate", 2)
    cmds.setAttr(area_light+".areaHiSamples", 64)
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def matchPoleVectorControl(jointChain, pv=None, doSnap=True):
    '''
    Position a pole vector based on a 3-joint chain

    '''

    def distanceBetween(a,b):
        difference = [x-y for x,y in zip(a,b)]
        return math.sqrt(sum([x**2 for x in difference]))    

    p1 = mc.xform(jointChain[0], query=True, rotatePivot=True, worldSpace=True)
    p2 = mc.xform(jointChain[1], query=True, rotatePivot=True, worldSpace=True)
    p3 = mc.xform(jointChain[2], query=True, rotatePivot=True, worldSpace=True)

    mag1 = distanceBetween(p2,p1)
    mag2 = distanceBetween(p3,p2)

    #these are all temporary nodes
    loc = mc.spaceLocator(name='TEMP#')[0]

    mc.pointConstraint(jointChain[0], loc, weight=mag2)
    mc.pointConstraint(jointChain[2], loc, weight=mag1)
    mc.aimConstraint(jointChain[1], loc, aimVector=(1,0,0), upVector=(0,1,0), worldUpType='object', worldUpObject=jointChain[0])

    pCenter = mc.xform(loc, query=True, rotatePivot=True, worldSpace=True)
    pPV = mc.xform(pv, query=True, rotatePivot=True, worldSpace=True)
    pvDist = distanceBetween(pPV,pCenter)

    loc2 = mc.spaceLocator(name='TEMP#')[0]
    loc2 = mc.parent(loc2, loc)[0]
    mc.setAttr(loc2+'.translate', (pvDist),0,0)

    if doSnap:
        snap(pv, loc2)
        mc.delete(loc)
    else:
        #for matching a range
        return loc, loc2
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
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_tools    作者:morganloomis    | 项目源码 | 文件源码
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)