def testNamespaceChild(self): self.buildScene() self.__files.append(util.expandFileName('testNamespace_foo_b.abc')) self.__files.append(util.expandFileName('testNamespace_bar_b.abc')) self.__files.append(util.expandFileName('testNamespace_b.abc')) MayaCmds.AbcExport(j='-root foo:b -fr 1 4 -file ' + self.__files[-3]) MayaCmds.AbcExport(j='-root bar:b -fr 1 4 -file ' + self.__files[-2]) MayaCmds.AbcExport(j='-root b -fr 1 4 -file ' + self.__files[-1]) self.buildStatic() MayaCmds.AbcImport(self.__files[-3], connect='foo:a') self.failUnless('testNamespace_foo_b_AlembicNode.outPolyMesh[0]' == MayaCmds.connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-3], connect='bar:a') self.failUnless('testNamespace_foo_b_AlembicNode1.outPolyMesh[0]' == MayaCmds.connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-3], connect='a') self.failUnless('testNamespace_foo_b_AlembicNode2.outPolyMesh[0]' == MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True)) self.buildStatic() MayaCmds.AbcImport(self.__files[-2], connect='foo:a') self.failUnless('testNamespace_bar_b_AlembicNode.outPolyMesh[0]' == MayaCmds.connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-2], connect='bar:a') self.failUnless('testNamespace_bar_b_AlembicNode1.outPolyMesh[0]' == MayaCmds.connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-2], connect='a') self.failUnless('testNamespace_bar_b_AlembicNode2.outPolyMesh[0]' == MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True))
def testAnimMeshReload(self): MayaCmds.polyCube( name = 'mesh') MayaCmds.setKeyframe('meshShape.vtx[0:7]', time=[1, 24]) MayaCmds.setKeyframe('meshShape.vtx[0:7]') MayaCmds.currentTime(12, update=True) MayaCmds.select('meshShape.vtx[0:7]') MayaCmds.scale(5, 5, 5, r=True) MayaCmds.setKeyframe('meshShape.vtx[0:7]', time=[12]) self.__files.append(util.expandFileName('testAnimMeshReadWrite.abc')) MayaCmds.AbcExport(j='-fr 1 24 -root mesh -f ' + self.__files[-1]) # reading test MayaCmds.AbcImport(self.__files[-1], mode='open') # save as a maya file self.__files.append(util.expandFileName('test.mb')) MayaCmds.file(rename=self.__files[-1]) MayaCmds.file(save=True) # reload as a maya file MayaCmds.file(self.__files[-1], open=True) MayaCmds.AbcImport(self.__files[-2], mode='import') retVal = True mesh1 = '|mesh|meshShape' mesh2 = '|mesh1|meshShape' for t in range(1, 25): MayaCmds.currentTime(t, update=True) if not util.compareMesh( mesh1, mesh2 ): self.fail('%s and %s were not equal at frame %d' % (mesh1, mesh2, t))
def testAnimCameraReadWrite(self): name = createCamera() MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture') MayaCmds.setKeyframe(name[1], attribute='focalLength') MayaCmds.setKeyframe(name[1], attribute='focusDistance') MayaCmds.setKeyframe(name[1], attribute='shutterAngle') MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture', value=0.95) MayaCmds.setKeyframe(name[1], attribute='focalLength', value=40) MayaCmds.setKeyframe(name[1], attribute='focusDistance', value=5.4) MayaCmds.setKeyframe(name[1], attribute='shutterAngle', value=174.94) self.__files.append(util.expandFileName('testAnimCameraReadWrite.abc')) self.__files.append(util.expandFileName('testAnimCameraReadWrite01_14.abc')) self.__files.append(util.expandFileName('testAnimCameraReadWrite15-24.abc')) # write to files MayaCmds.AbcExport(j='-fr 1 14 -root %s -file %s' % (name[0], self.__files[-2])) MayaCmds.AbcExport(j='-fr 15 24 -root %s -file %s' % (name[0], self.__files[-1])) subprocess.call(self.__abcStitcher + self.__files[-3:]) # read from file MayaCmds.AbcImport(self.__files[-3], mode='import') camList = MayaCmds.ls(type='camera') for t in range(1, 25): MayaCmds.currentTime(t, update=True) if not util.compareCamera(camList[0], camList[1]): self.fail('%s and %s are not the same at frame %d' % (camList[0], camList[1], t))
def testSelectionFlag(self): makeRobot() MayaCmds.select('bottom', 'leftArm', 'head') self.__files.append(util.expandFileName('selectionTest_partial.abc')) MayaCmds.AbcExport(j='-sl -root head -root body -root lower -file ' + self.__files[-1]) self.__files.append(util.expandFileName('selectionTest.abc')) MayaCmds.AbcExport(j='-sl -file ' + self.__files[-1]) MayaCmds.AbcImport(self.__files[-1], m='open') self.failUnless(MayaCmds.objExists("robot|head")) self.failUnless(MayaCmds.objExists("robot|body|leftArm")) self.failUnless(MayaCmds.objExists("robot|lower|bottom")) self.failIf(MayaCmds.objExists("robot|body|rightArm")) self.failIf(MayaCmds.objExists("robot|body|chest")) self.failIf(MayaCmds.objExists("robot|lower|rightLeg")) self.failIf(MayaCmds.objExists("robot|lower|leftLeg")) MayaCmds.AbcImport(self.__files[-2], m='open') self.failUnless(MayaCmds.objExists("head")) self.failUnless(MayaCmds.objExists("body|leftArm")) self.failUnless(MayaCmds.objExists("lower|bottom")) # we didnt actually select any meshes so there shouldnt # be any in the scene self.failIf(MayaCmds.ls(type='mesh'))
def test_agst(self): # animated geometry, static transform node nodename = 'agst_node' MayaCmds.polyCube(name=nodename) MayaCmds.select(nodename+'.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('agst_motionblur_noSampleGeo_Test.abc')) MayaCmds.AbcExport(j='-fr 1 5 -step 0.5 -wfg -root %s -file %s' % ( nodename, self.__files[-1])) # frameRange: 1, 2, 3, 4, 5, 6 self.isFrameRangeTransAndFrameRangeShapeExists(self.__files[-1]) self.__files.append(util.expandFileName('agst_motionblur_Test.abc')) MayaCmds.AbcExport(j='-fr 1 5 -step 0.5 -root %s -f %s' % ( nodename, self.__files[-1])) # frameRange: 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6 self.isFrameRangeExists(self.__files[-1]) self.__files.append(util.expandFileName('agst_noSampleGeo_Test.abc')) MayaCmds.AbcExport(j='-fr 1 5 -wfg -root %s -f %s' % (nodename, self.__files[-1])) # frameRange: 1, 2, 3, 4, 5 self.isFrameRangeExists(self.__files[-1])
def testAnimIKRW(self): name = createJoints() handleName = MayaCmds.ikHandle(sj=name, ee='joint4')[0] MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(handleName, breakdown=0, hierarchy='none', controlPoints=False, shape=False) MayaCmds.currentTime(16, update=True) MayaCmds.move(-1.040057, -7.278225, 6.498725, r=True) MayaCmds.setKeyframe(handleName, breakdown=0, hierarchy='none', controlPoints=False, shape=False) self.__files.append(util.expandFileName('testAnimIKRW.abc')) self.__files.append(util.expandFileName('testAnimIKRW01_08.abc')) self.__files.append(util.expandFileName('testAnimIKRW09-16.abc')) # write to files MayaCmds.AbcExport(j='-fr 1 8 -root %s -f %s' % (name, self.__files[-2])) MayaCmds.AbcExport(j='-fr 9 16 -root %s -f %s' % (name, self.__files[-1])) MayaCmds.select(name) MayaCmds.group(name='original') subprocess.call(self.__abcStitcher + self.__files[-3:]) # read from file MayaCmds.AbcImport(self.__files[-3], mode='import') # make sure the translate and rotation are the same nodes1 = ["|original|joint1", "|original|joint1|joint2", "|original|joint1|joint2|joint3", "|original|joint1|joint2|joint3|joint4"] nodes2 = ["|joint1", "|joint1|joint2", "|joint1|joint2|joint3", "|joint1|joint2|joint3|joint4"] for t in range(1, 25): MayaCmds.currentTime(t, update=True) for i in range(0, 4): self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i]+'.tx'), MayaCmds.getAttr(nodes2[i]+'.tx'), 4) self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i]+'.ty'), MayaCmds.getAttr(nodes2[i]+'.ty'), 4) self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i]+'.tz'), MayaCmds.getAttr(nodes2[i]+'.tz'), 4)
def setUp(self): MayaCmds.file(new=True, force=True) self.__files = [] # write out an animated Alembic file createAnimatedSolarSystem() self.__files.append(util.expandFileName("testAnimatedSolarSystem.abc")) MayaCmds.AbcExport(j="-fr 1 24 -root group1 -root group2 -file " + self.__files[-1]) # write out a static Alembic file that's different than the static scene # created by createStaticSolarSystem() MayaCmds.currentTime(12, update=True) self.__files.append(util.expandFileName("testStaticSolarSystem.abc")) MayaCmds.AbcExport(j="-fr 12 12 -root group1 -root group2 -file " + self.__files[-1]) # write out an animated mesh with animated parent transform node MayaCmds.polyPlane(sx=2, sy=2, w=1, h=1, ch=0, n="polyMesh") MayaCmds.createNode("transform", n="group") MayaCmds.parent("polyMesh", "group") # key the transform node MayaCmds.setKeyframe("group", attribute="translate", t=[1, 4]) MayaCmds.move(0.36, 0.72, 0.36) MayaCmds.setKeyframe("group", attribute="translate", t=2) # key the mesh node MayaCmds.select("polyMesh.vtx[0:8]") MayaCmds.setKeyframe(t=[1, 4]) MayaCmds.scale(0.1, 0.1, 0.1, r=True) MayaCmds.setKeyframe(t=2) self.__files.append(util.expandFileName("testAnimatedMesh.abc")) MayaCmds.AbcExport(j="-fr 1 4 -root group -file " + self.__files[-1]) MayaCmds.file(new=True, force=True)
def testAnimNurbsCurveGrpRW(self): # create Nurbs Curve group knotVec = [0,0,0,1,2,2,2] curve1CV = [(0, 0, 0), (3, 5, 0), (5, 6, 0), (9, 9, 0), (12, 10, 0)] curve2CV = [(0, 0, 3), (3, 5, 3), (5, 6, 3), (9, 9, 3), (12, 10, 3)] curve3CV = [(0, 0, 6), (3, 5, 6), (5, 6, 6), (9, 9, 6), (12, 10, 6)] MayaCmds.curve(d=3, p=curve1CV, k=knotVec, name='curve1') MayaCmds.curve(d=3, p=curve2CV, k=knotVec, name='curve2') MayaCmds.curve(d=3, p=curve3CV, k=knotVec, name='curve3') MayaCmds.group('curve1', 'curve2', 'curve3', name='group') MayaCmds.addAttr('group', longName='riCurves', at='bool', dv=True) # frame 1 MayaCmds.currentTime(1, update=True) MayaCmds.select('curve1.cv[0:4]', 'curve2.cv[0:4]', 'curve3.cv[0:4]', replace=True) MayaCmds.setKeyframe() # frame 24 MayaCmds.currentTime(24, update=True) MayaCmds.select('curve1.cv[0:4]') MayaCmds.rotate(0.0, '90deg', 0.0, relative=True ) MayaCmds.select('curve2.cv[0:4]') MayaCmds.move(0.0, 0.5, 0.0, relative=True ) MayaCmds.select('curve3.cv[0:4]') MayaCmds.scale(1.0, 0.5, 1.0, relative=True ) MayaCmds.select('curve1.cv[0:4]', 'curve2.cv[0:4]', 'curve3.cv[0:4]', replace=True) MayaCmds.setKeyframe() self.__files.append(util.expandFileName('testAnimNCGrp.abc')) self.__files.append(util.expandFileName('testAnimNCGrp01_14.abc')) self.__files.append(util.expandFileName('testAnimNCGrp15_24.abc')) MayaCmds.AbcExport(j='-fr 1 14 -root %s -file %s' % ('group', self.__files[-2])) MayaCmds.AbcExport(j='-fr 15 24 -root %s -file %s' % ('group', self.__files[-1])) # use AbcStitcher to combine two files into one subprocess.call(self.__abcStitcher + self.__files[-3:]) # reading test MayaCmds.AbcImport(self.__files[-3], mode='import') shapeNames = MayaCmds.ls(exactType='nurbsCurve') MayaCmds.currentTime(1, update=True) for i in range(0, 3): self.failUnless( util.compareNurbsCurve(shapeNames[i], shapeNames[i+3])) MayaCmds.currentTime(12, update=True) for i in range(0, 3): self.failUnless( util.compareNurbsCurve(shapeNames[i], shapeNames[i+3])) MayaCmds.currentTime(24, update=True) for i in range(0, 3): self.failUnless( util.compareNurbsCurve(shapeNames[i], shapeNames[i+3]))
def testAnimNurbsCurveGrpRW(self): # create Nurbs Curve group knotVec = [0, 0, 0, 1, 2, 2, 2] curve1CV = [(0, 0, 0), (3, 5, 0), (5, 6, 0), (9, 9, 0), (12, 10, 0)] curve2CV = [(0, 0, 3), (3, 5, 3), (5, 6, 3), (9, 9, 3), (12, 10, 3)] curve3CV = [(0, 0, 6), (3, 5, 6), (5, 6, 6), (9, 9, 6), (12, 10, 6)] MayaCmds.curve(d=3, p=curve1CV, k=knotVec, name="curve1") MayaCmds.curve(d=3, p=curve2CV, k=knotVec, name="curve2") MayaCmds.curve(d=3, p=curve3CV, k=knotVec, name="curve3") MayaCmds.group("curve1", "curve2", "curve3", name="group") MayaCmds.addAttr("group", longName="riCurves", at="bool", dv=True) # frame 1 MayaCmds.currentTime(1, update=True) MayaCmds.select("curve1.cv[0:4]", "curve2.cv[0:4]", "curve3.cv[0:4]", replace=True) MayaCmds.setKeyframe() # frame 24 MayaCmds.currentTime(24, update=True) MayaCmds.select("curve1.cv[0:4]") MayaCmds.rotate(0.0, "90deg", 0.0, relative=True) MayaCmds.select("curve2.cv[0:4]") MayaCmds.move(0.0, 0.5, 0.0, relative=True) MayaCmds.select("curve3.cv[0:4]") MayaCmds.scale(1.0, 0.5, 1.0, relative=True) MayaCmds.select("curve1.cv[0:4]", "curve2.cv[0:4]", "curve3.cv[0:4]", replace=True) MayaCmds.setKeyframe() self.__files.append(util.expandFileName("testAnimNCGrp.abc")) self.__files.append(util.expandFileName("testAnimNCGrp01_14.abc")) self.__files.append(util.expandFileName("testAnimNCGrp15_24.abc")) MayaCmds.AbcExport(j="-fr 1 14 -root %s -file %s" % ("group", self.__files[-2])) MayaCmds.AbcExport(j="-fr 15 24 -root %s -file %s" % ("group", self.__files[-1])) # use AbcStitcher to combine two files into one subprocess.call(self.__abcStitcher + self.__files[-3:]) # reading test MayaCmds.AbcImport(self.__files[-3], mode="import") shapeNames = MayaCmds.ls(exactType="nurbsCurve") MayaCmds.currentTime(1, update=True) for i in range(0, 3): self.failUnless(util.compareNurbsCurve(shapeNames[i], shapeNames[i + 3])) MayaCmds.currentTime(12, update=True) for i in range(0, 3): self.failUnless(util.compareNurbsCurve(shapeNames[i], shapeNames[i + 3])) MayaCmds.currentTime(24, update=True) for i in range(0, 3): self.failUnless(util.compareNurbsCurve(shapeNames[i], shapeNames[i + 3]))
def testAnimNSurfaceAndPolyDeleteReload(self): # create a poly cube and animate shapeName = 'pCube' MayaCmds.polyCube(name=shapeName) MayaCmds.move(5, 0, 0, r=True) MayaCmds.setKeyframe(shapeName+'.vtx[2:5]', time=[1, 24]) MayaCmds.currentTime(12) MayaCmds.select(shapeName+'.vtx[2:5]',replace=True) MayaCmds.move(0, 4, 0, r=True) MayaCmds.setKeyframe(shapeName+'.vtx[2:5]', time=[12]) # create an animated Nurbs plane MayaCmds.nurbsPlane(ch=False, name='nPlane') MayaCmds.move(-5, 5, 0, relative=True) MayaCmds.select('nPlane.cv[0:3][0:3]', replace=True) MayaCmds.setKeyframe(time=1) MayaCmds.currentTime(12, update=True) MayaCmds.rotate(0, 0, 90, relative=True) MayaCmds.setKeyframe(time=12) MayaCmds.currentTime(24, update=True) MayaCmds.rotate(0, 0, 90, relative=True) MayaCmds.setKeyframe(time=24) # write it out to Abc file and load back in self.__files.append(util.expandFileName('testNSurfaceAndPolyReload.abc')) MayaCmds.AbcExport(j='-fr 1 24 -root pCube -root nPlane -file ' + self.__files[-1]) # load back the Abc file, delete the cube and save to a maya file MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.delete('pCube') self.__files.append(util.expandFileName('test.mb')) MayaCmds.file(rename=self.__files[-1]) MayaCmds.file(save=True) # import the saved maya file to compare with the original scene MayaCmds.file(self.__files[-1], open=True) MayaCmds.select('nPlane', replace=True) MayaCmds.group(name='ReloadGrp') MayaCmds.AbcImport(self.__files[-2], mode='import') shapeList = MayaCmds.ls(type='mesh') self.failUnlessEqual(len(shapeList), 1) surfaceList = MayaCmds.ls(type='nurbsSurface') self.failUnlessEqual(len(surfaceList), 2) # test the equality of plane surface1 = '|nPlane|nPlaneShape' surface2 = '|ReloadGrp|nPlane|nPlaneShape' for t in range(1, 25): MayaCmds.currentTime(t, update=True) if not util.compareNurbsSurface( surface1, surface2 ): self.fail('%s and %s are not the same at frame %d' % (surface1, surface2, t))
def testStaticNurbsSurfaceWithoutTrimReadWrite(self): # open - open surface self.__files.append(util.expandFileName('testStaticNurbsPlaneWithoutTrim.abc')) testStaticNurbsWithoutTrim(self, 0, self.__files[-1]) # open - periodic surface self.__files.append(util.expandFileName('testStaticNurbsSphereWithoutTrim.abc')) testStaticNurbsWithoutTrim(self, 1, self.__files[-1]) # periodic - periodic surface self.__files.append(util.expandFileName('testStaticNurbsTorusWithoutTrim.abc')) testStaticNurbsWithoutTrim(self, 2 , self.__files[-1])
def testStaticNurbsSurfaceWithOneCloseCurveTrimOutsideReadWrite(self): # open - open surface self.__files.append(util.expandFileName('testStaticNurbsPlaneWithOneCloseCurveTrimOutside.abc')) testStaticNurbsWithOneCloseCurveTrim(self, 0, self.__files[-1], 1) # open - periodic surface self.__files.append(util.expandFileName('testStaticNurbsSphereWithOneCloseCurveTrimOutside.abc')) testStaticNurbsWithOneCloseCurveTrim(self, 1, self.__files[-1], 1) # periodic - periodic surface self.__files.append(util.expandFileName('testStaticNurbsTorusWithOneCloseCurveTrimOutside.abc')) testStaticNurbsWithOneCloseCurveTrim(self, 2, self.__files[-1], 1)
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)
def testPreRollRanges(self): self.createXformNode() # Export (1, 10), [11, 100], (101, 109), [110, 200] __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testPreRollRanges1.abc')) MayaCmds.AbcExport(j = '-fr 1 10 -pr -fr 11 100 -fr 101 109 -pr -fr 110 200 -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) referenceList = [] for i in range(11, 101): referenceList.append(i) for i in range(110, 201): referenceList.append(i) self.failUnlessEqual(framesList, referenceList) # Import MayaCmds.AbcImport(self.__files[-1], mode = 'open') # Test sampling points self.failUnlessXformValuesEqual([(11, 10), (100, 20), (110, 20), (200, 10)]) # Test not-sampled points self.failUnlessXformValuesEqual([(1, 10), (105, 20), (205, 10)]) # Another pre roll test MayaCmds.file(new = True, force = True) self.createXformNode() # Export [1, 10], (11, 99), [100, 110], (111, 200) __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testPreRollRanges2.abc')) MayaCmds.AbcExport(j = '-fr 1 10 -fr 11 99 -pr -fr 100 110 -fr 111 200 -pr -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) referenceList = [] for i in range(1, 11): referenceList.append(i) for i in range(100, 111): referenceList.append(i) self.failUnlessEqual(framesList, referenceList) # Import MayaCmds.AbcImport(self.__files[-1], mode = 'open') # Test sampling points self.failUnlessXformValuesEqual([(1, 10), (3, 20), (10, 20), (100, 20), (110, 20)]) # Test not-sampled points self.failUnlessXformValuesEqual([(11, 20), (50, 20), (200, 20)])
def testPreRollRanges(self): self.createXformNode() # Export (1, 10), [11, 100], (101, 109), [110, 200] __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testPreRollRanges1.abc')) MayaCmds.AbcExport(j='-fr 1 10 -pr -fr 11 100 -fr 101 109 -pr -fr 110 200 -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) referenceList = [] for i in range(11, 101): referenceList.append(i) for i in range(110, 201): referenceList.append(i) self.failUnlessEqual(framesList, referenceList) # Import MayaCmds.AbcImport(self.__files[-1], mode='open') # Test sampling points self.failUnlessXformValuesEqual([(11, 10), (100, 20), (110, 20), (200, 10)]) # Test not-sampled points self.failUnlessXformValuesEqual([(1, 10), (105, 20), (205, 10)]) # Another pre roll test MayaCmds.file(new=True, force=True) self.createXformNode() # Export [1, 10], (11, 99), [100, 110], (111, 200) __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testPreRollRanges2.abc')) MayaCmds.AbcExport(j='-fr 1 10 -fr 11 99 -pr -fr 100 110 -fr 111 200 -pr -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) referenceList = [] for i in range(1, 11): referenceList.append(i) for i in range(100, 111): referenceList.append(i) self.failUnlessEqual(framesList, referenceList) # Import MayaCmds.AbcImport(self.__files[-1], mode='open') # Test sampling points self.failUnlessXformValuesEqual([(1, 10), (3, 20), (10, 20), (100, 20), (110, 20)]) # Test not-sampled points self.failUnlessXformValuesEqual([(11, 20), (50, 20), (200, 20)])
def testAnimWholeFrameGeoCameraReadWrite(self): name = createCamera() MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture') MayaCmds.setKeyframe(name[1], attribute='focalLength') MayaCmds.setKeyframe(name[1], attribute='focusDistance') MayaCmds.setKeyframe(name[1], attribute='shutterAngle') MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture', value=0.95) MayaCmds.setKeyframe(name[1], attribute='focalLength', value=40) MayaCmds.setKeyframe(name[1], attribute='focusDistance', value=5.4) MayaCmds.setKeyframe(name[1], attribute='shutterAngle', value=174.94) self.__files.append( util.expandFileName('testAnimWFGCameraReadWrite.abc')) # write to files MayaCmds.AbcExport( j='-fr 1 24 -frs -0.25 -frs 0.0 -frs 0.25 -wfg -root %s -file %s' % (name[0], self.__files[-1])) # read from file MayaCmds.AbcImport(self.__files[-1], mode='import') camList = MayaCmds.ls(type='camera') for t in range(1, 25): MayaCmds.currentTime(t, update=True) if not util.compareCamera(camList[0], camList[1]): self.fail('%s and %s are not the same at frame %d' % (camList[0], camList[1], t))
def testPolyUVs(self): MayaCmds.polyCube(name='cube') cubeObj = getObjFromName('cubeShape') fnMesh = OpenMaya.MFnMesh(cubeObj) # get the name of the current UV set uvSetName = fnMesh.currentUVSetName() uArray = OpenMaya.MFloatArray() vArray = OpenMaya.MFloatArray() fnMesh.getUVs(uArray, vArray, uvSetName) newUArray = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2, -1, -1] newVArray = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 1, 0, 1] for i in range(0, 14): uArray[i] = newUArray[i] vArray[i] = newVArray[i] fnMesh.setUVs(uArray, vArray, uvSetName) self.__files.append(util.expandFileName('polyUvsTest.abc')) MayaCmds.AbcExport(j='-uv -root cube -file ' + self.__files[-1]) # reading test MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.select('cube.map[0:13]', replace=True) uvs = MayaCmds.polyEditUV(query=True) for i in range(0, 14): self.failUnlessAlmostEqual(newUArray[i], uvs[2 * i], 4, 'map[%d].u is not the same' % i) self.failUnlessAlmostEqual(newVArray[i], uvs[2 * i + 1], 4, 'map[%d].v is not the same' % i)
def testSubD(self): trans = MayaCmds.polyPlane(n='plane', sx=1, sy=1, ch=False)[0] shape = MayaCmds.pickWalk(d='down')[0] MayaCmds.addAttr(attributeType='bool', defaultValue=1, keyable=True, longName='SubDivisionMesh') MayaCmds.select(trans + '.vtx[0:3]', r=True) MayaCmds.move(0, 1, 0, r=True) MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe() MayaCmds.currentTime(2, update=True) MayaCmds.move(0, 5, 0, r=True) MayaCmds.setKeyframe() self.__files.append(util.expandFileName('testSubDInterpolation.abc')) MayaCmds.AbcExport(j='-fr 1 2 -root %s -file %s' % (trans, self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.currentTime(1.004, update=True) ty = MayaCmds.getAttr(shape + '.vt[0]')[0][1] self.failUnlessAlmostEqual(1.02, ty) setTime = MayaCmds.currentTime(1.422, update=True) alpha = (setTime - 1) / (2 - 1) ty = MayaCmds.getAttr(shape + '.vt[0]')[0][1] self.failUnlessAlmostEqual(ty, (1 - alpha) * 1.0 + alpha * 6.0, 3)
def testWholeFrameGeo(self): self.createXformNode() self.createCubeNode() # Export [2, 4]{-0.2, 0, 0.2}:2 [10, 10]{-0.5, 0, 0.5} -wfg # i.e. xform: 1.8, 2, 2.2, 3.8, 4, 4.2, 9.5, 10, 10.5 # geometry: 2, 4, 10 __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testWholeFrameGeos.abc')) MayaCmds.AbcExport(j = '-fr 2 4 -s 2 -frs -0.2 -frs 0 -frs 0.2 -fr 10 10 -frs -0.5 -frs 0 -frs 0.5 -wfg -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) self.failUnlessEqual(framesList, [1.8, 2, 2.2, 3.8, 4, 4.2, 9.5, 10, 10.5]) # Import MayaCmds.AbcImport(self.__files[-1], mode = 'open') # Test sampling xform points self.failUnlessXformValuesEqual([(1.8, 14), (2, 15), (2.2, 16), (3.8, 20), (4, 20), (4.2, 20), (9.5, 20), (10, 20), (10.5, 15)]) # Test not-sampled xform points self.failUnlessXformValuesEqual([(2.8, 17.5), (3, 18), (3.2, 18.5)]) # lerp # Test sampling mesh points self.failUnlessCubeWidthEqual([(2, 20), (4, 20), (10, 20)]) # Test not-sampled cube points # No subsample for the cube self.failUnlessCubeWidthEqual([(2.2, 20), (3.8, 20), (4.2, 20)])
def testStep(self): self.createXformNode() # Export [1, 10]:5 [100, 200]:10 __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testStepRanges.abc')) MayaCmds.AbcExport( j='-fr 0 10 -s 5 -fr 100 200 -s 10 -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) referenceList = [] for i in range(0, 11, 5): referenceList.append(i) for i in range(100, 201, 10): referenceList.append(i) self.failUnlessEqual(framesList, referenceList) # Import MayaCmds.AbcImport(self.__files[-1], mode='open') # Test sampling points self.failUnlessXformValuesEqual([(0, 10), (5, 20), (10, 20), (100, 20), (110, 20), (200, 10)]) # Test not-sampled points self.failUnlessXformValuesEqual([(2.5, 15)]) # lerp
def testStaticIKRW(self): name = createJoints() MayaCmds.ikHandle(sj=name, ee='joint4') MayaCmds.move(-1.040057, -7.278225, 6.498725, r=True) # write to file self.__files.append(util.expandFileName('testStaticIK.abc')) MayaCmds.AbcExport(j='-root %s -f %s' % (name, self.__files[-1])) MayaCmds.select(name) MayaCmds.group(name='original') # read from file MayaCmds.AbcImport(self.__files[-1], mode='import') # make sure the translate and rotation are the same nodes1 = [ "|original|joint1", "|original|joint1|joint2", "|original|joint1|joint2|joint3", "|original|joint1|joint2|joint3|joint4" ] nodes2 = [ "|joint1", "|joint1|joint2", "|joint1|joint2|joint3", "|joint1|joint2|joint3|joint4" ] for i in range(0, 4): self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i] + '.tx'), MayaCmds.getAttr(nodes2[i] + '.tx'), 4) self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i] + '.ty'), MayaCmds.getAttr(nodes2[i] + '.ty'), 4) self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i] + '.tz'), MayaCmds.getAttr(nodes2[i] + '.tz'), 4)
def testAnimWFGSimpleNurbsCurveRW(self): # create the Nurbs Curve name = MayaCmds.curve(d=3, p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9), (12, 10, 2)], k=[0, 0, 0, 1, 2, 2, 2]) MayaCmds.select(name + ".cv[0:4]") # frame 1 MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe() # frame 24 MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe() # frame 12 MayaCmds.currentTime(12, update=True) MayaCmds.move(3, 0, 0, r=True) MayaCmds.setKeyframe() self.__files.append(util.expandFileName("testAnimWFGNurbsSingleCurve.abc")) MayaCmds.AbcExport(j="-fr 1 24 -wfg -frs -0.25 -frs 0.0 -frs 0.25 -root %s -file %s" % (name, self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode="import") shapeNames = MayaCmds.ls(exactType="nurbsCurve") MayaCmds.currentTime(1, update=True) self.failUnless(util.compareNurbsCurve(shapeNames[0], shapeNames[1])) MayaCmds.currentTime(12, update=True) self.failUnless(util.compareNurbsCurve(shapeNames[0], shapeNames[1])) MayaCmds.currentTime(24, update=True) self.failUnless(util.compareNurbsCurve(shapeNames[0], shapeNames[1]))
def testThreeFrameRanges(self): self.createXformNode() # Export 3 frame ranges: [1,3], [10,11], [110, 200] __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testThreeFrameRanges.abc')) MayaCmds.AbcExport(j = '-fr 1 3 -fr 10 11 -fr 110 200 -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) referenceList = [] for i in range(1, 4): referenceList.append(i) for i in range(10, 12): referenceList.append(i) for i in range(110, 201): referenceList.append(i) self.failUnlessEqual(framesList, referenceList) # Import MayaCmds.AbcImport(self.__files[-1], mode = 'open') # Test sampling points self.failUnlessXformValuesEqual([(1, 10), (3, 20), (10, 20), (11, 10), (110, 20), (200, 10)]) # Test not-sampled points self.failUnlessXformValuesEqual([(7, 20), (60.5, 15)]) # lerp
def testPolyUVs(self): MayaCmds.polyCube(name = 'cube') cubeObj = getObjFromName('cubeShape') fnMesh = OpenMaya.MFnMesh(cubeObj) # get the name of the current UV set uvSetName = fnMesh.currentUVSetName() uArray = OpenMaya.MFloatArray() vArray = OpenMaya.MFloatArray() fnMesh.getUVs(uArray, vArray, uvSetName) newUArray = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2, -1, -1] newVArray = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 1 , 0, 1] for i in range(0, 14): uArray[i] = newUArray[i] vArray[i] = newVArray[i] fnMesh.setUVs(uArray, vArray, uvSetName) self.__files.append(util.expandFileName('polyUvsTest.abc')) MayaCmds.AbcExport(j='-uv -root cube -file ' + self.__files[-1]) # reading test MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.select('cube.map[0:13]', replace=True) uvs = MayaCmds.polyEditUV(query=True) for i in range(0, 14): self.failUnlessAlmostEqual(newUArray[i], uvs[2*i], 4, 'map[%d].u is not the same' % i) self.failUnlessAlmostEqual(newVArray[i], uvs[2*i+1], 4, 'map[%d].v is not the same' % i)
def testThreeFrameRanges(self): self.createXformNode() # Export 3 frame ranges: [1,3], [10,11], [110, 200] __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testThreeFrameRanges.abc')) MayaCmds.AbcExport(j='-fr 1 3 -fr 10 11 -fr 110 200 -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) referenceList = [] for i in range(1, 4): referenceList.append(i) for i in range(10, 12): referenceList.append(i) for i in range(110, 201): referenceList.append(i) self.failUnlessEqual(framesList, referenceList) # Import MayaCmds.AbcImport(self.__files[-1], mode='open') # Test sampling points self.failUnlessXformValuesEqual([(1, 10), (3, 20), (10, 20), (11, 10), (110, 20), (200, 10)]) # Test not-sampled points self.failUnlessXformValuesEqual([(7, 20), (60.5, 15)]) # lerp
def testCamera(self): # create an animated camera and write out name = MayaCmds.camera() MayaCmds.setAttr(name[1]+'.horizontalFilmAperture', 0.962) MayaCmds.setAttr(name[1]+'.verticalFilmAperture', 0.731) MayaCmds.setAttr(name[1]+'.focalLength', 50) MayaCmds.setAttr(name[1]+'.focusDistance', 5) MayaCmds.setAttr(name[1]+'.shutterAngle', 144) # animate the camera MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture') MayaCmds.setKeyframe(name[1], attribute='focalLength') MayaCmds.setKeyframe(name[1], attribute='focusDistance') MayaCmds.setKeyframe(name[1], attribute='shutterAngle') MayaCmds.currentTime(6, update=True) MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture', value=0.95) MayaCmds.setKeyframe(name[1], attribute='focalLength', value=40) MayaCmds.setKeyframe(name[1], attribute='focusDistance', value=5.4) MayaCmds.setKeyframe(name[1], attribute='shutterAngle', value=174.94) self.__files.append(util.expandFileName('testCameraInterpolation.abc')) MayaCmds.AbcExport(j='-fr 1 6 -root %s -f %s' % (name[0], self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode='import') camList = MayaCmds.ls(type='camera') t = 1.004 MayaCmds.currentTime(t, update=True) self.failUnlessAlmostEqual(MayaCmds.getAttr(camList[0]+'.horizontalFilmAperture'), 0.962, 3) setTime = MayaCmds.currentTime(1.422, update=True) alpha = (setTime - 1) / (2 - 1) if not util.compareCamera(camList[0], camList[1]): self.fail('%s and %s are not the same at frame %d' % (camList[0], camList[1], t))
def testStaticVisibility(self): poly1 = MayaCmds.polyPlane(sx=2, sy=2, w=1, h=1, ch=0)[0] group1 = MayaCmds.group() group2 = MayaCmds.createNode("transform") MayaCmds.select(group1, group2) group3 = MayaCmds.group() group4 = (MayaCmds.duplicate(group1, rr=1))[0] group5 = MayaCmds.group() MayaCmds.select(group3, group5) root = MayaCmds.group(name='root') MayaCmds.setAttr(group1 + '.visibility', 0) MayaCmds.setAttr(group2 + '.visibility', 0) MayaCmds.setAttr(group5 + '.visibility', 0) self.__files.append(util.expandFileName('staticVisibilityTest.abc')) MayaCmds.AbcExport(j='-wv -root %s -file %s' % (root, self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], m='open') self.failIf(MayaCmds.getAttr(group1 + '.visibility')) self.failIf(MayaCmds.getAttr(group2 + '.visibility')) self.failIf(MayaCmds.getAttr(group5 + '.visibility')) self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group3 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '.visibility')) self.failUnless(MayaCmds.getAttr(root + '.visibility'))
def testStaticVisibility(self): poly1 = MayaCmds.polyPlane(sx=2, sy=2, w=1, h=1, ch=0)[0] group1 = MayaCmds.group() group2 = MayaCmds.createNode("transform") MayaCmds.select(group1, group2) group3 = MayaCmds.group() group4 = (MayaCmds.duplicate(group1, rr=1))[0] group5 = MayaCmds.group() MayaCmds.select(group3, group5) root = MayaCmds.group(name='root') MayaCmds.setAttr(group1 + '.visibility', 0) MayaCmds.setAttr(group2 + '.visibility', 0) MayaCmds.setAttr(group5 + '.visibility', 0) self.__files.append(util.expandFileName('staticVisibilityTest.abc')) MayaCmds.AbcExport(j='-wv -root %s -file %s' % (root, self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], m='open') self.failIf(MayaCmds.getAttr(group1+'.visibility')) self.failIf(MayaCmds.getAttr(group2+'.visibility')) self.failIf(MayaCmds.getAttr(group5+'.visibility')) self.failUnless(MayaCmds.getAttr(group1+'|'+poly1+'.visibility')) self.failUnless(MayaCmds.getAttr(group4+'|'+poly1+'.visibility')) self.failUnless(MayaCmds.getAttr(group3+'.visibility')) self.failUnless(MayaCmds.getAttr(group4+'.visibility')) self.failUnless(MayaCmds.getAttr(root+'.visibility'))
def testNurbsCurveGrpWidthRW2(self): MayaCmds.curve( d=3, p=[(0, 0, 0), (3, 5, 0), (5, 6, 0), (9, 9, 0), (12, 10, 0)], k=[0, 0, 0, 1, 2, 2, 2], name="curve1" ) MayaCmds.select("curveShape1") MayaCmds.curve( d=3, p=[(0, 0, 3), (3, 5, 3), (5, 6, 3), (9, 9, 3), (12, 10, 3)], k=[0, 0, 0, 1, 2, 2, 2], name="curve2" ) MayaCmds.curve( d=3, p=[(0, 0, 6), (3, 5, 6), (5, 6, 6), (9, 9, 6), (12, 10, 6)], k=[0, 0, 0, 1, 2, 2, 2], name="curve3" ) MayaCmds.select("curveShape3") MayaCmds.group("curve1", "curve2", "curve3", name="group") MayaCmds.addAttr("group", longName="riCurves", at="bool", dv=True) MayaCmds.addAttr("group", longName="width", attributeType="double", dv=0.75) self.__files.append(util.expandFileName("testStaticNurbsCurveGrpWidthTest2.abc")) MayaCmds.AbcExport(j="-root group -file " + self.__files[-1]) MayaCmds.AbcImport(self.__files[-1], mode="open") # constant width check self.failUnless("width" in MayaCmds.listAttr("|group")) self.failUnlessAlmostEqual(MayaCmds.getAttr("|group.width"), 0.75, 4)
def testStaticTransformPropReadWrite(self): nodeName = MayaCmds.createNode('transform') self.setProps(nodeName) self.__files.append(util.expandFileName('staticPropTransform.abc')) MayaCmds.AbcExport(j='-atp SPT_ -root %s -file %s' % (nodeName, self.__files[-1])) self.verifyProps(nodeName, self.__files[-1])
def testWholeFrameGeo(self): self.createXformNode() self.createCubeNode() # Export [2, 4]{-0.2, 0, 0.2}:2 [10, 10]{-0.5, 0, 0.5} -wfg # i.e. xform: 1.8, 2, 2.2, 3.8, 4, 4.2, 9.5, 10, 10.5 # geometry: 2, 4, 10 __builtins__['framesList'] = [] self.__files.append(util.expandFileName('testWholeFrameGeos.abc')) MayaCmds.AbcExport(j='-fr 2 4 -s 2 -frs -0.2 -frs 0 -frs 0.2 -fr 10 10 -frs -0.5 -frs 0 -frs 0.5 -wfg -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1]) self.failUnlessEqual(framesList, [1.8, 2, 2.2, 3.8, 4, 4.2, 9.5, 10, 10.5]) # Import MayaCmds.AbcImport(self.__files[-1], mode='open') # Test sampling xform points self.failUnlessXformValuesEqual([(1.8, 14), (2, 15), (2.2, 16), (3.8, 20), (4, 20), (4.2, 20), (9.5, 20), (10, 20), (10.5, 15)]) # Test not-sampled xform points self.failUnlessXformValuesEqual([(2.8, 17.5), (3, 18), (3.2, 18.5)]) # lerp # Test sampling mesh points self.failUnlessCubeWidthEqual([(2, 20), (4, 20), (10, 20)]) # Test not-sampled cube points # No subsample for the cube self.failUnlessCubeWidthEqual([(2.2, 20), (3.8, 20), (4.2, 20)])
def testSubD(self): trans = MayaCmds.polyPlane(n='plane', sx=1, sy=1, ch=False)[0] shape = MayaCmds.pickWalk(d='down')[0] MayaCmds.addAttr(attributeType='bool', defaultValue=1, keyable=True, longName='SubDivisionMesh') MayaCmds.select(trans+'.vtx[0:3]', r=True) MayaCmds.move(0, 1, 0, r=True) MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe() MayaCmds.currentTime(2, update=True) MayaCmds.move(0, 5, 0, r=True) MayaCmds.setKeyframe() self.__files.append(util.expandFileName('testSubDInterpolation.abc')) MayaCmds.AbcExport(j='-fr 1 2 -root %s -file %s' % (trans, self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.currentTime(1.004, update=True) ty = MayaCmds.getAttr(shape+'.vt[0]')[0][1] self.failUnlessAlmostEqual(1.02, ty) setTime = MayaCmds.currentTime(1.422, update=True) alpha = (setTime - 1) / (2 - 1) ty = MayaCmds.getAttr(shape+'.vt[0]')[0][1] self.failUnlessAlmostEqual(ty, (1-alpha)*1.0+alpha*6.0, 3)
def testAnimVisibility(self): poly1 = MayaCmds.polyPlane( sx=2, sy=2, w=1, h=1, ch=0)[0] group1 = MayaCmds.group() group2 = MayaCmds.createNode("transform") MayaCmds.select(group1, group2) group3 = MayaCmds.group() group4 = (MayaCmds.duplicate(group1, rr=1))[0] group5 = MayaCmds.group() MayaCmds.select(group3, group5) root = MayaCmds.group(name='root') MayaCmds.setKeyframe(group1 + '.visibility', v=0, t=[1, 4]) MayaCmds.setKeyframe(group2 + '.visibility', v=0, t=[1, 4]) MayaCmds.setKeyframe(group5 + '.visibility', v=0, t=[1, 4]) MayaCmds.setKeyframe(group1 + '.visibility', v=1, t=2) MayaCmds.setKeyframe(group2 + '.visibility', v=1, t=2) MayaCmds.setKeyframe(group5 + '.visibility', v=1, t=2) self.__files.append(util.expandFileName('animVisibilityTest.abc')) MayaCmds.AbcExport(j='-wv -fr 1 4 -root %s -file %s' % (root, self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.currentTime(1, update = True) self.failIf(MayaCmds.getAttr(group1 + '.visibility')) self.failIf(MayaCmds.getAttr(group2 + '.visibility')) self.failIf(MayaCmds.getAttr(group5 + '.visibility')) self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group3 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '.visibility')) self.failUnless(MayaCmds.getAttr(root+'.visibility')) MayaCmds.currentTime(2, update = True) self.failUnless(MayaCmds.getAttr(group1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group2 + '.visibility')) self.failUnless(MayaCmds.getAttr(group5 + '.visibility')) self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group3 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '.visibility')) self.failUnless(MayaCmds.getAttr(root + '.visibility')) MayaCmds.currentTime(4, update = True ) self.failIf(MayaCmds.getAttr(group1 + '.visibility')) self.failIf(MayaCmds.getAttr(group2 + '.visibility')) self.failIf(MayaCmds.getAttr(group5 + '.visibility')) self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group3 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '.visibility')) self.failUnless(MayaCmds.getAttr(root+'.visibility'))
def testAnimVisibility(self): poly1 = MayaCmds.polyPlane(sx=2, sy=2, w=1, h=1, ch=0)[0] group1 = MayaCmds.group() group2 = MayaCmds.createNode("transform") MayaCmds.select(group1, group2) group3 = MayaCmds.group() group4 = (MayaCmds.duplicate(group1, rr=1))[0] group5 = MayaCmds.group() MayaCmds.select(group3, group5) root = MayaCmds.group(name='root') MayaCmds.setKeyframe(group1 + '.visibility', v=0, t=[1, 4]) MayaCmds.setKeyframe(group2 + '.visibility', v=0, t=[1, 4]) MayaCmds.setKeyframe(group5 + '.visibility', v=0, t=[1, 4]) MayaCmds.setKeyframe(group1 + '.visibility', v=1, t=2) MayaCmds.setKeyframe(group2 + '.visibility', v=1, t=2) MayaCmds.setKeyframe(group5 + '.visibility', v=1, t=2) self.__files.append(util.expandFileName('animVisibilityTest.abc')) MayaCmds.AbcExport(j='-wv -fr 1 4 -root %s -file %s' % (root, self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.currentTime(1, update=True) self.failIf(MayaCmds.getAttr(group1 + '.visibility')) self.failIf(MayaCmds.getAttr(group2 + '.visibility')) self.failIf(MayaCmds.getAttr(group5 + '.visibility')) self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group3 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '.visibility')) self.failUnless(MayaCmds.getAttr(root + '.visibility')) MayaCmds.currentTime(2, update=True) self.failUnless(MayaCmds.getAttr(group1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group2 + '.visibility')) self.failUnless(MayaCmds.getAttr(group5 + '.visibility')) self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group3 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '.visibility')) self.failUnless(MayaCmds.getAttr(root + '.visibility')) MayaCmds.currentTime(4, update=True) self.failIf(MayaCmds.getAttr(group1 + '.visibility')) self.failIf(MayaCmds.getAttr(group2 + '.visibility')) self.failIf(MayaCmds.getAttr(group5 + '.visibility')) self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility')) self.failUnless(MayaCmds.getAttr(group3 + '.visibility')) self.failUnless(MayaCmds.getAttr(group4 + '.visibility')) self.failUnless(MayaCmds.getAttr(root + '.visibility'))
def testStaticCameraPropReadWrite(self): root = MayaCmds.camera() nodeName = root[0] shapeName = root[1] self.setProps(shapeName) self.__files.append(util.expandFileName('staticPropCamera.abc')) MayaCmds.AbcExport(j='-atp SPT_ -root %s -f %s' % (nodeName, self.__files[-1])) self.verifyProps(shapeName, self.__files[-1])
def testStaticNurbsSurfacePropReadWrite(self): nodeName = 'nSphere' shapeName = 'nSphereShape' MayaCmds.sphere(name=nodeName) self.setProps(shapeName) self.__files.append(util.expandFileName('staticPropNurbs.abc')) MayaCmds.AbcExport(j='-atp SPT_ -root %s -file %s' % (nodeName, self.__files[-1])) self.verifyProps(shapeName, self.__files[-1])
def testStaticParticlePropReadWrite(self): root = MayaCmds.particle(p=[(0, 0, 0), (1, 1, 1)]) nodeName = root[0] shapeName = root[1] self.setProps(shapeName) self.__files.append(util.expandFileName('staticPropParticles.abc')) MayaCmds.AbcExport(j='-atp -root %s -f %s' % (nodeName, self.__files[-1])) self.verifyProps(shapeName, self.__files[-1])
def testStaticMeshPropReadWrite(self): nodeName = 'polyCube' shapeName = 'polyCubeShape' MayaCmds.polyCube(name=nodeName) self.setProps(shapeName) self.__files.append(util.expandFileName('staticPropMesh.abc')) MayaCmds.AbcExport(j='-atp SPT_ -root %s -f %s' % (nodeName, self.__files[-1])) self.verifyProps(shapeName, self.__files[-1])
def testStaticMeshPolyNormals(self): # create a polygon cube polyName = 'polyCube' polyShapeName = 'polyCubeShape' MayaCmds.polyCube(sx=1, sy=1, sz=1, name=polyName, constructionHistory=False) # add the necessary props MayaCmds.select(polyShapeName) MayaCmds.addAttr(longName='SubDivisionMesh', attributeType='bool', defaultValue=False) MayaCmds.addAttr(longName='noNormals', attributeType='bool', defaultValue=False) MayaCmds.addAttr(longName='flipNormals', attributeType='bool', defaultValue=False) # tweek some normals MayaCmds.select(polyName + '.vtxFace[2][1]', replace=True) MayaCmds.polyNormalPerVertex(xyz=(0.707107, 0.707107, 0)) MayaCmds.select(polyName + '.vtxFace[7][4]', replace=True) MayaCmds.polyNormalPerVertex(xyz=(-0.707107, 0.707107, 0)) # write to file self.__files.append(util.expandFileName('staticPolyNormalsTest.abc')) MayaCmds.AbcExport(j='-root %s -f %s' % (polyName, self.__files[-1])) # read back from file MayaCmds.AbcImport(self.__files[-1], mode='import') self.failIf( MayaCmds.listAttr('polyCube1|polyCubeShape').count('noNormals') != 0) # make sure the normals are the same shapeObj = getObjFromName('polyCube1|polyCubeShape') fnMesh = OpenMaya.MFnMesh(shapeObj) numFaces = fnMesh.numPolygons() for faceIndex in range(0, numFaces): vertexList = OpenMaya.MIntArray() fnMesh.getPolygonVertices(faceIndex, vertexList) numVertices = vertexList.length() for v in range(0, numVertices): vertexIndex = vertexList[v] normal = OpenMaya.MVector() fnMesh.getFaceVertexNormal(faceIndex, vertexIndex, normal) vtxFaceAttrName = '.vtxFace[%d][%d]' % (vertexIndex, faceIndex) MayaCmds.select(polyName + vtxFaceAttrName, replace=True) oNormal = MayaCmds.polyNormalPerVertex(query=True, xyz=True) self.failUnlessAlmostEqual(normal[0], oNormal[0], 4) self.failUnlessAlmostEqual(normal[1], oNormal[1], 4) self.failUnlessAlmostEqual(normal[2], oNormal[2], 4)
def test_sgst(self): # static geometry, static transform node nodename = 'sgst_node' MayaCmds.polyCube(name=nodename) self.__files.append(util.expandFileName('sgst_motionblur_noSampleGeo_Test.abc')) MayaCmds.AbcExport(j='-fr 1 5 -step 0.5 -wfg -root %s -file %s ' % ( nodename, self.__files[-1])) self.failIf(MayaCmds.AbcImport(self.__files[-1]) != "") self.__files.append(util.expandFileName('sgst_moblur_noSampleGeo_norange_Test.abc')) MayaCmds.AbcExport(j='-step 0.5 -wfg -root %s -file %s' % ( nodename, self.__files[-1])) # frameRange: NA self.noFrameRangeExists(self.__files[-1])
def testNurbsCurveGrpReadWrite(self): # test w/r of simple Nurbs Curve self.__files.append(util.expandFileName("testStaticNurbsCurves.abc")) testNurbsCurveRW(self, False, self.__files[-1], "haka") self.__files.append(util.expandFileName("testStaticNurbsCurveGrp.abc")) testNurbsCurveRW(self, True, self.__files[-1], "haka") # test if some curves have different degree or close states information MayaCmds.file(new=True, force=True) name = MayaCmds.textCurves(font="Courier", text="Maya") MayaCmds.addAttr(name[0], longName="riCurves", at="bool", dv=True) self.__files.append(util.expandFileName("testStaticNurbsCurveGrp2.abc")) MayaCmds.AbcExport(j="-root %s -f %s" % (name[0], self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode="open") if "riCurves" in MayaCmds.listAttr(name[0]): self.fail(name[0] + ".riCurves shouldn't exist")
def testRenderableOnly(self): MayaCmds.polyPlane(name='potato') MayaCmds.polyPlane(name='hidden') MayaCmds.setAttr("hidden.visibility", 0) self.__files.append(util.expandFileName('renderableOnlyTest.abc')) MayaCmds.AbcExport(j='-renderableOnly -file ' + self.__files[-1]) MayaCmds.AbcImport(self.__files[-1], m='open') self.failUnless(MayaCmds.objExists('potato')) self.failIf(MayaCmds.objExists('hidden'))
def testStaticNurbsCurvePropReadWrite(self): nodeName = 'nCurve' shapeName = 'curveShape1' MayaCmds.curve(p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9)], name=nodeName) self.setProps(shapeName) self.__files.append(util.expandFileName('staticPropCurve.abc')) MayaCmds.AbcExport(j='-atp SPT_ -root %s -f %s' % (nodeName, self.__files[-1])) self.verifyProps(shapeName, self.__files[-1])
def testAnimSimpleNurbsCurveRW(self): # create the Nurbs Curve name = MayaCmds.curve(d=3, p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9), (12, 10, 2)], k=[0, 0, 0, 1, 2, 2, 2]) MayaCmds.select(name + '.cv[0:4]') # frame 1 MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe() # frame 24 MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe() # frame 12 MayaCmds.currentTime(12, update=True) MayaCmds.move(3, 0, 0, r=True) MayaCmds.setKeyframe() self.__files.append( util.expandFileName('testAnimNurbsSingleCurve.abc')) self.__files.append( util.expandFileName('testAnimNurbsSingleCurve01_14.abc')) self.__files.append( util.expandFileName('testAnimNurbsSingleCurve15_24.abc')) MayaCmds.AbcExport(j='-fr 1 14 -root %s -file %s' % (name, self.__files[-2])) MayaCmds.AbcExport(j='-fr 15 24 -root %s -file %s' % (name, self.__files[-1])) # use AbcStitcher to combine two files into one subprocess.call(self.__abcStitcher + self.__files[-3:]) MayaCmds.AbcImport(self.__files[-3], mode='import') shapeNames = MayaCmds.ls(exactType='nurbsCurve') MayaCmds.currentTime(1, update=True) self.failUnless(util.compareNurbsCurve(shapeNames[0], shapeNames[1])) MayaCmds.currentTime(12, update=True) self.failUnless(util.compareNurbsCurve(shapeNames[0], shapeNames[1])) MayaCmds.currentTime(24, update=True) self.failUnless(util.compareNurbsCurve(shapeNames[0], shapeNames[1]))
def test_sgat(self): # static geometry, animated transform node nodename = 'sgat_node' MayaCmds.polyCube(name=nodename) MayaCmds.setKeyframe(nodename+'.translateX', time=1.0, v=1.0) MayaCmds.setKeyframe(nodename+'.translateX', time=5.0, v=10.0) self.__files.append(util.expandFileName('sgat_motionblur_noSampleGeo_Test.abc')) MayaCmds.AbcExport(j='-fr 1 5 -step 0.5 -wfg -root %s -f %s' % ( nodename, self.__files[-1])) # frameRange: 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6 self.isFrameRangeTransAndFrameRangeShapeExists(self.__files[-1]) self.__files.append(util.expandFileName('sgat_motionblur_Test.abc')) MayaCmds.AbcExport(j='-fr 1 5 -step 0.5 -root %s -f %s ' % ( nodename, self.__files[-1])) # frameRange: 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6 self.isFrameRangeExists(self.__files[-1])
def testNurbsCurveGrpReadWrite(self): # test w/r of simple Nurbs Curve self.__files.append(util.expandFileName('testStaticNurbsCurves.abc')) testNurbsCurveRW(self, False, self.__files[-1], 'haka') self.__files.append(util.expandFileName('testStaticNurbsCurveGrp.abc')) testNurbsCurveRW(self, True, self.__files[-1], 'haka') # test if some curves have different degree or close states information MayaCmds.file(new=True, force=True) name = MayaCmds.textCurves(font='Courier', text='Maya') MayaCmds.addAttr(name[0], longName='riCurves', at='bool', dv=True) self.__files.append( util.expandFileName('testStaticNurbsCurveGrp2.abc')) MayaCmds.AbcExport(j='-root %s -f %s' % (name[0], self.__files[-1])) MayaCmds.AbcImport(self.__files[-1], mode='open') if 'riCurves' in MayaCmds.listAttr(name[0]): self.fail(name[0] + ".riCurves shouldn't exist")
def testSelectionNamespace(self): nodes = MayaCmds.polyCube() MayaCmds.namespace(add="potato") MayaCmds.rename(nodes[0], "potato:" + nodes[0]) MayaCmds.select(MayaCmds.ls(type="mesh")) self.__files.append(util.expandFileName('selectionTest_namespace.abc')) MayaCmds.AbcExport(j='-sl -file ' + self.__files[-1]) MayaCmds.AbcImport(self.__files[-1], m='open') self.failUnless(MayaCmds.ls(type="mesh") != 1)
def testStaticCameraReadWrite(self): name = createCamera() # write to file self.__files.append(util.expandFileName('testStaticCameraReadWrite.abc')) MayaCmds.AbcExport(j='-root %s -file %s' % (name[0], self.__files[-1])) # read from file MayaCmds.AbcImport(self.__files[-1], mode='import') camList = MayaCmds.ls(type='camera') self.failUnless(util.compareCamera(camList[0], camList[1]))
def testNamespaceChild(self): self.buildScene() self.__files.append(util.expandFileName('testNamespace_foo_b.abc')) self.__files.append(util.expandFileName('testNamespace_bar_b.abc')) self.__files.append(util.expandFileName('testNamespace_b.abc')) MayaCmds.AbcExport(j='-root foo:b -fr 1 4 -file ' + self.__files[-3]) MayaCmds.AbcExport(j='-root bar:b -fr 1 4 -file ' + self.__files[-2]) MayaCmds.AbcExport(j='-root b -fr 1 4 -file ' + self.__files[-1]) self.buildStatic() MayaCmds.AbcImport(self.__files[-3], connect='foo:a') self.failUnless( 'testNamespace_foo_b_AlembicNode.outPolyMesh[0]' == MayaCmds. connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-3], connect='bar:a') self.failUnless( 'testNamespace_foo_b_AlembicNode1.outPolyMesh[0]' == MayaCmds. connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-3], connect='a') self.failUnless( 'testNamespace_foo_b_AlembicNode2.outPolyMesh[0]' == MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True)) self.buildStatic() MayaCmds.AbcImport(self.__files[-2], connect='foo:a') self.failUnless( 'testNamespace_bar_b_AlembicNode.outPolyMesh[0]' == MayaCmds. connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-2], connect='bar:a') self.failUnless( 'testNamespace_bar_b_AlembicNode1.outPolyMesh[0]' == MayaCmds. connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True)) MayaCmds.AbcImport(self.__files[-2], connect='a') self.failUnless( 'testNamespace_bar_b_AlembicNode2.outPolyMesh[0]' == MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True))
def testSet_noNormals_Attr(self): MayaCmds.polyCube(name='polyCube') # add the necessary props MayaCmds.select('polyCubeShape') MayaCmds.addAttr(longName='SubDivisionMesh', attributeType='bool', defaultValue=False) MayaCmds.addAttr(longName='interpolateBoundary', attributeType='bool', defaultValue=True) MayaCmds.addAttr(longName='noNormals', attributeType='bool', defaultValue=False) MayaCmds.addAttr(longName='flipNormals', attributeType='bool', defaultValue=False) MayaCmds.addAttr(longName='faceVaryingInterpolateBoundary', attributeType='bool', defaultValue=False) MayaCmds.polySphere(name='polySphere') # add the necessary props MayaCmds.select('polySphereShape') MayaCmds.addAttr(longName='SubDivisionMesh', attributeType='bool', defaultValue=False) MayaCmds.addAttr(longName='interpolateBoundary', attributeType='bool', defaultValue=True) MayaCmds.addAttr(longName='noNormals', attributeType='bool', defaultValue=True) MayaCmds.addAttr(longName='flipNormals', attributeType='bool', defaultValue=False) MayaCmds.addAttr(longName='faceVaryingInterpolateBoundary', attributeType='bool', defaultValue=False) #ignore facevaryingType, subdPaintLev MayaCmds.group('polyCube', 'polySphere', name='polygons') self.__files.append( util.expandFileName('staticPoly_noNormals_AttrTest.abc')) MayaCmds.AbcExport(j='-root polygons -f ' + self.__files[-1]) # reading test MayaCmds.AbcImport(self.__files[-1], mode='open', debug=False) # make sure the noNormal attribute is set correctly when the file is loaded self.failIf(MayaCmds.listAttr('polyCubeShape').count('noNormals') != 0) self.failUnless(MayaCmds.getAttr('polySphereShape.noNormals'))
def testStaticLocatorRW(self): name = createLocator() # write to file self.__files.append(util.expandFileName('testStaticLocatorRW.abc')) MayaCmds.AbcExport(j='-root %s -file %s' % (name[0], self.__files[-1])) # read from file MayaCmds.AbcImport(self.__files[-1], mode='import') locatorList = MayaCmds.ls(type='locator') self.failUnless(util.compareLocator(locatorList[0], locatorList[1]))