當前位置: 首頁>>代碼示例>>Python>>正文


Python cmds.xform方法代碼示例

本文整理匯總了Python中maya.cmds.xform方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.xform方法的具體用法?Python cmds.xform怎麽用?Python cmds.xform使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在maya.cmds的用法示例。


在下文中一共展示了cmds.xform方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: shapeSizeSetup

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def shapeSizeSetup(self, transformNode, *args):
        """ Find shapes, create a cluster deformer to all and set the pivot to transform pivot.
            Returns the created cluster.
        """
        clusterHandle = None
        childShapeList = cmds.listRelatives(transformNode, shapes=True, children=True)
    #    print "Child length {0}".format(len(childShapeList))
        if childShapeList:
            thisNamespace = childShapeList[0].split(":")[0]
            cmds.namespace(set=thisNamespace, force=True)
            clusterName = transformNode.split(":")[1]+"_ShapeSizeCH"
            clusterHandle = cmds.cluster(childShapeList, name=clusterName)[1]
            cmds.setAttr(clusterHandle+".visibility", 0)
            cmds.xform(clusterHandle, scalePivot=(0, 0, 0), worldSpace=True)
            cmds.namespace(set=":")
        else:
            print "There are not children shape to create shapeSize setup of:", transformNode
        return clusterHandle 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:20,代碼來源:dpControls.py

示例2: reset_actor

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def reset_actor():
    from . import sisidebar_sub
    sel = cmds.ls(sl=True, l=True)
    joints = cmds.ls(sl=True, l=True, type='joint')
    if not joints:
        joints = []
    for s in sel:
        if cmds.nodeType(s) == 'KTG_ModelRoot':
            child_joints = cmds.ls(cmds.listRelatives(s, ad=True, f=True), l=True, type='joint')
            if child_joints:
                joints += child_joints
    if not sel:
        joints = cmds.ls(l=True, type='joint')
    for j in joints:
        con_info = cmds.connectionInfo(j+'.bindPose', dfs=True)
        if not con_info:
            continue
        con_info = con_info[0]
        bind_info = con_info.replace('world', 'xform')
        pose = cmds.getAttr(bind_info)
        cmds.xform(j, m=pose)
    sisidebar_sub.get_matrix() 
開發者ID:ShikouYamaue,項目名稱:SISideBar,代碼行數:24,代碼來源:transform.py

示例3: distance

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def distance(node1=None, node2=None):
    """Calculate the distance between two nodes

    :param node1: First node
    :param node2: Second node
    :return: The distance
    """
    if node1 is None or node2 is None:
        # Default to selection
        selection = cmds.ls(sl=True, type='transform')
        if len(selection) != 2:
            raise RuntimeError('Select 2 transforms.')
        node1, node2 = selection

    pos1 = cmds.xform(node1, query=True, worldSpace=True, translation=True)
    pos2 = cmds.xform(node2, query=True, worldSpace=True, translation=True)

    pos1 = OpenMaya.MPoint(pos1[0], pos1[1], pos1[2])
    pos2 = OpenMaya.MPoint(pos2[0], pos2[1], pos2[2])
    return pos1.distanceTo(pos2) 
開發者ID:chadmv,項目名稱:cmt,代碼行數:22,代碼來源:shortcuts.py

示例4: vector_to

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def vector_to(source=None, target=None):
    """Calculate the distance between two nodes

    :param source: First node
    :param target: Second node
    :return: MVector (API2)
    """
    if source is None or target is None:
        # Default to selection
        selection = cmds.ls(sl=True, type='transform')
        if len(selection) != 2:
            raise RuntimeError('Select 2 transforms.')
        source, target = selection

    pos1 = cmds.xform(source, query=True, worldSpace=True, translation=True)
    pos2 = cmds.xform(target, query=True, worldSpace=True, translation=True)

    source = OpenMaya2.MPoint(pos1[0], pos1[1], pos1[2])
    target = OpenMaya2.MPoint(pos2[0], pos2[1], pos2[2])
    return target - source 
開發者ID:chadmv,項目名稱:cmt,代碼行數:22,代碼來源:shortcuts.py

