コード例 #1
0
ファイル: control.py プロジェクト: GitHGuillaumeG/DEV
    def set_shape_data(self):
        """
        Sets/replaces the control nurbsCurves shapes with the instance shape data (self._shape)
        """

        # Delete current curve's shapes below node
        current_shapes = self.get_shape()
        if current_shapes:
            cmds.delete(current_shapes)

        for i, shape_name in enumerate(self._shape):
            # Create a nurbsCurve parented under node
            curve = cmds.createNode('nurbsCurve',
                                    skipSelect=True,
                                    parent=self.name,
                                    n='{0}Shape{1}'.format(self.name, i))

            # Create a temp curve with instance data
            degree = self.shape[shape_name]['degree']
            knot = self.shape[shape_name]['knot']
            periodic = self.shape[shape_name]['periodic']
            curve_points = list()
            for key in sorted(self.shape[shape_name]['point']):
                curve_points.append(self.shape[shape_name]['point'][key])

            temp_curve = cmds.curve(degree=degree,
                                    point=curve_points,
                                    knot=knot,
                                    periodic=periodic,
                                    n='temp_transform')

            # Connect temp curve local to nurbsCurve create attribute. Eval and delete temp curve
            cmds.connectAttr('{0}.local'.format(temp_curve), '{0}.create'.format(curve))
            cmds.dgeval('{0}.local'.format(curve))
            cmds.delete(temp_curve)
コード例 #2
0
def quickConnect(driverName, drivenName):
    tempNode = cmds.createNode("multMatrix")
    cmds.connectAttr(drivenName + ".worldMatrix[0]", tempNode + ".matrixIn[0]")
    cmds.connectAttr(driverName + ".worldInverseMatrix[0]",
                     tempNode + ".matrixIn[1]")
    print cmds.dgeval(tempNode + ".matrixSum")
    offsetVal = cmds.getAttr(tempNode + ".matrixSum")
    print driverName
    print drivenName
    print offsetVal
    cmds.setAttr(multMatrix + ".matrixIn[0]", offsetVal, type="matrix")
    cmds.delete(tempNode)
    multMatrix = cmds.createNode("multMatrix",
                                 name="parentConstraint_" + drivenName +
                                 "_mMatrix")
    decomposeMatrix = cmds.createNode("decomposeMatrix",
                                      name="parentConstraint_" + driverName +
                                      "_dMatrix")
    # cmds.connectAttr(driverName + ".scale", composeMatrix + ".inputScale", force = True)
    cmds.connectAttr(driverName + ".worldMatrix[0]",
                     multMatrix + ".matrixIn[1]")
    cmds.connectAttr(drivenName + ".parentInverseMatrix[0]",
                     multMatrix + ".matrixIn[2]")
    cmds.connectAttr(multMatrix + ".matrixSum",
                     decomposeMatrix + ".inputMatrix")
    cmds.connectAttr(decomposeMatrix + ".outputTranslate",
                     drivenName + ".translate",
                     force=True)
    cmds.connectAttr(decomposeMatrix + ".outputRotate",
                     drivenName + ".rotate",
                     force=True)
コード例 #3
0
def update_shape(source, target):
    """ Connect the shape output from source to the input shape on target

    :param source: maya shape node
    :type source: str

    :param target: maya shape node
    :type target: str
    """

    # clean uvs on mesh nodes
    clean_uvs_sets(target)

    # get attributes names
    attributes = get_shape_type_attributes(source)

    logger.debug("Updating shape: {} using --> {}".format(target, source))

    # updates the shape
    cmds.connectAttr("{}.{}".format(source, attributes["output"]),
                     "{}.{}".format(target, attributes["input"]),
                     force=True)

    # forces shape evaluation to achieve the update
    cmds.dgeval("{}.{}".format(target, attributes["output"]))

    # finish shape update
    cmds.disconnectAttr("{}.{}".format(source, attributes["output"]),
                        "{}.{}".format(target, attributes["input"]))
コード例 #4
0
ファイル: update.py プロジェクト: nestorcolt/flex
def update_deformed_shape(source, target):
    """ Updates the target shape with the given source shape content

    :param source: maya shape node
    :type source: str

    :param target: maya shape node
    :type target: str
    """

    deform_origin = get_shape_orig(target)

    if not deform_origin:
        return

    deform_origin = deform_origin[0]

    # updates the shape
    cmds.connectAttr("{}.outMesh".format(source),
                     "{}.inMesh".format(deform_origin),
                     force=True)

    # forces shape evaluation to achieve the update
    cmds.dgeval("{}.outMesh".format(target))

    # finish shape update
    cmds.disconnectAttr("{}.outMesh".format(source),
                        "{}.inMesh".format(deform_origin))
コード例 #5
0
ファイル: ARTools.py プロジェクト: Jap3dWorks/autoRig_Tools
    def deltaCorrective(joints, bShape):
        """
        extract and apply delto to a blendShape
        """

        mesh = pm.PyNode(bShape.getGeometry()[0])
        meshTransform = mesh.getTransform()

        for joint in joints:
            # create poseInterpolator
            poseInterpolator = pm.PyNode(
                pm.poseInterpolator(joint,
                                    name=str(joint) + '_poseInterpolator')[0])
            poseInterpolatorShape = poseInterpolator.getShape()
            print poseInterpolator

            # create basic poses
            for i, pose in enumerate(
                ['neutral', 'neutralSwing', 'neutralTwist']):
                pm.poseInterpolator(poseInterpolator, e=True, addPose=pose)
                poseInterpolatorShape.pose[i].poseType.set(i)

            for rot in ([0, 90, 0], [0, -90, 0], [0, 0, 90], [0, 0, -90]):
                baseMesh = meshTransform.duplicate(name=str(joint) +
                                                   ('_baseMesh'))[0]
                baseMesh.setParent(w=True)

                joint.setRotation(rot, 'object')
                negativeMesh = meshTransform.duplicate(name=str(joint) +
                                                       ('_negative'))[0]
                negativeMesh.setParent(w=True)
                joint.setRotation([0, 0, 0], 'object')

                deltaMush = cmds.deltaMush(str(meshTransform), si=180, ss=0.1)
                cmds.dgeval(deltaMush)
                # set poses
                joint.setRotation(rot, 'object')
                namePose = str(joint) + ('_%s_%s_%s' %
                                         (rot[0], rot[1], rot[2])).replace(
                                             '-', 'n')
                pm.poseInterpolator(poseInterpolator, e=True, addPose=namePose)

                # duplicate mesh
                positive = meshTransform.duplicate(name=namePose)[0]
                positive.setParent(w=True)

                # get delta
                deltaShape = PSDUtils.getDelta(positive.getShape(),
                                               negativeMesh.getShape(),
                                               baseMesh.getShape())

                pm.delete(baseMesh)
                cmds.delete(deltaMush)

                # create bShape
                weightIndex = bShape.numWeights()
                bShape.addTarget(mesh, weightIndex, deltaShape, 1.0)

                joint.setRotation([0, 0, 0], 'object')
