借用了当年机器猫大大的代码,又借用了当年甜菜大大的代码,然后简化了一下,写了这个有玩意,用来熟悉一下maya pymel的K帧、属性创建、face的相关方法等等。

如图:要求鱼一条一条出现,下一条总会出现在前一条鱼之后,然后铺满平面网格

import random
from pymel.core import *
TOFFSET = 2

# 先选择平面再选择小盒子,执行全部
def appear(obj, start_frame):
    t = [0, 6, 10, 14, 18]
    v = [0, 1.5, 0.7, 1.1, 1]
    for i in range(len(t)):
        obj.sx.setKey(v=v[i], t=t[i]+start_frame)
        obj.sy.setKey(v=v[i], t=t[i]+start_frame)
        obj.sz.setKey(v=v[i], t=t[i]+start_frame)
def getStartFrame(obj):
    if not obj.hasAttr('startFrame'):
        recordStartFrame(obj,currentTime(q=1))
    return obj.startFrame.get()
def recordStartFrame(obj, start_frame):
    if not obj.hasAttr('startFrame'):
        addAttr(obj,ln='startFrame',at='double')
        setAttr(obj.startFrame,e=1,keyable=1)
    obj.startFrame.set(start_frame)

def facePos(self):
    return sum(self.getPoints('world'))/len(self.getPoints('world'))  
from types import MethodType
MeshFace.facePos = MethodType(facePos, None, MeshFace)


face_id_list = []
obj = selected()[0]
for f in obj.f:
    face_id_list.append(f.currentItemIndex())  
random.shuffle(face_id_list)

select(selected()[1])
for face_id in face_id_list:

    p = obj.f[face_id].facePos()
    start_frame = getStartFrame(selected()[0]) + TOFFSET
    new_obj = duplicate(rr=1)[0]
    move(new_obj, p)
    appear(new_obj, start_frame)
    recordStartFrame(new_obj, start_frame)