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

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

项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def make_planar(joints):
    for joint in joints:
        parent = cmds.listRelatives(joint, parent=True, path=True)
        if not parent:
            log.warning('Cannot make %s planar because it does not have a parent.', joint)
            continue
        children = _unparent_children(joint)
        if not children:
            log.warning('Cannot make %s planar because it does not have any children.', joint)
            continue
        cmds.delete(cmds.aimConstraint(children[0], joint, aim=(1, 0, 0), u=(0, 1, 0), worldUpType='object', worldUpObject=parent[0]))
        cmds.makeIdentity(joint, apply=True)
        _reparent_children(joint, children)

    if joints:
        cmds.select(joints)
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def align_with_child(joints):
    """Aligns the up axis of the given joints with their respective child joint.

    @param joints: List of joints to orient.
    """
    for joint in joints:
        children = _unparent_children(joint)
        if children:
            cmds.delete(cmds.aimConstraint(children[0], joint, aim=(1, 0, 0), upVector=(0, 1, 0),
                                           worldUpType="objectrotation", worldUpVector=(0, 1, 0),
                                           worldUpObject=children[0]))
            cmds.makeIdentity(joint, apply=True)
        _reparent_children(joint, children)

    if joints:
        cmds.select(joints)
项目:gozbruh    作者:LumaPictures    | 项目源码 | 文件源码
def get_goz_objs():
    """Grab meshes from selection, filter out extraneous DAG objects and
    freeze transforms on objects.
    """
    objs = cmds.ls(selection=True, type='mesh', dag=True)
    if objs:
        xforms = cmds.listRelatives(objs, parent=True, fullPath=True)
        # freeze transform
        cmds.makeIdentity(xforms, apply=True, t=1, r=1, s=1, n=0)
        cmds.select(xforms)
        objs = cmds.ls(selection=True)
    return objs

