-
Notifications
You must be signed in to change notification settings - Fork 1
/
shapeKey_animate.py
47 lines (38 loc) · 1.1 KB
/
shapeKey_animate.py
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
41
42
43
44
45
46
47
import bpy
import bmesh
VERTS = 1
EDGES = 2
FACES = 3
def addShapeKey(obj, frame: int, mode: int):
kn = "stage{0:0>5}".format(frame)
sk = obj.shape_key_add(kn) #, from_mix=False)
bm = bmesh.new()
bm.from_mesh(obj.data)
bm.verts.ensure_lookup_table()
sl = bm.verts.layers.shape.get(kn)
for i in range(frame, frame + 1):
if i % 100 == 0:
print(i)
for u in range(mode):
bm.verts[mode * i + u][sl] *= 0
bm.to_mesh(obj.data)
obj = bpy.context.active_object
scene = bpy.context.scene
bpy.ops.object.shape_key_remove(all=True)
sk0 = obj.shape_key_add("Basis")
print(sk0)
sk0 = obj.data.shape_keys
print(sk0)
sk0.use_relative = False
frameScale = 1
currentFrame = 1
obj.data.shape_keys.eval_time = 10
obj.data.shape_keys.keyframe_insert('eval_time', frame=currentFrame)
currentFrame = currentFrame + frameScale
for i in range(len(obj.data.vertices)):
addShapeKey(obj, i, FACES)
obj.data.shape_keys.eval_time = 10 * (i + 2)
obj.data.shape_keys.keyframe_insert('eval_time', frame=currentFrame)
currentFrame = currentFrame + frameScale
scene.frame_end = currentFrame
bpy.ops.object.shape_key_retime()