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 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 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 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 testFakeAnimCameraReadWrite(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') # write to file self.__files.append(util.expandFileName('testFakeAnimCameraReadWrite.abc')) MayaCmds.AbcExport(j='-fr 1 10 -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 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 testAnimCameraDeleteReload(self): # cam1 MayaCmds.camera(name='cam1') MayaCmds.setAttr('cam1Shape1.horizontalFilmAperture', 0.962) MayaCmds.setAttr('cam1Shape1.verticalFilmAperture', 0.731) MayaCmds.setAttr('cam1Shape1.focalLength', 50) MayaCmds.setAttr('cam1Shape1.focusDistance', 5) MayaCmds.setAttr('cam1Shape1.shutterAngle', 144) MayaCmds.setAttr('cam1Shape1.centerOfInterest', 1384.825) # cam2 MayaCmds.duplicate('cam1', returnRootsOnly=True) # cam3 MayaCmds.duplicate('cam1', returnRootsOnly=True) # cam4 MayaCmds.duplicate('cam1', returnRootsOnly=True) # animate each camera slightly different MayaCmds.currentTime(1, update=True) MayaCmds.setKeyframe('cam1Shape1', attribute='horizontalFilmAperture') MayaCmds.setKeyframe('cam2Shape', attribute='focalLength') MayaCmds.setKeyframe('cam3Shape', attribute='focusDistance') MayaCmds.setKeyframe('cam4Shape', attribute='shutterAngle') MayaCmds.setKeyframe('cam4Shape', attribute='centerOfInterest') MayaCmds.currentTime(24, update=True) MayaCmds.setKeyframe('cam1Shape1', attribute='horizontalFilmAperture', value=0.95) MayaCmds.setKeyframe('cam2Shape', attribute='focalLength', value=40) MayaCmds.setKeyframe('cam3Shape', attribute='focusDistance', value=5.4) MayaCmds.setKeyframe('cam4Shape', attribute='shutterAngle', value=174.94) MayaCmds.setKeyframe('cam4Shape', attribute='centerOfInterest', value=67.418) # write them out to an Abc file and load back in self.__files.append(util.expandFileName('testCamReload.abc')) MayaCmds.AbcExport(j='-fr 1 24 -root cam1 -root cam2 -root cam3 -root cam4 -file ' + self.__files[-1]) # load back the Abc file, delete the 2nd camera and save to a maya file MayaCmds.AbcImport(self.__files[-1], mode='open') MayaCmds.delete('cam2') 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('cam1', 'cam3', 'cam4', replace=True) MayaCmds.group(name='ReloadGrp') MayaCmds.AbcImport(self.__files[-2], mode='import') camList = MayaCmds.ls(type='camera') # should be 7, but this query will return the four standard cameras in # the scene too self.failUnlessEqual(len(camList), 11) # test the equality of cameras cameras = [('|cam1|cam1Shape1', '|ReloadGrp|cam1|cam1Shape1'), ('|cam3|cam3Shape', '|ReloadGrp|cam3|cam3Shape'), ('|cam4|cam4Shape', '|ReloadGrp|cam4|cam4Shape')] for c in cameras: for t in range(1, 25): MayaCmds.currentTime(t, update=True) if not util.compareCamera(c[0], c[1]): self.fail('%s and %s are not the same at frame %d' % (c[0], c[1], t))