#------------------------------------------------------------------------------
# Renaming
#------------------------------------------------------------------------------
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def template_joints(joints=None, reorient_children=True, reset_orientation=True):
    if joints is None:
        joints = cmds.ls(sl=True, type='joint')
    if not joints:
        raise RuntimeError('No joint selected to orient.')

    if reorient_children:
        children = cmds.listRelatives(fullPath=True, allDescendents=True, type='joint')
        joints.extend(children)

    red, green, blue = create_shaders()

    orient_group = cmds.createNode('transform', name=ORIENT_GROUP)
    manips = []
    for joint in joints:
        if reset_orientation:
            cmds.makeIdentity(joint, apply=True)
            cmds.joint(joint, edit=True, orientJoint='xyz', secondaryAxisOrient='yup', children=False, zeroScaleOrient=True)
        if not cmds.listRelatives(joint, children=True):
            zero_orient([joint])
            continue
        group, manip = create_orient_manipulator(joint, blue)
        manips.append(manip)
        cmds.parent(group, orient_group)
        cmds.parentConstraint(joint, group)
        cmds.setAttr(joint + '.template', 1)
    cmds.select(manips)
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def create_orient_manipulator(joint, material):
    joint_scale = cmds.jointDisplayScale(query=True)
    joint_radius = cmds.getAttr('{0}.radius'.format(joint))
    radius = joint_scale * joint_radius
    children = cmds.listRelatives(joint, children=True, path=True)
    if children:
        p1 = cmds.xform(joint, q=True, ws=True, t=True)
        p1 = OpenMaya.MPoint(*p1)
        p2 = cmds.xform(children[0], q=True, ws=True, t=True)
        p2 = OpenMaya.MPoint(*p2)
        radius = p1.distanceTo(p2)
    arrow_cvs = [[-1, 0, 0], [-1, 2, 0], [-2, 2, 0], [0, 4, 0], [2, 2, 0], [1, 2, 0], [1, 0, 0], [-1, 0, 0]]
    arrow_cvs = [[x[0]*radius, x[1]*radius, x[2]*radius] for x in arrow_cvs]
    shape = cmds.curve(name='{0}_zForward'.format(joint), degree=1, point=arrow_cvs)
    # shape = cmds.sphere(n='{0}_zForward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0]
    # cmds.setAttr('{0}.sz'.format(shape), 0)
    # cmds.select(shape)
    # cmds.hyperShade(assign=material)
    group = cmds.createNode('transform', name='{0}_grp'.format(shape))
    cmds.parent(shape, group)
    cmds.makeIdentity(shape, apply=True)
    cmds.addAttr(shape, longName=MESSAGE_ATTRIBUTE, attributeType='message')
    cmds.connectAttr('{0}.message'.format(joint), '{0}.{1}'.format(shape, MESSAGE_ATTRIBUTE))
    for attr in ['tx', 'ty', 'tz', 'ry', 'rz', 'v']:
        cmds.setAttr('{0}.{1}'.format(shape, attr), lock=True, keyable=False)
    return group, shape
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_freezeTranslate(box, menuItem, key, *args):
    with sysCmd.Undo():
        if cmds.ls(sl=1):
            cmds.makeIdentity(t=1, r=0, s=0, n=0, a=1)
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_freezeRotate(box, menuItem, key, *args):
    with sysCmd.Undo():
        if cmds.ls(sl=1):
            cmds.makeIdentity(t=0, r=1, s=0, n=0, a=1)
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_freezeScale(box, menuItem, key, *args):
    with sysCmd.Undo():
        if cmds.ls(sl=1):
            cmds.makeIdentity(t=0, r=0, s=1, n=0, a=1)
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_freezeTranslateRotate(box, menuItem, key, *args):
    with sysCmd.Undo():
        if cmds.ls(sl=1):
            cmds.makeIdentity(t=1, r=1, s=0, n=0, a=1)
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_freezeTranslateScale(box, menuItem, key, *args):
    with sysCmd.Undo():
        if cmds.ls(sl=1):
            cmds.makeIdentity(t=1, r=0, s=1, n=0, a=1)
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_freezeJointOrient(box, menuItem, key, *args):
    with sysCmd.Undo():
        if cmds.ls(sl=1):
            cmds.makeIdentity(t=0, r=0, s=0, n=0, jo=1, a=1)
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_freezeAll(box, menuItem, key, *args):
    with sysCmd.Undo():
        state = cmds.menuItem(menuItem, q=1, isOptionBox=1)

        if not state:
            if cmds.ls(sl=1):
                cmds.makeIdentity(t=1, r=1, s=1, n=0, a=1)
        else:
            channelbox_command_freezeUI()
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def boundingBoxCtrl(sel=[], prnt=True, *args):
    """
    creates a control based on the bounding box
    selList (list) - list of obj to use to create control
    prnt (bool) - whether you want to parent the obj to the ctrl
    """

    if not sel:
        sel = cmds.ls(sl=True, type="transform")

    if sel:
        box = cmds.exactWorldBoundingBox(sel) #[xmin, ymin, zmin, xmax, ymax, zmax]
        X = om.MVector(box[0], box[3])
        Y = om.MVector(box[1], box[4])
        Z = om.MVector(box[2], box[5])

        #get bbox lengths along axes
        lenX = (X.y - X.x)
        lenY = (Y.y - Y.x)
        lenZ = (Z.y - Z.x)
        # print lenX, lenY, lenZ

        ctrl = createControl(name="ctrl", type="cube", color="pink")

        cvs ={"xyz":[5, 15],"-xyz":[0, 4],"xy-z":[10, 14],"x-yz":[6, 8],"-x-yz":[3, 7],"-x-y-z":[2, 12],"x-y-z":[9, 13],"-xy-z":[1, 11]}

        for a in cvs["xyz"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.y, Z.y))
        for a in cvs["-xyz"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.y, Z.y))
        for a in cvs["x-yz"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.x, Z.y))
        for a in cvs["-x-yz"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.x, Z.y))
        for a in cvs["xy-z"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.y, Z.x))
        for a in cvs["-xy-z"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.y, Z.x))
        for a in cvs["-x-y-z"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.x, Y.x, Z.x))
        for a in cvs["x-y-z"]:
            cmds.xform("{0}.cv[{1}]".format(ctrl, a), ws=True, t=(X.y, Y.x, Z.x))

        # center pivot on ctrl
        cmds.xform(ctrl, cp=True)

        # get ctrl back to 
        wsPos = cmds.xform(ctrl, ws=True, q=True, rp=True)
        cmds.xform(ctrl, ws=True, t=(-wsPos[0], -wsPos[1], -wsPos[2]))
        cmds.makeIdentity(ctrl, apply=True)
        cmds.xform(ctrl, ws=True, t=wsPos)

        if prnt:
            cmds.parent(sel, ctrl)
        cmds.select(ctrl)

        return(ctrl)
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def parentShape(child=None, parent=None, maintainOffset=True):
    '''
    Parent a child shape node to a parent transform. The child node can be a shape,
    or a transform which has any number of shapes.
    '''

    if not child or not parent:
        sel = mc.ls(sl=True)
        if sel and len(sel) > 1:
            child = sel[:-1]
            parent = sel[-1]
        else:
            OpenMaya.MGlobal.displayWarning('Please make a selection.')
            return

    parentNodeType = mc.nodeType(parent)
    if not parentNodeType in ('transform', 'joint', 'ikHandle'):
        OpenMaya.MGlobal.displayWarning('Parent must be a transform node.')
        return

    if not isinstance(child, (list, tuple)):
        child = [child]

    newChild = unparentShape(child)

    shapes = list()
    for each in newChild:
        thisChild = mc.parent(each, parent)[0]
        mc.makeIdentity(thisChild, apply=True)

        for s in mc.listRelatives(thisChild, shapes=True, noIntermediate=True, path=True):
            shape = mc.parent(s, parent, shape=True, relative=True)[0]
            #move to bottom
            mc.reorder(shape, back=True)

            #rename
            parentName = mc.ls(parent, shortNames=True)[0]
            shapes.append(mc.rename(shape, parentName+'Shape#'))

    mc.delete(newChild)

    for each in child:
        if not mc.listRelatives(each):
            #if it doesn't have any kids, delete it
            mc.delete(each)

    return shapes