コード例 #6
0
    def refreshDagNodes(self):

        for loopMotionTrail in self.nodeInfo.keys():

            motionTrailNode = self.nodeInfo[loopMotionTrail]["motionTrailNode"]
            motionTrailAttr = self.nodeInfo[loopMotionTrail]["motionTrailAttr"]

            cmds.setAttr("%s.update" % motionTrailNode, 0)
            cmds.setAttr("%s.update" % motionTrailNode, 1)
            cmds.dgeval(motionTrailAttr)
コード例 #7
0
ファイル: motionTrail.py プロジェクト: Italic-/maya-prefs
 def refreshDagNodes(self):
     
     for loopMotionTrail in self.nodeInfo.keys():                
             
         motionTrailNode    = self.nodeInfo[loopMotionTrail]["motionTrailNode"] 
         motionTrailAttr    = self.nodeInfo[loopMotionTrail]["motionTrailAttr"]  
     
         cmds.setAttr("%s.update"%motionTrailNode, 0)
         cmds.setAttr("%s.update"%motionTrailNode, 1)
         cmds.dgeval(motionTrailAttr)
コード例 #8
0
ファイル: motionTrail.py プロジェクト: Italic-/maya-prefs
 def makeDirty(self, motionTrail):
             
     if self.checkIfDeleted(motionTrail): return        
     
     motionTrailAttr    = self.nodeInfo[motionTrail]["motionTrailAttr"]   
     cmds.dgeval(motionTrailAttr)
         
     for loopFrame in self.sortedRange:  
 
         if not self.nodeInfo[motionTrail].has_key(loopFrame): self.nodeInfo[motionTrail][loopFrame] = {}
                 
         self.nodeInfo[motionTrail][loopFrame]["status"] = "dirty" 
コード例 #9
0
    def makeDirty(self, motionTrail):

        if self.checkIfDeleted(motionTrail): return

        motionTrailAttr = self.nodeInfo[motionTrail]["motionTrailAttr"]
        cmds.dgeval(motionTrailAttr)

        for loopFrame in self.sortedRange:

            if not self.nodeInfo[motionTrail].has_key(loopFrame):
                self.nodeInfo[motionTrail][loopFrame] = {}

            self.nodeInfo[motionTrail][loopFrame]["status"] = "dirty"
コード例 #10
0
    def __bindMeshes(meshShapes, rootNodes, descNodes):
        """Bound to multiple or single mesh"""
        for rootNode in rootNodes:
            for i, mesh in enumerate(meshShapes):
                fromAttr = r"%s.worldMesh" % mesh
                toAttr = r"%s.boundMesh[%d]" % (rootNode, i)
                cmds.connectAttr(fromAttr, toAttr)

        for descNode in descNodes:
            # Force grooming DG eval
            # This must be done once before Transfer Mode turned off
            descAttr = r"%s.outSplineData" % descNode
            cmds.dgeval(descAttr)
コード例 #11
0
def doit(cage_tgt=None):
    if not cage_tgt:
        cage_tgt = cmds.ls(sl=True, o=True)
    cage = cage_tgt[0]
    tgt = cage_tgt[1:]

    cmds.loadPlugin('greenCageDeformer.py', qt=True)
    deformer = cmds.deformer(tgt, type='greenCageDeformer')[0]

    freezer = cmds.createNode('transformGeometry')
    cmds.connectAttr(cage + '.o', freezer + '.ig')
    cmds.connectAttr(cage + '.wm', freezer + '.txf')
    cmds.connectAttr(freezer + '.og', deformer + '.bc')
    cmds.disconnectAttr(freezer + '.og', deformer + '.bc')
    cmds.delete(freezer)

    cmds.connectAttr(cage + '.w', deformer + '.ic')
    cmds.dgeval(cmds.listConnections(deformer + '.og', s=False, d=True, sh=True, p=True))
