show | version | enable_checker |
---|---|---|
step |
1.0 |
true |
- 上次玩了动画
- 可以把动画流程总结一下吗?
import bpy
def clear_scene():
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
def create_man():
mat = bpy.data.materials.new('blue')
color = (0, 0, 1, 1)
mat.diffuse_color = color
man = bpy.data.objects.new("man", None)
bpy.data.collections["Collection"].objects.link(man)
bpy.ops.mesh.primitive_uv_sphere_add()
head = bpy.context.object
head.location = (0,0,2.5)
head.data.materials.append(mat)
head.parent = man
bpy.ops.mesh.primitive_cone_add()
body = bpy.context.object
body.location = (0,0,1)
body.parent = man
body.data.materials.append(mat)
def create_plane():
bpy.ops.mesh.primitive_plane_add()
plane = bpy.context.object
plane.scale = (10,10,1)
def create_camera():
bpy.ops.object.camera_add()
camera = bpy.context.object
camera.location = (3.059990406036377, -9.885231018066406, 12.905241966247559)
camera.rotation_euler = (0.7260572910308838, -6.679311326251991e-09, 0.30019673705101013)
bpy.context.scene.camera = camera
def create_spot():
bpy.ops.object.light_add(type='SPOT')
spot = bpy.context.object
spot.location = (-1.2811667919158936, -3.316868543624878, 12.282358169555664)
spot.rotation_euler = (0.34208473563194275, 1.8850268901360323e-08, -0.3071775436401367)
spot.data.energy = 1000
def render():
bpy.context.scene.render.resolution_x = 320
bpy.context.scene.render.resolution_y = 240
bpy.context.scene.render.resolution_percentage = 50
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = '/tmp/render2.png'
bpy.ops.render.render(write_still=True)
clear_scene()
create_man()
create_plane()
create_camera()
create_spot()
render()
- 为人物增加关键帧
帧号 | location |
---|---|
1 | (0,0,0) |
10 | (10,0,0) |
man.location = (0, 0, 0)
man.keyframe_insert(data_path="location", frame=1)
man.location = (10, 0, 0)
man.keyframe_insert(data_path="location", frame=10)
- 在layout视图中观察到
- 关键
- 人物动画
- 能动了吗?
- 在layout工作区
- 观察man的时间轴
- 确实有关键帧
- 能渲染出来吗
- 切回Script工作区
- 设置渲染动画
def render():
bpy.context.scene.frame_end = 10
bpy.context.scene.render.resolution_x = 200
bpy.context.scene.render.resolution_y = 150
bpy.context.scene.render.resolution_percentage = 50
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = "/home/shiyanlou/Code/o"
bpy.ops.render.render(animation=True)
- 点击运行按钮
- 渲染起来
feh /home/shiyanlou/Code
- 最终效果
- 人物动了
- 跑黑影里了
- 下面准备
- 让灯光追踪角色
- 选中聚光灯spot
- 约束调板
- 添加对象约束
- 约束类型为
- Track to
- 将Track To目标
- 设置为man
- 并设置z轴负向
- 指向man
- 开启实时渲染模式
- 在layout工作区
- 将上述工作转化为代码
import bpy
def clear_scene():
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
def create_man():
mat = bpy.data.materials.new('blue')
color = (0, 0, 1, 1)
mat.diffuse_color = color
man = bpy.data.objects.new("man", None)
bpy.data.collections["Collection"].objects.link(man)
bpy.ops.mesh.primitive_uv_sphere_add()
head = bpy.context.object
head.location = (0,0,2.5)
head.data.materials.append(mat)
head.parent = man
bpy.ops.mesh.primitive_cone_add()
body = bpy.context.object
body.location = (0,0,1)
body.parent = man
body.data.materials.append(mat)
man.location = (0, 0, 0)
man.keyframe_insert(data_path="location", frame=1)
man.location = (10, 0, 0)
man.keyframe_insert(data_path="location", frame=10)
def create_plane():
bpy.ops.mesh.primitive_plane_add()
plane = bpy.context.object
plane.scale = (10,10,1)
def create_camera():
bpy.ops.object.camera_add()
camera = bpy.context.object
camera.location = (3.059990406036377, -9.885231018066406, 12.905241966247559)
camera.rotation_euler = (0.7260572910308838, -6.679311326251991e-09, 0.30019673705101013)
bpy.context.scene.camera = camera
def create_spot():
bpy.ops.object.light_add(type='SPOT')
spot = bpy.context.object
spot.location = (-1.2811667919158936, -3.316868543624878, 12.282358169555664)
spot.rotation_euler = (0.34208473563194275, 1.8850268901360323e-08, -0.3071775436401367)
spot.data.energy = 1000
spot.constraints.new(type='TRACK_TO')
spot.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'
spot.constraints["Track To"].use_target_z = True
spot.constraints["Track To"].up_axis = 'UP_X'
spot.constraints["Track To"].target = bpy.data.objects["man"]
def render():
bpy.context.scene.frame_end = 10
bpy.context.scene.render.resolution_x = 200
bpy.context.scene.render.resolution_y = 150
bpy.context.scene.render.resolution_percentage = 50
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = "/home/shiyanlou/Code/o"
bpy.ops.render.render(animation=True)
clear_scene()
create_man()
create_plane()
create_camera()
create_spot()
render()
feh /home/shiyanlou/Code
- 观察序列效果
- 摄影机没跟上
- 在layout工作区
- 选中摄影机
- 在第1帧
- 设置rotation属性为关键帧
- 开启 4视图模式
- 将播放头移动到第10帧
- 并将 透视图 设置为
- 摄影机看到的画面
- 在保证
- 摄影机位置不变的基础上
- 调整摄影机的旋转角度
- 蓝色轴控制z轴旋转
- 红绿轴控制xy轴旋转
- 观察最终位置
- 并代码化
- 相应代码
import bpy
def clear_scene():
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
def create_man():
mat = bpy.data.materials.new('blue')
color = (0, 0, 1, 1)
mat.diffuse_color = color
man = bpy.data.objects.new("man", None)
bpy.data.collections["Collection"].objects.link(man)
bpy.ops.mesh.primitive_uv_sphere_add()
head = bpy.context.object
head.location = (0,0,2.5)
head.data.materials.append(mat)
head.parent = man
bpy.ops.mesh.primitive_cone_add()
body = bpy.context.object
body.location = (0,0,1)
body.parent = man
body.data.materials.append(mat)
man.location = (0, 0, 0)
man.keyframe_insert(data_path="location", frame=1)
man.location = (10, 0, 0)
man.keyframe_insert(data_path="location", frame=10)
def create_plane():
bpy.ops.mesh.primitive_plane_add()
plane = bpy.context.object
plane.scale = (10,10,1)
def create_camera():
bpy.ops.object.camera_add()
camera = bpy.context.object
camera.location = (3.059990406036377, -9.885231018066406, 12.905241966247559)
camera.rotation_euler = (0.7260572910308838, -6.679311326251991e-09, 0.30019673705101013)
bpy.context.scene.camera = camera
camera.keyframe_insert(data_path="rotation_euler", frame=1)
camera.rotation_euler = (0.7763736844062805, -0.06353582441806793, -0.6263947486877441)
camera.keyframe_insert(data_path="rotation_euler", frame=10)
def create_spot():
bpy.ops.object.light_add(type='SPOT')
spot = bpy.context.object
spot.location = (-1.2811667919158936, -3.316868543624878, 12.282358169555664)
spot.rotation_euler = (0.34208473563194275, 1.8850268901360323e-08, -0.3071775436401367)
spot.data.energy = 1000
spot.constraints.new(type='TRACK_TO')
spot.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'
spot.constraints["Track To"].use_target_z = True
spot.constraints["Track To"].up_axis = 'UP_X'
spot.constraints["Track To"].target = bpy.data.objects["man"]
def render():
bpy.context.scene.frame_end = 10
bpy.context.scene.render.resolution_x = 200
bpy.context.scene.render.resolution_y = 150
bpy.context.scene.render.resolution_percentage = 50
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = "/home/shiyanlou/Code/o"
bpy.ops.render.render(animation=True)
clear_scene()
create_man()
create_plane()
create_camera()
create_spot()
render()
feh /home/shiyanlou/Code
- 观察序列效果
- 灯光和摄影机
- 都开始跟着角色了
- 灯光和摄影机
- 可以 把镜头
- 推上来吗?
名称 | 时长 |
---|---|
起幅 | 10帧 |
镜头焦距推 | 10帧 |
落幅 | 10帧 |
- 将视图
- 从4视图
- 还原为单一视图
- 观察摄影机焦距
- 50mm
- 尝试推镜头
- 将镜头焦距
- 设置为70 mm
- 观察效果
- 将 推镜头 代码化
import bpy
def clear_scene():
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()
def create_man():
mat = bpy.data.materials.new('blue')
color = (0, 0, 1, 1)
mat.diffuse_color = color
man = bpy.data.objects.new("man", None)
bpy.data.collections["Collection"].objects.link(man)
bpy.ops.mesh.primitive_uv_sphere_add()
head = bpy.context.object
head.location = (0,0,2.5)
head.data.materials.append(mat)
head.parent = man
bpy.ops.mesh.primitive_cone_add()
body = bpy.context.object
body.location = (0,0,1)
body.parent = man
body.data.materials.append(mat)
man.location = (0, 0, 0)
man.keyframe_insert(data_path="location", frame=1)
man.location = (10, 0, 0)
man.keyframe_insert(data_path="location", frame=10)
def create_plane():
bpy.ops.mesh.primitive_plane_add()
plane = bpy.context.object
plane.scale = (10,10,1)
def create_camera():
bpy.ops.object.camera_add()
camera = bpy.context.object
camera.location = (3.059990406036377, -9.885231018066406, 12.905241966247559)
camera.rotation_euler = (0.7260572910308838, -6.679311326251991e-09, 0.30019673705101013)
bpy.context.scene.camera = camera
camera.keyframe_insert(data_path="rotation_euler", frame=1)
camera.rotation_euler = (0.7763736844062805, -0.06353582441806793, -0.6263947486877441)
camera.keyframe_insert(data_path="rotation_euler", frame=10)
camera.data.lens = 50
camera.data.keyframe_insert(data_path="lens", frame=20)
camera.data.lens = 70
camera.data.keyframe_insert(data_path="lens", frame=30)
camera.data.lens = 70
camera.data.keyframe_insert(data_path="lens", frame=40)
def create_spot():
bpy.ops.object.light_add(type='SPOT')
spot = bpy.context.object
spot.location = (-1.2811667919158936, -3.316868543624878, 12.282358169555664)
spot.rotation_euler = (0.34208473563194275, 1.8850268901360323e-08, -0.3071775436401367)
spot.data.energy = 1000
spot.constraints.new(type='TRACK_TO')
spot.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'
spot.constraints["Track To"].use_target_z = True
spot.constraints["Track To"].up_axis = 'UP_X'
spot.constraints["Track To"].target = bpy.data.objects["man"]
def render():
bpy.context.scene.frame_end = 40
bpy.context.scene.render.resolution_x = 200
bpy.context.scene.render.resolution_y = 150
bpy.context.scene.render.resolution_percentage = 50
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.filepath = "/home/shiyanlou/Code/o"
bpy.ops.render.render(animation=True)
clear_scene()
create_man()
create_plane()
create_camera()
create_spot()
render()
- 这次总共需要渲染40帧
feh /home/shiyanlou/Code
- 可以在时间轴上看关键帧吗?
- 在dope sheet 中观察
- 关键帧
- 摄影机的旋转
- 1、10帧
- 摄影机的焦距
- 20、30、40帧
- 这次将动态图渲染做了总结
- ?🤔
- 我们下次再说!👋