示例5: align

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def align(node, target, axis, world_up):
    """Align an axis of one node to another using offsetParentMatrix.

    :param node: Node to align
    :param target: Node to align to
    :param axis: Local axis to match
    :param world_up: World up axis
    """
    axis = OpenMaya.MVector(axis)
    world_up = OpenMaya.MVector(world_up)
    tm = OpenMaya.MMatrix(cmds.getAttr("{}.worldMatrix[0]".format(target)))
    world_axis = axis * tm
    world_z = world_axis ^ world_up
    world_up = world_z ^ world_axis
    t = cmds.xform(node, q=True, ws=True, t=True)
    x = list(world_axis) + [0.0]
    y = list(world_up) + [0.0]
    z = list(world_z) + [0.0]
    t = [t[0], t[1], t[2], 1.0]
    m = OpenMaya.MMatrix(*[x + y + z + t])
    parent = cmds.listRelatives(node, parent=True, path=True)
    if parent:
        p = OpenMaya.MMatrix(cmds.getAttr("{}.worldInverseMatrix[0]".format(parent[0])))
        m *= p
    cmds.setAttr("{}.offsetParentMatrix".format(node), list(m), type="matrix") 
開發者ID:chadmv,項目名稱:cmt,代碼行數:27,代碼來源:common.py

示例6: place_pole_vector

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def place_pole_vector(start, mid, end, pole_vector, offset):
    """Place a pole vector along the plane of the 2 bone ik

    :param start: Start joint
    :param mid: Mid joint
    :param end: End joint
    :param pole_vector: Pole vector transform
    :param offset: Scalar offset from the mid joint
    """
    v1 = OpenMaya.MVector(cmds.xform(start, q=True, ws=True, t=True))
    v2 = OpenMaya.MVector(cmds.xform(mid, q=True, ws=True, t=True))
    v3 = OpenMaya.MVector(cmds.xform(end, q=True, ws=True, t=True))

    e1 = (v3 - v1).normal()
    e2 = v2 - v1
    v = v1 + e1 * (e1 * e2)
    pos = v2 + (v2 - v).normal() * offset
    cmds.xform(pole_vector, ws=True, t=list(pos)) 
開發者ID:chadmv,項目名稱:cmt,代碼行數:20,代碼來源:common.py

示例7: create_arrow

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def create_arrow(jointName):
    curve = cmds.curve(
        name="%s_ForwardDirection" % jointName,
        degree=1,
        point=[
            (-1, 0, 0),
            (-1, 2, 0),
            (-2, 2, 0),
            (0, 4, 0),
            (2, 2, 0),
            (1, 2, 0),
            (1, 0, 0),
            (-1, 0, 0),
        ],
    )
    group = cmds.group()
    cmds.xform(objectSpace=True, pivots=(0, 0, 0))
    jointScale = cmds.jointDisplayScale(query=True)
    jointRadius = cmds.getAttr("%s.radius" % jointName)
    jointScale *= jointRadius
    cmds.xform(scale=(jointScale, jointScale, jointScale))

    return group 
開發者ID:chadmv,項目名稱:cmt,代碼行數:25,代碼來源:orientjoints.py

示例8: dpInvertAttrTranformation

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def dpInvertAttrTranformation(self, nodeName, invT=True, invR=False, *args):
        """ Creates a setup to invert attribute transformations in order to avoid doubleTransformation.
        """
        axisList = ['X', 'Y', 'Z']
        if cmds.objExists(nodeName):
            nodePivot = cmds.xform(nodeName, query=True, worldSpace=True, rotatePivot=True)
            if invR:
                invRGrp = cmds.group(nodeName, name=nodeName+"_InvR_Grp")
                cmds.xform(invRGrp, worldSpace=True, rotatePivot=(nodePivot[0], nodePivot[1], nodePivot[2]), rotateOrder="zyx")
                rMD = cmds.createNode('multiplyDivide', name=nodeName+"_InvR_MD", skipSelect=True)
                cmds.setAttr(rMD+'.input2X', -1)
                cmds.setAttr(rMD+'.input2Y', -1)
                cmds.setAttr(rMD+'.input2Z', -1)
                for axis in axisList:
                    cmds.connectAttr(nodeName+'.rotate'+axis, rMD+'.input1'+axis, force=True)
                    cmds.connectAttr(rMD+'.output'+axis, invRGrp+'.rotate'+axis, force=True)
            if invT:
                invTGrp = cmds.group(nodeName, name=nodeName+"_InvT_Grp")
                cmds.xform(invTGrp, worldSpace=True, rotatePivot=(nodePivot[0], nodePivot[1], nodePivot[2]))
                tMD = cmds.createNode('multiplyDivide', name=nodeName+"_InvT_MD", skipSelect=True)
                cmds.setAttr(tMD+'.input2X', -1)
                cmds.setAttr(tMD+'.input2Y', -1)
                cmds.setAttr(tMD+'.input2Z', -1)
                for axis in axisList:
                    cmds.connectAttr(nodeName+'.translate'+axis, tMD+'.input1'+axis, force=True)
                    cmds.connectAttr(tMD+'.output'+axis, invTGrp+'.translate'+axis, force=True) 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:28,代碼來源:dpRivet.py