コード例 #12
0
    def testPreRollStartFrameFlag(self):

        MayaCmds.createNode('transform', name='node')
        MayaCmds.setAttr('node.tx', 0.0)
        MayaCmds.expression(
            string="if(time==0)\n\tnode.tx=0;\n\nif (time*24 > 6 && node.tx > 0.8)\n\tnode.tx = 10;\n\nnode.tx = node.tx + time;\n",
            name="startAtExp", ae=1, uc=all)

        self.__files.append(util.expandFileName('startAtTest.abc'))
        MayaCmds.AbcExport(j='-fr 1 10 -root node -file ' + self.__files[-1], prs=0, duf=True)

        MayaCmds.AbcImport(self.__files[-1], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        # if the evaluation doesn't start at frame 0, node.tx < 10
        MayaCmds.currentTime(10, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnless(MayaCmds.getAttr('node.translateX')-10 > 0)
コード例 #13
0
def doit(cage_tgt=None):
    if not cage_tgt:
        cage_tgt = cmds.ls(sl=True, o=True)
    cage = cage_tgt[0]
    tgt = cage_tgt[1:]

    cmds.loadPlugin('greenCageDeformer.py', qt=True)
    deformer = cmds.deformer(tgt, type='greenCageDeformer')[0]

    freezer = cmds.createNode('transformGeometry')
    cmds.connectAttr(cage + '.o', freezer + '.ig')
    cmds.connectAttr(cage + '.wm', freezer + '.txf')
    cmds.connectAttr(freezer + '.og', deformer + '.bc')
    cmds.disconnectAttr(freezer + '.og', deformer + '.bc')
    cmds.delete(freezer)

    cmds.connectAttr(cage + '.w', deformer + '.ic')
    cmds.dgeval(
        cmds.listConnections(deformer + '.og',
                             s=False,
                             d=True,
                             sh=True,
                             p=True))
コード例 #14
0
    def testSkipFrames(self):

        MayaCmds.createNode('transform', name='node')
        MayaCmds.setKeyframe('node.translateX', time=1.0, v=1.0)
        MayaCmds.setKeyframe('node.translateX', time=10.0, v=10.0)

        MayaCmds.duplicate(name='dupNode')
        MayaCmds.setAttr('dupNode.tx', 0.0)
        MayaCmds.expression(
            string=
            "if(time==11)\n\tdupNode.tx=-50;\n\ndupNode.tx = dupNode.tx + time;\n",
            name="startAtExp",
            ae=1,
            uc=all)

        self.__files.append(util.expandFileName('skipFrameTest1.abc'))
        self.__files.append(util.expandFileName('skipFrameTest2.abc'))

        MayaCmds.AbcExport(j=[
            '-fr 1 10 -root node -file ' +
            self.__files[-2], '-fr 20 25 -root dupNode -file ' +
            self.__files[-1]
        ])

        MayaCmds.AbcImport(self.__files[-2], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        # make sure all the frames needed are written out and correctly
        for val in range(1, 11):
            MayaCmds.currentTime(val, update=True)
            MayaCmds.dgeval(abcNodeName, verbose=False)
            self.failUnlessAlmostEqual(MayaCmds.getAttr('node.tx'), val, 3)

        # also make sure nothing extra gets written out
        MayaCmds.currentTime(11, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.tx'), 10.0)

        MayaCmds.AbcImport(self.__files[-1], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        # if dontSkipFrames flag is not set maya would evaluate frame 11 and
        # set dupNode.tx to a big negative number
        MayaCmds.currentTime(20, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnless(MayaCmds.getAttr('dupNode.tx') > 0)
コード例 #15
0
    def testSkipFrames(self):

        MayaCmds.createNode('transform', name='node')
        MayaCmds.setKeyframe('node.translateX', time=1.0, v=1.0)
        MayaCmds.setKeyframe('node.translateX', time=10.0, v=10.0)

        MayaCmds.duplicate(name='dupNode')
        MayaCmds.setAttr('dupNode.tx', 0.0)
        MayaCmds.expression(
            string="if(time==11)\n\tdupNode.tx=-50;\n\ndupNode.tx = dupNode.tx + time;\n",
            name="startAtExp", ae=1, uc=all)

        self.__files.append(util.expandFileName('skipFrameTest1.abc'))
        self.__files.append(util.expandFileName('skipFrameTest2.abc'))

        MayaCmds.AbcExport(j=['-fr 1 10 -root node -file ' + self.__files[-2],
            '-fr 20 25 -root dupNode -file ' + self.__files[-1]])

        MayaCmds.AbcImport(self.__files[-2], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        # make sure all the frames needed are written out and correctly
        for val in range(1, 11):
            MayaCmds.currentTime(val, update=True)
            MayaCmds.dgeval(abcNodeName, verbose=False)
            self.failUnlessAlmostEqual(MayaCmds.getAttr('node.tx'), val, 3)

        # also make sure nothing extra gets written out
        MayaCmds.currentTime(11, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.tx'), 10.0)

        MayaCmds.AbcImport(self.__files[-1], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        # if dontSkipFrames flag is not set maya would evaluate frame 11 and
        # set dupNode.tx to a big negative number
        MayaCmds.currentTime(20, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnless(MayaCmds.getAttr('dupNode.tx') > 0)
コード例 #16
0
    def testWholeFrameGeoFlag(self):

        MayaCmds.polyCube(name='node')
        MayaCmds.setKeyframe('node.translateX', time=1.0, v=1.0)
        MayaCmds.setKeyframe('node.translateX', time=2.0, v=-3.0)
        MayaCmds.setKeyframe('node.translateX', time=5.0, v=9.0)

        MayaCmds.select('node.vtx[0:8]')
        MayaCmds.setKeyframe(time=1.0)
        MayaCmds.scale(1.5, 1.5, 1.8)
        MayaCmds.setKeyframe(time=5.0)

        self.__files.append(util.expandFileName('noSampleGeoTest.abc'))
        MayaCmds.AbcExport(j='-fr 1 5 -wfg -frs 0 -frs 0.9 -root node -file ' +
                           self.__files[-1])

        MayaCmds.AbcImport(self.__files[-1], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        setTime = MayaCmds.currentTime(1, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        val_1 = MayaCmds.getAttr('node.vt[0]')[0][0]

        MayaCmds.currentTime(2.0, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        MayaCmds.getAttr('node.vt[0]')
        val_2 = MayaCmds.getAttr('node.vt[0]')[0][0]
        self.failUnlessAlmostEqual(val_2, -0.5625, 3)

        setTime = MayaCmds.currentTime(1.9, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessAlmostEqual(MayaCmds.getAttr('node.tx'), -3.086, 3)
        # the vertex will get linearly interpolated
        alpha = (setTime - 1) / (2 - 1)
        self.failUnlessAlmostEqual(
            MayaCmds.getAttr('node.vt[0]')[0][0],
            (1 - alpha) * val_1 + alpha * val_2, 3)
コード例 #17
0
    def testWholeFrameGeoFlag(self):

        MayaCmds.polyCube(name='node')
        MayaCmds.setKeyframe('node.translateX', time=1.0, v=1.0)
        MayaCmds.setKeyframe('node.translateX', time=2.0, v=-3.0)
        MayaCmds.setKeyframe('node.translateX', time=5.0, v=9.0)

        MayaCmds.select('node.vtx[0:8]')
        MayaCmds.setKeyframe(time=1.0)
        MayaCmds.scale(1.5, 1.5, 1.8)
        MayaCmds.setKeyframe(time=5.0)

        self.__files.append(util.expandFileName('noSampleGeoTest.abc'))
        MayaCmds.AbcExport(j='-fr 1 5 -wfg -frs 0 -frs 0.9 -root node -file ' + self.__files[-1])

        MayaCmds.AbcImport(self.__files[-1], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        setTime = MayaCmds.currentTime(1, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        val_1 = MayaCmds.getAttr('node.vt[0]')[0][0]

        MayaCmds.currentTime(2.0, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        MayaCmds.getAttr('node.vt[0]')
        val_2 = MayaCmds.getAttr('node.vt[0]')[0][0]
        self.failUnlessAlmostEqual(val_2, -0.5625, 3)

        setTime = MayaCmds.currentTime(1.9, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessAlmostEqual(MayaCmds.getAttr('node.tx'), -3.086, 3)
        # the vertex will get linearly interpolated
        alpha = (setTime - 1) / (2 - 1)
        self.failUnlessAlmostEqual(MayaCmds.getAttr('node.vt[0]')[0][0],
                                   (1-alpha)*val_1+alpha*val_2, 3)
コード例 #18
0
ファイル: animTransform_test.py プロジェクト: ElaraFX/alembic
    def testAnimTransformReadWrite(self):
        nodeName = MayaCmds.createNode('transform', n='test')

        # shear
        MayaCmds.setKeyframe(nodeName, value=0, attribute='shearXY', t=[1, 24])
        MayaCmds.setKeyframe(nodeName, value=0, attribute='shearYZ', t=[1, 24])
        MayaCmds.setKeyframe(nodeName, value=0, attribute='shearXZ', t=[1, 24])
        MayaCmds.setKeyframe(nodeName, value=1.5,   attribute='shearXY', t=12)
        MayaCmds.setKeyframe(nodeName, value=5,     attribute='shearYZ', t=12)
        MayaCmds.setKeyframe(nodeName, value=2.5,   attribute='shearXZ', t=12)

        # translate
        MayaCmds.setKeyframe('test', value=0, attribute='translateX',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=0, attribute='translateY',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=0, attribute='translateZ',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.5, attribute='translateX', t=12)
        MayaCmds.setKeyframe('test', value=5, attribute='translateY', t=12)
        MayaCmds.setKeyframe('test', value=2.5, attribute='translateZ', t=12)

        # rotate
        MayaCmds.setKeyframe('test', value=0, attribute='rotateX', t=[1, 24])
        MayaCmds.setKeyframe('test', value=0, attribute='rotateY', t=[1, 24])
        MayaCmds.setKeyframe('test', value=0, attribute='rotateZ', t=[1, 24])
        MayaCmds.setKeyframe('test', value=24, attribute='rotateX', t=12)
        MayaCmds.setKeyframe('test', value=53, attribute='rotateY', t=12)
        MayaCmds.setKeyframe('test', value=90, attribute='rotateZ', t=12)

        # scale
        MayaCmds.setKeyframe('test', value=1, attribute='scaleX', t=[1, 24])
        MayaCmds.setKeyframe('test', value=1, attribute='scaleY', t=[1, 24])
        MayaCmds.setKeyframe('test', value=1, attribute='scaleZ', t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.2, attribute='scaleX', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scaleY', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scaleZ', t=12)

        # rotate pivot
        MayaCmds.setKeyframe('test', value=0.5, attribute='rotatePivotX',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=-0.1, attribute='rotatePivotY',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=1, attribute='rotatePivotZ',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=0.8, attribute='rotatePivotX', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='rotatePivotY', t=12)
        MayaCmds.setKeyframe('test', value=-1, attribute='rotatePivotZ', t=12)

        # scale pivot
        MayaCmds.setKeyframe('test', value=1.2, attribute='scalePivotX',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.0, attribute='scalePivotY',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.2, attribute='scalePivotZ',
            t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.4, attribute='scalePivotX', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scalePivotY', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scalePivotZ', t=12)

        self.__files.append(util.expandFileName('testAnimTransformReadWrite.abc'))
        self.__files.append(util.expandFileName('testAnimTransformReadWrite01_14.abc'))
        self.__files.append(util.expandFileName('testAnimTransformReadWrite15_24.abc'))

        MayaCmds.AbcExport(j='-fr 1 14 -root test -file ' + self.__files[-2])
        MayaCmds.AbcExport(j='-fr 15 24 -root test -file ' + self.__files[-1])

        subprocess.call(self.__abcStitcher + self.__files[-3:])
        MayaCmds.AbcImport(self.__files[-3], mode='open')

        # frame 1
        MayaCmds.currentTime(1, update=True)

        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr('test.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr('test.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr('test.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotZ'))

        # frame 12
        MayaCmds.currentTime(12, update=True);
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.shearXY'))
        self.failUnlessEqual(5, MayaCmds.getAttr('test.shearYZ'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr('test.shearXZ'))

        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.translateX'))
        self.failUnlessEqual(5, MayaCmds.getAttr('test.translateY'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr('test.translateZ'))

        self.failUnlessAlmostEqual(24.0, MayaCmds.getAttr('test.rotateX'), 4)
        self.failUnlessAlmostEqual(53.0, MayaCmds.getAttr('test.rotateY'), 4)
        self.failUnlessAlmostEqual(90.0, MayaCmds.getAttr('test.rotateZ'), 4)

        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scaleX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scaleY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scaleZ'))

        self.failUnlessEqual(0.8, MayaCmds.getAttr('test.rotatePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.rotatePivotY'))
        self.failUnlessEqual(-1, MayaCmds.getAttr('test.rotatePivotZ'))

        self.failUnlessEqual(1.4, MayaCmds.getAttr('test.scalePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scalePivotY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scalePivotZ'))

        # frame 24
        MayaCmds.currentTime(24, update=True);
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr('test.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr('test.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr('test.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotZ'))
コード例 #19
0
    def testRangeFlag(self):

        MayaCmds.createNode('transform', name='node')
        MayaCmds.setKeyframe('node.translateX', time=1.0, v=1.0)
        MayaCmds.setKeyframe('node.translateX', time=11.0, v=11.0)

        self.__files.append(util.expandFileName('rangeTest.abc'))
        MayaCmds.AbcExport(j='-fr 1 11 -step 0.25 -root node -file ' +
                           self.__files[-1])

        MayaCmds.AbcImport(self.__files[-1], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        MayaCmds.currentTime(0, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 1)

        MayaCmds.currentTime(1, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 1)

        MayaCmds.currentTime(1.0003, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 1)

        MayaCmds.currentTime(1.333333, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessAlmostEqual(MayaCmds.getAttr('node.translateX'),
                                   1.333333333, 2)

        MayaCmds.currentTime(9.66667, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessAlmostEqual(MayaCmds.getAttr('node.translateX'),
                                   9.6666666666, 2)

        MayaCmds.currentTime(11, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 11)

        MayaCmds.currentTime(12, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 11)
コード例 #20
0
    def testRangeFlag(self):

        MayaCmds.createNode('transform', name='node')
        MayaCmds.setKeyframe('node.translateX', time=1.0, v=1.0)
        MayaCmds.setKeyframe('node.translateX', time=11.0, v=11.0)

        self.__files.append(util.expandFileName('rangeTest.abc'))
        MayaCmds.AbcExport(j='-fr 1 11 -step 0.25 -root node -file ' + self.__files[-1])

        MayaCmds.AbcImport(self.__files[-1], m='open')

        abcNodeName = MayaCmds.ls(exactType='AlembicNode')

        MayaCmds.currentTime(0, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 1)

        MayaCmds.currentTime(1, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 1)

        MayaCmds.currentTime(1.0003, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 1)

        MayaCmds.currentTime(1.333333, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessAlmostEqual(MayaCmds.getAttr('node.translateX'),
            1.333333333, 2)

        MayaCmds.currentTime(9.66667, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessAlmostEqual(MayaCmds.getAttr('node.translateX'),
            9.6666666666, 2)

        MayaCmds.currentTime(11, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 11)

        MayaCmds.currentTime(12, update=True)
        MayaCmds.dgeval(abcNodeName, verbose=False)
        self.failUnlessEqual(MayaCmds.getAttr('node.translateX'), 11)
コード例 #21
0
    def testSampledConnectionDetectionRW(self):

        # connect to plugs at parent level and see if when loaded back
        # the sampled channels are recognized correctly

        driver = MayaCmds.createNode('transform', n='driverTrans')

        # shear
        MayaCmds.setKeyframe(driver, value=0, attribute='shearXY', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='shearYZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='shearXZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.5, attribute='shearXY', t=12)
        MayaCmds.setKeyframe(driver, value=5, attribute='shearYZ', t=12)
        MayaCmds.setKeyframe(driver, value=2.5, attribute='shearXZ', t=12)

        # translate
        MayaCmds.setKeyframe(driver,
                             value=0,
                             attribute='translateX',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver,
                             value=0,
                             attribute='translateY',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver,
                             value=0,
                             attribute='translateZ',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.5, attribute='translateX', t=12)
        MayaCmds.setKeyframe(driver, value=5, attribute='translateY', t=12)
        MayaCmds.setKeyframe(driver, value=2.5, attribute='translateZ', t=12)

        # rotate
        MayaCmds.setKeyframe(driver, value=0, attribute='rotateX', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='rotateY', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='rotateZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=24, attribute='rotateX', t=12)
        MayaCmds.setKeyframe(driver, value=53, attribute='rotateY', t=12)
        MayaCmds.setKeyframe(driver, value=90, attribute='rotateZ', t=12)

        # scale
        MayaCmds.setKeyframe(driver, value=1, attribute='scaleX', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1, attribute='scaleY', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1, attribute='scaleZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.2, attribute='scaleX', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scaleY', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scaleZ', t=12)

        # rotate pivot
        MayaCmds.setKeyframe(driver,
                             value=0.5,
                             attribute='rotatePivotX',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver,
                             value=-0.1,
                             attribute='rotatePivotY',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver,
                             value=1,
                             attribute='rotatePivotZ',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0.8, attribute='rotatePivotX', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='rotatePivotY', t=12)
        MayaCmds.setKeyframe(driver, value=-1, attribute='rotatePivotZ', t=12)

        # scale pivot
        MayaCmds.setKeyframe(driver,
                             value=1.2,
                             attribute='scalePivotX',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver,
                             value=1.0,
                             attribute='scalePivotY',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver,
                             value=1.2,
                             attribute='scalePivotZ',
                             t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.4, attribute='scalePivotX', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scalePivotY', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scalePivotZ', t=12)

        # create the transform node that's been driven by the connections
        driven = MayaCmds.createNode('transform', n='drivenTrans')
        MayaCmds.connectAttr(driver + '.translate', driven + '.translate')
        MayaCmds.connectAttr(driver + '.scale', driven + '.scale')
        MayaCmds.connectAttr(driver + '.rotate', driven + '.rotate')
        MayaCmds.connectAttr(driver + '.shear', driven + '.shear')
        MayaCmds.connectAttr(driver + '.rotatePivot', driven + '.rotatePivot')
        MayaCmds.connectAttr(driver + '.scalePivot', driven + '.scalePivot')

        self.__files.append(
            util.expandFileName('testSampledTransformDetection.abc'))
        MayaCmds.AbcExport(j='-fr 1 24 -root drivenTrans -file ' +
                           self.__files[-1])

        # reading test
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # frame 1
        MayaCmds.currentTime(1, update=True)

        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr(driven + '.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr(driven + '.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven + '.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr(driven + '.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven + '.scalePivotZ'))

        # frame 12
        MayaCmds.currentTime(12, update=True)
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven + '.shearXY'))
        self.failUnlessEqual(5, MayaCmds.getAttr(driven + '.shearYZ'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr(driven + '.shearXZ'))

        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven + '.translateX'))
        self.failUnlessEqual(5, MayaCmds.getAttr(driven + '.translateY'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr(driven + '.translateZ'))

        self.failUnlessAlmostEqual(24.0, MayaCmds.getAttr(driven + '.rotateX'),
                                   4)
        self.failUnlessAlmostEqual(53.0, MayaCmds.getAttr(driven + '.rotateY'),
                                   4)
        self.failUnlessAlmostEqual(90.0, MayaCmds.getAttr(driven + '.rotateZ'),
                                   4)

        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven + '.scaleX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven + '.scaleY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven + '.scaleZ'))

        self.failUnlessEqual(0.8, MayaCmds.getAttr(driven + '.rotatePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven + '.rotatePivotY'))
        self.failUnlessEqual(-1, MayaCmds.getAttr(driven + '.rotatePivotZ'))

        self.failUnlessEqual(1.4, MayaCmds.getAttr(driven + '.scalePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven + '.scalePivotY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven + '.scalePivotZ'))

        # frame 24
        MayaCmds.currentTime(24, update=True)
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven + '.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr(driven + '.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr(driven + '.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven + '.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven + '.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr(driven + '.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven + '.scalePivotZ'))
コード例 #22
0
    def testAnimTransformReadWrite(self, wfg=False):
        nodeName = MayaCmds.createNode('transform', n='test')

        # shear
        MayaCmds.setKeyframe(nodeName, value=0, attribute='shearXY', t=[1, 24])
        MayaCmds.setKeyframe(nodeName, value=0, attribute='shearYZ', t=[1, 24])
        MayaCmds.setKeyframe(nodeName, value=0, attribute='shearXZ', t=[1, 24])
        MayaCmds.setKeyframe(nodeName, value=1.5, attribute='shearXY', t=12)
        MayaCmds.setKeyframe(nodeName, value=5, attribute='shearYZ', t=12)
        MayaCmds.setKeyframe(nodeName, value=2.5, attribute='shearXZ', t=12)

        # translate
        MayaCmds.setKeyframe('test',
                             value=0,
                             attribute='translateX',
                             t=[1, 24])
        MayaCmds.setKeyframe('test',
                             value=0,
                             attribute='translateY',
                             t=[1, 24])
        MayaCmds.setKeyframe('test',
                             value=0,
                             attribute='translateZ',
                             t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.5, attribute='translateX', t=12)
        MayaCmds.setKeyframe('test', value=5, attribute='translateY', t=12)
        MayaCmds.setKeyframe('test', value=2.5, attribute='translateZ', t=12)

        # rotate
        MayaCmds.setKeyframe('test', value=0, attribute='rotateX', t=[1, 24])
        MayaCmds.setKeyframe('test', value=0, attribute='rotateY', t=[1, 24])
        MayaCmds.setKeyframe('test', value=0, attribute='rotateZ', t=[1, 24])
        MayaCmds.setKeyframe('test', value=24, attribute='rotateX', t=12)
        MayaCmds.setKeyframe('test', value=53, attribute='rotateY', t=12)
        MayaCmds.setKeyframe('test', value=90, attribute='rotateZ', t=12)

        # scale
        MayaCmds.setKeyframe('test', value=1, attribute='scaleX', t=[1, 24])
        MayaCmds.setKeyframe('test', value=1, attribute='scaleY', t=[1, 24])
        MayaCmds.setKeyframe('test', value=1, attribute='scaleZ', t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.2, attribute='scaleX', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scaleY', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scaleZ', t=12)

        # rotate pivot
        MayaCmds.setKeyframe('test',
                             value=0.5,
                             attribute='rotatePivotX',
                             t=[1, 24])
        MayaCmds.setKeyframe('test',
                             value=-0.1,
                             attribute='rotatePivotY',
                             t=[1, 24])
        MayaCmds.setKeyframe('test',
                             value=1,
                             attribute='rotatePivotZ',
                             t=[1, 24])
        MayaCmds.setKeyframe('test', value=0.8, attribute='rotatePivotX', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='rotatePivotY', t=12)
        MayaCmds.setKeyframe('test', value=-1, attribute='rotatePivotZ', t=12)

        # scale pivot
        MayaCmds.setKeyframe('test',
                             value=1.2,
                             attribute='scalePivotX',
                             t=[1, 24])
        MayaCmds.setKeyframe('test',
                             value=1.0,
                             attribute='scalePivotY',
                             t=[1, 24])
        MayaCmds.setKeyframe('test',
                             value=1.2,
                             attribute='scalePivotZ',
                             t=[1, 24])
        MayaCmds.setKeyframe('test', value=1.4, attribute='scalePivotX', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scalePivotY', t=12)
        MayaCmds.setKeyframe('test', value=1.5, attribute='scalePivotZ', t=12)

        if wfg:
            self.__files.append(
                util.expandFileName('testAnimWFGTransformReadWrite.abc'))

            MayaCmds.AbcExport(
                j='-fr 1 24 -wfg -frs -0.25 -frs 0.0 -frs 0.25 -root test -file '
                + self.__files[-1])
            MayaCmds.AbcImport(self.__files[-1], mode='open')
        else:
            self.__files.append(
                util.expandFileName('testAnimTransformReadWrite.abc'))
            self.__files.append(
                util.expandFileName('testAnimTransformReadWrite01_14.abc'))
            self.__files.append(
                util.expandFileName('testAnimTransformReadWrite15_24.abc'))

            MayaCmds.AbcExport(j='-fr 1 14 -root test -file ' +
                               self.__files[-2])
            MayaCmds.AbcExport(j='-fr 15 24 -root test -file ' +
                               self.__files[-1])

            subprocess.call(self.__abcStitcher + self.__files[-3:])
            MayaCmds.AbcImport(self.__files[-3], mode='open')

        # frame 1
        MayaCmds.currentTime(1, update=True)

        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr('test.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr('test.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr('test.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotZ'))

        # frame 12
        MayaCmds.currentTime(12, update=True)
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.shearXY'))
        self.failUnlessEqual(5, MayaCmds.getAttr('test.shearYZ'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr('test.shearXZ'))

        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.translateX'))
        self.failUnlessEqual(5, MayaCmds.getAttr('test.translateY'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr('test.translateZ'))

        self.failUnlessAlmostEqual(24.0, MayaCmds.getAttr('test.rotateX'), 4)
        self.failUnlessAlmostEqual(53.0, MayaCmds.getAttr('test.rotateY'), 4)
        self.failUnlessAlmostEqual(90.0, MayaCmds.getAttr('test.rotateZ'), 4)

        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scaleX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scaleY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scaleZ'))

        self.failUnlessEqual(0.8, MayaCmds.getAttr('test.rotatePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.rotatePivotY'))
        self.failUnlessEqual(-1, MayaCmds.getAttr('test.rotatePivotZ'))

        self.failUnlessEqual(1.4, MayaCmds.getAttr('test.scalePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scalePivotY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr('test.scalePivotZ'))

        # frame 24
        MayaCmds.currentTime(24, update=True)
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr('test.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr('test.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr('test.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr('test.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr('test.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr('test.scalePivotZ'))
コード例 #23
0
def convertToTwistSpline(pfx, crv, numJoints=10):
	""" Convert a given NURBS or Bezier curve to a TwistSpline

	Arguments:
		pfx (str): The user name of the spline. Will be formatted into the given naming convention
		crv (str): The transform or shape of a *bezier* spline
		numJoints (int): The number of joints to create that ride this spline
	"""
	# get nurbs curve shape
	crvShape, toDelete = _bezierConvert(crv)

	# Get the curve function set
	# There's no way to get the knots through pure MEL (nodes don't count)
	# So as long as I'm doing it this way, I'll do it all like this
	objects = OpenMaya.MSelectionList()
	OpenMaya.MGlobal.getSelectionListByName(crvShape, objects)
	meshDag = OpenMaya.MDagPath()
	objects.getDagPath(0, meshDag)
	curveFn = OpenMaya.MFnNurbsCurve(meshDag)

	# Get the curve data
	knots = OpenMaya.MDoubleArray()
	curveFn.getKnots(knots)
	params = list(knots)[1::3]
	numCVs = len(params)
	curveLen = curveFn.length()

	# Maya reports the wrong form of the curve through the API
	# So I've got to do it via mel
	#curveForm = curveFn.form()
	curveForm = cmds.getAttr("{0}.form".format(crvShape))
	isClosed = curveForm > 0 # 1->closed 2->periodic
	if isClosed:
		numCVs -= 1

	# Get the point data
	# I could do it with cmds if I wanted, but I would have to un-flatten the list
	# it's annoying either way
	#allPos = cmds.xform("{0}.cv[*]".format(crvShape), q=True, worldSpace=True, translation=True)
	allPos = OpenMaya.MPointArray()
	curveFn.getCVs(allPos)
	# Just testing a micro-optimization
	# 2 steps means not creating 3 MPoints per loop
	allPos = [allPos[i] for i in range(allPos.length())]
	allPos = [(p.x, p.y, p.z) for p in allPos]

	# Build the spline
	tempRet = makeTwistSpline(pfx, numCVs, numJoints=numJoints, maxParam=curveLen / 3.0, spread=1.0, closed=isClosed)
	cvs, bfrs, oTans, iTans, jPars, joints, group, spline, master, riderCnst = tempRet

	# Set the positions
	for pos, cv in zip(allPos[::3], bfrs):
		cmds.xform(cv, ws=True, a=True, t=pos)

	# Pin all the controllers so no length preservation happens
	# That way we can get the rotations at each param
	for cv in cvs:
		cmds.setAttr("{0}.Pin".format(cv), 1)

	for pos, cv in zip(allPos[1::3], oTans):
		cmds.xform(cv, ws=True, a=True, t=pos)
		cmds.setAttr("{0}.Auto".format(cv), 0)

	for pos, cv in zip(allPos[2::3], iTans):
		cmds.xform(cv, ws=True, a=True, t=pos)
		cmds.setAttr("{0}.Auto".format(cv), 0)

	# Make sure there is a rider constraint so I can follow the twist all along the spline
	tmpCnst = cmds.createNode("riderConstraint")
	cmds.connectAttr("{}.outputSpline".format(spline), "{}.inputSplines[0].spline".format(tmpCnst))

	# Get the rotations at each CV point
	newInd = 0
	rotations = []
	cmds.setAttr("{0}.normValue".format(tmpCnst), params[-1])
	for param in params:
		cmds.setAttr("{0}.params[{1}].param".format(tmpCnst, newInd), param)
		cmds.dgeval(tmpCnst) # maybe a propagation bug somewhere in the constraint?
		rot = cmds.getAttr("{0}.outputs[{1}].rotate".format(tmpCnst, newInd))
		rotations.append(rot[0])
	cmds.delete(tmpCnst)

	# Update the rotations after I've got them all
	for rot, ctrl in zip(rotations, bfrs):
		cmds.setAttr("{0}.rotate".format(ctrl), *rot)

	# Un-pin everything but the first, so back to length preservation
	for cv in cvs[1:]:
		cmds.setAttr("{0}.Pin".format(cv), 0)

	# Re-set the tangent worldspace positions now that things have changed
	for pos, cv in zip(allPos[1::3], oTans):
		cmds.xform(cv, ws=True, a=True, t=pos)
		cmds.setAttr("{0}.Auto".format(cv), 0)

	for pos, cv in zip(allPos[2::3], iTans):
		cmds.xform(cv, ws=True, a=True, t=pos)
		cmds.setAttr("{0}.Auto".format(cv), 0)

	# Delete the extra joint group and the constraint if I had to make 'em
	if toDelete:
		cmds.delete(toDelete)

	# Lock the buffers
	for bfr in bfrs:
		for att in [x+y for x in 'trs' for y in 'xyz']:
			cmds.setAttr("{0}.{1}".format(bfr, att), lock=True)
コード例 #24
0
ファイル: animTransform_test.py プロジェクト: ElaraFX/alembic
    def testSampledConnectionDetectionRW(self):

        # connect to plugs at parent level and see if when loaded back
        # the sampled channels are recognized correctly

        driver = MayaCmds.createNode('transform', n='driverTrans')

        # shear
        MayaCmds.setKeyframe(driver, value=0, attribute='shearXY', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='shearYZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='shearXZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.5, attribute='shearXY', t=12)
        MayaCmds.setKeyframe(driver, value=5, attribute='shearYZ', t=12)
        MayaCmds.setKeyframe(driver, value=2.5, attribute='shearXZ', t=12)

        # translate
        MayaCmds.setKeyframe(driver, value=0, attribute='translateX',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='translateY',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='translateZ',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.5, attribute='translateX', t=12)
        MayaCmds.setKeyframe(driver, value=5, attribute='translateY', t=12)
        MayaCmds.setKeyframe(driver, value=2.5, attribute='translateZ', t=12)

        # rotate
        MayaCmds.setKeyframe(driver, value=0, attribute='rotateX', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='rotateY', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0, attribute='rotateZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=24, attribute='rotateX', t=12)
        MayaCmds.setKeyframe(driver, value=53, attribute='rotateY', t=12)
        MayaCmds.setKeyframe(driver, value=90, attribute='rotateZ', t=12)

        # scale
        MayaCmds.setKeyframe(driver, value=1, attribute='scaleX', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1, attribute='scaleY', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1, attribute='scaleZ', t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.2, attribute='scaleX', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scaleY', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scaleZ', t=12)

        # rotate pivot
        MayaCmds.setKeyframe(driver, value=0.5, attribute='rotatePivotX',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=-0.1, attribute='rotatePivotY',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1, attribute='rotatePivotZ',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=0.8, attribute='rotatePivotX', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='rotatePivotY', t=12)
        MayaCmds.setKeyframe(driver, value=-1, attribute='rotatePivotZ', t=12)

        # scale pivot
        MayaCmds.setKeyframe(driver, value=1.2, attribute='scalePivotX',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.0, attribute='scalePivotY',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.2, attribute='scalePivotZ',
            t=[1, 24])
        MayaCmds.setKeyframe(driver, value=1.4, attribute='scalePivotX', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scalePivotY', t=12)
        MayaCmds.setKeyframe(driver, value=1.5, attribute='scalePivotZ', t=12)

        # create the transform node that's been driven by the connections
        driven = MayaCmds.createNode('transform', n = 'drivenTrans')
        MayaCmds.connectAttr(driver+'.translate', driven+'.translate')
        MayaCmds.connectAttr(driver+'.scale', driven+'.scale')
        MayaCmds.connectAttr(driver+'.rotate', driven+'.rotate')
        MayaCmds.connectAttr(driver+'.shear', driven+'.shear')
        MayaCmds.connectAttr(driver+'.rotatePivot', driven+'.rotatePivot')
        MayaCmds.connectAttr(driver+'.scalePivot', driven+'.scalePivot')

        self.__files.append(util.expandFileName('testSampledTransformDetection.abc'))
        MayaCmds.AbcExport(j='-fr 1 24 -root drivenTrans -file ' + self.__files[-1])

        # reading test
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # frame 1
        MayaCmds.currentTime(1, update=True)

        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr(driven+'.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr(driven+'.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr(driven+'.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scalePivotZ'))

        # frame 12
        MayaCmds.currentTime(12, update=True);
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.shearXY'))
        self.failUnlessEqual(5, MayaCmds.getAttr(driven+'.shearYZ'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr(driven+'.shearXZ'))

        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.translateX'))
        self.failUnlessEqual(5, MayaCmds.getAttr(driven+'.translateY'))
        self.failUnlessEqual(2.5, MayaCmds.getAttr(driven+'.translateZ'))

        self.failUnlessAlmostEqual(24.0, MayaCmds.getAttr(driven+'.rotateX'),
            4)
        self.failUnlessAlmostEqual(53.0, MayaCmds.getAttr(driven+'.rotateY'),
            4)
        self.failUnlessAlmostEqual(90.0, MayaCmds.getAttr(driven+'.rotateZ'), 4)

        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scaleX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scaleY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scaleZ'))

        self.failUnlessEqual(0.8, MayaCmds.getAttr(driven+'.rotatePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.rotatePivotY'))
        self.failUnlessEqual(-1, MayaCmds.getAttr(driven+'.rotatePivotZ'))

        self.failUnlessEqual(1.4, MayaCmds.getAttr(driven+'.scalePivotX'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scalePivotY'))
        self.failUnlessEqual(1.5, MayaCmds.getAttr(driven+'.scalePivotZ'))

        # frame 24
        MayaCmds.currentTime(24, update=True);
        abcNodeName = MayaCmds.ls(exactType='AlembicNode')
        MayaCmds.dgeval(abcNodeName, verbose=True)

        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearYZ'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.shearXZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.translateZ'))

        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateX'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateY'))
        self.failUnlessEqual(0, MayaCmds.getAttr(driven+'.rotateZ'))

        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleX'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.scaleZ'))

        self.failUnlessEqual(0.5, MayaCmds.getAttr(driven+'.rotatePivotX'))
        self.failUnlessEqual(-0.1, MayaCmds.getAttr(driven+'.rotatePivotY'))
        self.failUnlessEqual(1, MayaCmds.getAttr(driven+'.rotatePivotZ'))

        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scalePivotX'))
        self.failUnlessEqual(1.0, MayaCmds.getAttr(driven+'.scalePivotY'))
        self.failUnlessEqual(1.2, MayaCmds.getAttr(driven+'.scalePivotZ'))