python scripted_shapekey_keyframing.py
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python scripted_shapekey_keyframing.py相关的知识,希望对你有一定的参考价值。
import bpy
import bmesh
import numpy as np
## ------- part 1 --- do this once.
sig = 0.3
n_frames = 101
bpy.context.scene.frame_end = n_frames
pi = np.pi
make_ico = bpy.ops.mesh.primitive_ico_sphere_add
make_ico(subdivisions=3, size = 2.0, location = (0,0,3))
obj = bpy.context.active_object
me = obj.data
ico0 = np.array([v.co for v in me.vertices]) # get ico vertices
zmin, zmax = ico0[:,2].min(), ico0[:,2].max()
zc = np.linspace(zmin, zmax, n_frames)
ico = np.zeros_like(ico0)
data = []
for i in range(n_frames):
ico[:,:2] = (1.0 + np.exp(-(ico0[:,2] - zc[i])**2/(2.*sig**2)))[:,None] * ico0[:,:2]
ico[:,2] = ico0[:,2]
data.append(ico.copy())
for i_frame in range(n_frames):
block = obj.shape_key_add(name=str(i_frame), from_mix=False) # returns a key_blocks member
block.value = 1
block.mute = True
for (vert, co) in zip(block.data, data[i_frame]):
vert.co = co
for i_frame in range(n_frames):
DATA_PATH = obj.data.shape_keys.key_blocks[str(i_frame)].path_from_id('mute')
block.mute = False
exec(obj.keyframe_insert(data_path=DATA_PATH, frame = i_frame + 1, index=-1))
block.mute = True
exec(obj.keyframe_insert(data_path=DATA_PATH, frame = i_frame + 2, index=-1))
以上是关于python scripted_shapekey_keyframing.py的主要内容,如果未能解决你的问题,请参考以下文章
python中__call__方法解析
python中的__name__
求一道python编程题
Python __name__ == ‘__main__’详细解释-Python零基础入门教程
Python __dict__与dir()区别
Python零碎