示例9: sqCheckCurveDirection

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def sqCheckCurveDirection(self, thisCurve, *args):
        posMinX = cmds.xform(thisCurve+".cv[0]", query=True, worldSpace=True, translation=True)[0]
        posMaxX = cmds.xform(thisCurve+".cv["+str(self.curveLenght-1)+"]", query=True, worldSpace=True, translation=True)[0]
        if posMinX > posMaxX:
            cmds.reverseCurve(thisCurve, constructionHistory=False, replaceOriginal=True) 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:7,代碼來源:sqStickyLipsSetup.py

示例10: sqGetPointLists

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def sqGetPointLists(self, *args):
        cmds.select(self.baseCurve+".cv[*]")
        pointList = cmds.ls(selection=True, flatten=True)
        
        minX = 0
        maxX = 0
        sideA = 0
        sideB = 0
        for i in range(0, len(pointList)):
            pointPosX = cmds.xform(pointList[i], query=True, worldSpace=True, translation=True)[0]
            if pointPosX < minX:
                minX = pointPosX
                sideA = i
            elif pointPosX > maxX:
                maxX = pointPosX
                sideB = i
        if sideA > sideB:
            sideC = sideA
            sideA = sideB
            sideB = sideC
        
        pointListA = pointList[sideA:(sideB+1)]
        pointListB = pointList[sideB:]
        for j in range(0, (sideA+1)):
            pointListB.append(pointList[j])
        
        return pointListA, pointListB, sideA, sideB 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:29,代碼來源:sqStickyLipsSetup.py

示例11: cvCharacter

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def cvCharacter(self, ctrlType, ctrlName, r=1, d=1, dir="+Y", rot=(0, 0, 0), *args):
        """ Create and return a curve to be used as a control.
        """
        # get radius by checking linear unit
        r = self.dpCheckLinearUnit(r)
        curve = self.cvControl(ctrlType, ctrlName, r, d, dir, rot)
        # edit a minime curve:
        cmds.addAttr(curve, longName="rigScale", attributeType='float', defaultValue=1, keyable=True)
        cmds.addAttr(curve, longName="rigScaleMultiplier", attributeType='float', defaultValue=1, keyable=False)
        
        # create Option_Ctrl Text:
        try:
            optCtrlTxt = cmds.group(name="Option_Ctrl_Txt", empty=True)
            try:
                cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Source Sans Pro", text="Option Ctrl", constructionHistory=False)[0]
            except:
                cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Arial", text="Option Ctrl", constructionHistory=False)[0]
            txtShapeList = cmds.listRelatives(cvText, allDescendents=True, type='nurbsCurve')
            if txtShapeList:
                for s, shape in enumerate(txtShapeList):
                    # store CV world position
                    curveCVList = cmds.getAttr(shape+'.cp', multiIndices=True)
                    vtxWorldPosition = []
                    for i in curveCVList :
                        cvPointPosition = cmds.xform(shape+'.cp['+str(i)+']', query=True, translation=True, worldSpace=True) 
                        vtxWorldPosition.append(cvPointPosition)
                    # parent the shapeNode :
                    cmds.parent(shape, optCtrlTxt, r=True, s=True)
                    # restore the shape world position
                    for i in curveCVList:
                        cmds.xform(shape+'.cp['+str(i)+']', a=True, worldSpace=True, t=vtxWorldPosition[i])
                    cmds.rename(shape, optCtrlTxt+"Shape"+str(s))
            cmds.delete(cvText)
            cmds.parent(optCtrlTxt, curve)
            cmds.setAttr(optCtrlTxt+".template", 1)
            cmds.setAttr(optCtrlTxt+".tx", -0.72*r)
            cmds.setAttr(optCtrlTxt+".ty", 1.1*r)
        except:
            # it will pass if we don't able to find the font to create the text
            pass
        return curve 
開發者ID:nilouco,項目名稱:dpAutoRigSystem,代碼行數:43,代碼來源:dpControls.py

示例12: reset_pivot_pos

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def reset_pivot_pos(nodes):
    if not nodes:
        nodes = cmds.ls(sl=True, tr=True, l=True)
    for s in nodes:
        cmds.xform(s+'.scalePivot', t=[0, 0, 0], os=True)
        cmds.xform(s+'.rotatePivot', t=[0, 0, 0], os=True) 
