假设有如下scene
group -em -n "sync_grp"; addAttr -ln "frameExtension" -at long -dv 0 |sync_grp; setAttr "sync_grp.frameExtension" 1; setKeyframe -at "frameExtension" -t 1 -v 1 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 120 -v 120 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 33 -v 40 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 70 -v 40 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 71 -v 41 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 72 -v 42 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 86 -v 90 -itt "linear" -ott "linear" "sync_grp";
在这个group的frameExtension属性上有如下图所示的曲线,如何得到每个frame对应的frameExtension值?
import maya.cmds as mc for i in range(1,121): m_f = mc.getAttr('sync_grp.frameExtension',t=i) print i,'-->',m_f m_frames.append( m_f ) print m_frames
首先把每个frame对应的mapped_frame的数值记录下来
[1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 33, 34, 35, 36, 38, 39, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 42, 45, 49, 52, 56, 59, 63, 66, 69, 73, 76, 80, 83, 87, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 101, 102, 103, 104, 105, 106, 107, 108, 109, 109, 110, 111, 112, 113, 114, 115, 116, 116, 117, 118, 119, 120]
然后把连续的frame放在一个list里
clips=[] clip=[] for f in m_frames: if not clip: clip.append(f) elif clip[-1]+1==f: if len(clip)>=2 and clip[0]==clip[-1]: clips.append(clip[:-1]) clip=[clip[-1],f] else: clip.append(f) elif clip[-1]==f and clip[0]==f: clip.append(f) else: clips.append(clip) clip=[f] clips.append(clip) print clips for c in clips: print '-->',c
从而得到了一个可以用于外部播放器比如rv的,复制多个原始clip进playlist,进行叠加所需要的起始结束帧的list
--> [1, 2, 3] --> [5, 6, 7, 8] --> [10, 11, 12, 13, 14] --> [16, 17, 18, 19] --> [21, 22, 23, 24, 25] --> [27, 28, 29, 30, 31] --> [33, 34, 35, 36] --> [38, 39, 40] --> [40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40] --> [40, 41, 42] --> [45] --> [49] --> [52] --> [56] --> [59] --> [63] --> [66] --> [69] --> [73] --> [76] --> [80] --> [83] --> [87] --> [90, 91, 92, 93, 94] --> [94, 95, 96, 97, 98, 99, 100, 101] --> [101, 102, 103, 104, 105, 106, 107, 108, 109] --> [109, 110, 111, 112, 113, 114, 115, 116] --> [116, 117, 118, 119, 120]
一个正常些的例子
group -em -n "sync_grp"; addAttr -ln "frameExtension" -at long -dv 0 |sync_grp; setAttr "sync_grp.frameExtension" 1; setKeyframe -at "frameExtension" -t 1 -v 1 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 120 -v 120 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 40 -v 40 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 45 -v 40 -itt "linear" -ott "linear" "sync_grp"; setKeyframe -at "frameExtension" -t 46 -v 46 -itt "linear" -ott "linear" "sync_grp";
运行结果
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 40, 40, 40, 40, 40, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120] --> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40] --> [40, 40, 40, 40, 40] --> [46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120]