当前位置: 首页>>代码示例>>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;未经允许,请勿转载。