開發者ID:ShikouYamaue,項目名稱:SISideBar,代碼行數:8,代碼來源:transform.py

示例13: set_joint_orient

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def set_joint_orient(reset=True):
    from . import sisidebar_sub
    joints = cmds.ls(sl=True, type='joint')

    if len(joints) == 0:
        confirm_mes = lang.Lang(
            en='Joint is not selected\nDo you want to process all the joints in the scene? ',
            ja=u'ジョイントが選択されていません\nシーン內のすべてのジョイントを処理しますか?'
        )
        rtn = pm.cmds.confirmDialog(title='Confirm', message=confirm_mes.output(), button=['Yes', 'No'], defaultButton='Yes',
                              cancelButton='No', dismissString='No')
        if rtn != 'Yes':
            return False

        joints = cmds.ls('*', type='joint')
        if len(joints) == 0:
            pm.confirmDialog(title='Warning', message='Joint Object Nothing.', button='OK', icon='Warning')
            return False

    for j in joints:
        # マトリックス取得
        mat = cmds.xform(j, q=True, m=True)
        # 回転とジョイントの方向をいったん0に
        cmds.rotate(0, 0, 0, j, objectSpace=True)
        cmds.joint(j, e=True, orientation=[0, 0, 0])
        # マトリックス再設定、回転のみに數値が入る。
        cmds.xform(j, m=mat)

        if reset:
            # 回転取得
            rot = cmds.xform(j, q=True, ro=True)
            # 回転を0にしてジョイントの方向に同じ値を移す
            cmds.rotate(0, 0, 0, j, objectSpace=True)
            cmds.joint(j, e=True, orientation=rot)
    sisidebar_sub.get_matrix() 
開發者ID:ShikouYamaue,項目名稱:SISideBar,代碼行數:37,代碼來源:transform.py

示例14: reset_transform

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def reset_transform(mode='', c_comp=False, reset_pivot=True):
    #print 'comp mode :', c_comp
    from . import sisidebar_sub
    if cmds.selectMode(q=True, co=True):
        return
    selections = cmds.ls(sl=True, l=True)
    #子供のノード退避用ダミーペアレントを用意
    dummy = common.TemporaryReparent().main(mode='create')
    for sel in selections:
        if c_comp:
            common.TemporaryReparent().main(sel, dummyParent=dummy, mode='cut')
        if mode == 'all':
            cmds.xform(sel, t=[0, 0, 0])
            cmds.xform(sel, ro=[0, 0, 0])
            cmds.xform(sel, s=[1, 1, 1])
        if mode == 'trans':
            cmds.xform(sel, t=[0, 0, 0])
        if mode == 'rot':
            cmds.xform(sel, ro=[0, 0, 0])
        if mode == 'scale':
            cmds.xform(sel, s=[1, 1, 1])
        if mode == 'trans' or mode =='all':
            if reset_pivot:
                cmds.xform(sel+'.scalePivot', t=[0, 0, 0], os=True)
                cmds.xform(sel+'.rotatePivot', t=[0, 0, 0], os=True)
        if c_comp:
            common.TemporaryReparent().main(sel, dummyParent=dummy, mode='parent')
    common.TemporaryReparent().main(dummyParent=dummy, mode='delete')#ダミー親削除
    cmds.select(selections, r=True)
    sisidebar_sub.get_matrix()
        
#フリーズスケーリングをまとめて 
開發者ID:ShikouYamaue,項目名稱:SISideBar,代碼行數:34,代碼來源:transform.py

示例15: BT_Setup

# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import xform [as 別名]
def BT_Setup(set = None):
    
    if not set:
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    if not transforms:
        return False

    if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
        cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
    else:
        return False

    btNode = cmds.createNode("BlendTransforms")
    cmds.setAttr(set +'.Blend_Node', btNode, type = "string")

    for i in range(0, len(transforms)):
        baseMatrix = cmds.xform(transforms[i], q = True, m = True)
        baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
        baseRotOffset = [0.0, 0.0, 0.0]

        if cmds.objectType(transforms[i], isType = 'joint'):
            baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]

        btAttr = 'transforms[' +str(i) +'].baseMatrix'
        btScaleAttr = 'transforms[' +str(i) +'].baseScale'
        btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'

        BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
        BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
        BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
        BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])

    return True 
開發者ID:duncanskertchly,項目名稱:BlendTransforms,代碼行數:37,代碼來源:BlendTransforms.py


注:本文中的maya.cmds.xform方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。